@wcomp/elementum 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +282 -2
  3. package/custom-elements.json +3613 -0
  4. package/mcp/server.js +593 -0
  5. package/package.json +77 -4
  6. package/skills/elementum-break-ui/CATALOG.md +11 -0
  7. package/skills/elementum-break-ui/SKILL.md +16 -0
  8. package/skills/elementum-mobile/SKILL.md +18 -0
  9. package/skills/elementum-motion/SKILL.md +18 -0
  10. package/skills/elementum-motion/STANDARDS.md +15 -0
  11. package/skills/elementum-penpot/SKILL.md +45 -0
  12. package/skills/elementum-ui/CATALOG.md +14 -0
  13. package/skills/elementum-ui/SKILL.md +21 -0
  14. package/src/ag-ui.js +474 -0
  15. package/src/behaviors/index.js +760 -0
  16. package/src/components/el-accordion.js +201 -0
  17. package/src/components/el-alert-dialog.js +186 -0
  18. package/src/components/el-alert.js +254 -0
  19. package/src/components/el-aspect-ratio.js +73 -0
  20. package/src/components/el-autocomplete.js +775 -0
  21. package/src/components/el-avatar.js +271 -0
  22. package/src/components/el-badge.js +131 -0
  23. package/src/components/el-border-beam.js +135 -0
  24. package/src/components/el-breadcrumb.js +203 -0
  25. package/src/components/el-button.js +231 -0
  26. package/src/components/el-calendar.js +436 -0
  27. package/src/components/el-callout.js +158 -0
  28. package/src/components/el-card.js +298 -0
  29. package/src/components/el-carousel.js +308 -0
  30. package/src/components/el-chart.js +632 -0
  31. package/src/components/el-checkbox-card.js +221 -0
  32. package/src/components/el-checkbox.js +208 -0
  33. package/src/components/el-chip.js +276 -0
  34. package/src/components/el-code-block.js +230 -0
  35. package/src/components/el-collapsible.js +124 -0
  36. package/src/components/el-command.js +556 -0
  37. package/src/components/el-context-menu.js +328 -0
  38. package/src/components/el-data-list.js +210 -0
  39. package/src/components/el-datepicker.js +192 -0
  40. package/src/components/el-dialog.js +272 -0
  41. package/src/components/el-diff-viewer.js +441 -0
  42. package/src/components/el-drawer.js +782 -0
  43. package/src/components/el-dropdown.js +182 -0
  44. package/src/components/el-dropzone.js +242 -0
  45. package/src/components/el-empty-state.js +130 -0
  46. package/src/components/el-field.js +394 -0
  47. package/src/components/el-form.js +185 -0
  48. package/src/components/el-input.js +229 -0
  49. package/src/components/el-inset.js +90 -0
  50. package/src/components/el-insight-card.js +263 -0
  51. package/src/components/el-kbd.js +151 -0
  52. package/src/components/el-menubar.js +254 -0
  53. package/src/components/el-meter.js +183 -0
  54. package/src/components/el-navbar.js +294 -0
  55. package/src/components/el-navigation-menu.js +327 -0
  56. package/src/components/el-number-field.js +510 -0
  57. package/src/components/el-number-flow.js +164 -0
  58. package/src/components/el-otp-input.js +266 -0
  59. package/src/components/el-pagination.js +231 -0
  60. package/src/components/el-popover.js +288 -0
  61. package/src/components/el-preview-card.js +202 -0
  62. package/src/components/el-progress.js +179 -0
  63. package/src/components/el-prompt-input.js +383 -0
  64. package/src/components/el-radio-card.js +360 -0
  65. package/src/components/el-radio.js +257 -0
  66. package/src/components/el-rating.js +165 -0
  67. package/src/components/el-reasoning-card.js +293 -0
  68. package/src/components/el-resizable.js +324 -0
  69. package/src/components/el-router.js +305 -0
  70. package/src/components/el-scroll-area.js +150 -0
  71. package/src/components/el-segmented-control.js +282 -0
  72. package/src/components/el-select.js +220 -0
  73. package/src/components/el-separator.js +85 -0
  74. package/src/components/el-sidebar.js +386 -0
  75. package/src/components/el-skeleton.js +156 -0
  76. package/src/components/el-slider.js +351 -0
  77. package/src/components/el-sources.js +288 -0
  78. package/src/components/el-spinner.js +159 -0
  79. package/src/components/el-streaming-text.js +199 -0
  80. package/src/components/el-switch.js +221 -0
  81. package/src/components/el-table.js +397 -0
  82. package/src/components/el-tabs.js +235 -0
  83. package/src/components/el-task-list.js +230 -0
  84. package/src/components/el-textarea.js +175 -0
  85. package/src/components/el-theme-switch.js +120 -0
  86. package/src/components/el-timeline.js +254 -0
  87. package/src/components/el-toast.js +778 -0
  88. package/src/components/el-toggle.js +311 -0
  89. package/src/components/el-tool-call.js +386 -0
  90. package/src/components/el-toolbar.js +183 -0
  91. package/src/components/el-tooltip.js +172 -0
  92. package/src/components/el-tree-view.js +261 -0
  93. package/src/components/el-visually-hidden.js +32 -0
  94. package/src/elementum.js +504 -0
  95. package/src/index.d.ts +1093 -0
  96. package/src/index.js +112 -0
  97. package/src/signal.js +215 -0
  98. package/src/ssr.js +136 -0
  99. package/src/template.js +321 -0
  100. package/src/tokens.css +416 -0
  101. package/tokens/figma-tokens.json +69 -0
  102. package/tokens/penpot-tokens.json +98 -0
@@ -0,0 +1,782 @@
1
+ import { Elementum } from '../elementum.js';
2
+ import { html, css } from '../template.js';
3
+ import { signal } from '../signal.js';
4
+
5
+ /**
6
+ * <el-drawer>
7
+ * Accessible, mobile-first slide-over drawer and iOS-style bottom sheet inspired by Vaul (Emil Kowalski).
8
+ * Features:
9
+ * - Four placements: bottom (sheet), right, left, top
10
+ * - iOS-style background scaling (scale-background) with proportional drag interpolation
11
+ * - Multi-stop snap points (snap-points="0.35, 0.75, 1") with inertia velocity flicking
12
+ * - Fluid touch/pointer drag-to-dismiss with rubber-band physics damping
13
+ * - Centered drag handle bar (.drawer-handle)
14
+ * - Coordinated scrollable content locking (scrollTop === 0 check)
15
+ * - Mobile virtual viewport / software keyboard adaptation
16
+ */
17
+ export class ElDrawer extends Elementum {
18
+ static observedAttributes = ['open', 'placement', 'title', 'heading', 'scale-background', 'snap-points', 'handle'];
19
+
20
+ isOpen = signal(false);
21
+ placement = signal('right'); // 'right' | 'left' | 'top' | 'bottom'
22
+ titleText = signal('');
23
+ activeSnapIndex = signal(-1);
24
+ hasHandle = signal(true);
25
+
26
+ #previousActiveElement = null;
27
+ #scaleWrapper = null;
28
+ #originalWrapperStyles = null;
29
+ #parsedSnapPoints = []; // array of pixel heights
30
+ #dragState = null;
31
+ #viewportHandler = null;
32
+ #justDragged = false;
33
+
34
+ get open() {
35
+ return this.isOpen.value;
36
+ }
37
+
38
+ set open(val) {
39
+ if (Boolean(val)) {
40
+ this.show();
41
+ } else {
42
+ this.close();
43
+ }
44
+ }
45
+
46
+ connected() {
47
+ this.isOpen.value = this.hasAttribute('open') && this.getAttribute('open') !== 'false';
48
+ this.placement.value = this.getAttribute('placement') || 'right';
49
+ this.titleText.value = this.getAttribute('heading') || this.getAttribute('title') || '';
50
+ this.hasHandle.value = this.getAttribute('handle') !== 'false';
51
+ this.setAttribute('data-state', this.isOpen.value ? 'open' : 'closed');
52
+ this.setAttribute('data-side', this.placement.value);
53
+
54
+ this.#parseSnapPoints();
55
+
56
+ window.addEventListener('keydown', this.#onKeyDown);
57
+
58
+ if (typeof window !== 'undefined' && window.visualViewport) {
59
+ this.#viewportHandler = () => this.#onViewportResize();
60
+ window.visualViewport.addEventListener('resize', this.#viewportHandler);
61
+ }
62
+
63
+ if (this.isOpen.value) {
64
+ if (typeof document !== 'undefined' && document.body) {
65
+ document.body.style.overflow = 'hidden';
66
+ }
67
+ this.#applyBackgroundScale(true);
68
+ }
69
+ }
70
+
71
+ rendered() {
72
+ if (this.isOpen.value && this.placement.value === 'bottom' && this.#parsedSnapPoints.length > 0) {
73
+ const idx = this.activeSnapIndex.value >= 0 ? this.activeSnapIndex.value : 0;
74
+ this.#setSheetHeight(this.#parsedSnapPoints[idx]);
75
+ }
76
+ }
77
+
78
+ disconnected() {
79
+ window.removeEventListener('keydown', this.#onKeyDown);
80
+ if (this.#viewportHandler && typeof window !== 'undefined' && window.visualViewport) {
81
+ window.visualViewport.removeEventListener('resize', this.#viewportHandler);
82
+ }
83
+ this.#applyBackgroundScale(false);
84
+ this.#releaseBodyScroll();
85
+ }
86
+
87
+ attributeChanged(name, oldValue, newValue) {
88
+ if (name === 'open') {
89
+ const shouldOpen = newValue !== null && newValue !== 'false';
90
+ if (shouldOpen) this.show();
91
+ else this.close();
92
+ } else if (name === 'placement') {
93
+ this.placement.value = newValue || 'right';
94
+ this.setAttribute('data-side', this.placement.value);
95
+ const panel = this.root?.querySelector('.drawer-panel');
96
+ if (panel && this.placement.value !== 'bottom') {
97
+ panel.style.height = '';
98
+ panel.style.maxHeight = '';
99
+ }
100
+ } else if (name === 'title' || name === 'heading') {
101
+ this.titleText.value = newValue || this.getAttribute('heading') || this.getAttribute('title') || '';
102
+ } else if (name === 'snap-points') {
103
+ this.#parseSnapPoints();
104
+ } else if (name === 'handle') {
105
+ this.hasHandle.value = newValue !== 'false';
106
+ }
107
+ }
108
+
109
+ #parseSnapPoints() {
110
+ const attr = this.getAttribute('snap-points');
111
+ if (!attr) {
112
+ this.#parsedSnapPoints = [];
113
+ return;
114
+ }
115
+ const raw = attr.split(',').map((s) => s.trim());
116
+ const vh = typeof window !== 'undefined' ? window.innerHeight : 800;
117
+
118
+ this.#parsedSnapPoints = raw.map((val) => {
119
+ if (val.endsWith('%')) {
120
+ return (parseFloat(val) / 100) * vh;
121
+ }
122
+ if (val.endsWith('px')) {
123
+ return parseFloat(val);
124
+ }
125
+ const num = parseFloat(val);
126
+ if (num > 0 && num <= 1) {
127
+ return num * vh;
128
+ }
129
+ return num || vh;
130
+ }).sort((a, b) => a - b);
131
+
132
+ if (this.activeSnapIndex.value < 0 && this.#parsedSnapPoints.length > 0) {
133
+ this.activeSnapIndex.value = this.#parsedSnapPoints[0] >= 220
134
+ ? 0
135
+ : Math.min(1, this.#parsedSnapPoints.length - 1);
136
+ }
137
+ }
138
+
139
+ #releaseBodyScroll() {
140
+ if (typeof document === 'undefined' || !document.body) return;
141
+ const otherOpen = Array.from(document.querySelectorAll('el-drawer[data-state="open"]')).some(
142
+ (el) => el !== this && el.isConnected
143
+ );
144
+ if (!otherOpen) {
145
+ document.body.style.overflow = '';
146
+ document.body.style.transform = '';
147
+ document.body.style.borderRadius = '';
148
+ }
149
+ }
150
+
151
+ show() {
152
+ if (this.isOpen.value) return;
153
+ if (typeof document !== 'undefined' && document.activeElement) {
154
+ this.#previousActiveElement = document.activeElement;
155
+ }
156
+ this.isOpen.value = true;
157
+ this.setAttribute('data-state', 'open');
158
+ this.setAttribute('data-side', this.placement.value);
159
+
160
+ if (typeof document !== 'undefined' && document.body) {
161
+ document.body.style.overflow = 'hidden';
162
+ }
163
+ this.#applyBackgroundScale(true);
164
+ this.emit('open');
165
+
166
+ // If bottom sheet with snap points, apply initial height
167
+ if (this.placement.value === 'bottom' && this.#parsedSnapPoints.length > 0) {
168
+ const idx = this.activeSnapIndex.value >= 0 ? this.activeSnapIndex.value : 0;
169
+ this.#setSheetHeight(this.#parsedSnapPoints[idx]);
170
+ } else {
171
+ const panel = this.root?.querySelector('.drawer-panel');
172
+ if (panel) {
173
+ panel.style.height = '';
174
+ panel.style.maxHeight = '';
175
+ }
176
+ }
177
+
178
+ setTimeout(() => {
179
+ const closeBtn = this.root?.querySelector('.close-btn');
180
+ closeBtn?.focus?.();
181
+ }, 50);
182
+ }
183
+
184
+ close() {
185
+ if (!this.isOpen.value) return;
186
+ this.isOpen.value = false;
187
+ this.setAttribute('data-state', 'closed');
188
+ if (this.hasAttribute('open')) {
189
+ this.removeAttribute('open');
190
+ }
191
+
192
+ // Reset panel transform and sheet height
193
+ const panel = this.root?.querySelector('.drawer-panel');
194
+ if (panel) {
195
+ panel.style.transform = '';
196
+ }
197
+
198
+ this.#applyBackgroundScale(false);
199
+ this.#releaseBodyScroll();
200
+ this.emit('close');
201
+
202
+ if (this.#previousActiveElement && typeof this.#previousActiveElement.focus === 'function') {
203
+ try {
204
+ this.#previousActiveElement.focus();
205
+ } catch {
206
+ // Ignore if detached
207
+ }
208
+ this.#previousActiveElement = null;
209
+ }
210
+ }
211
+
212
+ #getScaleWrapper() {
213
+ if (typeof document === 'undefined') return null;
214
+ const candidate =
215
+ document.querySelector('[data-vaul-drawer-wrapper]') ||
216
+ document.querySelector('[data-drawer-wrapper]');
217
+ if (candidate && !candidate.contains(this)) {
218
+ return candidate;
219
+ }
220
+ return null;
221
+ }
222
+
223
+ #applyBackgroundScale(active, dragFraction = 0) {
224
+ if (!this.hasAttribute('scale-background')) return;
225
+ const wrapper = this.#getScaleWrapper();
226
+ if (!wrapper) return;
227
+
228
+ if (active) {
229
+ if (!this.#originalWrapperStyles) {
230
+ this.#originalWrapperStyles = {
231
+ transform: wrapper.style.transform,
232
+ borderRadius: wrapper.style.borderRadius,
233
+ transition: wrapper.style.transition,
234
+ overflow: wrapper.style.overflow
235
+ };
236
+ }
237
+
238
+ if (dragFraction > 0) {
239
+ // Continuous scale interpolation during active drag
240
+ const scaleVal = 0.96 + 0.04 * Math.min(1, dragFraction);
241
+ const yVal = 8 * (1 - Math.min(1, dragFraction));
242
+ wrapper.style.transition = 'none';
243
+ wrapper.style.transform = `scale(${scaleVal}) translateY(${yVal}px)`;
244
+ } else {
245
+ wrapper.style.transition = 'transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), border-radius 0.35s cubic-bezier(0.16, 1, 0.3, 1)';
246
+ wrapper.style.transform = 'scale(0.96) translateY(8px)';
247
+ wrapper.style.borderRadius = '16px';
248
+ wrapper.style.overflow = 'hidden';
249
+ }
250
+ } else {
251
+ if (this.#originalWrapperStyles) {
252
+ wrapper.style.transition = 'transform 0.32s cubic-bezier(0.16, 1, 0.3, 1), border-radius 0.32s ease';
253
+ wrapper.style.transform = this.#originalWrapperStyles.transform || '';
254
+ wrapper.style.borderRadius = this.#originalWrapperStyles.borderRadius || '';
255
+ wrapper.style.overflow = this.#originalWrapperStyles.overflow || '';
256
+ this.#originalWrapperStyles = null;
257
+ }
258
+ }
259
+ }
260
+
261
+ #setSheetHeight(pixels) {
262
+ const panel = this.root?.querySelector('.drawer-panel');
263
+ if (!panel) return;
264
+ panel.style.height = `${Math.round(pixels)}px`;
265
+ panel.style.maxHeight = '96vh';
266
+ }
267
+
268
+ #onKeyDown = (e) => {
269
+ if (this.isOpen.value && e.key === 'Escape') {
270
+ e.stopPropagation();
271
+ this.close();
272
+ }
273
+ };
274
+
275
+ #onBackdropClick = (e) => {
276
+ if (this.#justDragged) {
277
+ this.#justDragged = false;
278
+ return;
279
+ }
280
+ if (e.target === e.currentTarget) {
281
+ this.close();
282
+ }
283
+ };
284
+
285
+ #onViewportResize = () => {
286
+ if (!this.isOpen.value || this.placement.value !== 'bottom' || typeof window === 'undefined') return;
287
+ const panel = this.root?.querySelector('.drawer-panel');
288
+ if (!panel || !window.visualViewport) return;
289
+
290
+ const keyboardHeight = window.innerHeight - window.visualViewport.height;
291
+ if (keyboardHeight > 100) {
292
+ panel.style.bottom = `${keyboardHeight}px`;
293
+ } else {
294
+ panel.style.bottom = '0px';
295
+ }
296
+ };
297
+
298
+ // =========================================================================
299
+ // GESTURE PHYSICS: Touch & Pointer Drag / Snapping / Pull-to-Dismiss
300
+ // =========================================================================
301
+
302
+ #onPointerDown = (e) => {
303
+ if (e.target.closest('button, a, input, select, textarea')) return;
304
+ const panel = this.root?.querySelector('.drawer-panel');
305
+ if (!panel) return;
306
+
307
+ // Content scroll lock check: if dragging inside body, only allow sheet drag if scrollTop === 0
308
+ const bodyEl = this.root?.querySelector('.drawer-body');
309
+ if (bodyEl && bodyEl.contains(e.target) && bodyEl.scrollTop > 0) {
310
+ return;
311
+ }
312
+
313
+ const isHandleOrHeader = Boolean(e.target.closest?.('.drawer-handle-bar, .drawer-header'));
314
+ if (isHandleOrHeader && typeof e.preventDefault === 'function') {
315
+ e.preventDefault();
316
+ }
317
+
318
+ this.#dragState = {
319
+ startY: e.clientY,
320
+ startX: e.clientX,
321
+ lastY: e.clientY,
322
+ lastTime: Date.now(),
323
+ currentDeltaY: 0,
324
+ currentDeltaX: 0,
325
+ isDragging: false,
326
+ pointerId: e.pointerId,
327
+ initialHeight: panel.offsetHeight || 320
328
+ };
329
+
330
+ try {
331
+ if (e.pointerId !== undefined) {
332
+ panel.setPointerCapture?.(e.pointerId);
333
+ }
334
+ } catch {
335
+ // Ignore in mock DOM
336
+ }
337
+
338
+ panel.style.transition = 'none';
339
+ };
340
+
341
+ #onPointerMove = (e) => {
342
+ if (!this.#dragState) return;
343
+ const panel = this.root?.querySelector('.drawer-panel');
344
+ if (!panel) return;
345
+
346
+ const deltaY = e.clientY - this.#dragState.startY;
347
+ const deltaX = e.clientX - this.#dragState.startX;
348
+ const now = Date.now();
349
+
350
+ this.#dragState.lastY = e.clientY;
351
+ this.#dragState.lastTime = now;
352
+ this.#dragState.currentDeltaY = deltaY;
353
+ this.#dragState.currentDeltaX = deltaX;
354
+
355
+ if (!this.#dragState.isDragging && (Math.abs(deltaY) > 5 || Math.abs(deltaX) > 5)) {
356
+ this.#dragState.isDragging = true;
357
+ try {
358
+ if (e.pointerId !== undefined) {
359
+ panel.setPointerCapture?.(e.pointerId);
360
+ }
361
+ } catch {
362
+ // Ignore
363
+ }
364
+ }
365
+
366
+ if (!this.#dragState.isDragging) return;
367
+
368
+ if (this.placement.value === 'bottom') {
369
+ if (deltaY > 0) {
370
+ // Dragging down (pulling toward close)
371
+ panel.style.transform = `translate3d(0, ${deltaY}px, 0)`;
372
+ this.#applyBackgroundScale(true, deltaY / this.#dragState.initialHeight);
373
+ } else {
374
+ // Dragging up beyond bounds (Rubber-band resistance)
375
+ const resistance = Math.pow(Math.abs(deltaY), 0.72);
376
+ panel.style.transform = `translate3d(0, -${resistance}px, 0)`;
377
+ }
378
+ } else if (this.placement.value === 'top') {
379
+ if (deltaY < 0) {
380
+ // Dragging up (pulling toward close)
381
+ panel.style.transform = `translate3d(0, ${deltaY}px, 0)`;
382
+ this.#applyBackgroundScale(true, Math.abs(deltaY) / this.#dragState.initialHeight);
383
+ } else {
384
+ // Dragging down beyond bounds (Rubber-band resistance)
385
+ const resistance = Math.pow(Math.abs(deltaY), 0.72);
386
+ panel.style.transform = `translate3d(0, ${resistance}px, 0)`;
387
+ }
388
+ } else if (this.placement.value === 'right') {
389
+ if (deltaX > 0) {
390
+ panel.style.transform = `translate3d(${deltaX}px, 0, 0)`;
391
+ } else {
392
+ const resistance = Math.pow(Math.abs(deltaX), 0.72);
393
+ panel.style.transform = `translate3d(-${resistance}px, 0, 0)`;
394
+ }
395
+ } else if (this.placement.value === 'left') {
396
+ if (deltaX < 0) {
397
+ panel.style.transform = `translate3d(${deltaX}px, 0, 0)`;
398
+ } else {
399
+ const resistance = Math.pow(Math.abs(deltaX), 0.72);
400
+ panel.style.transform = `translate3d(${resistance}px, 0, 0)`;
401
+ }
402
+ }
403
+ };
404
+
405
+ #onPointerUp = (e) => {
406
+ if (!this.#dragState) return;
407
+ const panel = this.root?.querySelector('.drawer-panel');
408
+ const state = this.#dragState;
409
+ this.#dragState = null;
410
+
411
+ try {
412
+ if (e.pointerId !== undefined) {
413
+ panel?.releasePointerCapture?.(e.pointerId);
414
+ }
415
+ } catch {
416
+ // Ignore
417
+ }
418
+
419
+ if (!panel || !state.isDragging) {
420
+ if (panel) panel.style.transition = '';
421
+ return;
422
+ }
423
+
424
+ this.#justDragged = true;
425
+ setTimeout(() => {
426
+ this.#justDragged = false;
427
+ }, 80);
428
+
429
+ panel.style.transition = 'transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), height 0.35s cubic-bezier(0.16, 1, 0.3, 1)';
430
+
431
+ const deltaY = state.currentDeltaY;
432
+ const timeDelta = Math.max(1, Date.now() - state.lastTime);
433
+ const velocityY = (e.clientY - state.lastY) / timeDelta; // px/ms
434
+
435
+ if (this.placement.value === 'bottom') {
436
+ // Downward velocity flick or heavy pull -> close
437
+ if (velocityY > 0.6 || deltaY > state.initialHeight * 0.45) {
438
+ this.close();
439
+ return;
440
+ }
441
+
442
+ // Check snap points if defined
443
+ if (this.#parsedSnapPoints.length > 0) {
444
+ const currentTotalH = state.initialHeight - deltaY;
445
+ let closestIdx = 0;
446
+ let minDiff = Infinity;
447
+
448
+ this.#parsedSnapPoints.forEach((pt, idx) => {
449
+ const diff = Math.abs(pt - currentTotalH);
450
+ if (diff < minDiff) {
451
+ minDiff = diff;
452
+ closestIdx = idx;
453
+ }
454
+ });
455
+
456
+ // Upward flick promotes to next snap point
457
+ if (velocityY < -0.4 && closestIdx < this.#parsedSnapPoints.length - 1) {
458
+ closestIdx++;
459
+ }
460
+
461
+ this.activeSnapIndex.value = closestIdx;
462
+ this.#setSheetHeight(this.#parsedSnapPoints[closestIdx]);
463
+ panel.style.transform = 'translate3d(0, 0, 0)';
464
+ this.#applyBackgroundScale(true);
465
+ } else {
466
+ // Snap back to open position
467
+ panel.style.transform = 'translate3d(0, 0, 0)';
468
+ this.#applyBackgroundScale(true);
469
+ }
470
+ } else if (this.placement.value === 'top') {
471
+ // Upward velocity flick or heavy pull up -> close
472
+ if (velocityY < -0.5 || deltaY < -state.initialHeight * 0.4) {
473
+ this.close();
474
+ return;
475
+ }
476
+ panel.style.transform = 'translate3d(0, 0, 0)';
477
+ this.#applyBackgroundScale(true);
478
+ } else {
479
+ // Side drawer flick
480
+ if (Math.abs(state.currentDeltaX) > 100) {
481
+ this.close();
482
+ } else {
483
+ panel.style.transform = 'translate3d(0, 0, 0)';
484
+ }
485
+ }
486
+ };
487
+
488
+ static styles = css`
489
+ :host {
490
+ display: contents;
491
+ }
492
+
493
+ .backdrop {
494
+ position: fixed;
495
+ inset: 0;
496
+ background: rgba(15, 23, 42, 0.45);
497
+ backdrop-filter: blur(4px);
498
+ -webkit-backdrop-filter: blur(4px);
499
+ z-index: 1000;
500
+ opacity: 0;
501
+ visibility: hidden;
502
+ pointer-events: none;
503
+ transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.3s cubic-bezier(0.16, 1, 0.3, 1);
504
+ }
505
+
506
+ .backdrop.open {
507
+ opacity: 1;
508
+ visibility: visible;
509
+ pointer-events: auto;
510
+ }
511
+
512
+ .drawer-panel {
513
+ position: fixed;
514
+ background: var(--el-surface-card, #ffffff);
515
+ color: var(--el-text-primary, #0f172a);
516
+ box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.28);
517
+ display: flex;
518
+ flex-direction: column;
519
+ z-index: 1001;
520
+ visibility: hidden;
521
+ pointer-events: none;
522
+ transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.35s cubic-bezier(0.16, 1, 0.3, 1);
523
+ box-sizing: border-box;
524
+ max-width: 100vw;
525
+ max-height: 100vh;
526
+ max-height: 100dvh;
527
+ overscroll-behavior: contain;
528
+ padding-bottom: env(safe-area-inset-bottom, 0px);
529
+ touch-action: none;
530
+ user-select: none;
531
+ will-change: transform;
532
+ }
533
+
534
+ :root[data-theme="dark"] .drawer-panel {
535
+ background: var(--el-surface-elevated, #1e293b);
536
+ color: #f8fafc;
537
+ box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.65);
538
+ }
539
+
540
+ /* Placements */
541
+ .placement-right {
542
+ top: 0;
543
+ right: 0;
544
+ bottom: 0;
545
+ width: var(--el-drawer-size, 380px);
546
+ transform: translate3d(100%, 0, 0);
547
+ border-left: 1px solid var(--el-surface-border, #e2e8f0);
548
+ }
549
+
550
+ .placement-left {
551
+ top: 0;
552
+ left: 0;
553
+ bottom: 0;
554
+ width: var(--el-drawer-size, 380px);
555
+ transform: translate3d(-100%, 0, 0);
556
+ border-right: 1px solid var(--el-surface-border, #e2e8f0);
557
+ }
558
+
559
+ .placement-top {
560
+ top: 0;
561
+ left: 0;
562
+ right: 0;
563
+ height: var(--el-drawer-size, auto);
564
+ min-height: 220px;
565
+ max-height: 90vh;
566
+ transform: translate3d(0, -100%, 0);
567
+ border-bottom: 1px solid var(--el-surface-border, #e2e8f0);
568
+ border-radius: 0 0 var(--el-radius-xl, 16px) var(--el-radius-xl, 16px);
569
+ }
570
+
571
+ /* Vaul iOS Bottom Sheet */
572
+ .placement-bottom {
573
+ bottom: 0;
574
+ left: 0;
575
+ right: 0;
576
+ height: var(--el-drawer-size, auto);
577
+ min-height: 240px;
578
+ max-height: 96vh;
579
+ transform: translate3d(0, 100%, 0);
580
+ border-top: 1px solid var(--el-surface-border, #e2e8f0);
581
+ border-radius: var(--el-radius-xl, 16px) var(--el-radius-xl, 16px) 0 0;
582
+ }
583
+
584
+ :root[data-theme="dark"] .placement-bottom {
585
+ border-top-color: #334155;
586
+ }
587
+
588
+ .drawer-panel.open {
589
+ transform: translate3d(0, 0, 0);
590
+ visibility: visible;
591
+ pointer-events: auto;
592
+ }
593
+
594
+ /* Vaul Drag Handle Pill */
595
+ .drawer-handle-bar {
596
+ display: flex;
597
+ align-items: center;
598
+ justify-content: center;
599
+ padding: 10px 0 4px 0;
600
+ cursor: grab;
601
+ touch-action: none;
602
+ flex-shrink: 0;
603
+ }
604
+
605
+ .drawer-handle-bar.handle-bottom {
606
+ padding: 6px 0 10px 0;
607
+ }
608
+
609
+ .drawer-handle-pill {
610
+ width: 38px;
611
+ height: 4.5px;
612
+ border-radius: 9999px;
613
+ background: var(--el-text-muted, #94a3b8);
614
+ opacity: 0.45;
615
+ transition: opacity 0.15s ease, transform 0.15s ease;
616
+ }
617
+
618
+ .drawer-handle-bar:hover .drawer-handle-pill,
619
+ .drawer-handle-bar:active .drawer-handle-pill {
620
+ opacity: 0.8;
621
+ transform: scaleY(1.2);
622
+ }
623
+
624
+ .drawer-header {
625
+ display: flex;
626
+ align-items: center;
627
+ justify-content: space-between;
628
+ padding: var(--el-spacing-md, 14px) var(--el-spacing-lg, 24px);
629
+ border-bottom: 1px solid var(--el-surface-border, #e2e8f0);
630
+ cursor: grab;
631
+ }
632
+
633
+ :root[data-theme="dark"] .drawer-header {
634
+ border-bottom-color: #334155;
635
+ }
636
+
637
+ .drawer-title {
638
+ margin: 0;
639
+ font-size: 1.125rem;
640
+ font-weight: 700;
641
+ font-family: var(--el-font-sans, system-ui, sans-serif);
642
+ letter-spacing: -0.015em;
643
+ }
644
+
645
+ .close-btn {
646
+ background: transparent;
647
+ border: none;
648
+ font-size: 18px;
649
+ cursor: pointer;
650
+ color: var(--el-text-muted, #64748b);
651
+ width: 32px;
652
+ height: 32px;
653
+ display: flex;
654
+ align-items: center;
655
+ justify-content: center;
656
+ border-radius: var(--el-radius-md, 8px);
657
+ transition: background 0.15s ease, color 0.15s ease;
658
+ }
659
+
660
+ .close-btn:hover {
661
+ background: var(--el-surface-muted, #f1f5f9);
662
+ color: var(--el-text-primary, #0f172a);
663
+ }
664
+
665
+ :root[data-theme="dark"] .close-btn:hover {
666
+ background: #334155;
667
+ color: #f8fafc;
668
+ }
669
+
670
+ .close-btn:focus-visible {
671
+ outline: 2px solid var(--el-color-primary, #2563eb);
672
+ }
673
+
674
+ .drawer-body {
675
+ flex: 1;
676
+ overflow-y: auto;
677
+ padding: var(--el-spacing-lg, 24px);
678
+ font-family: var(--el-font-sans, system-ui, sans-serif);
679
+ touch-action: pan-y;
680
+ user-select: text;
681
+ }
682
+
683
+ .drawer-footer {
684
+ display: flex;
685
+ align-items: center;
686
+ justify-content: flex-end;
687
+ gap: var(--el-spacing-sm, 8px);
688
+ padding: var(--el-spacing-md, 14px) var(--el-spacing-lg, 24px);
689
+ border-top: 1px solid var(--el-surface-border, #e2e8f0);
690
+ background: var(--el-surface-muted, #f8fafc);
691
+ }
692
+
693
+ :root[data-theme="dark"] .drawer-footer {
694
+ background: #111827;
695
+ border-top-color: #334155;
696
+ }
697
+
698
+ @media (max-width: 640px) {
699
+ .placement-left,
700
+ .placement-right {
701
+ width: 100vw !important;
702
+ max-width: 100vw !important;
703
+ }
704
+
705
+ .drawer-header,
706
+ .drawer-body,
707
+ .drawer-footer {
708
+ padding-left: var(--el-spacing-md, 16px);
709
+ padding-right: var(--el-spacing-md, 16px);
710
+ }
711
+ }
712
+ `;
713
+
714
+ render() {
715
+ return html`
716
+ <div
717
+ class=${() => `backdrop ${this.isOpen.value ? 'open' : ''}`}
718
+ @click=${this.#onBackdropClick}
719
+ aria-hidden="true"
720
+ ></div>
721
+
722
+ <div
723
+ class=${() =>
724
+ `drawer-panel placement-${this.placement.value} ${this.isOpen.value ? 'open' : ''}`}
725
+ part="panel"
726
+ role="dialog"
727
+ aria-modal="true"
728
+ aria-labelledby="drawer-title"
729
+ @pointerdown=${this.#onPointerDown}
730
+ @pointermove=${this.#onPointerMove}
731
+ @pointerup=${this.#onPointerUp}
732
+ @pointercancel=${this.#onPointerUp}
733
+ >
734
+ ${() =>
735
+ this.hasHandle.value &&
736
+ (this.placement.value === 'bottom' ||
737
+ (this.hasAttribute('handle') && this.placement.value !== 'top'))
738
+ ? html`
739
+ <div class="drawer-handle-bar" part="handle">
740
+ <div class="drawer-handle-pill"></div>
741
+ </div>
742
+ `
743
+ : null}
744
+
745
+ <div class="drawer-header" part="header">
746
+ <h2 id="drawer-title" class="drawer-title">
747
+ <slot name="header">${() => this.titleText.value}</slot>
748
+ </h2>
749
+ <button
750
+ type="button"
751
+ class="close-btn"
752
+ aria-label="Close drawer"
753
+ @click=${() => this.close()}
754
+ >
755
+ ✕
756
+ </button>
757
+ </div>
758
+
759
+ <div class="drawer-body" part="body">
760
+ <slot></slot>
761
+ </div>
762
+
763
+ <div class="drawer-footer" part="footer">
764
+ <slot name="footer"></slot>
765
+ </div>
766
+
767
+ ${() =>
768
+ this.hasHandle.value && this.placement.value === 'top'
769
+ ? html`
770
+ <div class="drawer-handle-bar handle-bottom" part="handle">
771
+ <div class="drawer-handle-pill"></div>
772
+ </div>
773
+ `
774
+ : null}
775
+ </div>
776
+ `;
777
+ }
778
+ }
779
+
780
+ if (typeof customElements !== 'undefined' && !customElements.get('el-drawer')) {
781
+ customElements.define('el-drawer', ElDrawer);
782
+ }