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