@andamento/dom 0.0.0-stage → 0.1.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/index.cjs +1004 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +400 -0
- package/dist/index.d.ts +400 -0
- package/dist/index.js +967 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -4
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1004 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __typeError = (msg) => {
|
|
7
|
+
throw TypeError(msg);
|
|
8
|
+
};
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
23
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
24
|
+
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);
|
|
25
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
26
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
27
|
+
|
|
28
|
+
// src/index.ts
|
|
29
|
+
var index_exports = {};
|
|
30
|
+
__export(index_exports, {
|
|
31
|
+
AndamentoLayoutElement: () => AndamentoLayoutElement,
|
|
32
|
+
MORPH_POINTS: () => MORPH_POINTS,
|
|
33
|
+
NOTHING_IN_VIEW: () => NOTHING_IN_VIEW,
|
|
34
|
+
backdropStyle: () => backdropStyle,
|
|
35
|
+
backgroundStyle: () => backgroundStyle,
|
|
36
|
+
cellFromPointer: () => cellFromPointer,
|
|
37
|
+
containerStyle: () => containerStyle,
|
|
38
|
+
coverStyle: () => coverStyle,
|
|
39
|
+
defaultPalette: () => import_svg2.defaultPalette,
|
|
40
|
+
defineTileLayoutElement: () => defineTileLayoutElement,
|
|
41
|
+
focusStyle: () => focusStyle,
|
|
42
|
+
frameBuilder: () => frameBuilder,
|
|
43
|
+
keyAction: () => keyAction,
|
|
44
|
+
layoutResolver: () => layoutResolver,
|
|
45
|
+
mountTileLayout: () => mountTileLayout,
|
|
46
|
+
neutralPalette: () => import_svg2.neutralPalette,
|
|
47
|
+
overlayStyle: () => overlayStyle,
|
|
48
|
+
resolvePerCell: () => resolvePerCell,
|
|
49
|
+
ringStrokes: () => ringStrokes,
|
|
50
|
+
safeBoxStyle: () => safeBoxStyle,
|
|
51
|
+
sameRect: () => sameRect,
|
|
52
|
+
shadowShape: () => shadowShape,
|
|
53
|
+
tileSheet: () => tileSheet,
|
|
54
|
+
tileStyle: () => tileStyle,
|
|
55
|
+
tileViewBox: () => tileViewBox,
|
|
56
|
+
viewRect: () => viewRect,
|
|
57
|
+
watchView: () => watchView
|
|
58
|
+
});
|
|
59
|
+
module.exports = __toCommonJS(index_exports);
|
|
60
|
+
|
|
61
|
+
// src/mount.ts
|
|
62
|
+
var import_core2 = require("@andamento/core");
|
|
63
|
+
|
|
64
|
+
// src/model.ts
|
|
65
|
+
var import_core = require("@andamento/core");
|
|
66
|
+
var import_svg = require("@andamento/svg");
|
|
67
|
+
var resolvePerCell = (v, cell, state) => typeof v === "function" ? v(cell, state) : v;
|
|
68
|
+
var MORPH_POINTS = 72;
|
|
69
|
+
var PLACEHOLDER = { region: { x: 0, y: 0, width: 1, height: 1 }, tiling: { type: "grid", width: 1 } };
|
|
70
|
+
function layoutResolver(component) {
|
|
71
|
+
let lastKey, lastCells, last;
|
|
72
|
+
return (options, layout, fit) => {
|
|
73
|
+
if (layout) return layout;
|
|
74
|
+
if (!options) throw new Error(`${component} needs either \`options\` or \`layout\``);
|
|
75
|
+
const fitting = !!fit?.fit && fit.count >= 1 && Number.isFinite(fit.count);
|
|
76
|
+
const mode = fit?.fit === "nearest" ? "nearest" : "atLeast";
|
|
77
|
+
const count = fit && Number.isFinite(fit.count) ? fit.count : 0;
|
|
78
|
+
const weights = fit?.weights?.some((w) => w > 1) && count > 0 ? Array.from({ length: count }, (_, i) => fit.weights[i] ?? 1) : void 0;
|
|
79
|
+
const cells = fitting || weights ? fit.cells : void 0;
|
|
80
|
+
const key = JSON.stringify([options, fitting && fit.count, mode, weights, weights && fit.placement]);
|
|
81
|
+
if (last && key === lastKey && cells === lastCells) return last;
|
|
82
|
+
last = weights ? (0, import_core.weightedLayout)(options, weights, { fit: fitting && mode, cells, placement: fit.placement }).layout : fitting ? (0, import_core.fitCount)(options, fit.count, { cells, mode }).layout : (0, import_core.createLayout)(options ?? PLACEHOLDER);
|
|
83
|
+
lastKey = key;
|
|
84
|
+
lastCells = cells;
|
|
85
|
+
return last;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function frameBuilder() {
|
|
89
|
+
let slotKey = "", slotLayout, slotCells, slots = [];
|
|
90
|
+
let fillLayout, fillSource, fills = [];
|
|
91
|
+
let bevelKey = "", bevelLayout, bevels = /* @__PURE__ */ new Map();
|
|
92
|
+
return (layout, o) => {
|
|
93
|
+
const key = JSON.stringify([o.count === Infinity ? -1 : o.count, o.aspects, o.placement, o.choose, typeof o.contentCells === "function" ? 0 : o.contentCells]);
|
|
94
|
+
if (layout !== slotLayout || key !== slotKey || o.contentCells !== slotCells) {
|
|
95
|
+
slots = o.aspects && o.count !== Infinity ? (0, import_core.matchSlots)(layout, Array.from({ length: o.count }, (_, i) => o.aspects[i] ?? 1), { cells: o.contentCells, placement: o.placement, choose: o.choose }) : (0, import_core.contentSlots)(layout, o.count, { cells: o.contentCells, placement: o.placement });
|
|
96
|
+
slotLayout = layout;
|
|
97
|
+
slotKey = key;
|
|
98
|
+
slotCells = o.contentCells;
|
|
99
|
+
}
|
|
100
|
+
const fill = o.fill ?? import_svg.neutralPalette;
|
|
101
|
+
if (layout !== fillLayout || fill !== fillSource) {
|
|
102
|
+
fills = (0, import_svg.resolveFills)(layout, fill);
|
|
103
|
+
fillLayout = layout;
|
|
104
|
+
fillSource = fill;
|
|
105
|
+
}
|
|
106
|
+
const relief = o.relief === true ? {} : o.relief || void 0;
|
|
107
|
+
const rk = relief ? JSON.stringify(relief) : "";
|
|
108
|
+
if (layout !== bevelLayout || rk !== bevelKey) {
|
|
109
|
+
bevels = /* @__PURE__ */ new Map();
|
|
110
|
+
bevelLayout = layout;
|
|
111
|
+
bevelKey = rk;
|
|
112
|
+
}
|
|
113
|
+
const width = relief ? relief.bevel ?? (0, import_svg.defaultBevel)(layout) : 0;
|
|
114
|
+
const cache = bevels;
|
|
115
|
+
const anim = o.animate ? {
|
|
116
|
+
duration: (typeof o.animate === "object" ? o.animate.duration : void 0) ?? 400,
|
|
117
|
+
easing: (typeof o.animate === "object" ? o.animate.easing : void 0) ?? "cubic-bezier(0.2, 0.8, 0.2, 1)"
|
|
118
|
+
} : void 0;
|
|
119
|
+
const timing = anim ? `${anim.duration}ms ${anim.easing}` : "";
|
|
120
|
+
const boxTransition = anim ? ["left", "top", "width", "height"].map((p) => `${p} ${timing}`).join(", ") : void 0;
|
|
121
|
+
return {
|
|
122
|
+
layout,
|
|
123
|
+
slots,
|
|
124
|
+
fills,
|
|
125
|
+
bevel(i) {
|
|
126
|
+
if (!relief || width <= 0) return void 0;
|
|
127
|
+
let b = cache.get(i);
|
|
128
|
+
if (!b) cache.set(i, b = (0, import_svg.reliefPaths)(layout, layout.cells[i], relief, width));
|
|
129
|
+
return b;
|
|
130
|
+
},
|
|
131
|
+
shadow: relief ? (0, import_svg.shadowOffset)(relief) : void 0,
|
|
132
|
+
anim,
|
|
133
|
+
boxTransition,
|
|
134
|
+
tileTransition: anim ? `${boxTransition}, clip-path ${timing}, background-color ${timing}` : void 0
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
var containerStyle = (layout) => ({
|
|
139
|
+
position: "relative",
|
|
140
|
+
width: "100%",
|
|
141
|
+
aspectRatio: `${layout.bounds.width} / ${layout.bounds.height}`
|
|
142
|
+
});
|
|
143
|
+
var backgroundStyle = (frame, background) => ({
|
|
144
|
+
position: "absolute",
|
|
145
|
+
inset: "0",
|
|
146
|
+
background,
|
|
147
|
+
clipPath: (0, import_core.regionCss)(frame.layout),
|
|
148
|
+
transition: frame.anim ? `clip-path ${frame.anim.duration}ms ${frame.anim.easing}` : void 0
|
|
149
|
+
});
|
|
150
|
+
function tileStyle(frame, cell, o) {
|
|
151
|
+
return {
|
|
152
|
+
...o.focus && !o.empty ? focusStyle(frame, cell, o.focus, o.aspect) : {},
|
|
153
|
+
position: "absolute",
|
|
154
|
+
boxSizing: "border-box",
|
|
155
|
+
overflow: "hidden",
|
|
156
|
+
...(0, import_core.cellCss)(cell, frame.layout, 4, frame.anim ? { points: MORPH_POINTS } : {}),
|
|
157
|
+
transition: frame.tileTransition,
|
|
158
|
+
background: (o.empty || o.safeArea) && !o.backdrop ? frame.fills[cell.index] : void 0,
|
|
159
|
+
cursor: o.clickable ? "pointer" : void 0
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function focusStyle(frame, cell, focus, aspect) {
|
|
163
|
+
const shape = aspect ?? focus.aspect;
|
|
164
|
+
const pos = shape && shape > 0 ? (0, import_core.objectPosition)(cell, frame.layout, { aspect: shape, focus }) : `${focus.x * 100}% ${focus.y * 100}%`;
|
|
165
|
+
return { "--andamento-object-position": pos };
|
|
166
|
+
}
|
|
167
|
+
var backdropStyle = (frame, cell) => ({
|
|
168
|
+
position: "absolute",
|
|
169
|
+
zIndex: -1,
|
|
170
|
+
pointerEvents: "none",
|
|
171
|
+
...(0, import_core.backdropCss)(cell, frame.layout),
|
|
172
|
+
transition: frame.boxTransition
|
|
173
|
+
});
|
|
174
|
+
var safeBoxStyle = (frame, cell, aspect, safe) => ({
|
|
175
|
+
position: "absolute",
|
|
176
|
+
boxSizing: "border-box",
|
|
177
|
+
...(0, import_core.safeAreaCss)(cell, frame.layout, { aspect, within: safe === "visible" ? "visible" : "tile" }),
|
|
178
|
+
transition: frame.boxTransition
|
|
179
|
+
});
|
|
180
|
+
var overlayStyle = { position: "absolute", inset: "0", width: "100%", height: "100%", pointerEvents: "none" };
|
|
181
|
+
var tileViewBox = (cell) => {
|
|
182
|
+
const b = (0, import_core.cellShape)(cell).bbox;
|
|
183
|
+
return `${b.x} ${b.y} ${b.width} ${b.height}`;
|
|
184
|
+
};
|
|
185
|
+
var ringStrokes = (frame, cell, color) => {
|
|
186
|
+
const d = (0, import_svg.cellPath)(frame.layout, cell);
|
|
187
|
+
return [
|
|
188
|
+
{ d, stroke: "#fff", width: 8 },
|
|
189
|
+
{ d, stroke: color, width: 4 }
|
|
190
|
+
];
|
|
191
|
+
};
|
|
192
|
+
function shadowShape(frame, cells) {
|
|
193
|
+
const s = frame.shadow;
|
|
194
|
+
if (!s) return void 0;
|
|
195
|
+
const { bounds } = frame.layout;
|
|
196
|
+
return {
|
|
197
|
+
viewBox: `${bounds.x} ${bounds.y} ${bounds.width} ${bounds.height}`,
|
|
198
|
+
style: { ...overlayStyle, clipPath: (0, import_core.viewCss)(frame.layout) },
|
|
199
|
+
blur: s.blur,
|
|
200
|
+
d: cells.map((c) => (0, import_svg.cellPath)(frame.layout, c)).join(""),
|
|
201
|
+
transform: `translate(${s.dx} ${s.dy})`,
|
|
202
|
+
opacity: s.opacity
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
function keyAction(layout, from, key, accept, canActivate) {
|
|
206
|
+
const dirs = { ArrowUp: "up", ArrowDown: "down", ArrowLeft: "left", ArrowRight: "right" };
|
|
207
|
+
let to;
|
|
208
|
+
if (dirs[key]) to = (0, import_core.cellInDirection)(layout, from, dirs[key], accept);
|
|
209
|
+
else if (key === "Home") to = layout.cells.find(accept);
|
|
210
|
+
else if (key === "End") to = [...layout.cells].reverse().find(accept);
|
|
211
|
+
else if ((key === "Enter" || key === " ") && canActivate) return { activate: true };
|
|
212
|
+
if (to) return { move: to };
|
|
213
|
+
return key.startsWith("Arrow") ? { prevent: true } : void 0;
|
|
214
|
+
}
|
|
215
|
+
function tileSheet(o) {
|
|
216
|
+
let css = "";
|
|
217
|
+
if (o.focusRing)
|
|
218
|
+
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}";
|
|
219
|
+
if (o.anim) {
|
|
220
|
+
const { duration, easing } = o.anim;
|
|
221
|
+
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}}`;
|
|
222
|
+
}
|
|
223
|
+
return css;
|
|
224
|
+
}
|
|
225
|
+
var NOTHING_IN_VIEW = { x: 0, y: 0, width: -1, height: -1 };
|
|
226
|
+
function viewRect(el, layout, overscan) {
|
|
227
|
+
const box = el.getBoundingClientRect();
|
|
228
|
+
const seen = visibleClientRect(el, box);
|
|
229
|
+
const { bounds } = layout;
|
|
230
|
+
const scale = Math.min(box.width / (bounds.width || 1), box.height / (bounds.height || 1));
|
|
231
|
+
if (!seen || !(scale > 0)) return NOTHING_IN_VIEW;
|
|
232
|
+
const a = (0, import_core.screenToLayout)(layout, box, seen.left - overscan, seen.top - overscan);
|
|
233
|
+
const b = (0, import_core.screenToLayout)(layout, box, seen.right + overscan, seen.bottom + overscan);
|
|
234
|
+
const q = Math.max(overscan / 2, 50) / scale;
|
|
235
|
+
const x0 = Math.floor(a.x / q) * q, y0 = Math.floor(a.y / q) * q;
|
|
236
|
+
return { x: x0, y: y0, width: Math.ceil(b.x / q) * q - x0, height: Math.ceil(b.y / q) * q - y0 };
|
|
237
|
+
}
|
|
238
|
+
var sameRect = (a, b) => !!a && !!b && a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
239
|
+
function watchView(el, measure) {
|
|
240
|
+
const raf = typeof requestAnimationFrame === "function" ? requestAnimationFrame : (f) => setTimeout(f, 16);
|
|
241
|
+
const cancel = typeof cancelAnimationFrame === "function" ? cancelAnimationFrame : (h) => clearTimeout(h);
|
|
242
|
+
let frame = 0;
|
|
243
|
+
const run = () => {
|
|
244
|
+
frame = 0;
|
|
245
|
+
measure();
|
|
246
|
+
};
|
|
247
|
+
const schedule = () => {
|
|
248
|
+
if (!frame) frame = raf(run);
|
|
249
|
+
};
|
|
250
|
+
measure();
|
|
251
|
+
window.addEventListener("scroll", schedule, { capture: true, passive: true });
|
|
252
|
+
window.addEventListener("resize", schedule);
|
|
253
|
+
const observer = typeof ResizeObserver === "function" ? new ResizeObserver(schedule) : void 0;
|
|
254
|
+
observer?.observe(el);
|
|
255
|
+
return () => {
|
|
256
|
+
if (frame) cancel(frame);
|
|
257
|
+
window.removeEventListener("scroll", schedule, { capture: true });
|
|
258
|
+
window.removeEventListener("resize", schedule);
|
|
259
|
+
observer?.disconnect();
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
function visibleClientRect(el, box) {
|
|
263
|
+
let left = Math.max(box.left, 0);
|
|
264
|
+
let top = Math.max(box.top, 0);
|
|
265
|
+
let right = Math.min(box.right, window.innerWidth || document.documentElement.clientWidth);
|
|
266
|
+
let bottom = Math.min(box.bottom, window.innerHeight || document.documentElement.clientHeight);
|
|
267
|
+
const parent = (n) => n.parentElement ?? (n.parentNode?.host ?? null);
|
|
268
|
+
for (let p = parent(el); p && p !== document.body && p !== document.documentElement; p = parent(p)) {
|
|
269
|
+
const s = getComputedStyle(p);
|
|
270
|
+
if (/(auto|scroll|hidden|clip)/.test(`${s.overflow} ${s.overflowX} ${s.overflowY}`)) {
|
|
271
|
+
const r = p.getBoundingClientRect();
|
|
272
|
+
left = Math.max(left, r.left);
|
|
273
|
+
top = Math.max(top, r.top);
|
|
274
|
+
right = Math.min(right, r.right);
|
|
275
|
+
bottom = Math.min(bottom, r.bottom);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return right > left && bottom > top ? { left, top, right, bottom } : void 0;
|
|
279
|
+
}
|
|
280
|
+
var coverStyle = {
|
|
281
|
+
display: "block",
|
|
282
|
+
width: "100%",
|
|
283
|
+
height: "100%",
|
|
284
|
+
objectFit: "cover",
|
|
285
|
+
// Set by the tile from the item's focal point (see `focalPoints`); centerd otherwise.
|
|
286
|
+
objectPosition: "var(--andamento-object-position, 50% 50%)"
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
// src/mount.ts
|
|
290
|
+
var SVG = "http://www.w3.org/2000/svg";
|
|
291
|
+
var kebab = (k) => k.startsWith("--") ? k : k.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
|
|
292
|
+
var isEmpty = (c) => c == null || c === "";
|
|
293
|
+
var styleMemo = /* @__PURE__ */ new WeakMap();
|
|
294
|
+
function applyStyle(el, next) {
|
|
295
|
+
const prev = styleMemo.get(el) ?? {};
|
|
296
|
+
for (const k of Object.keys(prev)) if (next[k] === void 0 && prev[k] !== void 0) el.style.removeProperty(kebab(k));
|
|
297
|
+
for (const [k, v] of Object.entries(next)) if (v !== void 0 && prev[k] !== v) el.style.setProperty(kebab(k), String(v));
|
|
298
|
+
styleMemo.set(el, next);
|
|
299
|
+
}
|
|
300
|
+
function attr(el, name, value) {
|
|
301
|
+
if (value === void 0 || value === null || value === false) {
|
|
302
|
+
if (el.hasAttribute(name)) el.removeAttribute(name);
|
|
303
|
+
} else {
|
|
304
|
+
const v = value === true ? "" : String(value);
|
|
305
|
+
if (el.getAttribute(name) !== v) el.setAttribute(name, v);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function setChildren(parent, nodes) {
|
|
309
|
+
let at = parent.firstChild;
|
|
310
|
+
for (const n of nodes) {
|
|
311
|
+
if (n === at) at = at.nextSibling;
|
|
312
|
+
else parent.insertBefore(n, at);
|
|
313
|
+
}
|
|
314
|
+
while (at) {
|
|
315
|
+
const next = at.nextSibling;
|
|
316
|
+
parent.removeChild(at);
|
|
317
|
+
at = next;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function svg(tag, attrs, children = []) {
|
|
321
|
+
const el = document.createElementNS(SVG, tag);
|
|
322
|
+
for (const [k, v] of Object.entries(attrs)) if (v !== void 0) el.setAttribute(k, String(v));
|
|
323
|
+
for (const c of children) el.appendChild(c);
|
|
324
|
+
return el;
|
|
325
|
+
}
|
|
326
|
+
var nodeIds = /* @__PURE__ */ new WeakMap();
|
|
327
|
+
var nextNodeId = 1;
|
|
328
|
+
var nodeId = (n) => {
|
|
329
|
+
let id = nodeIds.get(n);
|
|
330
|
+
if (!id) nodeIds.set(n, id = nextNodeId++);
|
|
331
|
+
return id;
|
|
332
|
+
};
|
|
333
|
+
var uidCount = 0;
|
|
334
|
+
function mountTileLayout(target, initial) {
|
|
335
|
+
let config = { ...initial };
|
|
336
|
+
const uid = `andamento-dom${++uidCount}`;
|
|
337
|
+
const resolveLayout = layoutResolver("mountTileLayout");
|
|
338
|
+
const buildFrame = frameBuilder();
|
|
339
|
+
const container = document.createElement("div");
|
|
340
|
+
container.setAttribute("data-andamento", "");
|
|
341
|
+
target.appendChild(container);
|
|
342
|
+
const sheet = document.createElement("style");
|
|
343
|
+
const backgroundEl = document.createElement("div");
|
|
344
|
+
backgroundEl.setAttribute("aria-hidden", "true");
|
|
345
|
+
const blur = svg("feGaussianBlur", {});
|
|
346
|
+
const shadowPath = svg("path", { "fill-rule": "evenodd", fill: "#000", filter: `url(#${uid}-shadow)` });
|
|
347
|
+
const shadowEl = svg("svg", { "aria-hidden": "true", "data-andamento-shadow": "", preserveAspectRatio: "none" }, [
|
|
348
|
+
svg("filter", { id: `${uid}-shadow`, x: "-10%", y: "-10%", width: "120%", height: "120%" }, [blur]),
|
|
349
|
+
shadowPath
|
|
350
|
+
]);
|
|
351
|
+
let layout;
|
|
352
|
+
let tiles = /* @__PURE__ */ new Map();
|
|
353
|
+
const leaving = /* @__PURE__ */ new Set();
|
|
354
|
+
const byElement = /* @__PURE__ */ new WeakMap();
|
|
355
|
+
let lastKeys = /* @__PURE__ */ new Set();
|
|
356
|
+
let mounted = false;
|
|
357
|
+
let activeId;
|
|
358
|
+
let pendingFocus;
|
|
359
|
+
let focusable = /* @__PURE__ */ new Set();
|
|
360
|
+
let view;
|
|
361
|
+
let stopWatching;
|
|
362
|
+
let watchedLayout;
|
|
363
|
+
const timers = /* @__PURE__ */ new Set();
|
|
364
|
+
let destroyed = false;
|
|
365
|
+
function render() {
|
|
366
|
+
if (destroyed) return;
|
|
367
|
+
const c = config;
|
|
368
|
+
const items = c.renderCell ? [] : c.items ?? [];
|
|
369
|
+
layout = resolveLayout(c.options, c.layout, {
|
|
370
|
+
fit: !c.renderCell && c.fit,
|
|
371
|
+
count: items.length,
|
|
372
|
+
cells: c.contentCells,
|
|
373
|
+
weights: c.renderCell ? void 0 : c.weights,
|
|
374
|
+
placement: c.placement
|
|
375
|
+
});
|
|
376
|
+
const frame = buildFrame(layout, {
|
|
377
|
+
count: c.renderCell ? Infinity : items.length,
|
|
378
|
+
aspects: c.renderCell ? void 0 : c.aspects,
|
|
379
|
+
contentCells: c.contentCells,
|
|
380
|
+
placement: c.placement,
|
|
381
|
+
choose: c.choose,
|
|
382
|
+
fill: c.fill,
|
|
383
|
+
relief: c.relief,
|
|
384
|
+
animate: c.animate
|
|
385
|
+
});
|
|
386
|
+
const { slots } = frame;
|
|
387
|
+
const focusRing = c.focusRing === void 0 ? "#1a56db" : c.focusRing;
|
|
388
|
+
const list = (c.role ?? "list") === "list";
|
|
389
|
+
const virtual = !!c.virtualize;
|
|
390
|
+
const keyOf = (i) => {
|
|
391
|
+
const slot = slots[i];
|
|
392
|
+
if (!c.renderCell && slot >= 0) {
|
|
393
|
+
const item = items[slot];
|
|
394
|
+
return item && typeof item === "object" ? `n${nodeId(item)}` : `i${slot}`;
|
|
395
|
+
}
|
|
396
|
+
return `c${layout.cells[i].id}`;
|
|
397
|
+
};
|
|
398
|
+
const hasContent = (i) => c.renderCell ? slots[i] >= 0 : slots[i] >= 0 && !isEmpty(items[slots[i]]);
|
|
399
|
+
focusable = new Set(c.navigable ? layout.cells.filter((cell) => hasContent(cell.index)).map((cell) => cell.id) : []);
|
|
400
|
+
const firstFocusable = layout.cells.find((cell) => focusable.has(cell.id))?.id;
|
|
401
|
+
const active = activeId !== void 0 && focusable.has(activeId) ? activeId : firstFocusable;
|
|
402
|
+
let shown;
|
|
403
|
+
if (!virtual) shown = layout.cells.map((_, i) => i);
|
|
404
|
+
else {
|
|
405
|
+
const s = new Set(view && view.width >= 0 ? (0, import_core2.cellsInRect)(layout, view).map((cell) => cell.index) : []);
|
|
406
|
+
const a = active !== void 0 ? layout.cells.find((cell) => cell.id === active) : void 0;
|
|
407
|
+
if (a) s.add(a.index);
|
|
408
|
+
shown = [...s].sort((x, y) => x - y);
|
|
409
|
+
}
|
|
410
|
+
let positions;
|
|
411
|
+
if (virtual) {
|
|
412
|
+
positions = /* @__PURE__ */ new Map();
|
|
413
|
+
for (const cell of layout.cells) if (hasContent(cell.index)) positions.set(cell.index, positions.size + 1);
|
|
414
|
+
}
|
|
415
|
+
const allKeys = frame.anim || virtual ? new Set(layout.cells.map((_, i) => keyOf(i))) : void 0;
|
|
416
|
+
const next = /* @__PURE__ */ new Map();
|
|
417
|
+
for (const i of shown) {
|
|
418
|
+
const cell = layout.cells[i];
|
|
419
|
+
const slot = slots[i];
|
|
420
|
+
const key = keyOf(i);
|
|
421
|
+
let content = c.renderCell ? c.renderCell(cell, { slot }) : slot >= 0 ? items[slot] : void 0;
|
|
422
|
+
const empty = isEmpty(content);
|
|
423
|
+
const state = { empty, slot: empty && !c.renderCell ? -1 : slot };
|
|
424
|
+
if (empty) content = resolvePerCell(c.fallback, cell, state);
|
|
425
|
+
const silent = empty && isEmpty(content);
|
|
426
|
+
let tile = tiles.get(key);
|
|
427
|
+
if (!tile || tile.leaving) {
|
|
428
|
+
const el2 = document.createElement("div");
|
|
429
|
+
tile = { key, el: el2, cell, state, empty };
|
|
430
|
+
if (frame.anim && mounted && !lastKeys.has(key)) el2.setAttribute("data-entering", "");
|
|
431
|
+
}
|
|
432
|
+
tiles.delete(key);
|
|
433
|
+
next.set(key, tile);
|
|
434
|
+
Object.assign(tile, { cell, state, empty });
|
|
435
|
+
const el = tile.el;
|
|
436
|
+
byElement.set(el, tile);
|
|
437
|
+
const canFocus = focusable.has(cell.id);
|
|
438
|
+
attr(el, "role", silent ? void 0 : list ? "listitem" : void 0);
|
|
439
|
+
attr(el, "aria-hidden", silent ? "true" : void 0);
|
|
440
|
+
attr(el, "aria-label", silent ? void 0 : resolvePerCell(c.cellLabel, cell, state));
|
|
441
|
+
attr(el, "aria-setsize", positions && list && !silent ? positions.size : void 0);
|
|
442
|
+
attr(el, "aria-posinset", positions && list && !silent ? positions.get(i) : void 0);
|
|
443
|
+
attr(el, "tabindex", canFocus ? cell.id === active ? 0 : -1 : void 0);
|
|
444
|
+
attr(el, "class", resolvePerCell(c.cellClass, cell, state) || void 0);
|
|
445
|
+
attr(el, "data-cell-id", cell.id);
|
|
446
|
+
attr(el, "data-index", cell.index);
|
|
447
|
+
attr(el, "data-empty", empty);
|
|
448
|
+
attr(el, "data-boundary", !!cell.boundary);
|
|
449
|
+
for (const [k, v] of Object.entries(resolvePerCell(c.cellAttributes, cell, state) ?? {})) attr(el, k, v);
|
|
450
|
+
applyStyle(el, {
|
|
451
|
+
...tileStyle(frame, cell, {
|
|
452
|
+
empty,
|
|
453
|
+
safeArea: c.safeArea,
|
|
454
|
+
backdrop: c.backdrop != null,
|
|
455
|
+
clickable: !!c.onCellActivate && !empty,
|
|
456
|
+
focus: slot >= 0 ? c.focalPoints?.[slot] : void 0,
|
|
457
|
+
aspect: slot >= 0 ? c.aspects?.[slot] : void 0
|
|
458
|
+
}),
|
|
459
|
+
...resolvePerCell(c.cellStyle, cell, state)
|
|
460
|
+
});
|
|
461
|
+
const kids = [];
|
|
462
|
+
if (c.backdrop != null) {
|
|
463
|
+
if (!tile.backdrop || tile.backdrop.source !== c.backdrop) {
|
|
464
|
+
const node2 = typeof c.backdrop === "function" ? c.backdrop() : c.backdrop.cloneNode(true);
|
|
465
|
+
const wrap = document.createElement("div");
|
|
466
|
+
wrap.setAttribute("aria-hidden", "true");
|
|
467
|
+
wrap.appendChild(node2);
|
|
468
|
+
tile.backdrop = { source: c.backdrop, node: wrap };
|
|
469
|
+
}
|
|
470
|
+
applyStyle(tile.backdrop.node, backdropStyle(frame, cell));
|
|
471
|
+
kids.push(tile.backdrop.node);
|
|
472
|
+
} else tile.backdrop = void 0;
|
|
473
|
+
let node;
|
|
474
|
+
if (typeof content === "string") {
|
|
475
|
+
if (!tile.text) tile.text = document.createTextNode(content);
|
|
476
|
+
else if (tile.text.data !== content) tile.text.data = content;
|
|
477
|
+
node = tile.text;
|
|
478
|
+
} else if (content) node = content;
|
|
479
|
+
if (node && c.safeArea) {
|
|
480
|
+
if (!tile.safe) {
|
|
481
|
+
tile.safe = document.createElement("div");
|
|
482
|
+
tile.safe.setAttribute("data-safe-area", "");
|
|
483
|
+
}
|
|
484
|
+
const aspect = !c.renderCell && !empty && c.aspects ? c.aspects[slot] ?? 1 : void 0;
|
|
485
|
+
applyStyle(tile.safe, safeBoxStyle(frame, cell, aspect, c.safeArea));
|
|
486
|
+
setChildren(tile.safe, [node]);
|
|
487
|
+
kids.push(tile.safe);
|
|
488
|
+
} else if (node) kids.push(node);
|
|
489
|
+
const bevel = frame.bevel(i);
|
|
490
|
+
if (bevel && bevel.length) {
|
|
491
|
+
const clip = frame.anim ? String(el.style.getPropertyValue("clip-path")) : "";
|
|
492
|
+
const bk = tileViewBox(cell) + clip + bevel.map((p) => p.d + p.fill + p.opacity).join();
|
|
493
|
+
if (tile.bevel?.key !== bk) {
|
|
494
|
+
const s = svg(
|
|
495
|
+
"svg",
|
|
496
|
+
{ "aria-hidden": "true", "data-bevel": "", "data-late": frame.anim ? "" : void 0, viewBox: tileViewBox(cell), preserveAspectRatio: "none" },
|
|
497
|
+
bevel.map((p) => svg("path", { d: p.d, fill: p.fill, "fill-opacity": p.opacity }))
|
|
498
|
+
);
|
|
499
|
+
applyStyle(s, overlayStyle);
|
|
500
|
+
tile.bevel = { key: bk, node: s };
|
|
501
|
+
}
|
|
502
|
+
kids.push(tile.bevel.node);
|
|
503
|
+
} else tile.bevel = void 0;
|
|
504
|
+
if (canFocus && focusRing !== false) {
|
|
505
|
+
const strokes = ringStrokes(frame, cell, focusRing);
|
|
506
|
+
const rk = tileViewBox(cell) + strokes[0].d + focusRing;
|
|
507
|
+
if (tile.ring?.key !== rk) {
|
|
508
|
+
const s = svg(
|
|
509
|
+
"svg",
|
|
510
|
+
{ "aria-hidden": "true", "data-focus-ring": "", viewBox: tileViewBox(cell), preserveAspectRatio: "none" },
|
|
511
|
+
strokes.map((p) => svg("path", { d: p.d, fill: "none", stroke: p.stroke, "stroke-width": p.width, "vector-effect": "non-scaling-stroke" }))
|
|
512
|
+
);
|
|
513
|
+
applyStyle(s, overlayStyle);
|
|
514
|
+
tile.ring = { key: rk, node: s };
|
|
515
|
+
}
|
|
516
|
+
kids.push(tile.ring.node);
|
|
517
|
+
} else tile.ring = void 0;
|
|
518
|
+
setChildren(el, kids);
|
|
519
|
+
}
|
|
520
|
+
const present = allKeys ?? new Set(next.keys());
|
|
521
|
+
for (const tile of tiles.values()) {
|
|
522
|
+
if (frame.anim && mounted && !present.has(tile.key)) startLeaving(tile, frame.anim.duration);
|
|
523
|
+
}
|
|
524
|
+
tiles = next;
|
|
525
|
+
attr(container, "role", c.role ?? "list");
|
|
526
|
+
attr(container, "aria-label", c.label);
|
|
527
|
+
attr(container, "class", c.className);
|
|
528
|
+
applyStyle(container, containerStyle(layout));
|
|
529
|
+
const css = tileSheet({ focusRing: !!c.navigable && focusRing !== false, anim: frame.anim });
|
|
530
|
+
if (sheet.textContent !== css) sheet.textContent = css;
|
|
531
|
+
const top = [];
|
|
532
|
+
if (css) top.push(sheet);
|
|
533
|
+
if (c.background) {
|
|
534
|
+
applyStyle(backgroundEl, backgroundStyle(frame, c.background));
|
|
535
|
+
top.push(backgroundEl);
|
|
536
|
+
}
|
|
537
|
+
const shadow = shadowShape(frame, shown.map((i) => layout.cells[i]));
|
|
538
|
+
if (shadow) {
|
|
539
|
+
attr(shadowEl, "viewBox", shadow.viewBox);
|
|
540
|
+
applyStyle(shadowEl, shadow.style);
|
|
541
|
+
attr(blur, "stdDeviation", shadow.blur);
|
|
542
|
+
attr(shadowPath, "d", shadow.d);
|
|
543
|
+
attr(shadowPath, "transform", shadow.transform);
|
|
544
|
+
attr(shadowPath, "fill-opacity", shadow.opacity);
|
|
545
|
+
top.push(shadowEl);
|
|
546
|
+
}
|
|
547
|
+
setChildren(container, [...top, ...[...tiles.values()].map((t) => t.el), ...[...leaving].map((t) => t.el)]);
|
|
548
|
+
lastKeys = present;
|
|
549
|
+
mounted = true;
|
|
550
|
+
if (pendingFocus) {
|
|
551
|
+
const t = [...tiles.values()].find((x) => x.cell.id === pendingFocus);
|
|
552
|
+
if (t) {
|
|
553
|
+
pendingFocus = void 0;
|
|
554
|
+
t.el.focus();
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
if (virtual && !stopWatching) stopWatching = watchView(container, measure);
|
|
558
|
+
else if (!virtual && stopWatching) {
|
|
559
|
+
stopWatching();
|
|
560
|
+
stopWatching = void 0;
|
|
561
|
+
view = void 0;
|
|
562
|
+
} else if (virtual && watchedLayout !== layout) queueMicrotask(measure);
|
|
563
|
+
watchedLayout = layout;
|
|
564
|
+
}
|
|
565
|
+
function measure() {
|
|
566
|
+
if (destroyed || !config.virtualize) return;
|
|
567
|
+
const overscan = Math.max(0, (typeof config.virtualize === "object" ? config.virtualize.overscan : void 0) ?? 300);
|
|
568
|
+
const next = viewRect(container, layout, overscan);
|
|
569
|
+
if (!sameRect(next, view)) {
|
|
570
|
+
view = next;
|
|
571
|
+
render();
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
function startLeaving(tile, duration) {
|
|
575
|
+
tile.leaving = true;
|
|
576
|
+
const el = tile.el;
|
|
577
|
+
for (const a of ["role", "tabindex", "aria-label", "aria-setsize", "aria-posinset", "data-entering"]) el.removeAttribute(a);
|
|
578
|
+
el.setAttribute("aria-hidden", "true");
|
|
579
|
+
el.setAttribute("data-exiting", "");
|
|
580
|
+
leaving.add(tile);
|
|
581
|
+
const timer = setTimeout(() => {
|
|
582
|
+
timers.delete(timer);
|
|
583
|
+
leaving.delete(tile);
|
|
584
|
+
el.remove();
|
|
585
|
+
}, duration);
|
|
586
|
+
timers.add(timer);
|
|
587
|
+
}
|
|
588
|
+
const tileOf = (e) => {
|
|
589
|
+
for (const n of e.composedPath()) {
|
|
590
|
+
if (n === container) return void 0;
|
|
591
|
+
if (n instanceof Element && n.parentNode === container) {
|
|
592
|
+
const t = byElement.get(n);
|
|
593
|
+
return t && !t.leaving ? t : void 0;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
return void 0;
|
|
597
|
+
};
|
|
598
|
+
const setActive = (id) => {
|
|
599
|
+
if (id === activeId) return;
|
|
600
|
+
activeId = id;
|
|
601
|
+
for (const t of tiles.values()) if (focusable.has(t.cell.id)) attr(t.el, "tabindex", t.cell.id === id ? 0 : -1);
|
|
602
|
+
};
|
|
603
|
+
const onClick = (e) => {
|
|
604
|
+
const t = tileOf(e);
|
|
605
|
+
if (t && !t.empty && config.onCellActivate) config.onCellActivate(t.cell, t.state);
|
|
606
|
+
};
|
|
607
|
+
const onFocusIn = (e) => {
|
|
608
|
+
const t = tileOf(e);
|
|
609
|
+
if (t && e.target === t.el && focusable.has(t.cell.id)) setActive(t.cell.id);
|
|
610
|
+
};
|
|
611
|
+
const onKeyDown = (e) => {
|
|
612
|
+
if (e.defaultPrevented || !config.navigable || e.altKey || e.ctrlKey || e.metaKey) return;
|
|
613
|
+
const t = tileOf(e);
|
|
614
|
+
if (!t || e.target !== t.el || !focusable.has(t.cell.id)) return;
|
|
615
|
+
const action = keyAction(layout, t.cell, e.key, (cell) => focusable.has(cell.id), !!config.onCellActivate);
|
|
616
|
+
if (!action) return;
|
|
617
|
+
e.preventDefault();
|
|
618
|
+
if ("activate" in action) config.onCellActivate(t.cell, t.state);
|
|
619
|
+
else if ("move" in action) {
|
|
620
|
+
const to = action.move;
|
|
621
|
+
setActive(to.id);
|
|
622
|
+
const shownTile = [...tiles.values()].find((x) => x.cell.id === to.id);
|
|
623
|
+
if (shownTile) shownTile.el.focus();
|
|
624
|
+
else {
|
|
625
|
+
pendingFocus = to.id;
|
|
626
|
+
render();
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
container.addEventListener("click", onClick);
|
|
631
|
+
container.addEventListener("focusin", onFocusIn);
|
|
632
|
+
container.addEventListener("keydown", onKeyDown);
|
|
633
|
+
render();
|
|
634
|
+
return {
|
|
635
|
+
element: container,
|
|
636
|
+
get layout() {
|
|
637
|
+
return layout;
|
|
638
|
+
},
|
|
639
|
+
update(changes) {
|
|
640
|
+
config = { ...config, ...changes };
|
|
641
|
+
render();
|
|
642
|
+
},
|
|
643
|
+
refresh: render,
|
|
644
|
+
tileElement(cellId) {
|
|
645
|
+
for (const t of tiles.values()) if (t.cell.id === cellId) return t.el;
|
|
646
|
+
return void 0;
|
|
647
|
+
},
|
|
648
|
+
destroy() {
|
|
649
|
+
destroyed = true;
|
|
650
|
+
stopWatching?.();
|
|
651
|
+
timers.forEach(clearTimeout);
|
|
652
|
+
container.removeEventListener("click", onClick);
|
|
653
|
+
container.removeEventListener("focusin", onFocusIn);
|
|
654
|
+
container.removeEventListener("keydown", onKeyDown);
|
|
655
|
+
for (const t of [...tiles.values(), ...leaving]) {
|
|
656
|
+
if (t.safe) setChildren(t.safe, []);
|
|
657
|
+
setChildren(t.el, []);
|
|
658
|
+
}
|
|
659
|
+
container.remove();
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// src/element.ts
|
|
665
|
+
var Base = typeof HTMLElement === "undefined" ? class {
|
|
666
|
+
} : HTMLElement;
|
|
667
|
+
var BOOLEAN = ["navigable", "animate", "relief", "safe-area", "virtualize"];
|
|
668
|
+
var ATTRIBUTES = [...BOOLEAN, "options", "fit", "placement", "content-cells", "choose", "background", "fill", "focus-ring", "label"];
|
|
669
|
+
var json = (v) => {
|
|
670
|
+
try {
|
|
671
|
+
return JSON.parse(v);
|
|
672
|
+
} catch {
|
|
673
|
+
throw new SyntaxError(`<andamento-layout>: not valid JSON: ${v}`);
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
var slotCount = 0;
|
|
677
|
+
var _config, _props, _handle, _observer, _queued, _slots, _items, _backdrop, _AndamentoLayoutElement_instances, backdropFor_fn, set_fn, schedule_fn, render_fn, configure_fn;
|
|
678
|
+
var AndamentoLayoutElement = class extends Base {
|
|
679
|
+
constructor() {
|
|
680
|
+
super();
|
|
681
|
+
__privateAdd(this, _AndamentoLayoutElement_instances);
|
|
682
|
+
__privateAdd(this, _config, {});
|
|
683
|
+
__privateAdd(this, _props, {});
|
|
684
|
+
__privateAdd(this, _handle);
|
|
685
|
+
__privateAdd(this, _observer);
|
|
686
|
+
__privateAdd(this, _queued, false);
|
|
687
|
+
__privateAdd(this, _slots, /* @__PURE__ */ new WeakMap());
|
|
688
|
+
__privateAdd(this, _items, []);
|
|
689
|
+
__privateAdd(this, _backdrop);
|
|
690
|
+
const root = this.attachShadow({ mode: "open" });
|
|
691
|
+
const style = document.createElement("style");
|
|
692
|
+
style.textContent = ":host{display:block}:host([hidden]){display:none}";
|
|
693
|
+
root.appendChild(style);
|
|
694
|
+
}
|
|
695
|
+
/** Layout options (also the `options` attribute, as JSON). */
|
|
696
|
+
get options() {
|
|
697
|
+
return __privateGet(this, _props).options;
|
|
698
|
+
}
|
|
699
|
+
set options(v) {
|
|
700
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, set_fn).call(this, { options: v });
|
|
701
|
+
}
|
|
702
|
+
/** A precomputed layout, instead of `options`. */
|
|
703
|
+
get layout() {
|
|
704
|
+
return __privateGet(this, _handle)?.layout ?? __privateGet(this, _props).layout;
|
|
705
|
+
}
|
|
706
|
+
set layout(v) {
|
|
707
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, set_fn).call(this, { layout: v });
|
|
708
|
+
}
|
|
709
|
+
/** Color of empty tiles: a color, a palette or a function per cell. */
|
|
710
|
+
get fill() {
|
|
711
|
+
return __privateGet(this, _props).fill;
|
|
712
|
+
}
|
|
713
|
+
set fill(v) {
|
|
714
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, set_fn).call(this, { fill: v });
|
|
715
|
+
}
|
|
716
|
+
get relief() {
|
|
717
|
+
return __privateGet(this, _props).relief;
|
|
718
|
+
}
|
|
719
|
+
set relief(v) {
|
|
720
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, set_fn).call(this, { relief: v });
|
|
721
|
+
}
|
|
722
|
+
/** Animate changes (the `animate` attribute; `animate` itself is the Web Animations method). */
|
|
723
|
+
get animated() {
|
|
724
|
+
return __privateGet(this, _props).animate;
|
|
725
|
+
}
|
|
726
|
+
set animated(v) {
|
|
727
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, set_fn).call(this, { animate: v });
|
|
728
|
+
}
|
|
729
|
+
get virtualize() {
|
|
730
|
+
return __privateGet(this, _props).virtualize;
|
|
731
|
+
}
|
|
732
|
+
set virtualize(v) {
|
|
733
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, set_fn).call(this, { virtualize: v });
|
|
734
|
+
}
|
|
735
|
+
get navigable() {
|
|
736
|
+
return __privateGet(this, _props).navigable;
|
|
737
|
+
}
|
|
738
|
+
set navigable(v) {
|
|
739
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, set_fn).call(this, { navigable: v });
|
|
740
|
+
}
|
|
741
|
+
get safeArea() {
|
|
742
|
+
return __privateGet(this, _props).safeArea;
|
|
743
|
+
}
|
|
744
|
+
set safeArea(v) {
|
|
745
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, set_fn).call(this, { safeArea: v });
|
|
746
|
+
}
|
|
747
|
+
get fit() {
|
|
748
|
+
return __privateGet(this, _props).fit;
|
|
749
|
+
}
|
|
750
|
+
set fit(v) {
|
|
751
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, set_fn).call(this, { fit: v });
|
|
752
|
+
}
|
|
753
|
+
get placement() {
|
|
754
|
+
return __privateGet(this, _props).placement;
|
|
755
|
+
}
|
|
756
|
+
set placement(v) {
|
|
757
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, set_fn).call(this, { placement: v });
|
|
758
|
+
}
|
|
759
|
+
get contentCells() {
|
|
760
|
+
return __privateGet(this, _props).contentCells;
|
|
761
|
+
}
|
|
762
|
+
set contentCells(v) {
|
|
763
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, set_fn).call(this, { contentCells: v });
|
|
764
|
+
}
|
|
765
|
+
get choose() {
|
|
766
|
+
return __privateGet(this, _props).choose;
|
|
767
|
+
}
|
|
768
|
+
set choose(v) {
|
|
769
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, set_fn).call(this, { choose: v });
|
|
770
|
+
}
|
|
771
|
+
/** Width / height of each child; otherwise read from children's `data-aspect`. */
|
|
772
|
+
get aspects() {
|
|
773
|
+
return __privateGet(this, _props).aspects;
|
|
774
|
+
}
|
|
775
|
+
set aspects(v) {
|
|
776
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, set_fn).call(this, { aspects: v });
|
|
777
|
+
}
|
|
778
|
+
/** Tiles each child spans; otherwise read from children's `data-weight`. */
|
|
779
|
+
get weights() {
|
|
780
|
+
return __privateGet(this, _props).weights;
|
|
781
|
+
}
|
|
782
|
+
set weights(v) {
|
|
783
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, set_fn).call(this, { weights: v });
|
|
784
|
+
}
|
|
785
|
+
/** Focal point of each child; otherwise read from children's `data-focus`. */
|
|
786
|
+
get focalPoints() {
|
|
787
|
+
return __privateGet(this, _props).focalPoints;
|
|
788
|
+
}
|
|
789
|
+
set focalPoints(v) {
|
|
790
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, set_fn).call(this, { focalPoints: v });
|
|
791
|
+
}
|
|
792
|
+
get background() {
|
|
793
|
+
return __privateGet(this, _props).background;
|
|
794
|
+
}
|
|
795
|
+
set background(v) {
|
|
796
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, set_fn).call(this, { background: v });
|
|
797
|
+
}
|
|
798
|
+
get focusRing() {
|
|
799
|
+
return __privateGet(this, _props).focusRing;
|
|
800
|
+
}
|
|
801
|
+
set focusRing(v) {
|
|
802
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, set_fn).call(this, { focusRing: v });
|
|
803
|
+
}
|
|
804
|
+
/** Accessible name of each tile. */
|
|
805
|
+
get cellLabel() {
|
|
806
|
+
return __privateGet(this, _props).cellLabel;
|
|
807
|
+
}
|
|
808
|
+
set cellLabel(v) {
|
|
809
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, set_fn).call(this, { cellLabel: v });
|
|
810
|
+
}
|
|
811
|
+
/** Extra style for each tile. */
|
|
812
|
+
get cellStyle() {
|
|
813
|
+
return __privateGet(this, _props).cellStyle;
|
|
814
|
+
}
|
|
815
|
+
set cellStyle(v) {
|
|
816
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, set_fn).call(this, { cellStyle: v });
|
|
817
|
+
}
|
|
818
|
+
/** Content for empty tiles (rendered in the shadow root). */
|
|
819
|
+
get fallback() {
|
|
820
|
+
return __privateGet(this, _props).fallback;
|
|
821
|
+
}
|
|
822
|
+
set fallback(v) {
|
|
823
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, set_fn).call(this, { fallback: v });
|
|
824
|
+
}
|
|
825
|
+
/** The tile element (in the shadow root) showing a cell, if it's rendered. */
|
|
826
|
+
tileElement(cellId) {
|
|
827
|
+
return __privateGet(this, _handle)?.tileElement(cellId);
|
|
828
|
+
}
|
|
829
|
+
connectedCallback() {
|
|
830
|
+
__privateSet(this, _observer, new MutationObserver((records) => {
|
|
831
|
+
if (records.some((r) => r.target === this || r.target.parentNode === this)) __privateMethod(this, _AndamentoLayoutElement_instances, schedule_fn).call(this);
|
|
832
|
+
}));
|
|
833
|
+
__privateGet(this, _observer).observe(this, { childList: true, subtree: true, attributes: true, attributeFilter: ["data-aspect", "data-focus", "data-weight", "slot"] });
|
|
834
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, schedule_fn).call(this);
|
|
835
|
+
}
|
|
836
|
+
disconnectedCallback() {
|
|
837
|
+
__privateGet(this, _observer)?.disconnect();
|
|
838
|
+
__privateSet(this, _observer, void 0);
|
|
839
|
+
__privateGet(this, _handle)?.destroy();
|
|
840
|
+
__privateSet(this, _handle, void 0);
|
|
841
|
+
}
|
|
842
|
+
attributeChangedCallback() {
|
|
843
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, schedule_fn).call(this);
|
|
844
|
+
}
|
|
845
|
+
/** Render now rather than at the end of the current task (e.g. before measuring). */
|
|
846
|
+
render() {
|
|
847
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, render_fn).call(this);
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
_config = new WeakMap();
|
|
851
|
+
_props = new WeakMap();
|
|
852
|
+
_handle = new WeakMap();
|
|
853
|
+
_observer = new WeakMap();
|
|
854
|
+
_queued = new WeakMap();
|
|
855
|
+
_slots = new WeakMap();
|
|
856
|
+
_items = new WeakMap();
|
|
857
|
+
_backdrop = new WeakMap();
|
|
858
|
+
_AndamentoLayoutElement_instances = new WeakSet();
|
|
859
|
+
/** The same function for the same backdrop child, so tiles keep their copies. */
|
|
860
|
+
backdropFor_fn = function(el) {
|
|
861
|
+
if (__privateGet(this, _backdrop)?.el !== el) __privateSet(this, _backdrop, { el, make: () => copyBackdrop(el) });
|
|
862
|
+
return __privateGet(this, _backdrop).make;
|
|
863
|
+
};
|
|
864
|
+
set_fn = function(changes) {
|
|
865
|
+
__privateSet(this, _props, { ...__privateGet(this, _props), ...changes });
|
|
866
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, schedule_fn).call(this);
|
|
867
|
+
};
|
|
868
|
+
/** Several changes in one go render once. */
|
|
869
|
+
schedule_fn = function() {
|
|
870
|
+
if (__privateGet(this, _queued)) return;
|
|
871
|
+
__privateSet(this, _queued, true);
|
|
872
|
+
queueMicrotask(() => {
|
|
873
|
+
__privateSet(this, _queued, false);
|
|
874
|
+
__privateMethod(this, _AndamentoLayoutElement_instances, render_fn).call(this);
|
|
875
|
+
});
|
|
876
|
+
};
|
|
877
|
+
render_fn = function() {
|
|
878
|
+
if (!this.isConnected) return;
|
|
879
|
+
const config = __privateMethod(this, _AndamentoLayoutElement_instances, configure_fn).call(this);
|
|
880
|
+
if (!config.options && !config.layout) return;
|
|
881
|
+
if (__privateGet(this, _handle)) __privateGet(this, _handle).update(config);
|
|
882
|
+
else {
|
|
883
|
+
__privateSet(this, _handle, mountTileLayout(this.shadowRoot, config));
|
|
884
|
+
__privateGet(this, _handle).element.setAttribute("part", "layout");
|
|
885
|
+
}
|
|
886
|
+
};
|
|
887
|
+
configure_fn = function() {
|
|
888
|
+
const a = (n) => this.getAttribute(n);
|
|
889
|
+
const flag = (n) => this.hasAttribute(n) && a(n) !== "false";
|
|
890
|
+
const fromAttrs = Object.fromEntries([...ATTRIBUTE_KEYS].map((k) => [k, void 0]));
|
|
891
|
+
if (a("options")) fromAttrs.options = json(a("options"));
|
|
892
|
+
for (const n of BOOLEAN) if (flag(n)) fromAttrs[n === "safe-area" ? "safeArea" : n] = true;
|
|
893
|
+
if (a("safe-area") === "tile" || a("safe-area") === "visible") fromAttrs.safeArea = a("safe-area");
|
|
894
|
+
if (a("fit")) fromAttrs.fit = a("fit") === "nearest" ? "nearest" : a("fit") === "false" ? false : true;
|
|
895
|
+
if (a("placement")) fromAttrs.placement = a("placement");
|
|
896
|
+
if (a("content-cells")) fromAttrs.contentCells = a("content-cells");
|
|
897
|
+
if (a("choose")) fromAttrs.choose = a("choose");
|
|
898
|
+
if (a("background")) fromAttrs.background = a("background");
|
|
899
|
+
if (a("fill")) fromAttrs.fill = a("fill").trim().startsWith("[") ? json(a("fill")) : a("fill");
|
|
900
|
+
if (a("focus-ring")) fromAttrs.focusRing = a("focus-ring") === "false" ? false : a("focus-ring");
|
|
901
|
+
if (a("label")) fromAttrs.label = a("label");
|
|
902
|
+
const children = [...this.children];
|
|
903
|
+
const backdrop = children.find((c) => c.getAttribute("slot") === "backdrop");
|
|
904
|
+
__privateSet(this, _items, children.filter((c) => c !== backdrop && c.localName !== "template"));
|
|
905
|
+
const items = __privateGet(this, _items).map((child) => {
|
|
906
|
+
let slot = __privateGet(this, _slots).get(child);
|
|
907
|
+
if (!slot) {
|
|
908
|
+
slot = document.createElement("slot");
|
|
909
|
+
slot.name = `andamento-${++slotCount}`;
|
|
910
|
+
__privateGet(this, _slots).set(child, slot);
|
|
911
|
+
}
|
|
912
|
+
if (child.getAttribute("slot") !== slot.name) child.setAttribute("slot", slot.name);
|
|
913
|
+
return slot;
|
|
914
|
+
});
|
|
915
|
+
const aspectAttrs = __privateGet(this, _items).map((c) => Number(c.getAttribute("data-aspect")));
|
|
916
|
+
const aspects = aspectAttrs.some((v) => v > 0) ? aspectAttrs.map((v) => v > 0 ? v : 1) : void 0;
|
|
917
|
+
const focusAttrs = __privateGet(this, _items).map((c) => {
|
|
918
|
+
const [x, y] = (c.getAttribute("data-focus") ?? "").trim().split(/[\s,]+/).map(Number);
|
|
919
|
+
return Number.isFinite(x) && Number.isFinite(y) && c.hasAttribute("data-focus") ? { x, y } : void 0;
|
|
920
|
+
});
|
|
921
|
+
const focalPoints = focusAttrs.some(Boolean) ? focusAttrs : void 0;
|
|
922
|
+
const weightAttrs = __privateGet(this, _items).map((c) => Number(c.getAttribute("data-weight")));
|
|
923
|
+
const weights = weightAttrs.some((v) => v > 1) ? weightAttrs.map((v) => v > 0 ? v : 1) : void 0;
|
|
924
|
+
__privateSet(this, _config, {
|
|
925
|
+
...fromAttrs,
|
|
926
|
+
aspects,
|
|
927
|
+
focalPoints,
|
|
928
|
+
weights,
|
|
929
|
+
...overrides(__privateGet(this, _props)),
|
|
930
|
+
items,
|
|
931
|
+
backdrop: backdrop ? __privateMethod(this, _AndamentoLayoutElement_instances, backdropFor_fn).call(this, backdrop) : void 0,
|
|
932
|
+
cellAttributes: (cell, state) => ({
|
|
933
|
+
part: ["tile", state.empty && "empty", cell.boundary && "boundary"].filter(Boolean).join(" ")
|
|
934
|
+
}),
|
|
935
|
+
onCellActivate: (cell, state) => {
|
|
936
|
+
const detail = { cell, slot: state.slot, item: __privateGet(this, _items)[state.slot] };
|
|
937
|
+
this.dispatchEvent(new CustomEvent("cellactivate", { detail, bubbles: true, composed: true }));
|
|
938
|
+
}
|
|
939
|
+
});
|
|
940
|
+
return __privateGet(this, _config);
|
|
941
|
+
};
|
|
942
|
+
AndamentoLayoutElement.observedAttributes = ATTRIBUTES;
|
|
943
|
+
var overrides = (props) => Object.fromEntries(Object.entries(props).filter(([k, v]) => v !== void 0 || !ATTRIBUTE_KEYS.has(k)));
|
|
944
|
+
var ATTRIBUTE_KEYS = /* @__PURE__ */ new Set(["options", "navigable", "animate", "relief", "safeArea", "virtualize", "fit", "placement", "contentCells", "choose", "background", "fill", "focusRing", "label", "aspects", "focalPoints", "weights"]);
|
|
945
|
+
function copyBackdrop(el) {
|
|
946
|
+
const copy = el.cloneNode(true);
|
|
947
|
+
copy.removeAttribute("slot");
|
|
948
|
+
if (/^(img|video|picture|canvas)$/.test(copy.localName)) {
|
|
949
|
+
for (const [k, v] of Object.entries(coverStyle)) copy.style.setProperty(k.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase()), String(v));
|
|
950
|
+
}
|
|
951
|
+
return copy;
|
|
952
|
+
}
|
|
953
|
+
function defineTileLayoutElement(tagName = "andamento-layout") {
|
|
954
|
+
if (typeof customElements === "undefined") return AndamentoLayoutElement;
|
|
955
|
+
const existing = customElements.get(tagName);
|
|
956
|
+
if (existing) return existing;
|
|
957
|
+
const cls = class extends AndamentoLayoutElement {
|
|
958
|
+
};
|
|
959
|
+
customElements.define(tagName, cls);
|
|
960
|
+
return cls;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
// src/pointer.ts
|
|
964
|
+
var import_core3 = require("@andamento/core");
|
|
965
|
+
function cellFromPointer(layout, event, options = {}) {
|
|
966
|
+
const el = options.element ?? event.currentTarget;
|
|
967
|
+
if (!el || typeof el.getBoundingClientRect !== "function") return void 0;
|
|
968
|
+
const point = (0, import_core3.screenToLayout)(layout, el.getBoundingClientRect(), event.clientX, event.clientY);
|
|
969
|
+
return (0, import_core3.cellAt)(layout, point, options);
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
// src/index.ts
|
|
973
|
+
var import_svg2 = require("@andamento/svg");
|
|
974
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
975
|
+
0 && (module.exports = {
|
|
976
|
+
AndamentoLayoutElement,
|
|
977
|
+
MORPH_POINTS,
|
|
978
|
+
NOTHING_IN_VIEW,
|
|
979
|
+
backdropStyle,
|
|
980
|
+
backgroundStyle,
|
|
981
|
+
cellFromPointer,
|
|
982
|
+
containerStyle,
|
|
983
|
+
coverStyle,
|
|
984
|
+
defaultPalette,
|
|
985
|
+
defineTileLayoutElement,
|
|
986
|
+
focusStyle,
|
|
987
|
+
frameBuilder,
|
|
988
|
+
keyAction,
|
|
989
|
+
layoutResolver,
|
|
990
|
+
mountTileLayout,
|
|
991
|
+
neutralPalette,
|
|
992
|
+
overlayStyle,
|
|
993
|
+
resolvePerCell,
|
|
994
|
+
ringStrokes,
|
|
995
|
+
safeBoxStyle,
|
|
996
|
+
sameRect,
|
|
997
|
+
shadowShape,
|
|
998
|
+
tileSheet,
|
|
999
|
+
tileStyle,
|
|
1000
|
+
tileViewBox,
|
|
1001
|
+
viewRect,
|
|
1002
|
+
watchView
|
|
1003
|
+
});
|
|
1004
|
+
//# sourceMappingURL=index.cjs.map
|