@e280/sly 0.2.5 → 0.3.0-10
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 +356 -626
- package/package.json +22 -30
- package/s/_archive/README.md +1221 -0
- package/s/_archive/view/index.ts +7 -0
- package/s/_archive/view/types.ts +45 -0
- package/s/demo/demo.bundle.ts +5 -8
- 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 -20
- package/s/demo/views/loaders.ts +9 -9
- package/s/demo/views/time-light.ts +19 -0
- package/s/demo/views/time-shadow.ts +22 -0
- package/s/dom/attrs/attrs.ts +3 -3
- package/s/dom/attrs/parts/attr-spec.ts +17 -5
- package/s/dom/attrs/parts/on-attrs.ts +1 -1
- package/s/dom/dom.ts +1 -1
- package/s/index.html.ts +30 -33
- package/s/index.ts +2 -4
- package/s/{loaders → loader}/index.barrel.ts +0 -1
- package/s/{loaders → loader}/index.ts +0 -1
- package/s/{loaders → loader}/make.ts +1 -1
- package/s/{loaders → loader}/parts/ascii-anim.ts +6 -8
- package/s/loader/parts/error-display.ts +26 -0
- package/s/{loaders → loader}/types.ts +1 -1
- package/s/test.ts +5 -0
- package/s/view/common/css-reset.ts +19 -0
- package/s/view/common/sly-shadow.ts +14 -0
- package/s/view/elements/light.ts +14 -0
- package/s/view/elements/shadow.ts +52 -0
- package/s/view/hooks/plumbing/hooks.ts +28 -0
- package/s/view/hooks/plumbing/hookscope.ts +12 -0
- package/s/view/hooks/use-attrs.ts +28 -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 +22 -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/shadow.ts +93 -0
- package/s/view/types.ts +15 -34
- package/x/demo/demo.bundle.js +5 -8
- package/x/demo/demo.bundle.js.map +1 -1
- package/x/demo/demo.bundle.min.js +52 -63
- 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 +24 -20
- package/x/demo/views/demo.js.map +1 -1
- package/x/demo/views/loaders.d.ts +1 -1
- package/x/demo/views/loaders.js +9 -9
- package/x/demo/views/loaders.js.map +1 -1
- package/x/demo/views/{counter.d.ts → time-light.d.ts} +3 -19
- package/x/demo/views/time-light.js +16 -0
- package/x/demo/views/time-light.js.map +1 -0
- package/x/demo/views/time-shadow.d.ts +365 -0
- package/x/demo/views/time-shadow.js +18 -0
- package/x/demo/views/time-shadow.js.map +1 -0
- package/x/dom/attrs/attrs.d.ts +3 -2
- package/x/dom/attrs/attrs.js +2 -2
- package/x/dom/attrs/attrs.js.map +1 -1
- package/x/dom/attrs/parts/attr-spec.d.ts +5 -1
- package/x/dom/attrs/parts/attr-spec.js +12 -6
- package/x/dom/attrs/parts/attr-spec.js.map +1 -1
- package/x/dom/attrs/parts/on-attrs.d.ts +1 -1
- package/x/dom/attrs/parts/on-attrs.js.map +1 -1
- package/x/dom/dom.d.ts +1 -1
- package/x/dom/dom.js.map +1 -1
- package/x/index.d.ts +2 -4
- 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 +2 -4
- package/x/index.js.map +1 -1
- package/x/{loaders → loader}/index.barrel.d.ts +0 -1
- package/x/loader/index.barrel.js.map +1 -0
- package/x/{loaders → loader}/index.d.ts +0 -1
- package/x/loader/index.js.map +1 -0
- package/x/{loaders → loader}/make.d.ts +1 -1
- package/x/loader/make.js.map +1 -0
- package/x/loader/mock.js.map +1 -0
- package/x/loader/parts/anims.js.map +1 -0
- package/x/{loaders → loader}/parts/ascii-anim.d.ts +1 -1
- package/x/{loaders → loader}/parts/ascii-anim.js +6 -7
- package/x/loader/parts/ascii-anim.js.map +1 -0
- package/x/loader/parts/error-display.d.ts +1 -0
- package/x/loader/parts/error-display.js +20 -0
- package/x/loader/parts/error-display.js.map +1 -0
- package/x/{loaders → loader}/types.d.ts +1 -1
- package/x/{loaders → loader}/types.js.map +1 -1
- package/x/loot/drag-and-drops.d.ts +2 -2
- package/x/loot/drops.d.ts +1 -1
- package/x/op/index.js.map +1 -0
- package/x/op/op.js.map +1 -0
- package/x/op/podium.js.map +1 -0
- package/x/{ops → op}/types.js.map +1 -1
- package/x/test.js +3 -0
- package/x/test.js.map +1 -0
- package/x/view/common/css-reset.js +17 -0
- package/x/view/common/css-reset.js.map +1 -0
- package/x/view/common/sly-shadow.d.ts +4 -0
- package/x/view/common/sly-shadow.js +11 -0
- package/x/view/common/sly-shadow.js.map +1 -0
- package/x/view/elements/light.d.ts +357 -0
- package/x/view/elements/light.js +10 -0
- package/x/view/elements/light.js.map +1 -0
- package/x/view/elements/shadow.d.ts +366 -0
- package/x/view/elements/shadow.js +42 -0
- package/x/view/elements/shadow.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-attrs.d.ts +2 -0
- package/x/view/hooks/use-attrs.js +23 -0
- package/x/view/hooks/use-attrs.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 +19 -4
- package/x/view/index.js +19 -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/shadow.d.ts +6 -0
- package/x/view/shadow.js +71 -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/s/demo/views/mounting.ts +0 -36
- package/s/loaders/parts/error-display.ts +0 -26
- package/s/tests.test.ts +0 -8
- 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 -55
- 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.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/demo/views/mounting.d.ts +0 -3
- package/x/demo/views/mounting.js +0 -28
- package/x/demo/views/mounting.js.map +0 -1
- package/x/loaders/index.barrel.js.map +0 -1
- package/x/loaders/index.js.map +0 -1
- package/x/loaders/make.js.map +0 -1
- package/x/loaders/mock.js.map +0 -1
- package/x/loaders/parts/anims.js.map +0 -1
- package/x/loaders/parts/ascii-anim.js.map +0 -1
- package/x/loaders/parts/error-display.d.ts +0 -1
- package/x/loaders/parts/error-display.js +0 -20
- package/x/loaders/parts/error-display.js.map +0 -1
- package/x/ops/index.js.map +0 -1
- package/x/ops/op.js.map +0 -1
- package/x/ops/podium.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/tests.test.js +0 -6
- package/x/tests.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 -56
- 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}/element.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/capsule.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/s/{loaders → loader}/mock.ts +0 -0
- /package/s/{loaders → loader}/parts/anims.ts +0 -0
- /package/s/{ops → op}/index.ts +0 -0
- /package/s/{ops → op}/op.ts +0 -0
- /package/s/{ops → op}/podium.ts +0 -0
- /package/s/{ops → op}/types.ts +0 -0
- /package/x/{loaders → loader}/index.barrel.js +0 -0
- /package/x/{loaders → loader}/index.js +0 -0
- /package/x/{loaders → loader}/make.js +0 -0
- /package/x/{loaders → loader}/mock.d.ts +0 -0
- /package/x/{loaders → loader}/mock.js +0 -0
- /package/x/{loaders → loader}/parts/anims.d.ts +0 -0
- /package/x/{loaders → loader}/parts/anims.js +0 -0
- /package/x/{loaders → loader}/types.js +0 -0
- /package/x/{ops → op}/index.d.ts +0 -0
- /package/x/{ops → op}/index.js +0 -0
- /package/x/{ops → op}/op.d.ts +0 -0
- /package/x/{ops → op}/op.js +0 -0
- /package/x/{ops → op}/podium.d.ts +0 -0
- /package/x/{ops → op}/podium.js +0 -0
- /package/x/{ops → op}/types.d.ts +0 -0
- /package/x/{ops → op}/types.js +0 -0
- /package/x/{tests.test.d.ts → test.d.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,45 @@
|
|
|
1
|
+
|
|
2
|
+
import {TemplateResult} from "lit"
|
|
3
|
+
import {Constructor} from "@e280/stz"
|
|
4
|
+
import {DirectiveResult} from "lit/directive.js"
|
|
5
|
+
|
|
6
|
+
import {Use} from "../base/use.js"
|
|
7
|
+
import {BaseElement} from "../base/element.js"
|
|
8
|
+
import {ViewChain} from "./utils/parts/chain.js"
|
|
9
|
+
|
|
10
|
+
export type Content = TemplateResult | DirectiveResult | HTMLElement | string | null | undefined | void | Content[]
|
|
11
|
+
|
|
12
|
+
export type ViewFn<Props extends any[]> = (
|
|
13
|
+
(use: Use) =>
|
|
14
|
+
(...props: Props) =>
|
|
15
|
+
Content
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
export type View<Props extends any[]> = {
|
|
19
|
+
(...props: Props): DirectiveResult
|
|
20
|
+
props: (...props: Props) => ViewChain<Props>
|
|
21
|
+
transmute: <PropsB extends any[]>(convert: (...propsB: PropsB) => Props) => View<PropsB>
|
|
22
|
+
component: <B extends Constructor<BaseElement>>(Base?: B) => {
|
|
23
|
+
props: (propFn: (component: InstanceType<B>) => Props) => (
|
|
24
|
+
ComponentClass<B, Props>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
naked: (host: HTMLElement) => NakedView<Props>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type ViewProps<V extends View<any>> = (
|
|
31
|
+
V extends View<infer Props>
|
|
32
|
+
? Props
|
|
33
|
+
: never
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
export type ComponentClass<B extends Constructor<BaseElement>, Props extends any[]> = {
|
|
37
|
+
view: View<Props>
|
|
38
|
+
new(): InstanceType<B>
|
|
39
|
+
} & B
|
|
40
|
+
|
|
41
|
+
export type NakedView<Props extends any[]> = {
|
|
42
|
+
host: HTMLElement
|
|
43
|
+
render: (...props: Props) => void
|
|
44
|
+
}
|
|
45
|
+
|
package/s/demo/demo.bundle.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
import {dom} from "../dom/dom.js"
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import {Demo} from "./views/demo.js"
|
|
4
|
+
import {TimeLight} from "./views/time-light.js"
|
|
5
|
+
import {TimeShadow} from "./views/time-shadow.js"
|
|
6
6
|
|
|
7
|
-
dom.register({
|
|
8
|
-
DemoComponent,
|
|
9
|
-
CounterComponent,
|
|
10
|
-
FastcountElement,
|
|
11
|
-
})
|
|
7
|
+
dom.register({TimeShadow, TimeLight})
|
|
12
8
|
|
|
9
|
+
dom.render(dom(".demo"), Demo())
|
|
13
10
|
console.log("🦝 sly")
|
|
14
11
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
import {html} from "lit"
|
|
3
|
+
import {light, useSignal} from "../../view/index.js"
|
|
4
|
+
|
|
5
|
+
export const CounterLight = light((start: number) => {
|
|
6
|
+
const $count = useSignal(start)
|
|
7
|
+
const increment = () => $count.value++
|
|
8
|
+
|
|
9
|
+
return html`
|
|
10
|
+
<button @click="${increment}">${$count()}</button>
|
|
11
|
+
`
|
|
12
|
+
})
|
|
13
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
import {css, html} from "lit"
|
|
3
|
+
import {shadow, useName, useCss, useSignal} from "../../view/index.js"
|
|
4
|
+
|
|
5
|
+
export const CounterShadow = shadow((start: number) => {
|
|
6
|
+
useName("counter-shadow")
|
|
7
|
+
useCss(css`:host{display:inline-block} button{color:cyan}`)
|
|
8
|
+
|
|
9
|
+
const $count = useSignal(start)
|
|
10
|
+
const increment = () => $count.value++
|
|
11
|
+
|
|
12
|
+
return html`
|
|
13
|
+
<button @click="${increment}">${$count()}</button>
|
|
14
|
+
`
|
|
15
|
+
})
|
|
16
|
+
|
package/s/demo/views/demo.ts
CHANGED
|
@@ -1,34 +1,38 @@
|
|
|
1
1
|
|
|
2
2
|
import {css, html} from "lit"
|
|
3
|
-
|
|
4
|
-
import {view} from "../../view/view.js"
|
|
5
|
-
import {CounterView} from "./counter.js"
|
|
6
3
|
import {LoadersView} from "./loaders.js"
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
4
|
+
import {CounterLight} from "./counter-light.js"
|
|
5
|
+
import {CounterShadow} from "./counter-shadow.js"
|
|
6
|
+
import {cssReset, shadow, useName, useStyles} from "../../view/index.js"
|
|
9
7
|
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
export const Demo = shadow(() => {
|
|
9
|
+
useName("demo")
|
|
10
|
+
useStyles(cssReset, styles)
|
|
13
11
|
|
|
14
12
|
return html`
|
|
15
|
-
${
|
|
13
|
+
<p>light ${CounterLight(123)}</p>
|
|
14
|
+
|
|
15
|
+
<p>
|
|
16
|
+
shadow ${CounterShadow.with({
|
|
17
|
+
props: [234],
|
|
18
|
+
attrs: {"data-lol": 555},
|
|
19
|
+
children: html`<p>hello</p>`,
|
|
20
|
+
})}
|
|
21
|
+
</p>
|
|
16
22
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
.children("view")
|
|
20
|
-
.render()}
|
|
23
|
+
<time-shadow></time-shadow>
|
|
24
|
+
<time-light></time-light>
|
|
21
25
|
|
|
22
26
|
${LoadersView()}
|
|
23
27
|
`
|
|
24
|
-
})
|
|
28
|
+
})
|
|
25
29
|
|
|
26
30
|
const styles = css`
|
|
27
|
-
:host {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
31
|
+
:host {
|
|
32
|
+
display: flex;
|
|
33
|
+
flex-direction: column;
|
|
34
|
+
align-items: center;
|
|
35
|
+
gap: 1em;
|
|
36
|
+
}
|
|
33
37
|
`
|
|
34
38
|
|
package/s/demo/views/loaders.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
|
|
2
2
|
import {css, html} from "lit"
|
|
3
|
-
import {Op} from "../../
|
|
4
|
-
import {
|
|
5
|
-
import {loaders} from "../../
|
|
6
|
-
import {cssReset} from "../../
|
|
3
|
+
import {Op} from "../../op/op.js"
|
|
4
|
+
import {shadow} from "../../view/shadow.js"
|
|
5
|
+
import {loaders} from "../../loader/index.js"
|
|
6
|
+
import {cssReset, useName, useOnce, useStyles} from "../../view/index.js"
|
|
7
7
|
|
|
8
|
-
export const LoadersView =
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
export const LoadersView = shadow(() => {
|
|
9
|
+
useName("loaders")
|
|
10
|
+
useStyles(cssReset, styles)
|
|
11
11
|
|
|
12
|
-
const op =
|
|
12
|
+
const op = useOnce(() => Op.loading())
|
|
13
13
|
|
|
14
|
-
const library =
|
|
14
|
+
const library = useOnce(() =>
|
|
15
15
|
Object.entries(loaders.anims).map(([key, anim]) => ({
|
|
16
16
|
key,
|
|
17
17
|
loader: loaders.make(anim)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
import {html} from "lit"
|
|
3
|
+
import {cycle, nap} from "@e280/stz"
|
|
4
|
+
import {useMount, useSignal} from "../../view/index.js"
|
|
5
|
+
import {lightElement} from "../../view/elements/light.js"
|
|
6
|
+
|
|
7
|
+
export class TimeLight extends lightElement(() => {
|
|
8
|
+
const $time = useSignal(Date.now())
|
|
9
|
+
|
|
10
|
+
useMount(() => cycle(async() => {
|
|
11
|
+
await nap(100)
|
|
12
|
+
$time(Date.now())
|
|
13
|
+
}))
|
|
14
|
+
|
|
15
|
+
return html`
|
|
16
|
+
<p>${$time()}</p>
|
|
17
|
+
`
|
|
18
|
+
}) {}
|
|
19
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
import {css, html} from "lit"
|
|
3
|
+
import {cycle, nap} from "@e280/stz"
|
|
4
|
+
import {shadowElement} from "../../view/elements/shadow.js"
|
|
5
|
+
import {useCss, useMount, useName, useSignal} from "../../view/index.js"
|
|
6
|
+
|
|
7
|
+
export class TimeShadow extends shadowElement(() => {
|
|
8
|
+
useName("time-shadow")
|
|
9
|
+
useCss(css`:host{display:inline-block} button{color:cyan}`)
|
|
10
|
+
|
|
11
|
+
const $time = useSignal(Date.now())
|
|
12
|
+
|
|
13
|
+
useMount(() => cycle(async() => {
|
|
14
|
+
await nap(100)
|
|
15
|
+
$time(Date.now())
|
|
16
|
+
}))
|
|
17
|
+
|
|
18
|
+
return html`
|
|
19
|
+
<p>${$time()}</p>
|
|
20
|
+
`
|
|
21
|
+
}) {}
|
|
22
|
+
|
package/s/dom/attrs/attrs.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
import {AttrSpec} from "../types.js"
|
|
3
3
|
import {onAttrs} from "./parts/on-attrs.js"
|
|
4
|
-
import {attrSpec} from "./parts/attr-spec.js"
|
|
5
4
|
import {AttrProxies} from "./parts/attr-proxies.js"
|
|
6
5
|
import {attrGet, attrSet} from "./parts/attr-fns.js"
|
|
6
|
+
import {attrSpec, AttrSpecOptions} from "./parts/attr-spec.js"
|
|
7
7
|
|
|
8
8
|
export function attrs(element: HTMLElement) {
|
|
9
9
|
const proxies = new AttrProxies(element)
|
|
@@ -11,8 +11,8 @@ export function attrs(element: HTMLElement) {
|
|
|
11
11
|
strings: proxies.strings,
|
|
12
12
|
numbers: proxies.numbers,
|
|
13
13
|
booleans: proxies.booleans,
|
|
14
|
-
on: (fn:
|
|
15
|
-
spec: <A extends AttrSpec>(spec: A) => attrSpec(element, spec),
|
|
14
|
+
on: (fn: MutationCallback) => onAttrs(element, fn),
|
|
15
|
+
spec: <A extends AttrSpec>(spec: A, options: AttrSpecOptions = {}) => attrSpec(element, spec, options),
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -2,10 +2,16 @@
|
|
|
2
2
|
import {attrGet, attrSet} from "./attr-fns.js"
|
|
3
3
|
import {AttrSpec, AttrTypes} from "../../types.js"
|
|
4
4
|
|
|
5
|
+
export type AttrSpecOptions = {
|
|
6
|
+
beforeSet?: (attrKey: string) => void
|
|
7
|
+
afterSet?: (attrKey: string) => void
|
|
8
|
+
}
|
|
9
|
+
|
|
5
10
|
/** specify available html attributes and their types and create a proxy accessor */
|
|
6
11
|
export const attrSpec = <A extends AttrSpec>(
|
|
7
12
|
e: HTMLElement,
|
|
8
13
|
spec: A,
|
|
14
|
+
options: AttrSpecOptions = {},
|
|
9
15
|
) => new Proxy(spec, {
|
|
10
16
|
|
|
11
17
|
get: (_target, key: string) => {
|
|
@@ -18,11 +24,17 @@ export const attrSpec = <A extends AttrSpec>(
|
|
|
18
24
|
},
|
|
19
25
|
|
|
20
26
|
set: (_target, key: string, value: any) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
try {
|
|
28
|
+
options.beforeSet?.(key)
|
|
29
|
+
switch (spec[key]) {
|
|
30
|
+
case String: return attrSet.string(e, key, value)
|
|
31
|
+
case Number: return attrSet.number(e, key, value)
|
|
32
|
+
case Boolean: return attrSet.boolean(e, key, value)
|
|
33
|
+
default: throw new Error(`invalid attribute type for "${key}"`)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
options.afterSet?.(key)
|
|
26
38
|
}
|
|
27
39
|
},
|
|
28
40
|
}) as any as AttrTypes<A>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
/** respond when any attribute changes on the html element */
|
|
3
|
-
export function onAttrs(element: HTMLElement, fn:
|
|
3
|
+
export function onAttrs(element: HTMLElement, fn: MutationCallback) {
|
|
4
4
|
const observer = new MutationObserver(fn)
|
|
5
5
|
observer.observe(element, {attributes: true})
|
|
6
6
|
return () => observer.disconnect()
|
package/s/dom/dom.ts
CHANGED
|
@@ -11,7 +11,7 @@ import {register} from "./parts/register.js"
|
|
|
11
11
|
import {Queryable, Renderable} from "./types.js"
|
|
12
12
|
import {queryAll, queryMaybe, queryRequire} from "./parts/queries.js"
|
|
13
13
|
|
|
14
|
-
export function dom<E extends
|
|
14
|
+
export function dom<E extends HTMLElement>(selector: string, container: Queryable = document) {
|
|
15
15
|
return queryRequire<E>(selector, container)
|
|
16
16
|
}
|
|
17
17
|
|
package/s/index.html.ts
CHANGED
|
@@ -1,38 +1,35 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
2
|
+
import {template, html, socialCard} from "@e280/scute"
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
export default template(import.meta.url, async orb => html`
|
|
5
|
+
<!doctype html>
|
|
6
|
+
<html>
|
|
7
|
+
<head>
|
|
8
|
+
<meta charset="utf-8"/>
|
|
9
|
+
<meta name="viewport" content="width=device-width,initial-scale=1"/>
|
|
10
|
+
<meta name="darkreader-lock"/>
|
|
11
|
+
<style>@layer base{html{background:#000}}</style>
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
favicon,
|
|
14
|
-
dark: true,
|
|
15
|
-
socialCard: {
|
|
16
|
-
themeColor: "#95ff7b",
|
|
17
|
-
title,
|
|
18
|
-
description,
|
|
19
|
-
siteName: "@e280/sly",
|
|
20
|
-
image: "https://" + domain + favicon,
|
|
21
|
-
},
|
|
13
|
+
<title>sly</title>
|
|
14
|
+
<link rel="icon" href="/assets/favicon.png"/>
|
|
15
|
+
<link rel="stylesheet" href="${orb.hashurl("demo/demo.css")}"/>
|
|
16
|
+
<script type="module" src="${orb.hashurl("demo/demo.bundle.min.js")}"></script>
|
|
22
17
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
18
|
+
${socialCard({
|
|
19
|
+
themeColor: "#95ff7b",
|
|
20
|
+
title: "sly",
|
|
21
|
+
description: "mischievous shadow views",
|
|
22
|
+
siteName: "@e280/sly",
|
|
23
|
+
image: "https://sly.e280.org/assets/favicon.png",
|
|
24
|
+
})}
|
|
25
|
+
</head>
|
|
26
|
+
<body>
|
|
27
|
+
<img class=icon alt="" src="/assets/favicon.png"/>
|
|
28
|
+
<h1>sly testing page</h1>
|
|
29
|
+
<p><a href="https://github.com/e280/sly">github.com/e280/sly</a></p>
|
|
30
|
+
<p class=lil>v${orb.packageVersion()}</p>
|
|
31
|
+
<div class="demo"></div>
|
|
32
|
+
</body>
|
|
33
|
+
</html>
|
|
34
|
+
`)
|
|
38
35
|
|
package/s/index.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
|
|
2
|
-
export * from "./base/index.js"
|
|
3
2
|
export * from "./dom/index.js"
|
|
4
|
-
export * from "./
|
|
3
|
+
export * from "./loader/index.js"
|
|
5
4
|
export * from "./loot/index.js"
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./spa/index.js"
|
|
5
|
+
export * from "./op/index.js"
|
|
8
6
|
export * from "./view/index.js"
|
|
9
7
|
|
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
|
|
2
2
|
import {css} from "lit"
|
|
3
3
|
import {nap, cycle} from "@e280/stz"
|
|
4
|
-
|
|
5
|
-
import {view} from "../../view/view.js"
|
|
6
4
|
import {Content} from "../../view/types.js"
|
|
7
|
-
import {cssReset} from "../../
|
|
5
|
+
import {cssReset, shadow, useMount, useName, useSignal, useStyles} from "../../view/index.js"
|
|
8
6
|
|
|
9
7
|
export function makeAsciiAnim(hz: number, frames: string[]): () => Content {
|
|
10
8
|
return () => AsciiAnim({hz, frames})
|
|
11
9
|
}
|
|
12
10
|
|
|
13
|
-
export const AsciiAnim =
|
|
11
|
+
export const AsciiAnim = shadow(({hz, frames}: {
|
|
14
12
|
hz: number,
|
|
15
13
|
frames: string[],
|
|
16
14
|
}) => {
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
useName("loading")
|
|
17
|
+
useStyles(cssReset, style)
|
|
20
18
|
|
|
21
|
-
const frame =
|
|
19
|
+
const frame = useSignal(0)
|
|
22
20
|
|
|
23
|
-
|
|
21
|
+
useMount(() => cycle(async() => {
|
|
24
22
|
await nap(1000 / hz)
|
|
25
23
|
const next = frame.get() + 1
|
|
26
24
|
frame.set(next >= frames.length ? 0 : next)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
import {css, html} from "lit"
|
|
3
|
+
import {shadow} from "../../view/shadow.js"
|
|
4
|
+
import {cssReset, useName, useStyles} from "../../view/index.js"
|
|
5
|
+
|
|
6
|
+
export const ErrorDisplay = shadow((error: any) => {
|
|
7
|
+
useName("error")
|
|
8
|
+
useStyles(cssReset, style)
|
|
9
|
+
|
|
10
|
+
if (typeof error === "string")
|
|
11
|
+
return error
|
|
12
|
+
|
|
13
|
+
else if (error instanceof Error)
|
|
14
|
+
return html`<strong>${error.name}:</strong> <span>${error.message}</span>`
|
|
15
|
+
|
|
16
|
+
else
|
|
17
|
+
return `error`
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const style = css`
|
|
21
|
+
:host {
|
|
22
|
+
font-family: monospace;
|
|
23
|
+
color: red;
|
|
24
|
+
}
|
|
25
|
+
`
|
|
26
|
+
|
package/s/test.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
import {css, CSSResultGroup} from "lit"
|
|
3
|
+
|
|
4
|
+
export const cssReset: CSSResultGroup = css`
|
|
5
|
+
* {
|
|
6
|
+
margin: 0;
|
|
7
|
+
padding: 0;
|
|
8
|
+
box-sizing: border-box;
|
|
9
|
+
|
|
10
|
+
scrollbar-width: thin;
|
|
11
|
+
scrollbar-color: #888 transparent;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
::-webkit-scrollbar { width: 8px; }
|
|
15
|
+
::-webkit-scrollbar-track { background: transparent; }
|
|
16
|
+
::-webkit-scrollbar-thumb { background: #888; border-radius: 1em; }
|
|
17
|
+
::-webkit-scrollbar-thumb:hover { background: #999; }
|
|
18
|
+
`
|
|
19
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
import {dom} from "../../dom/dom.js"
|
|
3
|
+
|
|
4
|
+
export class SlyShadow extends HTMLElement {
|
|
5
|
+
static register() {
|
|
6
|
+
dom.register({SlyShadow}, {soft: true})
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
connectedCallback() {
|
|
10
|
+
if (!this.hasAttribute("view"))
|
|
11
|
+
this.setAttribute("view", "")
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
import {render} from "lit"
|
|
3
|
+
import {light} from "../light.js"
|
|
4
|
+
import {Content} from "../types.js"
|
|
5
|
+
|
|
6
|
+
export function lightElement(view: () => Content) {
|
|
7
|
+
const fn = light(view)
|
|
8
|
+
|
|
9
|
+
return class extends HTMLElement {
|
|
10
|
+
connectedCallback() { render(fn(), this) }
|
|
11
|
+
disconnectedCallback() { render(null, this) }
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
|
|
2
|
+
import {microbounce} from "@e280/stz"
|
|
3
|
+
import {render as litRender} from "lit"
|
|
4
|
+
import {Content} from "../types.js"
|
|
5
|
+
import {ShadowCx} from "../parts/cx.js"
|
|
6
|
+
import {hooks} from "../hooks/plumbing/hooks.js"
|
|
7
|
+
import {Reactivity} from "../parts/reactivity.js"
|
|
8
|
+
import {Hookscope} from "../hooks/plumbing/hookscope.js"
|
|
9
|
+
|
|
10
|
+
export function shadowElement(view: () => Content) {
|
|
11
|
+
return class extends HTMLElement {
|
|
12
|
+
#cx
|
|
13
|
+
#hookscope
|
|
14
|
+
#reactivity = new Reactivity()
|
|
15
|
+
#shadow = this.attachShadow({mode: "open"})
|
|
16
|
+
|
|
17
|
+
constructor() {
|
|
18
|
+
super()
|
|
19
|
+
const rerender = microbounce(() => {
|
|
20
|
+
if (!this.isConnected) return
|
|
21
|
+
const content = this.#renderContent()
|
|
22
|
+
litRender(content, this.#cx.shadow)
|
|
23
|
+
this.#cx.doneRender()
|
|
24
|
+
})
|
|
25
|
+
this.#cx = new ShadowCx(rerender, this, this.#shadow)
|
|
26
|
+
this.#hookscope = new Hookscope(this.#cx)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
#renderContent() {
|
|
30
|
+
return this.#reactivity.observe(
|
|
31
|
+
() => hooks.wrap(this.#hookscope, () => view()),
|
|
32
|
+
this.#cx.render,
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
render() {
|
|
37
|
+
litRender(this.#renderContent(), this.#cx.shadow)
|
|
38
|
+
this.#cx.doneRender()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
connectedCallback() {
|
|
42
|
+
this.#hookscope.mounts.remountAll()
|
|
43
|
+
this.#cx.render()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
disconnectedCallback() {
|
|
47
|
+
this.#hookscope.mounts.unmountAll()
|
|
48
|
+
this.#reactivity.clear()
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
import {Hookscope} from "./hookscope.js"
|
|
3
|
+
|
|
4
|
+
export class Hooks {
|
|
5
|
+
#scopes: Hookscope[] = []
|
|
6
|
+
|
|
7
|
+
get scope() {
|
|
8
|
+
const scope = this.#scopes.at(-1)
|
|
9
|
+
if (!scope) throw new Error("hooks must be called within a render fn")
|
|
10
|
+
return scope
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
increment() {
|
|
14
|
+
const scope = this.scope
|
|
15
|
+
const position = scope.position++
|
|
16
|
+
return {scope, position}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
wrap<Ret>(scope: Hookscope, fn: () => Ret) {
|
|
20
|
+
scope.position = 0
|
|
21
|
+
this.#scopes.push(scope)
|
|
22
|
+
try { return fn() }
|
|
23
|
+
finally { this.#scopes.pop() }
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const hooks: Hooks = (globalThis as any)[Symbol.for("e280.hooks")] ??= new Hooks()
|
|
28
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
import {GMap} from "@e280/stz"
|
|
3
|
+
import {Mounts} from "../use-mount.js"
|
|
4
|
+
import {LightCx, ShadowCx} from "../../parts/cx.js"
|
|
5
|
+
|
|
6
|
+
export class Hookscope {
|
|
7
|
+
position = 0
|
|
8
|
+
values = new GMap<number, any>()
|
|
9
|
+
mounts = new Mounts()
|
|
10
|
+
constructor(public cx: LightCx | ShadowCx) {}
|
|
11
|
+
}
|
|
12
|
+
|