@mrpelz/uikit-ish 7.13.1 → 7.26.2

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 (276) hide show
  1. package/dist/components/accordion/style.css +1 -1
  2. package/dist/components/action-sheet/main.d.ts.map +1 -1
  3. package/dist/components/action-sheet/main.js +9 -6
  4. package/dist/components/action-sheet/main.js.map +1 -1
  5. package/dist/components/action-sheet/props.d.ts +2 -1
  6. package/dist/components/action-sheet/props.d.ts.map +1 -1
  7. package/dist/components/alert/main.d.ts.map +1 -1
  8. package/dist/components/alert/main.js +12 -4
  9. package/dist/components/alert/main.js.map +1 -1
  10. package/dist/components/alert/props.d.ts +2 -1
  11. package/dist/components/alert/props.d.ts.map +1 -1
  12. package/dist/components/alert/style.css +27 -5
  13. package/dist/components/button/main.js +1 -1
  14. package/dist/components/button/main.js.map +1 -1
  15. package/dist/components/button/props.d.ts +3 -2
  16. package/dist/components/button/props.d.ts.map +1 -1
  17. package/dist/components/button/style.css +6 -17
  18. package/dist/components/card/main.d.ts +53 -0
  19. package/dist/components/card/main.d.ts.map +1 -0
  20. package/dist/components/card/main.js +286 -0
  21. package/dist/components/card/main.js.map +1 -0
  22. package/dist/components/card/props.d.ts +83 -0
  23. package/dist/components/card/props.d.ts.map +1 -0
  24. package/dist/components/card/props.js +2 -0
  25. package/dist/components/card/props.js.map +1 -0
  26. package/dist/components/card/style.css +900 -0
  27. package/dist/components/collapsible/style.css +1 -1
  28. package/dist/components/color-picker/main.d.ts.map +1 -1
  29. package/dist/components/color-picker/main.js +20 -33
  30. package/dist/components/color-picker/main.js.map +1 -1
  31. package/dist/components/color-picker/style.css +4 -23
  32. package/dist/components/contextual-menu/main.d.ts +6 -2
  33. package/dist/components/contextual-menu/main.d.ts.map +1 -1
  34. package/dist/components/contextual-menu/main.js +67 -43
  35. package/dist/components/contextual-menu/main.js.map +1 -1
  36. package/dist/components/contextual-menu/props.d.ts +2 -1
  37. package/dist/components/contextual-menu/props.d.ts.map +1 -1
  38. package/dist/components/contextual-menu/style.css +64 -2
  39. package/dist/components/control-cards/main.d.ts +49 -0
  40. package/dist/components/control-cards/main.d.ts.map +1 -0
  41. package/dist/components/control-cards/main.js +835 -0
  42. package/dist/components/control-cards/main.js.map +1 -0
  43. package/dist/components/control-cards/props.d.ts +409 -0
  44. package/dist/components/control-cards/props.d.ts.map +1 -0
  45. package/dist/components/control-cards/props.js +2 -0
  46. package/dist/components/control-cards/props.js.map +1 -0
  47. package/dist/components/control-cards/style.css +492 -0
  48. package/dist/components/date-picker/main.d.ts.map +1 -1
  49. package/dist/components/date-picker/main.js +3 -2
  50. package/dist/components/date-picker/main.js.map +1 -1
  51. package/dist/components/date-picker/style.css +1 -1
  52. package/dist/components/drawer/style.css +6 -0
  53. package/dist/components/edit-menu/main.d.ts +2 -1
  54. package/dist/components/edit-menu/main.d.ts.map +1 -1
  55. package/dist/components/edit-menu/main.js +8 -4
  56. package/dist/components/edit-menu/main.js.map +1 -1
  57. package/dist/components/glass/backdrop.d.ts +75 -0
  58. package/dist/components/glass/backdrop.d.ts.map +1 -0
  59. package/dist/components/glass/backdrop.js +608 -0
  60. package/dist/components/glass/backdrop.js.map +1 -0
  61. package/dist/components/glass/gradient.d.ts +17 -0
  62. package/dist/components/glass/gradient.d.ts.map +1 -0
  63. package/dist/components/glass/gradient.js +233 -0
  64. package/dist/components/glass/gradient.js.map +1 -0
  65. package/dist/components/glass/main.d.ts +60 -6
  66. package/dist/components/glass/main.d.ts.map +1 -1
  67. package/dist/components/glass/main.js +100 -122
  68. package/dist/components/glass/main.js.map +1 -1
  69. package/dist/components/glass/marker.d.ts +66 -0
  70. package/dist/components/glass/marker.d.ts.map +1 -0
  71. package/dist/components/glass/marker.js +268 -0
  72. package/dist/components/glass/marker.js.map +1 -0
  73. package/dist/components/glass/props.d.ts +33 -7
  74. package/dist/components/glass/props.d.ts.map +1 -1
  75. package/dist/components/glass/style.css +139 -75
  76. package/dist/components/grid/dashes.d.ts +15 -0
  77. package/dist/components/grid/dashes.d.ts.map +1 -0
  78. package/dist/components/grid/dashes.js +37 -0
  79. package/dist/components/grid/dashes.js.map +1 -0
  80. package/dist/components/grid/edit.d.ts +11 -0
  81. package/dist/components/grid/edit.d.ts.map +1 -0
  82. package/dist/components/grid/edit.js +1066 -0
  83. package/dist/components/grid/edit.js.map +1 -0
  84. package/dist/components/grid/handle.d.ts +123 -0
  85. package/dist/components/grid/handle.d.ts.map +1 -0
  86. package/dist/components/grid/handle.js +194 -0
  87. package/dist/components/grid/handle.js.map +1 -0
  88. package/dist/components/grid/icons.d.ts +40 -0
  89. package/dist/components/grid/icons.d.ts.map +1 -0
  90. package/dist/components/grid/icons.js +140 -0
  91. package/dist/components/grid/icons.js.map +1 -0
  92. package/dist/components/grid/layout.d.ts +111 -0
  93. package/dist/components/grid/layout.d.ts.map +1 -0
  94. package/dist/components/grid/layout.js +1257 -0
  95. package/dist/components/grid/layout.js.map +1 -0
  96. package/dist/components/grid/main.d.ts +63 -0
  97. package/dist/components/grid/main.d.ts.map +1 -0
  98. package/dist/components/grid/main.js +1894 -0
  99. package/dist/components/grid/main.js.map +1 -0
  100. package/dist/components/grid/overlay.d.ts +24 -0
  101. package/dist/components/grid/overlay.d.ts.map +1 -0
  102. package/dist/components/grid/overlay.js +312 -0
  103. package/dist/components/grid/overlay.js.map +1 -0
  104. package/dist/components/grid/plan.d.ts +78 -0
  105. package/dist/components/grid/plan.d.ts.map +1 -0
  106. package/dist/components/grid/plan.js +249 -0
  107. package/dist/components/grid/plan.js.map +1 -0
  108. package/dist/components/grid/props.d.ts +509 -0
  109. package/dist/components/grid/props.d.ts.map +1 -0
  110. package/dist/components/grid/props.js +2 -0
  111. package/dist/components/grid/props.js.map +1 -0
  112. package/dist/components/grid/reshape.d.ts +60 -0
  113. package/dist/components/grid/reshape.d.ts.map +1 -0
  114. package/dist/components/grid/reshape.js +214 -0
  115. package/dist/components/grid/reshape.js.map +1 -0
  116. package/dist/components/grid/style.css +1293 -0
  117. package/dist/components/header/main.d.ts.map +1 -1
  118. package/dist/components/header/main.js +97 -10
  119. package/dist/components/header/main.js.map +1 -1
  120. package/dist/components/header/props.d.ts +2 -2
  121. package/dist/components/header/props.d.ts.map +1 -1
  122. package/dist/components/header/style.css +28 -43
  123. package/dist/components/index.d.ts +10 -6
  124. package/dist/components/index.d.ts.map +1 -1
  125. package/dist/components/index.js +5 -1
  126. package/dist/components/index.js.map +1 -1
  127. package/dist/components/island/main.d.ts +2 -2
  128. package/dist/components/island/main.d.ts.map +1 -1
  129. package/dist/components/island/main.js +193 -41
  130. package/dist/components/island/main.js.map +1 -1
  131. package/dist/components/island/props.d.ts +4 -2
  132. package/dist/components/island/props.d.ts.map +1 -1
  133. package/dist/components/island/style.css +50 -3
  134. package/dist/components/layout/main.d.ts +3 -6
  135. package/dist/components/layout/main.d.ts.map +1 -1
  136. package/dist/components/layout/main.js +225 -56
  137. package/dist/components/layout/main.js.map +1 -1
  138. package/dist/components/layout/props.d.ts +43 -2
  139. package/dist/components/layout/props.d.ts.map +1 -1
  140. package/dist/components/layout/style.css +84 -23
  141. package/dist/components/list/main.d.ts +3 -3
  142. package/dist/components/list/main.d.ts.map +1 -1
  143. package/dist/components/list/main.js +90 -19
  144. package/dist/components/list/main.js.map +1 -1
  145. package/dist/components/list/props.d.ts +20 -0
  146. package/dist/components/list/props.d.ts.map +1 -1
  147. package/dist/components/list/reorder.d.ts +16 -2
  148. package/dist/components/list/reorder.d.ts.map +1 -1
  149. package/dist/components/list/reorder.js.map +1 -1
  150. package/dist/components/list/style.css +60 -3
  151. package/dist/components/menu/main.d.ts +9 -5
  152. package/dist/components/menu/main.d.ts.map +1 -1
  153. package/dist/components/menu/main.js +87 -9
  154. package/dist/components/menu/main.js.map +1 -1
  155. package/dist/components/menu/props.d.ts +14 -0
  156. package/dist/components/menu/props.d.ts.map +1 -1
  157. package/dist/components/menu/style.css +3 -1
  158. package/dist/components/page/main.d.ts.map +1 -1
  159. package/dist/components/page/main.js +6 -3
  160. package/dist/components/page/main.js.map +1 -1
  161. package/dist/components/page/props.d.ts +3 -2
  162. package/dist/components/page/props.d.ts.map +1 -1
  163. package/dist/components/page/style.css +8 -4
  164. package/dist/components/page-control/props.d.ts +3 -3
  165. package/dist/components/popover/main.d.ts +10 -4
  166. package/dist/components/popover/main.d.ts.map +1 -1
  167. package/dist/components/popover/main.js +30 -19
  168. package/dist/components/popover/main.js.map +1 -1
  169. package/dist/components/popover/props.d.ts +2 -0
  170. package/dist/components/popover/props.d.ts.map +1 -1
  171. package/dist/components/popover/style.css +6 -2
  172. package/dist/components/progress/style.css +2 -2
  173. package/dist/components/roll/main.d.ts.map +1 -1
  174. package/dist/components/roll/main.js +5 -3
  175. package/dist/components/roll/main.js.map +1 -1
  176. package/dist/components/segmented/main.d.ts.map +1 -1
  177. package/dist/components/segmented/main.js +4 -4
  178. package/dist/components/segmented/main.js.map +1 -1
  179. package/dist/components/segmented/props.d.ts +5 -2
  180. package/dist/components/segmented/props.d.ts.map +1 -1
  181. package/dist/components/segmented/style.css +1 -1
  182. package/dist/components/settings/main.d.ts +13 -0
  183. package/dist/components/settings/main.d.ts.map +1 -1
  184. package/dist/components/settings/main.js +16 -0
  185. package/dist/components/settings/main.js.map +1 -1
  186. package/dist/components/settings/props.d.ts +1 -0
  187. package/dist/components/settings/props.d.ts.map +1 -1
  188. package/dist/components/sheet/main.d.ts.map +1 -1
  189. package/dist/components/sheet/main.js +156 -45
  190. package/dist/components/sheet/main.js.map +1 -1
  191. package/dist/components/sheet/props.d.ts +4 -2
  192. package/dist/components/sheet/props.d.ts.map +1 -1
  193. package/dist/components/sheet/snap.d.ts +54 -0
  194. package/dist/components/sheet/snap.d.ts.map +1 -1
  195. package/dist/components/sheet/snap.js +253 -23
  196. package/dist/components/sheet/snap.js.map +1 -1
  197. package/dist/components/sheet/style.css +126 -20
  198. package/dist/components/sidebar/main.d.ts +2 -1
  199. package/dist/components/sidebar/main.d.ts.map +1 -1
  200. package/dist/components/sidebar/main.js +18 -6
  201. package/dist/components/sidebar/main.js.map +1 -1
  202. package/dist/components/sidebar/props.d.ts +2 -1
  203. package/dist/components/sidebar/props.d.ts.map +1 -1
  204. package/dist/components/sidebar/style.css +78 -0
  205. package/dist/components/slider/main.d.ts.map +1 -1
  206. package/dist/components/slider/main.js +51 -9
  207. package/dist/components/slider/main.js.map +1 -1
  208. package/dist/components/slider/props.d.ts +1 -0
  209. package/dist/components/slider/props.d.ts.map +1 -1
  210. package/dist/components/slider/style.css +9 -0
  211. package/dist/components/switch/main.d.ts.map +1 -1
  212. package/dist/components/switch/main.js +4 -2
  213. package/dist/components/switch/main.js.map +1 -1
  214. package/dist/components/symbol/main.d.ts.map +1 -1
  215. package/dist/components/symbol/main.js +5 -1
  216. package/dist/components/symbol/main.js.map +1 -1
  217. package/dist/components/symbol/props.d.ts +10 -0
  218. package/dist/components/symbol/props.d.ts.map +1 -1
  219. package/dist/components/symbol/style.css +21 -3
  220. package/dist/components/tab-bar/main.d.ts.map +1 -1
  221. package/dist/components/tab-bar/main.js +8 -5
  222. package/dist/components/tab-bar/main.js.map +1 -1
  223. package/dist/components/tab-bar/props.d.ts +16 -12
  224. package/dist/components/tab-bar/props.d.ts.map +1 -1
  225. package/dist/components/tab-bar/style.css +3 -9
  226. package/dist/components/text-field/main.d.ts.map +1 -1
  227. package/dist/components/text-field/main.js +6 -3
  228. package/dist/components/text-field/main.js.map +1 -1
  229. package/dist/components/text-field/style.css +1 -1
  230. package/dist/components/toolbar/main.js +1 -1
  231. package/dist/components/toolbar/main.js.map +1 -1
  232. package/dist/components/toolbar/props.d.ts +3 -3
  233. package/dist/components/toolbar/style.css +1 -1
  234. package/dist/components/tooltip/main.d.ts +6 -1
  235. package/dist/components/tooltip/main.d.ts.map +1 -1
  236. package/dist/components/tooltip/main.js +13 -7
  237. package/dist/components/tooltip/main.js.map +1 -1
  238. package/dist/components/utils/main.d.ts +31 -2
  239. package/dist/components/utils/main.d.ts.map +1 -1
  240. package/dist/components/utils/main.js +60 -3
  241. package/dist/components/utils/main.js.map +1 -1
  242. package/dist/components/viewport/current.d.ts +15 -0
  243. package/dist/components/viewport/current.d.ts.map +1 -0
  244. package/dist/components/viewport/current.js +74 -0
  245. package/dist/components/viewport/current.js.map +1 -0
  246. package/dist/components/viewport/edge-effect.d.ts.map +1 -1
  247. package/dist/components/viewport/edge-effect.js +52 -24
  248. package/dist/components/viewport/edge-effect.js.map +1 -1
  249. package/dist/components/viewport/edge.d.ts +7 -4
  250. package/dist/components/viewport/edge.d.ts.map +1 -1
  251. package/dist/components/viewport/edge.js +21 -7
  252. package/dist/components/viewport/edge.js.map +1 -1
  253. package/dist/components/viewport/focus-scroll.d.ts +21 -0
  254. package/dist/components/viewport/focus-scroll.d.ts.map +1 -0
  255. package/dist/components/viewport/focus-scroll.js +272 -0
  256. package/dist/components/viewport/focus-scroll.js.map +1 -0
  257. package/dist/components/viewport/input.d.ts +39 -1
  258. package/dist/components/viewport/input.d.ts.map +1 -1
  259. package/dist/components/viewport/input.js +122 -13
  260. package/dist/components/viewport/input.js.map +1 -1
  261. package/dist/components/viewport/main.d.ts +16 -1
  262. package/dist/components/viewport/main.d.ts.map +1 -1
  263. package/dist/components/viewport/main.js +243 -49
  264. package/dist/components/viewport/main.js.map +1 -1
  265. package/dist/components/viewport/padding.d.ts +1 -1
  266. package/dist/components/viewport/padding.d.ts.map +1 -1
  267. package/dist/components/viewport/padding.js +2 -2
  268. package/dist/components/viewport/props.d.ts +12 -2
  269. package/dist/components/viewport/props.d.ts.map +1 -1
  270. package/dist/components/viewport/status-bar.d.ts +9 -0
  271. package/dist/components/viewport/status-bar.d.ts.map +1 -0
  272. package/dist/components/viewport/status-bar.js +131 -0
  273. package/dist/components/viewport/status-bar.js.map +1 -0
  274. package/dist/components/viewport/style.css +62 -5
  275. package/dist/styles.css +123 -198
  276. package/package.json +5 -4
@@ -0,0 +1,1257 @@
1
+ import { useLayoutEffect, useRef } from 'react';
2
+ import { reducedMotionOf } from '../utils/main.js';
3
+ // A grid's layout (see main.tsx): its columns and unit for a width, its
4
+ // breaks placed while editing, its items gliding as it changes.
5
+ /** A width's unit at some columns. */
6
+ export const unitOf = (width, gap, columns) => Math.max(0, (width - (columns - 1) * gap) / columns);
7
+ /**
8
+ * A unit's range: from `min` to `max`, stretched to take in `target` (one
9
+ * aimed for outside them still aimed for).
10
+ */
11
+ export const unitRangeOf = (min, target, max) => [Math.min(min, target), Math.max(max, target)];
12
+ /**
13
+ * The columns and unit for a width (see the top): the columns whose unit is
14
+ * in range (see `unitRangeOf`) and nearest `target`; none in range, those
15
+ * whose unit is nearest it. Never fewer than `minColumns` (its units
16
+ * shrinking below the range then).
17
+ */
18
+ export const layoutOf = (width, gap, min, target, max, minColumns) => {
19
+ const [low, high] = unitRangeOf(min, target, max);
20
+ const fit = (unit) => Math.max(1, Math.floor((width + gap) / (unit + gap)));
21
+ // (How far a unit is from the range, then from the target.)
22
+ const missOf = (unit) => [Math.max(0, low - unit, unit - high), Math.abs(unit - target)];
23
+ let columns = 1;
24
+ let best;
25
+ for (let count = Math.max(1, fit(high) - 1); count <= fit(low) + 1; count += 1) {
26
+ const miss = missOf(unitOf(width, gap, count));
27
+ if (best &&
28
+ (miss[0] > best[0] || (miss[0] === best[0] && miss[1] >= best[1]))) {
29
+ continue;
30
+ }
31
+ best = miss;
32
+ columns = count;
33
+ }
34
+ columns = Math.max(columns, minColumns);
35
+ return { columns, unit: unitOf(width, gap, columns) };
36
+ };
37
+ export const reflowDuration = 300;
38
+ export const reflowEasing = 'cubic-bezier(0.32, 0.72, 0, 1)';
39
+ // (A tile in its area too (see main.tsx): re-centered in it as it's resized,
40
+ // gliding there, within its cell, carried by it.)
41
+ // (Not a break: drawn where it's placed at once (its shape by its row's
42
+ // layout, see `placeBreaks`), not gliding apart from it.)
43
+ const glidingSelector = ':scope > [data-grid-part="section"], :scope [data-grid-part="item"], :scope [data-grid-part="spacer"], :scope [data-grid-part="body"]';
44
+ /** Its own children in the order they're shown (CSS `order`, else DOM). */
45
+ const shownOrder = (container) => Array.from(container.children)
46
+ .filter((element) => element instanceof HTMLElement)
47
+ .map((element, index) => ({
48
+ element,
49
+ index,
50
+ order: Number.parseInt(element.style.order || '0', 10) || 0,
51
+ }))
52
+ .toSorted((a, b) => a.order - b.order || a.index - b.index)
53
+ .map(({ element }) => element);
54
+ /** A break, or a break to be (a dragged cell's, see edit.ts). */
55
+ const isBreak = (element) => element.dataset.gridPart === 'break' ||
56
+ Object.hasOwn(element.dataset, 'gridBreak');
57
+ /** A break's rows (see `Break`). */
58
+ const rowsOf = (element) => Number.parseInt(element.dataset.gridRows ?? '1', 10) || 1;
59
+ /**
60
+ * Its fillers: what keeps the rows below a break of more than one row
61
+ * empty (see `placeBreaks`), right after it (in the DOM, in the order
62
+ * shown).
63
+ */
64
+ const fills = new WeakMap();
65
+ /** A break's fillers (none: none). */
66
+ export const fillsOf = (element) => fills.get(element) ?? [];
67
+ /** A style property set (unset: `undefined`), only if it changes. */
68
+ const setStyle = (element, property, value) => {
69
+ if (value === undefined) {
70
+ if (element.style.getPropertyValue(property)) {
71
+ element.style.removeProperty(property);
72
+ }
73
+ }
74
+ else if (element.style.getPropertyValue(property) !== value) {
75
+ element.style.setProperty(property, value);
76
+ }
77
+ };
78
+ /** A grid's measures (see `Metrics`), read off its root. */
79
+ export const metricsOf = (element) => {
80
+ const root = element.closest('.uikit-grid-root') ?? element;
81
+ const styles = getComputedStyle(root);
82
+ const value = (property, fallback) => Number.parseFloat(styles.getPropertyValue(property)) || fallback;
83
+ const unit = value('--uikit-grid-unit', 110);
84
+ return {
85
+ column: value('--uikit-grid-column', unit),
86
+ columns: value('--uikit-grid-columns', 1),
87
+ end: value('--uikit-grid-end', 0),
88
+ gap: value('--uikit-grid-gap', 0),
89
+ maxRows: value('--uikit-grid-max-rows', 3),
90
+ unit,
91
+ };
92
+ };
93
+ /**
94
+ * A full width's part of the end-of-line column, editing (see
95
+ * `fullClipOf`): its first row's upper half (px, as tall), the rest of it
96
+ * a break's after it (see `breakPlace`).
97
+ */
98
+ const fullHalfOf = ({ gap, unit }) => (unit - gap) / 2;
99
+ const rectOf = (element) => ({
100
+ bottom: element.offsetTop + element.offsetHeight,
101
+ left: element.offsetLeft,
102
+ right: element.offsetLeft + element.offsetWidth,
103
+ top: element.offsetTop,
104
+ });
105
+ /** An SVG mask's image (a CSS `url()`): its paths, filled or outlined. */
106
+ const maskOf = (width, height, paths) => {
107
+ const size = `width="${String(width)}" height="${String(height)}" viewBox="0 0 ${String(width)} ${String(height)}"`;
108
+ const inner = paths
109
+ .map(([path, paint]) => `<path d="${path}" ${paint}/>`)
110
+ .join('');
111
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" ${size}>${inner}</svg>`;
112
+ return `url("data:image/svg+xml,${encodeURIComponent(svg)}")`;
113
+ };
114
+ /**
115
+ * A break's shape (see `placeIn`, the CSS), from its first row's start
116
+ * (`from` columns before it) to the grid's end (through its end-of-line
117
+ * column, while editing): its first rows (`stem`, one by default) from
118
+ * where it starts (`top` px down: after a full width, below its part of
119
+ * that column), its rows below from their start, every corner rounded
120
+ * (the inner one too). Mirrored when right to left. An SVG path (px), for
121
+ * a `clip-path` (drawn at once, no image to decode) or a mask.
122
+ */
123
+ export const breakPath = ({ column, gap, unit }, { from, isRtl, radius, rows, stem = 1, top = 0, width, }) => {
124
+ const pitch = unit + gap;
125
+ const height = rows * pitch - gap;
126
+ const start = from * (column + gap);
127
+ const isStem = rows <= stem || start === 0;
128
+ const head = start > 0 ? top : 0;
129
+ const below = stem * pitch;
130
+ // (Its corners no rounder than its narrowest part: a first row only in
131
+ // its end-of-line column, too; its part there, below a full width's.)
132
+ const r = Math.min(radius, Math.min(column, unit) / 2, start > 0 ? (width - start) / 2 : Number.POSITIVE_INFINITY, ((isStem ? height : below - gap) - head) / 2);
133
+ const x = (value) => String(isRtl ? width - value : value);
134
+ const y = String;
135
+ const arc = (sweep, ax, ay) => `A${y(r)} ${y(r)} 0 0 ${String(isRtl ? 1 - sweep : sweep)} ${x(ax)} ${y(ay)}`;
136
+ const box = (left) => [
137
+ `M${x(left + r)} ${y(head)}H${x(width - r)}`,
138
+ arc(1, width, head + r),
139
+ `V${y(height - r)}`,
140
+ arc(1, width - r, height),
141
+ `H${x(left + r)}`,
142
+ arc(1, left, height - r),
143
+ `V${y(head + r)}`,
144
+ arc(1, left + r, head),
145
+ 'Z',
146
+ ].join('');
147
+ const path = isStem
148
+ ? box(rows <= stem ? start : 0)
149
+ : [
150
+ `M${x(start + r)} ${y(head)}H${x(width - r)}`,
151
+ arc(1, width, head + r),
152
+ `V${y(height - r)}`,
153
+ arc(1, width - r, height),
154
+ `H${x(r)}`,
155
+ arc(1, 0, height - r),
156
+ `V${y(below + r)}`,
157
+ arc(1, r, below),
158
+ `H${x(start - r)}`,
159
+ arc(0, start, below - r),
160
+ `V${y(head + r)}`,
161
+ arc(1, start + r, head),
162
+ 'Z',
163
+ ].join('');
164
+ return path;
165
+ };
166
+ /**
167
+ * A break's resize outline at some rows (see main.tsx, the CSS): its shape
168
+ * (see `breakPath`) as it'd be, through the end-of-line column, filled
169
+ * faintly and edged inside (a mask); where it goes from the break's own
170
+ * box (px).
171
+ */
172
+ export const breakOutlineOf = (element, rows) => {
173
+ const container = element.parentElement;
174
+ const metrics = metricsOf(element);
175
+ const styles = getComputedStyle(element);
176
+ const isNone = Object.hasOwn(element.dataset, 'gridBreakNone');
177
+ // (Its rows in the end-of-line column first (see `breakPlace`): after a
178
+ // full width, below its part of it.)
179
+ const stem = Number(element.dataset.gridBreakStem ?? 1) || 1;
180
+ const head = Object.hasOwn(element.dataset, 'gridBreakAfterFull')
181
+ ? fullHalfOf(metrics) + metrics.gap
182
+ : 0;
183
+ const pitch = metrics.unit + metrics.gap;
184
+ const above = isNone
185
+ ? 0
186
+ : Number.parseFloat(styles.getPropertyValue('--uikit-grid-break-above')) ||
187
+ 0;
188
+ const from = above > 0 || isNone
189
+ ? metrics.columns
190
+ : Number.parseFloat(styles.getPropertyValue('--uikit-grid-break-from')) ||
191
+ 0;
192
+ const width = container?.clientWidth ?? 0;
193
+ const height = rows * pitch - metrics.gap;
194
+ const isRtl = styles.direction === 'rtl';
195
+ const path = breakPath(metrics, {
196
+ from,
197
+ isRtl,
198
+ radius: Number.parseFloat(styles.getPropertyValue('--uikit-grid-item-radius')) ||
199
+ 24,
200
+ rows,
201
+ stem,
202
+ top: head,
203
+ width,
204
+ });
205
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${String(width)}" height="${String(height)}"><clipPath id="c"><path d="${path}"/></clipPath><path d="${path}" fill="#000" fill-opacity="0.15"/><path d="${path}" fill="none" stroke="#000" stroke-width="4" clip-path="url(#c)"/></svg>`;
206
+ return {
207
+ height,
208
+ // (From its container's inline start.)
209
+ start: -(isRtl
210
+ ? width - element.offsetLeft - element.offsetWidth
211
+ : element.offsetLeft),
212
+ mask: `url("data:image/svg+xml,${encodeURIComponent(svg)}")`,
213
+ // (Taking no room: its box from its first row's top (after a full
214
+ // width, below that one's part of the end-of-line column).)
215
+ top: isNone ? -head : -above * pitch,
216
+ width,
217
+ };
218
+ };
219
+ /**
220
+ * A row's free runs (by its middle, px), from a column on, by what's
221
+ * before (their boxes).
222
+ */
223
+ const freeRuns = (y, from, before, { column: width, columns, gap }) => {
224
+ const pitch = width + gap;
225
+ const runs = [];
226
+ let start;
227
+ for (let column = from; column <= columns; column += 1) {
228
+ const x = column * pitch + width / 2;
229
+ const isTaken = column === columns ||
230
+ before.some((other) => other.offsetTop < y &&
231
+ other.offsetTop + other.offsetHeight > y &&
232
+ other.offsetLeft < x &&
233
+ other.offsetLeft + other.offsetWidth > x);
234
+ if (!isTaken) {
235
+ start ??= column;
236
+ continue;
237
+ }
238
+ if (start === undefined)
239
+ continue;
240
+ runs.push({ from: start, to: column });
241
+ start = undefined;
242
+ }
243
+ return runs;
244
+ };
245
+ /** A break's last row kept empty, by its middle (px; see `breakPlace`). */
246
+ const keptRows = new WeakMap();
247
+ /**
248
+ * Where a break goes: in the row of the one before it (after a break: the
249
+ * row after the last it keeps empty, from its start; first: the row above
250
+ * the first), from the first free unit after it to what's in the way
251
+ * (else its row's end); fillers in that row's other free runs on, and in
252
+ * the rows below it (its rows less one), so what follows starts below it.
253
+ * No room left in that row: in the row below, its rows there and below
254
+ * (one less) kept empty the same way, drawn from that row's end-of-line
255
+ * column (see `breakShape`); one row only, it keeps nothing
256
+ * empty, so it takes no room (drawn in that row's end-of-line column while
257
+ * editing). The same while editing or not. Its sign and handle at its
258
+ * rows' end (in the end-of-line column, where nothing is in the way).
259
+ */
260
+ const breakPlace = (element, previous, before, metrics) => {
261
+ const pitch = metrics.unit + metrics.gap;
262
+ const rows = rowsOf(element);
263
+ const isCell = previous !== undefined && !isBreak(previous);
264
+ // (After a break: from the row after the last it keeps empty, its rows
265
+ // adding to that one's, as they're merged on Done.)
266
+ let y = metrics.origin - pitch;
267
+ let start = metrics.columns;
268
+ if (previous) {
269
+ const row = previous.offsetTop + metrics.unit / 2;
270
+ y = isCell ? row : (keptRows.get(previous) ?? row) + pitch;
271
+ start = isCell
272
+ ? Math.round((previous.offsetLeft + previous.offsetWidth + metrics.gap) /
273
+ (metrics.column + metrics.gap))
274
+ : 0;
275
+ }
276
+ const below = (from, count) => Array.from({ length: Math.max(0, count) }, (_, row) => freeRuns(y + (from + row) * pitch, 0, before, metrics)).flat();
277
+ keptRows.set(element, y + (rows - 1) * pitch);
278
+ const isAfterFull = isCell && Object.hasOwn(previous.dataset, 'gridFull');
279
+ const [first, ...rest] = isAfterFull
280
+ ? []
281
+ : freeRuns(y, start, before, metrics);
282
+ if (first) {
283
+ return {
284
+ above: 0,
285
+ column: `${String(first.from + 1)} / ${String(first.to + 1)}`,
286
+ drawn: rows,
287
+ fills: [...rest, ...below(1, rows - 1)],
288
+ from: first.from,
289
+ handle: metrics.columns - first.to,
290
+ head: 0,
291
+ kind: 'cell',
292
+ rest: metrics.columns - first.to,
293
+ sign: metrics.columns - first.to,
294
+ };
295
+ }
296
+ // (No room left in its row (a full width's ends it anyway): in the
297
+ // end-of-line column, down the rows below filled from their start to
298
+ // their end too (a full width's, a tall tile's at its row's end); after
299
+ // a full width, below its part of that column (see `fullHalfOf`). No
300
+ // taller: keeping nothing empty. Taller: the rows after them too, from
301
+ // their first free unit on.)
302
+ const head = isAfterFull ? fullHalfOf(metrics) + metrics.gap : 0;
303
+ let stem = 1;
304
+ while (stem < metrics.maxRows &&
305
+ freeRuns(y + stem * pitch, 0, before, metrics).length === 0) {
306
+ stem += 1;
307
+ }
308
+ const [next, ...others] = rows > stem ? freeRuns(y + stem * pitch, 0, before, metrics) : [];
309
+ if (!next) {
310
+ keptRows.set(element, y + (stem - 1) * pitch);
311
+ // (First in its container (keeping nothing: one row): shown in its
312
+ // first row's end-of-line column, not above it.)
313
+ return {
314
+ head,
315
+ height: rows * pitch - metrics.gap - head,
316
+ kind: 'none',
317
+ stem,
318
+ top: (previous ? y : y + pitch) - metrics.unit / 2 + head,
319
+ };
320
+ }
321
+ return {
322
+ above: stem,
323
+ column: `${String(next.from + 1)} / ${String(next.to + 1)}`,
324
+ drawn: rows - stem,
325
+ fills: [...others, ...below(stem + 1, rows - stem - 1)],
326
+ from: next.from,
327
+ handle: metrics.columns - next.to,
328
+ head,
329
+ kind: 'cell',
330
+ rest: metrics.columns - next.to,
331
+ sign: metrics.columns - next.to,
332
+ };
333
+ };
334
+ /**
335
+ * A break's fillers (see `breakPlace`), one row each, right after it (in
336
+ * the DOM; in the order shown, by its own `order`). Kept (`kept`); remade
337
+ * only as they change.
338
+ */
339
+ const fillIn = (element, runs, kept) => {
340
+ const own = fills.get(element) ?? [];
341
+ while (own.length > runs.length)
342
+ own.pop()?.remove();
343
+ while (own.length < runs.length) {
344
+ const fill = document.createElement('div');
345
+ fill.className = 'uikit-grid-break-fill';
346
+ fill.dataset.gridPart = 'break-fill';
347
+ fill.setAttribute('aria-hidden', 'true');
348
+ own.push(fill);
349
+ }
350
+ fills.set(element, own);
351
+ for (const [index, { from, to }] of runs.entries()) {
352
+ const fill = own[index];
353
+ if (!fill)
354
+ continue;
355
+ kept.add(fill);
356
+ setStyle(fill, 'grid-column', `${String(from + 1)} / ${String(to + 1)}`);
357
+ setStyle(fill, 'order', element.style.order || undefined);
358
+ }
359
+ // (Right after it, in order.)
360
+ let last = element;
361
+ for (const fill of own) {
362
+ if (last.nextElementSibling !== fill)
363
+ last.after(fill);
364
+ last = fill;
365
+ }
366
+ };
367
+ /**
368
+ * A break's place (see `breakPlace`) on it: its cell, where it's drawn
369
+ * from and to, its shape (see the CSS). A break to be: faint (`isFaint`).
370
+ */
371
+ const styleBreak = (element, place, metrics) => {
372
+ const isNone = place.kind === 'none';
373
+ element.toggleAttribute('data-grid-break-none', isNone);
374
+ // (After a full width: below its part of the end-of-line column, its
375
+ // return sign in the half there, see the CSS; its rows there first.)
376
+ element.toggleAttribute('data-grid-break-after-full', place.head > 0);
377
+ const stem = isNone ? place.stem : place.above;
378
+ if (stem > 0) {
379
+ element.dataset.gridBreakStem = String(stem);
380
+ }
381
+ else {
382
+ delete element.dataset.gridBreakStem;
383
+ }
384
+ setStyle(element, '--uikit-grid-break-none-height', isNone ? `${String(place.height)}px` : undefined);
385
+ setStyle(element, '--uikit-grid-break-head', isNone || place.head === 0 ? undefined : `${String(place.head)}px`);
386
+ setStyle(element, '--uikit-grid-break-above', isNone || place.above === 0 ? undefined : String(place.above));
387
+ setStyle(element, 'grid-column', isNone ? undefined : place.column);
388
+ setStyle(element, '--uikit-grid-break-top', isNone ? `${String(place.top)}px` : undefined);
389
+ // (Where it starts, and the columns after it: drawn from its row's
390
+ // start to the grid's end, see style.css.)
391
+ setStyle(element, '--uikit-grid-break-from', isNone ? undefined : String(place.from));
392
+ setStyle(element, '--uikit-grid-break-rest', isNone ? undefined : String(place.rest));
393
+ setStyle(element, '--uikit-grid-break-drawn', isNone ? undefined : String(place.drawn));
394
+ setStyle(element, '--uikit-grid-break-handle', isNone ? undefined : String(place.handle));
395
+ setStyle(element, '--uikit-grid-break-sign', isNone ? undefined : String(place.sign));
396
+ setStyle(element, '--uikit-grid-break-shape', isNone
397
+ ? undefined
398
+ : `path("${breakPath(metrics, {
399
+ from: place.above > 0 ? metrics.columns : place.from,
400
+ isRtl: metrics.isRtl,
401
+ radius: metrics.radius,
402
+ rows: place.drawn + place.above,
403
+ stem: Math.max(1, place.above),
404
+ top: place.head,
405
+ width: metrics.width,
406
+ })}")`);
407
+ // (A break to be, of more rows: those below its first fainter.)
408
+ setStyle(element, '--uikit-grid-break-fade', !isNone && metrics.isFaint && place.drawn + place.above > 1
409
+ ? `${String(metrics.unit)}px`
410
+ : undefined);
411
+ };
412
+ /**
413
+ * A container's breaks placed (see `placeBreaks`), in the order shown, what
414
+ * comes before each measured.
415
+ */
416
+ const placeIn = (container, metrics, kept) => {
417
+ const before = [];
418
+ let previous;
419
+ // (Its first row's middle: below its header.)
420
+ const header = container.querySelector(':scope > [data-grid-part="header"]');
421
+ const origin = (header ? header.offsetTop + header.offsetHeight + metrics.gap : 0) +
422
+ metrics.unit / 2;
423
+ for (const element of shownOrder(container)) {
424
+ const part = element.dataset.gridPart;
425
+ // (Dragged: out of the flow, its placeholder in it; see edit.ts.)
426
+ if (Object.hasOwn(element.dataset, 'gridDragging'))
427
+ continue;
428
+ if (part === 'break-fill') {
429
+ before.push(element);
430
+ continue;
431
+ }
432
+ if (part !== 'item' &&
433
+ part !== 'spacer' &&
434
+ part !== 'break' &&
435
+ part !== 'placeholder') {
436
+ continue;
437
+ }
438
+ if (isBreak(element)) {
439
+ const place = breakPlace(element, previous, before, {
440
+ ...metrics,
441
+ origin,
442
+ });
443
+ const isNone = place.kind === 'none';
444
+ styleBreak(element, place, {
445
+ ...metrics,
446
+ isFaint: part === 'placeholder',
447
+ width: container.clientWidth,
448
+ });
449
+ fillIn(element, isNone ? [] : place.fills, kept);
450
+ // (Taking no room: not what the next is placed after, nor in the
451
+ // way.)
452
+ if (isNone) {
453
+ previous = element;
454
+ continue;
455
+ }
456
+ }
457
+ before.push(element);
458
+ previous = element;
459
+ }
460
+ };
461
+ /**
462
+ * A full width's shape, editing (see the CSS): what's past its last
463
+ * column, in the end-of-line column, cut away below its first row's upper
464
+ * half (see `fullHalfOf`), the corners left rounded (the inner one too),
465
+ * on below it. Mirrored when right to left. A `clip-path` (px,
466
+ * for something in it at `offset` from its top left: its hatch, what its
467
+ * tile shows; even-odd: all around it, less the cut).
468
+ */
469
+ const fullClipOf = (cell, metrics, [dx, dy] = [0, 0]) => {
470
+ const width = cell.offsetWidth;
471
+ const height = cell.offsetHeight;
472
+ const half = fullHalfOf(metrics);
473
+ const strip = metrics.end + metrics.gap;
474
+ const last = width - strip;
475
+ const r = Math.min(metrics.radius, strip / 2, half / 2);
476
+ const far = 10_000;
477
+ const x = (value) => String((metrics.isRtl ? width - value : value) - dx);
478
+ const y = (value) => String(value - dy);
479
+ const arc = (sweep, ax, ay) => `A${String(r)} ${String(r)} 0 0 ${String(metrics.isRtl ? 1 - sweep : sweep)} ${x(ax)} ${y(ay)}`;
480
+ const around = `M${x(-far)} ${y(-far)}H${x(width + far)}V${y(height + far)}H${x(-far)}Z`;
481
+ const cut = [
482
+ `M${x(last + r)} ${y(half)}H${x(width - r)}`,
483
+ arc(0, width, half - r),
484
+ // (On past its bottom: no sliver of it left there, its edge however
485
+ // it's rounded to pixels.)
486
+ `H${x(width + far)}V${y(height + far)}H${x(last - r)}V${y(height)}`,
487
+ arc(0, last, height - r),
488
+ `V${y(half + r)}`,
489
+ arc(1, last + r, half),
490
+ 'Z',
491
+ ].join('');
492
+ return `path(evenodd, "${around}${cut}")`;
493
+ };
494
+ /**
495
+ * A full width's shape, editing (see `fullClipOf`), as a closed SVG path
496
+ * (px) of its box at a height: its columns, and its end-of-line column's
497
+ * part, every corner rounded (the inner one too). Mirrored when right to
498
+ * left.
499
+ */
500
+ const fullPathOf = (metrics, width, height,
501
+ // (Its edge `inset` px in: the same shape, its outer corners less round,
502
+ // its inner one rounder.)
503
+ inset = 0) => {
504
+ const { isRtl } = metrics;
505
+ const half = fullHalfOf(metrics);
506
+ const last = width - metrics.end - metrics.gap;
507
+ const outer = Math.min(metrics.radius, (width - last) / 2, half / 2);
508
+ const r = Math.max(0, outer - inset);
509
+ const ri = outer + inset;
510
+ const [left, top, right, bottom] = [
511
+ inset,
512
+ inset,
513
+ width - inset,
514
+ height - inset,
515
+ ];
516
+ const [notch, column] = [half - inset, last - inset];
517
+ const x = (value) => String(isRtl ? width - value : value);
518
+ const arc = (radius, sweep, ax, ay) => `A${String(radius)} ${String(radius)} 0 0 ${String(isRtl ? 1 - sweep : sweep)} ${x(ax)} ${String(ay)}`;
519
+ return [
520
+ `M${x(left + r)} ${String(top)}H${x(right - r)}`,
521
+ arc(r, 1, right, top + r),
522
+ `V${String(notch - r)}`,
523
+ arc(r, 1, right - r, notch),
524
+ `H${x(column + ri)}`,
525
+ arc(ri, 0, column, notch + ri),
526
+ `V${String(bottom - r)}`,
527
+ arc(r, 1, column - r, bottom),
528
+ `H${x(left + r)}`,
529
+ arc(r, 1, left, bottom - r),
530
+ `V${String(top + r)}`,
531
+ arc(r, 1, left + r, top),
532
+ 'Z',
533
+ ].join('');
534
+ };
535
+ /** A cell's metrics for its full width's shape (see `fullPathOf`). */
536
+ const shapeMetricsOf = (cell) => {
537
+ const styles = getComputedStyle(cell);
538
+ return {
539
+ ...metricsOf(cell),
540
+ isRtl: styles.direction === 'rtl',
541
+ radius: Number.parseFloat(styles.getPropertyValue('--uikit-grid-item-radius')) ||
542
+ 24,
543
+ };
544
+ };
545
+ /**
546
+ * A path's edge, inside it, as a mask (a CSS `url()`; `width` px wide, in
547
+ * a box as big), filled faintly too (`fill`, 0: not).
548
+ */
549
+ const edgeMaskOf = (path, [width, height], { fill = 0, line }) => {
550
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${String(width)}" height="${String(height)}"><clipPath id="c"><path d="${path}"/></clipPath>${fill > 0 ? `<path d="${path}" fill="#000" fill-opacity="${String(fill)}"/>` : ''}<path d="${path}" fill="none" stroke="#000" stroke-width="${String(line * 2)}" clip-path="url(#c)"/></svg>`;
551
+ return `url("data:image/svg+xml,${encodeURIComponent(svg)}")`;
552
+ };
553
+ /**
554
+ * A full width's resize outline at some rows (see main.tsx, the CSS): its
555
+ * shape as it'd be (see `fullPathOf`; a break's, see `breakOutlineOf`),
556
+ * filled faintly and edged inside (a mask), from its top left (px); none
557
+ * while there's no end-of-line column.
558
+ */
559
+ export const fullOutlineOf = (cell, rows) => {
560
+ const metrics = shapeMetricsOf(cell);
561
+ if (metrics.end < 1)
562
+ return undefined;
563
+ const width = cell.offsetWidth;
564
+ const height = rows * (metrics.unit + metrics.gap) - metrics.gap;
565
+ const path = fullPathOf(metrics, width, height);
566
+ return {
567
+ height,
568
+ mask: edgeMaskOf(path, [width, height], { fill: 0.15, line: 2 }),
569
+ width,
570
+ };
571
+ };
572
+ /** Cells shaped (see `shapeFulls`), to unshape once they're not. */
573
+ const shaped = new WeakMap();
574
+ /** A cell's shapes (see `shapeFulls`) set, or unset (`undefined`). */
575
+ const shapeCell = (cell, metrics) => {
576
+ setStyle(cell, '--uikit-grid-full-shape', metrics ? fullClipOf(cell, metrics) : undefined);
577
+ // (An area's room's edge (see main.tsx, the CSS): in its shape.)
578
+ const size = [cell.offsetWidth, cell.offsetHeight];
579
+ // (Set before it's shown: a full width's, whether it has room or not
580
+ // yet, so an area's edge is in its shape from its first frame.)
581
+ setStyle(cell, '--uikit-grid-full-edge',
582
+ // (A clip, as the shape's: drawn at once, no image to decode.)
583
+ metrics
584
+ ? `path(evenodd, "${fullPathOf(metrics, ...size)}${fullPathOf(metrics, ...size, 1.5)}")`
585
+ : undefined);
586
+ const body = cell.querySelector(':scope > [data-grid-part="body"]');
587
+ if (!body)
588
+ return;
589
+ setStyle(body, '--uikit-grid-body-shape', metrics
590
+ ? fullClipOf(cell, metrics, [body.offsetLeft, body.offsetTop])
591
+ : undefined);
592
+ // (How far its tile runs past the last column (a full-width tile, one
593
+ // in a trailing corner): its trailing controls in by as much, clear of
594
+ // the cut (see the CSS); its ring only where it'd be in the cut, below
595
+ // its first row's upper half.)
596
+ const strip = metrics ? metrics.end + metrics.gap : 0;
597
+ const overhang = metrics
598
+ ? Math.max(0, metrics.isRtl
599
+ ? strip - body.offsetLeft
600
+ : body.offsetLeft + body.offsetWidth - (cell.offsetWidth - strip))
601
+ : 0;
602
+ const ring = body.querySelector(':scope > .uikit-grid-move-sign');
603
+ const isRingCut = metrics !== undefined &&
604
+ body.offsetTop + (ring?.offsetHeight ?? 44) > fullHalfOf(metrics);
605
+ setStyle(body, '--uikit-grid-body-overhang', overhang > 0 ? `${String(overhang)}px` : undefined);
606
+ setStyle(body, '--uikit-grid-body-overhang-top', overhang > 0 && isRingCut ? `${String(overhang)}px` : undefined);
607
+ };
608
+ /**
609
+ * Its full widths shaped while editing (see `fullClipOf`), else not; one
610
+ * no longer a full width (e.g. its area resized to fixed columns), or no
611
+ * longer in it, unshaped. Shaped: its hatch (an area's room), and what
612
+ * its tile shows (by its tile's place in it): a full-width tile in a
613
+ * full-width area, too, shows past its last column only where its area
614
+ * does (its handle at that column's corner, see the CSS). Not the cell
615
+ * itself, nor its tile: their resize outlines whole (a full width's in
616
+ * its shape, see `fullOutlineOf`).
617
+ */
618
+ const shapeFulls = (root) => {
619
+ const fulls = root.querySelectorAll('[data-grid-part="item"][data-grid-full]');
620
+ const before = shaped.get(root) ?? new Set();
621
+ const now = new Set(fulls);
622
+ for (const cell of before) {
623
+ if (!now.has(cell))
624
+ shapeCell(cell, undefined);
625
+ }
626
+ shaped.set(root, now);
627
+ if (fulls.length === 0)
628
+ return;
629
+ const styles = getComputedStyle(root);
630
+ const metrics = {
631
+ ...metricsOf(root),
632
+ isRtl: styles.direction === 'rtl',
633
+ radius: Number.parseFloat(styles.getPropertyValue('--uikit-grid-item-radius')) ||
634
+ 24,
635
+ };
636
+ const isShaped = Object.hasOwn(root.dataset, 'editing') && metrics.end >= 1;
637
+ for (const cell of fulls) {
638
+ shapeCell(cell, isShaped ? metrics : undefined);
639
+ }
640
+ };
641
+ /**
642
+ * Its breaks as cells (see `breakPlace`): in the order shown, one after
643
+ * another (each placed, the next measured), as tall as their rows (see the
644
+ * CSS); not editing, not drawn (keeping nothing empty: none). Not one
645
+ * dragged.
646
+ * Fillers no longer needed removed.
647
+ */
648
+ export const placeBreaks = (root) => {
649
+ shapeFulls(root);
650
+ const kept = new Set();
651
+ const breaks = Array.from(root.querySelectorAll('[data-grid-part="break"], [data-grid-break]'));
652
+ for (const element of breaks) {
653
+ if (!Object.hasOwn(element.dataset, 'gridDragging'))
654
+ continue;
655
+ setStyle(element, 'grid-column', undefined);
656
+ setStyle(element, '--uikit-grid-break-from', undefined);
657
+ setStyle(element, '--uikit-grid-break-rest', undefined);
658
+ setStyle(element, '--uikit-grid-break-shape', undefined);
659
+ setStyle(element, '--uikit-grid-break-fade', undefined);
660
+ setStyle(element, '--uikit-grid-break-drawn', undefined);
661
+ setStyle(element, '--uikit-grid-break-handle', undefined);
662
+ setStyle(element, '--uikit-grid-break-sign', undefined);
663
+ setStyle(element, '--uikit-grid-break-top', undefined);
664
+ setStyle(element, '--uikit-grid-break-above', undefined);
665
+ setStyle(element, '--uikit-grid-break-none-height', undefined);
666
+ setStyle(element, '--uikit-grid-break-head', undefined);
667
+ delete element.dataset.gridBreakNone;
668
+ delete element.dataset.gridBreakAfterFull;
669
+ delete element.dataset.gridBreakStem;
670
+ }
671
+ if (breaks.length > 0) {
672
+ const styles = getComputedStyle(root);
673
+ const metrics = {
674
+ ...metricsOf(root),
675
+ isRtl: styles.direction === 'rtl',
676
+ radius: Number.parseFloat(styles.getPropertyValue('--uikit-grid-item-radius')) || 24,
677
+ };
678
+ const containers = new Set(breaks.map((element) => element.parentElement));
679
+ for (const container of containers) {
680
+ if (container)
681
+ placeIn(container, metrics, kept);
682
+ }
683
+ }
684
+ for (const fill of root.querySelectorAll('[data-grid-part="break-fill"]')) {
685
+ if (!kept.has(fill))
686
+ fill.remove();
687
+ }
688
+ };
689
+ /** Its page: the nearest ancestor clipping or scrolling (else none). */
690
+ const pages = new WeakMap();
691
+ const pageOf = (root) => {
692
+ let page = pages.get(root);
693
+ if (page === undefined || (page && !page.contains(root))) {
694
+ page = root.parentElement;
695
+ while (page && getComputedStyle(page).overflowX === 'visible') {
696
+ page = page.parentElement;
697
+ }
698
+ pages.set(root, page);
699
+ }
700
+ return page;
701
+ };
702
+ const bandProperties = [
703
+ '--uikit-grid-bands',
704
+ '--uikit-grid-bands-end',
705
+ '--uikit-grid-bands-height',
706
+ '--uikit-grid-bands-start',
707
+ '--uikit-grid-bands-top',
708
+ ];
709
+ /** A band's line (px), and how far it's drawn around its rows' boxes. */
710
+ const bandLine = 1.5;
711
+ const bandOffset = 4;
712
+ /**
713
+ * A container's rows' outline, one band, as reading goes (an SVG path, in
714
+ * px): its first row from the grid's start (rounded) on to the trailing
715
+ * edge (`end` past the grid's), the rows between from the leading edge
716
+ * (`start` before the grid's) to the trailing, its last from the leading
717
+ * to the grid's end (rounded); one row: a rounded box. Mirrored when
718
+ * right to left.
719
+ */
720
+ const bandsPath = ({ end, isRtl, offset, pitch, radius, rows, start, unit, width, }) => {
721
+ const all = start + width + end;
722
+ // (Around its rows' boxes by `offset` (the image as much past its first
723
+ // and last rows), inside that by half its line; its corners concentric
724
+ // with theirs.)
725
+ const h = bandLine / 2;
726
+ const r = Math.max(0, Math.min(radius, unit / 2) + offset - h);
727
+ const from = Math.max(h, start - offset + h);
728
+ const to = Math.min(all - h, start + width + offset - h);
729
+ const x = (value) => String(isRtl ? all - value : value);
730
+ const sweep = (value) => String(isRtl ? 1 - value : value);
731
+ const arc = (value, ax, ay) => `A${String(r)} ${String(r)} 0 0 ${sweep(value)} ${x(ax)} ${String(ay)}`;
732
+ const line = (y) => `M${x(0)} ${String(y)}H${x(all)}`;
733
+ const parts = [];
734
+ for (let row = 0; row < rows; row += 1) {
735
+ const top = row * pitch + h;
736
+ const bottom = row * pitch + unit + 2 * offset - h;
737
+ const isFirst = row === 0;
738
+ const isLast = row === rows - 1;
739
+ if (isFirst && isLast) {
740
+ parts.push(`M${x(from + r)} ${String(top)}H${x(to - r)}`, arc(1, to, top + r), `V${String(bottom - r)}`, arc(1, to - r, bottom), `H${x(from + r)}`, arc(1, from, bottom - r), `V${String(top + r)}`, arc(1, from + r, top));
741
+ }
742
+ else if (isFirst) {
743
+ parts.push(`M${x(all)} ${String(top)}H${x(from + r)}`, arc(0, from, top + r), `V${String(bottom - r)}`, arc(0, from + r, bottom), `H${x(all)}`);
744
+ }
745
+ else if (isLast) {
746
+ parts.push(`M${x(0)} ${String(top)}H${x(to - r)}`, arc(1, to, top + r), `V${String(bottom - r)}`, arc(1, to - r, bottom), `H${x(0)}`);
747
+ }
748
+ else {
749
+ parts.push(line(top), line(bottom));
750
+ }
751
+ }
752
+ return { all, path: parts.join('') };
753
+ };
754
+ /**
755
+ * Its containers' rows outlined while editing (see `bandsPath`, the CSS):
756
+ * the band's outline (a mask) and where it goes, set on each container;
757
+ * not editing, none.
758
+ */
759
+ const placeBands = (root) => {
760
+ const sections = Array.from(root.querySelectorAll(':scope > [data-grid-part="section"]'));
761
+ const containers = sections.length > 0 ? sections : [root];
762
+ if (!Object.hasOwn(root.dataset, 'editing')) {
763
+ for (const container of containers) {
764
+ for (const property of bandProperties) {
765
+ setStyle(container, property, undefined);
766
+ }
767
+ }
768
+ return;
769
+ }
770
+ const styles = getComputedStyle(root);
771
+ const value = (property, fallback) => Number.parseFloat(styles.getPropertyValue(property)) || fallback;
772
+ const gap = value('--uikit-grid-gap', 0);
773
+ const unit = value('--uikit-grid-unit', 1);
774
+ const radius = value('--uikit-grid-item-radius', 24);
775
+ const pitch = unit + gap;
776
+ const isRtl = styles.direction === 'rtl';
777
+ const page = pageOf(root);
778
+ const edge = page?.getBoundingClientRect();
779
+ const left = edge ? edge.left + (page?.clientLeft ?? 0) : 0;
780
+ const right = edge
781
+ ? left + (page?.clientWidth ?? 0)
782
+ : document.documentElement.clientWidth;
783
+ for (const container of containers) {
784
+ const header = container.querySelector(':scope > [data-grid-part="header"]');
785
+ const top = header ? header.offsetTop + header.offsetHeight + gap : 0;
786
+ const rows = Math.round((container.clientHeight - top + gap) / pitch);
787
+ if (rows < 1) {
788
+ for (const property of bandProperties) {
789
+ setStyle(container, property, undefined);
790
+ }
791
+ continue;
792
+ }
793
+ const box = container.getBoundingClientRect();
794
+ const before = Math.max(0, Math.floor(box.left - left));
795
+ const after = Math.max(0, Math.floor(right - box.right));
796
+ const start = isRtl ? after : before;
797
+ const end = isRtl ? before : after;
798
+ const width = container.clientWidth;
799
+ // (Around them, clear of the next row's.)
800
+ const offset = Math.max(0, Math.min(bandOffset, gap / 2 - bandLine));
801
+ const height = rows * pitch - gap + 2 * offset;
802
+ const { all, path } = bandsPath({
803
+ end,
804
+ isRtl,
805
+ offset,
806
+ pitch,
807
+ radius,
808
+ rows,
809
+ start,
810
+ unit,
811
+ width,
812
+ });
813
+ setStyle(container, '--uikit-grid-bands', maskOf(all, height, [
814
+ [path, `fill="none" stroke="#000" stroke-width="${String(bandLine)}"`],
815
+ ]));
816
+ setStyle(container, '--uikit-grid-bands-end', `${String(end)}px`);
817
+ setStyle(container, '--uikit-grid-bands-height', `${String(height)}px`);
818
+ setStyle(container, '--uikit-grid-bands-start', `${String(start)}px`);
819
+ setStyle(container, '--uikit-grid-bands-top', `${String(top - offset)}px`);
820
+ }
821
+ };
822
+ /** (Within a pixel: what's laid out in fractions.) */
823
+ const isWithin = (inner, outer) => inner.left >= outer.left - 1 &&
824
+ inner.right <= outer.right + 1 &&
825
+ inner.top >= outer.top - 1 &&
826
+ inner.bottom <= outer.bottom + 1;
827
+ const isOverlapping = (a, b) => a.left < b.right - 1 &&
828
+ b.left < a.right - 1 &&
829
+ a.top < b.bottom - 1 &&
830
+ b.top < a.bottom - 1;
831
+ /**
832
+ * The breaks right before and after one, in order (each next to the
833
+ * one before it: merged on Done, see the app's).
834
+ */
835
+ const adjacentBreaks = (cells, cell) => {
836
+ const at = cells.indexOf(cell);
837
+ const adjacent = [];
838
+ for (const step of [-1, 1]) {
839
+ for (let index = at + step; cells[index]?.dataset.gridPart === 'break'; index += step) {
840
+ adjacent.push(cells[index]);
841
+ }
842
+ }
843
+ return adjacent;
844
+ };
845
+ /** Where a resize grows a cell to (see `mergedBy`), in its container. */
846
+ const grownAreas = (cell, columns, rows, { column, gap, unit }) => {
847
+ const pitch = unit + gap;
848
+ const own = rectOf(cell);
849
+ if (cell.dataset.gridPart === 'break') {
850
+ // (Its rows as drawn (one less below a full row), to as many more.)
851
+ const drawn = Math.round((cell.offsetHeight + gap) / pitch);
852
+ const shown = rows - rowsOf(cell) + drawn;
853
+ if (shown <= drawn)
854
+ return [];
855
+ return [
856
+ own,
857
+ {
858
+ bottom: own.top + shown * pitch - gap,
859
+ left: 0,
860
+ right: cell.parentElement?.clientWidth ?? 0,
861
+ top: own.bottom + gap,
862
+ },
863
+ ];
864
+ }
865
+ const width = columns * (column + gap) - gap;
866
+ const isRtl = getComputedStyle(cell).direction === 'rtl';
867
+ return [
868
+ {
869
+ bottom: own.top + rows * pitch - gap,
870
+ left: isRtl ? own.right - width : own.left,
871
+ right: isRtl ? own.right : own.left + width,
872
+ top: own.top,
873
+ },
874
+ ];
875
+ };
876
+ /**
877
+ * What a cell resized to a size takes in (see `ResizeHandle`): growing,
878
+ * an item or a spacer every spacer it reaches, a break the breaks right
879
+ * before and after it in order; either, the breaks (a break: also the
880
+ * spacers) wholly inside what it grows over (a break's: its fillers too).
881
+ * Items are never taken in: they reflow as usual. An item or a spacer
882
+ * grows right and down from its top leading corner; a break by rows,
883
+ * each a whole row below it. Only what the app can be told of and remove
884
+ * (named, its `dropName`; a remove button in it, see `Grid.RemoveButton`):
885
+ * the app removes what's taken in (told by name), the rest reflows as
886
+ * items do.
887
+ */
888
+ /**
889
+ * Whether a cell can be taken in: named (its `dropName`, as the app's
890
+ * told of it) and removable (a remove button in it).
891
+ */
892
+ const isRemovable = (cell) => Object.hasOwn(cell.dataset, 'gridName') &&
893
+ cell.querySelector(':scope > [data-grid-part="remove-button"]') !== null;
894
+ export const mergedBy = (cell, columns, rows) => {
895
+ const container = cell.parentElement;
896
+ if (!container)
897
+ return [];
898
+ const areas = grownAreas(cell, columns, rows, metricsOf(container));
899
+ if (areas.length === 0)
900
+ return [];
901
+ // (Its cells, in order: what takes room there, by what it belongs to (a
902
+ // break: its fillers too).)
903
+ const cells = Array.from(container.children).filter((child) => child instanceof HTMLElement &&
904
+ ['break', 'item', 'spacer'].includes(child.dataset.gridPart ?? '') &&
905
+ !Object.hasOwn(child.dataset, 'gridDragging'));
906
+ const isBreakResized = cell.dataset.gridPart === 'break';
907
+ const merged = new Set(isBreakResized ? adjacentBreaks(cells, cell) : []);
908
+ // (The break right after it: still ending its row after it, grown or
909
+ // not (in its end-of-line column, then); never taken in.)
910
+ const following = cells[cells.indexOf(cell) + 1];
911
+ const kept = !isBreakResized && following?.dataset.gridPart === 'break'
912
+ ? following
913
+ : undefined;
914
+ const isIn = (rect) => areas.some((area) => isWithin(rect, area));
915
+ const touches = (rect) => areas.some((area) => isOverlapping(rect, area));
916
+ for (const each of cells) {
917
+ if (each === cell || each === kept || merged.has(each))
918
+ continue;
919
+ const part = each.dataset.gridPart;
920
+ const rects = [
921
+ rectOf(each),
922
+ ...(part === 'break' ? fillsOf(each).map((fill) => rectOf(fill)) : []),
923
+ ];
924
+ // (An item or a spacer growing swallows spacers it reaches; anything
925
+ // else, wholly inside it. Items are never taken in: they reflow.)
926
+ const isTaken = part === 'spacer' && !isBreakResized
927
+ ? rects.some((rect) => touches(rect))
928
+ : part !== 'item' &&
929
+ !Object.hasOwn(each.dataset, 'gridBreakNone') &&
930
+ rects.every((rect) => isIn(rect));
931
+ if (isTaken)
932
+ merged.add(each);
933
+ }
934
+ return [...merged].filter((each) => isRemovable(each));
935
+ };
936
+ /** An element's position in its grid's layout (not its `translate`). */
937
+ const layoutPosition = (element, root) => {
938
+ let x = 0;
939
+ let y = 0;
940
+ for (let current = element; current && current !== root; current = current.offsetParent) {
941
+ x += current.offsetLeft;
942
+ y += current.offsetTop;
943
+ }
944
+ return [x, y];
945
+ };
946
+ /** The nearest ancestor scrolling vertically, or the document's (as List). */
947
+ export const scrollerOf = (element) => {
948
+ for (let current = element.parentElement; current; current = current.parentElement) {
949
+ const { overflowY } = getComputedStyle(current);
950
+ if ((overflowY === 'auto' || overflowY === 'scroll') &&
951
+ current.scrollHeight > current.clientHeight) {
952
+ return current;
953
+ }
954
+ }
955
+ return element.ownerDocument.scrollingElement ?? element.ownerDocument.body;
956
+ };
957
+ /** A scroller's visible top and bottom: its box, less its bars' room. */
958
+ export const visibleEdgesOf = (scroller, root) => {
959
+ const isDocument = scroller === scroller.ownerDocument.scrollingElement;
960
+ const { bottom, top } = isDocument
961
+ ? { bottom: window.innerHeight, top: 0 }
962
+ : scroller.getBoundingClientRect();
963
+ const styles = getComputedStyle(root);
964
+ const inset = (name) => Number.parseFloat(styles.getPropertyValue(name)) || 0;
965
+ return {
966
+ bottom: bottom - inset('--uikit-viewport-anchor-block-end'),
967
+ top: top + inset('--uikit-viewport-anchor-block-start'),
968
+ };
969
+ };
970
+ /** An element's top on screen by its layout (not its `translate`). */
971
+ const topOf = (element, root) => root.getBoundingClientRect().top + layoutPosition(element, root)[1];
972
+ /**
973
+ * Whether an element's getting to a new box by itself (a tile, its cell,
974
+ * see reshape.ts): not glided by the reflow meanwhile.
975
+ */
976
+ export const isReshaping = (element) => Object.hasOwn(element.dataset, 'gridReshaping');
977
+ /** Keyframes from an offset to none. */
978
+ const fromOffset = (x, y) => [
979
+ { translate: `${String(x)}px ${String(y)}px` },
980
+ { translate: '0 0' },
981
+ ];
982
+ /**
983
+ * An element gliding from where it was (`dx`, `dy` off) to where it is, by
984
+ * a `translate` added to any running one.
985
+ */
986
+ const glide = (element, dx, dy) => {
987
+ const timing = {
988
+ composite: 'add',
989
+ duration: reflowDuration,
990
+ easing: reflowEasing,
991
+ };
992
+ element.animate(fromOffset(dx, dy), timing);
993
+ };
994
+ /**
995
+ * Whether a cell stays where it's laid out, not gliding there: the one
996
+ * dragged, one dropped in its area (gliding from where it was let go, see
997
+ * main.tsx); none with reduced motion; nor a tile getting to a new box,
998
+ * nor its cell (drawn there by itself, see reshape.ts).
999
+ */
1000
+ const isStill = (element, dragged, isReduced) => element === dragged ||
1001
+ Object.hasOwn(element.dataset, 'gridPlaced') ||
1002
+ isReduced ||
1003
+ isReshaping(element);
1004
+ /**
1005
+ * Its sections and cells gliding from where they were to where they are, as
1006
+ * the layout changes (a cell resized, moved, a section's height changing,
1007
+ * the columns changing): FLIP, by a `translate` animation added to any
1008
+ * running one, a section's carrying its cells (theirs within it). Not the
1009
+ * one dragged. Edit mode toggled: what's on screen kept there (see below).
1010
+ */
1011
+ export const useReflow = (rootRef, dragged, editing) => {
1012
+ // (What's on screen as last laid out or scrolled: see `editing` below.)
1013
+ const anchor = useRef(undefined);
1014
+ const shift = useRef(undefined);
1015
+ const keep = useRef(undefined);
1016
+ useLayoutEffect(() => {
1017
+ const { current: root } = rootRef;
1018
+ if (!root)
1019
+ return undefined;
1020
+ const last = new WeakMap();
1021
+ const reduce = reducedMotionOf(root);
1022
+ const scroller = scrollerOf(root);
1023
+ // (The first item shown whole below the scroller's bars, where it is:
1024
+ // by its layout, not what's gliding.)
1025
+ // (Chosen anew only when scrolled by the user (not by `keep`): the
1026
+ // same one kept through a run of layout changes, so it doesn't drift
1027
+ // by being swapped for another.)
1028
+ let kept = Number.NaN;
1029
+ let laidOut;
1030
+ const laidOutNow = () => (laidOut ??= Array.from(root.querySelectorAll('[data-grid-part="item"]'))
1031
+ .filter((each) => each.offsetParent !== null)
1032
+ .map((each) => ({
1033
+ element: each,
1034
+ height: each.offsetHeight,
1035
+ y: layoutPosition(each, root)[1],
1036
+ })));
1037
+ const record = (isChosen = false) => {
1038
+ // (Not chosen by a scroll: its layout changed, or may have.)
1039
+ if (!isChosen)
1040
+ laidOut = undefined;
1041
+ const rootTop = root.getBoundingClientRect().top;
1042
+ const held = anchor.current?.element;
1043
+ let element;
1044
+ let y;
1045
+ if (isChosen || !held?.isConnected || held.offsetParent === null) {
1046
+ const { top } = visibleEdgesOf(scroller, root);
1047
+ // (The highest seen whole below the bars (the leading one of a
1048
+ // row): what's looked at, not one mostly under them; else the first
1049
+ // seen at all.)
1050
+ const items = laidOutNow();
1051
+ let chosen;
1052
+ for (const each of items) {
1053
+ if (rootTop + each.y < top - 1)
1054
+ continue;
1055
+ if (!chosen || each.y < chosen.y - 1)
1056
+ chosen = each;
1057
+ }
1058
+ chosen ??= items.find((each) => rootTop + each.y + each.height > top);
1059
+ element = chosen?.element;
1060
+ y = chosen?.y;
1061
+ }
1062
+ else {
1063
+ element = held;
1064
+ }
1065
+ anchor.current = element && {
1066
+ element,
1067
+ scrolled: scroller.scrollTop,
1068
+ top: y === undefined ? topOf(element, root) : rootTop + y,
1069
+ };
1070
+ };
1071
+ // (Scrolled by as much (see `editing` below): what's in the grid gliding
1072
+ // by where it was on screen, not in the grid.)
1073
+ shift.current = (dy) => {
1074
+ for (const child of root.children) {
1075
+ const element = child;
1076
+ const before = last.get(element);
1077
+ if (!before)
1078
+ continue;
1079
+ last.set(element, [before[0], before[1] + dy]);
1080
+ }
1081
+ };
1082
+ // (Where everything is, as laid out, nothing gliding.)
1083
+ const recordAll = () => {
1084
+ for (const element of root.querySelectorAll(glidingSelector)) {
1085
+ if (!element.offsetParent) {
1086
+ last.delete(element);
1087
+ continue;
1088
+ }
1089
+ last.set(element, element.dataset.gridPart === 'section'
1090
+ ? layoutPosition(element, root)
1091
+ : [element.offsetLeft, element.offsetTop]);
1092
+ }
1093
+ };
1094
+ // (Not gliding: until it's measured, and into its first measured
1095
+ // layout; while its width changes on the same columns (the units
1096
+ // stretching along), what's on screen kept there (see `keep`), where
1097
+ // things were kept until it's painted, so columns changing with it
1098
+ // glide from where they were shown.)
1099
+ let isMeasured = false;
1100
+ let width = -1;
1101
+ let columns = '';
1102
+ let unit = '';
1103
+ let settle = 0;
1104
+ let isStretching = false;
1105
+ // (Its columns changed, not yet painted: what follows in the same frame
1106
+ // (e.g. what's in it re-rendered for them) kept on screen too.)
1107
+ let isSettling = false;
1108
+ let settled = 0;
1109
+ let settleTimer = 0;
1110
+ const stopSettling = () => {
1111
+ cancelAnimationFrame(settle);
1112
+ clearTimeout(settleTimer);
1113
+ };
1114
+ // (What's on screen kept there, its layout changed: scrolled by as much
1115
+ // as the first item shown moved, before it's painted; the glide taking
1116
+ // that in. However it's scrolled since: by this, or the browser's own
1117
+ // anchoring.)
1118
+ keep.current = () => {
1119
+ const held = anchor.current;
1120
+ if (!held?.element.isConnected)
1121
+ return;
1122
+ const dy = topOf(held.element, root) - held.top;
1123
+ if (Math.abs(dy) >= 0.5)
1124
+ scroller.scrollTop += dy;
1125
+ kept = scroller.scrollTop;
1126
+ const scrolled = scroller.scrollTop - held.scrolled;
1127
+ if (scrolled !== 0)
1128
+ shift.current?.(scrolled);
1129
+ };
1130
+ const reflow = () => {
1131
+ placeBreaks(root);
1132
+ placeBands(root);
1133
+ const wasMeasured = isMeasured;
1134
+ isMeasured = Object.hasOwn(root.dataset, 'gridMeasured');
1135
+ const isResized = root.clientWidth !== width;
1136
+ width = root.clientWidth;
1137
+ const hasColumns = root.style.getPropertyValue('--uikit-grid-columns') !== columns;
1138
+ columns = root.style.getPropertyValue('--uikit-grid-columns');
1139
+ // (Its columns' width too: narrower beside its end-of-line column
1140
+ // as it opens, see main.tsx.)
1141
+ const unitNow = `${root.style.getPropertyValue('--uikit-grid-unit')}/${root.style.getPropertyValue('--uikit-grid-column')}`;
1142
+ const hasUnit = unitNow !== unit;
1143
+ unit = unitNow;
1144
+ if (!wasMeasured || !isMeasured) {
1145
+ recordAll();
1146
+ record();
1147
+ return;
1148
+ }
1149
+ // (Stretched on the same columns: what's on screen kept there, nothing
1150
+ // gliding.)
1151
+ if ((isResized || hasUnit || isStretching) && !hasColumns) {
1152
+ keep.current?.();
1153
+ record();
1154
+ isStretching = true;
1155
+ stopSettling();
1156
+ // (Once it's painted: after its frame, not in it (its callbacks run
1157
+ // before its resizing).)
1158
+ settle = requestAnimationFrame(() => {
1159
+ settleTimer = window.setTimeout(() => {
1160
+ isStretching = false;
1161
+ recordAll();
1162
+ });
1163
+ });
1164
+ return;
1165
+ }
1166
+ stopSettling();
1167
+ isStretching = false;
1168
+ // (Its columns changed, or just did: what's on screen kept there.)
1169
+ if (hasColumns) {
1170
+ isSettling = true;
1171
+ cancelAnimationFrame(settled);
1172
+ settled = requestAnimationFrame(() => {
1173
+ isSettling = false;
1174
+ });
1175
+ }
1176
+ if (isSettling)
1177
+ keep.current?.();
1178
+ for (const element of root.querySelectorAll(glidingSelector)) {
1179
+ // (Not shown, e.g. a break while not editing: no position to glide
1180
+ // from once it is.)
1181
+ if (!element.offsetParent) {
1182
+ last.delete(element);
1183
+ continue;
1184
+ }
1185
+ // (A section's in the grid; a cell's in its section, which carries
1186
+ // it.)
1187
+ const position = element.dataset.gridPart === 'section'
1188
+ ? layoutPosition(element, root)
1189
+ : [element.offsetLeft, element.offsetTop];
1190
+ const before = last.get(element);
1191
+ last.set(element, position);
1192
+ if (!before || isStill(element, dragged.current, reduce.matches)) {
1193
+ continue;
1194
+ }
1195
+ const dx = before[0] - position[0];
1196
+ const dy = before[1] - position[1];
1197
+ if (dx === 0 && dy === 0)
1198
+ continue;
1199
+ glide(element, dx, dy);
1200
+ }
1201
+ record();
1202
+ };
1203
+ let frame = 0;
1204
+ const onScroll = () => {
1205
+ cancelAnimationFrame(frame);
1206
+ // (Scrolled by the user: chosen anew. By `keep`: already recorded;
1207
+ // not again before its frame's resizing (a frame's callbacks run
1208
+ // before its observers: what they'd read isn't kept yet).)
1209
+ if (scroller.scrollTop === kept)
1210
+ return;
1211
+ frame = requestAnimationFrame(() => record(true));
1212
+ };
1213
+ const scrolled = scroller === root.ownerDocument.scrollingElement ? window : scroller;
1214
+ scrolled.addEventListener('scroll', onScroll, { passive: true });
1215
+ reflow();
1216
+ const resizeObserver = new ResizeObserver(reflow);
1217
+ resizeObserver.observe(root);
1218
+ // (Its page's width: its rows' bands run to its edges.)
1219
+ const page = pageOf(root);
1220
+ if (page)
1221
+ resizeObserver.observe(page);
1222
+ const mutationObserver = new MutationObserver(reflow);
1223
+ mutationObserver.observe(root, {
1224
+ attributeFilter: [
1225
+ 'data-editing',
1226
+ 'data-grid-measured',
1227
+ 'data-size',
1228
+ 'hidden',
1229
+ 'style',
1230
+ ],
1231
+ attributes: true,
1232
+ childList: true,
1233
+ subtree: true,
1234
+ });
1235
+ return () => {
1236
+ cancelAnimationFrame(frame);
1237
+ stopSettling();
1238
+ cancelAnimationFrame(settled);
1239
+ scrolled.removeEventListener('scroll', onScroll);
1240
+ resizeObserver.disconnect();
1241
+ mutationObserver.disconnect();
1242
+ shift.current = undefined;
1243
+ keep.current = undefined;
1244
+ };
1245
+ }, [dragged, rootRef]);
1246
+ // (Edit mode toggled: what it shows or hides (sections' end rows, breaks)
1247
+ // not moving what's on screen (see `keep`).)
1248
+ const isFirst = useRef(true);
1249
+ useLayoutEffect(() => {
1250
+ if (isFirst.current) {
1251
+ isFirst.current = false;
1252
+ return;
1253
+ }
1254
+ keep.current?.();
1255
+ }, [editing, rootRef]);
1256
+ };
1257
+ //# sourceMappingURL=layout.js.map