@mrpelz/uikit-ish 7.13.1 → 7.26.2
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/dist/components/accordion/style.css +1 -1
- package/dist/components/action-sheet/main.d.ts.map +1 -1
- package/dist/components/action-sheet/main.js +9 -6
- package/dist/components/action-sheet/main.js.map +1 -1
- package/dist/components/action-sheet/props.d.ts +2 -1
- package/dist/components/action-sheet/props.d.ts.map +1 -1
- package/dist/components/alert/main.d.ts.map +1 -1
- package/dist/components/alert/main.js +12 -4
- package/dist/components/alert/main.js.map +1 -1
- package/dist/components/alert/props.d.ts +2 -1
- package/dist/components/alert/props.d.ts.map +1 -1
- package/dist/components/alert/style.css +27 -5
- package/dist/components/button/main.js +1 -1
- package/dist/components/button/main.js.map +1 -1
- package/dist/components/button/props.d.ts +3 -2
- package/dist/components/button/props.d.ts.map +1 -1
- package/dist/components/button/style.css +6 -17
- package/dist/components/card/main.d.ts +53 -0
- package/dist/components/card/main.d.ts.map +1 -0
- package/dist/components/card/main.js +286 -0
- package/dist/components/card/main.js.map +1 -0
- package/dist/components/card/props.d.ts +83 -0
- package/dist/components/card/props.d.ts.map +1 -0
- package/dist/components/card/props.js +2 -0
- package/dist/components/card/props.js.map +1 -0
- package/dist/components/card/style.css +900 -0
- package/dist/components/collapsible/style.css +1 -1
- package/dist/components/color-picker/main.d.ts.map +1 -1
- package/dist/components/color-picker/main.js +20 -33
- package/dist/components/color-picker/main.js.map +1 -1
- package/dist/components/color-picker/style.css +4 -23
- package/dist/components/contextual-menu/main.d.ts +6 -2
- package/dist/components/contextual-menu/main.d.ts.map +1 -1
- package/dist/components/contextual-menu/main.js +67 -43
- package/dist/components/contextual-menu/main.js.map +1 -1
- package/dist/components/contextual-menu/props.d.ts +2 -1
- package/dist/components/contextual-menu/props.d.ts.map +1 -1
- package/dist/components/contextual-menu/style.css +64 -2
- package/dist/components/control-cards/main.d.ts +49 -0
- package/dist/components/control-cards/main.d.ts.map +1 -0
- package/dist/components/control-cards/main.js +835 -0
- package/dist/components/control-cards/main.js.map +1 -0
- package/dist/components/control-cards/props.d.ts +409 -0
- package/dist/components/control-cards/props.d.ts.map +1 -0
- package/dist/components/control-cards/props.js +2 -0
- package/dist/components/control-cards/props.js.map +1 -0
- package/dist/components/control-cards/style.css +492 -0
- package/dist/components/date-picker/main.d.ts.map +1 -1
- package/dist/components/date-picker/main.js +3 -2
- package/dist/components/date-picker/main.js.map +1 -1
- package/dist/components/date-picker/style.css +1 -1
- package/dist/components/drawer/style.css +6 -0
- package/dist/components/edit-menu/main.d.ts +2 -1
- package/dist/components/edit-menu/main.d.ts.map +1 -1
- package/dist/components/edit-menu/main.js +8 -4
- package/dist/components/edit-menu/main.js.map +1 -1
- package/dist/components/glass/backdrop.d.ts +75 -0
- package/dist/components/glass/backdrop.d.ts.map +1 -0
- package/dist/components/glass/backdrop.js +608 -0
- package/dist/components/glass/backdrop.js.map +1 -0
- package/dist/components/glass/gradient.d.ts +17 -0
- package/dist/components/glass/gradient.d.ts.map +1 -0
- package/dist/components/glass/gradient.js +233 -0
- package/dist/components/glass/gradient.js.map +1 -0
- package/dist/components/glass/main.d.ts +60 -6
- package/dist/components/glass/main.d.ts.map +1 -1
- package/dist/components/glass/main.js +100 -122
- package/dist/components/glass/main.js.map +1 -1
- package/dist/components/glass/marker.d.ts +66 -0
- package/dist/components/glass/marker.d.ts.map +1 -0
- package/dist/components/glass/marker.js +268 -0
- package/dist/components/glass/marker.js.map +1 -0
- package/dist/components/glass/props.d.ts +33 -7
- package/dist/components/glass/props.d.ts.map +1 -1
- package/dist/components/glass/style.css +139 -75
- package/dist/components/grid/dashes.d.ts +15 -0
- package/dist/components/grid/dashes.d.ts.map +1 -0
- package/dist/components/grid/dashes.js +37 -0
- package/dist/components/grid/dashes.js.map +1 -0
- package/dist/components/grid/edit.d.ts +11 -0
- package/dist/components/grid/edit.d.ts.map +1 -0
- package/dist/components/grid/edit.js +1066 -0
- package/dist/components/grid/edit.js.map +1 -0
- package/dist/components/grid/handle.d.ts +123 -0
- package/dist/components/grid/handle.d.ts.map +1 -0
- package/dist/components/grid/handle.js +194 -0
- package/dist/components/grid/handle.js.map +1 -0
- package/dist/components/grid/icons.d.ts +40 -0
- package/dist/components/grid/icons.d.ts.map +1 -0
- package/dist/components/grid/icons.js +140 -0
- package/dist/components/grid/icons.js.map +1 -0
- package/dist/components/grid/layout.d.ts +111 -0
- package/dist/components/grid/layout.d.ts.map +1 -0
- package/dist/components/grid/layout.js +1257 -0
- package/dist/components/grid/layout.js.map +1 -0
- package/dist/components/grid/main.d.ts +63 -0
- package/dist/components/grid/main.d.ts.map +1 -0
- package/dist/components/grid/main.js +1894 -0
- package/dist/components/grid/main.js.map +1 -0
- package/dist/components/grid/overlay.d.ts +24 -0
- package/dist/components/grid/overlay.d.ts.map +1 -0
- package/dist/components/grid/overlay.js +312 -0
- package/dist/components/grid/overlay.js.map +1 -0
- package/dist/components/grid/plan.d.ts +78 -0
- package/dist/components/grid/plan.d.ts.map +1 -0
- package/dist/components/grid/plan.js +249 -0
- package/dist/components/grid/plan.js.map +1 -0
- package/dist/components/grid/props.d.ts +509 -0
- package/dist/components/grid/props.d.ts.map +1 -0
- package/dist/components/grid/props.js +2 -0
- package/dist/components/grid/props.js.map +1 -0
- package/dist/components/grid/reshape.d.ts +60 -0
- package/dist/components/grid/reshape.d.ts.map +1 -0
- package/dist/components/grid/reshape.js +214 -0
- package/dist/components/grid/reshape.js.map +1 -0
- package/dist/components/grid/style.css +1293 -0
- package/dist/components/header/main.d.ts.map +1 -1
- package/dist/components/header/main.js +97 -10
- package/dist/components/header/main.js.map +1 -1
- package/dist/components/header/props.d.ts +2 -2
- package/dist/components/header/props.d.ts.map +1 -1
- package/dist/components/header/style.css +28 -43
- package/dist/components/index.d.ts +10 -6
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +5 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/island/main.d.ts +2 -2
- package/dist/components/island/main.d.ts.map +1 -1
- package/dist/components/island/main.js +193 -41
- package/dist/components/island/main.js.map +1 -1
- package/dist/components/island/props.d.ts +4 -2
- package/dist/components/island/props.d.ts.map +1 -1
- package/dist/components/island/style.css +50 -3
- package/dist/components/layout/main.d.ts +3 -6
- package/dist/components/layout/main.d.ts.map +1 -1
- package/dist/components/layout/main.js +225 -56
- package/dist/components/layout/main.js.map +1 -1
- package/dist/components/layout/props.d.ts +43 -2
- package/dist/components/layout/props.d.ts.map +1 -1
- package/dist/components/layout/style.css +84 -23
- package/dist/components/list/main.d.ts +3 -3
- package/dist/components/list/main.d.ts.map +1 -1
- package/dist/components/list/main.js +90 -19
- package/dist/components/list/main.js.map +1 -1
- package/dist/components/list/props.d.ts +20 -0
- package/dist/components/list/props.d.ts.map +1 -1
- package/dist/components/list/reorder.d.ts +16 -2
- package/dist/components/list/reorder.d.ts.map +1 -1
- package/dist/components/list/reorder.js.map +1 -1
- package/dist/components/list/style.css +60 -3
- package/dist/components/menu/main.d.ts +9 -5
- package/dist/components/menu/main.d.ts.map +1 -1
- package/dist/components/menu/main.js +87 -9
- package/dist/components/menu/main.js.map +1 -1
- package/dist/components/menu/props.d.ts +14 -0
- package/dist/components/menu/props.d.ts.map +1 -1
- package/dist/components/menu/style.css +3 -1
- package/dist/components/page/main.d.ts.map +1 -1
- package/dist/components/page/main.js +6 -3
- package/dist/components/page/main.js.map +1 -1
- package/dist/components/page/props.d.ts +3 -2
- package/dist/components/page/props.d.ts.map +1 -1
- package/dist/components/page/style.css +8 -4
- package/dist/components/page-control/props.d.ts +3 -3
- package/dist/components/popover/main.d.ts +10 -4
- package/dist/components/popover/main.d.ts.map +1 -1
- package/dist/components/popover/main.js +30 -19
- package/dist/components/popover/main.js.map +1 -1
- package/dist/components/popover/props.d.ts +2 -0
- package/dist/components/popover/props.d.ts.map +1 -1
- package/dist/components/popover/style.css +6 -2
- package/dist/components/progress/style.css +2 -2
- package/dist/components/roll/main.d.ts.map +1 -1
- package/dist/components/roll/main.js +5 -3
- package/dist/components/roll/main.js.map +1 -1
- package/dist/components/segmented/main.d.ts.map +1 -1
- package/dist/components/segmented/main.js +4 -4
- package/dist/components/segmented/main.js.map +1 -1
- package/dist/components/segmented/props.d.ts +5 -2
- package/dist/components/segmented/props.d.ts.map +1 -1
- package/dist/components/segmented/style.css +1 -1
- package/dist/components/settings/main.d.ts +13 -0
- package/dist/components/settings/main.d.ts.map +1 -1
- package/dist/components/settings/main.js +16 -0
- package/dist/components/settings/main.js.map +1 -1
- package/dist/components/settings/props.d.ts +1 -0
- package/dist/components/settings/props.d.ts.map +1 -1
- package/dist/components/sheet/main.d.ts.map +1 -1
- package/dist/components/sheet/main.js +156 -45
- package/dist/components/sheet/main.js.map +1 -1
- package/dist/components/sheet/props.d.ts +4 -2
- package/dist/components/sheet/props.d.ts.map +1 -1
- package/dist/components/sheet/snap.d.ts +54 -0
- package/dist/components/sheet/snap.d.ts.map +1 -1
- package/dist/components/sheet/snap.js +253 -23
- package/dist/components/sheet/snap.js.map +1 -1
- package/dist/components/sheet/style.css +126 -20
- package/dist/components/sidebar/main.d.ts +2 -1
- package/dist/components/sidebar/main.d.ts.map +1 -1
- package/dist/components/sidebar/main.js +18 -6
- package/dist/components/sidebar/main.js.map +1 -1
- package/dist/components/sidebar/props.d.ts +2 -1
- package/dist/components/sidebar/props.d.ts.map +1 -1
- package/dist/components/sidebar/style.css +78 -0
- package/dist/components/slider/main.d.ts.map +1 -1
- package/dist/components/slider/main.js +51 -9
- package/dist/components/slider/main.js.map +1 -1
- package/dist/components/slider/props.d.ts +1 -0
- package/dist/components/slider/props.d.ts.map +1 -1
- package/dist/components/slider/style.css +9 -0
- package/dist/components/switch/main.d.ts.map +1 -1
- package/dist/components/switch/main.js +4 -2
- package/dist/components/switch/main.js.map +1 -1
- package/dist/components/symbol/main.d.ts.map +1 -1
- package/dist/components/symbol/main.js +5 -1
- package/dist/components/symbol/main.js.map +1 -1
- package/dist/components/symbol/props.d.ts +10 -0
- package/dist/components/symbol/props.d.ts.map +1 -1
- package/dist/components/symbol/style.css +21 -3
- package/dist/components/tab-bar/main.d.ts.map +1 -1
- package/dist/components/tab-bar/main.js +8 -5
- package/dist/components/tab-bar/main.js.map +1 -1
- package/dist/components/tab-bar/props.d.ts +16 -12
- package/dist/components/tab-bar/props.d.ts.map +1 -1
- package/dist/components/tab-bar/style.css +3 -9
- package/dist/components/text-field/main.d.ts.map +1 -1
- package/dist/components/text-field/main.js +6 -3
- package/dist/components/text-field/main.js.map +1 -1
- package/dist/components/text-field/style.css +1 -1
- package/dist/components/toolbar/main.js +1 -1
- package/dist/components/toolbar/main.js.map +1 -1
- package/dist/components/toolbar/props.d.ts +3 -3
- package/dist/components/toolbar/style.css +1 -1
- package/dist/components/tooltip/main.d.ts +6 -1
- package/dist/components/tooltip/main.d.ts.map +1 -1
- package/dist/components/tooltip/main.js +13 -7
- package/dist/components/tooltip/main.js.map +1 -1
- package/dist/components/utils/main.d.ts +31 -2
- package/dist/components/utils/main.d.ts.map +1 -1
- package/dist/components/utils/main.js +60 -3
- package/dist/components/utils/main.js.map +1 -1
- package/dist/components/viewport/current.d.ts +15 -0
- package/dist/components/viewport/current.d.ts.map +1 -0
- package/dist/components/viewport/current.js +74 -0
- package/dist/components/viewport/current.js.map +1 -0
- package/dist/components/viewport/edge-effect.d.ts.map +1 -1
- package/dist/components/viewport/edge-effect.js +52 -24
- package/dist/components/viewport/edge-effect.js.map +1 -1
- package/dist/components/viewport/edge.d.ts +7 -4
- package/dist/components/viewport/edge.d.ts.map +1 -1
- package/dist/components/viewport/edge.js +21 -7
- package/dist/components/viewport/edge.js.map +1 -1
- package/dist/components/viewport/focus-scroll.d.ts +21 -0
- package/dist/components/viewport/focus-scroll.d.ts.map +1 -0
- package/dist/components/viewport/focus-scroll.js +272 -0
- package/dist/components/viewport/focus-scroll.js.map +1 -0
- package/dist/components/viewport/input.d.ts +39 -1
- package/dist/components/viewport/input.d.ts.map +1 -1
- package/dist/components/viewport/input.js +122 -13
- package/dist/components/viewport/input.js.map +1 -1
- package/dist/components/viewport/main.d.ts +16 -1
- package/dist/components/viewport/main.d.ts.map +1 -1
- package/dist/components/viewport/main.js +243 -49
- package/dist/components/viewport/main.js.map +1 -1
- package/dist/components/viewport/padding.d.ts +1 -1
- package/dist/components/viewport/padding.d.ts.map +1 -1
- package/dist/components/viewport/padding.js +2 -2
- package/dist/components/viewport/props.d.ts +12 -2
- package/dist/components/viewport/props.d.ts.map +1 -1
- package/dist/components/viewport/status-bar.d.ts +9 -0
- package/dist/components/viewport/status-bar.d.ts.map +1 -0
- package/dist/components/viewport/status-bar.js +131 -0
- package/dist/components/viewport/status-bar.js.map +1 -0
- package/dist/components/viewport/style.css +62 -5
- package/dist/styles.css +123 -198
- package/package.json +5 -4
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
// A background's color at a point (see backdrop.ts): its layers (computed
|
|
2
|
+
// `background-image`, the topmost first) as gradients evaluated there,
|
|
3
|
+
// then its color. Linear gradients (any angle, `to` a side or corner) and
|
|
4
|
+
// radial ones (circles and ellipses, at a position) by their stops; a
|
|
5
|
+
// repeating one, its stops' average; anything else (an image, a conic
|
|
6
|
+
// gradient), unknown. Drawn over the whole box (its size, position and
|
|
7
|
+
// repeat not taken into account): what backgrounds behind glass mostly are.
|
|
8
|
+
/** A string split at its top-level commas (not within parentheses). */
|
|
9
|
+
const splitTopLevel = (value) => {
|
|
10
|
+
const parts = [];
|
|
11
|
+
let depth = 0;
|
|
12
|
+
let start = 0;
|
|
13
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
14
|
+
const character = value[index];
|
|
15
|
+
if (character === '(')
|
|
16
|
+
depth += 1;
|
|
17
|
+
else if (character === ')')
|
|
18
|
+
depth -= 1;
|
|
19
|
+
else if (character === ',' && depth === 0) {
|
|
20
|
+
parts.push(value.slice(start, index).trim());
|
|
21
|
+
start = index + 1;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
parts.push(value.slice(start).trim());
|
|
25
|
+
return parts;
|
|
26
|
+
};
|
|
27
|
+
const colorPattern = /(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)\([^)]*\)|#[\da-f]{3,8}\b|\btransparent\b/iu;
|
|
28
|
+
/**
|
|
29
|
+
* Stops' positions left out filled in: the first at 0, the last at the end
|
|
30
|
+
* (`length`), those between spread evenly; none before an earlier one's.
|
|
31
|
+
*/
|
|
32
|
+
const spread = (stops, length) => {
|
|
33
|
+
const first = stops[0];
|
|
34
|
+
const last = stops.at(-1);
|
|
35
|
+
if (first && first.position === undefined)
|
|
36
|
+
first.position = 0;
|
|
37
|
+
if (last && last.position === undefined)
|
|
38
|
+
last.position = length;
|
|
39
|
+
for (let index = 0; index < stops.length; index += 1) {
|
|
40
|
+
if (stops[index]?.position !== undefined)
|
|
41
|
+
continue;
|
|
42
|
+
const before = index - 1;
|
|
43
|
+
let after = index;
|
|
44
|
+
while (stops[after]?.position === undefined)
|
|
45
|
+
after += 1;
|
|
46
|
+
const from = stops[before]?.position ?? 0;
|
|
47
|
+
const to = stops[after]?.position ?? length;
|
|
48
|
+
for (let gap = index; gap < after; gap += 1) {
|
|
49
|
+
const stop = stops[gap];
|
|
50
|
+
if (stop) {
|
|
51
|
+
stop.position =
|
|
52
|
+
from + ((to - from) * (gap - before)) / (after - before);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
let floor = -Infinity;
|
|
57
|
+
for (const stop of stops) {
|
|
58
|
+
stop.position = Math.max(stop.position ?? 0, floor);
|
|
59
|
+
floor = stop.position;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* A gradient's stops (`color [position [position]]`), their positions in px
|
|
64
|
+
* along a line `length` long (percentages of it), in order; a stop with two
|
|
65
|
+
* positions, two stops.
|
|
66
|
+
*/
|
|
67
|
+
const stopsOf = (parts, length, parse) => {
|
|
68
|
+
const stops = [];
|
|
69
|
+
for (const part of parts) {
|
|
70
|
+
const match = colorPattern.exec(part);
|
|
71
|
+
if (!match)
|
|
72
|
+
return undefined;
|
|
73
|
+
const color = parse(match[0]);
|
|
74
|
+
if (!color)
|
|
75
|
+
return undefined;
|
|
76
|
+
const positions = part
|
|
77
|
+
.replace(match[0], '')
|
|
78
|
+
.trim()
|
|
79
|
+
.split(/\s+/u)
|
|
80
|
+
.filter(Boolean)
|
|
81
|
+
.map((token) => {
|
|
82
|
+
const value = Number.parseFloat(token);
|
|
83
|
+
return token.endsWith('%') ? (value / 100) * length : value;
|
|
84
|
+
});
|
|
85
|
+
if (positions.length === 0)
|
|
86
|
+
stops.push({ color, position: undefined });
|
|
87
|
+
for (const position of positions)
|
|
88
|
+
stops.push({ color, position });
|
|
89
|
+
}
|
|
90
|
+
spread(stops, length);
|
|
91
|
+
return stops;
|
|
92
|
+
};
|
|
93
|
+
/** The color at `distance` along a gradient's stops (see `stopsOf`). */
|
|
94
|
+
const colorAlong = (stops, distance) => {
|
|
95
|
+
const first = stops[0];
|
|
96
|
+
if (!first)
|
|
97
|
+
return [0, 0, 0, 0];
|
|
98
|
+
if (distance <= (first.position ?? 0))
|
|
99
|
+
return first.color;
|
|
100
|
+
for (let index = 1; index < stops.length; index += 1) {
|
|
101
|
+
const from = stops[index - 1];
|
|
102
|
+
const to = stops[index];
|
|
103
|
+
if (!from || !to)
|
|
104
|
+
continue;
|
|
105
|
+
const start = from.position ?? 0;
|
|
106
|
+
const end = to.position ?? 0;
|
|
107
|
+
if (distance > end)
|
|
108
|
+
continue;
|
|
109
|
+
const t = end === start ? 1 : (distance - start) / (end - start);
|
|
110
|
+
return from.color.map((channel, channelIndex) => channel + ((to.color[channelIndex] ?? 0) - channel) * t);
|
|
111
|
+
}
|
|
112
|
+
return stops.at(-1)?.color ?? first.color;
|
|
113
|
+
};
|
|
114
|
+
const sideAngles = {
|
|
115
|
+
bottom: 180,
|
|
116
|
+
left: 270,
|
|
117
|
+
right: 90,
|
|
118
|
+
top: 0,
|
|
119
|
+
};
|
|
120
|
+
const degreesPattern = /^(?<value>-?[\d.]+)deg$/u;
|
|
121
|
+
const turnPattern = /^(?<value>-?[\d.]+)turn$/u;
|
|
122
|
+
/** A linear gradient's angle (deg) from its first part, if it's one. */
|
|
123
|
+
const angleOf = (part, { height, width }) => {
|
|
124
|
+
const degrees = degreesPattern.exec(part);
|
|
125
|
+
if (degrees)
|
|
126
|
+
return Number(degrees.groups?.value);
|
|
127
|
+
const turn = turnPattern.exec(part);
|
|
128
|
+
if (turn)
|
|
129
|
+
return Number(turn.groups?.value) * 360;
|
|
130
|
+
if (!part.startsWith('to '))
|
|
131
|
+
return undefined;
|
|
132
|
+
const sides = part.slice(3).split(/\s+/u);
|
|
133
|
+
if (sides.length === 1)
|
|
134
|
+
return sideAngles[sides[0] ?? ''];
|
|
135
|
+
// (A corner: the angle pointing at it, for the box's proportions.)
|
|
136
|
+
const vertical = sides.includes('top') ? -1 : 1;
|
|
137
|
+
const horizontal = sides.includes('left') ? -1 : 1;
|
|
138
|
+
return (Math.atan2(horizontal * height, -vertical * width) * 180) / Math.PI;
|
|
139
|
+
};
|
|
140
|
+
const linearAt = (parts, at, parse) => {
|
|
141
|
+
const [head = ''] = parts;
|
|
142
|
+
const given = angleOf(head, at);
|
|
143
|
+
const angle = ((given ?? 180) * Math.PI) / 180;
|
|
144
|
+
const sin = Math.sin(angle);
|
|
145
|
+
const cos = Math.cos(angle);
|
|
146
|
+
const length = Math.abs(at.width * sin) + Math.abs(at.height * cos);
|
|
147
|
+
const stops = stopsOf(given === undefined ? parts : parts.slice(1), length, parse);
|
|
148
|
+
if (!stops)
|
|
149
|
+
return undefined;
|
|
150
|
+
const distance = length / 2 + (at.x - at.width / 2) * sin - (at.y - at.height / 2) * cos;
|
|
151
|
+
return colorAlong(stops, distance);
|
|
152
|
+
};
|
|
153
|
+
/** A position's coordinate (`50%`, `12px`) in a box's side `size` long. */
|
|
154
|
+
const coordinate = (token, size) => {
|
|
155
|
+
if (token === undefined)
|
|
156
|
+
return size / 2;
|
|
157
|
+
const keywords = {
|
|
158
|
+
bottom: 1,
|
|
159
|
+
center: 0.5,
|
|
160
|
+
left: 0,
|
|
161
|
+
right: 1,
|
|
162
|
+
top: 0,
|
|
163
|
+
};
|
|
164
|
+
const keyword = keywords[token];
|
|
165
|
+
if (keyword !== undefined)
|
|
166
|
+
return keyword * size;
|
|
167
|
+
const value = Number.parseFloat(token);
|
|
168
|
+
return token.endsWith('%') ? (value / 100) * size : value;
|
|
169
|
+
};
|
|
170
|
+
const radialAt = (parts, at, parse) => {
|
|
171
|
+
const [head = ''] = parts;
|
|
172
|
+
const hasShape = !colorPattern.test(head);
|
|
173
|
+
const shape = hasShape ? head : '';
|
|
174
|
+
const [, position = ''] = shape.split(/\bat\b/u);
|
|
175
|
+
const [xToken, yToken] = position.trim().split(/\s+/u).filter(Boolean);
|
|
176
|
+
const cx = coordinate(xToken, at.width);
|
|
177
|
+
const cy = coordinate(yToken, at.height);
|
|
178
|
+
// (Its size the farthest corner, as by default; an ellipse's radii in its
|
|
179
|
+
// box's proportions.)
|
|
180
|
+
const dx = Math.max(cx, at.width - cx);
|
|
181
|
+
const dy = Math.max(cy, at.height - cy);
|
|
182
|
+
const isCircle = shape.includes('circle');
|
|
183
|
+
const rx = isCircle ? Math.hypot(dx, dy) : dx * Math.SQRT2;
|
|
184
|
+
const ry = isCircle ? rx : dy * Math.SQRT2;
|
|
185
|
+
const stops = stopsOf(hasShape ? parts.slice(1) : parts, rx, parse);
|
|
186
|
+
if (!stops)
|
|
187
|
+
return undefined;
|
|
188
|
+
const distance = Math.hypot(at.x - cx, ((at.y - cy) * rx) / (ry || 1));
|
|
189
|
+
return colorAlong(stops, distance);
|
|
190
|
+
};
|
|
191
|
+
/** A repeating gradient: its stops' colors' average. */
|
|
192
|
+
const averageOf = (parts, parse) => {
|
|
193
|
+
const colors = parts
|
|
194
|
+
.map((part) => colorPattern.exec(part)?.[0])
|
|
195
|
+
.filter((color) => color !== undefined)
|
|
196
|
+
.map((color) => parse(color))
|
|
197
|
+
.filter((color) => color !== undefined);
|
|
198
|
+
return colors.length === 0
|
|
199
|
+
? undefined
|
|
200
|
+
: [0, 1, 2, 3].map((index) => colors.reduce((sum, color) => sum + (color[index] ?? 0), 0) /
|
|
201
|
+
colors.length);
|
|
202
|
+
};
|
|
203
|
+
/** One layer's color at the point (undefined: unknown). */
|
|
204
|
+
const layerAt = (layer, at, parse) => {
|
|
205
|
+
const open = layer.indexOf('(');
|
|
206
|
+
if (open === -1 || !layer.endsWith(')'))
|
|
207
|
+
return undefined;
|
|
208
|
+
const kind = layer.slice(0, open);
|
|
209
|
+
const parts = splitTopLevel(layer.slice(open + 1, -1));
|
|
210
|
+
if (kind === 'linear-gradient')
|
|
211
|
+
return linearAt(parts, at, parse);
|
|
212
|
+
if (kind === 'radial-gradient')
|
|
213
|
+
return radialAt(parts, at, parse);
|
|
214
|
+
return kind.startsWith('repeating-') ? averageOf(parts, parse) : undefined;
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* A background's color at a point (see the top): its topmost layer there
|
|
218
|
+
* at least 30% opaque, else its color (null: none that opaque; undefined:
|
|
219
|
+
* a layer unknown, e.g. an image).
|
|
220
|
+
*/
|
|
221
|
+
export const backgroundColorAt = (backgroundImage, backgroundColor, at, parse) => {
|
|
222
|
+
const layers = backgroundImage === 'none' ? [] : splitTopLevel(backgroundImage);
|
|
223
|
+
for (const layer of layers) {
|
|
224
|
+
const color = layerAt(layer, at, parse);
|
|
225
|
+
if (color === undefined)
|
|
226
|
+
return undefined;
|
|
227
|
+
if (color[3] >= 0.3)
|
|
228
|
+
return color;
|
|
229
|
+
}
|
|
230
|
+
const color = parse(backgroundColor);
|
|
231
|
+
return color && color[3] >= 0.3 ? color : null;
|
|
232
|
+
};
|
|
233
|
+
//# sourceMappingURL=gradient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gradient.js","sourceRoot":"","sources":["../../../src/components/glass/gradient.ts"],"names":[],"mappings":"AA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+
import type { ColorScheme } from '../utils/main.js';
|
|
4
|
+
import { type BackdropTone } from './backdrop.js';
|
|
5
|
+
import type { GlassBackgroundProps, GlassContext, GlassContextValue, GlassMode } from './props.js';
|
|
6
|
+
export { type BackdropTone, type BackdropToneOptions, resampleBackdrops, toneOfColor, useBackdropTone, } from './backdrop.js';
|
|
7
|
+
export { type BackdropArea, backdropGridOf, type BackdropMarkerValue, type ImageBackdropMarkerOptions, useBackdropMarker, useImageBackdropMarker, } from './marker.js';
|
|
8
|
+
export type { GlassBackgroundProps, GlassContext, GlassContextValue, GlassMode, GlassModeProps, GlassSurfaceProps, } from './props.js';
|
|
5
9
|
/**
|
|
6
|
-
* The glass context to draw with: the given one, or (`adaptive`)
|
|
7
|
-
* what's behind the element
|
|
10
|
+
* The glass context to draw with: the given one, or (`adaptive`) the tone of
|
|
11
|
+
* what's behind the element (see `useBackdropTone`), held for `dwell` ms
|
|
12
|
+
* before it flips (large surfaces); none given, `undefined` (by the color
|
|
13
|
+
* scheme). Reduced transparency or more contrast (opaque glass), never
|
|
14
|
+
* sampled.
|
|
8
15
|
*/
|
|
9
16
|
export declare const useGlassContext: (ref: {
|
|
10
17
|
current: Element | null;
|
|
11
|
-
}, context: GlassContextValue | undefined) => GlassContext | undefined;
|
|
18
|
+
}, context: GlassContextValue | undefined, dwell?: number) => GlassContext | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* A glass surface's color scheme by its `context` (e.g. a sheet's, a
|
|
21
|
+
* card's): bright, light; dim, dark (sampled, `adaptive`: held a moment,
|
|
22
|
+
* see `useGlassContext`); none, `undefined` (the page's). Shown with
|
|
23
|
+
* `data-color-scheme` and `colorSchemeStyle` on its element, and `ColorSchemeScope` around its
|
|
24
|
+
* content (for `useSettings` and portals opened from it).
|
|
25
|
+
*/
|
|
26
|
+
export declare const useGlassScheme: (ref: {
|
|
27
|
+
current: Element | null;
|
|
28
|
+
}, context: GlassContextValue | undefined) => ColorScheme | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* An element's style showing a color scheme of its own (for `withStyle`,
|
|
31
|
+
* beside its `data-color-scheme`; none, none).
|
|
32
|
+
*/
|
|
33
|
+
export declare const colorSchemeStyle: (colorScheme: ColorScheme | undefined) => Record<string, string>;
|
|
34
|
+
/**
|
|
35
|
+
* A surface its content's tones are sampled within (e.g. a card's glass,
|
|
36
|
+
* see `useContentTone`): its element; none, not sampled (e.g. while its
|
|
37
|
+
* card's grid is editing, its veil over it).
|
|
38
|
+
*/
|
|
39
|
+
export declare const ContentToneScope: import("preact").Context<{
|
|
40
|
+
current: Element | null;
|
|
41
|
+
} | undefined>;
|
|
42
|
+
/**
|
|
43
|
+
* A part's tone on the surface it's on (see `ContentToneScope`): what's
|
|
44
|
+
* painted right behind it there (the surface's glass, a slider's fill),
|
|
45
|
+
* sampled within it, as the surface changes. `undefined` outside one.
|
|
46
|
+
*/
|
|
47
|
+
export declare const useContentTone: (ref: {
|
|
48
|
+
current: Element | null;
|
|
49
|
+
}, enabled?: boolean) => BackdropTone | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* A content part's props for its tone (see `useContentTone`): its
|
|
52
|
+
* `data-backdrop-tone` and a color scheme of its own (its text's
|
|
53
|
+
* `light-dark()` colors by it), for `withStyle`.
|
|
54
|
+
*/
|
|
55
|
+
export declare const contentToneProps: (tone: BackdropTone | undefined) => {
|
|
56
|
+
"data-backdrop-tone"?: BackdropTone;
|
|
57
|
+
style: Record<string, string>;
|
|
58
|
+
};
|
|
12
59
|
/**
|
|
13
60
|
* The context of the glass bar a component is in (e.g. a `Toolbar`'s), for
|
|
14
61
|
* glass inside it without a context of its own (e.g. a `PageControl`).
|
|
@@ -31,4 +78,11 @@ export declare const InheritedGlassContext: import("preact").Context<GlassContex
|
|
|
31
78
|
* to 1) clears the fill and shows the lens' edge.
|
|
32
79
|
*/
|
|
33
80
|
export declare const GlassBackground: FunctionComponent<GlassBackgroundProps>;
|
|
81
|
+
/**
|
|
82
|
+
* A scroll container's glass (its `glass` prop, see `GlassModeProps`), as
|
|
83
|
+
* its `data-glass`: `auto` resolved, flat while it can scroll (`bounces`:
|
|
84
|
+
* it does anyway), measured as it or its content resizes; else as given.
|
|
85
|
+
* Internal (Page, the content parts).
|
|
86
|
+
*/
|
|
87
|
+
export declare const useGlassMode: (ref: RefObject<HTMLElement | null>, glass: GlassMode, bounces: boolean) => "flat" | "live";
|
|
34
88
|
//# sourceMappingURL=main.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../src/components/glass/main.tsx"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AAErB,OAAO,EAEL,iBAAiB,
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../src/components/glass/main.tsx"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AAErB,OAAO,EAEL,iBAAiB,EACjB,SAAS,EAIV,MAAM,OAAO,CAAC;AAGf,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,KAAK,YAAY,EAAmB,MAAM,eAAe,CAAC;AACnE,OAAO,KAAK,EACV,oBAAoB,EACpB,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,iBAAiB,EACjB,WAAW,EACX,eAAe,GAChB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,KAAK,YAAY,EACjB,cAAc,EACd,KAAK,mBAAmB,EACxB,KAAK,0BAA0B,EAC/B,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,oBAAoB,EACpB,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,cAAc,EACd,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAOpB;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAC1B,KAAK;IAAE,OAAO,EAAE,OAAO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, useLayoutEffect, useState, } from 'react';
|
|
3
|
+
import { createContext, useContext, useLayoutEffect, useState, } from 'react';
|
|
4
|
+
import { useSettings } from '../settings/main.js';
|
|
5
|
+
import { useBackdropTone } from './backdrop.js';
|
|
6
|
+
export { resampleBackdrops, toneOfColor, useBackdropTone, } from './backdrop.js';
|
|
7
|
+
export { backdropGridOf, useBackdropMarker, useImageBackdropMarker, } from './marker.js';
|
|
4
8
|
// Glass building blocks shared by components: glass materials behind
|
|
5
9
|
// bars and capsules, and glass lenses (the pressed, magnified state of knobs
|
|
6
10
|
// and selections), styled by style.css. Tokens and their sources are in
|
|
7
11
|
// `styles.css` (`--glass-ui-*`).
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (luminance > toBright)
|
|
23
|
-
return 'background-bright';
|
|
24
|
-
return last ?? (luminance < 0.6 ? 'background-dim' : 'background-bright');
|
|
25
|
-
};
|
|
26
|
-
/** A CSS color's relative luminance (0 to 1) and alpha. */
|
|
27
|
-
const luminanceOf = (color) => {
|
|
28
|
-
colorCanvas ??= document.createElement('canvas').getContext('2d');
|
|
29
|
-
if (!colorCanvas)
|
|
30
|
-
return undefined;
|
|
31
|
-
colorCanvas.fillStyle = '#000';
|
|
32
|
-
colorCanvas.fillStyle = color;
|
|
33
|
-
const normalized = colorCanvas.fillStyle;
|
|
34
|
-
const channels = normalized.startsWith('#')
|
|
35
|
-
? [1, 3, 5].map((index) => Number.parseInt(normalized.slice(index, index + 2), 16))
|
|
36
|
-
: (normalized.match(/[\d.]+/gu) ?? []).map(Number);
|
|
37
|
-
const [red = 0, green = 0, blue = 0, alpha = 1] = channels;
|
|
38
|
-
return {
|
|
39
|
-
alpha,
|
|
40
|
-
luminance: 0.2126 * linear(red) + 0.7152 * linear(green) + 0.0722 * linear(blue),
|
|
41
|
-
};
|
|
12
|
+
/**
|
|
13
|
+
* The glass context to draw with: the given one, or (`adaptive`) the tone of
|
|
14
|
+
* what's behind the element (see `useBackdropTone`), held for `dwell` ms
|
|
15
|
+
* before it flips (large surfaces); none given, `undefined` (by the color
|
|
16
|
+
* scheme). Reduced transparency or more contrast (opaque glass), never
|
|
17
|
+
* sampled.
|
|
18
|
+
*/
|
|
19
|
+
export const useGlassContext = (ref, context, dwell = 0) => {
|
|
20
|
+
const { contrast, reducedTransparency } = useSettings();
|
|
21
|
+
const sampled = useBackdropTone(ref, {
|
|
22
|
+
dwell,
|
|
23
|
+
enabled: context === 'adaptive' && !reducedTransparency && contrast !== 'more',
|
|
24
|
+
});
|
|
25
|
+
return context === 'adaptive' ? sampled : context;
|
|
42
26
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
27
|
+
/** How long a surface's sampled tone holds before it flips (ms). */
|
|
28
|
+
const surfaceDwell = 150;
|
|
29
|
+
/**
|
|
30
|
+
* A glass surface's color scheme by its `context` (e.g. a sheet's, a
|
|
31
|
+
* card's): bright, light; dim, dark (sampled, `adaptive`: held a moment,
|
|
32
|
+
* see `useGlassContext`); none, `undefined` (the page's). Shown with
|
|
33
|
+
* `data-color-scheme` and `colorSchemeStyle` on its element, and `ColorSchemeScope` around its
|
|
34
|
+
* content (for `useSettings` and portals opened from it).
|
|
35
|
+
*/
|
|
36
|
+
export const useGlassScheme = (ref, context) => {
|
|
37
|
+
const tone = useGlassContext(ref, context, surfaceDwell);
|
|
38
|
+
if (tone === undefined)
|
|
49
39
|
return undefined;
|
|
50
|
-
return
|
|
51
|
-
...(backgroundImage === 'none'
|
|
52
|
-
? []
|
|
53
|
-
: (backgroundImage.match(colorPattern) ?? [])),
|
|
54
|
-
backgroundColor,
|
|
55
|
-
].filter((color) => (luminanceOf(color)?.alpha ?? 0) >= 0.3);
|
|
56
|
-
};
|
|
57
|
-
/** The luminance of what's behind an element (its center and corners). */
|
|
58
|
-
const luminanceBehind = (element) => {
|
|
59
|
-
const { bottom, left, right, top } = element.getBoundingClientRect();
|
|
60
|
-
const inset = 4;
|
|
61
|
-
const points = [
|
|
62
|
-
[(left + right) / 2, (top + bottom) / 2],
|
|
63
|
-
[left + inset, top + inset],
|
|
64
|
-
[right - inset, top + inset],
|
|
65
|
-
[left + inset, bottom - inset],
|
|
66
|
-
[right - inset, bottom - inset],
|
|
67
|
-
];
|
|
68
|
-
const values = [];
|
|
69
|
-
for (const [x = 0, y = 0] of points) {
|
|
70
|
-
const stack = document.elementsFromPoint(x, y);
|
|
71
|
-
// Below the element (not what's over it, nor the element itself), in
|
|
72
|
-
// paint order (the page's layers, not only its ancestors): the first
|
|
73
|
-
// with a background.
|
|
74
|
-
const at = stack.findIndex((candidate) => element.contains(candidate));
|
|
75
|
-
let colors = [];
|
|
76
|
-
for (const candidate of stack.slice(at === -1 ? 0 : at)) {
|
|
77
|
-
if (element.contains(candidate))
|
|
78
|
-
continue;
|
|
79
|
-
colors = backgroundColorsOf(candidate);
|
|
80
|
-
if (colors?.length !== 0)
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
if (!colors)
|
|
84
|
-
continue;
|
|
85
|
-
for (const color of colors) {
|
|
86
|
-
const value = luminanceOf(color)?.luminance;
|
|
87
|
-
if (value !== undefined)
|
|
88
|
-
values.push(value);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return values.length === 0
|
|
92
|
-
? undefined
|
|
93
|
-
: values.reduce((sum, value) => sum + value, 0) / values.length;
|
|
40
|
+
return tone === 'bright' ? 'light' : 'dark';
|
|
94
41
|
};
|
|
95
42
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
43
|
+
* An element's style showing a color scheme of its own (for `withStyle`,
|
|
44
|
+
* beside its `data-color-scheme`; none, none).
|
|
98
45
|
*/
|
|
99
|
-
export const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
};
|
|
118
|
-
const schedule = () => {
|
|
119
|
-
frame ||= requestAnimationFrame(update);
|
|
120
|
-
};
|
|
121
|
-
update();
|
|
122
|
-
addEventListener('scroll', schedule, { capture: true, passive: true });
|
|
123
|
-
addEventListener('resize', schedule);
|
|
124
|
-
const observer = new ResizeObserver(schedule);
|
|
125
|
-
observer.observe(element);
|
|
126
|
-
return () => {
|
|
127
|
-
cancelAnimationFrame(frame);
|
|
128
|
-
removeEventListener('scroll', schedule, { capture: true });
|
|
129
|
-
removeEventListener('resize', schedule);
|
|
130
|
-
observer.disconnect();
|
|
131
|
-
};
|
|
132
|
-
}, [context, ref]);
|
|
133
|
-
return context === 'adaptive' ? sampled : context;
|
|
46
|
+
export const colorSchemeStyle = (colorScheme) => colorScheme === undefined ? {} : { 'color-scheme': colorScheme };
|
|
47
|
+
/**
|
|
48
|
+
* A surface its content's tones are sampled within (e.g. a card's glass,
|
|
49
|
+
* see `useContentTone`): its element; none, not sampled (e.g. while its
|
|
50
|
+
* card's grid is editing, its veil over it).
|
|
51
|
+
*/
|
|
52
|
+
export const ContentToneScope = createContext(undefined);
|
|
53
|
+
/**
|
|
54
|
+
* A part's tone on the surface it's on (see `ContentToneScope`): what's
|
|
55
|
+
* painted right behind it there (the surface's glass, a slider's fill),
|
|
56
|
+
* sampled within it, as the surface changes. `undefined` outside one.
|
|
57
|
+
*/
|
|
58
|
+
export const useContentTone = (ref, enabled = true) => {
|
|
59
|
+
const within = useContext(ContentToneScope);
|
|
60
|
+
return useBackdropTone(ref, {
|
|
61
|
+
enabled: enabled && within !== undefined,
|
|
62
|
+
within,
|
|
63
|
+
});
|
|
134
64
|
};
|
|
65
|
+
/**
|
|
66
|
+
* A content part's props for its tone (see `useContentTone`): its
|
|
67
|
+
* `data-backdrop-tone` and a color scheme of its own (its text's
|
|
68
|
+
* `light-dark()` colors by it), for `withStyle`.
|
|
69
|
+
*/
|
|
70
|
+
export const contentToneProps = (tone) => tone === undefined
|
|
71
|
+
? { style: {} }
|
|
72
|
+
: {
|
|
73
|
+
'data-backdrop-tone': tone,
|
|
74
|
+
style: colorSchemeStyle(tone === 'bright' ? 'light' : 'dark'),
|
|
75
|
+
};
|
|
135
76
|
/**
|
|
136
77
|
* The context of the glass bar a component is in (e.g. a `Toolbar`'s), for
|
|
137
78
|
* glass inside it without a context of its own (e.g. a `PageControl`).
|
|
@@ -154,4 +95,41 @@ export const InheritedGlassContext = createContext(undefined);
|
|
|
154
95
|
* to 1) clears the fill and shows the lens' edge.
|
|
155
96
|
*/
|
|
156
97
|
export const GlassBackground = ({ kind = 'bar', tinted = false, }) => (_jsxs(_Fragment, { children: [kind === 'bar' ? (_jsx("span", { "aria-hidden": "true", className: "uikit-glass-blur", "data-glass-part": "blur" })) : (_jsx("span", { "aria-hidden": "true", className: "uikit-glass-halo", "data-glass-part": "halo" })), tinted ? (_jsxs("span", { "aria-hidden": "true", className: "uikit-glass-tint-group", "data-glass-part": "tint-group", children: [_jsx("span", { className: "uikit-glass-tint-base", "data-glass-part": "tint-base" }), _jsx("span", { className: "uikit-glass-tint-saturation", "data-glass-part": "tint-saturation" }), _jsx("span", { className: "uikit-glass-tint-overlay", "data-glass-part": "tint-overlay" }), _jsx("span", { className: "uikit-glass-tint", "data-glass-part": "tint" })] })) : (_jsx("span", { "aria-hidden": "true", className: "uikit-glass-fill", "data-glass-part": "fill" })), tinted ? (_jsx("span", { "aria-hidden": "true", className: "uikit-glass-tinted-effect", "data-glass-part": "tinted-effect" })) : (_jsx("span", { "aria-hidden": "true", className: "uikit-glass-effect", "data-glass-part": "effect" })), _jsx("span", { "aria-hidden": "true", className: "uikit-glass-lens", "data-glass-part": "lens" })] }));
|
|
98
|
+
/** Whether an element can scroll (its content larger than it, either way). */
|
|
99
|
+
const canScroll = (element) => element.scrollHeight > element.clientHeight ||
|
|
100
|
+
element.scrollWidth > element.clientWidth;
|
|
101
|
+
/**
|
|
102
|
+
* A scroll container's glass (its `glass` prop, see `GlassModeProps`), as
|
|
103
|
+
* its `data-glass`: `auto` resolved, flat while it can scroll (`bounces`:
|
|
104
|
+
* it does anyway), measured as it or its content resizes; else as given.
|
|
105
|
+
* Internal (Page, the content parts).
|
|
106
|
+
*/
|
|
107
|
+
export const useGlassMode = (ref, glass, bounces) => {
|
|
108
|
+
const [scrolls, setScrolls] = useState(false);
|
|
109
|
+
useLayoutEffect(() => {
|
|
110
|
+
const { current: element } = ref;
|
|
111
|
+
if (!element || glass !== 'auto' || bounces)
|
|
112
|
+
return undefined;
|
|
113
|
+
const measure = () => setScrolls(canScroll(element));
|
|
114
|
+
const resizeObserver = new ResizeObserver(measure);
|
|
115
|
+
// (It and its children: its content's size.)
|
|
116
|
+
const observe = () => {
|
|
117
|
+
resizeObserver.disconnect();
|
|
118
|
+
resizeObserver.observe(element);
|
|
119
|
+
for (const child of element.children)
|
|
120
|
+
resizeObserver.observe(child);
|
|
121
|
+
measure();
|
|
122
|
+
};
|
|
123
|
+
const mutationObserver = new MutationObserver(observe);
|
|
124
|
+
mutationObserver.observe(element, { childList: true });
|
|
125
|
+
observe();
|
|
126
|
+
return () => {
|
|
127
|
+
resizeObserver.disconnect();
|
|
128
|
+
mutationObserver.disconnect();
|
|
129
|
+
};
|
|
130
|
+
}, [bounces, glass, ref]);
|
|
131
|
+
if (glass !== 'auto')
|
|
132
|
+
return glass;
|
|
133
|
+
return bounces || scrolls ? 'flat' : 'live';
|
|
134
|
+
};
|
|
157
135
|
//# sourceMappingURL=main.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/components/glass/main.tsx"],"names":[],"mappings":";AAAA,OAAO,aAAa,CAAC;AAErB,OAAO,EACL,a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