@ewe-studios/foundation-wasm-ui 0.0.0-stage → 0.1.13
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 +201 -0
- package/README.md +11 -2
- package/bundle.js +15565 -0
- package/bundle.min.js +2 -0
- package/foundation_wasm/runtime/foundation-wasm.js +2449 -0
- package/index.js +3 -0
- package/package.json +12 -4
- package/ui/runtimes/foundation-ui-actions.js +698 -0
- package/ui/runtimes/foundation-ui-behaviours.js +792 -0
- package/ui/runtimes/foundation-ui-bootstrap.js +13 -0
- package/ui/runtimes/foundation-ui-connections.js +99 -0
- package/ui/runtimes/foundation-ui-frames.js +1023 -0
- package/ui/runtimes/foundation-ui-live.js +186 -0
- package/ui/runtimes/foundation-ui-recovery.js +66 -0
- package/ui/runtimes/foundation-ui-vocab.js +262 -0
- package/ui/runtimes/foundation-ui-wire.js +1 -0
- package/ui/runtimes/foundation-wasm-ui.js +2164 -0
- package/ui/runtimes/platform-scheme-interceptor.js +124 -0
- package/ui/runtimes/runtime-entry.js +4 -0
|
@@ -0,0 +1,792 @@
|
|
|
1
|
+
// Browser implementations of the component machinery in foundation_ui_components.
|
|
2
|
+
import { BehaviourId } from "./foundation-ui-wire.js";
|
|
3
|
+
|
|
4
|
+
function composite(scope){
|
|
5
|
+
var root = scope.parent();
|
|
6
|
+
if (!root || root.__composite) return; root.__composite = true;
|
|
7
|
+
var orientation = root.getAttribute('data-orientation') || 'horizontal';
|
|
8
|
+
var loop = root.getAttribute('data-loop') !== 'false';
|
|
9
|
+
function items(){
|
|
10
|
+
return Array.prototype.slice.call(root.querySelectorAll('[data-composite-item]'))
|
|
11
|
+
.filter(function(el){ return !el.hasAttribute('disabled') && el.getAttribute('aria-disabled') !== 'true'; });
|
|
12
|
+
}
|
|
13
|
+
function seed(){
|
|
14
|
+
var list = items();
|
|
15
|
+
var active = list.findIndex(function(el){ return el.hasAttribute('data-composite-active'); });
|
|
16
|
+
if (active < 0) active = 0;
|
|
17
|
+
list.forEach(function(el,i){ el.tabIndex = i === active ? 0 : -1; });
|
|
18
|
+
}
|
|
19
|
+
function move(idx){
|
|
20
|
+
var list = items();
|
|
21
|
+
if (idx < 0) idx = loop ? list.length - 1 : 0;
|
|
22
|
+
if (idx >= list.length) idx = loop ? 0 : list.length - 1;
|
|
23
|
+
list.forEach(function(el,i){ el.tabIndex = i === idx ? 0 : -1; });
|
|
24
|
+
if (list[idx]) {
|
|
25
|
+
list[idx].focus();
|
|
26
|
+
if (root.hasAttribute('data-composite-select')) list[idx].click();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
var nextKey = orientation === 'vertical' ? 'ArrowDown' : 'ArrowRight';
|
|
30
|
+
var prevKey = orientation === 'vertical' ? 'ArrowUp' : 'ArrowLeft';
|
|
31
|
+
// Typeahead (M5; port of floating-ui useTypeahead): 750ms buffer reset,
|
|
32
|
+
// locale-lowercased prefix match, same-letter cycling.
|
|
33
|
+
var buf = '', bufAt = 0, matchIdx = -1;
|
|
34
|
+
function label(el){ return (el.getAttribute('data-label') || el.textContent || '').trim().toLowerCase(); }
|
|
35
|
+
function typeahead(ch){
|
|
36
|
+
var list = items();
|
|
37
|
+
if (!list.length) return;
|
|
38
|
+
var now = Date.now();
|
|
39
|
+
if (now - bufAt > 750) { buf = ''; }
|
|
40
|
+
bufAt = now;
|
|
41
|
+
var cur = list.indexOf(document.activeElement);
|
|
42
|
+
if (buf === '') matchIdx = cur;
|
|
43
|
+
var allowRapid = list.every(function(el){ var t = label(el); return t.length < 2 || t[0] !== t[1]; });
|
|
44
|
+
if (allowRapid && buf === ch.toLowerCase()) { buf = ''; }
|
|
45
|
+
buf += ch.toLowerCase();
|
|
46
|
+
var start = (matchIdx >= 0 ? matchIdx : cur) + 1;
|
|
47
|
+
for (var k = 0; k < list.length; k++) {
|
|
48
|
+
var i = (((start + k) % list.length) + list.length) % list.length;
|
|
49
|
+
if (label(list[i]).indexOf(buf) === 0) { matchIdx = i; move(i); return; }
|
|
50
|
+
}
|
|
51
|
+
buf = '';
|
|
52
|
+
}
|
|
53
|
+
scope.addEvent(root, 'keydown', function(e){
|
|
54
|
+
var list = items();
|
|
55
|
+
var cur = list.indexOf(document.activeElement);
|
|
56
|
+
var next = null;
|
|
57
|
+
if (e.key === nextKey) next = cur + 1;
|
|
58
|
+
else if (e.key === prevKey) next = cur - 1;
|
|
59
|
+
else if (e.key === 'Home') next = 0;
|
|
60
|
+
else if (e.key === 'End') next = list.length - 1;
|
|
61
|
+
else if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) { e.preventDefault(); typeahead(e.key); return; }
|
|
62
|
+
else return;
|
|
63
|
+
if (cur < 0 && e.key !== 'Home' && e.key !== 'End') return;
|
|
64
|
+
e.preventDefault();
|
|
65
|
+
move(next);
|
|
66
|
+
});
|
|
67
|
+
seed();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function dialog(scope){
|
|
71
|
+
var dlg = scope.parent();
|
|
72
|
+
if (!dlg || dlg.__dialog || !dlg.showModal) return; dlg.__dialog = true;
|
|
73
|
+
var modal = dlg.getAttribute('data-dialog-mode') !== 'nonmodal';
|
|
74
|
+
function sync(){
|
|
75
|
+
var want = dlg.hasAttribute('data-open');
|
|
76
|
+
if (want && !dlg.open) { try { modal ? dlg.showModal() : dlg.show(); } catch (e) {} }
|
|
77
|
+
else if (!want && dlg.open) { dlg.close(); }
|
|
78
|
+
}
|
|
79
|
+
function requestClose(reason){
|
|
80
|
+
var act = dlg.querySelector('[data-dialog-close]');
|
|
81
|
+
if (act) { act.setAttribute('data-dismiss-reason', reason); act.click(); }
|
|
82
|
+
}
|
|
83
|
+
scope.addEvent(dlg, 'cancel', function(e){ e.preventDefault(); requestClose('escape-key'); });
|
|
84
|
+
// Backdrop (light) dismiss: a click landing on the dialog box itself (not its
|
|
85
|
+
// content) is the backdrop. Opt out with data-dialog-dismissable="false".
|
|
86
|
+
scope.addEvent(dlg, 'click', function(e){
|
|
87
|
+
if (e.target === dlg && dlg.getAttribute('data-dialog-dismissable') !== 'false') {
|
|
88
|
+
requestClose('outside-press');
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
sync();
|
|
92
|
+
var mo = new MutationObserver(sync);
|
|
93
|
+
scope.onDispose(() => mo.disconnect());
|
|
94
|
+
mo.observe(dlg, { attributes: true, attributeFilter: ['data-open', 'data-closed'] });
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function dismiss(scope){
|
|
98
|
+
var popup = scope.parent();
|
|
99
|
+
if (!popup || popup.__dismiss) return; popup.__dismiss = true;
|
|
100
|
+
var doc = popup.ownerDocument || document;
|
|
101
|
+
function dismiss(reason){
|
|
102
|
+
var act = popup.querySelector('[data-dismiss-action]');
|
|
103
|
+
if (!act) return;
|
|
104
|
+
act.setAttribute('data-dismiss-reason', reason);
|
|
105
|
+
act.click();
|
|
106
|
+
}
|
|
107
|
+
if (popup.getAttribute('data-dismiss-escape') !== 'false') {
|
|
108
|
+
scope.addEvent(doc, 'keydown', function(e){
|
|
109
|
+
if (e.key !== 'Escape' && e.key !== 'Esc') return;
|
|
110
|
+
e.preventDefault();
|
|
111
|
+
dismiss('escape-key');
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
if (popup.getAttribute('data-dismiss-outside') !== 'false') {
|
|
115
|
+
scope.addEvent(doc, 'pointerdown', function(e){
|
|
116
|
+
if (popup.contains(e.target)) return;
|
|
117
|
+
var anchor = popup.getAttribute('data-anchor');
|
|
118
|
+
if (anchor) {
|
|
119
|
+
var trig = doc.getElementById(anchor);
|
|
120
|
+
if (trig && trig.contains(e.target)) return;
|
|
121
|
+
}
|
|
122
|
+
dismiss('outside-press');
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function focus_trap(scope){
|
|
128
|
+
var el = scope.parent();
|
|
129
|
+
if (!el || el.__focusTrap) return; el.__focusTrap = true;
|
|
130
|
+
var doc = el.ownerDocument || document;
|
|
131
|
+
var SEL = 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])';
|
|
132
|
+
function tabbables(){
|
|
133
|
+
return Array.prototype.slice.call(el.querySelectorAll(SEL)).filter(function(n){
|
|
134
|
+
return n.offsetWidth || n.offsetHeight || n.getClientRects().length;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
var restore = null;
|
|
138
|
+
function activate(){
|
|
139
|
+
restore = doc.activeElement;
|
|
140
|
+
var init = el.getAttribute('data-initial-focus');
|
|
141
|
+
if (init === 'none') return;
|
|
142
|
+
var node = init ? el.querySelector(init) : (tabbables()[0] || el);
|
|
143
|
+
if (node && node.focus) node.focus();
|
|
144
|
+
}
|
|
145
|
+
function deactivate(){
|
|
146
|
+
var node = (restore && restore.focus) ? restore : null;
|
|
147
|
+
if (!node) {
|
|
148
|
+
var anchor = el.getAttribute('data-anchor');
|
|
149
|
+
if (anchor) { var t = doc.getElementById(anchor); if (t) node = t; }
|
|
150
|
+
}
|
|
151
|
+
if (node && node.focus) node.focus();
|
|
152
|
+
restore = null;
|
|
153
|
+
}
|
|
154
|
+
scope.addEvent(el, 'keydown', function(e){
|
|
155
|
+
if (e.key !== 'Tab') return;
|
|
156
|
+
var list = tabbables();
|
|
157
|
+
if (!list.length) { e.preventDefault(); return; }
|
|
158
|
+
var first = list[0], last = list[list.length - 1];
|
|
159
|
+
if (e.shiftKey && doc.activeElement === first) { e.preventDefault(); last.focus(); }
|
|
160
|
+
else if (!e.shiftKey && doc.activeElement === last) { e.preventDefault(); first.focus(); }
|
|
161
|
+
});
|
|
162
|
+
var isOpen = el.hasAttribute('data-open');
|
|
163
|
+
if (isOpen) activate();
|
|
164
|
+
var mo = new MutationObserver(function(){
|
|
165
|
+
var now = el.hasAttribute('data-open');
|
|
166
|
+
if (now === isOpen) return;
|
|
167
|
+
isOpen = now;
|
|
168
|
+
if (now) activate(); else deactivate();
|
|
169
|
+
});
|
|
170
|
+
scope.onDispose(() => mo.disconnect());
|
|
171
|
+
mo.observe(el, { attributes: true, attributeFilter: ['data-open', 'data-closed'] });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function slider_drag(scope){
|
|
175
|
+
var root = scope.parent();
|
|
176
|
+
if (!root || root.__slider) return; root.__slider = true;
|
|
177
|
+
var win = (root.ownerDocument && root.ownerDocument.defaultView) || window;
|
|
178
|
+
var control = root.querySelector('[data-slider-control]');
|
|
179
|
+
var input = root.querySelector('[data-slider-input]');
|
|
180
|
+
if (!control || !input) return;
|
|
181
|
+
function num(a){ var v = parseFloat(root.getAttribute(a)); return isNaN(v) ? null : v; }
|
|
182
|
+
var min = num('data-min'); if (min == null) min = 0;
|
|
183
|
+
var max = num('data-max'); if (max == null) max = 100;
|
|
184
|
+
var step = num('data-step') || 1;
|
|
185
|
+
var largeStep = num('data-large-step') || 10;
|
|
186
|
+
var vertical = root.getAttribute('data-orientation') === 'vertical';
|
|
187
|
+
var rtl = root.getAttribute('dir') === 'rtl';
|
|
188
|
+
function roundStep(v){ return Math.round((v - min) / step) * step + min; }
|
|
189
|
+
function clampV(v){ return Math.max(min, Math.min(max, v)); }
|
|
190
|
+
function fingerValue(e){
|
|
191
|
+
var rect = control.getBoundingClientRect(), pct;
|
|
192
|
+
if (vertical) pct = (rect.bottom - e.clientY) / rect.height;
|
|
193
|
+
else pct = rtl ? (rect.right - e.clientX) / rect.width : (e.clientX - rect.left) / rect.width;
|
|
194
|
+
pct = Math.max(0, Math.min(1, pct));
|
|
195
|
+
return clampV(roundStep((max - min) * pct + min));
|
|
196
|
+
}
|
|
197
|
+
function commit(v){ input.value = String(v); input.dispatchEvent(new Event('change', { bubbles: true })); }
|
|
198
|
+
var dragging = false;
|
|
199
|
+
scope.addEvent(control, 'pointerdown', function(e){
|
|
200
|
+
if (e.button) return;
|
|
201
|
+
e.preventDefault(); dragging = true;
|
|
202
|
+
root.setAttribute('data-dragging', '');
|
|
203
|
+
if (control.setPointerCapture) { try { control.setPointerCapture(e.pointerId); } catch (_) {} }
|
|
204
|
+
if (input.focus) input.focus();
|
|
205
|
+
commit(fingerValue(e));
|
|
206
|
+
});
|
|
207
|
+
scope.addEvent(win, 'pointermove', function(e){ if (dragging) commit(fingerValue(e)); });
|
|
208
|
+
scope.addEvent(win, 'pointerup', function(){ if (!dragging) return; dragging = false; root.removeAttribute('data-dragging'); });
|
|
209
|
+
scope.addEvent(input, 'keydown', function(e){
|
|
210
|
+
var cur = parseFloat(input.value); if (isNaN(cur)) cur = min;
|
|
211
|
+
if (e.key === 'PageUp') { e.preventDefault(); commit(clampV(cur + largeStep)); }
|
|
212
|
+
else if (e.key === 'PageDown') { e.preventDefault(); commit(clampV(cur - largeStep)); }
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function swipe(scope){
|
|
217
|
+
var el = scope.parent();
|
|
218
|
+
if (!el || el.__swipe) return; el.__swipe = true;
|
|
219
|
+
var win = (el.ownerDocument && el.ownerDocument.defaultView) || window;
|
|
220
|
+
var dir = el.getAttribute('data-swipe-direction') || 'down';
|
|
221
|
+
var prefix = el.getAttribute('data-swipe-prefix') || '--swipe';
|
|
222
|
+
var threshold = parseFloat(el.getAttribute('data-swipe-threshold')) || 50;
|
|
223
|
+
var horizontal = dir === 'left' || dir === 'right';
|
|
224
|
+
var sign = (dir === 'up' || dir === 'left') ? -1 : 1;
|
|
225
|
+
var startX = 0, startY = 0, swiping = false, mx = 0, my = 0;
|
|
226
|
+
function setVars(){
|
|
227
|
+
el.style.setProperty(prefix + '-movement-x', mx + 'px');
|
|
228
|
+
el.style.setProperty(prefix + '-movement-y', my + 'px');
|
|
229
|
+
var along = horizontal ? mx : my;
|
|
230
|
+
var progress = Math.max(0, Math.min(1, (along * sign) / Math.max(1, el.offsetHeight || el.offsetWidth)));
|
|
231
|
+
el.style.setProperty('--drawer-swipe-progress', String(progress));
|
|
232
|
+
}
|
|
233
|
+
function reset(){ mx = 0; my = 0; setVars(); }
|
|
234
|
+
reset();
|
|
235
|
+
scope.addEvent(el, 'pointerdown', function(e){
|
|
236
|
+
if (e.button) return;
|
|
237
|
+
swiping = true; startX = e.clientX; startY = e.clientY;
|
|
238
|
+
el.setAttribute('data-swiping', '');
|
|
239
|
+
el.setAttribute('data-swipe-direction', dir);
|
|
240
|
+
if (el.setPointerCapture) { try { el.setPointerCapture(e.pointerId); } catch (_) {} }
|
|
241
|
+
});
|
|
242
|
+
scope.addEvent(el, 'pointermove', function(e){
|
|
243
|
+
if (!swiping) return;
|
|
244
|
+
var dx = e.clientX - startX, dy = e.clientY - startY;
|
|
245
|
+
// Only allow movement in the dismiss direction.
|
|
246
|
+
mx = horizontal ? (sign > 0 ? Math.max(0, dx) : Math.min(0, dx)) : 0;
|
|
247
|
+
my = horizontal ? 0 : (sign > 0 ? Math.max(0, dy) : Math.min(0, dy));
|
|
248
|
+
setVars();
|
|
249
|
+
});
|
|
250
|
+
scope.addEvent(el, 'pointerup', function(){
|
|
251
|
+
if (!swiping) return; swiping = false;
|
|
252
|
+
el.removeAttribute('data-swiping');
|
|
253
|
+
var along = (horizontal ? mx : my) * sign;
|
|
254
|
+
if (along >= threshold) {
|
|
255
|
+
var act = el.querySelector('[data-swipe-dismiss]');
|
|
256
|
+
if (act) act.click();
|
|
257
|
+
}
|
|
258
|
+
reset();
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function snap(scope){
|
|
263
|
+
var el = scope.parent();
|
|
264
|
+
if (!el || el.__snap) return; el.__snap = true;
|
|
265
|
+
var dir = el.getAttribute('data-swipe-direction') || 'bottom';
|
|
266
|
+
function sign(){ return (dir === 'up' || dir === 'left') ? -1 : 1; }
|
|
267
|
+
var horizontal = dir === 'left' || dir === 'right';
|
|
268
|
+
var points = (el.getAttribute('data-snap-points') || '1').split(',').map(parseFloat)
|
|
269
|
+
.filter(function(n){ return !isNaN(n); }).sort(function(a, b){ return a - b; });
|
|
270
|
+
if (!points.length) points = [1];
|
|
271
|
+
var sequential = el.getAttribute('data-snap-sequential') === 'true';
|
|
272
|
+
var snapInput = el.querySelector('[data-snap-input]');
|
|
273
|
+
var full = horizontal ? el.offsetWidth : el.offsetHeight;
|
|
274
|
+
var startCoord = 0, dragging = false, curIdx = points.length - 1, base = 0;
|
|
275
|
+
function toOffset(f){ return (1 - f) * full; }
|
|
276
|
+
function setOffset(px){
|
|
277
|
+
el.style.setProperty('--drawer-offset', px + 'px');
|
|
278
|
+
el.style.setProperty('--drawer-snap-progress', String(full ? 1 - px / full : 1));
|
|
279
|
+
}
|
|
280
|
+
setOffset(toOffset(points[curIdx]));
|
|
281
|
+
scope.addEvent(el, 'pointerdown', function(e){
|
|
282
|
+
if (e.button) return;
|
|
283
|
+
dragging = true; startCoord = horizontal ? e.clientX : e.clientY;
|
|
284
|
+
base = toOffset(points[curIdx]);
|
|
285
|
+
el.setAttribute('data-swiping', '');
|
|
286
|
+
if (el.setPointerCapture) { try { el.setPointerCapture(e.pointerId); } catch (_) {} }
|
|
287
|
+
});
|
|
288
|
+
scope.addEvent(el, 'pointermove', function(e){
|
|
289
|
+
if (!dragging) return;
|
|
290
|
+
var d = (horizontal ? e.clientX : e.clientY) - startCoord;
|
|
291
|
+
var off = Math.max(0, Math.min(base + sign() * d, full));
|
|
292
|
+
setOffset(off);
|
|
293
|
+
});
|
|
294
|
+
scope.addEvent(el, 'pointerup', function(){
|
|
295
|
+
if (!dragging) return; dragging = false; el.removeAttribute('data-swiping');
|
|
296
|
+
var off = parseFloat(el.style.getPropertyValue('--drawer-offset')) || 0;
|
|
297
|
+
var frac = full ? 1 - off / full : 1;
|
|
298
|
+
if (frac < points[0] / 2) { var act = el.querySelector('[data-swipe-dismiss]'); if (act) { act.click(); return; } }
|
|
299
|
+
var best = 0, bestD = Infinity;
|
|
300
|
+
for (var i = 0; i < points.length; i++) { var dd = Math.abs(points[i] - frac); if (dd < bestD) { bestD = dd; best = i; } }
|
|
301
|
+
if (sequential) best = Math.max(curIdx - 1, Math.min(curIdx + 1, best));
|
|
302
|
+
curIdx = best;
|
|
303
|
+
setOffset(toOffset(points[curIdx]));
|
|
304
|
+
if (snapInput) { snapInput.value = String(curIdx); snapInput.dispatchEvent(new Event('change', { bubbles: true })); }
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function hover(scope){
|
|
309
|
+
var trig = scope.parent();
|
|
310
|
+
if (!trig || trig.__hover) return; trig.__hover = true;
|
|
311
|
+
var doc = trig.ownerDocument || document;
|
|
312
|
+
var win = doc.defaultView || window;
|
|
313
|
+
var root = trig.parentNode;
|
|
314
|
+
var openDelay = parseInt(trig.getAttribute('data-hover-delay'), 10) || 0;
|
|
315
|
+
var closeDelay = parseInt(trig.getAttribute('data-hover-close-delay'), 10) || 0;
|
|
316
|
+
function floating(){ return root && root.querySelector('[data-hover-popup]'); }
|
|
317
|
+
function fire(sel){ var a = root && root.querySelector(sel); if (a) a.click(); }
|
|
318
|
+
var openT = null, closeT = null, polyT = null, moveHandler = null;
|
|
319
|
+
function clearOpen(){ if (openT) { win.clearTimeout(openT); openT = null; } }
|
|
320
|
+
function clearClose(){ if (closeT) { win.clearTimeout(closeT); closeT = null; } }
|
|
321
|
+
function clearPoly(){ if (polyT) { win.clearTimeout(polyT); polyT = null; } }
|
|
322
|
+
function removeMove(){ if (moveHandler) { doc.removeEventListener('mousemove', moveHandler); moveHandler = null; } clearPoly(); }
|
|
323
|
+
scope.onDispose(() => { clearOpen(); clearClose(); removeMove(); });
|
|
324
|
+
function open(){ clearClose(); removeMove(); clearOpen(); openT = win.setTimeout(function(){ fire('[data-hover-open]'); }, openDelay); }
|
|
325
|
+
function scheduleClose(){ removeMove(); clearClose(); closeT = win.setTimeout(function(){ fire('[data-hover-close]'); }, closeDelay); }
|
|
326
|
+
|
|
327
|
+
var BUF = 0.5, SPEED = 0.1;
|
|
328
|
+
function edge(px, py, xi, yi, xj, yj){ return (yi >= py) !== (yj >= py) && px <= ((xj - xi) * (py - yi)) / (yj - yi) + xi; }
|
|
329
|
+
function inQuad(px, py, x1, y1, x2, y2, x3, y3, x4, y4){
|
|
330
|
+
var s = false;
|
|
331
|
+
if (edge(px, py, x1, y1, x2, y2)) s = !s;
|
|
332
|
+
if (edge(px, py, x2, y2, x3, y3)) s = !s;
|
|
333
|
+
if (edge(px, py, x3, y3, x4, y4)) s = !s;
|
|
334
|
+
if (edge(px, py, x4, y4, x1, y1)) s = !s;
|
|
335
|
+
return s;
|
|
336
|
+
}
|
|
337
|
+
function inRect(px, py, r){ return px >= r.left && px <= r.right && py >= r.top && py <= r.bottom; }
|
|
338
|
+
function inAA(px, py, x1, y1, x2, y2){
|
|
339
|
+
return px >= Math.min(x1, x2) && px <= Math.max(x1, x2) && py >= Math.min(y1, y2) && py <= Math.max(y1, y2);
|
|
340
|
+
}
|
|
341
|
+
function startPolygon(x, y){
|
|
342
|
+
var fl = floating();
|
|
343
|
+
if (!fl) { scheduleClose(); return; }
|
|
344
|
+
var side = fl.getAttribute('data-side') || 'bottom';
|
|
345
|
+
var landed = false, lastX = null, lastY = null, lastT = (win.performance ? win.performance.now() : Date.now());
|
|
346
|
+
function slow(nx, ny){
|
|
347
|
+
var t = (win.performance ? win.performance.now() : Date.now()), dt = t - lastT;
|
|
348
|
+
if (lastX === null || dt === 0) { lastX = nx; lastY = ny; lastT = t; return false; }
|
|
349
|
+
var dx = nx - lastX, dy = ny - lastY, d2 = dx * dx + dy * dy, th = dt * dt * SPEED * SPEED;
|
|
350
|
+
lastX = nx; lastY = ny; lastT = t;
|
|
351
|
+
return d2 < th;
|
|
352
|
+
}
|
|
353
|
+
clearClose();
|
|
354
|
+
moveHandler = function(e){
|
|
355
|
+
clearPoly();
|
|
356
|
+
var refRect = trig.getBoundingClientRect(), rect = fl.getBoundingClientRect();
|
|
357
|
+
var cx = e.clientX, cy = e.clientY, target = e.target;
|
|
358
|
+
if (fl.contains(target)) { landed = true; return; }
|
|
359
|
+
if (trig.contains(target)) { landed = true; return; }
|
|
360
|
+
var leaveRight = x > rect.right - rect.width / 2, leaveBottom = y > rect.bottom - rect.height / 2;
|
|
361
|
+
var wider = rect.width > refRect.width, taller = rect.height > refRect.height;
|
|
362
|
+
var left = (wider ? refRect : rect).left, right = (wider ? refRect : rect).right;
|
|
363
|
+
var top = (taller ? refRect : rect).top, bottom = (taller ? refRect : rect).bottom;
|
|
364
|
+
if ((side === 'top' && y >= refRect.bottom - 1) || (side === 'bottom' && y <= refRect.top + 1) ||
|
|
365
|
+
(side === 'left' && x >= refRect.right - 1) || (side === 'right' && x <= refRect.left + 1)) { scheduleClose(); return; }
|
|
366
|
+
var trough = false;
|
|
367
|
+
if (side === 'top') trough = inAA(cx, cy, left, refRect.top + 1, right, rect.bottom - 1);
|
|
368
|
+
else if (side === 'bottom') trough = inAA(cx, cy, left, rect.top + 1, right, refRect.bottom - 1);
|
|
369
|
+
else if (side === 'left') trough = inAA(cx, cy, rect.right - 1, bottom, refRect.left + 1, top);
|
|
370
|
+
else if (side === 'right') trough = inAA(cx, cy, refRect.right - 1, bottom, rect.left + 1, top);
|
|
371
|
+
if (trough) return;
|
|
372
|
+
if (landed && !inRect(cx, cy, refRect)) { scheduleClose(); return; }
|
|
373
|
+
if (slow(cx, cy)) { scheduleClose(); return; }
|
|
374
|
+
var inside = false;
|
|
375
|
+
if (side === 'top' || side === 'bottom') {
|
|
376
|
+
var off = wider ? BUF / 2 : BUF * 4;
|
|
377
|
+
var p1x = wider ? x + off : (leaveRight ? x + off : x - off);
|
|
378
|
+
var p2x = wider ? x - off : (leaveRight ? x + off : x - off);
|
|
379
|
+
var py = side === 'top' ? y + BUF + 1 : y - BUF;
|
|
380
|
+
var nearY = side === 'top' ? rect.bottom - BUF : rect.top + BUF;
|
|
381
|
+
var farY = side === 'top' ? rect.top : rect.bottom;
|
|
382
|
+
var cyL = leaveRight ? nearY : (wider ? nearY : farY);
|
|
383
|
+
var cyR = leaveRight ? (wider ? nearY : farY) : nearY;
|
|
384
|
+
inside = inQuad(cx, cy, p1x, py, p2x, py, rect.left, cyL, rect.right, cyR);
|
|
385
|
+
} else {
|
|
386
|
+
var offY = taller ? BUF / 2 : BUF * 4;
|
|
387
|
+
var p1y = taller ? y + offY : (leaveBottom ? y + offY : y - offY);
|
|
388
|
+
var p2y = taller ? y - offY : (leaveBottom ? y + offY : y - offY);
|
|
389
|
+
var px = side === 'left' ? x + BUF + 1 : x - BUF;
|
|
390
|
+
var nearX = side === 'left' ? rect.right - BUF : rect.left + BUF;
|
|
391
|
+
var farX = side === 'left' ? rect.left : rect.right;
|
|
392
|
+
var cxT = leaveBottom ? nearX : (taller ? nearX : farX);
|
|
393
|
+
var cxB = leaveBottom ? (taller ? nearX : farX) : nearX;
|
|
394
|
+
if (side === 'left') inside = inQuad(cx, cy, cxT, rect.top, cxB, rect.bottom, px, p1y, px, p2y);
|
|
395
|
+
else inside = inQuad(cx, cy, px, p1y, px, p2y, cxT, rect.top, cxB, rect.bottom);
|
|
396
|
+
}
|
|
397
|
+
if (!inside) { scheduleClose(); }
|
|
398
|
+
else if (!landed) { polyT = win.setTimeout(function(){ fire('[data-hover-close]'); }, 40); }
|
|
399
|
+
};
|
|
400
|
+
doc.addEventListener('mousemove', moveHandler);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
scope.addEvent(trig, 'pointerenter', open);
|
|
404
|
+
scope.addEvent(trig, 'pointerleave', function(e){ clearOpen(); startPolygon(e.clientX, e.clientY); });
|
|
405
|
+
scope.addEvent(trig, 'focus', function(){ clearClose(); removeMove(); clearOpen(); fire('[data-hover-open]'); });
|
|
406
|
+
scope.addEvent(trig, 'blur', function(){ scheduleClose(); });
|
|
407
|
+
var fl0 = floating();
|
|
408
|
+
if (fl0) {
|
|
409
|
+
scope.addEvent(fl0, 'pointerenter', function(){ clearClose(); removeMove(); });
|
|
410
|
+
scope.addEvent(fl0, 'pointerleave', function(e){ startPolygon(e.clientX, e.clientY); });
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function listbox(scope){
|
|
415
|
+
var pop = scope.parent();
|
|
416
|
+
if (!pop || pop.__listbox) return; pop.__listbox = true;
|
|
417
|
+
var loop = pop.getAttribute('data-loop') !== 'false';
|
|
418
|
+
var buf = '', bufAt = 0;
|
|
419
|
+
function items(){
|
|
420
|
+
return Array.prototype.slice.call(pop.querySelectorAll('[data-list-item]')).filter(function(el){
|
|
421
|
+
return !el.hasAttribute('disabled') && el.getAttribute('aria-disabled') !== 'true' && el.offsetParent !== null;
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
function current(){ var l = items(); for (var i = 0; i < l.length; i++) if (l[i].hasAttribute('data-highlighted')) return i; return -1; }
|
|
425
|
+
function setHL(idx){
|
|
426
|
+
var l = items();
|
|
427
|
+
l.forEach(function(el){ el.removeAttribute('data-highlighted'); });
|
|
428
|
+
if (idx >= 0 && idx < l.length){
|
|
429
|
+
var el = l[idx];
|
|
430
|
+
el.setAttribute('data-highlighted', '');
|
|
431
|
+
if (el.id) pop.setAttribute('aria-activedescendant', el.id);
|
|
432
|
+
if (el.scrollIntoView) el.scrollIntoView({ block: 'nearest' });
|
|
433
|
+
} else {
|
|
434
|
+
pop.removeAttribute('aria-activedescendant');
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
function move(delta){
|
|
438
|
+
var l = items(); if (!l.length) return;
|
|
439
|
+
var idx = current() + delta;
|
|
440
|
+
if (idx < 0) idx = loop ? l.length - 1 : 0;
|
|
441
|
+
if (idx >= l.length) idx = loop ? 0 : l.length - 1;
|
|
442
|
+
setHL(idx);
|
|
443
|
+
}
|
|
444
|
+
function typeahead(ch){
|
|
445
|
+
var now = Date.now();
|
|
446
|
+
if (now - bufAt > 750) buf = '';
|
|
447
|
+
bufAt = now; buf += ch.toLowerCase();
|
|
448
|
+
var l = items(); if (!l.length) return;
|
|
449
|
+
var start = (current() + 1) % l.length;
|
|
450
|
+
for (var k = 0; k < l.length; k++){
|
|
451
|
+
var i = (start + k) % l.length;
|
|
452
|
+
var label = (l[i].getAttribute('data-label') || l[i].textContent || '').trim().toLowerCase();
|
|
453
|
+
if (label.indexOf(buf) === 0){ setHL(i); return; }
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
scope.addEvent(pop, 'keydown', function(e){
|
|
457
|
+
if (e.key === 'ArrowDown'){ e.preventDefault(); move(1); }
|
|
458
|
+
else if (e.key === 'ArrowUp'){ e.preventDefault(); move(-1); }
|
|
459
|
+
else if (e.key === 'Home'){ e.preventDefault(); setHL(0); }
|
|
460
|
+
else if (e.key === 'End'){ e.preventDefault(); setHL(items().length - 1); }
|
|
461
|
+
else if (e.key === 'Enter' || e.key === ' '){ var c = current(); var l = items(); if (c >= 0){ e.preventDefault(); l[c].click(); } }
|
|
462
|
+
else if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey){ typeahead(e.key); }
|
|
463
|
+
});
|
|
464
|
+
scope.addEvent(pop, 'pointermove', function(e){
|
|
465
|
+
var item = e.target.closest ? e.target.closest('[data-list-item]') : null;
|
|
466
|
+
if (item){ var i = items().indexOf(item); if (i >= 0) setHL(i); }
|
|
467
|
+
});
|
|
468
|
+
var l = items();
|
|
469
|
+
var active = -1;
|
|
470
|
+
for (var i = 0; i < l.length; i++) if (l[i].hasAttribute('data-active-item')) { active = i; break; }
|
|
471
|
+
setHL(active);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function panel_size(scope){
|
|
475
|
+
var el = scope.parent();
|
|
476
|
+
if (!el || el.__panelSize) return; el.__panelSize = true;
|
|
477
|
+
var win = (el.ownerDocument && el.ownerDocument.defaultView) || window;
|
|
478
|
+
var prefix = el.getAttribute('data-size-var') || '--panel';
|
|
479
|
+
function measure(){
|
|
480
|
+
el.style.setProperty(prefix + '-height', el.scrollHeight + 'px');
|
|
481
|
+
el.style.setProperty(prefix + '-width', el.scrollWidth + 'px');
|
|
482
|
+
}
|
|
483
|
+
measure();
|
|
484
|
+
if (win.ResizeObserver) { var ro = new win.ResizeObserver(measure); ro.observe(el); scope.onDispose(() => ro.disconnect()); }
|
|
485
|
+
scope.addEvent(win, 'resize', measure);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function tab_indicator(scope){
|
|
489
|
+
var list = scope.parent();
|
|
490
|
+
if (!list || list.__tabIndicator) return; list.__tabIndicator = true;
|
|
491
|
+
var win = (list.ownerDocument && list.ownerDocument.defaultView) || window;
|
|
492
|
+
function measure(){
|
|
493
|
+
var tab = list.querySelector('[role="tab"][data-active]');
|
|
494
|
+
if (!tab) return;
|
|
495
|
+
var l = list.getBoundingClientRect(), t = tab.getBoundingClientRect();
|
|
496
|
+
var s = list.style;
|
|
497
|
+
s.setProperty('--active-tab-left', (t.left - l.left) + 'px');
|
|
498
|
+
s.setProperty('--active-tab-right', (l.right - t.right) + 'px');
|
|
499
|
+
s.setProperty('--active-tab-top', (t.top - l.top) + 'px');
|
|
500
|
+
s.setProperty('--active-tab-bottom', (l.bottom - t.bottom) + 'px');
|
|
501
|
+
s.setProperty('--active-tab-width', t.width + 'px');
|
|
502
|
+
s.setProperty('--active-tab-height', t.height + 'px');
|
|
503
|
+
}
|
|
504
|
+
measure();
|
|
505
|
+
var mo = new MutationObserver(measure);
|
|
506
|
+
scope.onDispose(() => mo.disconnect());
|
|
507
|
+
mo.observe(list, { attributes: true, subtree: true, attributeFilter: ['data-active'] });
|
|
508
|
+
if (win.ResizeObserver) { var ro = new win.ResizeObserver(measure); ro.observe(list); scope.onDispose(() => ro.disconnect()); }
|
|
509
|
+
scope.addEvent(win, 'resize', measure);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function position(scope){
|
|
513
|
+
var pos = scope.parent();
|
|
514
|
+
if (!pos) return;
|
|
515
|
+
var doc = pos.ownerDocument || document;
|
|
516
|
+
var win = doc.defaultView || window;
|
|
517
|
+
var anchorId = pos.getAttribute('data-anchor');
|
|
518
|
+
var prefSide = pos.getAttribute('data-prefer-side') || 'bottom';
|
|
519
|
+
var prefAlign = pos.getAttribute('data-prefer-align') || 'center';
|
|
520
|
+
var offset = parseFloat(pos.getAttribute('data-offset')) || 0;
|
|
521
|
+
var pad = parseFloat(pos.getAttribute('data-collision-padding'));
|
|
522
|
+
if (isNaN(pad)) pad = 5;
|
|
523
|
+
var sideMode = pos.getAttribute('data-collision-side') || 'flip';
|
|
524
|
+
var alignMode = pos.getAttribute('data-collision-align') || 'flip';
|
|
525
|
+
var fallbackAxis = pos.getAttribute('data-fallback-axis') || 'none';
|
|
526
|
+
var sticky = pos.getAttribute('data-sticky') === 'true';
|
|
527
|
+
var arrowPad = parseFloat(pos.getAttribute('data-arrow-padding')); if (isNaN(arrowPad)) arrowPad = 5;
|
|
528
|
+
var rtl = pos.getAttribute('dir') === 'rtl';
|
|
529
|
+
var track = pos.getAttribute('data-disable-anchor-tracking') !== 'true';
|
|
530
|
+
function opposite(s){ return {top:'bottom',bottom:'top',left:'right',right:'left'}[s]; }
|
|
531
|
+
function vertical(s){ return s === 'top' || s === 'bottom'; }
|
|
532
|
+
function anchorEl(){ return anchorId ? doc.getElementById(anchorId) : pos.previousElementSibling; }
|
|
533
|
+
function place(){
|
|
534
|
+
var anchor = anchorEl();
|
|
535
|
+
if (!anchor) return;
|
|
536
|
+
var a = anchor.getBoundingClientRect();
|
|
537
|
+
var p = pos.getBoundingClientRect();
|
|
538
|
+
var w = p.width, h = p.height;
|
|
539
|
+
var vw = doc.documentElement.clientWidth;
|
|
540
|
+
var vh = doc.documentElement.clientHeight;
|
|
541
|
+
var space = { top: a.top - pad, bottom: vh - a.bottom - pad, left: a.left - pad, right: vw - a.right - pad };
|
|
542
|
+
var side = prefSide, align = prefAlign;
|
|
543
|
+
var need = (vertical(side) ? h : w) + offset;
|
|
544
|
+
if (sideMode === 'flip' && space[side] < need && space[opposite(side)] > space[side]) side = opposite(side);
|
|
545
|
+
// fallbackAxisSide: preferred axis cannot fit either way → perpendicular axis.
|
|
546
|
+
if (fallbackAxis !== 'none' && space[side] < need && space[opposite(side)] < need) {
|
|
547
|
+
var perpNeed = (vertical(side) ? w : h) + offset;
|
|
548
|
+
var perp = vertical(side) ? ['left', 'right'] : ['top', 'bottom'];
|
|
549
|
+
if (vertical(side) && rtl) perp = ['right', 'left']; // logical start in RTL
|
|
550
|
+
if (fallbackAxis === 'end') perp = [perp[1], perp[0]]; // logical end first
|
|
551
|
+
var chosen = null;
|
|
552
|
+
for (var pi = 0; pi < perp.length; pi++) { if (space[perp[pi]] >= perpNeed) { chosen = perp[pi]; break; } }
|
|
553
|
+
if (!chosen) chosen = space[perp[0]] >= space[perp[1]] ? perp[0] : perp[1];
|
|
554
|
+
side = chosen;
|
|
555
|
+
}
|
|
556
|
+
var left, top;
|
|
557
|
+
if (side === 'top') top = a.top - h - offset;
|
|
558
|
+
else if (side === 'bottom') top = a.bottom + offset;
|
|
559
|
+
else if (side === 'left') left = a.left - w - offset;
|
|
560
|
+
else left = a.right + offset;
|
|
561
|
+
function cross(al){
|
|
562
|
+
if (vertical(side)) return al === 'start' ? a.left : al === 'end' ? a.right - w : a.left + (a.width - w) / 2;
|
|
563
|
+
return al === 'start' ? a.top : al === 'end' ? a.bottom - h : a.top + (a.height - h) / 2;
|
|
564
|
+
}
|
|
565
|
+
var lo = pad;
|
|
566
|
+
var hi = vertical(side) ? vw - w - pad : vh - h - pad;
|
|
567
|
+
var c = cross(align);
|
|
568
|
+
if (alignMode === 'flip' && (align === 'start' || align === 'end')) {
|
|
569
|
+
if (c < lo || c > hi) {
|
|
570
|
+
var alt = align === 'start' ? 'end' : 'start', c2 = cross(alt);
|
|
571
|
+
if (c2 >= lo && c2 <= hi) { align = alt; c = c2; }
|
|
572
|
+
}
|
|
573
|
+
} else if (alignMode === 'shift') {
|
|
574
|
+
if (c > hi) c = hi;
|
|
575
|
+
if (c < lo) c = lo;
|
|
576
|
+
}
|
|
577
|
+
if (vertical(side)) left = c; else top = c;
|
|
578
|
+
// sticky: keep the popup fully on-screen even as the anchor scrolls out.
|
|
579
|
+
if (sticky) {
|
|
580
|
+
left = Math.max(pad, Math.min(left, vw - w - pad));
|
|
581
|
+
top = Math.max(pad, Math.min(top, vh - h - pad));
|
|
582
|
+
}
|
|
583
|
+
var fixed = pos.getAttribute('data-position-method') === 'fixed';
|
|
584
|
+
pos.style.position = fixed ? 'fixed' : 'absolute';
|
|
585
|
+
var sx = fixed ? 0 : (win.scrollX || 0), sy = fixed ? 0 : (win.scrollY || 0);
|
|
586
|
+
pos.style.left = (left + sx) + 'px';
|
|
587
|
+
pos.style.top = (top + sy) + 'px';
|
|
588
|
+
pos.setAttribute('data-side', side);
|
|
589
|
+
pos.setAttribute('data-align', align);
|
|
590
|
+
var hidden = a.bottom < 0 || a.right < 0 || a.top > vh || a.left > vw;
|
|
591
|
+
if (hidden && !sticky) pos.setAttribute('data-anchor-hidden', '');
|
|
592
|
+
else pos.removeAttribute('data-anchor-hidden');
|
|
593
|
+
// Arrow centering: align a [data-arrow] to the anchor centre on the cross
|
|
594
|
+
// axis, clamped by arrowPadding; data-uncentered when it had to be clamped.
|
|
595
|
+
var arrow = pos.querySelector('[data-arrow]');
|
|
596
|
+
if (arrow) {
|
|
597
|
+
var as = arrow.style;
|
|
598
|
+
if (vertical(side)) {
|
|
599
|
+
var center = a.left + a.width / 2 - left;
|
|
600
|
+
var clamped = Math.max(arrowPad, Math.min(center, w - arrowPad));
|
|
601
|
+
as.setProperty('--arrow-x', clamped + 'px'); as.removeProperty('--arrow-y');
|
|
602
|
+
if (clamped !== center) arrow.setAttribute('data-uncentered', ''); else arrow.removeAttribute('data-uncentered');
|
|
603
|
+
} else {
|
|
604
|
+
var centerY = a.top + a.height / 2 - top;
|
|
605
|
+
var clampedY = Math.max(arrowPad, Math.min(centerY, h - arrowPad));
|
|
606
|
+
as.setProperty('--arrow-y', clampedY + 'px'); as.removeProperty('--arrow-x');
|
|
607
|
+
if (clampedY !== centerY) arrow.setAttribute('data-uncentered', ''); else arrow.removeAttribute('data-uncentered');
|
|
608
|
+
}
|
|
609
|
+
arrow.setAttribute('data-side', side);
|
|
610
|
+
}
|
|
611
|
+
var st = pos.style;
|
|
612
|
+
st.setProperty('--anchor-width', a.width + 'px');
|
|
613
|
+
st.setProperty('--anchor-height', a.height + 'px');
|
|
614
|
+
st.setProperty('--available-width', Math.max(0, vertical(side) ? vw - 2 * pad : space[side]) + 'px');
|
|
615
|
+
st.setProperty('--available-height', Math.max(0, vertical(side) ? space[side] : vh - 2 * pad) + 'px');
|
|
616
|
+
st.setProperty('--positioner-width', w + 'px');
|
|
617
|
+
st.setProperty('--positioner-height', h + 'px');
|
|
618
|
+
st.setProperty('--popup-width', w + 'px');
|
|
619
|
+
st.setProperty('--popup-height', h + 'px');
|
|
620
|
+
var ox = align === 'start' ? '0%' : align === 'end' ? '100%' : '50%';
|
|
621
|
+
st.setProperty('--transform-origin', vertical(side)
|
|
622
|
+
? ox + ' ' + (side === 'top' ? '100%' : '0%')
|
|
623
|
+
: (side === 'left' ? '100%' : '0%') + ' ' + ox);
|
|
624
|
+
}
|
|
625
|
+
place();
|
|
626
|
+
if (track) {
|
|
627
|
+
scope.addEvent(doc, 'scroll', place, true);
|
|
628
|
+
scope.addEvent(win, 'resize', place);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function scroll_lock(scope){
|
|
633
|
+
var el = scope.parent();
|
|
634
|
+
if (!el || el.__scrollLock) return; el.__scrollLock = true;
|
|
635
|
+
var doc = el.ownerDocument || document;
|
|
636
|
+
var win = doc.defaultView || window;
|
|
637
|
+
var html = doc.documentElement, body = doc.body;
|
|
638
|
+
function targetEl(){
|
|
639
|
+
var bs = win.getComputedStyle(body), oy = bs.overflowY;
|
|
640
|
+
return (oy === 'scroll' || oy === 'hidden' || oy === 'auto') ? body : html;
|
|
641
|
+
}
|
|
642
|
+
var saved = null;
|
|
643
|
+
function lock(){
|
|
644
|
+
if (saved) return;
|
|
645
|
+
var t = targetEl();
|
|
646
|
+
var stable = win.CSS && win.CSS.supports && win.CSS.supports('scrollbar-gutter', 'stable');
|
|
647
|
+
saved = { t: t, overflowY: t.style.overflowY, gutter: t.style.scrollbarGutter, padding: t.style.paddingRight };
|
|
648
|
+
t.style.overflowY = 'hidden';
|
|
649
|
+
if (stable) {
|
|
650
|
+
t.style.scrollbarGutter = 'stable';
|
|
651
|
+
} else {
|
|
652
|
+
var sbw = win.innerWidth - html.clientWidth;
|
|
653
|
+
if (sbw > 0) t.style.paddingRight = (parseFloat(win.getComputedStyle(t).paddingRight) + sbw) + 'px';
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
function unlock(){
|
|
657
|
+
if (!saved) return;
|
|
658
|
+
saved.t.style.overflowY = saved.overflowY;
|
|
659
|
+
saved.t.style.scrollbarGutter = saved.gutter;
|
|
660
|
+
saved.t.style.paddingRight = saved.padding;
|
|
661
|
+
saved = null;
|
|
662
|
+
}
|
|
663
|
+
scope.onDispose(unlock);
|
|
664
|
+
function sync(){ if (el.hasAttribute('data-open')) lock(); else unlock(); }
|
|
665
|
+
sync();
|
|
666
|
+
var mo = new MutationObserver(sync);
|
|
667
|
+
scope.onDispose(() => mo.disconnect());
|
|
668
|
+
mo.observe(el, { attributes: true, attributeFilter: ['data-open', 'data-closed'] });
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
function transition(scope){
|
|
672
|
+
var el = scope.parent();
|
|
673
|
+
if (!el || el.__transition) return; el.__transition = true;
|
|
674
|
+
var win = (el.ownerDocument && el.ownerDocument.defaultView) || window;
|
|
675
|
+
function twoFrames(fn){ win.requestAnimationFrame(function(){ win.requestAnimationFrame(fn); }); }
|
|
676
|
+
function onEnd(e){
|
|
677
|
+
if (e.target !== el) return;
|
|
678
|
+
el.removeEventListener('transitionend', onEnd);
|
|
679
|
+
el.removeAttribute('data-ending-style');
|
|
680
|
+
var act = el.querySelector('[data-transition-complete]');
|
|
681
|
+
if (act) act.click();
|
|
682
|
+
}
|
|
683
|
+
function enter(){
|
|
684
|
+
el.removeAttribute('data-ending-style');
|
|
685
|
+
el.removeEventListener('transitionend', onEnd);
|
|
686
|
+
if (el.hasAttribute('data-instant')) return;
|
|
687
|
+
el.setAttribute('data-starting-style', '');
|
|
688
|
+
twoFrames(function(){ el.removeAttribute('data-starting-style'); });
|
|
689
|
+
}
|
|
690
|
+
function leave(){
|
|
691
|
+
el.removeAttribute('data-starting-style');
|
|
692
|
+
if (el.hasAttribute('data-instant')) { el.removeAttribute('data-ending-style'); return; }
|
|
693
|
+
el.setAttribute('data-ending-style', '');
|
|
694
|
+
scope.addEvent(el, 'transitionend', onEnd);
|
|
695
|
+
}
|
|
696
|
+
var isOpen = el.hasAttribute('data-open');
|
|
697
|
+
if (isOpen) enter();
|
|
698
|
+
var mo = new MutationObserver(function(){
|
|
699
|
+
var now = el.hasAttribute('data-open');
|
|
700
|
+
if (now === isOpen) return;
|
|
701
|
+
isOpen = now;
|
|
702
|
+
if (now) enter(); else leave();
|
|
703
|
+
});
|
|
704
|
+
scope.onDispose(() => mo.disconnect());
|
|
705
|
+
mo.observe(el, { attributes: true, attributeFilter: ['data-open', 'data-closed'] });
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
const active = new WeakMap();
|
|
709
|
+
const custom = new Map();
|
|
710
|
+
|
|
711
|
+
function machinery(fn) {
|
|
712
|
+
return (node, args) => {
|
|
713
|
+
const removals = [];
|
|
714
|
+
const scope = {
|
|
715
|
+
parent: () => node,
|
|
716
|
+
onDispose: cleanup => removals.push(cleanup),
|
|
717
|
+
args,
|
|
718
|
+
addEvent: (target, name, callback, options) => {
|
|
719
|
+
if (typeof target === "string") target = node.querySelector(target);
|
|
720
|
+
if (!target) return;
|
|
721
|
+
target.addEventListener(name, callback, options);
|
|
722
|
+
removals.push(() => target.removeEventListener(name, callback, options));
|
|
723
|
+
},
|
|
724
|
+
};
|
|
725
|
+
fn(scope);
|
|
726
|
+
return () => { for (const remove of removals) remove(); };
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
export const SHARED = Object.freeze({
|
|
731
|
+
DIALOG: machinery(dialog), DISMISS: machinery(dismiss),
|
|
732
|
+
SCROLL_LOCK: machinery(scroll_lock), TRANSITION: machinery(transition),
|
|
733
|
+
});
|
|
734
|
+
export const WEB_ONLY = Object.freeze({
|
|
735
|
+
composite: machinery(composite), focus_trap: machinery(focus_trap),
|
|
736
|
+
gestures: machinery(scope => {
|
|
737
|
+
const mode = scope.args.find(arg => arg.name === "mode")?.value?.v;
|
|
738
|
+
({ slider: slider_drag, swipe, snap }[mode] ?? slider_drag)(scope);
|
|
739
|
+
}),
|
|
740
|
+
hover: machinery(hover), listbox: machinery(listbox),
|
|
741
|
+
measure: machinery(scope => {
|
|
742
|
+
const mode = scope.args.find(arg => arg.name === "mode")?.value?.v;
|
|
743
|
+
(mode === "tab_indicator" ? tab_indicator : panel_size)(scope);
|
|
744
|
+
}),
|
|
745
|
+
position: machinery(position),
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
export function registerWebBehaviour(name, fn) {
|
|
749
|
+
if (typeof fn !== "function") throw new TypeError("Expected a behaviour function");
|
|
750
|
+
custom.set(name, fn);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
function apply(node, name, args, run) {
|
|
754
|
+
if (!run) return false;
|
|
755
|
+
let entries = active.get(node);
|
|
756
|
+
if (!entries) active.set(node, entries = new Map());
|
|
757
|
+
if (!entries.has(name)) entries.set(name, run(node, args));
|
|
758
|
+
return true;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
export function applyBehaviour(node, id, args = []) {
|
|
762
|
+
const name = BehaviourId[id];
|
|
763
|
+
return apply(node, name, args, SHARED[name]);
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
export function applyWebBehaviour(node, name, args = []) {
|
|
767
|
+
const mode = (name === "gestures" || name === "measure")
|
|
768
|
+
? args?.find(arg => arg.name === "mode")?.value?.v : undefined;
|
|
769
|
+
const key = mode === undefined ? name : name + ":" + mode;
|
|
770
|
+
return apply(node, key, args, Object.hasOwn(WEB_ONLY, name) ? WEB_ONLY[name] : custom.get(name));
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
export function disposeBehaviours(node) {
|
|
774
|
+
const entries = active.get(node);
|
|
775
|
+
active.delete(node);
|
|
776
|
+
if (entries) for (const cleanup of entries.values()) if (typeof cleanup === "function") cleanup();
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// First-page markup uses the same parent binding as a frame.
|
|
780
|
+
export function hydrateMarkers(root) {
|
|
781
|
+
for (const marker of root.querySelectorAll?.("span[data-ewe-behaviour]") ?? []) {
|
|
782
|
+
const parent = marker.parentElement ?? marker.parentNode;
|
|
783
|
+
if (!parent) continue;
|
|
784
|
+
const name = marker.getAttribute("data-ewe-behaviour");
|
|
785
|
+
const mode = marker.getAttribute("data-ewe-mode");
|
|
786
|
+
const args = mode === null ? [] : [{name:"mode",value:{v:mode}}];
|
|
787
|
+
const shared = BehaviourId[name.toUpperCase()];
|
|
788
|
+
const applied = shared ? applyBehaviour(parent,shared,args) : applyWebBehaviour(parent,name,args);
|
|
789
|
+
if (!applied) console.error("Unknown component behaviour", name);
|
|
790
|
+
marker.remove();
|
|
791
|
+
}
|
|
792
|
+
}
|