@stacksjs/stx 0.2.648 → 0.2.654
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-17srvghf.js +2 -0
- package/dist/{chunk-nt0n0vjm.js → chunk-1zb7ar32.js} +2 -2
- package/dist/{chunk-e87xa4r3.js → chunk-26whq1rg.js} +2 -2
- package/dist/{chunk-k79x96ra.js → chunk-28jtt8hn.js} +42 -42
- package/dist/{chunk-zsgcsqat.js → chunk-2yg9y1na.js} +99 -99
- package/dist/{chunk-481d4kr9.js → chunk-2zqg980j.js} +1 -1
- package/dist/{chunk-x5tjb4y4.js → chunk-35zjpdcb.js} +1 -1
- package/dist/chunk-3634ds4n.js +2 -0
- package/dist/{chunk-nj1t4g3a.js → chunk-36649w15.js} +6 -6
- package/dist/chunk-3msbc4zj.js +2 -0
- package/dist/chunk-3q3gsr7m.js +2 -0
- package/dist/{chunk-3q163st5.js → chunk-3v8yejzc.js} +3 -3
- package/dist/chunk-42v0vegr.js +2 -0
- package/dist/{chunk-2jh21f1n.js → chunk-46w53nj5.js} +1 -1
- package/dist/{chunk-0jhdrgpr.js → chunk-48acjmeg.js} +2 -2
- package/dist/{chunk-55zaxb4s.js → chunk-4e0z858k.js} +10 -10
- package/dist/{chunk-yq021b3r.js → chunk-4nbq7mnp.js} +4 -4
- package/dist/{chunk-7rta163c.js → chunk-4qwvqbzf.js} +2 -2
- package/dist/{chunk-hjm69qnj.js → chunk-50pkybyn.js} +1 -1
- package/dist/{chunk-88z4wkrj.js → chunk-5yxd4ryz.js} +2 -2
- package/dist/{chunk-vqc4h16r.js → chunk-6598d3m6.js} +2 -2
- package/dist/{chunk-ab7zqtax.js → chunk-6raq8r7w.js} +1 -1
- package/dist/{chunk-zmh9p9aa.js → chunk-6rparhvs.js} +1 -1
- package/dist/{chunk-t1k9160w.js → chunk-71mthavp.js} +32 -32
- package/dist/chunk-73swyb5p.js +2 -0
- package/dist/{chunk-b0hpshvk.js → chunk-7wnd2psp.js} +1 -1
- package/dist/{chunk-ymymwzt5.js → chunk-8gewq710.js} +1 -1
- package/dist/{chunk-3zyjqvsq.js → chunk-929zbzh7.js} +9 -9
- package/dist/{chunk-v2x9vzgw.js → chunk-9y2ncrnq.js} +2 -2
- package/dist/{chunk-c9k40352.js → chunk-a2a74f6c.js} +1 -1
- package/dist/{chunk-67xhsacd.js → chunk-bgt1dx8c.js} +1 -1
- package/dist/chunk-c9b0cme2.js +2 -0
- package/dist/{chunk-89yj6tcd.js → chunk-cq40n7ak.js} +1 -1
- package/dist/{chunk-f46ht5kq.js → chunk-cvw7gknw.js} +3 -3
- package/dist/chunk-d0xcykw6.js +2 -0
- package/dist/{chunk-vdxjy7j2.js → chunk-d3bsfd10.js} +2 -2
- package/dist/{chunk-rjh2jwxx.js → chunk-d4tf0tfn.js} +4 -4
- package/dist/chunk-dxjc11hx.js +2 -0
- package/dist/{chunk-zhf01af3.js → chunk-dxk5sqtv.js} +2 -2
- package/dist/chunk-edz1h5f9.js +2 -0
- package/dist/{chunk-fg3jw17w.js → chunk-en8jgavy.js} +6 -5
- package/dist/chunk-etw04j02.js +2 -0
- package/dist/chunk-ewng6v6g.js +49 -0
- package/dist/{chunk-9121nkpj.js → chunk-ex1kd5gs.js} +3 -3
- package/dist/chunk-fbd9w4ys.js +2 -0
- package/dist/{chunk-qfe7ps3v.js → chunk-ff1cb7k4.js} +2 -2
- package/dist/chunk-fnj3gja0.js +2 -0
- package/dist/chunk-fsnby15p.js +2 -0
- package/dist/{chunk-pbtkbe48.js → chunk-g7j3mwzd.js} +18 -18
- package/dist/{chunk-3p7mk3mw.js → chunk-gmrc24cb.js} +1 -1
- package/dist/{chunk-p44kmbdg.js → chunk-h09a03ay.js} +4 -4
- package/dist/chunk-h0bg2h0j.js +2 -0
- package/dist/{chunk-wjt0kej9.js → chunk-h4vg78mw.js} +1 -1
- package/dist/{chunk-4q2dtxdk.js → chunk-hjmnsa6a.js} +1 -1
- package/dist/{chunk-er60h3j3.js → chunk-ht3dxx5m.js} +1 -1
- package/dist/{chunk-h5nmf98w.js → chunk-hw7sv4ac.js} +1 -1
- package/dist/{chunk-pg0xzsss.js → chunk-j2bkjtp3.js} +4 -4
- package/dist/chunk-j3472s37.js +3 -0
- package/dist/chunk-jmx4q1yr.js +2 -0
- package/dist/{chunk-j393gsfd.js → chunk-k49fg322.js} +2 -2
- package/dist/{chunk-0vkawews.js → chunk-k7nan28e.js} +5 -5
- package/dist/{chunk-06w0z1cm.js → chunk-kcrtqyek.js} +4 -4
- package/dist/{chunk-t2pzy3x1.js → chunk-khvc43pq.js} +2 -2
- package/dist/{chunk-qm4672dj.js → chunk-ktvr9ta8.js} +2 -2
- package/dist/{chunk-wq6j2h32.js → chunk-m47spkxr.js} +7 -7
- package/dist/chunk-m947aq9a.js +2 -0
- package/dist/{chunk-jkaszw24.js → chunk-mgj34bbg.js} +1 -1
- package/dist/{chunk-r1r6311d.js → chunk-n7xbhzzt.js} +4 -4
- package/dist/chunk-ndtxkps4.js +2 -0
- package/dist/{chunk-np4zm2ph.js → chunk-nttspz8c.js} +4 -4
- package/dist/chunk-pge3bzqx.js +2 -0
- package/dist/{chunk-9txn4rvb.js → chunk-phws2c9s.js} +1 -1
- package/dist/{chunk-j5gd0e53.js → chunk-q1x7ckfw.js} +1 -1
- package/dist/chunk-q79ksfcd.js +2 -0
- package/dist/chunk-qjf1c8fa.js +2 -0
- package/dist/{chunk-gv793yqq.js → chunk-qrt8b179.js} +2 -2
- package/dist/{chunk-w2zceynt.js → chunk-qygynhzc.js} +1 -1
- package/dist/{chunk-6ea6az61.js → chunk-ra56jh7e.js} +1 -1
- package/dist/chunk-rmdw6s65.js +2 -0
- package/dist/chunk-s0crnpyx.js +2 -0
- package/dist/{chunk-8p9kpfk8.js → chunk-s4cs2n2c.js} +1 -1
- package/dist/{chunk-t82be9yf.js → chunk-sd4jwn3y.js} +1 -1
- package/dist/chunk-t7j4h3nf.js +128 -0
- package/dist/{chunk-sgptbhrc.js → chunk-v9bmw06j.js} +1 -1
- package/dist/{chunk-gz90fqn8.js → chunk-vmn2b6p6.js} +1 -1
- package/dist/{chunk-aprhqxky.js → chunk-vngnface.js} +3 -3
- package/dist/{chunk-0h8tg21j.js → chunk-vs8kg85h.js} +1 -1
- package/dist/{chunk-84djpte6.js → chunk-wbzmr6a4.js} +2 -2
- package/dist/{chunk-ye8tgmd3.js → chunk-wh838rdh.js} +1 -1
- package/dist/{chunk-xm2mee4a.js → chunk-x9d4bpmh.js} +21 -21
- package/dist/{chunk-mnp8ecj9.js → chunk-xdgvb5a5.js} +1 -1
- package/dist/{chunk-pxs7sgnp.js → chunk-xhmpfq9d.js} +1 -1
- package/dist/{chunk-hfpv56cp.js → chunk-xq410rsc.js} +1 -1
- package/dist/{chunk-xvs04cnp.js → chunk-y8881za3.js} +1 -1
- package/dist/chunk-z75bp57x.js +2 -0
- package/dist/{chunk-8d2f2e42.js → chunk-znnfjxph.js} +1 -1
- package/dist/chunk-zrqremja.js +2 -0
- package/dist/cli.js +11 -11
- package/dist/client/signals-head-runtime.js +2 -1
- package/dist/craft-entry.js +1 -1
- package/dist/craft.js +1 -1
- package/dist/expressions.js +9 -0
- package/dist/interpolation-context.d.ts +2 -0
- package/dist/interpolation-context.js +8 -0
- package/dist/native/bridge/protocol.d.ts +2 -0
- package/dist/native/compiler/bundle.d.ts +6 -0
- package/dist/native/compiler/bundle.js +16 -9
- package/dist/native/compiler/headwind-to-style.d.ts +5 -1
- package/dist/native/compiler/headwind-to-style.js +188 -3
- package/dist/native/compiler/html-to-ir.d.ts +2 -1
- package/dist/native/compiler/html-to-ir.js +9 -4
- package/dist/native/compiler/ir.d.ts +15 -0
- package/dist/native/compiler/layout-chrome.d.ts +6 -0
- package/dist/native/compiler/layout-chrome.js +72 -0
- package/dist/native/compiler/render-screen.js +19 -3
- package/dist/native/compiler/style-config.d.ts +32 -0
- package/dist/native/compiler/style-config.js +71 -0
- package/dist/native/compiler/stylesheet-rules.d.ts +17 -0
- package/dist/native/compiler/stylesheet-rules.js +107 -0
- package/dist/native/runtime/browser-screen.js +11 -0
- package/dist/native/runtime/craft-bridge.d.ts +3 -0
- package/dist/native/runtime/craft-bridge.js +41 -4
- package/dist/native/runtime/jsc-globals.d.ts +2 -0
- package/dist/native/runtime/jsc-globals.js +8 -1
- package/dist/native/runtime/native-host.d.ts +5 -0
- package/dist/native/runtime/native-host.js +48 -5
- package/dist/native/runtime/shared-screen.js +18 -2
- package/dist/native/runtime/web-navigation.d.ts +33 -0
- package/dist/native/runtime/web-navigation.js +107 -0
- package/dist/native/runtime/web-storage.d.ts +56 -0
- package/dist/native/runtime/web-storage.js +89 -0
- package/dist/native/testing.d.ts +3 -0
- package/dist/native/testing.js +3 -0
- package/dist/native-signing.d.ts +2 -0
- package/dist/native-signing.js +13 -4
- package/dist/process.js +2 -0
- package/dist/pwa.js +3 -3
- package/dist/reactive-bindings.js +3 -1
- package/dist/ssg.js +12 -12
- package/dist/utils.js +1 -1
- package/package.json +5 -5
- package/dist/chunk-0en5jwjy.js +0 -2
- package/dist/chunk-2n3pa5gm.js +0 -2
- package/dist/chunk-354jmw2k.js +0 -3
- package/dist/chunk-3b5bphcn.js +0 -2
- package/dist/chunk-57md41g9.js +0 -2
- package/dist/chunk-6vh8s0pg.js +0 -2
- package/dist/chunk-8fsq2ynj.js +0 -2
- package/dist/chunk-8tpmz4as.js +0 -2
- package/dist/chunk-9x0zt65f.js +0 -2
- package/dist/chunk-a2bw46t9.js +0 -2
- package/dist/chunk-a4sggwcz.js +0 -2
- package/dist/chunk-b4fd2dtk.js +0 -2
- package/dist/chunk-c1479y92.js +0 -2
- package/dist/chunk-embejqx4.js +0 -2
- package/dist/chunk-eyfxw7ds.js +0 -2
- package/dist/chunk-f3y4fnaa.js +0 -2
- package/dist/chunk-f7930sce.js +0 -2
- package/dist/chunk-fsbjat59.js +0 -2
- package/dist/chunk-h15xb2vd.js +0 -2
- package/dist/chunk-m6qfqkbh.js +0 -2
- package/dist/chunk-ncqh5qe5.js +0 -2
- package/dist/chunk-radggg3p.js +0 -49
- package/dist/chunk-sszhz1zh.js +0 -2
- package/dist/chunk-weqc0ssb.js +0 -2
- package/dist/chunk-xfzcv0jc.js +0 -2
- package/dist/chunk-y9x4pyp2.js +0 -2
- package/dist/chunk-zdnc7a4t.js +0 -127
- package/dist/chunk-zyqs6a3p.js +0 -2
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { DENSITY_FONT_SIZES, DENSITY_SPACING, SEMANTIC_TOKENS, SHAPE_TOKENS, tokenVariable } from "../../theme-tokens.js";
|
|
2
2
|
import { nativeDensitySpacing, nativeDensityType, nativeShapeRadius } from "./design-tokens.js";
|
|
3
|
+
import { nativeBreakpoint, nativeShortcut, nativeThemeColor } from "./style-config.js";
|
|
4
|
+
import { parseNativeStyle } from "./inline-style.js";
|
|
3
5
|
const colors = {
|
|
4
6
|
transparent: "transparent",
|
|
5
7
|
current: "currentColor",
|
|
@@ -354,7 +356,7 @@ const colors = {
|
|
|
354
356
|
};
|
|
355
357
|
function resolveColor(colorClass) {
|
|
356
358
|
const slash = colorClass.lastIndexOf("/");
|
|
357
|
-
if (slash > 0 && !colorClass.endsWith("]")) {
|
|
359
|
+
if (slash > 0 && (!colorClass.endsWith("]") || /\/\[[\d.]+%?\]$/.test(colorClass))) {
|
|
358
360
|
const base = resolveColor(colorClass.slice(0, slash)), amount = colorClass.slice(slash + 1), alpha = /^\[(.+)\]$/.test(amount) ? Number.parseFloat(amount.slice(1, -1)) * (amount.includes("%") ? 1 : 100) : Number.parseFloat(amount);
|
|
359
361
|
if (!base || !Number.isFinite(alpha))
|
|
360
362
|
return;
|
|
@@ -598,6 +600,42 @@ const classParsers = {
|
|
|
598
600
|
style.left = 0;
|
|
599
601
|
return !0;
|
|
600
602
|
},
|
|
603
|
+
"mx-auto": (_, style) => {
|
|
604
|
+
style.alignSelf = "center";
|
|
605
|
+
return !0;
|
|
606
|
+
},
|
|
607
|
+
fixed: (_, style) => {
|
|
608
|
+
style.position = "absolute";
|
|
609
|
+
return !0;
|
|
610
|
+
},
|
|
611
|
+
sticky: () => !0,
|
|
612
|
+
"sr-only": (_, style) => {
|
|
613
|
+
style.position = "absolute";
|
|
614
|
+
style.width = 1;
|
|
615
|
+
style.height = 1;
|
|
616
|
+
style.overflow = "hidden";
|
|
617
|
+
return !0;
|
|
618
|
+
},
|
|
619
|
+
inline: () => !0,
|
|
620
|
+
"inline-block": () => !0,
|
|
621
|
+
contents: () => !0,
|
|
622
|
+
"align-top": () => !0,
|
|
623
|
+
"align-middle": () => !0,
|
|
624
|
+
"align-bottom": () => !0,
|
|
625
|
+
"align-baseline": () => !0,
|
|
626
|
+
"align-text-top": () => !0,
|
|
627
|
+
"whitespace-normal": () => !0,
|
|
628
|
+
"whitespace-pre": () => !0,
|
|
629
|
+
"whitespace-pre-line": () => !0,
|
|
630
|
+
"whitespace-pre-wrap": () => !0,
|
|
631
|
+
"whitespace-nowrap": () => !0,
|
|
632
|
+
"break-words": () => !0,
|
|
633
|
+
"break-all": () => !0,
|
|
634
|
+
"break-normal": () => !0,
|
|
635
|
+
"object-cover": () => !0,
|
|
636
|
+
"object-contain": () => !0,
|
|
637
|
+
"object-fill": () => !0,
|
|
638
|
+
"object-center": () => !0,
|
|
601
639
|
"tracking-tighter": (_, style) => {
|
|
602
640
|
style.letterSpacing = -0.8;
|
|
603
641
|
return !0;
|
|
@@ -1085,7 +1123,24 @@ function parseTypography(className, style) {
|
|
|
1085
1123
|
}
|
|
1086
1124
|
return !1;
|
|
1087
1125
|
}
|
|
1126
|
+
function parseOffset(className, style) {
|
|
1127
|
+
const match = /^(-?)(inset-x|inset-y|inset|top|right|bottom|left)-(.+)$/.exec(className);
|
|
1128
|
+
if (!match)
|
|
1129
|
+
return !1;
|
|
1130
|
+
const raw = match[3], bracket = /^\[(-?[\d.]+)px\]$/.exec(raw), amount = bracket ? Number(bracket[1]) : spacing[raw];
|
|
1131
|
+
if (amount === void 0 || !Number.isFinite(amount))
|
|
1132
|
+
return !1;
|
|
1133
|
+
const value = match[1] ? -amount : amount, sides = match[2] === "inset" ? ["top", "right", "bottom", "left"] : match[2] === "inset-x" ? ["left", "right"] : match[2] === "inset-y" ? ["top", "bottom"] : [match[2]];
|
|
1134
|
+
for (const side of sides)
|
|
1135
|
+
style[side] = value;
|
|
1136
|
+
return !0;
|
|
1137
|
+
}
|
|
1088
1138
|
function parseGridColumns(className, style) {
|
|
1139
|
+
const tracks = /^grid-cols-\[(.+)\]$/.exec(className);
|
|
1140
|
+
if (tracks) {
|
|
1141
|
+
style.gridColumns = tracks[1].split("_").filter(Boolean).length;
|
|
1142
|
+
return !0;
|
|
1143
|
+
}
|
|
1089
1144
|
const match = /^grid-cols-(\d+)$/.exec(className);
|
|
1090
1145
|
if (!match)
|
|
1091
1146
|
return !1;
|
|
@@ -1199,12 +1254,130 @@ function parseShadow(className, style) {
|
|
|
1199
1254
|
Object.assign(style, { shadowColor: "#000000", shadowOpacity: opacity, shadowRadius: radius, shadowOffset: { width: 0, height: offset }, elevation });
|
|
1200
1255
|
return !0;
|
|
1201
1256
|
}
|
|
1257
|
+
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
|
+
function splitVariants(token) {
|
|
1259
|
+
const parts = [];
|
|
1260
|
+
let depth = 0, start = 0;
|
|
1261
|
+
for (let index = 0;index < token.length; index++) {
|
|
1262
|
+
const char = token[index];
|
|
1263
|
+
if (char === "[")
|
|
1264
|
+
depth++;
|
|
1265
|
+
else if (char === "]")
|
|
1266
|
+
depth = Math.max(0, depth - 1);
|
|
1267
|
+
else if (char === ":" && depth === 0) {
|
|
1268
|
+
parts.push(token.slice(start, index));
|
|
1269
|
+
start = index + 1;
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
parts.push(token.slice(start));
|
|
1273
|
+
return parts;
|
|
1274
|
+
}
|
|
1275
|
+
function expandShortcuts(token, seen = new Set) {
|
|
1276
|
+
const parts = splitVariants(token), utility = parts[parts.length - 1], shortcut = seen.has(utility) ? void 0 : nativeShortcut(utility);
|
|
1277
|
+
if (shortcut === void 0)
|
|
1278
|
+
return [token];
|
|
1279
|
+
const prefix = parts.slice(0, -1).map((part) => `${part}:`).join(""), inner = new Set(seen).add(utility);
|
|
1280
|
+
return shortcut.split(/\s+/).filter(Boolean).flatMap((name) => expandShortcuts(`${prefix}${name}`, inner));
|
|
1281
|
+
}
|
|
1202
1282
|
export function compileClassStyles(classes, variables, options = {}) {
|
|
1283
|
+
const groups = new Map, group = (key, init) => {
|
|
1284
|
+
if (!groups.has(key))
|
|
1285
|
+
groups.set(key, { ...init, classes: [], authored: new Map });
|
|
1286
|
+
return groups.get(key);
|
|
1287
|
+
};
|
|
1288
|
+
group("base", {});
|
|
1289
|
+
const ruleNames = [];
|
|
1290
|
+
for (const authored of classes.split(/\s+/).filter(Boolean)) {
|
|
1291
|
+
if (options.rules && Object.hasOwn(options.rules, authored)) {
|
|
1292
|
+
ruleNames.push(authored);
|
|
1293
|
+
continue;
|
|
1294
|
+
}
|
|
1295
|
+
for (const token of expandShortcuts(authored)) {
|
|
1296
|
+
const parts = splitVariants(token), utility = parts.pop(), focusing = parts.some((variant) => variant.startsWith("focus"));
|
|
1297
|
+
if (parts.some((variant) => /^(?:group-|peer-)?focus(?:-visible|-within)?$/.test(variant)) && /^(?:ring|outline)(?:-|$)/.test(utility))
|
|
1298
|
+
continue;
|
|
1299
|
+
if (WEB_ONLY_UTILITY.test(utility) || !focusing && parts.some((variant) => POINTER_ONLY_VARIANTS.has(variant)))
|
|
1300
|
+
continue;
|
|
1301
|
+
let min, disabled = !1;
|
|
1302
|
+
const kept = [];
|
|
1303
|
+
for (const variant of parts) {
|
|
1304
|
+
const width = nativeBreakpoint(variant);
|
|
1305
|
+
if (width !== void 0 && min === void 0)
|
|
1306
|
+
min = width;
|
|
1307
|
+
else if (variant === "disabled" && !disabled)
|
|
1308
|
+
disabled = !0;
|
|
1309
|
+
else
|
|
1310
|
+
kept.push(variant);
|
|
1311
|
+
}
|
|
1312
|
+
const stripped = [...kept, utility].join(":"), target = disabled ? group("disabled", { disabled: !0 }) : min !== void 0 ? group(`min:${min}`, { min }) : groups.get("base");
|
|
1313
|
+
if (disabled && min !== void 0) {
|
|
1314
|
+
groups.get("base").authored.set(token, authored);
|
|
1315
|
+
groups.get("base").classes.push(token);
|
|
1316
|
+
continue;
|
|
1317
|
+
}
|
|
1318
|
+
target.classes.push(stripped);
|
|
1319
|
+
if (!target.authored.has(stripped))
|
|
1320
|
+
target.authored.set(stripped, authored === token ? token : `${authored} (${token})`);
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
const authoredNames = (layer, names) => names.map((name) => layer.authored.get(name) ?? name), base = groups.get("base"), result = compileLayer(base.classes.join(" "), variables, options), ruleResponsive = new Map;
|
|
1324
|
+
if (ruleNames.length) {
|
|
1325
|
+
const parse = (css) => css ? parseNativeStyle(css, () => {}, { inheritedVariables: variables }) : {};
|
|
1326
|
+
let light = {}, dark = {};
|
|
1327
|
+
for (const name of ruleNames) {
|
|
1328
|
+
const rule = options.rules[name];
|
|
1329
|
+
light = { ...light, ...parse(rule.light) };
|
|
1330
|
+
dark = { ...dark, ...parse(rule.dark) };
|
|
1331
|
+
for (const layer of rule.responsive ?? []) {
|
|
1332
|
+
const entry = ruleResponsive.get(layer.min) ?? { style: {} };
|
|
1333
|
+
entry.style = { ...entry.style, ...parse(layer.light) };
|
|
1334
|
+
if (layer.dark)
|
|
1335
|
+
entry.dark = { ...entry.dark, ...parse(layer.dark) };
|
|
1336
|
+
ruleResponsive.set(layer.min, entry);
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
result.style = { ...light, ...result.style };
|
|
1340
|
+
if (Object.keys(dark).length)
|
|
1341
|
+
result.dark = { ...dark, ...result.dark };
|
|
1342
|
+
}
|
|
1343
|
+
result.unknown = authoredNames(base, result.unknown);
|
|
1344
|
+
const responsive = [];
|
|
1345
|
+
for (const layer of groups.values()) {
|
|
1346
|
+
if (layer === base)
|
|
1347
|
+
continue;
|
|
1348
|
+
const compiled = compileLayer(layer.classes.join(" "), variables);
|
|
1349
|
+
result.unknown = [...new Set([...result.unknown, ...authoredNames(layer, compiled.unknown)])];
|
|
1350
|
+
const entry = { style: compiled.style, ...compiled.dark ? { dark: compiled.dark } : {} };
|
|
1351
|
+
if (layer.disabled)
|
|
1352
|
+
result.disabled = entry;
|
|
1353
|
+
else
|
|
1354
|
+
responsive.push({ min: layer.min, ...entry });
|
|
1355
|
+
}
|
|
1356
|
+
for (const [min, layer] of ruleResponsive) {
|
|
1357
|
+
const existing = responsive.find((entry) => entry.min === min);
|
|
1358
|
+
if (existing) {
|
|
1359
|
+
existing.style = { ...layer.style, ...existing.style };
|
|
1360
|
+
if (layer.dark || existing.dark)
|
|
1361
|
+
existing.dark = { ...layer.dark, ...existing.dark };
|
|
1362
|
+
} else
|
|
1363
|
+
responsive.push({ min, ...layer });
|
|
1364
|
+
}
|
|
1365
|
+
if (responsive.length)
|
|
1366
|
+
result.responsive = responsive.sort((a, b) => a.min - b.min);
|
|
1367
|
+
return result;
|
|
1368
|
+
}
|
|
1369
|
+
function compileLayer(classes, variables, options = {}) {
|
|
1203
1370
|
const plain = [], dark = [], semanticDark = [], unsupported = [], focusLayers = {
|
|
1204
1371
|
focus: { classes: [], originals: new Map },
|
|
1205
1372
|
focusWithin: { classes: [], originals: new Map }
|
|
1206
1373
|
}, originals = new Map;
|
|
1207
1374
|
function roleClasses(name, scheme) {
|
|
1375
|
+
const themed = /^(bg|text|border(?:-[trblxy])?|from|via|to|fill|stroke|divide|decoration|caret|accent)-(.+?)(\/[^\s]+)?$/.exec(name), themeValue = themed && nativeThemeColor(themed[2]);
|
|
1376
|
+
if (themed && themeValue) {
|
|
1377
|
+
const variable = /^var\(\s*(--[\w-]+)\s*(?:,\s*(.+?)\s*)?\)$/.exec(themeValue), value = variable ? variables?.get(variable[1]) ?? variable[2] : themeValue;
|
|
1378
|
+
if (value && /^(?:#[0-9a-f]{3,8}|rgba?\(.+\)|hsla?\(.+\))$/i.test(value))
|
|
1379
|
+
return [`${themed[1]}-[${value.replace(/\s+/g, "")}]${themed[3] || ""}`];
|
|
1380
|
+
}
|
|
1208
1381
|
const match = /^(text|bg|border|ring)-([a-z-]+)(\/[^\s]+)?$/.exec(name), role = match && SEMANTIC_TOKENS[match[2]];
|
|
1209
1382
|
if (role) {
|
|
1210
1383
|
const override = variables?.get(tokenVariable(match[2]));
|
|
@@ -1268,8 +1441,11 @@ export function compileClassStyles(classes, variables, options = {}) {
|
|
|
1268
1441
|
result.dark.transform = [...style.transform.filter((step) => !Object.keys(step).some((key) => overridden.has(key))), ...result.dark.transform];
|
|
1269
1442
|
}
|
|
1270
1443
|
for (const name of plain) {
|
|
1271
|
-
if (name === "truncate")
|
|
1444
|
+
if (name === "truncate" || name === "whitespace-nowrap")
|
|
1272
1445
|
result.numberOfLines = 1;
|
|
1446
|
+
const fit = /^object-(cover|contain|fill)$/.exec(name);
|
|
1447
|
+
if (fit)
|
|
1448
|
+
result.resizeMode = fit[1] === "fill" ? "stretch" : fit[1];
|
|
1273
1449
|
const clamp = /^line-clamp-(\d+)$/.exec(name);
|
|
1274
1450
|
if (clamp)
|
|
1275
1451
|
result.numberOfLines = Number(clamp[1]);
|
|
@@ -1282,7 +1458,7 @@ export function compileClassStyles(classes, variables, options = {}) {
|
|
|
1282
1458
|
const layer = focusLayers[key];
|
|
1283
1459
|
if (!layer.classes.length)
|
|
1284
1460
|
continue;
|
|
1285
|
-
const focused =
|
|
1461
|
+
const focused = compileLayer(layer.classes.join(" "), variables);
|
|
1286
1462
|
result[key] = { style: focused.style, dark: focused.dark };
|
|
1287
1463
|
result.unknown = [...new Set([...result.unknown, ...focused.unknown.flatMap((name) => layer.originals.get(name) ?? [name])])];
|
|
1288
1464
|
for (const name of layer.classes)
|
|
@@ -1337,6 +1513,15 @@ export function compileHeadwindToStyle(classes, unknown) {
|
|
|
1337
1513
|
continue;
|
|
1338
1514
|
if (parseGridColumns(className, style))
|
|
1339
1515
|
continue;
|
|
1516
|
+
const layer = /^z-\[(-?\d+)\]$/.exec(className) ?? /^z-(\d+)$/.exec(className);
|
|
1517
|
+
if (layer) {
|
|
1518
|
+
style.zIndex = Number(layer[1]);
|
|
1519
|
+
continue;
|
|
1520
|
+
}
|
|
1521
|
+
if (className === "z-auto")
|
|
1522
|
+
continue;
|
|
1523
|
+
if (parseOffset(className, style))
|
|
1524
|
+
continue;
|
|
1340
1525
|
const order = /^order-\[(-?\d+)\]$/.exec(className) ?? /^order-(-?\d+)$/.exec(className);
|
|
1341
1526
|
if (order) {
|
|
1342
1527
|
style.order = Number(order[1]);
|
|
@@ -46,4 +46,5 @@ export type TranslationDiagnosticKind = | 'unmapped-tag'
|
|
|
46
46
|
/** A control with no supported native interaction contract. */
|
|
47
47
|
| 'unsupported-control'
|
|
48
48
|
/** A theme declaration cannot be evaluated faithfully on the native target. */
|
|
49
|
-
| 'unsupported-theme-rule'
|
|
49
|
+
| 'unsupported-theme-rule'
|
|
50
|
+
| 'unsupported-style-rule';
|
|
@@ -3,6 +3,7 @@ import { NATIVE_EVENT_NAMES as EVENT_NAMES } from "../event-names.js";
|
|
|
3
3
|
import { NATIVE_BOOLEAN_PROPS, nativePropName } from "../prop-names.js";
|
|
4
4
|
import { mapToNativeComponent } from "./component-mapping.js";
|
|
5
5
|
import { resolveIconName } from "./icons.js";
|
|
6
|
+
import { extractStylesheetRules } from "./stylesheet-rules.js";
|
|
6
7
|
import { applyNativeLayoutDefaults, parseNativeStyle } from "./inline-style.js";
|
|
7
8
|
import { createStyleVariables } from "./style-variables.js";
|
|
8
9
|
import { extractStylesheetTheme } from "./stylesheet-theme.js";
|
|
@@ -155,7 +156,7 @@ function readAttributes(tag, attributes, diagnostics, styleContext = {}) {
|
|
|
155
156
|
props[prop] = decoded;
|
|
156
157
|
}
|
|
157
158
|
}
|
|
158
|
-
const focus = props["data-native"] ? props["data-native"] === "TextInput" : tag === "textarea" || tag === "input" && !["checkbox", "radio", "hidden"].includes(String(props.type ?? "text").toLowerCase()), compiledClasses = classes ? compileClassStyles(classes, variables, { focus, focusWithin: !0 }) : void 0;
|
|
159
|
+
const focus = props["data-native"] ? props["data-native"] === "TextInput" : tag === "textarea" || tag === "input" && !["checkbox", "radio", "hidden"].includes(String(props.type ?? "text").toLowerCase()), compiledClasses = classes ? compileClassStyles(classes, variables, { focus, focusWithin: !0, rules: styleContext.rules }) : void 0;
|
|
159
160
|
for (const name of new Set(compiledClasses?.unknown ?? []))
|
|
160
161
|
diagnostics.push({ kind: "unknown-class", tag, name });
|
|
161
162
|
const style = applyNativeLayoutDefaults({ ...compiledClasses?.style, ...inline });
|
|
@@ -214,7 +215,7 @@ function settle(frame, diagnostics) {
|
|
|
214
215
|
return node;
|
|
215
216
|
}
|
|
216
217
|
export async function translateHtmlToIR(html, options = {}) {
|
|
217
|
-
const diagnostics = [], stylesheetTheme = await extractStylesheetTheme(html, (name) => diagnostics.push({ kind: "unsupported-theme-rule", tag: "style", name })), stylesheetVariables = createStyleVariables(stylesheetTheme.light).computed(), roots = [], stack = [], seenUnmapped = new Set;
|
|
218
|
+
const diagnostics = [], stylesheetTheme = await extractStylesheetTheme(html, (name) => diagnostics.push({ kind: "unsupported-theme-rule", tag: "style", name })), stylesheetVariables = createStyleVariables(stylesheetTheme.light).computed(), stylesheetRules = await extractStylesheetRules(html, (name) => diagnostics.push({ kind: "unsupported-style-rule", tag: "style", name })), roots = [], stack = [], seenUnmapped = new Set;
|
|
218
219
|
function attach(node) {
|
|
219
220
|
const parent = stack[stack.length - 1];
|
|
220
221
|
if (!parent)
|
|
@@ -258,7 +259,7 @@ export async function translateHtmlToIR(html, options = {}) {
|
|
|
258
259
|
let variables = parentFrame?.variables ?? stylesheetVariables;
|
|
259
260
|
const { props, style, events, bindings, classes, inline } = dropped || inheritedDrop ? { props: {}, style: {}, events: {}, bindings: {}, classes: "", inline: {} } : readAttributes(tag, attributes, diagnostics, { inheritedVariables: variables, onVariables: (value) => {
|
|
260
261
|
variables = value;
|
|
261
|
-
} });
|
|
262
|
+
}, rules: stylesheetRules });
|
|
262
263
|
if (tag === "html")
|
|
263
264
|
variables = stylesheetVariables;
|
|
264
265
|
const declared = props["data-native"];
|
|
@@ -268,6 +269,8 @@ export async function translateHtmlToIR(html, options = {}) {
|
|
|
268
269
|
delete props["data-native"];
|
|
269
270
|
} else {
|
|
270
271
|
type = BOX_ONLY.has(tag) ? "View" : mapToNativeComponent(tag);
|
|
272
|
+
if ((tag === "i" || tag === "span") && /(?:^|\s)i-[a-z0-9]+-[a-z0-9-]+(?:\s|$)/.test(classes))
|
|
273
|
+
type = "Icon";
|
|
271
274
|
if (tag === "input") {
|
|
272
275
|
const inputType = String(props.type ?? "text").toLowerCase();
|
|
273
276
|
if (inputType === "checkbox") {
|
|
@@ -357,7 +360,7 @@ export async function translateHtmlToIR(html, options = {}) {
|
|
|
357
360
|
let variables = parent?.variables ?? stylesheetVariables;
|
|
358
361
|
const { props, style, events, bindings, classes, inline } = readAttributes(tag, attributes, diagnostics, { inheritedVariables: variables, onVariables: (value) => {
|
|
359
362
|
variables = value;
|
|
360
|
-
} });
|
|
363
|
+
}, rules: stylesheetRules });
|
|
361
364
|
if (type === "Svg") {
|
|
362
365
|
const viewBox = parseViewBox(props.viewBox);
|
|
363
366
|
if (viewBox)
|
|
@@ -433,6 +436,8 @@ export async function translateHtmlToIR(html, options = {}) {
|
|
|
433
436
|
const root = roots.length === 1 ? roots[0] : createNode("View", {}, {}, {}, roots);
|
|
434
437
|
if (stylesheetTheme.light.length || stylesheetTheme.dark.length)
|
|
435
438
|
root._stylesheetTheme = stylesheetTheme;
|
|
439
|
+
if (Object.keys(stylesheetRules).length)
|
|
440
|
+
root._stylesheetRules = stylesheetRules;
|
|
436
441
|
const project = (node) => {
|
|
437
442
|
const projected = projectAccessibility(node.props);
|
|
438
443
|
if (Object.keys(projected).length) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { NativeStylesheetRules } from './stylesheet-rules';
|
|
1
2
|
import type { NativeStylesheetTheme } from './stylesheet-theme';
|
|
2
3
|
// ============================================================================
|
|
3
4
|
// Factory Functions
|
|
@@ -21,6 +22,7 @@ export declare interface STXNode {
|
|
|
21
22
|
_styleSource?: string
|
|
22
23
|
_styleAncestors?: string[]
|
|
23
24
|
_stylesheetTheme?: NativeStylesheetTheme
|
|
25
|
+
_stylesheetRules?: NativeStylesheetRules
|
|
24
26
|
_classes?: string
|
|
25
27
|
_source?: {
|
|
26
28
|
file: string
|
|
@@ -171,6 +173,19 @@ export declare interface STXDocument {
|
|
|
171
173
|
headwindConfig?: string
|
|
172
174
|
warnings?: string[]
|
|
173
175
|
}
|
|
176
|
+
title?: string
|
|
177
|
+
chrome?: NativeLayoutChrome
|
|
178
|
+
}
|
|
179
|
+
/** A link of a layout's chrome: a tab, or a navigation-bar button. */
|
|
180
|
+
export declare interface NativeChromeItem {
|
|
181
|
+
path: string
|
|
182
|
+
title: string
|
|
183
|
+
symbol?: string
|
|
184
|
+
}
|
|
185
|
+
/** What a layout marked as chrome (`data-native-chrome`), by where it goes. */
|
|
186
|
+
export declare interface NativeLayoutChrome {
|
|
187
|
+
tabs: NativeChromeItem[]
|
|
188
|
+
bar: NativeChromeItem[]
|
|
174
189
|
}
|
|
175
190
|
/** Platform-specific style overrides */
|
|
176
191
|
export declare interface PlatformStyles {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { NativeLayoutChrome } from './ir';
|
|
2
|
+
/**
|
|
3
|
+
* Take the chrome out of a rendered page: the page without it, and its links.
|
|
4
|
+
* `chrome` is null when the page marks none.
|
|
5
|
+
*/
|
|
6
|
+
export declare function extractLayoutChrome(html: string): Promise<{ html: string, chrome: NativeLayoutChrome | null }>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { iconClassIn, resolveIconName } from "./icons.js";
|
|
2
|
+
const CHROME = "[data-native-chrome]";
|
|
3
|
+
function regionKind(value) {
|
|
4
|
+
const kind = (value ?? "").trim().toLowerCase();
|
|
5
|
+
return kind === "tabs" || kind === "bar" ? kind : "";
|
|
6
|
+
}
|
|
7
|
+
function chromeSymbol(icon) {
|
|
8
|
+
const resolved = resolveIconName(icon);
|
|
9
|
+
return resolved.known || /^i-|:/.test(icon) ? resolved.symbol : icon;
|
|
10
|
+
}
|
|
11
|
+
function appPath(href) {
|
|
12
|
+
const value = (href ?? "").trim();
|
|
13
|
+
if (!value.startsWith("/") || value.startsWith("//"))
|
|
14
|
+
return null;
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
function readable(text) {
|
|
18
|
+
return text.replace(/ /g, " ").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/�?39;/g, "'").replace(/\s+/g, " ").trim();
|
|
19
|
+
}
|
|
20
|
+
export async function extractLayoutChrome(html) {
|
|
21
|
+
if (!/\bdata-native-chrome\b/i.test(html))
|
|
22
|
+
return { html, chrome: null };
|
|
23
|
+
const regions = [], items = [];
|
|
24
|
+
let open = null, marked = !1;
|
|
25
|
+
await new HTMLRewriter().on(CHROME, {
|
|
26
|
+
element(element) {
|
|
27
|
+
marked = !0;
|
|
28
|
+
regions.push(regionKind(element.getAttribute("data-native-chrome")));
|
|
29
|
+
element.onEndTag(() => {
|
|
30
|
+
regions.pop();
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}).on(`${CHROME} a`, {
|
|
34
|
+
element(element) {
|
|
35
|
+
const path = appPath(element.getAttribute("href")), region = regions[regions.length - 1] ?? "";
|
|
36
|
+
if (!path || !region)
|
|
37
|
+
return;
|
|
38
|
+
const icon = element.getAttribute("data-native-icon") || iconClassIn(element.getAttribute("class") ?? ""), item = {
|
|
39
|
+
path,
|
|
40
|
+
title: "",
|
|
41
|
+
region,
|
|
42
|
+
label: element.getAttribute("aria-label") || element.getAttribute("title") || "",
|
|
43
|
+
...icon ? { symbol: chromeSymbol(icon) } : {}
|
|
44
|
+
};
|
|
45
|
+
open = item;
|
|
46
|
+
element.onEndTag(() => {
|
|
47
|
+
item.title = readable(item.title) || readable(item.label);
|
|
48
|
+
items.push(item);
|
|
49
|
+
if (open === item)
|
|
50
|
+
open = null;
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
text(chunk) {
|
|
54
|
+
if (open)
|
|
55
|
+
open.title += chunk.text;
|
|
56
|
+
}
|
|
57
|
+
}).on(`${CHROME} a *`, {
|
|
58
|
+
element(element) {
|
|
59
|
+
if (!open || open.symbol)
|
|
60
|
+
return;
|
|
61
|
+
const icon = element.getAttribute("data-native-icon") || iconClassIn(element.getAttribute("class") ?? "");
|
|
62
|
+
if (icon)
|
|
63
|
+
open.symbol = chromeSymbol(icon);
|
|
64
|
+
}
|
|
65
|
+
}).transform(new Response(html)).text();
|
|
66
|
+
if (!marked)
|
|
67
|
+
return { html, chrome: null };
|
|
68
|
+
const stripped = await new HTMLRewriter().on(CHROME, { element(element) {
|
|
69
|
+
element.remove();
|
|
70
|
+
} }).transform(new Response(html)).text(), of = (region) => items.filter((item) => item.region === region).map(({ path, title, symbol }) => ({ path, title, ...symbol ? { symbol } : {} }));
|
|
71
|
+
return { html: stripped, chrome: { tabs: of("tabs"), bar: of("bar") } };
|
|
72
|
+
}
|
|
@@ -7,6 +7,7 @@ import { processScriptSetup } from "../../signal-processing.js";
|
|
|
7
7
|
import { appThemeCSS } from "./app-theme.js";
|
|
8
8
|
import { translateHtmlToDocument } from "./html-to-ir.js";
|
|
9
9
|
import { extractClientScript } from "./client-script.js";
|
|
10
|
+
import { extractLayoutChrome } from "./layout-chrome.js";
|
|
10
11
|
import { extractGeneratedSetupScript, extractNativeClientScripts } from "./setup-script.js";
|
|
11
12
|
export function nativePrimitivesDir() {
|
|
12
13
|
const candidates = [
|
|
@@ -19,8 +20,11 @@ export function nativePrimitivesDir() {
|
|
|
19
20
|
return candidates[0];
|
|
20
21
|
}
|
|
21
22
|
export async function compileScreenSource(source, filePath, options = {}) {
|
|
22
|
-
const root = options.root ?? path.dirname(filePath), loaded = await loadStxConfig(root), config = {
|
|
23
|
+
const root = options.root ?? path.dirname(filePath), loaded = await loadStxConfig(root), fromRoot = (dir, fallback) => dir ? path.isAbsolute(dir) ? dir : path.resolve(root, dir) : path.join(root, fallback), config = {
|
|
23
24
|
root,
|
|
25
|
+
layoutsDir: fromRoot(loaded.layoutsDir, "layouts"),
|
|
26
|
+
partialsDir: fromRoot(loaded.partialsDir, "partials"),
|
|
27
|
+
storesDir: fromRoot(loaded.storesDir, "stores"),
|
|
24
28
|
componentsDir: options.componentsDir ?? loaded.componentsDir ?? path.join(root, "components"),
|
|
25
29
|
buildMode: "serve",
|
|
26
30
|
cache: !1,
|
|
@@ -29,10 +33,14 @@ export async function compileScreenSource(source, filePath, options = {}) {
|
|
|
29
33
|
_nativeHostAttrs: !0,
|
|
30
34
|
skipEventDirectives: !0,
|
|
31
35
|
_pluginComponentDirs: loaded._pluginComponentDirs ?? []
|
|
32
|
-
}, context = { ...options.context ?? {}, __stx_inject_css: !1 }, dependencies = new Set([filePath]), renderedHtml = await processDirectives(source, context, filePath, config, dependencies), { html, manifest } = extractBindingManifest(
|
|
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, {
|
|
33
37
|
source: filePath,
|
|
34
38
|
script: extractClientScript(source)
|
|
35
|
-
});
|
|
39
|
+
}), head = context.__stx_runtime_head;
|
|
40
|
+
if (typeof head?.title === "string" && head.title.trim())
|
|
41
|
+
document.title = head.title.trim();
|
|
42
|
+
if (chrome)
|
|
43
|
+
document.chrome = chrome;
|
|
36
44
|
let setup = extractGeneratedSetupScript(html);
|
|
37
45
|
const scripts = extractNativeClientScripts(html);
|
|
38
46
|
if (extractClientScript(source).code.trim()) {
|
|
@@ -41,6 +49,14 @@ export async function compileScreenSource(source, filePath, options = {}) {
|
|
|
41
49
|
if (forcedSetup && !scripts.some((script) => script.code === forcedSetup.code))
|
|
42
50
|
scripts.push({ code: forcedSetup.code });
|
|
43
51
|
}
|
|
52
|
+
if (/<script\b[^>]*\bdata-stx-stores\b/i.test(html)) {
|
|
53
|
+
const { getStoreScript } = await import("../../store-loader.js"), stores = await getStoreScript(config.storesDir);
|
|
54
|
+
if (stores) {
|
|
55
|
+
scripts.unshift({ code: stores });
|
|
56
|
+
for (const file of new Bun.Glob("*.ts").scanSync({ cwd: config.storesDir, absolute: !0 }))
|
|
57
|
+
dependencies.add(file);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
44
60
|
const { buildModuleRegistryScript, registeredModuleIdsIn } = await import("../../client-module-registry.js"), moduleInputs = [], modules = await buildModuleRegistryScript(registeredModuleIdsIn(...scripts.map((script) => script.code)), {
|
|
45
61
|
collectInputs: moduleInputs
|
|
46
62
|
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Use `config` for every native class resolution from now on. */
|
|
2
|
+
export declare function setNativeStyleConfig(config: NativeStyleConfig | null | undefined): void;
|
|
3
|
+
/** Run `work` with `config` in force, then put back what was there (a compile's config is its own). */
|
|
4
|
+
export declare function withNativeStyleConfig<T>(config: NativeStyleConfig, work: () => Promise<T>): Promise<T>;
|
|
5
|
+
/**
|
|
6
|
+
* The part of a project's CSS config native styles read, in the shape a
|
|
7
|
+
* native bundle carries (plain JSON): shortcuts, theme colours, breakpoints.
|
|
8
|
+
*/
|
|
9
|
+
export declare function nativeStyleConfigFrom(cssConfig: Record<string, any> | null | undefined): NativeStyleConfig;
|
|
10
|
+
/** A shortcut's classes, or undefined when `name` is not one. */
|
|
11
|
+
export declare function nativeShortcut(name: string): string | undefined;
|
|
12
|
+
/** A theme colour's value (`var(--hq-action, #007aff)`), or undefined. */
|
|
13
|
+
export declare function nativeThemeColor(name: string): string | undefined;
|
|
14
|
+
/** A breakpoint's min-width in points, or undefined when `name` is not one. */
|
|
15
|
+
export declare function nativeBreakpoint(name: string): number | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* The app's own utility vocabulary, for native styles.
|
|
18
|
+
*
|
|
19
|
+
* A web view and a native screen are one source: the same classes have to
|
|
20
|
+
* mean the same thing on both. The web reads the app's CSS config (Crosswind
|
|
21
|
+
* shortcuts like `card` and `btn-primary`, theme colours like `bg-hq-action`,
|
|
22
|
+
* the breakpoints behind `md:`); native styles read the same config through
|
|
23
|
+
* here. The compiler loads it from the project and the native bundle carries
|
|
24
|
+
* it, so classes bound at runtime resolve the same way.
|
|
25
|
+
*/
|
|
26
|
+
/** Tailwind's (and Crosswind's) default min-widths, in points. */
|
|
27
|
+
export declare const DEFAULT_BREAKPOINTS: Readonly<Record<string, number>>;
|
|
28
|
+
export declare interface NativeStyleConfig {
|
|
29
|
+
shortcuts?: Record<string, string>
|
|
30
|
+
colors?: Record<string, unknown>
|
|
31
|
+
breakpoints?: Record<string, number>
|
|
32
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export const DEFAULT_BREAKPOINTS = { sm: 640, md: 768, lg: 1024, xl: 1280, "2xl": 1536 };
|
|
2
|
+
let current = resolve({}), globalSource, globalResolved = null;
|
|
3
|
+
function active() {
|
|
4
|
+
const source = globalThis.__stxNativeStyleConfig;
|
|
5
|
+
if (!source)
|
|
6
|
+
return current;
|
|
7
|
+
if (source !== globalSource) {
|
|
8
|
+
globalSource = source;
|
|
9
|
+
globalResolved = resolve(source);
|
|
10
|
+
}
|
|
11
|
+
return globalResolved;
|
|
12
|
+
}
|
|
13
|
+
function flattenColors(colors, into = new Map, prefix = "") {
|
|
14
|
+
for (const [name, value] of Object.entries(colors ?? {})) {
|
|
15
|
+
const key = name === "DEFAULT" ? prefix.replace(/-$/, "") : `${prefix}${name}`;
|
|
16
|
+
if (typeof value === "string")
|
|
17
|
+
into.set(key, value);
|
|
18
|
+
else if (value && typeof value === "object")
|
|
19
|
+
flattenColors(value, into, `${key}-`);
|
|
20
|
+
}
|
|
21
|
+
return into;
|
|
22
|
+
}
|
|
23
|
+
function breakpointsOf(config) {
|
|
24
|
+
const out = {};
|
|
25
|
+
for (const [name, value] of Object.entries(config ?? {})) {
|
|
26
|
+
const points = typeof value === "number" ? value : Number.parseFloat(String(value));
|
|
27
|
+
if (Number.isFinite(points))
|
|
28
|
+
out[name] = points;
|
|
29
|
+
}
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
function resolve(config) {
|
|
33
|
+
return {
|
|
34
|
+
shortcuts: new Map(Object.entries(config.shortcuts ?? {}).filter(([, value]) => typeof value === "string")),
|
|
35
|
+
colors: flattenColors(config.colors),
|
|
36
|
+
breakpoints: new Map(Object.entries({ ...DEFAULT_BREAKPOINTS, ...breakpointsOf(config.breakpoints) }))
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
let currentSource = {};
|
|
40
|
+
export function setNativeStyleConfig(config) {
|
|
41
|
+
currentSource = config ?? {};
|
|
42
|
+
current = resolve(currentSource);
|
|
43
|
+
}
|
|
44
|
+
export async function withNativeStyleConfig(config, work) {
|
|
45
|
+
const before = currentSource;
|
|
46
|
+
setNativeStyleConfig(config);
|
|
47
|
+
try {
|
|
48
|
+
return await work();
|
|
49
|
+
} finally {
|
|
50
|
+
setNativeStyleConfig(before);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export function nativeStyleConfigFrom(cssConfig) {
|
|
54
|
+
if (!cssConfig)
|
|
55
|
+
return {};
|
|
56
|
+
const theme = cssConfig.theme ?? {}, shortcuts = Object.fromEntries(Object.entries(cssConfig.shortcuts ?? {}).filter(([, value]) => typeof value === "string"));
|
|
57
|
+
return {
|
|
58
|
+
...Object.keys(shortcuts).length ? { shortcuts } : {},
|
|
59
|
+
...theme.colors ? { colors: JSON.parse(JSON.stringify(theme.colors)) } : {},
|
|
60
|
+
...theme.screens ? { breakpoints: breakpointsOf(theme.screens) } : {}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export function nativeShortcut(name) {
|
|
64
|
+
return active().shortcuts.get(name);
|
|
65
|
+
}
|
|
66
|
+
export function nativeThemeColor(name) {
|
|
67
|
+
return active().colors.get(name);
|
|
68
|
+
}
|
|
69
|
+
export function nativeBreakpoint(name) {
|
|
70
|
+
return active().breakpoints.get(name);
|
|
71
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** The page's simple class rules; anything more involved is reported, not guessed at. */
|
|
2
|
+
export declare function extractStylesheetRules(html: string, report: (name: string) => void): Promise<NativeStylesheetRules>;
|
|
3
|
+
/**
|
|
4
|
+
* A class's declarations from the page's own stylesheets, as CSS text, by
|
|
5
|
+
* layer: what `.stat-value { ... }` gives an element with that class.
|
|
6
|
+
*
|
|
7
|
+
* Web views style their parts with small classes of their own (`.panel-title`,
|
|
8
|
+
* `.bw-card`) beside the utilities. Natively a class only meant something if
|
|
9
|
+
* it was a utility, so those parts lost their look. The text is parsed where
|
|
10
|
+
* it is applied, so a `var(--hq-action)` in it reads the screen's variables.
|
|
11
|
+
*/
|
|
12
|
+
export declare interface NativeStylesheetRule {
|
|
13
|
+
light?: string
|
|
14
|
+
dark?: string
|
|
15
|
+
responsive?: Array<{ min: number, light?: string, dark?: string }>
|
|
16
|
+
}
|
|
17
|
+
export type NativeStylesheetRules = Record<string, NativeStylesheetRule>;
|