spell-ui 0.8.5 → 0.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/hot.js CHANGED
@@ -152,11 +152,15 @@ var s = class PackHotSwap {
152
152
  static onScripts(e) {
153
153
  let t = e.detail?.paths ?? [], n = t.map((e) => a.sourceOf(e));
154
154
  t.length && !n.some((e) => !e) && (e.preventDefault(), Promise.all(n.map((e) => a.reload(e, PackHotSwap.swap))).then((e) => {
155
- e.includes("reload") && location.reload();
155
+ e.includes("reload") && PackHotSwap.reload();
156
156
  }, (e) => {
157
- console.error("PackHotSwap: couldn't swap the rebuilt pack in; reloading", e), location.reload();
157
+ console.error("PackHotSwap: couldn't swap the rebuilt pack in; reloading", e), PackHotSwap.reload();
158
158
  }));
159
159
  }
160
+ static reload() {
161
+ let e = globalThis.SPELL_SERVER;
162
+ e?.reload ? e.reload() : location.reload();
163
+ }
160
164
  static isInstalled = !1;
161
165
  }, c = "spell-server:scripts-reloading";
162
166
  //#endregion
package/dist/hot.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"hot.js","names":["E.ElementDefinition","E.ERRORED_STATE","HotDefinitions","UIComponent","tag","dictionary","domElement","sources","key","source","original","SpellSolid","Class","resolved","ElementDefinition","known","defined","Previous","Next","before","after","definition","TagClass","next","reason","Base","DOMElement","previous","added","name","removed","refused","swapped","message","hot","css","stem","id","refs","found","ref","ERRORED_STATE","values","kept","attribute","runtime","task","previousTexts","text","changed","PackHotSwap","SCRIPTS_EVENT","keeps","paths","event","ComponentPacks","path","results","error"],"sources":["../../src/element/HotDefinitions.ts","../src/components/ui-components/PackHotSwap.ts"],"sourcesContent":["/*! Derived from `@solidjs/element` and `component-register`: MIT licence, (c) Ryan Carniato. */\nimport { E } from \"spell/element\"\n\n/****************\n * ### `HotDefinitions`\n * Hot replacement of a set's elements: an edited component re-renders every live element in place,\n * keeping the element objects, their attributes and their property values.\n * - Two users:\n * - `yarn dev`: loaded into every component barrel, before its `define()` calls run,\n * by the kit's Vite plugin (`src/element-tools/HotElements.ts`), which Spell UI's `vite.config.ts` adds\n * - a page that swaps in a REBUILT COMPONENT PACK instead of reloading (epic `epic-engine` I116):\n * Spell UI's `PackHotSwap` installs it as the page's bundle loads, before any pack defines;\n * the pack's `define()` runs again, and only the families whose sources changed are swapped (`keeps`)\n * - Not in the `spell/element` barrel: only the pages and builds that swap pay for it.\n * - SIDE EFFECT:\n * `install()` wraps `UIComponent.define`, and hooks into every DOM element made (`DOMElement.hotReloadHooks`).\n * - Why: `define()` is idempotent per tag, so a barrel re-run by HMR would return the OLD element class.\n * - The wrapper records every tag's class and dictionary.\n * - When a DIFFERENT class of the SAME name defines a known tag (its module was re-evaluated),\n * that class takes over EVERY tag the old one had, the translated aliases (`es-boton`) included.\n * - The platform can't define a tag twice, so each tag's DOM element class STAYS,\n * and what it reads is swapped in place (`redefine()`):\n * its definition, its properties, how it builds its component.\n * - Only when nothing the platform read once at definition changed\n * (observed attributes, DOM API `formAssociated`, the base class, shadow root options);\n * else `update()` reloads the page.\n * - Then the barrel's `import.meta.hot.accept()` calls `update()`,\n * which re-renders every live element of the swapped classes.\n * - Their component-internal state (a query, an open menu) resets; their attributes and properties don't.\n * - Also:\n * - English texts the edit changed reach the page's runtime, Spell UI's `UI.i18n`\n * (`define()` never overwrites a registered text)\n * - `updateStyle()` re-registers a component sheet whose `?inline` CSS changed\n * - NOTE: a vocabulary whose tag was renamed defines the NEW tag; instances of the old one keep the old class.\n * - A changed vocabulary is swapped into the runtime, which re-resolves its translated names from it\n * (Spell UI's `UI.vocabulary.replace()`).\n * - Imports the package through `spell/element`, as a component file does: it's loaded into component barrels,\n * and NOTHING in the package imports it (it's not in the `spell/element` barrel).\n * - STATIC and instance-free on purpose: ONE record of definitions per page, as `customElements` is.\n * - Began as the old `solid-element` package's hot reload, merged into its one user (epic `spell-element`, Q11).\n ****************/\nexport class HotDefinitions {\n /** Wrap `UIComponent.define`, and hook into every DOM element made; idempotent. */\n static install() {\n if (HotDefinitions.original) return\n HotDefinitions.original = E.UIComponent.define\n E.UIComponent.define = function (this: E.UIComponentClass, tag?: string, dictionary?: E.Dictionary) {\n return HotDefinitions.define(this, tag, dictionary)\n }\n E.DOMElement.hotReloadHooks = {\n created: (domElement) => HotDefinitions.track(domElement),\n valueSet: (domElement, key, source) => {\n let sources = HotDefinitions.sources.get(domElement)\n if (!sources) HotDefinitions.sources.set(domElement, (sources = {}))\n sources[key] = source\n }\n }\n }\n\n /** The wrapped `define()`: record, re-define on a new version of a class, else as declared. */\n static define(\n Class: E.UIComponentClass,\n tag?: string,\n dictionary?: E.Dictionary\n ): CustomElementConstructor | undefined {\n const original = HotDefinitions.original!\n // no settings yet: the original waits for them, and runs this again then (`SpellSolid.whenInstalled()`)\n if (!E.SpellSolid.isInstalled) return original.call(Class, tag, dictionary)\n const resolved = new E.ElementDefinition(Class.prototype.vocabulary, { tag, dictionary }).tag\n const known = HotDefinitions.tags.get(resolved)\n if (!known) {\n HotDefinitions.tags.set(resolved, { Class, tag, dictionary })\n return original.call(Class, tag, dictionary)\n }\n const defined = customElements.get(resolved)\n if (!defined || known.Class === Class || known.Class.name !== Class.name)\n return original.call(Class, tag, dictionary)\n // a pack swap keeping this tag's family as it was (its sources didn't change): the live class stays\n if (HotDefinitions.keeps?.(resolved)) return defined\n HotDefinitions.replace(known.Class, Class)\n return defined\n }\n\n /**\n * While a pack is swapped in (`PackHotSwap`): whether a re-run `define()` of tag `tag` KEEPS its live class.\n * - `true`: its family's sources didn't change, so its elements aren't re-rendered\n * - `undefined` (the default, and in `yarn dev`): every new version of a class is swapped in\n */\n static keeps?: (tag: string) => boolean\n\n /** `Next` is a new version of `Previous`: re-define every tag `Previous` had with it (`redefine()`). */\n static replace(Previous: E.UIComponentClass, Next: E.UIComponentClass) {\n HotDefinitions.updateSheets(Previous, Next)\n const before = Previous.prototype.vocabulary\n const after = Next.prototype.vocabulary\n if (before !== after) {\n HotDefinitions.whenRuntime(() => {\n // `register()` refuses a second vocabulary object for a tag:\n // swap the new version in, so the registration below is a no-op and localized names re-resolve\n E.SpellSolid.settings.words.registerVocabulary(after, \"replace\")\n HotDefinitions.updateTexts(before, after)\n })\n }\n for (const known of HotDefinitions.tags.values()) {\n if (known.Class !== Previous) continue\n known.Class = Next\n const definition = new E.ElementDefinition(Next.prototype.vocabulary, known)\n const TagClass = customElements.get(definition.tag) as E.DOMElementClass | undefined\n if (TagClass) HotDefinitions.redefine(TagClass, Next, definition)\n }\n }\n\n /**\n * Swap `TagClass`'s definition, properties and component (`Next`) in place,\n * or record why the platform can't take the change (`update()` then reloads the page).\n * - Each live element's values are carried over (`migrate()`).\n * - NEVER re-renders: `update()` does, once the whole barrel has re-run.\n * - Throws, changing nothing, when a new attribute property would hide a member of the element\n * (as a first definition would).\n */\n static redefine(TagClass: E.DOMElementClass, Next: E.UIComponentClass, definition: E.ElementDefinition) {\n E.UIComponent.register.call(Next, definition)\n const next = E.UIComponent.tagSetupFor(Next, definition)\n const reason = HotDefinitions.changeOf(TagClass, Next.prototype.elementSetup.DOMElement, next)\n if (reason) {\n HotDefinitions.pending.refused.push({ tag: definition.tag, reason })\n return\n }\n // dry run on a stand-in with the same chain: a clash throws BEFORE anything changed\n const Base = Object.getPrototypeOf(TagClass) as E.AnyDOMElementClass\n const Probe = class extends Base {} as unknown as E.DOMElementClass\n Probe.tagSetup = next\n E.DOMElement.defineProperties(Probe)\n const previous = TagClass.tagSetup.elementDefinition\n E.DOMElement.removeProperties(TagClass)\n TagClass.tagSetup = next\n E.DOMElement.defineProperties(TagClass)\n for (const domElement of HotDefinitions.liveElements(TagClass)) {\n HotDefinitions.migrate(domElement, previous, definition)\n }\n HotDefinitions.pending.swapped.add(TagClass)\n }\n\n /**\n * Why `TagClass` can't take `next`, or `undefined` if it can.\n * - All of these are read ONCE,\n * by DOM API `customElements.define()` or by the constructor of elements that already exist.\n */\n static changeOf(TagClass: E.DOMElementClass, Base: E.AnyDOMElementClass, next: E.TagSetup): string | undefined {\n const before = TagClass.observedAttributes\n const after = E.DOMElement.observedAttributesFor(next.elementDefinition)\n const added = after.filter((name) => !before.includes(name))\n const removed = before.filter((name) => !after.includes(name))\n if (added.length || removed.length) {\n const diff = [...added.map((name) => `+${name}`), ...removed.map((name) => `-${name}`)].join(\" \")\n return `observed attributes changed (${diff})`\n }\n if (Object.getPrototypeOf(TagClass) !== Base) return \"DOM element class changed\"\n const formAssociated = !!(TagClass as unknown as { formAssociated?: boolean }).formAssociated\n if (formAssociated !== next.isAFormControl) return \"formAssociated changed\"\n if (JSON.stringify(TagClass.tagSetup.shadowRootInit) !== JSON.stringify(next.shadowRootInit)) {\n return \"shadow root options changed\"\n }\n return undefined\n }\n\n /**\n * Finish a hot update: re-render the live elements of every class swapped since the last call;\n * or, if a re-definition was refused, log it and `hot.invalidate()` (Vite then reloads the page).\n * - The Vite plugin calls it from each barrel's `import.meta.hot.accept()`.\n * - A pack swap calls it with no `hot`: it reloads the page itself on a refusal (`PackHotSwap`).\n */\n static update(hot?: HotContext): HotUpdateResult {\n const refused = HotDefinitions.pending.refused.splice(0)\n const swapped = [...HotDefinitions.pending.swapped]\n HotDefinitions.pending.swapped.clear()\n if (refused.length) {\n const message = refused.map(({ tag, reason }) => `<${tag}>: ${reason}, full reload`).join(\"\\n\")\n E.SpellSolid.settings.warn(\"HotDefinitions\", message)\n hot?.invalidate(message)\n return { reloaded: [], refused }\n }\n for (const TagClass of swapped) {\n for (const domElement of HotDefinitions.liveElements(TagClass)) HotDefinitions.reload(domElement)\n }\n return { reloaded: swapped.map((TagClass) => TagClass.tagSetup.elementDefinition.tag), refused }\n }\n\n /**\n * The style sheets `Next` changed from `Previous`'s, re-registered by name: the elements' shadow roots already\n * adopted them, and the runtime replaces their rules in place (`styles.register()`).\n * - Why: a sheet registers once per name, so a new class's changed text never reached the page (a pack swap)\n */\n private static updateSheets(Previous: E.UIComponentClass, Next: E.UIComponentClass) {\n const before = Previous.prototype.elementSetup.styleSheets ?? {}\n for (const [name, css] of Object.entries(Next.prototype.elementSetup.styleSheets ?? {})) {\n if (before[name] !== css) HotDefinitions.whenRuntime(() => E.SpellSolid.settings.styles.register(name, css))\n }\n }\n\n /**\n * A component sheet's `?inline` CSS changed: re-register it by name (`UIButton.css` => `button`).\n * - The name is the file's, without `UI`, in kebab-case (`UITreeDiagram.css` => `tree-diagram`):\n * elements register their sheets by that bare name (`elementSetup = { styleSheets: { button: buttonCSS } }`).\n * - A second sheet (`UIDimmer.page.css`) or a sheet registered under another name isn't matched:\n * an edit to it shows after a page reload.\n * - The runtime's `styles.register()` replaces the rules of the sheet every shadow root already adopted:\n * no re-render (Spell UI's `Styles.register()`).\n * - Registered even if no element used it yet, so a later `adoptStyleSheets()` finds the new text\n * (Spell UI's `UI.styles.registerOnce()` only registers names that are missing).\n */\n static updateStyle(this: void, id: string, css: string) {\n const stem = /(?:^|\\/)UI([A-Za-z0-9]+)\\.css(?:\\?|$)/.exec(id)?.[1]\n if (!stem) return\n const name = stem.replace(/(?<=.)([A-Z])/g, \"-$1\").toLowerCase()\n HotDefinitions.whenRuntime(() => E.SpellSolid.settings.styles.register(name, css))\n }\n\n ////////////////\n // ## Live elements\n ////////////////\n\n /** Remember `domElement` as a live element of its class; weak, so tracking never keeps an element alive. */\n static track(domElement: E.DOMElement) {\n const TagClass = domElement.constructor as E.DOMElementClass\n let refs = HotDefinitions.live.get(TagClass)\n if (!refs) HotDefinitions.live.set(TagClass, (refs = new Set()))\n refs.add(new WeakRef(domElement))\n }\n\n /** Every element of `TagClass` still in memory, connected or not. */\n static liveElements(TagClass: E.DOMElementClass): E.DOMElement[] {\n const refs = HotDefinitions.live.get(TagClass)\n const found: E.DOMElement[] = []\n for (const ref of refs ?? []) {\n const domElement = ref.deref()\n if (domElement) found.push(domElement)\n else refs!.delete(ref)\n }\n return found\n }\n\n /**\n * Dispose `domElement`'s component and, if connected, build and render its class's CURRENT component.\n * - Kept: the element, its attributes, its property values (`attributeValues`), its shadow root and adopted sheets.\n * - Lost: state inside the component.\n * - Clears DOM API `:state(errored)`, so an element whose render failed recovers with the next good component.\n * - A detached element is only disposed: it renders the current component on its next connect.\n */\n static reload(domElement: E.DOMElement) {\n domElement.dispose()\n domElement.renderRoot.textContent = \"\"\n domElement.setState(E.ERRORED_STATE, false)\n if (domElement.isConnected) domElement.connectedCallback()\n }\n\n /**\n * Carry `domElement`'s values over to the `next` definition.\n * - Last written as a PROPERTY: kept as is (a framework's rich data, a controlled value).\n * - Last written by its ATTRIBUTE: converted again (a vocabulary that learned a value).\n * - Never written: the new starting value.\n * - Attributes the new definition dropped are dropped.\n */\n private static migrate(domElement: E.DOMElement, previous: E.ElementDefinition, next: E.ElementDefinition) {\n const sources = HotDefinitions.sources.get(domElement) ?? {}\n const values = domElement.attributeValues\n const kept: Record<string, unknown> = {}\n for (const attribute of next.attributes) {\n const isKnown = previous.attributes.some(({ key }) => key === attribute.key)\n const source = isKnown ? sources[attribute.key] : undefined\n // shown or hidden: the `hidden` attribute holds it (`DOMElement`, \"Shown or hidden\")\n if (attribute.key === \"visible\" && next.takesShared(\"visible\")) {\n kept[attribute.key] = !domElement.hasAttribute(\"hidden\")\n } else if (source === \"property\") kept[attribute.key] = values[attribute.key]\n else if (source === \"attribute\") {\n kept[attribute.key] = next.convert(attribute, domElement.getAttribute(attribute.attribute))\n } else kept[attribute.key] = next.startingValue(attribute)\n }\n for (const key of Object.keys(values)) delete values[key]\n Object.assign(values, kept)\n }\n\n ////////////////\n // ## Helpers\n ////////////////\n\n /**\n * Run `task` now if the runtime is loaded, else once it is.\n * - Queued behind registrations `define()` already queued, ahead of the ones it queues next (same promise).\n */\n private static whenRuntime(task: () => void) {\n const { runtime } = E.SpellSolid.settings\n if (runtime.isLoaded) task()\n else void runtime.load().then(task)\n }\n\n /**\n * English texts the `next` version of a vocabulary changed, as its new defaults.\n * - Defaults sit below every registered string (Spell UI's `I18n.registerDefaults()`), so a translation still wins.\n */\n private static updateTexts(previous: E.ComponentVocabulary, next: E.ComponentVocabulary) {\n const previousTexts = new Map(previous.texts.map(({ key, text }) => [key, text]))\n const changed: Record<string, string> = {}\n for (const { key, text } of next.texts) if (previousTexts.get(key) !== text) changed[key] = text\n if (Object.keys(changed).length) E.SpellSolid.settings.words.registerTexts(changed, next.tag)\n }\n\n ////////////////\n // ## Page-wide registry\n ////////////////\n\n /** Every tag defined so far, with what defined it; by resolved tag. */\n private static readonly tags = new Map<string, HotTag>()\n\n /** Live elements per tag class. */\n private static readonly live = new WeakMap<E.DOMElementClass, Set<WeakRef<E.DOMElement>>>()\n\n /** Where each element's attribute values last came from, by key: `migrate()` reads it. */\n private static readonly sources = new WeakMap<E.DOMElement, Record<string, E.ValueSource>>()\n\n /** Swaps and refusals since the last `update()`. */\n private static readonly pending = {\n swapped: new Set<E.DOMElementClass>(),\n refused: [] as HotRefusal[]\n }\n\n /** `UIComponent.define` as declared, once `install()` has run. */\n private static original?: typeof E.UIComponent.define\n}\n\n/** What defined one tag: enough to define it again with a new version of the class. */\ntype HotTag = {\n /** Current class. */\n Class: E.UIComponentClass\n /** `define()`'s `tag` argument, as passed. */\n tag?: string\n /** `define()`'s `dictionary` argument. */\n dictionary?: E.Dictionary\n}\n\n/** A re-definition the platform can't take: the tag, and why. */\nexport type HotRefusal = { tag: string; reason: string }\n\n/** `update()`'s result: the tags re-rendered, or the refusals that reloaded the page. */\nexport type HotUpdateResult = { reloaded: string[]; refused: HotRefusal[] }\n\n/** The part of Vite's `import.meta.hot` `update()` uses. */\nexport type HotContext = { invalidate(message?: string): void }\n\nHotDefinitions.install()\n","import { HotDefinitions } from \"spell/element/HotDefinitions\"\n\n// Through the family's barrel, its lib entry: so `hot.js` shares `ComponentPacks` with `ui-components.js`\nimport { ComponentPacks } from \"spell/ui/components/ui-components\"\nimport type { PackSwap } from \"./UIComponents.types\"\n\n/****************\n * ### `PackHotSwap`\n * A page that swaps in a REBUILT component pack instead of reloading (epic `epic-engine` I116; Owen, 2026-10-25,\n * on every epic page reloading at each merge: \"YUCK. Can you do something about that?\").\n * - The page server's live client says which scripts changed, and offers them (`spell-server:scripts-reloading`) before it\n * reloads. When every one is a pack on the page, this takes them: no reload.\n * - Each pack's script runs again (`ComponentPacks.reload()`), and only the families whose sources changed are\n * swapped into the live elements, which re-render in place (the kit's `HotDefinitions`);\n * the rest keep their elements as they are.\n * - A change the platform can't take in place (a new tag, observed attributes ...): ONE page reload, as before.\n * - What a re-rendered element keeps: itself, its attributes and properties, its light DOM;\n * what it loses: state inside its component (an open popover).\n * - `install()` it as the page's bundle loads, BEFORE any pack defines its tags: `HotDefinitions` records each\n * definition as it happens. The docs bundle (spell-epic's `spell-ui.entry.js`) and the site's (`SitePacks.ts`) do.\n * - Its own lib entry, `spell/ui/hot`: only the pages that swap carry `HotDefinitions`.\n * - STATIC: one per page.\n ****************/\nexport class PackHotSwap {\n /** Install it on this page: `HotDefinitions`, and the live client's offer; idempotent. */\n static install() {\n if (PackHotSwap.isInstalled) return\n PackHotSwap.isInstalled = true\n HotDefinitions.install()\n addEventListener(SCRIPTS_EVENT, PackHotSwap.onScripts as EventListener)\n }\n\n /** How `ComponentPacks.reload()` swaps a pack in: `HotDefinitions`' keep predicate, then its update. */\n static readonly swap: PackSwap = {\n keep(keeps) {\n HotDefinitions.keeps = keeps\n },\n finish() {\n return !HotDefinitions.update().refused.length\n }\n }\n\n /**\n * The live client offers the scripts that changed (`spell-server:scripts-reloading`): take them when every one is a pack on\n * the page, and swap each in; else leave them, and the page reloads.\n */\n private static onScripts(event: CustomEvent<{ paths: string[] }>) {\n const paths = event.detail?.paths ?? []\n const sources = paths.map((path) => ComponentPacks.sourceOf(path))\n if (!paths.length || sources.some((source) => !source)) return\n event.preventDefault()\n Promise.all(sources.map((source) => ComponentPacks.reload(source!, PackHotSwap.swap))).then(\n (results) => {\n if (results.includes(\"reload\")) location.reload()\n },\n (error: unknown) => {\n console.error(\"PackHotSwap: couldn't swap the rebuilt pack in; reloading\", error)\n location.reload()\n }\n )\n }\n\n /** `install()` ran. */\n private static isInstalled = false\n}\n\n/** The live client's offer of the scripts that changed, before it reloads (the kit's `liveClient()`). */\nconst SCRIPTS_EVENT = \"spell-server:scripts-reloading\"\n"],"mappings":";;;;AAyCA,IAAaE,IAAb,MAAa,eAAe;CAE1B,OAAO,UAAU;EACf,AAAI,eAAe,aACnB,eAAe,WAAAC,EAAyB,QACxC,EAAc,SAAS,SAAoC,GAAc,GAA2B;GAClG,OAAO,eAAe,OAAO,MAAMC,GAAKC,CAAU;EACpD,GACA,EAAa,iBAAiB;GAC5B,UAAU,MAAe,eAAe,MAAMC,CAAU;GACxD,WAAW,GAAY,GAAK,MAAW;IACrC,IAAIC,IAAU,eAAe,QAAQ,IAAID,CAAU;IAEnD,AADKC,KAAS,eAAe,QAAQ,IAAID,GAAa,IAAU,CAAC,CAAE,GACnE,EAAQE,KAAOC;GACjB;EACF;CACF;CAGA,OAAO,OACL,GACA,GACA,GACsC;EACtC,IAAMC,IAAW,eAAe;EAEhC,IAAI,CAAAC,EAAc,aAAa,OAAOD,EAAS,KAAKE,GAAOR,GAAKC,CAAU;EAC1E,IAAMQ,IAAW,IAAIb,EAAoBY,EAAM,UAAU,YAAY;GAAE;GAAK;EAAW,CAAC,CAAC,CAAC,KACpFG,IAAQ,eAAe,KAAK,IAAIF,CAAQ;EAC9C,IAAI,CAACE,GAEH,OADA,eAAe,KAAK,IAAIF,GAAU;GAAE;GAAO;GAAK;EAAW,CAAC,GACrDH,EAAS,KAAKE,GAAOR,GAAKC,CAAU;EAE7C,IAAMW,IAAU,eAAe,IAAIH,CAAQ;EAM3C,OALI,CAACG,KAAWD,EAAM,UAAUH,KAASG,EAAM,MAAM,SAASH,EAAM,OAC3DF,EAAS,KAAKE,GAAOR,GAAKC,CAAU,KAEzC,eAAe,QAAQQ,CAAQ,KACnC,eAAe,QAAQE,EAAM,OAAOH,CAAK,GADII;CAG/C;CAOA,OAAO;CAGP,OAAO,QAAQ,GAA8B,GAA0B;EACrE,eAAe,aAAaC,GAAUC,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EACpC,SAAS,CAAC;CACZ;CAGA,OAAe;AACjB;AAqBArB,EAAe,QAAQ;;;ACtUvB,IAAagD,IAAb,MAAa,YAAY;CAEvB,OAAO,UAAU;EACf,AAAI,YAAY,gBAChB,YAAY,cAAc,IAC1BhD,EAAe,QAAQ,GACvB,iBAAiBiD,GAAe,YAAY,SAA0B;CACxE;CAGA,OAAgB,OAAiB;EAC/B,KAAK,GAAO;GACV,EAAe,QAAQC;EACzB;EACA,SAAS;GACP,OAAO,CAAClD,EAAe,OAAO,CAAC,CAAC,QAAQ;EAC1C;CACF;CAMA,OAAe,UAAU,GAAyC;EAChE,IAAMmD,IAAQC,EAAM,QAAQ,SAAS,CAAC,GAChC/C,IAAU8C,EAAM,KAAK,MAASE,EAAe,SAASC,CAAI,CAAC;EACjE,AAAKH,EAAM,UAAU,GAAQ,MAAM,MAAW,CAAC5C,CAAM,MACrD6C,EAAM,eAAe,GACrB,QAAQ,IAAI/C,EAAQ,KAAK,MAAWgD,EAAe,OAAO9C,GAAS,YAAY,IAAI,CAAC,CAAC,CAAC,CAAC,MACpF,MAAY;GACX,AAAIgD,EAAQ,SAAS,QAAQ,KAAG,SAAS,OAAO;EAClD,IACC,MAAmB;GAElB,AADA,QAAQ,MAAM,+DAA+DC,CAAK,GAClF,SAAS,OAAO;EAClB,CACF;CACF;CAGA,OAAe,cAAc;AAC/B,GAGMP,IAAgB"}
1
+ {"version":3,"file":"hot.js","names":["E.ElementDefinition","E.ERRORED_STATE","HotDefinitions","UIComponent","tag","dictionary","domElement","sources","key","source","original","SpellSolid","Class","resolved","ElementDefinition","known","defined","Previous","Next","before","after","definition","TagClass","next","reason","Base","DOMElement","previous","added","name","removed","refused","swapped","message","hot","css","stem","id","refs","found","ref","ERRORED_STATE","values","kept","attribute","runtime","task","previousTexts","text","changed","PackHotSwap","SCRIPTS_EVENT","keeps","paths","event","ComponentPacks","path","results","error","server"],"sources":["../../src/element/HotDefinitions.ts","../src/components/ui-components/PackHotSwap.ts"],"sourcesContent":["/*! Derived from `@solidjs/element` and `component-register`: MIT licence, (c) Ryan Carniato. */\nimport { E } from \"spell/element\"\n\n/****************\n * ### `HotDefinitions`\n * Hot replacement of a set's elements: an edited component re-renders every live element in place,\n * keeping the element objects, their attributes and their property values.\n * - Two users:\n * - `yarn dev`: loaded into every component barrel, before its `define()` calls run,\n * by the kit's Vite plugin (`src/element-tools/HotElements.ts`), which Spell UI's `vite.config.ts` adds\n * - a page that swaps in a REBUILT COMPONENT PACK instead of reloading (epic `epic-engine` I116):\n * Spell UI's `PackHotSwap` installs it as the page's bundle loads, before any pack defines;\n * the pack's `define()` runs again, and only the families whose sources changed are swapped (`keeps`)\n * - Not in the `spell/element` barrel: only the pages and builds that swap pay for it.\n * - SIDE EFFECT:\n * `install()` wraps `UIComponent.define`, and hooks into every DOM element made (`DOMElement.hotReloadHooks`).\n * - Why: `define()` is idempotent per tag, so a barrel re-run by HMR would return the OLD element class.\n * - The wrapper records every tag's class and dictionary.\n * - When a DIFFERENT class of the SAME name defines a known tag (its module was re-evaluated),\n * that class takes over EVERY tag the old one had, the translated aliases (`es-boton`) included.\n * - The platform can't define a tag twice, so each tag's DOM element class STAYS,\n * and what it reads is swapped in place (`redefine()`):\n * its definition, its properties, how it builds its component.\n * - Only when nothing the platform read once at definition changed\n * (observed attributes, DOM API `formAssociated`, the base class, shadow root options);\n * else `update()` reloads the page.\n * - Then the barrel's `import.meta.hot.accept()` calls `update()`,\n * which re-renders every live element of the swapped classes.\n * - Their component-internal state (a query, an open menu) resets; their attributes and properties don't.\n * - Also:\n * - English texts the edit changed reach the page's runtime, Spell UI's `UI.i18n`\n * (`define()` never overwrites a registered text)\n * - `updateStyle()` re-registers a component sheet whose `?inline` CSS changed\n * - NOTE: a vocabulary whose tag was renamed defines the NEW tag; instances of the old one keep the old class.\n * - A changed vocabulary is swapped into the runtime, which re-resolves its translated names from it\n * (Spell UI's `UI.vocabulary.replace()`).\n * - Imports the package through `spell/element`, as a component file does: it's loaded into component barrels,\n * and NOTHING in the package imports it (it's not in the `spell/element` barrel).\n * - STATIC and instance-free on purpose: ONE record of definitions per page, as `customElements` is.\n * - Began as the old `solid-element` package's hot reload, merged into its one user (epic `spell-element`, Q11).\n ****************/\nexport class HotDefinitions {\n /** Wrap `UIComponent.define`, and hook into every DOM element made; idempotent. */\n static install() {\n if (HotDefinitions.original) return\n HotDefinitions.original = E.UIComponent.define\n E.UIComponent.define = function (this: E.UIComponentClass, tag?: string, dictionary?: E.Dictionary) {\n return HotDefinitions.define(this, tag, dictionary)\n }\n E.DOMElement.hotReloadHooks = {\n created: (domElement) => HotDefinitions.track(domElement),\n valueSet: (domElement, key, source) => {\n let sources = HotDefinitions.sources.get(domElement)\n if (!sources) HotDefinitions.sources.set(domElement, (sources = {}))\n sources[key] = source\n }\n }\n }\n\n /** The wrapped `define()`: record, re-define on a new version of a class, else as declared. */\n static define(\n Class: E.UIComponentClass,\n tag?: string,\n dictionary?: E.Dictionary\n ): CustomElementConstructor | undefined {\n const original = HotDefinitions.original!\n // no settings yet: the original waits for them, and runs this again then (`SpellSolid.whenInstalled()`)\n if (!E.SpellSolid.isInstalled) return original.call(Class, tag, dictionary)\n const resolved = new E.ElementDefinition(Class.prototype.vocabulary, { tag, dictionary }).tag\n const known = HotDefinitions.tags.get(resolved)\n if (!known) {\n HotDefinitions.tags.set(resolved, { Class, tag, dictionary })\n return original.call(Class, tag, dictionary)\n }\n const defined = customElements.get(resolved)\n if (!defined || known.Class === Class || known.Class.name !== Class.name)\n return original.call(Class, tag, dictionary)\n // a pack swap keeping this tag's family as it was (its sources didn't change): the live class stays\n if (HotDefinitions.keeps?.(resolved)) return defined\n HotDefinitions.replace(known.Class, Class)\n return defined\n }\n\n /**\n * While a pack is swapped in (`PackHotSwap`): whether a re-run `define()` of tag `tag` KEEPS its live class.\n * - `true`: its family's sources didn't change, so its elements aren't re-rendered\n * - `undefined` (the default, and in `yarn dev`): every new version of a class is swapped in\n */\n static keeps?: (tag: string) => boolean\n\n /** `Next` is a new version of `Previous`: re-define every tag `Previous` had with it (`redefine()`). */\n static replace(Previous: E.UIComponentClass, Next: E.UIComponentClass) {\n HotDefinitions.updateSheets(Previous, Next)\n const before = Previous.prototype.vocabulary\n const after = Next.prototype.vocabulary\n if (before !== after) {\n HotDefinitions.whenRuntime(() => {\n // `register()` refuses a second vocabulary object for a tag:\n // swap the new version in, so the registration below is a no-op and localized names re-resolve\n E.SpellSolid.settings.words.registerVocabulary(after, \"replace\")\n HotDefinitions.updateTexts(before, after)\n })\n }\n for (const known of HotDefinitions.tags.values()) {\n if (known.Class !== Previous) continue\n known.Class = Next\n const definition = new E.ElementDefinition(Next.prototype.vocabulary, known)\n const TagClass = customElements.get(definition.tag) as E.DOMElementClass | undefined\n if (TagClass) HotDefinitions.redefine(TagClass, Next, definition)\n }\n }\n\n /**\n * Swap `TagClass`'s definition, properties and component (`Next`) in place,\n * or record why the platform can't take the change (`update()` then reloads the page).\n * - Each live element's values are carried over (`migrate()`).\n * - NEVER re-renders: `update()` does, once the whole barrel has re-run.\n * - Throws, changing nothing, when a new attribute property would hide a member of the element\n * (as a first definition would).\n */\n static redefine(TagClass: E.DOMElementClass, Next: E.UIComponentClass, definition: E.ElementDefinition) {\n E.UIComponent.register.call(Next, definition)\n const next = E.UIComponent.tagSetupFor(Next, definition)\n const reason = HotDefinitions.changeOf(TagClass, Next.prototype.elementSetup.DOMElement, next)\n if (reason) {\n HotDefinitions.pending.refused.push({ tag: definition.tag, reason })\n return\n }\n // dry run on a stand-in with the same chain: a clash throws BEFORE anything changed\n const Base = Object.getPrototypeOf(TagClass) as E.AnyDOMElementClass\n const Probe = class extends Base {} as unknown as E.DOMElementClass\n Probe.tagSetup = next\n E.DOMElement.defineProperties(Probe)\n const previous = TagClass.tagSetup.elementDefinition\n E.DOMElement.removeProperties(TagClass)\n TagClass.tagSetup = next\n E.DOMElement.defineProperties(TagClass)\n for (const domElement of HotDefinitions.liveElements(TagClass)) {\n HotDefinitions.migrate(domElement, previous, definition)\n }\n HotDefinitions.pending.swapped.add(TagClass)\n }\n\n /**\n * Why `TagClass` can't take `next`, or `undefined` if it can.\n * - All of these are read ONCE,\n * by DOM API `customElements.define()` or by the constructor of elements that already exist.\n */\n static changeOf(TagClass: E.DOMElementClass, Base: E.AnyDOMElementClass, next: E.TagSetup): string | undefined {\n const before = TagClass.observedAttributes\n const after = E.DOMElement.observedAttributesFor(next.elementDefinition)\n const added = after.filter((name) => !before.includes(name))\n const removed = before.filter((name) => !after.includes(name))\n if (added.length || removed.length) {\n const diff = [...added.map((name) => `+${name}`), ...removed.map((name) => `-${name}`)].join(\" \")\n return `observed attributes changed (${diff})`\n }\n if (Object.getPrototypeOf(TagClass) !== Base) return \"DOM element class changed\"\n const formAssociated = !!(TagClass as unknown as { formAssociated?: boolean }).formAssociated\n if (formAssociated !== next.isAFormControl) return \"formAssociated changed\"\n if (JSON.stringify(TagClass.tagSetup.shadowRootInit) !== JSON.stringify(next.shadowRootInit)) {\n return \"shadow root options changed\"\n }\n return undefined\n }\n\n /**\n * Finish a hot update: re-render the live elements of every class swapped since the last call;\n * or, if a re-definition was refused, log it and `hot.invalidate()` (Vite then reloads the page).\n * - The Vite plugin calls it from each barrel's `import.meta.hot.accept()`.\n * - A pack swap calls it with no `hot`: it reloads the page itself on a refusal (`PackHotSwap`).\n */\n static update(hot?: HotContext): HotUpdateResult {\n const refused = HotDefinitions.pending.refused.splice(0)\n const swapped = [...HotDefinitions.pending.swapped]\n HotDefinitions.pending.swapped.clear()\n if (refused.length) {\n const message = refused.map(({ tag, reason }) => `<${tag}>: ${reason}, full reload`).join(\"\\n\")\n E.SpellSolid.settings.warn(\"HotDefinitions\", message)\n hot?.invalidate(message)\n return { reloaded: [], refused }\n }\n for (const TagClass of swapped) {\n for (const domElement of HotDefinitions.liveElements(TagClass)) HotDefinitions.reload(domElement)\n }\n return { reloaded: swapped.map((TagClass) => TagClass.tagSetup.elementDefinition.tag), refused }\n }\n\n /**\n * The style sheets `Next` changed from `Previous`'s, re-registered by name: the elements' shadow roots already\n * adopted them, and the runtime replaces their rules in place (`styles.register()`).\n * - Why: a sheet registers once per name, so a new class's changed text never reached the page (a pack swap)\n */\n private static updateSheets(Previous: E.UIComponentClass, Next: E.UIComponentClass) {\n const before = Previous.prototype.elementSetup.styleSheets ?? {}\n for (const [name, css] of Object.entries(Next.prototype.elementSetup.styleSheets ?? {})) {\n if (before[name] !== css) HotDefinitions.whenRuntime(() => E.SpellSolid.settings.styles.register(name, css))\n }\n }\n\n /**\n * A component sheet's `?inline` CSS changed: re-register it by name (`UIButton.css` => `button`).\n * - The name is the file's, without `UI`, in kebab-case (`UITreeDiagram.css` => `tree-diagram`):\n * elements register their sheets by that bare name (`elementSetup = { styleSheets: { button: buttonCSS } }`).\n * - A second sheet (`UIDimmer.page.css`) or a sheet registered under another name isn't matched:\n * an edit to it shows after a page reload.\n * - The runtime's `styles.register()` replaces the rules of the sheet every shadow root already adopted:\n * no re-render (Spell UI's `Styles.register()`).\n * - Registered even if no element used it yet, so a later `adoptStyleSheets()` finds the new text\n * (Spell UI's `UI.styles.registerOnce()` only registers names that are missing).\n */\n static updateStyle(this: void, id: string, css: string) {\n const stem = /(?:^|\\/)UI([A-Za-z0-9]+)\\.css(?:\\?|$)/.exec(id)?.[1]\n if (!stem) return\n const name = stem.replace(/(?<=.)([A-Z])/g, \"-$1\").toLowerCase()\n HotDefinitions.whenRuntime(() => E.SpellSolid.settings.styles.register(name, css))\n }\n\n ////////////////\n // ## Live elements\n ////////////////\n\n /** Remember `domElement` as a live element of its class; weak, so tracking never keeps an element alive. */\n static track(domElement: E.DOMElement) {\n const TagClass = domElement.constructor as E.DOMElementClass\n let refs = HotDefinitions.live.get(TagClass)\n if (!refs) HotDefinitions.live.set(TagClass, (refs = new Set()))\n refs.add(new WeakRef(domElement))\n }\n\n /** Every element of `TagClass` still in memory, connected or not. */\n static liveElements(TagClass: E.DOMElementClass): E.DOMElement[] {\n const refs = HotDefinitions.live.get(TagClass)\n const found: E.DOMElement[] = []\n for (const ref of refs ?? []) {\n const domElement = ref.deref()\n if (domElement) found.push(domElement)\n else refs!.delete(ref)\n }\n return found\n }\n\n /**\n * Dispose `domElement`'s component and, if connected, build and render its class's CURRENT component.\n * - Kept: the element, its attributes, its property values (`attributeValues`), its shadow root and adopted sheets.\n * - Lost: state inside the component.\n * - Clears DOM API `:state(errored)`, so an element whose render failed recovers with the next good component.\n * - A detached element is only disposed: it renders the current component on its next connect.\n */\n static reload(domElement: E.DOMElement) {\n domElement.dispose()\n domElement.renderRoot.textContent = \"\"\n domElement.setState(E.ERRORED_STATE, false)\n if (domElement.isConnected) domElement.connectedCallback()\n }\n\n /**\n * Carry `domElement`'s values over to the `next` definition.\n * - Last written as a PROPERTY: kept as is (a framework's rich data, a controlled value).\n * - Last written by its ATTRIBUTE: converted again (a vocabulary that learned a value).\n * - Never written: the new starting value.\n * - Attributes the new definition dropped are dropped.\n */\n private static migrate(domElement: E.DOMElement, previous: E.ElementDefinition, next: E.ElementDefinition) {\n const sources = HotDefinitions.sources.get(domElement) ?? {}\n const values = domElement.attributeValues\n const kept: Record<string, unknown> = {}\n for (const attribute of next.attributes) {\n const isKnown = previous.attributes.some(({ key }) => key === attribute.key)\n const source = isKnown ? sources[attribute.key] : undefined\n // shown or hidden: the `hidden` attribute holds it (`DOMElement`, \"Shown or hidden\")\n if (attribute.key === \"visible\" && next.takesShared(\"visible\")) {\n kept[attribute.key] = !domElement.hasAttribute(\"hidden\")\n } else if (source === \"property\") kept[attribute.key] = values[attribute.key]\n else if (source === \"attribute\") {\n kept[attribute.key] = next.convert(attribute, domElement.getAttribute(attribute.attribute))\n } else kept[attribute.key] = next.startingValue(attribute)\n }\n for (const key of Object.keys(values)) delete values[key]\n Object.assign(values, kept)\n }\n\n ////////////////\n // ## Helpers\n ////////////////\n\n /**\n * Run `task` now if the runtime is loaded, else once it is.\n * - Queued behind registrations `define()` already queued, ahead of the ones it queues next (same promise).\n */\n private static whenRuntime(task: () => void) {\n const { runtime } = E.SpellSolid.settings\n if (runtime.isLoaded) task()\n else void runtime.load().then(task)\n }\n\n /**\n * English texts the `next` version of a vocabulary changed, as its new defaults.\n * - Defaults sit below every registered string (Spell UI's `I18n.registerDefaults()`), so a translation still wins.\n */\n private static updateTexts(previous: E.ComponentVocabulary, next: E.ComponentVocabulary) {\n const previousTexts = new Map(previous.texts.map(({ key, text }) => [key, text]))\n const changed: Record<string, string> = {}\n for (const { key, text } of next.texts) if (previousTexts.get(key) !== text) changed[key] = text\n if (Object.keys(changed).length) E.SpellSolid.settings.words.registerTexts(changed, next.tag)\n }\n\n ////////////////\n // ## Page-wide registry\n ////////////////\n\n /** Every tag defined so far, with what defined it; by resolved tag. */\n private static readonly tags = new Map<string, HotTag>()\n\n /** Live elements per tag class. */\n private static readonly live = new WeakMap<E.DOMElementClass, Set<WeakRef<E.DOMElement>>>()\n\n /** Where each element's attribute values last came from, by key: `migrate()` reads it. */\n private static readonly sources = new WeakMap<E.DOMElement, Record<string, E.ValueSource>>()\n\n /** Swaps and refusals since the last `update()`. */\n private static readonly pending = {\n swapped: new Set<E.DOMElementClass>(),\n refused: [] as HotRefusal[]\n }\n\n /** `UIComponent.define` as declared, once `install()` has run. */\n private static original?: typeof E.UIComponent.define\n}\n\n/** What defined one tag: enough to define it again with a new version of the class. */\ntype HotTag = {\n /** Current class. */\n Class: E.UIComponentClass\n /** `define()`'s `tag` argument, as passed. */\n tag?: string\n /** `define()`'s `dictionary` argument. */\n dictionary?: E.Dictionary\n}\n\n/** A re-definition the platform can't take: the tag, and why. */\nexport type HotRefusal = { tag: string; reason: string }\n\n/** `update()`'s result: the tags re-rendered, or the refusals that reloaded the page. */\nexport type HotUpdateResult = { reloaded: string[]; refused: HotRefusal[] }\n\n/** The part of Vite's `import.meta.hot` `update()` uses. */\nexport type HotContext = { invalidate(message?: string): void }\n\nHotDefinitions.install()\n","import { HotDefinitions } from \"spell/element/HotDefinitions\"\n\n// Through the family's barrel, its lib entry: so `hot.js` shares `ComponentPacks` with `ui-components.js`\nimport { ComponentPacks } from \"spell/ui/components/ui-components\"\nimport type { PackSwap } from \"./UIComponents.types\"\n\n/****************\n * ### `PackHotSwap`\n * A page that swaps in a REBUILT component pack instead of reloading (epic `epic-engine` I116; Owen, 2026-10-25,\n * on every epic page reloading at each merge: \"YUCK. Can you do something about that?\").\n * - The page server's live client says which scripts changed, and offers them (`spell-server:scripts-reloading`) before it\n * reloads. When every one is a pack on the page, this takes them: no reload.\n * - Each pack's script runs again (`ComponentPacks.reload()`), and only the families whose sources changed are\n * swapped into the live elements, which re-render in place (the kit's `HotDefinitions`);\n * the rest keep their elements as they are.\n * - A change the platform can't take in place (a new tag, observed attributes ...): ONE page reload, as before.\n * - What a re-rendered element keeps: itself, its attributes and properties, its light DOM;\n * what it loses: state inside its component (an open popover).\n * - `install()` it as the page's bundle loads, BEFORE any pack defines its tags: `HotDefinitions` records each\n * definition as it happens. The docs bundle (spell-epic's `spell-ui.entry.js`) and the site's (`SitePacks.ts`) do.\n * - Its own lib entry, `spell/ui/hot`: only the pages that swap carry `HotDefinitions`.\n * - STATIC: one per page.\n ****************/\nexport class PackHotSwap {\n /** Install it on this page: `HotDefinitions`, and the live client's offer; idempotent. */\n static install() {\n if (PackHotSwap.isInstalled) return\n PackHotSwap.isInstalled = true\n HotDefinitions.install()\n addEventListener(SCRIPTS_EVENT, PackHotSwap.onScripts as EventListener)\n }\n\n /** How `ComponentPacks.reload()` swaps a pack in: `HotDefinitions`' keep predicate, then its update. */\n static readonly swap: PackSwap = {\n keep(keeps) {\n HotDefinitions.keeps = keeps\n },\n finish() {\n return !HotDefinitions.update().refused.length\n }\n }\n\n /**\n * The live client offers the scripts that changed (`spell-server:scripts-reloading`): take them when every one is a pack on\n * the page, and swap each in; else leave them, and the page reloads.\n */\n private static onScripts(event: CustomEvent<{ paths: string[] }>) {\n const paths = event.detail?.paths ?? []\n const sources = paths.map((path) => ComponentPacks.sourceOf(path))\n if (!paths.length || sources.some((source) => !source)) return\n event.preventDefault()\n Promise.all(sources.map((source) => ComponentPacks.reload(source!, PackHotSwap.swap))).then(\n (results) => {\n if (results.includes(\"reload\")) PackHotSwap.reload()\n },\n (error: unknown) => {\n console.error(\"PackHotSwap: couldn't swap the rebuilt pack in; reloading\", error)\n PackHotSwap.reload()\n }\n )\n }\n\n /**\n * Reload the page: through the live client when it's there (`SPELL_SERVER.reload()`), which keeps the scroll and\n * holds the new page behind the old one until it's ready (epic `epic-engine` I164); else a plain reload.\n * - measured before: `location.reload()` here lost the scroll and the item open, through ~150ms of bare background\n */\n private static reload() {\n const server = (globalThis as { SPELL_SERVER?: { reload?: () => void } }).SPELL_SERVER\n if (server?.reload) server.reload()\n else location.reload()\n }\n\n /** `install()` ran. */\n private static isInstalled = false\n}\n\n/** The live client's offer of the scripts that changed, before it reloads (the kit's `liveClient()`). */\nconst SCRIPTS_EVENT = \"spell-server:scripts-reloading\"\n"],"mappings":";;;;AAyCA,IAAaE,IAAb,MAAa,eAAe;CAE1B,OAAO,UAAU;EACf,AAAI,eAAe,aACnB,eAAe,WAAAC,EAAyB,QACxC,EAAc,SAAS,SAAoC,GAAc,GAA2B;GAClG,OAAO,eAAe,OAAO,MAAMC,GAAKC,CAAU;EACpD,GACA,EAAa,iBAAiB;GAC5B,UAAU,MAAe,eAAe,MAAMC,CAAU;GACxD,WAAW,GAAY,GAAK,MAAW;IACrC,IAAIC,IAAU,eAAe,QAAQ,IAAID,CAAU;IAEnD,AADKC,KAAS,eAAe,QAAQ,IAAID,GAAa,IAAU,CAAC,CAAE,GACnE,EAAQE,KAAOC;GACjB;EACF;CACF;CAGA,OAAO,OACL,GACA,GACA,GACsC;EACtC,IAAMC,IAAW,eAAe;EAEhC,IAAI,CAAAC,EAAc,aAAa,OAAOD,EAAS,KAAKE,GAAOR,GAAKC,CAAU;EAC1E,IAAMQ,IAAW,IAAIb,EAAoBY,EAAM,UAAU,YAAY;GAAE;GAAK;EAAW,CAAC,CAAC,CAAC,KACpFG,IAAQ,eAAe,KA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