@e280/sly 0.2.4 → 0.3.0-1
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/LICENSE +1 -1
- package/README.md +302 -614
- package/package.json +6 -8
- package/s/_archive/README.md +1221 -0
- package/s/{base → _archive/base}/element.ts +5 -2
- package/s/_archive/view/index.ts +7 -0
- package/s/_archive/view/types.ts +45 -0
- package/s/{view → _archive/view}/utils/parts/capsule.ts +9 -2
- package/s/demo/demo.bundle.ts +2 -9
- package/s/demo/views/counter-light.ts +13 -0
- package/s/demo/views/counter-shadow.ts +16 -0
- package/s/demo/views/demo.ts +24 -18
- package/s/demo/views/loaders.ts +7 -7
- package/s/index.html.ts +30 -33
- package/s/index.ts +0 -2
- package/s/loaders/make.ts +1 -1
- package/s/loaders/parts/ascii-anim.ts +6 -8
- package/s/loaders/parts/error-display.ts +9 -9
- package/s/tests.test.ts +1 -4
- package/s/view/common/css-reset.ts +19 -0
- package/s/view/hooks/plumbing/hooks.ts +28 -0
- package/s/view/hooks/plumbing/hookscope.ts +12 -0
- package/s/view/hooks/use-css.ts +14 -0
- package/s/view/hooks/use-cx.ts +41 -0
- package/s/view/hooks/use-life.ts +17 -0
- package/s/view/hooks/use-mount.ts +30 -0
- package/s/view/hooks/use-name.ts +10 -0
- package/s/view/hooks/use-once.ts +9 -0
- package/s/view/hooks/use-op.ts +12 -0
- package/s/view/hooks/use-ref.ts +11 -0
- package/s/view/hooks/use-signal.ts +16 -0
- package/s/view/hooks/use-state.ts +20 -0
- package/s/view/hooks/use-wake.ts +8 -0
- package/s/view/index.ts +17 -4
- package/s/view/light.ts +50 -0
- package/s/view/parts/apply-attrs.ts +22 -0
- package/s/view/parts/apply-styles.ts +21 -0
- package/s/view/parts/cx.ts +26 -0
- package/s/view/parts/reactivity.ts +22 -0
- package/s/view/parts/sly-shadow.ts +8 -0
- package/s/view/shadow.ts +93 -0
- package/s/view/types.ts +15 -34
- package/x/demo/demo.bundle.js +2 -8
- package/x/demo/demo.bundle.js.map +1 -1
- package/x/demo/demo.bundle.min.js +45 -58
- package/x/demo/demo.bundle.min.js.map +4 -4
- package/x/demo/views/counter-light.d.ts +1 -0
- package/x/demo/views/counter-light.js +10 -0
- package/x/demo/views/counter-light.js.map +1 -0
- package/x/demo/views/counter-shadow.d.ts +1 -0
- package/x/demo/views/counter-shadow.js +12 -0
- package/x/demo/views/counter-shadow.js.map +1 -0
- package/x/demo/views/demo.d.ts +1 -4
- package/x/demo/views/demo.js +23 -18
- package/x/demo/views/demo.js.map +1 -1
- package/x/demo/views/loaders.d.ts +1 -1
- package/x/demo/views/loaders.js +7 -7
- package/x/demo/views/loaders.js.map +1 -1
- package/x/index.d.ts +0 -2
- package/x/index.html +30 -140
- package/x/index.html.js +31 -31
- package/x/index.html.js.map +1 -1
- package/x/index.js +0 -2
- package/x/index.js.map +1 -1
- package/x/loaders/make.d.ts +1 -1
- package/x/loaders/parts/ascii-anim.d.ts +1 -1
- package/x/loaders/parts/ascii-anim.js +6 -7
- package/x/loaders/parts/ascii-anim.js.map +1 -1
- package/x/loaders/parts/error-display.d.ts +1 -1
- package/x/loaders/parts/error-display.js +9 -9
- package/x/loaders/parts/error-display.js.map +1 -1
- package/x/tests.test.js +1 -4
- package/x/tests.test.js.map +1 -1
- package/x/view/common/css-reset.js +17 -0
- package/x/view/common/css-reset.js.map +1 -0
- package/x/view/hooks/plumbing/hooks.d.ts +11 -0
- package/x/view/hooks/plumbing/hooks.js +26 -0
- package/x/view/hooks/plumbing/hooks.js.map +1 -0
- package/x/view/hooks/plumbing/hookscope.d.ts +10 -0
- package/x/view/hooks/plumbing/hookscope.js +12 -0
- package/x/view/hooks/plumbing/hookscope.js.map +1 -0
- package/x/view/hooks/use-css.d.ts +4 -0
- package/x/view/hooks/use-css.js +10 -0
- package/x/view/hooks/use-css.js.map +1 -0
- package/x/view/hooks/use-cx.d.ts +10 -0
- package/x/view/hooks/use-cx.js +33 -0
- package/x/view/hooks/use-cx.js.map +1 -0
- package/x/view/hooks/use-life.d.ts +2 -0
- package/x/view/hooks/use-life.js +13 -0
- package/x/view/hooks/use-life.js.map +1 -0
- package/x/{base/utils/mounts.d.ts → view/hooks/use-mount.d.ts} +1 -0
- package/x/{base/utils/mounts.js → view/hooks/use-mount.js} +7 -1
- package/x/view/hooks/use-mount.js.map +1 -0
- package/x/view/hooks/use-name.d.ts +2 -0
- package/x/view/hooks/use-name.js +8 -0
- package/x/view/hooks/use-name.js.map +1 -0
- package/x/view/hooks/use-once.d.ts +2 -0
- package/x/view/hooks/use-once.js +7 -0
- package/x/view/hooks/use-once.js.map +1 -0
- package/x/view/hooks/use-op.d.ts +3 -0
- package/x/view/hooks/use-op.js +9 -0
- package/x/view/hooks/use-op.js.map +1 -0
- package/x/view/hooks/use-ref.d.ts +5 -0
- package/x/view/hooks/use-ref.js +11 -0
- package/x/view/hooks/use-ref.js.map +1 -0
- package/x/view/hooks/use-signal.d.ts +3 -0
- package/x/view/hooks/use-signal.js +12 -0
- package/x/view/hooks/use-signal.js.map +1 -0
- package/x/view/hooks/use-state.d.ts +1 -0
- package/x/view/hooks/use-state.js +17 -0
- package/x/view/hooks/use-state.js.map +1 -0
- package/x/view/hooks/use-wake.d.ts +2 -0
- package/x/view/hooks/use-wake.js +6 -0
- package/x/view/hooks/use-wake.js.map +1 -0
- package/x/view/index.d.ts +15 -4
- package/x/view/index.js +15 -4
- package/x/view/index.js.map +1 -1
- package/x/view/light.d.ts +2 -0
- package/x/view/light.js +41 -0
- package/x/view/light.js.map +1 -0
- package/x/view/parts/apply-attrs.d.ts +2 -0
- package/x/view/parts/apply-attrs.js +22 -0
- package/x/view/parts/apply-attrs.js.map +1 -0
- package/x/{base/utils → view/parts}/apply-styles.js.map +1 -1
- package/x/view/parts/cx.d.ts +12 -0
- package/x/view/parts/cx.js +24 -0
- package/x/view/parts/cx.js.map +1 -0
- package/x/view/parts/reactivity.d.ts +5 -0
- package/x/view/parts/reactivity.js +18 -0
- package/x/view/parts/reactivity.js.map +1 -0
- package/x/view/parts/sly-shadow.d.ts +3 -0
- package/x/view/parts/sly-shadow.js +7 -0
- package/x/view/parts/sly-shadow.js.map +1 -0
- package/x/view/shadow.d.ts +6 -0
- package/x/view/shadow.js +72 -0
- package/x/view/shadow.js.map +1 -0
- package/x/view/types.d.ts +13 -21
- package/s/demo/views/counter.ts +0 -50
- package/s/demo/views/fastcount.ts +0 -29
- package/x/base/css-reset.js +0 -19
- package/x/base/css-reset.js.map +0 -1
- package/x/base/element.d.ts +0 -19
- package/x/base/element.js +0 -52
- package/x/base/element.js.map +0 -1
- package/x/base/index.d.ts +0 -5
- package/x/base/index.js +0 -6
- package/x/base/index.js.map +0 -1
- package/x/base/types.d.ts +0 -3
- package/x/base/types.js +0 -3
- package/x/base/types.js.map +0 -1
- package/x/base/use.d.ts +0 -59
- package/x/base/use.js +0 -129
- package/x/base/use.js.map +0 -1
- package/x/base/utils/attr-watcher.d.ts +0 -8
- package/x/base/utils/attr-watcher.js +0 -20
- package/x/base/utils/attr-watcher.js.map +0 -1
- package/x/base/utils/mounts.js.map +0 -1
- package/x/base/utils/reactor.d.ts +0 -5
- package/x/base/utils/reactor.js +0 -25
- package/x/base/utils/reactor.js.map +0 -1
- package/x/base/utils/states.d.ts +0 -13
- package/x/base/utils/states.js +0 -41
- package/x/base/utils/states.js.map +0 -1
- package/x/base/utils/use-attrs.d.ts +0 -11
- package/x/base/utils/use-attrs.js +0 -18
- package/x/base/utils/use-attrs.js.map +0 -1
- package/x/demo/views/counter.d.ts +0 -374
- package/x/demo/views/counter.js +0 -42
- package/x/demo/views/counter.js.map +0 -1
- package/x/demo/views/fastcount.d.ts +0 -12
- package/x/demo/views/fastcount.js +0 -21
- package/x/demo/views/fastcount.js.map +0 -1
- package/x/spa/index.barrel.d.ts +0 -4
- package/x/spa/index.barrel.js +0 -3
- package/x/spa/index.barrel.js.map +0 -1
- package/x/spa/index.d.ts +0 -2
- package/x/spa/index.js +0 -2
- package/x/spa/index.js.map +0 -1
- package/x/spa/plumbing/braces.d.ts +0 -12
- package/x/spa/plumbing/braces.js +0 -55
- package/x/spa/plumbing/braces.js.map +0 -1
- package/x/spa/plumbing/primitives.d.ts +0 -22
- package/x/spa/plumbing/primitives.js +0 -65
- package/x/spa/plumbing/primitives.js.map +0 -1
- package/x/spa/plumbing/router-core.d.ts +0 -13
- package/x/spa/plumbing/router-core.js +0 -38
- package/x/spa/plumbing/router-core.js.map +0 -1
- package/x/spa/plumbing/types.d.ts +0 -35
- package/x/spa/plumbing/types.js +0 -2
- package/x/spa/plumbing/types.js.map +0 -1
- package/x/spa/router.d.ts +0 -13
- package/x/spa/router.js +0 -39
- package/x/spa/router.js.map +0 -1
- package/x/spa/spa.test.d.ts +0 -15
- package/x/spa/spa.test.js +0 -78
- package/x/spa/spa.test.js.map +0 -1
- package/x/view/utils/contextualize.d.ts +0 -13
- package/x/view/utils/contextualize.js +0 -18
- package/x/view/utils/contextualize.js.map +0 -1
- package/x/view/utils/make-component.d.ts +0 -5
- package/x/view/utils/make-component.js +0 -17
- package/x/view/utils/make-component.js.map +0 -1
- package/x/view/utils/make-view.d.ts +0 -2
- package/x/view/utils/make-view.js +0 -32
- package/x/view/utils/make-view.js.map +0 -1
- package/x/view/utils/parts/capsule.d.ts +0 -12
- package/x/view/utils/parts/capsule.js +0 -50
- package/x/view/utils/parts/capsule.js.map +0 -1
- package/x/view/utils/parts/chain.d.ts +0 -13
- package/x/view/utils/parts/chain.js +0 -26
- package/x/view/utils/parts/chain.js.map +0 -1
- package/x/view/utils/parts/context.d.ts +0 -9
- package/x/view/utils/parts/context.js +0 -10
- package/x/view/utils/parts/context.js.map +0 -1
- package/x/view/utils/parts/directive.d.ts +0 -5
- package/x/view/utils/parts/directive.js +0 -20
- package/x/view/utils/parts/directive.js.map +0 -1
- package/x/view/utils/parts/naked.d.ts +0 -18
- package/x/view/utils/parts/naked.js +0 -57
- package/x/view/utils/parts/naked.js.map +0 -1
- package/x/view/utils/parts/sly-view.d.ts +0 -6
- package/x/view/utils/parts/sly-view.js +0 -16
- package/x/view/utils/parts/sly-view.js.map +0 -1
- package/x/view/view.d.ts +0 -11
- package/x/view/view.js +0 -15
- package/x/view/view.js.map +0 -1
- /package/s/{base → _archive/base}/css-reset.ts +0 -0
- /package/s/{base → _archive/base}/index.ts +0 -0
- /package/s/{base → _archive/base}/types.ts +0 -0
- /package/s/{base → _archive/base}/use.ts +0 -0
- /package/s/{base → _archive/base}/utils/apply-styles.ts +0 -0
- /package/s/{base → _archive/base}/utils/attr-watcher.ts +0 -0
- /package/s/{base → _archive/base}/utils/mounts.ts +0 -0
- /package/s/{base → _archive/base}/utils/reactor.ts +0 -0
- /package/s/{base → _archive/base}/utils/states.ts +0 -0
- /package/s/{base → _archive/base}/utils/use-attrs.ts +0 -0
- /package/s/{spa → _archive/spa}/index.barrel.ts +0 -0
- /package/s/{spa → _archive/spa}/index.ts +0 -0
- /package/s/{spa → _archive/spa}/plumbing/braces.ts +0 -0
- /package/s/{spa → _archive/spa}/plumbing/primitives.ts +0 -0
- /package/s/{spa → _archive/spa}/plumbing/router-core.ts +0 -0
- /package/s/{spa → _archive/spa}/plumbing/types.ts +0 -0
- /package/s/{spa → _archive/spa}/router.ts +0 -0
- /package/s/{spa → _archive/spa}/spa.test.ts +0 -0
- /package/s/{view → _archive/view}/utils/contextualize.ts +0 -0
- /package/s/{view → _archive/view}/utils/make-component.ts +0 -0
- /package/s/{view → _archive/view}/utils/make-view.ts +0 -0
- /package/s/{view → _archive/view}/utils/parts/chain.ts +0 -0
- /package/s/{view → _archive/view}/utils/parts/context.ts +0 -0
- /package/s/{view → _archive/view}/utils/parts/directive.ts +0 -0
- /package/s/{view → _archive/view}/utils/parts/naked.ts +0 -0
- /package/s/{view → _archive/view}/utils/parts/sly-view.ts +0 -0
- /package/s/{view → _archive/view}/view.ts +0 -0
- /package/x/{base → view/common}/css-reset.d.ts +0 -0
- /package/x/{base/utils → view/parts}/apply-styles.d.ts +0 -0
- /package/x/{base/utils → view/parts}/apply-styles.js +0 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** return the current count of how many times this view has been rendered (starts at 0) */
|
|
2
|
+
export declare function useCount(): number;
|
|
3
|
+
/** return a function that triggers the view to rerender */
|
|
4
|
+
export declare function useRender(): () => Promise<void>;
|
|
5
|
+
/** return a promise that resolves after the next render is complete */
|
|
6
|
+
export declare function useRendered(): Promise<void>;
|
|
7
|
+
/** return the shadow view's host element */
|
|
8
|
+
export declare function useHost(): HTMLElement;
|
|
9
|
+
/** return the shadow root */
|
|
10
|
+
export declare function useShadow(): ShadowRoot;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ShadowCx } from "../parts/cx.js";
|
|
2
|
+
import { hooks } from "./plumbing/hooks.js";
|
|
3
|
+
function useCx() {
|
|
4
|
+
const { scope } = hooks.increment();
|
|
5
|
+
return scope.cx;
|
|
6
|
+
}
|
|
7
|
+
function useShadowCx() {
|
|
8
|
+
const cx = useCx();
|
|
9
|
+
if (!(cx instanceof ShadowCx))
|
|
10
|
+
throw new Error("this hook only works on shadow views (but was called in a light view)");
|
|
11
|
+
return cx;
|
|
12
|
+
}
|
|
13
|
+
/** return the current count of how many times this view has been rendered (starts at 0) */
|
|
14
|
+
export function useCount() {
|
|
15
|
+
return useCx().count;
|
|
16
|
+
}
|
|
17
|
+
/** return a function that triggers the view to rerender */
|
|
18
|
+
export function useRender() {
|
|
19
|
+
return useCx().render;
|
|
20
|
+
}
|
|
21
|
+
/** return a promise that resolves after the next render is complete */
|
|
22
|
+
export function useRendered() {
|
|
23
|
+
return useCx().rendered.promise;
|
|
24
|
+
}
|
|
25
|
+
/** return the shadow view's host element */
|
|
26
|
+
export function useHost() {
|
|
27
|
+
return useShadowCx().host;
|
|
28
|
+
}
|
|
29
|
+
/** return the shadow root */
|
|
30
|
+
export function useShadow() {
|
|
31
|
+
return useShadowCx().shadow;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=use-cx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-cx.js","sourceRoot":"","sources":["../../../s/view/hooks/use-cx.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAC,KAAK,EAAC,MAAM,qBAAqB,CAAA;AAEzC,SAAS,KAAK;IACb,MAAM,EAAC,KAAK,EAAC,GAAG,KAAK,CAAC,SAAS,EAAE,CAAA;IACjC,OAAO,KAAK,CAAC,EAAE,CAAA;AAChB,CAAC;AAED,SAAS,WAAW;IACnB,MAAM,EAAE,GAAG,KAAK,EAAE,CAAA;IAClB,IAAI,CAAC,CAAC,EAAE,YAAY,QAAQ,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAA;IACzF,OAAO,EAAE,CAAA;AACV,CAAC;AAED,2FAA2F;AAC3F,MAAM,UAAU,QAAQ;IACvB,OAAO,KAAK,EAAE,CAAC,KAAK,CAAA;AACrB,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,SAAS;IACxB,OAAO,KAAK,EAAE,CAAC,MAAM,CAAA;AACtB,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,WAAW;IAC1B,OAAO,KAAK,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAA;AAChC,CAAC;AAED,4CAA4C;AAC5C,MAAM,UAAU,OAAO;IACtB,OAAO,WAAW,EAAE,CAAC,IAAI,CAAA;AAC1B,CAAC;AAED,6BAA6B;AAC7B,MAAM,UAAU,SAAS;IACxB,OAAO,WAAW,EAAE,CAAC,MAAM,CAAA;AAC5B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useRef } from "./use-ref.js";
|
|
2
|
+
import { useMount } from "./use-mount.js";
|
|
3
|
+
/** mount/unmount lifecycle, but also return a value */
|
|
4
|
+
export function useLife(fn) {
|
|
5
|
+
const ref = useRef(undefined);
|
|
6
|
+
useMount(() => {
|
|
7
|
+
const [value, dispose] = fn();
|
|
8
|
+
ref.value = value;
|
|
9
|
+
return dispose;
|
|
10
|
+
});
|
|
11
|
+
return ref.value;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=use-life.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-life.js","sourceRoot":"","sources":["../../../s/view/hooks/use-life.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAA;AACnC,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAA;AAEvC,uDAAuD;AACvD,MAAM,UAAU,OAAO,CAAQ,EAA6C;IAC3E,MAAM,GAAG,GAAG,MAAM,CAAQ,SAAkB,CAAC,CAAA;IAE7C,QAAQ,CAAC,GAAG,EAAE;QACb,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE,CAAA;QAC7B,GAAG,CAAC,KAAK,GAAG,KAAK,CAAA;QACjB,OAAO,OAAO,CAAA;IACf,CAAC,CAAC,CAAA;IAEF,OAAO,GAAG,CAAC,KAAK,CAAA;AACjB,CAAC"}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { useOnce } from "./use-once.js";
|
|
2
|
+
import { hooks } from "./plumbing/hooks.js";
|
|
3
|
+
export function useMount(fn) {
|
|
4
|
+
const { scope } = hooks.increment();
|
|
5
|
+
return useOnce(() => scope.mounts.mount(fn));
|
|
6
|
+
}
|
|
1
7
|
export class Mounts {
|
|
2
8
|
#mounters = [];
|
|
3
9
|
#unmounters = [];
|
|
@@ -15,4 +21,4 @@ export class Mounts {
|
|
|
15
21
|
this.#unmounters.push(mount());
|
|
16
22
|
}
|
|
17
23
|
}
|
|
18
|
-
//# sourceMappingURL=
|
|
24
|
+
//# sourceMappingURL=use-mount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-mount.js","sourceRoot":"","sources":["../../../s/view/hooks/use-mount.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAA;AACrC,OAAO,EAAC,KAAK,EAAC,MAAM,qBAAqB,CAAA;AAEzC,MAAM,UAAU,QAAQ,CAAC,EAAoB;IAC5C,MAAM,EAAC,KAAK,EAAC,GAAG,KAAK,CAAC,SAAS,EAAE,CAAA;IACjC,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAA;AAC7C,CAAC;AAED,MAAM,OAAO,MAAM;IAClB,SAAS,GAAyB,EAAE,CAAA;IACpC,WAAW,GAAmB,EAAE,CAAA;IAEhC,KAAK,CAAC,KAAuB;QAC5B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAC1B,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAA;IAC/B,CAAC;IAED,UAAU;QACT,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,WAAW;YACrC,OAAO,EAAE,CAAA;QACV,IAAI,CAAC,WAAW,GAAG,EAAE,CAAA;IACtB,CAAC;IAED,UAAU;QACT,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,SAAS;YACjC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAA;IAChC,CAAC;CACD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useHost } from "./use-cx.js";
|
|
2
|
+
import { useOnce } from "./use-once.js";
|
|
3
|
+
/** sets the host element's "data-view" attribute */
|
|
4
|
+
export function useName(name = "") {
|
|
5
|
+
const host = useHost();
|
|
6
|
+
useOnce(() => host.setAttribute("view", name));
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=use-name.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-name.js","sourceRoot":"","sources":["../../../s/view/hooks/use-name.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,aAAa,CAAA;AACnC,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAA;AAErC,oDAAoD;AACpD,MAAM,UAAU,OAAO,CAAC,IAAI,GAAG,EAAE;IAChC,MAAM,IAAI,GAAG,OAAO,EAAE,CAAA;IACtB,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAA;AAC/C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-once.js","sourceRoot":"","sources":["../../../s/view/hooks/use-once.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,EAAC,MAAM,qBAAqB,CAAA;AAEzC,+BAA+B;AAC/B,MAAM,UAAU,OAAO,CAAQ,EAAe;IAC7C,MAAM,EAAC,KAAK,EAAE,QAAQ,EAAC,GAAG,KAAK,CAAC,SAAS,EAAE,CAAA;IAC3C,OAAO,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,EAAE,CAAU,CAAA;AACrD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Op } from "../../ops/op.js";
|
|
2
|
+
import { useOnce } from "./use-once.js";
|
|
3
|
+
export function useOp(fn) {
|
|
4
|
+
return useOnce(() => Op.load(fn));
|
|
5
|
+
}
|
|
6
|
+
export function useOpPromise(promise) {
|
|
7
|
+
return useOnce(() => Op.promise(promise));
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=use-op.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-op.js","sourceRoot":"","sources":["../../../s/view/hooks/use-op.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,EAAE,EAAC,MAAM,iBAAiB,CAAA;AAClC,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAA;AAErC,MAAM,UAAU,KAAK,CAAQ,EAAwB;IACpD,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;AAClC,CAAC;AAED,MAAM,UAAU,YAAY,CAAQ,OAAuB;IAC1D,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;AAC1C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-ref.js","sourceRoot":"","sources":["../../../s/view/hooks/use-ref.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAA;AAErC,MAAM,UAAU,MAAM,CAAQ,KAAY;IACzC,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;AACrC,CAAC;AAED,MAAM,OAAO,GAAG;IACI;IAAnB,YAAmB,KAAY;QAAZ,UAAK,GAAL,KAAK,CAAO;IAAG,CAAC;CACnC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function useSignal<Value>(value: Value): import("@e280/strata").SignalFn<Value>;
|
|
2
|
+
export declare function useDerived<Value>(fn: () => Value): import("@e280/strata").DerivedFn<Value>;
|
|
3
|
+
export declare function useLazy<Value>(fn: () => Value): import("@e280/strata").LazyFn<Value>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { signal } from "@e280/strata";
|
|
2
|
+
import { useOnce } from "./use-once.js";
|
|
3
|
+
export function useSignal(value) {
|
|
4
|
+
return useOnce(() => signal(value));
|
|
5
|
+
}
|
|
6
|
+
export function useDerived(fn) {
|
|
7
|
+
return useOnce(() => signal.derived(fn));
|
|
8
|
+
}
|
|
9
|
+
export function useLazy(fn) {
|
|
10
|
+
return useOnce(() => signal.lazy(fn));
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=use-signal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-signal.js","sourceRoot":"","sources":["../../../s/view/hooks/use-signal.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAA;AACnC,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAA;AAErC,MAAM,UAAU,SAAS,CAAQ,KAAY;IAC5C,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;AACpC,CAAC;AAED,MAAM,UAAU,UAAU,CAAQ,EAAe;IAChD,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;AACzC,CAAC;AAED,MAAM,UAAU,OAAO,CAAQ,EAAe;IAC7C,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;AACtC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useState<Value>(value: Value): readonly [Value, (next: Value | ((prev: Value) => Value)) => void];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useRef } from "./use-ref.js";
|
|
2
|
+
import { useRender } from "./use-cx.js";
|
|
3
|
+
export function useState(value) {
|
|
4
|
+
const render = useRender();
|
|
5
|
+
const ref = useRef(value);
|
|
6
|
+
const set = (next) => {
|
|
7
|
+
const value = typeof next === "function"
|
|
8
|
+
? next(ref.value)
|
|
9
|
+
: next;
|
|
10
|
+
if (Object.is(value, ref.value))
|
|
11
|
+
return;
|
|
12
|
+
ref.value = value;
|
|
13
|
+
render();
|
|
14
|
+
};
|
|
15
|
+
return [ref.value, set];
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=use-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-state.js","sourceRoot":"","sources":["../../../s/view/hooks/use-state.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAA;AACnC,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAA;AAErC,MAAM,UAAU,QAAQ,CAAQ,KAAY;IAC3C,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAC1B,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;IAEzB,MAAM,GAAG,GAAG,CAAC,IAAsC,EAAE,EAAE;QACtD,MAAM,KAAK,GAAG,OAAO,IAAI,KAAK,UAAU;YACvC,CAAC,CAAE,IAA+B,CAAC,GAAG,CAAC,KAAK,CAAC;YAC7C,CAAC,CAAC,IAAI,CAAA;QACP,IAAI,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC;YAAE,OAAM;QACvC,GAAG,CAAC,KAAK,GAAG,KAAK,CAAA;QACjB,MAAM,EAAE,CAAA;IACT,CAAC,CAAA;IAED,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAU,CAAA;AACjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-wake.js","sourceRoot":"","sources":["../../../s/view/hooks/use-wake.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AAEtC,8CAA8C;AAC9C,MAAM,UAAU,OAAO,CAAQ,EAAe;IAC7C,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC,CAAA;AACvC,CAAC"}
|
package/x/view/index.d.ts
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
1
|
+
export * from "./common/css-reset.js";
|
|
2
|
+
export * from "./hooks/use-css.js";
|
|
3
|
+
export * from "./hooks/use-cx.js";
|
|
4
|
+
export * from "./hooks/use-life.js";
|
|
5
|
+
export * from "./hooks/use-mount.js";
|
|
6
|
+
export * from "./hooks/use-name.js";
|
|
7
|
+
export * from "./hooks/use-once.js";
|
|
8
|
+
export * from "./hooks/use-op.js";
|
|
9
|
+
export * from "./hooks/use-ref.js";
|
|
10
|
+
export * from "./hooks/use-signal.js";
|
|
11
|
+
export * from "./hooks/use-state.js";
|
|
12
|
+
export * from "./hooks/use-cx.js";
|
|
13
|
+
export * from "./hooks/use-wake.js";
|
|
14
|
+
export * from "./light.js";
|
|
15
|
+
export * from "./shadow.js";
|
|
4
16
|
export * from "./types.js";
|
|
5
|
-
export * from "./view.js";
|
package/x/view/index.js
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
1
|
+
export * from "./common/css-reset.js";
|
|
2
|
+
export * from "./hooks/use-css.js";
|
|
3
|
+
export * from "./hooks/use-cx.js";
|
|
4
|
+
export * from "./hooks/use-life.js";
|
|
5
|
+
export * from "./hooks/use-mount.js";
|
|
6
|
+
export * from "./hooks/use-name.js";
|
|
7
|
+
export * from "./hooks/use-once.js";
|
|
8
|
+
export * from "./hooks/use-op.js";
|
|
9
|
+
export * from "./hooks/use-ref.js";
|
|
10
|
+
export * from "./hooks/use-signal.js";
|
|
11
|
+
export * from "./hooks/use-state.js";
|
|
12
|
+
export * from "./hooks/use-cx.js";
|
|
13
|
+
export * from "./hooks/use-wake.js";
|
|
14
|
+
export * from "./light.js";
|
|
15
|
+
export * from "./shadow.js";
|
|
4
16
|
export * from "./types.js";
|
|
5
|
-
export * from "./view.js";
|
|
6
17
|
//# sourceMappingURL=index.js.map
|
package/x/view/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../s/view/index.ts"],"names":[],"mappings":"AACA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../s/view/index.ts"],"names":[],"mappings":"AACA,cAAc,uBAAuB,CAAA;AAErC,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AACpC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,sBAAsB,CAAA;AACpC,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AAEnC,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
|
package/x/view/light.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { microbounce } from "@e280/stz";
|
|
2
|
+
import { LightCx } from "./parts/cx.js";
|
|
3
|
+
import { hooks } from "./hooks/plumbing/hooks.js";
|
|
4
|
+
import { Reactivity } from "./parts/reactivity.js";
|
|
5
|
+
import { Hookscope } from "./hooks/plumbing/hookscope.js";
|
|
6
|
+
import { AsyncDirective, directive } from "lit/async-directive.js";
|
|
7
|
+
export function light(view) {
|
|
8
|
+
return directive(class D extends AsyncDirective {
|
|
9
|
+
#props;
|
|
10
|
+
#cx = new LightCx(microbounce(() => {
|
|
11
|
+
if (!this.#props)
|
|
12
|
+
throw new Error("cannot render before props");
|
|
13
|
+
if (this.isConnected) {
|
|
14
|
+
const content = this.render(...this.#props);
|
|
15
|
+
this.setValue(content);
|
|
16
|
+
this.#cx.doneRender();
|
|
17
|
+
}
|
|
18
|
+
}));
|
|
19
|
+
#hookscope = new Hookscope(this.#cx);
|
|
20
|
+
#reactivity = new Reactivity();
|
|
21
|
+
update(part, props) {
|
|
22
|
+
const ret = super.update(part, props);
|
|
23
|
+
if (this.isConnected)
|
|
24
|
+
this.#cx.doneRender();
|
|
25
|
+
return ret;
|
|
26
|
+
}
|
|
27
|
+
render(...props) {
|
|
28
|
+
this.#props = props;
|
|
29
|
+
return this.#reactivity.observe(() => hooks.wrap(this.#hookscope, () => view(...this.#props)), this.#cx.render);
|
|
30
|
+
}
|
|
31
|
+
disconnected() {
|
|
32
|
+
this.#hookscope.mounts.unmountAll();
|
|
33
|
+
this.#reactivity.clear();
|
|
34
|
+
}
|
|
35
|
+
reconnected() {
|
|
36
|
+
this.#hookscope.mounts.remountAll();
|
|
37
|
+
this.#cx.render();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=light.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"light.js","sourceRoot":"","sources":["../../s/view/light.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,WAAW,EAAC,MAAM,WAAW,CAAA;AAGrC,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAA;AACrC,OAAO,EAAC,KAAK,EAAC,MAAM,2BAA2B,CAAA;AAC/C,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAC,SAAS,EAAC,MAAM,+BAA+B,CAAA;AACvD,OAAO,EAAC,cAAc,EAAE,SAAS,EAAO,MAAM,wBAAwB,CAAA;AAEtE,MAAM,UAAU,KAAK,CAAsB,IAAiB;IAC3D,OAAO,SAAS,CAAC,MAAM,CAAE,SAAQ,cAAc;QAC9C,MAAM,CAAQ;QACd,GAAG,GAAG,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE;YAClC,IAAI,CAAC,IAAI,CAAC,MAAM;gBAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;YAC/D,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;gBACtB,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAA;gBAC3C,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;gBACtB,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,CAAA;YACtB,CAAC;QACF,CAAC,CAAC,CAAC,CAAA;QACH,UAAU,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACpC,WAAW,GAAG,IAAI,UAAU,EAAE,CAAA;QAE9B,MAAM,CAAC,IAAU,EAAE,KAAY;YAC9B,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;YACrC,IAAI,IAAI,CAAC,WAAW;gBAAE,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,CAAA;YAC3C,OAAO,GAAG,CAAA;QACX,CAAC;QAED,MAAM,CAAC,GAAG,KAAY;YACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;YACnB,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAC9B,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,EAC7D,IAAI,CAAC,GAAG,CAAC,MAAM,CACf,CAAA;QACF,CAAC;QAED,YAAY;YACX,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,CAAA;YACnC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAA;QACzB,CAAC;QAED,WAAW;YACV,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,CAAA;YACnC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAA;QAClB,CAAC;KACD,CAAgB,CAAA;AAClB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function applyAttrs(element, attrs) {
|
|
2
|
+
for (const [name, value] of Object.entries(attrs))
|
|
3
|
+
applyAttr(element, name, value);
|
|
4
|
+
}
|
|
5
|
+
function applyAttr(element, name, value) {
|
|
6
|
+
const existing = element.getAttribute(name);
|
|
7
|
+
const v = coerce(value);
|
|
8
|
+
if (v === existing)
|
|
9
|
+
return;
|
|
10
|
+
if (v === null)
|
|
11
|
+
element.removeAttribute(name);
|
|
12
|
+
else
|
|
13
|
+
element.setAttribute(name, v);
|
|
14
|
+
}
|
|
15
|
+
function coerce(value) {
|
|
16
|
+
if (typeof value === "string")
|
|
17
|
+
return value;
|
|
18
|
+
else if (typeof value === "number")
|
|
19
|
+
return value.toString();
|
|
20
|
+
return value ? "" : null;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=apply-attrs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-attrs.js","sourceRoot":"","sources":["../../../s/view/parts/apply-attrs.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,UAAU,CAAC,OAAoB,EAAE,KAAgB;IAChE,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;QAChD,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;AACjC,CAAC;AAED,SAAS,SAAS,CAAC,OAAoB,EAAE,IAAY,EAAE,KAAe;IACrE,MAAM,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA;IAC3C,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;IACvB,IAAI,CAAC,KAAK,QAAQ;QAAE,OAAM;IAC1B,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA;;QACxC,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;AACnC,CAAC;AAED,SAAS,MAAM,CAAC,KAAe;IAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;SACtC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAA;IAC3D,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;AACzB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply-styles.js","sourceRoot":"","sources":["../../../s/
|
|
1
|
+
{"version":3,"file":"apply-styles.js","sourceRoot":"","sources":["../../../s/view/parts/apply-styles.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,WAAW,EAAqC,kBAAkB,EAAC,MAAM,KAAK,CAAA;AAEtF,MAAM,UAAU,WAAW,CAAC,MAAkB,EAAE,MAAuB;IACtE,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAA;AAC3C,CAAC;AAED,SAAS,aAAa,CAAC,MAAuB;IAC7C,MAAM,aAAa,GAAG,EAAE,CAAA;IAExB,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAE,MAAyB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC,CAAA;QACxE,KAAK,MAAM,CAAC,IAAI,GAAG;YAClB,aAAa,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAsB,CAAC,CAAC,CAAA;IACnE,CAAC;SACI,IAAI,MAAM,KAAK,SAAS;QAC5B,aAAa,CAAC,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAA;IAE/C,OAAO,aAAa,CAAA;AACrB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class LightCx {
|
|
2
|
+
render: () => Promise<void>;
|
|
3
|
+
count: number;
|
|
4
|
+
rendered: import("@e280/stz").Deferred<void>;
|
|
5
|
+
constructor(render: () => Promise<void>);
|
|
6
|
+
doneRender(): void;
|
|
7
|
+
}
|
|
8
|
+
export declare class ShadowCx extends LightCx {
|
|
9
|
+
host: HTMLElement;
|
|
10
|
+
shadow: ShadowRoot;
|
|
11
|
+
constructor(render: () => Promise<void>, host: HTMLElement, shadow: ShadowRoot);
|
|
12
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defer } from "@e280/stz";
|
|
2
|
+
export class LightCx {
|
|
3
|
+
render;
|
|
4
|
+
count = 0;
|
|
5
|
+
rendered = defer();
|
|
6
|
+
constructor(render) {
|
|
7
|
+
this.render = render;
|
|
8
|
+
}
|
|
9
|
+
doneRender() {
|
|
10
|
+
this.count++;
|
|
11
|
+
this.rendered.resolve();
|
|
12
|
+
this.rendered = defer();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class ShadowCx extends LightCx {
|
|
16
|
+
host;
|
|
17
|
+
shadow;
|
|
18
|
+
constructor(render, host, shadow) {
|
|
19
|
+
super(render);
|
|
20
|
+
this.host = host;
|
|
21
|
+
this.shadow = shadow;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=cx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cx.js","sourceRoot":"","sources":["../../../s/view/parts/cx.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,EAAC,MAAM,WAAW,CAAA;AAE/B,MAAM,OAAO,OAAO;IAIA;IAHnB,KAAK,GAAG,CAAC,CAAA;IACT,QAAQ,GAAG,KAAK,EAAQ,CAAA;IAExB,YAAmB,MAA2B;QAA3B,WAAM,GAAN,MAAM,CAAqB;IAAG,CAAC;IAElD,UAAU;QACT,IAAI,CAAC,KAAK,EAAE,CAAA;QACZ,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAA;QACvB,IAAI,CAAC,QAAQ,GAAG,KAAK,EAAE,CAAA;IACxB,CAAC;CACD;AAED,MAAM,OAAO,QAAS,SAAQ,OAAO;IAG3B;IACA;IAHT,YACE,MAA2B,EACpB,IAAiB,EACjB,MAAkB;QAE1B,KAAK,CAAC,MAAM,CAAC,CAAA;QAHL,SAAI,GAAJ,IAAI,CAAa;QACjB,WAAM,GAAN,MAAM,CAAY;IAG3B,CAAC;CACD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { tracker } from "@e280/strata";
|
|
2
|
+
export class Reactivity {
|
|
3
|
+
#stoppers = [];
|
|
4
|
+
clear() {
|
|
5
|
+
this.#stoppers.forEach(stop => stop());
|
|
6
|
+
this.#stoppers = [];
|
|
7
|
+
}
|
|
8
|
+
observe(fn, rerender) {
|
|
9
|
+
const { seen, result } = tracker.observe(fn);
|
|
10
|
+
this.clear();
|
|
11
|
+
for (const item of seen) {
|
|
12
|
+
const stop = tracker.subscribe(item, rerender);
|
|
13
|
+
this.#stoppers.push(stop);
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=reactivity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactivity.js","sourceRoot":"","sources":["../../../s/view/parts/reactivity.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAA;AAEpC,MAAM,OAAO,UAAU;IACtB,SAAS,GAAmB,EAAE,CAAA;IAE9B,KAAK;QACJ,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAA;QACtC,IAAI,CAAC,SAAS,GAAG,EAAE,CAAA;IACpB,CAAC;IAED,OAAO,CAAI,EAAW,EAAE,QAA6B;QACpD,MAAM,EAAC,IAAI,EAAE,MAAM,EAAC,GAAG,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;QAC1C,IAAI,CAAC,KAAK,EAAE,CAAA;QACZ,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;YACzB,MAAM,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;YAC9C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC1B,CAAC;QACD,OAAO,MAAM,CAAA;IACd,CAAC;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sly-shadow.js","sourceRoot":"","sources":["../../../s/view/parts/sly-shadow.ts"],"names":[],"mappings":"AACA,MAAM,OAAO,SAAU,SAAQ,WAAW;IACzC,iBAAiB;QAChB,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC;YAC7B,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IAC/B,CAAC;CACD"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { View, ShadowSetup, ShadowView } from "./types.js";
|
|
2
|
+
export declare function shadow<Props extends any[]>(view: View<Props>): ShadowView<Props>;
|
|
3
|
+
export declare namespace shadow {
|
|
4
|
+
var config: (setupFn: () => ShadowSetup) => <Props extends any[]>(view: View<Props>) => ShadowView<Props>;
|
|
5
|
+
}
|
|
6
|
+
export declare function rawShadow<Props extends any[]>(setup: () => ShadowSetup, view: View<Props>): ShadowView<Props>;
|
package/x/view/shadow.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { microbounce } from "@e280/stz";
|
|
2
|
+
import { render as litRender } from "lit";
|
|
3
|
+
import { dom } from "../dom/dom.js";
|
|
4
|
+
import { ShadowCx } from "./parts/cx.js";
|
|
5
|
+
import { SlyShadow } from "./parts/sly-shadow.js";
|
|
6
|
+
import { hooks } from "./hooks/plumbing/hooks.js";
|
|
7
|
+
import { Reactivity } from "./parts/reactivity.js";
|
|
8
|
+
import { applyAttrs } from "./parts/apply-attrs.js";
|
|
9
|
+
import { Hookscope } from "./hooks/plumbing/hookscope.js";
|
|
10
|
+
import { AsyncDirective, directive } from "lit/async-directive.js";
|
|
11
|
+
export function shadow(view) {
|
|
12
|
+
const setupFn = () => {
|
|
13
|
+
dom.register({ SlyShadow }, { soft: true });
|
|
14
|
+
const host = document.createElement("sly-shadow");
|
|
15
|
+
const shadow = host.attachShadow({ mode: "open" });
|
|
16
|
+
return { host, shadow };
|
|
17
|
+
};
|
|
18
|
+
return rawShadow(setupFn, view);
|
|
19
|
+
}
|
|
20
|
+
shadow.config = (setupFn) => ((view) => (rawShadow(setupFn, view)));
|
|
21
|
+
export function rawShadow(setup, view) {
|
|
22
|
+
const directiveFn = directive(class extends AsyncDirective {
|
|
23
|
+
#cx;
|
|
24
|
+
#hookscope;
|
|
25
|
+
#props;
|
|
26
|
+
#reactivity = new Reactivity();
|
|
27
|
+
constructor(part) {
|
|
28
|
+
super(part);
|
|
29
|
+
const { host, shadow } = setup();
|
|
30
|
+
const rerender = microbounce(() => {
|
|
31
|
+
if (!this.#props)
|
|
32
|
+
throw new Error("cannot render before props");
|
|
33
|
+
if (!this.isConnected)
|
|
34
|
+
return;
|
|
35
|
+
const content = this.#renderContent(this.#props);
|
|
36
|
+
litRender(content, this.#cx.shadow);
|
|
37
|
+
this.#cx.doneRender();
|
|
38
|
+
});
|
|
39
|
+
this.#cx = new ShadowCx(rerender, host, shadow);
|
|
40
|
+
this.#hookscope = new Hookscope(this.#cx);
|
|
41
|
+
}
|
|
42
|
+
#renderContent(props) {
|
|
43
|
+
this.#props = props;
|
|
44
|
+
return this.#reactivity.observe(() => hooks.wrap(this.#hookscope, () => view(...this.#props)), this.#cx.render);
|
|
45
|
+
}
|
|
46
|
+
render({ props, children, attrs }) {
|
|
47
|
+
const { host } = this.#cx;
|
|
48
|
+
if (!this.isConnected)
|
|
49
|
+
return host;
|
|
50
|
+
if (attrs)
|
|
51
|
+
applyAttrs(host, attrs);
|
|
52
|
+
litRender(children, this.#cx.host);
|
|
53
|
+
litRender(this.#renderContent(props), this.#cx.shadow);
|
|
54
|
+
this.#cx.doneRender();
|
|
55
|
+
return host;
|
|
56
|
+
}
|
|
57
|
+
disconnected() {
|
|
58
|
+
this.#hookscope.mounts.unmountAll();
|
|
59
|
+
this.#reactivity.clear();
|
|
60
|
+
}
|
|
61
|
+
reconnected() {
|
|
62
|
+
this.#hookscope.mounts.remountAll();
|
|
63
|
+
this.#cx.render();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
function shadowView(...props) {
|
|
67
|
+
return directiveFn({ props });
|
|
68
|
+
}
|
|
69
|
+
shadowView.with = directiveFn;
|
|
70
|
+
return shadowView;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=shadow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shadow.js","sourceRoot":"","sources":["../../s/view/shadow.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,WAAW,EAAC,MAAM,WAAW,CAAA;AACrC,OAAO,EAAC,MAAM,IAAI,SAAS,EAAC,MAAM,KAAK,CAAA;AAEvC,OAAO,EAAC,GAAG,EAAC,MAAM,eAAe,CAAA;AACjC,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAA;AACtC,OAAO,EAAC,SAAS,EAAC,MAAM,uBAAuB,CAAA;AAC/C,OAAO,EAAC,KAAK,EAAC,MAAM,2BAA2B,CAAA;AAC/C,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAC,UAAU,EAAC,MAAM,wBAAwB,CAAA;AACjD,OAAO,EAAC,SAAS,EAAC,MAAM,+BAA+B,CAAA;AAEvD,OAAO,EAAC,cAAc,EAAE,SAAS,EAAW,MAAM,wBAAwB,CAAA;AAE1E,MAAM,UAAU,MAAM,CAAsB,IAAiB;IAC5D,MAAM,OAAO,GAAG,GAAgB,EAAE;QACjC,GAAG,CAAC,QAAQ,CAAC,EAAC,SAAS,EAAC,EAAE,EAAC,IAAI,EAAE,IAAI,EAAC,CAAC,CAAA;QACvC,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,YAAY,CAAC,CAAA;QACjD,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC,CAAA;QAChD,OAAO,EAAC,IAAI,EAAE,MAAM,EAAC,CAAA;IACtB,CAAC,CAAA;IACD,OAAO,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;AAChC,CAAC;AAED,MAAM,CAAC,MAAM,GAAG,CAAC,OAA0B,EAAE,EAAE,CAAC,CAC/C,CAAsB,IAAiB,EAAE,EAAE,CAAC,CAC3C,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CACxB,CACD,CAAA;AAED,MAAM,UAAU,SAAS,CACvB,KAAwB,EACxB,IAAiB;IAGlB,MAAM,WAAW,GAAG,SAAS,CAAC,KAAM,SAAQ,cAAc;QACzD,GAAG,CAAA;QACH,UAAU,CAAA;QACV,MAAM,CAAQ;QACd,WAAW,GAAG,IAAI,UAAU,EAAE,CAAA;QAE9B,YAAY,IAAc;YACzB,KAAK,CAAC,IAAI,CAAC,CAAA;YACX,MAAM,EAAC,IAAI,EAAE,MAAM,EAAC,GAAG,KAAK,EAAE,CAAA;YAC9B,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE;gBACjC,IAAI,CAAC,IAAI,CAAC,MAAM;oBAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;gBAC/D,IAAI,CAAC,IAAI,CAAC,WAAW;oBAAE,OAAM;gBAC7B,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;gBAChD,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;gBACnC,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,CAAA;YACtB,CAAC,CAAC,CAAA;YACF,IAAI,CAAC,GAAG,GAAG,IAAI,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;YAC/C,IAAI,CAAC,UAAU,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAC1C,CAAC;QAED,cAAc,CAAC,KAAY;YAC1B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;YACnB,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAC9B,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,EAC7D,IAAI,CAAC,GAAG,CAAC,MAAM,CACf,CAAA;QACF,CAAC;QAED,MAAM,CAAC,EAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAmB;YAChD,MAAM,EAAC,IAAI,EAAC,GAAG,IAAI,CAAC,GAAG,CAAA;YACvB,IAAI,CAAC,IAAI,CAAC,WAAW;gBAAE,OAAO,IAAI,CAAA;YAClC,IAAI,KAAK;gBAAE,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;YAClC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;YAClC,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;YACtD,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,CAAA;YACrB,OAAO,IAAI,CAAA;QACZ,CAAC;QAED,YAAY;YACX,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,CAAA;YACnC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAA;QACzB,CAAC;QAED,WAAW;YACV,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,CAAA;YACnC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAA;QAClB,CAAC;KACD,CAAmC,CAAA;IAEpC,SAAS,UAAU,CAAC,GAAG,KAAY;QAClC,OAAO,WAAW,CAAC,EAAC,KAAK,EAAC,CAAC,CAAA;IAC5B,CAAC;IAED,UAAU,CAAC,IAAI,GAAG,WAAW,CAAA;IAE7B,OAAO,UAA+B,CAAA;AACvC,CAAC"}
|
package/x/view/types.d.ts
CHANGED
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
import { TemplateResult } from "lit";
|
|
2
|
-
import {
|
|
3
|
-
import { DirectiveResult } from "lit/directive.js";
|
|
4
|
-
import { Use } from "../base/use.js";
|
|
5
|
-
import { BaseElement } from "../base/element.js";
|
|
6
|
-
import { ViewChain } from "./utils/parts/chain.js";
|
|
2
|
+
import { DirectiveResult } from "lit/async-directive.js";
|
|
7
3
|
export type Content = TemplateResult | DirectiveResult | HTMLElement | string | null | undefined | void | Content[];
|
|
8
|
-
export type
|
|
9
|
-
export type
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
naked: (host: HTMLElement) => NakedView<Props>;
|
|
4
|
+
export type View<Props extends any[]> = (...props: Props) => Content;
|
|
5
|
+
export type ViewAttr = string | number | boolean;
|
|
6
|
+
export type ViewAttrs = Record<string, ViewAttr>;
|
|
7
|
+
export type Placement<Props extends any[]> = {
|
|
8
|
+
props: Props;
|
|
9
|
+
children?: Content;
|
|
10
|
+
attrs?: ViewAttrs;
|
|
17
11
|
};
|
|
18
|
-
export type
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} & B;
|
|
23
|
-
export type NakedView<Props extends any[]> = {
|
|
12
|
+
export type ShadowView<Props extends any[]> = View<Props> & {
|
|
13
|
+
with: (placement: Placement<Props>) => Content;
|
|
14
|
+
};
|
|
15
|
+
export type ShadowSetup = {
|
|
24
16
|
host: HTMLElement;
|
|
25
|
-
|
|
17
|
+
shadow: ShadowRoot;
|
|
26
18
|
};
|