@stacksjs/stx 0.2.577 → 0.2.578
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-0047meje.js +2 -0
- package/dist/chunk-00p22wzr.js +3 -0
- package/dist/{chunk-z33z3rr4.js → chunk-0k5faspy.js} +6 -6
- package/dist/{chunk-wwhxgvr8.js → chunk-0vnngvy1.js} +4 -4
- package/dist/{chunk-7a0ewpz0.js → chunk-101ekf6y.js} +2 -2
- package/dist/{chunk-t79xnvzr.js → chunk-117xss52.js} +2 -2
- package/dist/chunk-1cat8kdj.js +2 -0
- package/dist/chunk-1dwnp35v.js +2 -0
- package/dist/{chunk-5vw8493b.js → chunk-1r1maqep.js} +3 -3
- package/dist/{chunk-zak5xare.js → chunk-1v1mew46.js} +1 -1
- package/dist/chunk-2dnr5qfk.js +2 -0
- package/dist/{chunk-1swmxkdt.js → chunk-2rx9d75e.js} +2 -2
- package/dist/chunk-2v73cjbc.js +2 -0
- package/dist/chunk-3akgppsy.js +2 -0
- package/dist/{chunk-8efe5vpm.js → chunk-3e3dpp7w.js} +3 -3
- package/dist/{chunk-vnsby98n.js → chunk-3qrrv6af.js} +1 -1
- package/dist/{chunk-fkbthywg.js → chunk-3wy8q3aq.js} +5 -5
- package/dist/chunk-3x6p9me0.js +2 -0
- package/dist/{chunk-tybk9hw9.js → chunk-43h8q2cm.js} +9 -9
- package/dist/{chunk-pqkb1m5x.js → chunk-4rkvwm6v.js} +5 -5
- package/dist/{chunk-bks1fe5e.js → chunk-4srg0qbv.js} +1 -1
- package/dist/chunk-4t67wmcg.js +2 -0
- package/dist/chunk-51zn42jy.js +2 -0
- package/dist/chunk-5702x95v.js +2 -0
- package/dist/{chunk-4z21afpp.js → chunk-5db5sxy3.js} +2 -2
- package/dist/{chunk-r4w1cye7.js → chunk-5kh5ehfh.js} +2 -2
- package/dist/chunk-5pgbsc3a.js +2 -0
- package/dist/chunk-60c2bsh9.js +2 -0
- package/dist/{chunk-vw1rmevt.js → chunk-620szfcp.js} +3 -3
- package/dist/{chunk-6rfm6b1c.js → chunk-6w2yqtrd.js} +2 -2
- package/dist/{chunk-37d52q0d.js → chunk-6z3e1tyz.js} +1 -1
- package/dist/{chunk-nskvepjv.js → chunk-71sdgv7e.js} +5 -5
- package/dist/chunk-79v4d9qh.js +2 -0
- package/dist/{chunk-qfb34r6k.js → chunk-7hkc96de.js} +6 -6
- package/dist/chunk-7pp2vx1g.js +2 -0
- package/dist/chunk-84f9dnq5.js +2 -0
- package/dist/chunk-8tq5x4z8.js +2 -0
- package/dist/{chunk-gjp2jxrp.js → chunk-8v19753h.js} +1 -1
- package/dist/chunk-8zm6tkqb.js +2 -0
- package/dist/{chunk-1dg5qxg9.js → chunk-9jh2ake5.js} +5 -5
- package/dist/chunk-a1z36dt5.js +2 -0
- package/dist/{chunk-7hr63cp5.js → chunk-ah9xyss2.js} +2 -2
- package/dist/chunk-atsf1fe0.js +2 -0
- package/dist/{chunk-x5xwe5nr.js → chunk-ayy9mmrw.js} +7 -7
- package/dist/chunk-b8qd6h1q.js +2 -0
- package/dist/{chunk-vde4mtfr.js → chunk-be2ba3hj.js} +2 -2
- package/dist/{chunk-pxk0tpw2.js → chunk-bj29pwm0.js} +3 -3
- package/dist/{chunk-gpb22a8n.js → chunk-c0h2eqe0.js} +2 -2
- package/dist/{chunk-agk478t4.js → chunk-c0s3k64c.js} +2 -2
- package/dist/{chunk-bctjmaxg.js → chunk-c1r7zq0q.js} +41 -41
- package/dist/{chunk-32gycb72.js → chunk-cb2pyg5t.js} +2 -2
- package/dist/chunk-ccxs40xy.js +2 -0
- package/dist/{chunk-7j9m4d7x.js → chunk-cdgwkzms.js} +3 -3
- package/dist/{chunk-6c2y9h5h.js → chunk-cnknvvwm.js} +1 -1
- package/dist/chunk-cp442y7a.js +2 -0
- package/dist/chunk-d4en5d3s.js +2 -0
- package/dist/chunk-dh80d57p.js +2 -0
- package/dist/{chunk-je0cttam.js → chunk-djft0m5h.js} +2 -2
- package/dist/chunk-dpn1pmxj.js +2 -0
- package/dist/chunk-dtcc09x1.js +2 -0
- package/dist/{chunk-sf7z2ar9.js → chunk-dvgvvy5b.js} +3 -3
- package/dist/chunk-dyqte1xq.js +2 -0
- package/dist/chunk-e4n4v022.js +2 -0
- package/dist/chunk-efgk2xv1.js +2 -0
- package/dist/{chunk-h1n43e5n.js → chunk-ev5f79mg.js} +5 -5
- package/dist/{chunk-1wkpxa58.js → chunk-eww6sdzz.js} +2 -2
- package/dist/{chunk-34fajf1n.js → chunk-faghmmrs.js} +139 -139
- package/dist/chunk-fj70wq7k.js +2 -0
- package/dist/chunk-g2fw68zm.js +2 -0
- package/dist/{chunk-szfkkbve.js → chunk-g4crr86j.js} +3 -3
- package/dist/{chunk-xh0808cd.js → chunk-h0a2s340.js} +2 -2
- package/dist/chunk-hcgm37dy.js +2 -0
- package/dist/chunk-hd2bn5q7.js +2 -0
- package/dist/{chunk-5dm4k229.js → chunk-hzfhn2vr.js} +2 -2
- package/dist/{chunk-6wz6f8d5.js → chunk-j1nqnmcd.js} +4 -4
- package/dist/{chunk-1c8sdf9a.js → chunk-jpqkm8tm.js} +2 -2
- package/dist/{chunk-550q827h.js → chunk-jtbzmbzz.js} +4 -4
- package/dist/chunk-k7jqkt93.js +2 -0
- package/dist/{chunk-wvk932dp.js → chunk-k9th7hc4.js} +4 -4
- package/dist/chunk-kp0hg06s.js +15 -0
- package/dist/{chunk-kskyfss0.js → chunk-ktyctev3.js} +2 -2
- package/dist/{chunk-xk2v20xe.js → chunk-m8tm44rq.js} +2 -2
- package/dist/chunk-mhjwtkx9.js +2 -0
- package/dist/chunk-mqy7g74k.js +2 -0
- package/dist/chunk-mxe21m6q.js +2 -0
- package/dist/chunk-ne03tfje.js +2 -0
- package/dist/{chunk-3gqrv02t.js → chunk-nrfh7gaa.js} +3 -3
- package/dist/chunk-p2sns0bn.js +2 -0
- package/dist/chunk-pjrh71sn.js +122 -0
- package/dist/{chunk-jgrtvs81.js → chunk-pmpb34md.js} +5 -5
- package/dist/chunk-q2a58n2a.js +2 -0
- package/dist/{chunk-5xwmkxkk.js → chunk-qazn64pm.js} +1 -1
- package/dist/{chunk-7bwkeake.js → chunk-qccgncp2.js} +6 -6
- package/dist/{chunk-1edvsndv.js → chunk-qdyp2zqf.js} +2 -2
- package/dist/chunk-rr8a7d4q.js +11 -0
- package/dist/{chunk-mr9c2ej6.js → chunk-s12bnv32.js} +2 -2
- package/dist/chunk-s1sycp43.js +2 -0
- package/dist/chunk-s932zfjz.js +2 -0
- package/dist/chunk-sp46w7z9.js +2 -0
- package/dist/{chunk-tasjpnbf.js → chunk-sv5nvfmb.js} +2 -2
- package/dist/chunk-sy1bk1ry.js +2 -0
- package/dist/chunk-t48ws5j0.js +2 -0
- package/dist/{chunk-sn3htx1z.js → chunk-t4g2fptt.js} +6 -6
- package/dist/{chunk-d8ek63nc.js → chunk-t8wpzqs4.js} +1 -1
- package/dist/{chunk-bpdsdbvg.js → chunk-ta3wn842.js} +2 -2
- package/dist/chunk-thbc9gtj.js +2 -0
- package/dist/chunk-tn9v10q2.js +2 -0
- package/dist/chunk-tpd5nwa3.js +2 -0
- package/dist/chunk-tpt4bgs5.js +2 -0
- package/dist/{chunk-n829xbbq.js → chunk-tszkg6sj.js} +2 -2
- package/dist/chunk-v8p5p2kp.js +2 -0
- package/dist/chunk-v9jd283e.js +2 -0
- package/dist/{chunk-4xvbc0mb.js → chunk-vpdx7qr3.js} +2 -2
- package/dist/chunk-vq0cb1m9.js +2 -0
- package/dist/chunk-vx75fb0d.js +33 -0
- package/dist/{chunk-pveafhzg.js → chunk-w3rmepwy.js} +2 -2
- package/dist/{chunk-xsxh7h8z.js → chunk-wg2w7zmt.js} +2 -2
- package/dist/chunk-wgkxgsqx.js +2 -0
- package/dist/{chunk-707n4pbz.js → chunk-wwj8zbzc.js} +5 -5
- package/dist/{chunk-p3xkj7pm.js → chunk-xpnpg967.js} +2 -2
- package/dist/chunk-y1bppxgw.js +2 -0
- package/dist/{chunk-1w9ngqpv.js → chunk-y8q1n7hx.js} +10 -10
- package/dist/{chunk-vmetcczm.js → chunk-yfq2v7x5.js} +6 -6
- package/dist/{chunk-h72befy4.js → chunk-yhpyqsbr.js} +4 -4
- package/dist/{chunk-n0kw3q6p.js → chunk-yk3fbzx5.js} +4 -4
- package/dist/chunk-yv5rwthv.js +2 -0
- package/dist/{chunk-mp99h8wh.js → chunk-yy3ser06.js} +5 -5
- package/dist/chunk-yygze2s0.js +2 -0
- package/dist/chunk-z1r4tdqy.js +2 -0
- package/dist/chunk-z732tf98.js +2 -0
- package/dist/{chunk-haeb904b.js → chunk-zk2xk0wd.js} +2 -2
- package/dist/chunk-zv288w4e.js +2 -0
- package/dist/{chunk-j4zyq2ap.js → chunk-zz02hwec.js} +11 -11
- package/dist/cli.js +19 -19
- package/dist/client-script-bundler.d.ts +12 -0
- package/dist/client-script-bundler.js +19 -5
- package/dist/composable-loader.js +2 -2
- package/dist/craft-entry.js +2 -2
- package/dist/craft.js +2 -2
- package/dist/native/compiler/bundle.d.ts +22 -0
- package/dist/native/compiler/bundle.js +164 -20
- package/dist/pwa.js +3 -3
- package/dist/ssg.js +3 -3
- package/dist/store-loader.js +7 -7
- package/package.json +5 -5
- package/dist/chunk-08a98yqt.js +0 -2
- package/dist/chunk-0q5s55km.js +0 -2
- package/dist/chunk-181m21rg.js +0 -2
- package/dist/chunk-194qgkc9.js +0 -2
- package/dist/chunk-1nbn56jw.js +0 -2
- package/dist/chunk-2ry2pfpe.js +0 -2
- package/dist/chunk-3bj1w990.js +0 -2
- package/dist/chunk-4a12azrb.js +0 -2
- package/dist/chunk-6aq3sm83.js +0 -2
- package/dist/chunk-6fpynp8q.js +0 -2
- package/dist/chunk-6q3yszw9.js +0 -74
- package/dist/chunk-6ryab0yy.js +0 -2
- package/dist/chunk-6sasxbv9.js +0 -2
- package/dist/chunk-6w9km7qb.js +0 -2
- package/dist/chunk-7kh4p06d.js +0 -2
- package/dist/chunk-7xrrzqh7.js +0 -2
- package/dist/chunk-7y73q42g.js +0 -11
- package/dist/chunk-8jaw6exk.js +0 -2
- package/dist/chunk-98r9jk2b.js +0 -2
- package/dist/chunk-9dgygz8d.js +0 -2
- package/dist/chunk-a51f04an.js +0 -2
- package/dist/chunk-aa52jhak.js +0 -2
- package/dist/chunk-ambynnzb.js +0 -2
- package/dist/chunk-ampr3fpv.js +0 -2
- package/dist/chunk-asbq9cgs.js +0 -2
- package/dist/chunk-bbdg3sqq.js +0 -33
- package/dist/chunk-bmtsb5mr.js +0 -2
- package/dist/chunk-c8rd3573.js +0 -2
- package/dist/chunk-d4b8cgvt.js +0 -2
- package/dist/chunk-d7skqhrc.js +0 -2
- package/dist/chunk-ensp20xk.js +0 -2
- package/dist/chunk-f1zyc84x.js +0 -2
- package/dist/chunk-f2y8bwdd.js +0 -2
- package/dist/chunk-g9vtny6q.js +0 -2
- package/dist/chunk-hcsrj8z6.js +0 -3
- package/dist/chunk-hj1bntaa.js +0 -2
- package/dist/chunk-hwy3aw5v.js +0 -2
- package/dist/chunk-hyafyqy6.js +0 -2
- package/dist/chunk-j75hqvgt.js +0 -2
- package/dist/chunk-j83ax407.js +0 -2
- package/dist/chunk-k3hfwve1.js +0 -2
- package/dist/chunk-ktc1ecsm.js +0 -2
- package/dist/chunk-mbmbaj0m.js +0 -2
- package/dist/chunk-nd3qttxh.js +0 -2
- package/dist/chunk-ndc1bmj7.js +0 -2
- package/dist/chunk-nn462qm9.js +0 -2
- package/dist/chunk-nr07vxm2.js +0 -2
- package/dist/chunk-q7a5pwaz.js +0 -2
- package/dist/chunk-qx6tr8mr.js +0 -2
- package/dist/chunk-r51vyhms.js +0 -2
- package/dist/chunk-s68bqf62.js +0 -2
- package/dist/chunk-s6sf70ty.js +0 -2
- package/dist/chunk-svavrmxb.js +0 -2
- package/dist/chunk-sw7mvg9p.js +0 -2
- package/dist/chunk-tz40t18m.js +0 -2
- package/dist/chunk-v1k0bdsg.js +0 -2
- package/dist/chunk-vd10tty0.js +0 -2
- package/dist/chunk-vqkzhd19.js +0 -2
- package/dist/chunk-w1yft5gg.js +0 -2
- package/dist/chunk-w6sa921x.js +0 -2
- package/dist/chunk-y120qq1a.js +0 -15
- package/dist/chunk-zcw74jmk.js +0 -2
- package/dist/chunk-zxvndwaz.js +0 -2
- package/dist/chunk-zzr0p4bb.js +0 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import fs from "node:fs";
|
|
3
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
4
|
import { getPublicEnvDefine } from "./public-env.js";
|
|
4
5
|
import { stateDir } from "./state-dir.js";
|
|
5
6
|
import { cacheEngineFingerprint } from "./engine-fingerprint.js";
|
|
@@ -179,7 +180,17 @@ function probeModuleFile(basePath) {
|
|
|
179
180
|
} catch {}
|
|
180
181
|
return;
|
|
181
182
|
}
|
|
182
|
-
|
|
183
|
+
const moduleSubstitutes = new AsyncLocalStorage;
|
|
184
|
+
export function withModuleSubstitutes(modules, run) {
|
|
185
|
+
const hasher = new Bun.CryptoHasher("md5");
|
|
186
|
+
for (const [file, contents] of [...modules].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0))
|
|
187
|
+
hasher.update(`${file}\x00${contents}\x00`);
|
|
188
|
+
return moduleSubstitutes.run({ modules, key: hasher.digest("hex").slice(0, 12) }, run);
|
|
189
|
+
}
|
|
190
|
+
export function moduleSubstitutionKey() {
|
|
191
|
+
return moduleSubstitutes.getStore()?.key ?? "";
|
|
192
|
+
}
|
|
193
|
+
function createBundlePlugin(projectRoot, templateDir, tmpEntry, inputFiles, externalizeUserModules, registrySpecifiers = new Map, serverApi, substitutes) {
|
|
183
194
|
const toRegistry = (importer, resolved, specifier) => {
|
|
184
195
|
if (isPrivateClientSource(resolved, projectRoot, serverApi))
|
|
185
196
|
return null;
|
|
@@ -271,6 +282,9 @@ function createBundlePlugin(projectRoot, templateDir, tmpEntry, inputFiles, exte
|
|
|
271
282
|
const extension = path.extname(args.path).toLowerCase(), loader = extension === ".json" ? "json" : extension === ".tsx" ? "tsx" : extension === ".jsx" ? "jsx" : extension === ".ts" || extension === ".mts" || extension === ".cts" ? "ts" : "js";
|
|
272
283
|
if (args.path !== tmpEntry)
|
|
273
284
|
inputFiles.add(args.path);
|
|
285
|
+
const substitute = substitutes?.get(args.path);
|
|
286
|
+
if (substitute !== void 0)
|
|
287
|
+
return { contents: substitute, loader: "js" };
|
|
274
288
|
return {
|
|
275
289
|
contents: fs.readFileSync(args.path, "utf8"),
|
|
276
290
|
loader
|
|
@@ -290,8 +304,8 @@ export function queueClientBundleBuild(task) {
|
|
|
290
304
|
return result;
|
|
291
305
|
}
|
|
292
306
|
export async function bundleClientScript(code, filePath, options = {}) {
|
|
293
|
-
const projectRoot = options.projectRoot || process.cwd(), serverApi = (await loadStxConfig(projectRoot)).serverApi, minify = options.minify ?? !1, externalizeUserModules = options.externalizeUserModules ?? !0, expose = options.expose?.length ? [...new Set(options.expose)].sort() : void 0, cacheDir = options.cacheDir || stateDir(projectRoot, "bundle-cache"), hasher = new Bun.CryptoHasher("md5");
|
|
294
|
-
hasher.update(`${BUNDLE_CACHE_VERSION}\x00${cacheEngineFingerprint()}\x00${JSON.stringify(serverApi ?? !1)}\x00${externalizeUserModules ? "registry" : "inline"}\x00${expose ? expose.join(",") : "*"}\x00${minify ? "minified" : "readable"}\x00${code}\x00${filePath}`);
|
|
307
|
+
const projectRoot = options.projectRoot || process.cwd(), serverApi = (await loadStxConfig(projectRoot)).serverApi, minify = options.minify ?? !1, externalizeUserModules = options.externalizeUserModules ?? !0, expose = options.expose?.length ? [...new Set(options.expose)].sort() : void 0, cacheDir = options.cacheDir || stateDir(projectRoot, "bundle-cache"), substituted = moduleSubstitutes.getStore(), hasher = new Bun.CryptoHasher("md5");
|
|
308
|
+
hasher.update(`${BUNDLE_CACHE_VERSION}\x00${cacheEngineFingerprint()}\x00${JSON.stringify(serverApi ?? !1)}\x00${externalizeUserModules ? "registry" : "inline"}\x00${expose ? expose.join(",") : "*"}\x00${minify ? "minified" : "readable"}\x00${substituted?.key ?? ""}\x00${code}\x00${filePath}`);
|
|
295
309
|
const hash = hasher.digest("hex").slice(0, 12), cachePath = path.join(cacheDir, `${hash}.js`), remembered = bundleMemo.get(cachePath);
|
|
296
310
|
if (remembered) {
|
|
297
311
|
if (depsUnchanged(remembered.files) && remembered.files.every((dep) => !isPrivateClientSource(dep.path, projectRoot, serverApi))) {
|
|
@@ -342,7 +356,7 @@ export async function bundleClientScript(code, filePath, options = {}) {
|
|
|
342
356
|
options.collectInputs.push(...(bundleMemo.get(cachePath)?.files ?? []).map((dep) => dep.path));
|
|
343
357
|
return shared;
|
|
344
358
|
}
|
|
345
|
-
const build = queueClientBundleBuild(() => buildBundle(code, filePath, { projectRoot, minify, cacheDir, hash, cachePath, depsPath, collectInputs: options.collectInputs, externalizeUserModules, serverApi, expose, throwOnFailure: options.throwOnFailure }));
|
|
359
|
+
const build = queueClientBundleBuild(() => buildBundle(code, filePath, { projectRoot, minify, cacheDir, hash, cachePath, depsPath, collectInputs: options.collectInputs, externalizeUserModules, serverApi, expose, throwOnFailure: options.throwOnFailure, substitutes: substituted?.modules }));
|
|
346
360
|
inFlightBundles.set(hash, build);
|
|
347
361
|
try {
|
|
348
362
|
return await build;
|
|
@@ -419,7 +433,7 @@ export { ${[...declNames].join(", ")} }` : "";
|
|
|
419
433
|
target: "browser",
|
|
420
434
|
format: "esm",
|
|
421
435
|
minify: minify ? { whitespace: !1, identifiers: !0, syntax: !0 } : !1,
|
|
422
|
-
plugins: [createBundlePlugin(projectRoot, templateDir, tmpEntry, inputFiles, externalizeUserModules, registrySpecifiers, options.serverApi)],
|
|
436
|
+
plugins: [createBundlePlugin(projectRoot, templateDir, tmpEntry, inputFiles, externalizeUserModules, registrySpecifiers, options.serverApi, options.substitutes)],
|
|
423
437
|
define: {
|
|
424
438
|
"process.env.NODE_ENV": minify ? '"production"' : '"development"',
|
|
425
439
|
...getPublicEnvDefine()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { unboundNames } from "./client-parameter-bindings.js";
|
|
3
|
-
import { bundleClientScript, clientBundleDependencies, hasUserImports } from "./client-script-bundler.js";
|
|
3
|
+
import { bundleClientScript, clientBundleDependencies, hasUserImports, moduleSubstitutionKey } from "./client-script-bundler.js";
|
|
4
4
|
import { loadStxConfig } from "./config.js";
|
|
5
5
|
import { isProduction, minifyClassicScript } from "./env.js";
|
|
6
6
|
import { getPublicEnvDefine } from "./public-env.js";
|
|
@@ -174,7 +174,7 @@ export async function getComposableScript(composablesDir, pageSource, extraSourc
|
|
|
174
174
|
}
|
|
175
175
|
if (selected.size === 0)
|
|
176
176
|
return null;
|
|
177
|
-
const includedFiles = composableFiles.filter((file) => selected.has(file)), cacheKey = `${resolvedDir}\x00${includedFiles.join("\x00")}`, cached = readSigned(_cachedComposableScripts, cacheKey, signature);
|
|
177
|
+
const includedFiles = composableFiles.filter((file) => selected.has(file)), cacheKey = `${resolvedDir}\x00${includedFiles.join("\x00")}\x00${moduleSubstitutionKey()}`, cached = readSigned(_cachedComposableScripts, cacheKey, signature);
|
|
178
178
|
if (cached !== void 0)
|
|
179
179
|
return cached || null;
|
|
180
180
|
const chunks = [], exportedNames = new Set, declaredNames = new Set;
|
package/dist/craft-entry.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{Jr,Bo,Fo}from"./chunk-620szfcp.js";import"./chunk-7hkc96de.js";import"./chunk-ah9xyss2.js";import"./chunk-yhpyqsbr.js";import"./chunk-zk2xk0wd.js";import"./chunk-vpdx7qr3.js";import"./chunk-faghmmrs.js";import"./chunk-43h8q2cm.js";import"./chunk-ayy9mmrw.js";import"./chunk-be2ba3hj.js";import"./chunk-eww6sdzz.js";import"./chunk-qdyp2zqf.js";import"./chunk-jtbzmbzz.js";import"./chunk-117xss52.js";import{Ad,Io,Pd,Id,Oo,Xr,Do,Od,Mo,Dd,Md,No,Lo,jo}from"./chunk-zz02hwec.js";import"./chunk-j1nqnmcd.js";import"./chunk-cdgwkzms.js";var m=new Map,d=new Map;function R(t,e){let n=e?.id||E(t),r=I(t),a=m.get(n);if(a&&a.hash===r)return a;let i=M(t),s=L(t),o=W(t),c=O(i),{staticParts:p,dynamicParts:l}=A(i),f=_(t),g={id:n,hash:r,tree:i,scripts:s,styles:o,staticParts:p,dynamicParts:l,dependencies:f,metadata:c};return m.set(n,g),g}async function Q(t,e={},n={}){let r=performance.now();if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`,c=d.get(o);if(c&&Date.now()-c.timestamp<(n.cacheTTL||60000))return{html:c.html,styles:t.styles.join(`
|
|
3
3
|
`),scripts:t.scripts.join(`
|
|
4
4
|
`),metadata:{renderTime:0,cacheHit:!0,totalSize:c.html.length,componentCount:t.metadata.componentCount}}}let a;if(n.streaming)a=await H(t.tree,e);else a=h(t.tree,e);let i;if(n.hydrate){let o=j(a,t,e);a=o.html,i=o.data}if(n.minify)a=D(a);if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`;d.set(o,{html:a,timestamp:Date.now()})}let s=performance.now()-r;return{html:a,styles:t.styles.join(`
|
|
5
5
|
`),scripts:t.scripts.join(`
|
|
6
6
|
`),hydrationData:i,metadata:{renderTime:s,cacheHit:!1,totalSize:a.length,componentCount:t.metadata.componentCount}}}function V(t,e){let n=[],r=[],a=[],i=new Map,s=[];return y(t.tree,(o,c)=>{if(o.type==="component"&&o.componentName){if(T(o.componentName))n.push(o.componentName)}if(o.type==="element"&&o.tag){let p=J(o);if(p)s.push(p);if(o.props){for(let[l,f]of Object.entries(o.props))if(l.startsWith("on")&&typeof f==="string"){let g=`handler_${i.size}`;i.set(g,f)}}}if(o.isStatic&&o.type==="element")r.push(b(o));else if(!o.isStatic&&o.type!=="text")a.push(o.tag||o.componentName||"unknown")}),{nativeComponents:n,staticHTML:r,dynamicParts:a,eventHandlers:i,nativeWidgets:s}}function Y(t,e={}){let n=R(t),r=P(n,e),a=new Map,i=[];return y(n.tree,(s)=>{if(s.type==="component"&&s.componentName){if(T(s.componentName)){i.push(s.componentName);let o=`<!--craft:${s.componentName}:${s.hydrationKey||"default"}-->`;a.set(s.hydrationKey||s.componentName,o)}}}),{staticHTML:r,dynamicPlaceholders:a,craftComponents:i}}function M(t){let e={type:"fragment",children:[]},n=e,r=[e],a=t,i=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);while(a.length>0){let s=a.match(/^<(@?[\w-]+)([^>]*)>/);if(s){let[p,l,f]=s,g=z(f),u=l.startsWith("@craft-"),C=u?l:l.toLowerCase(),S={type:u?"component":"element",tag:C,props:g,children:[],componentName:u?C.slice(1):void 0,isStatic:!v(f),hydrationKey:F()};if(n.children=n.children||[],n.children.push(S),!i.has(C)&&!f.endsWith("/"))r.push(S),n=S;a=a.slice(p.length);continue}let o=a.match(/^<\/(@?[\w-]+)>/);if(o){let[p,l]=o,g=l.startsWith("@craft-")?l:l.toLowerCase();while(r.length>1){let u=r.pop();if(n=r[r.length-1],u.tag===g)break}a=a.slice(p.length);continue}let c=a.match(/^[^<]+/);if(c){let p=c[0];if(p.trim()){let l={type:"text",text:p,isStatic:!v(p)};n.children=n.children||[],n.children.push(l)}a=a.slice(p.length);continue}a=a.slice(1)}return e}function z(t){let e={},n=/([\w-:@]+)(?:=(?:"([^"]*)"|'([^']*)'|(\S+)))?/g,r;while((r=n.exec(t))!==null){let[,a,i,s,o]=r,c=i??s??o??!0;e[a]=c}return e}function y(t,e,n=[]){if(e(t,n),t.children)t.children.forEach((r,a)=>{y(r,e,[...n,`${a}`])})}function h(t,e){switch(t.type){case"text":return x(t.text||"",e);case"element":case"component":{let n=t.tag||"div",r=N(t.props||{},e),a=(t.children||[]).map((i)=>h(i,e)).join("");if(!t.children||t.children.length===0){if(["input","br","hr","img","meta","link"].includes(n))return`<${n}${r} />`}return`<${n}${r}>${a}</${n}>`}case"fragment":return(t.children||[]).map((n)=>h(n,e)).join("");case"slot":return`<!--slot:${t.slotName||"default"}-->`;default:return""}}function b(t){if(t.type==="text")return t.text||"";let e=t.tag||"div",n=N(t.props||{},{});return`<${e}${n}></${e}>`}function N(t,e){let n=[];for(let[r,a]of Object.entries(t))if(a===!0)n.push(` ${r}`);else if(a!==!1&&a!==null&&a!==void 0){let i=x(String(a),e);n.push(` ${r}="${k(i)}"`)}return n.join("")}async function H(t,e){return h(t,e)}function P(t,e){let n=[];return y(t.tree,(r)=>{if(r.isStatic)n.push(h(r,e))}),n.join("")}function j(t,e,n){let r={templateId:e.id,context:n,dynamicParts:Array.from(e.dynamicParts.entries())},a=`
|
|
7
7
|
<script data-craft-hydration>
|
|
8
8
|
window.__CRAFT_HYDRATION__ = ${JSON.stringify(r)};
|
|
9
|
-
</script>`;return{html:t+a,data:r}}function O(t){let e=!1,n=!1,r=!1,a=!1,i=0,s=0;function o(c,p){if(s=Math.max(s,p),c.type==="slot")e=!0;if(c.type==="component")i++;if(!c.isStatic)n=!0;if(c.props)for(let l of Object.keys(c.props)){if(l.startsWith("on"))r=!0;if(l==="@async"||l==="data-async")a=!0}if(c.children)c.children.forEach((l)=>o(l,p+1))}return o(t,0),{hasSlots:e,hasDynamicContent:n,hasEventHandlers:r,hasAsyncContent:a,componentCount:i,maxDepth:s,estimatedSize:JSON.stringify(t).length}}function A(t){let e=new Map,n=new Map;return y(t,(r,a)=>{let i=a.join(".");if(r.isStatic)e.set(i,b(r));else n.set(i,r.tag||r.componentName||"dynamic")}),{staticParts:e,dynamicParts:n}}function L(t){let e=[],n=/<script[^>]*>([\s\S]*?)<\/script>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function W(t){let e=[],n=/<style[^>]*>([\s\S]*?)<\/style>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function _(t){let e=[],n=/@include\s*\(\s*['"]([^'"]+)['"]/g,r;while((r=n.exec(t))!==null)e.push(r[1]);let a=/@component\s*\(\s*['"]([^'"]+)['"]/g;while((r=a.exec(t))!==null)e.push(r[1]);let i=/<@craft-[\w-]+/g;while((r=i.exec(t))!==null)e.push(r[0].slice(2));return[...new Set(e)]}function v(t){return/\{\{.*?\}\}|\{\!\!.*?\!\!\}/.test(t)}function x(t,e){let n=t.replace(/\{\{\s*(.+?)\s*\}\}/g,(r,a)=>{try{let i=w(a.trim(),e);return k(String(i??""))}catch{return""}});return n=n.replace(/\{!!\s*(.+?)\s*!!\}/g,(r,a)=>{try{let i=w(a.trim(),e);return String(i??"")}catch{return""}}),n}function w(t,e){if(/^[\w.]+$/.test(t)){let n=t.split("."),r=e;for(let a of n)if(r&&typeof r==="object"&&a in r)r=r[a];else return;return r}try{return Function(...Object.keys(e),`return ${t}`)(...Object.values(e))}catch{return}}function k(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function D(t){return t.replace(/\s+/g," ").replace(/>\s+</g,"><").replace(/\s+>/g,">").replace(/<\s+/g,"<").trim()}function E(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return`tpl_${Math.abs(e).toString(36)}`}function I(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return Math.abs(e).toString(36)}var K=0;function F(){return`h_${++K}`}function T(t){return["craft-button","craft-text-input","craft-textarea","craft-checkbox","craft-radio","craft-select","craft-slider","craft-toggle","craft-date-picker","craft-time-picker","craft-color-picker","craft-file-input","craft-modal","craft-alert","craft-toast","craft-progress","craft-spinner","craft-avatar","craft-badge","craft-card","craft-accordion","craft-tabs","craft-tooltip","craft-popover","craft-dropdown","craft-context-menu","craft-data-table","craft-virtual-list","craft-tree-view","craft-map","craft-chart","craft-video","craft-audio","craft-webview","craft-canvas","craft-image-viewer","craft-pdf-viewer","craft-code-editor","craft-rich-editor"].includes(t)}function J(t){let e=t.tag?.toLowerCase(),n=t.props?.type,r={button:{component:"craft-button",confidence:0.95,reason:"Native button provides better touch feedback"},"input:text":{component:"craft-text-input",confidence:0.9,reason:"Native text input has better keyboard handling"},"input:checkbox":{component:"craft-checkbox",confidence:0.95,reason:"Native checkbox follows platform conventions"},"input:range":{component:"craft-slider",confidence:0.9,reason:"Native slider provides smooth interaction"},"input:date":{component:"craft-date-picker",confidence:0.95,reason:"Native date picker provides platform-specific UI"},"input:time":{component:"craft-time-picker",confidence:0.95,reason:"Native time picker provides platform-specific UI"},"input:color":{component:"craft-color-picker",confidence:0.9,reason:"Native color picker provides platform-specific UI"},textarea:{component:"craft-textarea",confidence:0.85,reason:"Native textarea handles multiline input better"},select:{component:"craft-select",confidence:0.9,reason:"Native select provides platform dropdown UI"},progress:{component:"craft-progress",confidence:0.95,reason:"Native progress bar matches platform style"},video:{component:"craft-video",confidence:0.95,reason:"Native video provides hardware acceleration"},audio:{component:"craft-audio",confidence:0.95,reason:"Native audio provides system integration"},dialog:{component:"craft-modal",confidence:0.9,reason:"Native modal provides proper layering and focus"}},a=n?`${e}:${n}`:e,i=r[a||""]||r[e||""];if(i)return{htmlSelector:a||e||"",nativeComponent:i.component,confidence:i.confidence,reason:i.reason};return null}function U(){m.clear()}function q(){d.clear()}function B(){U(),q()}function G(){return{templateCacheSize:m.size,renderCacheSize:d.size,totalEntries:m.size+d.size}}export{
|
|
9
|
+
</script>`;return{html:t+a,data:r}}function O(t){let e=!1,n=!1,r=!1,a=!1,i=0,s=0;function o(c,p){if(s=Math.max(s,p),c.type==="slot")e=!0;if(c.type==="component")i++;if(!c.isStatic)n=!0;if(c.props)for(let l of Object.keys(c.props)){if(l.startsWith("on"))r=!0;if(l==="@async"||l==="data-async")a=!0}if(c.children)c.children.forEach((l)=>o(l,p+1))}return o(t,0),{hasSlots:e,hasDynamicContent:n,hasEventHandlers:r,hasAsyncContent:a,componentCount:i,maxDepth:s,estimatedSize:JSON.stringify(t).length}}function A(t){let e=new Map,n=new Map;return y(t,(r,a)=>{let i=a.join(".");if(r.isStatic)e.set(i,b(r));else n.set(i,r.tag||r.componentName||"dynamic")}),{staticParts:e,dynamicParts:n}}function L(t){let e=[],n=/<script[^>]*>([\s\S]*?)<\/script>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function W(t){let e=[],n=/<style[^>]*>([\s\S]*?)<\/style>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function _(t){let e=[],n=/@include\s*\(\s*['"]([^'"]+)['"]/g,r;while((r=n.exec(t))!==null)e.push(r[1]);let a=/@component\s*\(\s*['"]([^'"]+)['"]/g;while((r=a.exec(t))!==null)e.push(r[1]);let i=/<@craft-[\w-]+/g;while((r=i.exec(t))!==null)e.push(r[0].slice(2));return[...new Set(e)]}function v(t){return/\{\{.*?\}\}|\{\!\!.*?\!\!\}/.test(t)}function x(t,e){let n=t.replace(/\{\{\s*(.+?)\s*\}\}/g,(r,a)=>{try{let i=w(a.trim(),e);return k(String(i??""))}catch{return""}});return n=n.replace(/\{!!\s*(.+?)\s*!!\}/g,(r,a)=>{try{let i=w(a.trim(),e);return String(i??"")}catch{return""}}),n}function w(t,e){if(/^[\w.]+$/.test(t)){let n=t.split("."),r=e;for(let a of n)if(r&&typeof r==="object"&&a in r)r=r[a];else return;return r}try{return Function(...Object.keys(e),`return ${t}`)(...Object.values(e))}catch{return}}function k(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function D(t){return t.replace(/\s+/g," ").replace(/>\s+</g,"><").replace(/\s+>/g,">").replace(/<\s+/g,"<").trim()}function E(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return`tpl_${Math.abs(e).toString(36)}`}function I(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return Math.abs(e).toString(36)}var K=0;function F(){return`h_${++K}`}function T(t){return["craft-button","craft-text-input","craft-textarea","craft-checkbox","craft-radio","craft-select","craft-slider","craft-toggle","craft-date-picker","craft-time-picker","craft-color-picker","craft-file-input","craft-modal","craft-alert","craft-toast","craft-progress","craft-spinner","craft-avatar","craft-badge","craft-card","craft-accordion","craft-tabs","craft-tooltip","craft-popover","craft-dropdown","craft-context-menu","craft-data-table","craft-virtual-list","craft-tree-view","craft-map","craft-chart","craft-video","craft-audio","craft-webview","craft-canvas","craft-image-viewer","craft-pdf-viewer","craft-code-editor","craft-rich-editor"].includes(t)}function J(t){let e=t.tag?.toLowerCase(),n=t.props?.type,r={button:{component:"craft-button",confidence:0.95,reason:"Native button provides better touch feedback"},"input:text":{component:"craft-text-input",confidence:0.9,reason:"Native text input has better keyboard handling"},"input:checkbox":{component:"craft-checkbox",confidence:0.95,reason:"Native checkbox follows platform conventions"},"input:range":{component:"craft-slider",confidence:0.9,reason:"Native slider provides smooth interaction"},"input:date":{component:"craft-date-picker",confidence:0.95,reason:"Native date picker provides platform-specific UI"},"input:time":{component:"craft-time-picker",confidence:0.95,reason:"Native time picker provides platform-specific UI"},"input:color":{component:"craft-color-picker",confidence:0.9,reason:"Native color picker provides platform-specific UI"},textarea:{component:"craft-textarea",confidence:0.85,reason:"Native textarea handles multiline input better"},select:{component:"craft-select",confidence:0.9,reason:"Native select provides platform dropdown UI"},progress:{component:"craft-progress",confidence:0.95,reason:"Native progress bar matches platform style"},video:{component:"craft-video",confidence:0.95,reason:"Native video provides hardware acceleration"},audio:{component:"craft-audio",confidence:0.95,reason:"Native audio provides system integration"},dialog:{component:"craft-modal",confidence:0.9,reason:"Native modal provides proper layering and focus"}},a=n?`${e}:${n}`:e,i=r[a||""]||r[e||""];if(i)return{htmlSelector:a||e||"",nativeComponent:i.component,confidence:i.confidence,reason:i.reason};return null}function U(){m.clear()}function q(){d.clear()}function B(){U(),q()}function G(){return{templateCacheSize:m.size,renderCacheSize:d.size,totalEntries:m.size+d.size}}export{Ad as CRAFT_BRIDGE_SCRIPT,Xr as CRAFT_COMPONENTS,Od as CRAFT_COMPONENT_RUNTIME,Do as CRAFT_COMPONENT_STYLES,Jr as NATIVE_COMPONENTS,No as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,Bo as compileToNative,Fo as createHotReloadServer,Io as generateCraftBridgeScript,V as generateCraftOptimizations,jo as getAvailableFormats,Lo as getAvailableTargets,Md as getCraftComponents,G as getSSRCacheStats,Oo as injectCraftBridge,Pd as isCraftEnvironment,Y as prerenderForCraft,Mo as processCraftComponents,Id as processCraftDirective,Dd as registerCraftComponent,Q as renderSSR};
|
package/dist/craft.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{Jr,Bo,Fo}from"./chunk-620szfcp.js";import"./chunk-7hkc96de.js";import"./chunk-ah9xyss2.js";import"./chunk-yhpyqsbr.js";import"./chunk-zk2xk0wd.js";import"./chunk-vpdx7qr3.js";import"./chunk-faghmmrs.js";import"./chunk-43h8q2cm.js";import"./chunk-ayy9mmrw.js";import"./chunk-be2ba3hj.js";import"./chunk-eww6sdzz.js";import"./chunk-qdyp2zqf.js";import"./chunk-jtbzmbzz.js";import"./chunk-117xss52.js";import{Ad,Io,Pd,Id,Oo,Xr,Do,Od,Mo,Dd,Md,No,Lo,jo}from"./chunk-zz02hwec.js";import"./chunk-j1nqnmcd.js";import"./chunk-cdgwkzms.js";var m=new Map,d=new Map;function R(t,e){let n=e?.id||E(t),r=I(t),a=m.get(n);if(a&&a.hash===r)return a;let i=M(t),s=L(t),o=W(t),c=O(i),{staticParts:p,dynamicParts:l}=A(i),f=_(t),g={id:n,hash:r,tree:i,scripts:s,styles:o,staticParts:p,dynamicParts:l,dependencies:f,metadata:c};return m.set(n,g),g}async function Q(t,e={},n={}){let r=performance.now();if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`,c=d.get(o);if(c&&Date.now()-c.timestamp<(n.cacheTTL||60000))return{html:c.html,styles:t.styles.join(`
|
|
3
3
|
`),scripts:t.scripts.join(`
|
|
4
4
|
`),metadata:{renderTime:0,cacheHit:!0,totalSize:c.html.length,componentCount:t.metadata.componentCount}}}let a;if(n.streaming)a=await H(t.tree,e);else a=h(t.tree,e);let i;if(n.hydrate){let o=j(a,t,e);a=o.html,i=o.data}if(n.minify)a=D(a);if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`;d.set(o,{html:a,timestamp:Date.now()})}let s=performance.now()-r;return{html:a,styles:t.styles.join(`
|
|
5
5
|
`),scripts:t.scripts.join(`
|
|
6
6
|
`),hydrationData:i,metadata:{renderTime:s,cacheHit:!1,totalSize:a.length,componentCount:t.metadata.componentCount}}}function V(t,e){let n=[],r=[],a=[],i=new Map,s=[];return y(t.tree,(o,c)=>{if(o.type==="component"&&o.componentName){if(T(o.componentName))n.push(o.componentName)}if(o.type==="element"&&o.tag){let p=J(o);if(p)s.push(p);if(o.props){for(let[l,f]of Object.entries(o.props))if(l.startsWith("on")&&typeof f==="string"){let g=`handler_${i.size}`;i.set(g,f)}}}if(o.isStatic&&o.type==="element")r.push(b(o));else if(!o.isStatic&&o.type!=="text")a.push(o.tag||o.componentName||"unknown")}),{nativeComponents:n,staticHTML:r,dynamicParts:a,eventHandlers:i,nativeWidgets:s}}function Y(t,e={}){let n=R(t),r=P(n,e),a=new Map,i=[];return y(n.tree,(s)=>{if(s.type==="component"&&s.componentName){if(T(s.componentName)){i.push(s.componentName);let o=`<!--craft:${s.componentName}:${s.hydrationKey||"default"}-->`;a.set(s.hydrationKey||s.componentName,o)}}}),{staticHTML:r,dynamicPlaceholders:a,craftComponents:i}}function M(t){let e={type:"fragment",children:[]},n=e,r=[e],a=t,i=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);while(a.length>0){let s=a.match(/^<(@?[\w-]+)([^>]*)>/);if(s){let[p,l,f]=s,g=z(f),u=l.startsWith("@craft-"),C=u?l:l.toLowerCase(),S={type:u?"component":"element",tag:C,props:g,children:[],componentName:u?C.slice(1):void 0,isStatic:!v(f),hydrationKey:F()};if(n.children=n.children||[],n.children.push(S),!i.has(C)&&!f.endsWith("/"))r.push(S),n=S;a=a.slice(p.length);continue}let o=a.match(/^<\/(@?[\w-]+)>/);if(o){let[p,l]=o,g=l.startsWith("@craft-")?l:l.toLowerCase();while(r.length>1){let u=r.pop();if(n=r[r.length-1],u.tag===g)break}a=a.slice(p.length);continue}let c=a.match(/^[^<]+/);if(c){let p=c[0];if(p.trim()){let l={type:"text",text:p,isStatic:!v(p)};n.children=n.children||[],n.children.push(l)}a=a.slice(p.length);continue}a=a.slice(1)}return e}function z(t){let e={},n=/([\w-:@]+)(?:=(?:"([^"]*)"|'([^']*)'|(\S+)))?/g,r;while((r=n.exec(t))!==null){let[,a,i,s,o]=r,c=i??s??o??!0;e[a]=c}return e}function y(t,e,n=[]){if(e(t,n),t.children)t.children.forEach((r,a)=>{y(r,e,[...n,`${a}`])})}function h(t,e){switch(t.type){case"text":return x(t.text||"",e);case"element":case"component":{let n=t.tag||"div",r=N(t.props||{},e),a=(t.children||[]).map((i)=>h(i,e)).join("");if(!t.children||t.children.length===0){if(["input","br","hr","img","meta","link"].includes(n))return`<${n}${r} />`}return`<${n}${r}>${a}</${n}>`}case"fragment":return(t.children||[]).map((n)=>h(n,e)).join("");case"slot":return`<!--slot:${t.slotName||"default"}-->`;default:return""}}function b(t){if(t.type==="text")return t.text||"";let e=t.tag||"div",n=N(t.props||{},{});return`<${e}${n}></${e}>`}function N(t,e){let n=[];for(let[r,a]of Object.entries(t))if(a===!0)n.push(` ${r}`);else if(a!==!1&&a!==null&&a!==void 0){let i=x(String(a),e);n.push(` ${r}="${k(i)}"`)}return n.join("")}async function H(t,e){return h(t,e)}function P(t,e){let n=[];return y(t.tree,(r)=>{if(r.isStatic)n.push(h(r,e))}),n.join("")}function j(t,e,n){let r={templateId:e.id,context:n,dynamicParts:Array.from(e.dynamicParts.entries())},a=`
|
|
7
7
|
<script data-craft-hydration>
|
|
8
8
|
window.__CRAFT_HYDRATION__ = ${JSON.stringify(r)};
|
|
9
|
-
</script>`;return{html:t+a,data:r}}function O(t){let e=!1,n=!1,r=!1,a=!1,i=0,s=0;function o(c,p){if(s=Math.max(s,p),c.type==="slot")e=!0;if(c.type==="component")i++;if(!c.isStatic)n=!0;if(c.props)for(let l of Object.keys(c.props)){if(l.startsWith("on"))r=!0;if(l==="@async"||l==="data-async")a=!0}if(c.children)c.children.forEach((l)=>o(l,p+1))}return o(t,0),{hasSlots:e,hasDynamicContent:n,hasEventHandlers:r,hasAsyncContent:a,componentCount:i,maxDepth:s,estimatedSize:JSON.stringify(t).length}}function A(t){let e=new Map,n=new Map;return y(t,(r,a)=>{let i=a.join(".");if(r.isStatic)e.set(i,b(r));else n.set(i,r.tag||r.componentName||"dynamic")}),{staticParts:e,dynamicParts:n}}function L(t){let e=[],n=/<script[^>]*>([\s\S]*?)<\/script>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function W(t){let e=[],n=/<style[^>]*>([\s\S]*?)<\/style>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function _(t){let e=[],n=/@include\s*\(\s*['"]([^'"]+)['"]/g,r;while((r=n.exec(t))!==null)e.push(r[1]);let a=/@component\s*\(\s*['"]([^'"]+)['"]/g;while((r=a.exec(t))!==null)e.push(r[1]);let i=/<@craft-[\w-]+/g;while((r=i.exec(t))!==null)e.push(r[0].slice(2));return[...new Set(e)]}function v(t){return/\{\{.*?\}\}|\{\!\!.*?\!\!\}/.test(t)}function x(t,e){let n=t.replace(/\{\{\s*(.+?)\s*\}\}/g,(r,a)=>{try{let i=w(a.trim(),e);return k(String(i??""))}catch{return""}});return n=n.replace(/\{!!\s*(.+?)\s*!!\}/g,(r,a)=>{try{let i=w(a.trim(),e);return String(i??"")}catch{return""}}),n}function w(t,e){if(/^[\w.]+$/.test(t)){let n=t.split("."),r=e;for(let a of n)if(r&&typeof r==="object"&&a in r)r=r[a];else return;return r}try{return Function(...Object.keys(e),`return ${t}`)(...Object.values(e))}catch{return}}function k(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function D(t){return t.replace(/\s+/g," ").replace(/>\s+</g,"><").replace(/\s+>/g,">").replace(/<\s+/g,"<").trim()}function E(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return`tpl_${Math.abs(e).toString(36)}`}function I(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return Math.abs(e).toString(36)}var K=0;function F(){return`h_${++K}`}function T(t){return["craft-button","craft-text-input","craft-textarea","craft-checkbox","craft-radio","craft-select","craft-slider","craft-toggle","craft-date-picker","craft-time-picker","craft-color-picker","craft-file-input","craft-modal","craft-alert","craft-toast","craft-progress","craft-spinner","craft-avatar","craft-badge","craft-card","craft-accordion","craft-tabs","craft-tooltip","craft-popover","craft-dropdown","craft-context-menu","craft-data-table","craft-virtual-list","craft-tree-view","craft-map","craft-chart","craft-video","craft-audio","craft-webview","craft-canvas","craft-image-viewer","craft-pdf-viewer","craft-code-editor","craft-rich-editor"].includes(t)}function J(t){let e=t.tag?.toLowerCase(),n=t.props?.type,r={button:{component:"craft-button",confidence:0.95,reason:"Native button provides better touch feedback"},"input:text":{component:"craft-text-input",confidence:0.9,reason:"Native text input has better keyboard handling"},"input:checkbox":{component:"craft-checkbox",confidence:0.95,reason:"Native checkbox follows platform conventions"},"input:range":{component:"craft-slider",confidence:0.9,reason:"Native slider provides smooth interaction"},"input:date":{component:"craft-date-picker",confidence:0.95,reason:"Native date picker provides platform-specific UI"},"input:time":{component:"craft-time-picker",confidence:0.95,reason:"Native time picker provides platform-specific UI"},"input:color":{component:"craft-color-picker",confidence:0.9,reason:"Native color picker provides platform-specific UI"},textarea:{component:"craft-textarea",confidence:0.85,reason:"Native textarea handles multiline input better"},select:{component:"craft-select",confidence:0.9,reason:"Native select provides platform dropdown UI"},progress:{component:"craft-progress",confidence:0.95,reason:"Native progress bar matches platform style"},video:{component:"craft-video",confidence:0.95,reason:"Native video provides hardware acceleration"},audio:{component:"craft-audio",confidence:0.95,reason:"Native audio provides system integration"},dialog:{component:"craft-modal",confidence:0.9,reason:"Native modal provides proper layering and focus"}},a=n?`${e}:${n}`:e,i=r[a||""]||r[e||""];if(i)return{htmlSelector:a||e||"",nativeComponent:i.component,confidence:i.confidence,reason:i.reason};return null}function U(){m.clear()}function q(){d.clear()}function B(){U(),q()}function G(){return{templateCacheSize:m.size,renderCacheSize:d.size,totalEntries:m.size+d.size}}export{
|
|
9
|
+
</script>`;return{html:t+a,data:r}}function O(t){let e=!1,n=!1,r=!1,a=!1,i=0,s=0;function o(c,p){if(s=Math.max(s,p),c.type==="slot")e=!0;if(c.type==="component")i++;if(!c.isStatic)n=!0;if(c.props)for(let l of Object.keys(c.props)){if(l.startsWith("on"))r=!0;if(l==="@async"||l==="data-async")a=!0}if(c.children)c.children.forEach((l)=>o(l,p+1))}return o(t,0),{hasSlots:e,hasDynamicContent:n,hasEventHandlers:r,hasAsyncContent:a,componentCount:i,maxDepth:s,estimatedSize:JSON.stringify(t).length}}function A(t){let e=new Map,n=new Map;return y(t,(r,a)=>{let i=a.join(".");if(r.isStatic)e.set(i,b(r));else n.set(i,r.tag||r.componentName||"dynamic")}),{staticParts:e,dynamicParts:n}}function L(t){let e=[],n=/<script[^>]*>([\s\S]*?)<\/script>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function W(t){let e=[],n=/<style[^>]*>([\s\S]*?)<\/style>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function _(t){let e=[],n=/@include\s*\(\s*['"]([^'"]+)['"]/g,r;while((r=n.exec(t))!==null)e.push(r[1]);let a=/@component\s*\(\s*['"]([^'"]+)['"]/g;while((r=a.exec(t))!==null)e.push(r[1]);let i=/<@craft-[\w-]+/g;while((r=i.exec(t))!==null)e.push(r[0].slice(2));return[...new Set(e)]}function v(t){return/\{\{.*?\}\}|\{\!\!.*?\!\!\}/.test(t)}function x(t,e){let n=t.replace(/\{\{\s*(.+?)\s*\}\}/g,(r,a)=>{try{let i=w(a.trim(),e);return k(String(i??""))}catch{return""}});return n=n.replace(/\{!!\s*(.+?)\s*!!\}/g,(r,a)=>{try{let i=w(a.trim(),e);return String(i??"")}catch{return""}}),n}function w(t,e){if(/^[\w.]+$/.test(t)){let n=t.split("."),r=e;for(let a of n)if(r&&typeof r==="object"&&a in r)r=r[a];else return;return r}try{return Function(...Object.keys(e),`return ${t}`)(...Object.values(e))}catch{return}}function k(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function D(t){return t.replace(/\s+/g," ").replace(/>\s+</g,"><").replace(/\s+>/g,">").replace(/<\s+/g,"<").trim()}function E(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return`tpl_${Math.abs(e).toString(36)}`}function I(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return Math.abs(e).toString(36)}var K=0;function F(){return`h_${++K}`}function T(t){return["craft-button","craft-text-input","craft-textarea","craft-checkbox","craft-radio","craft-select","craft-slider","craft-toggle","craft-date-picker","craft-time-picker","craft-color-picker","craft-file-input","craft-modal","craft-alert","craft-toast","craft-progress","craft-spinner","craft-avatar","craft-badge","craft-card","craft-accordion","craft-tabs","craft-tooltip","craft-popover","craft-dropdown","craft-context-menu","craft-data-table","craft-virtual-list","craft-tree-view","craft-map","craft-chart","craft-video","craft-audio","craft-webview","craft-canvas","craft-image-viewer","craft-pdf-viewer","craft-code-editor","craft-rich-editor"].includes(t)}function J(t){let e=t.tag?.toLowerCase(),n=t.props?.type,r={button:{component:"craft-button",confidence:0.95,reason:"Native button provides better touch feedback"},"input:text":{component:"craft-text-input",confidence:0.9,reason:"Native text input has better keyboard handling"},"input:checkbox":{component:"craft-checkbox",confidence:0.95,reason:"Native checkbox follows platform conventions"},"input:range":{component:"craft-slider",confidence:0.9,reason:"Native slider provides smooth interaction"},"input:date":{component:"craft-date-picker",confidence:0.95,reason:"Native date picker provides platform-specific UI"},"input:time":{component:"craft-time-picker",confidence:0.95,reason:"Native time picker provides platform-specific UI"},"input:color":{component:"craft-color-picker",confidence:0.9,reason:"Native color picker provides platform-specific UI"},textarea:{component:"craft-textarea",confidence:0.85,reason:"Native textarea handles multiline input better"},select:{component:"craft-select",confidence:0.9,reason:"Native select provides platform dropdown UI"},progress:{component:"craft-progress",confidence:0.95,reason:"Native progress bar matches platform style"},video:{component:"craft-video",confidence:0.95,reason:"Native video provides hardware acceleration"},audio:{component:"craft-audio",confidence:0.95,reason:"Native audio provides system integration"},dialog:{component:"craft-modal",confidence:0.9,reason:"Native modal provides proper layering and focus"}},a=n?`${e}:${n}`:e,i=r[a||""]||r[e||""];if(i)return{htmlSelector:a||e||"",nativeComponent:i.component,confidence:i.confidence,reason:i.reason};return null}function U(){m.clear()}function q(){d.clear()}function B(){U(),q()}function G(){return{templateCacheSize:m.size,renderCacheSize:d.size,totalEntries:m.size+d.size}}export{Ad as CRAFT_BRIDGE_SCRIPT,Xr as CRAFT_COMPONENTS,Od as CRAFT_COMPONENT_RUNTIME,Do as CRAFT_COMPONENT_STYLES,Jr as NATIVE_COMPONENTS,No as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,Bo as compileToNative,Fo as createHotReloadServer,Io as generateCraftBridgeScript,V as generateCraftOptimizations,jo as getAvailableFormats,Lo as getAvailableTargets,Md as getCraftComponents,G as getSSRCacheStats,Oo as injectCraftBridge,Pd as isCraftEnvironment,Y as prerenderForCraft,Mo as processCraftComponents,Id as processCraftDirective,Dd as registerCraftComponent,Q as renderSSR};
|
|
@@ -21,6 +21,16 @@ export declare function compileNativeBundle(options: CompileNativeBundleOptions)
|
|
|
21
21
|
export declare function compileSharedScreenBundle(file: string, options?: Pick<CompileNativeBundleOptions, 'minify' | 'outFile' | 'root'>): Promise<NativeBundleResult>;
|
|
22
22
|
/** One `.stx` file, as the public single-screen native compiler writes it. */
|
|
23
23
|
export declare function compileScreenBundle(file: string, options?: Pick<CompileNativeBundleOptions, 'minify' | 'outFile' | 'root'>): Promise<NativeBundleResult>;
|
|
24
|
+
/**
|
|
25
|
+
* The runtime prelude's name in a `routesDir`: `__runtime.js`, which a host
|
|
26
|
+
* evaluates in each screen's context before that screen's own route file.
|
|
27
|
+
*/
|
|
28
|
+
export declare const NATIVE_RUNTIME_ROUTE: '__runtime';
|
|
29
|
+
/**
|
|
30
|
+
* Where a `routesDir` keeps the messages: `__messages/<language>/<area>.json`,
|
|
31
|
+
* and `__messages/routes.json`, each route's areas.
|
|
32
|
+
*/
|
|
33
|
+
export declare const NATIVE_MESSAGES_DIR: '__messages';
|
|
24
34
|
export declare interface CompileNativeBundleOptions {
|
|
25
35
|
screens: Record<string, string>
|
|
26
36
|
initialScreen?: string
|
|
@@ -31,6 +41,12 @@ export declare interface CompileNativeBundleOptions {
|
|
|
31
41
|
app?: string
|
|
32
42
|
browser?: BrowserScreenOptions & { platformModule: string, platformOptions?: Record<string, unknown> }
|
|
33
43
|
routesDir?: string
|
|
44
|
+
sharedRuntime?: boolean
|
|
45
|
+
messages?: NativeMessagesOptions
|
|
46
|
+
}
|
|
47
|
+
export declare interface NativeMessagesOptions {
|
|
48
|
+
dir: string
|
|
49
|
+
languages: string[]
|
|
34
50
|
}
|
|
35
51
|
/** Something the compiler could not translate exactly: an unknown icon or class. */
|
|
36
52
|
export declare interface NativeDiagnostic {
|
|
@@ -42,6 +58,12 @@ export declare interface NativeBundleResult {
|
|
|
42
58
|
code: string
|
|
43
59
|
outFile?: string
|
|
44
60
|
routes?: Record<string, string>
|
|
61
|
+
runtime?: string
|
|
62
|
+
messages?: {
|
|
63
|
+
dir: string
|
|
64
|
+
languages: string[]
|
|
65
|
+
routes: Record<string, string[]>
|
|
66
|
+
}
|
|
45
67
|
diagnostics: NativeDiagnostic[]
|
|
46
68
|
}
|
|
47
69
|
/** @deprecated Use `CompileNativeBundleOptions`. */
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { existsSync, mkdirSync } from "node:fs";
|
|
1
|
+
import { existsSync, mkdirSync, realpathSync, rmSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { compileScreenFile } from "./render-screen.js";
|
|
4
4
|
import { NATIVE_APP_ROUTE } from "../runtime/shared-screen.js";
|
|
5
5
|
import { generateSignalsRuntime } from "../../signals.js";
|
|
6
|
+
import { withModuleSubstitutes } from "../../client-script-bundler.js";
|
|
7
|
+
export const NATIVE_RUNTIME_ROUTE = "__runtime", NATIVE_MESSAGES_DIR = "__messages";
|
|
6
8
|
function nativeRuntimeModule(name) {
|
|
7
9
|
const resolved = [
|
|
8
10
|
path.join(import.meta.dir, "..", "runtime", `${name}.ts`),
|
|
@@ -13,11 +15,12 @@ function nativeRuntimeModule(name) {
|
|
|
13
15
|
throw Error(`Native runtime module ${name} is missing`);
|
|
14
16
|
return resolved;
|
|
15
17
|
}
|
|
16
|
-
async function build(entry, plugins, minify, dependencies) {
|
|
18
|
+
async function build(entry, plugins, minify, dependencies, substitutes) {
|
|
17
19
|
const track = { name: "stx-screen-inputs", setup(builder) {
|
|
18
20
|
builder.onLoad({ filter: /.*/, namespace: "file" }, ({ path: file }) => {
|
|
19
21
|
dependencies.add(file);
|
|
20
|
-
|
|
22
|
+
const contents = substitutes?.get(file);
|
|
23
|
+
return contents === void 0 ? void 0 : { contents, loader: "js" };
|
|
21
24
|
});
|
|
22
25
|
} }, result = await Bun.build({
|
|
23
26
|
entrypoints: [entry],
|
|
@@ -35,6 +38,58 @@ ${messages}`);
|
|
|
35
38
|
}
|
|
36
39
|
return (await result.outputs[0].text()).trim();
|
|
37
40
|
}
|
|
41
|
+
const MESSAGE_AREA = /^[\w-]+(?:\/[\w-]+)*$/, MESSAGE_LANGUAGE = /^[\w-]+$/;
|
|
42
|
+
async function collectMessages(root, options) {
|
|
43
|
+
const dir = path.resolve(root, options.dir);
|
|
44
|
+
if (!options.languages?.length)
|
|
45
|
+
throw Error("messages.languages must name at least one language");
|
|
46
|
+
const files = new Map, data = new Map;
|
|
47
|
+
for (const language of options.languages) {
|
|
48
|
+
if (!MESSAGE_LANGUAGE.test(language))
|
|
49
|
+
throw Error(`messages: "${language}" is not a language directory name`);
|
|
50
|
+
const base = path.join(dir, language);
|
|
51
|
+
if (!existsSync(base))
|
|
52
|
+
throw Error(`messages: ${path.relative(root, base)} does not exist`);
|
|
53
|
+
const areas = new Map;
|
|
54
|
+
for (const relative of [...new Bun.Glob("**/*.{ts,js,mjs,json}").scanSync({ cwd: base })].sort()) {
|
|
55
|
+
if (/\.(?:test|spec|d)\.[^.]+$/.test(relative))
|
|
56
|
+
continue;
|
|
57
|
+
const area = relative.replace(/\.[^./]+$/, "").split(path.sep).join("/");
|
|
58
|
+
if (!MESSAGE_AREA.test(area))
|
|
59
|
+
throw Error(`messages: ${language}/${relative} is not an area name`);
|
|
60
|
+
if (areas.has(area))
|
|
61
|
+
throw Error(`messages: ${language}/${area} is defined twice`);
|
|
62
|
+
const file = path.join(base, relative), module = await import(file), others = Object.keys(module).filter((name) => name !== "default");
|
|
63
|
+
if (others.length)
|
|
64
|
+
throw Error(`messages: ${language}/${relative} exports ${others.join(", ")}; a message module exports its messages as default, and nothing else`);
|
|
65
|
+
const value = module.default, json = value !== null && typeof value === "object" && !Array.isArray(value) ? JSON.stringify(value) : void 0;
|
|
66
|
+
if (json === void 0 || !Bun.deepEquals(JSON.parse(json), value, !0))
|
|
67
|
+
throw Error(`messages: ${language}/${relative} must export plain data (an object JSON can hold) as default`);
|
|
68
|
+
areas.set(area, json);
|
|
69
|
+
files.set(file, { language, area });
|
|
70
|
+
}
|
|
71
|
+
data.set(language, areas);
|
|
72
|
+
}
|
|
73
|
+
return { files, data };
|
|
74
|
+
}
|
|
75
|
+
function messagesStub(language, area) {
|
|
76
|
+
return `export default globalThis.__stxNativeRuntime.messages(${JSON.stringify(language)}, ${JSON.stringify(area)});`;
|
|
77
|
+
}
|
|
78
|
+
function messageStubs(messages) {
|
|
79
|
+
const stubs = new Map;
|
|
80
|
+
for (const [file, { language, area }] of messages.files) {
|
|
81
|
+
const stub = messagesStub(language, area);
|
|
82
|
+
stubs.set(file, stub);
|
|
83
|
+
stubs.set(realpathSync(file), stub);
|
|
84
|
+
}
|
|
85
|
+
return stubs;
|
|
86
|
+
}
|
|
87
|
+
function areasRead(code) {
|
|
88
|
+
const areas = new Set;
|
|
89
|
+
for (const match of code.matchAll(/__stxNativeRuntime\.messages\(\s*"[\w-]+"\s*,\s*"([\w/-]+)"\s*\)/g))
|
|
90
|
+
areas.add(match[1]);
|
|
91
|
+
return [...areas].sort();
|
|
92
|
+
}
|
|
38
93
|
function runtimeDocument(document) {
|
|
39
94
|
return { ...document, script: { exports: document.script.exports, functions: [], code: "" } };
|
|
40
95
|
}
|
|
@@ -45,13 +100,27 @@ export async function compileNativeBundle(options) {
|
|
|
45
100
|
const routed = options.routed ?? !0, initialScreen = options.initialScreen ?? names[0];
|
|
46
101
|
if (!options.screens[initialScreen])
|
|
47
102
|
throw Error(`Initial screen ${initialScreen} is not in screens`);
|
|
48
|
-
const root = path.resolve(options.root ?? process.cwd())
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
103
|
+
const root = path.resolve(options.root ?? process.cwd());
|
|
104
|
+
if (options.messages && !options.routesDir)
|
|
105
|
+
throw Error("messages ship a language at a time beside route files: they need routesDir");
|
|
106
|
+
if (options.sharedRuntime && !options.routesDir)
|
|
107
|
+
throw Error("sharedRuntime is the route files' runtime: it needs routesDir");
|
|
108
|
+
if (options.messages && !options.sharedRuntime)
|
|
109
|
+
throw Error("messages are read by the shared runtime: they need sharedRuntime");
|
|
110
|
+
if (options.messages && options.outFile)
|
|
111
|
+
throw Error("messages leave the languages out of the screens' code, which the one-file bundle cannot read: build it without messages");
|
|
112
|
+
const messages = options.messages ? await collectMessages(root, options.messages) : null, stubs = messages ? messageStubs(messages) : null, compiledScreens = [], compileScreens = async () => {
|
|
113
|
+
for (const name of names) {
|
|
114
|
+
const file = path.resolve(root, options.screens[name]);
|
|
115
|
+
if (!file.endsWith(".stx"))
|
|
116
|
+
throw Error(`Screen ${name} must name a .stx file`);
|
|
117
|
+
compiledScreens.push({ name, file, compiled: await compileScreenFile(file, { root }) });
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
if (stubs)
|
|
121
|
+
await withModuleSubstitutes(stubs, compileScreens);
|
|
122
|
+
else
|
|
123
|
+
await compileScreens();
|
|
55
124
|
const runtimeGlobals = nativeRuntimeModule("jsc-globals"), sharedScreen = nativeRuntimeModule("shared-screen"), appFile = options.app ? path.resolve(root, options.app) : null;
|
|
56
125
|
if (appFile && !existsSync(appFile))
|
|
57
126
|
throw Error(`The app script ${options.app} does not exist`);
|
|
@@ -60,9 +129,12 @@ export async function compileNativeBundle(options) {
|
|
|
60
129
|
if (appFile && options.screens[NATIVE_APP_ROUTE])
|
|
61
130
|
throw Error(`${NATIVE_APP_ROUTE} is the app script's route, not a screen name`);
|
|
62
131
|
const browser = options.browser;
|
|
132
|
+
if (options.screens[NATIVE_RUNTIME_ROUTE])
|
|
133
|
+
throw Error(`${NATIVE_RUNTIME_ROUTE} is the runtime prelude's file, not a screen name`);
|
|
134
|
+
const signalsRuntime = generateSignalsRuntime();
|
|
63
135
|
if (browser && options.routesDir)
|
|
64
136
|
throw Error("A browser screen is one route; routesDir is for device hosts");
|
|
65
|
-
const entry = (bundled, withApp) => {
|
|
137
|
+
const entry = (bundled, withApp, runtimeVersion) => {
|
|
66
138
|
const route = routed ? `var routeName = g.__stxNativeRoute || ${JSON.stringify(initialScreen)};
|
|
67
139
|
var isApp = ${appFile ? `routeName === ${JSON.stringify(NATIVE_APP_ROUTE)}` : "false"};
|
|
68
140
|
if (!isApp && routeNames.indexOf(routeName) === -1) throw new Error(['Unknown native screen:', routeName].join(' '));
|
|
@@ -82,8 +154,12 @@ ${script.code}
|
|
|
82
154
|
}`).join(`
|
|
83
155
|
`), app = withApp && appFile, browserRuntime = browser ? nativeRuntimeModule("browser-screen") : null, platformModule = browser ? Bun.resolveSync(browser.platformModule, root) : null;
|
|
84
156
|
return `
|
|
85
|
-
|
|
86
|
-
|
|
157
|
+
${runtimeVersion ? `var runtime = globalThis.__stxNativeRuntime;
|
|
158
|
+
if (!runtime || runtime.version !== ${JSON.stringify(runtimeVersion)}) throw new Error('This screen needs the stx native runtime it was built with: evaluate ${NATIVE_RUNTIME_ROUTE}.js from the same build first');
|
|
159
|
+
var installJSCGlobals = runtime.installJSCGlobals;
|
|
160
|
+
var prepareNativeApp = runtime.prepareNativeApp;
|
|
161
|
+
var prepareSharedNativeScreen = runtime.prepareSharedNativeScreen;` : `import { installJSCGlobals } from ${JSON.stringify(runtimeGlobals)};
|
|
162
|
+
import { prepareNativeApp, prepareSharedNativeScreen } from ${JSON.stringify(sharedScreen)};`}
|
|
87
163
|
${browser ? `import { createBrowserScreenBridge } from ${JSON.stringify(browserRuntime)};
|
|
88
164
|
import { createBrowserPlatform } from ${JSON.stringify(platformModule)};` : ""}
|
|
89
165
|
${app ? `import * as nativeAppModule from ${JSON.stringify(appFile)};` : "var nativeAppModule = null;"}
|
|
@@ -112,7 +188,7 @@ else {
|
|
|
112
188
|
g.__stx_host = screen.host;
|
|
113
189
|
g.__stxNativeUnmount = function() { screen.unmount(); };
|
|
114
190
|
}
|
|
115
|
-
${
|
|
191
|
+
${runtimeVersion ? "runtime.startSignals();" : signalsRuntime}
|
|
116
192
|
var pageSetup = g.__stx_latestSetup;
|
|
117
193
|
var pageRuntimeSetup = g.stx && g.stx._latestSetup;
|
|
118
194
|
${setups}
|
|
@@ -143,23 +219,91 @@ g.addEventListener('pagehide', function(event) { if (!event.persisted) g.__stxNa
|
|
|
143
219
|
level: "warning",
|
|
144
220
|
message: [diagnostic.kind, diagnostic.tag, diagnostic.name].filter(Boolean).join(": ")
|
|
145
221
|
})), minify = options.minify ?? !1;
|
|
146
|
-
let routes;
|
|
222
|
+
let routes, runtime, written;
|
|
147
223
|
if (options.routesDir) {
|
|
148
224
|
const dir = path.resolve(root, options.routesDir);
|
|
149
225
|
mkdirSync(dir, { recursive: !0 });
|
|
150
|
-
const
|
|
226
|
+
const prelude = `
|
|
227
|
+
import { installJSCGlobals } from ${JSON.stringify(runtimeGlobals)};
|
|
228
|
+
import { prepareNativeApp, prepareSharedNativeScreen } from ${JSON.stringify(sharedScreen)};
|
|
229
|
+
globalThis.__stxNativeRuntime = {
|
|
230
|
+
version: '__STX_NATIVE_RUNTIME_VERSION__',
|
|
231
|
+
installJSCGlobals: installJSCGlobals,
|
|
232
|
+
prepareNativeApp: prepareNativeApp,
|
|
233
|
+
prepareSharedNativeScreen: prepareSharedNativeScreen,
|
|
234
|
+
// Each screen starts its own signals runtime, after its host is in place.
|
|
235
|
+
startSignals: function() {
|
|
236
|
+
${signalsRuntime}
|
|
237
|
+
},
|
|
238
|
+
// A language's messages for an area (the compile's \`messages\`), read the
|
|
239
|
+
// first time they are looked into: a screen never parses a language it
|
|
240
|
+
// is not shown in, nor an area it does not use.
|
|
241
|
+
messages: function(language, area) {
|
|
242
|
+
var g = globalThis;
|
|
243
|
+
var loaded = g.__stxNativeMessages || (g.__stxNativeMessages = {});
|
|
244
|
+
function table() {
|
|
245
|
+
var forLanguage = loaded[language] || (loaded[language] = {});
|
|
246
|
+
if (Object.prototype.hasOwnProperty.call(forLanguage, area)) return forLanguage[area];
|
|
247
|
+
var value = null;
|
|
248
|
+
if (typeof g.__stxNativeReadMessages === 'function') {
|
|
249
|
+
try {
|
|
250
|
+
var text = g.__stxNativeReadMessages(language, area);
|
|
251
|
+
if (typeof text === 'string') value = JSON.parse(text);
|
|
252
|
+
}
|
|
253
|
+
catch (error) { console.error('[stx native] could not read the ' + language + ' messages for ' + area, error); }
|
|
254
|
+
}
|
|
255
|
+
forLanguage[area] = value;
|
|
256
|
+
return value;
|
|
257
|
+
}
|
|
258
|
+
var own = Object.prototype.hasOwnProperty;
|
|
259
|
+
return new Proxy({}, {
|
|
260
|
+
get: function(target, name) { var messages = table(); return messages && own.call(messages, name) ? messages[name] : undefined; },
|
|
261
|
+
has: function(target, name) { var messages = table(); return !!messages && own.call(messages, name); },
|
|
262
|
+
ownKeys: function() { var messages = table(); return messages ? Object.keys(messages) : []; },
|
|
263
|
+
getOwnPropertyDescriptor: function(target, name) {
|
|
264
|
+
var messages = table();
|
|
265
|
+
return messages && own.call(messages, name) ? { value: messages[name], writable: false, enumerable: true, configurable: true } : undefined;
|
|
266
|
+
},
|
|
267
|
+
});
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
`;
|
|
271
|
+
let runtimeVersion;
|
|
272
|
+
const runtimeFile = path.join(dir, `${NATIVE_RUNTIME_ROUTE}.js`);
|
|
273
|
+
if (options.sharedRuntime) {
|
|
274
|
+
const preludeCode = await build("stx:native-shared-screens", [plugin(prelude)], minify, dependencies);
|
|
275
|
+
runtimeVersion = Bun.hash(preludeCode).toString(36);
|
|
276
|
+
runtime = runtimeFile;
|
|
277
|
+
await Bun.write(runtime, preludeCode.replace("__STX_NATIVE_RUNTIME_VERSION__", runtimeVersion));
|
|
278
|
+
} else
|
|
279
|
+
rmSync(runtimeFile, { force: !0 });
|
|
280
|
+
const messagesDir = path.join(dir, NATIVE_MESSAGES_DIR);
|
|
281
|
+
rmSync(messagesDir, { recursive: !0, force: !0 });
|
|
282
|
+
const routeAreas = {}, targets = [
|
|
151
283
|
...compiledScreens.map((screen) => ({ name: screen.name, screens: [screen], app: !1 })),
|
|
152
284
|
...appFile ? [{ name: NATIVE_APP_ROUTE, screens: [], app: !0 }] : []
|
|
153
285
|
];
|
|
154
286
|
routes = {};
|
|
155
287
|
for (let next = 0;next < targets.length; next += 6)
|
|
156
288
|
await Promise.all(targets.slice(next, next + 6).map(async (target) => {
|
|
157
|
-
const file = path.join(dir, `${target.name}.js`);
|
|
158
|
-
await Bun.write(file,
|
|
289
|
+
const file = path.join(dir, `${target.name}.js`), code = await build("stx:native-shared-screens", [plugin(entry(target.screens, target.app, runtimeVersion))], minify, dependencies, stubs ?? void 0);
|
|
290
|
+
await Bun.write(file, code);
|
|
159
291
|
routes[target.name] = file;
|
|
292
|
+
if (messages)
|
|
293
|
+
routeAreas[target.name] = areasRead(code);
|
|
160
294
|
}));
|
|
295
|
+
if (messages) {
|
|
296
|
+
for (const [language, areas] of messages.data)
|
|
297
|
+
for (const [area, json] of areas)
|
|
298
|
+
await Bun.write(path.join(messagesDir, language, `${area}.json`), json);
|
|
299
|
+
const sorted = Object.fromEntries(Object.keys(routeAreas).sort().map((name) => [name, routeAreas[name]]));
|
|
300
|
+
await Bun.write(path.join(messagesDir, "routes.json"), JSON.stringify(sorted));
|
|
301
|
+
for (const file of messages.files.keys())
|
|
302
|
+
dependencies.add(file);
|
|
303
|
+
written = { dir: messagesDir, languages: [...messages.data.keys()], routes: sorted };
|
|
304
|
+
}
|
|
161
305
|
if (!options.outFile)
|
|
162
|
-
return { code: "", routes, diagnostics, dependencies: [...dependencies] };
|
|
306
|
+
return { code: "", routes, runtime, ...written ? { messages: written } : {}, diagnostics, dependencies: [...dependencies] };
|
|
163
307
|
}
|
|
164
308
|
const code = await build("stx:native-shared-screens", [plugin(entry(compiledScreens, !0))], minify, dependencies);
|
|
165
309
|
if (!options.outFile)
|
|
@@ -167,7 +311,7 @@ g.addEventListener('pagehide', function(event) { if (!event.persisted) g.__stxNa
|
|
|
167
311
|
const outFile = path.resolve(root, options.outFile);
|
|
168
312
|
mkdirSync(path.dirname(outFile), { recursive: !0 });
|
|
169
313
|
await Bun.write(outFile, code);
|
|
170
|
-
return { code, outFile, ...routes ? { routes } : {}, diagnostics, dependencies: [...dependencies] };
|
|
314
|
+
return { code, outFile, ...routes ? { routes, runtime } : {}, ...written ? { messages: written } : {}, diagnostics, dependencies: [...dependencies] };
|
|
171
315
|
}
|
|
172
316
|
export async function compileSharedScreenBundle(file, options = {}) {
|
|
173
317
|
return compileNativeBundle({ ...options, screens: { main: file }, routed: !1 });
|
package/dist/pwa.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
3
|
-
Icon generation requires the sharp package for image processing.`),e.success=!1,e}let g=await c.default(o).metadata();if(g.width&&g.width<512)e.warnings.push(`Source icon is ${g.width}x${g.height}. Recommend using at least 512x512 for best quality.`);for(let i of s){let d=u.join(a,`icon-${i}x${i}.png`);if(await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d),l){let x=u.join(a,`icon-${i}x${i}.webp`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).webp({quality:90}).toFile(x),e.generatedFiles.push(x)}}if(p){for(let d of S){let x=u.join(a,`apple-touch-icon-${d}x${d}.png`);await c.default(o).resize(d,d,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(x),e.generatedFiles.push(x)}let i=u.join(a,"apple-touch-icon.png");await c.default(o).resize(180,180,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(i),e.generatedFiles.push(i)}for(let i of P){let d=u.join(a,`favicon-${i}x${i}.png`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d)}let f=512,y=u.join(a,`icon-maskable-${f}x${f}.png`),m=Math.floor(f*0.1),k=f-m*2;await c.default(o).resize(k,k,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).extend({top:m,bottom:m,left:m,right:m,background:{r:255,g:255,b:255,alpha:1}}).png().toFile(y),e.generatedFiles.push(y)}catch(c){let h=c instanceof Error?c.message:String(c);e.errors.push(`Icon generation failed: ${h}`),e.success=!1}return e}function N(n){let t=n.sizes||v,e=n.outputDir?`/${n.outputDir}`:"/pwa-icons",r=n.generateWebP??!0,o=n.generateAppleIcons??!0,a=[];for(let s of t)if(a.push(`${e}/icon-${s}x${s}.png`),r)a.push(`${e}/icon-${s}x${s}.webp`);if(o){a.push(`${e}/apple-touch-icon.png`);for(let s of S)a.push(`${e}/apple-touch-icon-${s}x${s}.png`)}for(let s of P)a.push(`${e}/favicon-${s}x${s}.png`);return a.push(`${e}/icon-maskable-512x512.png`),a}async function I(){try{return await import("sharp"),!0}catch{return!1}}function A(n,t,e,r){let o=[],a=r.join(" ");for(let s of n)if(o.push({src:`${t}/icon-${s}x${s}.png`,sizes:`${s}x${s}`,type:"image/png",purpose:a}),e)o.push({src:`${t}/icon-${s}x${s}.webp`,sizes:`${s}x${s}`,type:"image/webp",purpose:a});return o}function C(n){return n.map((t)=>({name:t.name,short_name:t.shortName,description:t.description,url:t.url,icons:t.icons?.map((e)=>({src:e.src,sizes:e.sizes,type:e.type}))}))}function T(n){let t=n.pwa?.shareTarget;if(!t?.enabled)return;let e={action:t.action||"/share",method:t.method||"POST",enctype:t.enctype||"multipart/form-data",params:{title:t.params?.title||"title",text:t.params?.text||"text",url:t.params?.url||"url"}};if(t.acceptFiles&&t.acceptFiles.length>0)e.params.files=t.acceptFiles.map((r)=>({name:r.name,accept:r.accept}));return e}function H(n){let t=n.pwa?.fileHandlers;if(!t?.enabled||!t.accept)return;let e=[{action:t.action||"/",accept:t.accept,launch_type:t.launchType||"single-client"}];if(t.icons)e[0].icons=t.icons.map((r)=>({src:r.src,sizes:r.sizes,type:r.type}));return e}function W(n){let t=n.pwa?.protocolHandlers;if(!t||t.length===0)return;return t.map((e)=>({protocol:e.protocol,url:e.url}))}function j(n){let t=n.pwa;if(!t?.enabled||!t.manifest)return null;let{manifest:e,icons:r}=t,o=r?.sizes||[72,96,128,144,152,192,384,512],a=r?.outputDir?`/${r.outputDir}`:"/pwa-icons",s=r?.generateWebP??!0,l=r?.purpose||["any","maskable"],p={name:e.name,short_name:e.shortName||e.name,description:e.description,start_url:e.startUrl||"/",display:e.display||"standalone",display_override:e.displayOverride,orientation:e.orientation,theme_color:e.themeColor,background_color:e.backgroundColor,scope:e.scope||"/",lang:e.lang,dir:e.dir,id:e.id,categories:e.categories,icons:A(o,a,s,l)};if(e.shortcuts&&e.shortcuts.length>0)p.shortcuts=C(e.shortcuts);if(e.screenshots&&e.screenshots.length>0)p.screenshots=e.screenshots.map((f)=>({src:f.src,sizes:f.sizes,type:f.type,label:f.label,form_factor:f.platform}));let c=T(n);if(c)p.share_target=c;let h=H(n);if(h)p.file_handlers=h;let g=W(n);if(g)p.protocol_handlers=g;if(e.launchHandler)p.launch_handler={client_mode:e.launchHandler};if(e.handleLinks)p.handle_links=e.handleLinks;if(e.edgeSidePanel?.enabled)p.edge_side_panel={preferred_width:e.edgeSidePanel.preferredWidth};return p}function _(n){let t=j(n);if(!t)return"";let e=JSON.parse(JSON.stringify(t));return JSON.stringify(e,null,2)}function q(n,t){return{...t,...n,shortcuts:n.shortcuts||t.shortcuts,screenshots:n.screenshots||t.screenshots,categories:n.categories||t.categories}}function D(n){let t=[],e=n.pwa;if(!e?.enabled)return t;let r=e.manifest;if(!r)return t.push("PWA manifest configuration is missing"),t;if(!r.name)t.push("Manifest name is required");let o=["fullscreen","standalone","minimal-ui","browser"];if(r.display&&!o.includes(r.display))t.push(`Invalid display mode: ${r.display}. Must be one of: ${o.join(", ")}`);let a=["any","natural","landscape","landscape-primary","landscape-secondary","portrait","portrait-primary","portrait-secondary"];if(r.orientation&&!a.includes(r.orientation))t.push(`Invalid orientation: ${r.orientation}`);let s=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;if(r.themeColor&&!s.test(r.themeColor))t.push(`Invalid theme color: ${r.themeColor}. Must be a valid hex color.`);if(r.backgroundColor&&!s.test(r.backgroundColor))t.push(`Invalid background color: ${r.backgroundColor}. Must be a valid hex color.`);if(e.shareTarget?.enabled){if(!e.shareTarget.action)t.push("Share target action URL is required")}if(e.fileHandlers?.enabled){if(!e.fileHandlers.accept||Object.keys(e.fileHandlers.accept).length===0)t.push("File handlers must specify accepted MIME types")}if(e.protocolHandlers)for(let l of e.protocolHandlers){if(!l.protocol)t.push("Protocol handler missing protocol");if(!l.url||!l.url.includes("%s"))t.push(`Protocol handler URL must contain %s placeholder: ${l.protocol}`)}return t}import z from"path";async function F(n){let t=n.pwa?.offline;if(!t?.enabled)return"";if(t.page){let e=z.isAbsolute(t.page)?t.page:z.resolve(process.cwd(),t.page);if(await Bun.file(e).exists())try{let{processDirectives:r}=await import("./chunk-
|
|
2
|
+
import{Vn,je,Xo,nc}from"./chunk-yk3fbzx5.js";import{Un,Yr,Qa,ec,tc}from"./chunk-t4g2fptt.js";import{qo,Go,Ko,Ya,Za}from"./chunk-c0h2eqe0.js";import{ae,yt,Zr}from"./chunk-jpqkm8tm.js";import{sl,ol,il,al,xr,Tu}from"./chunk-hzfhn2vr.js";import B from"fs";import w from"path";import O from"fs";import u from"path";var v=[72,96,128,144,152,192,384,512],S=[120,152,167,180],P=[16,32];async function M(n,t){let e={success:!0,generatedFiles:[],errors:[],warnings:[]},r=n.pwa?.icons;if(!r?.src)return e.errors.push("No source icon specified in pwa.icons.src"),e.success=!1,e;let o=u.isAbsolute(r.src)?r.src:u.resolve(process.cwd(),r.src);if(!await Bun.file(o).exists())return e.errors.push(`Source icon not found: ${o}`),e.success=!1,e;let a=u.resolve(t,r.outputDir||"pwa-icons");try{O.mkdirSync(a,{recursive:!0})}catch{return e.errors.push(`Failed to create output directory: ${a}`),e.success=!1,e}let s=r.sizes||v,l=r.generateWebP??!0,p=r.generateAppleIcons??!0;try{let c;try{c=await import("sharp")}catch{return e.errors.push(`sharp is not installed. Install it with: bun add sharp
|
|
3
|
+
Icon generation requires the sharp package for image processing.`),e.success=!1,e}let g=await c.default(o).metadata();if(g.width&&g.width<512)e.warnings.push(`Source icon is ${g.width}x${g.height}. Recommend using at least 512x512 for best quality.`);for(let i of s){let d=u.join(a,`icon-${i}x${i}.png`);if(await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d),l){let x=u.join(a,`icon-${i}x${i}.webp`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).webp({quality:90}).toFile(x),e.generatedFiles.push(x)}}if(p){for(let d of S){let x=u.join(a,`apple-touch-icon-${d}x${d}.png`);await c.default(o).resize(d,d,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(x),e.generatedFiles.push(x)}let i=u.join(a,"apple-touch-icon.png");await c.default(o).resize(180,180,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(i),e.generatedFiles.push(i)}for(let i of P){let d=u.join(a,`favicon-${i}x${i}.png`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d)}let f=512,y=u.join(a,`icon-maskable-${f}x${f}.png`),m=Math.floor(f*0.1),k=f-m*2;await c.default(o).resize(k,k,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).extend({top:m,bottom:m,left:m,right:m,background:{r:255,g:255,b:255,alpha:1}}).png().toFile(y),e.generatedFiles.push(y)}catch(c){let h=c instanceof Error?c.message:String(c);e.errors.push(`Icon generation failed: ${h}`),e.success=!1}return e}function N(n){let t=n.sizes||v,e=n.outputDir?`/${n.outputDir}`:"/pwa-icons",r=n.generateWebP??!0,o=n.generateAppleIcons??!0,a=[];for(let s of t)if(a.push(`${e}/icon-${s}x${s}.png`),r)a.push(`${e}/icon-${s}x${s}.webp`);if(o){a.push(`${e}/apple-touch-icon.png`);for(let s of S)a.push(`${e}/apple-touch-icon-${s}x${s}.png`)}for(let s of P)a.push(`${e}/favicon-${s}x${s}.png`);return a.push(`${e}/icon-maskable-512x512.png`),a}async function I(){try{return await import("sharp"),!0}catch{return!1}}function A(n,t,e,r){let o=[],a=r.join(" ");for(let s of n)if(o.push({src:`${t}/icon-${s}x${s}.png`,sizes:`${s}x${s}`,type:"image/png",purpose:a}),e)o.push({src:`${t}/icon-${s}x${s}.webp`,sizes:`${s}x${s}`,type:"image/webp",purpose:a});return o}function C(n){return n.map((t)=>({name:t.name,short_name:t.shortName,description:t.description,url:t.url,icons:t.icons?.map((e)=>({src:e.src,sizes:e.sizes,type:e.type}))}))}function T(n){let t=n.pwa?.shareTarget;if(!t?.enabled)return;let e={action:t.action||"/share",method:t.method||"POST",enctype:t.enctype||"multipart/form-data",params:{title:t.params?.title||"title",text:t.params?.text||"text",url:t.params?.url||"url"}};if(t.acceptFiles&&t.acceptFiles.length>0)e.params.files=t.acceptFiles.map((r)=>({name:r.name,accept:r.accept}));return e}function H(n){let t=n.pwa?.fileHandlers;if(!t?.enabled||!t.accept)return;let e=[{action:t.action||"/",accept:t.accept,launch_type:t.launchType||"single-client"}];if(t.icons)e[0].icons=t.icons.map((r)=>({src:r.src,sizes:r.sizes,type:r.type}));return e}function W(n){let t=n.pwa?.protocolHandlers;if(!t||t.length===0)return;return t.map((e)=>({protocol:e.protocol,url:e.url}))}function j(n){let t=n.pwa;if(!t?.enabled||!t.manifest)return null;let{manifest:e,icons:r}=t,o=r?.sizes||[72,96,128,144,152,192,384,512],a=r?.outputDir?`/${r.outputDir}`:"/pwa-icons",s=r?.generateWebP??!0,l=r?.purpose||["any","maskable"],p={name:e.name,short_name:e.shortName||e.name,description:e.description,start_url:e.startUrl||"/",display:e.display||"standalone",display_override:e.displayOverride,orientation:e.orientation,theme_color:e.themeColor,background_color:e.backgroundColor,scope:e.scope||"/",lang:e.lang,dir:e.dir,id:e.id,categories:e.categories,icons:A(o,a,s,l)};if(e.shortcuts&&e.shortcuts.length>0)p.shortcuts=C(e.shortcuts);if(e.screenshots&&e.screenshots.length>0)p.screenshots=e.screenshots.map((f)=>({src:f.src,sizes:f.sizes,type:f.type,label:f.label,form_factor:f.platform}));let c=T(n);if(c)p.share_target=c;let h=H(n);if(h)p.file_handlers=h;let g=W(n);if(g)p.protocol_handlers=g;if(e.launchHandler)p.launch_handler={client_mode:e.launchHandler};if(e.handleLinks)p.handle_links=e.handleLinks;if(e.edgeSidePanel?.enabled)p.edge_side_panel={preferred_width:e.edgeSidePanel.preferredWidth};return p}function _(n){let t=j(n);if(!t)return"";let e=JSON.parse(JSON.stringify(t));return JSON.stringify(e,null,2)}function q(n,t){return{...t,...n,shortcuts:n.shortcuts||t.shortcuts,screenshots:n.screenshots||t.screenshots,categories:n.categories||t.categories}}function D(n){let t=[],e=n.pwa;if(!e?.enabled)return t;let r=e.manifest;if(!r)return t.push("PWA manifest configuration is missing"),t;if(!r.name)t.push("Manifest name is required");let o=["fullscreen","standalone","minimal-ui","browser"];if(r.display&&!o.includes(r.display))t.push(`Invalid display mode: ${r.display}. Must be one of: ${o.join(", ")}`);let a=["any","natural","landscape","landscape-primary","landscape-secondary","portrait","portrait-primary","portrait-secondary"];if(r.orientation&&!a.includes(r.orientation))t.push(`Invalid orientation: ${r.orientation}`);let s=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;if(r.themeColor&&!s.test(r.themeColor))t.push(`Invalid theme color: ${r.themeColor}. Must be a valid hex color.`);if(r.backgroundColor&&!s.test(r.backgroundColor))t.push(`Invalid background color: ${r.backgroundColor}. Must be a valid hex color.`);if(e.shareTarget?.enabled){if(!e.shareTarget.action)t.push("Share target action URL is required")}if(e.fileHandlers?.enabled){if(!e.fileHandlers.accept||Object.keys(e.fileHandlers.accept).length===0)t.push("File handlers must specify accepted MIME types")}if(e.protocolHandlers)for(let l of e.protocolHandlers){if(!l.protocol)t.push("Protocol handler missing protocol");if(!l.url||!l.url.includes("%s"))t.push(`Protocol handler URL must contain %s placeholder: ${l.protocol}`)}return t}import z from"path";async function F(n){let t=n.pwa?.offline;if(!t?.enabled)return"";if(t.page){let e=z.isAbsolute(t.page)?t.page:z.resolve(process.cwd(),t.page);if(await Bun.file(e).exists())try{let{processDirectives:r}=await import("./chunk-sy1bk1ry.js"),o=await Bun.file(e).text();return await r(o,{},e,n,new Set)}catch(r){console.warn(`[PWA] Failed to process custom offline page: ${r}`)}else console.warn(`[PWA] Custom offline page not found: ${e}`)}return E(n)}function E(n){let t=n.pwa?.offline,e=n.pwa?.manifest,r=t?.fallbackTitle||"You are offline",o=t?.fallbackMessage||"Please check your internet connection and try again.",a=e?.themeColor||"#4f46e5",s=e?.shortName||e?.name||"App";return`<!DOCTYPE html>
|
|
4
4
|
<html lang="en">
|
|
5
5
|
<head>
|
|
6
6
|
<meta charset="UTF-8">
|
|
@@ -233,4 +233,4 @@ Icon generation requires the sharp package for image processing.`),e.success=!1,
|
|
|
233
233
|
}, 5000);
|
|
234
234
|
</script>
|
|
235
235
|
</body>
|
|
236
|
-
</html>`}function b(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}async function re(n,t){let e={success:!0,files:{icons:[]},errors:[],warnings:[]},r=n.pwa;if(!r?.enabled)return e;try{B.mkdirSync(t,{recursive:!0})}catch{return e.errors.push(`Failed to create output directory: ${t}`),e.success=!1,e}try{let a=_(n);if(a){let s=w.join(t,"manifest.json");await Bun.write(s,a),e.files.manifest=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate manifest.json: ${s}`),e.success=!1}if(r.icons?.src)if(await I()){let s=await M(n,t);if(e.files.icons=s.generatedFiles,e.warnings.push(...s.warnings),!s.success)e.errors.push(...s.errors),e.success=!1}else e.warnings.push("sharp is not installed. Skipping icon generation. Install with: bun add sharp");if(r.offline?.enabled)try{let a=await F(n);if(a){let s=w.join(t,"offline.html");await Bun.write(s,a),e.files.offlinePage=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate offline page: ${s}`),e.success=!1}let o;if(r.precache?.enabled){let a=ae(t,n);o={fileCount:a.fileCount,totalSize:a.totalSize},e.precacheStats=o}try{let a=
|
|
236
|
+
</html>`}function b(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}async function re(n,t){let e={success:!0,files:{icons:[]},errors:[],warnings:[]},r=n.pwa;if(!r?.enabled)return e;try{B.mkdirSync(t,{recursive:!0})}catch{return e.errors.push(`Failed to create output directory: ${t}`),e.success=!1,e}try{let a=_(n);if(a){let s=w.join(t,"manifest.json");await Bun.write(s,a),e.files.manifest=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate manifest.json: ${s}`),e.success=!1}if(r.icons?.src)if(await I()){let s=await M(n,t);if(e.files.icons=s.generatedFiles,e.warnings.push(...s.warnings),!s.success)e.errors.push(...s.errors),e.success=!1}else e.warnings.push("sharp is not installed. Skipping icon generation. Install with: bun add sharp");if(r.offline?.enabled)try{let a=await F(n);if(a){let s=w.join(t,"offline.html");await Bun.write(s,a),e.files.offlinePage=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate offline page: ${s}`),e.success=!1}let o;if(r.precache?.enabled){let a=ae(t,n);o={fileCount:a.fileCount,totalSize:a.totalSize},e.precacheStats=o}try{let a=Vn(n,t);if(a){let s=je(n),l=w.join(t,s);await Bun.write(l,a),e.files.serviceWorker=l}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate service worker: ${s}`),e.success=!1}return e}function se(n,t){return Yr(n,t)}function oe(n){return n.pwa?.enabled===!0}export{S as APPLE_TOUCH_ICON_SIZES,v as DEFAULT_ICON_SIZES,P as FAVICON_SIZES,Go as auditBuildOutput,qo as auditConfig,re as buildPwaAssets,Ko as calculateAuditResult,Za as formatAuditResult,Zr as formatSize,j as generateManifest,_ as generateManifestJson,ec as generateManifestLink,F as generateOfflinePage,ae as generatePrecacheManifest,yt as generatePrecacheManifestJs,M as generatePwaIcons,Un as generatePwaTags,Vn as generateServiceWorker,nc as generateServiceWorkerAuto,Qa as generateSwRegistrationScript,tc as generateThemeColorMeta,N as getExpectedIconPaths,je as getServiceWorkerFileName,Yr as injectPwaTags,oe as isPwaEnabled,I as isSharpAvailable,Xo as isWorkboxEnabled,q as mergeManifestConfig,se as processPwaHtml,xr as pwaDirectives,sl as pwaInstallDirective,il as pwaOfflineDirective,al as pwaPushDirective,ol as pwaUpdateDirective,Tu as registerPwaDirectives,Ya as runPwaAudit,D as validateManifest};
|