@surdeddd/wmkit 0.1.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/LICENSE +21 -0
- package/README.md +308 -0
- package/README.ru.md +120 -0
- package/dist/chunk-7HHDQEBI.js +1334 -0
- package/dist/chunk-7HHDQEBI.js.map +1 -0
- package/dist/chunk-KWLI7JIY.cjs +1349 -0
- package/dist/chunk-KWLI7JIY.cjs.map +1 -0
- package/dist/controller-B0bogK9N.d.cts +65 -0
- package/dist/controller-D5zIriLg.d.ts +65 -0
- package/dist/index.cjs +64 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/persist.cjs +74 -0
- package/dist/persist.cjs.map +1 -0
- package/dist/persist.d.cts +22 -0
- package/dist/persist.d.ts +22 -0
- package/dist/persist.js +72 -0
- package/dist/persist.js.map +1 -0
- package/dist/popout.cjs +66 -0
- package/dist/popout.cjs.map +1 -0
- package/dist/popout.d.cts +28 -0
- package/dist/popout.d.ts +28 -0
- package/dist/popout.js +63 -0
- package/dist/popout.js.map +1 -0
- package/dist/react.cjs +57 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +16 -0
- package/dist/react.d.ts +16 -0
- package/dist/react.js +51 -0
- package/dist/react.js.map +1 -0
- package/dist/solid.cjs +45 -0
- package/dist/solid.cjs.map +1 -0
- package/dist/solid.d.cts +15 -0
- package/dist/solid.d.ts +15 -0
- package/dist/solid.js +40 -0
- package/dist/solid.js.map +1 -0
- package/dist/svelte.cjs +60 -0
- package/dist/svelte.cjs.map +1 -0
- package/dist/svelte.d.cts +24 -0
- package/dist/svelte.d.ts +24 -0
- package/dist/svelte.js +55 -0
- package/dist/svelte.js.map +1 -0
- package/dist/themes/glass.css +203 -0
- package/dist/types-CtFzL_oA.d.cts +151 -0
- package/dist/types-CtFzL_oA.d.ts +151 -0
- package/dist/vue.cjs +54 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.cts +11 -0
- package/dist/vue.d.ts +11 -0
- package/dist/vue.js +48 -0
- package/dist/vue.js.map +1 -0
- package/package.json +257 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { W as WindowManager } from './types-CtFzL_oA.js';
|
|
2
|
+
|
|
3
|
+
interface PersistStorage {
|
|
4
|
+
getItem(key: string): string | null;
|
|
5
|
+
setItem(key: string, value: string): void;
|
|
6
|
+
removeItem(key: string): void;
|
|
7
|
+
}
|
|
8
|
+
interface PersistOptions {
|
|
9
|
+
key?: string;
|
|
10
|
+
storage?: PersistStorage;
|
|
11
|
+
debounce?: number;
|
|
12
|
+
autoRestore?: boolean;
|
|
13
|
+
}
|
|
14
|
+
interface PersistController {
|
|
15
|
+
restore(): boolean;
|
|
16
|
+
save(): void;
|
|
17
|
+
clear(): void;
|
|
18
|
+
destroy(): void;
|
|
19
|
+
}
|
|
20
|
+
declare function persist(wm: WindowManager, options?: PersistOptions): PersistController;
|
|
21
|
+
|
|
22
|
+
export { type PersistController, type PersistOptions, type PersistStorage, persist };
|
package/dist/persist.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// src/persist.ts
|
|
2
|
+
function defaultStorage() {
|
|
3
|
+
try {
|
|
4
|
+
const storage = globalThis.localStorage;
|
|
5
|
+
const probe = "__wmkit_probe__";
|
|
6
|
+
storage.setItem(probe, "1");
|
|
7
|
+
storage.removeItem(probe);
|
|
8
|
+
return storage;
|
|
9
|
+
} catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function persist(wm, options = {}) {
|
|
14
|
+
const key = options.key ?? "wmkit";
|
|
15
|
+
const storage = options.storage ?? defaultStorage();
|
|
16
|
+
const debounce = options.debounce ?? 150;
|
|
17
|
+
let timer;
|
|
18
|
+
let suspended = false;
|
|
19
|
+
function save() {
|
|
20
|
+
if (!storage) return;
|
|
21
|
+
try {
|
|
22
|
+
storage.setItem(key, JSON.stringify(wm.serialize()));
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function restore() {
|
|
27
|
+
if (!storage) return false;
|
|
28
|
+
let raw = null;
|
|
29
|
+
try {
|
|
30
|
+
raw = storage.getItem(key);
|
|
31
|
+
} catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (!raw) return false;
|
|
35
|
+
let data;
|
|
36
|
+
try {
|
|
37
|
+
data = JSON.parse(raw);
|
|
38
|
+
} catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
suspended = true;
|
|
42
|
+
const restored = wm.hydrate(data);
|
|
43
|
+
suspended = false;
|
|
44
|
+
return restored;
|
|
45
|
+
}
|
|
46
|
+
function clear() {
|
|
47
|
+
if (!storage) return;
|
|
48
|
+
try {
|
|
49
|
+
storage.removeItem(key);
|
|
50
|
+
} catch {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const unsubscribe = wm.subscribe(() => {
|
|
54
|
+
if (suspended || !storage) return;
|
|
55
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
56
|
+
timer = setTimeout(save, debounce);
|
|
57
|
+
});
|
|
58
|
+
if (options.autoRestore !== false) restore();
|
|
59
|
+
return {
|
|
60
|
+
restore,
|
|
61
|
+
save,
|
|
62
|
+
clear,
|
|
63
|
+
destroy() {
|
|
64
|
+
unsubscribe();
|
|
65
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { persist };
|
|
71
|
+
//# sourceMappingURL=persist.js.map
|
|
72
|
+
//# sourceMappingURL=persist.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/persist.ts"],"names":[],"mappings":";AAsBA,SAAS,cAAA,GAAwC;AAC/C,EAAA,IAAI;AACF,IAAA,MAAM,UAAU,UAAA,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,IACT;AACA,IAAA,SAAA,GAAY,IAAA;AACZ,IAAA,MAAM,QAAA,GAAW,EAAA,CAAG,OAAA,CAAQ,IAAI,CAAA;AAChC,IAAA,SAAA,GAAY,KAAA;AACZ,IAAA,OAAO,QAAA;AAAA,EACT;AAEA,EAAA,SAAS,KAAA,GAAc;AACrB,IAAA,IAAI,CAAC,OAAA,EAAS;AACd,IAAA,IAAI;AACF,MAAA,OAAA,CAAQ,WAAW,GAAG,CAAA;AAAA,IACxB,CAAA,CAAA,MAAQ;AAAA,IAAC;AAAA,EACX;AAEA,EAAA,MAAM,WAAA,GAAc,EAAA,CAAG,SAAA,CAAU,MAAM;AACrC,IAAA,IAAI,SAAA,IAAa,CAAC,OAAA,EAAS;AAC3B,IAAA,IAAI,KAAA,KAAU,MAAA,EAAW,YAAA,CAAa,KAAK,CAAA;AAC3C,IAAA,KAAA,GAAQ,UAAA,CAAW,MAAM,QAAQ,CAAA;AAAA,EACnC,CAAC,CAAA;AAED,EAAA,IAAI,OAAA,CAAQ,WAAA,KAAgB,KAAA,EAAO,OAAA,EAAQ;AAE3C,EAAA,OAAO;AAAA,IACL,OAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA;AAAA,IACA,OAAA,GAAU;AACR,MAAA,WAAA,EAAY;AACZ,MAAA,IAAI,KAAA,KAAU,MAAA,EAAW,YAAA,CAAa,KAAK,CAAA;AAAA,IAC7C;AAAA,GACF;AACF","file":"persist.js","sourcesContent":["import type { SerializedState, WindowManager } from './core/types'\n\nexport interface PersistStorage {\n getItem(key: string): string | null\n setItem(key: string, value: string): void\n removeItem(key: string): void\n}\n\nexport interface PersistOptions {\n key?: string\n storage?: PersistStorage\n debounce?: number\n autoRestore?: boolean\n}\n\nexport interface PersistController {\n restore(): boolean\n save(): void\n clear(): void\n destroy(): void\n}\n\nfunction defaultStorage(): PersistStorage | null {\n try {\n const storage = globalThis.localStorage\n const probe = '__wmkit_probe__'\n storage.setItem(probe, '1')\n storage.removeItem(probe)\n return storage\n } catch {\n return null\n }\n}\n\nexport function persist(wm: WindowManager, options: PersistOptions = {}): PersistController {\n const key = options.key ?? 'wmkit'\n const storage = options.storage ?? defaultStorage()\n const debounce = options.debounce ?? 150\n let timer: ReturnType<typeof setTimeout> | undefined\n let suspended = false\n\n function save(): void {\n if (!storage) return\n try {\n storage.setItem(key, JSON.stringify(wm.serialize()))\n } catch {}\n }\n\n function restore(): boolean {\n if (!storage) return false\n let raw: string | null = null\n try {\n raw = storage.getItem(key)\n } catch {\n return false\n }\n if (!raw) return false\n let data: SerializedState\n try {\n data = JSON.parse(raw) as SerializedState\n } catch {\n return false\n }\n suspended = true\n const restored = wm.hydrate(data)\n suspended = false\n return restored\n }\n\n function clear(): void {\n if (!storage) return\n try {\n storage.removeItem(key)\n } catch {}\n }\n\n const unsubscribe = wm.subscribe(() => {\n if (suspended || !storage) return\n if (timer !== undefined) clearTimeout(timer)\n timer = setTimeout(save, debounce)\n })\n\n if (options.autoRestore !== false) restore()\n\n return {\n restore,\n save,\n clear,\n destroy() {\n unsubscribe()\n if (timer !== undefined) clearTimeout(timer)\n },\n }\n}\n"]}
|
package/dist/popout.cjs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/popout.ts
|
|
4
|
+
function isPopoutSupported() {
|
|
5
|
+
return typeof window !== "undefined" && window.documentPictureInPicture !== void 0;
|
|
6
|
+
}
|
|
7
|
+
function copyStylesInto(pipWindow, source) {
|
|
8
|
+
for (const sheet of Array.from(source.styleSheets)) {
|
|
9
|
+
const owner = sheet.ownerNode;
|
|
10
|
+
if (!owner) continue;
|
|
11
|
+
try {
|
|
12
|
+
const rules = Array.from(sheet.cssRules).map((rule) => rule.cssText).join("\n");
|
|
13
|
+
const style = pipWindow.document.createElement("style");
|
|
14
|
+
style.textContent = rules;
|
|
15
|
+
pipWindow.document.head.append(style);
|
|
16
|
+
} catch {
|
|
17
|
+
if (owner instanceof HTMLLinkElement && owner.href) {
|
|
18
|
+
const link = pipWindow.document.createElement("link");
|
|
19
|
+
link.rel = "stylesheet";
|
|
20
|
+
link.href = owner.href;
|
|
21
|
+
pipWindow.document.head.append(link);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async function popout(wm, id, content, options = {}) {
|
|
27
|
+
const win = wm.get(id);
|
|
28
|
+
if (!win) throw new Error(`wmkit: cannot pop out unknown window "${id}"`);
|
|
29
|
+
const api = typeof window !== "undefined" ? window.documentPictureInPicture : void 0;
|
|
30
|
+
if (!api) throw new Error("wmkit: Document Picture-in-Picture is not supported in this browser");
|
|
31
|
+
const pipWindow = await api.requestWindow({
|
|
32
|
+
width: options.width ?? Math.round(win.bounds.width),
|
|
33
|
+
height: options.height ?? Math.round(win.bounds.height)
|
|
34
|
+
});
|
|
35
|
+
if (options.copyStyles !== false) copyStylesInto(pipWindow, content.ownerDocument);
|
|
36
|
+
const parent = content.parentNode;
|
|
37
|
+
const marker = content.ownerDocument.createComment("wmkit-popout");
|
|
38
|
+
parent?.insertBefore(marker, content);
|
|
39
|
+
pipWindow.document.body.append(content);
|
|
40
|
+
pipWindow.document.title = win.title;
|
|
41
|
+
const minimizeWhilePopped = options.minimizeWhilePopped !== false;
|
|
42
|
+
if (minimizeWhilePopped) wm.minimize(id);
|
|
43
|
+
let closed = false;
|
|
44
|
+
function handleReturn() {
|
|
45
|
+
if (closed) return;
|
|
46
|
+
closed = true;
|
|
47
|
+
if (marker.parentNode) {
|
|
48
|
+
marker.parentNode.insertBefore(content, marker);
|
|
49
|
+
marker.remove();
|
|
50
|
+
}
|
|
51
|
+
if (minimizeWhilePopped && wm.get(id)) wm.restore(id);
|
|
52
|
+
}
|
|
53
|
+
pipWindow.addEventListener("pagehide", handleReturn);
|
|
54
|
+
return {
|
|
55
|
+
pipWindow,
|
|
56
|
+
close() {
|
|
57
|
+
pipWindow.close();
|
|
58
|
+
handleReturn();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
exports.isPopoutSupported = isPopoutSupported;
|
|
64
|
+
exports.popout = popout;
|
|
65
|
+
//# sourceMappingURL=popout.cjs.map
|
|
66
|
+
//# sourceMappingURL=popout.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/popout.ts"],"names":[],"mappings":";;;AA4BO,SAAS,iBAAA,GAA6B;AAC3C,EAAA,OAAO,OAAO,MAAA,KAAW,WAAA,IAAe,MAAA,CAAO,wBAAA,KAA6B,MAAA;AAC9E;AAEA,SAAS,cAAA,CAAe,WAAmB,MAAA,EAAwB;AACjE,EAAA,KAAA,MAAW,KAAA,IAAS,KAAA,CAAM,IAAA,CAAK,MAAA,CAAO,WAAW,CAAA,EAAG;AAClD,IAAA,MAAM,QAAQ,KAAA,CAAM,SAAA;AACpB,IAAA,IAAI,CAAC,KAAA,EAAO;AACZ,IAAA,IAAI;AACF,MAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,IAAA,CAAK,KAAA,CAAM,QAAQ,CAAA,CACpC,GAAA,CAAI,CAAC,IAAA,KAAS,IAAA,CAAK,OAAO,CAAA,CAC1B,KAAK,IAAI,CAAA;AACZ,MAAA,MAAM,KAAA,GAAQ,SAAA,CAAU,QAAA,CAAS,aAAA,CAAc,OAAO,CAAA;AACtD,MAAA,KAAA,CAAM,WAAA,GAAc,KAAA;AACpB,MAAA,SAAA,CAAU,QAAA,CAAS,IAAA,CAAK,MAAA,CAAO,KAAK,CAAA;AAAA,IACtC,CAAA,CAAA,MAAQ;AACN,MAAA,IAAI,KAAA,YAAiB,eAAA,IAAmB,KAAA,CAAM,IAAA,EAAM;AAClD,QAAA,MAAM,IAAA,GAAO,SAAA,CAAU,QAAA,CAAS,aAAA,CAAc,MAAM,CAAA;AACpD,QAAA,IAAA,CAAK,GAAA,GAAM,YAAA;AACX,QAAA,IAAA,CAAK,OAAO,KAAA,CAAM,IAAA;AAClB,QAAA,SAA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5D,EAAA,IAAI,mBAAA,EAAqB,EAAA,CAAG,QAAA,CAAS,EAAE,CAAA;AAEvC,EAAA,IAAI,MAAA,GAAS,KAAA;AACb,EAAA,SAAS,YAAA,GAAqB;AAC5B,IAAA,IAAI,MAAA,EAAQ;AACZ,IAAA,MAAA,GAAS,IAAA;AACT,IAAA,IAAI,OAAO,UAAA,EAAY;AACrB,MAAA,MAAA,CAAO,UAAA,CAAW,YAAA,CAAa,OAAA,EAAS,MAAM,CAAA;AAC9C,MAAA,MAAA,CAAO,MAAA,EAAO;AAAA,IAChB;AACA,IAAA,IAAI,uBAAuB,EAAA,CAAG,GAAA,CAAI,EAAE,CAAA,EAAG,EAAA,CAAG,QAAQ,EAAE,CAAA;AAAA,EACtD;AAEA,EAAA,SAAA,CAAU,gBAAA,CAAiB,YAAY,YAAY,CAAA;AAEnD,EAAA,OAAO;AAAA,IACL,SAAA;AAAA,IACA,KAAA,GAAQ;AACN,MAAA,SAAA,CAAU,KAAA,EAAM;AAChB,MAAA,YAAA,EAAa;AAAA,IACf;AAAA,GACF;AACF","file":"popout.cjs","sourcesContent":["import type { WindowManager } from './core/types'\n\ninterface DocumentPictureInPictureApi {\n requestWindow(options?: {\n width?: number\n height?: number\n disallowReturnToOpener?: boolean\n }): Promise<Window>\n}\n\ndeclare global {\n interface Window {\n documentPictureInPicture?: DocumentPictureInPictureApi\n }\n}\n\nexport interface PopoutOptions {\n width?: number\n height?: number\n copyStyles?: boolean\n minimizeWhilePopped?: boolean\n}\n\nexport interface PopoutHandle {\n pipWindow: Window\n close(): void\n}\n\nexport function isPopoutSupported(): boolean {\n return typeof window !== 'undefined' && window.documentPictureInPicture !== undefined\n}\n\nfunction copyStylesInto(pipWindow: Window, source: Document): void {\n for (const sheet of Array.from(source.styleSheets)) {\n const owner = sheet.ownerNode\n if (!owner) continue\n try {\n const rules = Array.from(sheet.cssRules)\n .map((rule) => rule.cssText)\n .join('\\n')\n const style = pipWindow.document.createElement('style')\n style.textContent = rules\n pipWindow.document.head.append(style)\n } catch {\n if (owner instanceof HTMLLinkElement && owner.href) {\n const link = pipWindow.document.createElement('link')\n link.rel = 'stylesheet'\n link.href = owner.href\n pipWindow.document.head.append(link)\n }\n }\n }\n}\n\nexport async function popout(\n wm: WindowManager,\n id: string,\n content: HTMLElement,\n options: PopoutOptions = {},\n): Promise<PopoutHandle> {\n const win = wm.get(id)\n if (!win) throw new Error(`wmkit: cannot pop out unknown window \"${id}\"`)\n const api = typeof window !== 'undefined' ? window.documentPictureInPicture : undefined\n if (!api) throw new Error('wmkit: Document Picture-in-Picture is not supported in this browser')\n\n const pipWindow = await api.requestWindow({\n width: options.width ?? Math.round(win.bounds.width),\n height: options.height ?? Math.round(win.bounds.height),\n })\n\n if (options.copyStyles !== false) copyStylesInto(pipWindow, content.ownerDocument)\n\n const parent = content.parentNode\n const marker = content.ownerDocument.createComment('wmkit-popout')\n parent?.insertBefore(marker, content)\n pipWindow.document.body.append(content)\n pipWindow.document.title = win.title\n\n const minimizeWhilePopped = options.minimizeWhilePopped !== false\n if (minimizeWhilePopped) wm.minimize(id)\n\n let closed = false\n function handleReturn(): void {\n if (closed) return\n closed = true\n if (marker.parentNode) {\n marker.parentNode.insertBefore(content, marker)\n marker.remove()\n }\n if (minimizeWhilePopped && wm.get(id)) wm.restore(id)\n }\n\n pipWindow.addEventListener('pagehide', handleReturn)\n\n return {\n pipWindow,\n close() {\n pipWindow.close()\n handleReturn()\n },\n }\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { W as WindowManager } from './types-CtFzL_oA.cjs';
|
|
2
|
+
|
|
3
|
+
interface DocumentPictureInPictureApi {
|
|
4
|
+
requestWindow(options?: {
|
|
5
|
+
width?: number;
|
|
6
|
+
height?: number;
|
|
7
|
+
disallowReturnToOpener?: boolean;
|
|
8
|
+
}): Promise<Window>;
|
|
9
|
+
}
|
|
10
|
+
declare global {
|
|
11
|
+
interface Window {
|
|
12
|
+
documentPictureInPicture?: DocumentPictureInPictureApi;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
interface PopoutOptions {
|
|
16
|
+
width?: number;
|
|
17
|
+
height?: number;
|
|
18
|
+
copyStyles?: boolean;
|
|
19
|
+
minimizeWhilePopped?: boolean;
|
|
20
|
+
}
|
|
21
|
+
interface PopoutHandle {
|
|
22
|
+
pipWindow: Window;
|
|
23
|
+
close(): void;
|
|
24
|
+
}
|
|
25
|
+
declare function isPopoutSupported(): boolean;
|
|
26
|
+
declare function popout(wm: WindowManager, id: string, content: HTMLElement, options?: PopoutOptions): Promise<PopoutHandle>;
|
|
27
|
+
|
|
28
|
+
export { type PopoutHandle, type PopoutOptions, isPopoutSupported, popout };
|
package/dist/popout.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { W as WindowManager } from './types-CtFzL_oA.js';
|
|
2
|
+
|
|
3
|
+
interface DocumentPictureInPictureApi {
|
|
4
|
+
requestWindow(options?: {
|
|
5
|
+
width?: number;
|
|
6
|
+
height?: number;
|
|
7
|
+
disallowReturnToOpener?: boolean;
|
|
8
|
+
}): Promise<Window>;
|
|
9
|
+
}
|
|
10
|
+
declare global {
|
|
11
|
+
interface Window {
|
|
12
|
+
documentPictureInPicture?: DocumentPictureInPictureApi;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
interface PopoutOptions {
|
|
16
|
+
width?: number;
|
|
17
|
+
height?: number;
|
|
18
|
+
copyStyles?: boolean;
|
|
19
|
+
minimizeWhilePopped?: boolean;
|
|
20
|
+
}
|
|
21
|
+
interface PopoutHandle {
|
|
22
|
+
pipWindow: Window;
|
|
23
|
+
close(): void;
|
|
24
|
+
}
|
|
25
|
+
declare function isPopoutSupported(): boolean;
|
|
26
|
+
declare function popout(wm: WindowManager, id: string, content: HTMLElement, options?: PopoutOptions): Promise<PopoutHandle>;
|
|
27
|
+
|
|
28
|
+
export { type PopoutHandle, type PopoutOptions, isPopoutSupported, popout };
|
package/dist/popout.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// src/popout.ts
|
|
2
|
+
function isPopoutSupported() {
|
|
3
|
+
return typeof window !== "undefined" && window.documentPictureInPicture !== void 0;
|
|
4
|
+
}
|
|
5
|
+
function copyStylesInto(pipWindow, source) {
|
|
6
|
+
for (const sheet of Array.from(source.styleSheets)) {
|
|
7
|
+
const owner = sheet.ownerNode;
|
|
8
|
+
if (!owner) continue;
|
|
9
|
+
try {
|
|
10
|
+
const rules = Array.from(sheet.cssRules).map((rule) => rule.cssText).join("\n");
|
|
11
|
+
const style = pipWindow.document.createElement("style");
|
|
12
|
+
style.textContent = rules;
|
|
13
|
+
pipWindow.document.head.append(style);
|
|
14
|
+
} catch {
|
|
15
|
+
if (owner instanceof HTMLLinkElement && owner.href) {
|
|
16
|
+
const link = pipWindow.document.createElement("link");
|
|
17
|
+
link.rel = "stylesheet";
|
|
18
|
+
link.href = owner.href;
|
|
19
|
+
pipWindow.document.head.append(link);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function popout(wm, id, content, options = {}) {
|
|
25
|
+
const win = wm.get(id);
|
|
26
|
+
if (!win) throw new Error(`wmkit: cannot pop out unknown window "${id}"`);
|
|
27
|
+
const api = typeof window !== "undefined" ? window.documentPictureInPicture : void 0;
|
|
28
|
+
if (!api) throw new Error("wmkit: Document Picture-in-Picture is not supported in this browser");
|
|
29
|
+
const pipWindow = await api.requestWindow({
|
|
30
|
+
width: options.width ?? Math.round(win.bounds.width),
|
|
31
|
+
height: options.height ?? Math.round(win.bounds.height)
|
|
32
|
+
});
|
|
33
|
+
if (options.copyStyles !== false) copyStylesInto(pipWindow, content.ownerDocument);
|
|
34
|
+
const parent = content.parentNode;
|
|
35
|
+
const marker = content.ownerDocument.createComment("wmkit-popout");
|
|
36
|
+
parent?.insertBefore(marker, content);
|
|
37
|
+
pipWindow.document.body.append(content);
|
|
38
|
+
pipWindow.document.title = win.title;
|
|
39
|
+
const minimizeWhilePopped = options.minimizeWhilePopped !== false;
|
|
40
|
+
if (minimizeWhilePopped) wm.minimize(id);
|
|
41
|
+
let closed = false;
|
|
42
|
+
function handleReturn() {
|
|
43
|
+
if (closed) return;
|
|
44
|
+
closed = true;
|
|
45
|
+
if (marker.parentNode) {
|
|
46
|
+
marker.parentNode.insertBefore(content, marker);
|
|
47
|
+
marker.remove();
|
|
48
|
+
}
|
|
49
|
+
if (minimizeWhilePopped && wm.get(id)) wm.restore(id);
|
|
50
|
+
}
|
|
51
|
+
pipWindow.addEventListener("pagehide", handleReturn);
|
|
52
|
+
return {
|
|
53
|
+
pipWindow,
|
|
54
|
+
close() {
|
|
55
|
+
pipWindow.close();
|
|
56
|
+
handleReturn();
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { isPopoutSupported, popout };
|
|
62
|
+
//# sourceMappingURL=popout.js.map
|
|
63
|
+
//# sourceMappingURL=popout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/popout.ts"],"names":[],"mappings":";AA4BO,SAAS,iBAAA,GAA6B;AAC3C,EAAA,OAAO,OAAO,MAAA,KAAW,WAAA,IAAe,MAAA,CAAO,wBAAA,KAA6B,MAAA;AAC9E;AAEA,SAAS,cAAA,CAAe,WAAmB,MAAA,EAAwB;AACjE,EAAA,KAAA,MAAW,KAAA,IAAS,KAAA,CAAM,IAAA,CAAK,MAAA,CAAO,WAAW,CAAA,EAAG;AAClD,IAAA,MAAM,QAAQ,KAAA,CAAM,SAAA;AACpB,IAAA,IAAI,CAAC,KAAA,EAAO;AACZ,IAAA,IAAI;AACF,MAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,IAAA,CAAK,KAAA,CAAM,QAAQ,CAAA,CACpC,GAAA,CAAI,CAAC,IAAA,KAAS,IAAA,CAAK,OAAO,CAAA,CAC1B,KAAK,IAAI,CAAA;AACZ,MAAA,MAAM,KAAA,GAAQ,SAAA,C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e,KAAA,EAAO,cAAA,CAAe,SAAA,EAAW,QAAQ,aAAa,CAAA;AAEjF,EAAA,MAAM,SAAS,OAAA,CAAQ,UAAA;AACvB,EAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,aAAA,CAAc,aAAA,CAAc,cAAc,CAAA;AACjE,EAAA,MAAA,EAAQ,YAAA,CAAa,QAAQ,OAAO,CAAA;AACpC,EAAA,SAAA,CAAU,QAAA,CAAS,IAAA,CAAK,MAAA,CAAO,OAAO,CAAA;AACtC,EAAA,SAAA,CAAU,QAAA,CAAS,QAAQ,GAAA,CAAI,KAAA;AAE/B,EAAA,MAAM,mBAAA,GAAsB,QAAQ,mBAAA,KAAwB,KAAA;AAC5D,EAAA,IAAI,mBAAA,EAAqB,EAAA,CAAG,QAAA,CAAS,EAAE,CAAA;AAEvC,EAAA,IAAI,MAAA,GAAS,KAAA;AACb,EAAA,SAAS,YAAA,GAAqB;AAC5B,IAAA,IAAI,MAAA,EAAQ;AACZ,IAAA,MAAA,GAAS,IAAA;AACT,IAAA,IAAI,OAAO,UAAA,EAAY;AACrB,MAAA,MAAA,CAAO,UAAA,CAAW,YAAA,CAAa,OAAA,EAAS,MAAM,CAAA;AAC9C,MAAA,MAAA,CAAO,MAAA,EAAO;AAAA,IAChB;AACA,IAAA,IAAI,uBAAuB,EAAA,CAAG,GAAA,CAAI,EAAE,CAAA,EAAG,EAAA,CAAG,QAAQ,EAAE,CAAA;AAAA,EACtD;AAEA,EAAA,SAAA,CAAU,gBAAA,CAAiB,YAAY,YAAY,CAAA;AAEnD,EAAA,OAAO;AAAA,IACL,SAAA;AAAA,IACA,KAAA,GAAQ;AACN,MAAA,SAAA,CAAU,KAAA,EAAM;AAChB,MAAA,YAAA,EAAa;AAAA,IACf;AAAA,GACF;AACF","file":"popout.js","sourcesContent":["import type { WindowManager } from './core/types'\n\ninterface DocumentPictureInPictureApi {\n requestWindow(options?: {\n width?: number\n height?: number\n disallowReturnToOpener?: boolean\n }): Promise<Window>\n}\n\ndeclare global {\n interface Window {\n documentPictureInPicture?: DocumentPictureInPictureApi\n }\n}\n\nexport interface PopoutOptions {\n width?: number\n height?: number\n copyStyles?: boolean\n minimizeWhilePopped?: boolean\n}\n\nexport interface PopoutHandle {\n pipWindow: Window\n close(): void\n}\n\nexport function isPopoutSupported(): boolean {\n return typeof window !== 'undefined' && window.documentPictureInPicture !== undefined\n}\n\nfunction copyStylesInto(pipWindow: Window, source: Document): void {\n for (const sheet of Array.from(source.styleSheets)) {\n const owner = sheet.ownerNode\n if (!owner) continue\n try {\n const rules = Array.from(sheet.cssRules)\n .map((rule) => rule.cssText)\n .join('\\n')\n const style = pipWindow.document.createElement('style')\n style.textContent = rules\n pipWindow.document.head.append(style)\n } catch {\n if (owner instanceof HTMLLinkElement && owner.href) {\n const link = pipWindow.document.createElement('link')\n link.rel = 'stylesheet'\n link.href = owner.href\n pipWindow.document.head.append(link)\n }\n }\n }\n}\n\nexport async function popout(\n wm: WindowManager,\n id: string,\n content: HTMLElement,\n options: PopoutOptions = {},\n): Promise<PopoutHandle> {\n const win = wm.get(id)\n if (!win) throw new Error(`wmkit: cannot pop out unknown window \"${id}\"`)\n const api = typeof window !== 'undefined' ? window.documentPictureInPicture : undefined\n if (!api) throw new Error('wmkit: Document Picture-in-Picture is not supported in this browser')\n\n const pipWindow = await api.requestWindow({\n width: options.width ?? Math.round(win.bounds.width),\n height: options.height ?? Math.round(win.bounds.height),\n })\n\n if (options.copyStyles !== false) copyStylesInto(pipWindow, content.ownerDocument)\n\n const parent = content.parentNode\n const marker = content.ownerDocument.createComment('wmkit-popout')\n parent?.insertBefore(marker, content)\n pipWindow.document.body.append(content)\n pipWindow.document.title = win.title\n\n const minimizeWhilePopped = options.minimizeWhilePopped !== false\n if (minimizeWhilePopped) wm.minimize(id)\n\n let closed = false\n function handleReturn(): void {\n if (closed) return\n closed = true\n if (marker.parentNode) {\n marker.parentNode.insertBefore(content, marker)\n marker.remove()\n }\n if (minimizeWhilePopped && wm.get(id)) wm.restore(id)\n }\n\n pipWindow.addEventListener('pagehide', handleReturn)\n\n return {\n pipWindow,\n close() {\n pipWindow.close()\n handleReturn()\n },\n }\n}\n"]}
|
package/dist/react.cjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkKWLI7JIY_cjs = require('./chunk-KWLI7JIY.cjs');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
|
|
6
|
+
function useWindowManager(options) {
|
|
7
|
+
const [wm] = react.useState(() => chunkKWLI7JIY_cjs.createWindowManager(options));
|
|
8
|
+
react.useEffect(() => () => wm.destroy(), [wm]);
|
|
9
|
+
return wm;
|
|
10
|
+
}
|
|
11
|
+
function useWmState(wm) {
|
|
12
|
+
return react.useSyncExternalStore(wm.subscribe, wm.getState, wm.getState);
|
|
13
|
+
}
|
|
14
|
+
function useWmWindow(wm, id) {
|
|
15
|
+
const getSnapshot = react.useCallback(() => wm.get(id), [wm, id]);
|
|
16
|
+
return react.useSyncExternalStore(wm.subscribe, getSnapshot, getSnapshot);
|
|
17
|
+
}
|
|
18
|
+
function useDesktop(wm, options) {
|
|
19
|
+
const optionsRef = react.useRef(options);
|
|
20
|
+
const binder = react.useMemo(() => chunkKWLI7JIY_cjs.createDesktopBinder(wm, optionsRef.current), [wm]);
|
|
21
|
+
const cleanupRef = react.useRef(null);
|
|
22
|
+
const ref = react.useCallback(
|
|
23
|
+
(node) => {
|
|
24
|
+
if (node) {
|
|
25
|
+
cleanupRef.current = binder.bindDesktop(node);
|
|
26
|
+
} else {
|
|
27
|
+
cleanupRef.current?.();
|
|
28
|
+
cleanupRef.current = null;
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
[binder]
|
|
32
|
+
);
|
|
33
|
+
return { ref, binder, controller: binder.controller };
|
|
34
|
+
}
|
|
35
|
+
function useWmWindowRef(binder, id, options) {
|
|
36
|
+
const optionsRef = react.useRef(options);
|
|
37
|
+
const cleanupRef = react.useRef(null);
|
|
38
|
+
return react.useCallback(
|
|
39
|
+
(node) => {
|
|
40
|
+
if (node) {
|
|
41
|
+
cleanupRef.current = binder.bindWindow(id, node, optionsRef.current);
|
|
42
|
+
} else {
|
|
43
|
+
cleanupRef.current?.();
|
|
44
|
+
cleanupRef.current = null;
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
[binder, id]
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
exports.useDesktop = useDesktop;
|
|
52
|
+
exports.useWindowManager = useWindowManager;
|
|
53
|
+
exports.useWmState = useWmState;
|
|
54
|
+
exports.useWmWindow = useWmWindow;
|
|
55
|
+
exports.useWmWindowRef = useWmWindowRef;
|
|
56
|
+
//# sourceMappingURL=react.cjs.map
|
|
57
|
+
//# sourceMappingURL=react.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react.ts"],"names":["useState","createWindowManager","useEffect","useSyncExternalStore","useCallback","useRef","useMemo","createDesktopBinder"],"mappings":";;;;;AAaO,SAAS,iBAAiB,OAAA,EAAyC;AACxE,EAAA,MAAM,CAAC,EAAE,CAAA,GAAIA,eAAS,MAAMC,qCAAA,CAAoB,OAAO,CAAC,CAAA;AACxD,EAAAC,eAAA,CAAU,MAAM,MAAM,EAAA,CAAG,SAAQ,EAAG,CAAC,EAAE,CAAC,CAAA;AACxC,EAAA,OAAO,EAAA;AACT;AAEO,SAAS,WAAW,EAAA,EAAiC;AAC1D,EAAA,OAAOC,2BAAqB,EAAA,CAAG,SAAA,EAAW,EAAA,CAAG,QAAA,EAAU,GAAG,QAAQ,CAAA;AACpE;AAEO,SAAS,WAAA,CAAY,IAAmB,EAAA,EAAqC;AAClF,EAAA,MAAM,WAAA,GAAcC,iBAAA,CAAY,MAAM,EAAA,CAAG,GAAA,CAAI,EAAE,CAAA,EAAG,CAAC,EAAA,EAAI,EAAE,CAAC,CAAA;AAC1D,EAAA,OAAOD,0BAAA,CAAqB,EAAA,CAA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GACb;AACF","file":"react.cjs","sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react'\nimport { createWindowManager } from './core/manager'\nimport type { ManagerOptions, ManagerState, WindowManager, WindowState } from './core/types'\nimport {\n createDesktopBinder,\n type DesktopBinder,\n type DesktopController,\n type DesktopOptions,\n type WindowAttachOptions,\n} from './dom/controller'\n\nexport type ElementRef = (node: HTMLElement | null) => void\n\nexport function useWindowManager(options?: ManagerOptions): WindowManager {\n const [wm] = useState(() => createWindowManager(options))\n useEffect(() => () => wm.destroy(), [wm])\n return wm\n}\n\nexport function useWmState(wm: WindowManager): ManagerState {\n return useSyncExternalStore(wm.subscribe, wm.getState, wm.getState)\n}\n\nexport function useWmWindow(wm: WindowManager, id: string): WindowState | undefined {\n const getSnapshot = useCallback(() => wm.get(id), [wm, id])\n return useSyncExternalStore(wm.subscribe, getSnapshot, getSnapshot)\n}\n\nexport interface UseDesktopResult {\n ref: ElementRef\n binder: DesktopBinder\n controller(): DesktopController | null\n}\n\nexport function useDesktop(wm: WindowManager, options?: DesktopOptions): UseDesktopResult {\n const optionsRef = useRef(options)\n const binder = useMemo(() => createDesktopBinder(wm, optionsRef.current), [wm])\n const cleanupRef = useRef<(() => void) | null>(null)\n const ref = useCallback<ElementRef>(\n (node) => {\n if (node) {\n cleanupRef.current = binder.bindDesktop(node)\n } else {\n cleanupRef.current?.()\n cleanupRef.current = null\n }\n },\n [binder],\n )\n return { ref, binder, controller: binder.controller }\n}\n\nexport function useWmWindowRef(\n binder: DesktopBinder,\n id: string,\n options?: WindowAttachOptions,\n): ElementRef {\n const optionsRef = useRef(options)\n const cleanupRef = useRef<(() => void) | null>(null)\n return useCallback<ElementRef>(\n (node) => {\n if (node) {\n cleanupRef.current = binder.bindWindow(id, node, optionsRef.current)\n } else {\n cleanupRef.current?.()\n cleanupRef.current = null\n }\n },\n [binder, id],\n )\n}\n"]}
|
package/dist/react.d.cts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { W as WindowManager, M as ManagerOptions, b as ManagerState, i as WindowState } from './types-CtFzL_oA.cjs';
|
|
2
|
+
import { D as DesktopBinder, b as DesktopController, d as DesktopOptions, W as WindowAttachOptions } from './controller-B0bogK9N.cjs';
|
|
3
|
+
|
|
4
|
+
type ElementRef = (node: HTMLElement | null) => void;
|
|
5
|
+
declare function useWindowManager(options?: ManagerOptions): WindowManager;
|
|
6
|
+
declare function useWmState(wm: WindowManager): ManagerState;
|
|
7
|
+
declare function useWmWindow(wm: WindowManager, id: string): WindowState | undefined;
|
|
8
|
+
interface UseDesktopResult {
|
|
9
|
+
ref: ElementRef;
|
|
10
|
+
binder: DesktopBinder;
|
|
11
|
+
controller(): DesktopController | null;
|
|
12
|
+
}
|
|
13
|
+
declare function useDesktop(wm: WindowManager, options?: DesktopOptions): UseDesktopResult;
|
|
14
|
+
declare function useWmWindowRef(binder: DesktopBinder, id: string, options?: WindowAttachOptions): ElementRef;
|
|
15
|
+
|
|
16
|
+
export { type ElementRef, type UseDesktopResult, useDesktop, useWindowManager, useWmState, useWmWindow, useWmWindowRef };
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { W as WindowManager, M as ManagerOptions, b as ManagerState, i as WindowState } from './types-CtFzL_oA.js';
|
|
2
|
+
import { D as DesktopBinder, b as DesktopController, d as DesktopOptions, W as WindowAttachOptions } from './controller-D5zIriLg.js';
|
|
3
|
+
|
|
4
|
+
type ElementRef = (node: HTMLElement | null) => void;
|
|
5
|
+
declare function useWindowManager(options?: ManagerOptions): WindowManager;
|
|
6
|
+
declare function useWmState(wm: WindowManager): ManagerState;
|
|
7
|
+
declare function useWmWindow(wm: WindowManager, id: string): WindowState | undefined;
|
|
8
|
+
interface UseDesktopResult {
|
|
9
|
+
ref: ElementRef;
|
|
10
|
+
binder: DesktopBinder;
|
|
11
|
+
controller(): DesktopController | null;
|
|
12
|
+
}
|
|
13
|
+
declare function useDesktop(wm: WindowManager, options?: DesktopOptions): UseDesktopResult;
|
|
14
|
+
declare function useWmWindowRef(binder: DesktopBinder, id: string, options?: WindowAttachOptions): ElementRef;
|
|
15
|
+
|
|
16
|
+
export { type ElementRef, type UseDesktopResult, useDesktop, useWindowManager, useWmState, useWmWindow, useWmWindowRef };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { createWindowManager, createDesktopBinder } from './chunk-7HHDQEBI.js';
|
|
2
|
+
import { useState, useEffect, useSyncExternalStore, useCallback, useRef, useMemo } from 'react';
|
|
3
|
+
|
|
4
|
+
function useWindowManager(options) {
|
|
5
|
+
const [wm] = useState(() => createWindowManager(options));
|
|
6
|
+
useEffect(() => () => wm.destroy(), [wm]);
|
|
7
|
+
return wm;
|
|
8
|
+
}
|
|
9
|
+
function useWmState(wm) {
|
|
10
|
+
return useSyncExternalStore(wm.subscribe, wm.getState, wm.getState);
|
|
11
|
+
}
|
|
12
|
+
function useWmWindow(wm, id) {
|
|
13
|
+
const getSnapshot = useCallback(() => wm.get(id), [wm, id]);
|
|
14
|
+
return useSyncExternalStore(wm.subscribe, getSnapshot, getSnapshot);
|
|
15
|
+
}
|
|
16
|
+
function useDesktop(wm, options) {
|
|
17
|
+
const optionsRef = useRef(options);
|
|
18
|
+
const binder = useMemo(() => createDesktopBinder(wm, optionsRef.current), [wm]);
|
|
19
|
+
const cleanupRef = useRef(null);
|
|
20
|
+
const ref = useCallback(
|
|
21
|
+
(node) => {
|
|
22
|
+
if (node) {
|
|
23
|
+
cleanupRef.current = binder.bindDesktop(node);
|
|
24
|
+
} else {
|
|
25
|
+
cleanupRef.current?.();
|
|
26
|
+
cleanupRef.current = null;
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
[binder]
|
|
30
|
+
);
|
|
31
|
+
return { ref, binder, controller: binder.controller };
|
|
32
|
+
}
|
|
33
|
+
function useWmWindowRef(binder, id, options) {
|
|
34
|
+
const optionsRef = useRef(options);
|
|
35
|
+
const cleanupRef = useRef(null);
|
|
36
|
+
return useCallback(
|
|
37
|
+
(node) => {
|
|
38
|
+
if (node) {
|
|
39
|
+
cleanupRef.current = binder.bindWindow(id, node, optionsRef.current);
|
|
40
|
+
} else {
|
|
41
|
+
cleanupRef.current?.();
|
|
42
|
+
cleanupRef.current = null;
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
[binder, id]
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { useDesktop, useWindowManager, useWmState, useWmWindow, useWmWindowRef };
|
|
50
|
+
//# sourceMappingURL=react.js.map
|
|
51
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react.ts"],"names":[],"mappings":";;;AAaO,SAAS,iBAAiB,OAAA,EAAyC;AACxE,EAAA,MAAM,CAAC,EAAE,CAAA,GAAI,SAAS,MAAM,mBAAA,CAAoB,OAAO,CAAC,CAAA;AACxD,EAAA,SAAA,CAAU,MAAM,MAAM,EAAA,CAAG,SAAQ,EAAG,CAAC,EAAE,CAAC,CAAA;AACxC,EAAA,OAAO,EAAA;AACT;AAEO,SAAS,WAAW,EAAA,EAAiC;AAC1D,EAAA,OAAO,qBAAqB,EAAA,CAAG,SAAA,EAAW,EAAA,CAAG,QAAA,EAAU,GAAG,QAAQ,CAAA;AACpE;AAEO,SAAS,WAAA,CAAY,IAAmB,EAAA,EAAqC;AAClF,EAAA,MAAM,WAAA,GAAc,WAAA,CAAY,MAAM,EAAA,CAAG,GAAA,CAAI,EAAE,CAAA,EAAG,CAAC,EAAA,EAAI,EAAE,CAAC,CAAA;AAC1D,EAAA,OAAO,oBAAA,CAAqB,EAAA,CAAG,SAAA,EAAW,WAAA,EAAa,WAAW,CAAA;AACpE;AAQO,SAAS,UAAA,CAAW,IAAmB,OAAA,EAA4C;AACxF,EAAA,MAAM,UAAA,GAAa,OAAO,OAAO,CAAA;AACjC,EAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,MAAM,mBAAA,CAAoB,EAAA,EAAI,WAAW,OAAO,CAAA,EAAG,CAAC,EAAE,CAAC,CAAA;AAC9E,EAAA,MAAM,UAAA,GAAa,OAA4B,IAAI,CAAA;AACnD,EAAA,MAAM,GAAA,GAAM,WAAA;AAAA,IACV,CAAC,IAAA,KAAS;AACR,MAAA,IAAI,IAAA,EAAM;AACR,QAAA,UAAA,CAAW,OAAA,GAAU,MAAA,CAAO,WAAA,CAAY,IAAI,CAAA;AAAA,MAC9C,CAAA,MAAO;AACL,QAAA,UAAA,CAAW,OAAA,IAAU;AACrB,QAAA,UAAA,CAAW,OAAA,GAAU,IAAA;AAAA,MACvB;AAAA,IACF,CAAA;AAAA,IACA,CAAC,MAAM;AAAA,GACT;AACA,EAAA,OAAO,EAAE,GAAA,EAAK,MAAA,EAAQ,UAAA,EAAY,OAAO,UAAA,EAAW;AACtD;AAEO,SAAS,cAAA,CACd,MAAA,EACA,EAAA,EACA,OAAA,EACY;AACZ,EAAA,MAAM,UAAA,GAAa,OAAO,OAAO,CAAA;AACjC,EAAA,MAAM,UAAA,GAAa,OAA4B,IAAI,CAAA;AACnD,EAAA,OAAO,WAAA;AAAA,IACL,CAAC,IAAA,KAAS;AACR,MAAA,IAAI,IAAA,EAAM;AACR,QAAA,UAAA,CAAW,UAAU,MAAA,CAAO,UAAA,CAAW,EAAA,EAAI,IAAA,EAAM,WAAW,OAAO,CAAA;AAAA,MACrE,CAAA,MAAO;AACL,QAAA,UAAA,CAAW,OAAA,IAAU;AACrB,QAAA,UAAA,CAAW,OAAA,GAAU,IAAA;AAAA,MACvB;AAAA,IACF,CAAA;AAAA,IACA,CAAC,QAAQ,EAAE;AAAA,GACb;AACF","file":"react.js","sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react'\nimport { createWindowManager } from './core/manager'\nimport type { ManagerOptions, ManagerState, WindowManager, WindowState } from './core/types'\nimport {\n createDesktopBinder,\n type DesktopBinder,\n type DesktopController,\n type DesktopOptions,\n type WindowAttachOptions,\n} from './dom/controller'\n\nexport type ElementRef = (node: HTMLElement | null) => void\n\nexport function useWindowManager(options?: ManagerOptions): WindowManager {\n const [wm] = useState(() => createWindowManager(options))\n useEffect(() => () => wm.destroy(), [wm])\n return wm\n}\n\nexport function useWmState(wm: WindowManager): ManagerState {\n return useSyncExternalStore(wm.subscribe, wm.getState, wm.getState)\n}\n\nexport function useWmWindow(wm: WindowManager, id: string): WindowState | undefined {\n const getSnapshot = useCallback(() => wm.get(id), [wm, id])\n return useSyncExternalStore(wm.subscribe, getSnapshot, getSnapshot)\n}\n\nexport interface UseDesktopResult {\n ref: ElementRef\n binder: DesktopBinder\n controller(): DesktopController | null\n}\n\nexport function useDesktop(wm: WindowManager, options?: DesktopOptions): UseDesktopResult {\n const optionsRef = useRef(options)\n const binder = useMemo(() => createDesktopBinder(wm, optionsRef.current), [wm])\n const cleanupRef = useRef<(() => void) | null>(null)\n const ref = useCallback<ElementRef>(\n (node) => {\n if (node) {\n cleanupRef.current = binder.bindDesktop(node)\n } else {\n cleanupRef.current?.()\n cleanupRef.current = null\n }\n },\n [binder],\n )\n return { ref, binder, controller: binder.controller }\n}\n\nexport function useWmWindowRef(\n binder: DesktopBinder,\n id: string,\n options?: WindowAttachOptions,\n): ElementRef {\n const optionsRef = useRef(options)\n const cleanupRef = useRef<(() => void) | null>(null)\n return useCallback<ElementRef>(\n (node) => {\n if (node) {\n cleanupRef.current = binder.bindWindow(id, node, optionsRef.current)\n } else {\n cleanupRef.current?.()\n cleanupRef.current = null\n }\n },\n [binder, id],\n )\n}\n"]}
|
package/dist/solid.cjs
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkKWLI7JIY_cjs = require('./chunk-KWLI7JIY.cjs');
|
|
4
|
+
var solidJs = require('solid-js');
|
|
5
|
+
|
|
6
|
+
function disposeWithOwner(dispose) {
|
|
7
|
+
if (solidJs.getOwner()) solidJs.onCleanup(dispose);
|
|
8
|
+
}
|
|
9
|
+
function useWindowManager(options) {
|
|
10
|
+
const wm = chunkKWLI7JIY_cjs.createWindowManager(options);
|
|
11
|
+
disposeWithOwner(() => wm.destroy());
|
|
12
|
+
return wm;
|
|
13
|
+
}
|
|
14
|
+
function useWmState(wm) {
|
|
15
|
+
const [state, setState] = solidJs.createSignal(wm.getState());
|
|
16
|
+
disposeWithOwner(wm.subscribe((next) => setState(next)));
|
|
17
|
+
return state;
|
|
18
|
+
}
|
|
19
|
+
function useWmWindow(wm, id) {
|
|
20
|
+
const state = useWmState(wm);
|
|
21
|
+
return () => state().windows[typeof id === "function" ? id() : id];
|
|
22
|
+
}
|
|
23
|
+
function createDesktop(wm, options) {
|
|
24
|
+
const binder = chunkKWLI7JIY_cjs.createDesktopBinder(wm, options);
|
|
25
|
+
return {
|
|
26
|
+
binder,
|
|
27
|
+
desktop(element) {
|
|
28
|
+
const unbind = binder.bindDesktop(element);
|
|
29
|
+
disposeWithOwner(unbind);
|
|
30
|
+
},
|
|
31
|
+
window(id, options2) {
|
|
32
|
+
return (element) => {
|
|
33
|
+
const unbind = binder.bindWindow(id, element, options2);
|
|
34
|
+
disposeWithOwner(unbind);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
exports.createDesktop = createDesktop;
|
|
41
|
+
exports.useWindowManager = useWindowManager;
|
|
42
|
+
exports.useWmState = useWmState;
|
|
43
|
+
exports.useWmWindow = useWmWindow;
|
|
44
|
+
//# sourceMappingURL=solid.cjs.map
|
|
45
|
+
//# sourceMappingURL=solid.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/solid.ts"],"names":["getOwner","onCleanup","createWindowManager","createSignal","createDesktopBinder","options"],"mappings":";;;;;AAUA,SAAS,iBAAiB,OAAA,EAA2B;AACnD,EAAA,IAAIA,gBAAA,EAAS,EAAGC,iBAAA,CAAU,OAAO,CA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 'solid-js'\nimport { createWindowManager } from './core/manager'\nimport type { ManagerOptions, ManagerState, WindowManager, WindowState } from './core/types'\nimport {\n createDesktopBinder,\n type DesktopBinder,\n type DesktopOptions,\n type WindowAttachOptions,\n} from './dom/controller'\n\nfunction disposeWithOwner(dispose: () => void): void {\n if (getOwner()) onCleanup(dispose)\n}\n\nexport function useWindowManager(options?: ManagerOptions): WindowManager {\n const wm = createWindowManager(options)\n disposeWithOwner(() => wm.destroy())\n return wm\n}\n\nexport function useWmState(wm: WindowManager): Accessor<ManagerState> {\n const [state, setState] = createSignal(wm.getState())\n disposeWithOwner(wm.subscribe((next) => setState(next)))\n return state\n}\n\nexport function useWmWindow(\n wm: WindowManager,\n id: string | Accessor<string>,\n): Accessor<WindowState | undefined> {\n const state = useWmState(wm)\n return () => state().windows[typeof id === 'function' ? id() : id]\n}\n\nexport interface SolidDesktop {\n binder: DesktopBinder\n desktop(element: HTMLElement): void\n window(id: string, options?: WindowAttachOptions): (element: HTMLElement) => void\n}\n\nexport function createDesktop(wm: WindowManager, options?: DesktopOptions): SolidDesktop {\n const binder = createDesktopBinder(wm, options)\n return {\n binder,\n desktop(element) {\n const unbind = binder.bindDesktop(element)\n disposeWithOwner(unbind)\n },\n window(id, options) {\n return (element) => {\n const unbind = binder.bindWindow(id, element, options)\n disposeWithOwner(unbind)\n }\n },\n }\n}\n"]}
|
package/dist/solid.d.cts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Accessor } from 'solid-js';
|
|
2
|
+
import { W as WindowManager, M as ManagerOptions, b as ManagerState, i as WindowState } from './types-CtFzL_oA.cjs';
|
|
3
|
+
import { D as DesktopBinder, W as WindowAttachOptions, d as DesktopOptions } from './controller-B0bogK9N.cjs';
|
|
4
|
+
|
|
5
|
+
declare function useWindowManager(options?: ManagerOptions): WindowManager;
|
|
6
|
+
declare function useWmState(wm: WindowManager): Accessor<ManagerState>;
|
|
7
|
+
declare function useWmWindow(wm: WindowManager, id: string | Accessor<string>): Accessor<WindowState | undefined>;
|
|
8
|
+
interface SolidDesktop {
|
|
9
|
+
binder: DesktopBinder;
|
|
10
|
+
desktop(element: HTMLElement): void;
|
|
11
|
+
window(id: string, options?: WindowAttachOptions): (element: HTMLElement) => void;
|
|
12
|
+
}
|
|
13
|
+
declare function createDesktop(wm: WindowManager, options?: DesktopOptions): SolidDesktop;
|
|
14
|
+
|
|
15
|
+
export { type SolidDesktop, createDesktop, useWindowManager, useWmState, useWmWindow };
|
package/dist/solid.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Accessor } from 'solid-js';
|
|
2
|
+
import { W as WindowManager, M as ManagerOptions, b as ManagerState, i as WindowState } from './types-CtFzL_oA.js';
|
|
3
|
+
import { D as DesktopBinder, W as WindowAttachOptions, d as DesktopOptions } from './controller-D5zIriLg.js';
|
|
4
|
+
|
|
5
|
+
declare function useWindowManager(options?: ManagerOptions): WindowManager;
|
|
6
|
+
declare function useWmState(wm: WindowManager): Accessor<ManagerState>;
|
|
7
|
+
declare function useWmWindow(wm: WindowManager, id: string | Accessor<string>): Accessor<WindowState | undefined>;
|
|
8
|
+
interface SolidDesktop {
|
|
9
|
+
binder: DesktopBinder;
|
|
10
|
+
desktop(element: HTMLElement): void;
|
|
11
|
+
window(id: string, options?: WindowAttachOptions): (element: HTMLElement) => void;
|
|
12
|
+
}
|
|
13
|
+
declare function createDesktop(wm: WindowManager, options?: DesktopOptions): SolidDesktop;
|
|
14
|
+
|
|
15
|
+
export { type SolidDesktop, createDesktop, useWindowManager, useWmState, useWmWindow };
|
package/dist/solid.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createWindowManager, createDesktopBinder } from './chunk-7HHDQEBI.js';
|
|
2
|
+
import { createSignal, getOwner, onCleanup } from 'solid-js';
|
|
3
|
+
|
|
4
|
+
function disposeWithOwner(dispose) {
|
|
5
|
+
if (getOwner()) onCleanup(dispose);
|
|
6
|
+
}
|
|
7
|
+
function useWindowManager(options) {
|
|
8
|
+
const wm = createWindowManager(options);
|
|
9
|
+
disposeWithOwner(() => wm.destroy());
|
|
10
|
+
return wm;
|
|
11
|
+
}
|
|
12
|
+
function useWmState(wm) {
|
|
13
|
+
const [state, setState] = createSignal(wm.getState());
|
|
14
|
+
disposeWithOwner(wm.subscribe((next) => setState(next)));
|
|
15
|
+
return state;
|
|
16
|
+
}
|
|
17
|
+
function useWmWindow(wm, id) {
|
|
18
|
+
const state = useWmState(wm);
|
|
19
|
+
return () => state().windows[typeof id === "function" ? id() : id];
|
|
20
|
+
}
|
|
21
|
+
function createDesktop(wm, options) {
|
|
22
|
+
const binder = createDesktopBinder(wm, options);
|
|
23
|
+
return {
|
|
24
|
+
binder,
|
|
25
|
+
desktop(element) {
|
|
26
|
+
const unbind = binder.bindDesktop(element);
|
|
27
|
+
disposeWithOwner(unbind);
|
|
28
|
+
},
|
|
29
|
+
window(id, options2) {
|
|
30
|
+
return (element) => {
|
|
31
|
+
const unbind = binder.bindWindow(id, element, options2);
|
|
32
|
+
disposeWithOwner(unbind);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { createDesktop, useWindowManager, useWmState, useWmWindow };
|
|
39
|
+
//# sourceMappingURL=solid.js.map
|
|
40
|
+
//# sourceMappingURL=solid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/solid.ts"],"names":["options"],"mappings":";;;AAUA,SAAS,iBAAiB,OAAA,EAA2B;AACnD,EAAA,IAAI,QAAA,EAAS,EAAG,SAAA,CAAU,OAAO,CAAA;AACnC;AAEO,SAAS,iBAAiB,OAAA,EAAyC;AACxE,EAAA,MAAM,EAAA,GAAK,oBAAoB,OAAO,CAAA;AACtC,EAAA,gBAAA,CAAiB,MAAM,EAAA,CAAG,OAAA,EAAS,CAAA;AACnC,EAAA,OAAO,EAAA;AACT;AAEO,SAAS,WAAW,EAAA,EAA2C;AACpE,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,IAAI,YAAA,CAAa,EAAA,CAAG,UAAU,CAAA;AACpD,EAAA,gBAAA,CAAiB,GAAG,SAAA,CAAU,CAAC,SAAS,QAAA,CAAS,IAAI,CAAC,CAAC,CAAA;AACvD,EAAA,OAAO,KAAA;AACT;AAEO,SAAS,WAAA,CACd,IACA,EAAA,EACmC;AACnC,EAAA,MAAM,KAAA,GAAQ,WAAW,EAAE,CAAA;AAC3B,EAAA,OAAO,MAAM,OAAM,CAAE,OAAA,CAAQ,OAAO,EAAA,KAAO,UAAA,GAAa,EAAA,EAAG,GAAI,EAAE,CAAA;AACnE;AAQO,SAAS,aAAA,CAAc,IAAmB,OAAA,EAAwC;AACvF,EAAA,MAAM,MAAA,GAAS,mBAAA,CAAoB,EAAA,EAAI,OAAO,CAAA;AAC9C,EAAA,OAAO;AAAA,IACL,MAAA;AAAA,IACA,QAAQ,OAAA,EAAS;AACf,MAAA,MAAM,MAAA,GAAS,MAAA,CAAO,WAAA,CAAY,OAAO,CAAA;AACzC,MAAA,gBAAA,CAAiB,MAAM,CAAA;AAAA,IACzB,CAAA;AAAA,IACA,MAAA,CAAO,IAAIA,QAAAA,EAAS;AAClB,MAAA,OAAO,CAAC,OAAA,KAAY;AAClB,QAAA,MAAM,MAAA,GAAS,MAAA,CAAO,UAAA,CAAW,EAAA,EAAI,SAASA,QAAO,CAAA;AACrD,QAAA,gBAAA,CAAiB,MAAM,CAAA;AAAA,MACzB,CAAA;AAAA,IACF;AAAA,GACF;AACF","file":"solid.js","sourcesContent":["import { type Accessor, createSignal, getOwner, onCleanup } from 'solid-js'\nimport { createWindowManager } from './core/manager'\nimport type { ManagerOptions, ManagerState, WindowManager, WindowState } from './core/types'\nimport {\n createDesktopBinder,\n type DesktopBinder,\n type DesktopOptions,\n type WindowAttachOptions,\n} from './dom/controller'\n\nfunction disposeWithOwner(dispose: () => void): void {\n if (getOwner()) onCleanup(dispose)\n}\n\nexport function useWindowManager(options?: ManagerOptions): WindowManager {\n const wm = createWindowManager(options)\n disposeWithOwner(() => wm.destroy())\n return wm\n}\n\nexport function useWmState(wm: WindowManager): Accessor<ManagerState> {\n const [state, setState] = createSignal(wm.getState())\n disposeWithOwner(wm.subscribe((next) => setState(next)))\n return state\n}\n\nexport function useWmWindow(\n wm: WindowManager,\n id: string | Accessor<string>,\n): Accessor<WindowState | undefined> {\n const state = useWmState(wm)\n return () => state().windows[typeof id === 'function' ? id() : id]\n}\n\nexport interface SolidDesktop {\n binder: DesktopBinder\n desktop(element: HTMLElement): void\n window(id: string, options?: WindowAttachOptions): (element: HTMLElement) => void\n}\n\nexport function createDesktop(wm: WindowManager, options?: DesktopOptions): SolidDesktop {\n const binder = createDesktopBinder(wm, options)\n return {\n binder,\n desktop(element) {\n const unbind = binder.bindDesktop(element)\n disposeWithOwner(unbind)\n },\n window(id, options) {\n return (element) => {\n const unbind = binder.bindWindow(id, element, options)\n disposeWithOwner(unbind)\n }\n },\n }\n}\n"]}
|