{"version":3,"file":"implementation-D3_N2zmm.mjs","names":[],"sources":["../src/css/implementation.ts","../src/registry/implementation.ts","../src/ssr/implementation.ts"],"sourcesContent":["/**\n * css tagged template literal - creates CSSStyleSheet for adoptedStyleSheets.\n *\n * In SSR environments (no CSSStyleSheet), returns a DathraStyleSheet\n * that carries the raw CSS text for DSD `<style>` injection.\n * @module\n */\n\n/**\n * Marker interface for SSR-compatible style sheets.\n * Carries raw CSS text for Declarative Shadow DOM output.\n */\ninterface DathraStyleSheet extends CSSStyleSheet {\n  /** Raw CSS text for SSR `<style>` injection. */\n  __cssText: string;\n}\n\ninterface GlobalStyleEntry {\n  readonly cssText: string;\n  readonly sheet: CSSStyleSheet;\n}\n\nconst globalStyles: GlobalStyleEntry[] = [];\nconst globalStyleTexts = new Set<string>();\nconst globalStyleSheets = new Set<CSSStyleSheet>();\nconst trackedRoots = new Set<ShadowRoot>();\n\nfunction readCssRulesText(sheet: CSSStyleSheet): string | undefined {\n  try {\n    const cssText = Array.from(sheet.cssRules, (rule) => rule.cssText).join(\n      \"\\n\",\n    );\n    (sheet as DathraStyleSheet).__cssText = cssText;\n    return cssText;\n  } catch {\n    return undefined;\n  }\n}\n\nfunction toStyleSheet(style: CSSStyleSheet | string): CSSStyleSheet {\n  if (typeof style !== \"string\") {\n    return style;\n  }\n\n  if (typeof CSSStyleSheet === \"undefined\") {\n    return { __cssText: style } as unknown as CSSStyleSheet;\n  }\n\n  const sheet = new CSSStyleSheet();\n  sheet.replaceSync(style);\n  (sheet as DathraStyleSheet).__cssText = style;\n  return sheet;\n}\n\nfunction normalizeCssTextForDedupe(\n  sheet: CSSStyleSheet | string,\n): string | undefined {\n  if (typeof sheet === \"string\") {\n    if (typeof CSSStyleSheet === \"undefined\") {\n      return sheet.trim();\n    }\n\n    const normalizedSheet = new CSSStyleSheet();\n    normalizedSheet.replaceSync(sheet);\n    return readCssRulesText(normalizedSheet) ?? sheet.trim();\n  }\n\n  return readCssRulesText(sheet) ?? getCssText(sheet)?.trim();\n}\n\nfunction mergeStyleSheets(\n  localSheets: readonly CSSStyleSheet[] = [],\n): readonly CSSStyleSheet[] {\n  const merged: CSSStyleSheet[] = [];\n  const seen = new Set<CSSStyleSheet>();\n  const seenCssTexts = new Set<string>();\n\n  const pushSheet = (sheet: CSSStyleSheet) => {\n    const cssText = normalizeCssTextForDedupe(sheet);\n    if (cssText !== undefined) {\n      if (seenCssTexts.has(cssText)) return;\n      seenCssTexts.add(cssText);\n    }\n\n    if (seen.has(sheet)) return;\n    seen.add(sheet);\n    merged.push(sheet);\n  };\n\n  for (const entry of globalStyles) {\n    pushSheet(entry.sheet);\n  }\n\n  for (const sheet of localSheets) {\n    pushSheet(sheet);\n  }\n\n  return merged;\n}\n\nfunction applyGlobalStylesToTrackedRoots(): void {\n  for (const root of trackedRoots) {\n    const localSheets =\n      (\n        root as ShadowRoot & {\n          __dathraLocalSheets?: readonly CSSStyleSheet[];\n        }\n      ).__dathraLocalSheets ?? [];\n    root.adoptedStyleSheets = [...mergeStyleSheets(localSheets)];\n  }\n}\n\n/**\n * Create a CSSStyleSheet from a template literal.\n * For use with defineComponent's styles option.\n *\n * In SSR environments, returns an object with `__cssText` for DSD output.\n * @param strings - Template string parts\n * @param values - Interpolated values\n * @returns Constructed CSSStyleSheet (with __cssText property)\n */\nfunction css(\n  strings: TemplateStringsArray,\n  ...values: unknown[]\n): CSSStyleSheet {\n  let result = \"\";\n  for (let i = 0; i < strings.length; i++) {\n    result += strings[i];\n    if (i < values.length) {\n      result += String(values[i]);\n    }\n  }\n\n  // SSR environment check\n  if (typeof CSSStyleSheet === \"undefined\") {\n    // Return an object carrying the CSS text for DSD <style> output\n    return { __cssText: result } as unknown as CSSStyleSheet;\n  }\n\n  const sheet = new CSSStyleSheet();\n  sheet.replaceSync(result);\n  // Attach raw CSS text for DSD SSR output\n  (sheet as DathraStyleSheet).__cssText = result;\n  return sheet;\n}\n\n/**\n * Extract raw CSS text from a CSSStyleSheet or DathraStyleSheet.\n * Returns undefined if the sheet has no attached text.\n */\nfunction getCssText(sheet: CSSStyleSheet | string): string | undefined {\n  if (typeof sheet === \"string\") return sheet;\n\n  const cssText = (sheet as DathraStyleSheet).__cssText;\n  if (cssText !== undefined) {\n    return cssText;\n  }\n\n  return readCssRulesText(sheet);\n}\n\nfunction adoptGlobalStyles(\n  ...styles: readonly (CSSStyleSheet | string)[]\n): void {\n  for (const style of styles) {\n    if (typeof style !== \"string\" && globalStyleSheets.has(style)) {\n      continue;\n    }\n\n    const sheet = toStyleSheet(style);\n    const cssText = getCssText(sheet);\n    const normalizedCssText = normalizeCssTextForDedupe(sheet);\n\n    if (typeof style !== \"string\") {\n      globalStyleSheets.add(style);\n    }\n\n    if (cssText === undefined || normalizedCssText === undefined) {\n      continue;\n    }\n\n    if (globalStyleTexts.has(normalizedCssText)) {\n      continue;\n    }\n\n    globalStyleSheets.add(sheet);\n    globalStyleTexts.add(normalizedCssText);\n    globalStyles.push({ cssText, sheet });\n  }\n\n  applyGlobalStylesToTrackedRoots();\n}\n\nfunction connectGlobalStyles(\n  root: ShadowRoot,\n  localSheets: readonly CSSStyleSheet[] = [],\n): void {\n  (\n    root as ShadowRoot & { __dathraLocalSheets?: readonly CSSStyleSheet[] }\n  ).__dathraLocalSheets = localSheets;\n  trackedRoots.add(root);\n  root.adoptedStyleSheets = [...mergeStyleSheets(localSheets)];\n}\n\nfunction disconnectGlobalStyles(root: ShadowRoot): void {\n  trackedRoots.delete(root);\n}\n\nfunction getGlobalStyleCssTexts(): readonly string[] {\n  return globalStyles.map((entry) => entry.cssText);\n}\n\nfunction clearGlobalStyles(): void {\n  globalStyles.length = 0;\n  globalStyleSheets.clear();\n  globalStyleTexts.clear();\n\n  for (const root of trackedRoots) {\n    const localSheets =\n      (\n        root as ShadowRoot & {\n          __dathraLocalSheets?: readonly CSSStyleSheet[];\n        }\n      ).__dathraLocalSheets ?? [];\n    root.adoptedStyleSheets = [...localSheets];\n  }\n\n  trackedRoots.clear();\n}\n\nexport {\n  adoptGlobalStyles,\n  clearGlobalStyles,\n  connectGlobalStyles,\n  css,\n  disconnectGlobalStyles,\n  getCssText,\n  getGlobalStyleCssTexts,\n};\nexport type { DathraStyleSheet };\n","/**\n * SSR Web Component Registry.\n *\n * When defineComponent() is called in SSR, it registers the component's\n * setup function, styles, and props schema here. The SSR renderer\n * queries this registry to generate Declarative Shadow DOM output.\n * @module\n */\n\nimport type {\n  PropsSchema,\n  SetupFunction,\n} from \"@/defineComponent/implementation\";\n\ninterface ComponentHydrationMetadata {\n  readonly kind: \"generic-plan\";\n  readonly planFactory?: unknown;\n  readonly unsupportedReason?: string;\n}\n\n/** Registered component metadata for SSR. */\ninterface ComponentRegistration {\n  /** Tag name of the custom element. */\n  readonly tagName: string;\n  /** Setup function that builds DOM content. */\n  readonly setup: SetupFunction;\n  /** Raw CSS text strings for DSD <style> output. */\n  readonly cssTexts: readonly string[];\n  /** Props schema for type coercion in SSR. */\n  readonly propsSchema?: PropsSchema;\n  /** Optional compiler-generated hydration metadata. */\n  readonly hydrationMetadata?: ComponentHydrationMetadata;\n}\n\n/** Global registry: tagName → ComponentRegistration */\nconst registry = new Map<string, ComponentRegistration>();\n\n/**\n * Register a Web Component for SSR rendering.\n * @param tagName - Custom element tag name (must contain a hyphen).\n * @param setup - Setup function that creates the component's DOM content.\n * @param cssTexts - Raw CSS text strings for SSR <style> output.\n * @param propsSchema - Props schema for type coercion.\n */\nfunction registerComponent(\n  tagName: string,\n  setup: SetupFunction,\n  cssTexts: readonly string[],\n  propsSchema?: PropsSchema,\n  hydrationMetadata?: ComponentHydrationMetadata,\n): void {\n  registry.set(tagName, {\n    tagName,\n    setup,\n    cssTexts,\n    propsSchema,\n    hydrationMetadata,\n  });\n}\n\n/**\n * Get a registered component by tag name.\n * @param tagName - Custom element tag name.\n * @returns Component registration or undefined if not registered.\n */\nfunction getComponent(tagName: string): ComponentRegistration | undefined {\n  return registry.get(tagName);\n}\n\n/**\n * Check if a tag name is a registered Web Component.\n * @param tagName - Tag name to check.\n */\nfunction hasComponent(tagName: string): boolean {\n  return registry.has(tagName);\n}\n\n/**\n * Clear the registry (useful for testing).\n */\nfunction clearRegistry(): void {\n  registry.clear();\n}\n\nexport { clearRegistry, getComponent, hasComponent, registerComponent };\nexport type { ComponentHydrationMetadata, ComponentRegistration };\n","/**\n * SSR DSD renderer for Web Components.\n *\n * Provides renderDSD/renderDSDContent for cross-framework SSR,\n * and auto-setup of ComponentRenderer for Dathra SSR.\n * @module\n */\n\nimport { getGlobalStyleCssTexts } from \"@/css/implementation\";\nimport type {\n  ComponentContext,\n  ComponentMetadata,\n  PropDefinition,\n  PropsSchema,\n} from \"@/defineComponent/implementation\";\nimport { getComponent } from \"@/registry/implementation\";\nimport { signal } from \"@dathra/reactivity\";\nimport {\n  createStoreScript,\n  type SerializableValue,\n  setComponentRenderer,\n} from \"@dathra/runtime/ssr\";\nimport { serializeState } from \"@dathra/runtime/ssr\";\nimport type {\n  AtomStore,\n  AtomStoreSnapshot,\n  PrimitiveAtom,\n} from \"@dathra/store\";\nimport { withStore } from \"@dathra/store\";\nimport { getCurrentStore } from \"@dathra/store/internal\";\n\ninterface SSRStoreOptions {\n  store?: AtomStore;\n  storeSnapshotSchema?: AtomStoreSnapshot<\n    Record<string, PrimitiveAtom<unknown>>\n  >;\n}\n\ntype SerializableStoreSnapshot = Record<string, SerializableValue>;\n\nfunction assertStoreSnapshotOptions(options: SSRStoreOptions): void {\n  if (\n    options.storeSnapshotSchema !== undefined &&\n    options.store === undefined\n  ) {\n    throw new Error(\"[dathra] storeSnapshotSchema requires a store\");\n  }\n}\n\n/**\n * Get the default value for a PropDefinition (mirrors CSR getDefaultValue).\n * @internal\n */\nfunction getDefaultValue(def: PropDefinition): unknown {\n  if (def.default !== undefined) return def.default;\n  if (def.type === String) return \"\";\n  if (def.type === Number) return 0;\n  if (def.type === Boolean) return false;\n  return undefined;\n}\n\n/**\n * Coerce an attribute value for SSR context (mirrors CSR coercion logic).\n * @internal\n */\nfunction coerceForSSR(def: PropDefinition, attrValue: string | null): unknown {\n  if (def.type === Boolean) return attrValue !== null;\n  if (def.type === Number) {\n    // Per SPEC ADR-006: null → default value (Number(null) = 0 would hide the real default)\n    if (attrValue === null) return getDefaultValue(def);\n    return Number(attrValue);\n  }\n  if (def.type === String) {\n    // Per SPEC ADR-006: null → default value\n    if (attrValue === null) return getDefaultValue(def);\n    return attrValue;\n  }\n  // Custom coercion function - pass null through as per SPEC\n  if (typeof def.type === \"function\") {\n    return def.type(attrValue);\n  }\n  // Fallback for null with no custom function\n  if (attrValue === null) {\n    return getDefaultValue(def);\n  }\n  return attrValue;\n}\n\n/**\n * Render DSD inner content for a registered component.\n * Returns `<style>` tags + component HTML, or null if not registered.\n * @internal\n */\nfunction renderComponentContent(\n  tagName: string,\n  attrs: Record<string, unknown>,\n  options: SSRStoreOptions = {},\n): string | null {\n  assertStoreSnapshotOptions(options);\n\n  const resolvedStore = options.store ?? getCurrentStore();\n\n  const registration = getComponent(tagName);\n  if (!registration) return null;\n\n  const { propsSchema } = registration;\n\n  // Build ComponentContext from props schema or raw attrs\n  const propSignals: Record<string, ReturnType<typeof signal>> = {};\n  if (propsSchema) {\n    for (const propName of Object.keys(propsSchema)) {\n      const def = propsSchema[propName]!;\n      const attrName =\n        def.attribute === false\n          ? null\n          : typeof def.attribute === \"string\"\n            ? def.attribute\n            : propName;\n      const rawValue =\n        attrName !== null && attrs[attrName] != null\n          ? stringifyAttrValue(attrs[attrName])\n          : null;\n      propSignals[propName] = signal(coerceForSSR(def, rawValue));\n    }\n  }\n  const ctx = {\n    host: {} as HTMLElement,\n    props: propSignals,\n    children: attrs.children,\n    client: {\n      strategy: null,\n      value: null,\n      hydrated: false,\n    },\n    get store() {\n      if (resolvedStore === undefined) {\n        throw new Error(\n          \"[dathra] SSR component context does not provide a store yet\",\n        );\n      }\n      return resolvedStore;\n    },\n  } as ComponentContext<PropsSchema>;\n\n  // Call setup function (in SSR mode, returns HTML string)\n  const result =\n    resolvedStore === undefined\n      ? registration.setup(ctx.host, ctx)\n      : withStore(resolvedStore, () => registration.setup(ctx.host, ctx));\n\n  // In SSR mode, the setup function returns an HTML string\n  const contentHtml = typeof result === \"string\" ? result : \"\";\n\n  // Build DSD content: <style> tags + component HTML\n  let dsdContent = \"\";\n\n  if (\n    options.storeSnapshotSchema !== undefined &&\n    resolvedStore !== undefined\n  ) {\n    const snapshot = options.storeSnapshotSchema.serialize(\n      resolvedStore,\n    ) as SerializableStoreSnapshot;\n    dsdContent += createStoreScript(serializeState(snapshot));\n  }\n\n  const emittedCssTexts = new Set<string>();\n\n  for (const cssText of getGlobalStyleCssTexts()) {\n    if (emittedCssTexts.has(cssText)) continue;\n    emittedCssTexts.add(cssText);\n    dsdContent += `<style>${cssText}</style>`;\n  }\n\n  // Add CSS as <style> tags inside DSD\n  for (const cssText of registration.cssTexts) {\n    if (emittedCssTexts.has(cssText)) continue;\n    emittedCssTexts.add(cssText);\n    dsdContent += `<style>${cssText}</style>`;\n  }\n\n  // Add component content\n  dsdContent += contentHtml;\n\n  return dsdContent;\n}\n\n/**\n * Escape an attribute value for safe HTML output.\n */\nfunction escapeAttr(value: string): string {\n  return value\n    .replace(/&/g, \"&amp;\")\n    .replace(/\"/g, \"&quot;\")\n    .replace(/</g, \"&lt;\")\n    .replace(/>/g, \"&gt;\");\n}\n\nfunction stringifyAttrValue(value: unknown): string {\n  switch (typeof value) {\n    case \"string\":\n      return value;\n    case \"number\":\n    case \"boolean\":\n    case \"bigint\":\n      return String(value);\n    case \"object\":\n      return JSON.stringify(value);\n    case \"symbol\":\n      return value.description ?? \"\";\n    default:\n      return String(value);\n  }\n}\n\n/**\n * Render trusted child markup into host light DOM for SSR slot projection.\n * String children are intentionally treated as HTML, not escaped text.\n */\nfunction renderLightDomChildren(value: unknown): string {\n  if (value === null || value === undefined || typeof value === \"boolean\") {\n    return \"\";\n  }\n\n  if (Array.isArray(value)) {\n    return value.map((item) => renderLightDomChildren(item)).join(\"\");\n  }\n\n  if (typeof value === \"function\") {\n    return renderLightDomChildren((value as () => unknown)());\n  }\n\n  if (\n    typeof value === \"string\" ||\n    typeof value === \"number\" ||\n    typeof value === \"bigint\"\n  ) {\n    return String(value);\n  }\n\n  if (typeof value === \"symbol\") {\n    return value.description ?? \"\";\n  }\n\n  return \"\";\n}\n\n/**\n * Render Declarative Shadow DOM content (inner template only).\n *\n * Returns `<template shadowrootmode=\"open\">...</template>` for a registered component.\n * Useful with `dangerouslySetInnerHTML` in React or similar patterns.\n *\n * @param target - The custom element tag name or component class.\n * @param attrs - Attribute values to pass to the component.\n * @returns The DSD template HTML string.\n * @throws If the component is not registered.\n *\n * @example\n * ```tsx\n * // With component class\n * const Counter = defineComponent('my-counter', ...);\n * const dsd = renderDSDContent(Counter, { initial: '10' });\n * <my-counter initial=\"10\" dangerouslySetInnerHTML={{ __html: dsd }} />\n *\n * // With tag name (legacy)\n * const dsd = renderDSDContent('my-counter', { initial: '10' });\n * ```\n */\nfunction renderDSDContent(\n  target: string | ComponentMetadata,\n  attrs: Record<string, unknown> = {},\n  options: SSRStoreOptions = {},\n): string {\n  const tagName = typeof target === \"string\" ? target : target.__tagName__;\n  const content = renderComponentContent(tagName, attrs, options);\n  if (content == null) {\n    throw new Error(\n      `[dathra] Component \"${tagName}\" is not registered. Call defineComponent() first.`,\n    );\n  }\n  return `<template shadowrootmode=\"open\">${content}</template>`;\n}\n\n/**\n * Render a complete custom element with Declarative Shadow DOM.\n *\n * Returns the full element HTML including the DSD template.\n * Can be directly inserted into any SSR output (React, Vue, etc.).\n *\n * @param target - The custom element tag name or component class.\n * @param attrs - Attribute values to pass to the component.\n * @returns The full custom element HTML with DSD.\n * @throws If the component is not registered.\n *\n * @example\n * ```typescript\n * // With component class (recommended)\n * const Counter = defineComponent('my-counter', ...);\n * const html = renderDSD(Counter, { initial: '10' });\n * // → '<my-counter initial=\"10\"><template shadowrootmode=\"open\">...</template></my-counter>'\n *\n * // With tag name (legacy)\n * const html = renderDSD('my-counter', { initial: '10' });\n * ```\n */\nfunction renderDSD(\n  target: string | ComponentMetadata,\n  attrs: Record<string, unknown> = {},\n  options: SSRStoreOptions = {},\n): string {\n  const tagName = typeof target === \"string\" ? target : target.__tagName__;\n  const dsdTemplate = renderDSDContent(tagName, attrs, options);\n  const childrenHtml = renderLightDomChildren(attrs.children);\n\n  // Build attribute string\n  let attrStr = \"\";\n  for (const [key, value] of Object.entries(attrs)) {\n    if (key === \"children\" && value !== undefined) {\n      let serialized: string;\n      try {\n        const json = JSON.stringify(value);\n        serialized = typeof json === \"string\" ? json : childrenHtml;\n      } catch {\n        serialized = childrenHtml;\n      }\n      attrStr += ` data-dh-children=\"${escapeAttr(serialized)}\"`;\n      continue;\n    }\n\n    if (value === null || value === undefined || value === false) {\n      continue;\n    }\n\n    if (value === true) {\n      attrStr += ` ${key}`;\n      continue;\n    }\n\n    attrStr += ` ${key}=\"${escapeAttr(stringifyAttrValue(value))}\"`;\n  }\n\n  return `<${tagName}${attrStr}>${dsdTemplate}${childrenHtml}</${tagName}>`;\n}\n\n/**\n * Create a component renderer callback for Dathra's renderToString.\n *\n * Uses the component registry to resolve custom element tags\n * and render their content with Declarative Shadow DOM.\n *\n * @internal This is primarily for internal use by Dathra's SSR system.\n * Most users should use `renderDSD` or `renderDSDContent` instead.\n *\n * @returns A function that takes (tagName, attrs) and returns DSD HTML or null.\n */\nfunction createComponentRenderer(): (\n  tagName: string,\n  attrs: Record<string, unknown>,\n) => string | null {\n  return renderComponentContent;\n}\n\n/** Whether the global ComponentRenderer has been initialized. */\nlet _rendererInitialized = false;\n\n/**\n * Ensure the global ComponentRenderer is set up for Dathra SSR.\n * Called automatically by defineComponent in SSR mode.\n * Safe to call multiple times (idempotent).\n * @internal\n */\nfunction ensureComponentRenderer(): void {\n  if (_rendererInitialized) return;\n  _rendererInitialized = true;\n  setComponentRenderer(renderComponentContent);\n}\n\n/**\n * Reset the SSR renderer initialization state.\n * @internal - For testing only.\n */\nfunction _resetRendererState(): void {\n  _rendererInitialized = false;\n  setComponentRenderer(undefined);\n}\n\nexport {\n  _resetRendererState,\n  createComponentRenderer,\n  ensureComponentRenderer,\n  renderDSD,\n  renderDSDContent,\n};\n"],"mappings":"qPAsBA,MAAM,EAAmC,EAAE,CACrC,EAAmB,IAAI,IACvB,EAAoB,IAAI,IACxB,EAAe,IAAI,IAEzB,SAAS,EAAiB,EAA0C,CAClE,GAAI,CACF,IAAM,EAAU,MAAM,KAAK,EAAM,SAAW,GAAS,EAAK,QAAQ,CAAC,KACjE;EACD,CAED,MADA,GAA4B,UAAY,EACjC,OACD,CACN,QAIJ,SAAS,EAAa,EAA8C,CAClE,GAAI,OAAO,GAAU,SACnB,OAAO,EAGT,GAAI,OAAO,cAAkB,IAC3B,MAAO,CAAE,UAAW,EAAO,CAG7B,IAAM,EAAQ,IAAI,cAGlB,OAFA,EAAM,YAAY,EAAM,CACxB,EAA4B,UAAY,EACjC,EAGT,SAAS,EACP,EACoB,CACpB,GAAI,OAAO,GAAU,SAAU,CAC7B,GAAI,OAAO,cAAkB,IAC3B,OAAO,EAAM,MAAM,CAGrB,IAAM,EAAkB,IAAI,cAE5B,OADA,EAAgB,YAAY,EAAM,CAC3B,EAAiB,EAAgB,EAAI,EAAM,MAAM,CAG1D,OAAO,EAAiB,EAAM,EAAI,EAAW,EAAM,EAAE,MAAM,CAG7D,SAAS,EACP,EAAwC,EAAE,CAChB,CAC1B,IAAM,EAA0B,EAAE,CAC5B,EAAO,IAAI,IACX,EAAe,IAAI,IAEnB,EAAa,GAAyB,CAC1C,IAAM,EAAU,EAA0B,EAAM,CAChD,GAAI,IAAY,IAAA,GAAW,CACzB,GAAI,EAAa,IAAI,EAAQ,CAAE,OAC/B,EAAa,IAAI,EAAQ,CAGvB,EAAK,IAAI,EAAM,GACnB,EAAK,IAAI,EAAM,CACf,EAAO,KAAK,EAAM,GAGpB,IAAK,IAAM,KAAS,EAClB,EAAU,EAAM,MAAM,CAGxB,IAAK,IAAM,KAAS,EAClB,EAAU,EAAM,CAGlB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