@e280/sly 0.2.0-7 → 0.2.0-9
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 +87 -24
- package/package.json +1 -1
- package/s/demo/demo.bundle.ts +13 -1
- package/s/demo/views/counter.ts +13 -5
- package/s/demo/views/demo.ts +10 -0
- package/s/demo/views/divine.ts +22 -0
- package/s/demo/views/incredi.ts +2 -1
- package/s/dom/attrs/attrs.ts +21 -0
- package/s/dom/attrs/parts/attr-fns.ts +38 -0
- package/s/dom/attrs/parts/attr-proxies.ts +35 -0
- package/s/dom/attrs/parts/attr-spec.ts +29 -0
- package/s/dom/attrs/parts/on-attrs.ts +8 -0
- package/s/dom/dom.ts +6 -5
- package/s/dom/{register.ts → parts/register.ts} +2 -10
- package/s/dom/types.ts +45 -0
- package/s/index.html.ts +2 -1
- package/s/index.ts +1 -4
- package/s/views/base-element.ts +15 -31
- package/s/views/types.ts +15 -6
- package/s/views/use.ts +10 -11
- package/s/views/utils/attr-watcher.ts +22 -0
- package/s/views/utils/reactor.ts +23 -0
- package/s/views/view.ts +73 -38
- package/x/demo/demo.bundle.js +11 -1
- package/x/demo/demo.bundle.js.map +1 -1
- package/x/demo/demo.bundle.min.js +19 -15
- package/x/demo/demo.bundle.min.js.map +4 -4
- package/x/demo/views/counter.d.ts +7 -1
- package/x/demo/views/counter.js +11 -5
- package/x/demo/views/counter.js.map +1 -1
- package/x/demo/views/demo.js +8 -0
- package/x/demo/views/demo.js.map +1 -1
- package/x/demo/views/divine.d.ts +8 -0
- package/x/demo/views/divine.js +19 -0
- package/x/demo/views/divine.js.map +1 -0
- package/x/demo/views/incredi.js +1 -1
- package/x/demo/views/incredi.js.map +1 -1
- package/x/dom/attrs/attrs.d.ts +20 -0
- package/x/dom/attrs/attrs.js +17 -0
- package/x/dom/attrs/attrs.js.map +1 -0
- package/x/dom/attrs/parts/attr-fns.d.ts +13 -0
- package/x/dom/attrs/parts/attr-fns.js +42 -0
- package/x/dom/attrs/parts/attr-fns.js.map +1 -0
- package/x/dom/attrs/parts/attr-proxies.d.ts +8 -0
- package/x/dom/attrs/parts/attr-proxies.js +21 -0
- package/x/dom/attrs/parts/attr-proxies.js.map +1 -0
- package/x/dom/attrs/parts/attr-spec.d.ts +3 -0
- package/x/dom/attrs/parts/attr-spec.js +21 -0
- package/x/dom/attrs/parts/attr-spec.js.map +1 -0
- package/x/dom/attrs/parts/on-attrs.d.ts +2 -0
- package/x/dom/attrs/parts/on-attrs.js +7 -0
- package/x/dom/attrs/parts/on-attrs.js.map +1 -0
- package/x/dom/dom.d.ts +10 -4
- package/x/dom/dom.js +5 -5
- package/x/dom/dom.js.map +1 -1
- package/x/dom/parts/dashify.js.map +1 -0
- package/x/dom/{register.d.ts → parts/register.d.ts} +2 -10
- package/x/dom/parts/register.js.map +1 -0
- package/x/dom/{attributes.d.ts → types.d.ts} +11 -2
- package/x/dom/types.js +2 -0
- package/x/dom/types.js.map +1 -0
- package/x/index.d.ts +1 -4
- package/x/index.html +4 -3
- package/x/index.html.js +2 -1
- package/x/index.html.js.map +1 -1
- package/x/index.js +1 -4
- package/x/index.js.map +1 -1
- package/x/views/base-element.js +9 -27
- package/x/views/base-element.js.map +1 -1
- package/x/views/types.d.ts +11 -6
- package/x/views/use.d.ts +2 -2
- package/x/views/use.js +2 -5
- package/x/views/use.js.map +1 -1
- package/x/views/utils/attr-watcher.d.ts +8 -0
- package/x/views/utils/attr-watcher.js +20 -0
- package/x/views/utils/attr-watcher.js.map +1 -0
- package/x/views/utils/reactor.d.ts +6 -0
- package/x/views/utils/reactor.js +18 -0
- package/x/views/utils/reactor.js.map +1 -0
- package/x/views/view.d.ts +8 -4
- package/x/views/view.js +59 -30
- package/x/views/view.js.map +1 -1
- package/s/dom/attributes.ts +0 -89
- package/x/dom/attributes.js +0 -46
- package/x/dom/attributes.js.map +0 -1
- package/x/dom/dashify.js.map +0 -1
- package/x/dom/register.js.map +0 -1
- /package/s/dom/{dashify.ts → parts/dashify.ts} +0 -0
- /package/x/dom/{dashify.d.ts → parts/dashify.d.ts} +0 -0
- /package/x/dom/{dashify.js → parts/dashify.js} +0 -0
- /package/x/dom/{register.js → parts/register.js} +0 -0
|
@@ -1 +1,7 @@
|
|
|
1
|
-
export declare const CounterView: import("../../index.js").View<[
|
|
1
|
+
export declare const CounterView: import("../../index.js").View<[start: number]>;
|
|
2
|
+
declare const CounterComponent_base: import("../../index.js").ComponentClass<{
|
|
3
|
+
start?: number;
|
|
4
|
+
}, [start: number]>;
|
|
5
|
+
export declare class CounterComponent extends CounterComponent_base {
|
|
6
|
+
}
|
|
7
|
+
export {};
|
package/x/demo/views/counter.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { css, html } from "lit";
|
|
2
2
|
import { repeat } from "@e280/stz";
|
|
3
|
+
import { dom } from "../../dom/dom.js";
|
|
3
4
|
import { view } from "../../views/view.js";
|
|
4
5
|
import { cssReset } from "../../views/css-reset.js";
|
|
5
|
-
export const CounterView = view(use => (
|
|
6
|
+
export const CounterView = view(use => (start) => {
|
|
6
7
|
use.name("counter");
|
|
7
8
|
use.styles(cssReset, styles);
|
|
8
9
|
const $seconds = use.signal(0);
|
|
9
|
-
const
|
|
10
|
+
const since = use.once(() => Date.now());
|
|
10
11
|
use.mount(() => repeat(async () => {
|
|
11
|
-
const
|
|
12
|
-
$seconds.set(Math.floor(
|
|
12
|
+
const delta = Date.now() - since;
|
|
13
|
+
$seconds.set(Math.floor(delta / 1000));
|
|
13
14
|
}));
|
|
14
|
-
const $count = use.signal(
|
|
15
|
+
const $count = use.signal(start);
|
|
15
16
|
const increment = () => $count.value++;
|
|
16
17
|
const $product = use.signal
|
|
17
18
|
.derived(() => $count() * $seconds());
|
|
@@ -31,6 +32,11 @@ export const CounterView = view(use => (initial) => {
|
|
|
31
32
|
</div>
|
|
32
33
|
`;
|
|
33
34
|
});
|
|
35
|
+
// convert a view into a web component
|
|
36
|
+
export class CounterComponent extends (CounterView
|
|
37
|
+
.component()
|
|
38
|
+
.props(c => [dom.attrs(c).number.start ?? 0])) {
|
|
39
|
+
}
|
|
34
40
|
const styles = css `
|
|
35
41
|
:host {
|
|
36
42
|
display: flex;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"counter.js","sourceRoot":"","sources":["../../../s/demo/views/counter.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAE,IAAI,EAAC,MAAM,KAAK,CAAA;AAC7B,OAAO,EAAC,MAAM,EAAC,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAC,IAAI,EAAC,MAAM,qBAAqB,CAAA;AACxC,OAAO,EAAC,QAAQ,EAAC,MAAM,0BAA0B,CAAA;AAEjD,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"counter.js","sourceRoot":"","sources":["../../../s/demo/views/counter.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAE,IAAI,EAAC,MAAM,KAAK,CAAA;AAC7B,OAAO,EAAC,MAAM,EAAC,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAC,GAAG,EAAC,MAAM,kBAAkB,CAAA;AACpC,OAAO,EAAC,IAAI,EAAC,MAAM,qBAAqB,CAAA;AACxC,OAAO,EAAC,QAAQ,EAAC,MAAM,0BAA0B,CAAA;AAEjD,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,KAAa,EAAE,EAAE;IACxD,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IACnB,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;IAE5B,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IAC9B,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;IACxC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,IAAG,EAAE;QAChC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAA;QAChC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAA;IACvC,CAAC,CAAC,CAAC,CAAA;IAEH,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAChC,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;IAEtC,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM;SACzB,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAC,CAAA;IAEtC,OAAO,IAAI,CAAA;;;WAGD,QAAQ,CAAC,GAAG,EAAE;;;WAGd,MAAM,CAAC,GAAG,EAAE;;;WAGZ,QAAQ,CAAC,GAAG,EAAE;;;qBAGJ,SAAS;;EAE5B,CAAA;AACF,CAAC,CAAC,CAAA;AAEF,sCAAsC;AACtC,MAAM,OAAO,gBAAiB,SAAQ,CACrC,WAAW;KACT,SAAS,EAAoB;KAC7B,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAC9C;CAAG;AAEJ,MAAM,MAAM,GAAG,GAAG,CAAA;;;;;;;;;;CAUjB,CAAA"}
|
package/x/demo/views/demo.js
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import { css, html } from "lit";
|
|
2
|
+
import { DivineView } from "./divine.js";
|
|
2
3
|
import { view } from "../../views/view.js";
|
|
3
4
|
import { CounterView } from "./counter.js";
|
|
4
5
|
import { LoadersView } from "./loaders.js";
|
|
5
6
|
import { cssReset } from "../../views/css-reset.js";
|
|
7
|
+
import { nap, repeat } from "@e280/stz";
|
|
6
8
|
export const DemoView = view(use => () => {
|
|
7
9
|
use.name("demo");
|
|
8
10
|
use.styles(cssReset, styles);
|
|
11
|
+
const $speed = use.signal(3);
|
|
12
|
+
use.mount(() => repeat(async () => {
|
|
13
|
+
await nap(1000);
|
|
14
|
+
$speed.value++;
|
|
15
|
+
}));
|
|
9
16
|
return html `
|
|
10
17
|
${CounterView.props(2).children("view").render()}
|
|
18
|
+
${DivineView($speed())}
|
|
11
19
|
${LoadersView()}
|
|
12
20
|
`;
|
|
13
21
|
});
|
package/x/demo/views/demo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"demo.js","sourceRoot":"","sources":["../../../s/demo/views/demo.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAE,IAAI,EAAC,MAAM,KAAK,CAAA;AAC7B,OAAO,EAAC,IAAI,EAAC,MAAM,qBAAqB,CAAA;AACxC,OAAO,EAAC,WAAW,EAAC,MAAM,cAAc,CAAA;AACxC,OAAO,EAAC,WAAW,EAAC,MAAM,cAAc,CAAA;AACxC,OAAO,EAAC,QAAQ,EAAC,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"demo.js","sourceRoot":"","sources":["../../../s/demo/views/demo.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAE,IAAI,EAAC,MAAM,KAAK,CAAA;AAC7B,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAA;AACtC,OAAO,EAAC,IAAI,EAAC,MAAM,qBAAqB,CAAA;AACxC,OAAO,EAAC,WAAW,EAAC,MAAM,cAAc,CAAA;AACxC,OAAO,EAAC,WAAW,EAAC,MAAM,cAAc,CAAA;AACxC,OAAO,EAAC,QAAQ,EAAC,MAAM,0BAA0B,CAAA;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAEvC,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE;IACxC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAChB,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;IAE5B,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IAE5B,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,IAAG,EAAE;QAChC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAA;QACf,MAAM,CAAC,KAAK,EAAE,CAAA;IACf,CAAC,CAAC,CAAC,CAAA;IAEH,OAAO,IAAI,CAAA;IACR,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE;IAC9C,UAAU,CAAC,MAAM,EAAE,CAAC;IACpB,WAAW,EAAE;EACf,CAAA;AACF,CAAC,CAAC,CAAA;AAEF,MAAM,MAAM,GAAG,GAAG,CAAA;;;;;;;CAOjB,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SignalFn } from "@e280/strata";
|
|
2
|
+
declare const DivineElement_base: import("../../index.js").ComponentClass<{
|
|
3
|
+
$speed: SignalFn<number>;
|
|
4
|
+
}, [speed: number]>;
|
|
5
|
+
export declare class DivineElement extends DivineElement_base {
|
|
6
|
+
}
|
|
7
|
+
export declare const DivineView: import("../../index.js").View<[speed: number]>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { html } from "lit";
|
|
2
|
+
import { view } from "../../views/view.js";
|
|
3
|
+
import { signal } from "@e280/strata";
|
|
4
|
+
export class DivineElement extends (view
|
|
5
|
+
.component(component => {
|
|
6
|
+
component.$speed = signal(1);
|
|
7
|
+
})
|
|
8
|
+
.props(component => [component.$speed()])
|
|
9
|
+
.render(use => speed => {
|
|
10
|
+
const $count = use.signal(0);
|
|
11
|
+
const increment = () => $count($count() + speed);
|
|
12
|
+
return html `
|
|
13
|
+
<span>${$count()}</span>
|
|
14
|
+
<button @click="${increment}">+${speed}</button>
|
|
15
|
+
`;
|
|
16
|
+
})) {
|
|
17
|
+
}
|
|
18
|
+
export const DivineView = DivineElement.view;
|
|
19
|
+
//# sourceMappingURL=divine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"divine.js","sourceRoot":"","sources":["../../../s/demo/views/divine.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,IAAI,EAAC,MAAM,KAAK,CAAA;AACxB,OAAO,EAAC,IAAI,EAAC,MAAM,qBAAqB,CAAA;AACxC,OAAO,EAAC,MAAM,EAAW,MAAM,cAAc,CAAA;AAE7C,MAAM,OAAO,aAAc,SAAQ,CAAC,IAAI;KACtC,SAAS,CAA6B,SAAS,CAAC,EAAE;IAClD,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;AAC7B,CAAC,CAAC;KACD,KAAK,CAAkB,SAAS,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;KACzD,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE;IACtB,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IAC5B,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAA;IAChD,OAAO,IAAI,CAAA;WACF,MAAM,EAAE;qBACE,SAAS,MAAM,KAAK;GACtC,CAAA;AACF,CAAC,CAAC,CACF;CAAG;AAEJ,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,CAAA"}
|
package/x/demo/views/incredi.js
CHANGED
|
@@ -4,7 +4,7 @@ import { dom } from "../../dom/dom.js";
|
|
|
4
4
|
import { BaseElement } from "../../views/base-element.js";
|
|
5
5
|
export class IncrediElement extends BaseElement {
|
|
6
6
|
static styles = css `span{color:orange}`;
|
|
7
|
-
attrs = dom.attrs(this
|
|
7
|
+
attrs = dom.attrs(this).spec({ value: Number });
|
|
8
8
|
something = { whatever: "rofl" };
|
|
9
9
|
render(use) {
|
|
10
10
|
const { value = 1 } = this.attrs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"incredi.js","sourceRoot":"","sources":["../../../s/demo/views/incredi.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAE,IAAI,EAAC,MAAM,KAAK,CAAA;AAC7B,OAAO,EAAC,GAAG,EAAE,MAAM,EAAC,MAAM,WAAW,CAAA;AAErC,OAAO,EAAC,GAAG,EAAC,MAAM,kBAAkB,CAAA;AAEpC,OAAO,EAAC,WAAW,EAAC,MAAM,6BAA6B,CAAA;AAEvD,MAAM,OAAO,cAAe,SAAQ,WAAW;IAC9C,MAAM,CAAC,MAAM,GAAG,GAAG,CAAA,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"incredi.js","sourceRoot":"","sources":["../../../s/demo/views/incredi.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAE,IAAI,EAAC,MAAM,KAAK,CAAA;AAC7B,OAAO,EAAC,GAAG,EAAE,MAAM,EAAC,MAAM,WAAW,CAAA;AAErC,OAAO,EAAC,GAAG,EAAC,MAAM,kBAAkB,CAAA;AAEpC,OAAO,EAAC,WAAW,EAAC,MAAM,6BAA6B,CAAA;AAEvD,MAAM,OAAO,cAAe,SAAQ,WAAW;IAC9C,MAAM,CAAC,MAAM,GAAG,GAAG,CAAA,oBAAoB,CAAA;IAEvC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAC,KAAK,EAAE,MAAM,EAAC,CAAC,CAAA;IAC7C,SAAS,GAAG,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAA;IAE9B,MAAM,CAAC,GAAQ;QACd,MAAM,EAAC,KAAK,GAAG,CAAC,EAAC,GAAG,IAAI,CAAC,KAAK,CAAA;QAC9B,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;QAE5B,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,IAAG,EAAE;YAChC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAA;YACb,MAAM,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;QAC3B,CAAC,CAAC,CAAC,CAAA;QAEH,OAAO,IAAI,CAAA;WACF,MAAM,EAAE,GAAG,KAAK;GACxB,CAAA;IACF,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AttrSpec } from "../types.js";
|
|
2
|
+
export declare function attrs(element: HTMLElement): {
|
|
3
|
+
string: Record<string, string | undefined>;
|
|
4
|
+
number: Record<string, number | undefined>;
|
|
5
|
+
boolean: Record<string, boolean | undefined>;
|
|
6
|
+
on: (fn: () => void) => () => void;
|
|
7
|
+
spec: <A extends AttrSpec>(spec: A) => import("../types.js").AttrTypes<A>;
|
|
8
|
+
};
|
|
9
|
+
export declare namespace attrs {
|
|
10
|
+
var get: {
|
|
11
|
+
string: (e: HTMLElement, key: string) => string | undefined;
|
|
12
|
+
number: (e: HTMLElement, key: string) => number | undefined;
|
|
13
|
+
boolean: (e: HTMLElement, key: string) => boolean;
|
|
14
|
+
};
|
|
15
|
+
var set: {
|
|
16
|
+
string: (e: HTMLElement, key: string, value: string | undefined) => boolean;
|
|
17
|
+
number: (e: HTMLElement, key: string, value: number | undefined) => boolean;
|
|
18
|
+
boolean: (e: HTMLElement, key: string, value: boolean | undefined) => boolean;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { onAttrs } from "./parts/on-attrs.js";
|
|
2
|
+
import { attrFns } from "./parts/attr-fns.js";
|
|
3
|
+
import { attrSpec } from "./parts/attr-spec.js";
|
|
4
|
+
import { AttrProxies } from "./parts/attr-proxies.js";
|
|
5
|
+
export function attrs(element) {
|
|
6
|
+
const proxies = new AttrProxies(element);
|
|
7
|
+
return {
|
|
8
|
+
string: proxies.string,
|
|
9
|
+
number: proxies.number,
|
|
10
|
+
boolean: proxies.boolean,
|
|
11
|
+
on: (fn) => onAttrs(element, fn),
|
|
12
|
+
spec: (spec) => attrSpec(element, spec),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
attrs.get = attrFns.get;
|
|
16
|
+
attrs.set = attrFns.set;
|
|
17
|
+
//# sourceMappingURL=attrs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attrs.js","sourceRoot":"","sources":["../../../s/dom/attrs/attrs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,OAAO,EAAC,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAC,OAAO,EAAC,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAA;AAC7C,OAAO,EAAC,WAAW,EAAC,MAAM,yBAAyB,CAAA;AAEnD,MAAM,UAAU,KAAK,CAAC,OAAoB;IACzC,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,CAAA;IACxC,OAAO;QACN,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,EAAE,EAAE,CAAC,EAAc,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;QAC5C,IAAI,EAAE,CAAqB,IAAO,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;KAC9D,CAAA;AACF,CAAC;AAED,KAAK,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAA;AACvB,KAAK,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** fns for getting and setting html attributes of various types */
|
|
2
|
+
export declare const attrFns: {
|
|
3
|
+
get: {
|
|
4
|
+
string: (e: HTMLElement, key: string) => string | undefined;
|
|
5
|
+
number: (e: HTMLElement, key: string) => number | undefined;
|
|
6
|
+
boolean: (e: HTMLElement, key: string) => boolean;
|
|
7
|
+
};
|
|
8
|
+
set: {
|
|
9
|
+
string: (e: HTMLElement, key: string, value: string | undefined) => boolean;
|
|
10
|
+
number: (e: HTMLElement, key: string, value: number | undefined) => boolean;
|
|
11
|
+
boolean: (e: HTMLElement, key: string, value: boolean | undefined) => boolean;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** fns for getting and setting html attributes of various types */
|
|
2
|
+
export const attrFns = {
|
|
3
|
+
get: {
|
|
4
|
+
string: (e, key) => {
|
|
5
|
+
return e.getAttribute(key) ?? undefined;
|
|
6
|
+
},
|
|
7
|
+
number: (e, key) => {
|
|
8
|
+
const raw = e.getAttribute(key);
|
|
9
|
+
return (raw === null || !raw)
|
|
10
|
+
? undefined
|
|
11
|
+
: Number(raw);
|
|
12
|
+
},
|
|
13
|
+
boolean: (e, key) => {
|
|
14
|
+
const raw = e.getAttribute(key);
|
|
15
|
+
return raw !== null;
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
set: {
|
|
19
|
+
string: (e, key, value) => {
|
|
20
|
+
if (value === undefined)
|
|
21
|
+
e.removeAttribute(key);
|
|
22
|
+
else
|
|
23
|
+
e.setAttribute(key, value);
|
|
24
|
+
return true;
|
|
25
|
+
},
|
|
26
|
+
number: (e, key, value) => {
|
|
27
|
+
if (value === undefined)
|
|
28
|
+
e.removeAttribute(key);
|
|
29
|
+
else
|
|
30
|
+
e.setAttribute(key, value.toString());
|
|
31
|
+
return true;
|
|
32
|
+
},
|
|
33
|
+
boolean: (e, key, value) => {
|
|
34
|
+
if (value)
|
|
35
|
+
e.setAttribute(key, "");
|
|
36
|
+
else
|
|
37
|
+
e.removeAttribute(key);
|
|
38
|
+
return true;
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=attr-fns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attr-fns.js","sourceRoot":"","sources":["../../../../s/dom/attrs/parts/attr-fns.ts"],"names":[],"mappings":"AACA,mEAAmE;AACnE,MAAM,CAAC,MAAM,OAAO,GAAG;IACtB,GAAG,EAAE;QACJ,MAAM,EAAE,CAAC,CAAc,EAAE,GAAW,EAAE,EAAE;YACvC,OAAO,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,SAAS,CAAA;QACxC,CAAC;QACD,MAAM,EAAE,CAAC,CAAc,EAAE,GAAW,EAAE,EAAE;YACvC,MAAM,GAAG,GAAG,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;YAC/B,OAAO,CAAC,GAAG,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC;gBAC5B,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACf,CAAC;QACD,OAAO,EAAE,CAAC,CAAc,EAAE,GAAW,EAAE,EAAE;YACxC,MAAM,GAAG,GAAG,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;YAC/B,OAAO,GAAG,KAAK,IAAI,CAAA;QACpB,CAAC;KACD;IAED,GAAG,EAAE;QACJ,MAAM,EAAE,CAAC,CAAc,EAAE,GAAW,EAAE,KAAyB,EAAE,EAAE;YAClE,IAAI,KAAK,KAAK,SAAS;gBAAE,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA;;gBAC1C,CAAC,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;YAC/B,OAAO,IAAI,CAAA;QACZ,CAAC;QACD,MAAM,EAAE,CAAC,CAAc,EAAE,GAAW,EAAE,KAAyB,EAAE,EAAE;YAClE,IAAI,KAAK,KAAK,SAAS;gBAAE,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA;;gBAC1C,CAAC,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAA;YAC1C,OAAO,IAAI,CAAA;QACZ,CAAC;QACD,OAAO,EAAE,CAAC,CAAc,EAAE,GAAW,EAAE,KAA0B,EAAE,EAAE;YACpE,IAAI,KAAK;gBAAE,CAAC,CAAC,YAAY,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;;gBAC7B,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA;YAC3B,OAAO,IAAI,CAAA;QACZ,CAAC;KACD;CACD,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** a typed proxy accessor for html attributes */
|
|
2
|
+
export declare class AttrProxies {
|
|
3
|
+
element: HTMLElement;
|
|
4
|
+
constructor(element: HTMLElement);
|
|
5
|
+
string: Record<string, string | undefined>;
|
|
6
|
+
number: Record<string, number | undefined>;
|
|
7
|
+
boolean: Record<string, boolean | undefined>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { attrFns } from "./attr-fns.js";
|
|
2
|
+
/** a typed proxy accessor for html attributes */
|
|
3
|
+
export class AttrProxies {
|
|
4
|
+
element;
|
|
5
|
+
constructor(element) {
|
|
6
|
+
this.element = element;
|
|
7
|
+
}
|
|
8
|
+
string = new Proxy({}, {
|
|
9
|
+
get: (_t, key) => (attrFns.get.string(this.element, key)),
|
|
10
|
+
set: (_t, key, value) => (attrFns.set.string(this.element, key, value)),
|
|
11
|
+
});
|
|
12
|
+
number = new Proxy({}, {
|
|
13
|
+
get: (_t, key) => (attrFns.get.number(this.element, key)),
|
|
14
|
+
set: (_t, key, value) => (attrFns.set.number(this.element, key, value)),
|
|
15
|
+
});
|
|
16
|
+
boolean = new Proxy({}, {
|
|
17
|
+
get: (_t, key) => (attrFns.get.boolean(this.element, key)),
|
|
18
|
+
set: (_t, key, value) => (attrFns.set.boolean(this.element, key, value)),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=attr-proxies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attr-proxies.js","sourceRoot":"","sources":["../../../../s/dom/attrs/parts/attr-proxies.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAA;AAErC,iDAAiD;AACjD,MAAM,OAAO,WAAW;IACJ;IAAnB,YAAmB,OAAoB;QAApB,YAAO,GAAP,OAAO,CAAa;IAAG,CAAC;IAE3C,MAAM,GAAG,IAAI,KAAK,CAAC,EAAE,EAAE;QACtB,GAAG,EAAE,CAAC,EAAE,EAAE,GAAW,EAAE,EAAE,CAAC,CACzB,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CACrC;QACD,GAAG,EAAE,CAAC,EAAE,EAAE,GAAW,EAAE,KAAyB,EAAE,EAAE,CAAC,CACpD,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,CAAC,CAC5C;KACD,CAAuC,CAAA;IAExC,MAAM,GAAG,IAAI,KAAK,CAAC,EAAE,EAAE;QACtB,GAAG,EAAE,CAAC,EAAE,EAAE,GAAW,EAAE,EAAE,CAAC,CACzB,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CACrC;QACD,GAAG,EAAE,CAAC,EAAE,EAAE,GAAW,EAAE,KAAyB,EAAE,EAAE,CAAC,CACpD,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,CAAC,CAC5C;KACD,CAAuC,CAAA;IAExC,OAAO,GAAG,IAAI,KAAK,CAAC,EAAE,EAAE;QACvB,GAAG,EAAE,CAAC,EAAE,EAAE,GAAW,EAAE,EAAE,CAAC,CACzB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CACtC;QACD,GAAG,EAAE,CAAC,EAAE,EAAE,GAAW,EAAE,KAA0B,EAAE,EAAE,CAAC,CACrD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,CAAC,CAC7C;KACD,CAAwC,CAAA;CACzC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { attrFns } from "./attr-fns.js";
|
|
2
|
+
/** specify available html attributes and their types and create a proxy accessor */
|
|
3
|
+
export const attrSpec = (e, spec) => new Proxy(spec, {
|
|
4
|
+
get: (_target, key) => {
|
|
5
|
+
switch (spec[key]) {
|
|
6
|
+
case String: return attrFns.get.string(e, key);
|
|
7
|
+
case Number: return attrFns.get.number(e, key);
|
|
8
|
+
case Boolean: return attrFns.get.boolean(e, key);
|
|
9
|
+
default: throw new Error(`invalid attribute type for "${key}"`);
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
set: (_target, key, value) => {
|
|
13
|
+
switch (spec[key]) {
|
|
14
|
+
case String: return attrFns.set.string(e, key, value);
|
|
15
|
+
case Number: return attrFns.set.number(e, key, value);
|
|
16
|
+
case Boolean: return attrFns.set.boolean(e, key, value);
|
|
17
|
+
default: throw new Error(`invalid attribute type for "${key}"`);
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=attr-spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attr-spec.js","sourceRoot":"","sources":["../../../../s/dom/attrs/parts/attr-spec.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAA;AAErC,oFAAoF;AACpF,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,CAAc,EACd,IAAO,EACN,EAAE,CAAC,IAAI,KAAK,CAAC,IAAI,EAAE;IAErB,GAAG,EAAE,CAAC,OAAO,EAAE,GAAW,EAAE,EAAE;QAC7B,QAAQ,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACnB,KAAK,MAAM,CAAC,CAAC,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;YAC9C,KAAK,MAAM,CAAC,CAAC,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;YAC9C,KAAK,OAAO,CAAC,CAAC,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;YAChD,OAAO,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,+BAA+B,GAAG,GAAG,CAAC,CAAA;QAChE,CAAC;IACF,CAAC;IAED,GAAG,EAAE,CAAC,OAAO,EAAE,GAAW,EAAE,KAAU,EAAE,EAAE;QACzC,QAAQ,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACnB,KAAK,MAAM,CAAC,CAAC,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;YACrD,KAAK,MAAM,CAAC,CAAC,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;YACrD,KAAK,OAAO,CAAC,CAAC,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;YACvD,OAAO,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,+BAA+B,GAAG,GAAG,CAAC,CAAA;QAChE,CAAC;IACF,CAAC;CACD,CAAwB,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** respond when any attribute changes on the html element */
|
|
2
|
+
export function onAttrs(element, fn) {
|
|
3
|
+
const observer = new MutationObserver(fn);
|
|
4
|
+
observer.observe(element, { attributes: true });
|
|
5
|
+
return () => observer.disconnect();
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=on-attrs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"on-attrs.js","sourceRoot":"","sources":["../../../../s/dom/attrs/parts/on-attrs.ts"],"names":[],"mappings":"AACA,6DAA6D;AAC7D,MAAM,UAAU,OAAO,CAAC,OAAoB,EAAE,EAAc;IAC3D,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,EAAE,CAAC,CAAA;IACzC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,EAAC,UAAU,EAAE,IAAI,EAAC,CAAC,CAAA;IAC7C,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAA;AACnC,CAAC"}
|
package/x/dom/dom.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { AttrSpec } from "./types.js";
|
|
1
2
|
import { Content } from "../views/types.js";
|
|
2
|
-
import { AttrSpec, AttrTypes } from "./attributes.js";
|
|
3
3
|
export type Renderable = HTMLElement | ShadowRoot | DocumentFragment;
|
|
4
4
|
export type Queryable = HTMLElement | ShadowRoot | Element | Document | DocumentFragment;
|
|
5
5
|
export declare class Dom<C extends Queryable> {
|
|
@@ -10,7 +10,13 @@ export declare class Dom<C extends Queryable> {
|
|
|
10
10
|
maybe<E extends Element = HTMLElement>(selector: string): E | null;
|
|
11
11
|
all<E extends Element = HTMLElement>(selector: string): E[];
|
|
12
12
|
render(...content: Content[]): import("lit-html").RootPart;
|
|
13
|
-
attrs
|
|
13
|
+
attrs(): {
|
|
14
|
+
string: Record<string, string | undefined>;
|
|
15
|
+
number: Record<string, number | undefined>;
|
|
16
|
+
boolean: Record<string, boolean | undefined>;
|
|
17
|
+
on: (fn: () => void) => () => void;
|
|
18
|
+
spec: <A extends AttrSpec>(spec: A) => import("./types.js").AttrTypes<A>;
|
|
19
|
+
};
|
|
14
20
|
}
|
|
15
21
|
export declare function dom<E extends Queryable>(selector: string): E;
|
|
16
22
|
export declare function dom<E extends Queryable>(element: E): Dom<E>;
|
|
@@ -19,8 +25,8 @@ export declare namespace dom {
|
|
|
19
25
|
export var require: <E extends Element = HTMLElement>(selector: string) => E;
|
|
20
26
|
export var maybe: <E extends Element = HTMLElement>(selector: string) => E | null;
|
|
21
27
|
export var all: <E extends Element = HTMLElement>(selector: string) => E[];
|
|
22
|
-
export var attrs:
|
|
23
|
-
export var register: typeof import("./register.js").register;
|
|
28
|
+
export var attrs: typeof import("./attrs/attrs.js").attrs;
|
|
29
|
+
export var register: typeof import("./parts/register.js").register;
|
|
24
30
|
export var render: (container: Renderable, ...content: Content[]) => import("lit-html").RootPart;
|
|
25
31
|
export { _a as in };
|
|
26
32
|
}
|
package/x/dom/dom.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { render } from "lit";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { attrs } from "./attrs/attrs.js";
|
|
3
|
+
import { register } from "./parts/register.js";
|
|
4
4
|
function require(container, selector) {
|
|
5
5
|
const e = container.querySelector(selector);
|
|
6
6
|
if (!e)
|
|
@@ -32,8 +32,8 @@ export class Dom {
|
|
|
32
32
|
render(...content) {
|
|
33
33
|
return render(content, this.element);
|
|
34
34
|
}
|
|
35
|
-
attrs(
|
|
36
|
-
return
|
|
35
|
+
attrs() {
|
|
36
|
+
return attrs(this.element);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
export function dom(selectorOrElement) {
|
|
@@ -46,7 +46,7 @@ dom.in = doc.in.bind(doc);
|
|
|
46
46
|
dom.require = doc.require.bind(doc);
|
|
47
47
|
dom.maybe = doc.maybe.bind(doc);
|
|
48
48
|
dom.all = doc.all.bind(doc);
|
|
49
|
-
dom.attrs =
|
|
49
|
+
dom.attrs = attrs;
|
|
50
50
|
dom.register = register;
|
|
51
51
|
dom.render = (container, ...content) => {
|
|
52
52
|
return render(content, container);
|
package/x/dom/dom.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom.js","sourceRoot":"","sources":["../../s/dom/dom.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"dom.js","sourceRoot":"","sources":["../../s/dom/dom.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,MAAM,KAAK,CAAA;AAE1B,OAAO,EAAC,KAAK,EAAC,MAAM,kBAAkB,CAAA;AAEtC,OAAO,EAAC,QAAQ,EAAC,MAAM,qBAAqB,CAAA;AAK5C,SAAS,OAAO,CACd,SAAoB,EACpB,QAAgB;IAEjB,MAAM,CAAC,GAAG,SAAS,CAAC,aAAa,CAAI,QAAQ,CAAC,CAAA;IAC9C,IAAI,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,QAAQ,GAAG,CAAC,CAAA;IAC1D,OAAO,CAAC,CAAA;AACT,CAAC;AAED,MAAM,OAAO,GAAG;IACI;IAAnB,YAAmB,OAAU;QAAV,YAAO,GAAP,OAAO,CAAG;IAAG,CAAC;IAEjC,EAAE,CAAwB,iBAA6B;QACtD,OAAO,IAAI,GAAG,CACb,CAAC,OAAO,iBAAiB,KAAK,QAAQ,CAAC;YACtC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,iBAAiB,CAAM;YAC/C,CAAC,CAAC,iBAAiB,CACpB,CAAA;IACF,CAAC;IAED,OAAO,CAAkC,QAAgB;QACxD,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAI,QAAQ,CAAC,CAAA;QACjD,IAAI,CAAC,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,QAAQ,GAAG,CAAC,CAAA;QAC1D,OAAO,CAAC,CAAA;IACT,CAAC;IAED,KAAK,CAAkC,QAAgB;QACtD,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAI,QAAQ,CAAC,CAAA;IAC/C,CAAC;IAED,GAAG,CAAkC,QAAgB;QACpD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAI,QAAQ,CAAC,CAAC,CAAA;IAC9D,CAAC;IAED,MAAM,CAAC,GAAG,OAAkB;QAC3B,OAAO,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,OAAqB,CAAC,CAAA;IACnD,CAAC;IAED,KAAK;QACJ,OAAO,KAAK,CAAC,IAAI,CAAC,OAAsB,CAAC,CAAA;IAC1C,CAAC;CACD;AAID,MAAM,UAAU,GAAG,CAAsB,iBAA6B;IACrE,OAAO,CAAC,OAAO,iBAAiB,KAAK,QAAQ,CAAC;QAC7C,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,iBAAiB,CAAM;QAC3C,CAAC,CAAC,IAAI,GAAG,CAAC,iBAAiB,CAAC,CAAA;AAC9B,CAAC;AAED,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAA;AAC7B,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACzB,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACnC,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC/B,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAE3B,GAAG,CAAC,KAAK,GAAG,KAAK,CAAA;AACjB,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAA;AACvB,GAAG,CAAC,MAAM,GAAG,CAAC,SAAqB,EAAE,GAAG,OAAkB,EAAE,EAAE;IAC7D,OAAO,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;AAClC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dashify.js","sourceRoot":"","sources":["../../../s/dom/parts/dashify.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,KAAa;IACpC,OAAO,KAAK,CAAC,OAAO,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC,WAAW,EAAE,CAAA;AAClE,CAAC"}
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
[key: string]: {
|
|
3
|
-
new (...args: any[]): HTMLElement;
|
|
4
|
-
};
|
|
5
|
-
};
|
|
6
|
-
export type RegistrationOptions = {
|
|
7
|
-
soft: boolean;
|
|
8
|
-
upgrade: boolean;
|
|
9
|
-
};
|
|
1
|
+
import { HTMLElementClasses, RegisterOptions } from "../types.js";
|
|
10
2
|
/**
|
|
11
3
|
* register custom elements (web components) to the dom
|
|
12
4
|
* - takes an object full of custom html elements, and automatically dashes the names
|
|
@@ -19,4 +11,4 @@ export type RegistrationOptions = {
|
|
|
19
11
|
* - `true` (default) will run `customElements.upgrade` where appropriate
|
|
20
12
|
* - `false` will NOT upgrade any existing elements on the page
|
|
21
13
|
*/
|
|
22
|
-
export declare function register<E extends HTMLElementClasses>(elements: E, options?: Partial<
|
|
14
|
+
export declare function register<E extends HTMLElementClasses>(elements: E, options?: Partial<RegisterOptions>): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../../s/dom/parts/register.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAA;AAGpC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,QAAQ,CACtB,QAAW,EACX,UAAoC,EAAE;IAGvC,MAAM,EACL,IAAI,GAAG,KAAK,EACZ,OAAO,GAAG,IAAI,GACd,GAAG,OAAO,CAAA;IAEX,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACxD,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;QACzB,MAAM,OAAO,GAAG,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAEvC,IAAI,IAAI,IAAI,OAAO;YAClB,SAAQ;QAET,cAAc,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QAEnC,IAAI,OAAO;YACV,QAAQ,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;gBAChD,IAAI,OAAO,CAAC,WAAW,KAAK,WAAW;oBACtC,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;YACjC,CAAC,CAAC,CAAA;IACJ,CAAC;AACF,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { attrs } from "./attrs/attrs.js";
|
|
1
2
|
export type AttrKind = (typeof String | typeof Number | typeof Boolean);
|
|
2
3
|
export type AttrType<H extends AttrKind> = (H extends typeof String ? string | undefined : H extends typeof Number ? number | undefined : H extends typeof Boolean ? boolean : never);
|
|
3
4
|
export type AttrSpec = {
|
|
@@ -6,5 +7,13 @@ export type AttrSpec = {
|
|
|
6
7
|
export type AttrTypes<A extends AttrSpec> = {
|
|
7
8
|
[P in keyof A]: AttrType<A[P]>;
|
|
8
9
|
};
|
|
9
|
-
export
|
|
10
|
-
export
|
|
10
|
+
export type Attrs = ReturnType<typeof attrs>;
|
|
11
|
+
export type HTMLElementClasses = {
|
|
12
|
+
[key: string]: {
|
|
13
|
+
new (...args: any[]): HTMLElement;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export type RegisterOptions = {
|
|
17
|
+
soft: boolean;
|
|
18
|
+
upgrade: boolean;
|
|
19
|
+
};
|
package/x/dom/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../s/dom/types.ts"],"names":[],"mappings":""}
|
package/x/index.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
export * from "./dom/
|
|
2
|
-
export * from "./dom/dashify.js";
|
|
1
|
+
export * from "./dom/types.js";
|
|
3
2
|
export * from "./dom/dom.js";
|
|
4
|
-
export * from "./dom/register.js";
|
|
5
3
|
export * from "./ops/loaders/make-loader.js";
|
|
6
4
|
export * from "./ops/loaders/parts/ascii-anim.js";
|
|
7
5
|
export * from "./ops/loaders/parts/error-display.js";
|
|
@@ -9,7 +7,6 @@ export * from "./ops/op.js";
|
|
|
9
7
|
export * from "./ops/podium.js";
|
|
10
8
|
export * from "./ops/types.js";
|
|
11
9
|
export * as loot from "./loot/index.js";
|
|
12
|
-
export * from "./dom/attributes.js";
|
|
13
10
|
export * from "./views/base-element.js";
|
|
14
11
|
export * from "./views/css-reset.js";
|
|
15
12
|
export * from "./views/types.js";
|
package/x/index.html
CHANGED
|
@@ -111,7 +111,7 @@ body {
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
</style>
|
|
114
|
-
<script type=module src="demo/demo.bundle.min.js?v=
|
|
114
|
+
<script type=module src="demo/demo.bundle.min.js?v=19bcd292549b"></script>
|
|
115
115
|
<link rel="icon" href="assets/favicon.png?v=4dc161ed79b3"/>
|
|
116
116
|
|
|
117
117
|
<meta name="theme-color" content="#95ff7b">
|
|
@@ -131,9 +131,10 @@ body {
|
|
|
131
131
|
<img class=icon alt="" src="/assets/favicon.png"/>
|
|
132
132
|
<h1>sly testing page</h1>
|
|
133
133
|
<p><a href="https://github.com/e280/sly">github.com/e280/sly</a></p>
|
|
134
|
-
<p class=lil>v0.2.0-
|
|
134
|
+
<p class=lil>v0.2.0-9</p>
|
|
135
135
|
<incredi-element></incredi-element>
|
|
136
|
-
<
|
|
136
|
+
<divine-element></divine-element>
|
|
137
|
+
<demo-counter initial="-1">component</demo-counter>
|
|
137
138
|
<div class=demo></div>
|
|
138
139
|
|
|
139
140
|
</body>
|
package/x/index.html.js
CHANGED
|
@@ -25,7 +25,8 @@ export default ssg.page(import.meta.url, async (orb) => ({
|
|
|
25
25
|
<p><a href="https://github.com/e280/sly">github.com/e280/sly</a></p>
|
|
26
26
|
<p class=lil>v${orb.packageVersion()}</p>
|
|
27
27
|
<incredi-element></incredi-element>
|
|
28
|
-
<
|
|
28
|
+
<divine-element></divine-element>
|
|
29
|
+
<demo-counter initial="-1">component</demo-counter>
|
|
29
30
|
<div class=demo></div>
|
|
30
31
|
`,
|
|
31
32
|
}));
|
package/x/index.html.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.html.js","sourceRoot":"","sources":["../s/index.html.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAE,IAAI,EAAC,MAAM,aAAa,CAAA;AAErC,MAAM,KAAK,GAAG,KAAK,CAAA;AACnB,MAAM,WAAW,GAAG,0BAA0B,CAAA;AAC9C,MAAM,MAAM,GAAG,cAAc,CAAA;AAC7B,MAAM,OAAO,GAAG,qBAAqB,CAAA;AAErC,eAAe,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAC,GAAG,EAAC,EAAE,CAAC,CAAC;IACtD,KAAK;IACL,EAAE,EAAE,yBAAyB;IAC7B,GAAG,EAAE,eAAe;IACpB,OAAO;IACP,IAAI,EAAE,IAAI;IACV,UAAU,EAAE;QACX,UAAU,EAAE,SAAS;QACrB,KAAK;QACL,WAAW;QACX,QAAQ,EAAE,WAAW;QACrB,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,OAAO;KACpC;IAED,IAAI,EAAE,IAAI,CAAA;;EAET;IAED,IAAI,EAAE,IAAI,CAAA;;;;kBAIO,GAAG,CAAC,cAAc,EAAE
|
|
1
|
+
{"version":3,"file":"index.html.js","sourceRoot":"","sources":["../s/index.html.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAE,IAAI,EAAC,MAAM,aAAa,CAAA;AAErC,MAAM,KAAK,GAAG,KAAK,CAAA;AACnB,MAAM,WAAW,GAAG,0BAA0B,CAAA;AAC9C,MAAM,MAAM,GAAG,cAAc,CAAA;AAC7B,MAAM,OAAO,GAAG,qBAAqB,CAAA;AAErC,eAAe,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAC,GAAG,EAAC,EAAE,CAAC,CAAC;IACtD,KAAK;IACL,EAAE,EAAE,yBAAyB;IAC7B,GAAG,EAAE,eAAe;IACpB,OAAO;IACP,IAAI,EAAE,IAAI;IACV,UAAU,EAAE;QACX,UAAU,EAAE,SAAS;QACrB,KAAK;QACL,WAAW;QACX,QAAQ,EAAE,WAAW;QACrB,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,OAAO;KACpC;IAED,IAAI,EAAE,IAAI,CAAA;;EAET;IAED,IAAI,EAAE,IAAI,CAAA;;;;kBAIO,GAAG,CAAC,cAAc,EAAE;;;;;EAKpC;CACD,CAAC,CAAC,CAAA"}
|
package/x/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
export * from "./dom/
|
|
2
|
-
export * from "./dom/dashify.js";
|
|
1
|
+
export * from "./dom/types.js";
|
|
3
2
|
export * from "./dom/dom.js";
|
|
4
|
-
export * from "./dom/register.js";
|
|
5
3
|
export * from "./ops/loaders/make-loader.js";
|
|
6
4
|
export * from "./ops/loaders/parts/ascii-anim.js";
|
|
7
5
|
export * from "./ops/loaders/parts/error-display.js";
|
|
@@ -9,7 +7,6 @@ export * from "./ops/op.js";
|
|
|
9
7
|
export * from "./ops/podium.js";
|
|
10
8
|
export * from "./ops/types.js";
|
|
11
9
|
export * as loot from "./loot/index.js";
|
|
12
|
-
export * from "./dom/attributes.js";
|
|
13
10
|
export * from "./views/base-element.js";
|
|
14
11
|
export * from "./views/css-reset.js";
|
|
15
12
|
export * from "./views/types.js";
|
package/x/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../s/index.ts"],"names":[],"mappings":"AACA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../s/index.ts"],"names":[],"mappings":"AACA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAE5B,cAAc,8BAA8B,CAAA;AAC5C,cAAc,mCAAmC,CAAA;AACjD,cAAc,sCAAsC,CAAA;AACpD,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAE9B,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAA;AAEvC,cAAc,yBAAyB,CAAA;AACvC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA"}
|
package/x/views/base-element.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { debounce, MapG } from "@e280/stz";
|
|
1
|
+
import { debounce } from "@e280/stz";
|
|
3
2
|
import { dom } from "../dom/dom.js";
|
|
4
|
-
import {
|
|
3
|
+
import { Reactor } from "./utils/reactor.js";
|
|
5
4
|
import { applyStyles } from "./utils/apply-styles.js";
|
|
5
|
+
import { AttrWatcher } from "./utils/attr-watcher.js";
|
|
6
6
|
import { Use, _disconnect, _reconnect, _wrap } from "./use.js";
|
|
7
7
|
export class BaseElement extends HTMLElement {
|
|
8
8
|
static styles;
|
|
9
9
|
shadow;
|
|
10
10
|
#use;
|
|
11
11
|
#mounts = 0;
|
|
12
|
-
#
|
|
12
|
+
#reactor = new Reactor();
|
|
13
|
+
#attrWatcher = new AttrWatcher(this, () => this.update());
|
|
13
14
|
constructor() {
|
|
14
15
|
super();
|
|
15
16
|
this.shadow = this.attachShadow({ mode: "open" });
|
|
@@ -17,10 +18,7 @@ export class BaseElement extends HTMLElement {
|
|
|
17
18
|
}
|
|
18
19
|
updateNow = () => {
|
|
19
20
|
this.#use[_wrap](() => {
|
|
20
|
-
|
|
21
|
-
dom.render(this.shadow, result);
|
|
22
|
-
for (const item of seen)
|
|
23
|
-
this.#tracking.guarantee(item, () => tracker.subscribe(item, this.update));
|
|
21
|
+
dom.render(this.shadow, this.#reactor.effect(() => this.render(this.#use), this.update));
|
|
24
22
|
});
|
|
25
23
|
};
|
|
26
24
|
update = debounce(0, this.updateNow);
|
|
@@ -34,29 +32,13 @@ export class BaseElement extends HTMLElement {
|
|
|
34
32
|
else {
|
|
35
33
|
this.#use[_reconnect]();
|
|
36
34
|
}
|
|
37
|
-
this.#
|
|
35
|
+
this.#attrWatcher.start();
|
|
38
36
|
this.#mounts++;
|
|
39
37
|
}
|
|
40
38
|
disconnectedCallback() {
|
|
41
|
-
this.#attrListening.stop();
|
|
42
39
|
this.#use[_disconnect]();
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.#tracking.clear();
|
|
40
|
+
this.#reactor.clear();
|
|
41
|
+
this.#attrWatcher.stop();
|
|
46
42
|
}
|
|
47
|
-
#attrListening = (() => {
|
|
48
|
-
let stopper;
|
|
49
|
-
const start = () => {
|
|
50
|
-
if (stopper)
|
|
51
|
-
stopper();
|
|
52
|
-
stopper = onAttrChange(this, () => this.update);
|
|
53
|
-
};
|
|
54
|
-
const stop = () => {
|
|
55
|
-
if (stopper)
|
|
56
|
-
stopper();
|
|
57
|
-
stopper = undefined;
|
|
58
|
-
};
|
|
59
|
-
return { start, stop };
|
|
60
|
-
})();
|
|
61
43
|
}
|
|
62
44
|
//# sourceMappingURL=base-element.js.map
|