@stacksjs/stx 0.2.552 → 0.2.554
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/app-service-worker.d.ts +2 -0
- package/dist/{chunk-5dps9j52.js → chunk-20xnk6jm.js} +1 -1
- package/dist/chunk-2dtvrkpk.js +2 -0
- package/dist/{chunk-arwy6xnb.js → chunk-2jc9e080.js} +1 -1
- package/dist/{chunk-ctxc46xf.js → chunk-3mv77zv3.js} +1 -1
- package/dist/chunk-3x3pn8qw.js +2 -0
- package/dist/{chunk-w8h7nb1d.js → chunk-4wwpxt4z.js} +226 -226
- package/dist/{chunk-1ed2k6tm.js → chunk-58dkqb3y.js} +1 -1
- package/dist/chunk-5c5aqc6z.js +2 -0
- package/dist/{chunk-2q7dwg3m.js → chunk-6bk7q8ef.js} +1 -1
- package/dist/{chunk-drbdamvr.js → chunk-72qdb639.js} +1 -1
- package/dist/{chunk-v3w4kamj.js → chunk-7qjnzhbv.js} +1 -1
- package/dist/{chunk-zbyxr3gp.js → chunk-8mzsz1k6.js} +1 -1
- package/dist/{chunk-4qdn2feh.js → chunk-91za8dqh.js} +1 -1
- package/dist/{chunk-ma06ph1w.js → chunk-9m93hezh.js} +1 -1
- package/dist/{chunk-qm5em90c.js → chunk-9mcnkrjx.js} +1 -1
- package/dist/{chunk-7p0c9hwn.js → chunk-aqpmja5j.js} +1 -1
- package/dist/{chunk-pfs583r2.js → chunk-bn25kybp.js} +1 -1
- package/dist/{chunk-r18sh8h9.js → chunk-bngcrt1x.js} +1 -1
- package/dist/{chunk-4rx8h4pj.js → chunk-bnh24b88.js} +1 -1
- package/dist/{chunk-5qpfrvb3.js → chunk-bqg1d720.js} +1 -1
- package/dist/{chunk-k59carj9.js → chunk-bzvmtger.js} +1 -1
- package/dist/{chunk-7dkjt05z.js → chunk-crcd5phx.js} +1 -1
- package/dist/{chunk-pa16zx05.js → chunk-d3gdmf4n.js} +1 -1
- package/dist/{chunk-swfbwd6n.js → chunk-d44d4n86.js} +5 -5
- package/dist/{chunk-ya0gg9k7.js → chunk-d8221ft9.js} +1 -1
- package/dist/{chunk-aykqn3ys.js → chunk-ddg0x0pp.js} +1 -1
- package/dist/{chunk-w6eg410v.js → chunk-epxyy8mz.js} +1 -1
- package/dist/{chunk-x04bpk0q.js → chunk-f54c3jwk.js} +1 -1
- package/dist/{chunk-tza9kvnx.js → chunk-fm0db2ey.js} +1 -1
- package/dist/{chunk-zd85q44h.js → chunk-fq58g560.js} +1 -1
- package/dist/{chunk-n0hqvqz9.js → chunk-h7kzag56.js} +1 -1
- package/dist/{chunk-t3qv2pgr.js → chunk-h8gs6xfz.js} +1 -1
- package/dist/{chunk-avtdbnwd.js → chunk-jjx4913r.js} +1 -1
- package/dist/{chunk-1r1t5e5d.js → chunk-kqt67yc7.js} +2 -2
- package/dist/{chunk-dm4af8rf.js → chunk-kw7t9eq7.js} +1 -1
- package/dist/{chunk-jddnfn1x.js → chunk-ndmbsbhk.js} +1 -1
- package/dist/{chunk-fbjsx29b.js → chunk-nmeapbn4.js} +1 -1
- package/dist/{chunk-3jmpyfmv.js → chunk-q1xay7e8.js} +2 -2
- package/dist/{chunk-3tyzjytz.js → chunk-qd367k3a.js} +1 -1
- package/dist/{chunk-fe4mge8v.js → chunk-qmew5tzd.js} +1 -1
- package/dist/{chunk-1hdezgrx.js → chunk-qvjyyns1.js} +1 -1
- package/dist/{chunk-mkx2wyg0.js → chunk-s8x5fe91.js} +1 -1
- package/dist/{chunk-dwjxc9xq.js → chunk-ssb2pdn0.js} +1 -1
- package/dist/{chunk-4kbzj481.js → chunk-w6mymv3q.js} +1 -1
- package/dist/{chunk-s1s6002m.js → chunk-wzb6dfd4.js} +1 -1
- package/dist/{chunk-3471jnbx.js → chunk-z0ar2gk7.js} +1 -1
- package/dist/{chunk-8qntnkf1.js → chunk-zjerecmr.js} +1 -1
- package/dist/{chunk-crpbzgjm.js → chunk-zpyzpp5h.js} +2 -2
- package/dist/cli.js +7 -7
- package/dist/component-processing.d.ts +1 -16
- package/dist/component-processing.js +3 -4
- package/dist/component-registry.d.ts +1 -6
- package/dist/component-registry.js +1 -3
- package/dist/component-renderer.js +2 -2
- package/dist/component-resolution.d.ts +16 -0
- package/dist/component-resolution.js +5 -2
- package/dist/craft-entry.js +1 -1
- package/dist/craft.js +1 -1
- package/dist/offline/app-service-worker.d.ts +2 -0
- package/dist/offline/app-service-worker.js +56 -15
- package/dist/pwa.js +1 -1
- package/dist/ssg.js +2 -2
- package/dist/utils.d.ts +3 -1
- package/dist/utils.js +5 -4
- package/package.json +5 -5
- package/dist/chunk-0tw2hcst.js +0 -2
- package/dist/chunk-ngjyts6r.js +0 -2
- package/dist/chunk-rw8ybnjq.js +0 -2
|
@@ -6,22 +6,7 @@
|
|
|
6
6
|
* (kebab-case and PascalCase).
|
|
7
7
|
*/
|
|
8
8
|
import type { StxOptions } from './types';
|
|
9
|
-
|
|
10
|
-
* Convert PascalCase to kebab-case with proper handling of consecutive uppercase letters.
|
|
11
|
-
*
|
|
12
|
-
* Examples:
|
|
13
|
-
* - `UserCard` → `user-card`
|
|
14
|
-
* - `XMLParser` → `xml-parser` (not `x-m-l-parser`)
|
|
15
|
-
* - `HTMLElement` → `html-element`
|
|
16
|
-
* - `MyURLParser` → `my-url-parser`
|
|
17
|
-
* - `IOStream` → `io-stream`
|
|
18
|
-
*
|
|
19
|
-
* The algorithm:
|
|
20
|
-
* 1. Insert hyphen before uppercase letters that follow lowercase letters
|
|
21
|
-
* 2. Insert hyphen before the last uppercase in a sequence of uppercase letters (before lowercase)
|
|
22
|
-
* 3. Convert to lowercase
|
|
23
|
-
*/
|
|
24
|
-
export declare function pascalToKebab(str: string): string;
|
|
9
|
+
export { pascalToKebab } from './component-resolution';
|
|
25
10
|
import { restoreStashedScripts, stashScriptElements } from './html-masking';
|
|
26
11
|
export { restoreStashedScripts, stashScriptElements };
|
|
27
12
|
/**
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { createSafeFunction, isExpressionSafe, safeEvaluateObject } from "./safe-evaluator.js";
|
|
3
3
|
import { renderComponentWithSlot, userComponentFileExists } from "./utils.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
4
|
+
import { pascalToKebab } from "./component-resolution.js";
|
|
5
|
+
export { pascalToKebab } from "./component-resolution.js";
|
|
7
6
|
import { restoreStashedScripts, stashScriptElements } from "./html-masking.js";
|
|
8
7
|
|
|
9
8
|
export { restoreStashedScripts, stashScriptElements };
|
|
@@ -689,7 +688,7 @@ export async function processCustomElements(template, context, filePath, compone
|
|
|
689
688
|
} else
|
|
690
689
|
props[attrName] = decodeAttributeEntities(attrValue);
|
|
691
690
|
}
|
|
692
|
-
const processedContent = await renderComponentWithSlot(componentPath, props, tag.content, componentsDir, context, filePath, options, processedComponents, dependencies);
|
|
691
|
+
const processedContent = await renderComponentWithSlot(componentPath, props, tag.content, componentsDir, context, filePath, options, processedComponents, dependencies, void 0, void 0, tag.tagName);
|
|
693
692
|
result = result.substring(0, tag.startIndex) + processedContent + result.substring(tag.endIndex);
|
|
694
693
|
}
|
|
695
694
|
return result;
|
|
@@ -78,12 +78,7 @@ export interface BuiltinComponentDef {
|
|
|
78
78
|
* @example kebabToPascal("stx-link") // "StxLink"
|
|
79
79
|
*/
|
|
80
80
|
export declare function kebabToPascal(str: string): string;
|
|
81
|
-
|
|
82
|
-
* Convert a PascalCase string to kebab-case.
|
|
83
|
-
*
|
|
84
|
-
* @example pascalToKebab("StxLink") // "stx-link"
|
|
85
|
-
*/
|
|
86
|
-
export declare function pascalToKebab(str: string): string;
|
|
81
|
+
export { pascalToKebab } from './component-resolution';
|
|
87
82
|
/**
|
|
88
83
|
* Central registry for STX components.
|
|
89
84
|
*
|
|
@@ -3,9 +3,7 @@ import { fileExists } from "./utils.js";
|
|
|
3
3
|
export function kebabToPascal(str) {
|
|
4
4
|
return str.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
5
5
|
}
|
|
6
|
-
export
|
|
7
|
-
return str.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
8
|
-
}
|
|
6
|
+
export { pascalToKebab } from "./component-resolution.js";
|
|
9
7
|
|
|
10
8
|
export class ComponentRegistry {
|
|
11
9
|
builtins = new Map;
|
|
@@ -471,7 +471,7 @@ async function processCustomElementTags(template, context, filePath, options, de
|
|
|
471
471
|
if (typeof resolvedProps.clientReactive.for === "string")
|
|
472
472
|
for (const name of loopBoundNames(resolvedProps.clientReactive.for))
|
|
473
473
|
loopNames.add(name);
|
|
474
|
-
const builtinDef = registry.getBuiltin(tag.tagName), overriddenByUser = builtinDef ? await userComponentFileExists(
|
|
474
|
+
const builtinDef = registry.getBuiltin(tag.tagName), overriddenByUser = builtinDef ? await userComponentFileExists(tag.tagName, componentsDir, context, filePath, options) : !1;
|
|
475
475
|
if (builtinDef && !overriddenByUser) {
|
|
476
476
|
const renderCtx = {
|
|
477
477
|
context,
|
|
@@ -497,7 +497,7 @@ async function processCustomElementTags(template, context, filePath, options, de
|
|
|
497
497
|
for (const [key, value] of Object.entries(resolvedProps.serverDynamic))
|
|
498
498
|
mergedProps[key] = value;
|
|
499
499
|
const renderMetadata = { declaredProps: new Set };
|
|
500
|
-
let finalContent = await renderComponentWithSlot(componentPath, mergedProps, stashed.restore(tag.content), componentsDir, context, filePath, options, processedComponents, dependencies, [...loopNames], renderMetadata);
|
|
500
|
+
let finalContent = await renderComponentWithSlot(componentPath, mergedProps, stashed.restore(tag.content), componentsDir, context, filePath, options, processedComponents, dependencies, [...loopNames], renderMetadata, tag.tagName);
|
|
501
501
|
finalContent = forwardHostAttrs(finalContent, resolvedProps, renderMetadata.declaredProps);
|
|
502
502
|
if (Object.keys(resolvedProps.events).length > 0) {
|
|
503
503
|
const root = findRenderedComponentRoot(finalContent);
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert PascalCase to kebab-case with proper handling of consecutive uppercase letters.
|
|
3
|
+
*
|
|
4
|
+
* Examples:
|
|
5
|
+
* - `UserCard` → `user-card`
|
|
6
|
+
* - `XMLParser` → `xml-parser` (not `x-m-l-parser`)
|
|
7
|
+
* - `HTMLElement` → `html-element`
|
|
8
|
+
* - `MyURLParser` → `my-url-parser`
|
|
9
|
+
* - `IOStream` → `io-stream`
|
|
10
|
+
*
|
|
11
|
+
* The algorithm:
|
|
12
|
+
* 1. Insert hyphen before uppercase letters that follow lowercase letters
|
|
13
|
+
* 2. Insert hyphen before the last uppercase in a sequence of uppercase letters (before lowercase)
|
|
14
|
+
* 3. Convert to lowercase
|
|
15
|
+
*/
|
|
16
|
+
export declare function pascalToKebab(str: string): string;
|
|
1
17
|
/** Shared package component index; editor checks bypass the renderer's cache. */
|
|
2
18
|
export declare function buildStxIndex(pkgDir: string, cache?: boolean): Map<string, string>;
|
|
3
19
|
/**
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
export function pascalToKebab(str) {
|
|
4
|
+
return str.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").toLowerCase();
|
|
5
|
+
}
|
|
3
6
|
const pkgStxIndexCache = new Map;
|
|
4
7
|
export function buildStxIndex(pkgDir, cache = !0) {
|
|
5
8
|
const cached = pkgStxIndexCache.get(pkgDir);
|
|
@@ -28,7 +31,7 @@ export function buildStxIndex(pkgDir, cache = !0) {
|
|
|
28
31
|
const lower = base.toLowerCase();
|
|
29
32
|
if (!index.has(lower))
|
|
30
33
|
index.set(lower, full);
|
|
31
|
-
const kebab = base
|
|
34
|
+
const kebab = pascalToKebab(base);
|
|
32
35
|
if (!index.has(kebab))
|
|
33
36
|
index.set(kebab, full);
|
|
34
37
|
}
|
|
@@ -69,7 +72,7 @@ export function componentImportCandidates(componentPath, filePath, options = {})
|
|
|
69
72
|
];
|
|
70
73
|
}
|
|
71
74
|
function variants(name) {
|
|
72
|
-
const base = name.endsWith(".stx") ? name.slice(0, -4) : name, pascal = base.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(""), kebab = base
|
|
75
|
+
const base = name.endsWith(".stx") ? name.slice(0, -4) : name, pascal = base.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(""), kebab = pascalToKebab(base);
|
|
73
76
|
return [base, pascal, kebab];
|
|
74
77
|
}
|
|
75
78
|
export function importedComponentPath(name, context) {
|
package/dist/craft-entry.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Wr,Io,Oo}from"./chunk-f1n5napx.js";import"./chunk-a5kaw8sc.js";import"./chunk-ec8k75ep.js";import"./chunk-kvmg6r89.js";import"./chunk-r4199q6x.js";import"./chunk-6v1gwdbv.js";import"./chunk-
|
|
2
|
+
import{Wr,Io,Oo}from"./chunk-f1n5napx.js";import"./chunk-a5kaw8sc.js";import"./chunk-ec8k75ep.js";import"./chunk-kvmg6r89.js";import"./chunk-r4199q6x.js";import"./chunk-6v1gwdbv.js";import"./chunk-4wwpxt4z.js";import"./chunk-j2erwdgt.js";import"./chunk-jmvp99ay.js";import"./chunk-e124cgb6.js";import"./chunk-bngcrt1x.js";import"./chunk-1xgs9gd5.js";import"./chunk-dyreg5df.js";import"./chunk-tqnh98j7.js";import{Cd,Eo,Ed,_d,_o,Vr,To,Td,$o,$d,Rd,Ro,Ao,Po}from"./chunk-8mzsz1k6.js";import"./chunk-q1xay7e8.js";import"./chunk-1b50m7e7.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(`
|
package/dist/craft.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Wr,Io,Oo}from"./chunk-f1n5napx.js";import"./chunk-a5kaw8sc.js";import"./chunk-ec8k75ep.js";import"./chunk-kvmg6r89.js";import"./chunk-r4199q6x.js";import"./chunk-6v1gwdbv.js";import"./chunk-
|
|
2
|
+
import{Wr,Io,Oo}from"./chunk-f1n5napx.js";import"./chunk-a5kaw8sc.js";import"./chunk-ec8k75ep.js";import"./chunk-kvmg6r89.js";import"./chunk-r4199q6x.js";import"./chunk-6v1gwdbv.js";import"./chunk-4wwpxt4z.js";import"./chunk-j2erwdgt.js";import"./chunk-jmvp99ay.js";import"./chunk-e124cgb6.js";import"./chunk-bngcrt1x.js";import"./chunk-1xgs9gd5.js";import"./chunk-dyreg5df.js";import"./chunk-tqnh98j7.js";import{Cd,Eo,Ed,_d,_o,Vr,To,Td,$o,$d,Rd,Ro,Ao,Po}from"./chunk-8mzsz1k6.js";import"./chunk-q1xay7e8.js";import"./chunk-1b50m7e7.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(`
|
|
@@ -72,6 +72,8 @@ export interface OfflineAppConfig {
|
|
|
72
72
|
* Default 1500. A kept copy is answered at once and does not wait at all.
|
|
73
73
|
*/
|
|
74
74
|
networkTimeoutMs?: number;
|
|
75
|
+
/** Deadline for each background precache request and response body, ms. Default 10000. Does not abort foreground reads. */
|
|
76
|
+
precacheTimeoutMs?: number;
|
|
75
77
|
/**
|
|
76
78
|
* Paths (prefixes) answered network first rather than from the kept copy:
|
|
77
79
|
* the kept copy is used only when the network does not answer in
|
|
@@ -146,12 +146,13 @@ export function offlineFallbackScope(fallback, scope) {
|
|
|
146
146
|
}
|
|
147
147
|
export const OFFLINE_REGISTER_SCRIPT = `<script data-stx-offline>${registerScriptSource()}</script>`;
|
|
148
148
|
export function generateOfflineWorker(config, buildId) {
|
|
149
|
-
const settings = {
|
|
149
|
+
const precacheTimeout = Number(config.precacheTimeoutMs), settings = {
|
|
150
150
|
build: String(buildId || "dev"),
|
|
151
151
|
pages: Array.from(new Set((config.pages || []).filter((page) => typeof page === "string" && page.startsWith("/")))),
|
|
152
152
|
staticPages: (config.staticPages || []).filter((page) => typeof page === "string" && ((config.pages || []).includes(page) || (config.routes || []).includes(page))),
|
|
153
153
|
api: config.apiPrefix || "/api/",
|
|
154
154
|
timeout: Math.max(500, Number(config.networkTimeoutMs) || 1500),
|
|
155
|
+
precacheTimeout: Number.isFinite(precacheTimeout) && precacheTimeout > 0 ? Math.min(2147483647, Math.max(1, Math.floor(precacheTimeout))) : 1e4,
|
|
155
156
|
networkFirst: (config.networkFirst || []).filter((path) => typeof path === "string" && path.startsWith("/")),
|
|
156
157
|
updateOnColdStart: config.updateOnColdStart === !0,
|
|
157
158
|
fallback: config.fallback || config.pages && config.pages[0] || null,
|
|
@@ -378,6 +379,39 @@ function withParams(response, params) {
|
|
|
378
379
|
// The stylesheets and scripts a kept page links to. Each page has its own
|
|
379
380
|
// generated CSS, fetched only when the page is shown: a screen kept at
|
|
380
381
|
// install but never opened online came up offline without its styles.
|
|
382
|
+
// Background installation must leave connections available for the page the
|
|
383
|
+
// person opens. Bound the whole response body, not just its response headers.
|
|
384
|
+
var backgroundQueue = [];
|
|
385
|
+
var backgroundActive = 0;
|
|
386
|
+
function startBackground(job) {
|
|
387
|
+
var controller = new AbortController();
|
|
388
|
+
var timer = setTimeout(function () { controller.abort(); }, S.precacheTimeout);
|
|
389
|
+
function finish() {
|
|
390
|
+
clearTimeout(timer);
|
|
391
|
+
backgroundActive--;
|
|
392
|
+
drainBackground();
|
|
393
|
+
}
|
|
394
|
+
Promise.resolve().then(function () { return job.work(controller.signal); }).then(function (value) {
|
|
395
|
+
finish();
|
|
396
|
+
job.resolve(value);
|
|
397
|
+
}, function (error) {
|
|
398
|
+
finish();
|
|
399
|
+
job.reject(error);
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
function drainBackground() {
|
|
403
|
+
while (backgroundActive < 2 && backgroundQueue.length) {
|
|
404
|
+
backgroundActive++;
|
|
405
|
+
startBackground(backgroundQueue.shift());
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
function background(work) {
|
|
409
|
+
return new Promise(function (resolve, reject) {
|
|
410
|
+
backgroundQueue.push({ work: work, resolve: resolve, reject: reject });
|
|
411
|
+
drainBackground();
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
|
|
381
415
|
var keepingAssets = {};
|
|
382
416
|
var ASSET_REF = /<(?:link|script)\\b[^>]*?\\s(?:href|src)="(\\/[^"]+\\.(?:css|js))"/g;
|
|
383
417
|
function assetRefs(html) {
|
|
@@ -394,23 +428,24 @@ function keepAsset(cache, request, response) {
|
|
|
394
428
|
return response.blob().then(function (body) { return cache.put(request, stamped(response, body, null)); });
|
|
395
429
|
}
|
|
396
430
|
|
|
397
|
-
function
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
return
|
|
401
|
-
return Promise.all(urls.map(function (url) {
|
|
431
|
+
function keepAssets(html) {
|
|
432
|
+
var urls = assetRefs(html);
|
|
433
|
+
return caches.open(ASSETS).then(function (cache) {
|
|
434
|
+
return Promise.all(urls.map(function (url) {
|
|
402
435
|
// A page and its fragment link the same files: one fetch each.
|
|
403
436
|
if (!keepingAssets[url]) {
|
|
404
437
|
keepingAssets[url] = cache.match(url).then(function (hit) {
|
|
405
438
|
if (hit) return;
|
|
406
|
-
return
|
|
407
|
-
|
|
439
|
+
return background(function (signal) {
|
|
440
|
+
return fetch(url, { credentials: 'same-origin', signal: signal, priority: 'low' }).then(function (asset) {
|
|
441
|
+
if (asset.status === 200) return keepAsset(cache, url, asset);
|
|
442
|
+
delete keepingAssets[url];
|
|
443
|
+
});
|
|
408
444
|
});
|
|
409
|
-
}).catch(function () {});
|
|
445
|
+
}).catch(function () { delete keepingAssets[url]; });
|
|
410
446
|
}
|
|
411
447
|
return keepingAssets[url];
|
|
412
|
-
|
|
413
|
-
});
|
|
448
|
+
}));
|
|
414
449
|
}).catch(function () {});
|
|
415
450
|
}
|
|
416
451
|
|
|
@@ -421,10 +456,16 @@ function precache() {
|
|
|
421
456
|
return Promise.all(wanted.map(function (page) {
|
|
422
457
|
return Promise.all([false, true].map(function (fragment) {
|
|
423
458
|
var headers = fragment ? { 'X-STX-Router': 'true', 'Accept': 'text/html' } : { 'Accept': 'text/html' };
|
|
424
|
-
return
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
459
|
+
return background(function (signal) {
|
|
460
|
+
return fetch(page.url, { headers: headers, credentials: 'same-origin', signal: signal, priority: 'low' }).then(function (response) {
|
|
461
|
+
if (response.status !== 200 || response.redirected) return null;
|
|
462
|
+
var copy = response.clone();
|
|
463
|
+
return Promise.all([store(cache, [page.key(fragment)], response), copy.text()]).then(function (parts) { return parts[1]; });
|
|
464
|
+
});
|
|
465
|
+
}).then(function (html) {
|
|
466
|
+
// Queue linked assets after releasing the page's slot. Waiting for
|
|
467
|
+
// child jobs inside a bounded parent job would deadlock installation.
|
|
468
|
+
if (html !== null) return keepAssets(html);
|
|
428
469
|
}).catch(function () {});
|
|
429
470
|
}));
|
|
430
471
|
}));
|
package/dist/pwa.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import{Bn,Ne,Ho,Ja}from"./chunk-vpmb8gcc.js";import{jn,qr,Ga,Ka,Xa}from"./chunk-8a4g0mex.js";import{Bo,Fo,zo,Wa,qa}from"./chunk-5fx8m234.js";import{ie,ht,Gr}from"./chunk-97vj2cqz.js";import{Qc,el,tl,nl,hr,vu}from"./chunk-xya3vdqy.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-
|
|
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-fm0db2ey.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">
|
package/dist/ssg.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import"./chunk-azb58ven.js";import"./chunk-a5kaw8sc.js";import"./chunk-ec8k75ep.js";import{nt,rt,st,ot,it,at}from"./chunk-kvmg6r89.js";import"./chunk-r4199q6x.js";import"./chunk-6v1gwdbv.js";import{f,ze,N,K,n,o}from"./chunk-
|
|
2
|
+
import"./chunk-azb58ven.js";import"./chunk-a5kaw8sc.js";import"./chunk-ec8k75ep.js";import{nt,rt,st,ot,it,at}from"./chunk-kvmg6r89.js";import"./chunk-r4199q6x.js";import"./chunk-6v1gwdbv.js";import{f,ze,N,K,n,o}from"./chunk-4wwpxt4z.js";import"./chunk-j2erwdgt.js";import{sr}from"./chunk-jmvp99ay.js";import"./chunk-e124cgb6.js";import"./chunk-bngcrt1x.js";import"./chunk-1xgs9gd5.js";import"./chunk-dyreg5df.js";import"./chunk-fq58g560.js";import{ae,yt,bt}from"./chunk-ssb2pdn0.js";import{No,Lo,jo}from"./chunk-wk85dz07.js";import{mt,Qt,en}from"./chunk-hpeg9erh.js";import"./chunk-1b50m7e7.js";import{a}from"./chunk-4cmqjmqr.js";import x from"fs";import g from"path";import{createHash as Dt}from"crypto";function Rt(t){try{return new Bun.Transpiler({loader:"js",minifyWhitespace:!0}).transformSync(t).replace(/\}(var |let |const |function )/g,"};$1").trim()}catch{return t}}var kt=/<script\s+type="stx\/island"\s+data-stx-island="([^"]+)"([^>]*)>([\s\S]*?)<\/script>/g;function Ct(t){return Bun.hash(t).toString(16)}function ut(t,i={}){if(!t.includes('type="stx/island"'))return{html:t,chunks:[]};let s=new Map,r=t.replace(kt,(e,l,w,y)=>{let h=y.trim();if(!h)return e;if(/\bdata-stx-src=/.test(w))return e;if(i.minify)h=Rt(h);let S=Ct(h);if(!s.has(S))s.set(S,h);let P=i.integrity?` data-stx-integrity="sha384-${Dt("sha384").update(h).digest("base64")}"`:"";return`<script type="stx/island" data-stx-island="${l}" data-stx-src="/_stx/islands/${S}.js"${P}${w}></script>`}),c=Array.from(s,([e,l])=>({hash:e,code:l}));return{html:r,chunks:c}}var Et=new Set(["visible","idle"]);function dt(t){if(!t.includes("data-stx-src="))return t;let i=new Map,s=/data-stx-scope="([^"]+)"[^>]*?stx-hydrate="([^"]+)"/g,r;while((r=s.exec(t))!==null)i.set(r[1],r[2]);let c=new Set,e=/data-stx-island="([^"]+)"[^>]*?data-stx-src="([^"]+)"/g,l;while((l=e.exec(t))!==null)if(Et.has(i.get(l[1])||""))c.add(l[2]);let w=t.lastIndexOf("</head>");if(c.size===0||w===-1)return t;let y=Array.from(c).filter((h)=>!t.includes(`rel="prefetch" href="${h}"`)).map((h)=>`<link rel="prefetch" href="${h}" as="script">`).join("");if(!y)return t;return t.slice(0,w)+y+t.slice(w)}var It=["STX_SITE_URL","SITE_URL","URL","VERCEL_URL","CF_PAGES_URL"];function q(t){let i=t.trim();if(!i)return null;let s=/^https?:\/\//i.test(i)?i:`https://${i}`;try{return new URL(s).origin+new URL(s).pathname.replace(/\/$/,"")}catch{return null}}function Bt(t){for(let i of It){let s=t[i];if(!s)continue;let r=q(s);if(r)return{url:r,source:"env",via:i}}return null}function gt(t){if(!t||typeof t!=="object")return null;let i=t,s=i.site?.url??i.url??i.app?.url;return typeof s==="string"?q(s):null}async function jt(t){let{existsSync:i}=await import("fs"),s=await import("path");for(let r of["site.config.ts","site.config.js",".config/site.config.ts"]){let c=s.resolve(t,r);if(!i(c))continue;try{let e=await import(c),l=gt(e.default??e);if(l)return l}catch{}}return null}async function pt(t={}){let i=t.cwd??process.cwd(),s=t.env??process.env;if(t.explicit){let l=q(t.explicit);if(l)return{url:l,source:"option"}}let r=gt(t.stxConfig);if(r)return{url:r,source:"stx.config",via:"site.url"};let c=await jt(i);if(c)return{url:c,source:"site.config",via:"url"};let e=Bt(s);if(e)return e;return{url:"http://localhost",source:"fallback"}}function ht(){return["No site URL configured \u2014 sitemap.xml and robots.txt will point at http://localhost."," Set one in stx.config.ts (site: { url: 'https://example.com' }), in site.config.ts,"," via --domain, or with SITE_URL in the build environment."].join(`
|
|
3
3
|
`)}class ft{cacheDir;cache=new Map;loaded=!1;salt;constructor(t,i=""){this.cacheDir=t,this.salt=i}async load(){if(this.loaded)return;let t=g.join(this.cacheDir,"build-cache.json");if(await Bun.file(t).exists())try{let i=JSON.parse(await Bun.file(t).text());for(let[s,r]of Object.entries(i))this.cache.set(s,r)}catch{}this.loaded=!0}async save(){await x.promises.mkdir(this.cacheDir,{recursive:!0});let t=g.join(this.cacheDir,"build-cache.json"),i={};for(let[s,r]of this.cache)i[s]=r;await Bun.write(t,JSON.stringify(i))}getHash(t,i){let s=x.statSync(t),r=`${this.salt}|${t}:${s.mtimeMs}`;for(let e of i)if(x.existsSync(e)){let l=x.statSync(e);r+=`:${e}:${l.mtimeMs}`}let c=0;for(let e=0;e<r.length;e++){let l=r.charCodeAt(e);c=(c<<5)-c+l,c=c&c}return Math.abs(c).toString(36)}get(t,i){let s=this.cache.get(t);if(!s)return null;let r=this.getHash(i,s.dependencies??[]);if(s.hash!==r)return this.cache.delete(t),null;return s.html}set(t,i,s,r){let c=this.getHash(i,s);this.cache.set(t,{hash:c,html:r,generatedAt:Date.now(),dependencies:s})}}class wt{cacheDir;constructor(t){this.cacheDir=t}getFilePath(t){let i=t.replace(/[^a-zA-Z0-9]/g,"_")+".json";return g.join(this.cacheDir,"isr",i)}async get(t){let i=this.getFilePath(t);if(!await Bun.file(i).exists())return null;try{return JSON.parse(await Bun.file(i).text())}catch{return null}}async set(t,i){let s=this.getFilePath(t);await x.promises.mkdir(g.dirname(s),{recursive:!0}),await Bun.write(s,JSON.stringify(i))}async invalidate(t){let i=this.getFilePath(t);if(await Bun.file(i).exists())await x.promises.unlink(i)}async invalidatePattern(t){let i=g.join(this.cacheDir,"isr");if(!x.existsSync(i))return;let s=await x.promises.readdir(i);for(let r of s){let c=r.replace(/_/g,"/").replace(".json","");if(t.test(c))await x.promises.unlink(g.join(i,r))}}async needsRevalidation(t){let i=await this.get(t);if(!i)return!0;return Date.now()>i.revalidateAfter}}async function Ft(t){try{let s=(await Bun.file(t).text()).match(/<script\s+server\b[^>]*>([\s\S]*?)<\/script>/i);if(!s)return null;let r=s[1];if(!r.includes("getStaticPaths"))return null;let c=r.match(/(?:export\s+)?(?:async\s+)?function\s+getStaticPaths\s*\([^)]*\)\s*\{([\s\S]*?)\n[\t ]*\}/);if(!c)return null;return await Function(`
|
|
4
4
|
return (async function getStaticPaths() {
|
|
5
5
|
${c[1]}
|
|
@@ -41,7 +41,7 @@ ${t.map((r)=>{let c=new URL(r.loc,i).href,e=` <url>
|
|
|
41
41
|
${s.join(`
|
|
42
42
|
`)}
|
|
43
43
|
</channel>
|
|
44
|
-
</rss>`}async function zt(t={}){let i=Date.now();bt();let s=await o(process.cwd()),r=s.build||{},c=await pt({explicit:t.domain||r.domain,stxConfig:s});if(c.source==="fallback"&&(t.sitemap??r.sitemap??!0))console.warn(ht());let e={router:t.router??s?.router??{},pagesDir:t.pagesDir||r.pagesDir||"pages",outputDir:t.outputDir||r.outputDir||"dist",baseUrl:t.baseUrl||r.baseUrl||"/",domain:c.url,revalidate:t.revalidate??r.revalidate??!1,sitemap:t.sitemap??r.sitemap??!0,sitemapExclude:t.sitemapExclude||r.sitemapExclude||[],robots:t.robots??r.robots??!0,rss:t.rss??r.rss??!1,concurrency:t.concurrency||r.concurrency||10,cache:t.cache??r.cache??!0,cacheDir:t.cacheDir||r.cacheDir||a(process.cwd(),"ssg-cache"),contentLoaders:t.contentLoaders||[],hooks:t.hooks||{},minify:t.minify??r.minify??!0,generate404:t.generate404??r.generate404??!0,publicDir:t.publicDir||r.publicDir||"public",trailingSlash:t.trailingSlash??r.trailingSlash??!1,cleanOutput:t.cleanOutput??r.cleanOutput??!0,cacheSalt:t.cacheSalt??"",partialsDir:t.partialsDir||s?.partialsDir||"",componentsDir:t.componentsDir||s?.componentsDir||"",failOnIncludeError:t.failOnIncludeError??!0,failOnServerScriptError:t.failOnServerScriptError??!0,chunkIslands:t.chunkIslands===!0,prefetchIslands:t.prefetchIslands===!0,integrityIslands:t.integrityIslands===!0},l={totalPages:0,successCount:0,failedCount:0,cachedCount:0,buildTime:0,pages:[],errors:[]},w=new Set,y=0,h={},S={};await e.hooks.onBuildStart?.();try{if(e.cleanOutput&&x.existsSync(e.outputDir))await x.promises.rm(e.outputDir,{recursive:!0});await x.promises.mkdir(e.outputDir,{recursive:!0});let D=e.cacheSalt;if(!D){let{resolveUserCssConfig:u,fingerprintConfig:m}=await import("./chunk-
|
|
44
|
+
</rss>`}async function zt(t={}){let i=Date.now();bt();let s=await o(process.cwd()),r=s.build||{},c=await pt({explicit:t.domain||r.domain,stxConfig:s});if(c.source==="fallback"&&(t.sitemap??r.sitemap??!0))console.warn(ht());let e={router:t.router??s?.router??{},pagesDir:t.pagesDir||r.pagesDir||"pages",outputDir:t.outputDir||r.outputDir||"dist",baseUrl:t.baseUrl||r.baseUrl||"/",domain:c.url,revalidate:t.revalidate??r.revalidate??!1,sitemap:t.sitemap??r.sitemap??!0,sitemapExclude:t.sitemapExclude||r.sitemapExclude||[],robots:t.robots??r.robots??!0,rss:t.rss??r.rss??!1,concurrency:t.concurrency||r.concurrency||10,cache:t.cache??r.cache??!0,cacheDir:t.cacheDir||r.cacheDir||a(process.cwd(),"ssg-cache"),contentLoaders:t.contentLoaders||[],hooks:t.hooks||{},minify:t.minify??r.minify??!0,generate404:t.generate404??r.generate404??!0,publicDir:t.publicDir||r.publicDir||"public",trailingSlash:t.trailingSlash??r.trailingSlash??!1,cleanOutput:t.cleanOutput??r.cleanOutput??!0,cacheSalt:t.cacheSalt??"",partialsDir:t.partialsDir||s?.partialsDir||"",componentsDir:t.componentsDir||s?.componentsDir||"",failOnIncludeError:t.failOnIncludeError??!0,failOnServerScriptError:t.failOnServerScriptError??!0,chunkIslands:t.chunkIslands===!0,prefetchIslands:t.prefetchIslands===!0,integrityIslands:t.integrityIslands===!0},l={totalPages:0,successCount:0,failedCount:0,cachedCount:0,buildTime:0,pages:[],errors:[]},w=new Set,y=0,h={},S={};await e.hooks.onBuildStart?.();try{if(e.cleanOutput&&x.existsSync(e.outputDir))await x.promises.rm(e.outputDir,{recursive:!0});await x.promises.mkdir(e.outputDir,{recursive:!0});let D=e.cacheSalt;if(!D){let{resolveUserCssConfig:u,fingerprintConfig:m}=await import("./chunk-6bk7q8ef.js");try{D=m(await u(process.cwd()))}catch{}}let{prepareImageDelivery:p}=await import("./chunk-2jc9e080.js"),b=await p(e.publicDir,e.outputDir);if(b.count>0)console.log(`Optimized ${b.count} image(s) for responsive delivery`),D=[D,b.fingerprint].filter(Boolean).join(":");let B=new ft(e.cacheDir,D);if(e.cache)await B.load();try{let{generateCss:u}=await import("./chunk-6bk7q8ef.js");await u('<div class="bg-black"></div>')}catch{}nt();let xt=s?.routeMiddleware?.dir||"middleware";await st(process.cwd(),xt);let H=rt();if(H.length>0)console.log(`Loaded ${H.length} middleware: ${H.join(", ")}`);let vt=s?.routeMiddleware?.global||[];jo(s?.layoutsDir,a(process.cwd()));let V=N(".",{pagesDir:e.pagesDir,pagesDirs:s?._layerPageDirs});console.log(`Found ${V.length} routes`);let _=[];for(let u of V){let m=await Ot(u);for(let v of m)_.push({route:u,url:v.url,params:v.params,props:v.props,revalidate:v.revalidate??e.revalidate})}l.totalPages=_.length,console.log(`Generating ${l.totalPages} pages...`);let A=[],X=[];for(let u=0;u<_.length;u+=e.concurrency)X.push(_.slice(u,u+e.concurrency));for(let u of X)await Promise.all(u.map(async(m)=>{let{route:v,url:d,params:L,props:Pt,revalidate:Q}=m;try{await e.hooks.onPageStart?.(d);let j=await Bun.file(v.filePath).text(),F=Jt(j),$t=F?.middleware?Array.isArray(F.middleware)?F.middleware:[F.middleware]:[],tt=[...vt,...$t];if(tt.length>0){let C=ot(d,L,F||{}),O=it(C,null,void 0,{isServer:!0}),E=await at(tt,O);if(E.redirect){let R=typeof E.redirect==="string"?E.redirect:E.redirect.path||E.redirect,U=Vt(String(R),d),T=Kt(d,e);await x.promises.mkdir(g.dirname(T),{recursive:!0}),await Bun.write(T,U),l.successCount++,l.pages.push({route:d,outputPath:T,size:Buffer.byteLength(U),cached:!1}),A.push({loc:d,lastmod:new Date().toISOString()}),console.log(` \u21B3 ${d} \u2192 redirect to ${R}`);return}if(E.abort){let R=typeof E.abort==="string"?E.abort:E.abort?.error?.message||"aborted";console.warn(` \u21B3 ${d} \u2014 middleware aborted: ${R}`);return}}let et=j.match(/definePageMeta\s*\(\s*\{[\s\S]*?validate\s*:\s*((?:\([^)]*\)|[^,}])*(?:\{[\s\S]*?\})?)/m);if(et)try{if(!await Function("route",`
|
|
45
45
|
const validate = ${et[1]};
|
|
46
46
|
return validate(route);
|
|
47
47
|
`)({params:L})){console.warn(`Validation failed for ${d}, skipping...`);return}}catch{}let k=null,ct=!1;if(e.cache){if(k=B.get(d,v.filePath),k)ct=!0,l.cachedCount++}if(!k){let C=await St(v,L,Pt,e,s);if(k=C.html,e.failOnIncludeError&&C.includeFailures.length>0)throw Error(`${C.includeFailures.length} include(s) failed to resolve, so this page would have shipped with an error banner where the markup should be:
|
package/dist/utils.d.ts
CHANGED
|
@@ -85,7 +85,9 @@ export declare function renderComponentWithSlot(componentPath: string, props: Re
|
|
|
85
85
|
*/
|
|
86
86
|
clientLoopNames?: readonly string[], renderMetadata?: {
|
|
87
87
|
declaredProps: Set<string>;
|
|
88
|
-
}
|
|
88
|
+
},
|
|
89
|
+
/** Original tag spelling for case-sensitive file lookup; identity stays canonical. */
|
|
90
|
+
lookupName?: string): Promise<string>;
|
|
89
91
|
/**
|
|
90
92
|
* Check if a file exists
|
|
91
93
|
*/
|
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { pascalToKebab } from "./component-resolution.js";
|
|
1
2
|
import fs from "node:fs";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { extractAndStripCssImports, extractBridgeData, injectBrowserCoreAutoImports, processClientScript, renderVendorStyleTags } from "./client-script.js";
|
|
@@ -464,7 +465,7 @@ export function scopeOnRootElement(html, attrs) {
|
|
|
464
465
|
return html.slice(0, insertAt) + attrs + html.slice(insertAt);
|
|
465
466
|
}
|
|
466
467
|
export async function userComponentFileExists(componentPath, componentsDir, parentContext, parentFilePath, options) {
|
|
467
|
-
const baseName = componentPath.endsWith(".stx") ? componentPath.slice(0, -4) : componentPath, kebabToPascal = (str) => str.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(""),
|
|
468
|
+
const baseName = componentPath.endsWith(".stx") ? componentPath.slice(0, -4) : componentPath, kebabToPascal = (str) => str.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(""), importedComponents = parentContext.__importedComponents;
|
|
468
469
|
if (importedComponents) {
|
|
469
470
|
for (const name of [baseName, baseName.toLowerCase(), kebabToPascal(baseName), pascalToKebab(baseName)])
|
|
470
471
|
if (importedComponents.has(name))
|
|
@@ -580,7 +581,7 @@ export function componentClientSignalNames(scripts) {
|
|
|
580
581
|
}
|
|
581
582
|
return [...names];
|
|
582
583
|
}
|
|
583
|
-
export async function renderComponentWithSlot(componentPath, props, slotContent, componentsDir, parentContext, parentFilePath, options, processedComponents = new Set, dependencies, clientLoopNames = inheritedClientLoopNames(parentContext), renderMetadata) {
|
|
584
|
+
export async function renderComponentWithSlot(componentPath, props, slotContent, componentsDir, parentContext, parentFilePath, options, processedComponents = new Set, dependencies, clientLoopNames = inheritedClientLoopNames(parentContext), renderMetadata, lookupName = componentPath) {
|
|
584
585
|
const { extractVariables } = await importOnce("stx/variable-extractor", () => import("./variable-extractor.js")), components = processedComponents ?? new Set;
|
|
585
586
|
if (components.has(componentPath))
|
|
586
587
|
return `[Circular component reference: ${componentPath}]`;
|
|
@@ -591,7 +592,7 @@ export async function renderComponentWithSlot(componentPath, props, slotContent,
|
|
|
591
592
|
delete props.client;
|
|
592
593
|
const hydrateTrigger = clientAttr && clientAttr !== "load" && isHydrateTrigger(clientAttr) ? clientAttr : "";
|
|
593
594
|
try {
|
|
594
|
-
const kebabToPascal = (str) => str.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(""),
|
|
595
|
+
const kebabToPascal = (str) => str.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(""), baseName = lookupName.endsWith(".stx") ? lookupName.slice(0, -4) : lookupName;
|
|
595
596
|
let componentFilePath = null;
|
|
596
597
|
const importedComponents = parentContext.__importedComponents;
|
|
597
598
|
if (importedComponents) {
|
|
@@ -794,7 +795,7 @@ export async function renderComponentWithSlot(componentPath, props, slotContent,
|
|
|
794
795
|
const scopeSeq = parentContext.__stx_scope_seq ??= {
|
|
795
796
|
n: 0,
|
|
796
797
|
key: Bun.hash(String(parentContext.__filename ?? parentFilePath)).toString(36).slice(0, 6)
|
|
797
|
-
}, componentUid = `stx_${
|
|
798
|
+
}, componentUid = `stx_${(componentPath.endsWith(".stx") ? componentPath.slice(0, -4) : componentPath).replace(/[^a-zA-Z0-9]/g, "_")}_${++scopeSeq.n}_${scopeSeq.key}`, componentContext = {
|
|
798
799
|
...filteredParentContext,
|
|
799
800
|
$uid: componentUid,
|
|
800
801
|
...props,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/stx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.554",
|
|
5
5
|
"description": "A performant UI Framework. Powered by Bun.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -123,12 +123,12 @@
|
|
|
123
123
|
"dependencies": {
|
|
124
124
|
"@stacksjs/ts-css": "^0.3.11",
|
|
125
125
|
"@stacksjs/clapp": "^0.2.16",
|
|
126
|
-
"@stacksjs/desktop": "0.2.
|
|
127
|
-
"@stacksjs/sanitizer": "0.2.
|
|
126
|
+
"@stacksjs/desktop": "0.2.554",
|
|
127
|
+
"@stacksjs/sanitizer": "0.2.554",
|
|
128
128
|
"@stacksjs/ts-i18n": "^0.1.11",
|
|
129
|
-
"bun-plugin-stx": "0.2.
|
|
129
|
+
"bun-plugin-stx": "0.2.554",
|
|
130
130
|
"bunfig": "^0.15.19",
|
|
131
|
-
"stx-router": "0.2.
|
|
131
|
+
"stx-router": "0.2.554",
|
|
132
132
|
"ts-broadcasting": "^0.0.11",
|
|
133
133
|
"ts-images": "^0.2.22",
|
|
134
134
|
"ts-syntax-highlighter": "^0.2.1"
|
package/dist/chunk-0tw2hcst.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{Fr,Fl,zl}from"./chunk-x04bpk0q.js";import"./chunk-dwjxc9xq.js";import"./chunk-zd85q44h.js";import"./chunk-azb58ven.js";import"./chunk-w8h7nb1d.js";import"./chunk-1b50m7e7.js";import"./chunk-ec8k75ep.js";import"./chunk-dyreg5df.js";import"./chunk-r18sh8h9.js";import"./chunk-e124cgb6.js";import"./chunk-jmvp99ay.js";import"./chunk-j2erwdgt.js";import"./chunk-a5kaw8sc.js";import"./chunk-6v1gwdbv.js";import"./chunk-r4199q6x.js";import"./chunk-kvmg6r89.js";import"./chunk-1xgs9gd5.js";export{zl as clearComposableCache,Fl as getComposableScript,Fr as listComposableModules};
|
package/dist/chunk-ngjyts6r.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{ad,cd}from"./chunk-dm4af8rf.js";import"./chunk-dwjxc9xq.js";import"./chunk-zd85q44h.js";import"./chunk-azb58ven.js";import"./chunk-w8h7nb1d.js";import"./chunk-1b50m7e7.js";import"./chunk-ec8k75ep.js";import"./chunk-dyreg5df.js";import"./chunk-r18sh8h9.js";import"./chunk-e124cgb6.js";import"./chunk-jmvp99ay.js";import"./chunk-j2erwdgt.js";import"./chunk-a5kaw8sc.js";import"./chunk-6v1gwdbv.js";import"./chunk-r4199q6x.js";import"./chunk-kvmg6r89.js";import"./chunk-1xgs9gd5.js";export{cd as clearStoreCache,ad as getStoreScript};
|
package/dist/chunk-rw8ybnjq.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{Xi,Ji}from"./chunk-swfbwd6n.js";import"./chunk-aykqn3ys.js";import"./chunk-w6eg410v.js";import"./chunk-b9jb44kv.js";import"./chunk-frgpx23w.js";import"./chunk-7dkjt05z.js";import"./chunk-yq1mvakj.js";import"./chunk-4qdn2feh.js";import{co}from"./chunk-crpbzgjm.js";import"./chunk-vvkfde23.js";import"./chunk-ah7h9q0x.js";import"./chunk-mkx2wyg0.js";import"./chunk-75hb7wg6.js";import"./chunk-3nc2fr4q.js";import"./chunk-3tyzjytz.js";import"./chunk-v79qs0qh.js";import"./chunk-8nwzd6eg.js";import"./chunk-gjx5256r.js";import"./chunk-pz8mf91e.js";import"./chunk-77j26p6r.js";import"./chunk-d37enreq.js";import"./chunk-zmq9hwta.js";import"./chunk-x04bpk0q.js";import"./chunk-kch9a9v1.js";import"./chunk-39tkfkp7.js";import"./chunk-7ze47qgv.js";import"./chunk-wy4hfmjs.js";import"./chunk-m6m19hwd.js";import"./chunk-dm4af8rf.js";import"./chunk-0fatkxpr.js";import"./chunk-k59carj9.js";import"./chunk-3jmpyfmv.js";import"./chunk-tqnh98j7.js";import"./chunk-wk85dz07.js";import"./chunk-dwjxc9xq.js";import"./chunk-zd85q44h.js";import"./chunk-azb58ven.js";import{ye,sn,on,K,d,n,Zn,R,o,de}from"./chunk-w8h7nb1d.js";import"./chunk-1b50m7e7.js";import"./chunk-ec8k75ep.js";import"./chunk-dyreg5df.js";import"./chunk-r18sh8h9.js";import"./chunk-e124cgb6.js";import"./chunk-jmvp99ay.js";import"./chunk-j2erwdgt.js";import"./chunk-a5kaw8sc.js";import"./chunk-6v1gwdbv.js";import"./chunk-r4199q6x.js";import"./chunk-kvmg6r89.js";import"./chunk-1xgs9gd5.js";export{Zn as buildWebComponents,on as cacheTemplate,sn as checkCache,co as classifyAllScripts,Xi as createMiddleware,Ji as createRoute,R as defaultConfig,d as extractVariables,K as injectRouterScript,o as loadStxConfig,ye as processClientScript,n as processDirectives,de as readMarkdownFile};
|