glasslikeui 1.9.0 → 1.10.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/README.md +892 -24
- package/dist/actions/adaptiveTone.d.ts +50 -0
- package/dist/actions/adaptiveTone.js +569 -0
- package/dist/actions/alertLogic.d.ts +67 -0
- package/dist/actions/alertLogic.js +123 -0
- package/dist/actions/anchorPlacement.d.ts +92 -0
- package/dist/actions/anchorPlacement.js +137 -0
- package/dist/actions/dragSnap.d.ts +1 -1
- package/dist/actions/dragSnapMath.d.ts +70 -0
- package/dist/actions/dragSnapMath.js +115 -0
- package/dist/actions/glassToneLogic.d.ts +182 -0
- package/dist/actions/glassToneLogic.js +513 -0
- package/dist/actions/heightTransition.d.ts +32 -0
- package/dist/actions/heightTransition.js +64 -0
- package/dist/actions/index.d.ts +1 -0
- package/dist/actions/index.js +1 -0
- package/dist/actions/inertSiblings.js +20 -4
- package/dist/actions/menuLogic.d.ts +40 -0
- package/dist/actions/menuLogic.js +68 -0
- package/dist/actions/modalDialog.d.ts +19 -0
- package/dist/actions/modalDialog.js +48 -0
- package/dist/actions/popoverLogic.d.ts +25 -0
- package/dist/actions/popoverLogic.js +48 -0
- package/dist/actions/rovingIndex.d.ts +30 -0
- package/dist/actions/rovingIndex.js +49 -0
- package/dist/actions/scrollRunTracker.d.ts +36 -0
- package/dist/actions/scrollRunTracker.js +77 -0
- package/dist/actions/scrollUnder.d.ts +21 -0
- package/dist/actions/scrollUnder.js +29 -0
- package/dist/actions/segmentedLogic.d.ts +38 -0
- package/dist/actions/segmentedLogic.js +59 -0
- package/dist/actions/sheetLogic.d.ts +43 -0
- package/dist/actions/sheetLogic.js +71 -0
- package/dist/actions/sliderLogic.d.ts +29 -0
- package/dist/actions/sliderLogic.js +53 -0
- package/dist/actions/swipeActions.d.ts +46 -2
- package/dist/actions/swipeActions.js +267 -46
- package/dist/actions/tabBarMinimize.d.ts +31 -0
- package/dist/actions/tabBarMinimize.js +38 -0
- package/dist/actions/tabViewLogic.d.ts +47 -0
- package/dist/actions/tabViewLogic.js +71 -0
- package/dist/actions/toggleKnobLogic.d.ts +57 -0
- package/dist/actions/toggleKnobLogic.js +66 -0
- package/dist/actions/toolbarFocus.d.ts +44 -0
- package/dist/actions/toolbarFocus.js +228 -0
- package/dist/actions/topLayer.d.ts +12 -0
- package/dist/actions/topLayer.js +18 -0
- package/dist/components/dialog/ActionSheet.svelte +457 -0
- package/dist/components/dialog/ActionSheet.svelte.d.ts +25 -0
- package/dist/components/dialog/Alert.svelte +337 -0
- package/dist/components/dialog/Alert.svelte.d.ts +28 -0
- package/dist/components/dialog/index.d.ts +6 -0
- package/dist/components/dialog/index.js +6 -0
- package/dist/components/glass/Glass.svelte +49 -17
- package/dist/components/glass/Glass.svelte.d.ts +8 -0
- package/dist/components/glass/GlassSection.svelte +9 -1
- package/dist/components/glass/LensFilters.svelte +4 -2
- package/dist/components/glass/Popover.svelte +379 -0
- package/dist/components/glass/Popover.svelte.d.ts +30 -0
- package/dist/components/glass/Sheet.svelte +470 -103
- package/dist/components/glass/Sheet.svelte.d.ts +55 -7
- package/dist/components/glass/index.d.ts +3 -0
- package/dist/components/glass/index.js +1 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +4 -0
- package/dist/components/interactive/Badge.svelte +97 -6
- package/dist/components/interactive/Badge.svelte.d.ts +13 -2
- package/dist/components/interactive/Button.svelte +162 -20
- package/dist/components/interactive/Button.svelte.d.ts +14 -1
- package/dist/components/interactive/IconButton.svelte +214 -4
- package/dist/components/interactive/IconButton.svelte.d.ts +2 -1
- package/dist/components/interactive/ProgressView.svelte +306 -0
- package/dist/components/interactive/ProgressView.svelte.d.ts +25 -0
- package/dist/components/interactive/Segment.d.ts +14 -0
- package/dist/components/interactive/Segment.js +1 -0
- package/dist/components/interactive/SegmentedControl.svelte +399 -0
- package/dist/components/interactive/SegmentedControl.svelte.d.ts +17 -0
- package/dist/components/interactive/Slider.svelte +299 -0
- package/dist/components/interactive/Slider.svelte.d.ts +23 -0
- package/dist/components/interactive/TabView.svelte +573 -41
- package/dist/components/interactive/TabView.svelte.d.ts +25 -0
- package/dist/components/interactive/Toggle.svelte +287 -16
- package/dist/components/interactive/Toggle.svelte.d.ts +12 -0
- package/dist/components/interactive/index.d.ts +4 -0
- package/dist/components/interactive/index.js +3 -0
- package/dist/components/list/List.svelte +41 -17
- package/dist/components/list/List.svelte.d.ts +1 -0
- package/dist/components/list/ListRow.svelte +208 -47
- package/dist/components/list/ListRow.svelte.d.ts +16 -1
- package/dist/components/menu/Menu.svelte +51 -27
- package/dist/components/menu/Menu.svelte.d.ts +5 -0
- package/dist/components/menu/MenuItem.svelte +82 -25
- package/dist/components/menu/MenuItem.svelte.d.ts +8 -0
- package/dist/components/menu/MenuSection.svelte +95 -0
- package/dist/components/menu/MenuSection.svelte.d.ts +18 -0
- package/dist/components/menu/MenuSubmenu.svelte +196 -0
- package/dist/components/menu/MenuSubmenu.svelte.d.ts +11 -0
- package/dist/components/menu/index.d.ts +4 -1
- package/dist/components/menu/index.js +3 -1
- package/dist/components/navigation/NavigationBar.svelte +97 -15
- package/dist/components/navigation/NavigationBar.svelte.d.ts +6 -0
- package/dist/components/toolbar/Toolbar.svelte +43 -0
- package/dist/components/toolbar/Toolbar.svelte.d.ts +13 -0
- package/dist/components/toolbar/ToolbarItemGroup.svelte +45 -0
- package/dist/components/toolbar/ToolbarItemGroup.svelte.d.ts +14 -0
- package/dist/components/toolbar/ToolbarSpacer.svelte +36 -0
- package/dist/components/toolbar/ToolbarSpacer.svelte.d.ts +12 -0
- package/dist/components/toolbar/index.d.ts +7 -0
- package/dist/components/toolbar/index.js +7 -0
- package/dist/components/typography/Text.svelte +9 -1
- package/dist/constants/alertAction.d.ts +19 -0
- package/dist/constants/alertAction.js +1 -0
- package/dist/constants/badge.d.ts +32 -0
- package/dist/constants/badge.js +47 -0
- package/dist/constants/buttons.d.ts +45 -0
- package/dist/constants/buttons.js +52 -0
- package/dist/constants/colors.d.ts +9 -4
- package/dist/constants/colors.js +9 -4
- package/dist/constants/index.d.ts +3 -0
- package/dist/constants/index.js +3 -0
- package/dist/constants/progress.d.ts +56 -0
- package/dist/constants/progress.js +75 -0
- package/dist/constants/variants.d.ts +6 -2
- package/dist/constants/variants.js +2 -2
- package/dist/styles/glasslikeui.css +135 -1
- package/dist/styles/lens.css +21 -19
- package/dist/styles/squircle.css +17 -7
- package/package.json +1 -1
|
@@ -10,6 +10,12 @@
|
|
|
10
10
|
* `min-width: var(--swipe-reveal)` then grows to fill exactly the revealed
|
|
11
11
|
* space, so no gap opens when the row is dragged past the action width.
|
|
12
12
|
*
|
|
13
|
+
* A row can carry actions on both edges at once, as SwiftUI allows one
|
|
14
|
+
* `.swipeActions` per edge: pass `leading` and `trailing`. The drag direction
|
|
15
|
+
* picks the edge, so dragging back past the resting point closes one side and
|
|
16
|
+
* then opens the other. Under `dir="rtl"` leading is on the right. The older
|
|
17
|
+
* single edge form (`edge` with the top level strip options) still works.
|
|
18
|
+
*
|
|
13
19
|
* Usage:
|
|
14
20
|
* <div use:swipeActions={{
|
|
15
21
|
* edge: 'trailing',
|
|
@@ -29,6 +35,15 @@ var __assign = (this && this.__assign) || function () {
|
|
|
29
35
|
};
|
|
30
36
|
return __assign.apply(this, arguments);
|
|
31
37
|
};
|
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
+
if (ar || !(i in from)) {
|
|
41
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
+
ar[i] = from[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
+
};
|
|
32
47
|
// The velocity helpers are axis-agnostic -- `y` is simply "position along the
|
|
33
48
|
// drag axis", so the x-axis gesture reuses them rather than cloning them.
|
|
34
49
|
import { computeVelocity, pushSample } from './dragSnapMath';
|
|
@@ -40,16 +55,47 @@ export var DEFAULT_SWIPE_RUBBER_BAND = 0.35;
|
|
|
40
55
|
export var DEFAULT_SWIPE_VELOCITY = 500;
|
|
41
56
|
/** px of travel before the gesture is claimed from the scroller. */
|
|
42
57
|
export var SWIPE_SLOP = 4;
|
|
43
|
-
/** Direction the content travels to reveal this edge's actions. */
|
|
44
|
-
export function edgeSign(edge) {
|
|
58
|
+
/** Direction the content travels to reveal this edge's actions: right is 1, left is -1. */
|
|
59
|
+
export function edgeSign(edge, direction) {
|
|
60
|
+
if (direction === void 0) { direction = 'ltr'; }
|
|
45
61
|
// Unknown edges fall back to trailing, matching SwiftUI's default.
|
|
46
|
-
|
|
62
|
+
var ltr = edge === 'leading' ? 1 : -1;
|
|
63
|
+
return direction === 'rtl' ? -ltr : ltr;
|
|
64
|
+
}
|
|
65
|
+
/** The edge an offset reveals, or null at rest. Right of rest is leading in `ltr`. */
|
|
66
|
+
export function edgeForOffset(offset, direction) {
|
|
67
|
+
if (direction === void 0) { direction = 'ltr'; }
|
|
68
|
+
if (!(offset > 0) && !(offset < 0))
|
|
69
|
+
return null;
|
|
70
|
+
return Math.sign(offset) === edgeSign('leading', direction) ? 'leading' : 'trailing';
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The edge-most action of a strip, which SwiftUI lists first and a full swipe
|
|
74
|
+
* triggers: the first child for leading, the last for trailing.
|
|
75
|
+
*/
|
|
76
|
+
export function edgeMostAction(strip, edge) {
|
|
77
|
+
if (!strip)
|
|
78
|
+
return null;
|
|
79
|
+
var found = edge === 'leading' ? strip.firstElementChild : strip.lastElementChild;
|
|
80
|
+
return found instanceof HTMLElement ? found : null;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The writing direction an element is laid out in: its computed CSS
|
|
84
|
+
* `direction`, which covers both `dir` and a stylesheet that sets `direction`.
|
|
85
|
+
* Where styles are not computed (some test DOMs report LTR for everything),
|
|
86
|
+
* the nearest `dir` attribute still counts. Read once per gesture, not per move.
|
|
87
|
+
*/
|
|
88
|
+
export function readDirection(el) {
|
|
89
|
+
var _a, _b;
|
|
90
|
+
if (((_a = el.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.getComputedStyle(el).direction) === 'rtl')
|
|
91
|
+
return 'rtl';
|
|
92
|
+
return String((_b = el.closest('[dir]')) === null || _b === void 0 ? void 0 : _b.getAttribute('dir')).trim().toLowerCase() === 'rtl' ? 'rtl' : 'ltr';
|
|
47
93
|
}
|
|
48
94
|
/** Constrain a raw pointer delta to the row's travel: one-to-one to the limit, damped beyond it, never past the row width, and zero against the configured edge. */
|
|
49
95
|
export function clampSwipeOffset(rawDx, geo) {
|
|
50
96
|
if (!Number.isFinite(rawDx))
|
|
51
97
|
return 0;
|
|
52
|
-
var sign = edgeSign(geo.edge);
|
|
98
|
+
var sign = edgeSign(geo.edge, geo.direction);
|
|
53
99
|
var magnitude = rawDx * sign;
|
|
54
100
|
// Negative magnitude means the drag opposes this edge.
|
|
55
101
|
if (magnitude <= 0)
|
|
@@ -75,7 +121,7 @@ export function revealedWidth(offset) {
|
|
|
75
121
|
export function resolveSwipeState(offset, velocity, geo) {
|
|
76
122
|
if (geo.actionsWidth <= 0)
|
|
77
123
|
return 'closed';
|
|
78
|
-
var sign = edgeSign(geo.edge);
|
|
124
|
+
var sign = edgeSign(geo.edge, geo.direction);
|
|
79
125
|
var magnitude = offset * sign;
|
|
80
126
|
if (magnitude <= 0)
|
|
81
127
|
return 'closed';
|
|
@@ -95,7 +141,7 @@ export function resolveSwipeState(offset, velocity, geo) {
|
|
|
95
141
|
}
|
|
96
142
|
/** The resting offset for a settled state. */
|
|
97
143
|
export function offsetForState(state, geo) {
|
|
98
|
-
var sign = edgeSign(geo.edge);
|
|
144
|
+
var sign = edgeSign(geo.edge, geo.direction);
|
|
99
145
|
if (state === 'open')
|
|
100
146
|
return geo.actionsWidth * sign;
|
|
101
147
|
if (state === 'fullSwipe')
|
|
@@ -116,54 +162,111 @@ function measureWidth(el) {
|
|
|
116
162
|
el.style.minWidth = previous;
|
|
117
163
|
return width;
|
|
118
164
|
}
|
|
165
|
+
var STATE_PROPERTIES = ['--swipe-x', '--swipe-reveal', '--swipe-reveal-leading', '--swipe-reveal-trailing'];
|
|
119
166
|
function clearState(el) {
|
|
120
|
-
|
|
121
|
-
|
|
167
|
+
for (var _i = 0, STATE_PROPERTIES_1 = STATE_PROPERTIES; _i < STATE_PROPERTIES_1.length; _i++) {
|
|
168
|
+
var property = STATE_PROPERTIES_1[_i];
|
|
169
|
+
el.style.removeProperty(property);
|
|
170
|
+
}
|
|
122
171
|
el.removeAttribute('data-swipe-state');
|
|
172
|
+
el.removeAttribute('data-swipe-direction');
|
|
173
|
+
el.removeAttribute('data-swipe-open-edge');
|
|
123
174
|
el.removeAttribute('data-swipe-dragging');
|
|
124
175
|
}
|
|
176
|
+
/** Close functions of the rows that are open now, so opening one closes the rest. */
|
|
177
|
+
var openRows = new Set();
|
|
178
|
+
var EDGES = ['leading', 'trailing'];
|
|
125
179
|
export function swipeActions(node, initialOptions) {
|
|
126
180
|
var options = __assign({}, initialOptions);
|
|
127
181
|
var state = 'closed';
|
|
182
|
+
var openEdge = null;
|
|
128
183
|
var pointerId = null;
|
|
129
184
|
var startX = 0;
|
|
130
185
|
var startY = 0;
|
|
131
186
|
var claimed = false;
|
|
132
187
|
var abandoned = false;
|
|
133
188
|
var samples = [];
|
|
134
|
-
//
|
|
189
|
+
// Each strip's natural width, read once per gesture. Re-reading it on every
|
|
135
190
|
// move would let a strip that grows with the drag raise its own limit.
|
|
136
|
-
var
|
|
137
|
-
function
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
191
|
+
var naturalWidths = new Map();
|
|
192
|
+
var unwatchStrips = function () { };
|
|
193
|
+
/** The actions on an edge, from the two edge form or the single edge one. */
|
|
194
|
+
function edgeActions(edge) {
|
|
195
|
+
var _a;
|
|
196
|
+
if (usesEdgeForm())
|
|
197
|
+
return options[edge];
|
|
198
|
+
if (edge !== ((_a = options.edge) !== null && _a !== void 0 ? _a : 'trailing'))
|
|
199
|
+
return undefined;
|
|
200
|
+
return {
|
|
201
|
+
actionsWidth: options.actionsWidth,
|
|
202
|
+
actionsElement: options.actionsElement,
|
|
203
|
+
allowsFullSwipe: options.allowsFullSwipe,
|
|
204
|
+
onFullSwipe: options.onFullSwipe
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function actionsWidth(edge) {
|
|
208
|
+
var actions = edgeActions(edge);
|
|
209
|
+
if (!actions)
|
|
210
|
+
return 0;
|
|
211
|
+
if (actions.actionsWidth !== undefined)
|
|
212
|
+
return actions.actionsWidth;
|
|
213
|
+
var remembered = naturalWidths.get(edge);
|
|
214
|
+
if (remembered !== undefined)
|
|
215
|
+
return remembered;
|
|
216
|
+
var measured = measureWidth(actions.actionsElement);
|
|
217
|
+
// 0 means "not laid out yet": do not remember it.
|
|
218
|
+
if (measured > 0)
|
|
219
|
+
naturalWidths.set(edge, measured);
|
|
220
|
+
return measured;
|
|
221
|
+
}
|
|
222
|
+
// Read once per gesture: computed style is too slow to read on every move.
|
|
223
|
+
var currentDirection = 'ltr';
|
|
224
|
+
// The direction is published too, so the strips' clips can follow a
|
|
225
|
+
// direction set from CSS, which no selector can see.
|
|
226
|
+
function refreshDirection() {
|
|
227
|
+
var _a;
|
|
228
|
+
currentDirection = (_a = options.direction) !== null && _a !== void 0 ? _a : readDirection(node);
|
|
229
|
+
for (var _i = 0, _b = targets(); _i < _b.length; _i++) {
|
|
230
|
+
var el = _b[_i];
|
|
231
|
+
el.setAttribute('data-swipe-direction', currentDirection);
|
|
146
232
|
}
|
|
147
|
-
return naturalWidth;
|
|
148
233
|
}
|
|
149
|
-
function
|
|
234
|
+
function direction() {
|
|
235
|
+
return currentDirection;
|
|
236
|
+
}
|
|
237
|
+
function geometry(edge) {
|
|
150
238
|
var _a, _b, _c;
|
|
151
239
|
return {
|
|
152
|
-
edge:
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
240
|
+
edge: edge,
|
|
241
|
+
direction: direction(),
|
|
242
|
+
actionsWidth: actionsWidth(edge),
|
|
243
|
+
rowWidth: (_a = options.rowWidth) !== null && _a !== void 0 ? _a : node.getBoundingClientRect().width,
|
|
244
|
+
allowsFullSwipe: (_c = (_b = edgeActions(edge)) === null || _b === void 0 ? void 0 : _b.allowsFullSwipe) !== null && _c !== void 0 ? _c : false
|
|
156
245
|
};
|
|
157
246
|
}
|
|
247
|
+
/** Where a raw offset lands: the edge it reveals and the clamped travel. */
|
|
248
|
+
function travel(raw) {
|
|
249
|
+
// An edge with no actions measures 0 wide, so it clamps to 0.
|
|
250
|
+
var edge = edgeForOffset(raw, direction());
|
|
251
|
+
return { edge: edge, offset: edge ? clampSwipeOffset(raw, geometry(edge)) : 0 };
|
|
252
|
+
}
|
|
253
|
+
function restingOffset() {
|
|
254
|
+
return openEdge ? offsetForState(state, geometry(openEdge)) : 0;
|
|
255
|
+
}
|
|
158
256
|
/** Every element the gesture reports to: the node, plus the optional ancestor. */
|
|
159
257
|
function targets() {
|
|
160
258
|
return options.stateElement ? [node, options.stateElement] : [node];
|
|
161
259
|
}
|
|
162
|
-
function applyOffset(offset) {
|
|
260
|
+
function applyOffset(offset, edge) {
|
|
261
|
+
var reveal = revealedWidth(offset);
|
|
163
262
|
for (var _i = 0, _a = targets(); _i < _a.length; _i++) {
|
|
164
263
|
var el = _a[_i];
|
|
165
264
|
el.style.setProperty('--swipe-x', "".concat(offset, "px"));
|
|
166
|
-
el.style.setProperty('--swipe-reveal', "".concat(
|
|
265
|
+
el.style.setProperty('--swipe-reveal', "".concat(reveal, "px"));
|
|
266
|
+
for (var _b = 0, EDGES_1 = EDGES; _b < EDGES_1.length; _b++) {
|
|
267
|
+
var side = EDGES_1[_b];
|
|
268
|
+
el.style.setProperty("--swipe-reveal-".concat(side), "".concat(side === edge ? reveal : 0, "px"));
|
|
269
|
+
}
|
|
167
270
|
}
|
|
168
271
|
}
|
|
169
272
|
function setDragging(on) {
|
|
@@ -175,14 +278,39 @@ export function swipeActions(node, initialOptions) {
|
|
|
175
278
|
el.removeAttribute('data-swipe-dragging');
|
|
176
279
|
}
|
|
177
280
|
}
|
|
178
|
-
function
|
|
281
|
+
function close() {
|
|
282
|
+
var _a;
|
|
283
|
+
if (state === 'closed')
|
|
284
|
+
return;
|
|
285
|
+
settle('closed', null);
|
|
286
|
+
(_a = options.onStateChange) === null || _a === void 0 ? void 0 : _a.call(options, 'closed');
|
|
287
|
+
}
|
|
288
|
+
function settle(next, edge) {
|
|
179
289
|
state = next;
|
|
290
|
+
openEdge = next === 'closed' ? null : edge;
|
|
180
291
|
setDragging(false);
|
|
181
292
|
for (var _i = 0, _a = targets(); _i < _a.length; _i++) {
|
|
182
293
|
var el = _a[_i];
|
|
183
294
|
el.setAttribute('data-swipe-state', next);
|
|
295
|
+
if (openEdge)
|
|
296
|
+
el.setAttribute('data-swipe-open-edge', openEdge);
|
|
297
|
+
else
|
|
298
|
+
el.removeAttribute('data-swipe-open-edge');
|
|
299
|
+
}
|
|
300
|
+
applyOffset(restingOffset(), openEdge);
|
|
301
|
+
if (openEdge)
|
|
302
|
+
claimOpen();
|
|
303
|
+
else
|
|
304
|
+
openRows.delete(close);
|
|
305
|
+
}
|
|
306
|
+
/** Only one row is open at a time, as in an iOS list. */
|
|
307
|
+
function claimOpen() {
|
|
308
|
+
for (var _i = 0, _a = __spreadArray([], openRows, true); _i < _a.length; _i++) {
|
|
309
|
+
var other = _a[_i];
|
|
310
|
+
if (other !== close)
|
|
311
|
+
other();
|
|
184
312
|
}
|
|
185
|
-
|
|
313
|
+
openRows.add(close);
|
|
186
314
|
}
|
|
187
315
|
function onPointerDown(event) {
|
|
188
316
|
if (options.disabled)
|
|
@@ -194,9 +322,13 @@ export function swipeActions(node, initialOptions) {
|
|
|
194
322
|
startY = event.clientY;
|
|
195
323
|
claimed = false;
|
|
196
324
|
abandoned = false;
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
325
|
+
refreshDirection();
|
|
326
|
+
// Measure the strips once, now, before the drag can stretch them.
|
|
327
|
+
naturalWidths = new Map();
|
|
328
|
+
for (var _i = 0, EDGES_2 = EDGES; _i < EDGES_2.length; _i++) {
|
|
329
|
+
var edge = EDGES_2[_i];
|
|
330
|
+
actionsWidth(edge);
|
|
331
|
+
}
|
|
200
332
|
samples = [{ y: event.clientX, t: performance.now() }];
|
|
201
333
|
}
|
|
202
334
|
function onPointerMove(event) {
|
|
@@ -214,57 +346,146 @@ export function swipeActions(node, initialOptions) {
|
|
|
214
346
|
return;
|
|
215
347
|
claimed = true;
|
|
216
348
|
setDragging(true);
|
|
349
|
+
// Keep the pointer even if it leaves the row, so the release lands here.
|
|
350
|
+
try {
|
|
351
|
+
node.setPointerCapture(event.pointerId);
|
|
352
|
+
}
|
|
353
|
+
catch (_a) {
|
|
354
|
+
// A synthetic or already released pointer cannot be captured, and
|
|
355
|
+
// some DOMs have no pointer capture at all.
|
|
356
|
+
}
|
|
357
|
+
claimOpen();
|
|
217
358
|
}
|
|
218
|
-
var
|
|
219
|
-
applyOffset(
|
|
359
|
+
var _b = travel(restingOffset() + dx), edge = _b.edge, offset = _b.offset;
|
|
360
|
+
applyOffset(offset, edge);
|
|
220
361
|
samples = pushSample(samples, { y: event.clientX, t: performance.now() });
|
|
221
362
|
if (event.cancelable)
|
|
222
363
|
event.preventDefault();
|
|
223
364
|
}
|
|
365
|
+
/**
|
|
366
|
+
* Swallows the click a browser sends after a pointer is released, so a
|
|
367
|
+
* swipe or a tap that closes the row does not also activate the row. Left
|
|
368
|
+
* in place for one task at most, in case no click follows.
|
|
369
|
+
*/
|
|
370
|
+
function swallowNextClick() {
|
|
371
|
+
var swallow = function (event) {
|
|
372
|
+
event.stopPropagation();
|
|
373
|
+
event.preventDefault();
|
|
374
|
+
};
|
|
375
|
+
node.addEventListener('click', swallow, { capture: true, once: true });
|
|
376
|
+
setTimeout(function () { return node.removeEventListener('click', swallow, { capture: true }); }, 0);
|
|
377
|
+
}
|
|
224
378
|
function onPointerUp(event) {
|
|
225
|
-
var _a, _b;
|
|
379
|
+
var _a, _b, _c;
|
|
226
380
|
if (pointerId === null || event.pointerId !== pointerId)
|
|
227
381
|
return;
|
|
228
382
|
var wasClaimed = claimed;
|
|
229
383
|
pointerId = null;
|
|
230
384
|
claimed = false;
|
|
231
|
-
if (
|
|
385
|
+
if (abandoned)
|
|
232
386
|
return;
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
387
|
+
if (!wasClaimed) {
|
|
388
|
+
// A tap on an open row closes it, as in iOS, and does nothing else.
|
|
389
|
+
if (state === 'closed')
|
|
390
|
+
return;
|
|
391
|
+
swallowNextClick();
|
|
392
|
+
close();
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
swallowNextClick();
|
|
396
|
+
var _d = travel(restingOffset() + (event.clientX - startX)), edge = _d.edge, offset = _d.offset;
|
|
397
|
+
var next = edge ? resolveSwipeState(offset, computeVelocity(samples), geometry(edge)) : 'closed';
|
|
398
|
+
settle(next, edge);
|
|
237
399
|
(_a = options.onStateChange) === null || _a === void 0 ? void 0 : _a.call(options, next);
|
|
238
|
-
if (next
|
|
239
|
-
|
|
400
|
+
if (next !== 'fullSwipe' || !edge)
|
|
401
|
+
return;
|
|
402
|
+
var keep = (_c = (_b = edgeActions(edge)) === null || _b === void 0 ? void 0 : _b.onFullSwipe) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
403
|
+
// The two edge form springs back after the action, as iOS does. The
|
|
404
|
+
// single edge form stays where it was, as it always has.
|
|
405
|
+
if (usesEdgeForm() && keep !== true)
|
|
406
|
+
close();
|
|
407
|
+
}
|
|
408
|
+
function usesEdgeForm() {
|
|
409
|
+
return !!(options.leading || options.trailing);
|
|
240
410
|
}
|
|
241
411
|
function onPointerCancel(event) {
|
|
242
412
|
if (pointerId === null || event.pointerId !== pointerId)
|
|
243
413
|
return;
|
|
244
414
|
pointerId = null;
|
|
245
415
|
claimed = false;
|
|
246
|
-
settle(state);
|
|
416
|
+
settle(state, openEdge);
|
|
417
|
+
}
|
|
418
|
+
// Focus on an action opens its edge, so a keyboard or screen reader user
|
|
419
|
+
// reaches every action, and sees it, with no swipe. Focus moving between
|
|
420
|
+
// the two strips leaves one (closing it) before it enters the other.
|
|
421
|
+
function openFromFocus(edge) {
|
|
422
|
+
var _a;
|
|
423
|
+
if (options.disabled || openEdge === edge)
|
|
424
|
+
return;
|
|
425
|
+
naturalWidths = new Map();
|
|
426
|
+
refreshDirection();
|
|
427
|
+
settle('open', edge);
|
|
428
|
+
(_a = options.onStateChange) === null || _a === void 0 ? void 0 : _a.call(options, 'open');
|
|
429
|
+
}
|
|
430
|
+
function watchStrips() {
|
|
431
|
+
unwatchStrips();
|
|
432
|
+
var stops = EDGES.flatMap(function (edge) {
|
|
433
|
+
var _a;
|
|
434
|
+
var strip = (_a = edgeActions(edge)) === null || _a === void 0 ? void 0 : _a.actionsElement;
|
|
435
|
+
if (!strip)
|
|
436
|
+
return [];
|
|
437
|
+
var onFocusIn = function () { return openFromFocus(edge); };
|
|
438
|
+
var onFocusOut = function (event) {
|
|
439
|
+
var next = event.relatedTarget;
|
|
440
|
+
if (!(next instanceof Node && strip.contains(next)))
|
|
441
|
+
close();
|
|
442
|
+
};
|
|
443
|
+
strip.addEventListener('focusin', onFocusIn);
|
|
444
|
+
strip.addEventListener('focusout', onFocusOut);
|
|
445
|
+
return [
|
|
446
|
+
function () {
|
|
447
|
+
strip.removeEventListener('focusin', onFocusIn);
|
|
448
|
+
strip.removeEventListener('focusout', onFocusOut);
|
|
449
|
+
}
|
|
450
|
+
];
|
|
451
|
+
});
|
|
452
|
+
unwatchStrips = function () {
|
|
453
|
+
for (var _i = 0, stops_1 = stops; _i < stops_1.length; _i++) {
|
|
454
|
+
var stop = stops_1[_i];
|
|
455
|
+
stop();
|
|
456
|
+
}
|
|
457
|
+
};
|
|
247
458
|
}
|
|
248
459
|
node.addEventListener('pointerdown', onPointerDown);
|
|
249
460
|
node.addEventListener('pointermove', onPointerMove);
|
|
250
461
|
node.addEventListener('pointerup', onPointerUp);
|
|
251
462
|
node.addEventListener('pointercancel', onPointerCancel);
|
|
252
|
-
|
|
463
|
+
watchStrips();
|
|
464
|
+
// Closed needs no direction: every gesture and focus reads it first.
|
|
465
|
+
settle('closed', null);
|
|
253
466
|
return {
|
|
254
467
|
update: function (newOptions) {
|
|
255
468
|
var previous = options.stateElement;
|
|
256
469
|
options = __assign({}, newOptions);
|
|
257
|
-
|
|
470
|
+
naturalWidths = new Map();
|
|
258
471
|
// A swapped-out ancestor must not keep stale state.
|
|
259
472
|
if (previous && previous !== options.stateElement)
|
|
260
473
|
clearState(previous);
|
|
261
|
-
|
|
474
|
+
watchStrips();
|
|
475
|
+
refreshDirection();
|
|
476
|
+
// An edge that lost its actions cannot stay open.
|
|
477
|
+
if (openEdge && !edgeActions(openEdge))
|
|
478
|
+
settle('closed', null);
|
|
479
|
+
else
|
|
480
|
+
settle(state, openEdge);
|
|
262
481
|
},
|
|
263
482
|
destroy: function () {
|
|
264
483
|
node.removeEventListener('pointerdown', onPointerDown);
|
|
265
484
|
node.removeEventListener('pointermove', onPointerMove);
|
|
266
485
|
node.removeEventListener('pointerup', onPointerUp);
|
|
267
486
|
node.removeEventListener('pointercancel', onPointerCancel);
|
|
487
|
+
unwatchStrips();
|
|
488
|
+
openRows.delete(close);
|
|
268
489
|
for (var _i = 0, _a = targets(); _i < _a.length; _i++) {
|
|
269
490
|
var el = _a[_i];
|
|
270
491
|
clearState(el);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When the tab bar minimises as the page scrolls (gap audit I4), as a pure step
|
|
3
|
+
* function so mutation testing reaches it. Mirrors SwiftUI's
|
|
4
|
+
* tabBarMinimizeBehavior: never, onScrollDown and onScrollUp. Internal.
|
|
5
|
+
*/
|
|
6
|
+
/** When the tab bar minimises: never, while the page scrolls down, or while it scrolls up. */
|
|
7
|
+
export type TabBarMinimizeBehavior = 'never' | 'onScrollDown' | 'onScrollUp';
|
|
8
|
+
/** How far, in CSS pixels, a scroll has to run one way before the bar changes. */
|
|
9
|
+
export declare const MINIMIZE_SCROLL_THRESHOLD = 24;
|
|
10
|
+
/** Within this many CSS pixels of the top the bar is always expanded. */
|
|
11
|
+
export declare const MINIMIZE_TOP_ZONE = 8;
|
|
12
|
+
/** Where one scroll source stands: where the current run started and the last position seen. */
|
|
13
|
+
export interface ScrollRun {
|
|
14
|
+
anchor: number;
|
|
15
|
+
last: number;
|
|
16
|
+
}
|
|
17
|
+
/** The bar state after one scroll position. */
|
|
18
|
+
export interface MinimizeStep {
|
|
19
|
+
minimized: boolean;
|
|
20
|
+
run: ScrollRun;
|
|
21
|
+
}
|
|
22
|
+
/** A fresh run at a position, for a new scroll source or after the bar was expanded by hand. */
|
|
23
|
+
export declare function scrollRunAt(y: number): ScrollRun;
|
|
24
|
+
/**
|
|
25
|
+
* The bar state after the source scrolls to `y`. A run is the distance moved
|
|
26
|
+
* in one direction since the last turn, so jitter shorter than the threshold
|
|
27
|
+
* changes nothing (hysteresis). A run down of at least the threshold minimises
|
|
28
|
+
* under onScrollDown and expands under onScrollUp; a run up does the opposite.
|
|
29
|
+
* Near the top, and always under `never`, the bar is expanded.
|
|
30
|
+
*/
|
|
31
|
+
export declare function minimizeStep(behavior: TabBarMinimizeBehavior, minimized: boolean, run: ScrollRun, y: number): MinimizeStep;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When the tab bar minimises as the page scrolls (gap audit I4), as a pure step
|
|
3
|
+
* function so mutation testing reaches it. Mirrors SwiftUI's
|
|
4
|
+
* tabBarMinimizeBehavior: never, onScrollDown and onScrollUp. Internal.
|
|
5
|
+
*/
|
|
6
|
+
/** How far, in CSS pixels, a scroll has to run one way before the bar changes. */
|
|
7
|
+
export var MINIMIZE_SCROLL_THRESHOLD = 24;
|
|
8
|
+
/** Within this many CSS pixels of the top the bar is always expanded. */
|
|
9
|
+
export var MINIMIZE_TOP_ZONE = 8;
|
|
10
|
+
/** A fresh run at a position, for a new scroll source or after the bar was expanded by hand. */
|
|
11
|
+
export function scrollRunAt(y) {
|
|
12
|
+
return { anchor: y, last: y };
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The bar state after the source scrolls to `y`. A run is the distance moved
|
|
16
|
+
* in one direction since the last turn, so jitter shorter than the threshold
|
|
17
|
+
* changes nothing (hysteresis). A run down of at least the threshold minimises
|
|
18
|
+
* under onScrollDown and expands under onScrollUp; a run up does the opposite.
|
|
19
|
+
* Near the top, and always under `never`, the bar is expanded.
|
|
20
|
+
*/
|
|
21
|
+
export function minimizeStep(behavior, minimized, run, y) {
|
|
22
|
+
if (!Number.isFinite(y))
|
|
23
|
+
return { minimized: minimized, run: run };
|
|
24
|
+
// A turn is a step against the run so far: the two moves have opposite signs.
|
|
25
|
+
var turned = (y - run.last) * (run.last - run.anchor) < 0;
|
|
26
|
+
var anchor = turned ? run.last : run.anchor;
|
|
27
|
+
var next = { anchor: anchor, last: y };
|
|
28
|
+
if (behavior === 'never' || y <= MINIMIZE_TOP_ZONE)
|
|
29
|
+
return { minimized: false, run: next };
|
|
30
|
+
var travelled = y - anchor;
|
|
31
|
+
if (travelled >= MINIMIZE_SCROLL_THRESHOLD) {
|
|
32
|
+
return { minimized: behavior === 'onScrollDown', run: next };
|
|
33
|
+
}
|
|
34
|
+
if (travelled <= -MINIMIZE_SCROLL_THRESHOLD) {
|
|
35
|
+
return { minimized: behavior === 'onScrollUp', run: next };
|
|
36
|
+
}
|
|
37
|
+
return { minimized: minimized, run: next };
|
|
38
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The keyboard and focus decisions TabView makes, as plain functions, so
|
|
3
|
+
* mutation testing reaches them (Stryker cannot instrument .svelte files). The
|
|
4
|
+
* component follows the WAI-ARIA tabs pattern with automatic activation: the
|
|
5
|
+
* arrow keys move focus and select in one step, as tapping a tab bar item
|
|
6
|
+
* does on iOS. Internal.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The index of the tab a key press moves to, or `null` when the key is not one
|
|
10
|
+
* the tab list handles. ArrowRight and ArrowLeft step to the next and previous
|
|
11
|
+
* tab, wrapping at either end, and swap under right to left text so that the
|
|
12
|
+
* key always moves the way its arrow points. Home and End go to the first and
|
|
13
|
+
* last tab.
|
|
14
|
+
*/
|
|
15
|
+
export declare function tabKeyTarget(key: string, index: number, count: number, rtl?: boolean): number | null;
|
|
16
|
+
/**
|
|
17
|
+
* The index of the tab that sits in the Tab order (roving tabindex): the
|
|
18
|
+
* selected one, or the first when no tab matches the selection, so the tab
|
|
19
|
+
* list can always be reached from the keyboard.
|
|
20
|
+
*/
|
|
21
|
+
export declare function rovingTabIndex(ids: readonly string[], activeId: string): number;
|
|
22
|
+
/** The part of a tab the grouping reads: its id and whether it is a search tab. */
|
|
23
|
+
export interface GroupedTab {
|
|
24
|
+
id: string;
|
|
25
|
+
role?: 'search' | undefined;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The tabs split into the main group and the search group, each in the order
|
|
29
|
+
* given. Search tabs sit apart at the trailing end of the bar, as on iOS 26, so
|
|
30
|
+
* they come last in the Tab and arrow key order too.
|
|
31
|
+
*/
|
|
32
|
+
export declare function tabGroups<T extends GroupedTab>(tabs: readonly T[]): {
|
|
33
|
+
main: T[];
|
|
34
|
+
search: T[];
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The main tab a minimised bar keeps showing: the selected one, or the first
|
|
38
|
+
* main tab when a search tab (or nothing) is selected. `null` when there are no
|
|
39
|
+
* main tabs.
|
|
40
|
+
*/
|
|
41
|
+
export declare function collapsedTabId(mainIds: readonly string[], activeId: string): string | null;
|
|
42
|
+
/**
|
|
43
|
+
* Whether the tab bar needs the dock layout: a search tab, a bottom accessory
|
|
44
|
+
* or a minimise behaviour. Without any of them the bar renders exactly as it
|
|
45
|
+
* did before these features, one glass capsule.
|
|
46
|
+
*/
|
|
47
|
+
export declare function needsTabDock(hasSearch: boolean, hasAccessory: boolean, minimizes: boolean): boolean;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The keyboard and focus decisions TabView makes, as plain functions, so
|
|
3
|
+
* mutation testing reaches them (Stryker cannot instrument .svelte files). The
|
|
4
|
+
* component follows the WAI-ARIA tabs pattern with automatic activation: the
|
|
5
|
+
* arrow keys move focus and select in one step, as tapping a tab bar item
|
|
6
|
+
* does on iOS. Internal.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The index of the tab a key press moves to, or `null` when the key is not one
|
|
10
|
+
* the tab list handles. ArrowRight and ArrowLeft step to the next and previous
|
|
11
|
+
* tab, wrapping at either end, and swap under right to left text so that the
|
|
12
|
+
* key always moves the way its arrow points. Home and End go to the first and
|
|
13
|
+
* last tab.
|
|
14
|
+
*/
|
|
15
|
+
export function tabKeyTarget(key, index, count, rtl) {
|
|
16
|
+
if (rtl === void 0) { rtl = false; }
|
|
17
|
+
if (count <= 0)
|
|
18
|
+
return null;
|
|
19
|
+
var forward = rtl ? 'ArrowLeft' : 'ArrowRight';
|
|
20
|
+
var backward = rtl ? 'ArrowRight' : 'ArrowLeft';
|
|
21
|
+
switch (key) {
|
|
22
|
+
case forward:
|
|
23
|
+
return (index + 1) % count;
|
|
24
|
+
case backward:
|
|
25
|
+
return (index - 1 + count) % count;
|
|
26
|
+
case 'Home':
|
|
27
|
+
return 0;
|
|
28
|
+
case 'End':
|
|
29
|
+
return count - 1;
|
|
30
|
+
default:
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The index of the tab that sits in the Tab order (roving tabindex): the
|
|
36
|
+
* selected one, or the first when no tab matches the selection, so the tab
|
|
37
|
+
* list can always be reached from the keyboard.
|
|
38
|
+
*/
|
|
39
|
+
export function rovingTabIndex(ids, activeId) {
|
|
40
|
+
return Math.max(0, ids.indexOf(activeId));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The tabs split into the main group and the search group, each in the order
|
|
44
|
+
* given. Search tabs sit apart at the trailing end of the bar, as on iOS 26, so
|
|
45
|
+
* they come last in the Tab and arrow key order too.
|
|
46
|
+
*/
|
|
47
|
+
export function tabGroups(tabs) {
|
|
48
|
+
return {
|
|
49
|
+
main: tabs.filter(function (t) { return t.role !== 'search'; }),
|
|
50
|
+
search: tabs.filter(function (t) { return t.role === 'search'; })
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The main tab a minimised bar keeps showing: the selected one, or the first
|
|
55
|
+
* main tab when a search tab (or nothing) is selected. `null` when there are no
|
|
56
|
+
* main tabs.
|
|
57
|
+
*/
|
|
58
|
+
export function collapsedTabId(mainIds, activeId) {
|
|
59
|
+
var _a;
|
|
60
|
+
if (mainIds.includes(activeId))
|
|
61
|
+
return activeId;
|
|
62
|
+
return (_a = mainIds[0]) !== null && _a !== void 0 ? _a : null;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Whether the tab bar needs the dock layout: a search tab, a bottom accessory
|
|
66
|
+
* or a minimise behaviour. Without any of them the bar renders exactly as it
|
|
67
|
+
* did before these features, one glass capsule.
|
|
68
|
+
*/
|
|
69
|
+
export function needsTabDock(hasSearch, hasAccessory, minimizes) {
|
|
70
|
+
return hasSearch || hasAccessory || minimizes;
|
|
71
|
+
}
|