@stacksjs/stx 0.2.188 → 0.2.190
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/browser-composables.d.ts +24 -7
- package/dist/browser-composables.js +58 -17
- package/dist/cli.js +729 -710
- package/dist/component-library.js +21 -4
- package/dist/composable-loader.d.ts +21 -7
- package/dist/composable-loader.js +77 -8
- package/dist/composables/use-cookie.d.ts +8 -3
- package/dist/craft.js +430 -412
- package/dist/dev-server/crosswind.d.ts +26 -0
- package/dist/dev-server/crosswind.js +50 -34
- package/dist/process.js +1 -1
- package/dist/pwa.js +455 -437
- package/dist/signals.js +21 -3
- package/dist/ssg.d.ts +14 -1
- package/dist/ssg.js +462 -444
- package/dist/stx.d.ts +37 -6
- package/dist/typecheck.js +47 -1
- package/dist/utils.js +23 -44
- package/dist/variable-extractor.js +3 -6
- package/package.json +5 -5
- package/stx.d.ts +37 -6
package/dist/stx.d.ts
CHANGED
|
@@ -355,15 +355,46 @@ declare function useFocus(_target: HTMLElement | StxRef<HTMLElement | null> | st
|
|
|
355
355
|
declare function useDebounce<T extends (..._args: any[]) => any>(_fn: T, _delay: number): T
|
|
356
356
|
declare function useDebouncedValue<T>(_value: StxSignal<T>, _delay: number): StxSignal<T>
|
|
357
357
|
declare function useThrottle<T extends (..._args: any[]) => any>(_fn: T, _delay: number): T
|
|
358
|
-
|
|
359
|
-
start
|
|
360
|
-
|
|
361
|
-
|
|
358
|
+
interface StxIntervalOptions {
|
|
359
|
+
/** Tick once on start/resume instead of waiting out the first interval. */
|
|
360
|
+
immediate?: boolean
|
|
361
|
+
/** Gate ticks. `false`, or a function returning false, skips them entirely. */
|
|
362
|
+
enabled?: boolean | (() => boolean)
|
|
363
|
+
/** Skip ticks while `document.hidden`. */
|
|
364
|
+
whileVisible?: boolean
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
interface StxIntervalControls {
|
|
368
|
+
/**
|
|
369
|
+
* Ticks elapsed. A plain number — read it, do not call it. It is not a
|
|
370
|
+
* signal and an `effect` cannot track it; use `subscribe` to react.
|
|
371
|
+
*/
|
|
372
|
+
readonly counter: number
|
|
373
|
+
pause: () => void
|
|
374
|
+
resume: () => void
|
|
375
|
+
reset: () => void
|
|
376
|
+
/** Runs on each tick with the new count. Returns an unsubscribe. */
|
|
377
|
+
subscribe: (_fn: (_count: number) => void) => () => void
|
|
362
378
|
}
|
|
363
|
-
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Interval with controls. Both call forms work:
|
|
382
|
+
* `useInterval(1000)` for the counter, `useInterval(fn, 1000)` to run something.
|
|
383
|
+
*
|
|
384
|
+
* There is deliberately no `start`/`stop`/`isActive` here. A declaration of that
|
|
385
|
+
* shape shipped for some time and nothing implemented it, so calls against it
|
|
386
|
+
* typechecked clean and threw `poll.start is not a function` on mount (#1941).
|
|
387
|
+
* `resume`/`pause` are the real names.
|
|
388
|
+
*/
|
|
389
|
+
declare function useInterval(_interval?: number, _options?: StxIntervalOptions): StxIntervalControls
|
|
390
|
+
declare function useInterval(_fn: (_count: number) => void, _ms?: number, _options?: StxIntervalOptions): StxIntervalControls
|
|
391
|
+
declare function useInterval(_fn: (_count: number) => void, _options?: StxIntervalOptions): StxIntervalControls
|
|
392
|
+
declare function useTimeout(_fn: () => void, _ms?: number): {
|
|
393
|
+
/** Plain boolean, not a signal. Use `subscribe` to react to it. */
|
|
394
|
+
readonly isPending: boolean
|
|
364
395
|
start: () => void
|
|
365
396
|
stop: () => void
|
|
366
|
-
|
|
397
|
+
subscribe: (_fn: (_pending: boolean) => void) => () => void
|
|
367
398
|
}
|
|
368
399
|
declare function nextTick(_fn?: () => void): Promise<void>
|
|
369
400
|
|
package/dist/typecheck.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { listComposableModules } from "./composable-loader.js";
|
|
3
4
|
import { STX_RUNTIME_GLOBALS } from "./runtime-globals.js";
|
|
4
5
|
import { stateDir } from "./state-dir.js";
|
|
5
6
|
import {
|
|
@@ -40,6 +41,50 @@ function virtualStxModuleDeclaration(files) {
|
|
|
40
41
|
].join(`
|
|
41
42
|
`);
|
|
42
43
|
}
|
|
44
|
+
const WINDOW_OWNED_NAMES = new Set([
|
|
45
|
+
"name",
|
|
46
|
+
"status",
|
|
47
|
+
"length",
|
|
48
|
+
"location",
|
|
49
|
+
"history",
|
|
50
|
+
"origin",
|
|
51
|
+
"closed",
|
|
52
|
+
"close",
|
|
53
|
+
"open",
|
|
54
|
+
"focus",
|
|
55
|
+
"blur",
|
|
56
|
+
"print",
|
|
57
|
+
"scroll",
|
|
58
|
+
"scrollTo",
|
|
59
|
+
"scrollBy",
|
|
60
|
+
"stop",
|
|
61
|
+
"top",
|
|
62
|
+
"parent",
|
|
63
|
+
"self",
|
|
64
|
+
"frames",
|
|
65
|
+
"event",
|
|
66
|
+
"external",
|
|
67
|
+
"menubar",
|
|
68
|
+
"toolbar"
|
|
69
|
+
]);
|
|
70
|
+
function composableGlobalDeclarations(modules) {
|
|
71
|
+
if (modules.length === 0)
|
|
72
|
+
return "";
|
|
73
|
+
const lines = ["// Generated \u2014 the composables the runtime publishes as bare globals."], taken = new Set(STX_RUNTIME_GLOBALS), reExports = [];
|
|
74
|
+
for (const { file, names } of modules) {
|
|
75
|
+
const specifier = JSON.stringify(file.replace(/\\/g, "/").replace(/\.ts$/, ""));
|
|
76
|
+
reExports.push(` export * from ${specifier}`);
|
|
77
|
+
for (const name of names) {
|
|
78
|
+
if (taken.has(name) || WINDOW_OWNED_NAMES.has(name))
|
|
79
|
+
continue;
|
|
80
|
+
taken.add(name);
|
|
81
|
+
lines.push(`declare const ${name}: typeof import(${specifier})[${JSON.stringify(name)}]`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
lines.push("declare module '@composables' {", ...reExports, "}");
|
|
85
|
+
return lines.join(`
|
|
86
|
+
`);
|
|
87
|
+
}
|
|
43
88
|
export function virtualPathFor(filePath, kind, index) {
|
|
44
89
|
return `${filePath}.__stx_${kind}${index}.ts`;
|
|
45
90
|
}
|
|
@@ -188,7 +233,8 @@ export async function typecheckStxFiles(files, options = {}) {
|
|
|
188
233
|
"// Generated \u2014 the context serve.ts injects into <script server> blocks.",
|
|
189
234
|
serverContextDeclarations(),
|
|
190
235
|
...runtimeTypes ? [] : ["declare const window: any", ...STX_RUNTIME_GLOBALS.map((name) => `declare const ${name}: any`)],
|
|
191
|
-
virtualStxModuleDeclaration(files)
|
|
236
|
+
virtualStxModuleDeclaration(files),
|
|
237
|
+
composableGlobalDeclarations(await listComposableModules())
|
|
192
238
|
].filter(Boolean).join(`
|
|
193
239
|
`), workDir = `${stateDir()}/typecheck`;
|
|
194
240
|
await Bun.$`rm -rf ${workDir}`.quiet().nothrow();
|
package/dist/utils.js
CHANGED
|
@@ -805,6 +805,17 @@ function assertInsideRoot(resolvedAbsolute, root) {
|
|
|
805
805
|
return p;
|
|
806
806
|
return null;
|
|
807
807
|
}
|
|
808
|
+
async function findLayoutIn(layoutsDir, templatePath, dependencies, debug) {
|
|
809
|
+
const stripped = templatePath.startsWith("layouts/") ? templatePath.slice(8) : templatePath, base = path.join(layoutsDir, stripped);
|
|
810
|
+
for (const candidate of base.endsWith(".stx") ? [base] : [base, `${base}.stx`])
|
|
811
|
+
if (await fileExists(candidate)) {
|
|
812
|
+
if (debug)
|
|
813
|
+
console.log(`Found layout in ${layoutsDir}: ${candidate}`);
|
|
814
|
+
dependencies?.add(candidate);
|
|
815
|
+
return candidate;
|
|
816
|
+
}
|
|
817
|
+
return null;
|
|
818
|
+
}
|
|
808
819
|
export async function resolveTemplatePath(templatePath, currentFilePath, options, dependencies) {
|
|
809
820
|
const result = await resolveTemplatePathInner(templatePath, currentFilePath, options, dependencies);
|
|
810
821
|
if (result === null)
|
|
@@ -856,7 +867,10 @@ async function resolveTemplatePathInner(templatePath, currentFilePath, options,
|
|
|
856
867
|
return pathWithExt;
|
|
857
868
|
}
|
|
858
869
|
}
|
|
859
|
-
|
|
870
|
+
const layoutSearchDirs = [];
|
|
871
|
+
if (options.layoutsDir)
|
|
872
|
+
layoutSearchDirs.push(path.isAbsolute(options.layoutsDir) ? options.layoutsDir : path.resolve(process.cwd(), options.layoutsDir));
|
|
873
|
+
let searchDir = path.resolve(dirPath);
|
|
860
874
|
const rootDir = process.cwd();
|
|
861
875
|
for (let i = 0;i < 10; i++) {
|
|
862
876
|
const candidate = path.join(searchDir, "layouts");
|
|
@@ -865,7 +879,7 @@ async function resolveTemplatePathInner(templatePath, currentFilePath, options,
|
|
|
865
879
|
candidateExists = fs.statSync(candidate, { throwIfNoEntry: !1 })?.isDirectory() ?? !1;
|
|
866
880
|
} catch {}
|
|
867
881
|
if (candidateExists) {
|
|
868
|
-
|
|
882
|
+
layoutSearchDirs.push(candidate);
|
|
869
883
|
break;
|
|
870
884
|
}
|
|
871
885
|
const parent = path.dirname(searchDir);
|
|
@@ -873,45 +887,10 @@ async function resolveTemplatePathInner(templatePath, currentFilePath, options,
|
|
|
873
887
|
break;
|
|
874
888
|
searchDir = parent;
|
|
875
889
|
}
|
|
876
|
-
|
|
877
|
-
const
|
|
878
|
-
if (
|
|
879
|
-
|
|
880
|
-
console.log(`Found in current layouts dir: ${fromCurrentLayouts}`);
|
|
881
|
-
if (dependencies)
|
|
882
|
-
dependencies.add(fromCurrentLayouts);
|
|
883
|
-
return fromCurrentLayouts;
|
|
884
|
-
}
|
|
885
|
-
if (!layoutTemplatePath.endsWith(".stx")) {
|
|
886
|
-
const fromCurrentLayoutsWithExt = `${fromCurrentLayouts}.stx`;
|
|
887
|
-
if (await fileExists(fromCurrentLayoutsWithExt)) {
|
|
888
|
-
if (options.debug)
|
|
889
|
-
console.log(`Found in current layouts dir with extension: ${fromCurrentLayoutsWithExt}`);
|
|
890
|
-
if (dependencies)
|
|
891
|
-
dependencies.add(fromCurrentLayoutsWithExt);
|
|
892
|
-
return fromCurrentLayoutsWithExt;
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
if (options.layoutsDir) {
|
|
897
|
-
const resolvedLayoutsDir = path.isAbsolute(options.layoutsDir) ? options.layoutsDir : path.resolve(process.cwd(), options.layoutsDir), strippedPath = templatePath.startsWith("layouts/") ? templatePath.slice(8) : templatePath, fromLayoutsDir = path.join(resolvedLayoutsDir, strippedPath);
|
|
898
|
-
if (await fileExists(fromLayoutsDir)) {
|
|
899
|
-
if (options.debug)
|
|
900
|
-
console.log(`Found in options.layoutsDir: ${fromLayoutsDir}`);
|
|
901
|
-
if (dependencies)
|
|
902
|
-
dependencies.add(fromLayoutsDir);
|
|
903
|
-
return fromLayoutsDir;
|
|
904
|
-
}
|
|
905
|
-
if (!templatePath.endsWith(".stx")) {
|
|
906
|
-
const fromLayoutsDirWithExt = `${fromLayoutsDir}.stx`;
|
|
907
|
-
if (await fileExists(fromLayoutsDirWithExt)) {
|
|
908
|
-
if (options.debug)
|
|
909
|
-
console.log(`Found in options.layoutsDir with extension: ${fromLayoutsDirWithExt}`);
|
|
910
|
-
if (dependencies)
|
|
911
|
-
dependencies.add(fromLayoutsDirWithExt);
|
|
912
|
-
return fromLayoutsDirWithExt;
|
|
913
|
-
}
|
|
914
|
-
}
|
|
890
|
+
for (const dir of layoutSearchDirs) {
|
|
891
|
+
const found = await findLayoutIn(dir, templatePath, dependencies, options.debug);
|
|
892
|
+
if (found)
|
|
893
|
+
return found;
|
|
915
894
|
}
|
|
916
895
|
if (templatePath.startsWith("layouts/") || templatePath.includes("/layouts/")) {
|
|
917
896
|
const parts = templatePath.split("layouts/"), layoutsPath = path.join(options.partialsDir || dirPath, "layouts", parts[1]);
|
|
@@ -934,9 +913,9 @@ async function resolveTemplatePathInner(templatePath, currentFilePath, options,
|
|
|
934
913
|
}
|
|
935
914
|
}
|
|
936
915
|
if (options.partialsDir) {
|
|
937
|
-
|
|
938
|
-
if (await fileExists(
|
|
939
|
-
const fromPartialsLayouts = path.join(
|
|
916
|
+
const partialsLayoutsDir = path.join(options.partialsDir, "layouts");
|
|
917
|
+
if (await fileExists(partialsLayoutsDir)) {
|
|
918
|
+
const fromPartialsLayouts = path.join(partialsLayoutsDir, templatePath);
|
|
940
919
|
if (await fileExists(fromPartialsLayouts)) {
|
|
941
920
|
if (options.debug)
|
|
942
921
|
console.log(`Found in partials layouts dir: ${fromPartialsLayouts}`);
|
|
@@ -49,7 +49,7 @@ export const STX_ENGINE_BINDING_NAMES = [
|
|
|
49
49
|
"fetch",
|
|
50
50
|
"params"
|
|
51
51
|
];
|
|
52
|
-
const ENGINE_BINDINGS = new Set(STX_ENGINE_BINDING_NAMES), STX_RUNTIME_SPECIFIERS = new Set(["stx", "@stacksjs/stx"]);
|
|
52
|
+
const ENGINE_BINDINGS = new Set(STX_ENGINE_BINDING_NAMES), CONTEXT_RESERVED_BINDINGS = new Set(["props", "$props", "defineProps"]), STX_RUNTIME_SPECIFIERS = new Set(["stx", "@stacksjs/stx"]);
|
|
53
53
|
import { findMatchingDelimiter } from "./parser/tokenizer.js";
|
|
54
54
|
import { mergeHeadConfigs, seoMetaToHeadConfig } from "./head.js";
|
|
55
55
|
import { getPublicEnvDefine } from "./public-env.js";
|
|
@@ -459,7 +459,7 @@ export async function extractVariables(scriptContent, context, filePath, options
|
|
|
459
459
|
removeEventListener: () => {}
|
|
460
460
|
}, mockConsole = console;
|
|
461
461
|
try {
|
|
462
|
-
const convertedScript = convertToCommonJS(jsContent, filePath), propsKeys = new Set(Object.keys(propsObj)), isIdentifier = (key) => /^[a-z_$][\w$]*$/i.test(key), filteredContextKeys = Object.keys(context).filter((key) => !propsKeys.has(key) && key
|
|
462
|
+
const convertedScript = convertToCommonJS(jsContent, filePath), propsKeys = new Set(Object.keys(propsObj)), isIdentifier = (key) => /^[a-z_$][\w$]*$/i.test(key), filteredContextKeys = Object.keys(context).filter((key) => !propsKeys.has(key) && !CONTEXT_RESERVED_BINDINGS.has(key) && isIdentifier(key)), filteredContextValues = filteredContextKeys.map((key) => context[key]);
|
|
463
463
|
if (!filteredContextKeys.includes("__stxServeContext")) {
|
|
464
464
|
filteredContextKeys.push("__stxServeContext");
|
|
465
465
|
filteredContextValues.push(void 0);
|
|
@@ -690,16 +690,13 @@ export function convertToCommonJS(scriptContent, filePath) {
|
|
|
690
690
|
const [imported, local] = [aliased[0].trim(), aliased[1].trim()];
|
|
691
691
|
if (isStxRuntime && ENGINE_BINDINGS.has(imported)) {
|
|
692
692
|
convertedLines.push(`const ${local} = ${imported};`);
|
|
693
|
-
exported.push(local);
|
|
694
693
|
continue;
|
|
695
694
|
}
|
|
696
695
|
specifiers.push(`${imported}: ${local}`);
|
|
697
696
|
exported.push(local);
|
|
698
697
|
} else {
|
|
699
|
-
if (isStxRuntime && ENGINE_BINDINGS.has(specifier))
|
|
700
|
-
exported.push(specifier);
|
|
698
|
+
if (isStxRuntime && ENGINE_BINDINGS.has(specifier))
|
|
701
699
|
continue;
|
|
702
|
-
}
|
|
703
700
|
specifiers.push(specifier);
|
|
704
701
|
exported.push(specifier);
|
|
705
702
|
}
|
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.190",
|
|
5
5
|
"description": "A performant UI Framework. Powered by Bun.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -117,12 +117,12 @@
|
|
|
117
117
|
"dependencies": {
|
|
118
118
|
"@cwcss/crosswind": "^0.2.14",
|
|
119
119
|
"@stacksjs/clapp": "^0.2.0",
|
|
120
|
-
"@stacksjs/desktop": "0.2.
|
|
121
|
-
"@stacksjs/sanitizer": "0.2.
|
|
120
|
+
"@stacksjs/desktop": "0.2.190",
|
|
121
|
+
"@stacksjs/sanitizer": "0.2.190",
|
|
122
122
|
"@stacksjs/ts-i18n": "^0.1.11",
|
|
123
|
-
"bun-plugin-stx": "0.2.
|
|
123
|
+
"bun-plugin-stx": "0.2.190",
|
|
124
124
|
"bunfig": "^0.15.17",
|
|
125
|
-
"stx-router": "0.2.
|
|
125
|
+
"stx-router": "0.2.190",
|
|
126
126
|
"ts-broadcasting": "^0.0.9",
|
|
127
127
|
"ts-images": "^0.2.11",
|
|
128
128
|
"ts-syntax-highlighter": "^0.2.1"
|
package/stx.d.ts
CHANGED
|
@@ -355,15 +355,46 @@ declare function useFocus(_target: HTMLElement | StxRef<HTMLElement | null> | st
|
|
|
355
355
|
declare function useDebounce<T extends (..._args: any[]) => any>(_fn: T, _delay: number): T
|
|
356
356
|
declare function useDebouncedValue<T>(_value: StxSignal<T>, _delay: number): StxSignal<T>
|
|
357
357
|
declare function useThrottle<T extends (..._args: any[]) => any>(_fn: T, _delay: number): T
|
|
358
|
-
|
|
359
|
-
start
|
|
360
|
-
|
|
361
|
-
|
|
358
|
+
interface StxIntervalOptions {
|
|
359
|
+
/** Tick once on start/resume instead of waiting out the first interval. */
|
|
360
|
+
immediate?: boolean
|
|
361
|
+
/** Gate ticks. `false`, or a function returning false, skips them entirely. */
|
|
362
|
+
enabled?: boolean | (() => boolean)
|
|
363
|
+
/** Skip ticks while `document.hidden`. */
|
|
364
|
+
whileVisible?: boolean
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
interface StxIntervalControls {
|
|
368
|
+
/**
|
|
369
|
+
* Ticks elapsed. A plain number — read it, do not call it. It is not a
|
|
370
|
+
* signal and an `effect` cannot track it; use `subscribe` to react.
|
|
371
|
+
*/
|
|
372
|
+
readonly counter: number
|
|
373
|
+
pause: () => void
|
|
374
|
+
resume: () => void
|
|
375
|
+
reset: () => void
|
|
376
|
+
/** Runs on each tick with the new count. Returns an unsubscribe. */
|
|
377
|
+
subscribe: (_fn: (_count: number) => void) => () => void
|
|
362
378
|
}
|
|
363
|
-
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Interval with controls. Both call forms work:
|
|
382
|
+
* `useInterval(1000)` for the counter, `useInterval(fn, 1000)` to run something.
|
|
383
|
+
*
|
|
384
|
+
* There is deliberately no `start`/`stop`/`isActive` here. A declaration of that
|
|
385
|
+
* shape shipped for some time and nothing implemented it, so calls against it
|
|
386
|
+
* typechecked clean and threw `poll.start is not a function` on mount (#1941).
|
|
387
|
+
* `resume`/`pause` are the real names.
|
|
388
|
+
*/
|
|
389
|
+
declare function useInterval(_interval?: number, _options?: StxIntervalOptions): StxIntervalControls
|
|
390
|
+
declare function useInterval(_fn: (_count: number) => void, _ms?: number, _options?: StxIntervalOptions): StxIntervalControls
|
|
391
|
+
declare function useInterval(_fn: (_count: number) => void, _options?: StxIntervalOptions): StxIntervalControls
|
|
392
|
+
declare function useTimeout(_fn: () => void, _ms?: number): {
|
|
393
|
+
/** Plain boolean, not a signal. Use `subscribe` to react to it. */
|
|
394
|
+
readonly isPending: boolean
|
|
364
395
|
start: () => void
|
|
365
396
|
stop: () => void
|
|
366
|
-
|
|
397
|
+
subscribe: (_fn: (_pending: boolean) => void) => () => void
|
|
367
398
|
}
|
|
368
399
|
declare function nextTick(_fn?: () => void): Promise<void>
|
|
369
400
|
|