@gemx-dev/clarity-visualize 0.8.70 → 0.8.71

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.
@@ -1668,6 +1668,35 @@ class LayoutHelper {
1668
1668
  // Reset dialog render state for new render cycle
1669
1669
  resetDialogRenderState();
1670
1670
  };
1671
+ /** Rebuild internal node/hash maps from a pre-rendered document (used for HTML cache restore). */
1672
+ this.hydrate = (doc) => {
1673
+ this.nodes = {};
1674
+ this.hashMapAlpha = {};
1675
+ this.hashMapBeta = {};
1676
+ // querySelectorAll does not include documentElement itself
1677
+ const htmlEl = doc.documentElement;
1678
+ if (htmlEl === null || htmlEl === void 0 ? void 0 : htmlEl.hasAttribute("data-clarity-id" /* Constant.Id */)) {
1679
+ const id = parseInt(htmlEl.getAttribute("data-clarity-id" /* Constant.Id */), 10);
1680
+ if (!isNaN(id) && id > 0) {
1681
+ this.nodes[id] = htmlEl;
1682
+ }
1683
+ }
1684
+ const elements = doc.querySelectorAll(`[${"data-clarity-id" /* Constant.Id */}]`);
1685
+ for (const el of Array.from(elements)) {
1686
+ const id = parseInt(el.getAttribute("data-clarity-id" /* Constant.Id */), 10);
1687
+ if (!isNaN(id) && id > 0) {
1688
+ this.nodes[id] = el;
1689
+ const ha = el.getAttribute("data-clarity-hashalpha" /* Constant.HashAlpha */);
1690
+ const hb = el.getAttribute("data-clarity-hashbeta" /* Constant.HashBeta */);
1691
+ if (ha) {
1692
+ this.hashMapAlpha[ha] = el;
1693
+ }
1694
+ if (hb) {
1695
+ this.hashMapBeta[hb] = el;
1696
+ }
1697
+ }
1698
+ }
1699
+ };
1671
1700
  this.get = (hash) => {
1672
1701
  if (hash in this.hashMapBeta && this.hashMapBeta[hash].isConnected) {
1673
1702
  return this.hashMapBeta[hash];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gemx-dev/clarity-visualize",
3
- "version": "0.8.70",
3
+ "version": "0.8.71",
4
4
  "description": "Clarity visualize",
5
5
  "author": "Microsoft Corp.",
6
6
  "license": "MIT",
@@ -9,7 +9,7 @@
9
9
  "unpkg": "build/clarity.visualize.min.js",
10
10
  "types": "types/index.d.ts",
11
11
  "dependencies": {
12
- "@gemx-dev/clarity-decode": "^0.8.70"
12
+ "@gemx-dev/clarity-decode": "^0.8.71"
13
13
  },
14
14
  "devDependencies": {
15
15
  "@rollup/plugin-commonjs": "^24.0.0",
package/src/layout.ts CHANGED
@@ -146,6 +146,30 @@ export class LayoutHelper {
146
146
  dialogCustom.resetDialogRenderState();
147
147
  }
148
148
 
149
+ /** Rebuild internal node/hash maps from a pre-rendered document (used for HTML cache restore). */
150
+ public hydrate = (doc: Document): void => {
151
+ this.nodes = {};
152
+ this.hashMapAlpha = {};
153
+ this.hashMapBeta = {};
154
+ // querySelectorAll does not include documentElement itself
155
+ const htmlEl = doc.documentElement;
156
+ if (htmlEl?.hasAttribute(Constant.Id)) {
157
+ const id = parseInt(htmlEl.getAttribute(Constant.Id), 10);
158
+ if (!isNaN(id) && id > 0) { this.nodes[id] = htmlEl; }
159
+ }
160
+ const elements = doc.querySelectorAll(`[${Constant.Id}]`);
161
+ for (const el of Array.from(elements)) {
162
+ const id = parseInt(el.getAttribute(Constant.Id), 10);
163
+ if (!isNaN(id) && id > 0) {
164
+ this.nodes[id] = el;
165
+ const ha = el.getAttribute(Constant.HashAlpha);
166
+ const hb = el.getAttribute(Constant.HashBeta);
167
+ if (ha) { this.hashMapAlpha[ha] = el as HTMLElement; }
168
+ if (hb) { this.hashMapBeta[hb] = el as HTMLElement; }
169
+ }
170
+ }
171
+ }
172
+
149
173
  public get = (hash) => {
150
174
  if (hash in this.hashMapBeta && this.hashMapBeta[hash].isConnected) {
151
175
  return this.hashMapBeta[hash];
@@ -31,6 +31,13 @@ export class Visualizer {
31
31
  configure: (opts: { excludeClassNames?: string[] }) => void;
32
32
  time: () => number;
33
33
  get: (hash: string) => HTMLElement;
34
+ layout: {
35
+ styleChange: (entry: Layout.StyleSheetEvent) => void;
36
+ customElement: (entry: Layout.CustomElementEvent) => void;
37
+ markup: (event: Layout.DomEvent, useproxy?: LinkHandler) => void;
38
+ };
39
+ mergeForHtml: (decoded: Data.DecodedPayload[]) => MergedPayload;
40
+ shortCircuitRendering: (strategy: ShortCircuitStrategy, domEvent: Layout.DomEvent, hash: string | null) => boolean;
34
41
  }
35
42
 
36
43
  export type ResizeHandler = (width: number, height: number) => void;