@vigla/svelte 0.0.0-stage → 5.57.3
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/action.d.ts +2 -0
- package/animate.d.ts +2 -0
- package/compiler/index.js +43266 -0
- package/compiler/index.js.map +1 -0
- package/compiler/package.json +3 -0
- package/compiler.d.ts +2 -0
- package/dist/compiler/diagnostics.d.ts +70 -0
- package/dist/compiler/diagnostics.d.ts.map +1 -0
- package/dist/compiler/diagnostics.js +166 -0
- package/dist/compiler/diagnostics.js.map +1 -0
- package/dist/compiler/index.d.ts +72 -0
- package/dist/compiler/index.d.ts.map +1 -0
- package/dist/compiler/index.js +178 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/options.d.ts +7 -0
- package/dist/compiler/options.d.ts.map +1 -0
- package/dist/compiler/options.js +126 -0
- package/dist/compiler/options.js.map +1 -0
- package/dist/compiler/preprocess/decode.d.ts +3 -0
- package/dist/compiler/preprocess/decode.d.ts.map +1 -0
- package/dist/compiler/preprocess/decode.js +60 -0
- package/dist/compiler/preprocess/decode.js.map +1 -0
- package/dist/compiler/preprocess/index.d.ts +27 -0
- package/dist/compiler/preprocess/index.d.ts.map +1 -0
- package/dist/compiler/preprocess/index.js +208 -0
- package/dist/compiler/preprocess/index.js.map +1 -0
- package/dist/compiler/preprocess/mapped.d.ts +25 -0
- package/dist/compiler/preprocess/mapped.d.ts.map +1 -0
- package/dist/compiler/preprocess/mapped.js +129 -0
- package/dist/compiler/preprocess/mapped.js.map +1 -0
- package/dist/compiler/proxy.d.ts +3 -0
- package/dist/compiler/proxy.d.ts.map +1 -0
- package/dist/compiler/proxy.js +133 -0
- package/dist/compiler/proxy.js.map +1 -0
- package/dist/entries/action.d.ts +2 -0
- package/dist/entries/action.d.ts.map +1 -0
- package/dist/entries/action.js +1 -0
- package/dist/entries/action.js.map +1 -0
- package/dist/entries/animate.d.ts +2 -0
- package/dist/entries/animate.d.ts.map +1 -0
- package/dist/entries/animate.js +2 -0
- package/dist/entries/animate.js.map +1 -0
- package/dist/entries/attachments.d.ts +2 -0
- package/dist/entries/attachments.d.ts.map +1 -0
- package/dist/entries/attachments.js +2 -0
- package/dist/entries/attachments.js.map +1 -0
- package/dist/entries/context.d.ts +15 -0
- package/dist/entries/context.d.ts.map +1 -0
- package/dist/entries/context.js +32 -0
- package/dist/entries/context.js.map +1 -0
- package/dist/entries/easing.d.ts +2 -0
- package/dist/entries/easing.d.ts.map +1 -0
- package/dist/entries/easing.js +2 -0
- package/dist/entries/easing.js.map +1 -0
- package/dist/entries/events.d.ts +2 -0
- package/dist/entries/events.d.ts.map +1 -0
- package/dist/entries/events.js +2 -0
- package/dist/entries/events.js.map +1 -0
- package/dist/entries/index-server.d.ts +4 -0
- package/dist/entries/index-server.d.ts.map +1 -0
- package/dist/entries/index-server.js +11 -0
- package/dist/entries/index-server.js.map +1 -0
- package/dist/entries/index.d.ts +10 -0
- package/dist/entries/index.d.ts.map +1 -0
- package/dist/entries/index.js +24 -0
- package/dist/entries/index.js.map +1 -0
- package/dist/entries/internal/client.d.ts +4 -0
- package/dist/entries/internal/client.d.ts.map +1 -0
- package/dist/entries/internal/client.js +9 -0
- package/dist/entries/internal/client.js.map +1 -0
- package/dist/entries/internal/disclose-version.d.ts +2 -0
- package/dist/entries/internal/disclose-version.d.ts.map +1 -0
- package/dist/entries/internal/disclose-version.js +4 -0
- package/dist/entries/internal/disclose-version.js.map +1 -0
- package/dist/entries/internal/index.d.ts +2 -0
- package/dist/entries/internal/index.d.ts.map +1 -0
- package/dist/entries/internal/index.js +2 -0
- package/dist/entries/internal/index.js.map +1 -0
- package/dist/entries/internal/server.d.ts +2 -0
- package/dist/entries/internal/server.d.ts.map +1 -0
- package/dist/entries/internal/server.js +7 -0
- package/dist/entries/internal/server.js.map +1 -0
- package/dist/entries/internal/tracing.d.ts +2 -0
- package/dist/entries/internal/tracing.d.ts.map +1 -0
- package/dist/entries/internal/tracing.js +2 -0
- package/dist/entries/internal/tracing.js.map +1 -0
- package/dist/entries/motion-server.d.ts +2 -0
- package/dist/entries/motion-server.d.ts.map +1 -0
- package/dist/entries/motion-server.js +2 -0
- package/dist/entries/motion-server.js.map +1 -0
- package/dist/entries/motion.d.ts +2 -0
- package/dist/entries/motion.d.ts.map +1 -0
- package/dist/entries/motion.js +2 -0
- package/dist/entries/motion.js.map +1 -0
- package/dist/entries/proxy.d.ts +6 -0
- package/dist/entries/proxy.d.ts.map +1 -0
- package/dist/entries/proxy.js +77 -0
- package/dist/entries/proxy.js.map +1 -0
- package/dist/entries/reactivity-server.d.ts +2 -0
- package/dist/entries/reactivity-server.d.ts.map +1 -0
- package/dist/entries/reactivity-server.js +2 -0
- package/dist/entries/reactivity-server.js.map +1 -0
- package/dist/entries/reactivity.d.ts +2 -0
- package/dist/entries/reactivity.d.ts.map +1 -0
- package/dist/entries/reactivity.js +2 -0
- package/dist/entries/reactivity.js.map +1 -0
- package/dist/entries/report.d.ts +3 -0
- package/dist/entries/report.d.ts.map +1 -0
- package/dist/entries/report.js +66 -0
- package/dist/entries/report.js.map +1 -0
- package/dist/entries/server.d.ts +8 -0
- package/dist/entries/server.d.ts.map +1 -0
- package/dist/entries/server.js +48 -0
- package/dist/entries/server.js.map +1 -0
- package/dist/entries/store-client.d.ts +12 -0
- package/dist/entries/store-client.d.ts.map +1 -0
- package/dist/entries/store-client.js +63 -0
- package/dist/entries/store-client.js.map +1 -0
- package/dist/entries/store-server.d.ts +12 -0
- package/dist/entries/store-server.d.ts.map +1 -0
- package/dist/entries/store-server.js +30 -0
- package/dist/entries/store-server.js.map +1 -0
- package/dist/entries/store.d.ts +25 -0
- package/dist/entries/store.d.ts.map +1 -0
- package/dist/entries/store.js +139 -0
- package/dist/entries/store.js.map +1 -0
- package/dist/entries/transition.d.ts +2 -0
- package/dist/entries/transition.d.ts.map +1 -0
- package/dist/entries/transition.js +2 -0
- package/dist/entries/transition.js.map +1 -0
- package/dist/entries/window-server.d.ts +2 -0
- package/dist/entries/window-server.d.ts.map +1 -0
- package/dist/entries/window-server.js +2 -0
- package/dist/entries/window-server.js.map +1 -0
- package/dist/entries/window.d.ts +2 -0
- package/dist/entries/window.d.ts.map +1 -0
- package/dist/entries/window.js +2 -0
- package/dist/entries/window.js.map +1 -0
- package/dist/front/ast.d.ts +290 -0
- package/dist/front/ast.d.ts.map +1 -0
- package/dist/front/ast.js +1 -0
- package/dist/front/ast.js.map +1 -0
- package/dist/front/diagnostics.d.ts +13 -0
- package/dist/front/diagnostics.d.ts.map +1 -0
- package/dist/front/diagnostics.js +38 -0
- package/dist/front/diagnostics.js.map +1 -0
- package/dist/front/ignores.d.ts +12 -0
- package/dist/front/ignores.d.ts.map +1 -0
- package/dist/front/ignores.js +75 -0
- package/dist/front/ignores.js.map +1 -0
- package/dist/front/index.d.ts +17 -0
- package/dist/front/index.d.ts.map +1 -0
- package/dist/front/index.js +65 -0
- package/dist/front/index.js.map +1 -0
- package/dist/front/legacy.d.ts +5 -0
- package/dist/front/legacy.d.ts.map +1 -0
- package/dist/front/legacy.js +408 -0
- package/dist/front/legacy.js.map +1 -0
- package/dist/front/locate.d.ts +4 -0
- package/dist/front/locate.d.ts.map +1 -0
- package/dist/front/locate.js +19 -0
- package/dist/front/locate.js.map +1 -0
- package/dist/front/lower.d.ts +39 -0
- package/dist/front/lower.d.ts.map +1 -0
- package/dist/front/lower.js +470 -0
- package/dist/front/lower.js.map +1 -0
- package/dist/front/parse/attribute.d.ts +12 -0
- package/dist/front/parse/attribute.d.ts.map +1 -0
- package/dist/front/parse/attribute.js +288 -0
- package/dist/front/parse/attribute.js.map +1 -0
- package/dist/front/parse/bracket.d.ts +3 -0
- package/dist/front/parse/bracket.d.ts.map +1 -0
- package/dist/front/parse/bracket.js +102 -0
- package/dist/front/parse/bracket.js.map +1 -0
- package/dist/front/parse/characters.d.ts +4 -0
- package/dist/front/parse/characters.d.ts.map +1 -0
- package/dist/front/parse/characters.js +6 -0
- package/dist/front/parse/characters.js.map +1 -0
- package/dist/front/parse/decode.d.ts +2 -0
- package/dist/front/parse/decode.d.ts.map +1 -0
- package/dist/front/parse/decode.js +89 -0
- package/dist/front/parse/decode.js.map +1 -0
- package/dist/front/parse/element.d.ts +3 -0
- package/dist/front/parse/element.d.ts.map +1 -0
- package/dist/front/parse/element.js +311 -0
- package/dist/front/parse/element.js.map +1 -0
- package/dist/front/parse/entities.d.ts +2 -0
- package/dist/front/parse/entities.d.ts.map +1 -0
- package/dist/front/parse/entities.js +2234 -0
- package/dist/front/parse/entities.js.map +1 -0
- package/dist/front/parse/expression.d.ts +5 -0
- package/dist/front/parse/expression.d.ts.map +1 -0
- package/dist/front/parse/expression.js +86 -0
- package/dist/front/parse/expression.js.map +1 -0
- package/dist/front/parse/html.d.ts +8 -0
- package/dist/front/parse/html.d.ts.map +1 -0
- package/dist/front/parse/html.js +146 -0
- package/dist/front/parse/html.js.map +1 -0
- package/dist/front/parse/identifier.d.ts +4 -0
- package/dist/front/parse/identifier.d.ts.map +1 -0
- package/dist/front/parse/identifier.js +24 -0
- package/dist/front/parse/identifier.js.map +1 -0
- package/dist/front/parse/index.d.ts +13 -0
- package/dist/front/parse/index.d.ts.map +1 -0
- package/dist/front/parse/index.js +74 -0
- package/dist/front/parse/index.js.map +1 -0
- package/dist/front/parse/js.d.ts +27 -0
- package/dist/front/parse/js.d.ts.map +1 -0
- package/dist/front/parse/js.js +241 -0
- package/dist/front/parse/js.js.map +1 -0
- package/dist/front/parse/options.d.ts +3 -0
- package/dist/front/parse/options.d.ts.map +1 -0
- package/dist/front/parse/options.js +198 -0
- package/dist/front/parse/options.js.map +1 -0
- package/dist/front/parse/parser.d.ts +50 -0
- package/dist/front/parse/parser.d.ts.map +1 -0
- package/dist/front/parse/parser.js +157 -0
- package/dist/front/parse/parser.js.map +1 -0
- package/dist/front/parse/pattern.d.ts +4 -0
- package/dist/front/parse/pattern.d.ts.map +1 -0
- package/dist/front/parse/pattern.js +53 -0
- package/dist/front/parse/pattern.js.map +1 -0
- package/dist/front/parse/script.d.ts +4 -0
- package/dist/front/parse/script.d.ts.map +1 -0
- package/dist/front/parse/script.js +60 -0
- package/dist/front/parse/script.js.map +1 -0
- package/dist/front/parse/style.d.ts +7 -0
- package/dist/front/parse/style.d.ts.map +1 -0
- package/dist/front/parse/style.js +397 -0
- package/dist/front/parse/style.js.map +1 -0
- package/dist/front/parse/tag.d.ts +3 -0
- package/dist/front/parse/tag.d.ts.map +1 -0
- package/dist/front/parse/tag.js +591 -0
- package/dist/front/parse/tag.js.map +1 -0
- package/dist/front/print/css.d.ts +5 -0
- package/dist/front/print/css.d.ts.map +1 -0
- package/dist/front/print/css.js +234 -0
- package/dist/front/print/css.js.map +1 -0
- package/dist/front/print/index.d.ts +18 -0
- package/dist/front/print/index.d.ts.map +1 -0
- package/dist/front/print/index.js +24 -0
- package/dist/front/print/index.js.map +1 -0
- package/dist/front/print/layout.d.ts +11 -0
- package/dist/front/print/layout.d.ts.map +1 -0
- package/dist/front/print/layout.js +73 -0
- package/dist/front/print/layout.js.map +1 -0
- package/dist/front/print/template.d.ts +5 -0
- package/dist/front/print/template.d.ts.map +1 -0
- package/dist/front/print/template.js +455 -0
- package/dist/front/print/template.js.map +1 -0
- package/dist/front/runes.d.ts +13 -0
- package/dist/front/runes.d.ts.map +1 -0
- package/dist/front/runes.js +253 -0
- package/dist/front/runes.js.map +1 -0
- package/dist/front/stores.d.ts +5 -0
- package/dist/front/stores.d.ts.map +1 -0
- package/dist/front/stores.js +84 -0
- package/dist/front/stores.js.map +1 -0
- package/dist/front/typescript.d.ts +2 -0
- package/dist/front/typescript.d.ts.map +1 -0
- package/dist/front/typescript.js +182 -0
- package/dist/front/typescript.js.map +1 -0
- package/dist/front/validate/anchors.d.ts +15 -0
- package/dist/front/validate/anchors.d.ts.map +1 -0
- package/dist/front/validate/anchors.js +43 -0
- package/dist/front/validate/anchors.js.map +1 -0
- package/dist/front/validate/index.d.ts +16 -0
- package/dist/front/validate/index.d.ts.map +1 -0
- package/dist/front/validate/index.js +139 -0
- package/dist/front/validate/index.js.map +1 -0
- package/dist/front/validate/legacy.d.ts +9 -0
- package/dist/front/validate/legacy.d.ts.map +1 -0
- package/dist/front/validate/legacy.js +102 -0
- package/dist/front/validate/legacy.js.map +1 -0
- package/dist/front/validate/report.d.ts +14 -0
- package/dist/front/validate/report.d.ts.map +1 -0
- package/dist/front/validate/report.js +29 -0
- package/dist/front/validate/report.js.map +1 -0
- package/dist/front/validate/template.d.ts +31 -0
- package/dist/front/validate/template.d.ts.map +1 -0
- package/dist/front/validate/template.js +507 -0
- package/dist/front/validate/template.js.map +1 -0
- package/dist/front/wording.d.ts +4 -0
- package/dist/front/wording.d.ts.map +1 -0
- package/dist/front/wording.js +110 -0
- package/dist/front/wording.js.map +1 -0
- package/dist/shared/format.d.ts +3 -0
- package/dist/shared/format.d.ts.map +1 -0
- package/dist/shared/format.js +7 -0
- package/dist/shared/format.js.map +1 -0
- package/easing.d.ts +2 -0
- package/elements.d.ts +1220 -0
- package/index.d.ts +2 -0
- package/motion.d.ts +2 -0
- package/package.json +123 -5
- package/src/compiler/diagnostics.ts +233 -0
- package/src/compiler/index.ts +292 -0
- package/src/compiler/options.ts +140 -0
- package/src/compiler/preprocess/decode.ts +85 -0
- package/src/compiler/preprocess/index.ts +299 -0
- package/src/compiler/preprocess/mapped.ts +146 -0
- package/src/compiler/proxy.ts +154 -0
- package/src/entries/action.ts +1 -0
- package/src/entries/animate.ts +1 -0
- package/src/entries/attachments.ts +1 -0
- package/src/entries/context.ts +50 -0
- package/src/entries/easing.ts +1 -0
- package/src/entries/events.ts +1 -0
- package/src/entries/index-server.ts +17 -0
- package/src/entries/index.ts +41 -0
- package/src/entries/internal/client.ts +15 -0
- package/src/entries/internal/disclose-version.ts +4 -0
- package/src/entries/internal/index.ts +3 -0
- package/src/entries/internal/server.ts +8 -0
- package/src/entries/internal/tracing.ts +1 -0
- package/src/entries/motion-server.ts +1 -0
- package/src/entries/motion.ts +1 -0
- package/src/entries/proxy.ts +86 -0
- package/src/entries/reactivity-server.ts +9 -0
- package/src/entries/reactivity.ts +9 -0
- package/src/entries/report.ts +81 -0
- package/src/entries/server.ts +76 -0
- package/src/entries/store-client.ts +80 -0
- package/src/entries/store-server.ts +44 -0
- package/src/entries/store.ts +201 -0
- package/src/entries/transition.ts +1 -0
- package/src/entries/window-server.ts +1 -0
- package/src/entries/window.ts +1 -0
- package/src/front/ast.ts +369 -0
- package/src/front/diagnostics.ts +53 -0
- package/src/front/ignores.ts +84 -0
- package/src/front/index.ts +86 -0
- package/src/front/legacy.ts +414 -0
- package/src/front/locate.ts +20 -0
- package/src/front/lower.ts +509 -0
- package/src/front/parse/attribute.ts +319 -0
- package/src/front/parse/bracket.ts +99 -0
- package/src/front/parse/characters.ts +19 -0
- package/src/front/parse/decode.ts +87 -0
- package/src/front/parse/element.ts +354 -0
- package/src/front/parse/entities.ts +2233 -0
- package/src/front/parse/expression.ts +85 -0
- package/src/front/parse/html.ts +158 -0
- package/src/front/parse/identifier.ts +29 -0
- package/src/front/parse/index.ts +88 -0
- package/src/front/parse/js.ts +284 -0
- package/src/front/parse/options.ts +194 -0
- package/src/front/parse/parser.ts +189 -0
- package/src/front/parse/pattern.ts +57 -0
- package/src/front/parse/script.ts +74 -0
- package/src/front/parse/style.ts +399 -0
- package/src/front/parse/tag.ts +601 -0
- package/src/front/print/css.ts +239 -0
- package/src/front/print/index.ts +40 -0
- package/src/front/print/layout.ts +87 -0
- package/src/front/print/template.ts +448 -0
- package/src/front/runes.ts +267 -0
- package/src/front/stores.ts +98 -0
- package/src/front/typescript.ts +178 -0
- package/src/front/validate/anchors.ts +54 -0
- package/src/front/validate/index.ts +174 -0
- package/src/front/validate/legacy.ts +119 -0
- package/src/front/validate/report.ts +38 -0
- package/src/front/validate/template.ts +549 -0
- package/src/front/wording.ts +112 -0
- package/src/shared/format.ts +8 -0
- package/store.d.ts +2 -0
- package/svelte-html.d.ts +53 -0
- package/transition.d.ts +2 -0
- package/types/compiler/interfaces.d.ts +2 -0
- package/types/compiler/preprocess.d.ts +2 -0
- package/types/index.d.ts +1453 -0
- package/README.md +0 -3
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type * as ES from 'estree';
|
|
2
|
+
import type { ExpressionProjection, Unit } from 'vigla/compiler';
|
|
3
|
+
|
|
4
|
+
type Source = Record<string, unknown>;
|
|
5
|
+
|
|
6
|
+
function record(value: unknown): value is Source {
|
|
7
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function property(node: ES.MemberExpression): string | null {
|
|
11
|
+
if (!node.computed && node.property.type === 'Identifier') return node.property.name;
|
|
12
|
+
return node.computed &&
|
|
13
|
+
node.property.type === 'Literal' &&
|
|
14
|
+
typeof node.property.value === 'string'
|
|
15
|
+
? node.property.value
|
|
16
|
+
: null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function primitive(node: ES.Expression): boolean {
|
|
20
|
+
return (
|
|
21
|
+
node.type === 'Literal' ||
|
|
22
|
+
node.type === 'TemplateLiteral' ||
|
|
23
|
+
node.type === 'UnaryExpression' ||
|
|
24
|
+
node.type === 'BinaryExpression'
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function optional(node: ES.Expression | ES.Super): boolean {
|
|
29
|
+
if (node.type === 'ChainExpression') return true;
|
|
30
|
+
if (node.type === 'MemberExpression') return node.optional || optional(node.object);
|
|
31
|
+
if (node.type === 'CallExpression') return node.optional || optional(node.callee);
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function literal(value: string, loc?: ES.SourceLocation | null): ES.Literal {
|
|
36
|
+
return { type: 'Literal', value, loc };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function call(callee: ES.Expression, ...args: ES.Expression[]): ES.SimpleCallExpression {
|
|
40
|
+
return { type: 'CallExpression', callee, arguments: args, optional: false };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function helper(runtime: ES.Identifier, name: string): ES.MemberExpression {
|
|
44
|
+
return {
|
|
45
|
+
type: 'MemberExpression',
|
|
46
|
+
object: runtime,
|
|
47
|
+
property: { type: 'Identifier', name },
|
|
48
|
+
computed: false,
|
|
49
|
+
optional: false
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function proxyDiagnostics(unit: Unit, filename: string): ExpressionProjection {
|
|
54
|
+
const searches = new WeakSet<object>();
|
|
55
|
+
const assignments = new WeakMap<object, string>();
|
|
56
|
+
const visit = (value: unknown, path: Source[]): void => {
|
|
57
|
+
if (Array.isArray(value)) {
|
|
58
|
+
for (const child of value) visit(child, path);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (!record(value)) return;
|
|
62
|
+
const parent = path.at(-1);
|
|
63
|
+
if (value.type === 'CallExpression') {
|
|
64
|
+
const node = value as unknown as ES.SimpleCallExpression;
|
|
65
|
+
const callee = node.callee;
|
|
66
|
+
if (
|
|
67
|
+
callee.type === 'MemberExpression' &&
|
|
68
|
+
!callee.optional &&
|
|
69
|
+
!node.optional &&
|
|
70
|
+
callee.object.type !== 'Super' &&
|
|
71
|
+
!optional(callee.object) &&
|
|
72
|
+
['includes', 'indexOf', 'lastIndexOf'].includes(property(callee) ?? '')
|
|
73
|
+
) {
|
|
74
|
+
searches.add(node);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (value.type === 'AssignmentExpression') {
|
|
78
|
+
const node = value as unknown as ES.AssignmentExpression;
|
|
79
|
+
const left = node.left;
|
|
80
|
+
const event =
|
|
81
|
+
parent?.type === 'ArrowFunctionExpression' &&
|
|
82
|
+
path.some((ancestor) => {
|
|
83
|
+
if (
|
|
84
|
+
ancestor.kind !== 'attribute' ||
|
|
85
|
+
typeof ancestor.name !== 'string' ||
|
|
86
|
+
!ancestor.name.startsWith('on')
|
|
87
|
+
)
|
|
88
|
+
return false;
|
|
89
|
+
const value = ancestor.value;
|
|
90
|
+
return record(value) && value.expression === parent;
|
|
91
|
+
});
|
|
92
|
+
if (
|
|
93
|
+
left.type === 'MemberExpression' &&
|
|
94
|
+
left.object.type !== 'Super' &&
|
|
95
|
+
left.property.type !== 'PrivateIdentifier' &&
|
|
96
|
+
['=', '&&=', '||=', '??='].includes(node.operator) &&
|
|
97
|
+
parent?.type !== 'ExpressionStatement' &&
|
|
98
|
+
!event &&
|
|
99
|
+
!path.some((ancestor) => ancestor.kind === 'binding') &&
|
|
100
|
+
!primitive(node.right)
|
|
101
|
+
) {
|
|
102
|
+
const position = left.loc?.start;
|
|
103
|
+
assignments.set(node, `${filename}:${position?.line ?? 0}:${position?.column ?? 0}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
for (const [key, child] of Object.entries(value)) {
|
|
107
|
+
if (key !== 'loc' && key !== 'leadingComments' && key !== 'trailingComments')
|
|
108
|
+
visit(child, [...path, value]);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
visit(unit, []);
|
|
112
|
+
return ({ original, lowered, runtime }) => {
|
|
113
|
+
if (
|
|
114
|
+
searches.has(original) &&
|
|
115
|
+
lowered.type === 'CallExpression' &&
|
|
116
|
+
lowered.callee.type === 'MemberExpression'
|
|
117
|
+
) {
|
|
118
|
+
const member = lowered.callee;
|
|
119
|
+
if (member.object.type === 'Super') return lowered;
|
|
120
|
+
return {
|
|
121
|
+
...lowered,
|
|
122
|
+
callee: call(
|
|
123
|
+
helper(runtime, 'search'),
|
|
124
|
+
member.object,
|
|
125
|
+
literal(property(member)!, member.property.loc)
|
|
126
|
+
)
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
const location = assignments.get(original);
|
|
130
|
+
if (
|
|
131
|
+
location !== undefined &&
|
|
132
|
+
lowered.type === 'AssignmentExpression' &&
|
|
133
|
+
lowered.left.type === 'MemberExpression'
|
|
134
|
+
) {
|
|
135
|
+
const member = lowered.left;
|
|
136
|
+
if (member.object.type === 'Super' || member.property.type === 'PrivateIdentifier')
|
|
137
|
+
return lowered;
|
|
138
|
+
const key = member.computed
|
|
139
|
+
? member.property
|
|
140
|
+
: literal((member.property as ES.Identifier).name, member.property.loc);
|
|
141
|
+
return {
|
|
142
|
+
...lowered,
|
|
143
|
+
left: {
|
|
144
|
+
type: 'MemberExpression',
|
|
145
|
+
object: call(helper(runtime, 'assignmentTarget'), member.object, key, literal(location)),
|
|
146
|
+
property: { type: 'Identifier', name: 'current' },
|
|
147
|
+
computed: false,
|
|
148
|
+
optional: false
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
return lowered;
|
|
153
|
+
};
|
|
154
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from 'vigla/action';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'vigla/animate';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'vigla/attachments';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Contexts as Keys } from 'vigla/internal/client';
|
|
2
|
+
import type { Context } from 'vigla/internal/index-client';
|
|
3
|
+
|
|
4
|
+
export interface Contexts extends Keys {
|
|
5
|
+
getAllContexts<T extends Map<unknown, unknown>>(): T;
|
|
6
|
+
createContext<T>(): Context<T>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface Scope {
|
|
10
|
+
readonly phase: () => 'initializing' | 'running' | null;
|
|
11
|
+
readonly failure: (code: string, message: string) => Error;
|
|
12
|
+
readonly provide: <T>(key: unknown, value: T) => T;
|
|
13
|
+
readonly keyed: <T>(keys: Keys) => Context<T>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function outside(scope: Scope, name: string): Error {
|
|
17
|
+
return scope.failure(
|
|
18
|
+
'lifecycle_outside_component',
|
|
19
|
+
`\`${name}(...)\` can only be used during component initialisation`
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function guard(scope: Scope, name: string): void {
|
|
24
|
+
if (scope.phase() === null) throw outside(scope, name);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function project(core: Contexts, scope: Scope): Contexts {
|
|
28
|
+
const keys: Keys = {
|
|
29
|
+
getContext(key) {
|
|
30
|
+
guard(scope, 'getContext');
|
|
31
|
+
return core.getContext(key);
|
|
32
|
+
},
|
|
33
|
+
setContext(key, value) {
|
|
34
|
+
guard(scope, 'setContext');
|
|
35
|
+
return scope.provide(key, value);
|
|
36
|
+
},
|
|
37
|
+
hasContext(key) {
|
|
38
|
+
guard(scope, 'hasContext');
|
|
39
|
+
return core.hasContext(key);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
...keys,
|
|
44
|
+
getAllContexts<T extends Map<unknown, unknown>>() {
|
|
45
|
+
guard(scope, 'getAllContexts');
|
|
46
|
+
return core.getAllContexts<T>();
|
|
47
|
+
},
|
|
48
|
+
createContext: <T>() => scope.keyed<T>(keys)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'vigla/easing';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'vigla/events';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as core from 'vigla/internal/index-server';
|
|
2
|
+
import { guard, project, type Scope } from './context.ts';
|
|
3
|
+
import { failure, keyed, phase, provide } from './internal/server.ts';
|
|
4
|
+
|
|
5
|
+
export * from 'vigla/internal/index-server';
|
|
6
|
+
|
|
7
|
+
const scope: Scope = { phase, failure, provide, keyed };
|
|
8
|
+
|
|
9
|
+
export const { getContext, setContext, hasContext, getAllContexts, createContext } = project(
|
|
10
|
+
core,
|
|
11
|
+
scope
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export function onDestroy(fn: () => void): void {
|
|
15
|
+
guard(scope, 'onDestroy');
|
|
16
|
+
core.onDestroy(fn);
|
|
17
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as core from 'vigla/internal/index-client';
|
|
2
|
+
import { guard, project, type Scope } from './context.ts';
|
|
3
|
+
import { failure, keyed, phase, provide } from './internal/client.ts';
|
|
4
|
+
import { format } from '../shared/format.ts';
|
|
5
|
+
|
|
6
|
+
export * from 'vigla/internal/index-client';
|
|
7
|
+
export { getReactionSignal as getAbortSignal } from './internal/client.ts';
|
|
8
|
+
|
|
9
|
+
const scope: Scope = { phase, failure, provide, keyed };
|
|
10
|
+
|
|
11
|
+
export const { getContext, setContext, hasContext, getAllContexts, createContext } = project(
|
|
12
|
+
core,
|
|
13
|
+
scope
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
export function mount<P extends core.Props, E extends core.Exports>(
|
|
17
|
+
component: core.Component<P, E>,
|
|
18
|
+
options: core.MountOptions<P>
|
|
19
|
+
): E {
|
|
20
|
+
return core.mount(component, { ...options, format: options.format ?? format });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function hydrate<P extends core.Props, E extends core.Exports>(
|
|
24
|
+
component: core.Component<P, E>,
|
|
25
|
+
options: core.HydrateOptions<P>
|
|
26
|
+
): E {
|
|
27
|
+
return core.hydrate(component, { ...options, format: options.format ?? format });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const createRawSnippet: typeof core.createRawSnippet = (factory) =>
|
|
31
|
+
core.createRawSnippet(factory, format);
|
|
32
|
+
|
|
33
|
+
export function onMount(fn: () => unknown): void {
|
|
34
|
+
guard(scope, 'onMount');
|
|
35
|
+
core.onMount(fn);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function onDestroy(fn: () => unknown): void {
|
|
39
|
+
guard(scope, 'onDestroy');
|
|
40
|
+
core.onDestroy(fn);
|
|
41
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { setReporter } from 'vigla/internal/client';
|
|
2
|
+
import { format } from '../../shared/format.ts';
|
|
3
|
+
import { reporter } from '../report.ts';
|
|
4
|
+
|
|
5
|
+
setReporter(reporter);
|
|
6
|
+
setReporter(reporter, format);
|
|
7
|
+
|
|
8
|
+
export * from 'vigla/internal/client';
|
|
9
|
+
export { assignmentTarget, search } from '../proxy.ts';
|
|
10
|
+
export {
|
|
11
|
+
lapsingDerived as derived,
|
|
12
|
+
pre as user_pre_effect,
|
|
13
|
+
unowned as without_reactive_context,
|
|
14
|
+
userEffect as user_effect
|
|
15
|
+
} from 'vigla/internal/client';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
throw new Error(
|
|
2
|
+
"Your application, or one of its dependencies, imported from 'svelte/internal', which was a private module used by Svelte 4 components that no longer exists in Svelte 5. It is not intended to be public API. If you're a library author and you used 'svelte/internal' deliberately, please raise an issue on https://github.com/sveltejs/svelte/issues detailing your use case."
|
|
3
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'vigla/internal/motion-server';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'vigla/internal/motion-client';
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { mutationTarget, original, type AssignmentTarget } from 'vigla/internal/client';
|
|
2
|
+
import { untrack } from 'vigla/internal/index-client';
|
|
3
|
+
import { reporter } from './report.ts';
|
|
4
|
+
|
|
5
|
+
type Search = 'includes' | 'indexOf' | 'lastIndexOf';
|
|
6
|
+
type Properties = Record<PropertyKey, unknown>;
|
|
7
|
+
|
|
8
|
+
const searches = {
|
|
9
|
+
includes: Array.prototype.includes,
|
|
10
|
+
indexOf: Array.prototype.indexOf,
|
|
11
|
+
lastIndexOf: Array.prototype.lastIndexOf
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
function identity(value: unknown): unknown {
|
|
15
|
+
try {
|
|
16
|
+
return original(value);
|
|
17
|
+
} catch {
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function assignmentTarget(
|
|
23
|
+
receiver: unknown,
|
|
24
|
+
key: PropertyKey,
|
|
25
|
+
location: string
|
|
26
|
+
): AssignmentTarget<unknown> {
|
|
27
|
+
const object = receiver as Properties;
|
|
28
|
+
let property: PropertyKey | undefined;
|
|
29
|
+
const reference = {
|
|
30
|
+
[Symbol.toPrimitive]() {
|
|
31
|
+
property = Reflect.ownKeys({ [key]: null })[0]!;
|
|
32
|
+
return property;
|
|
33
|
+
}
|
|
34
|
+
} as unknown as PropertyKey;
|
|
35
|
+
return mutationTarget(object, reference, (value) => {
|
|
36
|
+
if (value !== null && typeof value === 'object') {
|
|
37
|
+
const current = untrack(() => object[property!]);
|
|
38
|
+
if (current !== value && identity(current) !== current) {
|
|
39
|
+
reporter.warn({
|
|
40
|
+
code: 'assignment_value_stale',
|
|
41
|
+
message: `Assignment to \`${String(property)}\` property (${location}) will evaluate to the right-hand side, not the value of \`${String(property)}\` following the assignment. This may result in unexpected behaviour.`,
|
|
42
|
+
values: {},
|
|
43
|
+
dev: true
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function search(receiver: unknown, key: Search) {
|
|
51
|
+
const object = receiver as Properties;
|
|
52
|
+
const method = object[key] as (...args: unknown[]) => unknown;
|
|
53
|
+
return (...args: unknown[]): unknown => {
|
|
54
|
+
const intrinsic = method === searches[key];
|
|
55
|
+
let from: number | undefined;
|
|
56
|
+
const passed = [...args];
|
|
57
|
+
if (intrinsic && key !== 'includes' && args.length > 1 && args[1] != null) {
|
|
58
|
+
passed[1] = {
|
|
59
|
+
[Symbol.toPrimitive]() {
|
|
60
|
+
return (from = +(args[1] as number));
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const result = Reflect.apply(method, receiver, passed);
|
|
65
|
+
if (intrinsic && (key === 'includes' ? result === false : result === -1)) {
|
|
66
|
+
untrack(() => {
|
|
67
|
+
const length = object.length as number;
|
|
68
|
+
const end = Math.min(key === 'lastIndexOf' ? (from ?? length - 1) + 1 : length, length);
|
|
69
|
+
const start = key === 'indexOf' ? Math.max(from ?? 0, 0) : 0;
|
|
70
|
+
for (let index = start; index < end; index++) {
|
|
71
|
+
const value = object[index];
|
|
72
|
+
if (value !== args[0] && identity(value) === args[0]) {
|
|
73
|
+
reporter.warn({
|
|
74
|
+
code: 'state_proxy_equality_mismatch',
|
|
75
|
+
message: `Reactive \`$state(...)\` proxies and the values they proxy have different identities. Because of this, comparisons with \`array.${key}(...)\` will produce unexpected results`,
|
|
76
|
+
values: {},
|
|
77
|
+
dev: true
|
|
78
|
+
});
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Notice, Reporter, Values } from 'vigla/internal/server';
|
|
2
|
+
|
|
3
|
+
interface Projection {
|
|
4
|
+
readonly code: string;
|
|
5
|
+
readonly message: (values: Values) => string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const projections: Readonly<Record<string, Projection>> = {
|
|
9
|
+
boundary_reset_noop: {
|
|
10
|
+
code: 'svelte_boundary_reset_noop',
|
|
11
|
+
message: () =>
|
|
12
|
+
'A `<svelte:boundary>` `reset` function only resets the boundary the first time it is called'
|
|
13
|
+
},
|
|
14
|
+
boundary_reset_onerror: {
|
|
15
|
+
code: 'svelte_boundary_reset_onerror',
|
|
16
|
+
message: () =>
|
|
17
|
+
'A `<svelte:boundary>` `reset` function cannot be called while an error is still being handled'
|
|
18
|
+
},
|
|
19
|
+
dynamic_element_invalid_tag: {
|
|
20
|
+
code: 'dynamic_element_invalid_tag',
|
|
21
|
+
message: ({ tag }) =>
|
|
22
|
+
`\`<svelte:element this="${tag}">\` is not a valid element name — the element will not be rendered`
|
|
23
|
+
},
|
|
24
|
+
source_invalid: {
|
|
25
|
+
code: 'store_invalid_shape',
|
|
26
|
+
message: ({ name }) => `\`${name}\` is not a store with a \`subscribe\` method`
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const explained = new Set([
|
|
31
|
+
'async_local_storage_unavailable',
|
|
32
|
+
'await_invalid',
|
|
33
|
+
'dynamic_element_invalid_tag',
|
|
34
|
+
'html_deprecated',
|
|
35
|
+
'hydratable_clobbering',
|
|
36
|
+
'hydratable_serialization_failed',
|
|
37
|
+
'invalid_csp',
|
|
38
|
+
'invalid_id_prefix',
|
|
39
|
+
'lifecycle_function_unavailable',
|
|
40
|
+
'server_context_required'
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
const entries = /\/svelte\/src\/entries\//;
|
|
44
|
+
|
|
45
|
+
function link(code: string): string {
|
|
46
|
+
return `https://svelte.dev/e/${code}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function project({ code, message, values, dev }: Notice): [string, string | null] {
|
|
50
|
+
const found = projections[code];
|
|
51
|
+
const shown = found === undefined ? code : found.code;
|
|
52
|
+
if (!dev && !explained.has(shown)) return [shown, null];
|
|
53
|
+
return [shown, found === undefined ? message : found.message(values)];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const reporter: Reporter = {
|
|
57
|
+
warn(notice) {
|
|
58
|
+
const [code, message] = project(notice);
|
|
59
|
+
if (message === null) console.warn(link(code));
|
|
60
|
+
else {
|
|
61
|
+
console.warn(
|
|
62
|
+
`%c[svelte] ${code}\n%c${message}\n${link(code)}`,
|
|
63
|
+
'font-weight: bold',
|
|
64
|
+
'font-weight: normal'
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
error(notice) {
|
|
69
|
+
const [code, message] = project(notice);
|
|
70
|
+
const error = new Error(message === null ? link(code) : `${code}\n${message}\n${link(code)}`);
|
|
71
|
+
error.name = 'Svelte error';
|
|
72
|
+
return error;
|
|
73
|
+
},
|
|
74
|
+
formatFrame(frame) {
|
|
75
|
+
if (entries.test(frame.replaceAll('\\', '/'))) return null;
|
|
76
|
+
return frame.replace(/\bReactive(Map|Set|Date|URLSearchParams|URL)\./g, 'Svelte$1.');
|
|
77
|
+
},
|
|
78
|
+
unhandled(error) {
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as core from 'vigla/server';
|
|
2
|
+
import { failure } from 'vigla/internal/server';
|
|
3
|
+
import { format } from '../shared/format.ts';
|
|
4
|
+
|
|
5
|
+
export * from 'vigla/server';
|
|
6
|
+
|
|
7
|
+
export interface Rendered extends core.Rendered {
|
|
8
|
+
readonly html: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type Rendering = Rendered & PromiseLike<Rendered>;
|
|
12
|
+
|
|
13
|
+
class Settled implements Rendered {
|
|
14
|
+
readonly head: string;
|
|
15
|
+
readonly body: string;
|
|
16
|
+
readonly hashes: core.Hashes;
|
|
17
|
+
|
|
18
|
+
constructor(value: core.Rendered) {
|
|
19
|
+
this.head = value.head;
|
|
20
|
+
this.body = value.body;
|
|
21
|
+
this.hashes = value.hashes;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get html(): string {
|
|
25
|
+
throw failure(
|
|
26
|
+
'html_deprecated',
|
|
27
|
+
'The `html` property of server render results has been deprecated. Use `body` instead.'
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
class Result implements Rendering {
|
|
33
|
+
readonly #result: core.Rendering;
|
|
34
|
+
|
|
35
|
+
constructor(result: core.Rendering) {
|
|
36
|
+
this.#result = result;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
get head(): string {
|
|
40
|
+
return this.#result.head;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
get body(): string {
|
|
44
|
+
return this.#result.body;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get html(): string {
|
|
48
|
+
return this.#result.body;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
get hashes(): core.Hashes {
|
|
52
|
+
return this.#result.hashes;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
then<A = Rendered, B = never>(
|
|
56
|
+
fulfilled?: ((value: Rendered) => A | PromiseLike<A>) | null,
|
|
57
|
+
rejected?: ((reason: unknown) => B | PromiseLike<B>) | null
|
|
58
|
+
): PromiseLike<A | B> {
|
|
59
|
+
return Promise.resolve(this.#result)
|
|
60
|
+
.then((value): Rendered => new Settled(value))
|
|
61
|
+
.then(fulfilled, rejected);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function render<P extends core.Props>(
|
|
66
|
+
component: core.Component<P>,
|
|
67
|
+
options: core.RenderOptions<P> = {}
|
|
68
|
+
): Rendering {
|
|
69
|
+
return new Result(
|
|
70
|
+
core.render(component, {
|
|
71
|
+
...options,
|
|
72
|
+
format: options.format ?? format,
|
|
73
|
+
inheritContext: options.inheritContext ?? false
|
|
74
|
+
})
|
|
75
|
+
);
|
|
76
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { effect, getOwner, tracking } from 'vigla/internal/index-client';
|
|
2
|
+
import { createSubscriber } from 'vigla/internal/reactivity-client';
|
|
3
|
+
import { get, subscribe, writable, type Readable, type Writable } from './store.ts';
|
|
4
|
+
|
|
5
|
+
export { derived, get, readable, readonly, writable } from './store.ts';
|
|
6
|
+
export type {
|
|
7
|
+
Readable,
|
|
8
|
+
StartStopNotifier,
|
|
9
|
+
Subscriber,
|
|
10
|
+
Unsubscriber,
|
|
11
|
+
Updater,
|
|
12
|
+
Writable
|
|
13
|
+
} from './store.ts';
|
|
14
|
+
|
|
15
|
+
export function toStore<T>(read: () => T, write: (value: T) => void): Writable<T>;
|
|
16
|
+
export function toStore<T>(read: () => T): Readable<T>;
|
|
17
|
+
export function toStore<T>(read: () => T, write?: (value: T) => void): Readable<T> | Writable<T> {
|
|
18
|
+
const owner = getOwner();
|
|
19
|
+
const initial = read();
|
|
20
|
+
const store = writable(initial, (publish) => {
|
|
21
|
+
let ran = initial !== read();
|
|
22
|
+
const start = (): (() => void) =>
|
|
23
|
+
effect.root(() => {
|
|
24
|
+
effect.pre(() => {
|
|
25
|
+
const value = read();
|
|
26
|
+
if (ran) publish(value);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
const stop = owner !== null && !owner.disposed ? owner.run(start) : start();
|
|
30
|
+
ran = true;
|
|
31
|
+
return stop;
|
|
32
|
+
});
|
|
33
|
+
return write === undefined
|
|
34
|
+
? { subscribe: store.subscribe, subscribeSync: store.subscribeSync }
|
|
35
|
+
: {
|
|
36
|
+
subscribe: store.subscribe,
|
|
37
|
+
subscribeSync: store.subscribeSync,
|
|
38
|
+
set: write,
|
|
39
|
+
update: (fn) => write(fn(read()))
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function fromStore<T>(store: Writable<T>): { current: T };
|
|
44
|
+
export function fromStore<T>(store: Readable<T>): { readonly current: T };
|
|
45
|
+
export function fromStore<T>(store: Readable<T>): { readonly current: T } {
|
|
46
|
+
let value: T;
|
|
47
|
+
const track = createSubscriber((update) => {
|
|
48
|
+
let active = false;
|
|
49
|
+
const release = subscribe(
|
|
50
|
+
store,
|
|
51
|
+
(next) => {
|
|
52
|
+
value = next;
|
|
53
|
+
if (active) update();
|
|
54
|
+
},
|
|
55
|
+
undefined,
|
|
56
|
+
true
|
|
57
|
+
);
|
|
58
|
+
active = true;
|
|
59
|
+
return release;
|
|
60
|
+
});
|
|
61
|
+
const read = (): T => {
|
|
62
|
+
if (!tracking()) return get(store);
|
|
63
|
+
track();
|
|
64
|
+
return value;
|
|
65
|
+
};
|
|
66
|
+
return 'set' in store
|
|
67
|
+
? {
|
|
68
|
+
get current() {
|
|
69
|
+
return read();
|
|
70
|
+
},
|
|
71
|
+
set current(value: T) {
|
|
72
|
+
(store as Writable<T>).set(value);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
: {
|
|
76
|
+
get current() {
|
|
77
|
+
return read();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|