@andamento/dom 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +27 -2
- package/dist/chunk-276TFSAG.cjs +299 -0
- package/dist/chunk-276TFSAG.cjs.map +1 -0
- package/dist/chunk-RCXEXYRF.js +299 -0
- package/dist/chunk-RCXEXYRF.js.map +1 -0
- package/dist/index.cjs +727 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +242 -0
- package/dist/index.d.ts +242 -0
- package/dist/index.js +727 -0
- package/dist/index.js.map +1 -0
- package/dist/internal-NveCwJWd.d.cts +169 -0
- package/dist/internal-NveCwJWd.d.ts +169 -0
- package/dist/internal.cjs +47 -0
- package/dist/internal.cjs.map +1 -0
- package/dist/internal.d.cts +3 -0
- package/dist/internal.d.ts +3 -0
- package/dist/internal.js +47 -0
- package/dist/internal.js.map +1 -0
- package/package.json +73 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Matt Putnam
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @andamento/dom
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[Andamento](https://mattputnam.github.io/andamento/) tiling layouts without a framework. Use the `<andamento-layout>` web
|
|
4
|
+
component in plain HTML, Angular, Svelte, Solid or Lit, or mount a layout into any element
|
|
5
|
+
with `mountTileLayout()`. Any content goes in the tiles, clipped to their shapes, with
|
|
6
|
+
keyboard navigation, animated transitions and virtualization.
|
|
7
|
+
|
|
8
|
+
**[Manual](https://mattputnam.github.io/andamento/) · [Web component](https://mattputnam.github.io/andamento/frameworks/web-component) · [Plain DOM](https://mattputnam.github.io/andamento/frameworks/dom) · [API](https://mattputnam.github.io/andamento/reference/)**
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @andamento/core @andamento/dom
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```html
|
|
15
|
+
<script type="module">
|
|
16
|
+
import { defineTileLayoutElement } from "@andamento/dom";
|
|
17
|
+
defineTileLayoutElement();
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<andamento-layout
|
|
21
|
+
options='{"region":{"x":0,"y":0,"width":240,"height":150},"tiling":{"type":"hexagonal","size":26},"gap":2}'
|
|
22
|
+
navigable animate label="Photos">
|
|
23
|
+
<img src="beach.jpg" alt="Beach" />
|
|
24
|
+
<img src="hills.jpg" alt="Hills" />
|
|
25
|
+
</andamento-layout>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
MIT licensed.
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
9
|
+
|
|
10
|
+
// src/model.ts
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
var _core = require('@andamento/core');
|
|
27
|
+
var _svg = require('@andamento/svg');
|
|
28
|
+
var _internal = require('@andamento/svg/internal');
|
|
29
|
+
var resolvePerCell = (v, cell, state) => typeof v === "function" ? v(cell, state) : v;
|
|
30
|
+
var MORPH_POINTS = 72;
|
|
31
|
+
var functionIds = /* @__PURE__ */ new WeakMap();
|
|
32
|
+
var nextFunctionId = 1;
|
|
33
|
+
function optionsKey(value) {
|
|
34
|
+
return JSON.stringify(value, (_key, v) => {
|
|
35
|
+
if (typeof v !== "function") return v;
|
|
36
|
+
let id = functionIds.get(v);
|
|
37
|
+
if (!id) functionIds.set(v, id = nextFunctionId++);
|
|
38
|
+
return `\u0192${id}`;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function layoutResolver(component) {
|
|
42
|
+
let lastKey, lastCells, last;
|
|
43
|
+
return (options, layout, fit) => {
|
|
44
|
+
if (layout) return layout;
|
|
45
|
+
if (!options) throw new Error(`${component} needs either \`options\` or \`layout\``);
|
|
46
|
+
const fitting = !!_optionalChain([fit, 'optionalAccess', _2 => _2.fit]) && fit.count >= 1 && Number.isFinite(fit.count);
|
|
47
|
+
const mode = _optionalChain([fit, 'optionalAccess', _3 => _3.fit]) === "nearest" ? "nearest" : "atLeast";
|
|
48
|
+
const count = fit && Number.isFinite(fit.count) ? fit.count : 0;
|
|
49
|
+
const weights = _optionalChain([fit, 'optionalAccess', _4 => _4.weights, 'optionalAccess', _5 => _5.some, 'call', _6 => _6((w) => w > 1)]) && count > 0 ? Array.from({ length: count }, (_, i) => _nullishCoalesce(fit.weights[i], () => ( 1))) : void 0;
|
|
50
|
+
const cells = fitting || weights ? fit.cells : void 0;
|
|
51
|
+
const key = optionsKey([options, fitting && fit.count, mode, weights, weights && fit.placement]);
|
|
52
|
+
if (last && key === lastKey && cells === lastCells) return last;
|
|
53
|
+
last = weights ? _core.weightedLayout.call(void 0, options, weights, { fit: fitting && mode, cells, placement: fit.placement }).layout : fitting ? _core.fitCount.call(void 0, options, fit.count, { cells, mode }).layout : _core.createLayout.call(void 0, options);
|
|
54
|
+
lastKey = key;
|
|
55
|
+
lastCells = cells;
|
|
56
|
+
return last;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function frameBuilder() {
|
|
60
|
+
let slotKey = "", slotLayout, slotCells, slots = [];
|
|
61
|
+
let fillLayout, fillSource, fills = [];
|
|
62
|
+
let bevelKey = "", bevelLayout, bevels = /* @__PURE__ */ new Map();
|
|
63
|
+
return (layout, o) => {
|
|
64
|
+
const key = JSON.stringify([o.count === Infinity ? -1 : o.count, o.aspects, o.placement, o.choose, typeof o.contentCells === "function" ? 0 : o.contentCells]);
|
|
65
|
+
if (layout !== slotLayout || key !== slotKey || o.contentCells !== slotCells) {
|
|
66
|
+
slots = o.aspects && o.count !== Infinity ? _core.matchSlots.call(void 0, layout, Array.from({ length: o.count }, (_, i) => _nullishCoalesce(o.aspects[i], () => ( 1))), { cells: o.contentCells, placement: o.placement, choose: o.choose }) : _core.contentSlots.call(void 0, layout, o.count, { cells: o.contentCells, placement: o.placement });
|
|
67
|
+
slotLayout = layout;
|
|
68
|
+
slotKey = key;
|
|
69
|
+
slotCells = o.contentCells;
|
|
70
|
+
}
|
|
71
|
+
const fill = _nullishCoalesce(o.fill, () => ( _svg.neutralPalette));
|
|
72
|
+
if (layout !== fillLayout || fill !== fillSource) {
|
|
73
|
+
fills = _internal.resolveFills.call(void 0, layout, fill);
|
|
74
|
+
fillLayout = layout;
|
|
75
|
+
fillSource = fill;
|
|
76
|
+
}
|
|
77
|
+
const relief = o.relief === true ? {} : o.relief || void 0;
|
|
78
|
+
const rk = relief ? optionsKey(relief) : "";
|
|
79
|
+
if (layout !== bevelLayout || rk !== bevelKey) {
|
|
80
|
+
bevels = /* @__PURE__ */ new Map();
|
|
81
|
+
bevelLayout = layout;
|
|
82
|
+
bevelKey = rk;
|
|
83
|
+
}
|
|
84
|
+
const width = relief ? _nullishCoalesce(relief.bevel, () => ( _svg.defaultBevel.call(void 0, layout))) : 0;
|
|
85
|
+
const cache = bevels;
|
|
86
|
+
const anim = o.animate ? {
|
|
87
|
+
duration: _nullishCoalesce((typeof o.animate === "object" ? o.animate.duration : void 0), () => ( 400)),
|
|
88
|
+
easing: _nullishCoalesce((typeof o.animate === "object" ? o.animate.easing : void 0), () => ( "cubic-bezier(0.2, 0.8, 0.2, 1)"))
|
|
89
|
+
} : void 0;
|
|
90
|
+
const timing = anim ? `${anim.duration}ms ${anim.easing}` : "";
|
|
91
|
+
const boxTransition = anim ? ["left", "top", "width", "height"].map((p) => `${p} ${timing}`).join(", ") : void 0;
|
|
92
|
+
return {
|
|
93
|
+
layout,
|
|
94
|
+
slots,
|
|
95
|
+
fills,
|
|
96
|
+
bevel(i) {
|
|
97
|
+
if (!relief || width <= 0) return void 0;
|
|
98
|
+
let b = cache.get(i);
|
|
99
|
+
if (!b) cache.set(i, b = _svg.reliefPaths.call(void 0, layout, layout.cells[i], relief, width));
|
|
100
|
+
return b;
|
|
101
|
+
},
|
|
102
|
+
shadow: relief ? _svg.shadowOffset.call(void 0, relief) : void 0,
|
|
103
|
+
anim,
|
|
104
|
+
boxTransition,
|
|
105
|
+
tileTransition: anim ? `${boxTransition}, clip-path ${timing}, background-color ${timing}` : void 0
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
var containerStyle = (layout) => ({
|
|
110
|
+
position: "relative",
|
|
111
|
+
width: "100%",
|
|
112
|
+
aspectRatio: `${layout.bounds.width} / ${layout.bounds.height}`
|
|
113
|
+
});
|
|
114
|
+
var backgroundStyle = (frame, background) => ({
|
|
115
|
+
position: "absolute",
|
|
116
|
+
inset: "0",
|
|
117
|
+
background,
|
|
118
|
+
clipPath: _core.regionCss.call(void 0, frame.layout),
|
|
119
|
+
transition: frame.anim ? `clip-path ${frame.anim.duration}ms ${frame.anim.easing}` : void 0
|
|
120
|
+
});
|
|
121
|
+
function tileStyle(frame, cell, o) {
|
|
122
|
+
return {
|
|
123
|
+
...o.focus && !o.empty ? focusStyle(frame, cell, o.focus, o.aspect) : {},
|
|
124
|
+
position: "absolute",
|
|
125
|
+
boxSizing: "border-box",
|
|
126
|
+
overflow: "hidden",
|
|
127
|
+
..._core.cellCss.call(void 0, cell, frame.layout, 4, frame.anim ? { points: MORPH_POINTS } : {}),
|
|
128
|
+
transition: frame.tileTransition,
|
|
129
|
+
background: (o.empty || o.safeArea) && !o.backdrop ? frame.fills[cell.index] : void 0,
|
|
130
|
+
cursor: o.clickable ? "pointer" : void 0
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function focusStyle(frame, cell, focus, aspect) {
|
|
134
|
+
const shape = _nullishCoalesce(aspect, () => ( focus.aspect));
|
|
135
|
+
const pos = shape && shape > 0 ? _core.objectPosition.call(void 0, cell, frame.layout, { aspect: shape, focus }) : `${focus.x * 100}% ${focus.y * 100}%`;
|
|
136
|
+
return { "--andamento-object-position": pos };
|
|
137
|
+
}
|
|
138
|
+
var backdropStyle = (frame, cell) => ({
|
|
139
|
+
position: "absolute",
|
|
140
|
+
zIndex: -1,
|
|
141
|
+
pointerEvents: "none",
|
|
142
|
+
..._core.backdropCss.call(void 0, cell, frame.layout),
|
|
143
|
+
transition: frame.boxTransition
|
|
144
|
+
});
|
|
145
|
+
var safeBoxStyle = (frame, cell, aspect, safe) => ({
|
|
146
|
+
position: "absolute",
|
|
147
|
+
boxSizing: "border-box",
|
|
148
|
+
..._core.safeAreaCss.call(void 0, cell, frame.layout, { aspect, within: safe === "visible" ? "visible" : "tile" }),
|
|
149
|
+
transition: frame.boxTransition
|
|
150
|
+
});
|
|
151
|
+
var overlayStyle = { position: "absolute", inset: "0", width: "100%", height: "100%", pointerEvents: "none" };
|
|
152
|
+
var tileViewBox = (cell) => {
|
|
153
|
+
const b = _core.cellShape.call(void 0, cell).bbox;
|
|
154
|
+
return `${b.x} ${b.y} ${b.width} ${b.height}`;
|
|
155
|
+
};
|
|
156
|
+
var ringStrokes = (frame, cell, color) => {
|
|
157
|
+
const d = _svg.cellPath.call(void 0, frame.layout, cell);
|
|
158
|
+
return [
|
|
159
|
+
{ d, stroke: "#fff", width: 8 },
|
|
160
|
+
{ d, stroke: color, width: 4 }
|
|
161
|
+
];
|
|
162
|
+
};
|
|
163
|
+
function shadowShape(frame, cells) {
|
|
164
|
+
const s = frame.shadow;
|
|
165
|
+
if (!s) return void 0;
|
|
166
|
+
const { bounds } = frame.layout;
|
|
167
|
+
return {
|
|
168
|
+
viewBox: `${bounds.x} ${bounds.y} ${bounds.width} ${bounds.height}`,
|
|
169
|
+
style: { ...overlayStyle, clipPath: _core.viewCss.call(void 0, frame.layout) },
|
|
170
|
+
blur: s.blur,
|
|
171
|
+
d: cells.map((c) => _svg.cellPath.call(void 0, frame.layout, c)).join(""),
|
|
172
|
+
transform: `translate(${s.dx} ${s.dy})`,
|
|
173
|
+
opacity: s.opacity
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
var runs = /* @__PURE__ */ new WeakMap();
|
|
177
|
+
function navigationLane(layout, from, direction) {
|
|
178
|
+
const vertical = direction === "up" || direction === "down";
|
|
179
|
+
const run = runs.get(layout);
|
|
180
|
+
if (run && run.at === from.id && run.vertical === vertical) return run.lane;
|
|
181
|
+
return vertical ? from.centroid.x : from.centroid.y;
|
|
182
|
+
}
|
|
183
|
+
function keyAction(layout, from, key, accept, canActivate) {
|
|
184
|
+
const dirs = { ArrowUp: "up", ArrowDown: "down", ArrowLeft: "left", ArrowRight: "right" };
|
|
185
|
+
let to;
|
|
186
|
+
const dir = dirs[key];
|
|
187
|
+
if (dir) {
|
|
188
|
+
const lane = navigationLane(layout, from, dir);
|
|
189
|
+
to = _core.cellInDirection.call(void 0, layout, from, dir, { accept, lane });
|
|
190
|
+
if (to) runs.set(layout, { at: to.id, vertical: dir === "up" || dir === "down", lane });
|
|
191
|
+
} else if (key === "Home") to = layout.cells.find(accept);
|
|
192
|
+
else if (key === "End") to = [...layout.cells].reverse().find(accept);
|
|
193
|
+
else if ((key === "Enter" || key === " ") && canActivate) return { activate: true };
|
|
194
|
+
if (to) return { move: to };
|
|
195
|
+
return key.startsWith("Arrow") ? { prevent: true } : void 0;
|
|
196
|
+
}
|
|
197
|
+
function tileSheet(o) {
|
|
198
|
+
let css = "";
|
|
199
|
+
if (o.focusRing)
|
|
200
|
+
css += "[data-andamento]>[data-cell-id]:focus{outline:none}[data-andamento]>[data-cell-id]>[data-focus-ring]{display:none}[data-andamento]>[data-cell-id]:focus-visible>[data-focus-ring]{display:block}";
|
|
201
|
+
if (o.anim) {
|
|
202
|
+
const { duration, easing } = o.anim;
|
|
203
|
+
css += `@keyframes andamento-enter{from{opacity:0;transform:scale(.85)}}@keyframes andamento-exit{to{opacity:0;transform:scale(.85)}}@keyframes andamento-late{0%,70%{opacity:0}to{opacity:1}}[data-andamento]>[data-entering]{animation:andamento-enter ${duration}ms ${easing} backwards}[data-andamento]>[data-exiting]{animation:andamento-exit ${duration}ms ${easing} forwards;pointer-events:none}[data-andamento]>[data-cell-id]>[data-late]{animation:andamento-late ${duration}ms linear backwards}@media (prefers-reduced-motion:reduce){[data-andamento]>[data-cell-id],[data-andamento]>[data-cell-id] *{transition:none!important;animation:none!important}[data-andamento]>[data-exiting]{display:none}}`;
|
|
204
|
+
}
|
|
205
|
+
return css;
|
|
206
|
+
}
|
|
207
|
+
var NOTHING_IN_VIEW = { x: 0, y: 0, width: -1, height: -1 };
|
|
208
|
+
function viewRect(el, layout, overscan) {
|
|
209
|
+
const box = el.getBoundingClientRect();
|
|
210
|
+
const seen = visibleClientRect(el, box);
|
|
211
|
+
const { bounds } = layout;
|
|
212
|
+
const scale = Math.min(box.width / (bounds.width || 1), box.height / (bounds.height || 1));
|
|
213
|
+
if (!seen || !(scale > 0)) return NOTHING_IN_VIEW;
|
|
214
|
+
const a = _core.screenToLayout.call(void 0, layout, box, seen.left - overscan, seen.top - overscan);
|
|
215
|
+
const b = _core.screenToLayout.call(void 0, layout, box, seen.right + overscan, seen.bottom + overscan);
|
|
216
|
+
const q = Math.max(overscan / 2, 50) / scale;
|
|
217
|
+
const x0 = Math.floor(a.x / q) * q, y0 = Math.floor(a.y / q) * q;
|
|
218
|
+
return { x: x0, y: y0, width: Math.ceil(b.x / q) * q - x0, height: Math.ceil(b.y / q) * q - y0 };
|
|
219
|
+
}
|
|
220
|
+
var sameRect = (a, b) => !!a && !!b && a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
221
|
+
function watchView(el, measure) {
|
|
222
|
+
const raf = typeof requestAnimationFrame === "function" ? requestAnimationFrame : (f) => setTimeout(f, 16);
|
|
223
|
+
const cancel = typeof cancelAnimationFrame === "function" ? cancelAnimationFrame : (h) => clearTimeout(h);
|
|
224
|
+
let frame = 0;
|
|
225
|
+
const run = () => {
|
|
226
|
+
frame = 0;
|
|
227
|
+
measure();
|
|
228
|
+
};
|
|
229
|
+
const schedule = () => {
|
|
230
|
+
if (!frame) frame = raf(run);
|
|
231
|
+
};
|
|
232
|
+
measure();
|
|
233
|
+
window.addEventListener("scroll", schedule, { capture: true, passive: true });
|
|
234
|
+
window.addEventListener("resize", schedule);
|
|
235
|
+
const observer = typeof ResizeObserver === "function" ? new ResizeObserver(schedule) : void 0;
|
|
236
|
+
_optionalChain([observer, 'optionalAccess', _7 => _7.observe, 'call', _8 => _8(el)]);
|
|
237
|
+
return () => {
|
|
238
|
+
if (frame) cancel(frame);
|
|
239
|
+
window.removeEventListener("scroll", schedule, { capture: true });
|
|
240
|
+
window.removeEventListener("resize", schedule);
|
|
241
|
+
_optionalChain([observer, 'optionalAccess', _9 => _9.disconnect, 'call', _10 => _10()]);
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function visibleClientRect(el, box) {
|
|
245
|
+
let left = Math.max(box.left, 0);
|
|
246
|
+
let top = Math.max(box.top, 0);
|
|
247
|
+
let right = Math.min(box.right, window.innerWidth || document.documentElement.clientWidth);
|
|
248
|
+
let bottom = Math.min(box.bottom, window.innerHeight || document.documentElement.clientHeight);
|
|
249
|
+
const parent = (n) => _nullishCoalesce(n.parentElement, () => ( (_nullishCoalesce(_optionalChain([n, 'access', _11 => _11.parentNode, 'optionalAccess', _12 => _12.host]), () => ( null)))));
|
|
250
|
+
for (let p = parent(el); p && p !== document.body && p !== document.documentElement; p = parent(p)) {
|
|
251
|
+
const s = getComputedStyle(p);
|
|
252
|
+
if (/(auto|scroll|hidden|clip)/.test(`${s.overflow} ${s.overflowX} ${s.overflowY}`)) {
|
|
253
|
+
const r = p.getBoundingClientRect();
|
|
254
|
+
left = Math.max(left, r.left);
|
|
255
|
+
top = Math.max(top, r.top);
|
|
256
|
+
right = Math.min(right, r.right);
|
|
257
|
+
bottom = Math.min(bottom, r.bottom);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return right > left && bottom > top ? { left, top, right, bottom } : void 0;
|
|
261
|
+
}
|
|
262
|
+
var coverStyle = {
|
|
263
|
+
display: "block",
|
|
264
|
+
width: "100%",
|
|
265
|
+
height: "100%",
|
|
266
|
+
objectFit: "cover",
|
|
267
|
+
// Set by the tile from the item's focal point (see `focalPoints`); centerd otherwise.
|
|
268
|
+
objectPosition: "var(--andamento-object-position, 50% 50%)"
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
exports.__privateGet = __privateGet; exports.__privateAdd = __privateAdd; exports.__privateSet = __privateSet; exports.__privateMethod = __privateMethod; exports.resolvePerCell = resolvePerCell; exports.MORPH_POINTS = MORPH_POINTS; exports.optionsKey = optionsKey; exports.layoutResolver = layoutResolver; exports.frameBuilder = frameBuilder; exports.containerStyle = containerStyle; exports.backgroundStyle = backgroundStyle; exports.tileStyle = tileStyle; exports.focusStyle = focusStyle; exports.backdropStyle = backdropStyle; exports.safeBoxStyle = safeBoxStyle; exports.overlayStyle = overlayStyle; exports.tileViewBox = tileViewBox; exports.ringStrokes = ringStrokes; exports.shadowShape = shadowShape; exports.keyAction = keyAction; exports.tileSheet = tileSheet; exports.NOTHING_IN_VIEW = NOTHING_IN_VIEW; exports.viewRect = viewRect; exports.sameRect = sameRect; exports.watchView = watchView; exports.coverStyle = coverStyle;
|
|
299
|
+
//# sourceMappingURL=chunk-276TFSAG.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/matthewputnam/code/andamento/packages/dom/dist/chunk-276TFSAG.cjs","../src/model.ts"],"names":[],"mappings":"AAAA,qrBAAI,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG;AAC3B,EAAE,MAAM,SAAS,CAAC,GAAG,CAAC;AACtB,CAAC;AACD,IAAI,cAAc,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,WAAW,CAAC,UAAU,EAAE,GAAG,CAAC;AACzF,IAAI,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,yBAAyB,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAChJ,IAAI,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,WAAW,CAAC,mDAAmD,EAAE,EAAE,OAAO,WAAW,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC;AACpM,IAAI,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAA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AACA;AACA;AACA","file":"/Users/matthewputnam/code/andamento/packages/dom/dist/chunk-276TFSAG.cjs","sourcesContent":[null,"import {\n backdropCss,\n cellCss,\n cellShape,\n cellInDirection,\n contentSlots,\n createLayout,\n objectPosition,\n fitCount,\n matchSlots,\n regionCss,\n safeAreaCss,\n screenToLayout,\n viewCss,\n type Cell,\n type ContentCells,\n type ContentPlacement,\n type Direction,\n type Focus,\n type Layout,\n type LayoutOptions,\n type Rect,\n weightedLayout,\n} from \"@andamento/core\";\nimport { cellPath, defaultBevel, neutralPalette, reliefPaths, shadowOffset, type FillSource, type ReliefOptions, type ReliefPath } from \"@andamento/svg\";\nimport { resolveFills } from \"@andamento/svg/internal\";\n\n/**\n * The parts of an HTML tile layout that don't depend on a framework: what each tile's\n * element looks like, what keys do, what's in view. `mountTileLayout`, the\n * `<andamento-layout>` element and the Vue components all render from these.\n */\n\n/** How a layout's `fit` option sizes its tiles. */\nexport type FitProp = boolean | \"atLeast\" | \"nearest\";\n\n/** What a per-cell option function is told about the cell besides its geometry. */\nexport interface CellState {\n /** The cell has no content. */\n empty: boolean;\n /** Position among the cells that hold content, in reading order (the item index), or -1. */\n slot: number;\n}\n\n/**\n * Put each tile's content in its safe area: `true` or \"tile\" fits the whole tile (for a tile\n * an `edges: \"window\"` layout cuts, content near the edge is then partly hidden like the\n * tile), \"visible\" fits the part that shows. See `SafeAreaOptions.within`.\n */\nexport type SafeAreaProp = boolean | \"tile\" | \"visible\";\n\n/** A value, or a function giving it per cell. */\nexport type PerCell<T> = T | ((cell: Cell, state: CellState) => T);\n\nexport const resolvePerCell = <T>(v: PerCell<T> | undefined, cell: Cell, state: CellState): T | undefined =>\n typeof v === \"function\" ? (v as (c: Cell, s: CellState) => T)(cell, state) : v;\n\n/** Style as property → value, camelCase (`clipPath`) or custom (`--x`). */\nexport type StyleMap = Record<string, string | number | undefined>;\n\n/** Clip paths get this many points when animating, so any two tile shapes can morph. */\nexport const MORPH_POINTS = 72;\n\nconst functionIds = new WeakMap<object, number>();\nlet nextFunctionId = 1;\n\n/**\n * A key for options that changes when they change: compared by value, with any function in\n * them (`sizeAt`, say) by identity, which JSON alone would leave out.\n */\nexport function optionsKey(value: unknown): string {\n return JSON.stringify(value, (_key, v: unknown) => {\n if (typeof v !== \"function\") return v;\n let id = functionIds.get(v);\n if (!id) functionIds.set(v, (id = nextFunctionId++));\n return `\\u0192${id}`;\n });\n}\n\n/** What a layout's items need from it: how many there are, and how they're sized and placed. */\nexport interface LayoutNeeds {\n fit?: FitProp;\n count: number;\n cells?: ContentCells;\n /** Tiles each item spans (see `weightedLayout`); heavier items get featured tiles. */\n weights?: readonly number[];\n placement?: ContentPlacement;\n}\n\n/**\n * A layout from options, worked out again only when they change (compared by value; a\n * `cells` function by identity). Returns `layout` itself when given.\n */\nexport function layoutResolver(component: string) {\n let lastKey: string | undefined, lastCells: ContentCells | undefined, last: Layout | undefined;\n return (options: LayoutOptions | undefined, layout: Layout | undefined, fit?: LayoutNeeds): Layout => {\n if (layout) return layout;\n if (!options) throw new Error(`${component} needs either \\`options\\` or \\`layout\\``);\n const fitting = !!fit?.fit && fit.count >= 1 && Number.isFinite(fit.count);\n const mode = fit?.fit === \"nearest\" ? \"nearest\" : \"atLeast\";\n // One weight per item, 1 for any not given; only items that are there count.\n const count = fit && Number.isFinite(fit.count) ? fit.count : 0;\n const weights = fit?.weights?.some((w) => w > 1) && count > 0 ? Array.from({ length: count }, (_, i) => fit.weights![i] ?? 1) : undefined;\n const cells = fitting || weights ? fit!.cells : undefined;\n const key = optionsKey([options, fitting && fit!.count, mode, weights, weights && fit!.placement]);\n if (last && key === lastKey && cells === lastCells) return last;\n last = weights\n ? weightedLayout(options, weights, { fit: fitting && mode, cells, placement: fit!.placement }).layout\n : fitting\n ? fitCount(options, fit!.count, { cells, mode }).layout\n : createLayout(options);\n lastKey = key;\n lastCells = cells;\n return last;\n };\n}\n\nexport interface FrameOptions {\n /** How many items there are to place (Infinity when every allowed cell gets content). */\n count: number;\n aspects?: readonly number[];\n contentCells?: ContentCells;\n placement?: ContentPlacement;\n choose?: \"placement\" | \"shape\";\n fill?: FillSource;\n relief?: boolean | ReliefOptions;\n animate?: boolean | { duration?: number; easing?: string };\n}\n\n/** Everything about a layout's tiles shared between them. */\nexport interface Frame {\n layout: Layout;\n /** Item index per cell, or -1. */\n slots: number[];\n /** Empty-tile color per cell. */\n fills: string[];\n /** Bevel paths for a cell (worked out on first use), or undefined without relief. */\n bevel(index: number): ReliefPath[] | undefined;\n shadow?: { dx: number; dy: number; blur: number; opacity: number };\n anim?: { duration: number; easing: string };\n /** `left, top, width, height` transitions, when animating. */\n boxTransition?: string;\n tileTransition?: string;\n}\n\n/** Builds frames, reusing the slots, fills and bevels of the last one where nothing they depend on changed. */\nexport function frameBuilder() {\n let slotKey = \"\", slotLayout: Layout | undefined, slotCells: ContentCells | undefined, slots: number[] = [];\n let fillLayout: Layout | undefined, fillSource: FillSource | undefined, fills: string[] = [];\n let bevelKey = \"\", bevelLayout: Layout | undefined, bevels = new Map<number, ReliefPath[]>();\n return (layout: Layout, o: FrameOptions): Frame => {\n const key = JSON.stringify([o.count === Infinity ? -1 : o.count, o.aspects, o.placement, o.choose, typeof o.contentCells === \"function\" ? 0 : o.contentCells]);\n if (layout !== slotLayout || key !== slotKey || o.contentCells !== slotCells) {\n slots = o.aspects && o.count !== Infinity\n ? matchSlots(layout, Array.from({ length: o.count }, (_, i) => o.aspects![i] ?? 1), { cells: o.contentCells, placement: o.placement, choose: o.choose })\n : contentSlots(layout, o.count, { cells: o.contentCells, placement: o.placement });\n slotLayout = layout;\n slotKey = key;\n slotCells = o.contentCells;\n }\n const fill = o.fill ?? neutralPalette;\n if (layout !== fillLayout || fill !== fillSource) {\n fills = resolveFills(layout, fill);\n fillLayout = layout;\n fillSource = fill;\n }\n const relief = o.relief === true ? {} : o.relief || undefined;\n const rk = relief ? optionsKey(relief) : \"\";\n if (layout !== bevelLayout || rk !== bevelKey) {\n bevels = new Map();\n bevelLayout = layout;\n bevelKey = rk;\n }\n const width = relief ? (relief.bevel ?? defaultBevel(layout)) : 0;\n const cache = bevels;\n const anim = o.animate\n ? {\n duration: (typeof o.animate === \"object\" ? o.animate.duration : undefined) ?? 400,\n easing: (typeof o.animate === \"object\" ? o.animate.easing : undefined) ?? \"cubic-bezier(0.2, 0.8, 0.2, 1)\",\n }\n : undefined;\n const timing = anim ? `${anim.duration}ms ${anim.easing}` : \"\";\n const boxTransition = anim ? [\"left\", \"top\", \"width\", \"height\"].map((p) => `${p} ${timing}`).join(\", \") : undefined;\n return {\n layout,\n slots,\n fills,\n bevel(i) {\n if (!relief || width <= 0) return undefined;\n let b = cache.get(i);\n if (!b) cache.set(i, (b = reliefPaths(layout, layout.cells[i]!, relief, width)));\n return b;\n },\n shadow: relief ? shadowOffset(relief) : undefined,\n anim,\n boxTransition,\n tileTransition: anim ? `${boxTransition}, clip-path ${timing}, background-color ${timing}` : undefined,\n };\n };\n}\n\n/** Style of the element holding the layout. */\nexport const containerStyle = (layout: Layout): StyleMap => ({\n position: \"relative\",\n width: \"100%\",\n aspectRatio: `${layout.bounds.width} / ${layout.bounds.height}`,\n});\n\n/** Style of the element painting `background` across the region (seen through the gaps). */\nexport const backgroundStyle = (frame: Frame, background: string): StyleMap => ({\n position: \"absolute\",\n inset: \"0\",\n background,\n clipPath: regionCss(frame.layout),\n transition: frame.anim ? `clip-path ${frame.anim.duration}ms ${frame.anim.easing}` : undefined,\n});\n\n/**\n * A tile's element: placed over its cell's bounding box and clipped to its shape. Empty\n * tiles (and every tile with `safeArea`) show their fill unless there's a backdrop.\n */\nexport function tileStyle(\n frame: Frame,\n cell: Cell,\n o: { empty: boolean; safeArea?: SafeAreaProp; backdrop?: boolean; clickable?: boolean; focus?: Focus; aspect?: number },\n): StyleMap {\n return {\n ...(o.focus && !o.empty ? focusStyle(frame, cell, o.focus, o.aspect) : {}),\n position: \"absolute\",\n boxSizing: \"border-box\",\n overflow: \"hidden\",\n ...cellCss(cell, frame.layout, 4, frame.anim ? { points: MORPH_POINTS } : {}),\n transition: frame.tileTransition,\n background: (o.empty || o.safeArea) && !o.backdrop ? frame.fills[cell.index] : undefined,\n cursor: o.clickable ? \"pointer\" : undefined,\n };\n}\n\n/**\n * The `--andamento-object-position` a tile sets for its content's focal point, which\n * `coverStyle` uses as its `object-position`. Exact with the image's `aspect` (given, or the focus's own; see\n * `objectPosition`); without, the focus as a percentage, which CSS keeps at the same place\n * in the tile's box rather than in the middle of what shows.\n */\nexport function focusStyle(frame: Frame, cell: Cell, focus: Focus, aspect?: number): StyleMap {\n const shape = aspect ?? focus.aspect;\n const pos = shape && shape > 0 ? objectPosition(cell, frame.layout, { aspect: shape, focus }) : `${focus.x * 100}% ${focus.y * 100}%`;\n return { \"--andamento-object-position\": pos };\n}\n\n/** A backdrop copy inside a tile: behind its content, covering the whole layout. */\nexport const backdropStyle = (frame: Frame, cell: Cell): StyleMap => ({\n position: \"absolute\",\n zIndex: -1,\n pointerEvents: \"none\",\n ...backdropCss(cell, frame.layout),\n transition: frame.boxTransition,\n});\n\n/** The box holding a tile's content with `safeArea`. */\nexport const safeBoxStyle = (frame: Frame, cell: Cell, aspect?: number, safe?: SafeAreaProp): StyleMap => ({\n position: \"absolute\",\n boxSizing: \"border-box\",\n ...safeAreaCss(cell, frame.layout, { aspect, within: safe === \"visible\" ? \"visible\" : \"tile\" }),\n transition: frame.boxTransition,\n});\n\n/** Style of an <svg> drawn over a tile (bevel, focus ring), with `viewBox` set to `tileViewBox`. */\nexport const overlayStyle: StyleMap = { position: \"absolute\", inset: \"0\", width: \"100%\", height: \"100%\", pointerEvents: \"none\" };\n\nexport const tileViewBox = (cell: Cell) => {\n const b = cellShape(cell).bbox;\n return `${b.x} ${b.y} ${b.width} ${b.height}`;\n};\n\n/** The focus ring's two strokes: white under the color, so it shows on any content. */\nexport const ringStrokes = (frame: Frame, cell: Cell, color: string) => {\n const d = cellPath(frame.layout, cell);\n return [\n { d, stroke: \"#fff\", width: 8 },\n { d, stroke: color, width: 4 },\n ];\n};\n\n/** The shadow tiles cast into the grout (with relief's `shadow`), for an <svg> over the region. */\nexport function shadowShape(frame: Frame, cells: readonly Cell[]) {\n const s = frame.shadow;\n if (!s) return undefined;\n const { bounds } = frame.layout;\n return {\n viewBox: `${bounds.x} ${bounds.y} ${bounds.width} ${bounds.height}`,\n style: { ...overlayStyle, clipPath: viewCss(frame.layout) } as StyleMap,\n blur: s.blur,\n d: cells.map((c) => cellPath(frame.layout, c)).join(\"\"),\n transform: `translate(${s.dx} ${s.dy})`,\n opacity: s.opacity,\n };\n}\n\n/** Where the last run of arrow presses along an axis started, per layout. */\nconst runs = new WeakMap<Layout, { at: string; vertical: boolean; lane: number }>();\n\n/**\n * The lane for a move (see `DirectionOptions.lane`): the one the last move along the same\n * axis used, if that move ended at `from`, else `from`'s own center. So holding one arrow\n * key keeps to a column (or row), zigzagging through hexagons or bricks.\n */\nfunction navigationLane(layout: Layout, from: Cell, direction: Direction): number {\n const vertical = direction === \"up\" || direction === \"down\";\n const run = runs.get(layout);\n if (run && run.at === from.id && run.vertical === vertical) return run.lane;\n return vertical ? from.centroid.x : from.centroid.y;\n}\n\n/**\n * What a key does on a focused tile: move focus to another tile, activate it, or just stop\n * the page scrolling (arrows at the edge). Undefined for keys that aren't ours.\n */\nexport function keyAction(\n layout: Layout,\n from: Cell,\n key: string,\n accept: (cell: Cell) => boolean,\n canActivate: boolean,\n): { move: Cell } | { activate: true } | { prevent: true } | undefined {\n const dirs: Record<string, Direction> = { ArrowUp: \"up\", ArrowDown: \"down\", ArrowLeft: \"left\", ArrowRight: \"right\" };\n let to: Cell | undefined;\n const dir = dirs[key];\n if (dir) {\n const lane = navigationLane(layout, from, dir);\n to = cellInDirection(layout, from, dir, { accept, lane });\n if (to) runs.set(layout, { at: to.id, vertical: dir === \"up\" || dir === \"down\", lane });\n } else if (key === \"Home\") to = layout.cells.find(accept);\n else if (key === \"End\") to = [...layout.cells].reverse().find(accept);\n else if ((key === \"Enter\" || key === \" \") && canActivate) return { activate: true };\n if (to) return { move: to };\n return key.startsWith(\"Arrow\") ? { prevent: true } : undefined;\n}\n\n/** Style sheet text for focus rings and animation (empty when neither is on). */\nexport function tileSheet(o: { focusRing: boolean; anim?: { duration: number; easing: string } }): string {\n let css = \"\";\n // The ring shows only on keyboard focus; a CSS outline would be clipped away anyway.\n if (o.focusRing)\n css +=\n \"[data-andamento]>[data-cell-id]:focus{outline:none}\" +\n \"[data-andamento]>[data-cell-id]>[data-focus-ring]{display:none}\" +\n \"[data-andamento]>[data-cell-id]:focus-visible>[data-focus-ring]{display:block}\";\n if (o.anim) {\n const { duration, easing } = o.anim;\n css +=\n \"@keyframes andamento-enter{from{opacity:0;transform:scale(.85)}}\" +\n \"@keyframes andamento-exit{to{opacity:0;transform:scale(.85)}}\" +\n \"@keyframes andamento-late{0%,70%{opacity:0}to{opacity:1}}\" +\n `[data-andamento]>[data-entering]{animation:andamento-enter ${duration}ms ${easing} backwards}` +\n `[data-andamento]>[data-exiting]{animation:andamento-exit ${duration}ms ${easing} forwards;pointer-events:none}` +\n `[data-andamento]>[data-cell-id]>[data-late]{animation:andamento-late ${duration}ms linear backwards}` +\n \"@media (prefers-reduced-motion:reduce){[data-andamento]>[data-cell-id],[data-andamento]>[data-cell-id] *{transition:none!important;animation:none!important}\" +\n \"[data-andamento]>[data-exiting]{display:none}}\";\n }\n return css;\n}\n\n/** \"Nothing in view\": `view` before the layout has been measured, or when it's off screen. */\nexport const NOTHING_IN_VIEW: Rect = { x: 0, y: 0, width: -1, height: -1 };\n\n/**\n * The part of the layout in view (in layout units), widened by `overscan` pixels and\n * snapped outwards to a coarse grid so small scrolls give the same rectangle.\n */\nexport function viewRect(el: Element, layout: Layout, overscan: number): Rect {\n const box = el.getBoundingClientRect();\n const seen = visibleClientRect(el, box);\n const { bounds } = layout;\n const scale = Math.min(box.width / (bounds.width || 1), box.height / (bounds.height || 1));\n if (!seen || !(scale > 0)) return NOTHING_IN_VIEW;\n const a = screenToLayout(layout, box, seen.left - overscan, seen.top - overscan);\n const b = screenToLayout(layout, box, seen.right + overscan, seen.bottom + overscan);\n const q = Math.max(overscan / 2, 50) / scale;\n const x0 = Math.floor(a.x / q) * q, y0 = Math.floor(a.y / q) * q;\n return { x: x0, y: y0, width: Math.ceil(b.x / q) * q - x0, height: Math.ceil(b.y / q) * q - y0 };\n}\n\nexport const sameRect = (a: Rect | undefined, b: Rect | undefined) =>\n !!a && !!b && a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;\n\n/**\n * Call `measure` now and again (at most once a frame) whenever the page or any scrolling\n * container scrolls, the window resizes or `el` does. Returns a function that stops it.\n */\nexport function watchView(el: Element, measure: () => void): () => void {\n const raf = typeof requestAnimationFrame === \"function\" ? requestAnimationFrame : (f: () => void) => setTimeout(f, 16) as unknown as number;\n const cancel = typeof cancelAnimationFrame === \"function\" ? cancelAnimationFrame : (h: number) => clearTimeout(h);\n let frame = 0;\n const run = () => {\n frame = 0;\n measure();\n };\n const schedule = () => {\n if (!frame) frame = raf(run);\n };\n measure();\n window.addEventListener(\"scroll\", schedule, { capture: true, passive: true });\n window.addEventListener(\"resize\", schedule);\n const observer = typeof ResizeObserver === \"function\" ? new ResizeObserver(schedule) : undefined;\n observer?.observe(el);\n return () => {\n if (frame) cancel(frame);\n window.removeEventListener(\"scroll\", schedule, { capture: true });\n window.removeEventListener(\"resize\", schedule);\n observer?.disconnect();\n };\n}\n\n/**\n * The part of `el` (whose box is `box`) visible on screen: within the window and every\n * ancestor that clips its overflow (across shadow roots too). Undefined when none of it is.\n */\nfunction visibleClientRect(el: Element, box: DOMRect) {\n let left = Math.max(box.left, 0);\n let top = Math.max(box.top, 0);\n let right = Math.min(box.right, window.innerWidth || document.documentElement.clientWidth);\n let bottom = Math.min(box.bottom, window.innerHeight || document.documentElement.clientHeight);\n const parent = (n: Element): Element | null => n.parentElement ?? ((n.parentNode as ShadowRoot | null)?.host ?? null);\n for (let p = parent(el); p && p !== document.body && p !== document.documentElement; p = parent(p)) {\n const s = getComputedStyle(p);\n if (/(auto|scroll|hidden|clip)/.test(`${s.overflow} ${s.overflowX} ${s.overflowY}`)) {\n const r = p.getBoundingClientRect();\n left = Math.max(left, r.left);\n top = Math.max(top, r.top);\n right = Math.min(right, r.right);\n bottom = Math.min(bottom, r.bottom);\n }\n }\n return right > left && bottom > top ? { left, top, right, bottom } : undefined;\n}\n\n/** Style that makes an <img> or <video> cover its tile, like `object-fit: cover`. */\nexport const coverStyle: StyleMap = {\n display: \"block\",\n width: \"100%\",\n height: \"100%\",\n objectFit: \"cover\",\n // Set by the tile from the item's focal point (see `focalPoints`); centerd otherwise.\n objectPosition: \"var(--andamento-object-position, 50% 50%)\",\n};\n"]}
|