@surdeddd/wmkit 0.8.0 → 0.9.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 (52) hide show
  1. package/README.md +23 -1
  2. package/README.ru.md +23 -1
  3. package/dist/angular.cjs +3 -3
  4. package/dist/angular.d.cts +2 -2
  5. package/dist/angular.d.ts +2 -2
  6. package/dist/angular.js +1 -1
  7. package/dist/{binder-B625OrjD.d.cts → binder-DGoj0xG1.d.cts} +1 -1
  8. package/dist/{binder-CpGY8Wye.d.ts → binder-Lo13iTVB.d.ts} +1 -1
  9. package/dist/chrome.cjs +122 -0
  10. package/dist/chrome.cjs.map +1 -0
  11. package/dist/chrome.d.cts +25 -0
  12. package/dist/chrome.d.ts +25 -0
  13. package/dist/chrome.js +114 -0
  14. package/dist/chrome.js.map +1 -0
  15. package/dist/{chunk-MGWCKHTZ.js → chunk-TUGQX3CX.js} +179 -17
  16. package/dist/chunk-TUGQX3CX.js.map +1 -0
  17. package/dist/{chunk-DINVOL6Z.cjs → chunk-ZWUVWRUS.cjs} +179 -17
  18. package/dist/chunk-ZWUVWRUS.cjs.map +1 -0
  19. package/dist/gestures.d.cts +1 -1
  20. package/dist/gestures.d.ts +1 -1
  21. package/dist/index.cjs +10 -10
  22. package/dist/index.d.cts +3 -3
  23. package/dist/index.d.ts +3 -3
  24. package/dist/index.js +1 -1
  25. package/dist/react.cjs +3 -3
  26. package/dist/react.d.cts +2 -2
  27. package/dist/react.d.ts +2 -2
  28. package/dist/react.js +1 -1
  29. package/dist/{shared-BBXgEeIa.d.ts → shared-BoHXlPCu.d.ts} +34 -1
  30. package/dist/{shared-DU_87nY9.d.cts → shared-DdGFz3oy.d.cts} +34 -1
  31. package/dist/solid.cjs +3 -3
  32. package/dist/solid.d.cts +2 -2
  33. package/dist/solid.d.ts +2 -2
  34. package/dist/solid.js +1 -1
  35. package/dist/svelte.cjs +3 -3
  36. package/dist/svelte.d.cts +2 -2
  37. package/dist/svelte.d.ts +2 -2
  38. package/dist/svelte.js +1 -1
  39. package/dist/themes/retro.css +8 -0
  40. package/dist/themes.cjs +8747 -0
  41. package/dist/themes.cjs.map +1 -0
  42. package/dist/themes.d.cts +12 -0
  43. package/dist/themes.d.ts +12 -0
  44. package/dist/themes.js +8742 -0
  45. package/dist/themes.js.map +1 -0
  46. package/dist/vue.cjs +3 -3
  47. package/dist/vue.d.cts +2 -2
  48. package/dist/vue.d.ts +2 -2
  49. package/dist/vue.js +1 -1
  50. package/package.json +44 -7
  51. package/dist/chunk-DINVOL6Z.cjs.map +0 -1
  52. package/dist/chunk-MGWCKHTZ.js.map +0 -1
@@ -1369,6 +1369,22 @@ function createAnnouncer(wm, container, messages = {}) {
1369
1369
  };
1370
1370
  }
1371
1371
 
1372
+ // src/dom/actions.ts
1373
+ function createActions(wm, id) {
1374
+ return {
1375
+ focus: () => wm.focus(id),
1376
+ close: () => wm.close(id),
1377
+ minimize: () => wm.minimize(id),
1378
+ maximize: () => wm.maximize(id),
1379
+ toggleMaximize: () => wm.toggleMaximize(id),
1380
+ restore: () => wm.restore(id),
1381
+ center: () => wm.center(id),
1382
+ sendToBack: () => wm.sendToBack(id),
1383
+ snap: (zone) => wm.snap(id, zone),
1384
+ moveToWorkspace: (workspace) => wm.moveToWorkspace(id, workspace)
1385
+ };
1386
+ }
1387
+
1372
1388
  // src/dom/drag.ts
1373
1389
  function createDragStarter(ctx) {
1374
1390
  const { wm, doc, view } = ctx;
@@ -1730,7 +1746,7 @@ function createResizeHandles(doc, edge, corner) {
1730
1746
  }
1731
1747
 
1732
1748
  // src/dom/shared.ts
1733
- var INTERACTIVE_SELECTOR = "button, input, select, textarea, a[href], [contenteditable], [data-wm-close], [data-wm-minimize], [data-wm-maximize]";
1749
+ var INTERACTIVE_SELECTOR = "button, input, select, textarea, a[href], [contenteditable], [data-wm-close], [data-wm-minimize], [data-wm-maximize], [data-wm-snap], [data-wm-restore], [data-wm-center], [data-wm-send-back], [data-wm-to-workspace]";
1734
1750
  function windowOf(element) {
1735
1751
  const view = element.ownerDocument.defaultView;
1736
1752
  if (!view) throw new Error("wmkit: desktop element is not attached to a document");
@@ -1827,8 +1843,49 @@ var SNAP_SHORTCUTS = {
1827
1843
  ArrowLeft: "left",
1828
1844
  ArrowRight: "right"
1829
1845
  };
1846
+ var SNAP_ZONES = /* @__PURE__ */ new Set([
1847
+ "left",
1848
+ "right",
1849
+ "top",
1850
+ "bottom",
1851
+ "top-left",
1852
+ "top-right",
1853
+ "bottom-left",
1854
+ "bottom-right",
1855
+ "left-third",
1856
+ "center-third",
1857
+ "right-third"
1858
+ ]);
1830
1859
  var LANDMARK_TAGS = /* @__PURE__ */ new Set(["header", "footer", "aside", "nav"]);
1831
1860
  var FOCUSABLE_SELECTOR = 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
1861
+ function focusablesOf(el) {
1862
+ const root = el.shadowRoot;
1863
+ if (!root) return [...el.querySelectorAll(FOCUSABLE_SELECTOR)];
1864
+ const found = [];
1865
+ for (const node of root.querySelectorAll(`${FOCUSABLE_SELECTOR}, slot`)) {
1866
+ if (!(node instanceof HTMLSlotElement)) {
1867
+ found.push(node);
1868
+ continue;
1869
+ }
1870
+ for (const assigned of node.assignedElements()) {
1871
+ if (assigned.matches(FOCUSABLE_SELECTOR)) found.push(assigned);
1872
+ found.push(...assigned.querySelectorAll(FOCUSABLE_SELECTOR));
1873
+ }
1874
+ }
1875
+ return found;
1876
+ }
1877
+ function dragHandleAt(node, clientX, clientY) {
1878
+ const handle = node.closest?.("[data-wm-drag]");
1879
+ if (handle) return handle;
1880
+ const inner = node.shadowRoot?.elementFromPoint?.(clientX, clientY) ?? null;
1881
+ return inner === null || inner === node ? null : dragHandleAt(inner, clientX, clientY);
1882
+ }
1883
+ function windowElementOf(node) {
1884
+ const found = node.closest("[data-wm-window]");
1885
+ if (found) return found;
1886
+ const host = node.getRootNode().host;
1887
+ return host ? windowElementOf(host) : null;
1888
+ }
1832
1889
  function defaultVariant(win) {
1833
1890
  const variant = win.meta.variant;
1834
1891
  return typeof variant === "string" && variant !== "" ? variant : null;
@@ -1947,8 +2004,8 @@ function attachDesktop(wm, element, options = {}) {
1947
2004
  groupTarget(clientX, clientY, selfId) {
1948
2005
  if (!groupingEnabled || typeof doc.elementsFromPoint !== "function") return null;
1949
2006
  for (const node of doc.elementsFromPoint(clientX, clientY)) {
1950
- const handle = node.closest?.("[data-wm-drag]");
1951
- const host = handle?.closest("[data-wm-window]");
2007
+ const handle = dragHandleAt(node, clientX, clientY);
2008
+ const host = handle && windowElementOf(handle);
1952
2009
  const id = host?.dataset.wmWindow;
1953
2010
  if (id && id !== selfId && registry.get(id)?.element === host) return id;
1954
2011
  }
@@ -2025,6 +2082,9 @@ function attachDesktop(wm, element, options = {}) {
2025
2082
  }
2026
2083
  el.hidden = hide;
2027
2084
  el.setAttribute("aria-label", win.title);
2085
+ if (attached.title && attached.title.textContent !== win.title) {
2086
+ attached.title.textContent = win.title;
2087
+ }
2028
2088
  if (win.layer === "modal") el.setAttribute("aria-modal", "true");
2029
2089
  else el.removeAttribute("aria-modal");
2030
2090
  for (const handle of attached.handles) {
@@ -2062,15 +2122,30 @@ function attachDesktop(wm, element, options = {}) {
2062
2122
  function syncAll() {
2063
2123
  const state = wm.getState();
2064
2124
  const orderChanged = state.order !== lastOrder;
2125
+ let restyle = null;
2065
2126
  for (const id of state.order) {
2066
2127
  const attached = registry.get(id);
2067
2128
  const win = state.windows[id];
2068
2129
  if (!attached || !win) continue;
2130
+ const wanted2 = typeof win.meta.skin === "string" ? win.meta.skin : null;
2131
+ if (attached.skin !== null && wanted2 !== null && wanted2 !== attached.skin) {
2132
+ restyle = restyle ?? [];
2133
+ restyle.push([id, wanted2]);
2134
+ continue;
2135
+ }
2069
2136
  const activeTab = win.groupId === null || state.groups[win.groupId]?.activeId === win.id;
2070
2137
  if (attached.lastState !== win || attached.lastWorkspace !== state.workspace || attached.lastTab !== activeTab) {
2071
2138
  syncWindow(attached, win, state.workspace, activeTab);
2072
2139
  }
2073
2140
  }
2141
+ if (restyle !== null) {
2142
+ for (const [id, wanted2] of restyle) {
2143
+ const attached = registry.get(id);
2144
+ if (attached && attached.skin !== wanted2) buildSkin(id, wanted2, attached.mountOptions);
2145
+ }
2146
+ syncAll();
2147
+ return;
2148
+ }
2074
2149
  if (orderChanged) applyStacking(state.order);
2075
2150
  const wanted = state.focusedId ? registry.get(state.focusedId)?.element ?? null : null;
2076
2151
  if (wanted !== focusedEl) {
@@ -2168,6 +2243,11 @@ function attachDesktop(wm, element, options = {}) {
2168
2243
  const attached = {
2169
2244
  element: windowElement,
2170
2245
  handle: null,
2246
+ title: null,
2247
+ skin: null,
2248
+ mount: null,
2249
+ mountOptions: windowOptions,
2250
+ release: null,
2171
2251
  handles: [],
2172
2252
  lastState: null,
2173
2253
  lastZ: UNASSIGNED,
@@ -2181,10 +2261,11 @@ function attachDesktop(wm, element, options = {}) {
2181
2261
  windowElement.style.position = "absolute";
2182
2262
  windowElement.style.left = "0";
2183
2263
  windowElement.style.top = "0";
2184
- const titleEl = windowElement.querySelector("[data-wm-title]");
2185
- if (titleEl) {
2186
- if (!titleEl.id) titleEl.id = `wmkit-title-${id}`;
2187
- windowElement.setAttribute("aria-labelledby", titleEl.id);
2264
+ const lightTitle = windowElement.querySelector("[data-wm-title]");
2265
+ attached.title = lightTitle ?? windowElement.shadowRoot?.querySelector("[data-wm-title]") ?? null;
2266
+ if (lightTitle) {
2267
+ if (!lightTitle.id) lightTitle.id = `wmkit-title-${id}`;
2268
+ windowElement.setAttribute("aria-labelledby", lightTitle.id);
2188
2269
  }
2189
2270
  const handle = typeof windowOptions.handle === "string" ? windowElement.querySelector(windowOptions.handle) : windowOptions.handle ?? windowElement.querySelector("[data-wm-drag]");
2190
2271
  attached.handle = handle;
@@ -2205,10 +2286,38 @@ function attachDesktop(wm, element, options = {}) {
2205
2286
  if (!current) return;
2206
2287
  if (target.closest("[data-wm-close]")) {
2207
2288
  if (current.closable && options.beforeClose?.(current) !== false) wm.close(id);
2208
- } else if (target.closest("[data-wm-minimize]")) {
2289
+ return;
2290
+ }
2291
+ if (target.closest("[data-wm-minimize]")) {
2209
2292
  if (current.minimizable) wm.minimize(id);
2210
- } else if (target.closest("[data-wm-maximize]")) {
2293
+ return;
2294
+ }
2295
+ if (target.closest("[data-wm-maximize]")) {
2211
2296
  if (current.maximizable) wm.toggleMaximize(id);
2297
+ return;
2298
+ }
2299
+ const act = createActions(wm, id);
2300
+ const snapTarget = target.closest("[data-wm-snap]");
2301
+ if (snapTarget) {
2302
+ const zone = snapTarget.dataset.wmSnap ?? "";
2303
+ if (current.snappable && SNAP_ZONES.has(zone)) act.snap(zone);
2304
+ return;
2305
+ }
2306
+ if (target.closest("[data-wm-restore]")) {
2307
+ act.restore();
2308
+ return;
2309
+ }
2310
+ if (target.closest("[data-wm-center]")) {
2311
+ act.center();
2312
+ return;
2313
+ }
2314
+ if (target.closest("[data-wm-send-back]")) {
2315
+ act.sendToBack();
2316
+ return;
2317
+ }
2318
+ const workspaceTarget = target.closest("[data-wm-to-workspace]");
2319
+ if (workspaceTarget) {
2320
+ act.moveToWorkspace(Number.parseInt(workspaceTarget.dataset.wmToWorkspace ?? "", 10));
2212
2321
  }
2213
2322
  };
2214
2323
  windowElement.addEventListener("click", onClick);
@@ -2246,7 +2355,7 @@ function attachDesktop(wm, element, options = {}) {
2246
2355
  const onResizeDown = (event) => startResize(id, direction, event);
2247
2356
  resizeHandle.addEventListener("pointerdown", onResizeDown);
2248
2357
  attached.cleanup.push(() => resizeHandle.removeEventListener("pointerdown", onResizeDown));
2249
- windowElement.append(resizeHandle);
2358
+ (windowElement.shadowRoot ?? windowElement).append(resizeHandle);
2250
2359
  attached.handles.push(resizeHandle);
2251
2360
  }
2252
2361
  }
@@ -2284,9 +2393,10 @@ function attachDesktop(wm, element, options = {}) {
2284
2393
  if (event.key !== "Tab") return;
2285
2394
  const current = wm.get(id);
2286
2395
  if (current?.layer !== "modal") return;
2287
- const focusables = [
2288
- ...windowElement.querySelectorAll(FOCUSABLE_SELECTOR)
2289
- ].filter((node) => node.offsetParent !== null || node === doc.activeElement);
2396
+ const active = windowElement.shadowRoot?.activeElement ?? doc.activeElement;
2397
+ const focusables = focusablesOf(windowElement).filter(
2398
+ (node) => node.offsetParent !== null || node === active
2399
+ );
2290
2400
  if (focusables.length === 0) return;
2291
2401
  const first = focusables[0];
2292
2402
  const last = focusables[focusables.length - 1];
@@ -2296,10 +2406,10 @@ function attachDesktop(wm, element, options = {}) {
2296
2406
  (event.shiftKey ? last : first).focus();
2297
2407
  return;
2298
2408
  }
2299
- if (event.shiftKey && doc.activeElement === first) {
2409
+ if (event.shiftKey && active === first) {
2300
2410
  event.preventDefault();
2301
2411
  last.focus();
2302
- } else if (!event.shiftKey && doc.activeElement === last) {
2412
+ } else if (!event.shiftKey && active === last) {
2303
2413
  event.preventDefault();
2304
2414
  first.focus();
2305
2415
  }
@@ -2337,10 +2447,62 @@ function attachDesktop(wm, element, options = {}) {
2337
2447
  }
2338
2448
  return detach;
2339
2449
  }
2450
+ function resolveSkin(skin) {
2451
+ if (typeof skin !== "string") return skin;
2452
+ const found = options.skins?.[skin];
2453
+ if (!found) throw new Error(`wmkit: unknown skin "${skin}"`);
2454
+ return found;
2455
+ }
2456
+ function buildSkin(id, skin, windowOptions) {
2457
+ const win = wm.get(id);
2458
+ if (!win) throw new Error(`wmkit: cannot mount unknown window "${id}"`);
2459
+ const standing = registry.get(id);
2460
+ const previous = standing?.mount ?? null;
2461
+ const carried = previous === null ? [] : [...previous.content.childNodes];
2462
+ if (previous !== null) {
2463
+ registry.delete(id);
2464
+ standing?.release?.();
2465
+ previous.element.remove();
2466
+ }
2467
+ const mount = resolveSkin(skin)({ doc, id, window: win, actions: createActions(wm, id) });
2468
+ element.append(mount.element);
2469
+ const release = attachWindow(id, mount.element, windowOptions);
2470
+ const attached = registry.get(id);
2471
+ attached.skin = typeof skin === "string" ? skin : null;
2472
+ attached.mount = mount;
2473
+ attached.mountOptions = windowOptions;
2474
+ attached.release = release;
2475
+ mount.content.append(...carried);
2476
+ previous?.destroy?.();
2477
+ return mount;
2478
+ }
2479
+ function mountWindow(id, skin, windowOptions = {}) {
2480
+ let last = buildSkin(id, skin, windowOptions);
2481
+ const live = () => {
2482
+ last = registry.get(id)?.mount ?? last;
2483
+ return last;
2484
+ };
2485
+ return {
2486
+ get element() {
2487
+ return live().element;
2488
+ },
2489
+ get content() {
2490
+ return live().content;
2491
+ },
2492
+ detach() {
2493
+ const mount = live();
2494
+ registry.get(id)?.release?.();
2495
+ mount.element.remove();
2496
+ mount.destroy?.();
2497
+ }
2498
+ };
2499
+ }
2340
2500
  return {
2341
2501
  element,
2342
2502
  wm,
2343
2503
  attachWindow,
2504
+ mountWindow,
2505
+ actions: (id) => createActions(wm, id),
2344
2506
  destroy() {
2345
2507
  endDrag(true);
2346
2508
  for (const [, attached] of registry) {
@@ -2419,5 +2581,5 @@ exports.defaultMessages = defaultMessages;
2419
2581
  exports.flipFromTarget = flipFromTarget;
2420
2582
  exports.flipToTarget = flipToTarget;
2421
2583
  exports.prefersReducedMotion = prefersReducedMotion;
2422
- //# sourceMappingURL=chunk-DINVOL6Z.cjs.map
2423
- //# sourceMappingURL=chunk-DINVOL6Z.cjs.map
2584
+ //# sourceMappingURL=chunk-ZWUVWRUS.cjs.map
2585
+ //# sourceMappingURL=chunk-ZWUVWRUS.cjs.map