@tenphi/tasty 0.0.0-snapshot.002b1b3
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/LICENSE +21 -0
- package/README.md +637 -0
- package/dist/async-storage-B7_o6FKt.js +44 -0
- package/dist/async-storage-B7_o6FKt.js.map +1 -0
- package/dist/collector-LuU1vZ68.d.ts +98 -0
- package/dist/collector-MOYY2SOr.js +230 -0
- package/dist/collector-MOYY2SOr.js.map +1 -0
- package/dist/config-A237aY9H.js +10235 -0
- package/dist/config-A237aY9H.js.map +1 -0
- package/dist/config-vuCRkBWX.d.ts +884 -0
- package/dist/context-CkSg-kDT.js +24 -0
- package/dist/context-CkSg-kDT.js.map +1 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.js +6 -0
- package/dist/core-BkKav78f.js +1592 -0
- package/dist/core-BkKav78f.js.map +1 -0
- package/dist/css-writer-Cos9tQRM.js +329 -0
- package/dist/css-writer-Cos9tQRM.js.map +1 -0
- package/dist/format-global-rules-Dbc_1tc3.js +22 -0
- package/dist/format-global-rules-Dbc_1tc3.js.map +1 -0
- package/dist/format-rules-C2oiTsEO.js +143 -0
- package/dist/format-rules-C2oiTsEO.js.map +1 -0
- package/dist/hydrate-miFzWIKR.js +45 -0
- package/dist/hydrate-miFzWIKR.js.map +1 -0
- package/dist/index-CJMXAAO5.d.ts +1602 -0
- package/dist/index-dUtwpOux.d.ts +1266 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +732 -0
- package/dist/index.js.map +1 -0
- package/dist/keyframes-DDtNo_hl.js +587 -0
- package/dist/keyframes-DDtNo_hl.js.map +1 -0
- package/dist/merge-styles-CtDJMhpJ.d.ts +7 -0
- package/dist/merge-styles-D_HbBOlq.js +144 -0
- package/dist/merge-styles-D_HbBOlq.js.map +1 -0
- package/dist/resolve-recipes-B7-823LL.js +144 -0
- package/dist/resolve-recipes-B7-823LL.js.map +1 -0
- package/dist/ssr/astro-client.d.ts +1 -0
- package/dist/ssr/astro-client.js +19 -0
- package/dist/ssr/astro-client.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +15 -0
- package/dist/ssr/astro-middleware.js +19 -0
- package/dist/ssr/astro-middleware.js.map +1 -0
- package/dist/ssr/astro.d.ts +97 -0
- package/dist/ssr/astro.js +149 -0
- package/dist/ssr/astro.js.map +1 -0
- package/dist/ssr/index.d.ts +44 -0
- package/dist/ssr/index.js +10 -0
- package/dist/ssr/index.js.map +1 -0
- package/dist/ssr/next.d.ts +46 -0
- package/dist/ssr/next.js +75 -0
- package/dist/ssr/next.js.map +1 -0
- package/dist/static/index.d.ts +91 -0
- package/dist/static/index.js +50 -0
- package/dist/static/index.js.map +1 -0
- package/dist/static/inject.d.ts +5 -0
- package/dist/static/inject.js +17 -0
- package/dist/static/inject.js.map +1 -0
- package/dist/zero/babel.d.ts +81 -0
- package/dist/zero/babel.js +466 -0
- package/dist/zero/babel.js.map +1 -0
- package/dist/zero/index.d.ts +67 -0
- package/dist/zero/index.js +2 -0
- package/dist/zero/next.d.ts +86 -0
- package/dist/zero/next.js +143 -0
- package/dist/zero/next.js.map +1 -0
- package/docs/README.md +31 -0
- package/docs/adoption.md +298 -0
- package/docs/comparison.md +419 -0
- package/docs/configuration.md +394 -0
- package/docs/debug.md +320 -0
- package/docs/design-system.md +436 -0
- package/docs/dsl.md +688 -0
- package/docs/getting-started.md +217 -0
- package/docs/injector.md +544 -0
- package/docs/methodology.md +616 -0
- package/docs/pipeline.md +673 -0
- package/docs/react-api.md +557 -0
- package/docs/ssr.md +442 -0
- package/docs/styles.md +596 -0
- package/docs/tasty-static.md +532 -0
- package/package.json +222 -0
- package/tasty.config.ts +15 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { b as isSelector, st as isDevEnv } from "./config-A237aY9H.js";
|
|
2
|
+
//#region src/utils/merge-styles.ts
|
|
3
|
+
const devMode = isDevEnv();
|
|
4
|
+
const INHERIT_VALUE = "@inherit";
|
|
5
|
+
/**
|
|
6
|
+
* Check if a value is a state map (object, not array).
|
|
7
|
+
*/
|
|
8
|
+
function isStateMap(value) {
|
|
9
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Normalize a parent value to a state map.
|
|
13
|
+
* - Already a state map → return as-is
|
|
14
|
+
* - Non-null, non-false primitive → wrap as `{ '': value }`
|
|
15
|
+
* - null / undefined / false → return null (no parent to merge with)
|
|
16
|
+
*/
|
|
17
|
+
function normalizeToStateMap(value) {
|
|
18
|
+
if (isStateMap(value)) return value;
|
|
19
|
+
if (value != null && value !== false) return { "": value };
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Resolve a child state map against a parent value.
|
|
24
|
+
*
|
|
25
|
+
* Mode is determined by whether the child contains a `''` (default) key:
|
|
26
|
+
* - No `''` → extend mode: parent entries preserved, child adds/overrides/repositions
|
|
27
|
+
* - Has `''` → replace mode: child defines everything, `@inherit` cherry-picks from parent
|
|
28
|
+
*
|
|
29
|
+
* In both modes:
|
|
30
|
+
* - `@inherit` value → resolve from parent state map
|
|
31
|
+
* - `null` value → remove this state from the result
|
|
32
|
+
* - `false` value → tombstone, persists through all layers, blocks recipe
|
|
33
|
+
*/
|
|
34
|
+
function resolveStateMap(parentValue, childMap) {
|
|
35
|
+
const isExtend = !("" in childMap);
|
|
36
|
+
const parentMap = normalizeToStateMap(parentValue);
|
|
37
|
+
if (!parentMap) {
|
|
38
|
+
const result = {};
|
|
39
|
+
for (const key of Object.keys(childMap)) {
|
|
40
|
+
const val = childMap[key];
|
|
41
|
+
if (val === null || val === INHERIT_VALUE) continue;
|
|
42
|
+
result[key] = val;
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
if (isExtend) return resolveExtendMode(parentMap, childMap);
|
|
47
|
+
return resolveReplaceMode(parentMap, childMap);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Extend mode: parent entries are preserved, child entries add/override/reposition.
|
|
51
|
+
*/
|
|
52
|
+
function resolveExtendMode(parentMap, childMap) {
|
|
53
|
+
const inheritKeys = /* @__PURE__ */ new Set();
|
|
54
|
+
const removeKeys = /* @__PURE__ */ new Set();
|
|
55
|
+
const overrideKeys = /* @__PURE__ */ new Map();
|
|
56
|
+
for (const key of Object.keys(childMap)) {
|
|
57
|
+
const val = childMap[key];
|
|
58
|
+
if (val === INHERIT_VALUE) {
|
|
59
|
+
if (key in parentMap) inheritKeys.add(key);
|
|
60
|
+
else if (devMode) console.warn(`[Tasty] @inherit used for state '${key}' that does not exist in the parent style map. Entry skipped.`);
|
|
61
|
+
} else if (val === null) removeKeys.add(key);
|
|
62
|
+
else if (key in parentMap) overrideKeys.set(key, val);
|
|
63
|
+
}
|
|
64
|
+
const result = {};
|
|
65
|
+
for (const key of Object.keys(parentMap)) {
|
|
66
|
+
if (removeKeys.has(key)) continue;
|
|
67
|
+
if (inheritKeys.has(key)) continue;
|
|
68
|
+
if (overrideKeys.has(key)) result[key] = overrideKeys.get(key);
|
|
69
|
+
else result[key] = parentMap[key];
|
|
70
|
+
}
|
|
71
|
+
for (const key of Object.keys(childMap)) if (inheritKeys.has(key)) result[key] = parentMap[key];
|
|
72
|
+
else if (!removeKeys.has(key) && !overrideKeys.has(key) && childMap[key] !== INHERIT_VALUE) result[key] = childMap[key];
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Replace mode: child entries define the result, `@inherit` pulls from parent.
|
|
77
|
+
*/
|
|
78
|
+
function resolveReplaceMode(parentMap, childMap) {
|
|
79
|
+
const result = {};
|
|
80
|
+
for (const key of Object.keys(childMap)) {
|
|
81
|
+
const val = childMap[key];
|
|
82
|
+
if (val === INHERIT_VALUE) {
|
|
83
|
+
if (key in parentMap) result[key] = parentMap[key];
|
|
84
|
+
else if (devMode) console.warn(`[Tasty] @inherit used for state '${key}' that does not exist in the parent style map. Entry skipped.`);
|
|
85
|
+
} else if (val !== null) result[key] = val;
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Merge sub-element properties with state map / null / undefined support.
|
|
91
|
+
*/
|
|
92
|
+
function mergeSubElementStyles(parentSub, childSub) {
|
|
93
|
+
const parent = parentSub;
|
|
94
|
+
const child = childSub;
|
|
95
|
+
const merged = {
|
|
96
|
+
...parent,
|
|
97
|
+
...child
|
|
98
|
+
};
|
|
99
|
+
for (const key of Object.keys(child)) {
|
|
100
|
+
const val = child[key];
|
|
101
|
+
if (val === void 0) {
|
|
102
|
+
if (parent && key in parent) merged[key] = parent[key];
|
|
103
|
+
} else if (val === null) delete merged[key];
|
|
104
|
+
else if (isStateMap(val)) merged[key] = resolveStateMap(parent ? parent[key] : void 0, val);
|
|
105
|
+
}
|
|
106
|
+
return merged;
|
|
107
|
+
}
|
|
108
|
+
function mergeStyles(...objects) {
|
|
109
|
+
let styles = objects[0] ? { ...objects[0] } : {};
|
|
110
|
+
let pos = 1;
|
|
111
|
+
while (pos in objects) {
|
|
112
|
+
const selectorKeys = Object.keys(styles).filter((key) => isSelector(key) && styles[key]);
|
|
113
|
+
const newStyles = objects[pos];
|
|
114
|
+
if (newStyles) {
|
|
115
|
+
const resultStyles = {
|
|
116
|
+
...styles,
|
|
117
|
+
...newStyles
|
|
118
|
+
};
|
|
119
|
+
const newSelectorKeys = Object.keys(newStyles).filter(isSelector);
|
|
120
|
+
const allSelectorKeys = new Set([...selectorKeys, ...newSelectorKeys]);
|
|
121
|
+
for (const key of allSelectorKeys) {
|
|
122
|
+
const newValue = newStyles?.[key];
|
|
123
|
+
if (newValue === false || newValue === null) delete resultStyles[key];
|
|
124
|
+
else if (newValue === void 0) resultStyles[key] = styles[key];
|
|
125
|
+
else if (newValue) resultStyles[key] = mergeSubElementStyles(styles[key], newValue);
|
|
126
|
+
}
|
|
127
|
+
for (const key of Object.keys(newStyles)) {
|
|
128
|
+
if (isSelector(key)) continue;
|
|
129
|
+
const newValue = newStyles[key];
|
|
130
|
+
if (newValue === void 0) if (key in styles) resultStyles[key] = styles[key];
|
|
131
|
+
else delete resultStyles[key];
|
|
132
|
+
else if (newValue === null) delete resultStyles[key];
|
|
133
|
+
else if (isStateMap(newValue)) resultStyles[key] = resolveStateMap(styles[key], newValue);
|
|
134
|
+
}
|
|
135
|
+
styles = resultStyles;
|
|
136
|
+
}
|
|
137
|
+
pos++;
|
|
138
|
+
}
|
|
139
|
+
return styles;
|
|
140
|
+
}
|
|
141
|
+
//#endregion
|
|
142
|
+
export { mergeStyles as t };
|
|
143
|
+
|
|
144
|
+
//# sourceMappingURL=merge-styles-D_HbBOlq.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-styles-D_HbBOlq.js","names":[],"sources":["../src/utils/merge-styles.ts"],"sourcesContent":["import { isSelector } from '../pipeline';\nimport type { Styles, StylesWithoutSelectors } from '../styles/types';\n\nimport { isDevEnv } from './is-dev-env';\n\nconst devMode = isDevEnv();\n\nconst INHERIT_VALUE = '@inherit';\n\n/**\n * Check if a value is a state map (object, not array).\n */\nfunction isStateMap(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * Normalize a parent value to a state map.\n * - Already a state map → return as-is\n * - Non-null, non-false primitive → wrap as `{ '': value }`\n * - null / undefined / false → return null (no parent to merge with)\n */\nfunction normalizeToStateMap(value: unknown): Record<string, unknown> | null {\n if (isStateMap(value)) return value as Record<string, unknown>;\n if (value != null && value !== false) return { '': value };\n return null;\n}\n\n/**\n * Resolve a child state map against a parent value.\n *\n * Mode is determined by whether the child contains a `''` (default) key:\n * - No `''` → extend mode: parent entries preserved, child adds/overrides/repositions\n * - Has `''` → replace mode: child defines everything, `@inherit` cherry-picks from parent\n *\n * In both modes:\n * - `@inherit` value → resolve from parent state map\n * - `null` value → remove this state from the result\n * - `false` value → tombstone, persists through all layers, blocks recipe\n */\nfunction resolveStateMap(\n parentValue: unknown,\n childMap: Record<string, unknown>,\n): Record<string, unknown> {\n const isExtend = !('' in childMap);\n const parentMap = normalizeToStateMap(parentValue);\n\n if (!parentMap) {\n // No parent to merge with — strip nulls and @inherit, return child entries\n const result: Record<string, unknown> = {};\n for (const key of Object.keys(childMap)) {\n const val = childMap[key];\n if (val === null || val === INHERIT_VALUE) continue;\n result[key] = val;\n }\n return result;\n }\n\n if (isExtend) {\n return resolveExtendMode(parentMap, childMap);\n }\n\n return resolveReplaceMode(parentMap, childMap);\n}\n\n/**\n * Extend mode: parent entries are preserved, child entries add/override/reposition.\n */\nfunction resolveExtendMode(\n parentMap: Record<string, unknown>,\n childMap: Record<string, unknown>,\n): Record<string, unknown> {\n const inheritKeys = new Set<string>();\n const removeKeys = new Set<string>();\n const overrideKeys = new Map<string, unknown>();\n\n for (const key of Object.keys(childMap)) {\n const val = childMap[key];\n if (val === INHERIT_VALUE) {\n if (key in parentMap) {\n inheritKeys.add(key);\n } else if (devMode) {\n console.warn(\n `[Tasty] @inherit used for state '${key}' that does not exist in the parent style map. Entry skipped.`,\n );\n }\n } else if (val === null) {\n removeKeys.add(key);\n } else if (key in parentMap) {\n overrideKeys.set(key, val);\n }\n }\n\n // 1. Parent entries in order (skip removed, skip repositioned, apply overrides)\n const result: Record<string, unknown> = {};\n for (const key of Object.keys(parentMap)) {\n if (removeKeys.has(key)) continue;\n if (inheritKeys.has(key)) continue;\n if (overrideKeys.has(key)) {\n result[key] = overrideKeys.get(key);\n } else {\n result[key] = parentMap[key];\n }\n }\n\n // 2. Append new + repositioned entries in child declaration order\n for (const key of Object.keys(childMap)) {\n if (inheritKeys.has(key)) {\n result[key] = parentMap[key];\n } else if (\n !removeKeys.has(key) &&\n !overrideKeys.has(key) &&\n // Skip @inherit for keys that weren't in the parent (already warned above)\n childMap[key] !== INHERIT_VALUE\n ) {\n result[key] = childMap[key];\n }\n }\n\n return result;\n}\n\n/**\n * Replace mode: child entries define the result, `@inherit` pulls from parent.\n */\nfunction resolveReplaceMode(\n parentMap: Record<string, unknown>,\n childMap: Record<string, unknown>,\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n\n for (const key of Object.keys(childMap)) {\n const val = childMap[key];\n if (val === INHERIT_VALUE) {\n if (key in parentMap) {\n result[key] = parentMap[key];\n } else if (devMode) {\n console.warn(\n `[Tasty] @inherit used for state '${key}' that does not exist in the parent style map. Entry skipped.`,\n );\n }\n } else if (val !== null) {\n result[key] = val;\n }\n }\n\n return result;\n}\n\n/**\n * Merge sub-element properties with state map / null / undefined support.\n */\nfunction mergeSubElementStyles(\n parentSub: StylesWithoutSelectors | undefined,\n childSub: StylesWithoutSelectors,\n): StylesWithoutSelectors {\n const parent = parentSub as Record<string, unknown> | undefined;\n const child = childSub as Record<string, unknown>;\n const merged: Record<string, unknown> = { ...parent, ...child };\n\n for (const key of Object.keys(child)) {\n const val = child[key];\n\n if (val === undefined) {\n if (parent && key in parent) {\n merged[key] = parent[key];\n }\n } else if (val === null) {\n delete merged[key];\n } else if (isStateMap(val)) {\n merged[key] = resolveStateMap(\n parent ? parent[key] : undefined,\n val as Record<string, unknown>,\n );\n }\n }\n\n return merged as StylesWithoutSelectors;\n}\n\nexport function mergeStyles(...objects: (Styles | undefined | null)[]): Styles {\n let styles: Styles = objects[0] ? { ...objects[0] } : {};\n let pos = 1;\n\n while (pos in objects) {\n const selectorKeys = Object.keys(styles).filter(\n (key) => isSelector(key) && styles[key],\n );\n const newStyles = objects[pos];\n\n if (newStyles) {\n const resultStyles = { ...styles, ...newStyles };\n\n // Collect all selector keys from both parent and child\n const newSelectorKeys = Object.keys(newStyles).filter(isSelector);\n const allSelectorKeys = new Set([...selectorKeys, ...newSelectorKeys]);\n\n for (const key of allSelectorKeys) {\n const newValue = newStyles?.[key];\n\n if (newValue === false || newValue === null) {\n delete resultStyles[key];\n } else if (newValue === undefined) {\n resultStyles[key] = styles[key];\n } else if (newValue) {\n resultStyles[key] = mergeSubElementStyles(\n styles[key] as StylesWithoutSelectors,\n newValue as StylesWithoutSelectors,\n );\n }\n }\n\n // Handle non-selector properties: state maps, null, undefined\n for (const key of Object.keys(newStyles)) {\n if (isSelector(key)) continue;\n\n const newValue = newStyles[key];\n\n if (newValue === undefined) {\n if (key in styles) {\n resultStyles[key] = styles[key];\n } else {\n delete resultStyles[key];\n }\n } else if (newValue === null) {\n delete resultStyles[key];\n } else if (isStateMap(newValue)) {\n (resultStyles as Record<string, unknown>)[key] = resolveStateMap(\n styles[key],\n newValue as Record<string, unknown>,\n );\n }\n }\n\n styles = resultStyles;\n }\n\n pos++;\n }\n\n return styles;\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { b as isSelector, l as getGlobalRecipes, st as isDevEnv } from "./config-A237aY9H.js";
|
|
2
|
+
import { t as mergeStyles } from "./merge-styles-D_HbBOlq.js";
|
|
3
|
+
//#region src/utils/resolve-recipes.ts
|
|
4
|
+
/**
|
|
5
|
+
* Recipe resolution utility.
|
|
6
|
+
*
|
|
7
|
+
* Resolves `recipe` style properties by looking up predefined recipe styles
|
|
8
|
+
* from global configuration and merging them with the component's own styles.
|
|
9
|
+
*
|
|
10
|
+
* Resolution order per level (top-level and each sub-element independently):
|
|
11
|
+
* base_recipe_1 base_recipe_2 → component styles → post_recipe_1 post_recipe_2
|
|
12
|
+
*
|
|
13
|
+
* The `/` separator splits base recipes (before component styles)
|
|
14
|
+
* from post recipes (after component styles). All merges use mergeStyles
|
|
15
|
+
* semantics: primitives and state maps with '' key fully replace;
|
|
16
|
+
* state maps without '' key extend the existing value.
|
|
17
|
+
*
|
|
18
|
+
* Returns the same object reference if no recipes are present (zero overhead).
|
|
19
|
+
*/
|
|
20
|
+
const devMode = isDevEnv();
|
|
21
|
+
/**
|
|
22
|
+
* Parse a recipe string into base and post recipe name groups.
|
|
23
|
+
*
|
|
24
|
+
* Syntax: `'base1 base2 / post1 post2'`
|
|
25
|
+
* - Names are space-separated within each group
|
|
26
|
+
* - `/` separates base (before component) from post (after component) groups
|
|
27
|
+
* - `/` is optional; if absent, all names are base
|
|
28
|
+
* - `none` as the sole base value means "no base recipes"
|
|
29
|
+
*
|
|
30
|
+
* Returns `{ base: null, post: null }` if the string is empty or invalid.
|
|
31
|
+
*/
|
|
32
|
+
function parseRecipeNames(value) {
|
|
33
|
+
const empty = {
|
|
34
|
+
base: null,
|
|
35
|
+
post: null
|
|
36
|
+
};
|
|
37
|
+
if (typeof value !== "string") return empty;
|
|
38
|
+
const trimmed = value.trim();
|
|
39
|
+
if (trimmed === "") return empty;
|
|
40
|
+
const slashIndex = trimmed.indexOf("/");
|
|
41
|
+
if (slashIndex === -1) {
|
|
42
|
+
if (trimmed === "none") return empty;
|
|
43
|
+
return {
|
|
44
|
+
base: splitNames(trimmed),
|
|
45
|
+
post: null
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const basePart = trimmed.slice(0, slashIndex);
|
|
49
|
+
const postPart = trimmed.slice(slashIndex + 1);
|
|
50
|
+
return {
|
|
51
|
+
base: basePart.trim() === "none" ? null : splitNames(basePart),
|
|
52
|
+
post: splitNames(postPart)
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function splitNames(s) {
|
|
56
|
+
const names = s.split(/\s+/).filter(Boolean);
|
|
57
|
+
return names.length > 0 ? names : null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Collect merged styles for a list of recipe names.
|
|
61
|
+
* Each recipe is flat-spread on top of the previous.
|
|
62
|
+
*/
|
|
63
|
+
function collectRecipeStyles(names, recipes) {
|
|
64
|
+
let merged = {};
|
|
65
|
+
for (const name of names) {
|
|
66
|
+
const recipeStyles = recipes[name];
|
|
67
|
+
if (!recipeStyles) {
|
|
68
|
+
if (devMode) console.warn(`[Tasty] Recipe "${name}" not found. Make sure it is defined in configure({ recipes: { ... } }).`);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
merged = {
|
|
72
|
+
...merged,
|
|
73
|
+
...recipeStyles
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return merged;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Resolve recipe references in a flat styles object (no sub-elements).
|
|
80
|
+
* Returns null if no `recipe` key is present.
|
|
81
|
+
*
|
|
82
|
+
* Resolution: base recipes → component styles → post recipes (all via mergeStyles)
|
|
83
|
+
*/
|
|
84
|
+
function resolveRecipesForLevel(styles, recipes) {
|
|
85
|
+
if (!("recipe" in styles)) return null;
|
|
86
|
+
const { base, post } = parseRecipeNames(styles.recipe);
|
|
87
|
+
const { recipe: _recipe, ...allRest } = styles;
|
|
88
|
+
const flatStyles = {};
|
|
89
|
+
const selectorStyles = {};
|
|
90
|
+
for (const key of Object.keys(allRest)) if (isSelector(key)) selectorStyles[key] = allRest[key];
|
|
91
|
+
else flatStyles[key] = allRest[key];
|
|
92
|
+
if (!base && !post) return allRest;
|
|
93
|
+
let result;
|
|
94
|
+
if (base) result = mergeStyles(collectRecipeStyles(base, recipes), flatStyles);
|
|
95
|
+
else result = { ...flatStyles };
|
|
96
|
+
if (post) {
|
|
97
|
+
const postStyles = collectRecipeStyles(post, recipes);
|
|
98
|
+
result = mergeStyles(result, postStyles);
|
|
99
|
+
}
|
|
100
|
+
for (const key of Object.keys(selectorStyles)) result[key] = selectorStyles[key];
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Resolve all `recipe` style properties in a styles object.
|
|
105
|
+
*
|
|
106
|
+
* Handles both top-level and sub-element recipe references.
|
|
107
|
+
* Returns the same object reference if no recipes are present anywhere
|
|
108
|
+
* (zero overhead for the common case).
|
|
109
|
+
*
|
|
110
|
+
* @param styles - The styles object potentially containing `recipe` keys
|
|
111
|
+
* @returns Resolved styles with recipe values merged in, or the original object if unchanged
|
|
112
|
+
*/
|
|
113
|
+
function resolveRecipes(styles) {
|
|
114
|
+
const recipes = getGlobalRecipes();
|
|
115
|
+
if (!recipes) return styles;
|
|
116
|
+
let changed = false;
|
|
117
|
+
const topResolved = resolveRecipesForLevel(styles, recipes);
|
|
118
|
+
let result;
|
|
119
|
+
if (topResolved) {
|
|
120
|
+
changed = true;
|
|
121
|
+
result = topResolved;
|
|
122
|
+
} else result = styles;
|
|
123
|
+
const keys = Object.keys(result);
|
|
124
|
+
for (const key of keys) {
|
|
125
|
+
if (!isSelector(key)) continue;
|
|
126
|
+
const subStyles = result[key];
|
|
127
|
+
if (!subStyles || typeof subStyles !== "object" || Array.isArray(subStyles)) continue;
|
|
128
|
+
const subRecord = subStyles;
|
|
129
|
+
if (!("recipe" in subRecord)) continue;
|
|
130
|
+
const subResolved = resolveRecipesForLevel(subRecord, recipes);
|
|
131
|
+
if (subResolved) {
|
|
132
|
+
if (!changed) {
|
|
133
|
+
changed = true;
|
|
134
|
+
result = { ...styles };
|
|
135
|
+
}
|
|
136
|
+
result[key] = subResolved;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return changed ? result : styles;
|
|
140
|
+
}
|
|
141
|
+
//#endregion
|
|
142
|
+
export { resolveRecipes as t };
|
|
143
|
+
|
|
144
|
+
//# sourceMappingURL=resolve-recipes-B7-823LL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-recipes-B7-823LL.js","names":[],"sources":["../src/utils/resolve-recipes.ts"],"sourcesContent":["/**\n * Recipe resolution utility.\n *\n * Resolves `recipe` style properties by looking up predefined recipe styles\n * from global configuration and merging them with the component's own styles.\n *\n * Resolution order per level (top-level and each sub-element independently):\n * base_recipe_1 base_recipe_2 → component styles → post_recipe_1 post_recipe_2\n *\n * The `/` separator splits base recipes (before component styles)\n * from post recipes (after component styles). All merges use mergeStyles\n * semantics: primitives and state maps with '' key fully replace;\n * state maps without '' key extend the existing value.\n *\n * Returns the same object reference if no recipes are present (zero overhead).\n */\n\nimport { getGlobalRecipes } from '../config';\nimport { isSelector } from '../pipeline';\nimport type { RecipeStyles, Styles } from '../styles/types';\n\nimport { isDevEnv } from './is-dev-env';\nimport { mergeStyles } from './merge-styles';\n\nconst devMode = isDevEnv();\n\ninterface ParsedRecipeGroups {\n base: string[] | null;\n post: string[] | null;\n}\n\n/**\n * Parse a recipe string into base and post recipe name groups.\n *\n * Syntax: `'base1 base2 / post1 post2'`\n * - Names are space-separated within each group\n * - `/` separates base (before component) from post (after component) groups\n * - `/` is optional; if absent, all names are base\n * - `none` as the sole base value means \"no base recipes\"\n *\n * Returns `{ base: null, post: null }` if the string is empty or invalid.\n */\nfunction parseRecipeNames(value: unknown): ParsedRecipeGroups {\n const empty: ParsedRecipeGroups = { base: null, post: null };\n\n if (typeof value !== 'string') return empty;\n const trimmed = value.trim();\n if (trimmed === '') return empty;\n\n const slashIndex = trimmed.indexOf('/');\n\n if (slashIndex === -1) {\n if (trimmed === 'none') return empty;\n const names = splitNames(trimmed);\n return { base: names, post: null };\n }\n\n const basePart = trimmed.slice(0, slashIndex);\n const postPart = trimmed.slice(slashIndex + 1);\n\n return {\n base: basePart.trim() === 'none' ? null : splitNames(basePart),\n post: splitNames(postPart),\n };\n}\n\nfunction splitNames(s: string): string[] | null {\n const names = s.split(/\\s+/).filter(Boolean);\n return names.length > 0 ? names : null;\n}\n\n/**\n * Collect merged styles for a list of recipe names.\n * Each recipe is flat-spread on top of the previous.\n */\nfunction collectRecipeStyles(\n names: string[],\n recipes: Record<string, RecipeStyles>,\n): Record<string, unknown> {\n let merged: Record<string, unknown> = {};\n\n for (const name of names) {\n const recipeStyles = recipes[name];\n\n if (!recipeStyles) {\n if (devMode) {\n console.warn(\n `[Tasty] Recipe \"${name}\" not found. ` +\n `Make sure it is defined in configure({ recipes: { ... } }).`,\n );\n }\n continue;\n }\n\n merged = { ...merged, ...(recipeStyles as Record<string, unknown>) };\n }\n\n return merged;\n}\n\n/**\n * Resolve recipe references in a flat styles object (no sub-elements).\n * Returns null if no `recipe` key is present.\n *\n * Resolution: base recipes → component styles → post recipes (all via mergeStyles)\n */\nfunction resolveRecipesForLevel(\n styles: Record<string, unknown>,\n recipes: Record<string, RecipeStyles>,\n): Record<string, unknown> | null {\n if (!('recipe' in styles)) return null;\n\n const { base, post } = parseRecipeNames(styles.recipe);\n\n // Separate selector keys (sub-elements) from flat style properties.\n // mergeStyles handles selectors with its own semantics (e.g. false = delete),\n // but at this level we only want recipe merging on flat properties.\n\n const { recipe: _recipe, ...allRest } = styles;\n const flatStyles: Record<string, unknown> = {};\n const selectorStyles: Record<string, unknown> = {};\n\n for (const key of Object.keys(allRest)) {\n if (isSelector(key)) {\n selectorStyles[key] = allRest[key];\n } else {\n flatStyles[key] = allRest[key];\n }\n }\n\n if (!base && !post) {\n return allRest;\n }\n\n // 1. Merge base recipes, then component styles on top (via mergeStyles)\n let result: Record<string, unknown>;\n\n if (base) {\n const baseStyles = collectRecipeStyles(base, recipes);\n result = mergeStyles(baseStyles as Styles, flatStyles as Styles) as Record<\n string,\n unknown\n >;\n } else {\n result = { ...flatStyles };\n }\n\n // 2. Apply post recipes via mergeStyles (state map extend semantics)\n if (post) {\n const postStyles = collectRecipeStyles(post, recipes);\n result = mergeStyles(result as Styles, postStyles as Styles) as Record<\n string,\n unknown\n >;\n }\n\n // Re-attach selector keys unchanged\n for (const key of Object.keys(selectorStyles)) {\n result[key] = selectorStyles[key];\n }\n\n return result;\n}\n\n/**\n * Resolve all `recipe` style properties in a styles object.\n *\n * Handles both top-level and sub-element recipe references.\n * Returns the same object reference if no recipes are present anywhere\n * (zero overhead for the common case).\n *\n * @param styles - The styles object potentially containing `recipe` keys\n * @returns Resolved styles with recipe values merged in, or the original object if unchanged\n */\nexport function resolveRecipes(styles: Styles): Styles {\n const recipes = getGlobalRecipes();\n\n // Fast path: no recipes configured globally\n if (!recipes) return styles;\n\n let changed = false;\n\n // Resolve top-level recipe\n const topResolved = resolveRecipesForLevel(\n styles as Record<string, unknown>,\n recipes,\n );\n\n let result: Record<string, unknown>;\n\n if (topResolved) {\n changed = true;\n result = topResolved;\n } else {\n // Keep reference; a shallow copy is deferred until a sub-element actually changes\n result = styles as Record<string, unknown>;\n }\n\n // Resolve sub-element recipes\n const keys = Object.keys(result);\n\n for (const key of keys) {\n if (!isSelector(key)) continue;\n\n const subStyles = result[key];\n\n if (\n !subStyles ||\n typeof subStyles !== 'object' ||\n Array.isArray(subStyles)\n ) {\n continue;\n }\n\n const subRecord = subStyles as Record<string, unknown>;\n\n if (!('recipe' in subRecord)) continue;\n\n const subResolved = resolveRecipesForLevel(subRecord, recipes);\n\n if (subResolved) {\n if (!changed) {\n // First change in sub-elements -- need to shallow-copy the top level\n changed = true;\n result = { ...(styles as Record<string, unknown>) };\n }\n result[key] = subResolved;\n }\n }\n\n return changed ? (result as Styles) : styles;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwBA,MAAM,UAAU,UAAU;;;;;;;;;;;;AAkB1B,SAAS,iBAAiB,OAAoC;CAC5D,MAAM,QAA4B;EAAE,MAAM;EAAM,MAAM;EAAM;AAE5D,KAAI,OAAO,UAAU,SAAU,QAAO;CACtC,MAAM,UAAU,MAAM,MAAM;AAC5B,KAAI,YAAY,GAAI,QAAO;CAE3B,MAAM,aAAa,QAAQ,QAAQ,IAAI;AAEvC,KAAI,eAAe,IAAI;AACrB,MAAI,YAAY,OAAQ,QAAO;AAE/B,SAAO;GAAE,MADK,WAAW,QAAQ;GACX,MAAM;GAAM;;CAGpC,MAAM,WAAW,QAAQ,MAAM,GAAG,WAAW;CAC7C,MAAM,WAAW,QAAQ,MAAM,aAAa,EAAE;AAE9C,QAAO;EACL,MAAM,SAAS,MAAM,KAAK,SAAS,OAAO,WAAW,SAAS;EAC9D,MAAM,WAAW,SAAS;EAC3B;;AAGH,SAAS,WAAW,GAA4B;CAC9C,MAAM,QAAQ,EAAE,MAAM,MAAM,CAAC,OAAO,QAAQ;AAC5C,QAAO,MAAM,SAAS,IAAI,QAAQ;;;;;;AAOpC,SAAS,oBACP,OACA,SACyB;CACzB,IAAI,SAAkC,EAAE;AAExC,MAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,eAAe,QAAQ;AAE7B,MAAI,CAAC,cAAc;AACjB,OAAI,QACF,SAAQ,KACN,mBAAmB,KAAK,0EAEzB;AAEH;;AAGF,WAAS;GAAE,GAAG;GAAQ,GAAI;GAA0C;;AAGtE,QAAO;;;;;;;;AAST,SAAS,uBACP,QACA,SACgC;AAChC,KAAI,EAAE,YAAY,QAAS,QAAO;CAElC,MAAM,EAAE,MAAM,SAAS,iBAAiB,OAAO,OAAO;CAMtD,MAAM,EAAE,QAAQ,SAAS,GAAG,YAAY;CACxC,MAAM,aAAsC,EAAE;CAC9C,MAAM,iBAA0C,EAAE;AAElD,MAAK,MAAM,OAAO,OAAO,KAAK,QAAQ,CACpC,KAAI,WAAW,IAAI,CACjB,gBAAe,OAAO,QAAQ;KAE9B,YAAW,OAAO,QAAQ;AAI9B,KAAI,CAAC,QAAQ,CAAC,KACZ,QAAO;CAIT,IAAI;AAEJ,KAAI,KAEF,UAAS,YADU,oBAAoB,MAAM,QAAQ,EACV,WAAqB;KAKhE,UAAS,EAAE,GAAG,YAAY;AAI5B,KAAI,MAAM;EACR,MAAM,aAAa,oBAAoB,MAAM,QAAQ;AACrD,WAAS,YAAY,QAAkB,WAAqB;;AAO9D,MAAK,MAAM,OAAO,OAAO,KAAK,eAAe,CAC3C,QAAO,OAAO,eAAe;AAG/B,QAAO;;;;;;;;;;;;AAaT,SAAgB,eAAe,QAAwB;CACrD,MAAM,UAAU,kBAAkB;AAGlC,KAAI,CAAC,QAAS,QAAO;CAErB,IAAI,UAAU;CAGd,MAAM,cAAc,uBAClB,QACA,QACD;CAED,IAAI;AAEJ,KAAI,aAAa;AACf,YAAU;AACV,WAAS;OAGT,UAAS;CAIX,MAAM,OAAO,OAAO,KAAK,OAAO;AAEhC,MAAK,MAAM,OAAO,MAAM;AACtB,MAAI,CAAC,WAAW,IAAI,CAAE;EAEtB,MAAM,YAAY,OAAO;AAEzB,MACE,CAAC,aACD,OAAO,cAAc,YACrB,MAAM,QAAQ,UAAU,CAExB;EAGF,MAAM,YAAY;AAElB,MAAI,EAAE,YAAY,WAAY;EAE9B,MAAM,cAAc,uBAAuB,WAAW,QAAQ;AAE9D,MAAI,aAAa;AACf,OAAI,CAAC,SAAS;AAEZ,cAAU;AACV,aAAS,EAAE,GAAI,QAAoC;;AAErD,UAAO,OAAO;;;AAIlB,QAAO,UAAW,SAAoB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { n as hydrateTastyClasses } from "../hydrate-miFzWIKR.js";
|
|
2
|
+
//#region src/ssr/astro-client.ts
|
|
3
|
+
/**
|
|
4
|
+
* Client-side cache hydration for Astro islands.
|
|
5
|
+
*
|
|
6
|
+
* Reads the class name list from `window.__TASTY__` (populated by
|
|
7
|
+
* inline scripts emitted during SSR) and pre-populates the injector
|
|
8
|
+
* so island hydration skips the style pipeline entirely.
|
|
9
|
+
*
|
|
10
|
+
* This module is browser-safe — it does NOT import node:async_hooks.
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* - Automatically injected by tastyIntegration() via injectScript('before-hydration')
|
|
14
|
+
* - Can be imported manually: `import '@tenphi/tasty/ssr/astro-client'`
|
|
15
|
+
*/
|
|
16
|
+
if (typeof window !== "undefined") hydrateTastyClasses();
|
|
17
|
+
//#endregion
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=astro-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"astro-client.js","names":[],"sources":["../../src/ssr/astro-client.ts"],"sourcesContent":["/**\n * Client-side cache hydration for Astro islands.\n *\n * Reads the class name list from `window.__TASTY__` (populated by\n * inline scripts emitted during SSR) and pre-populates the injector\n * so island hydration skips the style pipeline entirely.\n *\n * This module is browser-safe — it does NOT import node:async_hooks.\n *\n * Usage:\n * - Automatically injected by tastyIntegration() via injectScript('before-hydration')\n * - Can be imported manually: `import '@tenphi/tasty/ssr/astro-client'`\n */\n\nimport { hydrateTastyClasses } from './hydrate';\n\nif (typeof window !== 'undefined') {\n hydrateTastyClasses();\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,IAAI,OAAO,WAAW,YACpB,sBAAqB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/ssr/astro-middleware.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Astro middleware entrypoint for tastyIntegration().
|
|
4
|
+
*
|
|
5
|
+
* Referenced by the integration via addMiddleware(). Not intended
|
|
6
|
+
* as a public package export — use tastyMiddleware() directly if
|
|
7
|
+
* you need manual middleware composition.
|
|
8
|
+
*
|
|
9
|
+
* The transferCache setting is controlled by setMiddlewareTransferCache(),
|
|
10
|
+
* called by tastyIntegration() before middleware is loaded.
|
|
11
|
+
*/
|
|
12
|
+
declare const onRequest: (_context: unknown, next: () => Promise<Response>) => Promise<Response>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { onRequest };
|
|
15
|
+
//# sourceMappingURL=astro-middleware.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getMiddlewareTransferCache, tastyMiddleware } from "./astro.js";
|
|
2
|
+
//#region src/ssr/astro-middleware.ts
|
|
3
|
+
/**
|
|
4
|
+
* Astro middleware entrypoint for tastyIntegration().
|
|
5
|
+
*
|
|
6
|
+
* Referenced by the integration via addMiddleware(). Not intended
|
|
7
|
+
* as a public package export — use tastyMiddleware() directly if
|
|
8
|
+
* you need manual middleware composition.
|
|
9
|
+
*
|
|
10
|
+
* The transferCache setting is controlled by setMiddlewareTransferCache(),
|
|
11
|
+
* called by tastyIntegration() before middleware is loaded.
|
|
12
|
+
*/
|
|
13
|
+
const onRequest = tastyMiddleware({ get transferCache() {
|
|
14
|
+
return getMiddlewareTransferCache();
|
|
15
|
+
} });
|
|
16
|
+
//#endregion
|
|
17
|
+
export { onRequest };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=astro-middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"astro-middleware.js","names":[],"sources":["../../src/ssr/astro-middleware.ts"],"sourcesContent":["/**\n * Astro middleware entrypoint for tastyIntegration().\n *\n * Referenced by the integration via addMiddleware(). Not intended\n * as a public package export — use tastyMiddleware() directly if\n * you need manual middleware composition.\n *\n * The transferCache setting is controlled by setMiddlewareTransferCache(),\n * called by tastyIntegration() before middleware is loaded.\n */\n\nimport { getMiddlewareTransferCache, tastyMiddleware } from './astro';\n\nexport const onRequest = tastyMiddleware({\n get transferCache() {\n return getMiddlewareTransferCache();\n },\n});\n"],"mappings":";;;;;;;;;;;;AAaA,MAAa,YAAY,gBAAgB,EACvC,IAAI,gBAAgB;AAClB,QAAO,4BAA4B;GAEtC,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
//#region src/ssr/astro.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Astro integration for Tasty SSR.
|
|
4
|
+
*
|
|
5
|
+
* Provides:
|
|
6
|
+
* - tastyIntegration() — Astro Integration API (recommended)
|
|
7
|
+
* - tastyMiddleware() — manual middleware for advanced composition
|
|
8
|
+
*
|
|
9
|
+
* Import from '@tenphi/tasty/ssr/astro'.
|
|
10
|
+
*/
|
|
11
|
+
interface TastyMiddlewareOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Whether to embed the class-list script for client hydration.
|
|
14
|
+
* Set to false to skip class transfer (e.g. for CSP restrictions).
|
|
15
|
+
* Without it, client components may re-inject CSS that already exists
|
|
16
|
+
* in server-rendered `<style>` tags. Default: true.
|
|
17
|
+
*/
|
|
18
|
+
transferCache?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create an Astro middleware that collects Tasty styles during SSR.
|
|
22
|
+
*
|
|
23
|
+
* All React components rendered during the request will have their
|
|
24
|
+
* computeStyles() calls captured by the collector via AsyncLocalStorage.
|
|
25
|
+
* After rendering, the middleware injects the collected CSS into </head>.
|
|
26
|
+
*
|
|
27
|
+
* @example Manual middleware setup
|
|
28
|
+
* ```ts
|
|
29
|
+
* // src/middleware.ts
|
|
30
|
+
* import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
|
|
31
|
+
* export const onRequest = tastyMiddleware();
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example Composing with other middleware
|
|
35
|
+
* ```ts
|
|
36
|
+
* // src/middleware.ts
|
|
37
|
+
* import { sequence } from 'astro:middleware';
|
|
38
|
+
* import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
|
|
39
|
+
*
|
|
40
|
+
* export const onRequest = sequence(
|
|
41
|
+
* tastyMiddleware(),
|
|
42
|
+
* myOtherMiddleware,
|
|
43
|
+
* );
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
declare function tastyMiddleware(options?: TastyMiddlewareOptions): (_context: unknown, next: () => Promise<Response>) => Promise<Response>;
|
|
47
|
+
/** @internal */
|
|
48
|
+
declare function setMiddlewareTransferCache(value: boolean): void;
|
|
49
|
+
/** @internal */
|
|
50
|
+
declare function getMiddlewareTransferCache(): boolean;
|
|
51
|
+
interface TastyIntegrationOptions {
|
|
52
|
+
/**
|
|
53
|
+
* Enable island hydration support.
|
|
54
|
+
*
|
|
55
|
+
* When `true` (default): injects a client hydration script via
|
|
56
|
+
* `injectScript('before-hydration')` and sets `transferCache: true`
|
|
57
|
+
* on the middleware. Islands skip the style pipeline during hydration.
|
|
58
|
+
*
|
|
59
|
+
* When `false`: no client JS is shipped and `transferCache` is set
|
|
60
|
+
* to `false`. Use this for fully static sites without `client:*`
|
|
61
|
+
* directives.
|
|
62
|
+
*/
|
|
63
|
+
islands?: boolean;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Astro integration that automatically sets up Tasty SSR.
|
|
67
|
+
*
|
|
68
|
+
* Registers middleware for cross-component CSS deduplication and
|
|
69
|
+
* optionally injects a client hydration script for island support.
|
|
70
|
+
*
|
|
71
|
+
* @example Basic setup (with islands)
|
|
72
|
+
* ```ts
|
|
73
|
+
* // astro.config.mjs
|
|
74
|
+
* import { tastyIntegration } from '@tenphi/tasty/ssr/astro';
|
|
75
|
+
*
|
|
76
|
+
* export default defineConfig({
|
|
77
|
+
* integrations: [tastyIntegration()],
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @example Static-only (no client JS)
|
|
82
|
+
* ```ts
|
|
83
|
+
* // astro.config.mjs
|
|
84
|
+
* import { tastyIntegration } from '@tenphi/tasty/ssr/astro';
|
|
85
|
+
*
|
|
86
|
+
* export default defineConfig({
|
|
87
|
+
* integrations: [tastyIntegration({ islands: false })],
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
declare function tastyIntegration(options?: TastyIntegrationOptions): {
|
|
92
|
+
name: string;
|
|
93
|
+
hooks: Record<string, (...args: never[]) => void>;
|
|
94
|
+
};
|
|
95
|
+
//#endregion
|
|
96
|
+
export { TastyIntegrationOptions, TastyMiddlewareOptions, getMiddlewareTransferCache, setMiddlewareTransferCache, tastyIntegration, tastyMiddleware };
|
|
97
|
+
//# sourceMappingURL=astro.d.ts.map
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { n as getConfig } from "../config-A237aY9H.js";
|
|
2
|
+
import { a as registerSSRCollectorGetterGlobal } from "../format-rules-C2oiTsEO.js";
|
|
3
|
+
import { t as ServerStyleCollector } from "../collector-MOYY2SOr.js";
|
|
4
|
+
import { n as runWithCollector, t as getSSRCollector } from "../async-storage-B7_o6FKt.js";
|
|
5
|
+
//#region src/ssr/astro.ts
|
|
6
|
+
/**
|
|
7
|
+
* Astro integration for Tasty SSR.
|
|
8
|
+
*
|
|
9
|
+
* Provides:
|
|
10
|
+
* - tastyIntegration() — Astro Integration API (recommended)
|
|
11
|
+
* - tastyMiddleware() — manual middleware for advanced composition
|
|
12
|
+
*
|
|
13
|
+
* Import from '@tenphi/tasty/ssr/astro'.
|
|
14
|
+
*/
|
|
15
|
+
registerSSRCollectorGetterGlobal(getSSRCollector);
|
|
16
|
+
/**
|
|
17
|
+
* Create an Astro middleware that collects Tasty styles during SSR.
|
|
18
|
+
*
|
|
19
|
+
* All React components rendered during the request will have their
|
|
20
|
+
* computeStyles() calls captured by the collector via AsyncLocalStorage.
|
|
21
|
+
* After rendering, the middleware injects the collected CSS into </head>.
|
|
22
|
+
*
|
|
23
|
+
* @example Manual middleware setup
|
|
24
|
+
* ```ts
|
|
25
|
+
* // src/middleware.ts
|
|
26
|
+
* import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
|
|
27
|
+
* export const onRequest = tastyMiddleware();
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example Composing with other middleware
|
|
31
|
+
* ```ts
|
|
32
|
+
* // src/middleware.ts
|
|
33
|
+
* import { sequence } from 'astro:middleware';
|
|
34
|
+
* import { tastyMiddleware } from '@tenphi/tasty/ssr/astro';
|
|
35
|
+
*
|
|
36
|
+
* export const onRequest = sequence(
|
|
37
|
+
* tastyMiddleware(),
|
|
38
|
+
* myOtherMiddleware,
|
|
39
|
+
* );
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
function tastyMiddleware(options) {
|
|
43
|
+
return async (_context, next) => {
|
|
44
|
+
const transferCache = options?.transferCache ?? true;
|
|
45
|
+
const collector = new ServerStyleCollector();
|
|
46
|
+
const rendered = await runWithCollector(collector, async () => {
|
|
47
|
+
const response = await next();
|
|
48
|
+
const body = response.body;
|
|
49
|
+
if (!body) return {
|
|
50
|
+
html: null,
|
|
51
|
+
status: response.status,
|
|
52
|
+
headers: response.headers
|
|
53
|
+
};
|
|
54
|
+
const reader = body.pipeThrough(new TextDecoderStream()).getReader();
|
|
55
|
+
const parts = [];
|
|
56
|
+
for (;;) {
|
|
57
|
+
const { done, value } = await reader.read();
|
|
58
|
+
if (done) break;
|
|
59
|
+
parts.push(value);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
html: parts.join(""),
|
|
63
|
+
status: response.status,
|
|
64
|
+
headers: response.headers
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
if (!rendered.html) return new Response(null, {
|
|
68
|
+
status: rendered.status,
|
|
69
|
+
headers: rendered.headers
|
|
70
|
+
});
|
|
71
|
+
let { html } = rendered;
|
|
72
|
+
const css = collector.getCSS();
|
|
73
|
+
if (!css) return new Response(html, {
|
|
74
|
+
status: rendered.status,
|
|
75
|
+
headers: rendered.headers
|
|
76
|
+
});
|
|
77
|
+
const nonce = getConfig().nonce;
|
|
78
|
+
const nonceAttr = nonce ? ` nonce="${nonce}"` : "";
|
|
79
|
+
const styleTag = `<style data-tasty-ssr${nonceAttr}>${css}</style>`;
|
|
80
|
+
let cacheTag = "";
|
|
81
|
+
if (transferCache) {
|
|
82
|
+
const classNames = collector.getRenderedClassNames();
|
|
83
|
+
if (classNames.length > 0) cacheTag = `<script${nonceAttr}>(window.__TASTY__=window.__TASTY__||[]).push(${classNames.map((n) => `"${n}"`).join(",")})<\/script>`;
|
|
84
|
+
}
|
|
85
|
+
const injection = styleTag + cacheTag;
|
|
86
|
+
const idx = html.indexOf("</head>");
|
|
87
|
+
if (idx !== -1) html = html.slice(0, idx) + injection + html.slice(idx);
|
|
88
|
+
else html = injection + html;
|
|
89
|
+
const headers = new Headers(rendered.headers);
|
|
90
|
+
headers.delete("content-length");
|
|
91
|
+
return new Response(html, {
|
|
92
|
+
status: rendered.status,
|
|
93
|
+
headers
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
let _middlewareTransferCache = true;
|
|
98
|
+
/** @internal */
|
|
99
|
+
function setMiddlewareTransferCache(value) {
|
|
100
|
+
_middlewareTransferCache = value;
|
|
101
|
+
}
|
|
102
|
+
/** @internal */
|
|
103
|
+
function getMiddlewareTransferCache() {
|
|
104
|
+
return _middlewareTransferCache;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Astro integration that automatically sets up Tasty SSR.
|
|
108
|
+
*
|
|
109
|
+
* Registers middleware for cross-component CSS deduplication and
|
|
110
|
+
* optionally injects a client hydration script for island support.
|
|
111
|
+
*
|
|
112
|
+
* @example Basic setup (with islands)
|
|
113
|
+
* ```ts
|
|
114
|
+
* // astro.config.mjs
|
|
115
|
+
* import { tastyIntegration } from '@tenphi/tasty/ssr/astro';
|
|
116
|
+
*
|
|
117
|
+
* export default defineConfig({
|
|
118
|
+
* integrations: [tastyIntegration()],
|
|
119
|
+
* });
|
|
120
|
+
* ```
|
|
121
|
+
*
|
|
122
|
+
* @example Static-only (no client JS)
|
|
123
|
+
* ```ts
|
|
124
|
+
* // astro.config.mjs
|
|
125
|
+
* import { tastyIntegration } from '@tenphi/tasty/ssr/astro';
|
|
126
|
+
*
|
|
127
|
+
* export default defineConfig({
|
|
128
|
+
* integrations: [tastyIntegration({ islands: false })],
|
|
129
|
+
* });
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
function tastyIntegration(options) {
|
|
133
|
+
const { islands = true } = options ?? {};
|
|
134
|
+
setMiddlewareTransferCache(islands);
|
|
135
|
+
return {
|
|
136
|
+
name: "@tenphi/tasty",
|
|
137
|
+
hooks: { "astro:config:setup": ({ addMiddleware, injectScript }) => {
|
|
138
|
+
addMiddleware({
|
|
139
|
+
entrypoint: new URL("./astro-middleware.js", import.meta.url),
|
|
140
|
+
order: "pre"
|
|
141
|
+
});
|
|
142
|
+
if (islands) injectScript("before-hydration", `import "@tenphi/tasty/ssr/astro-client";`);
|
|
143
|
+
} }
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
//#endregion
|
|
147
|
+
export { getMiddlewareTransferCache, setMiddlewareTransferCache, tastyIntegration, tastyMiddleware };
|
|
148
|
+
|
|
149
|
+
//# sourceMappingURL=astro.js.map
|