@andamento/react 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 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,26 @@
1
- # Temporary Holding Version
1
+ # @andamento/react
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ React components for [Andamento](https://mattputnam.github.io/andamento/) tiling layouts. Split a region into hexagons,
4
+ herringbone, Penrose rhombs, hats, jigsaw pieces and more, and put any children in the tiles,
5
+ clipped to their shapes. Includes photo matching, focal points, featured tiles, keyboard
6
+ navigation, animated transitions and virtualization.
7
+
8
+ **[Manual](https://mattputnam.github.io/andamento/) · [React](https://mattputnam.github.io/andamento/frameworks/react) · [Examples](https://mattputnam.github.io/andamento/examples/) · [API](https://mattputnam.github.io/andamento/reference/) · [Playground](https://mattputnam.github.io/andamento/playground/)**
9
+
10
+ ```bash
11
+ npm install @andamento/core @andamento/react
12
+ ```
13
+
14
+ ```tsx
15
+ import { TileLayout, coverStyle } from "@andamento/react";
16
+ import { hexagonal } from "@andamento/core";
17
+
18
+ <TileLayout
19
+ options={{ region: { x: 0, y: 0, width: 240, height: 150 }, tiling: hexagonal({ size: 26 }), gap: 2 }}
20
+ navigable animate aria-label="Photos"
21
+ >
22
+ {photos.map((p) => <img key={p.src} src={p.src} alt={p.alt} style={coverStyle} />)}
23
+ </TileLayout>
24
+ ```
25
+
26
+ MIT licensed.
package/dist/index.cjs ADDED
@@ -0,0 +1,580 @@
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 __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.tsx
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ SvgCellImage: () => SvgCellImage,
24
+ SvgTileLayout: () => SvgTileLayout,
25
+ TileLayout: () => TileLayout,
26
+ cellFromPointer: () => import_dom3.cellFromPointer,
27
+ coverStyle: () => coverStyle,
28
+ defaultPalette: () => import_svg2.defaultPalette,
29
+ neutralPalette: () => import_svg2.neutralPalette,
30
+ useFitCount: () => useFitCount,
31
+ useImageAspects: () => useImageAspects,
32
+ useImageFill: () => useImageFill,
33
+ useImageFocus: () => useImageFocus,
34
+ useTileLayout: () => useTileLayout
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+
38
+ // src/TileLayout.tsx
39
+ var import_react2 = require("react");
40
+ var import_core2 = require("@andamento/core");
41
+ var import_dom2 = require("@andamento/dom");
42
+
43
+ // src/useTileLayout.ts
44
+ var import_react = require("react");
45
+ var import_core = require("@andamento/core");
46
+ var import_dom = require("@andamento/dom");
47
+ function useTileLayout(options) {
48
+ const key = JSON.stringify(options);
49
+ return (0, import_react.useMemo)(() => (0, import_core.createLayout)(options), [key]);
50
+ }
51
+ function useFitCount(options, count, fit = {}) {
52
+ const key = JSON.stringify(options);
53
+ const { cells, mode } = fit;
54
+ return (0, import_react.useMemo)(() => (0, import_core.fitCount)(options, count, { cells, mode }).layout, [key, count, cells, mode]);
55
+ }
56
+ function useResolvedLayout(component, options, layout, fit) {
57
+ const resolver = (0, import_react.useRef)();
58
+ resolver.current ?? (resolver.current = (0, import_dom.layoutResolver)(`<${component}>`));
59
+ return resolver.current(options, layout, fit);
60
+ }
61
+
62
+ // src/TileLayout.tsx
63
+ var import_jsx_runtime = require("react/jsx-runtime");
64
+ var isEmpty = (n) => n == null || n === false || n === true || n === "";
65
+ var css = (s) => s;
66
+ function TileLayout(props) {
67
+ const {
68
+ options,
69
+ layout: given,
70
+ children,
71
+ renderCell,
72
+ contentCells,
73
+ placement,
74
+ aspects,
75
+ choose,
76
+ focalPoints,
77
+ weights,
78
+ safeArea: safeArea2,
79
+ fill,
80
+ fit,
81
+ backdrop,
82
+ relief,
83
+ navigable,
84
+ onCellActivate,
85
+ cellLabel,
86
+ focusRing = "#1a56db",
87
+ animate,
88
+ virtualize,
89
+ fallback,
90
+ cellClassName,
91
+ cellStyle,
92
+ background,
93
+ style,
94
+ role,
95
+ onKeyDown,
96
+ ...rest
97
+ } = props;
98
+ const uid = "andamento" + (0, import_react2.useId)().replace(/:/g, "");
99
+ const items = renderCell ? [] : import_react2.Children.toArray(children);
100
+ const layout = useResolvedLayout("TileLayout", options, given, {
101
+ fit: !renderCell && fit,
102
+ count: items.length,
103
+ cells: contentCells,
104
+ weights: renderCell ? void 0 : weights,
105
+ placement
106
+ });
107
+ const { bounds } = layout;
108
+ const buildFrame = (0, import_react2.useRef)();
109
+ buildFrame.current ?? (buildFrame.current = (0, import_dom2.frameBuilder)());
110
+ const frame = buildFrame.current(layout, {
111
+ count: renderCell ? Infinity : items.length,
112
+ aspects: renderCell ? void 0 : aspects,
113
+ contentCells,
114
+ placement,
115
+ choose,
116
+ fill,
117
+ relief,
118
+ animate
119
+ });
120
+ const { slots, anim } = frame;
121
+ const keyOf = (i) => {
122
+ const slot = slots[i];
123
+ if (!renderCell && slot >= 0) {
124
+ const child = items[slot];
125
+ return (0, import_react2.isValidElement)(child) && child.key != null ? `child:${child.key}` : `child:${slot}`;
126
+ }
127
+ return `cell:${layout.cells[i].id}`;
128
+ };
129
+ const makeEntry = (i) => {
130
+ const cell = layout.cells[i];
131
+ const slot = slots[i];
132
+ let content = null;
133
+ if (renderCell) content = renderCell(cell, { slot });
134
+ else if (slot >= 0) content = items[slot];
135
+ const empty = isEmpty(content);
136
+ const state = { empty, slot: empty && !renderCell ? -1 : slot };
137
+ if (empty) content = (0, import_dom2.resolvePerCell)(fallback, cell, state);
138
+ return { i, cell, content, key: keyOf(i), empty, state };
139
+ };
140
+ const virtual = !!virtualize;
141
+ const overscan = Math.max(0, (typeof virtualize === "object" ? virtualize.overscan : void 0) ?? 300);
142
+ const container = (0, import_react2.useRef)(null);
143
+ const [view, setView] = (0, import_react2.useState)(null);
144
+ const allEntries = virtual ? void 0 : layout.cells.map((_, i) => makeEntry(i));
145
+ const hasContent = (i) => allEntries ? !allEntries[i].empty : renderCell ? slots[i] >= 0 : slots[i] >= 0 && !isEmpty(items[slots[i]]);
146
+ const mounted = (0, import_react2.useRef)(false);
147
+ const lastKeys = (0, import_react2.useRef)(/* @__PURE__ */ new Set());
148
+ const entering = (0, import_react2.useRef)(/* @__PURE__ */ new Set());
149
+ const lastTiles = (0, import_react2.useRef)(/* @__PURE__ */ new Map());
150
+ const [exiting, setExiting] = (0, import_react2.useState)(() => /* @__PURE__ */ new Map());
151
+ const timers = (0, import_react2.useRef)(/* @__PURE__ */ new Set());
152
+ const focusable = new Set(navigable ? layout.cells.filter((c) => hasContent(c.index)).map((c) => c.id) : []);
153
+ const [activeId, setActiveId] = (0, import_react2.useState)();
154
+ const firstFocusable = layout.cells.find((c) => focusable.has(c.id))?.id;
155
+ const active = activeId !== void 0 && focusable.has(activeId) ? activeId : firstFocusable;
156
+ const tiles = (0, import_react2.useRef)(/* @__PURE__ */ new Map());
157
+ const pendingFocus = (0, import_react2.useRef)();
158
+ const list = (role ?? "list") === "list";
159
+ let entries;
160
+ if (allEntries) entries = allEntries;
161
+ else {
162
+ const shown = new Set(view && view.width >= 0 ? (0, import_core2.cellsInRect)(layout, view).map((c) => c.index) : []);
163
+ const activeCell = active !== void 0 ? layout.cells.find((c) => c.id === active) : void 0;
164
+ if (activeCell) shown.add(activeCell.index);
165
+ entries = [...shown].sort((a, b) => a - b).map(makeEntry);
166
+ }
167
+ let positions;
168
+ if (virtual) {
169
+ positions = /* @__PURE__ */ new Map();
170
+ for (const c of layout.cells) if (hasContent(c.index)) positions.set(c.index, positions.size + 1);
171
+ }
172
+ const allKeys = anim ? new Set(layout.cells.map((_, i) => keyOf(i))) : void 0;
173
+ for (const e of entries) if (anim && mounted.current && !lastKeys.current.has(e.key)) entering.current.add(e.key);
174
+ const handleKeyDown = (e) => {
175
+ onKeyDown?.(e);
176
+ if (e.defaultPrevented || !navigable || e.altKey || e.ctrlKey || e.metaKey) return;
177
+ const entry = entries.find((x) => tiles.current.get(x.cell.id) === e.target);
178
+ if (!entry || !focusable.has(entry.cell.id)) return;
179
+ const action = (0, import_dom2.keyAction)(layout, entry.cell, e.key, (c) => focusable.has(c.id), !!onCellActivate);
180
+ if (!action) return;
181
+ e.preventDefault();
182
+ if ("activate" in action) onCellActivate(entry.cell, entry.state);
183
+ else if ("move" in action) {
184
+ setActiveId(action.move.id);
185
+ const el = tiles.current.get(action.move.id);
186
+ if (el) el.focus();
187
+ else pendingFocus.current = action.move.id;
188
+ }
189
+ };
190
+ const rendered = entries.map(({ i, cell, content, key, empty, state }) => {
191
+ const slot = slots[i];
192
+ const bevel = frame.bevel(i);
193
+ const tile = (0, import_dom2.tileStyle)(frame, cell, {
194
+ empty,
195
+ safeArea: safeArea2,
196
+ backdrop: backdrop != null,
197
+ clickable: !!onCellActivate && !empty,
198
+ focus: !renderCell && slot >= 0 ? focalPoints?.[slot] : void 0,
199
+ aspect: !renderCell && slot >= 0 ? aspects?.[slot] : void 0
200
+ });
201
+ const silent = empty && isEmpty(content);
202
+ const canFocus = focusable.has(cell.id);
203
+ const viewBox = (0, import_dom2.tileViewBox)(cell);
204
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
205
+ "div",
206
+ {
207
+ ref: (el) => {
208
+ if (el) tiles.current.set(cell.id, el);
209
+ else tiles.current.delete(cell.id);
210
+ },
211
+ role: silent ? void 0 : list ? "listitem" : void 0,
212
+ "aria-hidden": silent ? true : void 0,
213
+ "aria-label": silent ? void 0 : (0, import_dom2.resolvePerCell)(cellLabel, cell, state),
214
+ "aria-setsize": positions && list && !silent ? positions.size : void 0,
215
+ "aria-posinset": positions && list && !silent ? positions.get(i) : void 0,
216
+ tabIndex: canFocus ? cell.id === active ? 0 : -1 : void 0,
217
+ onFocus: canFocus ? (e) => e.target === e.currentTarget && setActiveId(cell.id) : void 0,
218
+ onClick: onCellActivate && !empty ? () => onCellActivate(cell, state) : void 0,
219
+ className: (0, import_dom2.resolvePerCell)(cellClassName, cell, state),
220
+ "data-cell-id": cell.id,
221
+ "data-index": cell.index,
222
+ "data-empty": empty ? "" : void 0,
223
+ "data-boundary": cell.boundary ? "" : void 0,
224
+ "data-entering": entering.current.has(key) ? "" : void 0,
225
+ style: { ...css(tile), ...(0, import_dom2.resolvePerCell)(cellStyle, cell, state) },
226
+ children: [
227
+ backdrop != null && // z-index -1 puts it behind the content but inside the tile: the tile's
228
+ // clip-path makes it a stacking context.
229
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { "aria-hidden": true, style: css((0, import_dom2.backdropStyle)(frame, cell)), children: backdrop }),
230
+ safeArea2 && content != null && !isEmpty(content) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { "data-safe-area": "", style: css((0, import_dom2.safeBoxStyle)(frame, cell, !renderCell && !empty && aspects ? aspects[slot] ?? 1 : void 0, safeArea2)), children: content }) : content,
231
+ bevel && bevel.length > 0 && // Over the content; the tile's box is its bounding box, so map that to the viewBox.
232
+ // When animating, the bevel is for the new shape, so it fades in as the tile arrives.
233
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
234
+ "svg",
235
+ {
236
+ "aria-hidden": true,
237
+ "data-bevel": "",
238
+ "data-late": anim ? "" : void 0,
239
+ viewBox,
240
+ preserveAspectRatio: "none",
241
+ style: css(import_dom2.overlayStyle),
242
+ children: bevel.map((p, k) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: p.d, fill: p.fill, fillOpacity: p.opacity }, k))
243
+ },
244
+ anim ? String(tile.clipPath) : void 0
245
+ ),
246
+ canFocus && focusRing !== false && // The tile's outline, stroked across its edge; the clip keeps the inner half.
247
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { "aria-hidden": true, "data-focus-ring": "", viewBox, preserveAspectRatio: "none", style: css(import_dom2.overlayStyle), children: (0, import_dom2.ringStrokes)(frame, cell, focusRing).map((p, k) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: p.d, fill: "none", stroke: p.stroke, strokeWidth: p.width, vectorEffect: "non-scaling-stroke" }, k)) })
248
+ ]
249
+ },
250
+ key
251
+ );
252
+ });
253
+ useIsomorphicLayoutEffect(() => {
254
+ const current = new Map(rendered.map((el) => [el.key, el]));
255
+ const present = allKeys ?? current;
256
+ if (anim && mounted.current) {
257
+ const gone = [...lastTiles.current].filter(([k]) => !present.has(k));
258
+ if (gone.length) {
259
+ setExiting((prev) => new Map([...prev, ...gone]));
260
+ const timer = setTimeout(() => {
261
+ timers.current.delete(timer);
262
+ setExiting((prev) => {
263
+ const next = new Map(prev);
264
+ for (const [k, el] of gone) if (next.get(k) === el) next.delete(k);
265
+ return next;
266
+ });
267
+ }, anim.duration);
268
+ timers.current.add(timer);
269
+ }
270
+ }
271
+ for (const k of entering.current) if (!present.has(k)) entering.current.delete(k);
272
+ lastKeys.current = new Set(present.keys());
273
+ lastTiles.current = current;
274
+ mounted.current = true;
275
+ if (pendingFocus.current) {
276
+ const el = tiles.current.get(pendingFocus.current);
277
+ if (el) {
278
+ pendingFocus.current = void 0;
279
+ el.focus();
280
+ }
281
+ }
282
+ });
283
+ useIsomorphicLayoutEffect(() => {
284
+ if (!virtual) return;
285
+ const el = container.current;
286
+ if (!el) return;
287
+ return (0, import_dom2.watchView)(el, () => {
288
+ const next = (0, import_dom2.viewRect)(el, layout, overscan);
289
+ setView((v) => (0, import_dom2.sameRect)(v ?? void 0, next) ? v : next);
290
+ });
291
+ }, [virtual, layout, overscan]);
292
+ (0, import_react2.useEffect)(() => {
293
+ const set = timers.current;
294
+ return () => set.forEach(clearTimeout);
295
+ }, []);
296
+ const leaving = anim ? [...exiting].filter(([k]) => !lastKeys.current.has(k) && !rendered.some((el) => el.key === k)) : [];
297
+ const sheet = (0, import_dom2.tileSheet)({ focusRing: !!navigable && focusRing !== false, anim });
298
+ const shadow = (0, import_dom2.shadowShape)(frame, entries.map((e) => e.cell));
299
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
300
+ "div",
301
+ {
302
+ "data-andamento": "",
303
+ ref: container,
304
+ role: role ?? "list",
305
+ ...rest,
306
+ onKeyDown: handleKeyDown,
307
+ style: { ...css((0, import_dom2.containerStyle)(layout)), ...style },
308
+ children: [
309
+ sheet && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { children: sheet }),
310
+ background && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { "aria-hidden": true, style: css((0, import_dom2.backgroundStyle)(frame, background)) }),
311
+ shadow && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { "aria-hidden": true, "data-andamento-shadow": "", viewBox: shadow.viewBox, preserveAspectRatio: "none", style: css(shadow.style), children: [
312
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("filter", { id: `${uid}-shadow`, x: "-10%", y: "-10%", width: "120%", height: "120%", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("feGaussianBlur", { stdDeviation: shadow.blur }) }),
313
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: shadow.d, fillRule: "evenodd", transform: shadow.transform, fill: "#000", fillOpacity: shadow.opacity, filter: `url(#${uid}-shadow)` })
314
+ ] }),
315
+ rendered,
316
+ leaving.map(
317
+ ([k, el]) => (
318
+ // Fades out through the [data-exiting] rule in the style sheet.
319
+ (0, import_react2.cloneElement)(el, {
320
+ key: k,
321
+ ref: null,
322
+ role: void 0,
323
+ tabIndex: void 0,
324
+ onClick: void 0,
325
+ onFocus: void 0,
326
+ "aria-hidden": true,
327
+ "data-entering": void 0,
328
+ "data-exiting": ""
329
+ })
330
+ )
331
+ )
332
+ ]
333
+ }
334
+ );
335
+ }
336
+ var useIsomorphicLayoutEffect = typeof window === "undefined" ? import_react2.useEffect : import_react2.useLayoutEffect;
337
+ var coverStyle = css(import_dom2.coverStyle);
338
+
339
+ // src/SvgTileLayout.tsx
340
+ var import_react3 = require("react");
341
+ var import_core3 = require("@andamento/core");
342
+ var import_svg = require("@andamento/svg");
343
+ var import_jsx_runtime2 = require("react/jsx-runtime");
344
+ function SvgTileLayout(props) {
345
+ const {
346
+ options,
347
+ layout: given,
348
+ images,
349
+ repeatImages,
350
+ contentCells,
351
+ placement,
352
+ imageAspects,
353
+ choose,
354
+ imageFit,
355
+ containWithin,
356
+ imageFocus,
357
+ imageWeights,
358
+ fit,
359
+ fill,
360
+ stroke,
361
+ strokeWidth = 1,
362
+ background,
363
+ backdrop,
364
+ relief: reliefProp,
365
+ renderCell,
366
+ title,
367
+ imageAlts,
368
+ ...svgProps
369
+ } = props;
370
+ const fitTo = Array.isArray(images) && !repeatImages ? images.length : 0;
371
+ const layout = useResolvedLayout("SvgTileLayout", options, given, {
372
+ fit,
373
+ count: fitTo,
374
+ cells: contentCells,
375
+ weights: Array.isArray(images) ? imageWeights : void 0,
376
+ placement
377
+ });
378
+ const prefix = "andamento" + (0, import_react3.useId)().replace(/:/g, "");
379
+ const styles = (0, import_react3.useMemo)(
380
+ () => (0, import_svg.resolveCellStyles)(layout, { images, repeatImages, fill, contentCells, placement, imageAspects, choose }),
381
+ [layout, images, repeatImages, fill, contentCells, placement, imageAspects, choose]
382
+ );
383
+ const { x, y, width, height } = layout.bounds;
384
+ const relief = reliefProp === true ? {} : reliefProp || void 0;
385
+ const reliefKey = relief ? JSON.stringify(relief) : "";
386
+ const bevels = (0, import_react3.useMemo)(() => {
387
+ if (!relief) return void 0;
388
+ const bevel = relief.bevel ?? (0, import_svg.defaultBevel)(layout);
389
+ return bevel > 0 ? layout.cells.map((c) => (0, import_svg.reliefPaths)(layout, c, relief, bevel)) : void 0;
390
+ }, [layout, reliefKey]);
391
+ const cast = relief && (0, import_svg.shadowOffset)(relief);
392
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: `${x} ${y} ${width} ${height}`, role: imageAlts?.length ? "group" : title ? "img" : void 0, ...svgProps, children: [
393
+ title && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("title", { children: title }),
394
+ background && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { className: "andamento-region", d: (0, import_svg.regionPath)(layout), fill: background, fillRule: "evenodd" }),
395
+ layout.view && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("clipPath", { id: `${prefix}-view`, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: (0, import_svg.viewPath)(layout), clipRule: "evenodd" }) }),
396
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("g", { className: layout.view ? "andamento-view" : void 0, clipPath: layout.view ? `url(#${prefix}-view)` : void 0, children: [
397
+ backdrop && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
398
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("clipPath", { id: `${prefix}-backdrop`, children: layout.cells.map((cell) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: (0, import_svg.cellPath)(layout, cell), clipRule: "evenodd" }, cell.id)) }),
399
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
400
+ "image",
401
+ {
402
+ className: "andamento-backdrop",
403
+ href: backdrop,
404
+ x,
405
+ y,
406
+ width,
407
+ height,
408
+ preserveAspectRatio: "xMidYMid slice",
409
+ clipPath: `url(#${prefix}-backdrop)`
410
+ }
411
+ )
412
+ ] }),
413
+ cast && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("g", { className: "andamento-shadow", clipPath: `url(#${prefix}-region)`, children: [
414
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("clipPath", { id: `${prefix}-region`, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: (0, import_svg.regionPath)(layout), clipRule: "evenodd" }) }),
415
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("filter", { id: `${prefix}-shadow`, x: "-10%", y: "-10%", width: "120%", height: "120%", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("feGaussianBlur", { stdDeviation: cast.blur }) }),
416
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
417
+ "path",
418
+ {
419
+ d: layout.cells.map((c) => (0, import_svg.cellPath)(layout, c)).join(""),
420
+ fillRule: "evenodd",
421
+ transform: `translate(${cast.dx} ${cast.dy})`,
422
+ fill: "#000",
423
+ fillOpacity: cast.opacity,
424
+ filter: `url(#${prefix}-shadow)`
425
+ }
426
+ )
427
+ ] }),
428
+ layout.cells.map((cell, i) => {
429
+ const d = (0, import_svg.cellPath)(layout, cell);
430
+ const clipPathId = `${prefix}-clip-${cell.index}`;
431
+ const style = styles[i];
432
+ const ctx = { path: d, clipPathId, clipPath: `url(#${clipPathId})`, ...style };
433
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
434
+ "g",
435
+ {
436
+ className: "andamento-cell",
437
+ "data-cell-id": cell.id,
438
+ "data-index": cell.index,
439
+ "data-empty": style.image ? void 0 : "",
440
+ "data-boundary": cell.boundary ? "" : void 0,
441
+ ...(0, import_svg.cellA11y)(style, imageAlts),
442
+ children: [
443
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("clipPath", { id: clipPathId, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d, clipRule: "evenodd" }) }),
444
+ renderCell ? renderCell(cell, ctx) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
445
+ DefaultCell,
446
+ {
447
+ cell,
448
+ ctx,
449
+ noFill: !!backdrop,
450
+ box: imageFit === "contain" && style.image ? (0, import_core3.safeArea)(cell, layout, { aspect: imageAspects && style.slot >= 0 ? imageAspects[style.slot] : void 0, within: containWithin }) : void 0,
451
+ cover: (() => {
452
+ const focus = imageFit !== "contain" && style.image && style.slot >= 0 ? Array.isArray(images) ? imageFocus?.[style.slot % images.length] : void 0 : void 0;
453
+ const aspect = focus ? imageAspects?.[style.slot % imageAspects.length] ?? focus.aspect : void 0;
454
+ return focus && aspect ? (0, import_core3.coverRect)(cell, layout, { aspect, focus }) : void 0;
455
+ })()
456
+ }
457
+ ),
458
+ bevels?.[i].map((p, k) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { className: "andamento-bevel", d: p.d, fill: p.fill, fillOpacity: p.opacity }, k)),
459
+ stroke && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d, fill: "none", stroke, strokeWidth })
460
+ ]
461
+ },
462
+ cell.id
463
+ );
464
+ })
465
+ ] })
466
+ ] });
467
+ }
468
+ function DefaultCell({ cell, ctx, noFill, box, cover }) {
469
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
470
+ !noFill && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: ctx.path, fill: ctx.fill, fillRule: "evenodd" }),
471
+ ctx.image && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SvgCellImage, { cell, href: ctx.image, clipPath: ctx.clipPath, box, cover })
472
+ ] });
473
+ }
474
+ function SvgCellImage({ cell, href, clipPath, box, cover, ...rest }) {
475
+ const b = box ?? cover ?? (0, import_core3.cellShape)(cell).bbox;
476
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
477
+ "image",
478
+ {
479
+ href,
480
+ x: b.x,
481
+ y: b.y,
482
+ width: b.width,
483
+ height: b.height,
484
+ preserveAspectRatio: box ? "xMidYMid meet" : "xMidYMid slice",
485
+ clipPath,
486
+ ...rest
487
+ }
488
+ );
489
+ }
490
+
491
+ // src/useImageFill.ts
492
+ var import_react4 = require("react");
493
+ var import_core4 = require("@andamento/core");
494
+ function useImageFill(src, options = {}) {
495
+ const { fit, palette, fallback, samples, maxSize = 256 } = options;
496
+ const [pixels, setPixels] = (0, import_react4.useState)();
497
+ (0, import_react4.useEffect)(() => {
498
+ if (!src) return;
499
+ let live = true;
500
+ (0, import_core4.loadImagePixels)(src, maxSize).then(
501
+ (p) => live && setPixels({ src, pixels: p }),
502
+ (e) => console.warn(`useImageFill: ${e.message}`)
503
+ );
504
+ return () => {
505
+ live = false;
506
+ };
507
+ }, [src, maxSize]);
508
+ const paletteKey = palette?.join(",");
509
+ return (0, import_react4.useMemo)(
510
+ () => pixels && pixels.src === src ? (0, import_core4.imageFill)(pixels.pixels, { fit, palette, fallback, samples }) : void 0,
511
+ // eslint-disable-next-line react-hooks/exhaustive-deps
512
+ [pixels, src, fit, paletteKey, fallback, samples]
513
+ );
514
+ }
515
+
516
+ // src/useImageAspects.ts
517
+ var import_react5 = require("react");
518
+ function useImageAspects(srcs) {
519
+ const key = srcs?.join("\n");
520
+ const [result, setResult] = (0, import_react5.useState)();
521
+ (0, import_react5.useEffect)(() => {
522
+ if (!srcs || key === void 0 || typeof Image === "undefined") return;
523
+ let live = true;
524
+ Promise.all(
525
+ srcs.map(
526
+ (src) => new Promise((resolve2) => {
527
+ const img = new Image();
528
+ img.onload = () => resolve2(img.naturalWidth && img.naturalHeight ? img.naturalWidth / img.naturalHeight : 1);
529
+ img.onerror = () => resolve2(1);
530
+ img.src = src;
531
+ })
532
+ )
533
+ ).then((aspects) => live && setResult({ key, aspects }));
534
+ return () => {
535
+ live = false;
536
+ };
537
+ }, [key]);
538
+ return result && result.key === key ? result.aspects : void 0;
539
+ }
540
+
541
+ // src/useImageFocus.ts
542
+ var import_react6 = require("react");
543
+ var import_core5 = require("@andamento/core");
544
+ function useImageFocus(srcs) {
545
+ const key = srcs?.join("\n");
546
+ const [result, setResult] = (0, import_react6.useState)();
547
+ (0, import_react6.useEffect)(() => {
548
+ if (!srcs || key === void 0 || typeof document === "undefined") return;
549
+ let live = true;
550
+ Promise.all(
551
+ srcs.map(
552
+ (src) => (0, import_core5.loadImagePixels)(src, 128).then(import_core5.estimateFocus).catch(() => ({ x: 0.5, y: 0.5 }))
553
+ )
554
+ ).then((focus) => live && setResult({ key, focus }));
555
+ return () => {
556
+ live = false;
557
+ };
558
+ }, [key]);
559
+ return result && result.key === key ? result.focus : void 0;
560
+ }
561
+
562
+ // src/index.tsx
563
+ var import_dom3 = require("@andamento/dom");
564
+ var import_svg2 = require("@andamento/svg");
565
+ // Annotate the CommonJS export names for ESM import in node:
566
+ 0 && (module.exports = {
567
+ SvgCellImage,
568
+ SvgTileLayout,
569
+ TileLayout,
570
+ cellFromPointer,
571
+ coverStyle,
572
+ defaultPalette,
573
+ neutralPalette,
574
+ useFitCount,
575
+ useImageAspects,
576
+ useImageFill,
577
+ useImageFocus,
578
+ useTileLayout
579
+ });
580
+ //# sourceMappingURL=index.cjs.map