-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
231fbbe
commit b01bfb4
Showing
27 changed files
with
316 additions
and
253 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,22 +13,22 @@ Visit [https://patelka2211.github.io/dominar/](https://patelka2211.github.io/dom | |
## Installation | ||
|
||
[![npm (scoped)](https://img.shields.io/npm/v/@patelka2211/dominar)](https://www.npmjs.com/package/@patelka2211/dominar) | ||
[![npm bundle size (scoped)](https://img.shields.io/bundlephobia/min/@patelka2211/dominar)](https://bundlephobia.com/package/@patelka2211/[email protected].2) | ||
[![npm bundle size (scoped)](https://img.shields.io/bundlephobia/min/@patelka2211/dominar)](https://bundlephobia.com/package/@patelka2211/[email protected].3) | ||
[![npm](https://img.shields.io/npm/dy/@patelka2211/dominar)](https://www.npmjs.com/package/@patelka2211/dominar) | ||
[![jsDelivr hits (npm scoped)](https://img.shields.io/jsdelivr/gh/hy/patelka2211/dominar)](https://cdn.jsdelivr.net/gh/patelka2211/[email protected].2/) | ||
[![jsDelivr hits (npm scoped)](https://img.shields.io/jsdelivr/gh/hy/patelka2211/dominar)](https://cdn.jsdelivr.net/gh/patelka2211/[email protected].3/) | ||
|
||
To install Dominar using npm, run the following command: | ||
|
||
```sh | ||
npm i @patelka2211/dominar | ||
``` | ||
|
||
Alternatively, you can include [Dominar's IIFE file](https://cdn.jsdelivr.net/gh/patelka2211/[email protected].2/Dominar.js) in your website using a `<script>` tag: | ||
Alternatively, you can include [Dominar's IIFE file](https://cdn.jsdelivr.net/gh/patelka2211/[email protected].3/Dominar.js) in your website using a `<script>` tag: | ||
|
||
```html | ||
<script | ||
async | ||
src="https://cdn.jsdelivr.net/gh/patelka2211/[email protected].2/Dominar.js" | ||
src="https://cdn.jsdelivr.net/gh/patelka2211/[email protected].3/Dominar.js" | ||
></script> | ||
``` | ||
|
||
|
@@ -91,12 +91,12 @@ addEventListeners(document.body, { | |
|
||
### When included as a `<script>` tag in a website. | ||
|
||
If the script tag is not already included in the `<head>` tag, please add the following script tag to include [Dominar's IIFE JavaScript](https://cdn.jsdelivr.net/gh/patelka2211/[email protected].2/Dominar.js) file. | ||
If the script tag is not already included in the `<head>` tag, please add the following script tag to include [Dominar's IIFE JavaScript](https://cdn.jsdelivr.net/gh/patelka2211/[email protected].3/Dominar.js) file. | ||
|
||
```html | ||
<script | ||
async | ||
src="https://cdn.jsdelivr.net/gh/patelka2211/[email protected].2/Dominar.js" | ||
src="https://cdn.jsdelivr.net/gh/patelka2211/[email protected].3/Dominar.js" | ||
></script> | ||
``` | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type DominarTagAttributes = { | ||
[attributeName: string]: string | number | true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { isInstanceOfDominarTag } from "../tag/isInstanceOfDominarTag"; | ||
import { isInstanceOfDominarTagList } from "../tagList/isInstanceOfDominarTagList"; | ||
import { isInstanceOfParsedSVG } from "../svg-parser/isInstanceOfparsedSVG"; | ||
import { parsedSVG } from "../svg-parser/parsedSVG"; | ||
import { DominarTag } from "../tag/DominarTag"; | ||
import { DominarTagChildren, childrenInsertType } from "../tag/types"; | ||
import { DominarTagList } from "../tagList/DominarTagList"; | ||
|
||
/** | ||
* Inserts children into an HTML element. | ||
* @param {HTMLElement} root The root HTML element where the children will be inserted. | ||
* @param {DominarTagChildren} children The children to be inserted. | ||
* @param {childrenInsertType} [insertType="append"] The type of insertion. Default is "append". | ||
* @returns {HTMLElement} The modified root HTML element. | ||
*/ | ||
export function insertChildren( | ||
root: HTMLElement, | ||
children: DominarTagChildren, | ||
insertType: childrenInsertType = "append" | ||
): HTMLElement { | ||
if (typeof children === "string" || typeof children === "number") | ||
root[insertType](String(children)); | ||
else if (isInstanceOfDominarTag(children)) | ||
root[insertType]((children as DominarTag).renderedTag); | ||
else if (isInstanceOfDominarTagList(children)) { | ||
let renderedTagList = (children as DominarTagList).renderedTagList, | ||
tagListLength = renderedTagList.length; | ||
for (let index = 0; index < tagListLength; index++) { | ||
root[insertType]( | ||
renderedTagList[ | ||
insertType === "append" ? index : tagListLength - 1 - index | ||
] | ||
); | ||
} | ||
} else if ( | ||
isInstanceOfParsedSVG(children) && | ||
(children as parsedSVG).svg !== null | ||
) | ||
root[insertType]((children as parsedSVG).svg as SVGSVGElement); | ||
else if (children instanceof HTMLElement) root[insertType](children); | ||
return root; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { DominarTagEventListeners } from "./types"; | ||
|
||
/** | ||
* Adds the specified event listeners to an HTML element. | ||
* | ||
* @param {HTMLElement} element The HTML element to add event listeners to. | ||
* @param {Object.<string, function>} eventListeners An object containing event listener functions keyed by event type. | ||
* @returns {HTMLElement} The same HTML element with the added event listeners. | ||
*/ | ||
export function addEventListeners( | ||
element: HTMLElement, | ||
eventListeners: DominarTagEventListeners | ||
): HTMLElement { | ||
Object.entries(eventListeners).forEach(([type, listener]) => { | ||
element.addEventListener(type, listener as (ev: Event) => void); | ||
}); | ||
return element; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { DominarTagEventListeners } from "./types"; | ||
|
||
/** | ||
* Removes the specified event listeners from an HTML element. | ||
* | ||
* @param {HTMLElement} element The HTML element to remove event listeners from. | ||
* @param {Object.<string, function>} eventListeners An object containing event listener functions keyed by event type. | ||
* @returns {HTMLElement} The same HTML element with the added event listeners. | ||
*/ | ||
export function removeEventListeners( | ||
element: HTMLElement, | ||
eventListeners: DominarTagEventListeners | ||
): HTMLElement { | ||
Object.entries(eventListeners).forEach(([type, listener]) => { | ||
element.removeEventListener(type, listener as (ev: Event) => void); | ||
}); | ||
return element; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type DominarTagEventListeners = { | ||
[K in keyof HTMLElementEventMap]?: (ev: HTMLElementEventMap[K]) => void; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
export { insertChildren, tag, tagList } from "./tags"; | ||
export { render } from "./render"; | ||
export { setAttributes } from "./attributes"; | ||
export { addEventListeners, removeEventListeners } from "./eventListeners"; | ||
export { SVGParser } from "./svgParser"; | ||
export { setAttributes } from "./attributes/setAttributes"; | ||
export { insertChildren } from "./children/insertChildren"; | ||
export { addEventListeners } from "./eventListeners/addEventListeners"; | ||
export { removeEventListeners } from "./eventListeners/removeEventListeners"; | ||
export { isInstanceOfDominarTag } from "./tag/isInstanceOfDominarTag"; | ||
export { isInstanceOfDominarTagList } from "./tagList/isInstanceOfDominarTagList"; | ||
export { isInstanceOfParsedSVG } from "./svg-parser/isInstanceOfparsedSVG"; | ||
export { render } from "./render/index"; | ||
export { SVGParser } from "./svg-parser/index"; | ||
export { tag } from "./tag/index"; | ||
export { tagList } from "./tagList/index"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { childrenInsertType } from "../tag/types"; | ||
|
||
export type RenderOptions = { | ||
clearBeforeRender?: boolean; | ||
insertType?: childrenInsertType; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { parsedSVG } from "./parsedSVG"; | ||
|
||
/** | ||
* Parses an SVG string and returns a parsedSVG instance. | ||
* @function | ||
* @param {string} svgString The SVG string to be parsed. | ||
* @returns {parsedSVG} The parsed SVG. | ||
*/ | ||
export function SVGParser(svgString: string): parsedSVG { | ||
return new parsedSVG(svgString); | ||
} | ||
|
||
// export { parsedSVG, SVGParser }; |
Oops, something went wrong.