@stacksjs/stx 0.2.146 → 0.2.147
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/cli.js +617 -560
- package/dist/client-script.d.ts +5 -0
- package/dist/client-script.js +49 -5
- package/dist/color-mode-boot.d.ts +88 -0
- package/dist/color-mode-boot.js +35 -0
- package/dist/composables/use-color-mode.js +5 -5
- package/dist/composables/use-storage.js +6 -1
- package/dist/craft.js +330 -273
- package/dist/document-shell.d.ts +8 -0
- package/dist/document-shell.js +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/process.js +7 -1
- package/dist/production-builder.js +6 -2
- package/dist/pwa.js +322 -265
- package/dist/script-classifier.d.ts +14 -8
- package/dist/script-classifier.js +33 -14
- package/dist/signals.js +66 -15
- package/dist/ssg.js +299 -242
- package/dist/stx.d.ts +32 -4
- package/dist/types/config-types.d.ts +2 -0
- package/package.json +5 -5
- package/stx.d.ts +32 -4
package/dist/document-shell.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AppHeadConfig } from './types/config-types';
|
|
2
|
+
import type { ColorModeBootConfig } from './color-mode-boot';
|
|
2
3
|
/**
|
|
3
4
|
* Insert the inline x-cloak <style> before </head> if a head exists and the
|
|
4
5
|
* style isn't already present. Idempotent (guards on the data-stx-cloak
|
|
@@ -43,6 +44,13 @@ export declare function generateDocumentShell(content: string, headConfig?: AppH
|
|
|
43
44
|
/** Stacks to inject (from @push directives) */
|
|
44
45
|
headStack?: string
|
|
45
46
|
bodyStack?: string
|
|
47
|
+
/**
|
|
48
|
+
* Pre-paint color-mode config (stacksjs/stx#1794). When present, the boot
|
|
49
|
+
* script is emitted at the very top of <head> — above the stylesheets,
|
|
50
|
+
* because a stylesheet link ahead of it would block its execution and
|
|
51
|
+
* delay the one thing it exists to do early.
|
|
52
|
+
*/
|
|
53
|
+
colorMode?: ColorModeBootConfig
|
|
46
54
|
}): string;
|
|
47
55
|
/**
|
|
48
56
|
* Check if HTML already has a document shell (<!DOCTYPE> or <html>).
|
package/dist/document-shell.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { generateColorModeBootScript } from "./color-mode-boot.js";
|
|
1
2
|
export const CLOAK_STYLE = "<style data-stx-cloak>[x-cloak]{display:none !important}</style>";
|
|
2
3
|
export function injectCloakStyle(html) {
|
|
3
4
|
if (html.includes("data-stx-cloak"))
|
|
@@ -105,6 +106,7 @@ export function generateDocumentShell(content, headConfig = {}, options = {}) {
|
|
|
105
106
|
}).filter(Boolean).join(`
|
|
106
107
|
`), bodyAttrStr = Object.entries(bodyAttrs).map(([k, v]) => ` ${k}="${v}"`).join(""), bodyClassStr = bodyClass ? ` class="${bodyClass}"` : "", { body: pageBody, hoisted: pageHeadTags } = hoistLeadingHeadTags(content), headParts = [
|
|
107
108
|
metaTags,
|
|
109
|
+
options.colorMode ? ` ${generateColorModeBootScript(options.colorMode)}` : "",
|
|
108
110
|
` <title>${pageTitle}</title>`,
|
|
109
111
|
` ${CLOAK_STYLE}`,
|
|
110
112
|
linkTags,
|
package/dist/index.d.ts
CHANGED
|
@@ -68,6 +68,7 @@ export * from './broadcasting';
|
|
|
68
68
|
export * from './caching';
|
|
69
69
|
export * from './components';
|
|
70
70
|
export * from './component-library';
|
|
71
|
+
export * from './color-mode-boot';
|
|
71
72
|
export * from './config';
|
|
72
73
|
// craft-bridge, craft-compiler, craft-components, craft-ssr, native-build
|
|
73
74
|
// moved to stx/craft
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,7 @@ export * from "./broadcasting.js";
|
|
|
27
27
|
export * from "./caching.js";
|
|
28
28
|
export * from "./components.js";
|
|
29
29
|
export * from "./component-library.js";
|
|
30
|
+
export * from "./color-mode-boot.js";
|
|
30
31
|
export * from "./config.js";
|
|
31
32
|
export * from "./csp.js";
|
|
32
33
|
export * from "./custom-directives.js";
|
package/dist/process.js
CHANGED
|
@@ -36,6 +36,7 @@ import { processServerBindings } from "./server-bindings.js";
|
|
|
36
36
|
import { processVueTemplate } from "./vue-template.js";
|
|
37
37
|
import { processDynamicComponents } from "./dynamic-components.js";
|
|
38
38
|
import { dedupeScopedStyles, processScopedStyles } from "./style-scoping.js";
|
|
39
|
+
import { injectColorModeBootScript } from "./color-mode-boot.js";
|
|
39
40
|
import { ensureDocumentShell, hasDocumentShell, injectCloakStyle, injectConfigHeadTags } from "./document-shell.js";
|
|
40
41
|
import { hasSignalsSyntax, convertSignalDirectivesToAttributes, convertSignalLoopsToAttributes, preEvalLiteralReactiveIfs, processSignals } from "./signal-processing.js";
|
|
41
42
|
import { processComponents } from "./component-renderer.js";
|
|
@@ -278,7 +279,9 @@ export async function processDirectives(template, context, filePath, options, de
|
|
|
278
279
|
...runtimeHead.htmlAttrs && { htmlAttrs: { ...baseHeadConfig.htmlAttrs || {}, ...runtimeHead.htmlAttrs } },
|
|
279
280
|
...runtimeHead.bodyAttrs && { bodyAttrs: { ...baseHeadConfig.bodyAttrs || {}, ...runtimeHead.bodyAttrs } }
|
|
280
281
|
}, alreadyShelled = hasDocumentShell(result);
|
|
281
|
-
result = ensureDocumentShell(result, headConfig
|
|
282
|
+
result = ensureDocumentShell(result, headConfig, {
|
|
283
|
+
...options.app?.colorMode && { colorMode: options.app.colorMode }
|
|
284
|
+
});
|
|
282
285
|
if (alreadyShelled)
|
|
283
286
|
result = injectConfigHeadTags(result, baseHeadConfig);
|
|
284
287
|
const layoutComment = result.match(/<!-- stx-layout: ([^ ]+) -->/);
|
|
@@ -297,6 +300,9 @@ export async function processDirectives(template, context, filePath, options, de
|
|
|
297
300
|
}
|
|
298
301
|
if (isTopLevel) {
|
|
299
302
|
result = injectCloakStyle(result);
|
|
303
|
+
const colorModeConfig = options.app?.colorMode;
|
|
304
|
+
if (colorModeConfig)
|
|
305
|
+
result = injectColorModeBootScript(result, colorModeConfig);
|
|
300
306
|
result = placeSignalsRuntimeBeforeScripts(result);
|
|
301
307
|
}
|
|
302
308
|
if (isTopLevel)
|
|
@@ -4,6 +4,7 @@ import { createRouter } from "./router.js";
|
|
|
4
4
|
import { buildRuntimeAsset, buildRouterAsset } from "./build-assets.js";
|
|
5
5
|
import { compileTemplate } from "./template-compiler.js";
|
|
6
6
|
import { generateManifest, writeManifest } from "./manifest.js";
|
|
7
|
+
import { injectColorModeBootScript } from "./color-mode-boot.js";
|
|
7
8
|
import { ensureDocumentShell } from "./document-shell.js";
|
|
8
9
|
import { extractContainerContent } from "./app-shell.js";
|
|
9
10
|
import { injectCrosswindCSS } from "./dev-server/crosswind.js";
|
|
@@ -47,7 +48,7 @@ export async function buildForProduction(options = {}) {
|
|
|
47
48
|
try {
|
|
48
49
|
projectConfig = await loadStxConfig();
|
|
49
50
|
} catch {}
|
|
50
|
-
const componentsDir = options.componentsDir ?? projectConfig.componentsDir ?? "components", partialsDir = options.partialsDir ?? projectConfig.partialsDir ?? "partials", layoutsDir = options.layoutsDir ?? projectConfig.layoutsDir ?? "layouts", publicDir = options.publicDir ?? projectConfig.publicDir ?? "public", headConfigDefault = projectConfig.app?.head || {}, routerContainer = projectConfig.router?.container || "main";
|
|
51
|
+
const componentsDir = options.componentsDir ?? projectConfig.componentsDir ?? "components", partialsDir = options.partialsDir ?? projectConfig.partialsDir ?? "partials", layoutsDir = options.layoutsDir ?? projectConfig.layoutsDir ?? "layouts", publicDir = options.publicDir ?? projectConfig.publicDir ?? "public", headConfigDefault = projectConfig.app?.head || {}, colorModeConfig = projectConfig.app?.colorMode, routerContainer = projectConfig.router?.container || "main";
|
|
51
52
|
if (fs.existsSync(outputDir))
|
|
52
53
|
fs.rmSync(outputDir, { recursive: !0 });
|
|
53
54
|
const dirs = [
|
|
@@ -82,8 +83,11 @@ export async function buildForProduction(options = {}) {
|
|
|
82
83
|
compiledPages.push(compiled);
|
|
83
84
|
compiled.html = compiled.html.replace(/runtime\.__STX_HASH__\.js/g, runtimeAsset.filename).replace(/router\.__STX_HASH__\.js/g, routerAsset.filename);
|
|
84
85
|
compiled.html = ensureDocumentShell(compiled.html, headConfigDefault, {
|
|
85
|
-
bodyScripts: [`<script src="/__stx/${routerAsset.filename}"></script>`]
|
|
86
|
+
bodyScripts: [`<script src="/__stx/${routerAsset.filename}"></script>`],
|
|
87
|
+
...colorModeConfig && { colorMode: colorModeConfig }
|
|
86
88
|
});
|
|
89
|
+
if (colorModeConfig)
|
|
90
|
+
compiled.html = injectColorModeBootScript(compiled.html, colorModeConfig);
|
|
87
91
|
if (!/<body[^>]*\bdata-stx=/.test(compiled.html)) {
|
|
88
92
|
const dataStxMatch = compiled.html.match(/<(?!body\b)[a-zA-Z][a-zA-Z0-9-]*\b[^>]*?\s(data-stx="[^"]+")[^>]*>/);
|
|
89
93
|
if (dataStxMatch && dataStxMatch[1]) {
|