@arcanejs/toolkit 0.2.1 → 0.3.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 (70) hide show
  1. package/dist/backend/components/base.d.mts +4 -1
  2. package/dist/backend/components/base.d.ts +4 -1
  3. package/dist/backend/components/base.js +10 -188
  4. package/dist/backend/components/base.mjs +1 -1
  5. package/dist/backend/components/button.d.mts +1 -0
  6. package/dist/backend/components/button.d.ts +1 -0
  7. package/dist/backend/components/button.js +5 -165
  8. package/dist/backend/components/button.mjs +2 -2
  9. package/dist/backend/components/group.d.mts +1 -0
  10. package/dist/backend/components/group.d.ts +1 -0
  11. package/dist/backend/components/group.js +7 -281
  12. package/dist/backend/components/group.mjs +2 -2
  13. package/dist/backend/components/label.d.mts +1 -0
  14. package/dist/backend/components/label.d.ts +1 -0
  15. package/dist/backend/components/label.js +5 -102
  16. package/dist/backend/components/label.mjs +2 -2
  17. package/dist/backend/components/rect.d.mts +1 -0
  18. package/dist/backend/components/rect.d.ts +1 -0
  19. package/dist/backend/components/rect.js +5 -102
  20. package/dist/backend/components/rect.mjs +2 -2
  21. package/dist/backend/components/slider-button.d.mts +1 -0
  22. package/dist/backend/components/slider-button.d.ts +1 -0
  23. package/dist/backend/components/slider-button.js +5 -158
  24. package/dist/backend/components/slider-button.mjs +2 -2
  25. package/dist/backend/components/switch.d.mts +1 -0
  26. package/dist/backend/components/switch.d.ts +1 -0
  27. package/dist/backend/components/switch.js +5 -141
  28. package/dist/backend/components/switch.mjs +2 -2
  29. package/dist/backend/components/tabs.d.mts +1 -0
  30. package/dist/backend/components/tabs.d.ts +1 -0
  31. package/dist/backend/components/tabs.js +7 -206
  32. package/dist/backend/components/tabs.mjs +2 -2
  33. package/dist/backend/components/text-input.d.mts +1 -0
  34. package/dist/backend/components/text-input.d.ts +1 -0
  35. package/dist/backend/components/text-input.js +5 -143
  36. package/dist/backend/components/text-input.mjs +2 -2
  37. package/dist/backend/components/timeline.d.mts +1 -0
  38. package/dist/backend/components/timeline.d.ts +1 -0
  39. package/dist/backend/components/timeline.js +5 -106
  40. package/dist/backend/components/timeline.mjs +2 -2
  41. package/dist/backend/util/index.js +5 -41
  42. package/dist/chunk-3RG5ZIWI.js +10 -0
  43. package/dist/{chunk-3O4P67DM.mjs → chunk-3Y3HRYLC.mjs} +1 -1
  44. package/dist/{chunk-HNEUZVCX.mjs → chunk-7ITSSJE2.mjs} +1 -1
  45. package/dist/chunk-DNCHAOYH.js +42 -0
  46. package/dist/chunk-DV5WTSFW.js +33 -0
  47. package/dist/chunk-EABM5X65.js +17 -0
  48. package/dist/{chunk-ZCHM3JJJ.mjs → chunk-EDTJ75FT.mjs} +4 -3
  49. package/dist/{chunk-TAZH4BBH.mjs → chunk-EH73E5FP.mjs} +1 -1
  50. package/dist/{chunk-JW4GXS54.mjs → chunk-H2UQDFTS.mjs} +1 -1
  51. package/dist/chunk-IW3JCC73.js +44 -0
  52. package/dist/chunk-J46AJUGE.js +66 -0
  53. package/dist/{chunk-IXTM35YM.mjs → chunk-NKNDCRUR.mjs} +1 -1
  54. package/dist/chunk-NZUYU32Z.js +164 -0
  55. package/dist/{chunk-SOC4TF3J.mjs → chunk-POUQGJN4.mjs} +1 -1
  56. package/dist/chunk-QUA3NBLD.js +104 -0
  57. package/dist/{chunk-ZU5H6SVA.mjs → chunk-SMTUN6HG.mjs} +1 -1
  58. package/dist/chunk-TSC5C5XR.js +29 -0
  59. package/dist/chunk-WIPEQNWR.js +29 -0
  60. package/dist/chunk-WXSKMMCV.js +55 -0
  61. package/dist/{chunk-TQ27Y7F4.mjs → chunk-YIXRQHTA.mjs} +1 -1
  62. package/dist/chunk-YN3FZMXY.js +59 -0
  63. package/dist/{chunk-APCR3ITH.mjs → chunk-YYM7PBRN.mjs} +1 -1
  64. package/dist/frontend.js +0 -3
  65. package/dist/frontend.js.map +2 -2
  66. package/dist/index.d.mts +21 -3
  67. package/dist/index.d.ts +21 -3
  68. package/dist/index.js +99 -669
  69. package/dist/index.mjs +28 -24
  70. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -1,53 +1,43 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- Button: () => Button,
34
- Group: () => Group,
35
- GroupHeader: () => GroupHeader,
36
- Label: () => Label,
37
- Rect: () => Rect,
38
- SliderButton: () => SliderButton,
39
- Switch: () => Switch,
40
- Tab: () => Tab,
41
- Tabs: () => Tabs,
42
- TextInput: () => TextInput,
43
- Timeline: () => Timeline,
44
- Toolkit: () => Toolkit
45
- });
46
- module.exports = __toCommonJS(src_exports);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2;
2
+
3
+
4
+ var _chunkWXSKMMCVjs = require('./chunk-WXSKMMCV.js');
5
+
6
+
7
+ var _chunkIW3JCC73js = require('./chunk-IW3JCC73.js');
8
+
9
+
10
+ var _chunkDV5WTSFWjs = require('./chunk-DV5WTSFW.js');
11
+
12
+
13
+ var _chunkEABM5X65js = require('./chunk-EABM5X65.js');
14
+
15
+
16
+ var _chunkJ46AJUGEjs = require('./chunk-J46AJUGE.js');
17
+
18
+
19
+
20
+ var _chunkQUA3NBLDjs = require('./chunk-QUA3NBLD.js');
21
+
22
+
23
+ var _chunkTSC5C5XRjs = require('./chunk-TSC5C5XR.js');
24
+
25
+
26
+ var _chunkWIPEQNWRjs = require('./chunk-WIPEQNWR.js');
27
+
28
+
29
+ var _chunkYN3FZMXYjs = require('./chunk-YN3FZMXY.js');
30
+
31
+
32
+ var _chunkDNCHAOYHjs = require('./chunk-DNCHAOYH.js');
33
+ require('./chunk-NZUYU32Z.js');
34
+
35
+
36
+ var _chunk3RG5ZIWIjs = require('./chunk-3RG5ZIWI.js');
47
37
 
48
38
  // src/backend/toolkit.ts
49
- var import_lodash = __toESM(require("lodash"));
50
- var import_diff = require("@arcanejs/diff/diff");
39
+ var _lodash = require('lodash'); var _lodash2 = _interopRequireDefault(_lodash);
40
+ var _diff = require('@arcanejs/diff/diff');
51
41
 
52
42
  // src/backend/options.ts
53
43
  var DEFAULT_LIGHT_DESK_OPTIONS = {
@@ -55,8 +45,8 @@ var DEFAULT_LIGHT_DESK_OPTIONS = {
55
45
  };
56
46
 
57
47
  // src/backend/server.ts
58
- var fs = __toESM(require("fs"));
59
- var path = __toESM(require("path"));
48
+ var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
49
+ var _path = require('path'); var path = _interopRequireWildcard(_path);
60
50
 
61
51
  // src/shared/static.ts
62
52
  var FONTS = {
@@ -85,20 +75,21 @@ var STATIC_FILES = {
85
75
  contentType: "text/plain"
86
76
  },
87
77
  [`/${FONTS.materialSymbolsOutlined}`]: {
88
- path: require.resolve("material-symbols/material-symbols-outlined.woff2"),
78
+ path: _chunk3RG5ZIWIjs.__require.resolve("material-symbols/material-symbols-outlined.woff2"),
89
79
  contentType: "font/woff2"
90
80
  }
91
81
  };
92
- console.log("STATIC_FILES", STATIC_FILES);
93
- var Server = class {
94
- constructor(options, onNewConnection, onClosedConnection, onMessage) {
82
+ var Server = (_class = class {
83
+ constructor(options, onNewConnection, onClosedConnection, onMessage, log) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);
95
84
  this.options = options;
96
85
  this.onNewConnection = onNewConnection;
97
86
  this.onClosedConnection = onClosedConnection;
98
87
  this.onMessage = onMessage;
88
+ this.log = log;
89
+ _optionalChain([log, 'optionalAccess', _14 => _14.debug, 'call', _15 => _15("Static Assets: %o", STATIC_FILES)]);
99
90
  }
100
- handleHttpRequest = async (req, res) => {
101
- console.log("handleHttpRequest", req.url);
91
+ __init() {this.handleHttpRequest = async (req, res) => {
92
+ _optionalChain([this, 'access', _16 => _16.log, 'optionalAccess', _17 => _17.debug, 'call', _18 => _18("handleHttpRequest %s", req.url)]);
102
93
  if (req.url === this.options.path) {
103
94
  const content = `
104
95
  <html>
@@ -124,7 +115,7 @@ var Server = class {
124
115
  this.sendStaticFile(f.path, res, f.contentType);
125
116
  },
126
117
  (err) => {
127
- console.error(err);
118
+ _optionalChain([this, 'access', _19 => _19.log, 'optionalAccess', _20 => _20.error, 'call', _21 => _21(err)]);
128
119
  res.writeHead(500, { "Content-Type": "text/plain" });
129
120
  res.end("Expected static file not found", "utf-8");
130
121
  }
@@ -133,9 +124,9 @@ var Server = class {
133
124
  }
134
125
  res.writeHead(404, { "Content-Type": "text/plain" });
135
126
  res.end("not found", "utf-8");
136
- };
137
- sendStaticFile = (file, response, contentType) => {
138
- fs.readFile(file, function(error, content) {
127
+ }}
128
+ __init2() {this.sendStaticFile = (file, response, contentType) => {
129
+ fs.readFile(file, (error, content) => {
139
130
  if (error) {
140
131
  if (error.code === "ENOENT") {
141
132
  response.writeHead(404, { "Content-Type": "text/plain" });
@@ -143,55 +134,40 @@ var Server = class {
143
134
  } else {
144
135
  response.writeHead(500, { "Content-Type": "text/plain" });
145
136
  response.end("Error", "utf-8");
146
- console.error(error);
137
+ _optionalChain([this, 'access', _22 => _22.log, 'optionalAccess', _23 => _23.error, 'call', _24 => _24(`Error reading static file: %s`, error)]);
147
138
  }
148
139
  } else {
149
140
  response.writeHead(200, { "Content-Type": contentType });
150
141
  response.end(content, "utf-8");
151
142
  }
152
143
  });
153
- };
154
- handleWsConnection = (ws) => {
144
+ }}
145
+ __init3() {this.handleWsConnection = (ws) => {
155
146
  const connection = {
156
147
  sendMessage: (msg) => ws.send(JSON.stringify(msg))
157
148
  };
158
149
  this.onNewConnection(connection);
159
- console.log("new connection");
150
+ _optionalChain([this, 'access', _25 => _25.log, 'optionalAccess', _26 => _26.debug, 'call', _27 => _27("new connection")]);
160
151
  ws.on(
161
152
  "message",
162
153
  (msg) => this.onMessage(connection, JSON.parse(msg.toString()))
163
154
  );
164
155
  ws.on("close", () => this.onClosedConnection(connection));
165
- };
166
- };
167
-
168
- // src/backend/util/id-map.ts
169
- var IDMap = class {
170
- idMap = /* @__PURE__ */ new WeakMap();
171
- nextId = 0;
172
- getId(object) {
173
- let i = this.idMap.get(object);
174
- if (i === void 0) {
175
- i = this.nextId++;
176
- this.idMap.set(object, i);
177
- }
178
- return i;
179
- }
180
- };
156
+ }}
157
+ }, _class);
181
158
 
182
159
  // src/backend/toolkit.ts
183
- var import_ws = require("ws");
184
- var import_http = require("http");
185
- console.log(import_diff.diffJson);
186
- var Toolkit = class {
187
- options;
160
+ var _ws = require('ws');
161
+ var _http = require('http');
162
+ var Toolkit = (_class2 = class {
163
+
188
164
  /**
189
165
  * Mapping from components to unique IDs that identify them
190
166
  */
191
- componentIDMap = new IDMap();
192
- connections = /* @__PURE__ */ new Map();
193
- rootGroup = null;
194
- constructor(options = {}) {
167
+ __init4() {this.componentIDMap = new (0, _chunkEABM5X65js.IDMap)()}
168
+ __init5() {this.connections = /* @__PURE__ */ new Map()}
169
+ __init6() {this.rootGroup = null}
170
+ constructor(options = {}) {;_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);_class2.prototype.__init6.call(this);_class2.prototype.__init7.call(this);_class2.prototype.__init8.call(this);_class2.prototype.__init9.call(this);_class2.prototype.__init10.call(this);_class2.prototype.__init11.call(this);_class2.prototype.__init12.call(this);_class2.prototype.__init13.call(this);
195
171
  this.options = {
196
172
  ...DEFAULT_LIGHT_DESK_OPTIONS,
197
173
  ...options
@@ -202,26 +178,27 @@ var Toolkit = class {
202
178
  );
203
179
  }
204
180
  }
205
- start = (opts) => {
181
+ __init7() {this.start = (opts) => {
206
182
  const server = new Server(
207
183
  this.options,
208
184
  this.onNewConnection,
209
185
  this.onClosedConnection,
210
- this.onMessage
186
+ this.onMessage,
187
+ this.options.log
211
188
  );
212
189
  if (opts.mode === "automatic") {
213
- const httpServer = (0, import_http.createServer)(server.handleHttpRequest);
214
- const wss = new import_ws.WebSocketServer({
190
+ const httpServer = _http.createServer.call(void 0, server.handleHttpRequest);
191
+ const wss = new (0, _ws.WebSocketServer)({
215
192
  server: httpServer
216
193
  });
217
194
  wss.on("connection", server.handleWsConnection);
195
+ const url = `http://localhost:${opts.port}${this.options.path}`;
218
196
  httpServer.listen(opts.port, () => {
219
- console.log(
220
- `Light Desk Started: http://localhost:${opts.port}${this.options.path}`
221
- );
197
+ _optionalChain([opts, 'access', _45 => _45.onReady, 'optionalCall', _46 => _46(url)]);
198
+ _optionalChain([this, 'access', _47 => _47.options, 'access', _48 => _48.log, 'optionalAccess', _49 => _49.info, 'call', _50 => _50(`Light Desk Started: ${url}`)]);
222
199
  });
223
200
  } else if (opts.mode === "express") {
224
- const wss = new import_ws.WebSocketServer({
201
+ const wss = new (0, _ws.WebSocketServer)({
225
202
  server: opts.server
226
203
  });
227
204
  wss.on("connection", server.handleWsConnection);
@@ -231,15 +208,18 @@ var Toolkit = class {
231
208
  } else {
232
209
  throw new Error(`Unsupported mode`);
233
210
  }
234
- };
235
- setRoot = (group) => {
211
+ }}
212
+ __init8() {this.setRoot = (group) => {
236
213
  if (this.rootGroup) {
237
214
  throw new Error("Can only set root group once");
238
215
  }
239
216
  this.rootGroup = group;
240
217
  this.rootGroup.setParent(this);
241
- };
242
- updateTree = import_lodash.default.throttle(
218
+ }}
219
+ log() {
220
+ return _nullishCoalesce(this.options.log, () => ( null));
221
+ }
222
+ __init9() {this.updateTree = _lodash2.default.throttle(
243
223
  () => {
244
224
  setImmediate(() => {
245
225
  if (!this.rootGroup) return;
@@ -247,7 +227,7 @@ var Toolkit = class {
247
227
  for (const [connection, meta] of this.connections.entries()) {
248
228
  connection.sendMessage({
249
229
  type: "tree-diff",
250
- diff: (0, import_diff.diffJson)(meta.lastTreeSent, root)
230
+ diff: _diff.diffJson.call(void 0, meta.lastTreeSent, root)
251
231
  });
252
232
  meta.lastTreeSent = root;
253
233
  }
@@ -255,15 +235,15 @@ var Toolkit = class {
255
235
  },
256
236
  10,
257
237
  { leading: true, trailing: true }
258
- );
259
- removeChild = (component) => {
238
+ )}
239
+ __init10() {this.removeChild = (component) => {
260
240
  if (this.rootGroup === component) {
261
241
  this.rootGroup = null;
262
242
  component.setParent(null);
263
243
  }
264
- };
265
- onNewConnection = (connection) => {
266
- const lastTreeSent = this.rootGroup?.getProtoInfo(this.componentIDMap) ?? void 0;
244
+ }}
245
+ __init11() {this.onNewConnection = (connection) => {
246
+ const lastTreeSent = _nullishCoalesce(_optionalChain([this, 'access', _51 => _51.rootGroup, 'optionalAccess', _52 => _52.getProtoInfo, 'call', _53 => _53(this.componentIDMap)]), () => ( void 0));
267
247
  this.connections.set(connection, { lastTreeSent });
268
248
  if (lastTreeSent) {
269
249
  connection.sendMessage({
@@ -271,582 +251,32 @@ var Toolkit = class {
271
251
  root: lastTreeSent
272
252
  });
273
253
  }
274
- };
275
- onClosedConnection = (connection) => {
276
- console.log("removing connection");
254
+ }}
255
+ __init12() {this.onClosedConnection = (connection) => {
256
+ _optionalChain([this, 'access', _54 => _54.options, 'access', _55 => _55.log, 'optionalAccess', _56 => _56.debug, 'call', _57 => _57("removing connection")]);
277
257
  this.connections.delete(connection);
278
- };
279
- onMessage = (_connection, message) => {
280
- console.log("got message", message);
258
+ }}
259
+ __init13() {this.onMessage = (_connection, message) => {
260
+ _optionalChain([this, 'access', _58 => _58.options, 'access', _59 => _59.log, 'optionalAccess', _60 => _60.debug, 'call', _61 => _61("got message: %o", message)]);
281
261
  switch (message.type) {
282
262
  case "component-message":
283
263
  if (this.rootGroup)
284
264
  this.rootGroup.routeMessage(this.componentIDMap, message);
285
265
  break;
286
266
  }
287
- };
288
- };
267
+ }}
268
+ }, _class2);
289
269
 
290
- // src/backend/components/base.ts
291
- var Base = class {
292
- /** @hidden */
293
- parent = null;
294
- /** @hidden */
295
- defaultProps;
296
- /** @hidden */
297
- _props;
298
- constructor(defaultProps, props) {
299
- this.defaultProps = defaultProps;
300
- this._props = Object.freeze({
301
- ...defaultProps,
302
- ...props
303
- });
304
- }
305
- get props() {
306
- return this._props;
307
- }
308
- set props(props) {
309
- this.setProps(props);
310
- }
311
- setProps = (props) => {
312
- this._props = Object.freeze({
313
- ...this.defaultProps,
314
- ...props
315
- });
316
- this.updateTree();
317
- };
318
- updateProps = (updates) => {
319
- this._props = Object.freeze({
320
- ...this._props,
321
- ...updates
322
- });
323
- this.updateTree();
324
- };
325
- /** @hidden */
326
- setParent(parent) {
327
- if (this.parent && this.parent !== parent) {
328
- this.parent.removeChild(this);
329
- }
330
- this.parent = parent;
331
- }
332
- /** @hidden */
333
- updateTree() {
334
- if (this.parent) this.parent.updateTree();
335
- }
336
- /** @hidden */
337
- handleMessage(message) {
338
- console.log("Component Received Message:", message);
339
- }
340
- routeMessage(_idMap, _message) {
341
- }
342
- };
343
- var BaseParent = class extends Base {
344
- /** @hidden */
345
- children = [];
346
- appendChildren = (...children) => {
347
- for (const c of children) {
348
- const newChildren = [...this.children.filter((ch) => ch !== c), c];
349
- this.validateChildren(newChildren);
350
- this.children = Object.freeze(newChildren);
351
- c.setParent(this);
352
- }
353
- this.updateTree();
354
- return children;
355
- };
356
- appendChild = (child) => {
357
- this.appendChildren(child);
358
- return child;
359
- };
360
- removeChild = (component) => {
361
- const match = this.children.findIndex((c) => c === component);
362
- if (match >= 0) {
363
- const removingChild = this.children[match];
364
- const newChildren = [
365
- ...this.children.slice(0, match),
366
- ...this.children.slice(match + 1)
367
- ];
368
- this.validateChildren(newChildren);
369
- this.children = Object.freeze(newChildren);
370
- removingChild?.setParent(null);
371
- this.updateTree();
372
- }
373
- };
374
- removeAllChildren = () => {
375
- this.children.map((c) => c.setParent(null));
376
- this.children = Object.freeze([]);
377
- this.updateTree();
378
- };
379
- /**
380
- * Return all children components that messages need to be routed to
381
- */
382
- getChildren = () => this.children;
383
- /**
384
- * TODO: we can do this better, right now it broadcasts the message to all
385
- * components of the tree
386
- *
387
- * @hidden
388
- */
389
- routeMessage(idMap, message) {
390
- if (idMap.getId(this) === message.componentKey) {
391
- this.handleMessage(message);
392
- } else {
393
- for (const c of this.children) {
394
- if (idMap.getId(c) === message.componentKey) {
395
- c.handleMessage(message);
396
- } else {
397
- c.routeMessage(idMap, message);
398
- }
399
- }
400
- }
401
- }
402
- insertBefore(child, beforeChild) {
403
- const filteredChildren = this.children.filter((c) => c !== child);
404
- let match = filteredChildren.findIndex((c) => c === beforeChild);
405
- console.log("match", match);
406
- if (match === -1) {
407
- match = filteredChildren.length;
408
- }
409
- const newChildren = [
410
- ...filteredChildren.slice(0, match),
411
- child,
412
- ...filteredChildren.slice(match)
413
- ];
414
- this.validateChildren(newChildren);
415
- this.children = Object.freeze(newChildren);
416
- child.setParent(this);
417
- this.updateTree();
418
- }
419
- };
420
- var EventEmitter = class {
421
- listeners = /* @__PURE__ */ new Map();
422
- addListener = (type, listener) => {
423
- let set = this.listeners.get(type);
424
- if (!set) {
425
- set = /* @__PURE__ */ new Set();
426
- this.listeners.set(type, set);
427
- }
428
- set.add(listener);
429
- };
430
- removeListener = (type, listener) => {
431
- this.listeners.get(type)?.delete(listener);
432
- };
433
- emit = (type, ...args) => {
434
- return Promise.all(
435
- [...this.listeners.get(type) || []].map(
436
- (l) => new Promise((resolve2, reject) => {
437
- try {
438
- resolve2(l(...args));
439
- } catch (e) {
440
- reject(e);
441
- }
442
- })
443
- )
444
- );
445
- };
446
- };
447
270
 
448
- // src/backend/components/button.ts
449
- var DEFAULT_PROPS = {
450
- text: null,
451
- icon: null,
452
- mode: "normal",
453
- error: null
454
- };
455
- var Button = class extends Base {
456
- /** @hidden */
457
- events = new EventEmitter();
458
- constructor(props) {
459
- super(DEFAULT_PROPS, props);
460
- }
461
- addListener = this.events.addListener;
462
- removeListener = this.events.removeListener;
463
- setText = (text) => {
464
- this.updateProps({ text });
465
- return this;
466
- };
467
- setIcon = (icon) => {
468
- this.updateProps({ icon: icon ?? null });
469
- return this;
470
- };
471
- setMode = (mode) => {
472
- this.updateProps({
473
- mode,
474
- error: null
475
- });
476
- return this;
477
- };
478
- /** @hidden */
479
- getProtoInfo = (idMap) => {
480
- return {
481
- component: "button",
482
- key: idMap.getId(this),
483
- text: this.props.text || "",
484
- state: this.props.error ? { state: "error", error: this.props.error } : { state: this.props.mode },
485
- icon: this.props.icon ?? void 0
486
- };
487
- };
488
- /** @hidden */
489
- handleMessage = (message) => {
490
- if (message.component === "button") {
491
- this.events.emit("click").then(() => {
492
- if (this.props.error) {
493
- this.updateProps({
494
- error: null
495
- });
496
- }
497
- }).catch((e) => {
498
- this.updateProps({
499
- error: `${e}`
500
- });
501
- });
502
- }
503
- };
504
- };
505
271
 
506
- // src/backend/components/group.ts
507
- var GROUP_DEFAULT_STYLE = {
508
- direction: "horizontal"
509
- };
510
- var DEFAULT_PROPS2 = {
511
- ...GROUP_DEFAULT_STYLE,
512
- title: null,
513
- labels: null
514
- };
515
- var GroupHeader = class extends BaseParent {
516
- validateChildren = () => {
517
- };
518
- /** @hidden */
519
- getProtoInfo = (idMap) => ({
520
- component: "group-header",
521
- key: idMap.getId(this),
522
- children: this.getChildren().map((c) => c.getProtoInfo(idMap))
523
- });
524
- };
525
- var Group = class extends BaseParent {
526
- /** @hidden */
527
- events = new EventEmitter();
528
- constructor(props) {
529
- super(DEFAULT_PROPS2, props);
530
- }
531
- addListener = this.events.addListener;
532
- removeListener = this.events.removeListener;
533
- validateChildren = () => {
534
- };
535
- setOptions = (options) => {
536
- this.updateProps(options);
537
- };
538
- setTitle = (title) => {
539
- this.updateProps({ title });
540
- };
541
- addLabel = (label) => {
542
- this.updateProps({ labels: [...this.props.labels || [], label] });
543
- };
544
- setLabels = (labels) => {
545
- this.updateProps({ labels });
546
- };
547
- addHeaderChild = (child) => {
548
- const header = new GroupHeader({});
549
- header.appendChild(child);
550
- this.appendChild(header);
551
- return child;
552
- };
553
- removeHeaderChild = (child) => {
554
- for (const c of this.getChildren()) {
555
- if (c instanceof GroupHeader) {
556
- c.removeChild(child);
557
- }
558
- }
559
- };
560
- removeAllHeaderChildren = () => {
561
- for (const child of this.getChildren()) {
562
- if (child instanceof GroupHeader) {
563
- child.removeAllChildren();
564
- }
565
- }
566
- };
567
- /** @hidden */
568
- getProtoInfo = (idMap) => {
569
- const children = [];
570
- const headers = [];
571
- for (const c of this.getChildren()) {
572
- const childProto = c.getProtoInfo(idMap);
573
- if (childProto.component === "group-header") {
574
- headers.push(childProto);
575
- } else {
576
- children.push(childProto);
577
- }
578
- }
579
- return {
580
- component: "group",
581
- key: idMap.getId(this),
582
- title: this.props.title ?? void 0,
583
- direction: this.props.direction,
584
- border: this.props.border,
585
- wrap: this.props.wrap,
586
- children,
587
- headers: headers.length > 0 ? headers : void 0,
588
- labels: this.props.labels ?? void 0,
589
- editableTitle: this.props.editableTitle || false,
590
- defaultCollapsibleState: this.props.defaultCollapsibleState
591
- };
592
- };
593
- /** @hidden */
594
- handleMessage = (message) => {
595
- if (message.component === "group") {
596
- this.events.emit("title-changed", message.title);
597
- }
598
- };
599
- };
600
272
 
601
- // src/backend/components/label.ts
602
- var Label = class extends Base {
603
- constructor(props) {
604
- super({ text: null }, props);
605
- }
606
- /** @hidden */
607
- getProtoInfo(idMap) {
608
- return {
609
- component: "label",
610
- key: idMap.getId(this),
611
- bold: this.props.bold,
612
- text: this.props.text ?? ""
613
- };
614
- }
615
- setText(text) {
616
- this.updateProps({
617
- text
618
- });
619
- return this;
620
- }
621
- };
622
273
 
623
- // src/backend/components/rect.ts
624
- var DEFAULT_PROPS3 = {
625
- color: "rgba(0, 0, 0, 0)"
626
- };
627
- var Rect = class extends Base {
628
- constructor(props) {
629
- super(DEFAULT_PROPS3, props);
630
- }
631
- /** @hidden */
632
- getProtoInfo(idMap) {
633
- return {
634
- component: "rect",
635
- key: idMap.getId(this),
636
- color: this.props.color
637
- };
638
- }
639
- setColor(color) {
640
- this.updateProps({ color });
641
- return this;
642
- }
643
- };
644
274
 
645
- // src/backend/components/slider-button.ts
646
- var DEFAULT_PROPS4 = {
647
- value: null,
648
- min: 0,
649
- max: 255,
650
- step: 5,
651
- mode: "writeBack"
652
- };
653
- var SliderButton = class extends Base {
654
- /** @hidden */
655
- events = new EventEmitter();
656
- constructor(props) {
657
- super(DEFAULT_PROPS4, props);
658
- }
659
- addListener = this.events.addListener;
660
- removeListener = this.events.removeListener;
661
- /** @hidden */
662
- getProtoInfo(idMap) {
663
- return {
664
- component: "slider_button",
665
- key: idMap.getId(this),
666
- min: this.props.min,
667
- max: this.props.max,
668
- step: this.props.step,
669
- value: this.props.value
670
- };
671
- }
672
- /** @hidden */
673
- handleMessage(message) {
674
- if (message.component !== "slider_button") return;
675
- const newValue = this.sanitizeNumber(message.value);
676
- if (this.props.value === newValue) return;
677
- if (this.props.mode === "writeBack") {
678
- this.updateProps({ value: newValue });
679
- }
680
- this.events.emit("change", newValue);
681
- }
682
- setValue(value) {
683
- const newValue = this.sanitizeNumber(value);
684
- if (newValue === this.props.value) return;
685
- this.updateProps({ value });
686
- this.updateTree();
687
- }
688
- sanitizeNumber(value) {
689
- const i = Math.round((value - this.props.min) / this.props.step);
690
- const v = i * this.props.step + this.props.min;
691
- const clampedValue = Math.max(this.props.min, Math.min(this.props.max, v));
692
- return clampedValue;
693
- }
694
- };
695
275
 
696
- // src/backend/components/switch.ts
697
- var DEFAULT_PROPS5 = {
698
- state: "off"
699
- };
700
- var Switch = class extends Base {
701
- /** @hidden */
702
- events = new EventEmitter();
703
- constructor(props) {
704
- super(DEFAULT_PROPS5, props);
705
- }
706
- addListener = this.events.addListener;
707
- removeListener = this.events.removeListener;
708
- /** @hidden */
709
- getProtoInfo(idMap) {
710
- return {
711
- component: "switch",
712
- key: idMap.getId(this),
713
- state: this.props.state
714
- };
715
- }
716
- /** @hidden */
717
- handleMessage(message) {
718
- if (message.component === "switch") {
719
- const state = this.props.state === "on" ? "off" : "on";
720
- this.updateProps({ state });
721
- this.events.emit("change", state);
722
- }
723
- }
724
- setValue(state) {
725
- if (state === this.props.state) return;
726
- this.updateProps({ state });
727
- }
728
- };
729
276
 
730
- // src/backend/components/tabs.ts
731
- var Tab = class extends BaseParent {
732
- validateChildren = (children) => {
733
- if (children.length > 1) {
734
- throw new Error("Tab can only have one child");
735
- }
736
- };
737
- /** @hidden */
738
- getProtoInfo = (idMap) => ({
739
- component: "tab",
740
- key: idMap.getId(this),
741
- name: this.props.name,
742
- child: this.getChildren().slice(0, 1).map((c) => c.getProtoInfo(idMap))[0]
743
- });
744
- };
745
- var Tabs = class extends BaseParent {
746
- validateChildren = (children) => {
747
- for (const child of children) {
748
- if (!(child instanceof Tab)) {
749
- throw new Error("Tabs can only have Tab children");
750
- }
751
- }
752
- };
753
- constructor(props) {
754
- super({}, { ...props });
755
- }
756
- addTabs(...tabs) {
757
- for (const t of tabs) {
758
- const tab = new Tab({ name: t.name });
759
- tab.appendChildren(t.component);
760
- this.appendChild(tab);
761
- }
762
- }
763
- addTab(name, component) {
764
- this.addTabs({ name, component });
765
- return component;
766
- }
767
- /** @hidden */
768
- getProtoInfo(idMap) {
769
- return {
770
- component: "tabs",
771
- key: idMap.getId(this),
772
- tabs: this.getChildren().map((c) => c.getProtoInfo(idMap))
773
- };
774
- }
775
- };
776
277
 
777
- // src/backend/components/text-input.ts
778
- var DEFAULT_PROPS6 = {
779
- value: null
780
- };
781
- var TextInput = class extends Base {
782
- /** @hidden */
783
- events = new EventEmitter();
784
- constructor(props) {
785
- super(DEFAULT_PROPS6, props);
786
- }
787
- addListener = this.events.addListener;
788
- removeListener = this.events.removeListener;
789
- /** @hidden */
790
- getProtoInfo = (idMap) => {
791
- return {
792
- component: "text-input",
793
- key: idMap.getId(this),
794
- value: this.props.value ?? ""
795
- };
796
- };
797
- /** @hidden */
798
- handleMessage = (message) => {
799
- if (message.component === "text-input") {
800
- if (this.props.value !== message.value) {
801
- this.updateProps({ value: message.value });
802
- this.events.emit("change", message.value);
803
- }
804
- }
805
- };
806
- getValue = () => this.props.value;
807
- getValidatedValue = (validator) => this.props.value === "" ? null : validator(this.props.value || "");
808
- setValue = (value) => {
809
- this.updateProps({ value });
810
- };
811
- };
812
278
 
813
- // src/backend/components/timeline.ts
814
- var DEFAULT_PROPS7 = {
815
- state: {
816
- state: "stopped",
817
- totalTimeMillis: 0,
818
- currentTimeMillis: 0
819
- },
820
- title: null,
821
- subtitles: null,
822
- source: null
823
- };
824
- var Timeline = class extends Base {
825
- constructor(props) {
826
- super(DEFAULT_PROPS7, props);
827
- }
828
- /** @hidden */
829
- getProtoInfo = (idMap) => ({
830
- component: "timeline",
831
- key: idMap.getId(this),
832
- state: this.props.state,
833
- title: this.props.title ?? void 0,
834
- subtitles: this.props.subtitles ?? void 0,
835
- source: this.props.source ?? void 0
836
- });
837
- };
838
- // Annotate the CommonJS export names for ESM import in node:
839
- 0 && (module.exports = {
840
- Button,
841
- Group,
842
- GroupHeader,
843
- Label,
844
- Rect,
845
- SliderButton,
846
- Switch,
847
- Tab,
848
- Tabs,
849
- TextInput,
850
- Timeline,
851
- Toolkit
852
- });
279
+
280
+
281
+
282
+ exports.Button = _chunkJ46AJUGEjs.Button; exports.Group = _chunkQUA3NBLDjs.Group; exports.GroupHeader = _chunkQUA3NBLDjs.GroupHeader; exports.Label = _chunkTSC5C5XRjs.Label; exports.Rect = _chunkWIPEQNWRjs.Rect; exports.SliderButton = _chunkYN3FZMXYjs.SliderButton; exports.Switch = _chunkDNCHAOYHjs.Switch; exports.Tab = _chunkWXSKMMCVjs.Tab; exports.Tabs = _chunkWXSKMMCVjs.Tabs; exports.TextInput = _chunkIW3JCC73js.TextInput; exports.Timeline = _chunkDV5WTSFWjs.Timeline; exports.Toolkit = Toolkit;