turbo-html2pdf-react 0.3.8 → 0.6.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/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/compile.ts","../src/sentinel.ts","../src/control-flow.tsx","../src/raw.ts","../src/paged-media.ts"],"sourcesContent":["// `turbo-html2pdf-react` — the first authoring frontend for turbo-pdf.\n//\n// React components that render *once at authoring time* to a turbo-pdf template\n// source string (Jinja control flow + `t:` paged-media directives + plain HTML).\n// React is never on the render hot path; expressions are strings resolved in Rust\n// at render. See ./compile for the entry point and ./sentinel for how literal Jinja\n// survives React's HTML-escaping.\n\nexport { compileTemplate, type CompileOptions } from \"./compile.js\";\nexport {\n Case,\n Default,\n Each,\n Else,\n ElseIf,\n Expr,\n If,\n Include,\n Switch,\n} from \"./control-flow.js\";\nexport { Raw } from \"./raw.js\";\nexport {\n Anchor,\n Counter,\n Endnote,\n Endnotes,\n Footnote,\n FootnoteSeparator,\n Leader,\n Page,\n PageMaster,\n Pages,\n Region,\n Running,\n RunningFooter,\n RunningHeader,\n UseMaster,\n Variant,\n} from \"./paged-media.js\";\n","// The public authoring entry point: turn a React element tree into a turbo-pdf\n// template *source string* (Jinja control flow + `t:` paged-media directives +\n// plain HTML). React runs **once at authoring time** here via `renderToStaticMarkup`;\n// it is never on the render hot path and has no access to render data (§8.4).\n\nimport type { ReactElement } from \"react\";\nimport { renderToStaticMarkup } from \"react-dom/server\";\nimport { expandSentinels } from \"./sentinel.js\";\n\n/** Options for {@link compileTemplate}. */\nexport interface CompileOptions {\n /**\n * Trim insignificant leading/trailing whitespace from the final string. On by\n * default; this is the only normalization applied (the interior is verbatim).\n */\n trim?: boolean;\n}\n\n/**\n * Render `element` to a turbo-pdf template source string.\n *\n * Pipeline: `renderToStaticMarkup` produces HTML where plain elements and `t:`\n * directives are emitted (and legitimately HTML-escaped) as-is, while control-flow\n * components emitted sentinel tokens carrying their literal Jinja. `expandSentinels`\n * then decodes those tokens into real `{% … %}` / `{{ … }}` text — the one\n * post-process pass that undoes nothing else, so the result is byte-stable.\n */\nexport function compileTemplate(element: ReactElement, options: CompileOptions = {}): string {\n const markup = renderToStaticMarkup(element);\n const expanded = expandSentinels(markup);\n return options.trim === false ? expanded : expanded.trim();\n}\n","// The Jinja-escaping problem, solved.\n//\n// React's `renderToStaticMarkup` HTML-escapes text children (`<` -> `<`,\n// `&` -> `&`, …) and attribute values (`\"` -> `"`, …). Our control-flow\n// components must emit *literal* Jinja statements like `{% if total > 0 %}` whose\n// expression strings contain `<`, `>`, `&`, `\"` that React would mangle.\n//\n// Approach: control-flow components do NOT render Jinja text directly. They render\n// a *sentinel token* — a base64url payload wrapped in two Unicode Private-Use-Area\n// characters (`` … ``). Those characters are not HTML-special, so React\n// passes them through `renderToStaticMarkup` byte-for-byte, no escaping. A single\n// post-process pass (`expandSentinels`) decodes each payload back into the literal\n// Jinja string. Plain HTML and `t:` elements are emitted by React normally and kept\n// verbatim — they legitimately *want* HTML escaping.\n//\n// Base64url keeps the encoded payload free of `<`, `>`, `&`, `\"`, `'`, `=` and the\n// sentinel chars themselves, so a payload can never be confused with markup or with\n// another sentinel.\n\nconst OPEN = \"\";\nconst CLOSE = \"\";\n\n/** Encode arbitrary text to a base64url string (no padding, HTML-safe alphabet). */\nfunction toBase64Url(text: string): string {\n const bytes = new TextEncoder().encode(text);\n let binary = \"\";\n for (const byte of bytes) {\n binary += String.fromCharCode(byte);\n }\n return btoa(binary).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\n\n/** Decode a base64url string produced by {@link toBase64Url}. */\nfunction fromBase64Url(encoded: string): string {\n const padded = encoded.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const binary = atob(padded);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return new TextDecoder().decode(bytes);\n}\n\n/** Wrap literal Jinja text in a sentinel token so React emits it un-escaped. */\nexport function sentinel(literal: string): string {\n return `${OPEN}${toBase64Url(literal)}${CLOSE}`;\n}\n\n/** Replace every sentinel token in `markup` with its decoded literal Jinja text. */\nexport function expandSentinels(markup: string): string {\n const pattern = new RegExp(`${OPEN}([A-Za-z0-9_-]*)${CLOSE}`, \"g\");\n return markup.replace(pattern, (_match, payload: string) => fromBase64Url(payload));\n}\n","// Control-flow components. These map to **Jinja statements**, never to `t:`\n// elements (a Jinja block tag is gone by the time html5ever sees the markup,\n// whereas structure that must survive into the DOM uses `t:` elements — §2).\n//\n// Each component emits literal Jinja via sentinel tokens (see ./sentinel) so the\n// expression strings survive React's HTML-escaping untouched. Attributes carry\n// **expression strings**, not evaluated JS: `cond=\"total > 0\"` stays the literal\n// `total > 0`.\n\nimport { Fragment, type ReactNode } from \"react\";\nimport { sentinel } from \"./sentinel.js\";\n\n/** A bare Jinja statement, e.g. `wrap(\"if total > 0\")` -> `{% if total > 0 %}`. */\nfunction statement(body: string): string {\n return sentinel(`{% ${body} %}`);\n}\n\n/** `{% if COND %} … {% endif %}` (§2.5). Chain with `<ElseIf>` / `<Else>`. */\nexport function If(props: { cond: string; children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(`if ${props.cond}`)}\n {props.children}\n {statement(\"endif\")}\n </Fragment>\n );\n}\n\n/** `{% elif COND %}` — a sibling inside the same `<If>` body (§2.5). */\nexport function ElseIf(props: { cond: string; children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(`elif ${props.cond}`)}\n {props.children}\n </Fragment>\n );\n}\n\n/** `{% else %}` — a sibling inside the same `<If>` (or `<Each>`) body (§2.5/2.7). */\nexport function Else(props: { children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(\"else\")}\n {props.children}\n </Fragment>\n );\n}\n\n/**\n * `{% for AS in OF %} … {% endfor %}` (§2.7). When `index` is supplied, the body\n * is prefixed with `{% set <index> = loop.index0 %}` so authors get a named\n * 0-based index.\n *\n * TODO(phase11): stock Jinja has no per-name index binding in the `for` header —\n * the built-in `loop.index`/`loop.index0` are always available. We model the\n * optional `index` prop as a `{% set %}` of `loop.index0` at body top, which is\n * the closest portable equivalent.\n */\nexport function Each(props: {\n of: string;\n as: string;\n index?: string;\n children?: ReactNode;\n}): ReactNode {\n return (\n <Fragment>\n {statement(`for ${props.as} in ${props.of}`)}\n {props.index ? statement(`set ${props.index} = loop.index0`) : null}\n {props.children}\n {statement(\"endfor\")}\n </Fragment>\n );\n}\n\n/** `{% switch ON %} … {% endswitch %}` (§2.6). Children are `<Case>` / `<Default>`. */\nexport function Switch(props: { on: string; children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(`switch ${props.on}`)}\n {props.children}\n {statement(\"endswitch\")}\n </Fragment>\n );\n}\n\n/** `{% case V1, V2, … %}` — comma means membership; first match wins (§2.6). */\nexport function Case(props: { value: string; children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(`case ${props.value}`)}\n {props.children}\n </Fragment>\n );\n}\n\n/** `{% default %}` — must be the last child of `<Switch>` (§2.6). */\nexport function Default(props: { children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(\"default\")}\n {props.children}\n </Fragment>\n );\n}\n\n/** Build the `include` statement, appending `with { … }` context when given. */\nfunction includeStatement(src: string, withCtx?: string): string {\n return withCtx ? `include ${src} with ${withCtx}` : `include ${src}`;\n}\n\n/**\n * `{% include SRC %}` / `{% include SRC with CTX %}` (§2.8). `src` is an\n * expression string (usually a quoted partial name, e.g. `\"remittance\"`).\n */\nexport function Include(props: { src: string; with?: string }): ReactNode {\n return <Fragment>{statement(includeStatement(props.src, props.with))}</Fragment>;\n}\n\n/** `{{ EXPR }}` interpolation (§2.4). The expression is resolved in Rust at render. */\nexport function Expr(props: { value: string }): ReactNode {\n return <Fragment>{sentinel(`{{ ${props.value} }}`)}</Fragment>;\n}\n","// Raw passthrough escape hatch.\n//\n// React's JSX intrinsics impose their own attribute model: `class`/`colspan` warn\n// (they want `className`/`colSpan`, though they still render), and `style` MUST be\n// an object — a `style=\"color:#111\"` *string* is a hard error. turbo-pdf templates,\n// by contrast, are plain HTML where `class`, `style=\"…\"`, and `t:style` are ordinary\n// string attributes (spec §8.4). `<Raw html=\"…\" />` lets an author drop a literal\n// markup fragment that bypasses React's attribute model entirely: the string is\n// emitted verbatim (un-escaped) via the same sentinel channel the control-flow\n// components use, so whatever you write is exactly what lands in the template.\n//\n// The author owns well-formedness here (just like hand-authored HTML); the markup is\n// re-parsed by html5ever in the core.\n\nimport { createElement, Fragment, type ReactElement } from \"react\";\nimport { sentinel } from \"./sentinel.js\";\n\n/** Emit `props.html` verbatim into the template (no HTML-escaping, no React model). */\nexport function Raw(props: { html: string }): ReactElement {\n return createElement(Fragment, null, sentinel(props.html));\n}\n","// Paged-media components. These map to the `t:` directive elements that must\n// survive into the parsed DOM as typed layout nodes (§3). The element names match\n// `turbo-pdf-core`'s authoritative `t_kind()` table exactly (node.rs).\n//\n// We build these with `createElement(string, …)` rather than JSX, because a JSX\n// tag like `<t:running-header>` parses as the member expression `t.running` — the\n// `t:` namespace prefix is only valid as a *string* tag name. React DOM renders an\n// arbitrary string tag verbatim, and `renderToStaticMarkup` HTML-escapes the\n// attribute values and text children exactly as a hand-written template would, so\n// the `t:` output is byte-identical to hand-authored markup.\n\nimport { createElement, type ReactElement, type ReactNode } from \"react\";\n\n/** Drop `undefined`-valued attributes so they don't render as `attr=\"undefined\"`. */\nfunction defined(attrs: Record<string, string | undefined>): Record<string, string> {\n const out: Record<string, string> = {};\n for (const [key, value] of Object.entries(attrs)) {\n if (value !== undefined) {\n out[key] = value;\n }\n }\n return out;\n}\n\n/** Create a `t:`-prefixed directive element with the given attrs and children. */\nfunction directive(\n name: string,\n attrs: Record<string, string | undefined>,\n children?: ReactNode,\n): ReactElement {\n return createElement(`t:${name}`, defined(attrs), children);\n}\n\n/** `<t:running-header>` — attaches header content to every page's top band (§3.0). */\nexport function RunningHeader(props: { extent?: string; children?: ReactNode }): ReactElement {\n return directive(\"running-header\", { extent: props.extent }, props.children);\n}\n\n/** `<t:running-footer>` — attaches footer content to every page's bottom band (§3.0). */\nexport function RunningFooter(props: { extent?: string; children?: ReactNode }): ReactElement {\n return directive(\"running-footer\", { extent: props.extent }, props.children);\n}\n\n/** `<t:page-master>` — named geometry + region bundle (§3.1). */\nexport function PageMaster(props: {\n name: string;\n size?: string;\n orientation?: string;\n margin?: string;\n children?: ReactNode;\n}): ReactElement {\n return directive(\n \"page-master\",\n {\n name: props.name,\n size: props.size,\n orientation: props.orientation,\n margin: props.margin,\n },\n props.children,\n );\n}\n\n/** `<t:region slot extent>` — a margin-box region inside a master (§3.1). */\nexport function Region(props: {\n slot: string;\n extent?: string;\n children?: ReactNode;\n}): ReactElement {\n return directive(\"region\", { slot: props.slot, extent: props.extent }, props.children);\n}\n\n/** `<t:variant kind>` — first/left/right/blank override inside a master (§3.2). */\nexport function Variant(props: { kind: string; children?: ReactNode }): ReactElement {\n return directive(\"variant\", { kind: props.kind }, props.children);\n}\n\n/** `<t:use-master name>` — switches the active master from flow position (§3.4). */\nexport function UseMaster(props: { name: string }): ReactElement {\n return directive(\"use-master\", { name: props.name });\n}\n\n/** `<t:footnote>` — inline footnote reference + body (§3.6). */\nexport function Footnote(props: {\n mark?: string;\n reset?: string;\n children?: ReactNode;\n}): ReactElement {\n return directive(\n \"footnote\",\n { mark: props.mark, \"t:footnote-reset\": props.reset },\n props.children,\n );\n}\n\n/** `<t:footnote-separator>` — the rule between body and footnote area (§3.6). */\nexport function FootnoteSeparator(props: { children?: ReactNode }): ReactElement {\n return directive(\"footnote-separator\", {}, props.children);\n}\n\n/** `<t:counter name action step start>` — a general named counter (§3.8). */\nexport function Counter(props: {\n name: string;\n action?: string;\n step?: string;\n start?: string;\n}): ReactElement {\n return directive(\"counter\", {\n name: props.name,\n action: props.action,\n step: props.step,\n start: props.start,\n });\n}\n\n/** `<t:leader>` — dot-fill between two inline boxes, for TOCs/footers (§3.10). */\nexport function Leader(props: { children?: ReactNode }): ReactElement {\n return directive(\"leader\", {}, props.children);\n}\n\n/** `<t:anchor id>` — a cross-reference target (§3.9, feature-gated in core). */\nexport function Anchor(props: { id: string }): ReactElement {\n return directive(\"anchor\", { id: props.id });\n}\n\n/** `<t:endnote>` — collects to a `<t:endnotes/>` sink (§3.7, feature-gated). */\nexport function Endnote(props: { children?: ReactNode }): ReactElement {\n return directive(\"endnote\", {}, props.children);\n}\n\n/** `<t:endnotes/>` — the endnote sink (§3.7, feature-gated). */\nexport function Endnotes(): ReactElement {\n return directive(\"endnotes\", {});\n}\n\n/**\n * Named running element (§3.5). There is **no** `t:running` element in the core's\n * authoritative `t_kind()` table — running content is marked with the\n * `t:running=\"name\"` *attribute* on a normal element (`<h1 t:running=\"section\">`).\n * So `<Running name=\"section\">` renders that attribute on a host element (default\n * `<span>`, override via `as`), optionally with `t:running-policy`.\n *\n * TODO(phase11): the handoff sketched `<Running>` -> `<t:running>`, but node.rs\n * has no such directive; spec §3.5 defines it as an attribute, which is what we emit.\n */\nexport function Running(props: {\n name: string;\n as?: string;\n policy?: string;\n children?: ReactNode;\n}): ReactElement {\n return createElement(\n props.as ?? \"span\",\n defined({ \"t:running\": props.name, \"t:running-policy\": props.policy }),\n props.children,\n );\n}\n\n/** `<t:page/>` — current 1-based page number convenience element (§3.3). */\nexport function Page(): ReactElement {\n return directive(\"page\", {});\n}\n\n/** `<t:pages/>` — total page count convenience element (§3.3). */\nexport function Pages(): ReactElement {\n return directive(\"pages\", {});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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SAAS,OAIR;AACf,SAAO;AAAA,IACL;AAAA,IACA,EAAE,MAAM,MAAM,MAAM,oBAAoB,MAAM,MAAM;AAAA,IACpD,MAAM;AAAA,EACR;AACF;AAGO,SAAS,kBAAkB,OAA+C;AAC/E,SAAO,UAAU,sBAAsB,CAAC,GAAG,MAAM,QAAQ;AAC3D;AAGO,SAAS,QAAQ,OAKP;AACf,SAAO,UAAU,WAAW;AAAA,IAC1B,MAAM,MAAM;AAAA,IACZ,QAAQ,MAAM;AAAA,IACd,MAAM,MAAM;AAAA,IACZ,OAAO,MAAM;AAAA,EACf,CAAC;AACH;AAGO,SAAS,OAAO,OAA+C;AACpE,SAAO,UAAU,UAAU,CAAC,GAAG,MAAM,QAAQ;AAC/C;AAGO,SAAS,OAAO,OAAqC;AAC1D,SAAO,UAAU,UAAU,EAAE,IAAI,MAAM,GAAG,CAAC;AAC7C;AAGO,SAAS,QAAQ,OAA+C;AACrE,SAAO,UAAU,WAAW,CAAC,GAAG,MAAM,QAAQ;AAChD;AAGO,SAAS,WAAyB;AACvC,SAAO,UAAU,YAAY,CAAC,CAAC;AACjC;AAYO,SAAS,QAAQ,OAKP;AACf,aAAO;AAAA,IACL,MAAM,MAAM;AAAA,IACZ,QAAQ,EAAE,aAAa,MAAM,MAAM,oBAAoB,MAAM,OAAO,CAAC;AAAA,IACrE,MAAM;AAAA,EACR;AACF;AAGO,SAAS,OAAqB;AACnC,SAAO,UAAU,QAAQ,CAAC,CAAC;AAC7B;AAGO,SAAS,QAAsB;AACpC,SAAO,UAAU,SAAS,CAAC,CAAC;AAC9B;","names":["import_react","import_react"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/compile.ts","../src/sentinel.ts","../src/control-flow.tsx","../src/raw.ts","../src/paged-media.ts"],"sourcesContent":["// `turbo-html2pdf-react` — the first authoring frontend for turbo-pdf.\n//\n// React components that render *once at authoring time* to a turbo-pdf template\n// source string (Jinja control flow + `t:` paged-media directives + plain HTML).\n// React is never on the render hot path; expressions are strings resolved in Rust\n// at render. See ./compile for the entry point and ./sentinel for how literal Jinja\n// survives React's HTML-escaping.\n\nexport { compileTemplate, type CompileOptions } from \"./compile.js\";\nexport {\n Case,\n Default,\n Each,\n Else,\n ElseIf,\n Expr,\n If,\n Include,\n Switch,\n} from \"./control-flow.js\";\nexport { Raw } from \"./raw.js\";\nexport {\n Anchor,\n Counter,\n Endnote,\n Endnotes,\n Footnote,\n FootnoteSeparator,\n Leader,\n Page,\n PageMaster,\n Pages,\n Region,\n Running,\n RunningFooter,\n RunningHeader,\n UseMaster,\n Variant,\n} from \"./paged-media.js\";\n","// The public authoring entry point: turn a React element tree into a turbo-pdf\n// template *source string* (Jinja control flow + `t:` paged-media directives +\n// plain HTML). React runs **once at authoring time** here via `renderToStaticMarkup`;\n// it is never on the render hot path and has no access to render data (§8.4).\n\nimport type { ReactElement } from \"react\";\nimport { renderToStaticMarkup } from \"react-dom/server\";\nimport { expandSentinels } from \"./sentinel.js\";\n\n/** Options for {@link compileTemplate}. */\nexport interface CompileOptions {\n /**\n * Trim insignificant leading/trailing whitespace from the final string. On by\n * default; this is the only normalization applied (the interior is verbatim).\n */\n trim?: boolean;\n}\n\n/**\n * Render `element` to a turbo-pdf template source string.\n *\n * Pipeline: `renderToStaticMarkup` produces HTML where plain elements and `t:`\n * directives are emitted (and legitimately HTML-escaped) as-is, while control-flow\n * components emitted sentinel tokens carrying their literal Jinja. `expandSentinels`\n * then decodes those tokens into real `{% … %}` / `{{ … }}` text — the one\n * post-process pass that undoes nothing else, so the result is byte-stable.\n */\nexport function compileTemplate(element: ReactElement, options: CompileOptions = {}): string {\n const markup = renderToStaticMarkup(element);\n const expanded = expandSentinels(markup);\n return options.trim === false ? expanded : expanded.trim();\n}\n","// The Jinja-escaping problem, solved.\n//\n// React's `renderToStaticMarkup` HTML-escapes text children (`<` -> `<`,\n// `&` -> `&`, …) and attribute values (`\"` -> `"`, …). Our control-flow\n// components must emit *literal* Jinja statements like `{% if total > 0 %}` whose\n// expression strings contain `<`, `>`, `&`, `\"` that React would mangle.\n//\n// Approach: control-flow components do NOT render Jinja text directly. They render\n// a *sentinel token* — a base64url payload wrapped in two Unicode Private-Use-Area\n// characters (`` … ``). Those characters are not HTML-special, so React\n// passes them through `renderToStaticMarkup` byte-for-byte, no escaping. A single\n// post-process pass (`expandSentinels`) decodes each payload back into the literal\n// Jinja string. Plain HTML and `t:` elements are emitted by React normally and kept\n// verbatim — they legitimately *want* HTML escaping.\n//\n// Base64url keeps the encoded payload free of `<`, `>`, `&`, `\"`, `'`, `=` and the\n// sentinel chars themselves, so a payload can never be confused with markup or with\n// another sentinel.\n\nconst OPEN = \"\";\nconst CLOSE = \"\";\n\n/** Encode arbitrary text to a base64url string (no padding, HTML-safe alphabet). */\nfunction toBase64Url(text: string): string {\n const bytes = new TextEncoder().encode(text);\n let binary = \"\";\n for (const byte of bytes) {\n binary += String.fromCharCode(byte);\n }\n return btoa(binary).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\n\n/** Decode a base64url string produced by {@link toBase64Url}. */\nfunction fromBase64Url(encoded: string): string {\n const padded = encoded.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const binary = atob(padded);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return new TextDecoder().decode(bytes);\n}\n\n/** Wrap literal Jinja text in a sentinel token so React emits it un-escaped. */\nexport function sentinel(literal: string): string {\n return `${OPEN}${toBase64Url(literal)}${CLOSE}`;\n}\n\n/** Replace every sentinel token in `markup` with its decoded literal Jinja text. */\nexport function expandSentinels(markup: string): string {\n const pattern = new RegExp(`${OPEN}([A-Za-z0-9_-]*)${CLOSE}`, \"g\");\n return markup.replace(pattern, (_match, payload: string) => fromBase64Url(payload));\n}\n","// Control-flow components. These map to **Jinja statements**, never to `t:`\n// elements (a Jinja block tag is gone by the time html5ever sees the markup,\n// whereas structure that must survive into the DOM uses `t:` elements — §2).\n//\n// Each component emits literal Jinja via sentinel tokens (see ./sentinel) so the\n// expression strings survive React's HTML-escaping untouched. Attributes carry\n// **expression strings**, not evaluated JS: `cond=\"total > 0\"` stays the literal\n// `total > 0`.\n\nimport { Fragment, type ReactNode } from \"react\";\nimport { sentinel } from \"./sentinel.js\";\n\n/** A bare Jinja statement, e.g. `wrap(\"if total > 0\")` -> `{% if total > 0 %}`. */\nfunction statement(body: string): string {\n return sentinel(`{% ${body} %}`);\n}\n\n/** `{% if COND %} … {% endif %}` (§2.5). Chain with `<ElseIf>` / `<Else>`. */\nexport function If(props: { cond: string; children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(`if ${props.cond}`)}\n {props.children}\n {statement(\"endif\")}\n </Fragment>\n );\n}\n\n/** `{% elif COND %}` — a sibling inside the same `<If>` body (§2.5). */\nexport function ElseIf(props: { cond: string; children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(`elif ${props.cond}`)}\n {props.children}\n </Fragment>\n );\n}\n\n/** `{% else %}` — a sibling inside the same `<If>` (or `<Each>`) body (§2.5/2.7). */\nexport function Else(props: { children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(\"else\")}\n {props.children}\n </Fragment>\n );\n}\n\n/**\n * `{% for AS in OF %} … {% endfor %}` (§2.7). When `index` is supplied, the body\n * is prefixed with `{% set <index> = loop.index0 %}` so authors get a named\n * 0-based index.\n *\n * TODO(phase11): stock Jinja has no per-name index binding in the `for` header —\n * the built-in `loop.index`/`loop.index0` are always available. We model the\n * optional `index` prop as a `{% set %}` of `loop.index0` at body top, which is\n * the closest portable equivalent.\n */\nexport function Each(props: {\n of: string;\n as: string;\n index?: string;\n children?: ReactNode;\n}): ReactNode {\n return (\n <Fragment>\n {statement(`for ${props.as} in ${props.of}`)}\n {props.index ? statement(`set ${props.index} = loop.index0`) : null}\n {props.children}\n {statement(\"endfor\")}\n </Fragment>\n );\n}\n\n/** `{% switch ON %} … {% endswitch %}` (§2.6). Children are `<Case>` / `<Default>`. */\nexport function Switch(props: { on: string; children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(`switch ${props.on}`)}\n {props.children}\n {statement(\"endswitch\")}\n </Fragment>\n );\n}\n\n/** `{% case V1, V2, … %}` — comma means membership; first match wins (§2.6). */\nexport function Case(props: { value: string; children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(`case ${props.value}`)}\n {props.children}\n </Fragment>\n );\n}\n\n/** `{% default %}` — must be the last child of `<Switch>` (§2.6). */\nexport function Default(props: { children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(\"default\")}\n {props.children}\n </Fragment>\n );\n}\n\n/** Build the `include` statement, appending `with { … }` context when given. */\nfunction includeStatement(src: string, withCtx?: string): string {\n return withCtx ? `include ${src} with ${withCtx}` : `include ${src}`;\n}\n\n/**\n * `{% include SRC %}` / `{% include SRC with CTX %}` (§2.8). `src` is an\n * expression string (usually a quoted partial name, e.g. `\"remittance\"`).\n */\nexport function Include(props: { src: string; with?: string }): ReactNode {\n return <Fragment>{statement(includeStatement(props.src, props.with))}</Fragment>;\n}\n\n/** `{{ EXPR }}` interpolation (§2.4). The expression is resolved in Rust at render. */\nexport function Expr(props: { value: string }): ReactNode {\n return <Fragment>{sentinel(`{{ ${props.value} }}`)}</Fragment>;\n}\n","// Raw passthrough escape hatch.\n//\n// React's JSX intrinsics impose their own attribute model: `class`/`colspan` warn\n// (they want `className`/`colSpan`, though they still render), and `style` MUST be\n// an object — a `style=\"color:#111\"` *string* is a hard error. turbo-pdf templates,\n// by contrast, are plain HTML where `class`, `style=\"…\"`, and `t:style` are ordinary\n// string attributes (spec §8.4). `<Raw html=\"…\" />` lets an author drop a literal\n// markup fragment that bypasses React's attribute model entirely: the string is\n// emitted verbatim (un-escaped) via the same sentinel channel the control-flow\n// components use, so whatever you write is exactly what lands in the template.\n//\n// The author owns well-formedness here (just like hand-authored HTML); the markup is\n// re-parsed by html5ever in the core.\n\nimport { createElement, Fragment, type ReactElement } from \"react\";\nimport { sentinel } from \"./sentinel.js\";\n\n/** Emit `props.html` verbatim into the template (no HTML-escaping, no React model). */\nexport function Raw(props: { html: string }): ReactElement {\n return createElement(Fragment, null, sentinel(props.html));\n}\n","// Paged-media components. These map to the `t:` directive elements that must\n// survive into the parsed DOM as typed layout nodes (§3). The element names match\n// `turbo-html2pdf-core`'s authoritative `t_kind()` table exactly (src/markers.rs).\n//\n// We build these with `createElement(string, …)` rather than JSX, because a JSX\n// tag like `<t:running-header>` parses as the member expression `t.running` — the\n// `t:` namespace prefix is only valid as a *string* tag name. React DOM renders an\n// arbitrary string tag verbatim, and `renderToStaticMarkup` HTML-escapes the\n// attribute values and text children exactly as a hand-written template would, so\n// the `t:` output is byte-identical to hand-authored markup.\n\nimport { createElement, type ReactElement, type ReactNode } from \"react\";\n\n/** Drop `undefined`-valued attributes so they don't render as `attr=\"undefined\"`. */\nfunction defined(attrs: Record<string, string | undefined>): Record<string, string> {\n const out: Record<string, string> = {};\n for (const [key, value] of Object.entries(attrs)) {\n if (value !== undefined) {\n out[key] = value;\n }\n }\n return out;\n}\n\n/** Create a `t:`-prefixed directive element with the given attrs and children. */\nfunction directive(\n name: string,\n attrs: Record<string, string | undefined>,\n children?: ReactNode,\n): ReactElement {\n return createElement(`t:${name}`, defined(attrs), children);\n}\n\n/** `<t:running-header>` — attaches header content to every page's top band (§3.0). */\nexport function RunningHeader(props: { extent?: string; children?: ReactNode }): ReactElement {\n return directive(\"running-header\", { extent: props.extent }, props.children);\n}\n\n/** `<t:running-footer>` — attaches footer content to every page's bottom band (§3.0). */\nexport function RunningFooter(props: { extent?: string; children?: ReactNode }): ReactElement {\n return directive(\"running-footer\", { extent: props.extent }, props.children);\n}\n\n/** `<t:page-master>` — named geometry + region bundle (§3.1). */\nexport function PageMaster(props: {\n name: string;\n size?: string;\n orientation?: string;\n margin?: string;\n children?: ReactNode;\n}): ReactElement {\n return directive(\n \"page-master\",\n {\n name: props.name,\n size: props.size,\n orientation: props.orientation,\n margin: props.margin,\n },\n props.children,\n );\n}\n\n/** `<t:region slot extent>` — a margin-box region inside a master (§3.1). */\nexport function Region(props: {\n slot: string;\n extent?: string;\n children?: ReactNode;\n}): ReactElement {\n return directive(\"region\", { slot: props.slot, extent: props.extent }, props.children);\n}\n\n/** `<t:variant kind>` — first/left/right/blank override inside a master (§3.2). */\nexport function Variant(props: { kind: string; children?: ReactNode }): ReactElement {\n return directive(\"variant\", { kind: props.kind }, props.children);\n}\n\n/** `<t:use-master name>` — switches the active master from flow position (§3.4). */\nexport function UseMaster(props: { name: string }): ReactElement {\n return directive(\"use-master\", { name: props.name });\n}\n\n/** `<t:footnote>` — inline footnote reference + body (§3.6). */\nexport function Footnote(props: {\n mark?: string;\n reset?: string;\n children?: ReactNode;\n}): ReactElement {\n return directive(\n \"footnote\",\n { mark: props.mark, \"t:footnote-reset\": props.reset },\n props.children,\n );\n}\n\n/** `<t:footnote-separator>` — the rule between body and footnote area (§3.6). */\nexport function FootnoteSeparator(props: { children?: ReactNode }): ReactElement {\n return directive(\"footnote-separator\", {}, props.children);\n}\n\n/** `<t:counter name action step start>` — a general named counter (§3.8). */\nexport function Counter(props: {\n name: string;\n action?: string;\n step?: string;\n start?: string;\n}): ReactElement {\n return directive(\"counter\", {\n name: props.name,\n action: props.action,\n step: props.step,\n start: props.start,\n });\n}\n\n/** `<t:leader>` — dot-fill between two inline boxes, for TOCs/footers (§3.10). */\nexport function Leader(props: { children?: ReactNode }): ReactElement {\n return directive(\"leader\", {}, props.children);\n}\n\n/** `<t:anchor id>` — a cross-reference target (§3.9, feature-gated in core). */\nexport function Anchor(props: { id: string }): ReactElement {\n return directive(\"anchor\", { id: props.id });\n}\n\n/** `<t:endnote>` — collects to a `<t:endnotes/>` sink (§3.7, feature-gated). */\nexport function Endnote(props: { children?: ReactNode }): ReactElement {\n return directive(\"endnote\", {}, props.children);\n}\n\n/** `<t:endnotes/>` — the endnote sink (§3.7, feature-gated). */\nexport function Endnotes(): ReactElement {\n return directive(\"endnotes\", {});\n}\n\n/**\n * Named running element (§3.5). There is **no** `t:running` element in the core's\n * authoritative `t_kind()` table — running content is marked with the\n * `t:running=\"name\"` *attribute* on a normal element (`<h1 t:running=\"section\">`).\n * So `<Running name=\"section\">` renders that attribute on a host element (default\n * `<span>`, override via `as`), optionally with `t:running-policy`.\n *\n * TODO(phase11): the handoff sketched `<Running>` -> `<t:running>`, but markers.rs\n * has no such directive; spec §3.5 defines it as an attribute, which is what we emit.\n */\nexport function Running(props: {\n name: string;\n as?: string;\n policy?: string;\n children?: ReactNode;\n}): ReactElement {\n return createElement(\n props.as ?? \"span\",\n defined({ \"t:running\": props.name, \"t:running-policy\": props.policy }),\n props.children,\n );\n}\n\n/** `<t:page/>` — current 1-based page number convenience element (§3.3). */\nexport function Page(): ReactElement {\n return directive(\"page\", {});\n}\n\n/** `<t:pages/>` — total page count convenience element (§3.3). */\nexport function Pages(): ReactElement {\n return directive(\"pages\", {});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMA,oBAAqC;;;ACarC,IAAM,OAAO;AACb,IAAM,QAAQ;AAGd,SAAS,YAAY,MAAsB;AACzC,QAAM,QAAQ,IAAI,YAAY,EAAE,OAAO,IAAI;AAC3C,MAAI,SAAS;AACb,aAAW,QAAQ,OAAO;AACxB,cAAU,OAAO,aAAa,IAAI;AAAA,EACpC;AACA,SAAO,KAAK,MAAM,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,EAAE;AAC/E;AAGA,SAAS,cAAc,SAAyB;AAC9C,QAAM,SAAS,QAAQ,QAAQ,MAAM,GAAG,EAAE,QAAQ,MAAM,GAAG;AAC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AAC1D,SAAO,UAAU,UAAU,EAAE,IAAI,MAAM,GAAG,CAAC;AAC7C;AAGO,SAAS,QAAQ,OAA+C;AACrE,SAAO,UAAU,WAAW,CAAC,GAAG,MAAM,QAAQ;AAChD;AAGO,SAAS,WAAyB;AACvC,SAAO,UAAU,YAAY,CAAC,CAAC;AACjC;AAYO,SAAS,QAAQ,OAKP;AACf,aAAO;AAAA,IACL,MAAM,MAAM;AAAA,IACZ,QAAQ,EAAE,aAAa,MAAM,MAAM,oBAAoB,MAAM,OAAO,CAAC;AAAA,IACrE,MAAM;AAAA,EACR;AACF;AAGO,SAAS,OAAqB;AACnC,SAAO,UAAU,QAAQ,CAAC,CAAC;AAC7B;AAGO,SAAS,QAAsB;AACpC,SAAO,UAAU,SAAS,CAAC,CAAC;AAC9B;","names":["import_react","import_react"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -152,7 +152,7 @@ declare function Endnotes(): ReactElement;
|
|
|
152
152
|
* So `<Running name="section">` renders that attribute on a host element (default
|
|
153
153
|
* `<span>`, override via `as`), optionally with `t:running-policy`.
|
|
154
154
|
*
|
|
155
|
-
* TODO(phase11): the handoff sketched `<Running>` -> `<t:running>`, but
|
|
155
|
+
* TODO(phase11): the handoff sketched `<Running>` -> `<t:running>`, but markers.rs
|
|
156
156
|
* has no such directive; spec §3.5 defines it as an attribute, which is what we emit.
|
|
157
157
|
*/
|
|
158
158
|
declare function Running(props: {
|
package/dist/index.d.ts
CHANGED
|
@@ -152,7 +152,7 @@ declare function Endnotes(): ReactElement;
|
|
|
152
152
|
* So `<Running name="section">` renders that attribute on a host element (default
|
|
153
153
|
* `<span>`, override via `as`), optionally with `t:running-policy`.
|
|
154
154
|
*
|
|
155
|
-
* TODO(phase11): the handoff sketched `<Running>` -> `<t:running>`, but
|
|
155
|
+
* TODO(phase11): the handoff sketched `<Running>` -> `<t:running>`, but markers.rs
|
|
156
156
|
* has no such directive; spec §3.5 defines it as an attribute, which is what we emit.
|
|
157
157
|
*/
|
|
158
158
|
declare function Running(props: {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/compile.ts","../src/sentinel.ts","../src/control-flow.tsx","../src/raw.ts","../src/paged-media.ts"],"sourcesContent":["// The public authoring entry point: turn a React element tree into a turbo-pdf\n// template *source string* (Jinja control flow + `t:` paged-media directives +\n// plain HTML). React runs **once at authoring time** here via `renderToStaticMarkup`;\n// it is never on the render hot path and has no access to render data (§8.4).\n\nimport type { ReactElement } from \"react\";\nimport { renderToStaticMarkup } from \"react-dom/server\";\nimport { expandSentinels } from \"./sentinel.js\";\n\n/** Options for {@link compileTemplate}. */\nexport interface CompileOptions {\n /**\n * Trim insignificant leading/trailing whitespace from the final string. On by\n * default; this is the only normalization applied (the interior is verbatim).\n */\n trim?: boolean;\n}\n\n/**\n * Render `element` to a turbo-pdf template source string.\n *\n * Pipeline: `renderToStaticMarkup` produces HTML where plain elements and `t:`\n * directives are emitted (and legitimately HTML-escaped) as-is, while control-flow\n * components emitted sentinel tokens carrying their literal Jinja. `expandSentinels`\n * then decodes those tokens into real `{% … %}` / `{{ … }}` text — the one\n * post-process pass that undoes nothing else, so the result is byte-stable.\n */\nexport function compileTemplate(element: ReactElement, options: CompileOptions = {}): string {\n const markup = renderToStaticMarkup(element);\n const expanded = expandSentinels(markup);\n return options.trim === false ? expanded : expanded.trim();\n}\n","// The Jinja-escaping problem, solved.\n//\n// React's `renderToStaticMarkup` HTML-escapes text children (`<` -> `<`,\n// `&` -> `&`, …) and attribute values (`\"` -> `"`, …). Our control-flow\n// components must emit *literal* Jinja statements like `{% if total > 0 %}` whose\n// expression strings contain `<`, `>`, `&`, `\"` that React would mangle.\n//\n// Approach: control-flow components do NOT render Jinja text directly. They render\n// a *sentinel token* — a base64url payload wrapped in two Unicode Private-Use-Area\n// characters (`` … ``). Those characters are not HTML-special, so React\n// passes them through `renderToStaticMarkup` byte-for-byte, no escaping. A single\n// post-process pass (`expandSentinels`) decodes each payload back into the literal\n// Jinja string. Plain HTML and `t:` elements are emitted by React normally and kept\n// verbatim — they legitimately *want* HTML escaping.\n//\n// Base64url keeps the encoded payload free of `<`, `>`, `&`, `\"`, `'`, `=` and the\n// sentinel chars themselves, so a payload can never be confused with markup or with\n// another sentinel.\n\nconst OPEN = \"\";\nconst CLOSE = \"\";\n\n/** Encode arbitrary text to a base64url string (no padding, HTML-safe alphabet). */\nfunction toBase64Url(text: string): string {\n const bytes = new TextEncoder().encode(text);\n let binary = \"\";\n for (const byte of bytes) {\n binary += String.fromCharCode(byte);\n }\n return btoa(binary).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\n\n/** Decode a base64url string produced by {@link toBase64Url}. */\nfunction fromBase64Url(encoded: string): string {\n const padded = encoded.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const binary = atob(padded);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return new TextDecoder().decode(bytes);\n}\n\n/** Wrap literal Jinja text in a sentinel token so React emits it un-escaped. */\nexport function sentinel(literal: string): string {\n return `${OPEN}${toBase64Url(literal)}${CLOSE}`;\n}\n\n/** Replace every sentinel token in `markup` with its decoded literal Jinja text. */\nexport function expandSentinels(markup: string): string {\n const pattern = new RegExp(`${OPEN}([A-Za-z0-9_-]*)${CLOSE}`, \"g\");\n return markup.replace(pattern, (_match, payload: string) => fromBase64Url(payload));\n}\n","// Control-flow components. These map to **Jinja statements**, never to `t:`\n// elements (a Jinja block tag is gone by the time html5ever sees the markup,\n// whereas structure that must survive into the DOM uses `t:` elements — §2).\n//\n// Each component emits literal Jinja via sentinel tokens (see ./sentinel) so the\n// expression strings survive React's HTML-escaping untouched. Attributes carry\n// **expression strings**, not evaluated JS: `cond=\"total > 0\"` stays the literal\n// `total > 0`.\n\nimport { Fragment, type ReactNode } from \"react\";\nimport { sentinel } from \"./sentinel.js\";\n\n/** A bare Jinja statement, e.g. `wrap(\"if total > 0\")` -> `{% if total > 0 %}`. */\nfunction statement(body: string): string {\n return sentinel(`{% ${body} %}`);\n}\n\n/** `{% if COND %} … {% endif %}` (§2.5). Chain with `<ElseIf>` / `<Else>`. */\nexport function If(props: { cond: string; children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(`if ${props.cond}`)}\n {props.children}\n {statement(\"endif\")}\n </Fragment>\n );\n}\n\n/** `{% elif COND %}` — a sibling inside the same `<If>` body (§2.5). */\nexport function ElseIf(props: { cond: string; children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(`elif ${props.cond}`)}\n {props.children}\n </Fragment>\n );\n}\n\n/** `{% else %}` — a sibling inside the same `<If>` (or `<Each>`) body (§2.5/2.7). */\nexport function Else(props: { children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(\"else\")}\n {props.children}\n </Fragment>\n );\n}\n\n/**\n * `{% for AS in OF %} … {% endfor %}` (§2.7). When `index` is supplied, the body\n * is prefixed with `{% set <index> = loop.index0 %}` so authors get a named\n * 0-based index.\n *\n * TODO(phase11): stock Jinja has no per-name index binding in the `for` header —\n * the built-in `loop.index`/`loop.index0` are always available. We model the\n * optional `index` prop as a `{% set %}` of `loop.index0` at body top, which is\n * the closest portable equivalent.\n */\nexport function Each(props: {\n of: string;\n as: string;\n index?: string;\n children?: ReactNode;\n}): ReactNode {\n return (\n <Fragment>\n {statement(`for ${props.as} in ${props.of}`)}\n {props.index ? statement(`set ${props.index} = loop.index0`) : null}\n {props.children}\n {statement(\"endfor\")}\n </Fragment>\n );\n}\n\n/** `{% switch ON %} … {% endswitch %}` (§2.6). Children are `<Case>` / `<Default>`. */\nexport function Switch(props: { on: string; children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(`switch ${props.on}`)}\n {props.children}\n {statement(\"endswitch\")}\n </Fragment>\n );\n}\n\n/** `{% case V1, V2, … %}` — comma means membership; first match wins (§2.6). */\nexport function Case(props: { value: string; children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(`case ${props.value}`)}\n {props.children}\n </Fragment>\n );\n}\n\n/** `{% default %}` — must be the last child of `<Switch>` (§2.6). */\nexport function Default(props: { children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(\"default\")}\n {props.children}\n </Fragment>\n );\n}\n\n/** Build the `include` statement, appending `with { … }` context when given. */\nfunction includeStatement(src: string, withCtx?: string): string {\n return withCtx ? `include ${src} with ${withCtx}` : `include ${src}`;\n}\n\n/**\n * `{% include SRC %}` / `{% include SRC with CTX %}` (§2.8). `src` is an\n * expression string (usually a quoted partial name, e.g. `\"remittance\"`).\n */\nexport function Include(props: { src: string; with?: string }): ReactNode {\n return <Fragment>{statement(includeStatement(props.src, props.with))}</Fragment>;\n}\n\n/** `{{ EXPR }}` interpolation (§2.4). The expression is resolved in Rust at render. */\nexport function Expr(props: { value: string }): ReactNode {\n return <Fragment>{sentinel(`{{ ${props.value} }}`)}</Fragment>;\n}\n","// Raw passthrough escape hatch.\n//\n// React's JSX intrinsics impose their own attribute model: `class`/`colspan` warn\n// (they want `className`/`colSpan`, though they still render), and `style` MUST be\n// an object — a `style=\"color:#111\"` *string* is a hard error. turbo-pdf templates,\n// by contrast, are plain HTML where `class`, `style=\"…\"`, and `t:style` are ordinary\n// string attributes (spec §8.4). `<Raw html=\"…\" />` lets an author drop a literal\n// markup fragment that bypasses React's attribute model entirely: the string is\n// emitted verbatim (un-escaped) via the same sentinel channel the control-flow\n// components use, so whatever you write is exactly what lands in the template.\n//\n// The author owns well-formedness here (just like hand-authored HTML); the markup is\n// re-parsed by html5ever in the core.\n\nimport { createElement, Fragment, type ReactElement } from \"react\";\nimport { sentinel } from \"./sentinel.js\";\n\n/** Emit `props.html` verbatim into the template (no HTML-escaping, no React model). */\nexport function Raw(props: { html: string }): ReactElement {\n return createElement(Fragment, null, sentinel(props.html));\n}\n","// Paged-media components. These map to the `t:` directive elements that must\n// survive into the parsed DOM as typed layout nodes (§3). The element names match\n// `turbo-pdf-core`'s authoritative `t_kind()` table exactly (node.rs).\n//\n// We build these with `createElement(string, …)` rather than JSX, because a JSX\n// tag like `<t:running-header>` parses as the member expression `t.running` — the\n// `t:` namespace prefix is only valid as a *string* tag name. React DOM renders an\n// arbitrary string tag verbatim, and `renderToStaticMarkup` HTML-escapes the\n// attribute values and text children exactly as a hand-written template would, so\n// the `t:` output is byte-identical to hand-authored markup.\n\nimport { createElement, type ReactElement, type ReactNode } from \"react\";\n\n/** Drop `undefined`-valued attributes so they don't render as `attr=\"undefined\"`. */\nfunction defined(attrs: Record<string, string | undefined>): Record<string, string> {\n const out: Record<string, string> = {};\n for (const [key, value] of Object.entries(attrs)) {\n if (value !== undefined) {\n out[key] = value;\n }\n }\n return out;\n}\n\n/** Create a `t:`-prefixed directive element with the given attrs and children. */\nfunction directive(\n name: string,\n attrs: Record<string, string | undefined>,\n children?: ReactNode,\n): ReactElement {\n return createElement(`t:${name}`, defined(attrs), children);\n}\n\n/** `<t:running-header>` — attaches header content to every page's top band (§3.0). */\nexport function RunningHeader(props: { extent?: string; children?: ReactNode }): ReactElement {\n return directive(\"running-header\", { extent: props.extent }, props.children);\n}\n\n/** `<t:running-footer>` — attaches footer content to every page's bottom band (§3.0). */\nexport function RunningFooter(props: { extent?: string; children?: ReactNode }): ReactElement {\n return directive(\"running-footer\", { extent: props.extent }, props.children);\n}\n\n/** `<t:page-master>` — named geometry + region bundle (§3.1). */\nexport function PageMaster(props: {\n name: string;\n size?: string;\n orientation?: string;\n margin?: string;\n children?: ReactNode;\n}): ReactElement {\n return directive(\n \"page-master\",\n {\n name: props.name,\n size: props.size,\n orientation: props.orientation,\n margin: props.margin,\n },\n props.children,\n );\n}\n\n/** `<t:region slot extent>` — a margin-box region inside a master (§3.1). */\nexport function Region(props: {\n slot: string;\n extent?: string;\n children?: ReactNode;\n}): ReactElement {\n return directive(\"region\", { slot: props.slot, extent: props.extent }, props.children);\n}\n\n/** `<t:variant kind>` — first/left/right/blank override inside a master (§3.2). */\nexport function Variant(props: { kind: string; children?: ReactNode }): ReactElement {\n return directive(\"variant\", { kind: props.kind }, props.children);\n}\n\n/** `<t:use-master name>` — switches the active master from flow position (§3.4). */\nexport function UseMaster(props: { name: string }): ReactElement {\n return directive(\"use-master\", { name: props.name });\n}\n\n/** `<t:footnote>` — inline footnote reference + body (§3.6). */\nexport function Footnote(props: {\n mark?: string;\n reset?: string;\n children?: ReactNode;\n}): ReactElement {\n return directive(\n \"footnote\",\n { mark: props.mark, \"t:footnote-reset\": props.reset },\n props.children,\n );\n}\n\n/** `<t:footnote-separator>` — the rule between body and footnote area (§3.6). */\nexport function FootnoteSeparator(props: { children?: ReactNode }): ReactElement {\n return directive(\"footnote-separator\", {}, props.children);\n}\n\n/** `<t:counter name action step start>` — a general named counter (§3.8). */\nexport function Counter(props: {\n name: string;\n action?: string;\n step?: string;\n start?: string;\n}): ReactElement {\n return directive(\"counter\", {\n name: props.name,\n action: props.action,\n step: props.step,\n start: props.start,\n });\n}\n\n/** `<t:leader>` — dot-fill between two inline boxes, for TOCs/footers (§3.10). */\nexport function Leader(props: { children?: ReactNode }): ReactElement {\n return directive(\"leader\", {}, props.children);\n}\n\n/** `<t:anchor id>` — a cross-reference target (§3.9, feature-gated in core). */\nexport function Anchor(props: { id: string }): ReactElement {\n return directive(\"anchor\", { id: props.id });\n}\n\n/** `<t:endnote>` — collects to a `<t:endnotes/>` sink (§3.7, feature-gated). */\nexport function Endnote(props: { children?: ReactNode }): ReactElement {\n return directive(\"endnote\", {}, props.children);\n}\n\n/** `<t:endnotes/>` — the endnote sink (§3.7, feature-gated). */\nexport function Endnotes(): ReactElement {\n return directive(\"endnotes\", {});\n}\n\n/**\n * Named running element (§3.5). There is **no** `t:running` element in the core's\n * authoritative `t_kind()` table — running content is marked with the\n * `t:running=\"name\"` *attribute* on a normal element (`<h1 t:running=\"section\">`).\n * So `<Running name=\"section\">` renders that attribute on a host element (default\n * `<span>`, override via `as`), optionally with `t:running-policy`.\n *\n * TODO(phase11): the handoff sketched `<Running>` -> `<t:running>`, but node.rs\n * has no such directive; spec §3.5 defines it as an attribute, which is what we emit.\n */\nexport function Running(props: {\n name: string;\n as?: string;\n policy?: string;\n children?: ReactNode;\n}): ReactElement {\n return createElement(\n props.as ?? \"span\",\n defined({ \"t:running\": props.name, \"t:running-policy\": props.policy }),\n props.children,\n );\n}\n\n/** `<t:page/>` — current 1-based page number convenience element (§3.3). */\nexport function Page(): ReactElement {\n return directive(\"page\", {});\n}\n\n/** `<t:pages/>` — total page count convenience element (§3.3). */\nexport function Pages(): ReactElement {\n return directive(\"pages\", {});\n}\n"],"mappings":";AAMA,SAAS,4BAA4B;;;ACarC,IAAM,OAAO;AACb,IAAM,QAAQ;AAGd,SAAS,YAAY,MAAsB;AACzC,QAAM,QAAQ,IAAI,YAAY,EAAE,OAAO,IAAI;AAC3C,MAAI,SAAS;AACb,aAAW,QAAQ,OAAO;AACxB,cAAU,OAAO,aAAa,IAAI;AAAA,EACpC;AACA,SAAO,KAAK,MAAM,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,EAAE;AAC/E;AAGA,SAAS,cAAc,SAAyB;AAC9C,QAAM,SAAS,QAAQ,QAAQ,MAAM,GAAG,EAAE,QAAQ,MAAM,GAAG;AAC3D,QAAM,SAAS,KAAK,MAAM;AAC1B,QAAM,QAAQ,IAAI,WAAW,OAAO,MAAM;AAC1C,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,UAAM,CAAC,IAAI,OAAO,WAAW,CAAC;AAAA,EAChC;AACA,SAAO,IAAI,YAAY,EAAE,OAAO,KAAK;AACvC;AAGO,SAAS,SAAS,SAAyB;AAChD,SAAO,GAAG,IAAI,GAAG,YAAY,OAAO,CAAC,GAAG,KAAK;AAC/C;AAGO,SAAS,gBAAgB,QAAwB;AACtD,QAAM,UAAU,IAAI,OAAO,GAAG,IAAI,mBAAmB,KAAK,IAAI,GAAG;AACjE,SAAO,OAAO,Q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U,QAAQ,CAAC,CAAC;AAC7B;AAGO,SAAS,QAAsB;AACpC,SAAO,UAAU,SAAS,CAAC,CAAC;AAC9B;","names":["Fragment","Fragment","createElement"]}
|
|
1
|
+
{"version":3,"sources":["../src/compile.ts","../src/sentinel.ts","../src/control-flow.tsx","../src/raw.ts","../src/paged-media.ts"],"sourcesContent":["// The public authoring entry point: turn a React element tree into a turbo-pdf\n// template *source string* (Jinja control flow + `t:` paged-media directives +\n// plain HTML). React runs **once at authoring time** here via `renderToStaticMarkup`;\n// it is never on the render hot path and has no access to render data (§8.4).\n\nimport type { ReactElement } from \"react\";\nimport { renderToStaticMarkup } from \"react-dom/server\";\nimport { expandSentinels } from \"./sentinel.js\";\n\n/** Options for {@link compileTemplate}. */\nexport interface CompileOptions {\n /**\n * Trim insignificant leading/trailing whitespace from the final string. On by\n * default; this is the only normalization applied (the interior is verbatim).\n */\n trim?: boolean;\n}\n\n/**\n * Render `element` to a turbo-pdf template source string.\n *\n * Pipeline: `renderToStaticMarkup` produces HTML where plain elements and `t:`\n * directives are emitted (and legitimately HTML-escaped) as-is, while control-flow\n * components emitted sentinel tokens carrying their literal Jinja. `expandSentinels`\n * then decodes those tokens into real `{% … %}` / `{{ … }}` text — the one\n * post-process pass that undoes nothing else, so the result is byte-stable.\n */\nexport function compileTemplate(element: ReactElement, options: CompileOptions = {}): string {\n const markup = renderToStaticMarkup(element);\n const expanded = expandSentinels(markup);\n return options.trim === false ? expanded : expanded.trim();\n}\n","// The Jinja-escaping problem, solved.\n//\n// React's `renderToStaticMarkup` HTML-escapes text children (`<` -> `<`,\n// `&` -> `&`, …) and attribute values (`\"` -> `"`, …). Our control-flow\n// components must emit *literal* Jinja statements like `{% if total > 0 %}` whose\n// expression strings contain `<`, `>`, `&`, `\"` that React would mangle.\n//\n// Approach: control-flow components do NOT render Jinja text directly. They render\n// a *sentinel token* — a base64url payload wrapped in two Unicode Private-Use-Area\n// characters (`` … ``). Those characters are not HTML-special, so React\n// passes them through `renderToStaticMarkup` byte-for-byte, no escaping. A single\n// post-process pass (`expandSentinels`) decodes each payload back into the literal\n// Jinja string. Plain HTML and `t:` elements are emitted by React normally and kept\n// verbatim — they legitimately *want* HTML escaping.\n//\n// Base64url keeps the encoded payload free of `<`, `>`, `&`, `\"`, `'`, `=` and the\n// sentinel chars themselves, so a payload can never be confused with markup or with\n// another sentinel.\n\nconst OPEN = \"\";\nconst CLOSE = \"\";\n\n/** Encode arbitrary text to a base64url string (no padding, HTML-safe alphabet). */\nfunction toBase64Url(text: string): string {\n const bytes = new TextEncoder().encode(text);\n let binary = \"\";\n for (const byte of bytes) {\n binary += String.fromCharCode(byte);\n }\n return btoa(binary).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\n\n/** Decode a base64url string produced by {@link toBase64Url}. */\nfunction fromBase64Url(encoded: string): string {\n const padded = encoded.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const binary = atob(padded);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return new TextDecoder().decode(bytes);\n}\n\n/** Wrap literal Jinja text in a sentinel token so React emits it un-escaped. */\nexport function sentinel(literal: string): string {\n return `${OPEN}${toBase64Url(literal)}${CLOSE}`;\n}\n\n/** Replace every sentinel token in `markup` with its decoded literal Jinja text. */\nexport function expandSentinels(markup: string): string {\n const pattern = new RegExp(`${OPEN}([A-Za-z0-9_-]*)${CLOSE}`, \"g\");\n return markup.replace(pattern, (_match, payload: string) => fromBase64Url(payload));\n}\n","// Control-flow components. These map to **Jinja statements**, never to `t:`\n// elements (a Jinja block tag is gone by the time html5ever sees the markup,\n// whereas structure that must survive into the DOM uses `t:` elements — §2).\n//\n// Each component emits literal Jinja via sentinel tokens (see ./sentinel) so the\n// expression strings survive React's HTML-escaping untouched. Attributes carry\n// **expression strings**, not evaluated JS: `cond=\"total > 0\"` stays the literal\n// `total > 0`.\n\nimport { Fragment, type ReactNode } from \"react\";\nimport { sentinel } from \"./sentinel.js\";\n\n/** A bare Jinja statement, e.g. `wrap(\"if total > 0\")` -> `{% if total > 0 %}`. */\nfunction statement(body: string): string {\n return sentinel(`{% ${body} %}`);\n}\n\n/** `{% if COND %} … {% endif %}` (§2.5). Chain with `<ElseIf>` / `<Else>`. */\nexport function If(props: { cond: string; children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(`if ${props.cond}`)}\n {props.children}\n {statement(\"endif\")}\n </Fragment>\n );\n}\n\n/** `{% elif COND %}` — a sibling inside the same `<If>` body (§2.5). */\nexport function ElseIf(props: { cond: string; children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(`elif ${props.cond}`)}\n {props.children}\n </Fragment>\n );\n}\n\n/** `{% else %}` — a sibling inside the same `<If>` (or `<Each>`) body (§2.5/2.7). */\nexport function Else(props: { children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(\"else\")}\n {props.children}\n </Fragment>\n );\n}\n\n/**\n * `{% for AS in OF %} … {% endfor %}` (§2.7). When `index` is supplied, the body\n * is prefixed with `{% set <index> = loop.index0 %}` so authors get a named\n * 0-based index.\n *\n * TODO(phase11): stock Jinja has no per-name index binding in the `for` header —\n * the built-in `loop.index`/`loop.index0` are always available. We model the\n * optional `index` prop as a `{% set %}` of `loop.index0` at body top, which is\n * the closest portable equivalent.\n */\nexport function Each(props: {\n of: string;\n as: string;\n index?: string;\n children?: ReactNode;\n}): ReactNode {\n return (\n <Fragment>\n {statement(`for ${props.as} in ${props.of}`)}\n {props.index ? statement(`set ${props.index} = loop.index0`) : null}\n {props.children}\n {statement(\"endfor\")}\n </Fragment>\n );\n}\n\n/** `{% switch ON %} … {% endswitch %}` (§2.6). Children are `<Case>` / `<Default>`. */\nexport function Switch(props: { on: string; children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(`switch ${props.on}`)}\n {props.children}\n {statement(\"endswitch\")}\n </Fragment>\n );\n}\n\n/** `{% case V1, V2, … %}` — comma means membership; first match wins (§2.6). */\nexport function Case(props: { value: string; children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(`case ${props.value}`)}\n {props.children}\n </Fragment>\n );\n}\n\n/** `{% default %}` — must be the last child of `<Switch>` (§2.6). */\nexport function Default(props: { children?: ReactNode }): ReactNode {\n return (\n <Fragment>\n {statement(\"default\")}\n {props.children}\n </Fragment>\n );\n}\n\n/** Build the `include` statement, appending `with { … }` context when given. */\nfunction includeStatement(src: string, withCtx?: string): string {\n return withCtx ? `include ${src} with ${withCtx}` : `include ${src}`;\n}\n\n/**\n * `{% include SRC %}` / `{% include SRC with CTX %}` (§2.8). `src` is an\n * expression string (usually a quoted partial name, e.g. `\"remittance\"`).\n */\nexport function Include(props: { src: string; with?: string }): ReactNode {\n return <Fragment>{statement(includeStatement(props.src, props.with))}</Fragment>;\n}\n\n/** `{{ EXPR }}` interpolation (§2.4). The expression is resolved in Rust at render. */\nexport function Expr(props: { value: string }): ReactNode {\n return <Fragment>{sentinel(`{{ ${props.value} }}`)}</Fragment>;\n}\n","// Raw passthrough escape hatch.\n//\n// React's JSX intrinsics impose their own attribute model: `class`/`colspan` warn\n// (they want `className`/`colSpan`, though they still render), and `style` MUST be\n// an object — a `style=\"color:#111\"` *string* is a hard error. turbo-pdf templates,\n// by contrast, are plain HTML where `class`, `style=\"…\"`, and `t:style` are ordinary\n// string attributes (spec §8.4). `<Raw html=\"…\" />` lets an author drop a literal\n// markup fragment that bypasses React's attribute model entirely: the string is\n// emitted verbatim (un-escaped) via the same sentinel channel the control-flow\n// components use, so whatever you write is exactly what lands in the template.\n//\n// The author owns well-formedness here (just like hand-authored HTML); the markup is\n// re-parsed by html5ever in the core.\n\nimport { createElement, Fragment, type ReactElement } from \"react\";\nimport { sentinel } from \"./sentinel.js\";\n\n/** Emit `props.html` verbatim into the template (no HTML-escaping, no React model). */\nexport function Raw(props: { html: string }): ReactElement {\n return createElement(Fragment, null, sentinel(props.html));\n}\n","// Paged-media components. These map to the `t:` directive elements that must\n// survive into the parsed DOM as typed layout nodes (§3). The element names match\n// `turbo-html2pdf-core`'s authoritative `t_kind()` table exactly (src/markers.rs).\n//\n// We build these with `createElement(string, …)` rather than JSX, because a JSX\n// tag like `<t:running-header>` parses as the member expression `t.running` — the\n// `t:` namespace prefix is only valid as a *string* tag name. React DOM renders an\n// arbitrary string tag verbatim, and `renderToStaticMarkup` HTML-escapes the\n// attribute values and text children exactly as a hand-written template would, so\n// the `t:` output is byte-identical to hand-authored markup.\n\nimport { createElement, type ReactElement, type ReactNode } from \"react\";\n\n/** Drop `undefined`-valued attributes so they don't render as `attr=\"undefined\"`. */\nfunction defined(attrs: Record<string, string | undefined>): Record<string, string> {\n const out: Record<string, string> = {};\n for (const [key, value] of Object.entries(attrs)) {\n if (value !== undefined) {\n out[key] = value;\n }\n }\n return out;\n}\n\n/** Create a `t:`-prefixed directive element with the given attrs and children. */\nfunction directive(\n name: string,\n attrs: Record<string, string | undefined>,\n children?: ReactNode,\n): ReactElement {\n return createElement(`t:${name}`, defined(attrs), children);\n}\n\n/** `<t:running-header>` — attaches header content to every page's top band (§3.0). */\nexport function RunningHeader(props: { extent?: string; children?: ReactNode }): ReactElement {\n return directive(\"running-header\", { extent: props.extent }, props.children);\n}\n\n/** `<t:running-footer>` — attaches footer content to every page's bottom band (§3.0). */\nexport function RunningFooter(props: { extent?: string; children?: ReactNode }): ReactElement {\n return directive(\"running-footer\", { extent: props.extent }, props.children);\n}\n\n/** `<t:page-master>` — named geometry + region bundle (§3.1). */\nexport function PageMaster(props: {\n name: string;\n size?: string;\n orientation?: string;\n margin?: string;\n children?: ReactNode;\n}): ReactElement {\n return directive(\n \"page-master\",\n {\n name: props.name,\n size: props.size,\n orientation: props.orientation,\n margin: props.margin,\n },\n props.children,\n );\n}\n\n/** `<t:region slot extent>` — a margin-box region inside a master (§3.1). */\nexport function Region(props: {\n slot: string;\n extent?: string;\n children?: ReactNode;\n}): ReactElement {\n return directive(\"region\", { slot: props.slot, extent: props.extent }, props.children);\n}\n\n/** `<t:variant kind>` — first/left/right/blank override inside a master (§3.2). */\nexport function Variant(props: { kind: string; children?: ReactNode }): ReactElement {\n return directive(\"variant\", { kind: props.kind }, props.children);\n}\n\n/** `<t:use-master name>` — switches the active master from flow position (§3.4). */\nexport function UseMaster(props: { name: string }): ReactElement {\n return directive(\"use-master\", { name: props.name });\n}\n\n/** `<t:footnote>` — inline footnote reference + body (§3.6). */\nexport function Footnote(props: {\n mark?: string;\n reset?: string;\n children?: ReactNode;\n}): ReactElement {\n return directive(\n \"footnote\",\n { mark: props.mark, \"t:footnote-reset\": props.reset },\n props.children,\n );\n}\n\n/** `<t:footnote-separator>` — the rule between body and footnote area (§3.6). */\nexport function FootnoteSeparator(props: { children?: ReactNode }): ReactElement {\n return directive(\"footnote-separator\", {}, props.children);\n}\n\n/** `<t:counter name action step start>` — a general named counter (§3.8). */\nexport function Counter(props: {\n name: string;\n action?: string;\n step?: string;\n start?: string;\n}): ReactElement {\n return directive(\"counter\", {\n name: props.name,\n action: props.action,\n step: props.step,\n start: props.start,\n });\n}\n\n/** `<t:leader>` — dot-fill between two inline boxes, for TOCs/footers (§3.10). */\nexport function Leader(props: { children?: ReactNode }): ReactElement {\n return directive(\"leader\", {}, props.children);\n}\n\n/** `<t:anchor id>` — a cross-reference target (§3.9, feature-gated in core). */\nexport function Anchor(props: { id: string }): ReactElement {\n return directive(\"anchor\", { id: props.id });\n}\n\n/** `<t:endnote>` — collects to a `<t:endnotes/>` sink (§3.7, feature-gated). */\nexport function Endnote(props: { children?: ReactNode }): ReactElement {\n return directive(\"endnote\", {}, props.children);\n}\n\n/** `<t:endnotes/>` — the endnote sink (§3.7, feature-gated). */\nexport function Endnotes(): ReactElement {\n return directive(\"endnotes\", {});\n}\n\n/**\n * Named running element (§3.5). There is **no** `t:running` element in the core's\n * authoritative `t_kind()` table — running content is marked with the\n * `t:running=\"name\"` *attribute* on a normal element (`<h1 t:running=\"section\">`).\n * So `<Running name=\"section\">` renders that attribute on a host element (default\n * `<span>`, override via `as`), optionally with `t:running-policy`.\n *\n * TODO(phase11): the handoff sketched `<Running>` -> `<t:running>`, but markers.rs\n * has no such directive; spec §3.5 defines it as an attribute, which is what we emit.\n */\nexport function Running(props: {\n name: string;\n as?: string;\n policy?: string;\n children?: ReactNode;\n}): ReactElement {\n return createElement(\n props.as ?? \"span\",\n defined({ \"t:running\": props.name, \"t:running-policy\": props.policy }),\n props.children,\n );\n}\n\n/** `<t:page/>` — current 1-based page number convenience element (§3.3). */\nexport function Page(): ReactElement {\n return directive(\"page\", {});\n}\n\n/** `<t:pages/>` — total page count convenience element (§3.3). */\nexport function Pages(): ReactElement {\n return directive(\"pages\", {});\n}\n"],"mappings":";AAMA,SAAS,4BAA4B;;;ACarC,IAAM,OAAO;AACb,IAAM,QAAQ;AAGd,SAAS,YAAY,MAAsB;AACzC,QAAM,QAAQ,IAAI,YAAY,EAAE,OAAO,IAAI;AAC3C,MAAI,SAAS;AACb,aAAW,QAAQ,OAAO;AACxB,cAAU,OAAO,aAAa,IAAI;AAAA,EACpC;AACA,SAAO,KAAK,MAAM,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,EAAE;AAC/E;AAGA,SAAS,cAAc,SAAyB;AAC9C,QAAM,SAAS,QAAQ,QAAQ,MAAM,GAAG,EAAE,QAAQ,MAAM,GAAG;AAC3D,QAAM,SAAS,KAAK,MAAM;AAC1B,QAAM,QAAQ,IAAI,WAAW,OAAO,MAAM;AAC1C,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,UAAM,CAAC,IAAI,OAAO,WAAW,CAAC;AAAA,EAChC;AACA,SAAO,IAAI,YAAY,EAAE,OAAO,KAAK;AACvC;AAGO,SAAS,SAAS,SAAyB;AAChD,SAAO,GAAG,IAAI,GAAG,YAAY,OAAO,CAAC,GAAG,KAAK;AAC/C;AAGO,SAAS,gBAAgB,QAAwB;AACtD,QAAM,UAAU,IAAI,O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