@repobit/dex-store-elements 1.4.73 → 1.5.0
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/CHANGELOG.md +15 -0
- package/dist/src/controllers/eta-renderer/eta-dom-renderer.d.ts +4 -0
- package/dist/src/controllers/eta-renderer/eta-dom-renderer.js +40 -0
- package/dist/src/controllers/eta-renderer/eta-dom-renderer.js.map +1 -1
- package/dist/src/controllers/eta-renderer/eta-template-cache.d.ts +3 -0
- package/dist/src/controllers/eta-renderer/eta-template-cache.js +9 -0
- package/dist/src/controllers/eta-renderer/eta-template-cache.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,21 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.5.0](https://github.com/bitdefender/dex-core/compare/@repobit/dex-store-elements@1.4.74...@repobit/dex-store-elements@1.5.0) (2026-07-16)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **DEX-24668:** fixed bug where nanomorph was cached with classes which were no longer in the dom
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## [1.4.74](https://github.com/bitdefender/dex-core/compare/@repobit/dex-store-elements@1.4.73...@repobit/dex-store-elements@1.4.74) (2026-07-15)
|
|
14
|
+
|
|
15
|
+
**Note:** Version bump only for package @repobit/dex-store-elements
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
6
21
|
## [1.4.73](https://github.com/bitdefender/dex-core/compare/@repobit/dex-store-elements@1.4.72...@repobit/dex-store-elements@1.4.73) (2026-07-15)
|
|
7
22
|
|
|
8
23
|
**Note:** Version bump only for package @repobit/dex-store-elements
|
|
@@ -16,6 +16,10 @@ export declare class EtaDomRenderer {
|
|
|
16
16
|
private _renderEtaAttributes;
|
|
17
17
|
private _hasRenderNodes;
|
|
18
18
|
private _hasNestedStateNode;
|
|
19
|
+
private _reconcileTemplateClasses;
|
|
20
|
+
/** Recursively remove from template elements any literal (non-template) classes
|
|
21
|
+
* that have been stripped from the corresponding live-DOM elements externally. */
|
|
22
|
+
private _patchRemovedClasses;
|
|
19
23
|
private _morphElementFromHTML;
|
|
20
24
|
}
|
|
21
25
|
export {};
|
|
@@ -62,8 +62,15 @@ export class EtaDomRenderer {
|
|
|
62
62
|
}
|
|
63
63
|
const entry = this.cache.updateElementEntry(child, currentSrc, { allowMutationRefresh: fromMutation });
|
|
64
64
|
if (!fromMutation) {
|
|
65
|
+
const lastRendered = this.cache.getLastRendered(child);
|
|
66
|
+
if (lastRendered !== undefined &&
|
|
67
|
+
currentSrc !== lastRendered &&
|
|
68
|
+
!currentSrc.includes("{{")) {
|
|
69
|
+
this._reconcileTemplateClasses(entry, currentSrc);
|
|
70
|
+
}
|
|
65
71
|
const out = this._safeEtaRender(entry, context, { onErrorReturnInput: true });
|
|
66
72
|
await this._morphElementFromHTML(child, out);
|
|
73
|
+
this.cache.setLastRendered(child, out);
|
|
67
74
|
}
|
|
68
75
|
await traverseShadow();
|
|
69
76
|
if ((++processed % 50) === 0) {
|
|
@@ -136,6 +143,39 @@ export class EtaDomRenderer {
|
|
|
136
143
|
_hasNestedStateNode(el) {
|
|
137
144
|
return !!el.querySelector?.("bd-state,bd-product,bd-option,bd-context");
|
|
138
145
|
}
|
|
146
|
+
_reconcileTemplateClasses(entry, currentDomSrc) {
|
|
147
|
+
const templateWrapper = document.createElement("div");
|
|
148
|
+
templateWrapper.innerHTML = entry.src;
|
|
149
|
+
const domWrapper = document.createElement("div");
|
|
150
|
+
domWrapper.innerHTML = currentDomSrc;
|
|
151
|
+
this._patchRemovedClasses(templateWrapper, domWrapper);
|
|
152
|
+
const patched = templateWrapper.innerHTML;
|
|
153
|
+
if (patched !== entry.src) {
|
|
154
|
+
entry.src = patched;
|
|
155
|
+
delete entry.fn;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/** Recursively remove from template elements any literal (non-template) classes
|
|
159
|
+
* that have been stripped from the corresponding live-DOM elements externally. */
|
|
160
|
+
_patchRemovedClasses(templateEl, domEl) {
|
|
161
|
+
const templateChildren = Array.from(templateEl.children);
|
|
162
|
+
const domChildren = Array.from(domEl.children);
|
|
163
|
+
for (let i = 0; i < Math.min(templateChildren.length, domChildren.length); i++) {
|
|
164
|
+
const tc = templateChildren[i];
|
|
165
|
+
const dc = domChildren[i];
|
|
166
|
+
if (tc.tagName !== dc.tagName)
|
|
167
|
+
continue;
|
|
168
|
+
for (const cls of [...tc.classList]) {
|
|
169
|
+
// Skip template expressions embedded inside class tokens (e.g. "{{it.cls}}")
|
|
170
|
+
if (cls.includes("{{"))
|
|
171
|
+
continue;
|
|
172
|
+
if (!dc.classList.contains(cls)) {
|
|
173
|
+
tc.classList.remove(cls);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
this._patchRemovedClasses(tc, dc);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
139
179
|
async _morphElementFromHTML(el, html) {
|
|
140
180
|
if (el.innerHTML === html)
|
|
141
181
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eta-dom-renderer.js","sourceRoot":"","sources":["../../../../src/controllers/eta-renderer/eta-dom-renderer.ts"],"names":[],"mappings":"AAEA,OAAO,GAAG,MAAM,kBAAkB,CAAC;AACnC,OAAO,KAAK,MAAM,WAAW,CAAC;AAS9B,MAAM,OAAO,cAAc;IAKzB,YAAY,IAAmB,EAAE,KAAuB,EAAE,iBAAqC;QAC7F,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAAe,EAAE,EAAE,YAAY,EAAE,UAAU,EAAiB;QACvE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,CAAC;QACrB,CAAC;QAAC,MAAM,CAAC;YACP,EAAE,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,CAAC;IACH,CAAC;CACF","sourcesContent":["import { EtaTemplateCache } from \"@/controllers/eta-renderer/eta-template-cache\";\nimport { EtaRenderHost, ObserveShadowRoot } from \"@/controllers/eta-renderer/eta-types\";\nimport eta from \"@/templating/eta\";\nimport morph from \"nanomorph\";\n\ntype RenderOptions = {\n fromMutation: boolean;\n dirtyRoots? : Set<HTMLElement> | null;\n};\n\ntype TemplateEntry = { src: string; fn?: ReturnType<typeof eta.compile> };\n\nexport class EtaDomRenderer {\n private host : EtaRenderHost;\n private cache : EtaTemplateCache;\n private observeShadowRoot?: ObserveShadowRoot;\n\n constructor(host: EtaRenderHost, cache: EtaTemplateCache, observeShadowRoot?: ObserveShadowRoot) {\n this.host = host;\n this.cache = cache;\n this.observeShadowRoot = observeShadowRoot;\n }\n\n async render(context: object, { fromMutation, dirtyRoots }: RenderOptions) {\n const roots = dirtyRoots && dirtyRoots.size ? Array.from(dirtyRoots) : [this.host as unknown as HTMLElement];\n\n const visitWithShadow = async (root: Element) => {\n await this._visit(root, context, fromMutation);\n if (root.hasAttribute(\"shadow\") && (root as HTMLElement).shadowRoot) {\n await this._visit((root as HTMLElement).shadowRoot as ShadowRoot, context, fromMutation);\n }\n };\n\n for (const r of roots) {\n if (!r) continue;\n await visitWithShadow(r);\n }\n }\n\n private async _visit(root: Element | ShadowRoot, context: object, fromMutation: boolean) {\n let processed = 0;\n for (const child of Array.from(root.children)) {\n if (!(child instanceof HTMLElement)) continue;\n\n await this._waitForCustomUpdate(child);\n\n const shadowRoot = child.hasAttribute(\"shadow\") ? child.shadowRoot : null;\n const traverseShadow = async () => {\n if (shadowRoot) {\n await this._visit(shadowRoot, context, fromMutation);\n }\n };\n if (shadowRoot && this.observeShadowRoot) {\n this.observeShadowRoot(shadowRoot, child);\n }\n\n const currentSrc = child.innerHTML ?? \"\";\n\n await this._renderEtaAttributes(child, context, fromMutation);\n\n if (this.host.isStateNodeElement(child) && child !== this.host) {\n continue; // nested provider; let it handle its subtree\n }\n\n const hasNestedStateNode = this._hasNestedStateNode(child);\n if (hasNestedStateNode) {\n await this._visit(child, context, fromMutation);\n await traverseShadow();\n continue;\n }\n\n if (this._hasRenderNodes(child)) {\n await this._visit(child, context, fromMutation);\n await traverseShadow();\n continue;\n }\n\n if (child.hasAttribute(\"data-store-render\")) {\n continue;\n }\n\n const hadTemplate = this.cache.hasTemplate(child);\n const noAttrs = this.cache.hasNoEtaAttrs(child);\n if (!currentSrc.includes(\"{{\") && noAttrs && !hadTemplate && !hasNestedStateNode) {\n await traverseShadow();\n continue;\n }\n\n const entry = this.cache.updateElementEntry(child, currentSrc, { allowMutationRefresh: fromMutation });\n\n if (!fromMutation) {\n const out = this._safeEtaRender(entry, context, { onErrorReturnInput: true });\n await this._morphElementFromHTML(child, out);\n }\n await traverseShadow();\n\n if ((++processed % 50) === 0) {\n await Promise.resolve();\n }\n }\n }\n\n private async _waitForCustomUpdate(el: HTMLElement) {\n const maybe = (el as unknown as { updateComplete?: Promise<unknown> }).updateComplete;\n if (maybe && typeof (maybe as Promise<unknown>).then === \"function\") {\n try {\n await maybe;\n } catch { /* ignore */ }\n }\n }\n\n private _safeEtaRender(entry: TemplateEntry, data: object, { onErrorReturnInput = false }: { onErrorReturnInput?: boolean } = {}) {\n try {\n if (!entry.fn) {\n entry.fn = eta.compile(entry.src);\n }\n const out = eta.render(entry.fn, data);\n return typeof out === \"string\" ? out : String(out ?? \"\");\n } catch (err) {\n console.error(\"Eta render error:\", err);\n return onErrorReturnInput ? entry.src : \"\";\n }\n }\n\n private async _renderEtaAttributes(el: HTMLElement, data: object, fromMutation: boolean) {\n const names = el.getAttributeNames();\n const cache = this.cache.getOrCreateAttrCache(el);\n\n if (this.cache.hasNoEtaAttrs(el)) return;\n\n let foundTemplateAttr = false;\n for (const a of names) {\n const raw = el.getAttribute(a);\n if (!raw || !raw.includes(\"{{\")) continue;\n foundTemplateAttr = true;\n const key = `imp:${a}`;\n let entry = cache.get(key);\n if (!entry || entry.src !== raw) {\n entry = { src: raw };\n cache.set(key, entry);\n }\n if (!fromMutation) {\n const rendered = this._safeEtaRender(entry, data, { onErrorReturnInput: true });\n if (rendered !== raw) {\n try { el.setAttribute(a, rendered); } catch { /* ignore */ }\n }\n }\n }\n\n if (!foundTemplateAttr) {\n this.cache.markNoEtaAttrs(el);\n }\n }\n\n private _hasRenderNodes(el: Element): boolean {\n const h = el as HTMLElement;\n if (!h) return false;\n if (h.hasAttribute && h.hasAttribute(\"data-store-render\")) return true;\n const html = h.innerHTML;\n return typeof html === \"string\" && html.includes(\"data-store-render\");\n }\n\n private _hasNestedStateNode(el: Element): boolean {\n return !!(el as Element).querySelector?.(\"bd-state,bd-product,bd-option,bd-context\");\n }\n\n private async _morphElementFromHTML(el: HTMLElement, html: string) {\n if (el.innerHTML === html) return;\n try {\n const wrapper = el.cloneNode(false) as HTMLElement;\n wrapper.innerHTML = html;\n morph(el, wrapper);\n } catch {\n el.innerHTML = html;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"eta-dom-renderer.js","sourceRoot":"","sources":["../../../../src/controllers/eta-renderer/eta-dom-renderer.ts"],"names":[],"mappings":"AAEA,OAAO,GAAG,MAAM,kBAAkB,CAAC;AACnC,OAAO,KAAK,MAAM,WAAW,CAAC;AAS9B,MAAM,OAAO,cAAc;IAKzB,YAAY,IAAmB,EAAE,KAAuB,EAAE,iBAAqC;QAC7F,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAAe,EAAE,EAAE,YAAY,EAAE,UAAU,EAAiB;QACvE,MAAM,KAAK,GAAG,UAAU,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,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,IAAI,CAAC;oBAAE,SAAS;gBACjC,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;oBAChC,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAC3B,CAAC;YACH,CAAC;YAED,IAAI,CAAC,oBAAoB,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,qBAAqB,CAAC,EAAe,EAAE,IAAY;QAC/D,IAAI,EAAE,CAAC,SAAS,KAAK,IAAI;YAAE,OAAO;QAClC,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,CAAgB,CAAC;YACnD,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;YACzB,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QACrB,CAAC;QAAC,MAAM,CAAC;YACP,EAAE,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,CAAC;IACH,CAAC;CACF","sourcesContent":["import { EtaTemplateCache } from \"@/controllers/eta-renderer/eta-template-cache\";\nimport { EtaRenderHost, ObserveShadowRoot } from \"@/controllers/eta-renderer/eta-types\";\nimport eta from \"@/templating/eta\";\nimport morph from \"nanomorph\";\n\ntype RenderOptions = {\n fromMutation: boolean;\n dirtyRoots? : Set<HTMLElement> | null;\n};\n\ntype TemplateEntry = { src: string; fn?: ReturnType<typeof eta.compile> };\n\nexport class EtaDomRenderer {\n private host : EtaRenderHost;\n private cache : EtaTemplateCache;\n private observeShadowRoot?: ObserveShadowRoot;\n\n constructor(host: EtaRenderHost, cache: EtaTemplateCache, observeShadowRoot?: ObserveShadowRoot) {\n this.host = host;\n this.cache = cache;\n this.observeShadowRoot = observeShadowRoot;\n }\n\n async render(context: object, { fromMutation, dirtyRoots }: RenderOptions) {\n const roots = dirtyRoots && dirtyRoots.size ? Array.from(dirtyRoots) : [this.host as unknown as HTMLElement];\n\n const visitWithShadow = async (root: Element) => {\n await this._visit(root, context, fromMutation);\n if (root.hasAttribute(\"shadow\") && (root as HTMLElement).shadowRoot) {\n await this._visit((root as HTMLElement).shadowRoot as ShadowRoot, context, fromMutation);\n }\n };\n\n for (const r of roots) {\n if (!r) continue;\n await visitWithShadow(r);\n }\n }\n\n private async _visit(root: Element | ShadowRoot, context: object, fromMutation: boolean) {\n let processed = 0;\n for (const child of Array.from(root.children)) {\n if (!(child instanceof HTMLElement)) continue;\n\n await this._waitForCustomUpdate(child);\n\n const shadowRoot = child.hasAttribute(\"shadow\") ? child.shadowRoot : null;\n const traverseShadow = async () => {\n if (shadowRoot) {\n await this._visit(shadowRoot, context, fromMutation);\n }\n };\n if (shadowRoot && this.observeShadowRoot) {\n this.observeShadowRoot(shadowRoot, child);\n }\n\n const currentSrc = child.innerHTML ?? \"\";\n\n await this._renderEtaAttributes(child, context, fromMutation);\n\n if (this.host.isStateNodeElement(child) && child !== this.host) {\n continue; // nested provider; let it handle its subtree\n }\n\n const hasNestedStateNode = this._hasNestedStateNode(child);\n if (hasNestedStateNode) {\n await this._visit(child, context, fromMutation);\n await traverseShadow();\n continue;\n }\n\n if (this._hasRenderNodes(child)) {\n await this._visit(child, context, fromMutation);\n await traverseShadow();\n continue;\n }\n\n if (child.hasAttribute(\"data-store-render\")) {\n continue;\n }\n\n const hadTemplate = this.cache.hasTemplate(child);\n const noAttrs = this.cache.hasNoEtaAttrs(child);\n if (!currentSrc.includes(\"{{\") && noAttrs && !hadTemplate && !hasNestedStateNode) {\n await traverseShadow();\n continue;\n }\n\n const entry = this.cache.updateElementEntry(child, currentSrc, { allowMutationRefresh: fromMutation });\n\n if (!fromMutation) {\n const lastRendered = this.cache.getLastRendered(child);\n if (\n lastRendered !== undefined &&\n currentSrc !== lastRendered &&\n !currentSrc.includes(\"{{\")\n ) {\n this._reconcileTemplateClasses(entry, currentSrc);\n }\n const out = this._safeEtaRender(entry, context, { onErrorReturnInput: true });\n await this._morphElementFromHTML(child, out);\n this.cache.setLastRendered(child, out);\n }\n await traverseShadow();\n\n if ((++processed % 50) === 0) {\n await Promise.resolve();\n }\n }\n }\n\n private async _waitForCustomUpdate(el: HTMLElement) {\n const maybe = (el as unknown as { updateComplete?: Promise<unknown> }).updateComplete;\n if (maybe && typeof (maybe as Promise<unknown>).then === \"function\") {\n try {\n await maybe;\n } catch { /* ignore */ }\n }\n }\n\n private _safeEtaRender(entry: TemplateEntry, data: object, { onErrorReturnInput = false }: { onErrorReturnInput?: boolean } = {}) {\n try {\n if (!entry.fn) {\n entry.fn = eta.compile(entry.src);\n }\n const out = eta.render(entry.fn, data);\n return typeof out === \"string\" ? out : String(out ?? \"\");\n } catch (err) {\n console.error(\"Eta render error:\", err);\n return onErrorReturnInput ? entry.src : \"\";\n }\n }\n\n private async _renderEtaAttributes(el: HTMLElement, data: object, fromMutation: boolean) {\n const names = el.getAttributeNames();\n const cache = this.cache.getOrCreateAttrCache(el);\n\n if (this.cache.hasNoEtaAttrs(el)) return;\n\n let foundTemplateAttr = false;\n for (const a of names) {\n const raw = el.getAttribute(a);\n if (!raw || !raw.includes(\"{{\")) continue;\n foundTemplateAttr = true;\n const key = `imp:${a}`;\n let entry = cache.get(key);\n if (!entry || entry.src !== raw) {\n entry = { src: raw };\n cache.set(key, entry);\n }\n if (!fromMutation) {\n const rendered = this._safeEtaRender(entry, data, { onErrorReturnInput: true });\n if (rendered !== raw) {\n try { el.setAttribute(a, rendered); } catch { /* ignore */ }\n }\n }\n }\n\n if (!foundTemplateAttr) {\n this.cache.markNoEtaAttrs(el);\n }\n }\n\n private _hasRenderNodes(el: Element): boolean {\n const h = el as HTMLElement;\n if (!h) return false;\n if (h.hasAttribute && h.hasAttribute(\"data-store-render\")) return true;\n const html = h.innerHTML;\n return typeof html === \"string\" && html.includes(\"data-store-render\");\n }\n\n private _hasNestedStateNode(el: Element): boolean {\n return !!(el as Element).querySelector?.(\"bd-state,bd-product,bd-option,bd-context\");\n }\n\n private _reconcileTemplateClasses(entry: TemplateEntry, currentDomSrc: string) {\n const templateWrapper = document.createElement(\"div\");\n templateWrapper.innerHTML = entry.src;\n\n const domWrapper = document.createElement(\"div\");\n domWrapper.innerHTML = currentDomSrc;\n\n this._patchRemovedClasses(templateWrapper, domWrapper);\n\n const patched = templateWrapper.innerHTML;\n if (patched !== entry.src) {\n entry.src = patched;\n delete entry.fn;\n }\n }\n\n /** Recursively remove from template elements any literal (non-template) classes\n * that have been stripped from the corresponding live-DOM elements externally. */\n private _patchRemovedClasses(templateEl: Element, domEl: Element) {\n const templateChildren = Array.from(templateEl.children);\n const domChildren = Array.from(domEl.children);\n\n for (let i = 0; i < Math.min(templateChildren.length, domChildren.length); i++) {\n const tc = templateChildren[i] as HTMLElement;\n const dc = domChildren[i] as HTMLElement;\n if (tc.tagName !== dc.tagName) continue;\n\n for (const cls of [...tc.classList]) {\n // Skip template expressions embedded inside class tokens (e.g. \"{{it.cls}}\")\n if (cls.includes(\"{{\")) continue;\n if (!dc.classList.contains(cls)) {\n tc.classList.remove(cls);\n }\n }\n\n this._patchRemovedClasses(tc, dc);\n }\n }\n\n private async _morphElementFromHTML(el: HTMLElement, html: string) {\n if (el.innerHTML === html) return;\n try {\n const wrapper = el.cloneNode(false) as HTMLElement;\n wrapper.innerHTML = html;\n morph(el, wrapper);\n } catch {\n el.innerHTML = html;\n }\n }\n}\n"]}
|
|
@@ -2,6 +2,7 @@ import eta from "../../templating/eta.js";
|
|
|
2
2
|
type TemplateEntry = {
|
|
3
3
|
src: string;
|
|
4
4
|
fn?: ReturnType<typeof eta.compile>;
|
|
5
|
+
lastRendered?: string;
|
|
5
6
|
};
|
|
6
7
|
type UpdateOptions = {
|
|
7
8
|
allowMutationRefresh: boolean;
|
|
@@ -17,5 +18,7 @@ export declare class EtaTemplateCache {
|
|
|
17
18
|
markNoEtaAttrs(el: HTMLElement): void;
|
|
18
19
|
clearNoEtaAttrs(el: HTMLElement): void;
|
|
19
20
|
updateElementEntry(el: HTMLElement, currentSrc: string, { allowMutationRefresh }: UpdateOptions): TemplateEntry;
|
|
21
|
+
getLastRendered(el: HTMLElement): string | undefined;
|
|
22
|
+
setLastRendered(el: HTMLElement, rendered: string): void;
|
|
20
23
|
}
|
|
21
24
|
export {};
|
|
@@ -44,9 +44,18 @@ export class EtaTemplateCache {
|
|
|
44
44
|
if (isTemplateLike || (allowMutationRefresh && !hadTemplate)) {
|
|
45
45
|
entry.src = currentSrc;
|
|
46
46
|
delete entry.fn;
|
|
47
|
+
delete entry.lastRendered;
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
return entry;
|
|
50
51
|
}
|
|
52
|
+
getLastRendered(el) {
|
|
53
|
+
return this._elementTemplates.get(el)?.lastRendered;
|
|
54
|
+
}
|
|
55
|
+
setLastRendered(el, rendered) {
|
|
56
|
+
const entry = this._elementTemplates.get(el);
|
|
57
|
+
if (entry)
|
|
58
|
+
entry.lastRendered = rendered;
|
|
59
|
+
}
|
|
51
60
|
}
|
|
52
61
|
//# sourceMappingURL=eta-template-cache.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eta-template-cache.js","sourceRoot":"","sources":["../../../../src/controllers/eta-renderer/eta-template-cache.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,gBAAgB;IAA7B;QACU,sBAAiB,GAAG,IAAI,OAAO,EAA8B,CAAC;QAC9D,mBAAc,GAAG,IAAI,OAAO,EAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"eta-template-cache.js","sourceRoot":"","sources":["../../../../src/controllers/eta-renderer/eta-template-cache.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,gBAAgB;IAA7B;QACU,sBAAiB,GAAG,IAAI,OAAO,EAA8B,CAAC;QAC9D,mBAAc,GAAG,IAAI,OAAO,EAA2C,CAAC;IAkElF,CAAC;IA/DC,eAAe,CAAC,EAAe;QAC7B,OAAO,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACxC,CAAC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I,CAAC,KAAK,EAAE,CAAC;YACX,KAAK,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC;YAC5B,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;YACtC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,KAAK,CAAC,GAAG,KAAK,UAAU,EAAE,CAAC;YAC7B,MAAM,cAAc,GAAG,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACjD,oFAAoF;YACpF,uDAAuD;YACvD,IAAI,cAAc,IAAI,CAAC,oBAAoB,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;gBAC7D,KAAK,CAAC,GAAG,GAAG,UAAU,CAAC;gBACvB,OAAO,KAAK,CAAC,EAAE,CAAC;gBAChB,OAAO,KAAK,CAAC,YAAY,CAAC;YAC5B,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,eAAe,CAAC,EAAe;QAC7B,OAAO,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,YAAY,CAAC;IACtD,CAAC;IAED,eAAe,CAAC,EAAe,EAAE,QAAgB;QAC/C,MAAM,KAAK,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC7C,IAAI,KAAK;YAAE,KAAK,CAAC,YAAY,GAAG,QAAQ,CAAC;IAC3C,CAAC;CACF","sourcesContent":["import eta from \"@/templating/eta\";\n\ntype TemplateEntry = { src: string; fn?: ReturnType<typeof eta.compile>; lastRendered?: string };\n\ntype UpdateOptions = {\n allowMutationRefresh: boolean;\n};\n\nexport class EtaTemplateCache {\n private _elementTemplates = new WeakMap<HTMLElement, TemplateEntry>();\n private _attrTemplates = new WeakMap<HTMLElement, Map<string, TemplateEntry>>();\n private _noEtaAttrs?: WeakSet<HTMLElement>;\n\n getElementEntry(el: HTMLElement): TemplateEntry | undefined {\n return this._elementTemplates.get(el);\n }\n\n hasTemplate(el: HTMLElement): boolean {\n const entry = this._elementTemplates.get(el);\n return Boolean(entry && entry.src && entry.src.includes(\"{{\"));\n }\n\n getOrCreateAttrCache(el: HTMLElement): Map<string, TemplateEntry> {\n let cache = this._attrTemplates.get(el);\n if (!cache) {\n cache = new Map();\n this._attrTemplates.set(el, cache);\n }\n return cache;\n }\n\n hasNoEtaAttrs(el: HTMLElement): boolean {\n return this._noEtaAttrs?.has(el) ?? false;\n }\n\n markNoEtaAttrs(el: HTMLElement) {\n if (!this._noEtaAttrs) this._noEtaAttrs = new WeakSet<HTMLElement>();\n this._noEtaAttrs.add(el);\n }\n\n clearNoEtaAttrs(el: HTMLElement) {\n this._noEtaAttrs?.delete(el);\n }\n\n updateElementEntry(el: HTMLElement, currentSrc: string, { allowMutationRefresh }: UpdateOptions): TemplateEntry {\n let entry = this._elementTemplates.get(el);\n const hadTemplate = Boolean(entry && entry.src && entry.src.includes(\"{{\"));\n\n if (!entry) {\n entry = { src: currentSrc };\n this._elementTemplates.set(el, entry);\n return entry;\n }\n\n if (entry.src !== currentSrc) {\n const isTemplateLike = currentSrc.includes(\"{{\");\n // Accept SPA-authored changes (even without templates) only when mutation-triggered\n // and the element did not previously cache a template.\n if (isTemplateLike || (allowMutationRefresh && !hadTemplate)) {\n entry.src = currentSrc;\n delete entry.fn;\n delete entry.lastRendered;\n }\n }\n\n return entry;\n }\n\n getLastRendered(el: HTMLElement): string | undefined {\n return this._elementTemplates.get(el)?.lastRendered;\n }\n\n setLastRendered(el: HTMLElement, rendered: string) {\n const entry = this._elementTemplates.get(el);\n if (entry) entry.lastRendered = rendered;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@repobit/dex-store-elements",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "HTML elements layer for pricings",
|
|
5
5
|
"author": "Buga Adrian Alexandru <abuga@bitdefender.com>",
|
|
6
6
|
"homepage": "https://github.com/bitdefender/dex-core#readme",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@lit/context": "^1.1.6",
|
|
54
54
|
"@lit/task": "^1.0.3",
|
|
55
|
-
"@repobit/dex-store": "1.3.
|
|
55
|
+
"@repobit/dex-store": "1.3.83",
|
|
56
56
|
"eta": "^4.5.1",
|
|
57
57
|
"nanomorph": "^5.4.3"
|
|
58
58
|
},
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
]
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "4bdb34bc53c0ea3a5a7e4d9858dd6a5829a98adf"
|
|
67
67
|
}
|