@stacksjs/stx 0.2.657 → 0.2.661
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/dist/{chunk-n9dbjget.js → chunk-0961mx93.js} +1 -1
- package/dist/{chunk-3zbrmm40.js → chunk-09a8tn6e.js} +1 -1
- package/dist/{chunk-py28zkeh.js → chunk-2cb9r3r9.js} +11 -11
- package/dist/{chunk-6w8sjav5.js → chunk-2jv7g2fs.js} +1 -1
- package/dist/{chunk-g3tk83ea.js → chunk-2x9h3whx.js} +1 -1
- package/dist/{chunk-fzxx3rad.js → chunk-2yvqydak.js} +3 -3
- package/dist/{chunk-v5981jwt.js → chunk-3fyj98v9.js} +1 -1
- package/dist/{chunk-zvj935ma.js → chunk-3p8p8sfw.js} +1 -1
- package/dist/{chunk-51kzs978.js → chunk-57nbg2f9.js} +2 -2
- package/dist/{chunk-kt3nk905.js → chunk-5em9ak8r.js} +1 -1
- package/dist/{chunk-47qc69v1.js → chunk-5n6sej6b.js} +1 -1
- package/dist/{chunk-gjwyy7kh.js → chunk-5nfc2tw2.js} +71 -71
- package/dist/{chunk-pcscq080.js → chunk-6qd27t9k.js} +1 -1
- package/dist/{chunk-q68rssa6.js → chunk-714gdfj9.js} +1 -1
- package/dist/{chunk-s3t9tmsz.js → chunk-7ek9yvwk.js} +1 -1
- package/dist/chunk-7j486x8f.js +2 -0
- package/dist/{chunk-vpmfm04j.js → chunk-7rjm58gn.js} +1 -1
- package/dist/chunk-8xypmt6s.js +2 -0
- package/dist/{chunk-gb6229zj.js → chunk-9rh5anvd.js} +2 -2
- package/dist/{chunk-ddtmrma9.js → chunk-9zy4kzqk.js} +1 -1
- package/dist/{chunk-j8g1v38x.js → chunk-afavkkkq.js} +1 -1
- package/dist/chunk-avmqg5t6.js +2 -0
- package/dist/{chunk-aqk9e27b.js → chunk-bt4bd4f5.js} +1 -1
- package/dist/{chunk-m0gd0264.js → chunk-d5k8gx93.js} +1 -1
- package/dist/{chunk-3r5rk2rz.js → chunk-d5vz53t1.js} +2 -2
- package/dist/{chunk-jp4ef6dc.js → chunk-dah90qrm.js} +1 -1
- package/dist/{chunk-2mppsbt3.js → chunk-dn2h9g79.js} +1 -1
- package/dist/{chunk-mgkrnwjk.js → chunk-dr1vedj2.js} +1 -1
- package/dist/{chunk-h39efd30.js → chunk-dv709hnm.js} +1 -1
- package/dist/{chunk-sng45f0b.js → chunk-dyzgrvg3.js} +8 -8
- package/dist/{chunk-vmwdt8fr.js → chunk-een2wqah.js} +6 -6
- package/dist/chunk-eqrkhc18.js +12 -0
- package/dist/{chunk-y463z9qf.js → chunk-eyvex6fk.js} +39 -39
- package/dist/{chunk-zn7ncwb8.js → chunk-f9fty8ty.js} +1 -1
- package/dist/{chunk-7gpxz94n.js → chunk-ghge79wv.js} +1 -1
- package/dist/chunk-j02834qv.js +2 -0
- package/dist/{chunk-h8h2n247.js → chunk-jtheqwp2.js} +5 -5
- package/dist/{chunk-gg3wbfxa.js → chunk-k99f2njc.js} +1 -1
- package/dist/chunk-mdk323pn.js +2 -0
- package/dist/{chunk-nr9z0zeq.js → chunk-mmern3j1.js} +1 -1
- package/dist/{chunk-7nx74hdr.js → chunk-mvv5cpen.js} +1 -1
- package/dist/{chunk-0h3gpwyv.js → chunk-n4x9hytk.js} +56 -56
- package/dist/{chunk-f9xed7c1.js → chunk-nw9x9gsb.js} +1 -1
- package/dist/chunk-p6p29613.js +2 -0
- package/dist/chunk-pnnqftq6.js +2 -0
- package/dist/{chunk-pbxq1rwd.js → chunk-pp4pyeg4.js} +4 -4
- package/dist/{chunk-x29qw59w.js → chunk-px8e8qgp.js} +1 -1
- package/dist/{chunk-mj3fghaq.js → chunk-qzv0mqw5.js} +1 -1
- package/dist/{chunk-a8aqch0j.js → chunk-r1y1k2ky.js} +38 -38
- package/dist/{chunk-nm1ggj8d.js → chunk-rzxhdmz9.js} +1 -1
- package/dist/{chunk-3ey8888k.js → chunk-sk82mf97.js} +1 -1
- package/dist/chunk-snwps673.js +129 -0
- package/dist/{chunk-xmb4ttnf.js → chunk-t1fxzg0m.js} +2 -2
- package/dist/{chunk-28jtt8hn.js → chunk-vp9hse5k.js} +48 -48
- package/dist/chunk-w7dcy972.js +2 -0
- package/dist/{chunk-shbabvaz.js → chunk-w82nvp7r.js} +1 -1
- package/dist/{chunk-3areak0p.js → chunk-wc3e138p.js} +2 -2
- package/dist/{chunk-ndn0rmhs.js → chunk-wcmzr1sk.js} +1 -1
- package/dist/{chunk-64ny75zz.js → chunk-xt9t5wvx.js} +1 -1
- package/dist/chunk-yharrk8v.js +2 -0
- package/dist/{chunk-w6kdpx52.js → chunk-z4fa7nsm.js} +5 -5
- package/dist/{chunk-tnqbck1r.js → chunk-z5qj7enn.js} +1 -1
- package/dist/chunk-zdfja1ap.js +2 -0
- package/dist/{chunk-zd23z1j8.js → chunk-zjnh64wm.js} +1 -1
- package/dist/cli.js +8 -8
- package/dist/craft-entry.js +1 -1
- package/dist/craft.js +1 -1
- package/dist/expressions.js +9 -0
- package/dist/native/bridge/protocol.d.ts +1 -0
- package/dist/native/compiler/bundle.d.ts +1 -0
- package/dist/native/compiler/bundle.js +3 -2
- package/dist/native/compiler/headwind-to-style.d.ts +4 -0
- package/dist/native/compiler/headwind-to-style.js +33 -3
- package/dist/native/compiler/html-to-ir.d.ts +12 -0
- package/dist/native/compiler/html-to-ir.js +56 -5
- package/dist/native/compiler/ir.d.ts +2 -0
- package/dist/native/compiler/render-screen.js +31 -5
- package/dist/native/runtime/binding-tree.js +2 -1
- package/dist/native/runtime/craft-bridge.d.ts +2 -0
- package/dist/native/runtime/craft-bridge.js +13 -3
- package/dist/native/runtime/native-host.d.ts +1 -0
- package/dist/native/runtime/native-host.js +82 -12
- package/dist/native/runtime/shared-screen.js +4 -3
- package/dist/native/runtime/web-navigation.d.ts +18 -0
- package/dist/native/runtime/web-navigation.js +59 -0
- package/dist/native/runtime/web-storage.d.ts +40 -1
- package/dist/native/runtime/web-storage.js +123 -26
- package/dist/native/testing.d.ts +1 -0
- package/dist/native/testing.js +1 -0
- package/dist/native/text-entry.d.ts +51 -0
- package/dist/native/text-entry.js +101 -0
- package/dist/native-build.js +3 -1
- package/dist/pwa.js +1 -1
- package/dist/ssg.js +25 -25
- package/dist/stx-virtual-ts.d.ts +1 -1
- package/dist/stx-virtual-ts.js +3 -1
- package/dist/utils.js +2 -0
- package/package.json +5 -5
- package/dist/chunk-0rs1j4bn.js +0 -2
- package/dist/chunk-1qmc6gg1.js +0 -2
- package/dist/chunk-2e9d0np1.js +0 -2
- package/dist/chunk-62x62wzy.js +0 -2
- package/dist/chunk-7js495j0.js +0 -2
- package/dist/chunk-cbsa2np9.js +0 -2
- package/dist/chunk-egg54kd0.js +0 -12
- package/dist/chunk-ez0s2kvp.js +0 -2
- package/dist/chunk-g884rvhy.js +0 -2
- package/dist/chunk-h42anr8g.js +0 -2
- package/dist/chunk-hz0g9xrq.js +0 -2
- package/dist/chunk-rhzkw6y4.js +0 -128
|
@@ -188,6 +188,7 @@ var bridge = browserBridge;
|
|
|
188
188
|
g.__stxNativeRoute = ${JSON.stringify(initialScreen)};` : "var bridge = g.__stxNativeBridge;"}
|
|
189
189
|
if (!bridge) throw new Error('Missing __stxNativeBridge');
|
|
190
190
|
var routeNames = ${JSON.stringify(routed ? names : ["main"])};
|
|
191
|
+
var shareStorage = ${JSON.stringify(options.shareStorage ?? {})};
|
|
191
192
|
${route}
|
|
192
193
|
g.__stxNativeRoute = routeName;
|
|
193
194
|
var nativeDocument;
|
|
@@ -196,11 +197,11 @@ ${selections}
|
|
|
196
197
|
var screen = null;
|
|
197
198
|
var app = null;
|
|
198
199
|
if (isApp) {
|
|
199
|
-
app = prepareNativeApp(bridge, { routeName: routeName, routeNames: routeNames });
|
|
200
|
+
app = prepareNativeApp(bridge, { routeName: routeName, routeNames: routeNames, shareStorage: shareStorage });
|
|
200
201
|
g.__stxNativeUnmount = function() { app.unmount(); };
|
|
201
202
|
}
|
|
202
203
|
else {
|
|
203
|
-
screen = prepareSharedNativeScreen(nativeDocument, manifest, bridge, { routeName: routeName, routeNames: routeNames });
|
|
204
|
+
screen = prepareSharedNativeScreen(nativeDocument, manifest, bridge, { routeName: routeName, routeNames: routeNames, shareStorage: shareStorage });
|
|
204
205
|
g.__stx_host = screen.host;
|
|
205
206
|
g.__stxNativeUnmount = function() { screen.unmount(); };
|
|
206
207
|
}
|
|
@@ -407,6 +407,8 @@ declare const fontSizes: Record<string, number>;
|
|
|
407
407
|
* ```
|
|
408
408
|
*/
|
|
409
409
|
declare const borderRadius: Record<string, number>;
|
|
410
|
+
/** ARIA state variants a native node can carry: its attribute is on the node, so the layer can follow it. */
|
|
411
|
+
export declare const NATIVE_STATE_VARIANTS: Set<any>;
|
|
410
412
|
// ============================================================================
|
|
411
413
|
// Main Compiler Function
|
|
412
414
|
// ============================================================================
|
|
@@ -421,6 +423,8 @@ export declare interface ClassStyles {
|
|
|
421
423
|
resizeMode?: string
|
|
422
424
|
responsive?: Array<{ min: number, max?: number, style: STXStyle, dark?: STXStyle }>
|
|
423
425
|
disabled?: { style: STXStyle, dark?: STXStyle }
|
|
426
|
+
states?: Record<string, { style: STXStyle, dark?: STXStyle }>
|
|
427
|
+
divide?: { style: STXStyle, dark?: STXStyle }
|
|
424
428
|
}
|
|
425
429
|
// ============================================================================
|
|
426
430
|
// Class Parsers
|
|
@@ -1254,6 +1254,17 @@ function parseShadow(className, style) {
|
|
|
1254
1254
|
Object.assign(style, { shadowColor: "#000000", shadowOpacity: opacity, shadowRadius: radius, shadowOffset: { width: 0, height: offset }, elevation });
|
|
1255
1255
|
return !0;
|
|
1256
1256
|
}
|
|
1257
|
+
function divideAsBorder(name) {
|
|
1258
|
+
const rule = /^divide-(?:(y|x)(?:-(.+))?|(.+))$/.exec(name);
|
|
1259
|
+
if (!rule)
|
|
1260
|
+
return null;
|
|
1261
|
+
if (rule[2] === "reverse")
|
|
1262
|
+
return "";
|
|
1263
|
+
if (rule[1])
|
|
1264
|
+
return `border-${rule[1] === "y" ? "t" : "l"}${rule[2] ? `-${rule[2]}` : ""}`;
|
|
1265
|
+
return `border-${rule[3]}`;
|
|
1266
|
+
}
|
|
1267
|
+
export const NATIVE_STATE_VARIANTS = new Set(["aria-selected", "aria-pressed", "aria-checked", "aria-expanded"]);
|
|
1257
1268
|
const POINTER_ONLY_VARIANTS = new Set(["hover", "group-hover", "peer-hover", "active", "group-active", "visited", "placeholder", "selection", "print", "motion-safe"]), WEB_ONLY_UTILITY = /^(?:transition(?:-[a-z]+)?|duration-\S+|ease-\S+|delay-\S+|will-change-\S+|cursor-\S+|select-(?:none|text|all|auto)|outline-none|outline-0|appearance-none|scroll-smooth|scroll-auto|antialiased|subpixel-antialiased|touch-\S+|resize(?:-\S+)?|backdrop-blur(?:-\S+)?|isolate|contain-\S+)$/;
|
|
1258
1269
|
function splitVariants(token) {
|
|
1259
1270
|
const parts = [];
|
|
@@ -1305,7 +1316,7 @@ export function compileClassStyles(classes, variables, options = {}) {
|
|
|
1305
1316
|
continue;
|
|
1306
1317
|
if (WEB_ONLY_UTILITY.test(utility) || !focusing && parts.some((variant) => POINTER_ONLY_VARIANTS.has(variant)))
|
|
1307
1318
|
continue;
|
|
1308
|
-
let min, max, disabled = !1;
|
|
1319
|
+
let min, max, disabled = !1, state;
|
|
1309
1320
|
const kept = [];
|
|
1310
1321
|
for (const variant of parts) {
|
|
1311
1322
|
const width = nativeBreakpoint(variant), below = variant.startsWith("max-") ? nativeBreakpoint(variant.slice(4)) : void 0;
|
|
@@ -1315,11 +1326,13 @@ export function compileClassStyles(classes, variables, options = {}) {
|
|
|
1315
1326
|
max = below - 0.02;
|
|
1316
1327
|
else if (variant === "disabled" && !disabled)
|
|
1317
1328
|
disabled = !0;
|
|
1329
|
+
else if (NATIVE_STATE_VARIANTS.has(variant) && state === void 0)
|
|
1330
|
+
state = variant;
|
|
1318
1331
|
else
|
|
1319
1332
|
kept.push(variant);
|
|
1320
1333
|
}
|
|
1321
|
-
const stripped = [...kept, utility].join(":"), ranged = min !== void 0 || max !== void 0, target = disabled ? group("disabled", { disabled: !0 }) : ranged ? group(`range:${min ?? 0}:${max ?? ""}`, { min: min ?? 0, max }) : groups.get("base");
|
|
1322
|
-
if (disabled && ranged) {
|
|
1334
|
+
const stripped = [...kept, utility].join(":"), ranged = min !== void 0 || max !== void 0, target = disabled ? group("disabled", { disabled: !0 }) : state ? group(`state:${state}`, { state }) : ranged ? group(`range:${min ?? 0}:${max ?? ""}`, { min: min ?? 0, max }) : groups.get("base");
|
|
1335
|
+
if ((disabled || state) && (ranged || disabled && state)) {
|
|
1323
1336
|
groups.get("base").authored.set(token, authored);
|
|
1324
1337
|
groups.get("base").classes.push(token);
|
|
1325
1338
|
continue;
|
|
@@ -1359,6 +1372,8 @@ export function compileClassStyles(classes, variables, options = {}) {
|
|
|
1359
1372
|
const entry = { style: compiled.style, ...compiled.dark ? { dark: compiled.dark } : {} };
|
|
1360
1373
|
if (layer.disabled)
|
|
1361
1374
|
result.disabled = entry;
|
|
1375
|
+
else if (layer.state)
|
|
1376
|
+
(result.states ??= {})[layer.state] = entry;
|
|
1362
1377
|
else
|
|
1363
1378
|
responsive.push({ min: layer.min ?? 0, ...layer.max === void 0 ? {} : { max: layer.max }, ...entry });
|
|
1364
1379
|
}
|
|
@@ -1416,7 +1431,17 @@ function compileLayer(classes, variables, options = {}) {
|
|
|
1416
1431
|
originals.get(translated).add(original);
|
|
1417
1432
|
return translated;
|
|
1418
1433
|
}
|
|
1434
|
+
const dividers = [], dividerOriginals = new Map;
|
|
1419
1435
|
for (const name of classes.split(/\s+/).filter(Boolean)) {
|
|
1436
|
+
const darkDivide = name.startsWith("dark:") ? name.slice(5) : name, border = divideAsBorder(darkDivide);
|
|
1437
|
+
if (border !== null) {
|
|
1438
|
+
const translated = border && `${name === darkDivide ? "" : "dark:"}${border}`;
|
|
1439
|
+
if (translated) {
|
|
1440
|
+
dividers.push(translated);
|
|
1441
|
+
dividerOriginals.set(translated, name);
|
|
1442
|
+
}
|
|
1443
|
+
continue;
|
|
1444
|
+
}
|
|
1420
1445
|
const focused = /^(dark:)?(focus|focus-within):(dark:)?(.+)$/.exec(name), focusKey = focused?.[2] === "focus" ? "focus" : "focusWithin";
|
|
1421
1446
|
if (focused && options[focusKey] && !(focused[1] && focused[3])) {
|
|
1422
1447
|
const translated = `${focused[1] || focused[3] ? "dark:" : ""}${focused[4]}`, layer = focusLayers[focusKey];
|
|
@@ -1463,6 +1488,11 @@ function compileLayer(classes, variables, options = {}) {
|
|
|
1463
1488
|
}
|
|
1464
1489
|
const authoredUnknown = unknown.flatMap((name) => [...originals.get(name) ?? [name]]);
|
|
1465
1490
|
result.unknown = [...new Set([...authoredUnknown.filter((name) => !/^line-clamp-\d+$/.test(name)), ...unsupported])];
|
|
1491
|
+
if (dividers.length) {
|
|
1492
|
+
const divided = compileLayer(dividers.join(" "), variables);
|
|
1493
|
+
result.divide = { style: divided.style, ...divided.dark ? { dark: divided.dark } : {} };
|
|
1494
|
+
result.unknown = [...new Set([...result.unknown, ...divided.unknown.map((name) => dividerOriginals.get(name) ?? name)])];
|
|
1495
|
+
}
|
|
1466
1496
|
for (const key of ["focus", "focusWithin"]) {
|
|
1467
1497
|
const layer = focusLayers[key];
|
|
1468
1498
|
if (!layer.classes.length)
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import type { STXDocument, STXNode } from './ir';
|
|
2
|
+
/**
|
|
3
|
+
* The binding a `{{ }}`-templated string makes, or null when it has none.
|
|
4
|
+
*
|
|
5
|
+
* The server evaluates what it can of a web view's mustaches and leaves the
|
|
6
|
+
* rest (a client signal, a call the device answers) for the browser's
|
|
7
|
+
* runtime, which binds them in the page's text. A native screen has no text
|
|
8
|
+
* nodes for that runtime to find, so a leftover mustache is a binding here,
|
|
9
|
+
* the `:text` or `:placeholder` an author could have written: a single one is
|
|
10
|
+
* its expression, words around it are joined in, and null or undefined reads
|
|
11
|
+
* as nothing, as the browser shows it.
|
|
12
|
+
*/
|
|
13
|
+
export declare function mustacheBinding(text: string): string | null;
|
|
2
14
|
/**
|
|
3
15
|
* Translate stx's rendered HTML into the native view IR.
|
|
4
16
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ACCESSIBILITY_FIELDS, projectAccessibility } from "../accessibility.js";
|
|
2
|
+
import { applyStaticTextEntry } from "../text-entry.js";
|
|
2
3
|
import { NATIVE_EVENT_NAMES as EVENT_NAMES } from "../event-names.js";
|
|
3
4
|
import { NATIVE_BOOLEAN_PROPS, nativePropName } from "../prop-names.js";
|
|
4
5
|
import { mapToNativeComponent } from "./component-mapping.js";
|
|
@@ -109,9 +110,28 @@ function decodeEntities(text) {
|
|
|
109
110
|
return whole;
|
|
110
111
|
});
|
|
111
112
|
}
|
|
113
|
+
export function mustacheBinding(text) {
|
|
114
|
+
if (!text.includes("{{"))
|
|
115
|
+
return null;
|
|
116
|
+
const parts = [];
|
|
117
|
+
let last = 0;
|
|
118
|
+
for (const match of text.matchAll(/\{\{([\s\S]+?)\}\}/g)) {
|
|
119
|
+
if (match.index > last)
|
|
120
|
+
parts.push(JSON.stringify(text.slice(last, match.index)));
|
|
121
|
+
parts.push(`(${match[1].trim()})`);
|
|
122
|
+
last = match.index + match[0].length;
|
|
123
|
+
}
|
|
124
|
+
if (!parts.some((part) => part.startsWith("(")))
|
|
125
|
+
return null;
|
|
126
|
+
if (last < text.length)
|
|
127
|
+
parts.push(JSON.stringify(text.slice(last)));
|
|
128
|
+
if (parts.length === 1)
|
|
129
|
+
return parts[0].slice(1, -1);
|
|
130
|
+
return `[${parts.join(", ")}].map(__stxPart => __stxPart == null ? '' : __stxPart).join('')`;
|
|
131
|
+
}
|
|
112
132
|
function readAttributes(tag, attributes, diagnostics, styleContext = {}) {
|
|
113
133
|
let variables = styleContext.inheritedVariables;
|
|
114
|
-
const props = {}, events = {}, bindings = {};
|
|
134
|
+
const props = {}, events = {}, bindings = {}, fromMustaches = [];
|
|
115
135
|
let classes = "", inline = {};
|
|
116
136
|
for (const [rawName, value] of attributes) {
|
|
117
137
|
const name = rawName.toLowerCase();
|
|
@@ -146,7 +166,13 @@ function readAttributes(tag, attributes, diagnostics, styleContext = {}) {
|
|
|
146
166
|
props.key = value;
|
|
147
167
|
continue;
|
|
148
168
|
}
|
|
149
|
-
const decoded = decodeEntities(value),
|
|
169
|
+
const decoded = decodeEntities(value), templated = mustacheBinding(decoded);
|
|
170
|
+
if (templated) {
|
|
171
|
+
bindings[name] = templated;
|
|
172
|
+
fromMustaches.push(name);
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const prop = nativePropName(rawName);
|
|
150
176
|
if (decoded === "" && NATIVE_BOOLEAN_PROPS.has(prop)) {
|
|
151
177
|
props[prop] = !0;
|
|
152
178
|
continue;
|
|
@@ -161,7 +187,7 @@ function readAttributes(tag, attributes, diagnostics, styleContext = {}) {
|
|
|
161
187
|
for (const name of new Set(compiledClasses?.unknown ?? []))
|
|
162
188
|
diagnostics.push({ kind: "unknown-class", tag, name });
|
|
163
189
|
const style = applyNativeLayoutDefaults({ ...compiledClasses?.style, ...inline });
|
|
164
|
-
return { props, style, events, bindings, classes, inline };
|
|
190
|
+
return { props, style, events, bindings, classes, inline, templated: fromMustaches };
|
|
165
191
|
}
|
|
166
192
|
function inlineStyle(tag, css, diagnostics, context) {
|
|
167
193
|
return parseNativeStyle(decodeEntities(css), (diagnostic) => diagnostics.push({ ...diagnostic, tag }), context);
|
|
@@ -261,7 +287,7 @@ export async function translateHtmlToIR(html, options = {}) {
|
|
|
261
287
|
return openSvg(tag, attributes, parentFrame);
|
|
262
288
|
const dropped = DROP_SUBTREE.has(tag) && !BOX_ONLY.has(tag), inheritedDrop = stack[stack.length - 1]?.dropped ?? !1;
|
|
263
289
|
let variables = parentFrame?.variables ?? stylesheetVariables;
|
|
264
|
-
const { props, style, events, bindings, classes, inline } = dropped || inheritedDrop ? { props: {}, style: {}, events: {}, bindings: {}, classes: "", inline: {} } : readAttributes(tag, attributes, diagnostics, { inheritedVariables: variables, onVariables: (value) => {
|
|
290
|
+
const { props, style, events, bindings, classes, inline, templated } = dropped || inheritedDrop ? { props: {}, style: {}, events: {}, bindings: {}, classes: "", inline: {}, templated: [] } : readAttributes(tag, attributes, diagnostics, { inheritedVariables: variables, onVariables: (value) => {
|
|
265
291
|
variables = value;
|
|
266
292
|
}, rules: stylesheetRules });
|
|
267
293
|
if (tag === "html")
|
|
@@ -338,6 +364,8 @@ export async function translateHtmlToIR(html, options = {}) {
|
|
|
338
364
|
node._classes = classes;
|
|
339
365
|
if (Object.keys(bindings).length > 0)
|
|
340
366
|
node.bindings = bindings;
|
|
367
|
+
if (templated.length > 0)
|
|
368
|
+
node._templated = templated;
|
|
341
369
|
if (typeof props.key === "string") {
|
|
342
370
|
node.key = props.key;
|
|
343
371
|
delete props.key;
|
|
@@ -362,7 +390,7 @@ export async function translateHtmlToIR(html, options = {}) {
|
|
|
362
390
|
return { tag, node: createNode("G", {}, {}, {}), svg: !0, dropped: !0, discard: !0, unwrap: !1 };
|
|
363
391
|
}
|
|
364
392
|
let variables = parent?.variables ?? stylesheetVariables;
|
|
365
|
-
const { props, style, events, bindings, classes, inline } = readAttributes(tag, attributes, diagnostics, { inheritedVariables: variables, onVariables: (value) => {
|
|
393
|
+
const { props, style, events, bindings, classes, inline, templated } = readAttributes(tag, attributes, diagnostics, { inheritedVariables: variables, onVariables: (value) => {
|
|
366
394
|
variables = value;
|
|
367
395
|
}, rules: stylesheetRules });
|
|
368
396
|
if (type === "Svg") {
|
|
@@ -397,6 +425,8 @@ export async function translateHtmlToIR(html, options = {}) {
|
|
|
397
425
|
node._classes = classes;
|
|
398
426
|
if (Object.keys(bindings).length > 0)
|
|
399
427
|
node.bindings = bindings;
|
|
428
|
+
if (templated.length > 0)
|
|
429
|
+
node._templated = templated;
|
|
400
430
|
if (typeof props.key === "string") {
|
|
401
431
|
node.key = props.key;
|
|
402
432
|
delete props.key;
|
|
@@ -443,11 +473,13 @@ export async function translateHtmlToIR(html, options = {}) {
|
|
|
443
473
|
if (Object.keys(stylesheetRules).length)
|
|
444
474
|
root._stylesheetRules = stylesheetRules;
|
|
445
475
|
const project = (node) => {
|
|
476
|
+
bindMustaches(node);
|
|
446
477
|
const projected = projectAccessibility(node.props);
|
|
447
478
|
if (Object.keys(projected).length) {
|
|
448
479
|
node._accessibilitySource = Object.fromEntries(ACCESSIBILITY_FIELDS.filter((name) => (name in node.props)).map((name) => [name, node.props[name]]));
|
|
449
480
|
Object.assign(node.props, projected);
|
|
450
481
|
}
|
|
482
|
+
applyStaticTextEntry(node);
|
|
451
483
|
for (const child of node.children)
|
|
452
484
|
if (typeof child !== "string")
|
|
453
485
|
project(child);
|
|
@@ -455,6 +487,25 @@ export async function translateHtmlToIR(html, options = {}) {
|
|
|
455
487
|
project(root);
|
|
456
488
|
return { root, diagnostics };
|
|
457
489
|
}
|
|
490
|
+
function bindMustaches(node) {
|
|
491
|
+
if (node.bindings?.text || node.children.length === 0 || !node.children.every((child) => typeof child === "string"))
|
|
492
|
+
return;
|
|
493
|
+
const expression = mustacheBinding(node.children.join(""));
|
|
494
|
+
if (!expression)
|
|
495
|
+
return;
|
|
496
|
+
if (node.type === "Text") {
|
|
497
|
+
node.bindings = { ...node.bindings, text: expression };
|
|
498
|
+
node._templated = [...node._templated ?? [], "text"];
|
|
499
|
+
node.children = [];
|
|
500
|
+
} else if (node.type === "Button") {
|
|
501
|
+
node.type = "Pressable";
|
|
502
|
+
node.props.role ??= "button";
|
|
503
|
+
const label = createNode("Text", {}, {}, {}, []);
|
|
504
|
+
label.bindings = { text: expression };
|
|
505
|
+
label._templated = ["text"];
|
|
506
|
+
node.children = [label];
|
|
507
|
+
}
|
|
508
|
+
}
|
|
458
509
|
export async function translateHtmlToDocument(html, options = {}) {
|
|
459
510
|
const { root, diagnostics } = await translateHtmlToIR(html, options), script = options.script ?? { exports: {}, functions: [], code: "" };
|
|
460
511
|
return {
|
|
@@ -12,6 +12,7 @@ export declare interface STXNode {
|
|
|
12
12
|
key?: string
|
|
13
13
|
props: Record<string, unknown>
|
|
14
14
|
_accessibilitySource?: Record<string, unknown>
|
|
15
|
+
_textEntrySource?: Record<string, unknown>
|
|
15
16
|
style: STXStyle
|
|
16
17
|
events: Record<string, string>
|
|
17
18
|
bindings?: Record<string, string>
|
|
@@ -24,6 +25,7 @@ export declare interface STXNode {
|
|
|
24
25
|
_stylesheetTheme?: NativeStylesheetTheme
|
|
25
26
|
_stylesheetRules?: NativeStylesheetRules
|
|
26
27
|
_classes?: string
|
|
28
|
+
_templated?: string[]
|
|
27
29
|
_source?: {
|
|
28
30
|
file: string
|
|
29
31
|
line: number
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { loadStxConfig } from "../../config.js";
|
|
4
|
-
import { extractBindingManifest } from "../../binding-manifest.js";
|
|
4
|
+
import { classifyAttribute, extractBindingManifest } from "../../binding-manifest.js";
|
|
5
5
|
import { processDirectives } from "../../process.js";
|
|
6
6
|
import { processScriptSetup } from "../../signal-processing.js";
|
|
7
7
|
import { appThemeCSS } from "./app-theme.js";
|
|
@@ -20,12 +20,12 @@ export function nativePrimitivesDir() {
|
|
|
20
20
|
return candidates[0];
|
|
21
21
|
}
|
|
22
22
|
export async function compileScreenSource(source, filePath, options = {}) {
|
|
23
|
-
const root = options.root ?? path.dirname(filePath), loaded = await loadStxConfig(root), fromRoot = (dir, fallback) => dir ? path.isAbsolute(dir) ? dir : path.resolve(
|
|
23
|
+
const root = options.root ?? path.dirname(filePath), loaded = await loadStxConfig(root), sourceRoot = typeof loaded.root === "string" && loaded.root ? path.resolve(root, loaded.root) : root, fromRoot = (dir, fallback) => dir ? path.isAbsolute(dir) ? dir : path.resolve(sourceRoot, dir) : path.join(sourceRoot, fallback), config = {
|
|
24
24
|
root,
|
|
25
25
|
layoutsDir: fromRoot(loaded.layoutsDir, "layouts"),
|
|
26
26
|
partialsDir: fromRoot(loaded.partialsDir, "partials"),
|
|
27
27
|
storesDir: fromRoot(loaded.storesDir, "stores"),
|
|
28
|
-
componentsDir: options.componentsDir ?? loaded.componentsDir
|
|
28
|
+
componentsDir: options.componentsDir ?? (loaded.componentsDir ? fromRoot(loaded.componentsDir, "components") : path.join(sourceRoot, "components")),
|
|
29
29
|
buildMode: "serve",
|
|
30
30
|
cache: !1,
|
|
31
31
|
_targetComponentDirs: [nativePrimitivesDir()],
|
|
@@ -33,10 +33,12 @@ export async function compileScreenSource(source, filePath, options = {}) {
|
|
|
33
33
|
_nativeHostAttrs: !0,
|
|
34
34
|
skipEventDirectives: !0,
|
|
35
35
|
_pluginComponentDirs: loaded._pluginComponentDirs ?? []
|
|
36
|
-
}, context = { ...options.context ?? {}, __stx_inject_css: !1 }, dependencies = new Set([filePath]), renderedHtml = await processDirectives(source, context, filePath, config, dependencies), { html: content, chrome } = await extractLayoutChrome(renderedHtml), { html, manifest } = extractBindingManifest(content), theme = await appThemeCSS(root), { document, diagnostics } = await translateHtmlToDocument(theme ? `<style>${theme}</style>${html}` : html, {
|
|
36
|
+
}, context = { ...options.context ?? {}, __stx_inject_css: !1, __stx_native_screen: !0 }, dependencies = new Set([filePath]), renderedHtml = await processDirectives(source, context, filePath, config, dependencies), { html: content, chrome } = await extractLayoutChrome(renderedHtml), { html, manifest } = extractBindingManifest(content), theme = await appThemeCSS(root), { document, diagnostics } = await translateHtmlToDocument(theme ? `<style>${theme}</style>${html}` : html, {
|
|
37
37
|
source: filePath,
|
|
38
38
|
script: extractClientScript(source)
|
|
39
|
-
})
|
|
39
|
+
});
|
|
40
|
+
enterTemplatedBindings(document.root, manifest);
|
|
41
|
+
const head = context.__stx_runtime_head;
|
|
40
42
|
if (typeof head?.title === "string" && head.title.trim())
|
|
41
43
|
document.title = head.title.trim();
|
|
42
44
|
if (chrome)
|
|
@@ -66,6 +68,30 @@ export async function compileScreenSource(source, filePath, options = {}) {
|
|
|
66
68
|
scripts.unshift({ code: modules });
|
|
67
69
|
return { document, manifest, setup, scripts, diagnostics, html, dependencies: [...dependencies] };
|
|
68
70
|
}
|
|
71
|
+
function enterTemplatedBindings(root, manifest) {
|
|
72
|
+
const entries = new Map(manifest.entries.map((entry) => [entry.id, entry]));
|
|
73
|
+
let next = manifest.entries.reduce((highest, entry) => Math.max(highest, entry.id), -1) + 1;
|
|
74
|
+
const visit = (node) => {
|
|
75
|
+
if (node._templated?.length && node.bindings) {
|
|
76
|
+
if (node.bindingId === void 0 || !entries.has(node.bindingId)) {
|
|
77
|
+
const entry = { id: node.bindingId ?? next++, bindings: [] };
|
|
78
|
+
node.bindingId = entry.id;
|
|
79
|
+
entries.set(entry.id, entry);
|
|
80
|
+
manifest.entries.push(entry);
|
|
81
|
+
}
|
|
82
|
+
const entry = entries.get(node.bindingId);
|
|
83
|
+
for (const name of node._templated) {
|
|
84
|
+
const attribute = `:${name}`, kind = classifyAttribute(attribute);
|
|
85
|
+
if (kind && !entry.bindings.some((binding) => binding.name === attribute))
|
|
86
|
+
entry.bindings.push({ name: attribute, value: node.bindings[name], kind });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
for (const child of node.children)
|
|
90
|
+
if (typeof child !== "string")
|
|
91
|
+
visit(child);
|
|
92
|
+
};
|
|
93
|
+
visit(root);
|
|
94
|
+
}
|
|
69
95
|
export async function compileScreenFile(filePath, options = {}) {
|
|
70
96
|
return compileScreenSource(await Bun.file(filePath).text(), filePath, options);
|
|
71
97
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { authoredAccessibilityProps } from "../accessibility.js";
|
|
2
|
+
import { authoredTextEntryProps } from "../text-entry.js";
|
|
2
3
|
function decodeBindingValue(value) {
|
|
3
4
|
return value.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/�?39;/g, "'").replace(/'/gi, "'").replace(/&/g, "&");
|
|
4
5
|
}
|
|
@@ -107,7 +108,7 @@ export function materializeNativeBindingTree(document, manifest, host) {
|
|
|
107
108
|
const node = createBindingNode(id, source.type, runtimeBindings, !0, source._classes, (value) => host.setAttribute(node, "class", value));
|
|
108
109
|
if (source.type === "Checkbox" && source.props.type === "checkbox")
|
|
109
110
|
node.tagName = "INPUT";
|
|
110
|
-
for (const [name, value] of Object.entries(authoredAccessibilityProps(source.props, source._accessibilitySource))) {
|
|
111
|
+
for (const [name, value] of Object.entries(authoredTextEntryProps(authoredAccessibilityProps(source.props, source._accessibilitySource), source._textEntrySource))) {
|
|
111
112
|
if (value === void 0 || value === null || name === "__stxId")
|
|
112
113
|
continue;
|
|
113
114
|
node.setAttribute(name, typeof value === "object" ? JSON.stringify(value) : String(value));
|
|
@@ -2,7 +2,7 @@ import { STXBridge } from "../bridge/protocol.js";
|
|
|
2
2
|
import { createEventSourceClass, createStreamingBody } from "./event-stream.js";
|
|
3
3
|
import { abortError, isNativeDocument, NativeFormData, nativeFormParts, updateNativeDocumentVisibility } from "./jsc-globals.js";
|
|
4
4
|
import { buttonsKey, changedTabItems, chromePath, hostButton, mergeChromeButtons } from "./navigation-chrome.js";
|
|
5
|
-
import { installNativeNavigation } from "./web-navigation.js";
|
|
5
|
+
import { installNativeNavigation, nativeRouteParams } from "./web-navigation.js";
|
|
6
6
|
import { installNativeWebStorage } from "./web-storage.js";
|
|
7
7
|
function capabilityFlags(capabilities) {
|
|
8
8
|
return {
|
|
@@ -186,8 +186,6 @@ export function installCraftBridge(protocol, nativeBridge, target = globalThis,
|
|
|
186
186
|
return request("Storage", "compareAndSet", [key, expectedValue, nextValue]);
|
|
187
187
|
}
|
|
188
188
|
});
|
|
189
|
-
if (isNativeDocument(target.document))
|
|
190
|
-
installNativeWebStorage(target, craft);
|
|
191
189
|
craft.secureStorage = Object.assign({ getSync: () => null }, craft.secureStorage || {}, {
|
|
192
190
|
get: (key) => request("SecureStorage", "get", [key]),
|
|
193
191
|
set: (key, value) => request("SecureStorage", "set", [key, value]),
|
|
@@ -212,6 +210,15 @@ export function installCraftBridge(protocol, nativeBridge, target = globalThis,
|
|
|
212
210
|
callback(token, previous);
|
|
213
211
|
})
|
|
214
212
|
});
|
|
213
|
+
if (isNativeDocument(target.document)) {
|
|
214
|
+
const shareStorage = { ...options.shareStorage, ...nativeBridge.shareStorage }, shared = installNativeWebStorage(target, craft, {
|
|
215
|
+
shareStorage,
|
|
216
|
+
...capabilities.has("secureStorage") ? { secure: () => craft.secureStorage } : {},
|
|
217
|
+
adopted: (key, value) => target.dispatchEvent?.(new target.CustomEvent("craftsharedstorage", { detail: { key, value } }))
|
|
218
|
+
});
|
|
219
|
+
if (shared)
|
|
220
|
+
craft.session.onChange(() => shared.changed(sessionKey));
|
|
221
|
+
}
|
|
215
222
|
craft.snapshots = Object.assign({ get: () => null, set: () => Promise.resolve(!1) }, craft.snapshots || {}, {
|
|
216
223
|
onChange: (callback) => protocol.on("SNAPSHOT_CHANGED", (message) => {
|
|
217
224
|
if (typeof message.payload?.name === "string")
|
|
@@ -709,6 +716,9 @@ export function installCraftBridge(protocol, nativeBridge, target = globalThis,
|
|
|
709
716
|
}
|
|
710
717
|
if (isNativeDocument(target.document)) {
|
|
711
718
|
installNativeNavigation(target, craft, { routeURL: nativeBridge.routeURL, appURL: craft.app?.url });
|
|
719
|
+
const pathParams = options.source ? nativeRouteParams(options.source, String(target.location?.pathname ?? "/")) : {};
|
|
720
|
+
target.__stx_rp = { ...pathParams, ...craft.route.params };
|
|
721
|
+
craft.route.onParams((params) => target.stx?.setRouteParams?.({ ...pathParams, ...params }));
|
|
712
722
|
let title = typeof options.title === "string" ? options.title : "";
|
|
713
723
|
Object.defineProperty(target.document, "title", {
|
|
714
724
|
configurable: !0,
|
|
@@ -23,6 +23,7 @@ export declare interface NativeHostOptions {
|
|
|
23
23
|
send: (operations: NativeMutationOperation[]) => void
|
|
24
24
|
schedule?: (flush: () => void) => void
|
|
25
25
|
followLink?: (href: string) => void
|
|
26
|
+
linkState?: (href: string, match: string | null) => { active: boolean, exact: boolean } | null
|
|
26
27
|
}
|
|
27
28
|
export declare interface NativeHost {
|
|
28
29
|
readonly isNative: true
|