@stacksjs/stx 0.0.0
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/README.md +800 -0
- package/dist/auth.d.ts +1 -0
- package/dist/bin/cli.js +633 -0
- package/dist/caching.d.ts +11 -0
- package/dist/chunk-04bqmpzb.js +7069 -0
- package/dist/chunk-0xkkmb8j.js +2502 -0
- package/dist/chunk-ywm063e4.js +20 -0
- package/dist/chunk-zhs1t2p5.js +4279 -0
- package/dist/client.d.ts +36 -0
- package/dist/client.js +90 -0
- package/dist/conditionals.d.ts +4 -0
- package/dist/config.d.ts +4 -0
- package/dist/custom-directives.d.ts +6 -0
- package/dist/docs.d.ts +20 -0
- package/dist/expressions.d.ts +9 -0
- package/dist/forms.d.ts +31 -0
- package/dist/i18n.d.ts +22 -0
- package/dist/includes.d.ts +21 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +14143 -0
- package/dist/loops.d.ts +3 -0
- package/dist/markdown.d.ts +2 -0
- package/dist/middleware.d.ts +5 -0
- package/dist/process.d.ts +11 -0
- package/dist/src/index.js +397 -0
- package/dist/streaming.d.ts +14 -0
- package/dist/types.d.ts +149 -0
- package/dist/utils.d.ts +9 -0
- package/dist/web-components.d.ts +16 -0
- package/package.json +74 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
declare type IslandHandlers = Record<string, () => Promise<any>>
|
|
2
|
+
|
|
3
|
+
type IslandHydrationFn = (element: any, props: any) => void | Promise<void>
|
|
4
|
+
|
|
5
|
+
const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined'
|
|
6
|
+
|
|
7
|
+
async function hydrateIsland(
|
|
8
|
+
element: any,
|
|
9
|
+
name: string,
|
|
10
|
+
handler: () => Promise<any>,
|
|
11
|
+
): Promise<void> {
|
|
12
|
+
if (!isBrowser) return
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const id = element.getAttribute('data-island-id')
|
|
16
|
+
const propsScript = document.querySelector(`script[data-island-props="${id}"]`)
|
|
17
|
+
const props = propsScript ? JSON.parse(propsScript.textContent || '{}') : {}
|
|
18
|
+
|
|
19
|
+
const module = await handler()
|
|
20
|
+
const hydrateFn: IslandHydrationFn = module.default || module.hydrate
|
|
21
|
+
|
|
22
|
+
if (typeof hydrateFn !== 'function') {
|
|
23
|
+
console.error(`Island handler for "${name}" does not export a valid hydration function`)
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
await hydrateFn(element, props)
|
|
28
|
+
|
|
29
|
+
element.setAttribute('data-hydrated', 'true')
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.error(`Failed to hydrate island "${name}":`, error)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export declare function hydrateIslands(handlers: IslandHandlers): void;
|
|
36
|
+
export declare function preloadIslandHandlers(handlers: IslandHandlers): void;
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
var isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
3
|
+
async function hydrateIsland(element, name, handler) {
|
|
4
|
+
if (!isBrowser)
|
|
5
|
+
return;
|
|
6
|
+
try {
|
|
7
|
+
const id = element.getAttribute("data-island-id");
|
|
8
|
+
const propsScript = document.querySelector(`script[data-island-props="${id}"]`);
|
|
9
|
+
const props = propsScript ? JSON.parse(propsScript.textContent || "{}") : {};
|
|
10
|
+
const module = await handler();
|
|
11
|
+
const hydrateFn = module.default || module.hydrate;
|
|
12
|
+
if (typeof hydrateFn !== "function") {
|
|
13
|
+
console.error(`Island handler for "${name}" does not export a valid hydration function`);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
await hydrateFn(element, props);
|
|
17
|
+
element.setAttribute("data-hydrated", "true");
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error(`Failed to hydrate island "${name}":`, error);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function hydrateIslands(handlers) {
|
|
23
|
+
if (!isBrowser)
|
|
24
|
+
return;
|
|
25
|
+
const islands = document.querySelectorAll("[data-island]");
|
|
26
|
+
const lazyIslands = [];
|
|
27
|
+
islands.forEach((island) => {
|
|
28
|
+
const name = island.getAttribute("data-island");
|
|
29
|
+
const priority = island.getAttribute("data-priority") || "lazy";
|
|
30
|
+
if (!name || !handlers[name] || island.getAttribute("data-hydrated") === "true") {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (priority === "eager") {
|
|
34
|
+
hydrateIsland(island, name, handlers[name]);
|
|
35
|
+
} else {
|
|
36
|
+
lazyIslands.push([island, name]);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
if (lazyIslands.length > 0 && "IntersectionObserver" in window) {
|
|
40
|
+
const observer = new IntersectionObserver((entries) => {
|
|
41
|
+
entries.forEach((entry) => {
|
|
42
|
+
if (entry.isIntersecting) {
|
|
43
|
+
const element = entry.target;
|
|
44
|
+
const name = element.getAttribute("data-island");
|
|
45
|
+
if (name && handlers[name] && element.getAttribute("data-hydrated") !== "true") {
|
|
46
|
+
hydrateIsland(element, name, handlers[name]);
|
|
47
|
+
observer.unobserve(element);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}, {
|
|
52
|
+
rootMargin: "200px",
|
|
53
|
+
threshold: 0
|
|
54
|
+
});
|
|
55
|
+
lazyIslands.forEach(([element]) => {
|
|
56
|
+
observer.observe(element);
|
|
57
|
+
});
|
|
58
|
+
} else {
|
|
59
|
+
setTimeout(() => {
|
|
60
|
+
lazyIslands.forEach(([element, name]) => {
|
|
61
|
+
if (element.getAttribute("data-hydrated") !== "true") {
|
|
62
|
+
hydrateIsland(element, name, handlers[name]);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}, 1000);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function preloadIslandHandlers(handlers) {
|
|
69
|
+
if (!isBrowser)
|
|
70
|
+
return;
|
|
71
|
+
Object.entries(handlers).forEach(([name, getHandler]) => {
|
|
72
|
+
try {
|
|
73
|
+
const handlerString = getHandler.toString();
|
|
74
|
+
const moduleMatch = handlerString.match(/import\(['"](.+)['"]\)/);
|
|
75
|
+
if (moduleMatch && moduleMatch[1]) {
|
|
76
|
+
const link = document.createElement("link");
|
|
77
|
+
link.rel = "modulepreload";
|
|
78
|
+
link.href = moduleMatch[1];
|
|
79
|
+
link.setAttribute("data-island-module", name);
|
|
80
|
+
document.head.appendChild(link);
|
|
81
|
+
}
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.warn(`Failed to preload island handler for "${name}":`, error);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
preloadIslandHandlers,
|
|
89
|
+
hydrateIslands
|
|
90
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function processConditionals(template: string, context: Record<string, any>, filePath: string): string;
|
|
2
|
+
export declare function processAuthDirectives(template: string, context: Record<string, any>): string;
|
|
3
|
+
export declare function processIssetEmptyDirectives(template: string, context: Record<string, any>, filePath?: string): string;
|
|
4
|
+
export declare function processEnvDirective(template: string, context: Record<string, any>, filePath?: string): string;
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CustomDirective, StxOptions } from './types';
|
|
2
|
+
|
|
3
|
+
export declare function processCustomDirectives(template: string, context: Record<string, any>, filePath: string, options: StxOptions): Promise<string>;
|
|
4
|
+
declare function processDirectiveWithEndTag(template: string, directive: CustomDirective, context: Record<string, any>, filePath: string, options: StxOptions): Promise<string>;
|
|
5
|
+
declare function processDirectiveWithoutEndTag(template: string, directive: CustomDirective, context: Record<string, any>, filePath: string, options: StxOptions): Promise<string>;
|
|
6
|
+
declare function parseDirectiveParams(paramString: string): string[];
|
package/dist/docs.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ComponentDoc, DirectiveDoc, TemplateDoc } from './types';
|
|
2
|
+
|
|
3
|
+
export declare function extractComponentProps(componentPath: string): Promise<ComponentPropDoc[]>;
|
|
4
|
+
export declare function extractComponentDescription(componentPath: string): Promise<string>;
|
|
5
|
+
export declare function generateComponentDoc(componentPath: string, isWebComponent?: boolean, webComponentTag?: string): Promise<ComponentDoc>;
|
|
6
|
+
export declare function findComponentFiles(componentsDir: string): Promise<string[]>;
|
|
7
|
+
export declare function generateComponentsDocs(componentsDir: string, webComponentsConfig?: any): Promise<ComponentDoc[]>;
|
|
8
|
+
export declare function generateTemplatesDocs(templatesDir: string): Promise<TemplateDoc[]>;
|
|
9
|
+
export declare function generateDirectivesDocs(customDirectives?: any[]): Promise<DirectiveDoc[]>;
|
|
10
|
+
export declare function formatDocsAsMarkdown(componentDocs?: ComponentDoc[], templateDocs?: TemplateDoc[], directiveDocs?: DirectiveDoc[], extraContent?: string): string;
|
|
11
|
+
export declare function formatDocsAsHtml(componentDocs?: ComponentDoc[], templateDocs?: TemplateDoc[], directiveDocs?: DirectiveDoc[], extraContent?: string): string;
|
|
12
|
+
export declare function formatDocsAsJson(componentDocs?: ComponentDoc[], templateDocs?: TemplateDoc[], directiveDocs?: DirectiveDoc[], extraContent?: string): string;
|
|
13
|
+
export declare function generateDocs(options: {
|
|
14
|
+
componentsDir?: string
|
|
15
|
+
templatesDir?: string
|
|
16
|
+
webComponentsConfig?: any
|
|
17
|
+
customDirectives?: any[]
|
|
18
|
+
config: Partial<DocGeneratorConfig>
|
|
19
|
+
}): Promise<boolean>;
|
|
20
|
+
export declare function docsCommand(options: any): Promise<boolean>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare type FilterFunction = (value: any, ...args: any[]) => any
|
|
2
|
+
|
|
3
|
+
let globalContext: Record<string, any> = {}
|
|
4
|
+
export declare function setGlobalContext(context: Record<string, any>): void;
|
|
5
|
+
export declare function escapeHtml(unsafe: string): string;
|
|
6
|
+
export declare function processExpressions(template: string, context: Record<string, any>, filePath: string): string;
|
|
7
|
+
export declare function applyFilters(value: any, filterExpression: string, context: Record<string, any>): any;
|
|
8
|
+
export declare function evaluateExpression(expression: string, context: Record<string, any>, silent?: boolean): any;
|
|
9
|
+
export declare function unescapeHtml(html: string): string;
|
package/dist/forms.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { StxOptions } from './types';
|
|
2
|
+
|
|
3
|
+
declare function genId(): string;
|
|
4
|
+
export declare function processForms(template: string, context: Record<string, any>, _filePath: string, _options: StxOptions): string;
|
|
5
|
+
export declare function processBasicFormDirectives(template: string, context: Record<string, any>): string;
|
|
6
|
+
export declare function processFormInputDirectives(template: string, context: Record<string, any>): string;
|
|
7
|
+
declare const name: unknown;
|
|
8
|
+
declare const attrs: unknown;
|
|
9
|
+
declare const type: unknown;
|
|
10
|
+
declare const existingClass: unknown;
|
|
11
|
+
declare const attrs: unknown;
|
|
12
|
+
declare const hasError: unknown;
|
|
13
|
+
declare const existingClass: unknown;
|
|
14
|
+
declare const attrs: unknown;
|
|
15
|
+
declare const hasError: unknown;
|
|
16
|
+
declare const existingClass: unknown;
|
|
17
|
+
declare const isSelected: oldValue;
|
|
18
|
+
declare const attrs: unknown;
|
|
19
|
+
declare const isChecked: oldValues;
|
|
20
|
+
declare const existingClass: unknown;
|
|
21
|
+
declare const attrs: unknown;
|
|
22
|
+
declare const isChecked: unknown;
|
|
23
|
+
declare const className: unknown;
|
|
24
|
+
declare const attrs: unknown;
|
|
25
|
+
declare const className: unknown;
|
|
26
|
+
export declare function processErrorDirective(template: string, context: Record<string, any>): string;
|
|
27
|
+
declare function hasFieldError(field: string, context: Record<string, any>): boolean;
|
|
28
|
+
declare function getErrorMessage(field: string, context: Record<string, any>): string;
|
|
29
|
+
declare function getOldValue(field: string, context: Record<string, any>): any;
|
|
30
|
+
declare function parseAttributes(attributesStr: string): string;
|
|
31
|
+
export declare function processFormDirectives(template: string, context: Record<string, any>): string;
|
package/dist/i18n.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { I18nConfig, StxOptions } from './types';
|
|
2
|
+
|
|
3
|
+
export declare const defaultI18nConfig: I18nConfig;
|
|
4
|
+
declare const translationsCache: Record<string, Record<string, any>>;
|
|
5
|
+
export declare function loadTranslation(locale: string, options: StxOptions): Promise<Record<string, any>>;
|
|
6
|
+
declare function parseYaml(content: string): Promise<Record<string, any>>;
|
|
7
|
+
declare function getFileExtension(format: string): string;
|
|
8
|
+
export declare function getTranslation(key: string,
|
|
9
|
+
translations: Record<string, any>,
|
|
10
|
+
fallbackToKey: boolean = true,
|
|
11
|
+
params: Record<string, any> = {},): string;
|
|
12
|
+
export declare function processTranslateDirective(template: string, context: Record<string, any>, filePath: string, options: StxOptions): Promise<string>;
|
|
13
|
+
declare const i18nConfig: {};
|
|
14
|
+
declare const translations: unknown;
|
|
15
|
+
declare const approaches: Array<(() => unknown) | (() => unknown) | (() => unknown)>;
|
|
16
|
+
declare const translation: unknown;
|
|
17
|
+
declare const matches: Array<((...args: any[]) => unknown)>;
|
|
18
|
+
declare const approaches: Array<(() => unknown) | (() => unknown) | (() => unknown)>;
|
|
19
|
+
declare function replaceAsync(str: string, regex: RegExp, asyncFn: (
|
|
20
|
+
match, ...groups?: any[]
|
|
21
|
+
)): Promise<string>;
|
|
22
|
+
export declare function createTranslateFilter(translations: Record<string, any>, fallbackToKey?: boolean): (value: string, params?: Record<string, any>) => string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { StxOptions } from './types';
|
|
2
|
+
|
|
3
|
+
export declare const partialsCache: Map<string, string>;
|
|
4
|
+
export declare function processIncludes(template: string, context: Record<string, any>, filePath: string, options: StxOptions, dependencies: Set<string>): Promise<string>;
|
|
5
|
+
declare const includeFilePath: unknown;
|
|
6
|
+
declare const conditionFn: unknown;
|
|
7
|
+
declare const includeFilePath: unknown;
|
|
8
|
+
declare const conditionFn: unknown;
|
|
9
|
+
declare const includeFilePath: unknown;
|
|
10
|
+
declare const matchOffset: unknown;
|
|
11
|
+
declare let pathArray: unknown;
|
|
12
|
+
declare const varsFn: unknown;
|
|
13
|
+
declare const includeFilePath: unknown;
|
|
14
|
+
declare const processed: unknown;
|
|
15
|
+
declare function resolvePath(includePath: string, partialsDir: string, filePath: string): string | null;
|
|
16
|
+
declare let processedIncludes: (...args: any[]) => unknown;
|
|
17
|
+
declare let matchOffset: unknown;
|
|
18
|
+
declare const varsFn: unknown;
|
|
19
|
+
declare const processedContent: unknown;
|
|
20
|
+
export declare function processStackPushDirectives(template: string, stacks: Record<string, string[]>): string;
|
|
21
|
+
export declare function processStackReplacements(template: string, stacks: Record<string, string[]>): string;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { plugin } from 'bun-plugin-stx';
|
|
2
|
+
|
|
3
|
+
export type { ComponentDoc, ComponentPropDoc, CustomDirective, DirectiveDoc, DocFormat, DocGeneratorConfig, HydrationConfig, I18nConfig, Island, Middleware, StreamingConfig, StreamRenderer, StxConfig, StxOptions, TemplateDoc, WebComponent, WebComponentConfig } from './types'
|
|
4
|
+
|
|
5
|
+
export { createTranslateFilter, getTranslation, loadTranslation, processTranslateDirective } from './i18n'
|
|
6
|
+
export { markdownDirectiveHandler, processMarkdownDirectives } from './markdown'
|
|
7
|
+
export { createStreamRenderer, islandDirective, processSectionDirectives, registerStreamingDirectives, streamTemplate } from './streaming'
|
|
8
|
+
export { buildWebComponents, webComponentDirectiveHandler } from './web-components'
|
|
9
|
+
|
|
10
|
+
export * from './auth'
|
|
11
|
+
export * from './caching'
|
|
12
|
+
export * from './config'
|
|
13
|
+
export * from './custom-directives'
|
|
14
|
+
export * from './docs'
|
|
15
|
+
export * from './expressions'
|
|
16
|
+
export * from './forms'
|
|
17
|
+
export * from './includes'
|
|
18
|
+
export * from './loops'
|
|
19
|
+
export * from './middleware'
|
|
20
|
+
export * from './process'
|
|
21
|
+
export * from './types'
|
|
22
|
+
export * from './utils'
|
|
23
|
+
|
|
24
|
+
export default plugin;
|