@decocms/blocks 8.17.0 → 8.18.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.
Files changed (88) hide show
  1. package/dist/v8/analytics/client.d.ts +48 -0
  2. package/dist/v8/analytics/client.d.ts.map +1 -0
  3. package/dist/v8/analytics/client.js +71 -0
  4. package/dist/v8/analytics/client.js.map +1 -0
  5. package/dist/v8/analytics/runtime/modules/click.d.ts +2 -0
  6. package/dist/v8/analytics/runtime/modules/click.d.ts.map +1 -0
  7. package/dist/v8/analytics/runtime/modules/click.js +48 -0
  8. package/dist/v8/analytics/runtime/modules/click.js.map +1 -0
  9. package/dist/v8/analytics/runtime/modules/commerce.d.ts +2 -0
  10. package/dist/v8/analytics/runtime/modules/commerce.d.ts.map +1 -0
  11. package/dist/v8/analytics/runtime/modules/commerce.js +41 -0
  12. package/dist/v8/analytics/runtime/modules/commerce.js.map +1 -0
  13. package/dist/v8/analytics/runtime/modules/consent.d.ts +33 -0
  14. package/dist/v8/analytics/runtime/modules/consent.d.ts.map +1 -0
  15. package/dist/v8/analytics/runtime/modules/consent.js +154 -0
  16. package/dist/v8/analytics/runtime/modules/consent.js.map +1 -0
  17. package/dist/v8/analytics/runtime/modules/deco.d.ts +2 -0
  18. package/dist/v8/analytics/runtime/modules/deco.d.ts.map +1 -0
  19. package/dist/v8/analytics/runtime/modules/deco.js +209 -0
  20. package/dist/v8/analytics/runtime/modules/deco.js.map +1 -0
  21. package/dist/v8/analytics/runtime/modules/engagement.d.ts +2 -0
  22. package/dist/v8/analytics/runtime/modules/engagement.d.ts.map +1 -0
  23. package/dist/v8/analytics/runtime/modules/engagement.js +128 -0
  24. package/dist/v8/analytics/runtime/modules/engagement.js.map +1 -0
  25. package/dist/v8/analytics/runtime/modules/errors.d.ts +2 -0
  26. package/dist/v8/analytics/runtime/modules/errors.d.ts.map +1 -0
  27. package/dist/v8/analytics/runtime/modules/errors.js +167 -0
  28. package/dist/v8/analytics/runtime/modules/errors.js.map +1 -0
  29. package/dist/v8/analytics/runtime/modules/heatmap.d.ts +2 -0
  30. package/dist/v8/analytics/runtime/modules/heatmap.d.ts.map +1 -0
  31. package/dist/v8/analytics/runtime/modules/heatmap.js +316 -0
  32. package/dist/v8/analytics/runtime/modules/heatmap.js.map +1 -0
  33. package/dist/v8/analytics/runtime/modules/vitals.d.ts +2 -0
  34. package/dist/v8/analytics/runtime/modules/vitals.d.ts.map +1 -0
  35. package/dist/v8/analytics/runtime/modules/vitals.js +119 -0
  36. package/dist/v8/analytics/runtime/modules/vitals.js.map +1 -0
  37. package/dist/v8/analytics/runtime/src/guards.d.ts +10 -0
  38. package/dist/v8/analytics/runtime/src/guards.d.ts.map +1 -0
  39. package/dist/v8/analytics/runtime/src/guards.js +70 -0
  40. package/dist/v8/analytics/runtime/src/guards.js.map +1 -0
  41. package/dist/v8/analytics/runtime/src/index.d.ts +2 -0
  42. package/dist/v8/analytics/runtime/src/index.d.ts.map +1 -0
  43. package/dist/v8/analytics/runtime/src/index.js +562 -0
  44. package/dist/v8/analytics/runtime/src/index.js.map +1 -0
  45. package/dist/v8/analytics/runtime/src/queue.d.ts +15 -0
  46. package/dist/v8/analytics/runtime/src/queue.d.ts.map +1 -0
  47. package/dist/v8/analytics/runtime/src/queue.js +36 -0
  48. package/dist/v8/analytics/runtime/src/queue.js.map +1 -0
  49. package/dist/v8/analytics/runtime/src/trim.d.ts +13 -0
  50. package/dist/v8/analytics/runtime/src/trim.d.ts.map +1 -0
  51. package/dist/v8/analytics/runtime/src/trim.js +38 -0
  52. package/dist/v8/analytics/runtime/src/trim.js.map +1 -0
  53. package/dist/v8/analytics/runtime/view/heat-core.d.ts +69 -0
  54. package/dist/v8/analytics/runtime/view/heat-core.d.ts.map +1 -0
  55. package/dist/v8/analytics/runtime/view/heat-core.js +314 -0
  56. package/dist/v8/analytics/runtime/view/heat-core.js.map +1 -0
  57. package/dist/v8/analytics/runtime/view/view.d.ts +51 -0
  58. package/dist/v8/analytics/runtime/view/view.d.ts.map +1 -0
  59. package/dist/v8/analytics/runtime/view/view.js +525 -0
  60. package/dist/v8/analytics/runtime/view/view.js.map +1 -0
  61. package/dist/v8/analytics/shared/anchor.d.ts +71 -0
  62. package/dist/v8/analytics/shared/anchor.d.ts.map +1 -0
  63. package/dist/v8/analytics/shared/anchor.js +155 -0
  64. package/dist/v8/analytics/shared/anchor.js.map +1 -0
  65. package/dist/v8/analytics/shared/contract.d.ts +294 -0
  66. package/dist/v8/analytics/shared/contract.d.ts.map +1 -0
  67. package/dist/v8/analytics/shared/contract.js +652 -0
  68. package/dist/v8/analytics/shared/contract.js.map +1 -0
  69. package/package.json +6 -1
  70. package/src/v8/analytics/client.ts +110 -0
  71. package/src/v8/analytics/runtime/globals.d.ts +36 -0
  72. package/src/v8/analytics/runtime/modules/click.ts +54 -0
  73. package/src/v8/analytics/runtime/modules/commerce.ts +73 -0
  74. package/src/v8/analytics/runtime/modules/consent.ts +150 -0
  75. package/src/v8/analytics/runtime/modules/deco.ts +207 -0
  76. package/src/v8/analytics/runtime/modules/engagement.ts +140 -0
  77. package/src/v8/analytics/runtime/modules/errors.ts +217 -0
  78. package/src/v8/analytics/runtime/modules/heatmap.ts +360 -0
  79. package/src/v8/analytics/runtime/modules/vitals.ts +128 -0
  80. package/src/v8/analytics/runtime/src/guards.ts +70 -0
  81. package/src/v8/analytics/runtime/src/index.ts +606 -0
  82. package/src/v8/analytics/runtime/src/queue.ts +40 -0
  83. package/src/v8/analytics/runtime/src/trim.ts +39 -0
  84. package/src/v8/analytics/runtime/view/heat-core.ts +335 -0
  85. package/src/v8/analytics/runtime/view/view.ts +596 -0
  86. package/src/v8/analytics/shared/anchor.ts +171 -0
  87. package/src/v8/analytics/shared/contract.ts +691 -0
  88. package/src/v8/analytics/tsconfig.json +14 -0
@@ -0,0 +1,171 @@
1
+ /** Element anchors for heatmaps: the ONE definition of "which element was clicked", shared by
2
+ * the browser runtime (`runtime/modules/heatmap.ts`) and the viewer that paints the heat on a
3
+ * server-rendered snapshot (insights-mcp vendors this file verbatim).
4
+ *
5
+ * Both sides must produce the same hash for the same element, so this file is self-contained:
6
+ * no imports, no globals beyond the DOM node it is handed, nothing that differs between a
7
+ * visitor's browser and a sandboxed iframe. `tests/fixtures/anchor-vectors.json` pins the output;
8
+ * a change to anything below that moves a vector is a breaking change for every heatmap already
9
+ * collected, so it bumps ANCHOR_VERSION and ships in both repos at once.
10
+ *
11
+ * The algorithm, exactly:
12
+ *
13
+ * 1. ANCHOR. From the click target, walk up at most 6 elements (target included) and take the
14
+ * first that matches ACTIONABLE (interactive = true). If none does, repeat the walk and take
15
+ * the first element carrying a `data-fs-*` attribute that is not a page wrapper, stopping at a
16
+ * Deco section (interactive = false). Else the target.
17
+ * A click on the <span> inside "Comprar" counts for the button, which is what a reader expects.
18
+ *
19
+ * 2. ROOT, the first that applies:
20
+ * a. the nearest `section[data-manifest-key]` (Deco CMS section, self included):
21
+ * identity `<manifest key>#<ordinal among sections with the same key, document order>`;
22
+ * b. the OUTERMOST element on the anchor's ancestor chain (self included, `body` excluded)
23
+ * carrying a `data-fs-*` attribute whose component name is not a page wrapper (WRAPPER):
24
+ * identity `fs:<name>#<ordinal among elements carrying that attribute>`. Outermost, not
25
+ * nearest: measured on FILA, New Balance and Umbro (2026-10-26), none of which render a
26
+ * single `data-manifest-key` section, the outermost FastStore component is the
27
+ * section-sized one (`hero-slideshow`, `tabbed-product-shelf`, `desktop-header`), while the
28
+ * nearest is a product card or a link whose ordinal shifts as lazy content loads;
29
+ * c. the nearest ancestor-or-self with an `id` that does not look generated (BAD_ID):
30
+ * identity `#<id>`;
31
+ * d. `body`: identity "" (the wire sends section index -1).
32
+ * `<name>` is the attribute name without `data-fs-`. A `data-fs-*` attribute is chosen as the
33
+ * alphabetically FIRST one on the element, so attribute order never matters.
34
+ *
35
+ * 3. PATH from root (exclusive) to anchor (inclusive), root first, segments joined by `>`:
36
+ * `<localName>` + (`[<first data-fs-* attribute name>]` if any) + `:` + nth-of-type (1-based).
37
+ * Example: `div:2>article[data-fs-product-card]:3>a:1`. Empty when the anchor is the root.
38
+ * Classes, text, href, src and non-root ids are excluded on purpose: classes churn on every
39
+ * Tailwind deploy, and text/href are PII and change daily.
40
+ *
41
+ * 4. HASH: `cyrb53(identity + "|" + path)`, a 53-bit integer (exact in a JS number and in JSON),
42
+ * sent as base36. Collision odds at ~5,000 clickable elements per page: about 1e-9.
43
+ */
44
+ export const ANCHOR_VERSION = 1;
45
+
46
+ export const ACTIONABLE =
47
+ "a,button,input,select,textarea,label,summary,[role=button],[role=link],[role=tab]," +
48
+ '[role=menuitem],[role=option],[role=checkbox],[tabindex]:not([tabindex="-1"])';
49
+
50
+ /** FastStore component names that wrap a whole page rather than one part of it. Umbro's home is
51
+ * `data-fs-home` around every block; taking it as the root would put the whole page in one
52
+ * "section". */
53
+ export const WRAPPER = /^(home|page|layout|content|main|root|wrapper|container|region|grid)$/;
54
+
55
+ /** Ids minted by a framework or a counter: different on every render, so useless as a root. */
56
+ export const BAD_ID = /\d{4,}|^:r|^radix-|^headlessui-|[0-9a-f]{8}|react-aria|[:«»]/;
57
+
58
+ /** cyrb53 (bryc, public domain): a fast 53-bit string hash with good avalanche. */
59
+ export function cyrb53(s: string, seed = 0): number {
60
+ let h1 = 0xdeadbeef ^ seed,
61
+ h2 = 0x41c6ce57 ^ seed;
62
+ for (let i = 0; i < s.length; i++) {
63
+ const ch = s.charCodeAt(i);
64
+ h1 = Math.imul(h1 ^ ch, 2654435761);
65
+ h2 = Math.imul(h2 ^ ch, 1597334677);
66
+ }
67
+ h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
68
+ h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
69
+ return 4294967296 * (2097151 & h2) + (h1 >>> 0);
70
+ }
71
+
72
+ /** The alphabetically first `data-fs-*` attribute name on an element, or "". */
73
+ export function fsAttr(e: Element): string {
74
+ let m = "";
75
+ for (const n of e.getAttributeNames()) if (n.startsWith("data-fs-") && (!m || n < m)) m = n;
76
+ return m;
77
+ }
78
+
79
+ /** Step 1. Returns the anchor and whether it is interactive. */
80
+ export function anchorOf(t: Element): [Element, boolean] {
81
+ let e: Element | null = t;
82
+ for (let i = 0; e && i < 6; e = e.parentElement, i++) if (e.matches(ACTIONABLE)) return [e, true];
83
+ // Never a page wrapper, and never across a Deco section: an <h2> clicked inside a section must
84
+ // not anchor on the `data-fs-home` that wraps every section of the page.
85
+ e = t;
86
+ for (
87
+ let i = 0;
88
+ e && i < 6 && !e.matches("section[data-manifest-key]");
89
+ e = e.parentElement, i++
90
+ ) {
91
+ const f = fsAttr(e);
92
+ if (f && !WRAPPER.test(f.slice(8))) return [e, false];
93
+ }
94
+ return [t, false];
95
+ }
96
+
97
+ const ordinal = (list: NodeListOf<Element>, e: Element, same: (x: Element) => boolean) => {
98
+ let n = 0;
99
+ for (const x of list) {
100
+ if (x === e) return n;
101
+ if (same(x)) n++;
102
+ }
103
+ return n;
104
+ };
105
+
106
+ /** A FastStore component root by step 2b, or "" — exported so a viewer can enumerate roots. */
107
+ export function fsRootName(e: Element): string {
108
+ const a = fsAttr(e);
109
+ return a && !WRAPPER.test(a.slice(8)) && /^[a-z0-9-]+$/.test(a) ? a : "";
110
+ }
111
+
112
+ /** Step 2. Returns the root element (null for body) and its identity. */
113
+ export function rootOf(a: Element): [Element | null, string] {
114
+ const d = a.ownerDocument;
115
+ const s = a.closest("section[data-manifest-key]");
116
+ if (s) {
117
+ const k = s.getAttribute("data-manifest-key")!;
118
+ return [
119
+ s,
120
+ k +
121
+ "#" +
122
+ ordinal(
123
+ d.querySelectorAll("section[data-manifest-key]"),
124
+ s,
125
+ (x) => x.getAttribute("data-manifest-key") === k,
126
+ ),
127
+ ];
128
+ }
129
+ let fs: Element | null = null,
130
+ name = "";
131
+ for (let e: Element | null = a; e && e !== d.body; e = e.parentElement) {
132
+ const n = fsRootName(e);
133
+ if (n) {
134
+ fs = e;
135
+ name = n;
136
+ }
137
+ }
138
+ if (fs)
139
+ return [
140
+ fs,
141
+ "fs:" + name.slice(8) + "#" + ordinal(d.querySelectorAll("[" + name + "]"), fs, () => true),
142
+ ];
143
+ for (let e: Element | null = a; e && e !== d.body; e = e.parentElement) {
144
+ if (e.id && !BAD_ID.test(e.id)) return [e, "#" + e.id];
145
+ }
146
+ return [null, ""];
147
+ }
148
+
149
+ /** Step 3. */
150
+ export function pathOf(root: Element | null, a: Element): string {
151
+ const out: string[] = [];
152
+ for (
153
+ let e: Element | null = a, i = 0;
154
+ e && e !== root && e !== e.ownerDocument.body && i < 64;
155
+ e = e.parentElement, i++
156
+ ) {
157
+ let n = 1;
158
+ for (let s = e.previousElementSibling; s; s = s.previousElementSibling)
159
+ if (s.localName === e.localName) n++;
160
+ const f = fsAttr(e);
161
+ out.push(e.localName + (f ? "[" + f + "]" : "") + ":" + n);
162
+ }
163
+ return out.reverse().join(">");
164
+ }
165
+
166
+ /** Steps 2-4 for an element already chosen as anchor: what the wire carries and what a viewer
167
+ * matches on. `root` is the identity string ("" = body), `el` the base36 hash. */
168
+ export function anchorHash(a: Element): { root: string; el: string; rootEl: Element | null } {
169
+ const [rootEl, root] = rootOf(a);
170
+ return { root, el: cyrb53(root + "|" + pathOf(rootEl, a)).toString(36), rootEl };
171
+ }