aktion-runtime 0.5.5 → 0.5.7
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 +120 -15
- package/dist/aktion.iife.js +42 -42
- package/dist/aktion.iife.js.map +1 -1
- package/dist/aktion.js +12655 -12123
- package/dist/aktion.js.map +1 -1
- package/dist/aktion.umd.cjs +42 -42
- package/dist/aktion.umd.cjs.map +1 -1
- package/dist/language.js +1348 -98
- package/dist/language.js.map +1 -1
- package/dist/plugin.cjs +12 -2
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.js +12 -2
- package/dist/plugin.js.map +1 -1
- package/dist/system_prompt.txt +40 -8
- package/dist/system_prompt_chat.txt +2 -1
- package/dist/testing.js +15415 -14698
- package/dist/testing.js.map +1 -1
- package/dist/types/element.d.ts +0 -1
- package/dist/types/language/builtins.d.ts +52 -0
- package/dist/types/language/index.d.ts +5 -2
- package/dist/types/language-api.d.ts +5 -1
- package/dist/types/library/components/helpers.d.ts +0 -5
- package/dist/types/library/components/wrappers.d.ts +1 -0
- package/dist/types/parser/types.d.ts +0 -1
- package/dist/types/runtime/effects.d.ts +1 -18
- package/dist/types/runtime/evaluator.d.ts +46 -5
- package/dist/types/runtime/http.d.ts +41 -0
- package/dist/types/runtime/index.d.ts +2 -1
- package/dist/types/runtime/router.d.ts +28 -2
- package/dist/types/runtime/toast.d.ts +45 -0
- package/dist/types/runtime/util.d.ts +11 -1
- package/dist/types/tooling/index.d.ts +6 -0
- package/dist/types/tooling/language-service.d.ts +10 -5
- package/dist/types/tooling/navigation.d.ts +91 -0
- package/dist/types/tooling/semantic-tokens.d.ts +24 -0
- package/dist/types/tooling/signature-help.d.ts +21 -0
- package/package.json +1 -1
package/dist/language.js
CHANGED
|
@@ -573,8 +573,8 @@ function parseFunctionDecl(ctx) {
|
|
|
573
573
|
loc: { line: start.line, column: start.column }
|
|
574
574
|
};
|
|
575
575
|
}
|
|
576
|
-
const
|
|
577
|
-
if (
|
|
576
|
+
const isPascalCase2 = nameTok.value.length > 0 && nameTok.value[0] >= "A" && nameTok.value[0] <= "Z";
|
|
577
|
+
if (isPascalCase2) {
|
|
578
578
|
return {
|
|
579
579
|
kind: "ComponentDeclaration",
|
|
580
580
|
name: nameTok.value,
|
|
@@ -588,7 +588,6 @@ function parseFunctionDecl(ctx) {
|
|
|
588
588
|
kind: "ActionDeclaration",
|
|
589
589
|
name: nameTok.value,
|
|
590
590
|
params,
|
|
591
|
-
optimistic: false,
|
|
592
591
|
body,
|
|
593
592
|
loc: { line: start.line, column: start.column }
|
|
594
593
|
};
|
|
@@ -2875,6 +2874,169 @@ const defaultTagMap = {
|
|
|
2875
2874
|
operator: "operator",
|
|
2876
2875
|
punctuation: null
|
|
2877
2876
|
};
|
|
2877
|
+
const builtinCatalog = [
|
|
2878
|
+
// Hooks (per-instance state — mirror React's use* family).
|
|
2879
|
+
{
|
|
2880
|
+
name: "state",
|
|
2881
|
+
sigil: "$state",
|
|
2882
|
+
category: "hook",
|
|
2883
|
+
signature: "$state(initial)",
|
|
2884
|
+
summary: "Hook: per-instance state → [value, setValue] (like React's useState)."
|
|
2885
|
+
},
|
|
2886
|
+
{
|
|
2887
|
+
name: "memo",
|
|
2888
|
+
sigil: "$memo",
|
|
2889
|
+
category: "hook",
|
|
2890
|
+
signature: "$memo(() => value, [deps])",
|
|
2891
|
+
summary: "Hook: value recomputed only when a dependency changes (like useMemo)."
|
|
2892
|
+
},
|
|
2893
|
+
{
|
|
2894
|
+
name: "ref",
|
|
2895
|
+
sigil: "$ref",
|
|
2896
|
+
category: "hook",
|
|
2897
|
+
signature: "$ref(initial)",
|
|
2898
|
+
summary: "Hook: stable { current } box; writing .current does not re-render (like useRef)."
|
|
2899
|
+
},
|
|
2900
|
+
{
|
|
2901
|
+
name: "reducer",
|
|
2902
|
+
sigil: "$reducer",
|
|
2903
|
+
category: "hook",
|
|
2904
|
+
signature: "$reducer((state, action) => next, initial)",
|
|
2905
|
+
summary: "Hook: [state, dispatch] (like useReducer)."
|
|
2906
|
+
},
|
|
2907
|
+
{
|
|
2908
|
+
name: "id",
|
|
2909
|
+
sigil: "$id",
|
|
2910
|
+
category: "hook",
|
|
2911
|
+
signature: "$id(prefix?)",
|
|
2912
|
+
summary: "Hook: stable unique id per component instance (like useId)."
|
|
2913
|
+
},
|
|
2914
|
+
// Effects + reactivity.
|
|
2915
|
+
{
|
|
2916
|
+
name: "effect",
|
|
2917
|
+
sigil: "$effect",
|
|
2918
|
+
category: "effect",
|
|
2919
|
+
signature: "$effect(() => { … }, [deps])",
|
|
2920
|
+
summary: 'Declarative side effect; deps mix $state, "mount"/"unmount", "every(N)", "debounce(N)".'
|
|
2921
|
+
},
|
|
2922
|
+
{
|
|
2923
|
+
name: "optimistic",
|
|
2924
|
+
sigil: "$optimistic",
|
|
2925
|
+
category: "effect",
|
|
2926
|
+
signature: "$optimistic(() => { … })",
|
|
2927
|
+
summary: "Run optimistic writes; auto-rolls back state if the callback throws or rejects."
|
|
2928
|
+
},
|
|
2929
|
+
{
|
|
2930
|
+
name: "store",
|
|
2931
|
+
sigil: "$store",
|
|
2932
|
+
category: "effect",
|
|
2933
|
+
signature: "$store({ ...state, ...methods })",
|
|
2934
|
+
summary: "Global store: shared state + actions (like Zustand/Pinia)."
|
|
2935
|
+
},
|
|
2936
|
+
// Data layer.
|
|
2937
|
+
{
|
|
2938
|
+
name: "http",
|
|
2939
|
+
sigil: "$http",
|
|
2940
|
+
category: "data",
|
|
2941
|
+
signature: "$http({ url, method, … })",
|
|
2942
|
+
summary: "Reactive HTTP resource bag — { data, loading, error, refetch }."
|
|
2943
|
+
},
|
|
2944
|
+
{
|
|
2945
|
+
name: "query",
|
|
2946
|
+
sigil: "$query",
|
|
2947
|
+
category: "data",
|
|
2948
|
+
signature: "$query({ url, key, ttl })",
|
|
2949
|
+
summary: "Cached + deduplicated HTTP read."
|
|
2950
|
+
},
|
|
2951
|
+
{
|
|
2952
|
+
name: "mutation",
|
|
2953
|
+
sigil: "$mutation",
|
|
2954
|
+
category: "data",
|
|
2955
|
+
signature: "$mutation({ url, method })",
|
|
2956
|
+
summary: "Deferred write; fires on .mutate(overrides?)."
|
|
2957
|
+
},
|
|
2958
|
+
// App / routing / theming / events.
|
|
2959
|
+
{
|
|
2960
|
+
name: "app",
|
|
2961
|
+
sigil: "$app",
|
|
2962
|
+
category: "app",
|
|
2963
|
+
signature: "$app(root)",
|
|
2964
|
+
summary: "Register the root of the rendered UI tree — every program needs one."
|
|
2965
|
+
},
|
|
2966
|
+
{
|
|
2967
|
+
name: "router",
|
|
2968
|
+
sigil: "$router",
|
|
2969
|
+
category: "routing",
|
|
2970
|
+
signature: "$router({ '/': Home(), default: NotFound() })",
|
|
2971
|
+
summary: "Outlet-first router: maps path patterns to component trees."
|
|
2972
|
+
},
|
|
2973
|
+
{
|
|
2974
|
+
name: "theme",
|
|
2975
|
+
sigil: "$theme",
|
|
2976
|
+
category: "theme",
|
|
2977
|
+
signature: "$theme({ colors, radius, font, … })",
|
|
2978
|
+
summary: "In-script theme override merged on top of the active base theme."
|
|
2979
|
+
},
|
|
2980
|
+
{
|
|
2981
|
+
name: "emit",
|
|
2982
|
+
sigil: "$emit",
|
|
2983
|
+
category: "event",
|
|
2984
|
+
signature: "$emit('name', detail)",
|
|
2985
|
+
summary: "Dispatch a CustomEvent from the host element."
|
|
2986
|
+
},
|
|
2987
|
+
// Namespaces (members reached via `.`).
|
|
2988
|
+
{
|
|
2989
|
+
name: "util",
|
|
2990
|
+
sigil: "$util",
|
|
2991
|
+
category: "namespace",
|
|
2992
|
+
signature: "$util",
|
|
2993
|
+
summary: "Runtime helper namespace ($util.format, $util.sum, $util.range, …).",
|
|
2994
|
+
namespace: true
|
|
2995
|
+
},
|
|
2996
|
+
{
|
|
2997
|
+
name: "storage",
|
|
2998
|
+
sigil: "$storage",
|
|
2999
|
+
category: "namespace",
|
|
3000
|
+
signature: "$storage",
|
|
3001
|
+
summary: "Persistent storage namespace ($storage.local, $storage.session, …).",
|
|
3002
|
+
namespace: true
|
|
3003
|
+
},
|
|
3004
|
+
{
|
|
3005
|
+
name: "console",
|
|
3006
|
+
sigil: "$console",
|
|
3007
|
+
category: "namespace",
|
|
3008
|
+
signature: "$console",
|
|
3009
|
+
summary: "Console namespace ($console.log, $console.warn, …).",
|
|
3010
|
+
namespace: true
|
|
3011
|
+
},
|
|
3012
|
+
{
|
|
3013
|
+
name: "toast",
|
|
3014
|
+
sigil: "$toast",
|
|
3015
|
+
category: "namespace",
|
|
3016
|
+
signature: "$toast",
|
|
3017
|
+
summary: "Imperative toasts: $toast.show/.success/.error/.dismiss; reactive .items.",
|
|
3018
|
+
namespace: true
|
|
3019
|
+
},
|
|
3020
|
+
{
|
|
3021
|
+
name: "i18n",
|
|
3022
|
+
sigil: "$i18n",
|
|
3023
|
+
category: "data",
|
|
3024
|
+
signature: "$i18n({ translations, … })",
|
|
3025
|
+
summary: "Translation bundle → { t, setCurrentLanguage, getCurrentLanguage }."
|
|
3026
|
+
}
|
|
3027
|
+
];
|
|
3028
|
+
const builtinNames = new Set(
|
|
3029
|
+
builtinCatalog.map((b) => b.name)
|
|
3030
|
+
);
|
|
3031
|
+
const builtinsByName = Object.freeze(
|
|
3032
|
+
Object.fromEntries(builtinCatalog.map((b) => [b.name, b]))
|
|
3033
|
+
);
|
|
3034
|
+
function findBuiltin(bareName) {
|
|
3035
|
+
return builtinsByName[bareName];
|
|
3036
|
+
}
|
|
3037
|
+
function isBuiltinName(bareName) {
|
|
3038
|
+
return builtinNames.has(bareName);
|
|
3039
|
+
}
|
|
2878
3040
|
const KEYWORDS = [
|
|
2879
3041
|
{ label: "function", detail: "Declare a component or action — either case works" },
|
|
2880
3042
|
{ label: "$effect", detail: "Reactive side-effect: $effect(() => { ... }, [deps])" },
|
|
@@ -2908,29 +3070,30 @@ function getDiagnostics(source, library) {
|
|
|
2908
3070
|
}
|
|
2909
3071
|
function getCompletions(source, position, library) {
|
|
2910
3072
|
const ctx = analyseCursor(source, position);
|
|
3073
|
+
const user = collectUserSymbols(source);
|
|
2911
3074
|
if (ctx.afterDollar) {
|
|
2912
3075
|
return [
|
|
3076
|
+
...user.atoms.map((name) => ({
|
|
3077
|
+
label: `$${name}`,
|
|
3078
|
+
kind: "state",
|
|
3079
|
+
detail: "Reactive atom declared in this file"
|
|
3080
|
+
})),
|
|
2913
3081
|
{ label: "$name = value", kind: "state", detail: "Declare or assign a reactive atom" },
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
{ label: "$router({ '/': Home(), default: NotFound() })", kind: "builtin", detail: "Outlet-first router" },
|
|
2920
|
-
{ label: "$util", kind: "builtin", detail: "Runtime helper namespace ($util.format, $util.sum, …)" },
|
|
2921
|
-
{ label: "$emit('name', detail)", kind: "builtin", detail: "Dispatch a CustomEvent" },
|
|
2922
|
-
{ label: "$theme({ colors, radius, ... })", kind: "builtin", detail: "In-script theme override" },
|
|
2923
|
-
{ label: "$storage", kind: "builtin", detail: "Persistent storage namespace ($storage.local, …)" },
|
|
2924
|
-
{ label: "$console", kind: "builtin", detail: "Console namespace ($console.log, …)" },
|
|
2925
|
-
{ label: "$i18n({ translations, ... })", kind: "builtin", detail: "Translation bundle" }
|
|
3082
|
+
...builtinCatalog.map((b) => ({
|
|
3083
|
+
label: b.signature,
|
|
3084
|
+
kind: "builtin",
|
|
3085
|
+
detail: b.summary
|
|
3086
|
+
}))
|
|
2926
3087
|
];
|
|
2927
3088
|
}
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
}
|
|
3089
|
+
const general = generalCompletions(library, user);
|
|
3090
|
+
if (ctx.objectCallee) {
|
|
3091
|
+
const spec = findComponent(library, ctx.objectCallee);
|
|
3092
|
+
if (spec) return [...propCompletions(spec), ...general];
|
|
2933
3093
|
}
|
|
3094
|
+
return general;
|
|
3095
|
+
}
|
|
3096
|
+
function generalCompletions(library, user) {
|
|
2934
3097
|
const keywordItems = /* @__PURE__ */ new Map();
|
|
2935
3098
|
for (const [label, doc] of Object.entries(keywordDocs)) {
|
|
2936
3099
|
keywordItems.set(label, {
|
|
@@ -2948,6 +3111,23 @@ ${doc.example}`
|
|
|
2948
3111
|
}
|
|
2949
3112
|
}
|
|
2950
3113
|
return [
|
|
3114
|
+
// Author-declared symbols first so they rank above the large library
|
|
3115
|
+
// list in editors that preserve provider order.
|
|
3116
|
+
...user.components.map((name) => ({
|
|
3117
|
+
label: name,
|
|
3118
|
+
kind: "component",
|
|
3119
|
+
detail: "Component declared in this file"
|
|
3120
|
+
})),
|
|
3121
|
+
...user.actions.map((name) => ({
|
|
3122
|
+
label: name,
|
|
3123
|
+
kind: "builtin",
|
|
3124
|
+
detail: "Action declared in this file"
|
|
3125
|
+
})),
|
|
3126
|
+
...user.atoms.map((name) => ({
|
|
3127
|
+
label: `$${name}`,
|
|
3128
|
+
kind: "state",
|
|
3129
|
+
detail: "Reactive atom declared in this file"
|
|
3130
|
+
})),
|
|
2951
3131
|
...keywordItems.values(),
|
|
2952
3132
|
...library.components.map((c) => ({
|
|
2953
3133
|
label: c.name,
|
|
@@ -2957,6 +3137,25 @@ ${doc.example}`
|
|
|
2957
3137
|
}))
|
|
2958
3138
|
];
|
|
2959
3139
|
}
|
|
3140
|
+
function collectUserSymbols(source) {
|
|
3141
|
+
const atoms = /* @__PURE__ */ new Set();
|
|
3142
|
+
const components2 = /* @__PURE__ */ new Set();
|
|
3143
|
+
const actions = /* @__PURE__ */ new Set();
|
|
3144
|
+
try {
|
|
3145
|
+
const program = parse(source);
|
|
3146
|
+
for (const stmt of program.statements) {
|
|
3147
|
+
if (stmt.kind === "Assignment" && stmt.isState && stmt.identifier) {
|
|
3148
|
+
atoms.add(stmt.identifier);
|
|
3149
|
+
} else if (stmt.kind === "ComponentDeclaration" && stmt.name) {
|
|
3150
|
+
components2.add(stmt.name);
|
|
3151
|
+
} else if (stmt.kind === "ActionDeclaration" && stmt.name) {
|
|
3152
|
+
actions.add(stmt.name);
|
|
3153
|
+
}
|
|
3154
|
+
}
|
|
3155
|
+
} catch {
|
|
3156
|
+
}
|
|
3157
|
+
return { atoms: [...atoms], components: [...components2], actions: [...actions] };
|
|
3158
|
+
}
|
|
2960
3159
|
function getHoverInfo(source, position, library) {
|
|
2961
3160
|
const word = wordAt(source, position);
|
|
2962
3161
|
if (!word) return null;
|
|
@@ -2969,13 +3168,16 @@ function getHoverInfo(source, position, library) {
|
|
|
2969
3168
|
Signature: \`${signaturePreview(spec)}\``
|
|
2970
3169
|
};
|
|
2971
3170
|
}
|
|
2972
|
-
if (word === "$state") {
|
|
2973
|
-
return { kind: "builtin", contents: "**$state(initial)** — hook returning `[value, setValue]` (per-instance state, like React's useState)" };
|
|
2974
|
-
}
|
|
2975
|
-
if (word === "$memo") {
|
|
2976
|
-
return { kind: "builtin", contents: "**$memo(() => value, [deps])** — hook returning a value recomputed only when a dependency changes (like React's useMemo)" };
|
|
2977
|
-
}
|
|
2978
3171
|
if (word.startsWith("$")) {
|
|
3172
|
+
const builtin = findBuiltin(word.slice(1));
|
|
3173
|
+
if (builtin) {
|
|
3174
|
+
return {
|
|
3175
|
+
kind: "builtin",
|
|
3176
|
+
contents: `**${builtin.sigil}** — ${builtin.summary}
|
|
3177
|
+
|
|
3178
|
+
Signature: \`${builtin.signature}\``
|
|
3179
|
+
};
|
|
3180
|
+
}
|
|
2979
3181
|
return { kind: "state", contents: `**${word}** — reactive state atom` };
|
|
2980
3182
|
}
|
|
2981
3183
|
const doc = keywordDocs[word];
|
|
@@ -3004,31 +3206,64 @@ ${doc.example}
|
|
|
3004
3206
|
\`\`\``;
|
|
3005
3207
|
}
|
|
3006
3208
|
function analyseCursor(source, position) {
|
|
3007
|
-
const offset = lineColumnToOffset(source, position);
|
|
3209
|
+
const offset = lineColumnToOffset$1(source, position);
|
|
3008
3210
|
const prefix = source.slice(0, offset);
|
|
3009
3211
|
const afterDollar = /\$[A-Za-z_]*$/.test(prefix);
|
|
3010
|
-
|
|
3011
|
-
let
|
|
3012
|
-
for (let i = prefix.length - 1; i >= 0; i -= 1) {
|
|
3212
|
+
const stack = [];
|
|
3213
|
+
for (let i = 0; i < prefix.length; i += 1) {
|
|
3013
3214
|
const ch = prefix[i];
|
|
3014
|
-
if (ch === "
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3215
|
+
if (ch === "/" && prefix[i + 1] === "/") {
|
|
3216
|
+
while (i < prefix.length && prefix[i] !== "\n") i += 1;
|
|
3217
|
+
continue;
|
|
3218
|
+
}
|
|
3219
|
+
if (ch === "/" && prefix[i + 1] === "*") {
|
|
3220
|
+
i += 2;
|
|
3221
|
+
while (i < prefix.length && !(prefix[i] === "*" && prefix[i + 1] === "/")) i += 1;
|
|
3222
|
+
i += 1;
|
|
3223
|
+
continue;
|
|
3224
|
+
}
|
|
3225
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
3226
|
+
i = skipStringLiteral(prefix, i, ch);
|
|
3227
|
+
continue;
|
|
3228
|
+
}
|
|
3229
|
+
if (ch === "(" || ch === "[" || ch === "{") {
|
|
3230
|
+
stack.push({ bracket: ch, callee: ch === "(" ? identifierBefore$1(prefix, i) : "" });
|
|
3231
|
+
} else if (ch === ")" || ch === "]" || ch === "}") {
|
|
3232
|
+
stack.pop();
|
|
3233
|
+
}
|
|
3234
|
+
}
|
|
3235
|
+
let objectCallee;
|
|
3236
|
+
const top = stack[stack.length - 1];
|
|
3237
|
+
if (top && top.bracket === "{") {
|
|
3238
|
+
for (let i = stack.length - 1; i >= 0; i -= 1) {
|
|
3239
|
+
if (stack[i].bracket === "(") {
|
|
3240
|
+
const callee = stack[i].callee;
|
|
3241
|
+
if (callee) objectCallee = callee;
|
|
3018
3242
|
break;
|
|
3019
3243
|
}
|
|
3020
|
-
depth -= 1;
|
|
3021
3244
|
}
|
|
3022
3245
|
}
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
const
|
|
3029
|
-
if (
|
|
3246
|
+
return { objectCallee, afterDollar };
|
|
3247
|
+
}
|
|
3248
|
+
function skipStringLiteral(source, start, quote) {
|
|
3249
|
+
let i = start + 1;
|
|
3250
|
+
while (i < source.length) {
|
|
3251
|
+
const ch = source[i];
|
|
3252
|
+
if (ch === "\\") {
|
|
3253
|
+
i += 2;
|
|
3254
|
+
continue;
|
|
3255
|
+
}
|
|
3256
|
+
if (ch === quote) return i;
|
|
3257
|
+
i += 1;
|
|
3030
3258
|
}
|
|
3031
|
-
return
|
|
3259
|
+
return source.length - 1;
|
|
3260
|
+
}
|
|
3261
|
+
function identifierBefore$1(source, openIndex) {
|
|
3262
|
+
let end = openIndex;
|
|
3263
|
+
while (end > 0 && /\s/.test(source[end - 1])) end -= 1;
|
|
3264
|
+
let start = end;
|
|
3265
|
+
while (start > 0 && /[\w$]/.test(source[start - 1])) start -= 1;
|
|
3266
|
+
return source.slice(start, end);
|
|
3032
3267
|
}
|
|
3033
3268
|
function propCompletions(spec) {
|
|
3034
3269
|
const positional = findPositionalProp(spec);
|
|
@@ -3056,7 +3291,7 @@ function signaturePreview(spec) {
|
|
|
3056
3291
|
if (rest === "") return `${spec.name}(${positionalLabel})`;
|
|
3057
3292
|
return `${spec.name}(${positionalLabel}, ${rest})`;
|
|
3058
3293
|
}
|
|
3059
|
-
function lineColumnToOffset(source, pos) {
|
|
3294
|
+
function lineColumnToOffset$1(source, pos) {
|
|
3060
3295
|
let line = 1;
|
|
3061
3296
|
let col = 1;
|
|
3062
3297
|
for (let i = 0; i < source.length; i += 1) {
|
|
@@ -3071,7 +3306,7 @@ function lineColumnToOffset(source, pos) {
|
|
|
3071
3306
|
return source.length;
|
|
3072
3307
|
}
|
|
3073
3308
|
function wordAt(source, pos) {
|
|
3074
|
-
const offset = lineColumnToOffset(source, pos);
|
|
3309
|
+
const offset = lineColumnToOffset$1(source, pos);
|
|
3075
3310
|
const isWord = (c) => /[\w$]/.test(c);
|
|
3076
3311
|
let start = offset;
|
|
3077
3312
|
while (start > 0 && isWord(source[start - 1])) start -= 1;
|
|
@@ -3080,6 +3315,282 @@ function wordAt(source, pos) {
|
|
|
3080
3315
|
if (start === end) return null;
|
|
3081
3316
|
return source.slice(start, end);
|
|
3082
3317
|
}
|
|
3318
|
+
function getDefinition(source, position) {
|
|
3319
|
+
const tokens = tokenize(source);
|
|
3320
|
+
const tok = findNameTokenAt(tokens, position);
|
|
3321
|
+
if (!tok) return null;
|
|
3322
|
+
const sym = resolveSymbol(tokens, tok);
|
|
3323
|
+
return sym ? sym.range : null;
|
|
3324
|
+
}
|
|
3325
|
+
function getDefinitionTarget(source, position) {
|
|
3326
|
+
const tokens = tokenize(source);
|
|
3327
|
+
const imports = parseImports(tokens);
|
|
3328
|
+
for (const clause of imports) {
|
|
3329
|
+
if (clause.sourceRange && positionInRange(position, clause.sourceRange)) {
|
|
3330
|
+
return { kind: "module", moduleSource: clause.source };
|
|
3331
|
+
}
|
|
3332
|
+
}
|
|
3333
|
+
const tok = findNameTokenAt(tokens, position);
|
|
3334
|
+
if (!tok) return null;
|
|
3335
|
+
const wantsState = tok.type === "StateIdentifier";
|
|
3336
|
+
for (const clause of imports) {
|
|
3337
|
+
for (const spec of clause.specifiers) {
|
|
3338
|
+
if (spec.local === tok.value && spec.isState === wantsState) {
|
|
3339
|
+
return {
|
|
3340
|
+
kind: "import-binding",
|
|
3341
|
+
imported: spec.imported,
|
|
3342
|
+
isState: spec.isState,
|
|
3343
|
+
moduleSource: clause.source
|
|
3344
|
+
};
|
|
3345
|
+
}
|
|
3346
|
+
}
|
|
3347
|
+
}
|
|
3348
|
+
const sym = resolveSymbol(tokens, tok);
|
|
3349
|
+
if (sym && sym.kind !== "import") return { kind: "local", range: sym.range };
|
|
3350
|
+
return null;
|
|
3351
|
+
}
|
|
3352
|
+
function findDeclaration(source, name, isState) {
|
|
3353
|
+
const table = collectSymbols(tokenize(source));
|
|
3354
|
+
const decl = isState ? table.state.get(name) : table.ident.get(name);
|
|
3355
|
+
if (!decl || decl.kind === "import") return null;
|
|
3356
|
+
return decl.range;
|
|
3357
|
+
}
|
|
3358
|
+
function getReferences(source, position, options = {}) {
|
|
3359
|
+
const includeDeclaration = options.includeDeclaration ?? true;
|
|
3360
|
+
const tokens = tokenize(source);
|
|
3361
|
+
const tok = findNameTokenAt(tokens, position);
|
|
3362
|
+
if (!tok) return [];
|
|
3363
|
+
const refs = occurrences(tokens, tok.type, tok.value);
|
|
3364
|
+
if (includeDeclaration) return refs;
|
|
3365
|
+
const sym = resolveSymbol(tokens, tok);
|
|
3366
|
+
if (!sym) return refs;
|
|
3367
|
+
return refs.filter((r) => !rangesEqual(r, sym.range));
|
|
3368
|
+
}
|
|
3369
|
+
function getDocumentHighlights(source, position) {
|
|
3370
|
+
return getReferences(source, position, { includeDeclaration: true });
|
|
3371
|
+
}
|
|
3372
|
+
function getRenameEdits(source, position, newName) {
|
|
3373
|
+
const tokens = tokenize(source);
|
|
3374
|
+
const tok = findNameTokenAt(tokens, position);
|
|
3375
|
+
if (!tok) return { edits: [], error: "No symbol to rename at this position." };
|
|
3376
|
+
const sym = resolveSymbol(tokens, tok);
|
|
3377
|
+
if (!sym) {
|
|
3378
|
+
return {
|
|
3379
|
+
edits: [],
|
|
3380
|
+
error: "Only file-scoped components, actions, hooks, and reactive atoms can be renamed."
|
|
3381
|
+
};
|
|
3382
|
+
}
|
|
3383
|
+
const bare = sym.sigil ? newName.replace(/^\$/, "") : newName;
|
|
3384
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(bare)) {
|
|
3385
|
+
return { edits: [], error: `"${newName}" is not a valid Aktion identifier.` };
|
|
3386
|
+
}
|
|
3387
|
+
const replacement = sym.sigil ? `$${bare}` : bare;
|
|
3388
|
+
const edits = occurrences(tokens, tok.type, tok.value).map((range) => ({
|
|
3389
|
+
range,
|
|
3390
|
+
newText: replacement
|
|
3391
|
+
}));
|
|
3392
|
+
return { edits };
|
|
3393
|
+
}
|
|
3394
|
+
function getDocumentSymbols(source) {
|
|
3395
|
+
const tokens = tokenize(source);
|
|
3396
|
+
const table = collectSymbols(tokens);
|
|
3397
|
+
return table.all.map((decl) => ({
|
|
3398
|
+
name: decl.sigil ? `$${decl.name}` : decl.name,
|
|
3399
|
+
detail: detailFor(decl.kind),
|
|
3400
|
+
kind: decl.kind,
|
|
3401
|
+
range: decl.range,
|
|
3402
|
+
selectionRange: decl.range
|
|
3403
|
+
}));
|
|
3404
|
+
}
|
|
3405
|
+
function resolveSymbol(tokens, tok) {
|
|
3406
|
+
const table = collectSymbols(tokens);
|
|
3407
|
+
if (tok.type === "StateIdentifier") return table.state.get(tok.value) ?? null;
|
|
3408
|
+
return table.ident.get(tok.value) ?? null;
|
|
3409
|
+
}
|
|
3410
|
+
function collectSymbols(tokens) {
|
|
3411
|
+
const table = { state: /* @__PURE__ */ new Map(), ident: /* @__PURE__ */ new Map(), all: [] };
|
|
3412
|
+
const add = (decl) => {
|
|
3413
|
+
const bucket = decl.sigil ? table.state : table.ident;
|
|
3414
|
+
if (bucket.has(decl.name)) return;
|
|
3415
|
+
bucket.set(decl.name, decl);
|
|
3416
|
+
table.all.push(decl);
|
|
3417
|
+
};
|
|
3418
|
+
let depth = 0;
|
|
3419
|
+
let stmtStart = true;
|
|
3420
|
+
for (let i = 0; i < tokens.length; i += 1) {
|
|
3421
|
+
const t = tokens[i];
|
|
3422
|
+
if (t.type === "Newline" || t.type === "Semicolon") {
|
|
3423
|
+
stmtStart = true;
|
|
3424
|
+
continue;
|
|
3425
|
+
}
|
|
3426
|
+
if (t.type === "EOF") break;
|
|
3427
|
+
if (t.type === "Keyword" && t.value === "import") {
|
|
3428
|
+
i = scanImport(tokens, i, add);
|
|
3429
|
+
stmtStart = true;
|
|
3430
|
+
continue;
|
|
3431
|
+
}
|
|
3432
|
+
if (t.type === "Keyword" && t.value === "function") {
|
|
3433
|
+
const nameTok = nextMeaningful$1(tokens, i + 1);
|
|
3434
|
+
if (nameTok) {
|
|
3435
|
+
if (nameTok.type === "StateIdentifier") {
|
|
3436
|
+
add({ name: nameTok.value, kind: "hook", sigil: true, range: tokenRange(nameTok) });
|
|
3437
|
+
} else if (nameTok.type === "Identifier") {
|
|
3438
|
+
add({
|
|
3439
|
+
name: nameTok.value,
|
|
3440
|
+
kind: isPascalCase(nameTok.value) ? "component" : "action",
|
|
3441
|
+
sigil: false,
|
|
3442
|
+
range: tokenRange(nameTok)
|
|
3443
|
+
});
|
|
3444
|
+
}
|
|
3445
|
+
}
|
|
3446
|
+
}
|
|
3447
|
+
if (t.type === "StateIdentifier" && stmtStart && depth === 0) {
|
|
3448
|
+
const next = nextMeaningful$1(tokens, i + 1);
|
|
3449
|
+
if (next && next.type === "Operator" && next.value === "=") {
|
|
3450
|
+
add({ name: t.value, kind: "state", sigil: true, range: tokenRange(t) });
|
|
3451
|
+
}
|
|
3452
|
+
}
|
|
3453
|
+
if (t.type === "Punctuation" && t.value === "{") {
|
|
3454
|
+
depth += 1;
|
|
3455
|
+
stmtStart = true;
|
|
3456
|
+
} else if (t.type === "Punctuation" && t.value === "}") {
|
|
3457
|
+
depth = Math.max(0, depth - 1);
|
|
3458
|
+
stmtStart = true;
|
|
3459
|
+
} else if (t.type === "Keyword" && t.value === "export") ;
|
|
3460
|
+
else {
|
|
3461
|
+
stmtStart = false;
|
|
3462
|
+
}
|
|
3463
|
+
}
|
|
3464
|
+
return table;
|
|
3465
|
+
}
|
|
3466
|
+
function scanImport(tokens, start, add) {
|
|
3467
|
+
const { clause, end } = readImportClause(tokens, start);
|
|
3468
|
+
for (const spec of clause.specifiers) {
|
|
3469
|
+
add({ name: spec.local, kind: "import", sigil: spec.isState, range: spec.localRange });
|
|
3470
|
+
}
|
|
3471
|
+
return end;
|
|
3472
|
+
}
|
|
3473
|
+
function parseImports(tokens) {
|
|
3474
|
+
const clauses = [];
|
|
3475
|
+
for (let i = 0; i < tokens.length; i += 1) {
|
|
3476
|
+
if (tokens[i].type === "Keyword" && tokens[i].value === "import") {
|
|
3477
|
+
const { clause, end } = readImportClause(tokens, i);
|
|
3478
|
+
clauses.push(clause);
|
|
3479
|
+
i = end;
|
|
3480
|
+
}
|
|
3481
|
+
}
|
|
3482
|
+
return clauses;
|
|
3483
|
+
}
|
|
3484
|
+
function readImportClause(tokens, start) {
|
|
3485
|
+
const names = [];
|
|
3486
|
+
let source = "";
|
|
3487
|
+
let sourceRange = null;
|
|
3488
|
+
let i = start + 1;
|
|
3489
|
+
for (; i < tokens.length; i += 1) {
|
|
3490
|
+
const t = tokens[i];
|
|
3491
|
+
if (t.type === "Newline" || t.type === "Semicolon" || t.type === "EOF") break;
|
|
3492
|
+
if (t.type === "Identifier" && t.value === "from") {
|
|
3493
|
+
const src = nextMeaningful$1(tokens, i + 1);
|
|
3494
|
+
if (src && src.type === "String") {
|
|
3495
|
+
source = src.value;
|
|
3496
|
+
sourceRange = {
|
|
3497
|
+
start: { line: src.line, column: src.column },
|
|
3498
|
+
end: { line: src.line, column: src.column + src.value.length + 2 }
|
|
3499
|
+
};
|
|
3500
|
+
}
|
|
3501
|
+
break;
|
|
3502
|
+
}
|
|
3503
|
+
if (t.type === "Punctuation") continue;
|
|
3504
|
+
if (t.type === "Identifier" || t.type === "StateIdentifier") names.push(t);
|
|
3505
|
+
}
|
|
3506
|
+
const specifiers = [];
|
|
3507
|
+
for (let n = 0; n < names.length; n += 1) {
|
|
3508
|
+
const nameTok = names[n];
|
|
3509
|
+
const asTok = names[n + 1];
|
|
3510
|
+
if (asTok && asTok.type === "Identifier" && asTok.value === "as" && names[n + 2]) {
|
|
3511
|
+
const aliasTok = names[n + 2];
|
|
3512
|
+
specifiers.push({
|
|
3513
|
+
imported: nameTok.value,
|
|
3514
|
+
local: aliasTok.value,
|
|
3515
|
+
isState: aliasTok.type === "StateIdentifier",
|
|
3516
|
+
localRange: tokenRange(aliasTok)
|
|
3517
|
+
});
|
|
3518
|
+
n += 2;
|
|
3519
|
+
} else {
|
|
3520
|
+
specifiers.push({
|
|
3521
|
+
imported: nameTok.value,
|
|
3522
|
+
local: nameTok.value,
|
|
3523
|
+
isState: nameTok.type === "StateIdentifier",
|
|
3524
|
+
localRange: tokenRange(nameTok)
|
|
3525
|
+
});
|
|
3526
|
+
}
|
|
3527
|
+
}
|
|
3528
|
+
return { clause: { source, sourceRange, specifiers }, end: i - 1 };
|
|
3529
|
+
}
|
|
3530
|
+
function positionInRange(position, range) {
|
|
3531
|
+
if (position.line !== range.start.line || position.line !== range.end.line) return false;
|
|
3532
|
+
return position.column >= range.start.column && position.column <= range.end.column;
|
|
3533
|
+
}
|
|
3534
|
+
function occurrences(tokens, type, value) {
|
|
3535
|
+
const out = [];
|
|
3536
|
+
for (const t of tokens) {
|
|
3537
|
+
if (t.type === type && t.value === value) out.push(tokenRange(t));
|
|
3538
|
+
}
|
|
3539
|
+
return out;
|
|
3540
|
+
}
|
|
3541
|
+
function findNameTokenAt(tokens, position) {
|
|
3542
|
+
let best = null;
|
|
3543
|
+
for (const t of tokens) {
|
|
3544
|
+
if (t.type !== "Identifier" && t.type !== "StateIdentifier") continue;
|
|
3545
|
+
if (t.line !== position.line) continue;
|
|
3546
|
+
const startCol = t.column;
|
|
3547
|
+
const endCol = t.column + tokenTextLength(t);
|
|
3548
|
+
if (position.column >= startCol && position.column <= endCol) {
|
|
3549
|
+
if (!best || t.column > best.column) best = t;
|
|
3550
|
+
}
|
|
3551
|
+
}
|
|
3552
|
+
return best;
|
|
3553
|
+
}
|
|
3554
|
+
function nextMeaningful$1(tokens, from) {
|
|
3555
|
+
for (let i = from; i < tokens.length; i += 1) {
|
|
3556
|
+
const t = tokens[i];
|
|
3557
|
+
if (t.type === "Newline") continue;
|
|
3558
|
+
return t;
|
|
3559
|
+
}
|
|
3560
|
+
return null;
|
|
3561
|
+
}
|
|
3562
|
+
function tokenTextLength(t) {
|
|
3563
|
+
return t.type === "StateIdentifier" ? t.value.length + 1 : t.value.length;
|
|
3564
|
+
}
|
|
3565
|
+
function tokenRange(t) {
|
|
3566
|
+
const length = tokenTextLength(t);
|
|
3567
|
+
return {
|
|
3568
|
+
start: { line: t.line, column: t.column },
|
|
3569
|
+
end: { line: t.line, column: t.column + length }
|
|
3570
|
+
};
|
|
3571
|
+
}
|
|
3572
|
+
function rangesEqual(a, b) {
|
|
3573
|
+
return a.start.line === b.start.line && a.start.column === b.start.column && a.end.line === b.end.line && a.end.column === b.end.column;
|
|
3574
|
+
}
|
|
3575
|
+
function isPascalCase(name) {
|
|
3576
|
+
return /^[A-Z]/.test(name);
|
|
3577
|
+
}
|
|
3578
|
+
function detailFor(kind) {
|
|
3579
|
+
switch (kind) {
|
|
3580
|
+
case "component":
|
|
3581
|
+
return "component";
|
|
3582
|
+
case "action":
|
|
3583
|
+
return "action";
|
|
3584
|
+
case "hook":
|
|
3585
|
+
return "hook";
|
|
3586
|
+
case "state":
|
|
3587
|
+
return "reactive atom";
|
|
3588
|
+
case "import":
|
|
3589
|
+
return "import";
|
|
3590
|
+
default:
|
|
3591
|
+
return "";
|
|
3592
|
+
}
|
|
3593
|
+
}
|
|
3083
3594
|
const SUPPORTED_VARIANTS = /* @__PURE__ */ new Set(["solid", "regular", "brands"]);
|
|
3084
3595
|
const DEFAULT_VARIANT = "solid";
|
|
3085
3596
|
function resolveIconClasses(value) {
|
|
@@ -4086,9 +4597,15 @@ const ScrollArea = {
|
|
|
4086
4597
|
}
|
|
4087
4598
|
};
|
|
4088
4599
|
const MODAL_SIZES = ["sm", "md", "lg", "xl", "full"];
|
|
4600
|
+
const FOCUSABLE_SELECTOR = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
4601
|
+
let modalIdSeq = 0;
|
|
4602
|
+
function activeWithin(el2) {
|
|
4603
|
+
const root = el2.getRootNode();
|
|
4604
|
+
return root.activeElement ?? null;
|
|
4605
|
+
}
|
|
4089
4606
|
const Modal = {
|
|
4090
4607
|
name: "Modal",
|
|
4091
|
-
description: "Dialog overlay shown when `open` is true. Pass a `$variable` as `open` to control it. The header always renders a × close button (disable via `closable: false`); the optional `footer` slot is the canonical place for action buttons. `closeOnBackdrop=true` opts in to backdrop-click dismissal. `onClose` fires every time the modal closes (× button, backdrop, programmatic state write).",
|
|
4608
|
+
description: "Dialog overlay shown when `open` is true. Pass a `$variable` as `open` to control it. The header always renders a × close button (disable via `closable: false`); the optional `footer` slot is the canonical place for action buttons. `closeOnBackdrop=true` opts in to backdrop-click dismissal. `onClose` fires every time the modal closes (× button, backdrop, programmatic state write). Accessible by default: the dialog is labelled by its title, focus moves into it on open and is restored on close, Tab is trapped inside, and Escape closes it (unless `closable: false`).",
|
|
4092
4609
|
props: [
|
|
4093
4610
|
{ name: "title", type: "string" },
|
|
4094
4611
|
{ name: "open", type: "boolean", description: "Open/closed state — usually a $variable" },
|
|
@@ -4106,14 +4623,20 @@ const Modal = {
|
|
|
4106
4623
|
class: "rui-modal-overlay",
|
|
4107
4624
|
"data-open": asBoolean(props.open) ? "true" : "false"
|
|
4108
4625
|
});
|
|
4626
|
+
const titleIdSlot = helpers.useInstanceState("rui-modal-title-id", "");
|
|
4627
|
+
if (!titleIdSlot.get()) titleIdSlot.set(`rui-modal-title-${modalIdSeq += 1}`);
|
|
4628
|
+
const titleId = titleIdSlot.get();
|
|
4109
4629
|
const dialog = el("div", {
|
|
4110
4630
|
class: "rui-modal",
|
|
4111
4631
|
role: "dialog",
|
|
4112
4632
|
"aria-modal": "true",
|
|
4633
|
+
"aria-labelledby": titleId,
|
|
4634
|
+
// Focusable so we can move focus into the dialog on open.
|
|
4635
|
+
tabindex: "-1",
|
|
4113
4636
|
"data-size": size
|
|
4114
4637
|
});
|
|
4115
4638
|
const header = el("header", { class: "rui-modal-header" });
|
|
4116
|
-
header.append(el("h3", { class: "rui-modal-title" }, [asString(props.title)]));
|
|
4639
|
+
header.append(el("h3", { class: "rui-modal-title", id: titleId }, [asString(props.title)]));
|
|
4117
4640
|
const stateName = node.argMeta?.[1]?.stateRef;
|
|
4118
4641
|
const closeModal = () => {
|
|
4119
4642
|
if (stateName) helpers.setState(stateName, false);
|
|
@@ -4147,6 +4670,54 @@ const Modal = {
|
|
|
4147
4670
|
if (event.target === overlay) closeModal();
|
|
4148
4671
|
};
|
|
4149
4672
|
}
|
|
4673
|
+
const isOpen = asBoolean(props.open);
|
|
4674
|
+
dialog.addEventListener("keydown", (event) => {
|
|
4675
|
+
if (event.key === "Escape" && closable) {
|
|
4676
|
+
event.stopPropagation();
|
|
4677
|
+
closeModal();
|
|
4678
|
+
return;
|
|
4679
|
+
}
|
|
4680
|
+
if (event.key !== "Tab") return;
|
|
4681
|
+
const items = [...dialog.querySelectorAll(FOCUSABLE_SELECTOR)];
|
|
4682
|
+
if (items.length === 0) {
|
|
4683
|
+
event.preventDefault();
|
|
4684
|
+
dialog.focus();
|
|
4685
|
+
return;
|
|
4686
|
+
}
|
|
4687
|
+
const first = items[0];
|
|
4688
|
+
const last = items[items.length - 1];
|
|
4689
|
+
const active = activeWithin(dialog);
|
|
4690
|
+
if (event.shiftKey && active === first) {
|
|
4691
|
+
event.preventDefault();
|
|
4692
|
+
last.focus();
|
|
4693
|
+
} else if (!event.shiftKey && active === last) {
|
|
4694
|
+
event.preventDefault();
|
|
4695
|
+
first.focus();
|
|
4696
|
+
}
|
|
4697
|
+
});
|
|
4698
|
+
const focusSlot = helpers.useInstanceState(
|
|
4699
|
+
"rui-modal-focus",
|
|
4700
|
+
{ open: false, prev: null }
|
|
4701
|
+
);
|
|
4702
|
+
const prevState = focusSlot.get();
|
|
4703
|
+
if (isOpen && !prevState.open) {
|
|
4704
|
+
const previouslyFocused = activeWithin(dialog);
|
|
4705
|
+
focusSlot.set({ open: true, prev: previouslyFocused });
|
|
4706
|
+
const focusFirst = () => {
|
|
4707
|
+
const items = [...dialog.querySelectorAll(FOCUSABLE_SELECTOR)];
|
|
4708
|
+
(items[0] ?? dialog).focus();
|
|
4709
|
+
};
|
|
4710
|
+
if (typeof queueMicrotask === "function") queueMicrotask(focusFirst);
|
|
4711
|
+
else void Promise.resolve().then(focusFirst);
|
|
4712
|
+
} else if (!isOpen && prevState.open) {
|
|
4713
|
+
const toRestore = prevState.prev;
|
|
4714
|
+
focusSlot.set({ open: false, prev: null });
|
|
4715
|
+
if (toRestore && typeof toRestore.focus === "function") {
|
|
4716
|
+
const restore = () => toRestore.focus();
|
|
4717
|
+
if (typeof queueMicrotask === "function") queueMicrotask(restore);
|
|
4718
|
+
else void Promise.resolve().then(restore);
|
|
4719
|
+
}
|
|
4720
|
+
}
|
|
4150
4721
|
return overlay;
|
|
4151
4722
|
}
|
|
4152
4723
|
};
|
|
@@ -5179,6 +5750,40 @@ const OnIntersect = {
|
|
|
5179
5750
|
return wrapper;
|
|
5180
5751
|
}
|
|
5181
5752
|
};
|
|
5753
|
+
const OnMount = {
|
|
5754
|
+
name: "OnMount",
|
|
5755
|
+
description: "Run imperative code against the wrapped component's rendered DOM node. `onMount(node)` fires once, on a microtask after the child is attached to the DOM — the Aktion way to get a DOM ref (measure an element, focus it, or hand it to an imperative library such as a chart / map / editor). `onUnmount(node)` fires when the component leaves the tree. Pair with `$ref(...)` to stash the node across renders.",
|
|
5756
|
+
props: [
|
|
5757
|
+
{ name: "child", type: "Node", positional: true, required: true, aliases: ["children"] },
|
|
5758
|
+
{ name: "onMount", type: "callable", optional: true, description: "`(node) => void` — fired once after the wrapped element is attached." },
|
|
5759
|
+
{ name: "onUnmount", type: "callable", optional: true, description: "`(node) => void` — fired when the wrapped element leaves the tree." }
|
|
5760
|
+
],
|
|
5761
|
+
render: (_node, props, helpers) => {
|
|
5762
|
+
const wrapper = el("span", {
|
|
5763
|
+
class: "rui-wrapper rui-on-mount",
|
|
5764
|
+
style: "display: contents;"
|
|
5765
|
+
});
|
|
5766
|
+
wrapper.append(renderChildAsNode(helpers, props.child));
|
|
5767
|
+
const mounted = helpers.useInstanceState("rui-on-mount", false);
|
|
5768
|
+
if (!mounted.get()) {
|
|
5769
|
+
mounted.set(true);
|
|
5770
|
+
const fire = () => {
|
|
5771
|
+
const node = wrapper.firstElementChild ?? wrapper;
|
|
5772
|
+
if (props.onMount != null) helpers.invoke(props.onMount, node);
|
|
5773
|
+
if (props.onUnmount != null) {
|
|
5774
|
+
helpers.registerDisposer(() => {
|
|
5775
|
+
const run = () => helpers.invoke(props.onUnmount, node);
|
|
5776
|
+
if (typeof queueMicrotask === "function") queueMicrotask(run);
|
|
5777
|
+
else void Promise.resolve().then(run);
|
|
5778
|
+
}, "rui-on-mount-unmount");
|
|
5779
|
+
}
|
|
5780
|
+
};
|
|
5781
|
+
if (typeof queueMicrotask === "function") queueMicrotask(fire);
|
|
5782
|
+
else void Promise.resolve().then(fire);
|
|
5783
|
+
}
|
|
5784
|
+
return wrapper;
|
|
5785
|
+
}
|
|
5786
|
+
};
|
|
5182
5787
|
function renderLinkChildren(helpers, child) {
|
|
5183
5788
|
if (child == null) return [];
|
|
5184
5789
|
if (typeof child === "string") return [document.createTextNode(child)];
|
|
@@ -8983,7 +9588,9 @@ const Toast = {
|
|
|
8983
9588
|
const position = asString(props.position);
|
|
8984
9589
|
const root = el("div", {
|
|
8985
9590
|
class: position ? "rui-toast rui-toast-standalone" : "rui-toast",
|
|
8986
|
-
|
|
9591
|
+
// Danger toasts are interruptive — `alert` + `assertive` so screen
|
|
9592
|
+
// readers announce them immediately; others are polite `status`.
|
|
9593
|
+
role: tone === "danger" ? "alert" : "status",
|
|
8987
9594
|
"aria-live": tone === "danger" ? "assertive" : "polite",
|
|
8988
9595
|
"data-tone": tone,
|
|
8989
9596
|
"data-position": position || null
|
|
@@ -12919,7 +13526,7 @@ const TopBar = {
|
|
|
12919
13526
|
};
|
|
12920
13527
|
const NavLink = {
|
|
12921
13528
|
name: "NavLink",
|
|
12922
|
-
description: 'Anchor that navigates to a route on click and stays in sync with the URL hash. Reflects `data-active="true"` when the current path matches `to` (set `exact=true` to require exact equality instead of prefix matching).',
|
|
13529
|
+
description: 'Anchor that navigates to a route on click and stays in sync with the URL hash. Reflects `data-active="true"` (and `aria-current="page"` for assistive tech) when the current path matches `to` (set `exact=true` to require exact equality instead of prefix matching).',
|
|
12923
13530
|
props: [
|
|
12924
13531
|
{ name: "label", type: "string", description: "Visible link text." },
|
|
12925
13532
|
{ name: "to", type: "string", description: 'Target route path, e.g. "/about".' },
|
|
@@ -12961,6 +13568,8 @@ const NavLink = {
|
|
|
12961
13568
|
class: "rui-nav-link",
|
|
12962
13569
|
"data-variant": variant,
|
|
12963
13570
|
"data-active": isActive ? "true" : "false",
|
|
13571
|
+
// Expose the active route to assistive tech, not just CSS.
|
|
13572
|
+
"aria-current": isActive ? "page" : null,
|
|
12964
13573
|
href: "#" + (to.startsWith("/") ? to : "/" + to)
|
|
12965
13574
|
});
|
|
12966
13575
|
const iconNode = renderIcon(props.icon, { className: "rui-nav-link-icon" });
|
|
@@ -13807,7 +14416,7 @@ const Redirect = {
|
|
|
13807
14416
|
};
|
|
13808
14417
|
const Lazy = {
|
|
13809
14418
|
name: "Lazy",
|
|
13810
|
-
description: "Defer rendering `
|
|
14419
|
+
description: "Defer rendering until an async `loader` resolves: show `fallback` while pending, then render the resolved value (or `children`). A synchronous loader value renders immediately.",
|
|
13811
14420
|
props: [
|
|
13812
14421
|
{ name: "loader", type: "any", positional: true, required: true },
|
|
13813
14422
|
{ name: "fallback", type: "Node", optional: true },
|
|
@@ -13815,18 +14424,54 @@ const Lazy = {
|
|
|
13815
14424
|
],
|
|
13816
14425
|
render: (_node, props, helpers) => {
|
|
13817
14426
|
const loader = props.loader;
|
|
13818
|
-
|
|
13819
|
-
|
|
13820
|
-
|
|
13821
|
-
|
|
13822
|
-
|
|
14427
|
+
const slot = helpers.useInstanceState("rui-lazy", { status: "init" });
|
|
14428
|
+
const wrapper = el("span", { class: "rui-lazy", style: "display: contents;" });
|
|
14429
|
+
const paint = (value) => {
|
|
14430
|
+
wrapper.replaceChildren(renderChild(helpers, value));
|
|
14431
|
+
};
|
|
14432
|
+
const fallback = () => props.fallback ?? null;
|
|
14433
|
+
const resolvedContent = (value) => value ?? props.children ?? null;
|
|
14434
|
+
const state = slot.get();
|
|
14435
|
+
if (state.status === "resolved") {
|
|
14436
|
+
paint(resolvedContent(state.value));
|
|
14437
|
+
return wrapper;
|
|
14438
|
+
}
|
|
14439
|
+
if (state.status === "pending" || state.status === "error") {
|
|
14440
|
+
paint(fallback());
|
|
14441
|
+
return wrapper;
|
|
14442
|
+
}
|
|
14443
|
+
let result;
|
|
14444
|
+
try {
|
|
14445
|
+
result = typeof loader === "function" ? loader() : loader;
|
|
14446
|
+
} catch {
|
|
14447
|
+
slot.set({ status: "error" });
|
|
14448
|
+
paint(fallback());
|
|
14449
|
+
return wrapper;
|
|
14450
|
+
}
|
|
14451
|
+
if (result && typeof result.then === "function") {
|
|
14452
|
+
slot.set({ status: "pending" });
|
|
14453
|
+
paint(fallback());
|
|
14454
|
+
let cancelled = false;
|
|
14455
|
+
helpers.registerDisposer(() => {
|
|
14456
|
+
cancelled = true;
|
|
14457
|
+
}, "rui-lazy-cancel");
|
|
14458
|
+
void result.then(
|
|
14459
|
+
(value) => {
|
|
14460
|
+
if (cancelled) return;
|
|
14461
|
+
slot.set({ status: "resolved", value });
|
|
14462
|
+
paint(resolvedContent(value));
|
|
14463
|
+
},
|
|
14464
|
+
() => {
|
|
14465
|
+
if (cancelled) return;
|
|
14466
|
+
slot.set({ status: "error" });
|
|
14467
|
+
paint(fallback());
|
|
13823
14468
|
}
|
|
13824
|
-
|
|
13825
|
-
|
|
13826
|
-
return renderChild(helpers, props.fallback ?? null);
|
|
13827
|
-
}
|
|
14469
|
+
);
|
|
14470
|
+
return wrapper;
|
|
13828
14471
|
}
|
|
13829
|
-
|
|
14472
|
+
slot.set({ status: "resolved", value: result });
|
|
14473
|
+
paint(resolvedContent(result));
|
|
14474
|
+
return wrapper;
|
|
13830
14475
|
}
|
|
13831
14476
|
};
|
|
13832
14477
|
const ErrorBoundary = {
|
|
@@ -14236,6 +14881,7 @@ const components = [
|
|
|
14236
14881
|
OnKeyboard,
|
|
14237
14882
|
OnFocus,
|
|
14238
14883
|
OnIntersect,
|
|
14884
|
+
OnMount,
|
|
14239
14885
|
Css,
|
|
14240
14886
|
Link,
|
|
14241
14887
|
// Escape hatches for raw HTML / CSS — last-resort primitives
|
|
@@ -14607,7 +15253,7 @@ const componentGroups = [
|
|
|
14607
15253
|
"- `Show(when, { fallback?, children })` is sugar over `if (expr) { children } else { fallback }`.",
|
|
14608
15254
|
"- `Portal(target?, children)` renders into a different DOM subtree (defaults to `document.body`).",
|
|
14609
15255
|
"- `Redirect(path)` is a router-aware component — see Routing.",
|
|
14610
|
-
"- `Lazy(loader, fallback?)` defers
|
|
15256
|
+
"- `Lazy(loader, fallback?)` defers rendering until the async `loader` resolves, showing `fallback` while pending (a synchronous loader value renders immediately).",
|
|
14611
15257
|
"- `ErrorBoundary(fallback?, onError?, children)` catches rendering errors thrown by descendants."
|
|
14612
15258
|
]
|
|
14613
15259
|
},
|
|
@@ -14619,6 +15265,7 @@ const componentGroups = [
|
|
|
14619
15265
|
"OnKeyboard",
|
|
14620
15266
|
"OnFocus",
|
|
14621
15267
|
"OnIntersect",
|
|
15268
|
+
"OnMount",
|
|
14622
15269
|
"Css",
|
|
14623
15270
|
"Link"
|
|
14624
15271
|
],
|
|
@@ -14629,6 +15276,7 @@ const componentGroups = [
|
|
|
14629
15276
|
"- `OnKeyboard(child, { onKeyDown?, onKeyUp?, onKeyPress?, focusable? })` attaches keyboard listeners. The wrapper is focusable by default; pass `focusable: false` when the child is already focusable (input, button).",
|
|
14630
15277
|
"- `OnFocus(child, { onFocus?, onBlur? })` tracks focus moving into or out of a subtree (uses bubbling `focusin` / `focusout` so descendants count).",
|
|
14631
15278
|
"- `OnIntersect(child, { onEnter?, onLeave?, onChange?, threshold?, rootMargin?, once? })` is the IntersectionObserver wrapper — perfect for lazy-load sentinels, infinite-scroll triggers, impression analytics, and reveal-on-scroll animations.",
|
|
15279
|
+
"- `OnMount(child, { onMount?, onUnmount? })` is the DOM-ref / lifecycle wrapper. `onMount(node)` fires once after the wrapped element attaches; `onUnmount(node)` fires when it leaves the tree. Use it to measure or focus an element, or to hand a node to an imperative library (chart / map / editor). Stash the node in a `$ref(...)`.",
|
|
14632
15280
|
"- `Css(child, { style?, class? })` merges raw class tokens and inline styles onto the wrapped child. Reach for it ONLY when the standard component props can't express the styling — prefer `Box`/`Stack`/`Grid` for layout and `$theme(...)` for tokens.",
|
|
14633
15281
|
"- `Link(label_or_child, { to?, href?, external?, variant? })` is the anchor primitive — accepts either a plain string label or a wrapped component. Use `to` for client-side router navigation and `href` (with `external: true`) for outbound links."
|
|
14634
15282
|
]
|
|
@@ -14649,6 +15297,284 @@ const defaultLibrary = {
|
|
|
14649
15297
|
components,
|
|
14650
15298
|
componentGroups
|
|
14651
15299
|
};
|
|
15300
|
+
const semanticTokenTypes = [
|
|
15301
|
+
"namespace",
|
|
15302
|
+
"class",
|
|
15303
|
+
"function",
|
|
15304
|
+
"variable",
|
|
15305
|
+
"property",
|
|
15306
|
+
"keyword",
|
|
15307
|
+
"number"
|
|
15308
|
+
];
|
|
15309
|
+
const semanticTokenModifiers = ["declaration", "defaultLibrary"];
|
|
15310
|
+
const HANDLE_KEYWORDS = /* @__PURE__ */ new Set(["route", "aktion"]);
|
|
15311
|
+
function getSemanticTokens(source, library = defaultLibrary) {
|
|
15312
|
+
const tokens = tokenize(source);
|
|
15313
|
+
const components2 = new Set(library.components.map((c) => c.name));
|
|
15314
|
+
const userComponents = /* @__PURE__ */ new Set();
|
|
15315
|
+
const userActions = /* @__PURE__ */ new Set();
|
|
15316
|
+
const hooks = /* @__PURE__ */ new Set();
|
|
15317
|
+
collectUserDeclarations(tokens, userComponents, userActions, hooks);
|
|
15318
|
+
const out = [];
|
|
15319
|
+
let prev;
|
|
15320
|
+
for (const t of tokens) {
|
|
15321
|
+
const classified = classify(t, prev, {
|
|
15322
|
+
components: components2,
|
|
15323
|
+
userComponents,
|
|
15324
|
+
userActions,
|
|
15325
|
+
hooks
|
|
15326
|
+
});
|
|
15327
|
+
if (classified) {
|
|
15328
|
+
out.push({
|
|
15329
|
+
line: t.line,
|
|
15330
|
+
column: t.column,
|
|
15331
|
+
length: tokenLength(t),
|
|
15332
|
+
tokenType: classified.type,
|
|
15333
|
+
tokenModifiers: classified.modifiers
|
|
15334
|
+
});
|
|
15335
|
+
}
|
|
15336
|
+
if (t.type !== "Newline") prev = t;
|
|
15337
|
+
}
|
|
15338
|
+
return out;
|
|
15339
|
+
}
|
|
15340
|
+
function classify(t, prev, scope) {
|
|
15341
|
+
if (t.type === "Keyword") return { type: "keyword", modifiers: [] };
|
|
15342
|
+
if (t.type === "Number") return { type: "number", modifiers: [] };
|
|
15343
|
+
if (t.type === "StateIdentifier") {
|
|
15344
|
+
const builtin = findBuiltin(t.value);
|
|
15345
|
+
if (builtin) {
|
|
15346
|
+
return {
|
|
15347
|
+
type: builtin.namespace ? "namespace" : "function",
|
|
15348
|
+
modifiers: ["defaultLibrary"]
|
|
15349
|
+
};
|
|
15350
|
+
}
|
|
15351
|
+
if (scope.hooks.has(t.value)) return { type: "function", modifiers: [] };
|
|
15352
|
+
return { type: "variable", modifiers: [] };
|
|
15353
|
+
}
|
|
15354
|
+
if (t.type === "Identifier") {
|
|
15355
|
+
if (HANDLE_KEYWORDS.has(t.value)) return { type: "keyword", modifiers: [] };
|
|
15356
|
+
if (isMemberAccess(prev)) return { type: "property", modifiers: [] };
|
|
15357
|
+
if (scope.components.has(t.value)) {
|
|
15358
|
+
return { type: "class", modifiers: ["defaultLibrary"] };
|
|
15359
|
+
}
|
|
15360
|
+
if (scope.userComponents.has(t.value)) return { type: "class", modifiers: [] };
|
|
15361
|
+
if (scope.userActions.has(t.value)) return { type: "function", modifiers: [] };
|
|
15362
|
+
if (/^[A-Z]/.test(t.value)) return { type: "class", modifiers: [] };
|
|
15363
|
+
return null;
|
|
15364
|
+
}
|
|
15365
|
+
return null;
|
|
15366
|
+
}
|
|
15367
|
+
function isMemberAccess(prev) {
|
|
15368
|
+
if (!prev) return false;
|
|
15369
|
+
return prev.type === "Punctuation" && prev.value === "." || prev.type === "Operator" && prev.value === "?.";
|
|
15370
|
+
}
|
|
15371
|
+
function collectUserDeclarations(tokens, components2, actions, hooks) {
|
|
15372
|
+
for (let i = 0; i < tokens.length; i += 1) {
|
|
15373
|
+
const t = tokens[i];
|
|
15374
|
+
if (t.type === "Keyword" && t.value === "function") {
|
|
15375
|
+
const next = nextMeaningful(tokens, i + 1);
|
|
15376
|
+
if (!next) continue;
|
|
15377
|
+
if (next.type === "StateIdentifier") hooks.add(next.value);
|
|
15378
|
+
else if (next.type === "Identifier") {
|
|
15379
|
+
if (/^[A-Z]/.test(next.value)) components2.add(next.value);
|
|
15380
|
+
else actions.add(next.value);
|
|
15381
|
+
}
|
|
15382
|
+
}
|
|
15383
|
+
}
|
|
15384
|
+
}
|
|
15385
|
+
function nextMeaningful(tokens, from) {
|
|
15386
|
+
for (let i = from; i < tokens.length; i += 1) {
|
|
15387
|
+
const t = tokens[i];
|
|
15388
|
+
if (t.type === "Newline") continue;
|
|
15389
|
+
return t;
|
|
15390
|
+
}
|
|
15391
|
+
return null;
|
|
15392
|
+
}
|
|
15393
|
+
function tokenLength(t) {
|
|
15394
|
+
return t.type === "StateIdentifier" ? t.value.length + 1 : t.value.length;
|
|
15395
|
+
}
|
|
15396
|
+
const projectParam = (prop) => {
|
|
15397
|
+
const param = {
|
|
15398
|
+
name: prop.name,
|
|
15399
|
+
type: prop.type,
|
|
15400
|
+
required: !prop.optional
|
|
15401
|
+
};
|
|
15402
|
+
if (prop.description) param.description = prop.description;
|
|
15403
|
+
if (prop.enum && prop.enum.length > 0) param.enumValues = prop.enum;
|
|
15404
|
+
return param;
|
|
15405
|
+
};
|
|
15406
|
+
const buildSignature = (spec) => {
|
|
15407
|
+
const parts = spec.props.map((p) => p.optional ? `${p.name}?` : p.name);
|
|
15408
|
+
return `${spec.name}(${parts.join(", ")})`;
|
|
15409
|
+
};
|
|
15410
|
+
const buildGroupIndex = (library) => {
|
|
15411
|
+
const index = /* @__PURE__ */ new Map();
|
|
15412
|
+
for (const group of library.componentGroups ?? []) {
|
|
15413
|
+
for (const name of group.components) index.set(name, group.name);
|
|
15414
|
+
}
|
|
15415
|
+
return index;
|
|
15416
|
+
};
|
|
15417
|
+
function getComponentCatalog(library = defaultLibrary) {
|
|
15418
|
+
const groupOf = buildGroupIndex(library);
|
|
15419
|
+
return library.components.map((spec) => ({
|
|
15420
|
+
name: spec.name,
|
|
15421
|
+
group: groupOf.get(spec.name) ?? "Other",
|
|
15422
|
+
description: spec.description,
|
|
15423
|
+
params: spec.props.map(projectParam),
|
|
15424
|
+
signature: buildSignature(spec)
|
|
15425
|
+
}));
|
|
15426
|
+
}
|
|
15427
|
+
function indexCatalog(entries) {
|
|
15428
|
+
const out = {};
|
|
15429
|
+
for (const entry of entries) out[entry.name] = entry;
|
|
15430
|
+
return out;
|
|
15431
|
+
}
|
|
15432
|
+
function getSignatureHelp(source, position, library = defaultLibrary) {
|
|
15433
|
+
const call = findActiveCall(source, position);
|
|
15434
|
+
if (!call || !call.callee) return null;
|
|
15435
|
+
const signature = libraryComponentSignature(call.callee, library) ?? builtinSignature(call.callee) ?? userSignature(call.callee, source);
|
|
15436
|
+
if (!signature) return null;
|
|
15437
|
+
const activeParameter = signature.parameters.length > 0 ? Math.min(call.argIndex, signature.parameters.length - 1) : 0;
|
|
15438
|
+
return { signatures: [signature], activeSignature: 0, activeParameter };
|
|
15439
|
+
}
|
|
15440
|
+
let cachedCatalog = null;
|
|
15441
|
+
function catalogFor(library) {
|
|
15442
|
+
if (cachedCatalog && cachedCatalog.library === library) return cachedCatalog.byName;
|
|
15443
|
+
const byName = {};
|
|
15444
|
+
for (const entry of getComponentCatalog(library)) byName[entry.name] = entry;
|
|
15445
|
+
cachedCatalog = { library, byName };
|
|
15446
|
+
return byName;
|
|
15447
|
+
}
|
|
15448
|
+
function libraryComponentSignature(callee, library) {
|
|
15449
|
+
const entry = catalogFor(library)[callee];
|
|
15450
|
+
if (!entry) return null;
|
|
15451
|
+
return {
|
|
15452
|
+
label: entry.signature,
|
|
15453
|
+
documentation: entry.description,
|
|
15454
|
+
parameters: entry.params.map((p) => ({
|
|
15455
|
+
label: p.required ? p.name : `${p.name}?`,
|
|
15456
|
+
documentation: paramDoc(p.type, p.enumValues, p.description)
|
|
15457
|
+
}))
|
|
15458
|
+
};
|
|
15459
|
+
}
|
|
15460
|
+
function builtinSignature(callee) {
|
|
15461
|
+
if (!callee.startsWith("$")) return null;
|
|
15462
|
+
const builtin = findBuiltin(callee.slice(1));
|
|
15463
|
+
if (!builtin) return null;
|
|
15464
|
+
return { label: builtin.signature, documentation: builtin.summary, parameters: [] };
|
|
15465
|
+
}
|
|
15466
|
+
function userSignature(callee, source) {
|
|
15467
|
+
let program;
|
|
15468
|
+
try {
|
|
15469
|
+
program = parse(source);
|
|
15470
|
+
} catch {
|
|
15471
|
+
return null;
|
|
15472
|
+
}
|
|
15473
|
+
for (const stmt of program.statements) {
|
|
15474
|
+
const matches = (stmt.kind === "ComponentDeclaration" || stmt.kind === "ActionDeclaration" || stmt.kind === "HookDeclaration") && stmt.name === callee;
|
|
15475
|
+
if (!matches) continue;
|
|
15476
|
+
const decl = stmt;
|
|
15477
|
+
const params = decl.params.map((p) => ({
|
|
15478
|
+
label: paramLabel(p)
|
|
15479
|
+
}));
|
|
15480
|
+
const label = `${callee}(${params.map((p) => p.label).join(", ")})`;
|
|
15481
|
+
return { label, documentation: `Declared in this file (${kindLabel(stmt.kind)}).`, parameters: params };
|
|
15482
|
+
}
|
|
15483
|
+
return null;
|
|
15484
|
+
}
|
|
15485
|
+
function paramLabel(p) {
|
|
15486
|
+
if (p.rest) return `...${p.name}`;
|
|
15487
|
+
return p.optional ? `${p.name}?` : p.name;
|
|
15488
|
+
}
|
|
15489
|
+
function kindLabel(kind) {
|
|
15490
|
+
if (kind === "ComponentDeclaration") return "component";
|
|
15491
|
+
if (kind === "ActionDeclaration") return "action";
|
|
15492
|
+
return "hook";
|
|
15493
|
+
}
|
|
15494
|
+
function paramDoc(type, enumValues, description) {
|
|
15495
|
+
const parts = [type];
|
|
15496
|
+
if (enumValues && enumValues.length > 0) {
|
|
15497
|
+
parts.push(`enum: ${enumValues.map((e) => `"${e}"`).join(" | ")}`);
|
|
15498
|
+
}
|
|
15499
|
+
const head = parts.join(" — ");
|
|
15500
|
+
return description ? `${head}
|
|
15501
|
+
|
|
15502
|
+
${description}` : head;
|
|
15503
|
+
}
|
|
15504
|
+
function findActiveCall(source, position) {
|
|
15505
|
+
const offset = lineColumnToOffset(source, position);
|
|
15506
|
+
const stack = [];
|
|
15507
|
+
for (let i = 0; i < offset; i += 1) {
|
|
15508
|
+
const ch = source[i];
|
|
15509
|
+
if (ch === "/" && source[i + 1] === "/") {
|
|
15510
|
+
while (i < offset && source[i] !== "\n") i += 1;
|
|
15511
|
+
continue;
|
|
15512
|
+
}
|
|
15513
|
+
if (ch === "/" && source[i + 1] === "*") {
|
|
15514
|
+
i += 2;
|
|
15515
|
+
while (i < offset && !(source[i] === "*" && source[i + 1] === "/")) i += 1;
|
|
15516
|
+
i += 1;
|
|
15517
|
+
continue;
|
|
15518
|
+
}
|
|
15519
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
15520
|
+
i = skipString(source, i, ch, offset);
|
|
15521
|
+
continue;
|
|
15522
|
+
}
|
|
15523
|
+
if (ch === "(" || ch === "[" || ch === "{") {
|
|
15524
|
+
const callee = ch === "(" ? identifierBefore(source, i) : "";
|
|
15525
|
+
stack.push({ bracket: ch, callee, commas: 0 });
|
|
15526
|
+
continue;
|
|
15527
|
+
}
|
|
15528
|
+
if (ch === ")" || ch === "]" || ch === "}") {
|
|
15529
|
+
stack.pop();
|
|
15530
|
+
continue;
|
|
15531
|
+
}
|
|
15532
|
+
if (ch === "," && stack.length > 0) {
|
|
15533
|
+
stack[stack.length - 1].commas += 1;
|
|
15534
|
+
}
|
|
15535
|
+
}
|
|
15536
|
+
for (let i = stack.length - 1; i >= 0; i -= 1) {
|
|
15537
|
+
const frame = stack[i];
|
|
15538
|
+
if (frame.bracket === "(") {
|
|
15539
|
+
return { callee: frame.callee, argIndex: frame.commas };
|
|
15540
|
+
}
|
|
15541
|
+
}
|
|
15542
|
+
return null;
|
|
15543
|
+
}
|
|
15544
|
+
function skipString(source, start, quote, limit) {
|
|
15545
|
+
let i = start + 1;
|
|
15546
|
+
while (i < limit) {
|
|
15547
|
+
const ch = source[i];
|
|
15548
|
+
if (ch === "\\") {
|
|
15549
|
+
i += 2;
|
|
15550
|
+
continue;
|
|
15551
|
+
}
|
|
15552
|
+
if (ch === quote) return i;
|
|
15553
|
+
i += 1;
|
|
15554
|
+
}
|
|
15555
|
+
return limit - 1;
|
|
15556
|
+
}
|
|
15557
|
+
function identifierBefore(source, parenIndex) {
|
|
15558
|
+
let end = parenIndex;
|
|
15559
|
+
while (end > 0 && /\s/.test(source[end - 1])) end -= 1;
|
|
15560
|
+
let start = end;
|
|
15561
|
+
while (start > 0 && /[\w$]/.test(source[start - 1])) start -= 1;
|
|
15562
|
+
return source.slice(start, end);
|
|
15563
|
+
}
|
|
15564
|
+
function lineColumnToOffset(source, pos) {
|
|
15565
|
+
let line = 1;
|
|
15566
|
+
let col = 1;
|
|
15567
|
+
for (let i = 0; i < source.length; i += 1) {
|
|
15568
|
+
if (line === pos.line && col === pos.column) return i;
|
|
15569
|
+
if (source[i] === "\n") {
|
|
15570
|
+
line += 1;
|
|
15571
|
+
col = 1;
|
|
15572
|
+
} else {
|
|
15573
|
+
col += 1;
|
|
15574
|
+
}
|
|
15575
|
+
}
|
|
15576
|
+
return source.length;
|
|
15577
|
+
}
|
|
14652
15578
|
const baseFonts = {
|
|
14653
15579
|
fontFamily: "system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif",
|
|
14654
15580
|
fontFamilyHeading: "system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif",
|
|
@@ -14994,42 +15920,6 @@ const builtInThemes = {
|
|
|
14994
15920
|
brutalist: brutalistTheme,
|
|
14995
15921
|
skyline: skylineTheme
|
|
14996
15922
|
};
|
|
14997
|
-
const projectParam = (prop) => {
|
|
14998
|
-
const param = {
|
|
14999
|
-
name: prop.name,
|
|
15000
|
-
type: prop.type,
|
|
15001
|
-
required: !prop.optional
|
|
15002
|
-
};
|
|
15003
|
-
if (prop.description) param.description = prop.description;
|
|
15004
|
-
if (prop.enum && prop.enum.length > 0) param.enumValues = prop.enum;
|
|
15005
|
-
return param;
|
|
15006
|
-
};
|
|
15007
|
-
const buildSignature = (spec) => {
|
|
15008
|
-
const parts = spec.props.map((p) => p.optional ? `${p.name}?` : p.name);
|
|
15009
|
-
return `${spec.name}(${parts.join(", ")})`;
|
|
15010
|
-
};
|
|
15011
|
-
const buildGroupIndex = (library) => {
|
|
15012
|
-
const index = /* @__PURE__ */ new Map();
|
|
15013
|
-
for (const group of library.componentGroups ?? []) {
|
|
15014
|
-
for (const name of group.components) index.set(name, group.name);
|
|
15015
|
-
}
|
|
15016
|
-
return index;
|
|
15017
|
-
};
|
|
15018
|
-
function getComponentCatalog(library = defaultLibrary) {
|
|
15019
|
-
const groupOf = buildGroupIndex(library);
|
|
15020
|
-
return library.components.map((spec) => ({
|
|
15021
|
-
name: spec.name,
|
|
15022
|
-
group: groupOf.get(spec.name) ?? "Other",
|
|
15023
|
-
description: spec.description,
|
|
15024
|
-
params: spec.props.map(projectParam),
|
|
15025
|
-
signature: buildSignature(spec)
|
|
15026
|
-
}));
|
|
15027
|
-
}
|
|
15028
|
-
function indexCatalog(entries) {
|
|
15029
|
-
const out = {};
|
|
15030
|
-
for (const entry of entries) out[entry.name] = entry;
|
|
15031
|
-
return out;
|
|
15032
|
-
}
|
|
15033
15923
|
const snippetCatalog = [
|
|
15034
15924
|
{
|
|
15035
15925
|
name: "App",
|
|
@@ -15188,6 +16078,7 @@ function getLanguageSpec(library = defaultLibrary) {
|
|
|
15188
16078
|
tagMap: defaultTagMap,
|
|
15189
16079
|
components: components2,
|
|
15190
16080
|
componentsByName: indexCatalog(components2),
|
|
16081
|
+
builtins: builtinCatalog,
|
|
15191
16082
|
snippets: getSnippets(),
|
|
15192
16083
|
keywordDocs,
|
|
15193
16084
|
themeNames: Object.keys(builtInThemes),
|
|
@@ -15297,15 +16188,374 @@ const COMMON_ICON_ALIASES = [
|
|
|
15297
16188
|
"thumbs-down",
|
|
15298
16189
|
"thumbtack"
|
|
15299
16190
|
];
|
|
16191
|
+
const INDENT = " ";
|
|
16192
|
+
const SAFE_IDENT = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
16193
|
+
const NEEDS_DOUBLE_QUOTE = /[\\"]/;
|
|
16194
|
+
function formatProgram(source) {
|
|
16195
|
+
const program = parse(source);
|
|
16196
|
+
if (program.errors.length > 0) {
|
|
16197
|
+
return { formatted: source, errors: [...program.errors] };
|
|
16198
|
+
}
|
|
16199
|
+
const out = printProgram(program);
|
|
16200
|
+
const second = parse(out);
|
|
16201
|
+
if (second.errors.length > 0) {
|
|
16202
|
+
return { formatted: source, errors: [] };
|
|
16203
|
+
}
|
|
16204
|
+
return { formatted: out, errors: [] };
|
|
16205
|
+
}
|
|
16206
|
+
function printProgram(program) {
|
|
16207
|
+
const lines = [];
|
|
16208
|
+
let prev = null;
|
|
16209
|
+
for (const stmt of program.statements) {
|
|
16210
|
+
if (prev && needsBlankLineBetween(prev, stmt)) lines.push("");
|
|
16211
|
+
lines.push(printStatement(stmt, 0));
|
|
16212
|
+
prev = stmt;
|
|
16213
|
+
}
|
|
16214
|
+
return lines.join("\n") + "\n";
|
|
16215
|
+
}
|
|
16216
|
+
function needsBlankLineBetween(prev, next) {
|
|
16217
|
+
const heavy = /* @__PURE__ */ new Set([
|
|
16218
|
+
"ComponentDeclaration",
|
|
16219
|
+
"EffectDeclaration",
|
|
16220
|
+
"ActionDeclaration",
|
|
16221
|
+
"HookDeclaration"
|
|
16222
|
+
]);
|
|
16223
|
+
if (heavy.has(prev.kind) || heavy.has(next.kind)) return true;
|
|
16224
|
+
return false;
|
|
16225
|
+
}
|
|
16226
|
+
function printStatement(stmt, indent) {
|
|
16227
|
+
const pad = INDENT.repeat(indent);
|
|
16228
|
+
const exp = "exported" in stmt && stmt.exported ? "export " : "";
|
|
16229
|
+
switch (stmt.kind) {
|
|
16230
|
+
case "Import": {
|
|
16231
|
+
const specs = stmt.specifiers.map((s) => {
|
|
16232
|
+
const imported = s.isState ? `$${s.imported}` : s.imported;
|
|
16233
|
+
if (s.local === s.imported) return imported;
|
|
16234
|
+
const local = s.isState ? `$${s.local}` : s.local;
|
|
16235
|
+
return `${imported} as ${local}`;
|
|
16236
|
+
}).join(", ");
|
|
16237
|
+
return `${pad}import { ${specs} } from "${stmt.source}"`;
|
|
16238
|
+
}
|
|
16239
|
+
case "Assignment": {
|
|
16240
|
+
const lhs = stmt.isState ? `$${stmt.identifier}` : stmt.identifier;
|
|
16241
|
+
const expr = printExpression(stmt.expression, indent);
|
|
16242
|
+
return `${pad}${exp}${lhs} = ${expr}`;
|
|
16243
|
+
}
|
|
16244
|
+
case "ComponentDeclaration": {
|
|
16245
|
+
const params = stmt.params.map(printDeclParam).join(", ");
|
|
16246
|
+
const head = `${pad}${exp}function ${stmt.name}(${params}) {`;
|
|
16247
|
+
const body = printBlock(stmt.body.body, indent + 1);
|
|
16248
|
+
return body.length > 0 ? `${head}
|
|
16249
|
+
${body}
|
|
16250
|
+
${pad}}` : `${head}
|
|
16251
|
+
${pad}}`;
|
|
16252
|
+
}
|
|
16253
|
+
case "EffectDeclaration": {
|
|
16254
|
+
const deps = stmt.triggers.map(printTrigger).filter((s) => s.length > 0);
|
|
16255
|
+
if (stmt.rateLimit) {
|
|
16256
|
+
deps.push(`"${stmt.rateLimit.kind}(${stmt.rateLimit.ms})"`);
|
|
16257
|
+
}
|
|
16258
|
+
const body = printBlock(stmt.body.body, indent + 1);
|
|
16259
|
+
const depsArray = `[${deps.join(", ")}]`;
|
|
16260
|
+
return `${pad}$effect(() => {
|
|
16261
|
+
${body}
|
|
16262
|
+
${pad}}, ${depsArray})`;
|
|
16263
|
+
}
|
|
16264
|
+
case "ActionDeclaration": {
|
|
16265
|
+
const params = stmt.params.map(printDeclParam).join(", ");
|
|
16266
|
+
const head = `${pad}${exp}function ${stmt.name}(${params}) {`;
|
|
16267
|
+
const body = printBlock(stmt.body.body, indent + 1);
|
|
16268
|
+
return `${head}
|
|
16269
|
+
${body}
|
|
16270
|
+
${pad}}`;
|
|
16271
|
+
}
|
|
16272
|
+
case "HookDeclaration": {
|
|
16273
|
+
const params = stmt.params.map(printDeclParam).join(", ");
|
|
16274
|
+
const head = `${pad}${exp}function $${stmt.name}(${params}) {`;
|
|
16275
|
+
const body = printBlock(stmt.body.body, indent + 1);
|
|
16276
|
+
return `${head}
|
|
16277
|
+
${body}
|
|
16278
|
+
${pad}}`;
|
|
16279
|
+
}
|
|
16280
|
+
case "Await": {
|
|
16281
|
+
return `${pad}await ${printExpression(stmt.argument, indent)}`;
|
|
16282
|
+
}
|
|
16283
|
+
case "Return": {
|
|
16284
|
+
return stmt.argument ? `${pad}return ${printExpression(stmt.argument, indent)}` : `${pad}return`;
|
|
16285
|
+
}
|
|
16286
|
+
case "ExpressionStatement": {
|
|
16287
|
+
return `${pad}${printExpression(stmt.expression, indent)}`;
|
|
16288
|
+
}
|
|
16289
|
+
case "IfStatement": {
|
|
16290
|
+
const test = printExpression(stmt.test, indent);
|
|
16291
|
+
const cons = `{
|
|
16292
|
+
${printBlock(stmt.consequent.body, indent + 1)}
|
|
16293
|
+
${pad}}`;
|
|
16294
|
+
if (!stmt.alternate) return `${pad}if (${test}) ${cons}`;
|
|
16295
|
+
const alt = stmt.alternate.kind === "IfStatement" ? printStatement(stmt.alternate, indent).trimStart() : `{
|
|
16296
|
+
${printBlock(stmt.alternate.body, indent + 1)}
|
|
16297
|
+
${pad}}`;
|
|
16298
|
+
return `${pad}if (${test}) ${cons} else ${alt}`;
|
|
16299
|
+
}
|
|
16300
|
+
case "SwitchStatement": {
|
|
16301
|
+
const disc = printExpression(stmt.discriminant, indent);
|
|
16302
|
+
const cases = stmt.cases.map((c) => printSwitchCase(c, indent + 1)).join("\n");
|
|
16303
|
+
return `${pad}switch (${disc}) {
|
|
16304
|
+
${cases}
|
|
16305
|
+
${pad}}`;
|
|
16306
|
+
}
|
|
16307
|
+
case "ForOfStatement": {
|
|
16308
|
+
const iter = printExpression(stmt.iterable, indent);
|
|
16309
|
+
const body = `{
|
|
16310
|
+
${printBlock(stmt.body.body, indent + 1)}
|
|
16311
|
+
${pad}}`;
|
|
16312
|
+
return `${pad}for (let ${stmt.item} of ${iter}) ${body}`;
|
|
16313
|
+
}
|
|
16314
|
+
case "ForClassicStatement": {
|
|
16315
|
+
const init = stmt.init ? printStatement(stmt.init, 0).trimStart() : "";
|
|
16316
|
+
const test = stmt.test ? printExpression(stmt.test, indent) : "";
|
|
16317
|
+
const update = stmt.update ? printExpression(stmt.update, indent) : "";
|
|
16318
|
+
const body = `{
|
|
16319
|
+
${printBlock(stmt.body.body, indent + 1)}
|
|
16320
|
+
${pad}}`;
|
|
16321
|
+
return `${pad}for (${init}; ${test}; ${update}) ${body}`;
|
|
16322
|
+
}
|
|
16323
|
+
case "WhileStatement": {
|
|
16324
|
+
const test = printExpression(stmt.test, indent);
|
|
16325
|
+
const body = `{
|
|
16326
|
+
${printBlock(stmt.body.body, indent + 1)}
|
|
16327
|
+
${pad}}`;
|
|
16328
|
+
return `${pad}while (${test}) ${body}`;
|
|
16329
|
+
}
|
|
16330
|
+
case "DoWhileStatement": {
|
|
16331
|
+
const test = printExpression(stmt.test, indent);
|
|
16332
|
+
const body = `{
|
|
16333
|
+
${printBlock(stmt.body.body, indent + 1)}
|
|
16334
|
+
${pad}}`;
|
|
16335
|
+
return `${pad}do ${body} while (${test})`;
|
|
16336
|
+
}
|
|
16337
|
+
case "ForInStatement": {
|
|
16338
|
+
const iter = printExpression(stmt.iterable, indent);
|
|
16339
|
+
const body = `{
|
|
16340
|
+
${printBlock(stmt.body.body, indent + 1)}
|
|
16341
|
+
${pad}}`;
|
|
16342
|
+
return `${pad}for (let ${stmt.item} in ${iter}) ${body}`;
|
|
16343
|
+
}
|
|
16344
|
+
case "DestructureStatement": {
|
|
16345
|
+
const open = stmt.patternKind === "array" ? "[" : "{";
|
|
16346
|
+
const close = stmt.patternKind === "array" ? "]" : "}";
|
|
16347
|
+
const parts = stmt.bindings.map((b) => {
|
|
16348
|
+
const lead = b.rest ? "..." : "";
|
|
16349
|
+
const keyed = b.sourceKey ? `${b.sourceKey}: ${b.name}` : b.name || "";
|
|
16350
|
+
const def = b.defaultValue ? ` = ${printExpression(b.defaultValue, indent)}` : "";
|
|
16351
|
+
return `${lead}${keyed}${def}`;
|
|
16352
|
+
});
|
|
16353
|
+
const expr = printExpression(stmt.expression, indent);
|
|
16354
|
+
return `${pad}let ${open}${parts.join(", ")}${close} = ${expr}`;
|
|
16355
|
+
}
|
|
16356
|
+
case "BreakStatement":
|
|
16357
|
+
return `${pad}break`;
|
|
16358
|
+
case "ContinueStatement":
|
|
16359
|
+
return `${pad}continue`;
|
|
16360
|
+
case "ThrowStatement":
|
|
16361
|
+
return `${pad}throw ${printExpression(stmt.argument, indent)}`;
|
|
16362
|
+
case "TryStatement": {
|
|
16363
|
+
const block = `{
|
|
16364
|
+
${printBlock(stmt.block.body, indent + 1)}
|
|
16365
|
+
${pad}}`;
|
|
16366
|
+
let out = `${pad}try ${block}`;
|
|
16367
|
+
if (stmt.catchBlock) {
|
|
16368
|
+
const catchHead = stmt.catchParam ? ` (${stmt.catchParam})` : "";
|
|
16369
|
+
const catchBody = `{
|
|
16370
|
+
${printBlock(stmt.catchBlock.body, indent + 1)}
|
|
16371
|
+
${pad}}`;
|
|
16372
|
+
out += ` catch${catchHead} ${catchBody}`;
|
|
16373
|
+
}
|
|
16374
|
+
if (stmt.finallyBlock) {
|
|
16375
|
+
const finBody = `{
|
|
16376
|
+
${printBlock(stmt.finallyBlock.body, indent + 1)}
|
|
16377
|
+
${pad}}`;
|
|
16378
|
+
out += ` finally ${finBody}`;
|
|
16379
|
+
}
|
|
16380
|
+
return out;
|
|
16381
|
+
}
|
|
16382
|
+
}
|
|
16383
|
+
}
|
|
16384
|
+
function printDeclParam(p) {
|
|
16385
|
+
if (p.defaultValue) {
|
|
16386
|
+
return `${p.name} = ${printExpression(p.defaultValue, 0)}`;
|
|
16387
|
+
}
|
|
16388
|
+
return p.name;
|
|
16389
|
+
}
|
|
16390
|
+
function printTrigger(t) {
|
|
16391
|
+
if (t.kind === "lifecycle") return `"${t.name}"`;
|
|
16392
|
+
if (t.kind === "every") return `"every(${t.intervalMs})"`;
|
|
16393
|
+
if (t.kind === "state") return `$${t.name}`;
|
|
16394
|
+
return "";
|
|
16395
|
+
}
|
|
16396
|
+
function printBlock(stmts, indent) {
|
|
16397
|
+
return stmts.map((s) => printStatement(s, indent)).join("\n");
|
|
16398
|
+
}
|
|
16399
|
+
function printExpression(expr, indent) {
|
|
16400
|
+
switch (expr.kind) {
|
|
16401
|
+
case "Literal":
|
|
16402
|
+
return printLiteral(expr.value);
|
|
16403
|
+
case "Identifier":
|
|
16404
|
+
return expr.name;
|
|
16405
|
+
case "StateRef":
|
|
16406
|
+
return `$${expr.name}`;
|
|
16407
|
+
case "Array": {
|
|
16408
|
+
if (expr.elements.length === 0) return "[]";
|
|
16409
|
+
const items = expr.elements.map((e) => printExpression(e, indent));
|
|
16410
|
+
const inline = `[${items.join(", ")}]`;
|
|
16411
|
+
if (inline.length <= 80 && !items.some((s) => s.includes("\n"))) return inline;
|
|
16412
|
+
const pad = INDENT.repeat(indent + 1);
|
|
16413
|
+
return `[
|
|
16414
|
+
${items.map((s) => `${pad}${s}`).join(",\n")}
|
|
16415
|
+
${INDENT.repeat(indent)}]`;
|
|
16416
|
+
}
|
|
16417
|
+
case "Object": {
|
|
16418
|
+
if (expr.properties.length === 0) return "{}";
|
|
16419
|
+
const items = expr.properties.map((p) => printObjectProp(p, indent));
|
|
16420
|
+
const inline = `{ ${items.join(", ")} }`;
|
|
16421
|
+
if (inline.length <= 80 && !items.some((s) => s.includes("\n"))) return inline;
|
|
16422
|
+
const pad = INDENT.repeat(indent + 1);
|
|
16423
|
+
return `{
|
|
16424
|
+
${items.map((s) => `${pad}${s}`).join(",\n")}
|
|
16425
|
+
${INDENT.repeat(indent)}}`;
|
|
16426
|
+
}
|
|
16427
|
+
case "Member": {
|
|
16428
|
+
const obj = printExpression(expr.object, indent);
|
|
16429
|
+
const dot = expr.optional ? "?." : ".";
|
|
16430
|
+
if (expr.property) return `${obj}${dot}${expr.property}`;
|
|
16431
|
+
if (expr.computed) {
|
|
16432
|
+
const inner = printExpression(expr.computed, indent);
|
|
16433
|
+
return expr.optional ? `${obj}?.[${inner}]` : `${obj}[${inner}]`;
|
|
16434
|
+
}
|
|
16435
|
+
return obj;
|
|
16436
|
+
}
|
|
16437
|
+
case "Unary":
|
|
16438
|
+
return `${expr.operator}${printExpression(expr.argument, indent)}`;
|
|
16439
|
+
case "Binary":
|
|
16440
|
+
return `${printExpression(expr.left, indent)} ${expr.operator} ${printExpression(expr.right, indent)}`;
|
|
16441
|
+
case "Ternary":
|
|
16442
|
+
return `${printExpression(expr.test, indent)} ? ${printExpression(expr.consequent, indent)} : ${printExpression(expr.alternate, indent)}`;
|
|
16443
|
+
case "Call":
|
|
16444
|
+
return printCall(expr.callee, expr.arguments, indent);
|
|
16445
|
+
case "MethodCall": {
|
|
16446
|
+
const target = printExpression(expr.object, indent);
|
|
16447
|
+
const sep = expr.optional ? "?." : ".";
|
|
16448
|
+
return printCall(`${target}${sep}${expr.method}`, expr.arguments, indent);
|
|
16449
|
+
}
|
|
16450
|
+
case "Invoke": {
|
|
16451
|
+
const callee = printExpression(expr.callee, indent);
|
|
16452
|
+
const sep = expr.optional ? "?." : "";
|
|
16453
|
+
return printCall(`${callee}${sep}`, expr.arguments, indent);
|
|
16454
|
+
}
|
|
16455
|
+
case "New": {
|
|
16456
|
+
const callee = printExpression(expr.callee, indent);
|
|
16457
|
+
return `new ${printCall(callee, expr.arguments, indent)}`;
|
|
16458
|
+
}
|
|
16459
|
+
case "BuiltinCall":
|
|
16460
|
+
return printCall(`@${expr.name}`, expr.arguments, indent);
|
|
16461
|
+
case "Template":
|
|
16462
|
+
return printTemplate(expr.quasis, expr.expressions, indent);
|
|
16463
|
+
case "Spread":
|
|
16464
|
+
return `...${printExpression(expr.argument, indent)}`;
|
|
16465
|
+
case "Lambda": {
|
|
16466
|
+
const params = expr.params.map((p) => {
|
|
16467
|
+
const prefix = p.rest ? "..." : "";
|
|
16468
|
+
return p.defaultValue ? `${prefix}${p.name} = ${printExpression(p.defaultValue, indent)}` : `${prefix}${p.name}`;
|
|
16469
|
+
}).join(", ");
|
|
16470
|
+
const head = expr.params.length === 1 && !expr.params[0].defaultValue && !expr.params[0].rest ? expr.params[0].name : `(${params})`;
|
|
16471
|
+
return `${head} => ${printExpression(expr.body, indent)}`;
|
|
16472
|
+
}
|
|
16473
|
+
case "Block":
|
|
16474
|
+
return `{
|
|
16475
|
+
${printBlock(expr.body, indent + 1)}
|
|
16476
|
+
${INDENT.repeat(indent)}}`;
|
|
16477
|
+
}
|
|
16478
|
+
}
|
|
16479
|
+
function printCall(callee, args, indent) {
|
|
16480
|
+
if (args.length === 0) return `${callee}()`;
|
|
16481
|
+
const parts = args.map((a) => printExpression(a, indent));
|
|
16482
|
+
const inline = `${callee}(${parts.join(", ")})`;
|
|
16483
|
+
if (inline.length <= 80 && !parts.some((s) => s.includes("\n"))) return inline;
|
|
16484
|
+
const pad = INDENT.repeat(indent + 1);
|
|
16485
|
+
return `${callee}(
|
|
16486
|
+
${parts.map((s) => `${pad}${s}`).join(",\n")}
|
|
16487
|
+
${INDENT.repeat(indent)})`;
|
|
16488
|
+
}
|
|
16489
|
+
function printSwitchCase(c, indent) {
|
|
16490
|
+
const pad = INDENT.repeat(indent);
|
|
16491
|
+
const body = c.body.map((s) => printStatement(s, indent + 1)).join("\n");
|
|
16492
|
+
if (c.test === null) {
|
|
16493
|
+
return `${pad}default:
|
|
16494
|
+
${body}
|
|
16495
|
+
${printStatement({ kind: "ExpressionStatement", expression: { kind: "Identifier", name: "break" } }, indent + 1)}`;
|
|
16496
|
+
}
|
|
16497
|
+
return `${pad}case ${printExpression(c.test, indent)}:
|
|
16498
|
+
${body}
|
|
16499
|
+
${INDENT.repeat(indent + 1)}break`;
|
|
16500
|
+
}
|
|
16501
|
+
function printObjectProp(prop, indent) {
|
|
16502
|
+
if (prop.spread) return `...${printExpression(prop.value, indent)}`;
|
|
16503
|
+
const value = printExpression(prop.value, indent);
|
|
16504
|
+
if (prop.value.kind === "Identifier" && prop.value.name === prop.key && SAFE_IDENT.test(prop.key)) {
|
|
16505
|
+
return prop.key;
|
|
16506
|
+
}
|
|
16507
|
+
const key = SAFE_IDENT.test(prop.key) ? prop.key : printStringLiteral(prop.key);
|
|
16508
|
+
return `${key}: ${value}`;
|
|
16509
|
+
}
|
|
16510
|
+
function printLiteral(value) {
|
|
16511
|
+
if (value === null) return "null";
|
|
16512
|
+
if (typeof value === "string") return printStringLiteral(value);
|
|
16513
|
+
if (typeof value === "boolean") return value ? "true" : "false";
|
|
16514
|
+
return String(value);
|
|
16515
|
+
}
|
|
16516
|
+
function printStringLiteral(value) {
|
|
16517
|
+
if (NEEDS_DOUBLE_QUOTE.test(value)) {
|
|
16518
|
+
const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
16519
|
+
return `"${escaped}"`;
|
|
16520
|
+
}
|
|
16521
|
+
return `"${value}"`;
|
|
16522
|
+
}
|
|
16523
|
+
function printTemplate(quasis, expressions, indent) {
|
|
16524
|
+
const parts = [];
|
|
16525
|
+
for (let i = 0; i < quasis.length; i += 1) {
|
|
16526
|
+
parts.push(quasis[i] ?? "");
|
|
16527
|
+
if (i < expressions.length) {
|
|
16528
|
+
parts.push("${");
|
|
16529
|
+
parts.push(printExpression(expressions[i], indent));
|
|
16530
|
+
parts.push("}");
|
|
16531
|
+
}
|
|
16532
|
+
}
|
|
16533
|
+
return `\`${parts.join("")}\``;
|
|
16534
|
+
}
|
|
15300
16535
|
export {
|
|
16536
|
+
builtinCatalog,
|
|
15301
16537
|
defaultLibrary,
|
|
16538
|
+
findBuiltin,
|
|
16539
|
+
findDeclaration,
|
|
16540
|
+
formatProgram,
|
|
15302
16541
|
getCompletions,
|
|
15303
16542
|
getComponentCatalog,
|
|
16543
|
+
getDefinition,
|
|
16544
|
+
getDefinitionTarget,
|
|
15304
16545
|
getDiagnostics,
|
|
16546
|
+
getDocumentHighlights,
|
|
16547
|
+
getDocumentSymbols,
|
|
15305
16548
|
getHoverInfo,
|
|
15306
16549
|
getLanguageSpec,
|
|
16550
|
+
getReferences,
|
|
16551
|
+
getRenameEdits,
|
|
16552
|
+
getSemanticTokens,
|
|
16553
|
+
getSignatureHelp,
|
|
15307
16554
|
getSnippets,
|
|
15308
16555
|
grammarSpec,
|
|
15309
|
-
|
|
16556
|
+
isBuiltinName,
|
|
16557
|
+
keywordDocs,
|
|
16558
|
+
semanticTokenModifiers,
|
|
16559
|
+
semanticTokenTypes
|
|
15310
16560
|
};
|
|
15311
16561
|
//# sourceMappingURL=language.js.map
|