@askrjs/themes 0.0.15 → 0.0.16
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.
|
@@ -64,10 +64,6 @@ function styleDeclarationsToClass(declarations) {
|
|
|
64
64
|
let className = styleClassCache.get(normalized);
|
|
65
65
|
if (className === void 0) {
|
|
66
66
|
className = `${STYLE_CLASS_PREFIX}${++nextStyleClassId}`;
|
|
67
|
-
if (styleClassCache.size >= MAX_STYLE_RULES) {
|
|
68
|
-
const oldest = styleClassCache.keys().next().value;
|
|
69
|
-
if (oldest !== void 0) styleClassCache.delete(oldest);
|
|
70
|
-
}
|
|
71
67
|
styleClassCache.set(normalized, className);
|
|
72
68
|
}
|
|
73
69
|
if (registry) {
|
|
@@ -79,7 +75,7 @@ function styleDeclarationsToClass(declarations) {
|
|
|
79
75
|
className,
|
|
80
76
|
rule
|
|
81
77
|
});
|
|
82
|
-
styleElement.
|
|
78
|
+
styleElement.append(rule, "\n");
|
|
83
79
|
}
|
|
84
80
|
}
|
|
85
81
|
return className;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.js","names":[],"sources":["../../../src/components/_internal/style.ts"],"sourcesContent":["import { cspNonce } from \"@askrjs/askr\";\n\nconst cssPropertyNameCache = new Map<string, string>();\n\nfunction cssPropertyName(name: string): string {\n let cached = cssPropertyNameCache.get(name);\n if (cached !== undefined) {\n return cached;\n }\n\n let result = \"\";\n\n for (let index = 0; index < name.length; index += 1) {\n const code = name.charCodeAt(index);\n\n if (code >= 65 && code <= 90) {\n result += `-${String.fromCharCode(code + 32)}`;\n } else {\n result += name[index];\n }\n }\n\n cssPropertyNameCache.set(name, result);\n return result;\n}\n\nexport function serializeCssDeclarations(styles: Record<string, unknown>): string {\n const keys = Object.keys(styles);\n let result = \"\";\n\n for (const key of keys) {\n const value = styles[key];\n if (value === undefined || value === null) {\n continue;\n }\n\n const declaration = `${cssPropertyName(key)}:${String(value)}`;\n result = result ? `${result};${declaration}` : declaration;\n }\n\n return result;\n}\n\nexport function mergeCssVar(style: unknown, name: string, value: string): string {\n const decl = `${name}:${value}`;\n\n if (typeof style === \"string\") {\n const trimmed = style.trim();\n return trimmed ? `${trimmed};${decl}` : decl;\n }\n\n if (style && typeof style === \"object\") {\n const entries = serializeCssDeclarations(style as Record<string, unknown>);\n return entries ? `${entries};${decl}` : decl;\n }\n\n return decl;\n}\n\nconst STYLE_REGISTRY_ATTR = \"data-askr-style-registry\";\nconst STYLE_CLASS_PREFIX = \"ak-style-\";\n\nconst styleClassCache = new Map<string, string>();\ntype StyleRegistry = {\n element: HTMLStyleElement;\n rules: Map<string, { className: string; rule: string }>;\n};\nconst registries = new WeakMap<Document, Map<string, StyleRegistry>>();\nconst MAX_STYLE_RULES = 512;\n\nlet nextStyleClassId = 0;\n\nfunction ensureStyleRegistry(nonce: string | undefined): StyleRegistry | null {\n if (typeof document === \"undefined\") return null;\n const key = nonce ?? \"\";\n let documentRegistries = registries.get(document);\n if (!documentRegistries) {\n documentRegistries = new Map();\n registries.set(document, documentRegistries);\n }\n const current = documentRegistries.get(key);\n if (current?.element.isConnected) return current;\n\n const styleElement = document.createElement(\"style\");\n styleElement.setAttribute(STYLE_REGISTRY_ATTR, \"true\");\n if (nonce !== undefined) styleElement.nonce = nonce;\n (document.head ?? document.documentElement).append(styleElement);\n const registry: StyleRegistry = { element: styleElement, rules: new Map() };\n documentRegistries.set(key, registry);\n return registry;\n}\n\nfunction normalizeDeclarations(declarations: string): string {\n return declarations.trim().replace(/;+\\s*$/, \"\");\n}\n\nexport function styleDeclarationsToClass(declarations: string | undefined): string | undefined {\n if (typeof declarations !== \"string\") return undefined;\n\n const normalized = normalizeDeclarations(declarations);\n if (!normalized) return undefined;\n\n const nonce = cspNonce();\n const registry = ensureStyleRegistry(nonce);\n const registered = registry?.rules.get(normalized);\n if (registered) return registered.className;\n\n let className = styleClassCache.get(normalized);\n if (className === undefined) {\n className = `${STYLE_CLASS_PREFIX}${++nextStyleClassId}`;\n
|
|
1
|
+
{"version":3,"file":"style.js","names":[],"sources":["../../../src/components/_internal/style.ts"],"sourcesContent":["import { cspNonce } from \"@askrjs/askr\";\n\nconst cssPropertyNameCache = new Map<string, string>();\n\nfunction cssPropertyName(name: string): string {\n let cached = cssPropertyNameCache.get(name);\n if (cached !== undefined) {\n return cached;\n }\n\n let result = \"\";\n\n for (let index = 0; index < name.length; index += 1) {\n const code = name.charCodeAt(index);\n\n if (code >= 65 && code <= 90) {\n result += `-${String.fromCharCode(code + 32)}`;\n } else {\n result += name[index];\n }\n }\n\n cssPropertyNameCache.set(name, result);\n return result;\n}\n\nexport function serializeCssDeclarations(styles: Record<string, unknown>): string {\n const keys = Object.keys(styles);\n let result = \"\";\n\n for (const key of keys) {\n const value = styles[key];\n if (value === undefined || value === null) {\n continue;\n }\n\n const declaration = `${cssPropertyName(key)}:${String(value)}`;\n result = result ? `${result};${declaration}` : declaration;\n }\n\n return result;\n}\n\nexport function mergeCssVar(style: unknown, name: string, value: string): string {\n const decl = `${name}:${value}`;\n\n if (typeof style === \"string\") {\n const trimmed = style.trim();\n return trimmed ? `${trimmed};${decl}` : decl;\n }\n\n if (style && typeof style === \"object\") {\n const entries = serializeCssDeclarations(style as Record<string, unknown>);\n return entries ? `${entries};${decl}` : decl;\n }\n\n return decl;\n}\n\nconst STYLE_REGISTRY_ATTR = \"data-askr-style-registry\";\nconst STYLE_CLASS_PREFIX = \"ak-style-\";\n\nconst styleClassCache = new Map<string, string>();\ntype StyleRegistry = {\n element: HTMLStyleElement;\n rules: Map<string, { className: string; rule: string }>;\n};\nconst registries = new WeakMap<Document, Map<string, StyleRegistry>>();\nconst MAX_STYLE_RULES = 512;\n\nlet nextStyleClassId = 0;\n\nfunction ensureStyleRegistry(nonce: string | undefined): StyleRegistry | null {\n if (typeof document === \"undefined\") return null;\n const key = nonce ?? \"\";\n let documentRegistries = registries.get(document);\n if (!documentRegistries) {\n documentRegistries = new Map();\n registries.set(document, documentRegistries);\n }\n const current = documentRegistries.get(key);\n if (current?.element.isConnected) return current;\n\n const styleElement = document.createElement(\"style\");\n styleElement.setAttribute(STYLE_REGISTRY_ATTR, \"true\");\n if (nonce !== undefined) styleElement.nonce = nonce;\n (document.head ?? document.documentElement).append(styleElement);\n const registry: StyleRegistry = { element: styleElement, rules: new Map() };\n documentRegistries.set(key, registry);\n return registry;\n}\n\nfunction normalizeDeclarations(declarations: string): string {\n return declarations.trim().replace(/;+\\s*$/, \"\");\n}\n\nexport function styleDeclarationsToClass(declarations: string | undefined): string | undefined {\n if (typeof declarations !== \"string\") return undefined;\n\n const normalized = normalizeDeclarations(declarations);\n if (!normalized) return undefined;\n\n const nonce = cspNonce();\n const registry = ensureStyleRegistry(nonce);\n const registered = registry?.rules.get(normalized);\n if (registered) return registered.className;\n\n let className = styleClassCache.get(normalized);\n if (className === undefined) {\n className = `${STYLE_CLASS_PREFIX}${++nextStyleClassId}`;\n styleClassCache.set(normalized, className);\n }\n\n if (registry) {\n const styleElement = registry.element;\n if (styleElement) {\n if (registry.rules.size >= MAX_STYLE_RULES)\n throw new RangeError(\"Theme style registry capacity exceeded.\");\n const rule = `.${className}{${normalized}}`;\n registry.rules.set(normalized, { className, rule });\n styleElement.append(rule, \"\\n\");\n }\n }\n\n return className;\n}\n"],"mappings":";;AAEA,MAAM,uCAAuB,IAAI,IAAoB;AAErD,SAAS,gBAAgB,MAAsB;CAC7C,IAAI,SAAS,qBAAqB,IAAI,IAAI;CAC1C,IAAI,WAAW,KAAA,GACb,OAAO;CAGT,IAAI,SAAS;CAEb,KAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,QAAQ,SAAS,GAAG;EACnD,MAAM,OAAO,KAAK,WAAW,KAAK;EAElC,IAAI,QAAQ,MAAM,QAAQ,IACxB,UAAU,IAAI,OAAO,aAAa,OAAO,EAAE;OAE3C,UAAU,KAAK;CAEnB;CAEA,qBAAqB,IAAI,MAAM,MAAM;CACrC,OAAO;AACT;AAEA,SAAgB,yBAAyB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CACrD,IAAI,CAAC,YAAY,OAAO,KAAA;CAGxB,MAAM,WAAW,oBADH,SAC2B,CAAC;CAC1C,MAAM,aAAa,UAAU,MAAM,IAAI,UAAU;CACjD,IAAI,YAAY,OAAO,WAAW;CAElC,IAAI,YAAY,gBAAgB,IAAI,UAAU;CAC9C,IAAI,cAAc,KAAA,GAAW;EAC3B,YAAY,GAAG,qBAAqB,EAAE;EACtC,gBAAgB,IAAI,YAAY,SAAS;CAC3C;CAEA,IAAI,UAAU;EACZ,MAAM,eAAe,SAAS;EAC9B,IAAI,cAAc;GAChB,IAAI,SAAS,MAAM,QAAQ,iBACzB,MAAM,IAAI,WAAW,yCAAyC;GAChE,MAAM,OAAO,IAAI,UAAU,GAAG,WAAW;GACzC,SAAS,MAAM,IAAI,YAAY;IAAE;IAAW;GAAK,CAAC;GAClD,aAAa,OAAO,MAAM,IAAI;EAChC;CACF;CAEA,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -108,10 +108,6 @@ export function styleDeclarationsToClass(declarations: string | undefined): stri
|
|
|
108
108
|
let className = styleClassCache.get(normalized);
|
|
109
109
|
if (className === undefined) {
|
|
110
110
|
className = `${STYLE_CLASS_PREFIX}${++nextStyleClassId}`;
|
|
111
|
-
if (styleClassCache.size >= MAX_STYLE_RULES) {
|
|
112
|
-
const oldest = styleClassCache.keys().next().value as string | undefined;
|
|
113
|
-
if (oldest !== undefined) styleClassCache.delete(oldest);
|
|
114
|
-
}
|
|
115
111
|
styleClassCache.set(normalized, className);
|
|
116
112
|
}
|
|
117
113
|
|
|
@@ -122,9 +118,7 @@ export function styleDeclarationsToClass(declarations: string | undefined): stri
|
|
|
122
118
|
throw new RangeError("Theme style registry capacity exceeded.");
|
|
123
119
|
const rule = `.${className}{${normalized}}`;
|
|
124
120
|
registry.rules.set(normalized, { className, rule });
|
|
125
|
-
styleElement.
|
|
126
|
-
"\n",
|
|
127
|
-
);
|
|
121
|
+
styleElement.append(rule, "\n");
|
|
128
122
|
}
|
|
129
123
|
}
|
|
130
124
|
|