flipfolio 0.1.0 → 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.
package/README.md CHANGED
@@ -1,14 +1,19 @@
1
1
  # flipfolio
2
2
 
3
+ [![npm](https://img.shields.io/npm/v/flipfolio)](https://www.npmjs.com/package/flipfolio)
4
+ [![minzipped size](https://img.shields.io/bundlephobia/minzip/flipfolio)](https://bundlephobia.com/package/flipfolio)
5
+ [![CI](https://github.com/kirthi-b/flipfolio/actions/workflows/ci.yml/badge.svg)](https://github.com/kirthi-b/flipfolio/actions/workflows/ci.yml)
6
+ [![license](https://img.shields.io/npm/l/flipfolio)](LICENSE)
7
+
3
8
  A gallery where every item is a folder: stack them, grid them, spin them.
4
9
 
5
10
  Started as a CSS 3D experiment; it now runs the [kirthi.studio](https://kirthi.studio) homepage. No framework, no dependencies.
6
11
 
7
- Live demo: [kirthi.studio/demos/flipfolio](https://kirthi.studio/demos/flipfolio/)
12
+ Live demo: [kirthi.studio/demos/flipfolio](https://kirthi.studio/demos/flipfolio/) · Edit it on [StackBlitz](https://stackblitz.com/github/kirthi-b/flipfolio/tree/master/examples/vanilla?file=main.js)
8
13
 
9
- > v0.1.0, an early release.
14
+ > v0.2.0. New this release: grab the active folder and throw it.
10
15
 
11
- ![flipfolio demo: stack, grid, and carousel modes](assets/demo.gif)
16
+ ![flipfolio demo: throwing folders off the stack, grid mode, and photo decals](assets/demo.gif)
12
17
 
13
18
  ## Quick start
14
19
  ```sh
@@ -86,6 +91,7 @@ Per-folder tab colors, tokens for radius and blur, and the silhouette itself is
86
91
  | `items` | `Item[]` | `[]` | `{ label?, color?, src?, content?, decal?, ...data }` |
87
92
  | `mode` | `'stack'\|'grid'\|'carousel'` | `'stack'` | 3 modes (a 4th "shelf" is planned) |
88
93
  | `peek` | `'hover'\|'always'\|'off'` | `'hover'` | contents slide out of the folder |
94
+ | `drag` | `'fling'\|'off'` | `'fling'` | grab the active folder and throw it (stack mode) |
89
95
  | `contentRenderer` | `(card, item, i) => void` | built-in | fills the folder interior with whatever you render |
90
96
  | `onSelect` | `(item, i) => void` | (none) | fired on click/Enter of the active folder (no built-in navigation) |
91
97
  | `folderPath` | `string` | manila default | SVG path `d` (viewBox `0 0 480 342`) |
@@ -40,10 +40,13 @@ var DEFAULTS = {
40
40
  // 'auto' | 'off' | 'force'
41
41
  peek: "hover",
42
42
  // 'hover' | 'always' | 'off'
43
+ drag: "fling",
44
+ // 'fling' | 'off' - grab the active folder and throw it (stack mode)
43
45
  defaultActiveIndex: 0,
44
46
  label: "Folder gallery"
45
47
  };
46
48
  var PEEK_MODES = /* @__PURE__ */ new Set(["hover", "always", "off"]);
49
+ var DRAG_MODES = /* @__PURE__ */ new Set(["fling", "off"]);
47
50
  var MODE_WIDTHS = { stack: 480, grid: 720, carousel: 720 };
48
51
  var SCROLL_THRESHOLD = 30;
49
52
  var SCROLL_COOLDOWN = { stack: 450, carousel: 300 };
@@ -104,6 +107,7 @@ function createFolderGallery(root, options = {}) {
104
107
  root.classList.add("fg-root");
105
108
  root.setAttribute("data-fg-mode", mode);
106
109
  root.setAttribute("data-fg-peek", PEEK_MODES.has(opts.peek) ? opts.peek : "hover");
110
+ root.setAttribute("data-fg-drag", DRAG_MODES.has(opts.drag) ? opts.drag : "fling");
107
111
  const scene = document.createElement("div");
108
112
  scene.className = "fg-scene";
109
113
  scene.setAttribute("role", "listbox");
@@ -124,6 +128,7 @@ function createFolderGallery(root, options = {}) {
124
128
  root.classList.remove("fg-root");
125
129
  root.removeAttribute("data-fg-mode");
126
130
  root.removeAttribute("data-fg-peek");
131
+ root.removeAttribute("data-fg-drag");
127
132
  }
128
133
  if (n === 0) {
129
134
  return { next() {
@@ -134,10 +139,12 @@ function createFolderGallery(root, options = {}) {
134
139
  }, getActiveIndex: () => -1, getMode: () => mode, destroy: teardown };
135
140
  }
136
141
  function setCardTransform(card, { x, y, z, rx, ry, s, zIndex, opacity, isActive }) {
137
- card.style.transform = `translate3d(${x}px,${y}px,${z}px) rotateX(${rx}deg) rotateY(${ry}deg) scale(${s})`;
142
+ if (!card.classList.contains("fg-card--flung")) {
143
+ card.style.transform = `translate3d(${x}px,${y}px,${z}px) rotateX(${rx}deg) rotateY(${ry}deg) scale(${s})`;
144
+ card.style.opacity = String(opacity);
145
+ }
138
146
  card.style.transformOrigin = "center bottom";
139
147
  card.style.zIndex = String(zIndex);
140
- card.style.opacity = String(opacity);
141
148
  card.setAttribute("aria-selected", isActive ? "true" : "false");
142
149
  card.classList.toggle("is-active", isActive);
143
150
  }
@@ -297,8 +304,14 @@ function createFolderGallery(root, options = {}) {
297
304
  if (!PEEK_MODES.has(p)) return;
298
305
  root.setAttribute("data-fg-peek", p);
299
306
  }
307
+ const dragEnabled = opts.drag !== "off";
308
+ let suppressClick = false;
300
309
  cardEls.forEach((card, i) => {
301
310
  on(card, "click", () => {
311
+ if (suppressClick) {
312
+ suppressClick = false;
313
+ return;
314
+ }
302
315
  i === active ? select(i) : goTo(i);
303
316
  });
304
317
  on(card, "keydown", (e) => {
@@ -378,6 +391,7 @@ function createFolderGallery(root, options = {}) {
378
391
  touchStartY = e.touches[0].clientY;
379
392
  }, { passive: true });
380
393
  on(scene, "touchend", (e) => {
394
+ if (dragEnabled && mode === "stack") return;
381
395
  const dx = touchStartX - e.changedTouches[0].clientX;
382
396
  const dy = touchStartY - e.changedTouches[0].clientY;
383
397
  const ax = Math.abs(dx);
@@ -386,6 +400,102 @@ function createFolderGallery(root, options = {}) {
386
400
  const dir = ax > ay ? dx > 0 ? 1 : -1 : dy > 0 ? 1 : -1;
387
401
  goTo(active + dir);
388
402
  }, { passive: true });
403
+ if (dragEnabled) {
404
+ const DRAG_ROT = 0.04;
405
+ const FLING_DIST = 90;
406
+ const FLING_VEL = 0.5;
407
+ const TAP_SLOP = 6;
408
+ let dragCard = null;
409
+ let dragBase = "";
410
+ let startPX = 0, startPY = 0, dragDX = 0, dragDY = 0;
411
+ let lastX = 0, lastY = 0, lastT = 0, velX = 0, velY = 0;
412
+ on(scene, "pointerdown", (e) => {
413
+ if (mode !== "stack") return;
414
+ if (e.button !== void 0 && e.button !== 0) return;
415
+ const card = e.target && e.target.closest ? e.target.closest(".fg-card") : null;
416
+ if (!card || !card.classList.contains("is-active")) return;
417
+ dragCard = card;
418
+ dragBase = card.style.transform;
419
+ startPX = e.clientX;
420
+ startPY = e.clientY;
421
+ dragDX = 0;
422
+ dragDY = 0;
423
+ lastX = e.clientX;
424
+ lastY = e.clientY;
425
+ lastT = typeof performance !== "undefined" ? performance.now() : Date.now();
426
+ velX = 0;
427
+ velY = 0;
428
+ card.classList.add("fg-card--dragging");
429
+ if (card.setPointerCapture && e.pointerId !== void 0) {
430
+ try {
431
+ card.setPointerCapture(e.pointerId);
432
+ } catch (_) {
433
+ }
434
+ }
435
+ });
436
+ on(window, "pointermove", (e) => {
437
+ if (!dragCard) return;
438
+ dragDX = e.clientX - startPX;
439
+ dragDY = e.clientY - startPY;
440
+ const now = typeof performance !== "undefined" ? performance.now() : Date.now();
441
+ const dt = Math.max(now - lastT, 1);
442
+ velX = (e.clientX - lastX) / dt;
443
+ velY = (e.clientY - lastY) / dt;
444
+ lastX = e.clientX;
445
+ lastY = e.clientY;
446
+ lastT = now;
447
+ dragCard.style.transform = `${dragBase} translate3d(${dragDX}px, ${dragDY}px, 40px) rotate(${(dragDX * DRAG_ROT).toFixed(2)}deg)`;
448
+ });
449
+ const endDrag = () => {
450
+ if (!dragCard) return;
451
+ const card = dragCard;
452
+ dragCard = null;
453
+ card.classList.remove("fg-card--dragging");
454
+ const dist = Math.hypot(dragDX, dragDY);
455
+ if (dist < TAP_SLOP) {
456
+ card.style.transform = dragBase;
457
+ return;
458
+ }
459
+ suppressClick = true;
460
+ const horizontal = Math.abs(dragDX) >= Math.abs(dragDY);
461
+ const flung = dist > FLING_DIST || Math.hypot(velX, velY) > FLING_VEL;
462
+ const dir = horizontal ? dragDX > 0 ? -1 : 1 : dragDY > 0 ? -1 : 1;
463
+ const target = active + dir;
464
+ const blocked = !opts.loop && (target < 0 || target > n - 1);
465
+ if (!flung || blocked) {
466
+ card.style.transform = dragBase;
467
+ return;
468
+ }
469
+ if (reduced) {
470
+ goTo(target);
471
+ return;
472
+ }
473
+ const offX = horizontal ? Math.sign(dragDX) * Math.max(window.innerWidth * 0.7, 480) : dragDX * 3;
474
+ const offY = horizontal ? dragDY * 3 : Math.sign(dragDY) * Math.max(window.innerHeight * 0.7, 480);
475
+ card.classList.add("fg-card--flung");
476
+ card.style.transform = `${dragBase} translate3d(${offX}px, ${offY}px, 40px) rotate(${Math.sign(dragDX || 1) * 18}deg)`;
477
+ card.style.opacity = "0";
478
+ goTo(target);
479
+ setTimeout(() => {
480
+ card.classList.add("fg-card--snap");
481
+ card.classList.remove("fg-card--flung");
482
+ applyLayout();
483
+ const slot = card.style.transform;
484
+ const slotOpacity = card.style.opacity;
485
+ card.style.transform = `${slot} translate3d(0, -90px, 0)`;
486
+ card.style.opacity = "0";
487
+ requestAnimationFrame(() => requestAnimationFrame(() => {
488
+ card.classList.remove("fg-card--snap");
489
+ card.classList.add("fg-card--entering");
490
+ card.style.transform = slot;
491
+ card.style.opacity = slotOpacity;
492
+ setTimeout(() => card.classList.remove("fg-card--entering"), 700);
493
+ }));
494
+ }, 400);
495
+ };
496
+ on(window, "pointerup", endDrag);
497
+ on(window, "pointercancel", endDrag);
498
+ }
389
499
  let resizeTimer;
390
500
  on(window, "resize", () => {
391
501
  clearTimeout(resizeTimer);
@@ -411,4 +521,4 @@ export {
411
521
  createFolderGallery,
412
522
  folder_gallery_default
413
523
  };
414
- //# sourceMappingURL=chunk-DT6YOBGV.js.map
524
+ //# sourceMappingURL=chunk-Q2NKZMCC.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/folder-gallery.js"],"sourcesContent":["/* ============================================================================\n * folder-gallery - a framework-agnostic 3D folder gallery (core, v0.1.0, WIP)\n *\n * import { createFolderGallery } from 'folder-gallery';\n * import 'folder-gallery/styles.css';\n *\n * const gallery = createFolderGallery(rootEl, {\n * items: [{ label, color, src }, ...], // or { content: Node | html }\n * mode: 'stack', // 'stack' | 'grid' | 'carousel'\n * onSelect: (item, index) => { ... },\n * });\n * gallery.next(); gallery.setMode('grid'); gallery.destroy();\n *\n * Ported from a hand-built portfolio engine. No framework, no dependencies.\n * Owns its own DOM and removes every listener on destroy().\n * ========================================================================== */\n\nconst SVG_NS = 'http://www.w3.org/2000/svg';\n\n/* Default manila-folder-with-tab silhouette (viewBox 0 0 480 342). */\nconst DEFAULT_FOLDER_PATH =\n 'M 0 22 C 0 10 10 0 22 0 L 155 0 C 168 0 172 6 176 14 C 180 24 188 32 204 32 ' +\n 'L 458 32 C 470 32 480 42 480 54 L 480 320 C 480 332 470 342 458 342 ' +\n 'L 22 342 C 10 342 0 332 0 320 Z';\n\nconst DEFAULTS = {\n mode: 'stack', // 'stack' | 'grid' | 'carousel'\n folderPath: DEFAULT_FOLDER_PATH,\n loop: true,\n scrollNav: true,\n reducedMotion: 'auto', // 'auto' | 'off' | 'force'\n peek: 'hover', // 'hover' | 'always' | 'off'\n drag: 'fling', // 'fling' | 'off' - grab the active folder and throw it (stack mode)\n defaultActiveIndex: 0,\n label: 'Folder gallery',\n};\n\nconst PEEK_MODES = new Set(['hover', 'always', 'off']);\nconst DRAG_MODES = new Set(['fling', 'off']);\n\nconst MODE_WIDTHS = { stack: 480, grid: 720, carousel: 720 };\nconst SCROLL_THRESHOLD = 30;\nconst SCROLL_COOLDOWN = { stack: 450, carousel: 300 };\n\nfunction hexToRgb(hex) {\n const h = String(hex).replace('#', '');\n return [parseInt(h.slice(0, 2), 16), parseInt(h.slice(2, 4), 16), parseInt(h.slice(4, 6), 16)];\n}\n/* Derive the folder's three surfaces from one base color (same offsets as the\n * original engine): back/tab −30, frosted front +40 at 0.55, solid front +35.\n * The solid variant is what keeps NON-active cards fully opaque - only the\n * active card gets the translucent frosted treatment. Also picks a label\n * color (white or ink) by the frontSolid surface's YIQ brightness, so a\n * dark folder color doesn't leave the label unreadable regardless of theme. */\nfunction folderColors(hex) {\n const [r, g, b] = hexToRgb(hex);\n const dn = (v) => Math.max(v - 30, 0);\n const up = (v, o) => Math.min(v + o, 255);\n const fr = up(r, 35);\n const fg = up(g, 35);\n const fb = up(b, 35);\n const yiq = (fr * 299 + fg * 587 + fb * 114) / 1000;\n return {\n back: `rgb(${dn(r)},${dn(g)},${dn(b)})`,\n front: `rgba(${up(r, 40)},${up(g, 40)},${up(b, 40)},0.55)`,\n frontSolid: `rgb(${fr},${fg},${fb})`,\n label: yiq >= 128 ? '#1c1c1a' : '#ffffff',\n };\n}\n\n/* Built-in default content renderer. Accepts item.content (a Node or HTML\n * string) or item.src (an image). Consumers pass their own contentRenderer\n * (card, item, index) to hold arbitrary content - that's the whole point. */\nfunction defaultContentRenderer(card, item /* , index */) {\n const wrap = document.createElement('div');\n wrap.className = 'fg-content';\n // Duck-type DOM nodes (nodeType) rather than `instanceof Node` - `Node`\n // isn't a global in every embedding (SSR shims, minimal DOM harnesses).\n if (item.content && typeof item.content === 'object' && typeof item.content.nodeType === 'number') {\n wrap.appendChild(item.content);\n } else if (typeof item.content === 'string') {\n wrap.innerHTML = item.content;\n } else if (item.src) {\n const img = document.createElement('img');\n img.className = 'fg-image';\n img.src = item.src;\n img.alt = item.label || '';\n img.loading = 'lazy';\n img.decoding = 'async';\n wrap.appendChild(img);\n }\n card.appendChild(wrap);\n}\n\nexport function createFolderGallery(root, options = {}) {\n if (!root || !root.nodeType) throw new Error('createFolderGallery: a root element is required');\n\n const opts = { ...DEFAULTS, ...options };\n const items = Array.isArray(opts.items) ? opts.items : [];\n const n = items.length;\n const renderContent =\n typeof opts.contentRenderer === 'function' ? opts.contentRenderer : defaultContentRenderer;\n\n const reduced =\n opts.reducedMotion === 'force' ||\n (opts.reducedMotion !== 'off' &&\n typeof matchMedia === 'function' &&\n matchMedia('(prefers-reduced-motion: reduce)').matches);\n\n let mode = MODE_WIDTHS[opts.mode] ? opts.mode : 'stack';\n let active = Math.min(Math.max(opts.defaultActiveIndex | 0, 0), Math.max(n - 1, 0));\n let scrollCooldown = false;\n let scrollAccum = 0;\n\n /* ── Listener bookkeeping for destroy() ── */\n const cleanups = [];\n const on = (el, ev, fn, o) => { el.addEventListener(ev, fn, o); cleanups.push(() => el.removeEventListener(ev, fn, o)); };\n const emit = (name, detail) => root.dispatchEvent(new CustomEvent(name, { detail, bubbles: true }));\n\n /* ── Build own DOM (no page scaffold assumed) ── */\n root.classList.add('fg-root');\n root.setAttribute('data-fg-mode', mode);\n root.setAttribute('data-fg-peek', PEEK_MODES.has(opts.peek) ? opts.peek : 'hover');\n root.setAttribute('data-fg-drag', DRAG_MODES.has(opts.drag) ? opts.drag : 'fling');\n const scene = document.createElement('div');\n scene.className = 'fg-scene';\n scene.setAttribute('role', 'listbox');\n scene.setAttribute('aria-label', opts.label);\n scene.setAttribute('aria-roledescription', 'folder gallery');\n const dotsEl = document.createElement('div');\n dotsEl.className = 'fg-dots';\n dotsEl.setAttribute('role', 'tablist');\n const live = document.createElement('div');\n live.className = 'fg-sr-only';\n live.setAttribute('aria-live', 'polite');\n live.setAttribute('aria-atomic', 'true');\n root.append(scene, dotsEl, live);\n\n function teardown() {\n cleanups.forEach((fn) => fn());\n cleanups.length = 0;\n root.replaceChildren();\n root.classList.remove('fg-root');\n root.removeAttribute('data-fg-mode');\n root.removeAttribute('data-fg-peek');\n root.removeAttribute('data-fg-drag');\n }\n\n if (n === 0) {\n return { next() {}, prev() {}, goTo() {}, setMode() {}, setPeek() {}, getActiveIndex: () => -1, getMode: () => mode, destroy: teardown };\n }\n\n /* ── Normalized transform - identical function list for every mode ── */\n function setCardTransform(card, { x, y, z, rx, ry, s, zIndex, opacity, isActive }) {\n /* A card mid-throw owns its own motion: layout updates its role\n (selection, stacking) but leaves transform and opacity to the fling,\n so the pile can shuffle immediately while the thrown folder finishes\n its flight. The fling handler relayouts it once it has faded out. */\n if (!card.classList.contains('fg-card--flung')) {\n card.style.transform = `translate3d(${x}px,${y}px,${z}px) rotateX(${rx}deg) rotateY(${ry}deg) scale(${s})`;\n card.style.opacity = String(opacity);\n }\n card.style.transformOrigin = 'center bottom';\n card.style.zIndex = String(zIndex);\n card.setAttribute('aria-selected', isActive ? 'true' : 'false');\n card.classList.toggle('is-active', isActive);\n }\n\n /* ── Build cards ── */\n const cardEls = items.map((item, i) => {\n const card = document.createElement('div');\n card.className = 'fg-card';\n card.tabIndex = i === active ? 0 : -1; // roving tabindex\n card.setAttribute('role', 'option');\n card.setAttribute('aria-label', item.label || `Item ${i + 1}`);\n if (item.color) {\n const c = folderColors(item.color);\n card.style.setProperty('--fg-folder-bg', item.color);\n card.style.setProperty('--fg-front', c.front);\n card.style.setProperty('--fg-front-solid', c.frontSolid);\n card.style.setProperty('--fg-label-on-color', c.label);\n }\n\n const svg = document.createElementNS(SVG_NS, 'svg');\n svg.setAttribute('class', 'fg-folder');\n svg.setAttribute('viewBox', '0 0 480 342');\n svg.setAttribute('preserveAspectRatio', 'none');\n svg.setAttribute('aria-hidden', 'true');\n const path = document.createElementNS(SVG_NS, 'path');\n path.setAttribute('d', opts.folderPath);\n path.setAttribute('fill', item.color ? folderColors(item.color).back : 'var(--fg-folder-bg)');\n svg.appendChild(path);\n\n card.appendChild(svg);\n\n renderContent(card, item, i);\n\n const front = document.createElement('div');\n front.className = 'fg-front';\n /* Decal: the photo prints on the folder's FRONT PANEL. The back and tab\n keep their color, so the folder stays a folder: colored tabs in the\n stack, a real material boundary at the front's lip. */\n if (item.decal) {\n card.classList.add('fg-card--decal');\n const photo = document.createElement('img');\n photo.className = 'fg-decal';\n photo.src = item.decal;\n photo.alt = '';\n photo.loading = 'lazy';\n photo.decoding = 'async';\n front.appendChild(photo);\n }\n if (item.label) {\n const label = document.createElement('div');\n label.className = 'fg-label';\n label.textContent = item.label;\n front.appendChild(label);\n }\n card.appendChild(front);\n\n scene.appendChild(card);\n return card;\n });\n\n /* ── Dots ── */\n const dots = cardEls.map((_, i) => {\n const dot = document.createElement('button');\n dot.type = 'button';\n dot.className = 'fg-dot';\n dot.setAttribute('role', 'tab');\n dot.setAttribute('aria-label', items[i].label || `Go to ${i + 1}`);\n on(dot, 'click', () => goTo(i));\n dotsEl.appendChild(dot);\n return dot;\n });\n\n /* ── Layouts ── */\n function layoutStack() {\n scene.style.height = '';\n cardEls.forEach((card, i) => {\n const behind = (i - active + n) % n;\n if (behind === 0) {\n setCardTransform(card, { x: 0, y: 100, z: 20, rx: 0, ry: 0, s: 1, zIndex: n + 1, opacity: 1, isActive: true });\n return;\n }\n const safeN = Math.max(n - 1, 1);\n const tz = -behind * 25 - behind * behind * 3;\n const rx = reduced ? 0 : -behind * 3;\n const ty = 100 - behind * 28 - behind * behind * 2;\n const sc = 1 - behind * 0.06 - (behind / safeN) * (behind / safeN) * 0.04;\n setCardTransform(card, { x: 0, y: ty, z: tz, rx, ry: 0, s: Math.max(sc, 0.5), zIndex: n - behind, opacity: 1 - behind * 0.08, isActive: false });\n });\n }\n function layoutGrid() {\n const sceneW = scene.clientWidth || MODE_WIDTHS.grid;\n // Two columns on narrow scenes so folders stay tappable and readable.\n const cols = sceneW < 520 ? 2 : n <= 4 ? 2 : 3;\n const gap = 16;\n const cardW = sceneW;\n const cardH = sceneW * (2 / 3);\n const sc = (sceneW - (cols - 1) * gap) / (cols * cardW);\n const scaledW = cardW * sc;\n const scaledH = cardH * sc;\n const tabScaled = 22 * sc;\n const rows = Math.ceil(n / cols);\n cardEls.forEach((card, i) => {\n const col = i % cols;\n const row = Math.floor(i / cols);\n const itemsInRow = Math.min(cols, n - row * cols);\n const rowW = itemsInRow * scaledW + (itemsInRow - 1) * gap;\n const rowStartX = (sceneW - rowW) / 2;\n const cellLeft = rowStartX + col * (scaledW + gap);\n const cellTop = row * (scaledH + tabScaled + gap) + tabScaled;\n const tx = cellLeft + scaledW / 2 - cardW / 2;\n const ty = cellTop + scaledH - cardH;\n setCardTransform(card, { x: tx, y: ty, z: 0, rx: 0, ry: 0, s: sc, zIndex: i === active ? 2 : 1, opacity: 1, isActive: i === active });\n });\n scene.style.height = rows * (scaledH + tabScaled + gap) + 20 + 'px';\n }\n function layoutCarousel() {\n const sceneW = scene.clientWidth || MODE_WIDTHS.carousel;\n const cardW = sceneW;\n const cardH = cardW * (2 / 3);\n const activeSc = 0.62;\n const activeW = cardW * activeSc;\n const sceneH = Math.max(cardH * activeSc + 40, 180);\n scene.style.height = sceneH + 'px';\n const offsetStep = Math.min(130, (sceneW - activeW) / 4);\n cardEls.forEach((card, i) => {\n let offset = i - active;\n if (n > 2 && offset > Math.floor(n / 2)) offset -= n;\n if (n > 2 && offset < -Math.floor(n / 2)) offset += n;\n const sc = Math.max(activeSc - Math.abs(offset) * 0.06, 0.28);\n const z = -Math.abs(offset) * 50;\n const op = Math.max(1 - Math.abs(offset) * 0.25, 0.15);\n const tx = sceneW / 2 + offset * offsetStep - cardW / 2;\n const ty = sceneH - 20 - cardH;\n setCardTransform(card, { x: tx, y: ty, z, rx: 0, ry: 0, s: sc, zIndex: n - Math.abs(offset), opacity: op, isActive: offset === 0 });\n });\n }\n // Scene width tracks the active mode so the layout math (which assumes the\n // mode's logical width) matches the actually-rendered card width. Layouts\n // then read scene.clientWidth, so everything stays self-consistent at any size.\n function sizeScene() {\n scene.style.width = `min(${MODE_WIDTHS[mode]}px, 92vw)`;\n }\n function applyLayout() {\n sizeScene();\n (mode === 'grid' ? layoutGrid : mode === 'carousel' ? layoutCarousel : layoutStack)();\n dots.forEach((d, i) => {\n d.classList.toggle('is-active', i === active);\n d.setAttribute('aria-selected', i === active ? 'true' : 'false');\n });\n cardEls.forEach((c, i) => { c.tabIndex = i === active ? 0 : -1; });\n const cur = items[active];\n live.textContent = cur && cur.label ? `${active + 1} of ${n}: ${cur.label}` : `${active + 1} of ${n}`;\n }\n\n /* ── Navigation ── */\n function goTo(i) {\n const next = opts.loop ? ((i % n) + n) % n : Math.min(Math.max(i, 0), n - 1);\n if (next === active) return;\n active = next;\n applyLayout();\n emit('fg-activechange', { index: active, item: items[active] });\n }\n function select(i) {\n emit('fg-select', { index: i, item: items[i] });\n if (typeof opts.onSelect === 'function') opts.onSelect(items[i], i);\n }\n function setMode(m) {\n if (m === mode || !MODE_WIDTHS[m]) return;\n mode = m;\n root.setAttribute('data-fg-mode', mode);\n applyLayout();\n emit('fg-modechange', { mode });\n }\n function setPeek(p) {\n if (!PEEK_MODES.has(p)) return;\n root.setAttribute('data-fg-peek', p);\n }\n\n /* ── Interaction ── */\n const dragEnabled = opts.drag !== 'off';\n let suppressClick = false; // a real drag eats the click that follows pointerup\n\n cardEls.forEach((card, i) => {\n on(card, 'click', () => {\n if (suppressClick) { suppressClick = false; return; }\n i === active ? select(i) : goTo(i);\n });\n on(card, 'keydown', (e) => {\n if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); select(i); }\n });\n });\n /* Arrow keys work two ways, matching the reference implementation:\n 1. Focus already inside the gallery (Tab to a card/dot) - bubbles here\n and re-focuses the new active card, standard roving-tabindex UX.\n 2. Mouse hovering the gallery, focus anywhere else on the page - a\n document-level listener picks it up. Without this route, arrow\n keys only work AFTER a click puts focus on a card - and a click is\n also what fires onSelect, which in real use is often a link. Making\n keyboard nav depend on that first click means the only way to\n \"activate\" arrows is to risk navigating away. Hover is enough. */\n function handleArrowKeys(e) {\n if (e.key === 'ArrowRight' || e.key === 'ArrowDown') { e.preventDefault(); goTo(active + 1); return true; }\n if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') { e.preventDefault(); goTo(active - 1); return true; }\n if (e.key === 'Home') { e.preventDefault(); goTo(0); return true; }\n if (e.key === 'End') { e.preventDefault(); goTo(n - 1); return true; }\n return false;\n }\n on(scene, 'keydown', (e) => { if (handleArrowKeys(e)) cardEls[active].focus(); });\n on(dotsEl, 'keydown', (e) => { if (handleArrowKeys(e)) cardEls[active].focus(); });\n\n let hovered = false;\n on(root, 'mouseenter', () => { hovered = true; });\n on(root, 'mouseleave', () => { hovered = false; });\n on(document, 'keydown', (e) => {\n if (!hovered) return;\n // Don't hijack arrows if focus is on an interactive control outside\n // the gallery (nav link, a form field elsewhere on the page).\n const ae = document.activeElement;\n if (ae && ae !== document.body && !root.contains(ae)) return;\n handleArrowKeys(e); // no forced focus - the user hasn't tabbed in\n });\n\n if (opts.scrollNav) {\n /* Bound to root, not just the scene box: root is the widget's full\n footprint (scene + dots), so wheel events over the dots row or any\n gap the consumer's own layout leaves around the gallery still cycle\n it, instead of requiring the pointer over the exact folder art. */\n on(root, 'wheel', (e) => {\n if (mode === 'grid') return;\n const atStart = !opts.loop && active === 0 && e.deltaY < 0;\n const atEnd = !opts.loop && active === n - 1 && e.deltaY > 0;\n if (atStart || atEnd) return;\n e.preventDefault();\n if (scrollCooldown) return;\n scrollAccum += e.deltaY;\n if (Math.abs(scrollAccum) >= SCROLL_THRESHOLD) {\n const dir = scrollAccum > 0 ? 1 : -1;\n scrollAccum = 0;\n scrollCooldown = true;\n goTo(active + dir);\n setTimeout(() => { scrollCooldown = false; scrollAccum = 0; }, SCROLL_COOLDOWN[mode] || 300);\n }\n }, { passive: false });\n }\n\n /* Dominant-axis swipe: up or left advances, down or right goes back.\n Horizontal is the natural phone gesture in carousel; vertical matches\n the wheel direction on the stack. Both work everywhere. */\n let touchStartX = 0;\n let touchStartY = 0;\n on(scene, 'touchstart', (e) => {\n touchStartX = e.touches[0].clientX;\n touchStartY = e.touches[0].clientY;\n }, { passive: true });\n on(scene, 'touchend', (e) => {\n // In stack mode the pointer-based drag below owns the gesture; letting\n // both fire would advance twice per swipe.\n if (dragEnabled && mode === 'stack') return;\n const dx = touchStartX - e.changedTouches[0].clientX;\n const dy = touchStartY - e.changedTouches[0].clientY;\n const ax = Math.abs(dx);\n const ay = Math.abs(dy);\n if (Math.max(ax, ay) < 40) return;\n const dir = ax > ay ? (dx > 0 ? 1 : -1) : (dy > 0 ? 1 : -1);\n goTo(active + dir);\n }, { passive: true });\n\n /* ── Drag: grab the active folder and throw it (stack mode) ──\n Pointer Events give one code path for mouse, touch, and pen. The\n gesture constants come from the folder-deck prototype this feature is\n ported from: rotation follows the drag at 0.04deg/px, a release past\n 90px of travel (or a genuine throw, over 0.5px/ms) flings the folder\n off along the dominant axis and advances; anything shorter springs\n back into the pile on the card's own transition. Direction keeps the\n swipe semantics: left or up is next, right or down is previous. */\n if (dragEnabled) {\n const DRAG_ROT = 0.04;\n const FLING_DIST = 90;\n const FLING_VEL = 0.5;\n const TAP_SLOP = 6;\n let dragCard = null;\n let dragBase = '';\n let startPX = 0, startPY = 0, dragDX = 0, dragDY = 0;\n let lastX = 0, lastY = 0, lastT = 0, velX = 0, velY = 0;\n\n on(scene, 'pointerdown', (e) => {\n if (mode !== 'stack') return;\n if (e.button !== undefined && e.button !== 0) return;\n const card = e.target && e.target.closest ? e.target.closest('.fg-card') : null;\n if (!card || !card.classList.contains('is-active')) return;\n dragCard = card;\n dragBase = card.style.transform;\n startPX = e.clientX; startPY = e.clientY;\n dragDX = 0; dragDY = 0;\n lastX = e.clientX; lastY = e.clientY;\n lastT = (typeof performance !== 'undefined' ? performance.now() : Date.now());\n velX = 0; velY = 0;\n card.classList.add('fg-card--dragging');\n if (card.setPointerCapture && e.pointerId !== undefined) {\n try { card.setPointerCapture(e.pointerId); } catch (_) { /* jsdom / detached */ }\n }\n });\n on(window, 'pointermove', (e) => {\n if (!dragCard) return;\n dragDX = e.clientX - startPX;\n dragDY = e.clientY - startPY;\n const now = (typeof performance !== 'undefined' ? performance.now() : Date.now());\n const dt = Math.max(now - lastT, 1);\n velX = (e.clientX - lastX) / dt;\n velY = (e.clientY - lastY) / dt;\n lastX = e.clientX; lastY = e.clientY; lastT = now;\n // translateZ lifts the grabbed folder clear of every plane in the\n // pile (tilted tops can poke past the active card's resting depth)\n // and reads as physically picking it up.\n dragCard.style.transform = `${dragBase} translate3d(${dragDX}px, ${dragDY}px, 40px) rotate(${(dragDX * DRAG_ROT).toFixed(2)}deg)`;\n });\n const endDrag = () => {\n if (!dragCard) return;\n const card = dragCard;\n dragCard = null;\n card.classList.remove('fg-card--dragging');\n const dist = Math.hypot(dragDX, dragDY);\n if (dist < TAP_SLOP) { card.style.transform = dragBase; return; } // a tap: the click handler owns it\n suppressClick = true;\n const horizontal = Math.abs(dragDX) >= Math.abs(dragDY);\n const flung = dist > FLING_DIST || Math.hypot(velX, velY) > FLING_VEL;\n const dir = horizontal ? (dragDX > 0 ? -1 : 1) : (dragDY > 0 ? -1 : 1);\n const target = active + dir;\n const blocked = !opts.loop && (target < 0 || target > n - 1);\n if (!flung || blocked) { card.style.transform = dragBase; return; } // spring back into the pile\n if (reduced) { goTo(target); return; }\n const offX = horizontal ? Math.sign(dragDX) * Math.max(window.innerWidth * 0.7, 480) : dragDX * 3;\n const offY = horizontal ? dragDY * 3 : Math.sign(dragDY) * Math.max(window.innerHeight * 0.7, 480);\n /* Choreography: the pile answers the throw IMMEDIATELY (goTo below;\n layout skips the flung card), while the thrown folder finishes its\n own flight - a longer, momentum-eased sail that fades over 340ms.\n Once it is fully invisible, it re-enters by DROPPING IN from above\n its new slot: never straight from off-screen, which would cross\n the other folders' 3D planes and slice them visibly. */\n card.classList.add('fg-card--flung');\n card.style.transform = `${dragBase} translate3d(${offX}px, ${offY}px, 40px) rotate(${Math.sign(dragDX || 1) * 18}deg)`;\n card.style.opacity = '0';\n goTo(target); // shuffle starts now; the flung card is exempt from this relayout\n setTimeout(() => {\n card.classList.add('fg-card--snap');\n card.classList.remove('fg-card--flung');\n applyLayout(); // now it takes its slot transform (invisible, transitions off)\n const slot = card.style.transform;\n const slotOpacity = card.style.opacity;\n card.style.transform = `${slot} translate3d(0, -90px, 0)`;\n card.style.opacity = '0';\n /* Phase boundary via double rAF, NOT a synchronous reflow flush:\n WebKit does not treat forced reflows as transition boundaries and\n will compute the transition from the last PAINTED state (the\n fling-off position), which flashes the card across the pile.\n Painting one real frame at the staging point (invisible,\n transitions off) gives every engine the same before-state. */\n requestAnimationFrame(() => requestAnimationFrame(() => {\n card.classList.remove('fg-card--snap');\n card.classList.add('fg-card--entering'); // quicker settle curve for the drop\n card.style.transform = slot; // descend into the pile\n card.style.opacity = slotOpacity;\n setTimeout(() => card.classList.remove('fg-card--entering'), 700);\n }));\n }, 400); // after the 340ms flung fade, with margin: never snap a visible card\n };\n on(window, 'pointerup', endDrag);\n on(window, 'pointercancel', endDrag);\n }\n\n let resizeTimer;\n on(window, 'resize', () => { clearTimeout(resizeTimer); resizeTimer = setTimeout(applyLayout, 150); });\n\n applyLayout();\n\n /* ── Public handle ── */\n return {\n next: () => goTo(active + 1),\n prev: () => goTo(active - 1),\n goTo,\n setMode,\n setPeek,\n getActiveIndex: () => active,\n getMode: () => mode,\n destroy: teardown,\n };\n}\n\nexport default createFolderGallery;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,IAAM,SAAS;AAGf,IAAM,sBACJ;AAIF,IAAM,WAAW;AAAA,EACf,MAAM;AAAA;AAAA,EACN,YAAY;AAAA,EACZ,MAAM;AAAA,EACN,WAAW;AAAA,EACX,eAAe;AAAA;AAAA,EACf,MAAM;AAAA;AAAA,EACN,MAAM;AAAA;AAAA,EACN,oBAAoB;AAAA,EACpB,OAAO;AACT;AAEA,IAAM,aAAa,oBAAI,IAAI,CAAC,SAAS,UAAU,KAAK,CAAC;AACrD,IAAM,aAAa,oBAAI,IAAI,CAAC,SAAS,KAAK,CAAC;AAE3C,IAAM,cAAc,EAAE,OAAO,KAAK,MAAM,KAAK,UAAU,IAAI;AAC3D,IAAM,mBAAmB;AACzB,IAAM,kBAAkB,EAAE,OAAO,KAAK,UAAU,IAAI;AAEpD,SAAS,SAAS,KAAK;AACrB,QAAM,IAAI,OAAO,GAAG,EAAE,QAAQ,KAAK,EAAE;AACrC,SAAO,CAAC,SAAS,EAAE,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,SAAS,EAAE,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,SAAS,EAAE,MAAM,GAAG,CAAC,GAAG,EAAE,CAAC;AAC/F;AAOA,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AG,GAAG;AAAA,QAClE,CAAC,CAAC;AAAA,MACJ,GAAG,GAAG;AAAA,IACR;AACA,OAAG,QAAQ,aAAa,OAAO;AAC/B,OAAG,QAAQ,iBAAiB,OAAO;AAAA,EACrC;AAEA,MAAI;AACJ,KAAG,QAAQ,UAAU,MAAM;AAAE,iBAAa,WAAW;AAAG,kBAAc,WAAW,aAAa,GAAG;AAAA,EAAG,CAAC;AAErG,cAAY;AAGZ,SAAO;AAAA,IACL,MAAM,MAAM,KAAK,SAAS,CAAC;AAAA,IAC3B,MAAM,MAAM,KAAK,SAAS,CAAC;AAAA,IAC3B;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB,MAAM;AAAA,IACtB,SAAS,MAAM;AAAA,IACf,SAAS;AAAA,EACX;AACF;AAEA,IAAO,yBAAQ;","names":[]}
package/dist/element.cjs CHANGED
@@ -53,10 +53,13 @@ var DEFAULTS = {
53
53
  // 'auto' | 'off' | 'force'
54
54
  peek: "hover",
55
55
  // 'hover' | 'always' | 'off'
56
+ drag: "fling",
57
+ // 'fling' | 'off' - grab the active folder and throw it (stack mode)
56
58
  defaultActiveIndex: 0,
57
59
  label: "Folder gallery"
58
60
  };
59
61
  var PEEK_MODES = /* @__PURE__ */ new Set(["hover", "always", "off"]);
62
+ var DRAG_MODES = /* @__PURE__ */ new Set(["fling", "off"]);
60
63
  var MODE_WIDTHS = { stack: 480, grid: 720, carousel: 720 };
61
64
  var SCROLL_THRESHOLD = 30;
62
65
  var SCROLL_COOLDOWN = { stack: 450, carousel: 300 };
@@ -117,6 +120,7 @@ function createFolderGallery(root, options = {}) {
117
120
  root.classList.add("fg-root");
118
121
  root.setAttribute("data-fg-mode", mode);
119
122
  root.setAttribute("data-fg-peek", PEEK_MODES.has(opts.peek) ? opts.peek : "hover");
123
+ root.setAttribute("data-fg-drag", DRAG_MODES.has(opts.drag) ? opts.drag : "fling");
120
124
  const scene = document.createElement("div");
121
125
  scene.className = "fg-scene";
122
126
  scene.setAttribute("role", "listbox");
@@ -137,6 +141,7 @@ function createFolderGallery(root, options = {}) {
137
141
  root.classList.remove("fg-root");
138
142
  root.removeAttribute("data-fg-mode");
139
143
  root.removeAttribute("data-fg-peek");
144
+ root.removeAttribute("data-fg-drag");
140
145
  }
141
146
  if (n === 0) {
142
147
  return { next() {
@@ -147,10 +152,12 @@ function createFolderGallery(root, options = {}) {
147
152
  }, getActiveIndex: () => -1, getMode: () => mode, destroy: teardown };
148
153
  }
149
154
  function setCardTransform(card, { x, y, z, rx, ry, s, zIndex, opacity, isActive }) {
150
- card.style.transform = `translate3d(${x}px,${y}px,${z}px) rotateX(${rx}deg) rotateY(${ry}deg) scale(${s})`;
155
+ if (!card.classList.contains("fg-card--flung")) {
156
+ card.style.transform = `translate3d(${x}px,${y}px,${z}px) rotateX(${rx}deg) rotateY(${ry}deg) scale(${s})`;
157
+ card.style.opacity = String(opacity);
158
+ }
151
159
  card.style.transformOrigin = "center bottom";
152
160
  card.style.zIndex = String(zIndex);
153
- card.style.opacity = String(opacity);
154
161
  card.setAttribute("aria-selected", isActive ? "true" : "false");
155
162
  card.classList.toggle("is-active", isActive);
156
163
  }
@@ -310,8 +317,14 @@ function createFolderGallery(root, options = {}) {
310
317
  if (!PEEK_MODES.has(p)) return;
311
318
  root.setAttribute("data-fg-peek", p);
312
319
  }
320
+ const dragEnabled = opts.drag !== "off";
321
+ let suppressClick = false;
313
322
  cardEls.forEach((card, i) => {
314
323
  on(card, "click", () => {
324
+ if (suppressClick) {
325
+ suppressClick = false;
326
+ return;
327
+ }
315
328
  i === active ? select(i) : goTo(i);
316
329
  });
317
330
  on(card, "keydown", (e) => {
@@ -391,6 +404,7 @@ function createFolderGallery(root, options = {}) {
391
404
  touchStartY = e.touches[0].clientY;
392
405
  }, { passive: true });
393
406
  on(scene, "touchend", (e) => {
407
+ if (dragEnabled && mode === "stack") return;
394
408
  const dx = touchStartX - e.changedTouches[0].clientX;
395
409
  const dy = touchStartY - e.changedTouches[0].clientY;
396
410
  const ax = Math.abs(dx);
@@ -399,6 +413,102 @@ function createFolderGallery(root, options = {}) {
399
413
  const dir = ax > ay ? dx > 0 ? 1 : -1 : dy > 0 ? 1 : -1;
400
414
  goTo(active + dir);
401
415
  }, { passive: true });
416
+ if (dragEnabled) {
417
+ const DRAG_ROT = 0.04;
418
+ const FLING_DIST = 90;
419
+ const FLING_VEL = 0.5;
420
+ const TAP_SLOP = 6;
421
+ let dragCard = null;
422
+ let dragBase = "";
423
+ let startPX = 0, startPY = 0, dragDX = 0, dragDY = 0;
424
+ let lastX = 0, lastY = 0, lastT = 0, velX = 0, velY = 0;
425
+ on(scene, "pointerdown", (e) => {
426
+ if (mode !== "stack") return;
427
+ if (e.button !== void 0 && e.button !== 0) return;
428
+ const card = e.target && e.target.closest ? e.target.closest(".fg-card") : null;
429
+ if (!card || !card.classList.contains("is-active")) return;
430
+ dragCard = card;
431
+ dragBase = card.style.transform;
432
+ startPX = e.clientX;
433
+ startPY = e.clientY;
434
+ dragDX = 0;
435
+ dragDY = 0;
436
+ lastX = e.clientX;
437
+ lastY = e.clientY;
438
+ lastT = typeof performance !== "undefined" ? performance.now() : Date.now();
439
+ velX = 0;
440
+ velY = 0;
441
+ card.classList.add("fg-card--dragging");
442
+ if (card.setPointerCapture && e.pointerId !== void 0) {
443
+ try {
444
+ card.setPointerCapture(e.pointerId);
445
+ } catch (_) {
446
+ }
447
+ }
448
+ });
449
+ on(window, "pointermove", (e) => {
450
+ if (!dragCard) return;
451
+ dragDX = e.clientX - startPX;
452
+ dragDY = e.clientY - startPY;
453
+ const now = typeof performance !== "undefined" ? performance.now() : Date.now();
454
+ const dt = Math.max(now - lastT, 1);
455
+ velX = (e.clientX - lastX) / dt;
456
+ velY = (e.clientY - lastY) / dt;
457
+ lastX = e.clientX;
458
+ lastY = e.clientY;
459
+ lastT = now;
460
+ dragCard.style.transform = `${dragBase} translate3d(${dragDX}px, ${dragDY}px, 40px) rotate(${(dragDX * DRAG_ROT).toFixed(2)}deg)`;
461
+ });
462
+ const endDrag = () => {
463
+ if (!dragCard) return;
464
+ const card = dragCard;
465
+ dragCard = null;
466
+ card.classList.remove("fg-card--dragging");
467
+ const dist = Math.hypot(dragDX, dragDY);
468
+ if (dist < TAP_SLOP) {
469
+ card.style.transform = dragBase;
470
+ return;
471
+ }
472
+ suppressClick = true;
473
+ const horizontal = Math.abs(dragDX) >= Math.abs(dragDY);
474
+ const flung = dist > FLING_DIST || Math.hypot(velX, velY) > FLING_VEL;
475
+ const dir = horizontal ? dragDX > 0 ? -1 : 1 : dragDY > 0 ? -1 : 1;
476
+ const target = active + dir;
477
+ const blocked = !opts.loop && (target < 0 || target > n - 1);
478
+ if (!flung || blocked) {
479
+ card.style.transform = dragBase;
480
+ return;
481
+ }
482
+ if (reduced) {
483
+ goTo(target);
484
+ return;
485
+ }
486
+ const offX = horizontal ? Math.sign(dragDX) * Math.max(window.innerWidth * 0.7, 480) : dragDX * 3;
487
+ const offY = horizontal ? dragDY * 3 : Math.sign(dragDY) * Math.max(window.innerHeight * 0.7, 480);
488
+ card.classList.add("fg-card--flung");
489
+ card.style.transform = `${dragBase} translate3d(${offX}px, ${offY}px, 40px) rotate(${Math.sign(dragDX || 1) * 18}deg)`;
490
+ card.style.opacity = "0";
491
+ goTo(target);
492
+ setTimeout(() => {
493
+ card.classList.add("fg-card--snap");
494
+ card.classList.remove("fg-card--flung");
495
+ applyLayout();
496
+ const slot = card.style.transform;
497
+ const slotOpacity = card.style.opacity;
498
+ card.style.transform = `${slot} translate3d(0, -90px, 0)`;
499
+ card.style.opacity = "0";
500
+ requestAnimationFrame(() => requestAnimationFrame(() => {
501
+ card.classList.remove("fg-card--snap");
502
+ card.classList.add("fg-card--entering");
503
+ card.style.transform = slot;
504
+ card.style.opacity = slotOpacity;
505
+ setTimeout(() => card.classList.remove("fg-card--entering"), 700);
506
+ }));
507
+ }, 400);
508
+ };
509
+ on(window, "pointerup", endDrag);
510
+ on(window, "pointercancel", endDrag);
511
+ }
402
512
  let resizeTimer;
403
513
  on(window, "resize", () => {
404
514
  clearTimeout(resizeTimer);
@@ -423,7 +533,7 @@ var ElementBase = typeof HTMLElement !== "undefined" ? HTMLElement : class {
423
533
  };
424
534
  var FolderGalleryElement = class extends ElementBase {
425
535
  static get observedAttributes() {
426
- return ["mode", "peek", "loop", "scroll-nav", "reduced-motion", "default-active-index", "label", "folder-path"];
536
+ return ["mode", "peek", "drag", "loop", "scroll-nav", "reduced-motion", "default-active-index", "label", "folder-path"];
427
537
  }
428
538
  constructor() {
429
539
  super();
@@ -466,6 +576,7 @@ var FolderGalleryElement = class extends ElementBase {
466
576
  const opts = { items: this._items };
467
577
  if (this.hasAttribute("mode")) opts.mode = this.getAttribute("mode");
468
578
  if (this.hasAttribute("peek")) opts.peek = this.getAttribute("peek");
579
+ if (this.hasAttribute("drag")) opts.drag = this.getAttribute("drag");
469
580
  if (this.hasAttribute("loop")) opts.loop = asBool(this.getAttribute("loop"));
470
581
  if (this.hasAttribute("scroll-nav")) opts.scrollNav = asBool(this.getAttribute("scroll-nav"));
471
582
  if (this.hasAttribute("reduced-motion")) opts.reducedMotion = this.getAttribute("reduced-motion");