@e280/sly 0.0.0-1 → 0.0.0-2
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 +183 -3
- package/package.json +3 -5
- package/s/demo/demo.bundle.ts +49 -0
- package/s/demo/demo.css +6 -0
- package/s/features/dom/dashify.ts +11 -0
- package/s/features/dom/dollar.ts +21 -0
- package/s/features/dom/register.ts +48 -0
- package/s/features/dom/types.ts +5 -0
- package/s/features/loady/ascii-loader.ts +38 -0
- package/s/features/loady/parts/ascii-anim.ts +27 -0
- package/s/features/loady/parts/ascii-loader.ts +14 -0
- package/s/features/loady/parts/error-display.ts +26 -0
- package/s/features/op/op.ts +98 -0
- package/s/features/op/pod.ts +19 -0
- package/s/features/op/types.ts +12 -0
- package/s/features/views/css-reset.ts +21 -0
- package/s/features/views/types.ts +23 -0
- package/s/features/views/use.ts +75 -0
- package/s/features/views/utils/apply-attrs.ts +33 -0
- package/s/features/views/utils/apply-styles.ts +21 -0
- package/s/features/views/utils/mounts.ts +22 -0
- package/s/features/views/view.ts +98 -0
- package/s/index.html.ts +2 -1
- package/s/index.ts +18 -0
- package/x/demo/demo.bundle.d.ts +1 -0
- package/x/demo/demo.bundle.js +37 -1
- package/x/demo/demo.bundle.js.map +1 -1
- package/x/demo/demo.bundle.min.js +72 -1
- package/x/demo/demo.bundle.min.js.map +4 -4
- package/x/demo/demo.css +6 -0
- package/x/features/dom/dashify.d.ts +7 -0
- package/x/features/dom/dashify.js +10 -0
- package/x/features/dom/dashify.js.map +1 -0
- package/x/features/dom/dollar.d.ts +8 -0
- package/x/features/dom/dollar.js +15 -0
- package/x/features/dom/dollar.js.map +1 -0
- package/x/features/dom/register.d.ts +18 -0
- package/x/features/dom/register.js +29 -0
- package/x/features/dom/register.js.map +1 -0
- package/x/features/dom/types.d.ts +5 -0
- package/x/features/dom/types.js +2 -0
- package/x/features/dom/types.js.map +1 -0
- package/x/features/loady/ascii-loader.d.ts +5 -0
- package/x/features/loady/ascii-loader.js +33 -0
- package/x/features/loady/ascii-loader.js.map +1 -0
- package/x/features/loady/parts/ascii-anim.d.ts +8 -0
- package/x/features/loady/parts/ascii-anim.js +21 -0
- package/x/features/loady/parts/ascii-anim.js.map +1 -0
- package/x/features/loady/parts/ascii-loader.d.ts +3 -0
- package/x/features/loady/parts/ascii-loader.js +10 -0
- package/x/features/loady/parts/ascii-loader.js.map +1 -0
- package/x/features/loady/parts/error-display.d.ts +8 -0
- package/x/features/loady/parts/error-display.js +20 -0
- package/x/features/loady/parts/error-display.js.map +1 -0
- package/x/features/op/op.d.ts +21 -0
- package/x/features/op/op.js +79 -0
- package/x/features/op/op.js.map +1 -0
- package/x/features/op/pod.d.ts +5 -0
- package/x/features/op/pod.js +16 -0
- package/x/features/op/pod.js.map +1 -0
- package/x/features/op/types.d.ts +9 -0
- package/x/features/op/types.js +2 -0
- package/x/features/op/types.js.map +1 -0
- package/x/features/views/css-reset.d.ts +2 -0
- package/x/features/views/css-reset.js +19 -0
- package/x/features/views/css-reset.js.map +1 -0
- package/x/features/views/types.d.ts +16 -0
- package/x/features/views/types.js +2 -0
- package/x/features/views/types.js.map +1 -0
- package/x/features/views/use.d.ts +25 -0
- package/x/features/views/use.js +62 -0
- package/x/features/views/use.js.map +1 -0
- package/x/features/views/utils/apply-attrs.d.ts +2 -0
- package/x/features/views/utils/apply-attrs.js +21 -0
- package/x/features/views/utils/apply-attrs.js.map +1 -0
- package/x/features/views/utils/apply-styles.d.ts +2 -0
- package/x/features/views/utils/apply-styles.js +16 -0
- package/x/features/views/utils/apply-styles.js.map +1 -0
- package/x/features/views/utils/mounts.d.ts +6 -0
- package/x/features/views/utils/mounts.js +18 -0
- package/x/features/views/utils/mounts.js.map +1 -0
- package/x/features/views/view.d.ts +16 -0
- package/x/features/views/view.js +81 -0
- package/x/features/views/view.js.map +1 -0
- package/x/index.d.ts +13 -0
- package/x/index.html +10 -3
- package/x/index.html.js +2 -1
- package/x/index.html.js.map +1 -1
- package/x/index.js +13 -1
- package/x/index.js.map +1 -1
package/x/demo/demo.css
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a camel-case name into a dashed name
|
|
3
|
+
* - for example
|
|
4
|
+
* dashify("BigManStyle")
|
|
5
|
+
* // "big-man-style"
|
|
6
|
+
*/
|
|
7
|
+
export function dashify(camel) {
|
|
8
|
+
return camel.replace(/([a-zA-Z])(?=[A-Z])/g, '$1-').toLowerCase();
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=dashify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dashify.js","sourceRoot":"","sources":["../../../s/features/dom/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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const $: typeof one;
|
|
2
|
+
export type Queryable = HTMLElement | Document | ShadowRoot | Element;
|
|
3
|
+
declare function one<E extends HTMLElement = HTMLElement>(selector: string, context?: Queryable): E;
|
|
4
|
+
declare namespace one {
|
|
5
|
+
var maybe: <E extends HTMLElement = HTMLElement>(selector: string, context?: Queryable) => E | null;
|
|
6
|
+
var all: <E extends HTMLElement = HTMLElement>(selector: string, context?: Queryable) => E[];
|
|
7
|
+
}
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const $ = one;
|
|
2
|
+
function all(selector, context = document) {
|
|
3
|
+
return Array.from(context.querySelectorAll(selector));
|
|
4
|
+
}
|
|
5
|
+
function one(selector, context = document) {
|
|
6
|
+
const e = context.querySelector(selector);
|
|
7
|
+
if (!e)
|
|
8
|
+
throw new Error(`$1 ${selector} not found`);
|
|
9
|
+
return e;
|
|
10
|
+
}
|
|
11
|
+
one.maybe = (selector, context = document) => {
|
|
12
|
+
return context.querySelector(selector);
|
|
13
|
+
};
|
|
14
|
+
one.all = all;
|
|
15
|
+
//# sourceMappingURL=dollar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dollar.js","sourceRoot":"","sources":["../../../s/features/dom/dollar.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,CAAC,GAAG,GAAG,CAAA;AAIpB,SAAS,GAAG,CAAsC,QAAgB,EAAE,UAAqB,QAAQ;IAChG,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAI,QAAQ,CAAC,CAAC,CAAA;AACzD,CAAC;AAED,SAAS,GAAG,CAAsC,QAAgB,EAAE,UAAqB,QAAQ;IAChG,MAAM,CAAC,GAAG,OAAO,CAAC,aAAa,CAAI,QAAQ,CAAC,CAAA;IAC5C,IAAI,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,MAAM,QAAQ,YAAY,CAAC,CAAA;IACnD,OAAO,CAAC,CAAA;AACT,CAAC;AAED,GAAG,CAAC,KAAK,GAAG,CAAsC,QAAgB,EAAE,UAAqB,QAAQ,EAAE,EAAE;IACpG,OAAO,OAAO,CAAC,aAAa,CAAI,QAAQ,CAAC,CAAA;AAC1C,CAAC,CAAA;AAED,GAAG,CAAC,GAAG,GAAG,GAAG,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { HTMLElementClasses } from "./types.js";
|
|
2
|
+
export type RegistrationOptions = {
|
|
3
|
+
soft: boolean;
|
|
4
|
+
upgrade: boolean;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* register custom elements (web components) to the dom
|
|
8
|
+
* - takes an object full of custom html elements, and automatically dashes the names
|
|
9
|
+
* - eg, `MyCoolElement` is registered as `<my-cool-element></my-cool-element>`
|
|
10
|
+
* - calls `customElements.define`
|
|
11
|
+
* - option `soft`
|
|
12
|
+
* - `false` (default) will throw errors if elements are already defined
|
|
13
|
+
* - `true` will do nothing if an element is already defined
|
|
14
|
+
* - option `upgrade`
|
|
15
|
+
* - `true` (default) will run `customElements.upgrade` where appropriate
|
|
16
|
+
* - `false` will NOT upgrade any existing elements on the page
|
|
17
|
+
*/
|
|
18
|
+
export declare function register<E extends HTMLElementClasses>(elements: E, options?: Partial<RegistrationOptions>): void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { dashify } from "./dashify.js";
|
|
2
|
+
/**
|
|
3
|
+
* register custom elements (web components) to the dom
|
|
4
|
+
* - takes an object full of custom html elements, and automatically dashes the names
|
|
5
|
+
* - eg, `MyCoolElement` is registered as `<my-cool-element></my-cool-element>`
|
|
6
|
+
* - calls `customElements.define`
|
|
7
|
+
* - option `soft`
|
|
8
|
+
* - `false` (default) will throw errors if elements are already defined
|
|
9
|
+
* - `true` will do nothing if an element is already defined
|
|
10
|
+
* - option `upgrade`
|
|
11
|
+
* - `true` (default) will run `customElements.upgrade` where appropriate
|
|
12
|
+
* - `false` will NOT upgrade any existing elements on the page
|
|
13
|
+
*/
|
|
14
|
+
export function register(elements, options = {}) {
|
|
15
|
+
const { soft = false, upgrade = true, } = options;
|
|
16
|
+
for (const [name, Element] of Object.entries(elements)) {
|
|
17
|
+
const tag = dashify(name);
|
|
18
|
+
const already = customElements.get(tag);
|
|
19
|
+
if (soft && already)
|
|
20
|
+
continue;
|
|
21
|
+
customElements.define(tag, Element);
|
|
22
|
+
if (upgrade)
|
|
23
|
+
document.querySelectorAll(tag).forEach(element => {
|
|
24
|
+
if (element.constructor === HTMLElement)
|
|
25
|
+
customElements.upgrade(element);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../../s/features/dom/register.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAA;AAQpC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,QAAQ,CACtB,QAAW,EACX,UAAwC,EAAE;IAG3C,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../s/features/dom/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const loady: {
|
|
2
|
+
cylon: <V>(op: import("../op/op.js").Op<V>, fn: (value: V) => import("../views/types.js").Content) => string | void | HTMLElement | import("lit-html").TemplateResult | import("lit-html/directive.js").DirectiveResult<import("lit-html/directive.js").DirectiveClass> | null | undefined;
|
|
3
|
+
dots: <V>(op: import("../op/op.js").Op<V>, fn: (value: V) => import("../views/types.js").Content) => string | void | HTMLElement | import("lit-html").TemplateResult | import("lit-html/directive.js").DirectiveResult<import("lit-html/directive.js").DirectiveClass> | null | undefined;
|
|
4
|
+
binary: <V>(op: import("../op/op.js").Op<V>, fn: (value: V) => import("../views/types.js").Content) => string | void | HTMLElement | import("lit-html").TemplateResult | import("lit-html/directive.js").DirectiveResult<import("lit-html/directive.js").DirectiveClass> | null | undefined;
|
|
5
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { makeAsciiLoader } from "./parts/ascii-loader.js";
|
|
2
|
+
const hz = 15;
|
|
3
|
+
export const loady = {
|
|
4
|
+
cylon: makeAsciiLoader(hz, [
|
|
5
|
+
"=----",
|
|
6
|
+
"-=---",
|
|
7
|
+
"--=--",
|
|
8
|
+
"---=-",
|
|
9
|
+
"----=",
|
|
10
|
+
"-----",
|
|
11
|
+
"-----",
|
|
12
|
+
]),
|
|
13
|
+
dots: makeAsciiLoader(hz, [
|
|
14
|
+
":....",
|
|
15
|
+
"::...",
|
|
16
|
+
".::..",
|
|
17
|
+
"..::.",
|
|
18
|
+
"...::",
|
|
19
|
+
"....:",
|
|
20
|
+
".....",
|
|
21
|
+
".....",
|
|
22
|
+
]),
|
|
23
|
+
binary: makeAsciiLoader(hz, [
|
|
24
|
+
"01111",
|
|
25
|
+
"10111",
|
|
26
|
+
"11011",
|
|
27
|
+
"11101",
|
|
28
|
+
"11110",
|
|
29
|
+
"11111",
|
|
30
|
+
"11111",
|
|
31
|
+
]),
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=ascii-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ascii-loader.js","sourceRoot":"","sources":["../../../s/features/loady/ascii-loader.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAC,MAAM,yBAAyB,CAAC;AAExD,MAAM,EAAE,GAAG,EAAE,CAAA;AAEb,MAAM,CAAC,MAAM,KAAK,GAAG;IACpB,KAAK,EAAE,eAAe,CAAC,EAAE,EAAE;QAC1B,OAAO;QACP,OAAO;QACP,OAAO;QACP,OAAO;QACP,OAAO;QACP,OAAO;QACP,OAAO;KACP,CAAC;IAEF,IAAI,EAAE,eAAe,CAAC,EAAE,EAAE;QACzB,OAAO;QACP,OAAO;QACP,OAAO;QACP,OAAO;QACP,OAAO;QACP,OAAO;QACP,OAAO;QACP,OAAO;KACP,CAAC;IAEF,MAAM,EAAE,eAAe,CAAC,EAAE,EAAE;QAC3B,OAAO;QACP,OAAO;QACP,OAAO;QACP,OAAO;QACP,OAAO;QACP,OAAO;QACP,OAAO;KACP,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const AsciiAnim: {
|
|
2
|
+
(hz: number, anim: string[]): import("lit-html/directive.js").DirectiveResult<any>;
|
|
3
|
+
props: /*elided*/ any;
|
|
4
|
+
with(w2: Partial<import("../../views/types.js").ViewWith>): /*elided*/ any;
|
|
5
|
+
children(children: import("../../views/types.js").Content): /*elided*/ any;
|
|
6
|
+
attrs(attrs: Record<string, import("../../views/types.js").AttrValue>): /*elided*/ any;
|
|
7
|
+
attr(name: string, value: import("../../views/types.js").AttrValue): /*elided*/ any;
|
|
8
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { css } from "lit";
|
|
2
|
+
import { nap, repeat } from "@e280/stz";
|
|
3
|
+
import { view } from "../../views/view.js";
|
|
4
|
+
import { cssReset } from "../../views/css-reset.js";
|
|
5
|
+
const style = css `
|
|
6
|
+
:host {
|
|
7
|
+
font-family: monospace;
|
|
8
|
+
}
|
|
9
|
+
`;
|
|
10
|
+
export const AsciiAnim = view(use => (hz, anim) => {
|
|
11
|
+
use.name("loading");
|
|
12
|
+
use.styles(cssReset, style);
|
|
13
|
+
const frame = use.signal(0);
|
|
14
|
+
use.mount(() => repeat(async () => {
|
|
15
|
+
await nap(1000 / hz);
|
|
16
|
+
const next = frame() + 1;
|
|
17
|
+
frame(next >= anim.length ? 0 : next);
|
|
18
|
+
}));
|
|
19
|
+
return anim.at(frame());
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=ascii-anim.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ascii-anim.js","sourceRoot":"","sources":["../../../../s/features/loady/parts/ascii-anim.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAC,MAAM,KAAK,CAAA;AACvB,OAAO,EAAC,GAAG,EAAE,MAAM,EAAC,MAAM,WAAW,CAAA;AAErC,OAAO,EAAC,IAAI,EAAC,MAAM,qBAAqB,CAAA;AACxC,OAAO,EAAC,QAAQ,EAAC,MAAM,0BAA0B,CAAA;AAEjD,MAAM,KAAK,GAAG,GAAG,CAAA;;;;CAIhB,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,EAAU,EAAE,IAAc,EAAE,EAAE;IACnE,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IACnB,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;IAC3B,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IAE3B,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,IAAG,EAAE;QAChC,MAAM,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC,CAAA;QACpB,MAAM,IAAI,GAAG,KAAK,EAAE,GAAG,CAAC,CAAA;QACxB,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IACtC,CAAC,CAAC,CAAC,CAAA;IAEH,OAAO,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAA;AACxB,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Op } from "../../op/op.js";
|
|
2
|
+
import { Content } from "../../views/types.js";
|
|
3
|
+
export declare function makeAsciiLoader(hz: number, anim: string[]): <V>(op: Op<V>, fn: (value: V) => Content) => string | void | HTMLElement | import("lit-html").TemplateResult | import("lit-html/directive.js").DirectiveResult<import("lit-html/directive.js").DirectiveClass> | null | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AsciiAnim } from "./ascii-anim.js";
|
|
2
|
+
import { ErrorDisplay } from "./error-display.js";
|
|
3
|
+
export function makeAsciiLoader(hz, anim) {
|
|
4
|
+
return (op, fn) => op.select({
|
|
5
|
+
loading: () => AsciiAnim(hz, anim),
|
|
6
|
+
error: error => ErrorDisplay(error),
|
|
7
|
+
ready: fn,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=ascii-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ascii-loader.js","sourceRoot":"","sources":["../../../../s/features/loady/parts/ascii-loader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAA;AAEzC,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAA;AAE/C,MAAM,UAAU,eAAe,CAAC,EAAU,EAAE,IAAc;IACzD,OAAO,CAAI,EAAS,EAAE,EAAyB,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC;QAC7D,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,IAAI,CAAC;QAClC,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC;QACnC,KAAK,EAAE,EAAE;KACT,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const ErrorDisplay: {
|
|
2
|
+
(error: any): import("lit-html/directive.js").DirectiveResult<any>;
|
|
3
|
+
props: /*elided*/ any;
|
|
4
|
+
with(w2: Partial<import("../../views/types.js").ViewWith>): /*elided*/ any;
|
|
5
|
+
children(children: import("../../views/types.js").Content): /*elided*/ any;
|
|
6
|
+
attrs(attrs: Record<string, import("../../views/types.js").AttrValue>): /*elided*/ any;
|
|
7
|
+
attr(name: string, value: import("../../views/types.js").AttrValue): /*elided*/ any;
|
|
8
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { css, html } from "lit";
|
|
2
|
+
import { view } from "../../views/view.js";
|
|
3
|
+
import { cssReset } from "../../views/css-reset.js";
|
|
4
|
+
const style = css `
|
|
5
|
+
:host {
|
|
6
|
+
font-family: monospace;
|
|
7
|
+
color: red;
|
|
8
|
+
}
|
|
9
|
+
`;
|
|
10
|
+
export const ErrorDisplay = view(use => (error) => {
|
|
11
|
+
use.name("loading");
|
|
12
|
+
use.styles(cssReset, style);
|
|
13
|
+
if (typeof error === "string")
|
|
14
|
+
return error;
|
|
15
|
+
else if (error instanceof Error)
|
|
16
|
+
return html `<strong>${error.name}:</strong> <span>${error.message}</span>`;
|
|
17
|
+
else
|
|
18
|
+
return `error`;
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=error-display.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-display.js","sourceRoot":"","sources":["../../../../s/features/loady/parts/error-display.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAE,IAAI,EAAC,MAAM,KAAK,CAAA;AAC7B,OAAO,EAAC,IAAI,EAAC,MAAM,qBAAqB,CAAA;AACxC,OAAO,EAAC,QAAQ,EAAC,MAAM,0BAA0B,CAAA;AAEjD,MAAM,KAAK,GAAG,GAAG,CAAA;;;;;CAKhB,CAAA;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,KAAU,EAAE,EAAE;IACtD,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IACnB,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;IAE3B,IAAI,OAAO,KAAK,KAAK,QAAQ;QAC5B,OAAO,KAAK,CAAA;SAER,IAAI,KAAK,YAAY,KAAK;QAC9B,OAAO,IAAI,CAAA,WAAW,KAAK,CAAC,IAAI,oBAAoB,KAAK,CAAC,OAAO,SAAS,CAAA;;QAG1E,OAAO,OAAO,CAAA;AAChB,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Pod, PodSelect } from "./types.js";
|
|
2
|
+
export declare class Op<V> {
|
|
3
|
+
#private;
|
|
4
|
+
static loading(): Op<unknown>;
|
|
5
|
+
static ready<V>(value: V): Op<V>;
|
|
6
|
+
static error(error: any): Op<unknown>;
|
|
7
|
+
static promise<V>(promise: Promise<V>): Op<V>;
|
|
8
|
+
static fn<V>(fn: () => Promise<V>): Op<V>;
|
|
9
|
+
readonly signal: import("@e280/strata/signals").Signal<Pod<V>>;
|
|
10
|
+
get wait(): Promise<unknown>;
|
|
11
|
+
setLoading(): Promise<void>;
|
|
12
|
+
setReady(value: V): Promise<void>;
|
|
13
|
+
setError(error: any): Promise<void>;
|
|
14
|
+
promise(promise: Promise<V>): Promise<V | undefined>;
|
|
15
|
+
fn(fn: () => Promise<V>): Promise<V | undefined>;
|
|
16
|
+
get pod(): Pod<V>;
|
|
17
|
+
get status(): "loading" | "ready" | "error";
|
|
18
|
+
get value(): V | undefined;
|
|
19
|
+
require(): V;
|
|
20
|
+
select<R>(select: PodSelect<V, R>): R;
|
|
21
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { pub } from "@e280/stz";
|
|
2
|
+
import { signal } from "@e280/strata/signals";
|
|
3
|
+
import { pod } from "./pod.js";
|
|
4
|
+
export class Op {
|
|
5
|
+
static loading() {
|
|
6
|
+
return new this();
|
|
7
|
+
}
|
|
8
|
+
static ready(value) {
|
|
9
|
+
const op = new this();
|
|
10
|
+
op.signal(["ready", value]);
|
|
11
|
+
return op;
|
|
12
|
+
}
|
|
13
|
+
static error(error) {
|
|
14
|
+
const op = new this();
|
|
15
|
+
op.signal(["error", error]);
|
|
16
|
+
return op;
|
|
17
|
+
}
|
|
18
|
+
static promise(promise) {
|
|
19
|
+
const op = new this();
|
|
20
|
+
op.promise(promise);
|
|
21
|
+
return op;
|
|
22
|
+
}
|
|
23
|
+
static fn(fn) {
|
|
24
|
+
return this.promise(fn());
|
|
25
|
+
}
|
|
26
|
+
signal = signal(["loading"]);
|
|
27
|
+
#resolve = pub();
|
|
28
|
+
#reject = pub();
|
|
29
|
+
get wait() {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
this.#resolve.next().then(resolve);
|
|
32
|
+
this.#reject.next().then(reject);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
async setLoading() {
|
|
36
|
+
await this.signal(["loading"]);
|
|
37
|
+
}
|
|
38
|
+
async setReady(value) {
|
|
39
|
+
await this.signal(["ready", value]);
|
|
40
|
+
await this.#resolve(value);
|
|
41
|
+
}
|
|
42
|
+
async setError(error) {
|
|
43
|
+
await this.signal(["error", error]);
|
|
44
|
+
await this.#reject(error);
|
|
45
|
+
}
|
|
46
|
+
async promise(promise) {
|
|
47
|
+
await this.setLoading();
|
|
48
|
+
try {
|
|
49
|
+
const value = await promise;
|
|
50
|
+
await this.setReady(value);
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
await this.setError(error);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async fn(fn) {
|
|
58
|
+
return this.promise(fn());
|
|
59
|
+
}
|
|
60
|
+
get pod() {
|
|
61
|
+
return this.signal();
|
|
62
|
+
}
|
|
63
|
+
get status() {
|
|
64
|
+
return this.signal()[0];
|
|
65
|
+
}
|
|
66
|
+
get value() {
|
|
67
|
+
return pod.value(this.signal());
|
|
68
|
+
}
|
|
69
|
+
require() {
|
|
70
|
+
const pod = this.signal();
|
|
71
|
+
if (pod[0] !== "ready")
|
|
72
|
+
throw new Error("required value not ready");
|
|
73
|
+
return pod[1];
|
|
74
|
+
}
|
|
75
|
+
select(select) {
|
|
76
|
+
return pod.select(this.signal(), select);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sour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AAE,CAAC,CAAC,CAAC,CAAA;IACxB,CAAC;IAED,IAAI,KAAK;QACR,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;IAChC,CAAC;IAED,OAAO;QACN,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,CAAA;QACzB,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;QACnE,OAAO,GAAG,CAAC,CAAC,CAAC,CAAA;IACd,CAAC;IAED,MAAM,CAAI,MAAuB;QAChC,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,CAAA;IACzC,CAAC;CACD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const pod = {
|
|
2
|
+
value: (pod) => {
|
|
3
|
+
return pod[0] === "ready"
|
|
4
|
+
? pod[1]
|
|
5
|
+
: undefined;
|
|
6
|
+
},
|
|
7
|
+
select: (pod, select) => {
|
|
8
|
+
switch (pod[0]) {
|
|
9
|
+
case "loading": return select.loading();
|
|
10
|
+
case "error": return select.error(pod[1]);
|
|
11
|
+
case "ready": return select.ready(pod[1]);
|
|
12
|
+
default: throw new Error("unknown op status");
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=pod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pod.js","sourceRoot":"","sources":["../../../s/features/op/pod.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,GAAG,GAAG;IAClB,KAAK,EAAE,CAAI,GAAW,EAAE,EAAE;QACzB,OAAO,GAAG,CAAC,CAAC,CAAC,KAAK,OAAO;YACxB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACR,CAAC,CAAC,SAAS,CAAA;IACb,CAAC;IACD,MAAM,EAAE,CAAO,GAAW,EAAE,MAAuB,EAAE,EAAE;QACtD,QAAQ,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YAChB,KAAK,SAAS,CAAC,CAAC,OAAO,MAAM,CAAC,OAAO,EAAE,CAAA;YACvC,KAAK,OAAO,CAAC,CAAC,OAAO,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;YACzC,KAAK,OAAO,CAAC,CAAC,OAAO,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;YACzC,OAAO,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;QAC9C,CAAC;IACF,CAAC;CACD,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type PodLoading = [status: "loading"];
|
|
2
|
+
export type PodReady<V> = [status: "ready", value: V];
|
|
3
|
+
export type PodError = [status: "error", error: any];
|
|
4
|
+
export type Pod<V> = PodLoading | PodReady<V> | PodError;
|
|
5
|
+
export type PodSelect<V, R> = {
|
|
6
|
+
loading: () => R;
|
|
7
|
+
ready: (value: V) => R;
|
|
8
|
+
error: (error: any) => R;
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../s/features/op/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { css } from "lit";
|
|
2
|
+
export const cssReset = css `
|
|
3
|
+
@layer reset {
|
|
4
|
+
* {
|
|
5
|
+
margin: 0;
|
|
6
|
+
padding: 0;
|
|
7
|
+
box-sizing: border-box;
|
|
8
|
+
|
|
9
|
+
scrollbar-width: thin;
|
|
10
|
+
scrollbar-color: #888 transparent;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
::-webkit-scrollbar { width: 8px; }
|
|
14
|
+
::-webkit-scrollbar-track { background: transparent; }
|
|
15
|
+
::-webkit-scrollbar-thumb { background: #333; border-radius: 1em; }
|
|
16
|
+
::-webkit-scrollbar-thumb:hover { background: #444; }
|
|
17
|
+
}
|
|
18
|
+
`;
|
|
19
|
+
//# sourceMappingURL=css-reset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-reset.js","sourceRoot":"","sources":["../../../s/features/views/css-reset.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAiB,MAAM,KAAK,CAAA;AAEvC,MAAM,CAAC,MAAM,QAAQ,GAAmB,GAAG,CAAA;;;;;;;;;;;;;;;;CAgB1C,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DirectiveResult } from "lit/directive.js";
|
|
2
|
+
import { CSSResultGroup, TemplateResult } from "lit";
|
|
3
|
+
import { Use } from "./use.js";
|
|
4
|
+
export type Content = TemplateResult | DirectiveResult | HTMLElement | string | null | undefined | void;
|
|
5
|
+
export type AttrValue = string | boolean | number | undefined | null | void;
|
|
6
|
+
export type ViewFn<Props extends any[]> = (use: Use) => (...props: Props) => Content;
|
|
7
|
+
export type View<Props extends any[]> = (...props: Props) => DirectiveResult<any>;
|
|
8
|
+
export type ViewSettings = ShadowRootInit & {
|
|
9
|
+
tag?: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
styles?: CSSResultGroup;
|
|
12
|
+
};
|
|
13
|
+
export type ViewWith = {
|
|
14
|
+
children: Content;
|
|
15
|
+
attrs: Record<string, AttrValue>;
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../s/features/views/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CSSResultGroup } from "lit";
|
|
2
|
+
import { Op } from "../op/op.js";
|
|
3
|
+
export declare const _wrap: unique symbol;
|
|
4
|
+
export declare const _disconnect: unique symbol;
|
|
5
|
+
export declare const _reconnect: unique symbol;
|
|
6
|
+
export declare class Use {
|
|
7
|
+
#private;
|
|
8
|
+
element: HTMLElement;
|
|
9
|
+
shadow: ShadowRoot;
|
|
10
|
+
[_wrap](fn: () => void): void;
|
|
11
|
+
[_disconnect](): void;
|
|
12
|
+
[_reconnect](): void;
|
|
13
|
+
constructor(element: HTMLElement, shadow: ShadowRoot);
|
|
14
|
+
get renderCount(): number;
|
|
15
|
+
get rendered(): Promise<void>;
|
|
16
|
+
once<V>(fn: () => V): V;
|
|
17
|
+
styles(...styles: CSSResultGroup[]): void;
|
|
18
|
+
name(name: string): void;
|
|
19
|
+
signal<V>(value: V): import("@e280/strata/signals").Signal<V>;
|
|
20
|
+
mount(mount: () => () => void): void;
|
|
21
|
+
op: {
|
|
22
|
+
promise: <V>(p: Promise<V>) => Op<V>;
|
|
23
|
+
fn: <V>(f: () => Promise<V>) => Op<V>;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { defer, MapG } from "@e280/stz";
|
|
2
|
+
import { signal } from "@e280/strata/signals";
|
|
3
|
+
import { Op } from "../op/op.js";
|
|
4
|
+
import { Mounts } from "./utils/mounts.js";
|
|
5
|
+
import { applyStyles } from "./utils/apply-styles.js";
|
|
6
|
+
export const _wrap = Symbol();
|
|
7
|
+
export const _disconnect = Symbol();
|
|
8
|
+
export const _reconnect = Symbol();
|
|
9
|
+
export class Use {
|
|
10
|
+
element;
|
|
11
|
+
shadow;
|
|
12
|
+
#runs = 0;
|
|
13
|
+
#position = 0;
|
|
14
|
+
#values = new MapG();
|
|
15
|
+
#rendered = defer();
|
|
16
|
+
#mounts = new Mounts();
|
|
17
|
+
[_wrap](fn) {
|
|
18
|
+
this.#runs++;
|
|
19
|
+
this.#position = 0;
|
|
20
|
+
this.#rendered = defer();
|
|
21
|
+
fn();
|
|
22
|
+
this.#rendered.resolve();
|
|
23
|
+
}
|
|
24
|
+
;
|
|
25
|
+
[_disconnect]() {
|
|
26
|
+
this.#mounts.unmountAll();
|
|
27
|
+
}
|
|
28
|
+
;
|
|
29
|
+
[_reconnect]() {
|
|
30
|
+
this.#mounts.remountAll();
|
|
31
|
+
}
|
|
32
|
+
constructor(element, shadow) {
|
|
33
|
+
this.element = element;
|
|
34
|
+
this.shadow = shadow;
|
|
35
|
+
}
|
|
36
|
+
get renderCount() {
|
|
37
|
+
return this.#runs;
|
|
38
|
+
}
|
|
39
|
+
get rendered() {
|
|
40
|
+
return this.#rendered.promise;
|
|
41
|
+
}
|
|
42
|
+
once(fn) {
|
|
43
|
+
return this.#values.guarantee(this.#position++, fn);
|
|
44
|
+
}
|
|
45
|
+
styles(...styles) {
|
|
46
|
+
this.once(() => applyStyles(this.shadow, styles));
|
|
47
|
+
}
|
|
48
|
+
name(name) {
|
|
49
|
+
this.once(() => this.element.setAttribute("view", name));
|
|
50
|
+
}
|
|
51
|
+
signal(value) {
|
|
52
|
+
return this.once(() => signal(value));
|
|
53
|
+
}
|
|
54
|
+
mount(mount) {
|
|
55
|
+
return this.once(() => this.#mounts.mount(mount));
|
|
56
|
+
}
|
|
57
|
+
op = {
|
|
58
|
+
promise: (p) => this.once(() => Op.promise(p)),
|
|
59
|
+
fn: (f) => this.once(() => Op.fn(f)),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=use.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use.js","sourceRoot":"","sources":["../../../s/features/views/use.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,KAAK,EAAE,IAAI,EAAC,MAAM,WAAW,CAAA;AACrC,OAAO,EAAC,MAAM,EAAC,MAAM,sBAAsB,CAAA;AAE3C,OAAO,EAAC,EAAE,EAAC,MAAM,aAAa,CAAA;AAC9B,OAAO,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAC,WAAW,EAAC,MAAM,yBAAyB,CAAA;AAEnD,MAAM,CAAC,MAAM,KAAK,GAAG,MAAM,EAAE,CAAA;AAC7B,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,EA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A;IAClD,CAAC;IAED,IAAI,CAAC,IAAY;QAChB,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAA;IACzD,CAAC;IAED,MAAM,CAAI,KAAQ;QACjB,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAI,KAAK,CAAC,CAAC,CAAA;IACzC,CAAC;IAED,KAAK,CAAC,KAAuB;QAC5B,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;IAClD,CAAC;IAED,EAAE,GAAG;QACJ,OAAO,EAAE,CAAI,CAAa,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC7D,EAAE,EAAE,CAAI,CAAmB,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;KACzD,CAAA;CACD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function applyAttrs(element, attrs) {
|
|
2
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
3
|
+
if (value === undefined)
|
|
4
|
+
element.removeAttribute(key);
|
|
5
|
+
else if (value === null)
|
|
6
|
+
element.removeAttribute(key);
|
|
7
|
+
else if (typeof value === "string")
|
|
8
|
+
element.setAttribute(key, value);
|
|
9
|
+
else if (typeof value === "number")
|
|
10
|
+
element.setAttribute(key, value.toString());
|
|
11
|
+
else if (typeof value === "boolean") {
|
|
12
|
+
if (value === true)
|
|
13
|
+
element.setAttribute(key, "");
|
|
14
|
+
else
|
|
15
|
+
element.removeAttribute(key);
|
|
16
|
+
}
|
|
17
|
+
else
|
|
18
|
+
console.warn(`invalid attribute type ${key} is ${typeof value}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=apply-attrs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-attrs.js","sourceRoot":"","sources":["../../../../s/features/views/utils/apply-attrs.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,UAAU,CACxB,OAAoB,EACpB,KAAgC;IAGjC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAClD,IAAI,KAAK,KAAK,SAAS;YACtB,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA;aAExB,IAAI,KAAK,KAAK,IAAI;YACtB,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA;aAExB,IAAI,OAAO,KAAK,KAAK,QAAQ;YACjC,OAAO,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;aAE5B,IAAI,OAAO,KAAK,KAAK,QAAQ;YACjC,OAAO,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAA;aAEvC,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;YACrC,IAAI,KAAK,KAAK,IAAI;gBACjB,OAAO,CAAC,YAAY,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;;gBAE7B,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA;QAC9B,CAAC;;YAGA,OAAO,CAAC,IAAI,CAAC,0BAA0B,GAAG,OAAO,OAAO,KAAK,EAAE,CAAC,CAAA;IAClE,CAAC;AACF,CAAC"}
|