effect-start 0.19.0 → 0.20.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/README.md +3 -3
- package/dist/Development.d.ts +3 -3
- package/dist/Development.js +3 -2
- package/dist/Effectify.d.ts +212 -0
- package/dist/Effectify.js +19 -0
- package/dist/FilePathPattern.d.ts +29 -0
- package/dist/FilePathPattern.js +86 -0
- package/dist/FileRouter.d.ts +39 -41
- package/dist/FileRouter.js +104 -158
- package/dist/FileRouterCodegen.d.ts +7 -8
- package/dist/FileRouterCodegen.js +97 -66
- package/dist/PlatformError.d.ts +46 -0
- package/dist/PlatformError.js +43 -0
- package/dist/PlatformRuntime.d.ts +23 -0
- package/dist/PlatformRuntime.js +42 -0
- package/dist/RouteBody.d.ts +1 -1
- package/dist/Start.d.ts +34 -3
- package/dist/Start.js +31 -6
- package/dist/bun/BunPlatformHttpServer.d.ts +10 -0
- package/dist/bun/BunPlatformHttpServer.js +53 -0
- package/dist/bun/BunRoute.d.ts +3 -5
- package/dist/bun/BunRoute.js +9 -17
- package/dist/bun/BunRuntime.d.ts +2 -1
- package/dist/bun/BunRuntime.js +10 -5
- package/dist/bun/BunServer.d.ts +33 -0
- package/dist/bun/BunServer.js +133 -0
- package/dist/bun/BunServerRequest.d.ts +60 -0
- package/dist/bun/BunServerRequest.js +252 -0
- package/dist/bun/index.d.ts +1 -1
- package/dist/bun/index.js +1 -1
- package/dist/datastar/actions/fetch.d.ts +30 -0
- package/dist/datastar/actions/fetch.js +411 -0
- package/dist/datastar/actions/peek.d.ts +1 -0
- package/dist/datastar/actions/peek.js +14 -0
- package/dist/datastar/actions/setAll.d.ts +1 -0
- package/dist/datastar/actions/setAll.js +13 -0
- package/dist/datastar/actions/toggleAll.d.ts +1 -0
- package/dist/datastar/actions/toggleAll.js +13 -0
- package/dist/datastar/attributes/attr.d.ts +1 -0
- package/dist/datastar/attributes/attr.js +49 -0
- package/dist/datastar/attributes/bind.d.ts +1 -0
- package/dist/datastar/attributes/bind.js +183 -0
- package/dist/datastar/attributes/class.d.ts +1 -0
- package/dist/datastar/attributes/class.js +50 -0
- package/dist/datastar/attributes/computed.d.ts +1 -0
- package/dist/datastar/attributes/computed.js +27 -0
- package/dist/datastar/attributes/effect.d.ts +1 -0
- package/dist/datastar/attributes/effect.js +10 -0
- package/dist/datastar/attributes/indicator.d.ts +1 -0
- package/dist/datastar/attributes/indicator.js +32 -0
- package/dist/datastar/attributes/init.d.ts +1 -0
- package/dist/datastar/attributes/init.js +27 -0
- package/dist/datastar/attributes/jsonSignals.d.ts +1 -0
- package/dist/datastar/attributes/jsonSignals.js +31 -0
- package/dist/datastar/attributes/on.d.ts +1 -0
- package/dist/datastar/attributes/on.js +59 -0
- package/dist/datastar/attributes/onIntersect.d.ts +1 -0
- package/dist/datastar/attributes/onIntersect.js +54 -0
- package/dist/datastar/attributes/onInterval.d.ts +1 -0
- package/dist/datastar/attributes/onInterval.js +31 -0
- package/dist/datastar/attributes/onSignalPatch.d.ts +1 -0
- package/dist/datastar/attributes/onSignalPatch.js +44 -0
- package/dist/datastar/attributes/ref.d.ts +1 -0
- package/dist/datastar/attributes/ref.js +11 -0
- package/dist/datastar/attributes/show.d.ts +1 -0
- package/dist/datastar/attributes/show.js +32 -0
- package/dist/datastar/attributes/signals.d.ts +1 -0
- package/dist/datastar/attributes/signals.js +18 -0
- package/dist/datastar/attributes/style.d.ts +1 -0
- package/dist/datastar/attributes/style.js +56 -0
- package/dist/datastar/attributes/text.d.ts +1 -0
- package/dist/datastar/attributes/text.js +27 -0
- package/dist/datastar/engine.d.ts +156 -0
- package/dist/datastar/engine.js +971 -0
- package/dist/datastar/index.d.ts +24 -0
- package/dist/datastar/index.js +24 -0
- package/dist/datastar/load.d.ts +24 -0
- package/dist/datastar/load.js +24 -0
- package/dist/datastar/utils.d.ts +51 -0
- package/dist/datastar/utils.js +205 -0
- package/dist/datastar/watchers/patchElements.d.ts +1 -0
- package/dist/datastar/watchers/patchElements.js +420 -0
- package/dist/datastar/watchers/patchSignals.d.ts +1 -0
- package/dist/datastar/watchers/patchSignals.js +15 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/node/NodeFileSystem.d.ts +7 -0
- package/dist/node/NodeFileSystem.js +420 -0
- package/dist/node/NodeUtils.d.ts +2 -0
- package/dist/node/NodeUtils.js +20 -0
- package/dist/x/tailwind/plugin.js +1 -1
- package/package.json +11 -7
- package/src/Development.ts +26 -25
- package/src/{node/Effectify.ts → Effectify.ts} +10 -3
- package/src/FilePathPattern.ts +115 -0
- package/src/FileRouter.ts +178 -255
- package/src/FileRouterCodegen.ts +135 -92
- package/src/{node/PlatformError.ts → PlatformError.ts} +34 -19
- package/src/PlatformRuntime.ts +97 -0
- package/src/RouteBody.ts +1 -1
- package/src/RouteHttp.ts +3 -1
- package/src/Start.ts +62 -14
- package/src/bun/BunPlatformHttpServer.ts +88 -0
- package/src/bun/BunRoute.ts +12 -22
- package/src/bun/BunRuntime.ts +21 -5
- package/src/bun/BunServer.ts +228 -0
- package/src/bun/index.ts +1 -1
- package/src/datastar/README.md +18 -0
- package/src/datastar/actions/fetch.ts +609 -0
- package/src/datastar/actions/peek.ts +17 -0
- package/src/datastar/actions/setAll.ts +20 -0
- package/src/datastar/actions/toggleAll.ts +20 -0
- package/src/datastar/attributes/attr.ts +50 -0
- package/src/datastar/attributes/bind.ts +220 -0
- package/src/datastar/attributes/class.ts +57 -0
- package/src/datastar/attributes/computed.ts +33 -0
- package/src/datastar/attributes/effect.ts +11 -0
- package/src/datastar/attributes/indicator.ts +39 -0
- package/src/datastar/attributes/init.ts +35 -0
- package/src/datastar/attributes/jsonSignals.ts +38 -0
- package/src/datastar/attributes/on.ts +71 -0
- package/src/datastar/attributes/onIntersect.ts +65 -0
- package/src/datastar/attributes/onInterval.ts +39 -0
- package/src/datastar/attributes/onSignalPatch.ts +63 -0
- package/src/datastar/attributes/ref.ts +12 -0
- package/src/datastar/attributes/show.ts +33 -0
- package/src/datastar/attributes/signals.ts +22 -0
- package/src/datastar/attributes/style.ts +63 -0
- package/src/datastar/attributes/text.ts +30 -0
- package/src/datastar/engine.ts +1341 -0
- package/src/datastar/index.ts +25 -0
- package/src/datastar/utils.ts +286 -0
- package/src/datastar/watchers/patchElements.ts +554 -0
- package/src/datastar/watchers/patchSignals.ts +15 -0
- package/src/index.ts +1 -1
- package/src/node/{FileSystem.ts → NodeFileSystem.ts} +2 -2
- package/src/node/{Utils.ts → NodeUtils.ts} +2 -0
- package/src/x/tailwind/plugin.ts +1 -1
- package/src/FileRouterCodegen.todo.ts +0 -1133
- package/src/FileRouterPattern.ts +0 -59
- package/src/RouterPattern.ts +0 -416
- package/src/StartApp.ts +0 -47
- package/src/bun/BunHttpServer.ts +0 -303
- /package/src/bun/{BunHttpServer_web.ts → BunServerRequest.ts} +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export * from "./engine.ts";
|
|
2
|
+
import "./actions/peek.ts";
|
|
3
|
+
import "./actions/setAll.ts";
|
|
4
|
+
import "./actions/toggleAll.ts";
|
|
5
|
+
import "./actions/fetch.ts";
|
|
6
|
+
import "./attributes/attr.ts";
|
|
7
|
+
import "./attributes/bind.ts";
|
|
8
|
+
import "./attributes/class.ts";
|
|
9
|
+
import "./attributes/computed.ts";
|
|
10
|
+
import "./attributes/effect.ts";
|
|
11
|
+
import "./attributes/indicator.ts";
|
|
12
|
+
import "./attributes/init.ts";
|
|
13
|
+
import "./attributes/jsonSignals.ts";
|
|
14
|
+
import "./attributes/on.ts";
|
|
15
|
+
import "./attributes/onIntersect.ts";
|
|
16
|
+
import "./attributes/onInterval.ts";
|
|
17
|
+
import "./attributes/onSignalPatch.ts";
|
|
18
|
+
import "./attributes/ref.ts";
|
|
19
|
+
import "./attributes/show.ts";
|
|
20
|
+
import "./attributes/signals.ts";
|
|
21
|
+
import "./attributes/style.ts";
|
|
22
|
+
import "./attributes/text.ts";
|
|
23
|
+
import "./watchers/patchElements.ts";
|
|
24
|
+
import "./watchers/patchSignals.ts";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export * from "./engine.js";
|
|
2
|
+
import "./actions/peek.js";
|
|
3
|
+
import "./actions/setAll.js";
|
|
4
|
+
import "./actions/toggleAll.js";
|
|
5
|
+
import "./actions/fetch.js";
|
|
6
|
+
import "./attributes/attr.js";
|
|
7
|
+
import "./attributes/bind.js";
|
|
8
|
+
import "./attributes/class.js";
|
|
9
|
+
import "./attributes/computed.js";
|
|
10
|
+
import "./attributes/effect.js";
|
|
11
|
+
import "./attributes/indicator.js";
|
|
12
|
+
import "./attributes/init.js";
|
|
13
|
+
import "./attributes/jsonSignals.js";
|
|
14
|
+
import "./attributes/on.js";
|
|
15
|
+
import "./attributes/onIntersect.js";
|
|
16
|
+
import "./attributes/onInterval.js";
|
|
17
|
+
import "./attributes/onSignalPatch.js";
|
|
18
|
+
import "./attributes/ref.js";
|
|
19
|
+
import "./attributes/show.js";
|
|
20
|
+
import "./attributes/signals.js";
|
|
21
|
+
import "./attributes/style.js";
|
|
22
|
+
import "./attributes/text.js";
|
|
23
|
+
import "./watchers/patchElements.js";
|
|
24
|
+
import "./watchers/patchSignals.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export * from "./engine.ts";
|
|
2
|
+
import "./actions/peek.ts";
|
|
3
|
+
import "./actions/setAll.ts";
|
|
4
|
+
import "./actions/toggleAll.ts";
|
|
5
|
+
import "./actions/fetch.ts";
|
|
6
|
+
import "./attributes/attr.ts";
|
|
7
|
+
import "./attributes/bind.ts";
|
|
8
|
+
import "./attributes/class.ts";
|
|
9
|
+
import "./attributes/computed.ts";
|
|
10
|
+
import "./attributes/effect.ts";
|
|
11
|
+
import "./attributes/indicator.ts";
|
|
12
|
+
import "./attributes/init.ts";
|
|
13
|
+
import "./attributes/jsonSignals.ts";
|
|
14
|
+
import "./attributes/on.ts";
|
|
15
|
+
import "./attributes/onIntersect.ts";
|
|
16
|
+
import "./attributes/onInterval.ts";
|
|
17
|
+
import "./attributes/onSignalPatch.ts";
|
|
18
|
+
import "./attributes/ref.ts";
|
|
19
|
+
import "./attributes/show.ts";
|
|
20
|
+
import "./attributes/signals.ts";
|
|
21
|
+
import "./attributes/style.ts";
|
|
22
|
+
import "./attributes/text.ts";
|
|
23
|
+
import "./watchers/patchElements.ts";
|
|
24
|
+
import "./watchers/patchSignals.ts";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export * from "./engine.js";
|
|
2
|
+
import "./actions/peek.js";
|
|
3
|
+
import "./actions/setAll.js";
|
|
4
|
+
import "./actions/toggleAll.js";
|
|
5
|
+
import "./actions/fetch.js";
|
|
6
|
+
import "./attributes/attr.js";
|
|
7
|
+
import "./attributes/bind.js";
|
|
8
|
+
import "./attributes/class.js";
|
|
9
|
+
import "./attributes/computed.js";
|
|
10
|
+
import "./attributes/effect.js";
|
|
11
|
+
import "./attributes/indicator.js";
|
|
12
|
+
import "./attributes/init.js";
|
|
13
|
+
import "./attributes/jsonSignals.js";
|
|
14
|
+
import "./attributes/on.js";
|
|
15
|
+
import "./attributes/onIntersect.js";
|
|
16
|
+
import "./attributes/onInterval.js";
|
|
17
|
+
import "./attributes/onSignalPatch.js";
|
|
18
|
+
import "./attributes/ref.js";
|
|
19
|
+
import "./attributes/show.js";
|
|
20
|
+
import "./attributes/signals.js";
|
|
21
|
+
import "./attributes/style.js";
|
|
22
|
+
import "./attributes/text.js";
|
|
23
|
+
import "./watchers/patchElements.js";
|
|
24
|
+
import "./watchers/patchSignals.js";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { EventCallbackHandler, HTMLOrSVG, Modifiers, Paths } from "./engine.ts";
|
|
2
|
+
/*********
|
|
3
|
+
* dom.ts
|
|
4
|
+
*********/
|
|
5
|
+
export declare const isHTMLOrSVG: (el: Node) => el is HTMLOrSVG;
|
|
6
|
+
/*********
|
|
7
|
+
* math.ts
|
|
8
|
+
*********/
|
|
9
|
+
export declare const clamp: (value: number, min: number, max: number) => number;
|
|
10
|
+
export declare const lerp: (min: number, max: number, t: number, clamped?: boolean) => number;
|
|
11
|
+
export declare const inverseLerp: (min: number, max: number, value: number, clamped?: boolean) => number;
|
|
12
|
+
export declare const fit: (value: number, inMin: number, inMax: number, outMin: number, outMax: number, clamped?: boolean, rounded?: boolean) => number;
|
|
13
|
+
/*********
|
|
14
|
+
* text.ts
|
|
15
|
+
*********/
|
|
16
|
+
export declare const kebab: (str: string) => string;
|
|
17
|
+
export declare const camel: (str: string) => string;
|
|
18
|
+
export declare const snake: (str: string) => string;
|
|
19
|
+
export declare const pascal: (str: string) => string;
|
|
20
|
+
export declare const title: (str: string) => string;
|
|
21
|
+
export declare const jsStrToObject: (raw: string) => any;
|
|
22
|
+
export declare const modifyCasing: (str: string, mods: Modifiers, defaultCase?: string) => string;
|
|
23
|
+
export declare const aliasify: (name: string) => string;
|
|
24
|
+
/*********
|
|
25
|
+
* tags.ts
|
|
26
|
+
*********/
|
|
27
|
+
export declare const tagToMs: (args: Set<string>) => number;
|
|
28
|
+
export declare const tagHas: (tags: Set<string>, tag: string, defaultValue?: boolean) => boolean;
|
|
29
|
+
export declare const tagFirst: (tags?: Set<string>, defaultValue?: string) => string;
|
|
30
|
+
/*********
|
|
31
|
+
* polyfills.ts
|
|
32
|
+
*********/
|
|
33
|
+
export declare const hasOwn: (obj: object, prop: PropertyKey) => boolean;
|
|
34
|
+
/*********
|
|
35
|
+
* paths.ts
|
|
36
|
+
*********/
|
|
37
|
+
export declare const isPojo: (obj: any) => obj is Record<string, any>;
|
|
38
|
+
export declare const isEmpty: (obj: Record<string, any>) => boolean;
|
|
39
|
+
export declare const updateLeaves: (obj: Record<string, any>, fn: (oldValue: any) => any) => void;
|
|
40
|
+
export declare const pathToObj: (paths: Paths) => Record<string, any>;
|
|
41
|
+
/*********
|
|
42
|
+
* timing.ts
|
|
43
|
+
*********/
|
|
44
|
+
export declare const delay: (callback: EventCallbackHandler, wait: number) => EventCallbackHandler;
|
|
45
|
+
export declare const throttle: (callback: EventCallbackHandler, wait: number, leading?: boolean, trailing?: boolean, debounce?: boolean) => EventCallbackHandler;
|
|
46
|
+
export declare const modifyTiming: (callback: EventCallbackHandler, mods: Modifiers) => EventCallbackHandler;
|
|
47
|
+
/*********
|
|
48
|
+
* view-transitions.ts
|
|
49
|
+
*********/
|
|
50
|
+
export declare const supportsViewTransitions = true;
|
|
51
|
+
export declare const modifyViewTransition: (callback: EventCallbackHandler, mods: Modifiers) => EventCallbackHandler;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/*********
|
|
2
|
+
* dom.ts
|
|
3
|
+
*********/
|
|
4
|
+
export const isHTMLOrSVG = (el) => el instanceof HTMLElement
|
|
5
|
+
|| el instanceof SVGElement
|
|
6
|
+
|| el instanceof MathMLElement;
|
|
7
|
+
/*********
|
|
8
|
+
* math.ts
|
|
9
|
+
*********/
|
|
10
|
+
export const clamp = (value, min, max) => {
|
|
11
|
+
return Math.max(min, Math.min(max, value));
|
|
12
|
+
};
|
|
13
|
+
export const lerp = (min, max, t, clamped = true) => {
|
|
14
|
+
const v = min + (max - min) * t;
|
|
15
|
+
return clamped ? clamp(v, min, max) : v;
|
|
16
|
+
};
|
|
17
|
+
export const inverseLerp = (min, max, value, clamped = true) => {
|
|
18
|
+
if (value < min)
|
|
19
|
+
return 0;
|
|
20
|
+
if (value > max)
|
|
21
|
+
return 1;
|
|
22
|
+
const v = (value - min) / (max - min);
|
|
23
|
+
return clamped ? clamp(v, min, max) : v;
|
|
24
|
+
};
|
|
25
|
+
export const fit = (value, inMin, inMax, outMin, outMax, clamped = true, rounded = false) => {
|
|
26
|
+
const t = inverseLerp(inMin, inMax, value, clamped);
|
|
27
|
+
const fitted = lerp(outMin, outMax, t, clamped);
|
|
28
|
+
return rounded ? Math.round(fitted) : fitted;
|
|
29
|
+
};
|
|
30
|
+
/*********
|
|
31
|
+
* text.ts
|
|
32
|
+
*********/
|
|
33
|
+
export const kebab = (str) => str
|
|
34
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1-$2")
|
|
35
|
+
.replace(/([a-z])([0-9]+)/gi, "$1-$2")
|
|
36
|
+
.replace(/([0-9]+)([a-z])/gi, "$1-$2")
|
|
37
|
+
.replace(/[\s_]+/g, "-")
|
|
38
|
+
.toLowerCase();
|
|
39
|
+
export const camel = (str) => kebab(str).replace(/-./g, (x) => x[1].toUpperCase());
|
|
40
|
+
export const snake = (str) => kebab(str).replace(/-/g, "_");
|
|
41
|
+
export const pascal = (str) => camel(str).replace(/(^.|(?<=\.).)/g, (x) => x[0].toUpperCase());
|
|
42
|
+
export const title = (str) => str.replace(/\b\w/g, (char) => char.toUpperCase());
|
|
43
|
+
export const jsStrToObject = (raw) => {
|
|
44
|
+
try {
|
|
45
|
+
return JSON.parse(raw);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return Function(`return (${raw})`)();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const caseFns = {
|
|
52
|
+
camel: (str) => str.replace(/-[a-z]/g, (x) => x[1].toUpperCase()),
|
|
53
|
+
snake: (str) => str.replace(/-/g, "_"),
|
|
54
|
+
pascal: (str) => str[0].toUpperCase() + caseFns.camel(str.slice(1)),
|
|
55
|
+
};
|
|
56
|
+
export const modifyCasing = (str, mods, defaultCase = "camel") => {
|
|
57
|
+
for (const c of mods.get("case") || [defaultCase]) {
|
|
58
|
+
str = caseFns[c]?.(str) || str;
|
|
59
|
+
}
|
|
60
|
+
return str;
|
|
61
|
+
};
|
|
62
|
+
export const aliasify = (name) => `data-${name}`;
|
|
63
|
+
/*********
|
|
64
|
+
* tags.ts
|
|
65
|
+
*********/
|
|
66
|
+
export const tagToMs = (args) => {
|
|
67
|
+
if (!args || args.size <= 0)
|
|
68
|
+
return 0;
|
|
69
|
+
for (const arg of args) {
|
|
70
|
+
if (arg.endsWith("ms")) {
|
|
71
|
+
return +arg.replace("ms", "");
|
|
72
|
+
}
|
|
73
|
+
if (arg.endsWith("s")) {
|
|
74
|
+
return +arg.replace("s", "") * 1000;
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
return Number.parseFloat(arg);
|
|
78
|
+
}
|
|
79
|
+
catch (_) { }
|
|
80
|
+
}
|
|
81
|
+
return 0;
|
|
82
|
+
};
|
|
83
|
+
export const tagHas = (tags, tag, defaultValue = false) => {
|
|
84
|
+
if (!tags)
|
|
85
|
+
return defaultValue;
|
|
86
|
+
return tags.has(tag.toLowerCase());
|
|
87
|
+
};
|
|
88
|
+
export const tagFirst = (tags, defaultValue = "") => {
|
|
89
|
+
if (tags && tags.size > 0) {
|
|
90
|
+
for (const tag of tags) {
|
|
91
|
+
return tag;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return defaultValue;
|
|
95
|
+
};
|
|
96
|
+
/*********
|
|
97
|
+
* polyfills.ts
|
|
98
|
+
*********/
|
|
99
|
+
export const hasOwn =
|
|
100
|
+
// @ts-ignore
|
|
101
|
+
Object.hasOwn ?? Object.prototype.hasOwnProperty.call;
|
|
102
|
+
/*********
|
|
103
|
+
* paths.ts
|
|
104
|
+
*********/
|
|
105
|
+
export const isPojo = (obj) => obj !== null
|
|
106
|
+
&& typeof obj === "object"
|
|
107
|
+
&& (Object.getPrototypeOf(obj) === Object.prototype
|
|
108
|
+
|| Object.getPrototypeOf(obj) === null);
|
|
109
|
+
export const isEmpty = (obj) => {
|
|
110
|
+
for (const prop in obj) {
|
|
111
|
+
if (hasOwn(obj, prop)) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
};
|
|
117
|
+
export const updateLeaves = (obj, fn) => {
|
|
118
|
+
for (const key in obj) {
|
|
119
|
+
const val = obj[key];
|
|
120
|
+
if (isPojo(val) || Array.isArray(val)) {
|
|
121
|
+
updateLeaves(val, fn);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
obj[key] = fn(val);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
export const pathToObj = (paths) => {
|
|
129
|
+
const result = {};
|
|
130
|
+
for (const [path, value] of paths) {
|
|
131
|
+
const keys = path.split(".");
|
|
132
|
+
const lastKey = keys.pop();
|
|
133
|
+
const obj = keys.reduce((acc, key) => (acc[key] ??= {}), result);
|
|
134
|
+
obj[lastKey] = value;
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
};
|
|
138
|
+
/*********
|
|
139
|
+
* timing.ts
|
|
140
|
+
*********/
|
|
141
|
+
export const delay = (callback, wait) => {
|
|
142
|
+
return (...args) => {
|
|
143
|
+
setTimeout(() => {
|
|
144
|
+
callback(...args);
|
|
145
|
+
}, wait);
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
export const throttle = (callback, wait, leading = true, trailing = false, debounce = false) => {
|
|
149
|
+
let lastArgs = null;
|
|
150
|
+
let timer = 0;
|
|
151
|
+
return (...args) => {
|
|
152
|
+
if (leading && !timer) {
|
|
153
|
+
callback(...args);
|
|
154
|
+
lastArgs = null;
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
lastArgs = args;
|
|
158
|
+
}
|
|
159
|
+
if (!timer || debounce) {
|
|
160
|
+
if (timer) {
|
|
161
|
+
clearTimeout(timer);
|
|
162
|
+
}
|
|
163
|
+
timer = setTimeout(() => {
|
|
164
|
+
if (trailing && lastArgs !== null) {
|
|
165
|
+
callback(...lastArgs);
|
|
166
|
+
}
|
|
167
|
+
lastArgs = null;
|
|
168
|
+
timer = 0;
|
|
169
|
+
}, wait);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
export const modifyTiming = (callback, mods) => {
|
|
174
|
+
const delayArgs = mods.get("delay");
|
|
175
|
+
if (delayArgs) {
|
|
176
|
+
const wait = tagToMs(delayArgs);
|
|
177
|
+
callback = delay(callback, wait);
|
|
178
|
+
}
|
|
179
|
+
const debounceArgs = mods.get("debounce");
|
|
180
|
+
if (debounceArgs) {
|
|
181
|
+
const wait = tagToMs(debounceArgs);
|
|
182
|
+
const leading = tagHas(debounceArgs, "leading", false);
|
|
183
|
+
const trailing = !tagHas(debounceArgs, "notrailing", false);
|
|
184
|
+
callback = throttle(callback, wait, leading, trailing, true);
|
|
185
|
+
}
|
|
186
|
+
const throttleArgs = mods.get("throttle");
|
|
187
|
+
if (throttleArgs) {
|
|
188
|
+
const wait = tagToMs(throttleArgs);
|
|
189
|
+
const leading = !tagHas(throttleArgs, "noleading", false);
|
|
190
|
+
const trailing = tagHas(throttleArgs, "trailing", false);
|
|
191
|
+
callback = throttle(callback, wait, leading, trailing);
|
|
192
|
+
}
|
|
193
|
+
return callback;
|
|
194
|
+
};
|
|
195
|
+
/*********
|
|
196
|
+
* view-transitions.ts
|
|
197
|
+
*********/
|
|
198
|
+
export const supportsViewTransitions = !!document.startViewTransition;
|
|
199
|
+
export const modifyViewTransition = (callback, mods) => {
|
|
200
|
+
if (mods.has("viewtransition") && supportsViewTransitions) {
|
|
201
|
+
const cb = callback;
|
|
202
|
+
callback = (...args) => document.startViewTransition(() => cb(...args));
|
|
203
|
+
}
|
|
204
|
+
return callback;
|
|
205
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|