sinho 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +24 -0
- package/.github/workflows/deploy-docs.yml +47 -0
- package/.prettierrc +3 -0
- package/LICENSE.md +21 -0
- package/README.md +33 -0
- package/ci/check-size.js +8 -0
- package/dist/array_mutation.d.ts +16 -0
- package/dist/array_mutation.js +75 -0
- package/dist/array_mutation.js.map +1 -0
- package/dist/bundle.d.ts +1126 -0
- package/dist/bundle.js +1074 -0
- package/dist/bundle.min.js +1 -0
- package/dist/component.d.ts +253 -0
- package/dist/component.js +256 -0
- package/dist/component.js.map +1 -0
- package/dist/context.d.ts +21 -0
- package/dist/context.js +34 -0
- package/dist/context.js.map +1 -0
- package/dist/create_element.d.ts +43 -0
- package/dist/create_element.js +43 -0
- package/dist/create_element.js.map +1 -0
- package/dist/dom.d.ts +602 -0
- package/dist/dom.js +97 -0
- package/dist/dom.js.map +1 -0
- package/dist/intrinsic/ClassComponent.d.ts +2 -0
- package/dist/intrinsic/ClassComponent.js +10 -0
- package/dist/intrinsic/ClassComponent.js.map +1 -0
- package/dist/intrinsic/Dynamic.d.ts +33 -0
- package/dist/intrinsic/Dynamic.js +53 -0
- package/dist/intrinsic/Dynamic.js.map +1 -0
- package/dist/intrinsic/ErrorBoundary.d.ts +14 -0
- package/dist/intrinsic/ErrorBoundary.js +36 -0
- package/dist/intrinsic/ErrorBoundary.js.map +1 -0
- package/dist/intrinsic/For.d.ts +10 -0
- package/dist/intrinsic/For.js +81 -0
- package/dist/intrinsic/For.js.map +1 -0
- package/dist/intrinsic/Fragment.d.ts +23 -0
- package/dist/intrinsic/Fragment.js +28 -0
- package/dist/intrinsic/Fragment.js.map +1 -0
- package/dist/intrinsic/If.d.ts +24 -0
- package/dist/intrinsic/If.js +47 -0
- package/dist/intrinsic/If.js.map +1 -0
- package/dist/intrinsic/Portal.d.ts +6 -0
- package/dist/intrinsic/Portal.js +15 -0
- package/dist/intrinsic/Portal.js.map +1 -0
- package/dist/intrinsic/Style.d.ts +7 -0
- package/dist/intrinsic/Style.js +70 -0
- package/dist/intrinsic/Style.js.map +1 -0
- package/dist/intrinsic/TagComponent.d.ts +4 -0
- package/dist/intrinsic/TagComponent.js +67 -0
- package/dist/intrinsic/TagComponent.js.map +1 -0
- package/dist/intrinsic/Text.d.ts +6 -0
- package/dist/intrinsic/Text.js +16 -0
- package/dist/intrinsic/Text.js.map +1 -0
- package/dist/intrinsic/mod.d.ts +5 -0
- package/dist/intrinsic/mod.js +6 -0
- package/dist/intrinsic/mod.js.map +1 -0
- package/dist/jsx-runtime/mod.d.ts +23 -0
- package/dist/jsx-runtime/mod.js +11 -0
- package/dist/jsx-runtime/mod.js.map +1 -0
- package/dist/mod.d.ts +8 -0
- package/dist/mod.js +7 -0
- package/dist/mod.js.map +1 -0
- package/dist/renderer.d.ts +13 -0
- package/dist/renderer.js +25 -0
- package/dist/renderer.js.map +1 -0
- package/dist/scope.d.ts +138 -0
- package/dist/scope.js +228 -0
- package/dist/scope.js.map +1 -0
- package/dist/template.d.ts +10 -0
- package/dist/template.js +7 -0
- package/dist/template.js.map +1 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +13 -0
- package/dist/utils.js.map +1 -0
- package/package.json +71 -0
- package/src/array_mutation.ts +118 -0
- package/src/component.ts +624 -0
- package/src/context.ts +70 -0
- package/src/create_element.ts +89 -0
- package/src/dom.ts +819 -0
- package/src/intrinsic/ClassComponent.ts +17 -0
- package/src/intrinsic/For.ts +122 -0
- package/src/intrinsic/Fragment.ts +38 -0
- package/src/intrinsic/If.ts +73 -0
- package/src/intrinsic/Portal.ts +25 -0
- package/src/intrinsic/Style.ts +120 -0
- package/src/intrinsic/TagComponent.ts +102 -0
- package/src/intrinsic/Text.ts +24 -0
- package/src/intrinsic/mod.ts +5 -0
- package/src/jsx-runtime/mod.ts +41 -0
- package/src/mod.ts +37 -0
- package/src/renderer.ts +45 -0
- package/src/scope.ts +404 -0
- package/src/template.ts +16 -0
- package/src/utils.ts +29 -0
- package/terser.config.json +16 -0
- package/tsconfig.json +18 -0
- package/web/README.md +41 -0
- package/web/babel.config.js +3 -0
- package/web/dist/shingo.min.d.ts +1131 -0
- package/web/dist/shingo.min.js +1 -0
- package/web/docusaurus.config.ts +151 -0
- package/web/package-lock.json +14850 -0
- package/web/package.json +54 -0
- package/web/sidebars.ts +31 -0
- package/web/src/components/monacoEditor.tsx +72 -0
- package/web/src/components/playground.tsx +89 -0
- package/web/src/components/playgroundComponent.tsx +168 -0
- package/web/src/css/custom.css +37 -0
- package/web/src/pages/index.module.css +31 -0
- package/web/src/pages/index.tsx +73 -0
- package/web/src/pages/playground.tsx +64 -0
- package/web/static/.nojekyll +0 -0
- package/web/static/dist/bundle.d.ts +1126 -0
- package/web/static/dist/bundle.min.js +1 -0
- package/web/tsconfig.json +8 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { setAttr, setStyle } from "../dom.js";
|
|
2
|
+
import { jsxPropNameToEventName } from "../utils.js";
|
|
3
|
+
import { MaybeSignal, useBatch, useEffect, useScope } from "../scope.js";
|
|
4
|
+
import { Fragment } from "./Fragment.js";
|
|
5
|
+
import { runWithRenderer, useRenderer } from "../renderer.js";
|
|
6
|
+
import { createTemplate } from "../template.js";
|
|
7
|
+
export const hydrateElement = (node, svg, props, heuristic) => {
|
|
8
|
+
const { ref, style, children, dangerouslySetInnerHTML, ...attrs } = props;
|
|
9
|
+
for (const name in style ?? {}) {
|
|
10
|
+
const value = style[name];
|
|
11
|
+
const signal = value;
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
setStyle(node, name, MaybeSignal.get(signal));
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
for (const name in attrs) {
|
|
17
|
+
const value = attrs[name];
|
|
18
|
+
if (name.startsWith("on")) {
|
|
19
|
+
// Register event
|
|
20
|
+
const s = useScope();
|
|
21
|
+
const listener = (evt) => {
|
|
22
|
+
s._run(() => useBatch(() => value(evt)));
|
|
23
|
+
};
|
|
24
|
+
const eventName = jsxPropNameToEventName(name);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
node.addEventListener(eventName, listener);
|
|
27
|
+
return () => node.removeEventListener(eventName, listener);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
// Set attribute
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
setAttr(node, name, MaybeSignal.get(value), heuristic);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (dangerouslySetInnerHTML) {
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
const html = MaybeSignal.get(dangerouslySetInnerHTML).__html;
|
|
40
|
+
if (node.innerHTML != html) {
|
|
41
|
+
node.innerHTML = html;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (ref) {
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
ref.set(node);
|
|
48
|
+
return () => ref.set(undefined);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (props.children != null) {
|
|
52
|
+
node.append(...runWithRenderer({
|
|
53
|
+
_svg: svg,
|
|
54
|
+
_nodes: node.childNodes.values(),
|
|
55
|
+
}, () => Fragment({ children: props.children }).build()));
|
|
56
|
+
}
|
|
57
|
+
return node;
|
|
58
|
+
};
|
|
59
|
+
export const TagComponent = (tagName, props = {}) => createTemplate(() => {
|
|
60
|
+
const renderer = useRenderer();
|
|
61
|
+
const svg = tagName == "svg" ? true : !!renderer._svg;
|
|
62
|
+
const node = hydrateElement(renderer._node(() => !svg
|
|
63
|
+
? document.createElement(tagName)
|
|
64
|
+
: document.createElementNS("http://www.w3.org/2000/svg", tagName)), svg, props, true);
|
|
65
|
+
return [node];
|
|
66
|
+
});
|
|
67
|
+
//# sourceMappingURL=TagComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TagComponent.js","sourceRoot":"","sources":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AC,UAAU,CAAC,MAAM,EAAE;SACjC,EACD,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,CACrD,CACF,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,OAAe,EACf,QAAuB,EAAE,EACf,EAAE,CACZ,cAAc,CAAC,GAAG,EAAE;IAClB,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,MAAM,GAAG,GAAG,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;IACtD,MAAM,IAAI,GAAG,cAAc,CACzB,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,CAClB,CAAC,GAAG;QACF,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC;QACjC,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,4BAA4B,EAAE,OAAO,CAAC,CACpE,EACD,GAAG,EACH,KAAK,EACL,IAAI,CACL,CAAC;IAEF,OAAO,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { MaybeSignal, useEffect } from "../scope.js";
|
|
2
|
+
import { useRenderer } from "../renderer.js";
|
|
3
|
+
import { createTemplate } from "../template.js";
|
|
4
|
+
export const Text = ({ text, marker }) => createTemplate(() => {
|
|
5
|
+
const renderer = useRenderer();
|
|
6
|
+
const anchor = marker && renderer._node(() => document.createComment(""));
|
|
7
|
+
const node = renderer._node(() => document.createTextNode(""));
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const textContent = "" + (MaybeSignal.get(text) ?? "");
|
|
10
|
+
if (node.textContent != textContent) {
|
|
11
|
+
node.textContent = textContent;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return anchor ? [anchor, node] : [node];
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=Text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Text.js","sourceRoot":"","sources":["../../src/intrinsic/Text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAW,MAAM,aAAa,CAAC;AAE9D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,CAAC,MAAM,IAAI,GAGZ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CACxB,cAAc,CAAC,GAAG,EAAE;IAClB,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,MAAM,MAAM,GAAG,MAAM,IAAI,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1E,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC;IAE/D,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,WAAW,GAAG,EAAE,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAEvD,IAAI,IAAI,CAAC,WAAW,IAAI,WAAW,EAAE,CAAC;YACpC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QACjC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAC1C,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/intrinsic/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAiB,QAAQ,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Template } from "../template.js";
|
|
2
|
+
import type { DomEventProps, DomIntrinsicElements, DomProps } from "../dom.js";
|
|
3
|
+
import type { jsxPropsSym } from "../component.js";
|
|
4
|
+
/** @ignore */
|
|
5
|
+
export declare const jsx: (type: any, props?: (object & {
|
|
6
|
+
key?: unknown;
|
|
7
|
+
}) | undefined, key?: unknown) => Template;
|
|
8
|
+
/** @ignore */
|
|
9
|
+
export declare namespace JSX {
|
|
10
|
+
type Element = Template;
|
|
11
|
+
type ElementClass = Omit<HTMLElement, typeof jsxPropsSym>;
|
|
12
|
+
interface ElementAttributesProperty {
|
|
13
|
+
[jsxPropsSym]: {};
|
|
14
|
+
}
|
|
15
|
+
interface ElementChildrenAttribute {
|
|
16
|
+
children: {};
|
|
17
|
+
}
|
|
18
|
+
type IntrinsicElements = DomIntrinsicElements;
|
|
19
|
+
interface IntrinsicClassAttributes<T> extends DomProps<T>, DomEventProps<T> {
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export { Fragment } from "../intrinsic/Fragment.js";
|
|
23
|
+
export { jsx as jsxDEV, jsx as jsxs };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createElement } from "../create_element.js";
|
|
2
|
+
/** @ignore */
|
|
3
|
+
export const jsx = (type, props, key) => {
|
|
4
|
+
if (props && key != null) {
|
|
5
|
+
props.key = key;
|
|
6
|
+
}
|
|
7
|
+
return createElement(type, props);
|
|
8
|
+
};
|
|
9
|
+
export { Fragment } from "../intrinsic/Fragment.js";
|
|
10
|
+
export { jsx as jsxDEV, jsx as jsxs };
|
|
11
|
+
//# sourceMappingURL=mod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/jsx-runtime/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAKrD,cAAc;AACd,MAAM,CAAC,MAAM,GAAG,GAAG,CACjB,IAAS,EACT,KAAkC,EAClC,GAAa,EACH,EAAE;IACZ,IAAI,KAAK,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QACzB,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC;IAClB,CAAC;IAED,OAAO,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACpC,CAAC,CAAC;AAuBF,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,GAAG,IAAI,MAAM,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC"}
|
package/dist/mod.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { type AttributeOptions, Component, type ComponentConstructor, type ComponentOptions, defineComponents, event, type EventConstructor, type FunctionalComponent, isComponent, type Metadata, prop, type PropOptions, useMountEffect as useEffect, } from "./component.js";
|
|
2
|
+
export { type Context, createContext, useContext } from "./context.js";
|
|
3
|
+
export { createElement, h } from "./create_element.js";
|
|
4
|
+
export { DangerousHtml, Styles } from "./dom.js";
|
|
5
|
+
export { type Template } from "./template.js";
|
|
6
|
+
export { type Cleanup, MaybeSignal, type SetSignalOptions, type Signal, type SignalLike, type SignalSetter, type SubscopeOptions, type RefSignal, type RefSignalSetter, useBatch, useMemo, useSignal, useRef, } from "./scope.js";
|
|
7
|
+
export * from "./intrinsic/mod.js";
|
|
8
|
+
export * from "./jsx-runtime/mod.js";
|
package/dist/mod.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Component, defineComponents, event, isComponent, prop, useMountEffect as useEffect, } from "./component.js";
|
|
2
|
+
export { createContext, useContext } from "./context.js";
|
|
3
|
+
export { createElement, h } from "./create_element.js";
|
|
4
|
+
export { MaybeSignal, useBatch, useMemo, useSignal, useRef, } from "./scope.js";
|
|
5
|
+
export * from "./intrinsic/mod.js";
|
|
6
|
+
export * from "./jsx-runtime/mod.js";
|
|
7
|
+
//# sourceMappingURL=mod.js.map
|
package/dist/mod.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,SAAS,EAGT,gBAAgB,EAChB,KAAK,EAGL,WAAW,EAEX,IAAI,EAEJ,cAAc,IAAI,SAAS,GAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAgB,aAAa,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAC;AAGvD,OAAO,EAEL,WAAW,EAQX,QAAQ,EACR,OAAO,EACP,SAAS,EACT,MAAM,GACP,MAAM,YAAY,CAAC;AAEpB,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Component } from "./component.js";
|
|
2
|
+
import { Signal } from "./scope.js";
|
|
3
|
+
interface Renderer {
|
|
4
|
+
_component?: Component;
|
|
5
|
+
_svg?: boolean;
|
|
6
|
+
_nodes?: IterableIterator<Node>;
|
|
7
|
+
_ifConditions: Signal<boolean | undefined>[];
|
|
8
|
+
_node<N extends Node>(fallback: () => N): N;
|
|
9
|
+
}
|
|
10
|
+
type RendererOverrides = Partial<Omit<Renderer, "_node">>;
|
|
11
|
+
export declare const useRenderer: () => Renderer;
|
|
12
|
+
export declare const runWithRenderer: <T>(override: RendererOverrides, fn: () => T) => T;
|
|
13
|
+
export {};
|
package/dist/renderer.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useEffect, useScope, useSubscope } from "./scope.js";
|
|
2
|
+
const createRenderer = (override = {}) => ({
|
|
3
|
+
_ifConditions: [],
|
|
4
|
+
_node(fallback) {
|
|
5
|
+
return this._nodes?.next().value ?? fallback();
|
|
6
|
+
},
|
|
7
|
+
...override,
|
|
8
|
+
});
|
|
9
|
+
export const useRenderer = () => {
|
|
10
|
+
const scope = useScope();
|
|
11
|
+
return (scope._details._renderer ??= createRenderer());
|
|
12
|
+
};
|
|
13
|
+
export const runWithRenderer = (override, fn) => {
|
|
14
|
+
const currRenderer = useRenderer();
|
|
15
|
+
const _renderer = createRenderer({
|
|
16
|
+
...currRenderer,
|
|
17
|
+
...override,
|
|
18
|
+
});
|
|
19
|
+
const [result, destroy] = useSubscope(fn, {
|
|
20
|
+
details: { _renderer },
|
|
21
|
+
});
|
|
22
|
+
useEffect(() => destroy);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAatE,MAAM,cAAc,GAAG,CAAC,WAA8B,EAAE,EAAY,EAAE,CAAC,CAAC;IACtE,aAAa,EAAE,EAAE;IACjB,KAAK,CAAiB,QAAiB;QACrC,OAAQ,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,KAAuB,IAAI,QAAQ,EAAE,CAAC;IACpE,CAAC;IACD,GAAG,QAAQ;CACZ,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE;IAC9B,MAAM,KAAK,GAAG,QAAQ,EAA4B,CAAC;IACnD,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,KAAK,cAAc,EAAE,CAAC,CAAC;AACzD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,QAA2B,EAC3B,EAAW,EACR,EAAE;IACL,MAAM,YAAY,GAAG,WAAW,EAAE,CAAC;IACnC,MAAM,SAAS,GAAG,cAAc,CAAC;QAC/B,GAAG,YAAY;QACf,GAAG,QAAQ;KACZ,CAAC,CAAC;IAEH,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,WAAW,CAAC,EAAE,EAAE;QACxC,OAAO,EAAE,EAAE,SAAS,EAAE;KACvB,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC;IAEzB,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
package/dist/scope.d.ts
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a signal-based computation.
|
|
3
|
+
*/
|
|
4
|
+
export interface SignalLike<out T> {
|
|
5
|
+
/**
|
|
6
|
+
* Gets the current value of the signal with tracking by default.
|
|
7
|
+
*/
|
|
8
|
+
(): T;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Represents a value that tracks changes over time.
|
|
12
|
+
*/
|
|
13
|
+
export interface Signal<out T> extends SignalLike<T> {
|
|
14
|
+
/** @ignore */
|
|
15
|
+
_effects: Set<Effect>;
|
|
16
|
+
/**
|
|
17
|
+
* Accesses the current value of the signal without tracking.
|
|
18
|
+
*/
|
|
19
|
+
peek(): T;
|
|
20
|
+
}
|
|
21
|
+
export interface SetSignalOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Whether to force the update of the signal even if the new value has the
|
|
24
|
+
* same reference.
|
|
25
|
+
*/
|
|
26
|
+
force?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Whether to suppress the update of the signal's effects.
|
|
29
|
+
*/
|
|
30
|
+
silent?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Can be used to update a signal with a new value.
|
|
34
|
+
*/
|
|
35
|
+
export interface SignalSetter<in T, out U = T> {
|
|
36
|
+
(update: (value: U) => T, opts?: SetSignalOptions): void;
|
|
37
|
+
(value: T extends Function ? never : T, opts?: SetSignalOptions): void;
|
|
38
|
+
}
|
|
39
|
+
export interface SubscopeOptions {
|
|
40
|
+
details?: object;
|
|
41
|
+
}
|
|
42
|
+
interface Effect {
|
|
43
|
+
_clean?: Cleanup;
|
|
44
|
+
_deps: Set<Signal<unknown>>;
|
|
45
|
+
_scope: Scope;
|
|
46
|
+
_run(): void;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Represents the cleanup function of an effect.
|
|
50
|
+
*/
|
|
51
|
+
export type Cleanup = (() => void) | void | undefined | null;
|
|
52
|
+
export interface Scope<out T = {}> {
|
|
53
|
+
readonly _parent?: Scope;
|
|
54
|
+
_effects: Effect[];
|
|
55
|
+
_subscopes: Scope[];
|
|
56
|
+
_details: T;
|
|
57
|
+
_run<T>(fn: () => T): T;
|
|
58
|
+
_cleanup(): void;
|
|
59
|
+
}
|
|
60
|
+
/** @ignore */
|
|
61
|
+
export declare const useScope: <T = {}>() => Scope<T>;
|
|
62
|
+
/**
|
|
63
|
+
* Creates a new signal with the given value.
|
|
64
|
+
* @returns A tuple with the signal and its setter.
|
|
65
|
+
*/
|
|
66
|
+
export declare const useSignal: (<T>(value: T, opts?: SetSignalOptions) => readonly [Signal<T>, SignalSetter<T>]) & (<T>(value?: T, opts?: SetSignalOptions) => readonly [Signal<T | undefined>, SignalSetter<T | undefined>]);
|
|
67
|
+
/**
|
|
68
|
+
* Runs the given function in a batch.
|
|
69
|
+
*
|
|
70
|
+
* @param fn Any calls to signal setters inside the function will be batched
|
|
71
|
+
* and updated at the same time.
|
|
72
|
+
*/
|
|
73
|
+
export declare const useBatch: <T>(fn: () => T) => T;
|
|
74
|
+
/**
|
|
75
|
+
* Creates an effect which will rerun when any accessed signal changes.
|
|
76
|
+
*
|
|
77
|
+
* @param fn The function to run; it can return a cleanup function.
|
|
78
|
+
*/
|
|
79
|
+
export declare const useEffect: (fn: () => Cleanup, deps?: SignalLike<unknown>[]) => void;
|
|
80
|
+
/**
|
|
81
|
+
* Creates a memoized signal.
|
|
82
|
+
*
|
|
83
|
+
* @param fn The computation function.
|
|
84
|
+
*/
|
|
85
|
+
export declare const useMemo: <T>(fn: () => T, opts?: SetSignalOptions) => Signal<T>;
|
|
86
|
+
/**
|
|
87
|
+
* Executes a function inside a subscope which can be manually destroyed.
|
|
88
|
+
*
|
|
89
|
+
* @param fn The function to run in the subscope.
|
|
90
|
+
* @returns A function to manually destroy the subscope.
|
|
91
|
+
*/
|
|
92
|
+
export declare const useSubscope: <T>(fn: () => T, opts?: SubscopeOptions) => [T, () => void];
|
|
93
|
+
/**
|
|
94
|
+
* Provide write capabilities to a signal.
|
|
95
|
+
*/
|
|
96
|
+
export interface RefSignal<in out T> extends Signal<T>, RefSignalSetter<T> {
|
|
97
|
+
/**
|
|
98
|
+
* Sets the value of the signal.
|
|
99
|
+
*/
|
|
100
|
+
set: SignalSetter<T>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* A contravariant variant of {@link RefSignal}.
|
|
104
|
+
*/
|
|
105
|
+
export interface RefSignalSetter<in T> {
|
|
106
|
+
/**
|
|
107
|
+
* Sets the value of the signal.
|
|
108
|
+
*/
|
|
109
|
+
set: SignalSetter<T, unknown>;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Creates a new signal with write capabilities.
|
|
113
|
+
*/
|
|
114
|
+
export declare const useRef: (<T>(value: T, opts?: SetSignalOptions) => RefSignal<T>) & (<T>(value?: T, opts?: SetSignalOptions) => RefSignal<T | undefined>);
|
|
115
|
+
/**
|
|
116
|
+
* Represents a value that can be a signal or a constant value.
|
|
117
|
+
*
|
|
118
|
+
* Note that functions are not allowed as constant values.
|
|
119
|
+
*/
|
|
120
|
+
export type MaybeSignal<T> = SignalLike<T> | (T extends Function ? never : T);
|
|
121
|
+
/**
|
|
122
|
+
* @namespace
|
|
123
|
+
*/
|
|
124
|
+
export declare const MaybeSignal: {
|
|
125
|
+
/**
|
|
126
|
+
* Transforms the given {@link MaybeSignal} into a {@link Signal}.
|
|
127
|
+
*/
|
|
128
|
+
upgrade: <T>(signal: MaybeSignal<T>) => SignalLike<T>;
|
|
129
|
+
/**
|
|
130
|
+
* Gets the value of the given {@link MaybeSignal}.
|
|
131
|
+
*/
|
|
132
|
+
get: <T_1>(signal: MaybeSignal<T_1>) => T_1;
|
|
133
|
+
/**
|
|
134
|
+
* Accesses the value of the given {@link MaybeSignal} without tracking.
|
|
135
|
+
*/
|
|
136
|
+
peek<T_2>(signal: MaybeSignal<T_2>): T_2;
|
|
137
|
+
};
|
|
138
|
+
export {};
|
package/dist/scope.js
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
const createScope = (parent) => {
|
|
2
|
+
return {
|
|
3
|
+
_parent: parent,
|
|
4
|
+
_effects: [],
|
|
5
|
+
_subscopes: [],
|
|
6
|
+
_details: { ...parent?._details },
|
|
7
|
+
_run(fn) {
|
|
8
|
+
const prevScope = currScope;
|
|
9
|
+
currScope = this;
|
|
10
|
+
try {
|
|
11
|
+
return fn();
|
|
12
|
+
}
|
|
13
|
+
finally {
|
|
14
|
+
currScope = prevScope;
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
_cleanup() {
|
|
18
|
+
for (let i = this._subscopes.length - 1; i >= 0; i--) {
|
|
19
|
+
this._subscopes[i]._cleanup();
|
|
20
|
+
}
|
|
21
|
+
this._subscopes = [];
|
|
22
|
+
for (let i = this._effects.length - 1; i >= 0; i--) {
|
|
23
|
+
const effect = this._effects[i];
|
|
24
|
+
effect._clean?.();
|
|
25
|
+
effect._deps.forEach((signal) => signal._effects.delete(effect));
|
|
26
|
+
effect._deps.clear();
|
|
27
|
+
}
|
|
28
|
+
this._effects = [];
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
let rootScope = createScope();
|
|
33
|
+
let currScope = rootScope;
|
|
34
|
+
let currUntracked = false;
|
|
35
|
+
let currEffect;
|
|
36
|
+
let currBatch;
|
|
37
|
+
/** @ignore */
|
|
38
|
+
export const useScope = () => currScope;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new signal with the given value.
|
|
41
|
+
* @returns A tuple with the signal and its setter.
|
|
42
|
+
*/
|
|
43
|
+
export const useSignal = (value, opts) => {
|
|
44
|
+
const signal = () => {
|
|
45
|
+
if (!currUntracked && currEffect) {
|
|
46
|
+
currEffect._deps.add(signal);
|
|
47
|
+
signal._effects.add(currEffect);
|
|
48
|
+
}
|
|
49
|
+
return signal.peek();
|
|
50
|
+
};
|
|
51
|
+
signal._effects = new Set();
|
|
52
|
+
signal.peek = () => value;
|
|
53
|
+
const setter = (arg, innerOpts) => {
|
|
54
|
+
innerOpts = { ...opts, ...innerOpts };
|
|
55
|
+
if (currBatch) {
|
|
56
|
+
const newValue = typeof arg == "function"
|
|
57
|
+
? arg(signal.peek())
|
|
58
|
+
: arg;
|
|
59
|
+
if (innerOpts?.force || newValue !== signal.peek()) {
|
|
60
|
+
if (innerOpts?.force) {
|
|
61
|
+
value = newValue;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
currBatch._setters.push(() => (value = newValue));
|
|
65
|
+
}
|
|
66
|
+
if (!innerOpts?.silent) {
|
|
67
|
+
signal._effects.forEach((effect) => currBatch._effects.add(effect));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
useBatch(() => setter(arg, innerOpts));
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
return [signal, setter];
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Runs the given function in a batch.
|
|
79
|
+
*
|
|
80
|
+
* @param fn Any calls to signal setters inside the function will be batched
|
|
81
|
+
* and updated at the same time.
|
|
82
|
+
*/
|
|
83
|
+
export const useBatch = (fn) => {
|
|
84
|
+
const prevBatch = currBatch;
|
|
85
|
+
currBatch = { _setters: [], _effects: new Set() };
|
|
86
|
+
try {
|
|
87
|
+
const result = fn();
|
|
88
|
+
while (currBatch._setters.length > 0 || currBatch._effects.size > 0) {
|
|
89
|
+
// Clean effect subscope
|
|
90
|
+
const effects = currBatch._effects;
|
|
91
|
+
currBatch._effects = new Set();
|
|
92
|
+
effects.forEach((effect) => effect._clean?.());
|
|
93
|
+
// Run signal updates
|
|
94
|
+
currBatch._setters.forEach((setter) => setter());
|
|
95
|
+
currBatch._setters = [];
|
|
96
|
+
// Run effects
|
|
97
|
+
effects.forEach((effect) => effect._run());
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
currBatch = prevBatch;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Creates an effect which will rerun when any accessed signal changes.
|
|
107
|
+
*
|
|
108
|
+
* @param fn The function to run; it can return a cleanup function.
|
|
109
|
+
*/
|
|
110
|
+
export const useEffect = (fn, deps) => {
|
|
111
|
+
const untracked = !!deps;
|
|
112
|
+
const effect = {
|
|
113
|
+
_scope: currScope,
|
|
114
|
+
_deps: new Set(),
|
|
115
|
+
_run() {
|
|
116
|
+
const prevEffect = currEffect;
|
|
117
|
+
const prevUntracked = currUntracked;
|
|
118
|
+
currEffect = this;
|
|
119
|
+
try {
|
|
120
|
+
if (!deps) {
|
|
121
|
+
// For automatic dependency tracking
|
|
122
|
+
// clean up dependencies and listeners
|
|
123
|
+
this._deps.forEach((dep) => dep._effects.delete(this));
|
|
124
|
+
this._deps.clear();
|
|
125
|
+
}
|
|
126
|
+
else if (!this._deps.size) {
|
|
127
|
+
// Track specified dependencies
|
|
128
|
+
deps.forEach((dep) => dep());
|
|
129
|
+
}
|
|
130
|
+
// Run effect
|
|
131
|
+
currUntracked = untracked;
|
|
132
|
+
this._clean?.();
|
|
133
|
+
const cleanup = this._scope._run(() => useBatch(fn));
|
|
134
|
+
this._clean = !cleanup
|
|
135
|
+
? null
|
|
136
|
+
: () => {
|
|
137
|
+
this._scope._run(() => useBatch(cleanup));
|
|
138
|
+
this._clean = null;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
finally {
|
|
142
|
+
// Restore scope state
|
|
143
|
+
currEffect = prevEffect;
|
|
144
|
+
currUntracked = prevUntracked;
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
effect._deps.forEach((signal) => signal._effects.add(effect));
|
|
149
|
+
currScope._effects.push(effect);
|
|
150
|
+
effect._run();
|
|
151
|
+
if (!effect._deps.size && !effect._clean) {
|
|
152
|
+
// Optimization: Destroy effect since there's no cleanup and this effect
|
|
153
|
+
// won't be called again
|
|
154
|
+
currScope._effects.pop();
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Creates a memoized signal.
|
|
159
|
+
*
|
|
160
|
+
* @param fn The computation function.
|
|
161
|
+
*/
|
|
162
|
+
export const useMemo = (fn, opts) => {
|
|
163
|
+
const [memo, setMemo] = useSignal();
|
|
164
|
+
let firstTime = true;
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
setMemo(fn, firstTime ? { ...opts, force: true } : opts);
|
|
167
|
+
firstTime = false;
|
|
168
|
+
});
|
|
169
|
+
return memo;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Executes a function inside a subscope which can be manually destroyed.
|
|
173
|
+
*
|
|
174
|
+
* @param fn The function to run in the subscope.
|
|
175
|
+
* @returns A function to manually destroy the subscope.
|
|
176
|
+
*/
|
|
177
|
+
export const useSubscope = (fn, opts) => {
|
|
178
|
+
const parent = currScope;
|
|
179
|
+
const scope = createScope(parent);
|
|
180
|
+
Object.assign(scope._details, opts?.details);
|
|
181
|
+
parent._subscopes.push(scope);
|
|
182
|
+
const result = scope._run(fn);
|
|
183
|
+
return [
|
|
184
|
+
result,
|
|
185
|
+
() => {
|
|
186
|
+
const index = parent._subscopes.indexOf(scope);
|
|
187
|
+
if (index >= 0) {
|
|
188
|
+
parent._subscopes.splice(index, 1);
|
|
189
|
+
}
|
|
190
|
+
scope._cleanup();
|
|
191
|
+
},
|
|
192
|
+
];
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Creates a new signal with write capabilities.
|
|
196
|
+
*/
|
|
197
|
+
export const useRef = (value, opts) => {
|
|
198
|
+
const [signal, setter] = useSignal(value, opts);
|
|
199
|
+
signal.set = setter;
|
|
200
|
+
return signal;
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* @namespace
|
|
204
|
+
*/
|
|
205
|
+
export const MaybeSignal = {
|
|
206
|
+
/**
|
|
207
|
+
* Transforms the given {@link MaybeSignal} into a {@link Signal}.
|
|
208
|
+
*/
|
|
209
|
+
upgrade: (signal) => () => MaybeSignal.get(signal),
|
|
210
|
+
/**
|
|
211
|
+
* Gets the value of the given {@link MaybeSignal}.
|
|
212
|
+
*/
|
|
213
|
+
get: (signal) => typeof signal == "function" ? signal() : signal,
|
|
214
|
+
/**
|
|
215
|
+
* Accesses the value of the given {@link MaybeSignal} without tracking.
|
|
216
|
+
*/
|
|
217
|
+
peek(signal) {
|
|
218
|
+
const prevUntracked = currUntracked;
|
|
219
|
+
currUntracked = true;
|
|
220
|
+
try {
|
|
221
|
+
return this.get(signal);
|
|
222
|
+
}
|
|
223
|
+
finally {
|
|
224
|
+
currUntracked = prevUntracked;
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
//# sourceMappingURL=scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAsEA,MAAM,WAAW,GAAG,CAAC,MAAc,EAAS,EAAE;IAC5C,OAAO;QACL,OAAO,EAAE,MAAM;QACf,QAAQ,EAAE,EAAE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IAEpE;;OAEG;IACH,IAAI,CAAI,MAAsB;QAC5B,MAAM,aAAa,GAAG,aAAa,CAAC;QACpC,aAAa,GAAG,IAAI,CAAC;QAErB,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC;gBAAS,CAAC;YACT,aAAa,GAAG,aAAa,CAAC;QAChC,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a render result of a component.
|
|
3
|
+
*/
|
|
4
|
+
export interface Template {
|
|
5
|
+
/**
|
|
6
|
+
* Build the DOM elements represented by this template.
|
|
7
|
+
*/
|
|
8
|
+
build(): Node[];
|
|
9
|
+
}
|
|
10
|
+
export declare const createTemplate: (build: () => Template | Node[]) => Template;
|
package/dist/template.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../src/template.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAA8B,EAAY,EAAE,CAAC,CAAC;IAC3E,KAAK;QACH,MAAM,KAAK,GAAG,KAAK,EAAE,CAAC;QACtB,OAAQ,KAAkB,CAAC,KAAK,EAAE,EAAE,IAAI,KAAK,CAAC;IAChD,CAAC;CACF,CAAC,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type RemoveOn<S extends string> = S extends `on${infer R}` ? Uncapitalize<R> : never;
|
|
2
|
+
export type CamelCaseToKebabCase<S extends string> = S extends `${infer F}${infer R}` ? F extends Lowercase<F> ? `${F}${CamelCaseToKebabCase<R>}` : `-${Lowercase<F>}${CamelCaseToKebabCase<R>}` : Lowercase<S>;
|
|
3
|
+
export declare const camelCaseToKebabCase: (value: string) => string;
|
|
4
|
+
export type JsxPropNameToEventName<S extends string> = CamelCaseToKebabCase<RemoveOn<S>>;
|
|
5
|
+
export declare const jsxPropNameToEventName: (value: `on${string}`) => string;
|
|
6
|
+
export {};
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const camelCaseToKebabCase = (value) => {
|
|
2
|
+
return ((value[0] ?? "").toLowerCase() +
|
|
3
|
+
value.slice(1).replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`));
|
|
4
|
+
};
|
|
5
|
+
export const jsxPropNameToEventName = (value) => {
|
|
6
|
+
if (value.startsWith("on:")) {
|
|
7
|
+
return value.slice(3);
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
return camelCaseToKebabCase(value.slice(2));
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAa,EAAU,EAAE;IAC5D,OAAO,CACL,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE;QAC9B,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAC/D,CAAC;AACJ,CAAC,CAAC;AAMF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,KAAoB,EAAU,EAAE;IACrE,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACxB,CAAC;SAAM,CAAC;QACN,OAAO,oBAAoB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,CAAC;AACH,CAAC,CAAC"}
|