@hypen-space/web 0.2.4 → 0.2.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/src/dom/renderer.js +12 -4
- package/dist/src/dom/renderer.js.map +3 -3
- package/package.json +22 -22
- package/src/dom/renderer.ts +18 -3
package/dist/src/dom/renderer.js
CHANGED
|
@@ -187,9 +187,17 @@ class DOMRenderer {
|
|
|
187
187
|
console.log(`[Renderer] Updated input value: "${value}"`);
|
|
188
188
|
return;
|
|
189
189
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
const nextText = String(value);
|
|
191
|
+
element.textContent = nextText;
|
|
192
|
+
const currentTemplate = element.dataset.textTemplate;
|
|
193
|
+
const nextLooksLikeTemplate = nextText.includes("${");
|
|
194
|
+
const currentLooksLikeTemplate = typeof currentTemplate === "string" && currentTemplate.includes("${");
|
|
195
|
+
if (nextLooksLikeTemplate) {
|
|
196
|
+
element.dataset.textTemplate = nextText;
|
|
197
|
+
} else if (currentTemplate === undefined) {
|
|
198
|
+
element.dataset.textTemplate = nextText;
|
|
199
|
+
} else if (!currentLooksLikeTemplate) {
|
|
200
|
+
element.dataset.textTemplate = nextText;
|
|
193
201
|
}
|
|
194
202
|
console.log(`[Renderer] Updated text content: "${value}"`);
|
|
195
203
|
return;
|
|
@@ -274,4 +282,4 @@ export {
|
|
|
274
282
|
|
|
275
283
|
export { DOMRenderer };
|
|
276
284
|
|
|
277
|
-
//# debugId=
|
|
285
|
+
//# debugId=4035E3738262CFE264756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/dom/renderer.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * DOM Renderer\n *\n * Renders Hypen patches to the DOM\n */\n\nimport type { Patch } from \"@hypen/core\";\nimport type { HypenModuleInstance, RouterContext } from \"@hypen/core\";\nimport type { HypenRouter } from \"@hypen/core\";\nimport type { HypenGlobalContext } from \"@hypen/core\";\nimport { ComponentRegistry } from \"./components/index.js\";\nimport { ApplicatorRegistry } from \"./applicators/index.js\";\nimport { canvasHandler, canvasApplicators } from \"./canvas/index.js\";\nimport { RerenderTracker, type DebugConfig, defaultDebugConfig } from \"./debug.js\";\n\n// Interface for the engine that renderer needs\ninterface IEngine {\n dispatchAction(name: string, payload?: any): void;\n}\n\nexport class DOMRenderer {\n private container: HTMLElement;\n private nodes: Map<string, HTMLElement> = new Map();\n private rootId: string | null = null;\n private components: ComponentRegistry;\n private applicators: ApplicatorRegistry;\n private engine: IEngine;\n private currentState: Record<string, any> = {};\n private routerContext: RouterContext | null = null;\n private globalContext: HypenGlobalContext | null = null;\n private componentInstances = new Map<string, HypenModuleInstance>();\n private debugTracker: RerenderTracker;\n\n constructor(container: HTMLElement, engine: IEngine, debugConfig?: Partial<DebugConfig>) {\n this.container = container;\n this.engine = engine;\n this.components = new ComponentRegistry();\n this.applicators = new ApplicatorRegistry();\n this.debugTracker = new RerenderTracker({ ...defaultDebugConfig, ...debugConfig });\n\n // Register canvas component and applicators\n this.components.register(\"canvas\", canvasHandler);\n for (const [name, handler] of Object.entries(canvasApplicators)) {\n this.applicators.register(name, handler);\n }\n }\n\n /**\n * Set router and global context for component composition\n */\n setContext(routerContext: RouterContext, globalContext: HypenGlobalContext): void {\n this.routerContext = routerContext;\n this.globalContext = globalContext;\n }\n\n /**\n * Apply a batch of patches to the DOM\n */\n applyPatches(patches: Patch[]): void {\n for (const patch of patches) {\n this.applyPatch(patch);\n }\n }\n\n /**\n * Update state and interpolate text content\n */\n updateState(state: Record<string, any>): void {\n console.log(`[Renderer] Updating state:`, state);\n this.currentState = state;\n this.interpolateAllText();\n }\n\n /**\n * Merge component state into current state and re-interpolate\n */\n private mergeComponentState(componentState: Record<string, any>): void {\n this.currentState = { ...this.currentState, ...componentState };\n console.log(`[Renderer] Merged state:`, this.currentState);\n this.interpolateAllText();\n }\n\n /**\n * Interpolate state values in all text elements\n */\n private interpolateAllText(): void {\n for (const [id, element] of this.nodes.entries()) {\n if (element.dataset.hypenType === \"text\" && element.dataset.textTemplate) {\n const template = element.dataset.textTemplate;\n const interpolated = this.interpolateText(template, this.currentState);\n\n // Track re-render if text actually changed\n const currentText = element.textContent;\n if (currentText !== interpolated) {\n this.debugTracker.trackRerender(id, element, \"interpolate\");\n }\n\n element.textContent = interpolated;\n }\n }\n }\n\n /**\n * Interpolate state values in text template\n */\n private interpolateText(template: string, state: Record<string, any>): string {\n return template.replace(/\\$\\{([^}]+)\\}/g, (match, path) => {\n try {\n const value = path.split('.').reduce((obj: any, key: string) => {\n if (key === 'state') return state;\n return obj?.[key];\n }, state);\n return value !== undefined ? String(value) : match;\n } catch {\n return match;\n }\n });\n }\n\n /**\n * Apply a single patch\n */\n private applyPatch(patch: Patch): void {\n switch (patch.type) {\n case \"create\":\n this.onCreate(patch.id!, (patch as any).element_type!, patch.props || {});\n break;\n case \"setProp\":\n this.onSetProp(patch.id!, patch.name!, patch.value);\n break;\n case \"setText\":\n this.onSetText(patch.id!, patch.text!);\n break;\n case \"insert\":\n this.onInsert((patch as any).parent_id!, patch.id!, (patch as any).before_id);\n break;\n case \"move\":\n this.onMove((patch as any).parent_id!, patch.id!, (patch as any).before_id);\n break;\n case \"remove\":\n this.onRemove(patch.id!);\n break;\n }\n }\n\n /**\n * Create a new element\n */\n private onCreate(id: string, elementType: string, props: Record<string, any> | Map<string, any>): void {\n const propsObj = props instanceof Map ? Object.fromEntries(props) : props;\n\n const element = this.components.createElement(elementType, propsObj);\n\n if (!element) {\n const fallback = document.createElement(\"div\");\n fallback.dataset.hypenType = elementType;\n fallback.textContent = `Unknown component: ${elementType}`;\n this.nodes.set(id, fallback);\n return;\n }\n\n element.dataset.hypenType = elementType.toLowerCase();\n element.dataset.hypenId = id;\n (element as any).__hypenEngine = this.engine;\n\n this.applicators.applyAll(element, propsObj);\n this.nodes.set(id, element);\n this.debugTracker.trackRerender(id, element, `create:${elementType}`);\n\n if (!this.rootId) {\n this.rootId = id;\n if (!this.container.contains(element)) {\n this.container.appendChild(element);\n }\n }\n }\n\n /**\n * Set a property on an element\n */\n private onSetProp(id: string, name: string, value: any): void {\n const element = this.nodes.get(id);\n if (!element) return;\n\n this.debugTracker.trackRerender(id, element, `setProp:${name}`);\n\n if (name === \"0\" || name === \"text\") {\n const elementType = element.dataset.hypenType;\n\n if (elementType === \"input\") {\n const inputEl = element as HTMLInputElement;\n inputEl.value = String(value);\n console.log(`[Renderer] Updated input value: \"${value}\"`);\n return;\n }\n\n element.textContent = String(value);\n if (element.dataset.textTemplate !== undefined) {\n element.dataset.textTemplate = String(value);\n }\n console.log(`[Renderer] Updated text content: \"${value}\"`);\n return;\n }\n\n this.applicators.apply(element, name, value);\n }\n\n /**\n * Set text content\n */\n private onSetText(id: string, text: string): void {\n const element = this.nodes.get(id);\n if (!element) return;\n\n this.debugTracker.trackRerender(id, element, \"setText\");\n element.textContent = text;\n }\n\n /**\n * Insert an element into the tree\n */\n private onInsert(parentId: string, id: string, beforeId?: string): void {\n const parent = parentId === \"root\" ? this.container : this.nodes.get(parentId);\n const child = this.nodes.get(id);\n\n console.log(`[Renderer] Inserting ${id} into ${parentId}`, {\n parent: parent ? `${parent.tagName}#${parent.id || 'no-id'}` : 'null',\n child: child ? `${child.tagName}#${child.id || 'no-id'}` : 'null',\n childText: child?.textContent?.substring(0, 20)\n });\n\n if (!parent || !child) return;\n\n if (parentId === \"root\") {\n this.rootId = id;\n }\n\n if (beforeId) {\n const before = this.nodes.get(beforeId);\n if (before && before.parentNode === parent) {\n parent.insertBefore(child, before);\n } else if (!parent.contains(child)) {\n parent.appendChild(child);\n }\n } else {\n if (!parent.contains(child)) {\n parent.appendChild(child);\n }\n }\n }\n\n /**\n * Move an element within the tree\n */\n private onMove(parentId: string, id: string, beforeId?: string): void {\n this.onInsert(parentId, id, beforeId);\n }\n\n /**\n * Remove an element from the tree\n */\n private onRemove(id: string): void {\n const element = this.nodes.get(id);\n if (!element) return;\n\n if (element.parentNode) {\n element.parentNode.removeChild(element);\n }\n\n this.nodes.delete(id);\n\n if (this.rootId === id) {\n this.rootId = null;\n }\n }\n\n /**\n * Get an element by ID\n */\n getNode(id: string): HTMLElement | undefined {\n return this.nodes.get(id);\n }\n\n /**\n * Clear all nodes\n */\n clear(): void {\n this.container.innerHTML = \"\";\n this.nodes.clear();\n this.rootId = null;\n }\n\n /**\n * Get the component registry (for registering custom components)\n */\n getComponentRegistry(): ComponentRegistry {\n return this.components;\n }\n\n /**\n * Get the applicator registry (for registering custom applicators)\n */\n getApplicatorRegistry(): ApplicatorRegistry {\n return this.applicators;\n }\n\n /**\n * Enable or configure debug mode\n */\n setDebugConfig(config: Partial<DebugConfig>): void {\n this.debugTracker.setConfig(config);\n }\n\n /**\n * Reset debug tracking for all elements\n */\n resetDebugTracking(): void {\n this.debugTracker.resetAll();\n }\n\n /**\n * Get debug statistics\n */\n getDebugStats(): { totalRerenders: number; elementCount: number; avgRerenders: number } {\n return this.debugTracker.getStats();\n }\n}\n"
|
|
5
|
+
"/**\n * DOM Renderer\n *\n * Renders Hypen patches to the DOM\n */\n\nimport type { Patch } from \"@hypen/core\";\nimport type { HypenModuleInstance, RouterContext } from \"@hypen/core\";\nimport type { HypenRouter } from \"@hypen/core\";\nimport type { HypenGlobalContext } from \"@hypen/core\";\nimport { ComponentRegistry } from \"./components/index.js\";\nimport { ApplicatorRegistry } from \"./applicators/index.js\";\nimport { canvasHandler, canvasApplicators } from \"./canvas/index.js\";\nimport { RerenderTracker, type DebugConfig, defaultDebugConfig } from \"./debug.js\";\n\n// Interface for the engine that renderer needs\ninterface IEngine {\n dispatchAction(name: string, payload?: any): void;\n}\n\nexport class DOMRenderer {\n private container: HTMLElement;\n private nodes: Map<string, HTMLElement> = new Map();\n private rootId: string | null = null;\n private components: ComponentRegistry;\n private applicators: ApplicatorRegistry;\n private engine: IEngine;\n private currentState: Record<string, any> = {};\n private routerContext: RouterContext | null = null;\n private globalContext: HypenGlobalContext | null = null;\n private componentInstances = new Map<string, HypenModuleInstance>();\n private debugTracker: RerenderTracker;\n\n constructor(container: HTMLElement, engine: IEngine, debugConfig?: Partial<DebugConfig>) {\n this.container = container;\n this.engine = engine;\n this.components = new ComponentRegistry();\n this.applicators = new ApplicatorRegistry();\n this.debugTracker = new RerenderTracker({ ...defaultDebugConfig, ...debugConfig });\n\n // Register canvas component and applicators\n this.components.register(\"canvas\", canvasHandler);\n for (const [name, handler] of Object.entries(canvasApplicators)) {\n this.applicators.register(name, handler);\n }\n }\n\n /**\n * Set router and global context for component composition\n */\n setContext(routerContext: RouterContext, globalContext: HypenGlobalContext): void {\n this.routerContext = routerContext;\n this.globalContext = globalContext;\n }\n\n /**\n * Apply a batch of patches to the DOM\n */\n applyPatches(patches: Patch[]): void {\n for (const patch of patches) {\n this.applyPatch(patch);\n }\n }\n\n /**\n * Update state and interpolate text content\n */\n updateState(state: Record<string, any>): void {\n console.log(`[Renderer] Updating state:`, state);\n this.currentState = state;\n this.interpolateAllText();\n }\n\n /**\n * Merge component state into current state and re-interpolate\n */\n private mergeComponentState(componentState: Record<string, any>): void {\n this.currentState = { ...this.currentState, ...componentState };\n console.log(`[Renderer] Merged state:`, this.currentState);\n this.interpolateAllText();\n }\n\n /**\n * Interpolate state values in all text elements\n */\n private interpolateAllText(): void {\n for (const [id, element] of this.nodes.entries()) {\n if (element.dataset.hypenType === \"text\" && element.dataset.textTemplate) {\n const template = element.dataset.textTemplate;\n const interpolated = this.interpolateText(template, this.currentState);\n\n // Track re-render if text actually changed\n const currentText = element.textContent;\n if (currentText !== interpolated) {\n this.debugTracker.trackRerender(id, element, \"interpolate\");\n }\n\n element.textContent = interpolated;\n }\n }\n }\n\n /**\n * Interpolate state values in text template\n */\n private interpolateText(template: string, state: Record<string, any>): string {\n return template.replace(/\\$\\{([^}]+)\\}/g, (match, path) => {\n try {\n const value = path.split('.').reduce((obj: any, key: string) => {\n if (key === 'state') return state;\n return obj?.[key];\n }, state);\n return value !== undefined ? String(value) : match;\n } catch {\n return match;\n }\n });\n }\n\n /**\n * Apply a single patch\n */\n private applyPatch(patch: Patch): void {\n switch (patch.type) {\n case \"create\":\n this.onCreate(patch.id!, (patch as any).element_type!, patch.props || {});\n break;\n case \"setProp\":\n this.onSetProp(patch.id!, patch.name!, patch.value);\n break;\n case \"setText\":\n this.onSetText(patch.id!, patch.text!);\n break;\n case \"insert\":\n this.onInsert((patch as any).parent_id!, patch.id!, (patch as any).before_id);\n break;\n case \"move\":\n this.onMove((patch as any).parent_id!, patch.id!, (patch as any).before_id);\n break;\n case \"remove\":\n this.onRemove(patch.id!);\n break;\n }\n }\n\n /**\n * Create a new element\n */\n private onCreate(id: string, elementType: string, props: Record<string, any> | Map<string, any>): void {\n const propsObj = props instanceof Map ? Object.fromEntries(props) : props;\n\n const element = this.components.createElement(elementType, propsObj);\n\n if (!element) {\n const fallback = document.createElement(\"div\");\n fallback.dataset.hypenType = elementType;\n fallback.textContent = `Unknown component: ${elementType}`;\n this.nodes.set(id, fallback);\n return;\n }\n\n element.dataset.hypenType = elementType.toLowerCase();\n element.dataset.hypenId = id;\n (element as any).__hypenEngine = this.engine;\n\n this.applicators.applyAll(element, propsObj);\n this.nodes.set(id, element);\n this.debugTracker.trackRerender(id, element, `create:${elementType}`);\n\n if (!this.rootId) {\n this.rootId = id;\n if (!this.container.contains(element)) {\n this.container.appendChild(element);\n }\n }\n }\n\n /**\n * Set a property on an element\n */\n private onSetProp(id: string, name: string, value: any): void {\n const element = this.nodes.get(id);\n if (!element) return;\n\n this.debugTracker.trackRerender(id, element, `setProp:${name}`);\n\n if (name === \"0\" || name === \"text\") {\n const elementType = element.dataset.hypenType;\n\n if (elementType === \"input\") {\n const inputEl = element as HTMLInputElement;\n inputEl.value = String(value);\n console.log(`[Renderer] Updated input value: \"${value}\"`);\n return;\n }\n\n const nextText = String(value);\n element.textContent = nextText;\n\n // Preserve the original template when it contains state interpolation.\n // Engine patches may send interpolated strings; if we overwrite the template,\n // future state updates won't be able to re-interpolate.\n const currentTemplate = element.dataset.textTemplate;\n const nextLooksLikeTemplate = nextText.includes(\"${\");\n const currentLooksLikeTemplate = typeof currentTemplate === \"string\" && currentTemplate.includes(\"${\");\n\n if (nextLooksLikeTemplate) {\n element.dataset.textTemplate = nextText;\n } else if (currentTemplate === undefined) {\n // No template stored yet; treat this as the template.\n element.dataset.textTemplate = nextText;\n } else if (!currentLooksLikeTemplate) {\n // If current template isn't a template, keep it in sync.\n element.dataset.textTemplate = nextText;\n }\n console.log(`[Renderer] Updated text content: \"${value}\"`);\n return;\n }\n\n this.applicators.apply(element, name, value);\n }\n\n /**\n * Set text content\n */\n private onSetText(id: string, text: string): void {\n const element = this.nodes.get(id);\n if (!element) return;\n\n this.debugTracker.trackRerender(id, element, \"setText\");\n element.textContent = text;\n }\n\n /**\n * Insert an element into the tree\n */\n private onInsert(parentId: string, id: string, beforeId?: string): void {\n const parent = parentId === \"root\" ? this.container : this.nodes.get(parentId);\n const child = this.nodes.get(id);\n\n console.log(`[Renderer] Inserting ${id} into ${parentId}`, {\n parent: parent ? `${parent.tagName}#${parent.id || 'no-id'}` : 'null',\n child: child ? `${child.tagName}#${child.id || 'no-id'}` : 'null',\n childText: child?.textContent?.substring(0, 20)\n });\n\n if (!parent || !child) return;\n\n if (parentId === \"root\") {\n this.rootId = id;\n }\n\n if (beforeId) {\n const before = this.nodes.get(beforeId);\n if (before && before.parentNode === parent) {\n parent.insertBefore(child, before);\n } else if (!parent.contains(child)) {\n parent.appendChild(child);\n }\n } else {\n if (!parent.contains(child)) {\n parent.appendChild(child);\n }\n }\n }\n\n /**\n * Move an element within the tree\n */\n private onMove(parentId: string, id: string, beforeId?: string): void {\n this.onInsert(parentId, id, beforeId);\n }\n\n /**\n * Remove an element from the tree\n */\n private onRemove(id: string): void {\n const element = this.nodes.get(id);\n if (!element) return;\n\n if (element.parentNode) {\n element.parentNode.removeChild(element);\n }\n\n this.nodes.delete(id);\n\n if (this.rootId === id) {\n this.rootId = null;\n }\n }\n\n /**\n * Get an element by ID\n */\n getNode(id: string): HTMLElement | undefined {\n return this.nodes.get(id);\n }\n\n /**\n * Clear all nodes\n */\n clear(): void {\n this.container.innerHTML = \"\";\n this.nodes.clear();\n this.rootId = null;\n }\n\n /**\n * Get the component registry (for registering custom components)\n */\n getComponentRegistry(): ComponentRegistry {\n return this.components;\n }\n\n /**\n * Get the applicator registry (for registering custom applicators)\n */\n getApplicatorRegistry(): ApplicatorRegistry {\n return this.applicators;\n }\n\n /**\n * Enable or configure debug mode\n */\n setDebugConfig(config: Partial<DebugConfig>): void {\n this.debugTracker.setConfig(config);\n }\n\n /**\n * Reset debug tracking for all elements\n */\n resetDebugTracking(): void {\n this.debugTracker.resetAll();\n }\n\n /**\n * Get debug statistics\n */\n getDebugStats(): { totalRerenders: number; elementCount: number; avgRerenders: number } {\n return this.debugTracker.getStats();\n }\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBO,MAAM,YAAY;AAAA,EACf;AAAA,EACA,QAAkC,IAAI;AAAA,EACtC,SAAwB;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA,eAAoC,CAAC;AAAA,EACrC,gBAAsC;AAAA,EACtC,gBAA2C;AAAA,EAC3C,qBAAqB,IAAI;AAAA,EACzB;AAAA,EAER,WAAW,CAAC,WAAwB,QAAiB,aAAoC;AAAA,IACvF,KAAK,YAAY;AAAA,IACjB,KAAK,SAAS;AAAA,IACd,KAAK,aAAa,IAAI;AAAA,IACtB,KAAK,cAAc,IAAI;AAAA,IACvB,KAAK,eAAe,IAAI,gBAAgB,KAAK,uBAAuB,YAAY,CAAC;AAAA,IAGjF,KAAK,WAAW,SAAS,UAAU,aAAa;AAAA,IAChD,YAAY,MAAM,YAAY,OAAO,QAAQ,iBAAiB,GAAG;AAAA,MAC/D,KAAK,YAAY,SAAS,MAAM,OA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B;AAAA,IACpE,KAAK,SAAS,UAAU,IAAI,QAAQ;AAAA;AAAA,EAM9B,QAAQ,CAAC,IAAkB;AAAA,IACjC,MAAM,UAAU,KAAK,MAAM,IAAI,EAAE;AAAA,IACjC,IAAI,CAAC;AAAA,MAAS;AAAA,IAEd,IAAI,QAAQ,YAAY;AAAA,MACtB,QAAQ,WAAW,YAAY,OAAO;AAAA,IACxC;AAAA,IAEA,KAAK,MAAM,OAAO,EAAE;AAAA,IAEpB,IAAI,KAAK,WAAW,IAAI;AAAA,MACtB,KAAK,SAAS;AAAA,IAChB;AAAA;AAAA,EAMF,OAAO,CAAC,IAAqC;AAAA,IAC3C,OAAO,KAAK,MAAM,IAAI,EAAE;AAAA;AAAA,EAM1B,KAAK,GAAS;AAAA,IACZ,KAAK,UAAU,YAAY;AAAA,IAC3B,KAAK,MAAM,MAAM;AAAA,IACjB,KAAK,SAAS;AAAA;AAAA,EAMhB,oBAAoB,GAAsB;AAAA,IACxC,OAAO,KAAK;AAAA;AAAA,EAMd,qBAAqB,GAAuB;AAAA,IAC1C,OAAO,KAAK;AAAA;AAAA,EAMd,cAAc,CAAC,QAAoC;AAAA,IACjD,KAAK,aAAa,UAAU,MAAM;AAAA;AAAA,EAMpC,kBAAkB,GAAS;AAAA,IACzB,KAAK,aAAa,SAAS;AAAA;AAAA,EAM7B,aAAa,GAA2E;AAAA,IACtF,OAAO,KAAK,aAAa,SAAS;AAAA;AAEtC;",
|
|
8
|
+
"debugId": "4035E3738262CFE264756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hypen-space/web",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "Hypen web renderers - DOM and Canvas rendering for browsers",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/index.js",
|
|
7
|
-
"module": "./dist/index.js",
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
9
|
-
"browser": "./dist/index.js",
|
|
6
|
+
"main": "./dist/src/index.js",
|
|
7
|
+
"module": "./dist/src/index.js",
|
|
8
|
+
"types": "./dist/src/index.d.ts",
|
|
9
|
+
"browser": "./dist/src/index.js",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
-
"types": "./dist/index.d.ts",
|
|
13
|
-
"browser": "./dist/index.js",
|
|
12
|
+
"types": "./dist/src/index.d.ts",
|
|
13
|
+
"browser": "./dist/src/index.js",
|
|
14
14
|
"bun": "./src/index.ts",
|
|
15
|
-
"import": "./dist/index.js",
|
|
16
|
-
"default": "./dist/index.js"
|
|
15
|
+
"import": "./dist/src/index.js",
|
|
16
|
+
"default": "./dist/src/index.js"
|
|
17
17
|
},
|
|
18
18
|
"./dom": {
|
|
19
|
-
"types": "./dist/dom/index.d.ts",
|
|
20
|
-
"browser": "./dist/dom/index.js",
|
|
19
|
+
"types": "./dist/src/dom/index.d.ts",
|
|
20
|
+
"browser": "./dist/src/dom/index.js",
|
|
21
21
|
"bun": "./src/dom/index.ts",
|
|
22
|
-
"import": "./dist/dom/index.js",
|
|
23
|
-
"default": "./dist/dom/index.js"
|
|
22
|
+
"import": "./dist/src/dom/index.js",
|
|
23
|
+
"default": "./dist/src/dom/index.js"
|
|
24
24
|
},
|
|
25
25
|
"./canvas": {
|
|
26
|
-
"types": "./dist/canvas/index.d.ts",
|
|
27
|
-
"browser": "./dist/canvas/index.js",
|
|
26
|
+
"types": "./dist/src/canvas/index.d.ts",
|
|
27
|
+
"browser": "./dist/src/canvas/index.js",
|
|
28
28
|
"bun": "./src/canvas/index.ts",
|
|
29
|
-
"import": "./dist/canvas/index.js",
|
|
30
|
-
"default": "./dist/canvas/index.js"
|
|
29
|
+
"import": "./dist/src/canvas/index.js",
|
|
30
|
+
"default": "./dist/src/canvas/index.js"
|
|
31
31
|
},
|
|
32
32
|
"./hypen": {
|
|
33
|
-
"types": "./dist/hypen.d.ts",
|
|
34
|
-
"browser": "./dist/hypen.js",
|
|
33
|
+
"types": "./dist/src/hypen.d.ts",
|
|
34
|
+
"browser": "./dist/src/hypen.js",
|
|
35
35
|
"bun": "./src/hypen.ts",
|
|
36
|
-
"import": "./dist/hypen.js",
|
|
37
|
-
"default": "./dist/hypen.js"
|
|
36
|
+
"import": "./dist/src/hypen.js",
|
|
37
|
+
"default": "./dist/src/hypen.js"
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"files": [
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"clean": "rm -rf dist"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@hypen-space/core": "
|
|
51
|
+
"@hypen-space/core": "^0.2.5"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@types/bun": "latest",
|
package/src/dom/renderer.ts
CHANGED
|
@@ -194,9 +194,24 @@ export class DOMRenderer {
|
|
|
194
194
|
return;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
197
|
+
const nextText = String(value);
|
|
198
|
+
element.textContent = nextText;
|
|
199
|
+
|
|
200
|
+
// Preserve the original template when it contains state interpolation.
|
|
201
|
+
// Engine patches may send interpolated strings; if we overwrite the template,
|
|
202
|
+
// future state updates won't be able to re-interpolate.
|
|
203
|
+
const currentTemplate = element.dataset.textTemplate;
|
|
204
|
+
const nextLooksLikeTemplate = nextText.includes("${");
|
|
205
|
+
const currentLooksLikeTemplate = typeof currentTemplate === "string" && currentTemplate.includes("${");
|
|
206
|
+
|
|
207
|
+
if (nextLooksLikeTemplate) {
|
|
208
|
+
element.dataset.textTemplate = nextText;
|
|
209
|
+
} else if (currentTemplate === undefined) {
|
|
210
|
+
// No template stored yet; treat this as the template.
|
|
211
|
+
element.dataset.textTemplate = nextText;
|
|
212
|
+
} else if (!currentLooksLikeTemplate) {
|
|
213
|
+
// If current template isn't a template, keep it in sync.
|
|
214
|
+
element.dataset.textTemplate = nextText;
|
|
200
215
|
}
|
|
201
216
|
console.log(`[Renderer] Updated text content: "${value}"`);
|
|
202
217
|
return;
|