@cosmicdrift/kumiko-headless 0.327.0 → 0.328.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 (109) hide show
  1. package/dist/apex/css.d.ts +3 -0
  2. package/{src/apex/css.ts → dist/apex/css.js} +11 -24
  3. package/dist/apex/index.d.ts +229 -0
  4. package/dist/apex/index.js +360 -0
  5. package/dist/apex/lightbox.d.ts +4 -0
  6. package/{src/apex/lightbox.ts → dist/apex/lightbox.js} +0 -4
  7. package/dist/contracts/asset.d.ts +15 -0
  8. package/dist/contracts/asset.js +17 -0
  9. package/dist/contracts/index.d.ts +3 -0
  10. package/dist/contracts/index.js +1 -0
  11. package/dist/contracts/locale.d.ts +7 -0
  12. package/dist/contracts/locale.js +11 -0
  13. package/dist/contracts/primitives.d.ts +93 -0
  14. package/dist/contracts/primitives.js +21 -0
  15. package/dist/dispatcher/index.d.ts +2 -0
  16. package/dist/dispatcher/index.js +1 -0
  17. package/dist/dispatcher/types.d.ts +86 -0
  18. package/dist/dispatcher/types.js +34 -0
  19. package/dist/form/form-controller.d.ts +2 -0
  20. package/dist/form/form-controller.js +404 -0
  21. package/dist/form/index.d.ts +3 -0
  22. package/dist/form/index.js +2 -0
  23. package/dist/form/types.d.ts +71 -0
  24. package/dist/form/types.js +1 -0
  25. package/dist/form/zod-bridge.d.ts +5 -0
  26. package/{src/form/zod-bridge.ts → dist/form/zod-bridge.js} +52 -58
  27. package/dist/format/escape.d.ts +5 -0
  28. package/{src/format/escape.ts → dist/format/escape.js} +43 -47
  29. package/dist/format/html-template.d.ts +9 -0
  30. package/dist/format/html-template.js +39 -0
  31. package/dist/format/index.d.ts +10 -0
  32. package/dist/format/index.js +192 -0
  33. package/dist/format/money.d.ts +1 -0
  34. package/{src/format/money.ts → dist/format/money.js} +6 -5
  35. package/dist/index.d.ts +14 -0
  36. package/dist/index.js +9 -0
  37. package/dist/locale-routing/index.d.ts +39 -0
  38. package/dist/locale-routing/index.js +143 -0
  39. package/dist/nav/index.d.ts +2 -0
  40. package/dist/nav/index.js +1 -0
  41. package/dist/nav/resolve.d.ts +2 -0
  42. package/dist/nav/resolve.js +58 -0
  43. package/dist/nav/types.d.ts +26 -0
  44. package/dist/nav/types.js +1 -0
  45. package/dist/store/create-store.d.ts +2 -0
  46. package/{src/store/create-store.ts → dist/store/create-store.js} +21 -23
  47. package/dist/store/equality.d.ts +1 -0
  48. package/{src/store/equality.ts → dist/store/equality.js} +19 -17
  49. package/dist/store/index.d.ts +3 -0
  50. package/dist/store/index.js +2 -0
  51. package/dist/store/types.d.ts +7 -0
  52. package/dist/store/types.js +10 -0
  53. package/dist/view-model/edit.d.ts +10 -0
  54. package/dist/view-model/edit.js +392 -0
  55. package/dist/view-model/embedded-list.d.ts +27 -0
  56. package/dist/view-model/embedded-list.js +63 -0
  57. package/dist/view-model/index.d.ts +7 -0
  58. package/dist/view-model/index.js +3 -0
  59. package/dist/view-model/list.d.ts +16 -0
  60. package/dist/view-model/list.js +201 -0
  61. package/dist/view-model/types.d.ts +300 -0
  62. package/dist/view-model/types.js +1 -0
  63. package/package.json +31 -12
  64. package/src/changes.json +7 -0
  65. package/src/apex/__tests__/lightbox.test.ts +0 -20
  66. package/src/apex/__tests__/page-head.test.ts +0 -63
  67. package/src/apex/__tests__/render.test.ts +0 -401
  68. package/src/apex/index.ts +0 -667
  69. package/src/contracts/__tests__/contracts.test.ts +0 -123
  70. package/src/contracts/__tests__/field-issue-compat.test.ts +0 -19
  71. package/src/contracts/asset.ts +0 -48
  72. package/src/contracts/index.ts +0 -23
  73. package/src/contracts/locale.ts +0 -33
  74. package/src/contracts/primitives.ts +0 -158
  75. package/src/dispatcher/__tests__/contract.test.ts +0 -163
  76. package/src/dispatcher/index.ts +0 -16
  77. package/src/dispatcher/types.ts +0 -217
  78. package/src/form/__tests__/conditional-fields.test.ts +0 -177
  79. package/src/form/__tests__/form-controller.test.ts +0 -231
  80. package/src/form/__tests__/submit.test.ts +0 -575
  81. package/src/form/__tests__/validation.test.ts +0 -274
  82. package/src/form/form-controller.ts +0 -458
  83. package/src/form/index.ts +0 -15
  84. package/src/form/types.ts +0 -297
  85. package/src/format/__tests__/escape.test.ts +0 -79
  86. package/src/format/__tests__/format.test.ts +0 -281
  87. package/src/format/__tests__/html-template.test.ts +0 -47
  88. package/src/format/html-template.ts +0 -49
  89. package/src/format/index.ts +0 -219
  90. package/src/index.ts +0 -118
  91. package/src/locale-routing/__tests__/locale-routing.test.ts +0 -276
  92. package/src/locale-routing/index.ts +0 -218
  93. package/src/nav/__tests__/resolve.test.ts +0 -279
  94. package/src/nav/index.ts +0 -8
  95. package/src/nav/resolve.ts +0 -60
  96. package/src/nav/types.ts +0 -70
  97. package/src/store/__tests__/create-store.test.ts +0 -139
  98. package/src/store/__tests__/equality.test.ts +0 -66
  99. package/src/store/index.ts +0 -3
  100. package/src/store/types.ts +0 -27
  101. package/src/view-model/__tests__/edit.test.ts +0 -1072
  102. package/src/view-model/__tests__/embedded-list.test.ts +0 -96
  103. package/src/view-model/__tests__/field-labels.test.ts +0 -62
  104. package/src/view-model/__tests__/list.test.ts +0 -428
  105. package/src/view-model/edit.ts +0 -641
  106. package/src/view-model/embedded-list.ts +0 -89
  107. package/src/view-model/index.ts +0 -43
  108. package/src/view-model/list.ts +0 -277
  109. package/src/view-model/types.ts +0 -392
@@ -0,0 +1,360 @@
1
+ // Apex marketing-surface renderer — turns a typed page description into a
2
+ // complete static HTML string. The shared structure (header/hero/feature-grid/
3
+ // pricing-grid/info-grid/final-cta/footer) lives here; apps pass only their data,
4
+ // brand tokens (brand.tokensCss) and content. Server-side, zero React, one
5
+ // cacheable HTTP response. See APEX_STRUCTURAL_CSS for the CSS contract.
6
+ import { escapeHtml } from "../format/index.js";
7
+ import { APEX_STRUCTURAL_CSS } from "./css.js";
8
+ import { APEX_LIGHTBOX_HTML, APEX_LIGHTBOX_SCRIPT } from "./lightbox.js";
9
+ export { APEX_NAV_MENU_CSS, APEX_NAV_TOGGLE_RESPONSIVE_CSS, APEX_STRUCTURAL_CSS } from "./css.js";
10
+ export { APEX_LIGHTBOX_HTML, APEX_LIGHTBOX_SCRIPT, APEX_LIGHTBOX_SCRIPT_CSP_HASH, } from "./lightbox.js";
11
+ // JSON in <script>-Kontext: `<` als < serialisieren, damit weder
12
+ // `</script>` noch `<!--` aus dem Block ausbrechen kann (JSON bleibt valide).
13
+ function scriptSafeJsonHtml(value) {
14
+ return JSON.stringify(value).replace(/</g, "\\u003c");
15
+ }
16
+ function dim(img) {
17
+ return `${img.width !== undefined ? ` width="${img.width}"` : ""}${img.height !== undefined ? ` height="${img.height}"` : ""}`;
18
+ }
19
+ function svgIcon(innerHtml) {
20
+ return `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${innerHtml}</svg>`;
21
+ }
22
+ function renderCta(cta) {
23
+ const variant = cta.variant ?? "primary";
24
+ const cls = variant === "link" ? "" : ` class="btn btn-${variant}"`;
25
+ return `<a${cls} href="${escapeHtml(cta.href)}">${escapeHtml(cta.label)}</a>`;
26
+ }
27
+ function renderSectionHead(s) {
28
+ if (s.eyebrow === undefined && s.heading === undefined && s.sub === undefined)
29
+ return "";
30
+ const eyebrow = s.eyebrow !== undefined ? `<span class="eyebrow">${escapeHtml(s.eyebrow)}</span>` : "";
31
+ const heading = s.heading !== undefined ? `<h2>${escapeHtml(s.heading)}</h2>` : "";
32
+ const sub = s.sub !== undefined ? `<p>${escapeHtml(s.sub)}</p>` : "";
33
+ return `<div class="section-head">${eyebrow}${heading}${sub}</div>`;
34
+ }
35
+ function bandAttrs(muted, id) {
36
+ const cls = muted === false ? "" : ` class="features"`;
37
+ const idAttr = id !== undefined ? ` id="${escapeHtml(id)}"` : "";
38
+ return cls + idAttr;
39
+ }
40
+ function renderHero(s) {
41
+ const logo = s.logo !== undefined
42
+ ? `<img class="hero-pony" src="${escapeHtml(s.logo.src)}" alt="${escapeHtml(s.logo.alt)}"${dim(s.logo)} />`
43
+ : "";
44
+ const ctasHtml = (s.ctas ?? []).map(renderCta).join("\n ");
45
+ const meta = s.metaHtml !== undefined ? `<p class="hero-meta">${s.metaHtml}</p>` : "";
46
+ const visual = s.screenshot !== undefined
47
+ ? `<div class="hero-visual"><div class="shot-frame"><div class="shot-bar"><span></span><span></span><span></span></div><img src="${escapeHtml(s.screenshot.src)}" alt="${escapeHtml(s.screenshot.alt)}"${dim(s.screenshot)} loading="eager" /></div></div>`
48
+ : "";
49
+ return `<section class="hero">
50
+ <div class="container hero-grid">
51
+ <div class="hero-copy">
52
+ ${logo}<h1>${escapeHtml(s.title)}</h1>
53
+ <p class="tagline">${escapeHtml(s.tagline)}</p>
54
+ ${ctasHtml !== "" ? `<div class="hero-cta">${ctasHtml}</div>` : ""}
55
+ ${meta}
56
+ </div>
57
+ ${visual}
58
+ </div>
59
+ </section>`;
60
+ }
61
+ function renderFeatureGrid(s) {
62
+ const cardsHtml = s.items
63
+ .map((f) => `<article class="feature">
64
+ ${f.icon !== undefined ? `<div class="feature-icon">${svgIcon(f.icon)}</div>` : ""}<h3>${escapeHtml(f.title)}</h3>
65
+ <p>${escapeHtml(f.desc)}</p>
66
+ </article>`)
67
+ .join("\n ");
68
+ return `<section${bandAttrs(s.muted, s.id)}>
69
+ <div class="container">
70
+ ${renderSectionHead(s)}
71
+ <div class="feature-grid">
72
+ ${cardsHtml}
73
+ </div>
74
+ </div>
75
+ </section>`;
76
+ }
77
+ function renderPricingCard(t) {
78
+ const featured = t.featured === true;
79
+ const badge = t.badge !== undefined ? `<span class="price-badge">${escapeHtml(t.badge)}</span>` : "";
80
+ const cap = t.capLine !== undefined ? [`<li class="price-cap">${escapeHtml(t.capLine)}</li>`] : [];
81
+ const benefits = t.benefits.map((b) => `<li>${escapeHtml(b)}</li>`);
82
+ const itemsHtml = [...cap, ...benefits].join("\n ");
83
+ const per = t.priceSuffix !== undefined ? `<span>${escapeHtml(t.priceSuffix)}</span>` : "";
84
+ const tagline = t.tagline !== undefined ? `<p class="price-tagline">${escapeHtml(t.tagline)}</p>` : "";
85
+ // Delegates to renderCta so a `variant: "link"` tier CTA gets the same
86
+ // class-free anchor as everywhere else instead of re-deriving the class
87
+ // string here (a prior inline duplicate had no "link" case, always
88
+ // emitting `.btn-link`, which the structural CSS never defines).
89
+ const cta = t.cta.variant === undefined
90
+ ? renderCta({ ...t.cta, variant: featured ? "primary" : "secondary" })
91
+ : renderCta(t.cta);
92
+ return `<article class="price-card${featured ? " price-card--featured" : ""}">
93
+ ${badge}<h3>${escapeHtml(t.name)}</h3>
94
+ ${tagline}<div class="price-amount">${escapeHtml(t.amount)}${per}</div>
95
+ <ul class="price-list">
96
+ ${itemsHtml}
97
+ </ul>
98
+ ${cta}
99
+ </article>`;
100
+ }
101
+ function renderPricingGrid(s) {
102
+ const cardsHtml = s.tiers.map(renderPricingCard).join("\n ");
103
+ const idAttr = s.id !== undefined ? ` id="${escapeHtml(s.id)}"` : "";
104
+ return `<section${idAttr}>
105
+ <div class="container">
106
+ ${renderSectionHead(s)}
107
+ <div class="price-grid">
108
+ ${cardsHtml}
109
+ </div>
110
+ </div>
111
+ </section>`;
112
+ }
113
+ function renderInfoGrid(s) {
114
+ const itemsHtml = s.items
115
+ .map((i) => `<div class="trust-item">
116
+ <h3>${escapeHtml(i.title)}</h3>
117
+ <p>${escapeHtml(i.desc)}</p>
118
+ </div>`)
119
+ .join("\n ");
120
+ return `<section${bandAttrs(s.muted, s.id)}>
121
+ <div class="container">
122
+ ${renderSectionHead(s)}
123
+ <div class="trust-grid">
124
+ ${itemsHtml}
125
+ </div>
126
+ </div>
127
+ </section>`;
128
+ }
129
+ function renderFinalCta(s) {
130
+ const img = s.image !== undefined
131
+ ? `<img class="final-cta-pony" src="${escapeHtml(s.image.src)}" alt="${escapeHtml(s.image.alt)}"${dim(s.image)} />`
132
+ : "";
133
+ const sub = s.sub !== undefined ? `<p>${escapeHtml(s.sub)}</p>` : "";
134
+ return `<section class="final-cta">
135
+ <div class="container">
136
+ ${img}<h2>${escapeHtml(s.heading)}</h2>
137
+ ${sub}${renderCta(s.cta)}
138
+ </div>
139
+ </section>`;
140
+ }
141
+ function renderSection(s) {
142
+ switch (s.kind) {
143
+ case "hero":
144
+ return renderHero(s);
145
+ case "feature-grid":
146
+ return renderFeatureGrid(s);
147
+ case "pricing-grid":
148
+ return renderPricingGrid(s);
149
+ case "info-grid":
150
+ return renderInfoGrid(s);
151
+ case "final-cta":
152
+ return renderFinalCta(s);
153
+ case "html":
154
+ return s.html;
155
+ }
156
+ }
157
+ function renderNavMenu(m) {
158
+ const itemsHtml = m.items
159
+ .map((it) => `<a class="nav-menu__item" href="${escapeHtml(it.href)}">${it.icon !== undefined ? `<span class="nav-menu__icon">${svgIcon(it.icon)}</span>` : ""}<span class="nav-menu__text"><span class="nav-menu__title">${escapeHtml(it.title)}</span>${it.desc !== undefined ? `<span class="nav-menu__desc">${escapeHtml(it.desc)}</span>` : ""}</span></a>`)
160
+ .join("");
161
+ const footer = m.footer !== undefined
162
+ ? `<div class="nav-menu__sep"></div><a class="nav-menu__more" href="${escapeHtml(m.footer.href)}">${escapeHtml(m.footer.label)}</a>`
163
+ : "";
164
+ return `<details class="nav-menu"><summary class="nav-menu__trigger">${escapeHtml(m.label)}<span class="nav-menu__chev">${svgIcon('<path d="m6 9 6 6 6-6"/>')}</span></summary><div class="nav-menu__panel">${itemsHtml}${footer}</div></details>`;
165
+ }
166
+ function renderNavEntry(entry) {
167
+ return entry.kind === "menu"
168
+ ? renderNavMenu(entry)
169
+ : `<a href="${escapeHtml(entry.href)}">${escapeHtml(entry.label)}</a>`;
170
+ }
171
+ /** Render just the apex header chrome (brand + nav + actions). Exported so a
172
+ * consumer that composes its own page shell (not a full apex page) can reuse
173
+ * the identical header — markup stays single-source. */
174
+ export function renderApexHeader(h) {
175
+ const logo = h.brand.logoSrc !== undefined ? `<img src="${escapeHtml(h.brand.logoSrc)}" alt="" /> ` : "";
176
+ const navLinksHtml = (h.navLinks ?? []).map(renderNavEntry).join("\n ");
177
+ const actionsHtml = (h.actions ?? []).map(renderCta).join("\n ");
178
+ return `<header>
179
+ <div class="container nav">
180
+ <div class="brand"><a href="${escapeHtml(h.brand.href)}">${logo}${escapeHtml(h.brand.label)}</a></div>
181
+ ${navLinksHtml !== "" ? `<nav class="nav-links">${navLinksHtml}</nav><details class="nav-toggle"><summary class="nav-toggle__trigger" aria-label="${escapeHtml(h.menuLabel ?? "Menu")}">${svgIcon('<path d="M4 6h16M4 12h16M4 18h16"/>')}</summary><nav class="nav-links">${navLinksHtml}</nav></details>` : ""}
182
+ ${actionsHtml !== "" ? `<div class="nav-actions">${actionsHtml}</div>` : ""}
183
+ </div>
184
+ </header>`;
185
+ }
186
+ function renderFooter(f) {
187
+ const cols = f.columns ?? [];
188
+ const logo = f.brand.logoSrc !== undefined ? `<img src="${escapeHtml(f.brand.logoSrc)}" alt="" /> ` : "";
189
+ const colHtml = cols
190
+ .map((c) => `<div class="footer-col">
191
+ <h4>${escapeHtml(c.heading)}</h4>
192
+ ${c.links.map((l) => `<a href="${escapeHtml(l.href)}">${escapeHtml(l.label)}</a>`).join("\n ")}
193
+ </div>`)
194
+ .join("\n ");
195
+ const bottom = f.bottomLeft !== undefined || f.bottomRight !== undefined
196
+ ? `<div class="footer-bottom">
197
+ ${f.bottomLeft !== undefined ? `<span>${escapeHtml(f.bottomLeft)}</span>` : ""}
198
+ ${f.bottomRight !== undefined ? `<span>${escapeHtml(f.bottomRight)}</span>` : ""}
199
+ </div>`
200
+ : "";
201
+ return `<footer>
202
+ <div class="container">
203
+ <div class="footer-grid" style="--footer-cols:${Math.max(1, cols.length)}">
204
+ <div>
205
+ <div class="footer-brand">${logo}${escapeHtml(f.brand.label)}</div>
206
+ ${f.tagline !== undefined ? `<p class="footer-tagline">${escapeHtml(f.tagline)}</p>` : ""}
207
+ </div>
208
+ ${colHtml}
209
+ </div>
210
+ ${bottom}
211
+ </div>
212
+ </footer>`;
213
+ }
214
+ // All <title>/meta/link/script tags for an ApexHead — the single source both
215
+ // renderApexPage and any other head (e.g. page-render's wrapInLayout) splice
216
+ // into their own <head>. Extracted verbatim from renderApexPage so existing
217
+ // output stays byte-identical (see render.test.ts regression coverage).
218
+ export function renderApexHeadTags(head) {
219
+ const ogUrl = head.canonicalUrl !== undefined
220
+ ? `\n <meta property="og:url" content="${escapeHtml(head.canonicalUrl)}" />`
221
+ : "";
222
+ const ogImage = head.ogImage !== undefined
223
+ ? `\n <meta property="og:image" content="${escapeHtml(head.ogImage)}" />`
224
+ : "";
225
+ const favicon = head.faviconHref !== undefined
226
+ ? `\n <link rel="icon" href="${escapeHtml(head.faviconHref)}" />`
227
+ : "";
228
+ const canonical = head.canonicalUrl !== undefined
229
+ ? `\n <link rel="canonical" href="${escapeHtml(head.canonicalUrl)}" />`
230
+ : "";
231
+ const alternates = (head.alternates ?? [])
232
+ .map((a) => `\n <link rel="alternate" hreflang="${escapeHtml(a.hreflang)}" href="${escapeHtml(a.href)}" />`)
233
+ .join("");
234
+ const robots = head.robots !== undefined
235
+ ? `\n <meta name="robots" content="${escapeHtml(head.robots)}" />`
236
+ : "";
237
+ const siteName = head.siteName !== undefined
238
+ ? `\n <meta property="og:site_name" content="${escapeHtml(head.siteName)}" />`
239
+ : "";
240
+ const locale = head.locale !== undefined
241
+ ? `\n <meta property="og:locale" content="${escapeHtml(head.locale)}" />`
242
+ : "";
243
+ const twitterCard = head.ogImage !== undefined
244
+ ? `\n <meta name="twitter:card" content="summary_large_image" />`
245
+ : "";
246
+ const twitterSite = head.twitterSite !== undefined
247
+ ? `\n <meta name="twitter:site" content="${escapeHtml(head.twitterSite)}" />`
248
+ : "";
249
+ const preconnects = (head.preconnects ?? [])
250
+ .map((url) => `\n <link rel="preconnect" href="${escapeHtml(url)}" />`)
251
+ .join("");
252
+ const schema = head.schemaJson !== undefined
253
+ ? `\n <script type="application/ld+json">${scriptSafeJsonHtml(head.schemaJson)}</script>`
254
+ : "";
255
+ const metaDescription = head.description
256
+ ? `\n <meta name="description" content="${escapeHtml(head.description)}" />`
257
+ : "";
258
+ const ogDescription = head.description
259
+ ? `\n <meta property="og:description" content="${escapeHtml(head.description)}" />`
260
+ : "";
261
+ return `<title>${escapeHtml(head.title)}</title>${metaDescription}
262
+ <meta property="og:title" content="${escapeHtml(head.title)}" />${ogDescription}
263
+ <meta property="og:type" content="website" />${ogUrl}${ogImage}${siteName}${locale}${twitterCard}${twitterSite}${favicon}${canonical}${alternates}${robots}${preconnects}${schema}`;
264
+ }
265
+ export function renderApexPage(page) {
266
+ const { head, brand } = page;
267
+ const theme = page.theme ?? "light";
268
+ // Brand-CSS ist app-authored (Trust-Boundary siehe Datei-Header), kein Tenant-Input.
269
+ const cssHtml = (brand.fontFaceCss ?? "") + brand.tokensCss + APEX_STRUCTURAL_CSS;
270
+ const sectionsHtml = page.sections.map(renderSection).join("\n\n ");
271
+ return `<!doctype html>
272
+ <html lang="${escapeHtml(head.lang)}">
273
+ <head>
274
+ <meta charset="utf-8" />
275
+ <meta name="viewport" content="width=device-width,initial-scale=1,interactive-widget=resizes-content" />
276
+ ${renderApexHeadTags(head)}
277
+ <style>${cssHtml}</style>
278
+ </head>
279
+ <body${theme === "dark" ? ` class="apex-dark"` : ""}>
280
+ ${renderApexHeader(page.header)}
281
+
282
+ ${sectionsHtml}
283
+
284
+ ${renderFooter(page.footer)}
285
+
286
+ ${APEX_LIGHTBOX_HTML}
287
+ ${APEX_LIGHTBOX_SCRIPT}
288
+ </body>
289
+ </html>`;
290
+ }
291
+ const HEAD_TAGS_MARKER = "<!-- kumiko-page-head -->";
292
+ const TITLE_TAG_RE = /<title\b[^>]*>[\s\S]*?<\/title>/i;
293
+ // Idempotent by marker (repeated calls, e.g. hostDispatch + default path
294
+ // both hitting the same request, never double-inject) and safe on a
295
+ // head-less document (nothing to splice into). `tagsHtml` is pre-rendered
296
+ // HTML from a caller (renderApexHeadTags) — this function only owns
297
+ // placement + the original <title> removal, not escaping.
298
+ export function injectPageHead(html, tagsHtml) {
299
+ if (html.includes(HEAD_TAGS_MARKER))
300
+ return html;
301
+ if (!html.includes("</head>"))
302
+ return html;
303
+ const withoutTitle = html.replace(TITLE_TAG_RE, "");
304
+ return withoutTitle.replace("</head>", () => `${HEAD_TAGS_MARKER}\n${tagsHtml}\n</head>`);
305
+ }
306
+ // Resolver runs alongside the request, never gates it: a slow, throwing, or
307
+ // null-returning resolver must never turn a 200 shell into a 500 or a
308
+ // stall. One constant shared by runProdApp and runDevApp so both time out
309
+ // on the same value (kumiko-framework#3026).
310
+ const PAGE_HEAD_TIMEOUT_MS = 300;
311
+ async function resolvePageHeadWithTimeout(resolvePageHead, input) {
312
+ let timer;
313
+ try {
314
+ const timedOut = new Promise((resolve) => {
315
+ timer = setTimeout(() => resolve(null), PAGE_HEAD_TIMEOUT_MS);
316
+ });
317
+ // .catch on the resolver's own promise (not just the outer try/catch)
318
+ // so a rejection arriving AFTER the timeout already won the race
319
+ // doesn't surface as an unhandled rejection.
320
+ const resolved = resolvePageHead(input).catch(() => null);
321
+ return await Promise.race([resolved, timedOut]);
322
+ }
323
+ catch {
324
+ return null;
325
+ }
326
+ finally {
327
+ if (timer !== undefined)
328
+ clearTimeout(timer);
329
+ }
330
+ }
331
+ // ApexHead.lang is required (html lang="..."); PageHeadMeta only carries
332
+ // og:locale-shaped strings ("de_DE", "en-US") since that's all og:locale
333
+ // needs. Take the language subtag before the region separator; default to
334
+ // "en" when there's no locale to derive one from.
335
+ function apexLangFromLocale(locale) {
336
+ return locale?.split(/[_-]/)[0]?.toLowerCase() || "en";
337
+ }
338
+ function toApexHead(meta) {
339
+ return {
340
+ lang: apexLangFromLocale(meta.locale),
341
+ title: meta.title,
342
+ description: meta.description ?? "",
343
+ ...(meta.canonicalUrl !== undefined ? { canonicalUrl: meta.canonicalUrl } : {}),
344
+ ...(meta.ogImage !== undefined ? { ogImage: meta.ogImage } : {}),
345
+ ...(meta.siteName !== undefined ? { siteName: meta.siteName } : {}),
346
+ ...(meta.locale !== undefined ? { locale: meta.locale } : {}),
347
+ };
348
+ }
349
+ /** Resolves per-request head metadata and splices it into `html`, capped at
350
+ * the shared timeout. Never throws and never changes `html` on a resolver
351
+ * error, a `null` resolve, or a timeout — the caller's shell always ships
352
+ * unchanged. runProdApp and runDevApp both call this single function, so a
353
+ * future change to timeout or fallback semantics has one place to land
354
+ * (kumiko-framework#3026). */
355
+ export async function resolveAndInjectPageHead(html, resolvePageHead, input) {
356
+ const meta = await resolvePageHeadWithTimeout(resolvePageHead, input);
357
+ if (!meta)
358
+ return html;
359
+ return injectPageHead(html, renderApexHeadTags(toApexHead(meta)));
360
+ }
@@ -0,0 +1,4 @@
1
+ export declare const APEX_LIGHTBOX_HTML = "<dialog id=\"apex-lightbox\" class=\"apex-lightbox\" aria-label=\"Screenshot preview\">\n <button type=\"button\" class=\"apex-lightbox__close\" aria-label=\"Close\">&times;</button>\n <img class=\"apex-lightbox__img\" alt=\"\" />\n</dialog>";
2
+ /** ponytail: one delegated listener; no-op when no .shot-frame on the page. */
3
+ export declare const APEX_LIGHTBOX_SCRIPT = "<script>\n(function () {\n var dlg = document.getElementById(\"apex-lightbox\");\n if (!dlg) return;\n var img = dlg.querySelector(\".apex-lightbox__img\");\n var closeBtn = dlg.querySelector(\".apex-lightbox__close\");\n if (!img || !closeBtn) return;\n function open(src, alt) {\n img.src = src;\n img.alt = alt || \"\";\n if (typeof dlg.showModal === \"function\") dlg.showModal();\n }\n function close() {\n if (dlg.open) dlg.close();\n }\n document.addEventListener(\"click\", function (e) {\n var t = e.target;\n if (!(t instanceof HTMLImageElement)) return;\n if (!t.closest(\".shot-frame\")) return;\n e.preventDefault();\n open(t.currentSrc || t.src, t.alt);\n });\n closeBtn.addEventListener(\"click\", close);\n dlg.addEventListener(\"click\", function (e) {\n if (e.target === dlg) close();\n });\n dlg.addEventListener(\"cancel\", function (e) {\n e.preventDefault();\n close();\n });\n})();\n</script>";
4
+ export declare const APEX_LIGHTBOX_SCRIPT_CSP_HASH = "sha256-f+hHLpDuQsjmtFZCjdM13D9NaMTCyOKaawAhfLf/X9o=";
@@ -1,11 +1,9 @@
1
1
  // Vanilla lightbox for Apex marketing pages — click .shot-frame img to enlarge.
2
2
  // Injected by renderApexPage; no React, no per-app wiring.
3
-
4
3
  export const APEX_LIGHTBOX_HTML = `<dialog id="apex-lightbox" class="apex-lightbox" aria-label="Screenshot preview">
5
4
  <button type="button" class="apex-lightbox__close" aria-label="Close">&times;</button>
6
5
  <img class="apex-lightbox__img" alt="" />
7
6
  </dialog>`;
8
-
9
7
  // Split from APEX_LIGHTBOX_SCRIPT so APEX_LIGHTBOX_SCRIPT_CSP_HASH hashes
10
8
  // exactly the bytes the browser executes — CSP's script-src hash-source
11
9
  // covers the content between <script> and </script>, nothing more/less.
@@ -41,10 +39,8 @@ const APEX_LIGHTBOX_SCRIPT_BODY = `
41
39
  });
42
40
  })();
43
41
  `;
44
-
45
42
  /** ponytail: one delegated listener; no-op when no .shot-frame on the page. */
46
43
  export const APEX_LIGHTBOX_SCRIPT = `<script>${APEX_LIGHTBOX_SCRIPT_BODY}</script>`;
47
-
48
44
  // CSP hash-source for the inline script above; apex output is often
49
45
  // pre-rendered, so a per-request nonce can't work. Guarded by lightbox.test.ts.
50
46
  export const APEX_LIGHTBOX_SCRIPT_CSP_HASH = "sha256-f+hHLpDuQsjmtFZCjdM13D9NaMTCyOKaawAhfLf/X9o=";
@@ -0,0 +1,15 @@
1
+ export type AssetResolveContext = {
2
+ readonly tenantId?: string;
3
+ readonly theme?: "light" | "dark";
4
+ readonly platform?: "web" | "ios" | "android";
5
+ readonly locale?: string;
6
+ };
7
+ export type AssetResolution = {
8
+ readonly uri: string;
9
+ readonly width?: number;
10
+ readonly height?: number;
11
+ readonly alt?: string;
12
+ };
13
+ export type AssetResolver = {
14
+ resolve(qn: string, ctx?: AssetResolveContext): AssetResolution | null;
15
+ };
@@ -0,0 +1,17 @@
1
+ // Asset-Resolver — the layer between "qualified asset name" and "URL the
2
+ // renderer can point an <img>/<Image> at". An asset (logo, illustration,
3
+ // icon bundle) is declared by a feature with a qualified name
4
+ // ("admin:asset:hero-logo") and resolved at render-time against the
5
+ // current tenant / theme / platform.
6
+ //
7
+ // Why a resolver indirection:
8
+ // - Tenant-theming (different logo per tenant) without the feature
9
+ // knowing what tenant it's rendering for.
10
+ // - Dark-mode / light-mode variants picked up from the current theme
11
+ // context.
12
+ // - Web vs mobile different asset bundles (e.g. PNG vs SVG).
13
+ //
14
+ // The app registers a concrete resolver on startup and hands it to the
15
+ // renderer via context. Feature code calls `useAsset("admin:asset:logo")`
16
+ // (renderer-side hook) → internally `AssetResolver.resolve(qn)`.
17
+ export {};
@@ -0,0 +1,3 @@
1
+ export type { AssetResolution, AssetResolveContext, AssetResolver, } from "./asset.js";
2
+ export type { LocaleResolver } from "./locale.js";
3
+ export type { BadgeProps, ButtonProps, CardProps, DatePickerProps, IconProps, ModalProps, NumberInputProps, PrimitiveCommonProps, PrimitivesContract, SelectOption, SelectProps, TextInputProps, ToastIntent, ToastProps, ToggleProps, } from "./primitives.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ export type LocaleResolver = {
2
+ translate(key: string, params?: Readonly<Record<string, unknown>>): string;
3
+ locale(): string;
4
+ timeZone(): string;
5
+ subscribe(listener: () => void): () => void;
6
+ setLocale?(locale: string): void;
7
+ };
@@ -0,0 +1,11 @@
1
+ // Locale-Resolver — translation lookup + language/region info the
2
+ // renderer needs. Sits in front of i18next (or whatever i18n library
3
+ // the app wires up). ui-core calls it generically so form-controller,
4
+ // view-model, and nav-resolver all produce already-translated strings
5
+ // to hand to the renderer.
6
+ //
7
+ // The framework already has an i18n layer (@cosmicdrift/kumiko-framework/i18n) that
8
+ // features register translations against. This contract is what ui-core
9
+ // consumes — the app's entrypoint instantiates the resolver from a
10
+ // framework i18next instance and passes it to the renderer via context.
11
+ export {};
@@ -0,0 +1,93 @@
1
+ export type PrimitiveCommonProps = {
2
+ readonly id?: string;
3
+ readonly name?: string;
4
+ readonly disabled?: boolean;
5
+ readonly readOnly?: boolean;
6
+ readonly required?: boolean;
7
+ readonly label?: string;
8
+ readonly placeholder?: string;
9
+ readonly helperText?: string;
10
+ readonly errors?: readonly string[];
11
+ };
12
+ export type TextInputProps = PrimitiveCommonProps & {
13
+ readonly value: string;
14
+ readonly onChange: (next: string) => void;
15
+ readonly onBlur?: () => void;
16
+ readonly type?: "text" | "email" | "url" | "tel" | "password";
17
+ readonly maxLength?: number;
18
+ readonly autoComplete?: string;
19
+ };
20
+ export type NumberInputProps = PrimitiveCommonProps & {
21
+ readonly value: number | null;
22
+ readonly onChange: (next: number | null) => void;
23
+ readonly onBlur?: () => void;
24
+ readonly min?: number;
25
+ readonly max?: number;
26
+ readonly step?: number;
27
+ };
28
+ export type SelectOption<TValue extends string = string> = {
29
+ readonly value: TValue;
30
+ readonly label: string;
31
+ };
32
+ export type SelectProps<TValue extends string = string> = PrimitiveCommonProps & {
33
+ readonly value: TValue | null;
34
+ readonly onChange: (next: TValue | null) => void;
35
+ readonly options: readonly SelectOption<TValue>[];
36
+ };
37
+ export type ToggleProps = PrimitiveCommonProps & {
38
+ readonly value: boolean;
39
+ readonly onChange: (next: boolean) => void;
40
+ };
41
+ export type DatePickerProps = PrimitiveCommonProps & {
42
+ readonly value: string | null;
43
+ readonly onChange: (next: string | null) => void;
44
+ readonly minDate?: string;
45
+ readonly maxDate?: string;
46
+ };
47
+ export type ButtonProps = {
48
+ readonly onPress: () => void;
49
+ readonly label: string;
50
+ readonly variant?: "primary" | "secondary" | "destructive" | "ghost";
51
+ readonly disabled?: boolean;
52
+ readonly loading?: boolean;
53
+ readonly leftIcon?: string;
54
+ readonly rightIcon?: string;
55
+ };
56
+ export type ModalProps = {
57
+ readonly open: boolean;
58
+ readonly onClose: () => void;
59
+ readonly title?: string;
60
+ readonly description?: string;
61
+ };
62
+ export type ToastIntent = "info" | "success" | "warning" | "error";
63
+ export type ToastProps = {
64
+ readonly intent: ToastIntent;
65
+ readonly title: string;
66
+ readonly description?: string;
67
+ readonly onDismiss?: () => void;
68
+ };
69
+ export type BadgeProps = {
70
+ readonly label: string;
71
+ readonly intent?: ToastIntent;
72
+ };
73
+ export type CardProps = {
74
+ readonly title?: string;
75
+ readonly description?: string;
76
+ };
77
+ export type IconProps = {
78
+ readonly name: string;
79
+ readonly size?: number;
80
+ };
81
+ export type PrimitivesContract<TPrimitive = unknown> = {
82
+ readonly TextInput: TPrimitive;
83
+ readonly NumberInput: TPrimitive;
84
+ readonly Select: TPrimitive;
85
+ readonly Toggle: TPrimitive;
86
+ readonly DatePicker: TPrimitive;
87
+ readonly Button: TPrimitive;
88
+ readonly Modal: TPrimitive;
89
+ readonly Toast: TPrimitive;
90
+ readonly Badge: TPrimitive;
91
+ readonly Card: TPrimitive;
92
+ readonly Icon: TPrimitive;
93
+ };
@@ -0,0 +1,21 @@
1
+ // Primitives-Contract — the minimal set of UI building blocks every
2
+ // renderer must provide. A "primitive" is a unit the standard-renderers
3
+ // (entityList, entityEdit, etc.) call into without knowing which library
4
+ // implements it. On web that's shadcn; on mobile it's react-native-paper;
5
+ // both packages (primitives-shadcn, primitives-paper) implement this
6
+ // contract and the app wires one of them into the renderer via context.
7
+ //
8
+ // Why a contract here (in ui-core) instead of in each renderer:
9
+ // ui-core's view-model builder and form-controller produce metadata
10
+ // (field-type, validation-state, label, placeholder) that the renderer
11
+ // translates into primitive invocations. Having the contract shape in
12
+ // ui-core means the metadata can carry references to primitives by name
13
+ // ("text-input", "select") and the translation is a pure map-lookup on
14
+ // the renderer side, not a switch statement that re-derives UI intent
15
+ // from entity-schema.
16
+ //
17
+ // Runtime-free: every primitive is expressed as its input contract only
18
+ // (what props it takes). Concrete components live in each primitives-*
19
+ // package and depend on React / React Native / etc.; ui-core never
20
+ // imports them.
21
+ export {};
@@ -0,0 +1,2 @@
1
+ export type { BatchResult, Command, Dispatcher, DispatcherError, DispatcherStatus, FieldIssue, PendingFile, PendingWrite, QueryOpts, QueryResult, StreamOpts, WriteOpts, WriteResult, } from "./types.js";
2
+ export { StreamFrame, type StreamFrameEvent } from "./types.js";
@@ -0,0 +1 @@
1
+ export { StreamFrame } from "./types.js";
@@ -0,0 +1,86 @@
1
+ import type { FieldIssue } from "@cosmicdrift/kumiko-framework/errors";
2
+ import type { Store } from "../store/index.js";
3
+ export type { FieldIssue };
4
+ export type DispatcherError = {
5
+ readonly code: string;
6
+ readonly httpStatus: number;
7
+ readonly i18nKey: string;
8
+ readonly i18nParams?: Readonly<Record<string, unknown>>;
9
+ readonly message: string;
10
+ readonly details?: {
11
+ readonly fields?: readonly FieldIssue[];
12
+ } & Record<string, unknown>;
13
+ readonly docsUrl?: string;
14
+ readonly requestId?: string;
15
+ };
16
+ export type WriteResult<TData = unknown> = {
17
+ readonly isSuccess: true;
18
+ readonly data: TData;
19
+ } | {
20
+ readonly isSuccess: false;
21
+ readonly error: DispatcherError;
22
+ };
23
+ export type QueryResult<TData = unknown> = {
24
+ readonly isSuccess: true;
25
+ readonly data: TData;
26
+ } | {
27
+ readonly isSuccess: false;
28
+ readonly error: DispatcherError;
29
+ };
30
+ export type BatchResult = {
31
+ readonly isSuccess: true;
32
+ readonly results: readonly WriteResult[];
33
+ } | {
34
+ readonly isSuccess: false;
35
+ readonly error: DispatcherError;
36
+ readonly failedIndex: number;
37
+ readonly results: readonly WriteResult[];
38
+ };
39
+ export type Command = {
40
+ readonly type: string;
41
+ readonly payload: unknown;
42
+ };
43
+ export type DispatcherStatus = "online" | "offline" | "syncing";
44
+ export type PendingWrite = {
45
+ readonly id: string;
46
+ readonly type: string;
47
+ readonly payload: unknown;
48
+ readonly queuedAt: string;
49
+ readonly attempts: number;
50
+ readonly lastError?: DispatcherError;
51
+ };
52
+ export type PendingFile = {
53
+ readonly id: string;
54
+ readonly fileName: string;
55
+ readonly sizeBytes: number;
56
+ readonly queuedAt: string;
57
+ readonly attempts: number;
58
+ readonly progress?: number;
59
+ readonly lastError?: DispatcherError;
60
+ };
61
+ export type WriteOpts = {
62
+ readonly requestId?: string;
63
+ readonly signal?: AbortSignal;
64
+ };
65
+ export type QueryOpts = {
66
+ readonly signal?: AbortSignal;
67
+ };
68
+ export type StreamOpts = {
69
+ readonly signal?: AbortSignal;
70
+ };
71
+ export declare const StreamFrame: {
72
+ readonly chunk: "chunk";
73
+ readonly ping: "ping";
74
+ readonly done: "done";
75
+ readonly error: "error";
76
+ };
77
+ export type StreamFrameEvent = (typeof StreamFrame)[keyof typeof StreamFrame];
78
+ export type Dispatcher = {
79
+ write<TData = unknown>(type: string, payload: unknown, opts?: WriteOpts): Promise<WriteResult<TData>>;
80
+ query<TData = unknown>(type: string, payload: unknown, opts?: QueryOpts): Promise<QueryResult<TData>>;
81
+ batch(commands: readonly Command[], opts?: WriteOpts): Promise<BatchResult>;
82
+ stream<TChunk = unknown>(type: string, payload: unknown, opts?: StreamOpts): AsyncGenerator<TChunk, void, undefined>;
83
+ readonly statusStore: Store<DispatcherStatus>;
84
+ pendingWrites(): readonly PendingWrite[];
85
+ pendingFiles(): readonly PendingFile[];
86
+ };