typestyles 0.1.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/dist/chunk-PFDN4Y4C.js +195 -0
- package/dist/chunk-PFDN4Y4C.js.map +1 -0
- package/dist/hmr-CSDtaPpU.d.cts +36 -0
- package/dist/hmr-CSDtaPpU.d.ts +36 -0
- package/dist/hmr.cjs +33 -0
- package/dist/hmr.cjs.map +1 -0
- package/dist/hmr.d.cts +1 -0
- package/dist/hmr.d.ts +1 -0
- package/dist/hmr.js +3 -0
- package/dist/hmr.js.map +1 -0
- package/dist/index.cjs +407 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +477 -0
- package/dist/index.d.ts +477 -0
- package/dist/index.js +326 -0
- package/dist/index.js.map +1 -0
- package/dist/server.cjs +74 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +34 -0
- package/dist/server.d.ts +34 -0
- package/dist/server.js +15 -0
- package/dist/server.js.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/sheet.ts
|
|
8
|
+
var STYLE_ELEMENT_ID = "typestyles";
|
|
9
|
+
var insertedRules = /* @__PURE__ */ new Set();
|
|
10
|
+
var pendingRules = [];
|
|
11
|
+
var allRules = [];
|
|
12
|
+
var flushScheduled = false;
|
|
13
|
+
var styleElement = null;
|
|
14
|
+
var ssrBuffer = null;
|
|
15
|
+
var isBrowser = typeof document !== "undefined" && typeof window !== "undefined";
|
|
16
|
+
function getStyleElement() {
|
|
17
|
+
if (styleElement) return styleElement;
|
|
18
|
+
const existing = document.getElementById(
|
|
19
|
+
STYLE_ELEMENT_ID
|
|
20
|
+
);
|
|
21
|
+
if (existing) {
|
|
22
|
+
styleElement = existing;
|
|
23
|
+
return styleElement;
|
|
24
|
+
}
|
|
25
|
+
styleElement = document.createElement("style");
|
|
26
|
+
styleElement.id = STYLE_ELEMENT_ID;
|
|
27
|
+
document.head.appendChild(styleElement);
|
|
28
|
+
return styleElement;
|
|
29
|
+
}
|
|
30
|
+
function flush() {
|
|
31
|
+
flushScheduled = false;
|
|
32
|
+
if (pendingRules.length === 0) return;
|
|
33
|
+
const rules = pendingRules;
|
|
34
|
+
pendingRules = [];
|
|
35
|
+
if (ssrBuffer) {
|
|
36
|
+
ssrBuffer.push(...rules);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (!isBrowser) return;
|
|
40
|
+
const el = getStyleElement();
|
|
41
|
+
const sheet = el.sheet;
|
|
42
|
+
if (sheet) {
|
|
43
|
+
for (const rule of rules) {
|
|
44
|
+
try {
|
|
45
|
+
sheet.insertRule(rule, sheet.cssRules.length);
|
|
46
|
+
} catch {
|
|
47
|
+
el.appendChild(document.createTextNode(rule));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
el.appendChild(document.createTextNode(rules.join("\n")));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function scheduleFlush() {
|
|
55
|
+
if (flushScheduled) return;
|
|
56
|
+
flushScheduled = true;
|
|
57
|
+
if (ssrBuffer) {
|
|
58
|
+
flush();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (isBrowser) {
|
|
62
|
+
queueMicrotask(flush);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function insertRule(key, css) {
|
|
66
|
+
if (insertedRules.has(key)) return;
|
|
67
|
+
insertedRules.add(key);
|
|
68
|
+
pendingRules.push(css);
|
|
69
|
+
allRules.push(css);
|
|
70
|
+
scheduleFlush();
|
|
71
|
+
}
|
|
72
|
+
function insertRules(rules) {
|
|
73
|
+
let added = false;
|
|
74
|
+
for (const { key, css } of rules) {
|
|
75
|
+
if (insertedRules.has(key)) continue;
|
|
76
|
+
insertedRules.add(key);
|
|
77
|
+
pendingRules.push(css);
|
|
78
|
+
allRules.push(css);
|
|
79
|
+
added = true;
|
|
80
|
+
}
|
|
81
|
+
if (added) scheduleFlush();
|
|
82
|
+
}
|
|
83
|
+
function startCollection() {
|
|
84
|
+
ssrBuffer = [];
|
|
85
|
+
return () => {
|
|
86
|
+
const css = ssrBuffer ? ssrBuffer.join("\n") : "";
|
|
87
|
+
ssrBuffer = null;
|
|
88
|
+
return css;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function getRegisteredCss() {
|
|
92
|
+
return allRules.join("\n");
|
|
93
|
+
}
|
|
94
|
+
function flushSync() {
|
|
95
|
+
flush();
|
|
96
|
+
}
|
|
97
|
+
function invalidatePrefix(prefix) {
|
|
98
|
+
for (const key of insertedRules) {
|
|
99
|
+
if (key.startsWith(prefix)) {
|
|
100
|
+
insertedRules.delete(key);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (!isBrowser) return;
|
|
104
|
+
const el = styleElement;
|
|
105
|
+
if (!el) return;
|
|
106
|
+
const sheet = el.sheet;
|
|
107
|
+
if (!sheet) return;
|
|
108
|
+
for (let i = sheet.cssRules.length - 1; i >= 0; i--) {
|
|
109
|
+
const rule = sheet.cssRules[i];
|
|
110
|
+
if (ruleMatchesPrefix(rule, prefix)) {
|
|
111
|
+
sheet.deleteRule(i);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function invalidateKeys(keys, prefixes) {
|
|
116
|
+
for (const key of keys) {
|
|
117
|
+
insertedRules.delete(key);
|
|
118
|
+
}
|
|
119
|
+
for (const prefix of prefixes) {
|
|
120
|
+
for (const key of insertedRules) {
|
|
121
|
+
if (key.startsWith(prefix)) {
|
|
122
|
+
insertedRules.delete(key);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (!isBrowser) return;
|
|
127
|
+
const el = styleElement;
|
|
128
|
+
if (!el) return;
|
|
129
|
+
const sheet = el.sheet;
|
|
130
|
+
if (!sheet) return;
|
|
131
|
+
const keySet = new Set(keys);
|
|
132
|
+
for (let i = sheet.cssRules.length - 1; i >= 0; i--) {
|
|
133
|
+
const rule = sheet.cssRules[i];
|
|
134
|
+
let shouldRemove = false;
|
|
135
|
+
for (const prefix of prefixes) {
|
|
136
|
+
if (ruleMatchesPrefix(rule, prefix)) {
|
|
137
|
+
shouldRemove = true;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (!shouldRemove) {
|
|
142
|
+
const ruleText = rule.cssText;
|
|
143
|
+
for (const key of keySet) {
|
|
144
|
+
if (ruleMatchesKey(ruleText, key)) {
|
|
145
|
+
shouldRemove = true;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (shouldRemove) {
|
|
151
|
+
sheet.deleteRule(i);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function ruleMatchesPrefix(rule, prefix) {
|
|
156
|
+
if (prefix.startsWith("font-face:")) {
|
|
157
|
+
const family = prefix.slice("font-face:".length).split(":")[0];
|
|
158
|
+
if (rule.cssText.includes("@font-face")) {
|
|
159
|
+
return rule.cssText.includes(`"${family}"`) || rule.cssText.includes(`'${family}'`);
|
|
160
|
+
}
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
if ("selectorText" in rule) {
|
|
164
|
+
return rule.selectorText.startsWith(prefix);
|
|
165
|
+
}
|
|
166
|
+
if ("name" in rule && prefix.startsWith("keyframes:")) {
|
|
167
|
+
return rule.name === prefix.slice("keyframes:".length);
|
|
168
|
+
}
|
|
169
|
+
if ("cssRules" in rule) {
|
|
170
|
+
const innerRules = rule.cssRules;
|
|
171
|
+
for (let i = 0; i < innerRules.length; i++) {
|
|
172
|
+
if (ruleMatchesPrefix(innerRules[i], prefix)) return true;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
function ruleMatchesKey(cssText, key) {
|
|
178
|
+
if (key.startsWith("tokens:")) {
|
|
179
|
+
const namespace = key.slice("tokens:".length);
|
|
180
|
+
return cssText.includes(`:root`) && cssText.includes(`--${namespace}-`);
|
|
181
|
+
}
|
|
182
|
+
if (key.startsWith("theme:")) {
|
|
183
|
+
const name = key.slice("theme:".length);
|
|
184
|
+
return cssText.includes(`.theme-${name}`);
|
|
185
|
+
}
|
|
186
|
+
if (key.startsWith("keyframes:")) {
|
|
187
|
+
const name = key.slice("keyframes:".length);
|
|
188
|
+
return cssText.includes(`@keyframes ${name}`);
|
|
189
|
+
}
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export { __export, flushSync, getRegisteredCss, insertRule, insertRules, invalidateKeys, invalidatePrefix, startCollection };
|
|
194
|
+
//# sourceMappingURL=chunk-PFDN4Y4C.js.map
|
|
195
|
+
//# sourceMappingURL=chunk-PFDN4Y4C.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sheet.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAM,gBAAA,GAAmB,YAAA;AAKzB,IAAM,aAAA,uBAAoB,GAAA,EAAY;AAKtC,IAAI,eAAyB,EAAC;AAO9B,IAAM,WAAqB,EAAC;AAK5B,IAAI,cAAA,GAAiB,KAAA;AAKrB,IAAI,YAAA,GAAwC,IAAA;AAK5C,IAAI,SAAA,GAA6B,IAAA;AAKjC,IAAM,SAAA,GACJ,OAAO,QAAA,KAAa,WAAA,IAAe,OAAO,MAAA,KAAW,WAAA;AAEvD,SAAS,eAAA,GAAoC;AAC3C,EAAA,IAAI,cAAc,OAAO,YAAA;AAGzB,EAAA,MAAM,WAAW,QAAA,CAAS,cAAA;AAAA,IACxB;AAAA,GACF;AACA,EAAA,IAAI,QAAA,EAAU;AACZ,IAAA,YAAA,GAAe,QAAA;AACf,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GAAA,CAAI,UAAA,CAAW,YAAY,CAAA,EAAG;AAChC,IAAA,MAAM,IAAA,GAAO,GAAA,CAAI,KAAA,CAAM,YAAA,CAAa,MAAM,CAAA;AAC1C,IAAA,OAAO,OAAA,CAAQ,QAAA,CAAS,CAAA,WAAA,EAAc,IAAI,CAAA,CAAE,CAAA;AAAA,EAC9C;AACA,EAAA,OAAO,KAAA;AACT","file":"chunk-PFDN4Y4C.js","sourcesContent":["const STYLE_ELEMENT_ID = 'typestyles';\n\n/**\n * Tracks which CSS rules have been inserted to avoid duplicates.\n */\nconst insertedRules = new Set<string>();\n\n/**\n * Buffer of CSS rules waiting to be flushed.\n */\nlet pendingRules: string[] = [];\n\n/**\n * All CSS rules ever registered (for SSR extraction).\n * Unlike pendingRules (which is cleared on flush), this retains every rule\n * so getRegisteredCss() can return the full stylesheet at any point.\n */\nconst allRules: string[] = [];\n\n/**\n * Whether a flush is scheduled.\n */\nlet flushScheduled = false;\n\n/**\n * The managed <style> element, lazily created.\n */\nlet styleElement: HTMLStyleElement | null = null;\n\n/**\n * When in SSR collection mode, CSS is captured here instead of injected.\n */\nlet ssrBuffer: string[] | null = null;\n\n/**\n * Whether we're running in a browser environment.\n */\nconst isBrowser =\n typeof document !== 'undefined' && typeof window !== 'undefined';\n\nfunction getStyleElement(): HTMLStyleElement {\n if (styleElement) return styleElement;\n\n // Check for an existing element (e.g., from SSR)\n const existing = document.getElementById(\n STYLE_ELEMENT_ID\n ) as HTMLStyleElement | null;\n if (existing) {\n styleElement = existing;\n return styleElement;\n }\n\n // Create a new one\n styleElement = document.createElement('style');\n styleElement.id = STYLE_ELEMENT_ID;\n document.head.appendChild(styleElement);\n return styleElement;\n}\n\nfunction flush(): void {\n flushScheduled = false;\n if (pendingRules.length === 0) return;\n\n const rules = pendingRules;\n pendingRules = [];\n\n if (ssrBuffer) {\n ssrBuffer.push(...rules);\n return;\n }\n\n if (!isBrowser) return;\n\n const el = getStyleElement();\n const sheet = el.sheet;\n\n if (sheet) {\n for (const rule of rules) {\n try {\n sheet.insertRule(rule, sheet.cssRules.length);\n } catch {\n // Fallback: append as text (handles edge cases with certain selectors)\n el.appendChild(document.createTextNode(rule));\n }\n }\n } else {\n // Sheet not available yet, append as text\n el.appendChild(document.createTextNode(rules.join('\\n')));\n }\n}\n\nfunction scheduleFlush(): void {\n if (flushScheduled) return;\n flushScheduled = true;\n\n if (ssrBuffer) {\n // In SSR mode, flush synchronously\n flush();\n return;\n }\n\n if (isBrowser) {\n // Use microtask for fast, batched insertion\n queueMicrotask(flush);\n }\n}\n\n/**\n * Insert a CSS rule. Deduplicates by rule key.\n */\nexport function insertRule(key: string, css: string): void {\n if (insertedRules.has(key)) return;\n insertedRules.add(key);\n pendingRules.push(css);\n allRules.push(css);\n scheduleFlush();\n}\n\n/**\n * Insert multiple CSS rules at once.\n */\nexport function insertRules(rules: Array<{ key: string; css: string }>): void {\n let added = false;\n for (const { key, css } of rules) {\n if (insertedRules.has(key)) continue;\n insertedRules.add(key);\n pendingRules.push(css);\n allRules.push(css);\n added = true;\n }\n if (added) scheduleFlush();\n}\n\n/**\n * Replace a CSS rule (used for HMR). Removes the old rule and inserts the new one.\n */\nexport function replaceRule(key: string, css: string): void {\n if (!isBrowser) return;\n\n insertedRules.delete(key);\n\n // Remove existing rule from the sheet if possible\n const el = getStyleElement();\n const sheet = el.sheet;\n if (sheet) {\n for (let i = sheet.cssRules.length - 1; i >= 0; i--) {\n // We can't reliably match by key in CSSOM, so for HMR we fall back to\n // clearing and re-inserting. This is fine since HMR is dev-only.\n }\n }\n\n insertRule(key, css);\n}\n\n/**\n * Start collecting CSS for SSR. Returns a function to stop collection and get the CSS.\n */\nexport function startCollection(): () => string {\n ssrBuffer = [];\n return () => {\n const css = ssrBuffer ? ssrBuffer.join('\\n') : '';\n ssrBuffer = null;\n return css;\n };\n}\n\n/**\n * Return all registered CSS as a string.\n *\n * Unlike `collectStyles`, this doesn't require wrapping a render function.\n * It simply returns every CSS rule that has been registered via\n * `styles.create`, `tokens.create`, `keyframes.create`, etc.\n *\n * Ideal for SSR frameworks that need the CSS separately from the render\n * pass (e.g. TanStack Start's `head()`, Next.js metadata, Remix links).\n *\n * @example\n * ```ts\n * import { getRegisteredCss } from 'typestyles/server';\n *\n * // In a route's head/meta function:\n * export const head = () => ({\n * styles: [{ id: 'typestyles', children: getRegisteredCss() }],\n * });\n * ```\n */\nexport function getRegisteredCss(): string {\n return allRules.join('\\n');\n}\n\n/**\n * Reset all state (useful for testing).\n */\nexport function reset(): void {\n insertedRules.clear();\n pendingRules = [];\n allRules.length = 0;\n flushScheduled = false;\n ssrBuffer = null;\n if (isBrowser && styleElement) {\n styleElement.remove();\n styleElement = null;\n }\n}\n\n/**\n * Flush all pending rules synchronously. Used for SSR and testing.\n */\nexport function flushSync(): void {\n flush();\n}\n\n/**\n * Invalidate all dedup keys that start with the given prefix.\n * Also removes matching rules from the live stylesheet.\n * Used for HMR — allows modules to re-register their styles after editing.\n */\nexport function invalidatePrefix(prefix: string): void {\n for (const key of insertedRules) {\n if (key.startsWith(prefix)) {\n insertedRules.delete(key);\n }\n }\n\n if (!isBrowser) return;\n\n const el = styleElement;\n if (!el) return;\n const sheet = el.sheet;\n if (!sheet) return;\n\n for (let i = sheet.cssRules.length - 1; i >= 0; i--) {\n const rule = sheet.cssRules[i];\n if (ruleMatchesPrefix(rule, prefix)) {\n sheet.deleteRule(i);\n }\n }\n}\n\n/**\n * Invalidate a list of exact keys or prefixes.\n * Each entry in `keys` is treated as an exact key match.\n * Each entry in `prefixes` is treated as a prefix match.\n * Used for HMR to invalidate all styles from a module at once.\n */\nexport function invalidateKeys(keys: string[], prefixes: string[]): void {\n for (const key of keys) {\n insertedRules.delete(key);\n }\n for (const prefix of prefixes) {\n for (const key of insertedRules) {\n if (key.startsWith(prefix)) {\n insertedRules.delete(key);\n }\n }\n }\n\n if (!isBrowser) return;\n\n const el = styleElement;\n if (!el) return;\n const sheet = el.sheet;\n if (!sheet) return;\n\n const keySet = new Set(keys);\n for (let i = sheet.cssRules.length - 1; i >= 0; i--) {\n const rule = sheet.cssRules[i];\n let shouldRemove = false;\n\n for (const prefix of prefixes) {\n if (ruleMatchesPrefix(rule, prefix)) {\n shouldRemove = true;\n break;\n }\n }\n\n if (!shouldRemove) {\n // Check exact key matches — for tokens/themes/keyframes,\n // we match based on rule content patterns\n const ruleText = rule.cssText;\n for (const key of keySet) {\n if (ruleMatchesKey(ruleText, key)) {\n shouldRemove = true;\n break;\n }\n }\n }\n\n if (shouldRemove) {\n sheet.deleteRule(i);\n }\n }\n}\n\nfunction ruleMatchesPrefix(rule: CSSRule, prefix: string): boolean {\n if (prefix.startsWith('font-face:')) {\n const family = prefix.slice('font-face:'.length).split(':')[0];\n // CSSFontFaceRule has type 5 and cssText contains @font-face\n if (rule.cssText.includes('@font-face')) {\n return (\n rule.cssText.includes(`\"${family}\"`) || rule.cssText.includes(`'${family}'`)\n );\n }\n return false;\n }\n if ('selectorText' in rule) {\n return (rule as CSSStyleRule).selectorText.startsWith(prefix);\n }\n if ('name' in rule && prefix.startsWith('keyframes:')) {\n return (rule as CSSKeyframesRule).name === prefix.slice('keyframes:'.length);\n }\n // For at-rules wrapping style rules, check inner rules\n if ('cssRules' in rule) {\n const innerRules = (rule as CSSGroupingRule).cssRules;\n for (let i = 0; i < innerRules.length; i++) {\n if (ruleMatchesPrefix(innerRules[i], prefix)) return true;\n }\n }\n return false;\n}\n\nfunction ruleMatchesKey(cssText: string, key: string): boolean {\n if (key.startsWith('tokens:')) {\n // tokens:color -> :root rule with --color- custom properties\n const namespace = key.slice('tokens:'.length);\n return cssText.includes(`:root`) && cssText.includes(`--${namespace}-`);\n }\n if (key.startsWith('theme:')) {\n // theme:dark -> .theme-dark selector\n const name = key.slice('theme:'.length);\n return cssText.includes(`.theme-${name}`);\n }\n if (key.startsWith('keyframes:')) {\n const name = key.slice('keyframes:'.length);\n return cssText.includes(`@keyframes ${name}`);\n }\n return false;\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Return all registered CSS as a string.
|
|
3
|
+
*
|
|
4
|
+
* Unlike `collectStyles`, this doesn't require wrapping a render function.
|
|
5
|
+
* It simply returns every CSS rule that has been registered via
|
|
6
|
+
* `styles.create`, `tokens.create`, `keyframes.create`, etc.
|
|
7
|
+
*
|
|
8
|
+
* Ideal for SSR frameworks that need the CSS separately from the render
|
|
9
|
+
* pass (e.g. TanStack Start's `head()`, Next.js metadata, Remix links).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { getRegisteredCss } from 'typestyles/server';
|
|
14
|
+
*
|
|
15
|
+
* // In a route's head/meta function:
|
|
16
|
+
* export const head = () => ({
|
|
17
|
+
* styles: [{ id: 'typestyles', children: getRegisteredCss() }],
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare function getRegisteredCss(): string;
|
|
22
|
+
/**
|
|
23
|
+
* Invalidate all dedup keys that start with the given prefix.
|
|
24
|
+
* Also removes matching rules from the live stylesheet.
|
|
25
|
+
* Used for HMR — allows modules to re-register their styles after editing.
|
|
26
|
+
*/
|
|
27
|
+
declare function invalidatePrefix(prefix: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Invalidate a list of exact keys or prefixes.
|
|
30
|
+
* Each entry in `keys` is treated as an exact key match.
|
|
31
|
+
* Each entry in `prefixes` is treated as a prefix match.
|
|
32
|
+
* Used for HMR to invalidate all styles from a module at once.
|
|
33
|
+
*/
|
|
34
|
+
declare function invalidateKeys(keys: string[], prefixes: string[]): void;
|
|
35
|
+
|
|
36
|
+
export { invalidatePrefix as a, getRegisteredCss as g, invalidateKeys as i };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Return all registered CSS as a string.
|
|
3
|
+
*
|
|
4
|
+
* Unlike `collectStyles`, this doesn't require wrapping a render function.
|
|
5
|
+
* It simply returns every CSS rule that has been registered via
|
|
6
|
+
* `styles.create`, `tokens.create`, `keyframes.create`, etc.
|
|
7
|
+
*
|
|
8
|
+
* Ideal for SSR frameworks that need the CSS separately from the render
|
|
9
|
+
* pass (e.g. TanStack Start's `head()`, Next.js metadata, Remix links).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { getRegisteredCss } from 'typestyles/server';
|
|
14
|
+
*
|
|
15
|
+
* // In a route's head/meta function:
|
|
16
|
+
* export const head = () => ({
|
|
17
|
+
* styles: [{ id: 'typestyles', children: getRegisteredCss() }],
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare function getRegisteredCss(): string;
|
|
22
|
+
/**
|
|
23
|
+
* Invalidate all dedup keys that start with the given prefix.
|
|
24
|
+
* Also removes matching rules from the live stylesheet.
|
|
25
|
+
* Used for HMR — allows modules to re-register their styles after editing.
|
|
26
|
+
*/
|
|
27
|
+
declare function invalidatePrefix(prefix: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Invalidate a list of exact keys or prefixes.
|
|
30
|
+
* Each entry in `keys` is treated as an exact key match.
|
|
31
|
+
* Each entry in `prefixes` is treated as a prefix match.
|
|
32
|
+
* Used for HMR to invalidate all styles from a module at once.
|
|
33
|
+
*/
|
|
34
|
+
declare function invalidateKeys(keys: string[], prefixes: string[]): void;
|
|
35
|
+
|
|
36
|
+
export { invalidatePrefix as a, getRegisteredCss as g, invalidateKeys as i };
|
package/dist/hmr.cjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/sheet.ts
|
|
4
|
+
var insertedRules = /* @__PURE__ */ new Set();
|
|
5
|
+
var isBrowser = typeof document !== "undefined" && typeof window !== "undefined";
|
|
6
|
+
function invalidatePrefix(prefix) {
|
|
7
|
+
for (const key of insertedRules) {
|
|
8
|
+
if (key.startsWith(prefix)) {
|
|
9
|
+
insertedRules.delete(key);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
if (!isBrowser) return;
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
function invalidateKeys(keys, prefixes) {
|
|
16
|
+
for (const key of keys) {
|
|
17
|
+
insertedRules.delete(key);
|
|
18
|
+
}
|
|
19
|
+
for (const prefix of prefixes) {
|
|
20
|
+
for (const key of insertedRules) {
|
|
21
|
+
if (key.startsWith(prefix)) {
|
|
22
|
+
insertedRules.delete(key);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (!isBrowser) return;
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
exports.invalidateKeys = invalidateKeys;
|
|
31
|
+
exports.invalidatePrefix = invalidatePrefix;
|
|
32
|
+
//# sourceMappingURL=hmr.cjs.map
|
|
33
|
+
//# sourceMappingURL=hmr.cjs.map
|
package/dist/hmr.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sheet.ts"],"names":[],"mappings":";;;AAKA,IAAM,aAAA,uBAAoB,GAAA,EAAY;AAgCtC,IAAM,SAAA,GACJ,OAAO,QAAA,KAAa,WAAA,IAAe,OAAO,MAAA,KAAW,WAAA;AAmLhD,SAAS,iBAAiB,MAAA,EAAsB;AACrD,EAAA,KAAA,MAAW,OAAO,aAAA,EAAe;AAC/B,IAAA,IAAI,GAAA,CAAI,UAAA,CAAW,MAAM,CAAA,EAAG;AAC1B,MAAA,aAAA,CAAc,OAAO,GAAG,CAAA;AAAA,IAC1B;AAAA,EACF;AAEA,EAAA,IAAI,CAAC,SAAA,EAAW;AAGhB,EAAS;AAUX;AAQO,SAAS,cAAA,CAAe,MAAgB,QAAA,EAA0B;AACvE,EAAA,KAAA,MAAW,OAAO,IAAA,EAAM;AACtB,IAAA,aAAA,CAAc,OAAO,GAAG,CAAA;AAAA,EAC1B;AACA,EAAA,KAAA,MAAW,UAAU,QAAA,EAAU;AAC7B,IAAA,KAAA,MAAW,OAAO,aAAA,EAAe;AAC/B,MAAA,IAAI,GAAA,CAAI,UAAA,CAAW,MAAM,CAAA,EAAG;AAC1B,QAAA,aAAA,CAAc,OAAO,GAAG,CAAA;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AAEA,EAAA,IAAI,CAAC,SAAA,EAAW;AAGhB,EAAS;AAgCX","file":"hmr.cjs","sourcesContent":["const STYLE_ELEMENT_ID = 'typestyles';\n\n/**\n * Tracks which CSS rules have been inserted to avoid duplicates.\n */\nconst insertedRules = new Set<string>();\n\n/**\n * Buffer of CSS rules waiting to be flushed.\n */\nlet pendingRules: string[] = [];\n\n/**\n * All CSS rules ever registered (for SSR extraction).\n * Unlike pendingRules (which is cleared on flush), this retains every rule\n * so getRegisteredCss() can return the full stylesheet at any point.\n */\nconst allRules: string[] = [];\n\n/**\n * Whether a flush is scheduled.\n */\nlet flushScheduled = false;\n\n/**\n * The managed <style> element, lazily created.\n */\nlet styleElement: HTMLStyleElement | null = null;\n\n/**\n * When in SSR collection mode, CSS is captured here instead of injected.\n */\nlet ssrBuffer: string[] | null = null;\n\n/**\n * Whether we're running in a browser environment.\n */\nconst isBrowser =\n typeof document !== 'undefined' && typeof window !== 'undefined';\n\nfunction getStyleElement(): HTMLStyleElement {\n if (styleElement) return styleElement;\n\n // Check for an existing element (e.g., from SSR)\n const existing = document.getElementById(\n STYLE_ELEMENT_ID\n ) as HTMLStyleElement | null;\n if (existing) {\n styleElement = existing;\n return styleElement;\n }\n\n // Create a new one\n styleElement = document.createElement('style');\n styleElement.id = STYLE_ELEMENT_ID;\n document.head.appendChild(styleElement);\n return styleElement;\n}\n\nfunction flush(): void {\n flushScheduled = false;\n if (pendingRules.length === 0) return;\n\n const rules = pendingRules;\n pendingRules = [];\n\n if (ssrBuffer) {\n ssrBuffer.push(...rules);\n return;\n }\n\n if (!isBrowser) return;\n\n const el = getStyleElement();\n const sheet = el.sheet;\n\n if (sheet) {\n for (const rule of rules) {\n try {\n sheet.insertRule(rule, sheet.cssRules.length);\n } catch {\n // Fallback: append as text (handles edge cases with certain selectors)\n el.appendChild(document.createTextNode(rule));\n }\n }\n } else {\n // Sheet not available yet, append as text\n el.appendChild(document.createTextNode(rules.join('\\n')));\n }\n}\n\nfunction scheduleFlush(): void {\n if (flushScheduled) return;\n flushScheduled = true;\n\n if (ssrBuffer) {\n // In SSR mode, flush synchronously\n flush();\n return;\n }\n\n if (isBrowser) {\n // Use microtask for fast, batched insertion\n queueMicrotask(flush);\n }\n}\n\n/**\n * Insert a CSS rule. Deduplicates by rule key.\n */\nexport function insertRule(key: string, css: string): void {\n if (insertedRules.has(key)) return;\n insertedRules.add(key);\n pendingRules.push(css);\n allRules.push(css);\n scheduleFlush();\n}\n\n/**\n * Insert multiple CSS rules at once.\n */\nexport function insertRules(rules: Array<{ key: string; css: string }>): void {\n let added = false;\n for (const { key, css } of rules) {\n if (insertedRules.has(key)) continue;\n insertedRules.add(key);\n pendingRules.push(css);\n allRules.push(css);\n added = true;\n }\n if (added) scheduleFlush();\n}\n\n/**\n * Replace a CSS rule (used for HMR). Removes the old rule and inserts the new one.\n */\nexport function replaceRule(key: string, css: string): void {\n if (!isBrowser) return;\n\n insertedRules.delete(key);\n\n // Remove existing rule from the sheet if possible\n const el = getStyleElement();\n const sheet = el.sheet;\n if (sheet) {\n for (let i = sheet.cssRules.length - 1; i >= 0; i--) {\n // We can't reliably match by key in CSSOM, so for HMR we fall back to\n // clearing and re-inserting. This is fine since HMR is dev-only.\n }\n }\n\n insertRule(key, css);\n}\n\n/**\n * Start collecting CSS for SSR. Returns a function to stop collection and get the CSS.\n */\nexport function startCollection(): () => string {\n ssrBuffer = [];\n return () => {\n const css = ssrBuffer ? ssrBuffer.join('\\n') : '';\n ssrBuffer = null;\n return css;\n };\n}\n\n/**\n * Return all registered CSS as a string.\n *\n * Unlike `collectStyles`, this doesn't require wrapping a render function.\n * It simply returns every CSS rule that has been registered via\n * `styles.create`, `tokens.create`, `keyframes.create`, etc.\n *\n * Ideal for SSR frameworks that need the CSS separately from the render\n * pass (e.g. TanStack Start's `head()`, Next.js metadata, Remix links).\n *\n * @example\n * ```ts\n * import { getRegisteredCss } from 'typestyles/server';\n *\n * // In a route's head/meta function:\n * export const head = () => ({\n * styles: [{ id: 'typestyles', children: getRegisteredCss() }],\n * });\n * ```\n */\nexport function getRegisteredCss(): string {\n return allRules.join('\\n');\n}\n\n/**\n * Reset all state (useful for testing).\n */\nexport function reset(): void {\n insertedRules.clear();\n pendingRules = [];\n allRules.length = 0;\n flushScheduled = false;\n ssrBuffer = null;\n if (isBrowser && styleElement) {\n styleElement.remove();\n styleElement = null;\n }\n}\n\n/**\n * Flush all pending rules synchronously. Used for SSR and testing.\n */\nexport function flushSync(): void {\n flush();\n}\n\n/**\n * Invalidate all dedup keys that start with the given prefix.\n * Also removes matching rules from the live stylesheet.\n * Used for HMR — allows modules to re-register their styles after editing.\n */\nexport function invalidatePrefix(prefix: string): void {\n for (const key of insertedRules) {\n if (key.startsWith(prefix)) {\n insertedRules.delete(key);\n }\n }\n\n if (!isBrowser) return;\n\n const el = styleElement;\n if (!el) return;\n const sheet = el.sheet;\n if (!sheet) return;\n\n for (let i = sheet.cssRules.length - 1; i >= 0; i--) {\n const rule = sheet.cssRules[i];\n if (ruleMatchesPrefix(rule, prefix)) {\n sheet.deleteRule(i);\n }\n }\n}\n\n/**\n * Invalidate a list of exact keys or prefixes.\n * Each entry in `keys` is treated as an exact key match.\n * Each entry in `prefixes` is treated as a prefix match.\n * Used for HMR to invalidate all styles from a module at once.\n */\nexport function invalidateKeys(keys: string[], prefixes: string[]): void {\n for (const key of keys) {\n insertedRules.delete(key);\n }\n for (const prefix of prefixes) {\n for (const key of insertedRules) {\n if (key.startsWith(prefix)) {\n insertedRules.delete(key);\n }\n }\n }\n\n if (!isBrowser) return;\n\n const el = styleElement;\n if (!el) return;\n const sheet = el.sheet;\n if (!sheet) return;\n\n const keySet = new Set(keys);\n for (let i = sheet.cssRules.length - 1; i >= 0; i--) {\n const rule = sheet.cssRules[i];\n let shouldRemove = false;\n\n for (const prefix of prefixes) {\n if (ruleMatchesPrefix(rule, prefix)) {\n shouldRemove = true;\n break;\n }\n }\n\n if (!shouldRemove) {\n // Check exact key matches — for tokens/themes/keyframes,\n // we match based on rule content patterns\n const ruleText = rule.cssText;\n for (const key of keySet) {\n if (ruleMatchesKey(ruleText, key)) {\n shouldRemove = true;\n break;\n }\n }\n }\n\n if (shouldRemove) {\n sheet.deleteRule(i);\n }\n }\n}\n\nfunction ruleMatchesPrefix(rule: CSSRule, prefix: string): boolean {\n if (prefix.startsWith('font-face:')) {\n const family = prefix.slice('font-face:'.length).split(':')[0];\n // CSSFontFaceRule has type 5 and cssText contains @font-face\n if (rule.cssText.includes('@font-face')) {\n return (\n rule.cssText.includes(`\"${family}\"`) || rule.cssText.includes(`'${family}'`)\n );\n }\n return false;\n }\n if ('selectorText' in rule) {\n return (rule as CSSStyleRule).selectorText.startsWith(prefix);\n }\n if ('name' in rule && prefix.startsWith('keyframes:')) {\n return (rule as CSSKeyframesRule).name === prefix.slice('keyframes:'.length);\n }\n // For at-rules wrapping style rules, check inner rules\n if ('cssRules' in rule) {\n const innerRules = (rule as CSSGroupingRule).cssRules;\n for (let i = 0; i < innerRules.length; i++) {\n if (ruleMatchesPrefix(innerRules[i], prefix)) return true;\n }\n }\n return false;\n}\n\nfunction ruleMatchesKey(cssText: string, key: string): boolean {\n if (key.startsWith('tokens:')) {\n // tokens:color -> :root rule with --color- custom properties\n const namespace = key.slice('tokens:'.length);\n return cssText.includes(`:root`) && cssText.includes(`--${namespace}-`);\n }\n if (key.startsWith('theme:')) {\n // theme:dark -> .theme-dark selector\n const name = key.slice('theme:'.length);\n return cssText.includes(`.theme-${name}`);\n }\n if (key.startsWith('keyframes:')) {\n const name = key.slice('keyframes:'.length);\n return cssText.includes(`@keyframes ${name}`);\n }\n return false;\n}\n"]}
|
package/dist/hmr.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { i as invalidateKeys, a as invalidatePrefix } from './hmr-CSDtaPpU.cjs';
|
package/dist/hmr.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { i as invalidateKeys, a as invalidatePrefix } from './hmr-CSDtaPpU.js';
|
package/dist/hmr.js
ADDED
package/dist/hmr.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"hmr.js"}
|