@tensor_1/react 2.43.0 → 2.44.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.
@@ -0,0 +1,113 @@
1
+ const DASHBOARD_CANVAS_COLUMNS = 12;
2
+ const whole = (value, fallback) => typeof value === "number" && Number.isFinite(value) ? Math.round(value) : fallback;
3
+ const clampTo = (value, low, high) => Math.min(high, Math.max(low, value));
4
+ function canvasItemLimits(item) {
5
+ const minW = clampTo(whole(item.minW, 1), 1, DASHBOARD_CANVAS_COLUMNS);
6
+ const maxW = clampTo(whole(item.maxW, DASHBOARD_CANVAS_COLUMNS), minW, DASHBOARD_CANVAS_COLUMNS);
7
+ const minH = Math.max(1, whole(item.minH, 1));
8
+ const maxH = Math.max(minH, whole(item.maxH, Number.POSITIVE_INFINITY));
9
+ return { minW, maxW, minH, maxH };
10
+ }
11
+ function clampCanvasItem(item) {
12
+ const { minW, maxW, minH, maxH } = canvasItemLimits(item);
13
+ const w = clampTo(whole(item.w, minW), minW, maxW);
14
+ const h = clampTo(whole(item.h, minH), minH, maxH);
15
+ const col = clampTo(whole(item.col, 0), 0, DASHBOARD_CANVAS_COLUMNS - w);
16
+ const row = Math.max(0, whole(item.row, 0));
17
+ if (col === item.col && row === item.row && w === item.w && h === item.h) return item;
18
+ return { ...item, col, row, w, h };
19
+ }
20
+ function canvasItemsOverlap(a, b) {
21
+ return a.id !== b.id && a.col < b.col + b.w && b.col < a.col + a.w && a.row < b.row + b.h && b.row < a.row + a.h;
22
+ }
23
+ function canvasReadingOrder(items) {
24
+ return items.map((item, index) => ({ item, index })).sort((a, b) => a.item.row - b.item.row || a.item.col - b.item.col || a.index - b.index).map(({ item }) => item);
25
+ }
26
+ function canvasRowCount(items) {
27
+ return items.reduce((rows, item) => Math.max(rows, item.row + item.h), 0);
28
+ }
29
+ function settle(fixed, rest) {
30
+ const settled = [...fixed];
31
+ for (const item of canvasReadingOrder(rest)) {
32
+ let candidate = item;
33
+ for (; ; ) {
34
+ const below = settled.filter((other) => canvasItemsOverlap(candidate, other)).reduce((lowest, other) => Math.max(lowest, other.row + other.h), -1);
35
+ if (below < 0) break;
36
+ candidate = { ...candidate, row: below };
37
+ }
38
+ settled.push(candidate);
39
+ }
40
+ return settled;
41
+ }
42
+ const inInputOrder = (items, settled) => {
43
+ const byId = new Map(settled.map((item) => [item.id, item]));
44
+ return items.map((item) => byId.get(item.id) ?? item);
45
+ };
46
+ function normalizeCanvas(items) {
47
+ const clamped = items.map((item) => clampCanvasItem(item));
48
+ return inInputOrder(clamped, settle([], clamped));
49
+ }
50
+ function placeCanvasItem(items, id, placement) {
51
+ const target = items.find((item) => item.id === id);
52
+ if (!target) return [...items];
53
+ const moved = clampCanvasItem({ ...target, ...placement });
54
+ const others = items.filter((item) => item.id !== id).map((item) => clampCanvasItem(item));
55
+ return inInputOrder(items, settle([moved], others));
56
+ }
57
+ function canvasMoveTarget(item, direction) {
58
+ const current = clampCanvasItem(item);
59
+ const col = current.col + (direction === "left" ? -1 : direction === "right" ? 1 : 0);
60
+ const row = current.row + (direction === "up" ? -1 : direction === "down" ? 1 : 0);
61
+ if (col < 0 || col + current.w > DASHBOARD_CANVAS_COLUMNS || row < 0) return null;
62
+ return { col, row, w: current.w, h: current.h };
63
+ }
64
+ function canvasResizeTarget(item, change) {
65
+ const current = clampCanvasItem(item);
66
+ const limits = canvasItemLimits(current);
67
+ if (change === "wider") {
68
+ if (current.w >= limits.maxW) return null;
69
+ const col = current.col + current.w < DASHBOARD_CANVAS_COLUMNS ? current.col : current.col - 1;
70
+ return { col, row: current.row, w: current.w + 1, h: current.h };
71
+ }
72
+ if (change === "narrower") {
73
+ return current.w <= limits.minW ? null : { col: current.col, row: current.row, w: current.w - 1, h: current.h };
74
+ }
75
+ if (change === "taller") {
76
+ return current.h >= limits.maxH ? null : { col: current.col, row: current.row, w: current.w, h: current.h + 1 };
77
+ }
78
+ return current.h <= limits.minH ? null : { col: current.col, row: current.row, w: current.w, h: current.h - 1 };
79
+ }
80
+ function moveCanvasItem(items, id, direction) {
81
+ const item = items.find((candidate) => candidate.id === id);
82
+ const target = item ? canvasMoveTarget(item, direction) : null;
83
+ return target ? placeCanvasItem(items, id, target) : [...items];
84
+ }
85
+ function resizeCanvasItem(items, id, change) {
86
+ const item = items.find((candidate) => candidate.id === id);
87
+ const target = item ? canvasResizeTarget(item, change) : null;
88
+ return target ? placeCanvasItem(items, id, target) : [...items];
89
+ }
90
+ function compactCanvas(items) {
91
+ const settled = [];
92
+ for (const item of canvasReadingOrder(normalizeCanvas(items))) {
93
+ let row = item.row;
94
+ while (row > 0 && !settled.some((other) => canvasItemsOverlap({ ...item, row: row - 1 }, other))) row -= 1;
95
+ settled.push(row === item.row ? item : { ...item, row });
96
+ }
97
+ return inInputOrder(items, settled);
98
+ }
99
+ export {
100
+ DASHBOARD_CANVAS_COLUMNS,
101
+ canvasItemLimits,
102
+ canvasItemsOverlap,
103
+ canvasMoveTarget,
104
+ canvasReadingOrder,
105
+ canvasResizeTarget,
106
+ canvasRowCount,
107
+ clampCanvasItem,
108
+ compactCanvas,
109
+ moveCanvasItem,
110
+ normalizeCanvas,
111
+ placeCanvasItem,
112
+ resizeCanvasItem
113
+ };
@@ -5,30 +5,30 @@ import { IconNode, UixIcon, IconProps } from './types.js';
5
5
  /** Renders a glyph as an inline SVG; the props contract shared by every icon. */
6
6
  declare function renderIcon(node: IconNode, { size, tone, label, strokeWidth, className, style, ...rest }: IconProps, ref?: unknown): react.ReactElement<{
7
7
  string?: number | string | undefined | undefined;
8
+ target?: string | undefined | undefined;
8
9
  filter?: string | undefined | undefined;
9
- values?: string | undefined | undefined;
10
10
  fill: string;
11
- color?: string | undefined | undefined;
12
- fontStyle?: number | string | undefined | undefined;
13
- fontWeight?: number | string | undefined | undefined;
14
- fontSize?: number | string | undefined | undefined;
15
- fontFamily?: string | undefined | undefined;
16
- width?: number | string | undefined | undefined;
17
- height?: number | string | undefined | undefined;
11
+ values?: string | undefined | undefined;
18
12
  type?: string | undefined | undefined;
19
- z?: number | string | undefined | undefined;
20
- opacity?: number | string | undefined | undefined;
21
- r?: number | string | undefined | undefined;
22
- target?: string | undefined | undefined;
23
13
  min?: number | string | undefined | undefined;
24
14
  max?: number | string | undefined | undefined;
25
15
  name?: string | undefined | undefined;
16
+ color?: string | undefined | undefined;
17
+ width?: number | string | undefined | undefined;
26
18
  rotate?: number | string | undefined | undefined;
27
19
  offset?: number | string | undefined | undefined;
28
20
  overflow?: number | string | undefined | undefined;
21
+ fontStyle?: number | string | undefined | undefined;
22
+ fontWeight?: number | string | undefined | undefined;
23
+ fontFamily?: string | undefined | undefined;
24
+ fontSize?: number | string | undefined | undefined;
25
+ opacity?: number | string | undefined | undefined;
26
+ height?: number | string | undefined | undefined;
29
27
  end?: number | string | undefined | undefined;
30
28
  scale?: number | string | undefined | undefined;
31
29
  to?: number | string | undefined | undefined;
30
+ z?: number | string | undefined | undefined;
31
+ r?: number | string | undefined | undefined;
32
32
  x?: number | string | undefined | undefined;
33
33
  cursor?: number | string | undefined | undefined;
34
34
  id?: string | undefined | undefined;