@synnaxlabs/drift 0.36.0 → 0.38.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 (65) hide show
  1. package/dist/debounce-BUAIXXZt.cjs +1 -0
  2. package/dist/debounce-DOZKRZa9.js +9 -0
  3. package/dist/electron.cjs +1 -0
  4. package/dist/electron.js +256 -0
  5. package/dist/index.cjs +1 -0
  6. package/dist/index.js +491 -0
  7. package/dist/react.cjs +1 -0
  8. package/dist/react.js +70 -0
  9. package/dist/selectors-CDBV8JlK.js +25 -0
  10. package/dist/selectors-DSYdcjUd.cjs +1 -0
  11. package/dist/src/configureStore.d.ts +43 -0
  12. package/dist/src/configureStore.d.ts.map +1 -0
  13. package/dist/src/debug.d.ts +4 -0
  14. package/dist/src/debug.d.ts.map +1 -0
  15. package/dist/src/electron/index.d.ts +49 -0
  16. package/dist/src/electron/index.d.ts.map +1 -0
  17. package/dist/src/external.d.ts +8 -0
  18. package/dist/src/external.d.ts.map +1 -0
  19. package/dist/src/index.d.ts +3 -0
  20. package/dist/src/index.d.ts.map +1 -0
  21. package/dist/src/middleware.d.ts +27 -0
  22. package/dist/src/middleware.d.ts.map +1 -0
  23. package/dist/src/middleware.spec.d.ts +2 -0
  24. package/dist/src/middleware.spec.d.ts.map +1 -0
  25. package/dist/src/mock/index.d.ts +2 -0
  26. package/dist/src/mock/index.d.ts.map +1 -0
  27. package/dist/src/mock/runtime.d.ts +44 -0
  28. package/dist/src/mock/runtime.d.ts.map +1 -0
  29. package/dist/src/react/Provider.d.ts +23 -0
  30. package/dist/src/react/Provider.d.ts.map +1 -0
  31. package/dist/src/react/hooks.d.ts +15 -0
  32. package/dist/src/react/hooks.d.ts.map +1 -0
  33. package/dist/src/react/index.d.ts +4 -0
  34. package/dist/src/react/index.d.ts.map +1 -0
  35. package/dist/src/react/selectors.d.ts +13 -0
  36. package/dist/src/react/selectors.d.ts.map +1 -0
  37. package/dist/src/runtime.d.ts +99 -0
  38. package/dist/src/runtime.d.ts.map +1 -0
  39. package/dist/src/selectors.d.ts +9 -0
  40. package/dist/src/selectors.d.ts.map +1 -0
  41. package/dist/src/serialization/index.d.ts +6 -0
  42. package/dist/src/serialization/index.d.ts.map +1 -0
  43. package/dist/src/state.d.ts +100 -0
  44. package/dist/src/state.d.ts.map +1 -0
  45. package/dist/src/sugar.d.ts +24 -0
  46. package/dist/src/sugar.d.ts.map +1 -0
  47. package/dist/src/sugar.spec.d.ts +2 -0
  48. package/dist/src/sugar.spec.d.ts.map +1 -0
  49. package/dist/src/sync.d.ts +11 -0
  50. package/dist/src/sync.d.ts.map +1 -0
  51. package/dist/src/sync.spec.d.ts +2 -0
  52. package/dist/src/sync.spec.d.ts.map +1 -0
  53. package/dist/src/tauri/index.d.ts +47 -0
  54. package/dist/src/tauri/index.d.ts.map +1 -0
  55. package/dist/src/validate.d.ts +11 -0
  56. package/dist/src/validate.d.ts.map +1 -0
  57. package/dist/src/validate.spec.d.ts +2 -0
  58. package/dist/src/validate.spec.d.ts.map +1 -0
  59. package/dist/src/window.d.ts +177 -0
  60. package/dist/src/window.d.ts.map +1 -0
  61. package/dist/state--TjGqMVk.cjs +13 -0
  62. package/dist/state-B6yPmERI.js +5918 -0
  63. package/dist/tauri.cjs +1 -0
  64. package/dist/tauri.js +2712 -0
  65. package/package.json +9 -10
@@ -0,0 +1 @@
1
+ "use strict";const n=(l,u)=>{let t=null;return u===0?l:(...e)=>{t!==null&&(clearTimeout(t),t=null),t=setTimeout(()=>l(...e),u)}};exports.o=n;
@@ -0,0 +1,9 @@
1
+ const n = (l, e) => {
2
+ let t = null;
3
+ return e === 0 ? l : (...u) => {
4
+ t !== null && (clearTimeout(t), t = null), t = setTimeout(() => l(...u), e);
5
+ };
6
+ };
7
+ export {
8
+ n as o
9
+ };
@@ -0,0 +1 @@
1
+ "use strict";var R=Object.defineProperty;var B=(t,e,o)=>e in t?R(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var _=(t,e,o)=>B(t,typeof e!="symbol"?e+"":e,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./state--TjGqMVk.cjs"),H=require("./debounce-BUAIXXZt.cjs"),E="drift://action",p="drift://create",w="drift://focus",b="drift://close",I="drift://set-minimized",N="drift://set-maximized",z="drift://set-visible",y="drift://set-fullscreen",M="drift://center",O="drift://set-position",A="drift://set-size",g="drift://set-min-size",V="drift://set-max-size",x="drift://set-resizable",W="drift://set-skip-taskbar",P="drift://set-always-on-top",k="drift://set-title",L="drift://set-decorations",S="drift://get-props",D="drift://get-label",Z=[E,p,w,b,I,N,z,y,M,O,A,g,V,x,W,P,k,L,S],q=t=>{if(!Z.includes(t))throw new Error(`Event ${t} is not on the list of allowed events`)},F=[E],U=t=>{if(!F.includes(t))throw new Error(`Event ${t} is not on the list of allowed events`)},$=[S,D],G=t=>{if(!$.includes(t))throw new Error(`Command ${t} is not on the list of allowed commands`)},J=t=>{var e,o,r,l,u,d,m,f;return{x:(e=t.position)==null?void 0:e.x,y:(o=t.position)==null?void 0:o.y,width:(r=t.size)==null?void 0:r.width,height:(l=t.size)==null?void 0:l.height,center:t.center,minHeight:(u=t.minSize)==null?void 0:u.height,minWidth:(d=t.minSize)==null?void 0:d.width,maxHeight:(m=t.maxSize)==null?void 0:m.height,maxWidth:(f=t.maxSize)==null?void 0:f.width,resizable:t.resizable,fullscreen:t.fullscreen,skipTaskbar:t.skipTaskbar,title:t.title,show:t.visible,transparent:t.transparent,alwaysOnTop:t.alwaysOnTop}},K=t=>{const[e,o]=t.getSize(),[r,l]=t.getPosition();return{size:{width:e,height:o},position:{x:r,y:l},minimized:t.isMinimized(),maximized:t.isMaximized(),fullscreen:t.isFullScreen(),visible:t.isVisible(),resizable:t.isResizable(),skipTaskbar:!1,title:t.getTitle(),alwaysOnTop:t.isAlwaysOnTop(),decorations:!1}},X=({mainWindow:t,createWindow:e})=>{const o=new Map,r=new Map;o.set(h.MAIN_WINDOW,t.id),r.set(t.id,h.MAIN_WINDOW);const{ipcMain:l,BrowserWindow:u}=require("electron"),d=(s,i)=>l.on(s,(n,a)=>{const c=u.fromWebContents(n.sender);c!=null&&i(c,a)});l.on(b,(s,i)=>{const n=o.get(i);if(n==null)return;const a=u.fromId(n);a!=null&&(a.close(),o.delete(i),r.delete(n))}),l.handle(S,s=>{const i=u.fromWebContents(s.sender);return i==null?void 0:{...K(i),label:r.get(i.id)}}),l.handle(D,s=>{const i=u.fromWebContents(s.sender);if(i!=null)return r.get(i.id)});const m=(s,i,n)=>{s.on(i,H.o(n,500))},f=s=>{var i;for(const n of r.keys())(i=u.fromId(n))==null||i.webContents.send(E,s)},C=(s,i)=>{const n=(a,c)=>{m(i,a,()=>{f({action:h.runtimeSetWindowProps({label:s,...c(i)}),emitter:"WHITELIST"})})};n("resize",a=>{const[c,v]=a.getSize();return{size:{width:c,height:v}}}),n("move",()=>{const[a,c]=i.getPosition();return{position:{x:a,y:c}}}),n("minimize",()=>({minimized:!0})),n("restore",()=>({minimized:!1})),n("maximize",()=>({maximized:!0})),n("unmaximize",()=>({maximized:!1})),n("enter-full-screen",a=>(a.setWindowButtonVisibility(!0),{fullscreen:!0})),n("leave-full-screen",()=>(i.setWindowButtonVisibility(!1),{fullscreen:!1}))};C(h.MAIN_WINDOW,t),d(w,s=>s.focus()),d(I,s=>s.minimize()),d(N,s=>s.maximize()),d(z,(s,i)=>i?s.show():s.hide()),d(y,s=>s.setFullScreen(!0)),d(M,s=>s.center()),d(O,(s,{x:i,y:n})=>{s.setPosition(Math.round(i),Math.round(n))}),d(A,(s,{width:i,height:n})=>{s.setSize(Math.round(i),Math.round(n))}),d(g,(s,{width:i,height:n})=>s.setMinimumSize(Math.round(i),Math.round(n))),d(V,(s,{width:i,height:n})=>s.setMaximumSize(Math.round(i),Math.round(n))),d(x,(s,i)=>s.setResizable(i)),d(W,(s,i)=>s.setSkipTaskbar(i)),d(P,(s,i)=>s.setAlwaysOnTop(i)),d(k,(s,i)=>s.setTitle(i)),l.on(p,(s,i,n)=>{const a=e(J(n));o.set(i,a.id),r.set(a.id,i),C(i,a)}),l.on(E,(s,i,n)=>{if(i==null)return;if(n==null)return f(i);const a=o.get(n);if(a==null)return;const c=u.fromId(a);c!=null&&c.webContents.send(E,i)})},T="driftAPI",j=()=>{const{ipcRenderer:t,contextBridge:e}=require("electron"),o={send:(r,...l)=>{q(r),t.send(r,...l)},invoke:async(r,...l)=>(G(r),await t.invoke(r,...l)),on:(r,l)=>{U(r),t.on(r,l)}};e.exposeInMainWorld(T,o)},Y=async()=>{if(!(T in window))throw new Error("Drift API not found. Make sure to call configurePreload in your preload script.");return await window[T].invoke(D)};class Q{constructor(){_(this,"_label","");_(this,"props",null);_(this,"api");if(!(T in window))throw new Error("Drift API not found. Make sure to call configurePreload in your preload script.");this.api=window[T]}async configure(){const{label:e,...o}=await this.api.invoke(S);this._label=e,this.props=o}label(){return this._label}isMain(){return this._label===h.MAIN_WINDOW}release(){}async emit(e,o){this.api.send(E,{...e,emitter:this.label()},o)}async subscribe(e){this.api.on(E,(o,r)=>e(r))}onCloseRequested(){}async create(e,o){this.api.send(p,e,JSON.parse(JSON.stringify(o)))}async close(e){this.api.send(b,e)}async listLabels(){return[]}async focus(){this.api.send(w)}async setMinimized(e){this.api.send(I,e)}async setMaximized(e){this.api.send(N,e)}async setVisible(e){this.api.send(z,e)}async setFullscreen(e){this.api.send(y,e)}async center(){this.api.send(M)}async setPosition(e){this.api.send(O,e)}async setSize(e){this.api.send(A,e)}async setMinSize(e){this.api.send(g,e)}async setMaxSize(e){this.api.send(V,e)}async setResizable(e){this.api.send(x,e)}async setSkipTaskbar(e){this.api.send(W,e)}async setAlwaysOnTop(e){this.api.send(P,e)}async setTitle(e){this.api.send(k,e)}async setDecorations(e){this.api.send(L,e)}async getProps(){if(this.props!=null)return this.props;throw new Error("Window not found")}}exports.ElectronRuntime=Q;exports.exposeAPI=j;exports.getWindowLabel=Y;exports.listenOnMain=X;
@@ -0,0 +1,256 @@
1
+ var R = Object.defineProperty;
2
+ var B = (t, e, o) => e in t ? R(t, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : t[e] = o;
3
+ var m = (t, e, o) => B(t, typeof e != "symbol" ? e + "" : e, o);
4
+ import { M as _, r as H } from "./state-B6yPmERI.js";
5
+ import { o as Z } from "./debounce-DOZKRZa9.js";
6
+ const E = "drift://action", S = "drift://create", w = "drift://focus", z = "drift://close", b = "drift://set-minimized", y = "drift://set-maximized", I = "drift://set-visible", N = "drift://set-fullscreen", M = "drift://center", O = "drift://set-position", g = "drift://set-size", A = "drift://set-min-size", V = "drift://set-max-size", x = "drift://set-resizable", k = "drift://set-skip-taskbar", C = "drift://set-always-on-top", P = "drift://set-title", L = "drift://set-decorations", p = "drift://get-props", W = "drift://get-label", F = [
7
+ E,
8
+ S,
9
+ w,
10
+ z,
11
+ b,
12
+ y,
13
+ I,
14
+ N,
15
+ M,
16
+ O,
17
+ g,
18
+ A,
19
+ V,
20
+ x,
21
+ k,
22
+ C,
23
+ P,
24
+ L,
25
+ p
26
+ ], U = (t) => {
27
+ if (!F.includes(t))
28
+ throw new Error(`Event ${t} is not on the list of allowed events`);
29
+ }, q = [E], $ = (t) => {
30
+ if (!q.includes(t))
31
+ throw new Error(`Event ${t} is not on the list of allowed events`);
32
+ }, G = [p, W], J = (t) => {
33
+ if (!G.includes(t))
34
+ throw new Error(`Command ${t} is not on the list of allowed commands`);
35
+ }, K = (t) => {
36
+ var e, o, r, l, u, d, T, f;
37
+ return {
38
+ x: (e = t.position) == null ? void 0 : e.x,
39
+ y: (o = t.position) == null ? void 0 : o.y,
40
+ width: (r = t.size) == null ? void 0 : r.width,
41
+ height: (l = t.size) == null ? void 0 : l.height,
42
+ center: t.center,
43
+ minHeight: (u = t.minSize) == null ? void 0 : u.height,
44
+ minWidth: (d = t.minSize) == null ? void 0 : d.width,
45
+ maxHeight: (T = t.maxSize) == null ? void 0 : T.height,
46
+ maxWidth: (f = t.maxSize) == null ? void 0 : f.width,
47
+ resizable: t.resizable,
48
+ fullscreen: t.fullscreen,
49
+ skipTaskbar: t.skipTaskbar,
50
+ title: t.title,
51
+ show: t.visible,
52
+ transparent: t.transparent,
53
+ alwaysOnTop: t.alwaysOnTop
54
+ };
55
+ }, X = (t) => {
56
+ const [e, o] = t.getSize(), [r, l] = t.getPosition();
57
+ return {
58
+ size: { width: e, height: o },
59
+ position: { x: r, y: l },
60
+ minimized: t.isMinimized(),
61
+ maximized: t.isMaximized(),
62
+ fullscreen: t.isFullScreen(),
63
+ visible: t.isVisible(),
64
+ resizable: t.isResizable(),
65
+ skipTaskbar: !1,
66
+ title: t.getTitle(),
67
+ alwaysOnTop: t.isAlwaysOnTop(),
68
+ decorations: !1
69
+ };
70
+ }, ee = ({ mainWindow: t, createWindow: e }) => {
71
+ const o = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
72
+ o.set(_, t.id), r.set(t.id, _);
73
+ const { ipcMain: l, BrowserWindow: u } = require("electron"), d = (s, i) => l.on(s, (n, a) => {
74
+ const c = u.fromWebContents(n.sender);
75
+ c != null && i(c, a);
76
+ });
77
+ l.on(z, (s, i) => {
78
+ const n = o.get(i);
79
+ if (n == null) return;
80
+ const a = u.fromId(n);
81
+ a != null && (a.close(), o.delete(i), r.delete(n));
82
+ }), l.handle(p, (s) => {
83
+ const i = u.fromWebContents(s.sender);
84
+ return i == null ? void 0 : { ...X(i), label: r.get(i.id) };
85
+ }), l.handle(W, (s) => {
86
+ const i = u.fromWebContents(s.sender);
87
+ if (i != null)
88
+ return r.get(i.id);
89
+ });
90
+ const T = (s, i, n) => {
91
+ s.on(i, Z(n, 500));
92
+ }, f = (s) => {
93
+ var i;
94
+ for (const n of r.keys())
95
+ (i = u.fromId(n)) == null || i.webContents.send(E, s);
96
+ }, D = (s, i) => {
97
+ const n = (a, c) => {
98
+ T(i, a, () => {
99
+ f({
100
+ action: H({ label: s, ...c(i) }),
101
+ emitter: "WHITELIST"
102
+ });
103
+ });
104
+ };
105
+ n("resize", (a) => {
106
+ const [c, v] = a.getSize();
107
+ return { size: { width: c, height: v } };
108
+ }), n("move", () => {
109
+ const [a, c] = i.getPosition();
110
+ return { position: { x: a, y: c } };
111
+ }), n("minimize", () => ({ minimized: !0 })), n("restore", () => ({ minimized: !1 })), n("maximize", () => ({ maximized: !0 })), n("unmaximize", () => ({ maximized: !1 })), n("enter-full-screen", (a) => (a.setWindowButtonVisibility(!0), { fullscreen: !0 })), n("leave-full-screen", () => (i.setWindowButtonVisibility(!1), { fullscreen: !1 }));
112
+ };
113
+ D(_, t), d(w, (s) => s.focus()), d(b, (s) => s.minimize()), d(y, (s) => s.maximize()), d(I, (s, i) => i ? s.show() : s.hide()), d(N, (s) => s.setFullScreen(!0)), d(M, (s) => s.center()), d(O, (s, { x: i, y: n }) => {
114
+ s.setPosition(Math.round(i), Math.round(n));
115
+ }), d(g, (s, { width: i, height: n }) => {
116
+ s.setSize(Math.round(i), Math.round(n));
117
+ }), d(
118
+ A,
119
+ (s, { width: i, height: n }) => s.setMinimumSize(Math.round(i), Math.round(n))
120
+ ), d(
121
+ V,
122
+ (s, { width: i, height: n }) => s.setMaximumSize(Math.round(i), Math.round(n))
123
+ ), d(x, (s, i) => s.setResizable(i)), d(
124
+ k,
125
+ (s, i) => s.setSkipTaskbar(i)
126
+ ), d(
127
+ C,
128
+ (s, i) => s.setAlwaysOnTop(i)
129
+ ), d(P, (s, i) => s.setTitle(i)), l.on(
130
+ S,
131
+ (s, i, n) => {
132
+ const a = e(K(n));
133
+ o.set(i, a.id), r.set(a.id, i), D(i, a);
134
+ }
135
+ ), l.on(E, (s, i, n) => {
136
+ if (i == null) return;
137
+ if (n == null) return f(i);
138
+ const a = o.get(n);
139
+ if (a == null) return;
140
+ const c = u.fromId(a);
141
+ c != null && c.webContents.send(E, i);
142
+ });
143
+ }, h = "driftAPI", te = () => {
144
+ const { ipcRenderer: t, contextBridge: e } = require("electron"), o = {
145
+ send: (r, ...l) => {
146
+ U(r), t.send(r, ...l);
147
+ },
148
+ invoke: async (r, ...l) => (J(r), await t.invoke(r, ...l)),
149
+ on: (r, l) => {
150
+ $(r), t.on(r, l);
151
+ }
152
+ };
153
+ e.exposeInMainWorld(h, o);
154
+ }, ie = async () => {
155
+ if (!(h in window))
156
+ throw new Error(
157
+ "Drift API not found. Make sure to call configurePreload in your preload script."
158
+ );
159
+ return await window[h].invoke(W);
160
+ };
161
+ class se {
162
+ constructor() {
163
+ m(this, "_label", "");
164
+ m(this, "props", null);
165
+ m(this, "api");
166
+ if (!(h in window))
167
+ throw new Error(
168
+ "Drift API not found. Make sure to call configurePreload in your preload script."
169
+ );
170
+ this.api = window[h];
171
+ }
172
+ async configure() {
173
+ const { label: e, ...o } = await this.api.invoke(p);
174
+ this._label = e, this.props = o;
175
+ }
176
+ label() {
177
+ return this._label;
178
+ }
179
+ isMain() {
180
+ return this._label === _;
181
+ }
182
+ release() {
183
+ }
184
+ async emit(e, o) {
185
+ this.api.send(E, { ...e, emitter: this.label() }, o);
186
+ }
187
+ async subscribe(e) {
188
+ this.api.on(E, (o, r) => e(r));
189
+ }
190
+ onCloseRequested() {
191
+ }
192
+ async create(e, o) {
193
+ this.api.send(S, e, JSON.parse(JSON.stringify(o)));
194
+ }
195
+ async close(e) {
196
+ this.api.send(z, e);
197
+ }
198
+ async listLabels() {
199
+ return [];
200
+ }
201
+ async focus() {
202
+ this.api.send(w);
203
+ }
204
+ async setMinimized(e) {
205
+ this.api.send(b, e);
206
+ }
207
+ async setMaximized(e) {
208
+ this.api.send(y, e);
209
+ }
210
+ async setVisible(e) {
211
+ this.api.send(I, e);
212
+ }
213
+ async setFullscreen(e) {
214
+ this.api.send(N, e);
215
+ }
216
+ async center() {
217
+ this.api.send(M);
218
+ }
219
+ async setPosition(e) {
220
+ this.api.send(O, e);
221
+ }
222
+ async setSize(e) {
223
+ this.api.send(g, e);
224
+ }
225
+ async setMinSize(e) {
226
+ this.api.send(A, e);
227
+ }
228
+ async setMaxSize(e) {
229
+ this.api.send(V, e);
230
+ }
231
+ async setResizable(e) {
232
+ this.api.send(x, e);
233
+ }
234
+ async setSkipTaskbar(e) {
235
+ this.api.send(k, e);
236
+ }
237
+ async setAlwaysOnTop(e) {
238
+ this.api.send(C, e);
239
+ }
240
+ async setTitle(e) {
241
+ this.api.send(P, e);
242
+ }
243
+ async setDecorations(e) {
244
+ this.api.send(L, e);
245
+ }
246
+ async getProps() {
247
+ if (this.props != null) return this.props;
248
+ throw new Error("Window not found");
249
+ }
250
+ }
251
+ export {
252
+ se as ElectronRuntime,
253
+ te as exposeAPI,
254
+ ie as getWindowLabel,
255
+ ee as listenOnMain
256
+ };
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("@reduxjs/toolkit"),t=require("./state--TjGqMVk.cjs"),f=require("./selectors-DSYdcjUd.cjs"),C=new Error("request for lock canceled");var L=function(i,e,s,o){function n(a){return a instanceof s?a:new s(function(r){r(a)})}return new(s||(s=Promise))(function(a,r){function l(c){try{u(o.next(c))}catch(w){r(w)}}function d(c){try{u(o.throw(c))}catch(w){r(w)}}function u(c){c.done?a(c.value):n(c.value).then(l,d)}u((o=o.apply(i,e||[])).next())})};class N{constructor(e,s=C){this._value=e,this._cancelError=s,this._queue=[],this._weightedWaiters=[]}acquire(e=1,s=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((o,n)=>{const a={resolve:o,reject:n,weight:e,priority:s},r=E(this._queue,l=>s<=l.priority);r===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(r+1,0,a)})}runExclusive(e){return L(this,arguments,void 0,function*(s,o=1,n=0){const[a,r]=yield this.acquire(o,n);try{return yield s(a)}finally{r()}})}waitForUnlock(e=1,s=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,s)?Promise.resolve():new Promise(o=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),P(this._weightedWaiters[e-1],{resolve:o,priority:s})})}isLocked(){return this._value<=0}getValue(){return this._value}setValue(e){this._value=e,this._dispatchQueue()}release(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);this._value+=e,this._dispatchQueue()}cancel(){this._queue.forEach(e=>e.reject(this._cancelError)),this._queue=[]}_dispatchQueue(){for(this._drainUnlockWaiters();this._queue.length>0&&this._queue[0].weight<=this._value;)this._dispatchItem(this._queue.shift()),this._drainUnlockWaiters()}_dispatchItem(e){const s=this._value;this._value-=e.weight,e.resolve([s,this._newReleaser(e.weight)])}_newReleaser(e){let s=!1;return()=>{s||(s=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const s=this._weightedWaiters[e-1];s&&(s.forEach(o=>o.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let s=this._value;s>0;s--){const o=this._weightedWaiters[s-1];if(!o)continue;const n=o.findIndex(a=>a.priority<=e);(n===-1?o:o.splice(0,n)).forEach(a=>a.resolve())}}}_couldLockImmediately(e,s){return(this._queue.length===0||this._queue[0].priority<s)&&e<=this._value}}function P(i,e){const s=E(i,o=>e.priority<=o.priority);i.splice(s+1,0,e)}function E(i,e){for(let s=i.length-1;s>=0;s--)if(e(i[s]))return s;return-1}var q=function(i,e,s,o){function n(a){return a instanceof s?a:new s(function(r){r(a)})}return new(s||(s=Promise))(function(a,r){function l(c){try{u(o.next(c))}catch(w){r(w)}}function d(c){try{u(o.throw(c))}catch(w){r(w)}}function u(c){c.done?a(c.value):n(c.value).then(l,d)}u((o=o.apply(i,e||[])).next())})};class D{constructor(e){this._semaphore=new N(1,e)}acquire(){return q(this,arguments,void 0,function*(e=0){const[,s]=yield this._semaphore.acquire(1,e);return s})}runExclusive(e,s=0){return this._semaphore.runExclusive(()=>e(),1,s)}isLocked(){return this._semaphore.isLocked()}waitForUnlock(e=0){return this._semaphore.waitForUnlock(1,e)}release(){this._semaphore.isLocked()&&this._semaphore.release()}cancel(){return this._semaphore.cancel()}}const R=i=>[...new Set(i)],F=(i,e,s=!0)=>{const o=new Map;return i.forEach(n=>{const a=e(n);if(o.has(a)){if(s)return;o.delete(a)}o.set(a,n)}),Array.from(o.values())},V=Object.freeze(Object.defineProperty({__proto__:null,by:F,unique:R},Symbol.toStringTag,{value:"Module"})),T="DA@",I="://",j=(i,e)=>T.concat(e,I,i),Z=i=>{const[e,s]=i.split(I);if(s==null)return[i,""];const[,o]=e.split(T);return[s,o]},b=(i,e)=>({...i,type:j(i.type,e)}),U=i=>{const[e,s]=Z(i.type);return{emitted:s!=null&&s.length>0,emitter:s,action:{...i,type:e}}},K=i=>{const{centerCount:e,processCount:s,focusCount:o,stage:n,key:a,prerenderLabel:r,reserved:l,minimized:d,...u}=i;return u},Q=async(i,e,s,o)=>{const n=(await s.listLabels()).filter(c=>c!==t.MAIN_WINDOW),a=Object.keys(i.windows).filter(c=>c!==t.MAIN_WINDOW);t.group(o,"syncInitial"),t.log(o,"existing windows in runtime",n.sort()),t.log(o,"non-main windows in state",a.sort()),t.groupEnd(o);const r=V.unique([...n,...a]);for(const c of r)!n.includes(c)&&s.isMain()?(t.log(o,"state window not in runtime, creating",c),await k(s,c,i.windows[c],o)):a.includes(c)||(t.log(o,"runtime window not in state, closing",c),await p(s,c,o));const l=s.label(),d=i.windows[l];if(d==null)return;const u={...t.INITIAL_WINDOW_STATE,key:l};await M(u,d,s,o),e(t.runtimeSetWindowProps({label:s.label(),...await s.getProps()}))},X=async(i,e,s,o)=>{t.log(o,"sync",i,e),s.isMain()&&await $(i,e,s,o);const n=i.windows[s.label()],a=e.windows[s.label()];n==null||a==null||await M(n,a,s,o)},M=async(i,e,s,o)=>{const n=[];e.title!=null&&e.title!==i.title&&n.push(["title",{prev:i.title,next:e.title},async()=>s.setTitle(e.title)]);const a=e.visible!=null&&e.visible!==i.visible,r=e.visible===!1,l=()=>n.push(["visible",{prev:i.visible,next:e.visible},async()=>{if(await s.setVisible(e.visible),e.visible===!1)return;let d=e.position;d??(d=(await s.getProps()).position),s.setPosition(t.G.translate(d,{x:1,y:1})),s.setPosition(d)}]);if(a&&r&&l(),e.skipTaskbar!=null&&e.skipTaskbar!==i.skipTaskbar&&n.push(["skipTaskbar",{prev:i.skipTaskbar,next:e.skipTaskbar},async()=>await s.setSkipTaskbar(e.skipTaskbar)]),e.maximized!=null&&e.maximized!==i.maximized&&n.push(["maximized",{prev:i.maximized,next:e.maximized},async()=>await s.setMaximized(e.maximized)]),e.fullscreen!=null&&e.fullscreen!==i.fullscreen&&n.push(["fullscreen",{prev:i.fullscreen,next:e.fullscreen},async()=>await s.setFullscreen(e.fullscreen)]),e.centerCount!==i.centerCount&&n.push(["center",{prev:i.centerCount,next:e.centerCount},async()=>s.center()]),e.minimized!=null&&e.minimized!==i.minimized&&n.push(["minimized",{prev:i.minimized,next:e.minimized},async()=>await s.setMinimized(e.minimized)]),e.resizable!=null&&e.resizable!==i.resizable&&n.push(["resizable",{prev:i.resizable,next:e.resizable},async()=>await s.setResizable(e.resizable)]),e.minSize!=null&&!t._.equals(e.minSize,i.minSize)&&n.push(["minSize",{prev:i.minSize,next:e.minSize},async()=>await s.setMinSize(e.minSize)]),e.maxSize!=null&&!t._.equals(e.maxSize,i.maxSize)&&n.push(["maxSize",{prev:i.maxSize,next:e.maxSize},async()=>await s.setMaxSize(e.maxSize)]),e.size!=null&&!t._.equals(e.size,i.size)&&n.push(["size",{prev:i.size,next:e.size},async()=>await s.setSize(e.size)]),e.position!=null&&!t._.equals(e.position,i.position)&&n.push(["position",{prev:i.position,next:e.position},async()=>await s.setPosition(e.position)]),e.focusCount!==i.focusCount&&n.push(["setVisible",{prev:i.visible,next:e.visible},async()=>await s.setVisible(!0)],["focus",{prev:i.focusCount,next:e.focusCount},async()=>await s.focus()]),e.decorations!=null&&e.decorations!==i.decorations&&n.push(["decorations",{prev:i.decorations,next:e.decorations},async()=>await s.setDecorations(e.decorations)]),e.alwaysOnTop!=null&&e.alwaysOnTop!==i.alwaysOnTop&&n.push(["alwaysOnTop",{prev:i.alwaysOnTop,next:e.alwaysOnTop},async()=>await s.setAlwaysOnTop(e.alwaysOnTop)]),a&&!r&&l(),n.length!==0){t.group(o,`syncCurrent, label: ${s.label()}, key: ${e.key}`);for(const[d,{prev:u,next:c}]of n)t.log(o,d,u,"->",c);t.groupEnd(o);for(const[,,d]of n)await d()}},$=async(i,e,s,o)=>{const n=Object.keys(i.windows).filter(l=>!(l in e.windows)),a=Object.keys(e.windows).filter(l=>!(l in i.windows)),r=s.isMain();if(r&&n.length>0)for(const l of n)t.log(o,"syncMain","closing",l),l===t.MAIN_WINDOW&&await Promise.all(Object.keys(e.windows).filter(d=>d!==t.MAIN_WINDOW).map(async d=>await p(s,d,o))),await p(s,l,o);if(r&&a.length>0)for(const l of a)await k(s,l,e.windows[l],o)},k=async(i,e,s,o)=>(t.log(o,"createWindow",s),await i.create(e,K(s))),p=async(i,e,s)=>(t.log(s,"closeWindow",e),await i.close(e)),z="[drift] - unexpected undefined action",m="[drift] - unexpected undefined action type",y=i=>{if(i.emitted??(i.emitted=!1),i.action==null)throw console.warn(z,i),new Error(z);if(i.action.type==null||i.action.type.length===0)throw console.warn(m,i),new Error(m)},G=new D,Y=[t.runtimeSetWindowProps.type,t.reloadWindow.type],B=(i,e=!1)=>({getState:s,dispatch:o})=>n=>a=>{let{action:r,emitted:l,emitter:d}=U(a);const u=i.label();y({action:a,emitted:l,emitter:d});const c=t.isDriftAction(r.type);if(c&&t.log(e,"[drift] - middleware",{action:r,emitted:l,emitter:d,host:u}),d===i.label())return;const w=c&&!Y.includes(r.type);let h=null;c&&(h=s().drift,r=t.assignLabel(r,h));const O=n(r),_=w?s().drift:null,v=t.shouldEmit(l,r.type);return G.runExclusive(async()=>{try{h!==null&&_!==null&&await X(h,_,i,e),v&&await i.emit({action:r})}catch(S){t.log(e,"[drift] - ERROR",{error:S.message,action:r,emitted:l,emitter:d,host:u}),o(t.setWindowError({key:u,message:S.message}))}}),O},H=(i,e,s=!1)=>o=>{const n=i!=null?typeof i=="function"?i(o):i:o();return[B(e,s),...n]},J=async({runtime:i,preloadedState:e,middleware:s,debug:o=!1,enablePrerender:n=!0,defaultWindowProps:a,...r})=>{await i.configure();let l;l=A.configureStore({...r,preloadedState:await x(o,i,()=>l,a,e),middleware:H(s,i,o)}),await Q(l.getState().drift,l.dispatch,i,o);const d=i.label();return l.dispatch(t.internalSetInitial({enablePrerender:n,defaultWindowProps:a,debug:o,label:d})),l.dispatch(t.setWindowStage({stage:"created"})),i.onCloseRequested(()=>l==null?void 0:l.dispatch(t.closeWindow({}))),l},x=async(i,e,s,o,n)=>e.isMain()?(await e.subscribe(({action:r,emitter:l,sendState:d})=>{const u=s();if(u==null)return;if(r!=null){y({action:r,emitter:l}),u.dispatch(b(r,l));return}const c=u.getState();d===!0&&e.emit({state:c},l)}),typeof n=="function"?g(o,i,await n()):g(o,i,n)):await new Promise((r,l)=>{(async()=>{try{await e.subscribe(({action:u,emitter:c,state:w})=>{const h=s();if(h==null)return w!=null?r(w):void 0;u!=null&&(y({action:u,emitter:c}),h.dispatch(b(u,c)))}),await e.emit({sendState:!0},t.MAIN_WINDOW)}catch(u){l(u)}})()}),W=J,g=(i,e,s)=>{if(s==null)return s;const o=s[t.SLICE_NAME];return o.config.debug=e??o.config.debug,o.windows=Object.fromEntries(Object.entries(o.windows).filter(([,n])=>n.reserved).map(([n,a])=>((i==null?void 0:i.visible)!=null&&(a.visible=i.visible),a.focusCount=0,a.centerCount=0,a.processCount=0,[n,a]))),s},ee=Object.freeze(Object.defineProperty({__proto__:null,MAIN_WINDOW:t.MAIN_WINDOW,SLICE_NAME:t.SLICE_NAME,ZERO_SLICE_STATE:t.ZERO_SLICE_STATE,closeWindow:t.closeWindow,completeProcess:t.completeProcess,configureStore:W,createWindow:t.createWindow,focusWindow:t.focusWindow,reducer:t.reducer,registerProcess:t.registerProcess,reloadWindow:t.reloadWindow,selectSliceState:f.selectSliceState,selectWindow:f.selectWindow,selectWindowAttribute:f.selectWindowAttribute,selectWindowKey:f.selectWindowKey,selectWindowLabel:f.selectWindowLabel,selectWindows:f.selectWindows,setWindowAlwaysOnTop:t.setWindowAlwaysOnTop,setWindowDecorations:t.setWindowDecorations,setWindowFullscreen:t.setWindowFullscreen,setWindowMaxSize:t.setWindowMaxSize,setWindowMaximized:t.setWindowMaximized,setWindowMinSize:t.setWindowMinSize,setWindowMinimized:t.setWindowMinimized,setWindowPosition:t.setWindowPosition,setWindowProps:t.setWindowProps,setWindowResizable:t.setWindowResizable,setWindowSize:t.setWindowSize,setWindowSkipTaskbar:t.setWindowSkipTaskbar,setWindowStage:t.setWindowStage,setWindowTitle:t.setWindowTitle,setWindowVisible:t.setWindowVisible,windowPropsZ:t.windowPropsZ},Symbol.toStringTag,{value:"Module"}));exports.MAIN_WINDOW=t.MAIN_WINDOW;exports.SLICE_NAME=t.SLICE_NAME;exports.ZERO_SLICE_STATE=t.ZERO_SLICE_STATE;exports.closeWindow=t.closeWindow;exports.completeProcess=t.completeProcess;exports.createWindow=t.createWindow;exports.focusWindow=t.focusWindow;exports.reducer=t.reducer;exports.registerProcess=t.registerProcess;exports.reloadWindow=t.reloadWindow;exports.setWindowAlwaysOnTop=t.setWindowAlwaysOnTop;exports.setWindowDecorations=t.setWindowDecorations;exports.setWindowFullscreen=t.setWindowFullscreen;exports.setWindowMaxSize=t.setWindowMaxSize;exports.setWindowMaximized=t.setWindowMaximized;exports.setWindowMinSize=t.setWindowMinSize;exports.setWindowMinimized=t.setWindowMinimized;exports.setWindowPosition=t.setWindowPosition;exports.setWindowProps=t.setWindowProps;exports.setWindowResizable=t.setWindowResizable;exports.setWindowSize=t.setWindowSize;exports.setWindowSkipTaskbar=t.setWindowSkipTaskbar;exports.setWindowStage=t.setWindowStage;exports.setWindowTitle=t.setWindowTitle;exports.setWindowVisible=t.setWindowVisible;exports.windowPropsZ=t.windowPropsZ;exports.selectSliceState=f.selectSliceState;exports.selectWindow=f.selectWindow;exports.selectWindowAttribute=f.selectWindowAttribute;exports.selectWindowKey=f.selectWindowKey;exports.selectWindowLabel=f.selectWindowLabel;exports.selectWindows=f.selectWindows;exports.Drift=ee;exports.configureStore=W;