@aznabee/freehand-ui 0.1.4 → 0.1.5

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.
@@ -41,7 +41,12 @@ var DEFAULT_OPTIONS = {
41
41
  /** Override the handwriting stack, e.g. a next/font CSS variable. */
42
42
  fontFamily: null,
43
43
  /** Fetch Caveat when the page has not provided it. */
44
- autoLoadFont: true
44
+ autoLoadFont: true,
45
+ /**
46
+ * Overlay stacking order. Omit to mirror the target element's z-index so
47
+ * doodles stay above the annotated element but below modals and other UI.
48
+ */
49
+ zIndex: null
45
50
  };
46
51
  function resolveElement(target) {
47
52
  if (!target) return null;
@@ -134,6 +139,40 @@ function getScrollableAncestors(element) {
134
139
  ancestors.push(window);
135
140
  return ancestors;
136
141
  }
142
+ function resolveOverlayZIndex(element, override) {
143
+ if (override != null) return override;
144
+ const { zIndex, position } = getComputedStyle(element);
145
+ if (zIndex !== "auto") {
146
+ const parsed = Number.parseInt(zIndex, 10);
147
+ if (Number.isFinite(parsed)) return parsed + 1;
148
+ }
149
+ let node = element.parentElement;
150
+ while (node && node !== document.documentElement) {
151
+ const style = getComputedStyle(node);
152
+ if (style.zIndex !== "auto" && style.position !== "static") {
153
+ const parsed = Number.parseInt(style.zIndex, 10);
154
+ if (Number.isFinite(parsed)) return parsed + 1;
155
+ }
156
+ node = node.parentElement;
157
+ }
158
+ return null;
159
+ }
160
+ function insertOverlaySvg(svg, element) {
161
+ const parent = element.parentNode;
162
+ if (!parent) {
163
+ document.body.appendChild(svg);
164
+ return;
165
+ }
166
+ parent.insertBefore(svg, element.nextSibling);
167
+ }
168
+ function syncOverlayStacking(svg, element, zIndexOverride) {
169
+ const zIndex = resolveOverlayZIndex(element, zIndexOverride);
170
+ if (zIndex == null) {
171
+ svg.style.zIndex = "";
172
+ } else {
173
+ svg.style.zIndex = String(zIndex);
174
+ }
175
+ }
137
176
 
138
177
  // src/geometry.js
139
178
  function averageCornerRadius(element) {
@@ -959,7 +998,6 @@ function createOverlaySvg(left, top, width, height) {
959
998
  svg.style.height = `${height}px`;
960
999
  svg.style.pointerEvents = "none";
961
1000
  svg.style.overflow = "visible";
962
- svg.style.zIndex = "2147483646";
963
1001
  return svg;
964
1002
  }
965
1003
 
@@ -1489,7 +1527,8 @@ var DoodleOverlay = class {
1489
1527
  }
1490
1528
  mount() {
1491
1529
  this.svg = createOverlaySvg(0, 0, 0, 0);
1492
- document.body.appendChild(this.svg);
1530
+ insertOverlaySvg(this.svg, this.element);
1531
+ syncOverlayStacking(this.svg, this.element, this.options.zIndex);
1493
1532
  this.resizeObserver = new ResizeObserver(this.onResize);
1494
1533
  this.resizeObserver.observe(this.element);
1495
1534
  if (this.options.children) {
@@ -1547,6 +1586,7 @@ var DoodleOverlay = class {
1547
1586
  );
1548
1587
  const overlayRect = unionRects(absoluteRects, margin);
1549
1588
  clearSvg(this.svg);
1589
+ syncOverlayStacking(this.svg, this.element, this.options.zIndex);
1550
1590
  this.svg.setAttribute("width", String(overlayRect.width));
1551
1591
  this.svg.setAttribute("height", String(overlayRect.height));
1552
1592
  this.svg.setAttribute("viewBox", `0 0 ${overlayRect.width} ${overlayRect.height}`);
@@ -16,7 +16,12 @@ var DEFAULT_OPTIONS = {
16
16
  /** Override the handwriting stack, e.g. a next/font CSS variable. */
17
17
  fontFamily: null,
18
18
  /** Fetch Caveat when the page has not provided it. */
19
- autoLoadFont: true
19
+ autoLoadFont: true,
20
+ /**
21
+ * Overlay stacking order. Omit to mirror the target element's z-index so
22
+ * doodles stay above the annotated element but below modals and other UI.
23
+ */
24
+ zIndex: null
20
25
  };
21
26
  function resolveElement(target) {
22
27
  if (!target) return null;
@@ -109,6 +114,40 @@ function getScrollableAncestors(element) {
109
114
  ancestors.push(window);
110
115
  return ancestors;
111
116
  }
117
+ function resolveOverlayZIndex(element, override) {
118
+ if (override != null) return override;
119
+ const { zIndex, position } = getComputedStyle(element);
120
+ if (zIndex !== "auto") {
121
+ const parsed = Number.parseInt(zIndex, 10);
122
+ if (Number.isFinite(parsed)) return parsed + 1;
123
+ }
124
+ let node = element.parentElement;
125
+ while (node && node !== document.documentElement) {
126
+ const style = getComputedStyle(node);
127
+ if (style.zIndex !== "auto" && style.position !== "static") {
128
+ const parsed = Number.parseInt(style.zIndex, 10);
129
+ if (Number.isFinite(parsed)) return parsed + 1;
130
+ }
131
+ node = node.parentElement;
132
+ }
133
+ return null;
134
+ }
135
+ function insertOverlaySvg(svg, element) {
136
+ const parent = element.parentNode;
137
+ if (!parent) {
138
+ document.body.appendChild(svg);
139
+ return;
140
+ }
141
+ parent.insertBefore(svg, element.nextSibling);
142
+ }
143
+ function syncOverlayStacking(svg, element, zIndexOverride) {
144
+ const zIndex = resolveOverlayZIndex(element, zIndexOverride);
145
+ if (zIndex == null) {
146
+ svg.style.zIndex = "";
147
+ } else {
148
+ svg.style.zIndex = String(zIndex);
149
+ }
150
+ }
112
151
 
113
152
  // src/geometry.js
114
153
  function averageCornerRadius(element) {
@@ -934,7 +973,6 @@ function createOverlaySvg(left, top, width, height) {
934
973
  svg.style.height = `${height}px`;
935
974
  svg.style.pointerEvents = "none";
936
975
  svg.style.overflow = "visible";
937
- svg.style.zIndex = "2147483646";
938
976
  return svg;
939
977
  }
940
978
 
@@ -1464,7 +1502,8 @@ var DoodleOverlay = class {
1464
1502
  }
1465
1503
  mount() {
1466
1504
  this.svg = createOverlaySvg(0, 0, 0, 0);
1467
- document.body.appendChild(this.svg);
1505
+ insertOverlaySvg(this.svg, this.element);
1506
+ syncOverlayStacking(this.svg, this.element, this.options.zIndex);
1468
1507
  this.resizeObserver = new ResizeObserver(this.onResize);
1469
1508
  this.resizeObserver.observe(this.element);
1470
1509
  if (this.options.children) {
@@ -1522,6 +1561,7 @@ var DoodleOverlay = class {
1522
1561
  );
1523
1562
  const overlayRect = unionRects(absoluteRects, margin);
1524
1563
  clearSvg(this.svg);
1564
+ syncOverlayStacking(this.svg, this.element, this.options.zIndex);
1525
1565
  this.svg.setAttribute("width", String(overlayRect.width));
1526
1566
  this.svg.setAttribute("height", String(overlayRect.height));
1527
1567
  this.svg.setAttribute("viewBox", `0 0 ${overlayRect.width} ${overlayRect.height}`);
package/dist/index.d.ts CHANGED
@@ -99,6 +99,11 @@ export interface DoodleOptions {
99
99
  * handwriting fallbacks.
100
100
  */
101
101
  autoLoadFont?: boolean;
102
+ /**
103
+ * Overlay stacking order. Omit to follow the target element's z-index so
104
+ * doodles stay above the annotated element but below modals and other UI.
105
+ */
106
+ zIndex?: number | null;
102
107
  }
103
108
 
104
109
  export interface DoodleInstance {
package/dist/react.cjs CHANGED
@@ -46,7 +46,12 @@ var DEFAULT_OPTIONS = {
46
46
  /** Override the handwriting stack, e.g. a next/font CSS variable. */
47
47
  fontFamily: null,
48
48
  /** Fetch Caveat when the page has not provided it. */
49
- autoLoadFont: true
49
+ autoLoadFont: true,
50
+ /**
51
+ * Overlay stacking order. Omit to mirror the target element's z-index so
52
+ * doodles stay above the annotated element but below modals and other UI.
53
+ */
54
+ zIndex: null
50
55
  };
51
56
  function resolveElement(target) {
52
57
  if (!target) return null;
@@ -139,6 +144,40 @@ function getScrollableAncestors(element) {
139
144
  ancestors.push(window);
140
145
  return ancestors;
141
146
  }
147
+ function resolveOverlayZIndex(element, override) {
148
+ if (override != null) return override;
149
+ const { zIndex, position } = getComputedStyle(element);
150
+ if (zIndex !== "auto") {
151
+ const parsed = Number.parseInt(zIndex, 10);
152
+ if (Number.isFinite(parsed)) return parsed + 1;
153
+ }
154
+ let node = element.parentElement;
155
+ while (node && node !== document.documentElement) {
156
+ const style = getComputedStyle(node);
157
+ if (style.zIndex !== "auto" && style.position !== "static") {
158
+ const parsed = Number.parseInt(style.zIndex, 10);
159
+ if (Number.isFinite(parsed)) return parsed + 1;
160
+ }
161
+ node = node.parentElement;
162
+ }
163
+ return null;
164
+ }
165
+ function insertOverlaySvg(svg, element) {
166
+ const parent = element.parentNode;
167
+ if (!parent) {
168
+ document.body.appendChild(svg);
169
+ return;
170
+ }
171
+ parent.insertBefore(svg, element.nextSibling);
172
+ }
173
+ function syncOverlayStacking(svg, element, zIndexOverride) {
174
+ const zIndex = resolveOverlayZIndex(element, zIndexOverride);
175
+ if (zIndex == null) {
176
+ svg.style.zIndex = "";
177
+ } else {
178
+ svg.style.zIndex = String(zIndex);
179
+ }
180
+ }
142
181
 
143
182
  // src/geometry.js
144
183
  function averageCornerRadius(element) {
@@ -964,7 +1003,6 @@ function createOverlaySvg(left, top, width, height) {
964
1003
  svg.style.height = `${height}px`;
965
1004
  svg.style.pointerEvents = "none";
966
1005
  svg.style.overflow = "visible";
967
- svg.style.zIndex = "2147483646";
968
1006
  return svg;
969
1007
  }
970
1008
 
@@ -1494,7 +1532,8 @@ var DoodleOverlay = class {
1494
1532
  }
1495
1533
  mount() {
1496
1534
  this.svg = createOverlaySvg(0, 0, 0, 0);
1497
- document.body.appendChild(this.svg);
1535
+ insertOverlaySvg(this.svg, this.element);
1536
+ syncOverlayStacking(this.svg, this.element, this.options.zIndex);
1498
1537
  this.resizeObserver = new ResizeObserver(this.onResize);
1499
1538
  this.resizeObserver.observe(this.element);
1500
1539
  if (this.options.children) {
@@ -1552,6 +1591,7 @@ var DoodleOverlay = class {
1552
1591
  );
1553
1592
  const overlayRect = unionRects(absoluteRects, margin);
1554
1593
  clearSvg(this.svg);
1594
+ syncOverlayStacking(this.svg, this.element, this.options.zIndex);
1555
1595
  this.svg.setAttribute("width", String(overlayRect.width));
1556
1596
  this.svg.setAttribute("height", String(overlayRect.height));
1557
1597
  this.svg.setAttribute("viewBox", `0 0 ${overlayRect.width} ${overlayRect.height}`);
package/dist/react.js CHANGED
@@ -29,7 +29,12 @@ var DEFAULT_OPTIONS = {
29
29
  /** Override the handwriting stack, e.g. a next/font CSS variable. */
30
30
  fontFamily: null,
31
31
  /** Fetch Caveat when the page has not provided it. */
32
- autoLoadFont: true
32
+ autoLoadFont: true,
33
+ /**
34
+ * Overlay stacking order. Omit to mirror the target element's z-index so
35
+ * doodles stay above the annotated element but below modals and other UI.
36
+ */
37
+ zIndex: null
33
38
  };
34
39
  function resolveElement(target) {
35
40
  if (!target) return null;
@@ -122,6 +127,40 @@ function getScrollableAncestors(element) {
122
127
  ancestors.push(window);
123
128
  return ancestors;
124
129
  }
130
+ function resolveOverlayZIndex(element, override) {
131
+ if (override != null) return override;
132
+ const { zIndex, position } = getComputedStyle(element);
133
+ if (zIndex !== "auto") {
134
+ const parsed = Number.parseInt(zIndex, 10);
135
+ if (Number.isFinite(parsed)) return parsed + 1;
136
+ }
137
+ let node = element.parentElement;
138
+ while (node && node !== document.documentElement) {
139
+ const style = getComputedStyle(node);
140
+ if (style.zIndex !== "auto" && style.position !== "static") {
141
+ const parsed = Number.parseInt(style.zIndex, 10);
142
+ if (Number.isFinite(parsed)) return parsed + 1;
143
+ }
144
+ node = node.parentElement;
145
+ }
146
+ return null;
147
+ }
148
+ function insertOverlaySvg(svg, element) {
149
+ const parent = element.parentNode;
150
+ if (!parent) {
151
+ document.body.appendChild(svg);
152
+ return;
153
+ }
154
+ parent.insertBefore(svg, element.nextSibling);
155
+ }
156
+ function syncOverlayStacking(svg, element, zIndexOverride) {
157
+ const zIndex = resolveOverlayZIndex(element, zIndexOverride);
158
+ if (zIndex == null) {
159
+ svg.style.zIndex = "";
160
+ } else {
161
+ svg.style.zIndex = String(zIndex);
162
+ }
163
+ }
125
164
 
126
165
  // src/geometry.js
127
166
  function averageCornerRadius(element) {
@@ -947,7 +986,6 @@ function createOverlaySvg(left, top, width, height) {
947
986
  svg.style.height = `${height}px`;
948
987
  svg.style.pointerEvents = "none";
949
988
  svg.style.overflow = "visible";
950
- svg.style.zIndex = "2147483646";
951
989
  return svg;
952
990
  }
953
991
 
@@ -1477,7 +1515,8 @@ var DoodleOverlay = class {
1477
1515
  }
1478
1516
  mount() {
1479
1517
  this.svg = createOverlaySvg(0, 0, 0, 0);
1480
- document.body.appendChild(this.svg);
1518
+ insertOverlaySvg(this.svg, this.element);
1519
+ syncOverlayStacking(this.svg, this.element, this.options.zIndex);
1481
1520
  this.resizeObserver = new ResizeObserver(this.onResize);
1482
1521
  this.resizeObserver.observe(this.element);
1483
1522
  if (this.options.children) {
@@ -1535,6 +1574,7 @@ var DoodleOverlay = class {
1535
1574
  );
1536
1575
  const overlayRect = unionRects(absoluteRects, margin);
1537
1576
  clearSvg(this.svg);
1577
+ syncOverlayStacking(this.svg, this.element, this.options.zIndex);
1538
1578
  this.svg.setAttribute("width", String(overlayRect.width));
1539
1579
  this.svg.setAttribute("height", String(overlayRect.height));
1540
1580
  this.svg.setAttribute("viewBox", `0 0 ${overlayRect.width} ${overlayRect.height}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aznabee/freehand-ui",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Wrap any existing web element with a beautiful, responsive, hand-drawn doodle layer",
5
5
  "type": "module",
6
6
  "main": "./dist/freehand-ui.cjs",