Skip to content

Commit

Permalink
Bun (#31)
Browse files Browse the repository at this point in the history
* Use bun on CI

* Update package.json

* Update bun.lockb

* Reduce public API methods
  • Loading branch information
joeldrapper authored May 12, 2024
1 parent c604c2b commit 4b2174b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 24 deletions.
Binary file modified bun.lockb
Binary file not shown.
6 changes: 2 additions & 4 deletions dist/morphlex.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ interface Options {
beforePropertyUpdated?: (node: Node, propertyName: PropertyKey, newValue: unknown) => boolean;
afterPropertyUpdated?: (node: Node, propertyName: PropertyKey, previousValue: unknown) => void;
}
export declare function morph(node: ChildNode, reference: ChildNode, options?: Options): void;
export declare function morphInner(element: Element, reference: Element, options?: Options): void;
export declare function morphFromString(node: ChildNode, reference: string, options?: Options): void;
export declare function morphInnerFromString(element: Element, reference: string, options?: Options): void;
export declare function morph(node: ChildNode, reference: ChildNode | string, options?: Options): void;
export declare function morphInner(element: Element, reference: Element | string, options?: Options): void;
export {};
11 changes: 3 additions & 8 deletions dist/morphlex.js

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

17 changes: 5 additions & 12 deletions src/morphlex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,16 @@ interface Options {
afterPropertyUpdated?: (node: Node, propertyName: PropertyKey, previousValue: unknown) => void;
}

export function morph(node: ChildNode, reference: ChildNode, options: Options = {}): void {
export function morph(node: ChildNode, reference: ChildNode | string, options: Options = {}): void {
if (typeof reference === "string") reference = parseChildNodeFromString(reference);
new Morph(options).morph([node, reference]);
}

export function morphInner(element: Element, reference: Element, options: Options = {}): void {
export function morphInner(element: Element, reference: Element | string, options: Options = {}): void {
if (typeof reference === "string") reference = parseElementFromString(reference);
new Morph(options).morphInner([element, reference]);
}

export function morphFromString(node: ChildNode, reference: string, options: Options = {}): void {
morph(node, parseChildNodeFromString(reference), options);
}

export function morphInnerFromString(element: Element, reference: string, options: Options = {}): void {
morphInner(element, parseElementFromString(reference), options);
}

function parseElementFromString(string: string): Element {
const node = parseChildNodeFromString(string);

Expand All @@ -75,9 +69,8 @@ function parseElementFromString(string: string): Element {
function parseChildNodeFromString(string: string): ChildNode {
const parser = new DOMParser();
const doc = parser.parseFromString(string, "text/html");
const firstChild = doc.body.firstChild;

if (doc.childNodes.length === 1) return firstChild as ChildNode;
if (doc.childNodes.length === 1) return doc.body.firstChild as ChildNode;
else throw new Error("[Morphlex] The string was not a valid HTML node.");
}

Expand Down

0 comments on commit 4b2174b

Please sign in to comment.