1// GENERATED from dc-runtime/src/*.ts â do not edit. Rebuild with `cd dc-runtime && bun run build`. 2"use strict"; 3(() => { 4 var __defProp = Object.defineProperty; 5 var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; 6 var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); 7 8
8// src/react.ts 9 function getReact() { 10 const R = window.React; 11 if (!R) throw new Error("dc-runtime: window.React is not available yet"); 12 return R; 13 } 14 function getReactDOM() { 15 const RD = window.ReactDOM; 16 if (!RD) throw new Error("dc-runtime: window.ReactDOM is not available yet"); 17 return RD; 18 } 19 var h = ((...args) => getReact().createElement( 20 ...args 21 )); 22 23
23// src/parse.ts 24 function parseDcDocument(doc) { 25 const dc = doc.querySelector("x-dc"); 26 if (!dc) return null; 27 const scriptEl = doc.querySelector("script[data-dc-script]"); 28 const { props, preview } = parseDataProps( 29 scriptEl?.getAttribute("data-props") ?? null 30 ); 31 return { 32 template: dc.innerHTML, 33 js: scriptEl ? scriptEl.textContent || "" : "", 34 props, 35 preview 36 }; 37 } 38 function parseDcText(src) { 39 const openMatch = /<x-dc(?:\s[^>]*)?>/.exec(src); 40 if (!openMatch) return null; 41 const close = src.lastIndexOf("</x-dc>"); 42 if (close === -1 || close < openMatch.index) return null; 43 const template = src.slice(openMatch.index + openMatch[0].length, close); 44 const doc = new DOMParser().parseFromString(src, "text/html"); 45 const scriptEl = doc.querySelector("script[data-dc-script]"); 46 const { props, preview } = parseDataProps( 47 scriptEl?.getAttribute("data-props") ?? null 48 ); 49 return { 50 template, 51 js: scriptEl ? scriptEl.textContent || "" : "", 52 props, 53 preview 54 }; 55 } 56 function parseDataProps(raw) { 57 if (!raw) return { props: null, preview: null }; 58 let parsed; 59 try { 60 parsed = JSON.parse(raw); 61 } catch { 62 return { props: null, preview: null }; 63 } 64 if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) { 65 return { props: null, preview: null }; 66 } 67 const obj = parsed; 68 const preview = obj.$preview && typeof obj.$preview === "object" ? obj.$preview : null; 69 const rest = {}; 70 for (const k of Object.keys(obj)) { 71 if (k[0] !== "$") rest[k] = obj[k]; 72 } 73 return { props: Object.keys(rest).length ? rest : null, preview }; 74 } 75 function dcNameFromPath(pathname) { 76 let p = pathname || ""; 77 try { 78 p = decodeURIComponent(p); 79 } catch { 80 } 81 const base = p.split("/").pop() || "Root"; 82 return base.replace(/\.dc\.html$/, "").replace(/\.html?$/, "") || "Root"; 83 } 84 85
85// src/boot.ts 86 var BASE_CSS = ` 87 .sc-placeholder{background:color-mix(in srgb,currentColor 8%,transparent); 88 border:1px solid color-mix(in srgb,currentColor 50%,transparent); 89 border-radius:2px;box-sizing:border-box;overflow:hidden} 90 @keyframes sc-shine{0%{background-position:100% 50%}100%{background-position:0% 50%}} 91 html.sc-dc-streaming .sc-placeholder, 92 html.sc-dc-streaming .sc-interp.sc-missing{position:relative; 93 background:color-mix(in srgb,currentColor 5%,transparent); 94 border-color:transparent} 95 html.sc-dc-streaming .sc-placeholder::before, 96 html.sc-dc-streaming .sc-interp.sc-missing::before{content:''; 97 position:absolute;inset:0;pointer-events:none; 98 background:linear-gradient(90deg,rgba(217,119,87,0) 25%,rgba(247,225,211,.95) 37%,rgba(217,119,87,0) 63%); 99 background-size:400% 100%;animation:sc-shine 1.4s ease infinite} 100 html.sc-dc-streaming .sc-placeholder:nth-child(n+9 of .sc-placeholder)::before, 101 html.sc-dc-streaming .sc-interp.sc-missing:nth-child(n+9 of .sc-interp.sc-missing)::before{animation:none; 102 background:color-mix(in srgb,currentColor 8%,transparent)} 103 .sc-placeholder-error{padding:4px 8px;font:11px/1.4 ui-monospace,monospace; 104 color:color-mix(in srgb,currentColor 70%,transparent);word-break:break-word} 105 .sc-interp.sc-missing{display:inline-block;width:2em;height:1em;overflow:hidden; 106 vertical-align:text-bottom;background:rgba(255,255,255,.3);border:1px solid rgba(0,0,0,.5); 107 border-radius:2px;box-sizing:border-box;color:transparent; 108 user-select:none} 109 .sc-interp.sc-unresolved{font-family:ui-monospace,monospace;font-size:.85em; 110 color:color-mix(in srgb,currentColor 50%,transparent); 111 background:color-mix(in srgb,currentColor 10%,transparent);border-radius:3px; 112 padding:0 3px} 113 .sc-host.sc-has-error{position:relative} 114 .sc-logic-error{position:absolute;top:8px;left:8px;z-index:2147483647;max-width:60ch; 115 padding:6px 10px;background:#b00020;color:#fff;font:12px/1.4 ui-monospace,monospace; 116 border-radius:4px;white-space:pre-wrap;pointer-events:none} 117 /* Mirrors PRINT_BASELINE_CSS in apps/web deck-stage-export.ts \u2014 keep both 118 in sync until dc-runtime regains a build step. */ 119 @media print { 120 @page { margin: 0.5cm; } 121 figure, table { break-inside: avoid; } 122 #dc-root, #dc-root > .sc-host { height: auto; } 123 *, *::before, *::after { 124 print-color-adjust: exact; -webkit-print-color-adjust: exact; 125 backdrop-filter: none !important; -webkit-backdrop-filter: none !important; 126 animation-delay: -99s !important; animation-duration: .001s !important; 127 animation-iteration-count: 1 !important; animation-fill-mode: both !important; 128 animation-play-state: running !important; transition-duration: 0s !important; 129 } 130 } 131 `; 132 var FULL_PAGE_CSS = "html,body{height:100%;margin:0}#dc-root,#dc-root>.sc-host{height:100%}"; 133 function rootNameForDocument(doc, loc) { 134 let bootPath = loc.pathname || ""; 135 if (!/\.dc\.html?$/i.test(safeDecode(bootPath))) { 136 try { 137 bootPath = new URL(doc.baseURI || "/").pathname; 138 } catch { 139 } 140 } 141 return dcNameFromPath(bootPath); 142 } 143 function safeDecode(s) { 144 try { 145 return decodeURIComponent(s); 146 } catch { 147 return s; 148 } 149 } 150 function boot(runtime, doc = document) { 151 const parsed = parseDcDocument(doc); 152 if (!parsed) return null; 153 const React = getReact(); 154 const rootName = rootNameForDocument(doc, location); 155 runtime.markFetched(rootName); 156 runtime.setRootName(rootName); 157 runtime.adoptParsed(rootName, parsed); 158 fetch(location.href).then((res) => res.ok ? res.text() : "").then((t) => { 159 const raw = t ? parseDcText(t) : null; 160 if (raw?.template) runtime.updateHtml(rootName, raw.template); 161 }).catch(() => { 162 }); 163 const dc = doc.querySelector("x-dc"); 164 const hostEl = doc.createElement("div"); 165 hostEl.id = "dc-root"; 166 dc.replaceWith(hostEl); 167 if (!parsed.preview) { 168 const s = doc.createElement("style"); 169 s.textContent = FULL_PAGE_CSS; 170 doc.head.appendChild(s); 171 } 172 const Root = runtime.getDC(rootName); 173 const entry = runtime.registry.get(rootName); 174 function StandaloneRoot() { 175 const [, setTick] = React.useState(0); 176 React.useEffect(() => { 177 const sub = () => setTick((n) => n + 1); 178 entry.subs.add(sub); 179 return () => { 180 entry.subs.delete(sub); 181 }; 182 }, []); 183 const defaults = React.useMemo(() => { 184 const d = {}; 185 for (const k in entry.propsMeta || {}) { 186 const v = entry.propsMeta?.[k]?.default; 187 if (v !== void 0) d[k] = v; 188 } 189 return d; 190 }, [entry.propsMeta]); 191 return h(Root, { ...defaults, ...entry.propOverrides || {} }); 192 } 193 const ReactDOM = getReactDOM(); 194 if (ReactDOM.createRoot) 195 ReactDOM.createRoot(hostEl).render(h(StandaloneRoot)); 196 else ReactDOM.render(h(StandaloneRoot), hostEl); 197 return rootName; 198 } 199 200
200// src/expr.ts 201 var IDENT_RE = /^[A-Za-z_$][A-Za-z0-9_$]*/; 202 var NUMBER_RE = /^-?\d+(\.\d+)?$/; 203 function resolve(vals, src) { 204 const expr = String(src).trim(); 205 if (!expr) return void 0; 206 if (expr[0] === "(" && expr[expr.length - 1] === ")" && parensWrapWhole(expr)) { 207 return resolve(vals, expr.slice(1, -1)); 208 } 209 const eq = findTopLevelEquality(expr); 210 if (eq) { 211 const lv = resolve(vals, expr.slice(0, eq.index)); 212 const rv = resolve(vals, expr.slice(eq.index + eq.op.length)); 213 switch (eq.op) { 214 case "===": 215 return lv === rv; 216 case "!==": 217 return lv !== rv; 218 case "==": 219 return lv == rv; 220 default: 221 return lv != rv; 222 } 223 } 224 if (expr[0] === "!") return !resolve(vals, expr.slice(1)); 225 if (expr === "true") return true; 226 if (expr === "false") return false; 227 if (expr === "null") return null; 228 if (expr === "undefined") return void 0; 229 if (NUMBER_RE.test(expr)) return Number(expr); 230 if (expr.length >= 2 && (expr[0] === '"' || expr[0] === "'") && expr[expr.length - 1] === expr[0]) { 231 return expr.slice(1, -1); 232 } 233 return resolvePath(vals, expr); 234 } 235 function parensWrapWhole(expr) { 236 let depth = 0; 237 for (let i = 0; i < expr.length - 1; i++) { 238 if (expr[i] === "(") depth++; 239 else if (expr[i] === ")") { 240 depth--; 241 if (depth === 0) return false; 242 } 243 } 244 return true; 245 } 246 function findTopLevelEquality(expr) { 247 let depth = 0; 248 for (let i = 0; i < expr.length; i++) { 249 const c = expr[i]; 250 if (c === "[" || c === "(") depth++; 251 else if (c === "]" || c === ")") depth--; 252 else if (depth === 0 && (c === "=" || c === "!") && expr[i + 1] === "=") { 253 if (i > 0 && (expr[i - 1] === "=" || expr[i - 1] === "!")) continue; 254 if (!expr.slice(0, i).trim()) continue; 255 const op = expr[i + 2] === "=" ? c + "==" : c + "="; 256 return { index: i, op }; 257 } 258 } 259 return null; 260 } 261 function resolvePath(vals, expr) { 262 const head = expr.match(IDENT_RE); 263 if (!head) return void 0; 264 let cur = vals == null ? void 0 : vals[head[0]]; 265 let i = head[0].length; 266 while (i < expr.length) { 267 if (expr[i] === ".") { 268 const m = expr.slice(i + 1).match(IDENT_RE) || expr.slice(i + 1).match(/^\d+/); 269 if (!m) return void 0; 270 cur = cur == null ? void 0 : cur[m[0]]; 271 i += 1 + m[0].length; 272 } else if (expr[i] === "[") { 273 let depth = 1; 274 let j = i + 1; 275 while (j < expr.length && depth > 0) { 276 if (expr[j] === "[") depth++; 277 else if (expr[j] === "]") { 278 depth--; 279 if (depth === 0) break; 280 } 281 j++; 282 } 283 if (depth !== 0) return void 0; 284 const key = resolve(vals, expr.slice(i + 1, j)); 285 cur = cur == null ? void 0 : cur[key]; 286 i = j + 1; 287 } else { 288 return void 0; 289 } 290 } 291 return cur; 292 } 293 294
294// src/encode.ts 295 var CAMEL_ATTR = "sc-camel-"; 296 var INLINE_TEXT_TAGS = new Set( 297 "a abbr b bdi bdo br cite code del dfn em i ins kbd mark q s samp small span strike strong sub sup u var wbr".split( 298 " " 299 ) 300 ); 301 var RAW_WRAP = { 302 select: "sc-raw-select", 303 table: "sc-raw-table", 304 tbody: "sc-raw-tbody", 305 thead: "sc-raw-thead", 306 tfoot: "sc-raw-tfoot", 307 tr: "sc-raw-tr", 308 td: "sc-raw-td", 309 th: "sc-raw-th", 310 caption: "sc-raw-caption" 311 }; 312 var RAW_UNWRAP = Object.fromEntries( 313 Object.entries(RAW_WRAP).map(([k, v]) => [v, k]) 314 ); 315 var EVENT_MAP = { 316 onclick: "onClick", 317 onchange: "onChange", 318 oninput: "onInput", 319 onsubmit: "onSubmit", 320 onkeydown: "onKeyDown", 321 onkeyup: "onKeyUp", 322 onkeypress: "onKeyPress", 323 onmousedown: "onMouseDown", 324 onmouseup: "onMouseUp", 325 onmouseenter: "onMouseEnter", 326 onmouseleave: "onMouseLeave", 327 onfocus: "onFocus", 328 onblur: "onBlur", 329 ondoubleclick: "onDoubleClick", 330 oncontextmenu: "onContextMenu" 331 }; 332 var ATTRS = `(?:[^>"']|"[^"]*"|'[^']*')*`; 333 var IMPORT_SELF_CLOSE_RE = new RegExp( 334 "<(x-import|dc-import)(" + ATTRS + ")/>", 335 "gi" 336 ); 337 var CAMEL_ATTR_RE = /(\s)([a-z]+[A-Z][A-Za-z0-9]*)(\s*=)/g; 338 function encodeCase(html) { 339 html = html.replace( 340 IMPORT_SELF_CLOSE_RE, 341 (_, t, a) => "<" + t + a + "></" + t + ">" 342 ); 343 html = html.replace(/<helmet(\s|>)/gi, "<sc-helmet$1"); 344 html = html.replace(/<\/helmet\s*>/gi, "</sc-helmet>"); 345 html = html.replace( 346 CAMEL_ATTR_RE, 347 (_, sp, name, eq) => sp + CAMEL_ATTR + name.replace(/[A-Z]/g, (c) => "-" + c.toLowerCase()) + eq 348 ); 349 for (const [real, alias] of Object.entries(RAW_WRAP)) { 350 html = html.replace( 351 new RegExp("(</?)" + real + "(?=[\\s>])", "gi"), 352 "$1" + alias 353 ); 354 } 355 return html; 356 } 357 function kebabToCamel(s) { 358 return s.replace(/-([a-z])/g, (_, c) => c.toUpperCase()); 359 } 360 function cssToObj(css) { 361 const o = {}; 362 for (const decl of css.split(";")) { 363 const i = decl.indexOf(":"); 364 if (i < 0) continue; 365 const prop = decl.slice(0, i).trim(); 366 o[prop.startsWith("--") ? prop : kebabToCamel(prop)] = decl.slice(i + 1).trim(); 367 } 368 return o; 369 } 370 function compileAttr(raw) { 371 const whole = raw.match(/^\s*\{\{([\s\S]+?)\}\}\s*$/); 372 if (whole) { 373 const path = whole[1]; 374 return (vals) => resolve(vals, path); 375 } 376 if (raw.includes("{{")) { 377 const parts = raw.split(/\{\{([\s\S]+?)\}\}/g); 378 return (vals) => parts.map((s, i) => i & 1 ? resolve(vals, s) ?? "" : s).join(""); 379 } 380 return () => raw; 381 } 382 383
383// src/compile.ts 384 function collectProps(node, kind, host) { 385 const propGetters = []; 386 const pseudoClasses = []; 387 let hintSize = null; 388 for (const { name, value } of [...node.attributes]) { 389 if (name === "sc-name" || name === "data-dc-tpl") continue; 390 let key = name; 391 if (key.startsWith(CAMEL_ATTR)) 392 key = kebabToCamel(key.slice(CAMEL_ATTR.length)); 393 if (key === "hint-size") { 394 hintSize = value; 395 continue; 396 } 397 if (key.startsWith("style-")) { 398 pseudoClasses.push(host.pseudoClass(key.slice(6), value)); 399 continue; 400 } 401 if (kind !== "dom") { 402 if (key.includes("-") && !(kind === "x-import" && (key.startsWith("aria-") || key.startsWith("data-")))) 403 key = kebabToCamel(key); 404 } else { 405 if (key === "class") key = "className"; 406 else if (key === "for") key = "htmlFor"; 407 else if (key.startsWith("on")) 408 key = EVENT_MAP[key] || "on" + key[2].toUpperCase() + key.slice(3); 409 } 410 propGetters.push([key, compileAttr(value)]); 411 } 412 return { propGetters, pseudoClasses, hintSize }; 413 } 414 var HOST_STYLE_PROPS = /* @__PURE__ */ new Set([ 415 "position", 416 "left", 417 "right", 418 "top", 419 "bottom", 420 "inset", 421 "width", 422 "height", 423 "z-index", 424 "transform" 425 ]); 426 function hostPositionStyle(style) { 427 const all = typeof style === "string" ? cssToObj(style) : style != null && typeof style === "object" ? style : null; 428 if (!all) return void 0; 429 const out = {}; 430 for (const [k, v] of Object.entries(all)) { 431 const kebab = k.replace(/[A-Z]/g, (c) => "-" + c.toLowerCase()); 432 if (HOST_STYLE_PROPS.has(kebab)) out[k] = v; 433 } 434 return Object.keys(out).length ? out : void 0; 435 } 436 function compileTemplate(html, host) { 437 const tpl = document.createElement("template"); 438 //! nosemgrep: direct-inner-html-assignment 439 tpl.innerHTML = encodeCase(html); 440 let tplN = 0; 441 (function stamp(node) { 442 if (node.nodeType === Node.ELEMENT_NODE) { 443 node.setAttribute("data-dc-tpl", String(tplN++)); 444 } 445 for (const c of node.childNodes) stamp(c); 446 })(tpl.content); 447 const builders = walkChildren(tpl.content, host); 448 const render = ((vals, ctx) => builders.map((b, i) => b(vals || {}, ctx, i))); 449 render.__annotated = tpl.innerHTML; 450 return render; 451 } 452 function walkChildren(node, host) { 453 return [...node.childNodes].map((c) => walk(c, host)).filter((b) => b != null); 454 } 455 function walk(node, host) { 456 if (node.nodeType === Node.TEXT_NODE) return walkText(node); 457 if (node.nodeType !== Node.ELEMENT_NODE) return null; 458 const el = node; 459 const tag = el.tagName.toLowerCase(); 460 if (tag === "sc-for") return walkFor(el, host); 461 if (tag === "sc-if") return walkIf(el, host); 462 if (tag === "x-import") return walkXImport(el, host); 463 if (tag === "sc-helmet") return host.helmet(el); 464 if (tag === "dc-import") return walkComponent(el, host); 465 return walkElement(el, host); 466 } 467 var warnedHoles = /* @__PURE__ */ new Set(); 468 function warnUnresolved(ctx, what) { 469 const key = (ctx?.__name || "?") + "\0" + what; 470 if (warnedHoles.has(key)) return; 471 warnedHoles.add(key); 472 console.warn("[dc-runtime] " + (ctx?.__name || "template") + ": " + what); 473 } 474 function walkText(node) { 475 const txt = node.nodeValue ?? ""; 476 if (!txt.includes("{{")) { 477 if (!txt.trim() && !txt.includes(" ")) return null; 478 return () => txt; 479 } 480 const parts = txt.split(/\{\{([\s\S]+?)\}\}/g); 481 return (vals, ctx, key) => h( 482 getReact().Fragment, 483 { key }, 484 ...parts.map((p, i) => { 485 if (!(i & 1)) return p; 486 const v = resolve(vals, p); 487 if (v === void 0) { 488 if (!ctx?.__streamingNow) { 489 if (document.body?.hasAttribute("data-dc-editor-on")) { 490 return h( 491 "span", 492 { key: i, className: "sc-interp sc-unresolved" }, 493 "{{ " + p.trim() + " }}" 494 ); 495 } 496 warnUnresolved( 497 ctx, 498 "{{ " + p.trim() + " }} never resolved \u2014 rendered as empty"
499 ); 500 return null; 501 } 502 return h( 503 "span", 504 { key: i, className: "sc-interp sc-missing" }, 505 p.trim() 506 ); 507 } 508 if (getReact().isValidElement(v) || Array.isArray(v)) { 509 return h(getReact().Fragment, { key: i }, v); 510 } 511 if (v === null || typeof v === "boolean") return null; 512 return h("span", { key: i, className: "sc-interp" }, String(v)); 513 }) 514 ); 515 } 516 function walkFor(el, host) { 517 const listGet = compileAttr(el.getAttribute("list") || ""); 518 const asName = el.getAttribute("as") || "item"; 519 const hintN = parseInt(el.getAttribute("hint-placeholder-count") || "0", 10); 520 const kids = walkChildren(el, host); 521 const listSrc = el.getAttribute("list") || ""; 522 return (vals, ctx, key) => { 523 let list = listGet(vals); 524 if (!Array.isArray(list)) { 525 if (!ctx?.__streamingNow) { 526 if (list !== void 0 && list !== null) { 527 warnUnresolved( 528 ctx, 529 'sc-for list="' + listSrc + '" is not an array (' + typeof list + ")" 530 ); 531 } 532 list = []; 533 } else { 534 list = hintN > 0 ? Array(hintN).fill(void 0) : []; 535 } 536 } 537 return h( 538 getReact().Fragment, 539 { key }, 540 list.map((item, i) => { 541 const sub = { ...vals, [asName]: item, $index: i }; 542 return h( 543 getReact().Fragment, 544 { key: i }, 545 kids.map((b, j) => b(sub, ctx, j)) 546 ); 547 }) 548 ); 549 }; 550 } 551 function walkIf(el, host) { 552 const valGet = compileAttr(el.getAttribute("value") || ""); 553 const hintRaw = el.getAttribute("hint-placeholder-val"); 554 const hintGet = hintRaw != null ? compileAttr(hintRaw) : null; 555 const kids = walkChildren(el, host); 556 return (vals, ctx, key) => { 557 let v = valGet(vals); 558 if (v === void 0 && hintGet && ctx?.__streamingNow) v = hintGet(vals); 559 return v ? h( 560 getReact().Fragment, 561 { key }, 562 kids.map((b, j) => b(vals, ctx, j)) 563 ) : null; 564 }; 565 } 566 function walkComponent(el, host) { 567 const name = el.getAttribute("name") || el.getAttribute("component") || ""; 568 el.removeAttribute("name"); 569 el.removeAttribute("component"); 570 const tplId = el.getAttribute("data-dc-tpl"); 571 const styleRaw = el.getAttribute("style"); 572 el.removeAttribute("style"); 573 const styleGet = styleRaw != null ? compileAttr(styleRaw) : null; 574 const { propGetters, hintSize } = collectProps(el, "dc-import", host); 575 const kids = walkChildren(el, host); 576 return (vals, ctx, key) => { 577 const props = { 578 key, 579 __hintSize: hintSize, 580 __tplId: tplId, 581 __hostStyle: styleGet ? hostPositionStyle(styleGet(vals)) : void 0 582 }; 583 for (const [k, g] of propGetters) { 584 const v = g(vals); 585 if (k === "dcProps") { 586 if (v && typeof v === "object") Object.assign(props, v); 587 continue; 588 } 589 props[k] = v; 590 } 591 if (kids.length) props.children = kids.map((b, j) => b(vals, ctx, j)); 592 return h(host.component(name), props); 593 }; 594 } 595 function walkXImport(el, host) { 596 const globalNameGet = compileAttr( 597 el.getAttribute("component-from-global-scope") || "" 598 ); 599 const exportNameGet = compileAttr( 600 el.getAttribute("component") || el.getAttribute("name") || "" 601 ); 602 const fromRaw = el.getAttribute("from") || el.getAttribute("src") || el.getAttribute("import") || ""; 603 const urls = fromRaw.trim() ? fromRaw.trim().split(/\s+/) : []; 604 const url = urls.length ? urls[urls.length - 1] : ""; 605 const kindOf = (u) => /\.(jsx|tsx)(\?|#|$)/i.test(u) ? "jsx" : "js"; 606 const tplId = el.getAttribute("data-dc-tpl"); 607 const styleRaw = el.getAttribute("style"); 608 el.removeAttribute("style"); 609 const styleGet = styleRaw != null ? compileAttr(styleRaw) : null; 610 const wrap = tplId != null || styleGet != null; 611 const { propGetters, hintSize } = collectProps(el, "x-import", host); 612 const hasContent = el.children.length > 0 || !!(el.textContent || "").trim();
613 const kids = hasContent ? walkChildren(el, host) : []; 614 const urlBindable = fromRaw.includes("{{"); 615 if (urls.length && !urlBindable) { 616 let prev; 617 for (const u of urls) prev = host.loadExternal(kindOf(u), u, prev); 618 } 619 const evalName = (g, vals) => { 620 const v = g(vals); 621 const s = v == null ? "" : String(v); 622 return s.includes("{{") ? "" : s; 623 }; 624 return (vals, ctx, key) => { 625 const globalName = evalName(globalNameGet, vals); 626 const name = globalName || evalName(exportNameGet, vals); 627 const C = !name || urlBindable ? null : globalName ? host.resolveExternalGlobal(url, globalName) : host.resolveExternal(url, name); 628 const hostStyle = styleGet ? hostPositionStyle(styleGet(vals)) : void 0; 629 const wrapper = wrap ? { 630 key, 631 className: "sc-host-x", 632 "data-dc-tpl": tplId, 633 style: hostStyle || { display: "contents" } 634 } : null; 635 if (!C) { 636 const error = urlBindable ? "x-import `from` cannot contain {{ \u2026 }} \u2014 module URLs are resolved at parse time; use a literal URL" : host.resolveExternalError(url, name); 637 const ph = host.placeholder({ 638 key: wrapper ? void 0 : key, 639 name, 640 hintSize, 641 error 642 }); 643 return wrapper ? h("div", wrapper, ph) : ph; 644 } 645 const props = wrapper ? {} : { key }; 646 let unresolvedHole = false; 647 for (const [k, g] of propGetters) { 648 if (k === "component" || k === "componentFromGlobalScope" || k === "from") { 649 continue; 650 } 651 const v = g(vals); 652 if (v === void 0) unresolvedHole = true; 653 if (k === "dcProps") { 654 if (v && typeof v === "object") Object.assign(props, v); 655 continue; 656 } 657 props[k] = v; 658 } 659 if (unresolvedHole && ctx?.__htmlStreamingNow) { 660 const ph = host.placeholder({ 661 key: wrapper ? void 0 : key, 662 name, 663 hintSize, 664 error: null 665 }); 666 return wrapper ? h("div", wrapper, ph) : ph; 667 } 668 if (kids.length) props.children = kids.map((b, j) => b(vals, ctx, j)); 669 return wrapper ? h("div", wrapper, h(C, props)) : h(C, props); 670 }; 671 } 672 function contentKey(el) { 673 const clone = el.cloneNode(true); 674 for (const d of clone.querySelectorAll("*")) { 675 while (d.attributes.length) d.removeAttribute(d.attributes[0].name); 676 } 677 const s = clone.innerHTML; 678 let h2 = 5381; 679 for (let i = 0; i < s.length; i++) h2 = (h2 << 5) + h2 + s.charCodeAt(i) | 0; 680 return s.length + "." + (h2 >>> 0).toString(36); 681 } 682 var NEVER_CONTENT_KEYED = new Set( 683 "script style textarea option title select canvas iframe video audio".split( 684 " " 685 ) 686 ); 687 var NOT_INLINE_SELECTOR = ":not(" + [...INLINE_TEXT_TAGS].join(",") + ")"; 688 function walkElement(el, host) { 689 const realTag = RAW_UNWRAP[el.localName] || el.localName; 690 const tplId = el.getAttribute("data-dc-tpl"); 691 const inlineOnly = el.childNodes.length > 0 && !NEVER_CONTENT_KEYED.has(realTag) && el.querySelector(NOT_INLINE_SELECTOR) === null; 692 const keySuffix = inlineOnly ? "|" + contentKey(el) : ""; 693 const { propGetters, pseudoClasses } = collectProps(el, "dom", host); 694 const kids = walkChildren(el, host); 695 return (vals, ctx, key) => { 696 const props = { 697 key: key + keySuffix, 698 "data-dc-tpl": tplId 699 }; 700 for (const [k, g] of propGetters) { 701 let v = g(vals); 702 if (k === "style" && typeof v === "string") v = cssToObj(v); 703 if ((k === "value" || k === "checked") && v === void 0) { 704 v = k === "checked" ? false : ""; 705 } 706 props[k] = v; 707 } 708 if (pseudoClasses.length) { 709 props.className = [props.className, ...pseudoClasses].filter(Boolean).join(" "); 710 } 711 return h(realTag, props, ...kids.map((b, j) => b(vals, ctx, j))); 712 }; 713 } 714 715
715// src/logic.ts 716 var StreamableLogic = class { 717 constructor(props) { 718 __publicField(this, "props"); 719 __publicField(this, "state", {}); 720 /** Back-pointer to the wrapper component, installed after construction. */ 721 __publicField(this, "__host"); 722 this.props = props || {}; 723 } 724 setState(update, cb) { 725 this.__host && this.__host.__setLogicState(update, cb); 726 } 727 forceUpdate() { 728 this.__host && this.__host.forceUpdate(); 729 } 730 componentDidMount() { 731 } 732 componentDidUpdate(_prevProps) { 733 } 734 componentWillUnmount() { 735 } 736 /** The flat object the template renders against (merged over props). */ 737 renderVals() { 738 return {}; 739 } 740 }; 741 function evalDcLogic(src) { 742 //! nosemgrep: eval-and-function-constructor 743 const fn = new Function( 744 "DCLogic", 745 "StreamableLogic", 746 "React", 747 src + '\n;return (typeof Component!=="undefined"&&Component)||undefined;' 748 ); 749 return fn(StreamableLogic, StreamableLogic, getReact()); 750 } 751 752
752// src/component.ts 753 function shallowEqual(a, b) { 754 if (!b) return false; 755 const ak = Object.keys(a).filter((k) => k !== "children"); 756 const bk = Object.keys(b).filter((k) => k !== "children"); 757 if (ak.length !== bk.length) return false; 758 for (const k of ak) if (a[k] !== b[k]) return false; 759 return true; 760 } 761 function Placeholder({ 762 name, 763 hintSize, 764 streaming, 765 error 766 }) { 767 const [w, hgt] = (hintSize || "100%,60px").split(","); 768 return h( 769 "div", 770 { 771 className: "sc-placeholder" + (streaming ? " sc-streaming" : ""), 772 style: { width: w.trim(), height: hgt && hgt.trim() }, 773 title: name 774 }, 775 error ? h( 776 "div", 777 { className: "sc-placeholder-error" }, 778 (name ? name + ": " : "") + error 779 ) : null 780 ); 781 } 782 function hintToMin(hint) { 783 if (!hint) return void 0; 784 const [w, hgt] = hint.split(","); 785 return { minWidth: w.trim(), minHeight: hgt && hgt.trim() }; 786 } 787 function createComponentFactory(registry, ensureFetched) { 788 const React = getReact(); 789 const AncestorContext = React.createContext([]); 790 class StreamableComponent extends React.Component { 791 constructor(props) { 792 super(props); 793 __publicField(this, "__name"); 794 __publicField(this, "__sub"); 795 __publicField(this, "__needsDidMount", false); 796 /** Snapshot of the registry's streaming flags taken at render time â 797 * builders read it off the RenderCtx (this) to pick placeholder vs 798 * render-nothing for unresolved values. */ 799 __publicField(this, "__streamingNow", false); 800 __publicField(this, "__htmlStreamingNow", false); 801 /** When a construct throws, remember the (class, registry.ver, props) 802 * triple so render-time reconcile doesn't re-attempt it on every parent 803 * re-render. A registry bump (new class, template, external module 804 * resolving via bumpAll) changes `ver` and breaks the memo so an 805 * env-dependent constructor can self-heal. */ 806 __publicField(this, "__failedLogic", null); 807 __publicField(this, "__failedUserProps", null); 808 __publicField(this, "__failedVer", -1); 809 /** Per-instance constructor error â kept here (not on the registry entry) 810 * so one instance's successful construct can't hide a sibling's failure, 811 * and a construct can never wipe an eval error `updateJs` recorded on 812 * `r.logicError`. */ 813 __publicField(this, "__ctorError", null); 814 __publicField(this, "logic"); 815 this.__name = props.__name; 816 this.state = { __v: 0, __err: null }; 817 this.__sub = () => { 818 if (this.state.__err) this.setState({ __err: null }); 819 this.forceUpdate(); 820 }; 821 this.__makeLogic(registry.get(this.__name).Logic, null); 822 ensureFetched(this.__name); 823 } 824 /** Error-boundary hook: a render crash anywhere in this DC's subtree 825 * (its own template, an x-import'd component, a child DC without its 826 * own deeper boundary) lands here instead of unmounting the page. */ 827 static getDerivedStateFromError(e) { 828 return { __err: e instanceof Error && e.message ? e.message : String(e) }; 829 } 830 componentDidCatch(e, info) { 831 console.error( 832 "[dc-runtime] render error in <" + this.__name + ">:", 833 e, 834 info?.componentStack || "" 835 ); 836 } 837 /** Instantiate the logic class (or the no-op base) and adopt `prevState` 838 * over its initial state â used both at mount and on hot-swap. */ 839 __makeLogic(Logic, prevState) { 840 const L = Logic || StreamableLogic; 841 try { 842 this.logic = new L(this.__userProps()); 843 this.__failedLogic = null; 844 this.__failedUserProps = null; 845 this.__ctorError = null; 846 } catch (e) { 847 console.error(e); 848 this.__failedLogic = Logic; 849 this.__failedUserProps = this.__userProps(); 850 this.__failedVer = registry.get(this.__name).ver; 851 this.__ctorError = this.__name + ": " + (e instanceof Error && e.message ? e.message :
851String(e)); 852 this.logic = new StreamableLogic( 853 this.__userProps() 854 ); 855 } 856 this.logic.__host = this; 857 if (prevState) 858 this.logic.state = { ...this.logic.state || {}, ...prevState }; 859 } 860 /** The props the author's logic + template see â internal __-prefixed 861 * wiring stripped. */ 862 __userProps() { 863 const { __name, __hintSize, __tplId, __hostStyle, ...rest } = this.props; 864 return rest; 865 } 866 __setLogicState(update, cb) { 867 const prev = this.logic.state; 868 const patch = typeof update === "function" ? update(prev) : update; 869 this.logic.state = { ...prev, ...patch }; 870 this.setState((s) => ({ __v: s.__v + 1 }), cb); 871 } 872 /** Swap the logic instance when the registry's Logic class changed 873 * (streaming completion, hot reload). State carries over; didMount 874 * re-fires after the swap commits so refs exist. */ 875 __reconcileLogic() { 876 const r = registry.get(this.__name); 877 const Next = r.Logic; 878 const Cur = this.logic.constructor; 879 if (Next === Cur || !Next && Cur === StreamableLogic || Next === this.__failedLogic && r.ver === this.__failedVer && shallowEqual(this.__userProps(), this.__failedUserProps)) { 880 return; 881 } 882 if (!this.__needsDidMount) { 883 try { 884 this.logic.componentWillUnmount(); 885 } catch (e) { 886 console.error(e); 887 } 888 } 889 this.__makeLogic(Next, this.logic.state); 890 this.__needsDidMount = true; 891 } 892 componentDidMount() { 893 registry.get(this.__name).subs.add(this.__sub); 894 try { 895 this.logic.componentDidMount(); 896 } catch (e) { 897 console.error(e); 898 } 899 } 900 componentDidUpdate(prevProps) { 901 this.logic.props = this.__userProps(); 902 if (this.__needsDidMount) { 903 if (this.state.__err || !registry.get(this.__name).tpl) return; 904 this.__needsDidMount = false; 905 try { 906 this.logic.componentDidMount(); 907 } catch (e) { 908 console.error(e); 909 } 910 } else { 911 try { 912 this.logic.componentDidUpdate(prevProps); 913 } catch (e) { 914 console.error(e); 915 } 916 } 917 } 918 componentWillUnmount() { 919 registry.get(this.__name).subs.delete(this.__sub); 920 if (!this.__needsDidMount) { 921 try { 922 this.logic.componentWillUnmount(); 923 } catch (e) { 924 console.error(e); 925 } 926 } 927 } 928 render() { 929 const r = registry.get(this.__name); 930 const cls = "sc-host" + (r.htmlStreaming ? " sc-streaming-html" : "") + (r.jsStreaming ? " sc-streaming-js" : ""); 931 const hintStyle = r.htmlStreaming ? hintToMin(this.props.__hintSize) : void 0; 932 const hostStyle = this.props.__hostStyle || hintStyle ? { ...hintStyle || {}, ...this.props.__hostStyle || {} } : void 0; 933 const hostBase = { 934 className: cls, 935 style: hostStyle, 936 "data-sc-name": this.__name, 937 "data-dc-tpl": this.props.__tplId 938 }; 939 const chain = Array.isArray(this.context) ? this.context : []; 940 if (chain.includes(this.__name)) { 941 const cycle = [ 942 ...chain.slice(chain.indexOf(this.__name)), 943 this.__name 944 ].join(" \u2192 "); 945 return h( 946 "div", 947 { ...hostBase, className: cls + " sc-has-error" }, 948 h(Placeholder, { 949 name: this.__name, 950 hintSize: this.props.__hintSize, 951 error: "circular import: " + cycle 952 }) 953 ); 954 } 955 if (this.state.__err) { 956 return h( 957 "div", 958 { ...hostBase, className: cls + " sc-has-error" }, 959 h( 960 "div", 961 { className: "sc-logic-error", "data-omelette-chrome": "" }, 962 this.__name + ": " + this.state.__err 963 ), 964 h(Placeholder, { 965 name: this.__name, 966 hintSize: this.props.__hintSize, 967 error: this.state.__err 968 }) 969 ); 970 } 971 this.__reconcileLogic(); 972 if (!r.tpl) { 973 return h( 974 "div", 975 hostBase, 976 h(Placeholder, { name: this.__name, hintSize: this.props.__hintSize }) 977 ); 978 } 979 const userProps = this.__userProps(); 980 this.logic.props = userProps; 981 let vals = userProps; 982 let renderErr = r.logicError || this.__ctorError; 983 try { 984 vals = { ...userProps, ...this.logic.renderVals() || {} }; 985 } catch (e) { 986 console.error(e); 987 renderErr = this.__name + ".renderVals(): " + (e instanceof Error && e.message ? e.message :
987String(e)); 988 } 989 this.__streamingNow = !!(r.htmlStreaming || r.jsStreaming); 990 this.__htmlStreamingNow = !!r.htmlStreaming; 991 return h( 992 "div", 993 { ...hostBase, className: cls + (renderErr ? " sc-has-error" : "") }, 994 renderErr && h( 995 "div", 996 { className: "sc-logic-error", "data-omelette-chrome": "" }, 997 renderErr 998 ), 999 h( 1000 AncestorContext.Provider, 1001 { value: [...chain, this.__name] }, 1002 r.tpl(vals, this) 1003 ) 1004 ); 1005 } 1006 } 1007 __publicField(StreamableComponent, "contextType", AncestorContext); 1008 const named = /* @__PURE__ */ new Map(); 1009 function getDC(name) { 1010 const hit = named.get(name); 1011 if (hit) return hit; 1012 function Dispatcher(p) { 1013 const [, setTick] = React.useState(0); 1014 React.useEffect(() => { 1015 const sub = () => setTick((n) => n + 1); 1016 registry.get(name).subs.add(sub); 1017 return () => { 1018 registry.get(name).subs.delete(sub); 1019 }; 1020 }, []); 1021 ensureFetched(name); 1022 return h(StreamableComponent, { ...p, __name: name }); 1023 } 1024 Dispatcher.displayName = name; 1025 named.set(name, Dispatcher); 1026 return Dispatcher; 1027 } 1028 return { 1029 getDC, 1030 StreamableComponent 1031 }; 1032 } 1033 1034
1034// src/external.ts 1035 var isCustomElementName = (n) => !n.includes(".") && n.includes("-"); 1036 function isRenderableType(g) { 1037 if (typeof g === "function") return !isElementClass(g); 1038 return typeof g === "object" && g !== null && typeof g.$$typeof === "symbol"; 1039 } 1040 function resolveDottedPath(root, name) { 1041 let cur = root; 1042 for (const seg of name.split(".")) { 1043 if (cur == null) return void 0; 1044 cur = cur[seg]; 1045 } 1046 return cur; 1047 } 1048 var BABEL_URL = "https://unpkg.com/@babel/[email protected]/babel.min.js"; 1049 var BABEL_SRI = "sha384-m08KidiNqLdpJqLq95G/LEi8Qvjl/xUYll3QILypMoQ65QorJ9Lvtp2RXYGBFj1y"; 1050 var GLOBAL_POLL_INTERVAL_MS = 50; 1051 var GLOBAL_POLL_TIMEOUT_MS = 3e4; 1052 function createExternalModules(onResolved) { 1053 const cache = /* @__PURE__ */ new Map(); 1054 let babelLoading = null; 1055 const reportedMissing = /* @__PURE__ */ new Map(); 1056 const polling = /* @__PURE__ */ new Set(); 1057 function ensureBabel() { 1058 if (window.Babel) return Promise.resolve(); 1059 if (babelLoading) return babelLoading; 1060 babelLoading = new Promise((res, rej) => { 1061 const s = document.createElement("script"); 1062 s.src = BABEL_URL; 1063 s.integrity = BABEL_SRI; 1064 s.crossOrigin = "anonymous"; 1065 s.onload = () => res(); 1066 s.onerror = rej; 1067 document.head.appendChild(s); 1068 }); 1069 return babelLoading; 1070 } 1071 const pending = /* @__PURE__ */ new Map(); 1072 function load(kind, url, after) { 1073 const existing = pending.get(url); 1074 if (existing) return existing; 1075 cache.set(url, null); 1076 console.info("[dc-runtime] x-import: loading", url, "(" + kind + ")"); 1077 const ready = Promise.all([
1078 kind === "jsx" ? ensureBabel() : Promise.resolve(), 1079 after ?? Promise.resolve() 1080 ]); 1081 const p = ready.then(() => fetch(url)).then((r) => { 1082 if (!r.ok) throw new Error("HTTP " + r.status); 1083 return r.text(); 1084 }).then((src) => { 1085 const code = kind === "jsx" ? window.Babel.transform(src, { 1086 filename: url, 1087 presets: ["react", "typescript"] 1088 }).code : src; 1089 const module = { exports: {} }; 1090 const before = new Set(Object.keys(window)); 1091 //! nosemgrep: eval-and-function-constructor 1092 new Function("React", "module", "exports", "require", code)( 1093 getReact(), 1094 module, 1095 module.exports, 1096 () => ({}) 1097 ); 1098 const globals = {}; 1099 for (const k of Object.keys(window)) { 1100 if (!before.has(k) && typeof window[k] === "function") { 1101 globals[k] = window[k]; 1102 } 1103 } 1104 cache.set(url, { mod: module.exports, globals }); 1105 console.info( 1106 "[dc-runtime] x-import: loaded", 1107 url, 1108 "\u2014 exports:", 1109 Object.keys(module.exports), 1110 "window globals:", 1111 Object.keys(globals) 1112 ); 1113 onResolved(); 1114 }).catch((e) => { 1115 cache.set(url, { 1116 mod: {}, 1117 globals: {}, 1118 error: "failed to load: " + (e instanceof Error && e.message ? e.message : String(e)) 1119 }); 1120 console.error( 1121 "[dc-runtime] x-import: FAILED to load", 1122 url, 1123 "(" + kind + ")", 1124 e 1125 ); 1126 onResolved(); 1127 }); 1128 pending.set(url, p); 1129 return p; 1130 } 1131 function resolve2(url, name) { 1132 const entry = cache.get(url); 1133 if (!entry) return null; 1134 const { mod, globals } = entry; 1135 const C = mod && mod[name] || globals && globals[name] || typeof window !== "undefined" && window[name] || mod && mod.default; 1136 if (typeof C === "function") return C; 1137 const key = url + "\0" + name; 1138 if (!reportedMissing.has(key)) { 1139 reportedMissing.set( 1140 key, 1141 entry.error || 'no export named "' + name + '" (has: ' + Object.keys(mod).join(", ") + ")" 1142 ); 1143 console.error( 1144 "[dc-runtime] x-import: module", 1145 url, 1146 "loaded but has no component named", 1147 JSON.stringify(name), 1148 "\u2014 available exports:", 1149 Object.keys(mod), 1150 "window globals:", 1151 Object.keys(globals), 1152 ". The module must `module.exports = {" + name + "}` or set `window." + name + "`." 1153 ); 1154 } 1155 return null; 1156 } 1157 function waitForGlobal(name) { 1158 if (polling.has(name)) return; 1159 polling.add(name); 1160 const started = Date.now(); 1161 const isCE = isCustomElementName(name); 1162 const tick = () => { 1163 const found = isCE ? customElements.get(name) : isRenderableType(resolveDottedPath(window, name)); 1164 if (found) { 1165 polling.delete(name); 1166 onResolved(); 1167 return; 1168 } 1169 if (Date.now() - started >= GLOBAL_POLL_TIMEOUT_MS) { 1170 console.warn( 1171 "[dc-runtime] x-import: global", 1172 JSON.stringify(name), 1173 "never appeared on window after " + GLOBAL_POLL_TIMEOUT_MS + "ms"
1174 ); 1175 return; 1176 } 1177 setTimeout(tick, GLOBAL_POLL_INTERVAL_MS); 1178 }; 1179 setTimeout(tick, GLOBAL_POLL_INTERVAL_MS); 1180 } 1181 function resolveGlobal(url, name) { 1182 const isCE = isCustomElementName(name); 1183 if (!url) { 1184 if (isCE) { 1185 if (customElements.get(name)) return name; 1186 waitForGlobal(name); 1187 return null; 1188 } 1189 const g2 = resolveDottedPath(window, name); 1190 if (isRenderableType(g2)) return g2; 1191 waitForGlobal(name); 1192 return null; 1193 } 1194 const entry = cache.get(url); 1195 if (!entry) return null; 1196 if (isCE && customElements.get(name)) return name; 1197 const g = entry.globals[name] ?? resolveDottedPath(window, name); 1198 if (isRenderableType(g)) return g; 1199 if (name.includes(".")) return null; 1200 const key = url + "\0global\0" + name; 1201 if (!reportedMissing.has(key)) { 1202 reportedMissing.set(key, null); 1203 if (isCE && !customElements.get(name)) { 1204 console.warn( 1205 "[dc-runtime] x-import:", 1206 url, 1207 "loaded but no custom element", 1208 JSON.stringify(name), 1209 "is registered and window." + name + " is not a function \u2014 rendering <" + name + "> as an unknown element." 1210 ); 1211 } 1212 } 1213 return name; 1214 } 1215 function getError(url, name) { 1216 const entry = cache.get(url); 1217 if (entry?.error) return entry.error; 1218 return reportedMissing.get(url + "\0" + name) || null; 1219 } 1220 return { load, resolve: resolve2, resolveGlobal, getError }; 1221 } 1222 function isElementClass(g) { 1223 try { 1224 return typeof g === "function" && typeof HTMLElement !== "undefined" && g.prototype instanceof HTMLElement; 1225 } catch { 1226 return false; 1227 } 1228 } 1229 1230
1230// src/atomics.ts 1231 var ATOMIC_CSS = ( 1232 // layout 1233 ".fx{display:flex}.col{display:flex;flex-direction:column}.grid{display:grid}.ac{align-items:center}.jc{justify-content:center}.jb{justify-content:space-between}.f1{flex:1}.noshrink{flex-shrink:0}.wrap{flex-wrap:wrap}.fw5{font-weight:500}.fw6{font-weight:600}.fw7{font-weight:700}.fw8{font-weight:800}.fs11{font-size:11px}.fs12{font-size:12px}.fs13{font-size:13px}.fs14{font-size:14px}.fs15{font-size:15px}.fs16{font-size:16px}.fs20{font-size:20px}.fs22{font-size:22px}.upper{text-transform:uppercase}.tc{text-align:center}.nowrap{white-space:nowrap}.gap8{gap:8px}.gap10{gap:10px}.gap12{gap:12px}.gap16{gap:16px}.gap24{gap:24px}.m0{margin:0}.mt8{margin-top:8px}.mt12{margin-top:12px}.mt16{margin-top:16px}.mb8{margin-bottom:8px}.mb12{margin-bottom:12px}.mb16{margin-bottom:16px}.posrel{position:relative}.posabs{position:absolute}.round{border-radius:50%}.ohide{overflow:hidden}.bbox{box-sizing:border-box}.pointer{cursor:pointer}.w100{width:100%}.b0{border:none}" 1234 ); 1235 1236
1236// src/helmet.ts 1237 var DESIGN_DOC_MODE_RE = /<meta\b[^>]*\bname\s*=\s*["']design_doc_mode["'][^>]*\b(?:content|value)\s*=\s*["'](\w+)["']/i; 1238 var CANVAS_BG_LIGHT = "#f0eee6"; 1239 var CANVAS_BG_DARK = "#2e2c26"; 1240 function createHelmetManager(doc, isStreaming) { 1241 const mounted = /* @__PURE__ */ new Set(); 1242 const live = /* @__PURE__ */ new Map(); 1243 let designDocMode = null; 1244 let canvasStyleEl = null; 1245 let appTheme = "light"; 1246 try { 1247 const ds = doc.documentElement.dataset.theme; 1248 appTheme = ds === "dark" || ds === "light" ? ds : new URLSearchParams(doc.defaultView?.location.search ?? "").get( 1249 "theme" 1250 ) === "dark" ? "dark" : "light"; 1251 } catch { 1252 } 1253 function applyCanvasBg() { 1254 if (!canvasStyleEl) return; 1255 const bg = appTheme === "dark" ? CANVAS_BG_DARK : CANVAS_BG_LIGHT; 1256 canvasStyleEl.textContent = `html,body{background:${bg}}#dc-root>.sc-host{position:relative}`; 1257 } 1258 function postDesignMode(mode) { 1259 if (window.parent === window) return; 1260 try { 1261 window.parent.postMessage({ type: "__dc_design_mode", mode }, "*"); 1262 } catch { 1263 } 1264 } 1265 function setDesignDocMode(mode) { 1266 if (mode === designDocMode) return; 1267 designDocMode = mode; 1268 postDesignMode(mode); 1269 if (mode === "canvas") { 1270 doc.documentElement.setAttribute("data-dc-canvas", ""); 1271 canvasStyleEl = doc.createElement("style"); 1272 canvasStyleEl.setAttribute("data-dc-canvas", ""); 1273 applyCanvasBg(); 1274 doc.head.appendChild(canvasStyleEl); 1275 } else { 1276 doc.documentElement.removeAttribute("data-dc-canvas"); 1277 canvasStyleEl?.remove(); 1278 canvasStyleEl = null; 1279 } 1280 } 1281 window.addEventListener("message", (e) => { 1282 const type = e.data && e.data.type; 1283 if (type === "__dc_theme") { 1284 const t = e.data.theme; 1285 if (t === "light" || t === "dark") { 1286 appTheme = t; 1287 doc.documentElement.dataset.theme = t; 1288 applyCanvasBg(); 1289 } 1290 return; 1291 } 1292 if (!designDocMode || type !== "__dc_probe") return; 1293 postDesignMode(designDocMode); 1294 }); 1295 function compile(node) { 1296 const raw = [...node.children]; 1297 const helmetClosed = node.nextSibling != null || node.parentNode?.nextSibling != null; 1298 if (node.hasAttribute("data-dc-atomics") && !mounted.has("__dc-atomics")) { 1299 mounted.add("__dc-atomics"); 1300 const el = doc.createElement("style"); 1301 el.id = "__dc-atomics"; 1302 el.textContent = ATOMIC_CSS; 1303 doc.head.appendChild(el); 1304 } 1305 return (_vals, ctx) => { 1306 const name = ctx && ctx.__name || ""; 1307 const streaming = !!(name && isStreaming(name)); 1308 for (let i = 0; i < raw.length; i++) { 1309 const child = raw[i]; 1310 const tag = child.tagName; 1311 const mayBePartial = streaming && !helmetClosed && i === raw.length - 1; 1312 if (tag === "SCRIPT") { 1313 if (mayBePartial) continue; 1314 const key = "SCRIPT|" + (child.getAttribute("src") || child.textContent || ""); 1315 if (mounted.has(key)) continue; 1316 mounted.add(key); 1317 const el = doc.createElement("script"); 1318 for (const { name: an, value } of [...child.attributes]) 1319 el.setAttribute(an, value); 1320 if (child.textContent) el.textContent = child.textContent; 1321 doc.head.appendChild(el); 1322 } else if (tag === "LINK" || tag === "META") { 1323 if (mayBePartial) continue; 1324 const key = tag + "|" + (child.getAttribute("href") || child.getAttribute("src") || child.outerHTML); 1325 if (mounted.has(key)) continue; 1326 mounted.add(key); 1327 doc.head.appendChild(child.cloneNode(true)); 1328 } else { 1329 const key = name + "|" + i; 1330 let el = live.get(key); 1331 if (!el || el.tagName !== tag) { 1332 if (el) el.remove(); 1333 el = doc.createElement(tag.toLowerCase()); 1334 live.set(key, el); 1335 doc.head.appendChild(el); 1336 } 1337 for (const { name: an, value } of [...child.attributes]) { 1338 if (el.getAttribute(an) !== value) el.setAttribute(an, value); 1339 } 1340 if (el.textContent !== child.textContent) 1341 el.textContent = child.textContent; 1342 } 1343 } 1344 return null; 1345 }; 1346 } 1347 return { compile, setDesignDocMode }; 1348 } 1349 1350
1350// src/pseudo.ts 1351 function createPseudoSheet(doc) { 1352 let el = null; 1353 const cache = /* @__PURE__ */ new Map(); 1354 let n = 0; 1355 return (pseudo, css) => { 1356 const k = pseudo + "|" + css; 1357 const hit = cache.get(k); 1358 if (hit) return hit; 1359 if (!el) { 1360 el = doc.createElement("style"); 1361 doc.head.appendChild(el); 1362 } 1363 const cls = "scp" + (n++).toString(36); 1364 const sel = pseudo === "before" || pseudo === "after" ? "." + cls + "::" + pseudo : "." + cls + ":" + pseudo; 1365 el.sheet.insertRule(sel + "{" + css + "}", el.sheet.cssRules.length); 1366 cache.set(k, cls); 1367 return cls; 1368 }; 1369 } 1370 1371
1371// src/registry.ts 1372 function createRegistry() { 1373 const entries = /* @__PURE__ */ Object.create(null); 1374 function get(name) { 1375 return entries[name] || (entries[name] = { 1376 html: "", 1377 tpl: null, 1378 Logic: null, 1379 jsStreaming: false, 1380 htmlStreaming: false, 1381 ver: 0, 1382 subs: /* @__PURE__ */ new Set(), 1383 fetched: false 1384 }); 1385 } 1386 function bump(name) { 1387 const r = get(name); 1388 r.ver++; 1389 for (const fn of r.subs) fn(); 1390 } 1391 return { 1392 entries, 1393 get, 1394 bump, 1395 bumpAll() { 1396 for (const n in entries) bump(n); 1397 } 1398 }; 1399 } 1400 1401
1401// src/runtime.ts 1402 var COMPONENT_DIR = "."; 1403 function createRuntime(doc = document) { 1404 const registry = createRegistry(); 1405 const pseudoClass = createPseudoSheet(doc); 1406 const helmet = createHelmetManager( 1407 doc, 1408 (name) => registry.get(name).htmlStreaming 1409 ); 1410 const external = createExternalModules(() => registry.bumpAll()); 1411 const factory = createComponentFactory(registry, ensureFetched); 1412 const host = { 1413 component: (name) => factory.getDC(name), 1414 placeholder: (props) => h(Placeholder, props), 1415 helmet: (node) => helmet.compile(node), 1416 loadExternal: (kind, url, after) => external.load(kind, url, after), 1417 resolveExternal: (url, name) => external.resolve(url, name), 1418 resolveExternalGlobal: (url, name) => external.resolveGlobal(url, name), 1419 resolveExternalError: (url, name) => external.getError(url, name), 1420 pseudoClass 1421 }; 1422 function ensureFetched(name) { 1423 const r = registry.get(name); 1424 if (r.fetched) return; 1425 r.fetched = true; 1426 const url = COMPONENT_DIR + "/" + encodeURIComponent(name) + ".dc.html"; 1427 fetch(url).then((res) => { 1428 if (!res.ok) { 1429 console.error( 1430 "[dc-runtime] sibling fetch for <" + name + "/> failed:", 1431 url, 1432 "returned", 1433 res.status, 1434 "\u2014 the reference renders as an empty placeholder." 1435 ); 1436 return ""; 1437 } 1438 return res.text(); 1439 }).then((t) => { 1440 if (!t) return; 1441 const parsed = parseDcText(t); 1442 if (!parsed) { 1443 console.error( 1444 "[dc-runtime] sibling fetch for <" + name + "/>:", 1445 url, 1446 "has no <x-dc> block \u2014 not a Design Component." 1447 ); 1448 return; 1449 } 1450 if (parsed.props) r.propsMeta = parsed.props; 1451 if (parsed.preview) r.preview = parsed.preview; 1452 if (parsed.template && !r.html) updateHtml(name, parsed.template); 1453 if (parsed.js && !r.Logic) updateJs(name, parsed.js); 1454 }).catch( 1455 (e) => console.error( 1456 "[dc-runtime] sibling fetch for <" + name + "/> threw:", 1457 url, 1458 e 1459 ) 1460 ); 1461 } 1462 let rootName = null; 1463 function updateHtml(name, html) { 1464 const r = registry.get(name); 1465 r.html = html; 1466 if (name === rootName) { 1467 const mode = DESIGN_DOC_MODE_RE.exec(html)?.[1] ?? null; 1468 if (mode || !r.htmlStreaming) helmet.setDesignDocMode(mode); 1469 } 1470 try { 1471 r.tpl = compileTemplate(html, host); 1472 } catch (e) { 1473 console.error("[dc-runtime] template compile FAILED for", name, e); 1474 } 1475 registry.bump(name); 1476 } 1477 function updateJs(name, src) { 1478 const r = registry.get(name); 1479 const seq = r.jsSeq = (r.jsSeq || 0) + 1; 1480 try { 1481 const Cls = evalDcLogic(src); 1482 if (r.jsSeq !== seq) return; 1483 if (typeof Cls !== "function") { 1484 r.logicError = name + ".dc.html: <script data-dc-script> must define `class Component extends DCLogic`"; 1485 } else { 1486 r.logicError = null; 1487 r.Logic = Cls; 1488 } 1489 } catch (e) { 1490 if (r.jsSeq !== seq) return; 1491 console.error( 1492 "[dc-runtime] logic class eval FAILED for", 1493 name, 1494 "\u2014 the template renders with props only.", 1495 e 1496 ); 1497 r.logicError = name + ": " + (e instanceof Error && e.message ? e.message : String(e)); 1498 } 1499 registry.bump(name); 1500 } 1501 function setStreaming(name, kind, on) { 1502 const r = registry.get(name); 1503 if (kind === "html") r.htmlStreaming = !!on; 1504 else r.jsStreaming = !!on; 1505 let any = false; 1506 for (const n in registry.entries) { 1507 const e = registry.entries[n]; 1508 if (e && (e.htmlStreaming || e.jsStreaming)) { 1509 any = true; 1510 break; 1511 } 1512 } 1513 doc.documentElement.classList.toggle("sc-dc-streaming", any); 1514 registry.bump(name); 1515 } 1516 function dcUpdate(name, kind, content, streaming) { 1517 if (streaming) registry.get(name).fetched = true; 1518 if (kind === "html") { 1519 setStreaming(name, "html", !!streaming); 1520 updateHtml(name, content); 1521 }
1521 else if (kind === "js") { 1522 setStreaming(name, "js", !!streaming); 1523 if (!streaming) updateJs(name, content); 1524 } else if (kind === "props") { 1525 const { props, preview } = parseDataProps(content); 1526 const r = registry.get(name); 1527 r.propsMeta = props ?? void 0; 1528 r.preview = preview; 1529 registry.bump(name); 1530 } 1531 } 1532 function setProps(name, overrides) { 1533 registry.get(name).propOverrides = overrides && typeof overrides === "object" ? { ...overrides } : null; 1534 registry.bump(name); 1535 } 1536 function adoptParsed(name, parsed) { 1537 if (!parsed) return; 1538 const r = registry.get(name); 1539 if (parsed.props) r.propsMeta = parsed.props; 1540 if (parsed.preview) r.preview = parsed.preview; 1541 if (parsed.template) updateHtml(name, parsed.template); 1542 if (parsed.js) updateJs(name, parsed.js); 1543 } 1544 return { 1545 registry, 1546 getDC: factory.getDC, 1547 updateHtml, 1548 updateJs, 1549 dcUpdate, 1550 setProps, 1551 adoptParsed, 1552 setRootName: (name) => { 1553 rootName = name; 1554 }, 1555 markFetched: (name) => { 1556 registry.get(name).fetched = true; 1557 }, 1558 annotatedTemplate: (name) => { 1559 const r = registry.get(name); 1560 return r.tpl && r.tpl.__annotated || null; 1561 }, 1562 templateSource: (name) => registry.get(name).html || null, 1563 StreamableLogic 1564 }; 1565 } 1566 1567
1567// src/index.ts 1568 var REACT_URL = "https://unpkg.com/[email protected]/umd/react.production.min.js"; 1569 var REACT_SRI = "sha384-DGyLxAyjq0f9SPpVevD6IgztCFlnMF6oW/XQGmfe+IsZ8TqEiDrcHkMLKI6fiB/Z"; 1570 var REACT_DOM_URL = "https://unpkg.com/[email protected]/umd/react-dom.production.min.js"; 1571 var REACT_DOM_SRI = "sha384-gTGxhz21lVGYNMcdJOyq01Edg0jhn/c22nsx0kyqP0TxaV5WVdsSH1fSDUf5YJj1"; 1572 function hideRawTemplate() { 1573 const s = document.createElement("style"); 1574 s.textContent = "x-dc{display:none!important}"; 1575 document.head.appendChild(s); 1576 } 1577 function loadScript(src, integrity) { 1578 return new Promise((resolve2, reject) => { 1579 //! nosemgrep: create-script-element 1580 const s = document.createElement("script"); 1581 s.src = src; 1582 s.integrity = integrity; 1583 s.crossOrigin = "anonymous"; 1584 s.async = false; 1585 s.onload = () => resolve2(); 1586 s.onerror = () => reject(new Error(`failed to load ${src}`)); 1587 document.head.appendChild(s); 1588 }); 1589 } 1590 function loadReactUmd() { 1591 const w = window; 1592 if (w.React && w.ReactDOM) return Promise.resolve(); 1593 return Promise.all([ 1594 loadScript(REACT_URL, REACT_SRI), 1595 loadScript(REACT_DOM_URL, REACT_DOM_SRI) 1596 ]).then(() => void 0); 1597 } 1598 function init() { 1599 const runtime = createRuntime(document); 1600 let rootName = "Root"; 1601 const baseCss = document.createElement("style"); 1602 baseCss.textContent = BASE_CSS; 1603 document.head.prepend(baseCss); 1604 const notifyHost = () => { 1605 if (window.parent === window) return; 1606 const r = runtime.registry.entries[rootName]; 1607 try { 1608 window.parent.postMessage( 1609 { 1610 type: "__dc_booted", 1611 rootName, 1612 propsMeta: r && r.propsMeta || null, 1613 preview: r && r.preview || null 1614 }, 1615 "*" 1616 ); 1617 } catch { 1618 } 1619 }; 1620 const api = { 1621 __dcUpdate: (name, kind, content, streaming) => { 1622 runtime.dcUpdate(name, kind, content, streaming); 1623 if (name === rootName && !streaming && kind === "props") notifyHost(); 1624 }, 1625 __dcSetProps: (name, overrides) => runtime.setProps(name, overrides), 1626 /** Name of the component currently mounted as the page root â DC tools 1627 * push their template-stream here when targeting "the open page". */ 1628 __dcRootName: () => rootName, 1629 /** Editor bridge â the encoded, `data-dc-tpl`-annotated template source. 1630 * The host editor parses this into its own template DOM so it can map a 1631 * rendered node (carrying the same `data-dc-tpl`) back to the source 1632 * node that emitted it. Returns the encoded form (`<sc-comp>`, 1633 * `sc-camel-*` attrs); the editor decodes on serialize. */ 1634 __dcAnnotatedTemplate: (name) => runtime.annotatedTemplate(name), 1635 /** Editor bridge â the *original* (decoded) template source. */ 1636 __dcTemplateSource: (name) => runtime.templateSource(name), 1637 __dcBoot: () => { 1638 rootName = boot(runtime, document) ?? rootName; 1639 notifyHost(); 1640 }, 1641 __dcRegistry: runtime.registry.entries, 1642 getDC: (name) => runtime.getDC(name), 1643 // `DCLogic` is the documented base class name; `StreamableLogic` is the 1644 // implementation alias kept for any project that already references it. 1645 DCLogic: runtime.StreamableLogic, 1646 StreamableLogic: runtime.StreamableLogic 1647 }; 1648 Object.assign(window, api); 1649 window.__dcContentKeyed = true; 1650 if (document.readyState !== "loading") api.__dcBoot(); 1651 else document.addEventListener("DOMContentLoaded", () => api.__dcBoot()); 1652 } 1653 hideRawTemplate(); 1654 loadReactUmd().then(init).catch((err) => { 1655 console.error("[dc] failed to load React or boot:", err); 1656 throw err; 1657 }); 1658})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.