@davidsouther/jiffies 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/assert.d.ts +23 -23
- package/build/assert.js +33 -33
- package/build/case.d.ts +1 -1
- package/build/case.js +5 -5
- package/build/components/button_bar.d.ts +8 -8
- package/build/components/button_bar.js +27 -27
- package/build/components/inline_edit.d.ts +12 -12
- package/build/components/inline_edit.js +48 -48
- package/build/components/logger.d.ts +6 -7
- package/build/components/logger.js +22 -22
- package/build/components/select.d.ts +13 -10
- package/build/components/select.js +3 -3
- package/build/components/test.d.ts +1 -1
- package/build/components/test.js +2 -2
- package/build/components/virtual_scroll.d.ts +40 -41
- package/build/components/virtual_scroll.js +94 -94
- package/build/components/virtual_scroll.test.d.ts +1 -1
- package/build/components/virtual_scroll.test.js +21 -21
- package/build/context.d.ts +15 -15
- package/build/context.js +43 -43
- package/build/context.test.d.ts +1 -1
- package/build/context.test.js +46 -46
- package/build/debounce.d.ts +1 -1
- package/build/debounce.js +7 -7
- package/build/display.d.ts +5 -5
- package/build/display.js +11 -11
- package/build/dom/css/border.d.ts +11 -11
- package/build/dom/css/border.js +27 -27
- package/build/dom/css/constants.d.ts +31 -31
- package/build/dom/css/constants.js +28 -28
- package/build/dom/css/core.d.ts +5 -5
- package/build/dom/css/core.js +24 -24
- package/build/dom/css/fstyle.d.ts +5 -5
- package/build/dom/css/fstyle.js +32 -32
- package/build/dom/css/sizing.d.ts +5 -5
- package/build/dom/css/sizing.js +10 -10
- package/build/dom/dom.d.ts +26 -27
- package/build/dom/dom.js +95 -95
- package/build/dom/fc.d.ts +14 -14
- package/build/dom/fc.js +36 -35
- package/build/dom/fc.test.d.ts +1 -1
- package/build/dom/fc.test.js +21 -21
- package/build/dom/form/form.app.d.ts +1 -1
- package/build/dom/form/form.app.js +23 -23
- package/build/dom/form/form.d.ts +26 -26
- package/build/dom/form/form.js +34 -34
- package/build/dom/form/form.test.js +1 -1
- package/build/dom/html.d.ts +113 -117
- package/build/dom/html.js +114 -114
- package/build/dom/html.test.d.ts +1 -1
- package/build/dom/html.test.js +58 -58
- package/build/dom/provide.d.ts +3 -3
- package/build/dom/provide.js +7 -7
- package/build/dom/router/link.d.ts +6 -6
- package/build/dom/router/link.js +3 -3
- package/build/dom/router/router.d.ts +12 -12
- package/build/dom/router/router.js +49 -49
- package/build/dom/svg.d.ts +64 -64
- package/build/dom/svg.js +65 -65
- package/build/dom/test.d.ts +1 -1
- package/build/dom/test.js +2 -2
- package/build/dom/types/css.d.ts +6612 -6612
- package/build/dom/types/css.js +23 -23
- package/build/dom/types/dom.js +1 -1
- package/build/dom/types/html.d.ts +616 -616
- package/build/dom/types/html.js +1 -1
- package/build/dom/xml.d.ts +1 -1
- package/build/dom/xml.js +4 -5
- package/build/equal.d.ts +5 -5
- package/build/equal.js +37 -37
- package/build/equal.test.d.ts +1 -1
- package/build/equal.test.js +20 -20
- package/build/flags.d.ts +7 -7
- package/build/flags.js +48 -48
- package/build/flags.test.d.ts +1 -1
- package/build/flags.test.js +35 -35
- package/build/fs.d.ts +48 -48
- package/build/fs.js +144 -144
- package/build/fs.test.d.ts +1 -1
- package/build/fs.test.js +43 -43
- package/build/generator.d.ts +1 -1
- package/build/generator.js +10 -10
- package/build/generator.test.d.ts +1 -1
- package/build/generator.test.js +24 -24
- package/build/is_browser.d.ts +1 -1
- package/build/is_browser.js +1 -1
- package/build/loader.d.mts +22 -22
- package/build/loader.mjs +35 -35
- package/build/lock.d.ts +1 -1
- package/build/lock.js +23 -23
- package/build/lock.test.d.ts +1 -1
- package/build/lock.test.js +16 -16
- package/build/log.d.ts +26 -26
- package/build/log.js +46 -46
- package/build/observable/observable.d.ts +83 -0
- package/build/observable/observable.js +148 -0
- package/build/observable/observable.test.d.ts +1 -0
- package/build/observable/observable.test.js +21 -0
- package/build/range.d.ts +1 -1
- package/build/range.js +7 -7
- package/build/result.d.ts +31 -31
- package/build/result.js +65 -65
- package/build/result.test.d.ts +1 -1
- package/build/result.test.js +71 -71
- package/build/safe.d.ts +1 -1
- package/build/safe.js +10 -10
- package/build/scope/describe.d.ts +18 -14
- package/build/scope/describe.js +61 -52
- package/build/scope/display/console.d.ts +2 -2
- package/build/scope/display/console.js +21 -21
- package/build/scope/display/dom.d.ts +3 -3
- package/build/scope/display/dom.js +26 -26
- package/build/scope/display/junit.d.ts +2 -2
- package/build/scope/display/junit.js +17 -17
- package/build/scope/execute.d.ts +12 -12
- package/build/scope/execute.js +85 -85
- package/build/scope/expect.d.ts +23 -23
- package/build/scope/expect.js +108 -108
- package/build/scope/fix.d.ts +4 -4
- package/build/scope/fix.js +22 -22
- package/build/scope/index.d.ts +3 -3
- package/build/scope/index.js +3 -3
- package/build/scope/scope.d.ts +17 -17
- package/build/scope/scope.js +1 -1
- package/build/server/http/apps.d.ts +5 -5
- package/build/server/http/apps.js +23 -23
- package/build/server/http/css.d.ts +5 -5
- package/build/server/http/css.js +50 -47
- package/build/server/http/index.d.ts +21 -21
- package/build/server/http/index.js +73 -73
- package/build/server/http/response.d.ts +4 -4
- package/build/server/http/response.js +40 -40
- package/build/server/http/sitemap.d.ts +2 -2
- package/build/server/http/sitemap.js +42 -42
- package/build/server/http/static.d.ts +2 -2
- package/build/server/http/static.js +21 -21
- package/build/server/http/typescript.d.ts +5 -5
- package/build/server/http/typescript.js +40 -40
- package/build/server/main.d.ts +2 -2
- package/build/server/main.js +9 -9
- package/build/test.d.mts +2 -2
- package/build/test.mjs +23 -23
- package/build/test_all.d.ts +7 -7
- package/build/test_all.js +18 -18
- package/build/transpile.d.mts +3 -3
- package/build/transpile.mjs +18 -18
- package/package.json +3 -3
- package/src/components/logger.ts +2 -3
- package/src/components/virtual_scroll.test.ts +4 -4
- package/src/components/virtual_scroll.ts +8 -8
- package/src/diff.test.ts +48 -0
- package/src/diff.ts +84 -0
- package/src/dom/dom.ts +73 -61
- package/src/dom/fc.ts +10 -9
- package/src/dom/html.test.ts +5 -5
- package/src/dom/html.ts +7 -10
- package/src/dom/observable.test.ts +43 -0
- package/src/dom/observable.ts +11 -0
- package/src/dom/router/router.ts +4 -4
- package/src/dom/test.ts +5 -1
- package/src/dom/xml.ts +1 -2
- package/src/index.html +6 -3
- package/src/observable/_notes +21 -8
- package/src/observable/event.ts +93 -0
- package/src/observable/observable.test.ts +73 -0
- package/src/observable/observable.ts +403 -0
- package/src/scope/describe.ts +14 -1
- package/src/scope/display/dom.ts +2 -2
- package/src/scope/execute.ts +2 -5
- package/src/server/http/css.ts +3 -1
- package/src/test_all.ts +10 -8
- package/src/observable/observable._js +0 -175
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
export const Sizes = {
|
|
2
|
-
none: "0px",
|
|
3
|
-
sm: "0.125rem",
|
|
4
|
-
"": "0.25rem",
|
|
5
|
-
md: "0.375rem",
|
|
6
|
-
lg: "0.5rem",
|
|
7
|
-
xl: "0.75rem",
|
|
8
|
-
"2xl": "1rem",
|
|
9
|
-
"3xl": "1.5rem",
|
|
10
|
-
full: "9999px",
|
|
11
|
-
};
|
|
12
|
-
export const Sides = {
|
|
13
|
-
"": "",
|
|
14
|
-
t: "Top",
|
|
15
|
-
r: "Right",
|
|
16
|
-
l: "Left",
|
|
17
|
-
b: "Bottom",
|
|
18
|
-
tl: "TopLeft",
|
|
19
|
-
tr: "TopRight",
|
|
20
|
-
bl: "BottomLeft",
|
|
21
|
-
br: "BottomRight",
|
|
22
|
-
};
|
|
23
|
-
export const Widths = {
|
|
24
|
-
"1/4": "25%",
|
|
25
|
-
"1/2": "50%",
|
|
26
|
-
"3/4": "75%",
|
|
27
|
-
full: "100%",
|
|
28
|
-
};
|
|
1
|
+
export const Sizes = {
|
|
2
|
+
none: "0px",
|
|
3
|
+
sm: "0.125rem",
|
|
4
|
+
"": "0.25rem",
|
|
5
|
+
md: "0.375rem",
|
|
6
|
+
lg: "0.5rem",
|
|
7
|
+
xl: "0.75rem",
|
|
8
|
+
"2xl": "1rem",
|
|
9
|
+
"3xl": "1.5rem",
|
|
10
|
+
full: "9999px",
|
|
11
|
+
};
|
|
12
|
+
export const Sides = {
|
|
13
|
+
"": "",
|
|
14
|
+
t: "Top",
|
|
15
|
+
r: "Right",
|
|
16
|
+
l: "Left",
|
|
17
|
+
b: "Bottom",
|
|
18
|
+
tl: "TopLeft",
|
|
19
|
+
tr: "TopRight",
|
|
20
|
+
bl: "BottomLeft",
|
|
21
|
+
br: "BottomRight",
|
|
22
|
+
};
|
|
23
|
+
export const Widths = {
|
|
24
|
+
"1/4": "25%",
|
|
25
|
+
"1/2": "50%",
|
|
26
|
+
"3/4": "75%",
|
|
27
|
+
full: "100%",
|
|
28
|
+
};
|
package/build/dom/css/core.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Side, Size, Sizes } from "./constants.js";
|
|
2
|
-
export declare function isSide(v: string): v is Side;
|
|
3
|
-
export declare function isSize(v: string): v is Size;
|
|
4
|
-
export declare function getSize(size: keyof typeof Sizes): string;
|
|
5
|
-
export declare function getSide(side: Side): string[];
|
|
1
|
+
import { Side, Size, Sizes } from "./constants.js";
|
|
2
|
+
export declare function isSide(v: string): v is Side;
|
|
3
|
+
export declare function isSize(v: string): v is Size;
|
|
4
|
+
export declare function getSize(size: keyof typeof Sizes): string;
|
|
5
|
+
export declare function getSide(side: Side): string[];
|
package/build/dom/css/core.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { Sides, Sizes } from "./constants.js";
|
|
2
|
-
export function isSide(v) {
|
|
3
|
-
return Sides[v] !== undefined;
|
|
4
|
-
}
|
|
5
|
-
export function isSize(v) {
|
|
6
|
-
return Sizes[v] !== undefined;
|
|
7
|
-
}
|
|
8
|
-
export function getSize(size) {
|
|
9
|
-
return Sizes[size];
|
|
10
|
-
}
|
|
11
|
-
export function getSide(side) {
|
|
12
|
-
switch (side) {
|
|
13
|
-
case "t":
|
|
14
|
-
return [...getSide("tl"), ...getSide("tr")];
|
|
15
|
-
case "r":
|
|
16
|
-
return [...getSide("tr"), ...getSide("br")];
|
|
17
|
-
case "b":
|
|
18
|
-
return [...getSide("br"), ...getSide("bl")];
|
|
19
|
-
case "l":
|
|
20
|
-
return [...getSide("tl"), ...getSide("bl")];
|
|
21
|
-
default:
|
|
22
|
-
return [Sides[side]];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
import { Sides, Sizes } from "./constants.js";
|
|
2
|
+
export function isSide(v) {
|
|
3
|
+
return Sides[v] !== undefined;
|
|
4
|
+
}
|
|
5
|
+
export function isSize(v) {
|
|
6
|
+
return Sizes[v] !== undefined;
|
|
7
|
+
}
|
|
8
|
+
export function getSize(size) {
|
|
9
|
+
return Sizes[size];
|
|
10
|
+
}
|
|
11
|
+
export function getSide(side) {
|
|
12
|
+
switch (side) {
|
|
13
|
+
case "t":
|
|
14
|
+
return [...getSide("tl"), ...getSide("tr")];
|
|
15
|
+
case "r":
|
|
16
|
+
return [...getSide("tr"), ...getSide("br")];
|
|
17
|
+
case "b":
|
|
18
|
+
return [...getSide("br"), ...getSide("bl")];
|
|
19
|
+
case "l":
|
|
20
|
+
return [...getSide("tl"), ...getSide("bl")];
|
|
21
|
+
default:
|
|
22
|
+
return [Sides[side]];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Properties } from "../types/css.js";
|
|
2
|
-
export declare type FStyle = Properties | {
|
|
3
|
-
[k: string]: FStyle;
|
|
4
|
-
};
|
|
5
|
-
export declare function compileFStyle(fstyle: FStyle, prefix?: string): string;
|
|
1
|
+
import { Properties } from "../types/css.js";
|
|
2
|
+
export declare type FStyle = Properties | {
|
|
3
|
+
[k: string]: FStyle;
|
|
4
|
+
};
|
|
5
|
+
export declare function compileFStyle(fstyle: FStyle, prefix?: string): string;
|
package/build/dom/css/fstyle.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { dashCase } from "../../case.js";
|
|
2
|
-
export function compileFStyle(fstyle, prefix = "") {
|
|
3
|
-
const properties = [];
|
|
4
|
-
const rules = [];
|
|
5
|
-
for (const [key, value] of Object.entries(fstyle)) {
|
|
6
|
-
if (typeof value == "string") {
|
|
7
|
-
properties.push({ key, value });
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
rules.push({ key, value });
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
let rule = "";
|
|
14
|
-
if (properties.length > 0) {
|
|
15
|
-
rule += `${prefix} {\n`;
|
|
16
|
-
for (const { key, value } of properties) {
|
|
17
|
-
rule += ` ${dashCase(key)}: ${value};\n`;
|
|
18
|
-
}
|
|
19
|
-
rule += "}\n\n";
|
|
20
|
-
}
|
|
21
|
-
for (const { key, value } of rules) {
|
|
22
|
-
if (key.startsWith("@media")) {
|
|
23
|
-
rule += `${key} {\n`;
|
|
24
|
-
rule += compileFStyle(value, " ");
|
|
25
|
-
rule += `}\n\n`;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
rule += compileFStyle(value, `${prefix} ${key}`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return rule;
|
|
32
|
-
}
|
|
1
|
+
import { dashCase } from "../../case.js";
|
|
2
|
+
export function compileFStyle(fstyle, prefix = "") {
|
|
3
|
+
const properties = [];
|
|
4
|
+
const rules = [];
|
|
5
|
+
for (const [key, value] of Object.entries(fstyle)) {
|
|
6
|
+
if (typeof value == "string") {
|
|
7
|
+
properties.push({ key, value });
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
rules.push({ key, value });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
let rule = "";
|
|
14
|
+
if (properties.length > 0) {
|
|
15
|
+
rule += `${prefix} {\n`;
|
|
16
|
+
for (const { key, value } of properties) {
|
|
17
|
+
rule += ` ${dashCase(key)}: ${value};\n`;
|
|
18
|
+
}
|
|
19
|
+
rule += "}\n\n";
|
|
20
|
+
}
|
|
21
|
+
for (const { key, value } of rules) {
|
|
22
|
+
if (key.startsWith("@media")) {
|
|
23
|
+
rule += `${key} {\n`;
|
|
24
|
+
rule += compileFStyle(value, " ");
|
|
25
|
+
rule += `}\n\n`;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
rule += compileFStyle(value, `${prefix} ${key}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return rule;
|
|
32
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Width } from "./constants.js";
|
|
2
|
-
export declare function width(amount: Width, block?: "inline"): {
|
|
3
|
-
width: string;
|
|
4
|
-
display?: string | undefined;
|
|
5
|
-
};
|
|
1
|
+
import { Width } from "./constants.js";
|
|
2
|
+
export declare function width(amount: Width, block?: "inline"): {
|
|
3
|
+
width: string;
|
|
4
|
+
display?: string | undefined;
|
|
5
|
+
};
|
package/build/dom/css/sizing.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Widths } from "./constants.js";
|
|
2
|
-
export function width(amount, block) {
|
|
3
|
-
if (amount === undefined && Widths[block] !== undefined) {
|
|
4
|
-
amount = block;
|
|
5
|
-
}
|
|
6
|
-
return {
|
|
7
|
-
...(block === "inline" ? { display: "inline-block" } : {}),
|
|
8
|
-
width: Widths[amount] ?? "0",
|
|
9
|
-
};
|
|
10
|
-
}
|
|
1
|
+
import { Widths } from "./constants.js";
|
|
2
|
+
export function width(amount, block) {
|
|
3
|
+
if (amount === undefined && Widths[block] !== undefined) {
|
|
4
|
+
amount = block;
|
|
5
|
+
}
|
|
6
|
+
return {
|
|
7
|
+
...(block === "inline" ? { display: "inline-block" } : {}),
|
|
8
|
+
width: Widths[amount] ?? "0",
|
|
9
|
+
};
|
|
10
|
+
}
|
package/build/dom/dom.d.ts
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare const Events: unique symbol;
|
|
3
|
-
export declare const CLEAR: unique symbol;
|
|
4
|
-
export declare type EventHandler = EventListenerOrEventListenerObject;
|
|
5
|
-
export declare type DenormChildren = Node | string | typeof CLEAR;
|
|
6
|
-
export declare type DOMElement = Element & DocumentAndElementEventHandlers & ElementCSSInlineStyle;
|
|
7
|
-
export declare type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
export declare type
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
[
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export declare
|
|
24
|
-
export declare function
|
|
25
|
-
export declare function
|
|
26
|
-
export
|
|
27
|
-
export {};
|
|
1
|
+
import { Properties } from "./types/css.js";
|
|
2
|
+
declare const Events: unique symbol;
|
|
3
|
+
export declare const CLEAR: unique symbol;
|
|
4
|
+
export declare type EventHandler = EventListenerOrEventListenerObject;
|
|
5
|
+
export declare type DenormChildren = Node | string | typeof CLEAR;
|
|
6
|
+
export declare type DOMElement = Element & DocumentAndElementEventHandlers & ElementCSSInlineStyle;
|
|
7
|
+
export declare type DomAttrs = {
|
|
8
|
+
class: string;
|
|
9
|
+
style: Partial<Properties> | string;
|
|
10
|
+
role: "button" | "list";
|
|
11
|
+
events: Partial<{
|
|
12
|
+
[K in keyof HTMLElementEventMap]: EventHandler;
|
|
13
|
+
}>;
|
|
14
|
+
};
|
|
15
|
+
export declare type Attrs<E extends Omit<Element, "update">, S = {}> = Partial<Omit<E, "style"> & S & DomAttrs>;
|
|
16
|
+
export declare type DenormAttrs<E extends Omit<Element, "update">, S = {}> = Attrs<E, S> | DenormChildren;
|
|
17
|
+
declare global {
|
|
18
|
+
interface Element {
|
|
19
|
+
[Events]: Map<string, EventHandler>;
|
|
20
|
+
update(attrs?: DenormAttrs<Element>, ...children: DenormChildren[]): this;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export declare function normalizeArguments<E extends Element>(attrs?: DenormAttrs<E>, children?: DenormChildren[], defaultAttrs?: Attrs<E>): [Attrs<E>, DenormChildren[]];
|
|
24
|
+
export declare function up<E extends Element>(element: Omit<E, "update">, attrs?: DenormAttrs<E>, ...children: DenormChildren[]): E;
|
|
25
|
+
export declare function update(element: Omit<Element, "update">, attrs: Attrs<Element>, children: DenormChildren[]): Element;
|
|
26
|
+
export {};
|
package/build/dom/dom.js
CHANGED
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
const Events = Symbol("events");
|
|
2
|
-
export const CLEAR = Symbol("Clear children");
|
|
3
|
-
function isAttrs(attrs) {
|
|
4
|
-
if (!attrs) {
|
|
5
|
-
return false;
|
|
6
|
-
}
|
|
7
|
-
if (typeof attrs === "string") {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
return !attrs.nodeType;
|
|
11
|
-
}
|
|
12
|
-
export function normalizeArguments(attrs, children = [], defaultAttrs = {}) {
|
|
13
|
-
let attributes;
|
|
14
|
-
if (isAttrs(attrs)) {
|
|
15
|
-
attributes = attrs;
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
if (attrs !== undefined) {
|
|
19
|
-
children.unshift(attrs);
|
|
20
|
-
}
|
|
21
|
-
attributes = defaultAttrs;
|
|
22
|
-
}
|
|
23
|
-
return [attributes, children.flat()];
|
|
24
|
-
}
|
|
25
|
-
export function up(element, attrs, ...children) {
|
|
26
|
-
return update(element, ...normalizeArguments(attrs, children));
|
|
27
|
-
}
|
|
28
|
-
export function update(element, attrs, children) {
|
|
29
|
-
// Track events, to remove later
|
|
30
|
-
const $events = (element[Events] ??= new Map());
|
|
31
|
-
const { style = {}, events = {}, ...rest } = attrs;
|
|
32
|
-
Object.entries(events).forEach(([k, v]) => {
|
|
33
|
-
if (v === null && $events.has(k)) {
|
|
34
|
-
const listener = $events.get(k);
|
|
35
|
-
element.removeEventListener(k, listener);
|
|
36
|
-
}
|
|
37
|
-
else if (!$events.has(k)) {
|
|
38
|
-
element.addEventListener(k, v);
|
|
39
|
-
$events.set(k, v);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
const _style = element.style;
|
|
43
|
-
if (_style) {
|
|
44
|
-
if (typeof style === "string") {
|
|
45
|
-
_style.cssText = style;
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
Object.entries(style).forEach(([k, v]) => {
|
|
49
|
-
// @ts-ignore Object.entries is unable to statically look into args
|
|
50
|
-
_style[k] = v;
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
Object.entries(rest).forEach(([k, v]) => {
|
|
55
|
-
if (k === "class" && typeof v === "string") {
|
|
56
|
-
v.split(/\s+/m)
|
|
57
|
-
.filter((s) => s !== "")
|
|
58
|
-
.forEach((c) => element.classList.add(c));
|
|
59
|
-
}
|
|
60
|
-
let useAttributes = k.startsWith("aria-") ||
|
|
61
|
-
k == "role" ||
|
|
62
|
-
element.namespaceURI != "http://www.w3.org/1999/xhtml";
|
|
63
|
-
if (useAttributes) {
|
|
64
|
-
switch (v) {
|
|
65
|
-
case false:
|
|
66
|
-
element.removeAttributeNS(element.namespaceURI, k);
|
|
67
|
-
break;
|
|
68
|
-
case true:
|
|
69
|
-
element.setAttributeNS(element.namespaceURI, k, k);
|
|
70
|
-
break;
|
|
71
|
-
default:
|
|
72
|
-
if (v === "") {
|
|
73
|
-
element.removeAttributeNS(element.namespaceURI, k);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
element.setAttributeNS(element.namespaceURI, k, v);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
// @ts-ignore Object.entries is unable to statically look into args
|
|
82
|
-
element[k] = v;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
if (children?.length > 0) {
|
|
86
|
-
if (children[0] === CLEAR) {
|
|
87
|
-
element.replaceChildren();
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
element.replaceChildren(...children);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
element.update ??= (attrs, ...children) => update(element, ...normalizeArguments(attrs, children));
|
|
94
|
-
return element;
|
|
95
|
-
}
|
|
1
|
+
const Events = Symbol("events");
|
|
2
|
+
export const CLEAR = Symbol("Clear children");
|
|
3
|
+
function isAttrs(attrs) {
|
|
4
|
+
if (!attrs) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
if (typeof attrs === "string") {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
return !attrs.nodeType;
|
|
11
|
+
}
|
|
12
|
+
export function normalizeArguments(attrs, children = [], defaultAttrs = {}) {
|
|
13
|
+
let attributes;
|
|
14
|
+
if (isAttrs(attrs)) {
|
|
15
|
+
attributes = attrs;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
if (attrs !== undefined) {
|
|
19
|
+
children.unshift(attrs);
|
|
20
|
+
}
|
|
21
|
+
attributes = defaultAttrs;
|
|
22
|
+
}
|
|
23
|
+
return [attributes, children.flat()];
|
|
24
|
+
}
|
|
25
|
+
export function up(element, attrs, ...children) {
|
|
26
|
+
return update(element, ...normalizeArguments(attrs, children));
|
|
27
|
+
}
|
|
28
|
+
export function update(element, attrs, children) {
|
|
29
|
+
// Track events, to remove later
|
|
30
|
+
const $events = (element[Events] ??= new Map());
|
|
31
|
+
const { style = {}, events = {}, ...rest } = attrs;
|
|
32
|
+
Object.entries(events).forEach(([k, v]) => {
|
|
33
|
+
if (v === null && $events.has(k)) {
|
|
34
|
+
const listener = $events.get(k);
|
|
35
|
+
element.removeEventListener(k, listener);
|
|
36
|
+
}
|
|
37
|
+
else if (!$events.has(k)) {
|
|
38
|
+
element.addEventListener(k, v);
|
|
39
|
+
$events.set(k, v);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
const _style = element.style;
|
|
43
|
+
if (_style) {
|
|
44
|
+
if (typeof style === "string") {
|
|
45
|
+
_style.cssText = style;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
Object.entries(style).forEach(([k, v]) => {
|
|
49
|
+
// @ts-ignore Object.entries is unable to statically look into args
|
|
50
|
+
_style[k] = v;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
Object.entries(rest).forEach(([k, v]) => {
|
|
55
|
+
if (k === "class" && typeof v === "string") {
|
|
56
|
+
v.split(/\s+/m)
|
|
57
|
+
.filter((s) => s !== "")
|
|
58
|
+
.forEach((c) => element.classList.add(c));
|
|
59
|
+
}
|
|
60
|
+
let useAttributes = k.startsWith("aria-") ||
|
|
61
|
+
k == "role" ||
|
|
62
|
+
element.namespaceURI != "http://www.w3.org/1999/xhtml";
|
|
63
|
+
if (useAttributes) {
|
|
64
|
+
switch (v) {
|
|
65
|
+
case false:
|
|
66
|
+
element.removeAttributeNS(element.namespaceURI, k);
|
|
67
|
+
break;
|
|
68
|
+
case true:
|
|
69
|
+
element.setAttributeNS(element.namespaceURI, k, k);
|
|
70
|
+
break;
|
|
71
|
+
default:
|
|
72
|
+
if (v === "") {
|
|
73
|
+
element.removeAttributeNS(element.namespaceURI, k);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
element.setAttributeNS(element.namespaceURI, k, v);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
// @ts-ignore Object.entries is unable to statically look into args
|
|
82
|
+
element[k] = v;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
if (children?.length > 0) {
|
|
86
|
+
if (children[0] === CLEAR) {
|
|
87
|
+
element.replaceChildren();
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
element.replaceChildren(...children);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
element.update ??= (attrs, ...children) => update(element, ...normalizeArguments(attrs, children));
|
|
94
|
+
return element;
|
|
95
|
+
}
|
package/build/dom/fc.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { DenormChildren, DomAttrs
|
|
2
|
-
export declare type Attrs<S> = S & Partial<DomAttrs>;
|
|
3
|
-
export declare const State: unique symbol;
|
|
4
|
-
export interface FCComponent<P extends object, S extends object> extends
|
|
5
|
-
[State]
|
|
6
|
-
update(attrs?: Partial<Attrs<P
|
|
7
|
-
}
|
|
8
|
-
export interface RenderFn<P extends object, S extends object> {
|
|
9
|
-
(el: FCComponent<P, S>, attrs: Attrs<P>, children: DenormChildren[]):
|
|
10
|
-
}
|
|
11
|
-
export interface FCComponentCtor<P extends object, S extends object> {
|
|
12
|
-
(attrs?: Attrs<P> | DenormChildren, ...children: DenormChildren[]): FCComponent<P, S>;
|
|
13
|
-
}
|
|
14
|
-
export declare function FC<P extends object, S extends object = {}>(name: string, component: RenderFn<P, S>): FCComponentCtor<P, S>;
|
|
1
|
+
import { DenormChildren, DomAttrs } from "./dom.js";
|
|
2
|
+
export declare type Attrs<S> = S & Partial<DomAttrs>;
|
|
3
|
+
export declare const State: unique symbol;
|
|
4
|
+
export interface FCComponent<P extends object, S extends object> extends Element {
|
|
5
|
+
[State]?: Partial<S>;
|
|
6
|
+
update(attrs?: Partial<Attrs<P> & DomAttrs> | DenormChildren, ...children: DenormChildren[]): this;
|
|
7
|
+
}
|
|
8
|
+
export interface RenderFn<P extends object, S extends object> {
|
|
9
|
+
(el: FCComponent<P, S>, attrs: Attrs<P>, children: DenormChildren[]): Element | Element[];
|
|
10
|
+
}
|
|
11
|
+
export interface FCComponentCtor<P extends object, S extends object> {
|
|
12
|
+
(attrs?: Attrs<P> | DenormChildren, ...children: DenormChildren[]): FCComponent<P, S>;
|
|
13
|
+
}
|
|
14
|
+
export declare function FC<P extends object, S extends object = {}>(name: string, component: RenderFn<P, S>): FCComponentCtor<P, S>;
|
package/build/dom/fc.js
CHANGED
|
@@ -1,35 +1,36 @@
|
|
|
1
|
-
import { CLEAR, normalizeArguments, update, } from "./dom.js";
|
|
2
|
-
export const State = Symbol();
|
|
3
|
-
export function FC(name, component) {
|
|
4
|
-
class FCImpl extends HTMLElement {
|
|
5
|
-
constructor() {
|
|
6
|
-
super();
|
|
7
|
-
}
|
|
8
|
-
[State] = {};
|
|
9
|
-
#attrs = {};
|
|
10
|
-
#children = [];
|
|
11
|
-
update(attrs, ...children) {
|
|
12
|
-
[attrs, children] = normalizeArguments(attrs, children);
|
|
13
|
-
if (children[0] === CLEAR) {
|
|
14
|
-
this.#children = [];
|
|
15
|
-
}
|
|
16
|
-
else if (children.length > 0) {
|
|
17
|
-
this.#children = children;
|
|
18
|
-
}
|
|
19
|
-
this.#attrs = { ...this.#attrs, ...attrs };
|
|
20
|
-
// Apply updates from the attrs to the dom node itself
|
|
21
|
-
// @ts-ignore
|
|
22
|
-
update(this, this.#attrs, []);
|
|
23
|
-
// Re-run the component function using new element, attrs, and children.
|
|
24
|
-
const replace = [component(this, this.#attrs, this.#children)];
|
|
25
|
-
this.replaceChildren(...replace.flat());
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
element.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
import { CLEAR, normalizeArguments, update, } from "./dom.js";
|
|
2
|
+
export const State = Symbol();
|
|
3
|
+
export function FC(name, component) {
|
|
4
|
+
class FCImpl extends HTMLElement {
|
|
5
|
+
constructor() {
|
|
6
|
+
super();
|
|
7
|
+
}
|
|
8
|
+
[State] = {};
|
|
9
|
+
#attrs = {};
|
|
10
|
+
#children = [];
|
|
11
|
+
update(attrs, ...children) {
|
|
12
|
+
[attrs, children] = normalizeArguments(attrs, children);
|
|
13
|
+
if (children[0] === CLEAR) {
|
|
14
|
+
this.#children = [];
|
|
15
|
+
}
|
|
16
|
+
else if (children.length > 0) {
|
|
17
|
+
this.#children = children;
|
|
18
|
+
}
|
|
19
|
+
this.#attrs = { ...this.#attrs, ...attrs };
|
|
20
|
+
// Apply updates from the attrs to the dom node itself
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
update(this, this.#attrs, []);
|
|
23
|
+
// Re-run the component function using new element, attrs, and children.
|
|
24
|
+
const replace = [component(this, this.#attrs, this.#children)];
|
|
25
|
+
this.replaceChildren(...replace.flat());
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
customElements.define(name, FCImpl);
|
|
30
|
+
const ctor = (attrs, ...children) => {
|
|
31
|
+
const element = document.createElement(name);
|
|
32
|
+
element.update(attrs, ...children);
|
|
33
|
+
return element;
|
|
34
|
+
};
|
|
35
|
+
return ctor;
|
|
36
|
+
}
|
package/build/dom/fc.test.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/build/dom/fc.test.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { describe, it, expect } from "../scope/index.js";
|
|
2
|
-
import { FC } from "./fc.js";
|
|
3
|
-
import { button, div, form, input, label, small } from "./html.js";
|
|
4
|
-
describe("FC", () => {
|
|
5
|
-
it("creates FCs", () => {
|
|
6
|
-
const Input = FC("fc-input", (el, attrs, children) => label(attrs.placeholder ?? attrs.name, input(attrs), ...children));
|
|
7
|
-
const f = form({ action: "#", method: "POST" }, div({ class: "grid" }, Input({
|
|
8
|
-
name: "firstName",
|
|
9
|
-
placeholder: "First Name",
|
|
10
|
-
required: true,
|
|
11
|
-
}), Input({
|
|
12
|
-
name: "lastName",
|
|
13
|
-
placeholder: "Last Name",
|
|
14
|
-
required: true,
|
|
15
|
-
})), Input({ name: "email", type: "email", placeholder: "E-Mail" }, small("We'll never share your information.")), button({ type: "submit" }, "Submit"));
|
|
16
|
-
// document.body.appendChild(f);
|
|
17
|
-
expect(f.children.length).toBe(3);
|
|
18
|
-
expect(f.querySelectorAll("input[required]").length).toBe(2);
|
|
19
|
-
expect(f.querySelectorAll('input[name="firstName"]').length).toBe(1);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
1
|
+
import { describe, it, expect } from "../scope/index.js";
|
|
2
|
+
import { FC } from "./fc.js";
|
|
3
|
+
import { button, div, form, input, label, small } from "./html.js";
|
|
4
|
+
describe("FC", () => {
|
|
5
|
+
it("creates FCs", () => {
|
|
6
|
+
const Input = FC("fc-input", (el, attrs, children) => label(attrs.placeholder ?? attrs.name, input(attrs), ...children));
|
|
7
|
+
const f = form({ action: "#", method: "POST" }, div({ class: "grid" }, Input({
|
|
8
|
+
name: "firstName",
|
|
9
|
+
placeholder: "First Name",
|
|
10
|
+
required: true,
|
|
11
|
+
}), Input({
|
|
12
|
+
name: "lastName",
|
|
13
|
+
placeholder: "Last Name",
|
|
14
|
+
required: true,
|
|
15
|
+
})), Input({ name: "email", type: "email", placeholder: "E-Mail" }, small("We'll never share your information.")), button({ type: "submit" }, "Submit"));
|
|
16
|
+
// document.body.appendChild(f);
|
|
17
|
+
expect(f.children.length).toBe(3);
|
|
18
|
+
expect(f.querySelectorAll("input[required]").length).toBe(2);
|
|
19
|
+
expect(f.querySelectorAll('input[name="firstName"]').length).toBe(1);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const App: () =>
|
|
1
|
+
export declare const App: () => HTMLElement;
|