Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bun #31

Merged
merged 4 commits into from
May 12, 2024
Merged

Bun #31

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,17 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: ".node-version"
cache: "npm"
- name: Setup Bun
uses: oven-sh/setup-bun@v1

- name: Install dependencies
run: npm install
run: bun install

- name: Build
run: npm run build
run: bun run build

- name: Lint
run: npm run lint
run: bun run lint

- name: Run Tests
run: npm run test || npm run test
run: bun run test || bun run test
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.

21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@
"url": "https://github.com/sponsors/joeldrapper"
},
"scripts": {
"test": "web-test-runner test/**/*.test.js --node-resolve",
"t": "web-test-runner --node-resolve",
"build": "npx tsc && prettier --write ./src ./dist",
"watch": "npx tsc -w",
"test:watch": "npm run test -- --watch",
"lint": "prettier --check ./src ./dist ./test",
"minify": "terser dist/morphlex.js -o dist/morphlex.min.js --config-file terser-config.json",
"prepare": "npm run build && npm run minify",
"ship": "npm run prepare && npm run test && npm run lint && npm publish",
"format": "prettier --write ./src ./dist ./test",
"size": "npm run prepare && gzip-size ./dist/morphlex.min.js --raw --include-original"
"test": "bun run web-test-runner test/**/*.test.js --node-resolve",
"build": "bun run tsc && bun run prettier --write ./src ./dist",
"watch": "bun run tsc -w",
"test:watch": "bun run test -- --watch",
"lint": "bun run prettier --check ./src ./dist ./test",
"minify": "bun run terser dist/morphlex.js -o dist/morphlex.min.js --config-file terser-config.json",
"prepare": "bun run build && bun run minify",
"ship": "bun run prepare && bun run test && bun run lint && bun run publish",
"format": "bun run prettier --write ./src ./dist ./test",
"size": "bun run prepare && bun run gzip-size ./dist/morphlex.min.js --raw --include-original"
},
"devDependencies": {
"@open-wc/testing": "^3.0.0-next.5",
Expand Down
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
Loading