Skip to content

Commit

Permalink
v1.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
patelka2211 committed Jul 5, 2023
1 parent 231fbbe commit b01bfb4
Show file tree
Hide file tree
Showing 27 changed files with 316 additions and 253 deletions.
4 changes: 2 additions & 2 deletions Dominar.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>
```

Expand Down Expand Up @@ -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>
```

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@patelka2211/dominar",
"version": "1.2.2",
"version": "1.2.3",
"description": "Dominar is a powerful library designed to make it easy for developers to manipulate the Document Object Model (DOM) and create dynamic HTML content. Dominar empowers you to take control of your web development projects like a pro. Unleash the power to dominate the DOM with Dominar.",
"main": "index.js",
"module": "index.js",
Expand All @@ -9,7 +9,7 @@
"tsc-build": "tsc -p ./tsconfig.json",
"rollup-esm": "rollup -c --environment format:esm",
"rollup-iife": "rollup -c --environment format:iife",
"terser-esm": "terser ./index.js -c -m -o ./index.js",
"terser-esm": "terser ./index.js -c -m --toplevel -o ./index.js",
"terser-iife": "terser ./Dominar.js -c -m -o ./Dominar.js",
"build": "npm run tsc-build && npm run rollup-esm && npm run rollup-iife && npm run terser-esm && npm run terser-iife && rm -rf ./lib/",
"test-build": "npm run tsc-build && npm run rollup-esm && tsc ./test/index.ts -t es6 && rollup ./test/index.js -o ./test/out.js && rm -rf ./lib/"
Expand Down
7 changes: 3 additions & 4 deletions src/attributes.ts → src/attributes/setAttributes.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
type DominarTagAttributes = { [attributeName: string]: string | number | true };
import { DominarTagAttributes } from "./types";

/**
* Sets the attributes of an HTML element based on the provided object.
*
* @param {HTMLElement} element The HTML element to set the attributes on.
* @param {Object} attributes An object containing the attribute names and values to set.
* @returns {HTMLElement} The same HTML element with the updated attributes.
*/
function setAttributes(
export function setAttributes(
element: HTMLElement,
attributes: DominarTagAttributes
): HTMLElement {
Expand All @@ -26,5 +27,3 @@ function setAttributes(
}
return element;
}

export { DominarTagAttributes, setAttributes };
3 changes: 3 additions & 0 deletions src/attributes/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type DominarTagAttributes = {
[attributeName: string]: string | number | true;
};
42 changes: 42 additions & 0 deletions src/children/insertChildren.ts
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;
}
37 changes: 0 additions & 37 deletions src/eventListeners.ts

This file was deleted.

18 changes: 18 additions & 0 deletions src/eventListeners/addEventListeners.ts
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;
}
18 changes: 18 additions & 0 deletions src/eventListeners/removeEventListeners.ts
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;
}
3 changes: 3 additions & 0 deletions src/eventListeners/types.ts
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;
};
16 changes: 11 additions & 5 deletions src/index.ts
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";
15 changes: 6 additions & 9 deletions src/render.ts → src/render/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { DominarTagChildren, insertChildren, childrenInsertType } from "./tags";
type RenderOptions = {
clearBeforeRender?: boolean;
insertType?: childrenInsertType;
};
import { insertChildren } from "../children/insertChildren";
import { DominarTagChildren } from "../tag/types";
import { RenderOptions } from "./types";

/**
* Renders a DOM element or a list of elements to a specified HTML element.
*
Expand All @@ -14,7 +13,7 @@ type RenderOptions = {
* @returns {Promise<void>} A Promise that resolves when the rendering is complete.
* @throws {Error} If the root parameter is null or undefined.
*/
async function render(
export async function render(
root: HTMLElement,
children: DominarTagChildren,
options: RenderOptions = {
Expand All @@ -30,13 +29,11 @@ async function render(
insertType = "append";
}

if (insertType === undefined) insertType = "append";
if (!insertType) insertType = "append";

if (insertType !== "append" && insertType !== "prepend")
throw Error(
`'insertType' in options can be 'append' or 'prepend' but not '${insertType}'.`
);
insertChildren(root, children, insertType);
}

export { render };
6 changes: 6 additions & 0 deletions src/render/types.ts
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;
};
13 changes: 13 additions & 0 deletions src/svg-parser/index.ts
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 };
Loading

0 comments on commit b01bfb4

Please sign in to comment.