@cossackframework/renderer 0.8.3 → 0.9.1

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.
Files changed (43) hide show
  1. package/README.md +171 -29
  2. package/agent-docs.json +121 -0
  3. package/dist/attributes.d.ts +824 -0
  4. package/dist/attributes.js +1 -0
  5. package/dist/browser-ssr.d.ts +5 -0
  6. package/dist/browser-ssr.js +7 -0
  7. package/dist/browser.d.ts +2 -0
  8. package/dist/browser.js +11 -0
  9. package/dist/component-tags.d.ts +69 -0
  10. package/dist/component-tags.js +106 -0
  11. package/dist/cossack-element.d.ts +36 -2
  12. package/dist/cossack-element.js +26 -28
  13. package/dist/cossack-html.d.ts +23 -5
  14. package/dist/cossack-html.js +1059 -551
  15. package/dist/css-result.d.ts +9 -0
  16. package/dist/css-result.js +14 -0
  17. package/dist/css-scoping.d.ts +4 -0
  18. package/dist/css-scoping.js +95 -0
  19. package/dist/css.d.ts +3 -16
  20. package/dist/css.js +13 -111
  21. package/dist/diagnostics.d.ts +85 -0
  22. package/dist/diagnostics.js +465 -0
  23. package/dist/directives.d.ts +13 -7
  24. package/dist/directives.js +7 -7
  25. package/dist/index.d.ts +2 -0
  26. package/dist/index.js +9 -7
  27. package/dist/minify-html.d.ts +22 -0
  28. package/dist/minify-html.js +123 -18
  29. package/dist/server.d.ts +3 -1
  30. package/dist/server.js +6 -4
  31. package/dist/ssr-form-values.d.ts +2 -0
  32. package/dist/ssr-form-values.js +72 -0
  33. package/dist/style-registry.d.ts +42 -0
  34. package/dist/style-registry.js +73 -0
  35. package/dist/style-runtime.d.ts +47 -0
  36. package/dist/style-runtime.js +43 -0
  37. package/dist/template-analysis.d.ts +224 -0
  38. package/dist/template-analysis.js +321 -0
  39. package/dist/template-parse.d.ts +157 -0
  40. package/dist/template-parse.js +526 -0
  41. package/dist/template.d.ts +2 -0
  42. package/dist/template.js +3 -0
  43. package/package.json +26 -6
@@ -1,6 +1,7 @@
1
1
  // @ts-self-types="./minify-html.d.ts"
2
+ import { RAW_TEXT_TAGS as e, forEachHtmlToken as t } from "./template-analysis.js";
2
3
  //#region src/minify-html.ts
3
- var e = /<(script|style|pre|textarea)\b[^>]*>[\s\S]*?<\/\1>/gi, t = RegExp(`<(${[.../* @__PURE__ */ new Set([
4
+ var n = /* @__PURE__ */ new Set([
4
5
  "area",
5
6
  "base",
6
7
  "br",
@@ -15,23 +16,127 @@ var e = /<(script|style|pre|textarea)\b[^>]*>[\s\S]*?<\/\1>/gi, t = RegExp(`<(${
15
16
  "source",
16
17
  "track",
17
18
  "wbr"
18
- ])].join("|")})(\\s[^>]*)?\\/\\s*>`, "gi"), n = /\s+type\s*=\s*["']text\/(javascript|css)["']/gi, r = /(\w[\w-]*)\s*=\s*["']([a-zA-Z0-9_.-]+)["'](?=(\s|\/?>))/g;
19
- function i(t) {
20
- let r = [];
21
- return {
22
- html: t.replace(e, (e) => {
23
- let t = e.replace(n, "");
24
- return r.push(t), `\x00PRESERVE_${r.length - 1}\x00`;
25
- }),
26
- blocks: r
19
+ ]), r = /* @__PURE__ */ new Set([
20
+ "base",
21
+ "basefont",
22
+ "bgsound",
23
+ "link",
24
+ "meta",
25
+ "noframes",
26
+ "script",
27
+ "style",
28
+ "title"
29
+ ]), i = /* @__PURE__ */ new Set([
30
+ "pre",
31
+ "listing",
32
+ "xmp",
33
+ "plaintext"
34
+ ]), a = /* @__PURE__ */ new Set(["xmp", "plaintext"]), o = /* @__PURE__ */ new Set([
35
+ "pre",
36
+ "pre-wrap",
37
+ "break-spaces",
38
+ "preserve",
39
+ "preserve-spaces"
40
+ ]), s = /* @__PURE__ */ new Set([
41
+ "whitespace-pre",
42
+ "whitespace-pre-wrap",
43
+ "whitespace-break-spaces"
44
+ ]), c = /^[a-zA-Z0-9_.-]+$/, l = /^<!--(?:\[if\s|\/?CRP|CSA-[SE])/, u = (e) => /(?:<|&[a-zA-Z0-9#]*)$/.test(e), d = (e, t) => {
45
+ let n = t.toLowerCase();
46
+ return e === "script" ? n === "text/javascript" : (e === "style" || e === "link") && n === "text/css";
47
+ }, f = (e) => {
48
+ let t = "", n = 0;
49
+ for (let r = 0; r < e.length;) {
50
+ let i = e.charCodeAt(r);
51
+ if (i !== 32 && i !== 9 && i !== 10 && i !== 13) {
52
+ r++;
53
+ continue;
54
+ }
55
+ let a = r, o = !1;
56
+ for (; a < e.length; a++) {
57
+ let t = e.charCodeAt(a);
58
+ if (t === 10 || t === 13) o = !0;
59
+ else if (t !== 32 && t !== 9) break;
60
+ }
61
+ (a - r > 1 || i === 9 || i === 13) && (t += e.slice(n, r) + (o ? "\n" : " "), n = a), r = a;
62
+ }
63
+ return n === 0 ? e : t + e.slice(n);
64
+ }, p = /^[ \t\n\f\r]+/, m = (e, t) => {
65
+ for (let n of t) {
66
+ if (n.valueStart < 0) continue;
67
+ let t = n.name.toLowerCase();
68
+ if (t !== "style" && t !== "class") continue;
69
+ let r = e.slice(n.valueStart, n.valueEnd).toLowerCase();
70
+ if (t === "style") {
71
+ if (!r.includes("white-space")) continue;
72
+ for (let [, e] of r.matchAll(/(?:^|;)\s*white-space(?:-collapse)?\s*:([^;]*)/g)) if (e.replace("!important", "").trim().split(/\s+/).some((e) => o.has(e))) return !0;
73
+ } else if (r.includes("whitespace-") && r.split(/[ \t\n\f\r]+/).some((e) => s.has(e.slice(e.lastIndexOf(":") + 1).replace(/^!/, "")))) return !0;
74
+ }
75
+ return !1;
76
+ };
77
+ function h(o) {
78
+ let s = "", h = "", g = 0, _ = null, v = () => {
79
+ h &&= (g !== 4 && (h = h.replace(p, ""), h && (g = 4)), s += f(h), "");
80
+ }, y = (e) => {
81
+ switch (g) {
82
+ case 0:
83
+ case 1:
84
+ g = e === "html" ? 1 : e === "head" || r.has(e) ? 2 : 4;
85
+ break;
86
+ case 2:
87
+ case 3:
88
+ e !== "html" && e !== "head" && !r.has(e) && (g = 4);
89
+ break;
90
+ }
91
+ }, b = (e, t, n) => {
92
+ if (t.valueStart < 0) return ` ${t.name}`;
93
+ let r = o.slice(t.valueStart, t.valueEnd), i = t.name.toLowerCase();
94
+ return i === "type" && d(e, r) ? "" : (i === "class" && (r = r.replace(/[ \t\n\f\r]+/g, " ").replace(/^ | $/g, "")), !n && (!t.quote || c.test(r)) ? ` ${t.name}=${r}` : t.quote ? ` ${t.name}=${t.quote}${r}${t.quote}` : ` ${t.name}="${r.replace(/"/g, "&quot;")}"`);
95
+ }, x = (e) => {
96
+ let t = e.attributes.find((t) => t.name.toLowerCase() === "type" && t.valueStart >= 0 && d(e.name, o.slice(t.valueStart, t.valueEnd)));
97
+ if (!t) return o.slice(e.start, e.end);
98
+ let n = t.nameStart;
99
+ for (; n > e.nameEnd && /[ \t\n\f\r]/.test(o[n - 1]);) n--;
100
+ let r = t.valueEnd + +!!t.quote;
101
+ return o.slice(e.start, n) + o.slice(r, e.end);
102
+ }, S = (e) => {
103
+ if (!e.closed || e.attributes.some((e) => e.name.startsWith("="))) return o.slice(e.start, e.end);
104
+ let { name: t, attributes: r } = e, i = e.selfClosing && !n.has(t), a = o.slice(e.start, e.nameEnd);
105
+ return r.forEach((e, n) => {
106
+ a += b(t, e, i && n === r.length - 1);
107
+ }), a + (i ? "/>" : ">");
27
108
  };
28
- }
29
- function a(e, t) {
30
- return e.replace(/\x00PRESERVE_(\d+)\x00/g, (e, n) => t[parseInt(n, 10)]);
31
- }
32
- function o(e) {
33
- let { html: o, blocks: s } = i(e), c = o.replace(/<!--(?!\[if\s|\/?CRP|CSA-[SE])[\s\S]*?-->/g, "");
34
- return c = c.replace(n, ""), c = c.replace(/\s+/g, " "), c = c.replace(/>\s+</g, "><"), c = c.replace(r, (e, t, n, r) => r === "/>" ? e : `${t}=${n}`), c = c.replace(t, (e, t, n) => `<${t}${n ? n.trimEnd() : ""}>`), c = a(c, s), c = c.replace(/>\s+</g, "><"), c = c.trim(), c;
109
+ return t(o, (t) => {
110
+ if (_) {
111
+ s += o.slice(t.start, t.end), t.type === "end-tag" && t.name === _.name && _.name !== "plaintext" ? (_.raw || --_.depth === 0) && (_ = null) : t.type === "start-tag" && t.name === _.name && !_.raw && _.depth++;
112
+ return;
113
+ }
114
+ switch (t.type) {
115
+ case "text":
116
+ h += o.slice(t.start, t.end);
117
+ break;
118
+ case "comment":
119
+ (l.test(o.slice(t.start, t.end)) || u(h)) && (v(), s += o.slice(t.start, t.end));
120
+ break;
121
+ case "start-tag": {
122
+ v(), y(t.name);
123
+ let { name: r } = t, c = !n.has(r) && (i.has(r) || m(o, t.attributes));
124
+ s += c || e.has(r) ? x(t) : S(t), c && (_ = {
125
+ name: r,
126
+ depth: 1,
127
+ raw: a.has(r)
128
+ });
129
+ break;
130
+ }
131
+ case "end-tag":
132
+ v(), g === 2 && t.name === "head" ? g = 3 : g !== 4 && !r.has(t.name) && (g = 4), s += `${o.slice(t.start, t.nameEnd)}>`;
133
+ break;
134
+ case "raw-text":
135
+ case "other":
136
+ v(), s += o.slice(t.start, t.end);
137
+ break;
138
+ }
139
+ }), v(), s;
35
140
  }
36
141
  //#endregion
37
- export { o as minifyHtml };
142
+ export { h as minifyHtml };
package/dist/server.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export { renderToString, escapeHtml } from './cossack-html.js';
2
2
  export { html, svg, nothing, TemplateResult } from './cossack-html.js';
3
- export type { SVGTemplateResult, ValueSanitizer, SanitizerFactory } from './cossack-html.js';
3
+ export type { SVGTemplateResult } from './cossack-html.js';
4
4
  export { css, unsafeCSS, CSSResult } from './css.js';
5
5
  export type { CSSResultGroup } from './css.js';
6
+ export { collectComponentStyles, renderComponentStyles } from './style-runtime.js';
7
+ export type { ComponentStyle } from './style-runtime.js';
6
8
  export { minifyHtml } from './minify-html.js';
package/dist/server.js CHANGED
@@ -1,5 +1,7 @@
1
1
  // @ts-self-types="./server.d.ts"
2
- import { CSSResult as e, css as t, unsafeCSS as n } from "./css.js";
3
- import { TemplateResult as r, escapeHtml as i, html as a, nothing as o, renderToString as s, svg as c } from "./cossack-html.js";
4
- import { minifyHtml as l } from "./minify-html.js";
5
- export { e as CSSResult, r as TemplateResult, t as css, i as escapeHtml, a as html, l as minifyHtml, o as nothing, s as renderToString, c as svg, n as unsafeCSS };
2
+ import { collectComponentStyles as e, renderComponentStyles as t } from "./style-runtime.js";
3
+ import { TemplateResult as n, escapeHtml as r, html as i, nothing as a, renderToString as o, svg as s } from "./cossack-html.js";
4
+ import { CSSResult as c } from "./css-result.js";
5
+ import { css as l, unsafeCSS as u } from "./css.js";
6
+ import { minifyHtml as d } from "./minify-html.js";
7
+ export { c as CSSResult, n as TemplateResult, e as collectComponentStyles, l as css, r as escapeHtml, i as html, d as minifyHtml, a as nothing, t as renderComponentStyles, o as renderToString, s as svg, u as unsafeCSS };
@@ -0,0 +1,2 @@
1
+ /** Convert temporary property attributes without reserializing authored markup or hydration markers. */
2
+ export declare const serializeFormValues: (source: string) => string;
@@ -0,0 +1,72 @@
1
+ // @ts-self-types="./ssr-form-values.d.ts"
2
+ import { parseFragment as e } from "parse5";
3
+ //#region src/ssr-form-values.ts
4
+ var t = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"), n = (n) => {
5
+ if (!n.includes(" .value=")) return n;
6
+ let r = e(n, { sourceCodeLocationInfo: !0 }), i = [], a = (e) => "tagName" in e && e.tagName === "script" ? "" : e.nodeName === "#text" ? e.value : "childNodes" in e ? e.childNodes.map(a).join("") : "", o = (e) => {
7
+ if ("tagName" in e) {
8
+ let n = e.attrs.find((e) => e.name === ".value"), r = e.sourceCodeLocation, s = r?.attrs?.[".value"];
9
+ if (n && s) {
10
+ let o = e.namespaceURI === "http://www.w3.org/1999/xhtml";
11
+ if (o && e.tagName === "textarea" && r?.startTag) {
12
+ i.push({
13
+ start: s.startOffset,
14
+ end: s.endOffset,
15
+ text: ""
16
+ });
17
+ let e = t(n.value);
18
+ i.push({
19
+ start: r.startTag.endOffset,
20
+ end: r.endTag?.startOffset ?? r.endOffset,
21
+ text: (e.startsWith("\n") ? "\n" : "") + e
22
+ });
23
+ } else if (o && e.tagName === "select") {
24
+ i.push({
25
+ start: s.startOffset,
26
+ end: s.endOffset,
27
+ text: ""
28
+ });
29
+ let t = !1, r = (e) => {
30
+ if ("tagName" in e && e.tagName === "option") {
31
+ let r = e.attrs.find((e) => e.name === ".value")?.value ?? e.attrs.find((e) => e.name === "value")?.value ?? a(e).replace(/[\t\n\f\r ]+/g, " ").replace(/^ | $/g, ""), o = !t && r === n.value;
32
+ t ||= o;
33
+ let s = e.sourceCodeLocation?.attrs?.selected;
34
+ s && i.push({
35
+ start: s.startOffset,
36
+ end: s.endOffset,
37
+ text: ""
38
+ });
39
+ let c = e.sourceCodeLocation?.startTag?.endOffset;
40
+ o && c !== void 0 && i.push({
41
+ start: c - 1,
42
+ end: c - 1,
43
+ text: " selected"
44
+ });
45
+ }
46
+ "childNodes" in e && e.childNodes.forEach(r);
47
+ };
48
+ e.childNodes.forEach(r);
49
+ } else {
50
+ let e = r?.attrs?.value;
51
+ e && i.push({
52
+ start: e.startOffset,
53
+ end: e.endOffset,
54
+ text: ""
55
+ }), i.push({
56
+ start: s.startOffset,
57
+ end: s.startOffset + 6,
58
+ text: "value"
59
+ });
60
+ }
61
+ }
62
+ e.tagName === "template" && "content" in e && o(e.content);
63
+ }
64
+ "childNodes" in e && e.childNodes.forEach(o);
65
+ };
66
+ o(r), i.sort((e, t) => e.start - t.start || e.end - t.end);
67
+ let s = "", c = 0;
68
+ for (let e of i) e.start > c && (s += n.slice(c, e.start)), s += e.text, c = Math.max(c, e.end);
69
+ return s + n.slice(c);
70
+ };
71
+ //#endregion
72
+ export { n as serializeFormValues };
@@ -0,0 +1,42 @@
1
+ import { type FinalizedStyles } from './style-runtime.js';
2
+ /**
3
+ * Client registry of component stylesheets.
4
+ *
5
+ * Each style root (a Document, or a ShadowRoot that rendered components live
6
+ * in) holds one `<style data-cossack-style="<scope id>">` per scope, with a
7
+ * count of the template instances that use it. In a document the element
8
+ * lives in `<head>`; SSR puts it there too, and the first use adopts it.
9
+ *
10
+ * - Acquisitions resolve their root once their nodes are in a document or
11
+ * shadow root: synchronously at the end of a render that inserted them, so
12
+ * styles exist before `updated()`, layout reads or paint, or at the latest
13
+ * in a microtask.
14
+ * - Releases wait for a macrotask. A client navigation tears down the old
15
+ * page and mounts the new one in one render, but nested components render
16
+ * in the microtasks that follow; waiting until they finished keeps every
17
+ * style the new page also uses, without removing and re-inserting it.
18
+ */
19
+ type StyleRoot = Document | ShadowRoot;
20
+ /** @internal One template instance's claim on a scope's stylesheet. */
21
+ export interface StyleUse {
22
+ readonly styles: FinalizedStyles;
23
+ /** A top-level node of the template instance, used to find its root. */
24
+ anchor: Node;
25
+ /** The root counted for this use; null until resolved or once released. */
26
+ root: StyleRoot | null;
27
+ released: boolean;
28
+ }
29
+ /** @internal Claim a scope's stylesheet for a new template instance. */
30
+ export declare const acquireStyle: (styles: FinalizedStyles, anchor: Node) => StyleUse;
31
+ /** @internal Give up a claim. The style goes, a macrotask later, with the last claim in its root. */
32
+ export declare const releaseStyle: (use: StyleUse) => void;
33
+ /**
34
+ * @internal Re-count a claim whose nodes moved to another root since it was
35
+ * counted (for example a subtree moved into a shadow root).
36
+ */
37
+ export declare const updateStyleRoot: (use: StyleUse) => void;
38
+ /** @internal Count pending claims whose nodes now sit in a document or shadow root. */
39
+ export declare const flushStyleAcquisitions: () => void;
40
+ /** @internal Whether a node is a registry-managed component style element. */
41
+ export declare const isManagedStyle: (node: Node) => boolean;
42
+ export {};
@@ -0,0 +1,73 @@
1
+ // @ts-self-types="./style-registry.d.ts"
2
+ import { COMPONENT_STYLE_ATTRIBUTE as e } from "./style-runtime.js";
3
+ //#region src/style-registry.ts
4
+ var t = /* @__PURE__ */ new WeakMap(), n = /* @__PURE__ */ new WeakSet(), r = /* @__PURE__ */ new Set(), i = [], a = !1, o = !1, s = (e) => e.nodeType === 9, c = (e) => typeof ShadowRoot < "u" && e instanceof ShadowRoot, l = (e, t) => {
5
+ let n = e.getRootNode();
6
+ return s(n) || c(n) ? n : t ? e.ownerDocument : null;
7
+ }, u = (t, { scopeId: r, cssText: i }) => {
8
+ let a = (s(t) ? t : t.ownerDocument).createElement("style");
9
+ if (a.setAttribute(e, r), a.textContent = i, s(t)) (t.head ?? t.documentElement)?.appendChild(a);
10
+ else {
11
+ let e = t.firstChild;
12
+ for (; e && n.has(e);) e = e.nextSibling;
13
+ t.insertBefore(a, e);
14
+ }
15
+ return a;
16
+ }, d = (e, r) => {
17
+ let i = t.get(r);
18
+ i || (i = /* @__PURE__ */ new Map(), t.set(r, i));
19
+ let { scopeId: a } = e.styles, o = i.get(a);
20
+ o || (o = {
21
+ count: 0,
22
+ element: r.querySelector(`style[data-cossack-style="${a}"]`) ?? u(r, e.styles)
23
+ }, n.add(o.element), i.set(a, o)), o.count++, e.root = r;
24
+ }, f = (e) => {
25
+ for (let t of r) {
26
+ let n = l(t.anchor, e);
27
+ n && (r.delete(t), d(t, n));
28
+ }
29
+ }, p = () => {
30
+ o = !1, f(!0);
31
+ let e = i;
32
+ i = [];
33
+ for (let { root: r, scopeId: i } of e) {
34
+ let e = t.get(r), a = e?.get(i);
35
+ !a || --a.count > 0 || (e.delete(i), n.delete(a.element), a.element.remove());
36
+ }
37
+ }, m = () => {
38
+ a || (a = !0, queueMicrotask(() => {
39
+ a = !1, f(!0);
40
+ }));
41
+ }, h = () => {
42
+ o || (o = !0, setTimeout(p, 0));
43
+ }, g = (e, t) => {
44
+ let n = {
45
+ styles: e,
46
+ anchor: t,
47
+ root: null,
48
+ released: !1
49
+ };
50
+ return r.add(n), m(), n;
51
+ }, _ = (e) => {
52
+ if (!e.released) {
53
+ if (e.released = !0, !e.root) {
54
+ r.delete(e);
55
+ return;
56
+ }
57
+ i.push({
58
+ root: e.root,
59
+ scopeId: e.styles.scopeId
60
+ }), e.root = null, h();
61
+ }
62
+ }, v = (e) => {
63
+ if (e.released || !e.root || !e.anchor.isConnected) return;
64
+ let t = e.anchor.getRootNode();
65
+ t === e.root || !(s(t) || c(t)) || (i.push({
66
+ root: e.root,
67
+ scopeId: e.styles.scopeId
68
+ }), d(e, t), h());
69
+ }, y = () => {
70
+ r.size > 0 && f(!1);
71
+ }, b = (e) => n.has(e);
72
+ //#endregion
73
+ export { g as acquireStyle, y as flushStyleAcquisitions, b as isManagedStyle, _ as releaseStyle, v as updateStyleRoot };
@@ -0,0 +1,47 @@
1
+ import type { CSSResultGroup } from './css-result.js';
2
+ export interface FinalizedStyles {
3
+ readonly cssText: string;
4
+ readonly scopeId: string;
5
+ }
6
+ /** One component style scope a render used: its id and its scoped CSS. */
7
+ export interface ComponentStyle {
8
+ readonly scopeId: string;
9
+ readonly cssText: string;
10
+ }
11
+ type StyledClass = Function & {
12
+ styles?: CSSResultGroup;
13
+ };
14
+ type StyleFinalizer = (styles: CSSResultGroup) => FinalizedStyles;
15
+ /** @internal Installed when css`` or unsafeCSS() constructs component styles. */
16
+ export declare const registerStyleFinalizer: (finalizer: StyleFinalizer) => void;
17
+ /** @internal Components without styles never need the CSS parser. */
18
+ export declare const getFinalizedStyles: (componentClass: StyledClass) => FinalizedStyles | null;
19
+ /**
20
+ * @internal The stylesheet for a scope that templates carry, or undefined when
21
+ * there is nothing to emit (unknown scope or empty CSS).
22
+ */
23
+ export declare const stylesForScope: (scopeId: string) => FinalizedStyles | undefined;
24
+ /** @internal Called by SSR for every template rendered in a style scope. */
25
+ export declare const recordStyleScope: (scopeId: string) => void;
26
+ /**
27
+ * Run a synchronous server render and return the component style scopes it
28
+ * used, in first-use order. Components do not inline their styles: emit the
29
+ * returned styles once per page, in `<head>`, with `renderComponentStyles()`.
30
+ *
31
+ * ```ts
32
+ * const { result: body, styles } = collectComponentStyles(() => renderToString(page, { hydrate: true }));
33
+ * const head = renderComponentStyles(styles);
34
+ * ```
35
+ */
36
+ export declare const collectComponentStyles: <T>(render: () => T) => {
37
+ result: T;
38
+ styles: ComponentStyle[];
39
+ };
40
+ /** Attribute naming the scope on every managed component `<style>` element. */
41
+ export declare const COMPONENT_STYLE_ATTRIBUTE = "data-cossack-style";
42
+ /**
43
+ * One `<style data-cossack-style="<scope id>">` element per collected scope.
44
+ * The client adopts these elements on hydration instead of inserting copies.
45
+ */
46
+ export declare const renderComponentStyles: (styles: readonly ComponentStyle[]) => string;
47
+ export {};
@@ -0,0 +1,43 @@
1
+ // @ts-self-types="./style-runtime.d.ts"
2
+ //#region src/style-runtime.ts
3
+ var e, t = /* @__PURE__ */ new WeakMap(), n = /* @__PURE__ */ new Map(), r = (e) => Array.isArray(e) && e.every(r), i = (t) => {
4
+ e = t;
5
+ }, a = (i) => {
6
+ if (t.has(i)) return t.get(i);
7
+ let a = i.styles, o;
8
+ if (a === void 0) o = null;
9
+ else if (e) o = e(a);
10
+ else if (r(a)) o = {
11
+ cssText: "",
12
+ scopeId: "cztntfp"
13
+ };
14
+ else throw TypeError("[cossack/renderer] static styles must contain only CSSResult values returned by css`` or unsafeCSS().");
15
+ return t.set(i, o), o && !n.has(o.scopeId) && n.set(o.scopeId, o), o;
16
+ }, o = (e) => {
17
+ let t = n.get(e);
18
+ return t && t.cssText !== "" ? t : void 0;
19
+ }, s, c = (e) => {
20
+ let t = s;
21
+ if (!t || t.has(e)) return;
22
+ let n = o(e);
23
+ n && t.set(e, {
24
+ scopeId: e,
25
+ cssText: n.cssText
26
+ });
27
+ }, l = (e) => {
28
+ let t = s, n = /* @__PURE__ */ new Map();
29
+ s = n;
30
+ try {
31
+ return {
32
+ result: e(),
33
+ styles: [...n.values()]
34
+ };
35
+ } finally {
36
+ if (s = t, t) for (let [e, r] of n) t.has(e) || t.set(e, r);
37
+ }
38
+ }, u = "data-cossack-style", d = (e) => e.map(({ scopeId: e, cssText: t }) => {
39
+ let n = t.replace(/<\/style/gi, "<\\/style");
40
+ return `<style ${u}="${e.replace(/[^a-z0-9_-]/gi, "")}">${n}</style>`;
41
+ }).join("");
42
+ //#endregion
43
+ export { u as COMPONENT_STYLE_ATTRIBUTE, l as collectComponentStyles, a as getFinalizedStyles, c as recordStyleScope, i as registerStyleFinalizer, d as renderComponentStyles, o as stylesForScope };