@arcanejs/toolkit 0.2.0 → 0.2.2

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 (77) hide show
  1. package/dist/backend/components/base.d.mts +69 -2
  2. package/dist/backend/components/base.d.ts +69 -2
  3. package/dist/backend/components/base.js +10 -188
  4. package/dist/backend/components/base.mjs +2 -1
  5. package/dist/backend/components/button.d.mts +5 -4
  6. package/dist/backend/components/button.d.ts +5 -4
  7. package/dist/backend/components/button.js +5 -165
  8. package/dist/backend/components/button.mjs +3 -2
  9. package/dist/backend/components/group.d.mts +9 -7
  10. package/dist/backend/components/group.d.ts +9 -7
  11. package/dist/backend/components/group.js +6 -282
  12. package/dist/backend/components/group.mjs +3 -2
  13. package/dist/backend/components/label.d.mts +5 -3
  14. package/dist/backend/components/label.d.ts +5 -3
  15. package/dist/backend/components/label.js +5 -102
  16. package/dist/backend/components/label.mjs +3 -2
  17. package/dist/backend/components/rect.d.mts +4 -3
  18. package/dist/backend/components/rect.d.ts +4 -3
  19. package/dist/backend/components/rect.js +5 -102
  20. package/dist/backend/components/rect.mjs +3 -2
  21. package/dist/backend/components/slider-button.d.mts +5 -4
  22. package/dist/backend/components/slider-button.d.ts +5 -4
  23. package/dist/backend/components/slider-button.js +5 -158
  24. package/dist/backend/components/slider-button.mjs +3 -2
  25. package/dist/backend/components/switch.d.mts +5 -4
  26. package/dist/backend/components/switch.d.ts +5 -4
  27. package/dist/backend/components/switch.js +5 -141
  28. package/dist/backend/components/switch.mjs +3 -2
  29. package/dist/backend/components/tabs.d.mts +5 -4
  30. package/dist/backend/components/tabs.d.ts +5 -4
  31. package/dist/backend/components/tabs.js +7 -206
  32. package/dist/backend/components/tabs.mjs +3 -2
  33. package/dist/backend/components/text-input.d.mts +5 -4
  34. package/dist/backend/components/text-input.d.ts +5 -4
  35. package/dist/backend/components/text-input.js +5 -143
  36. package/dist/backend/components/text-input.mjs +3 -2
  37. package/dist/backend/components/timeline.d.mts +6 -5
  38. package/dist/backend/components/timeline.d.ts +6 -5
  39. package/dist/backend/components/timeline.js +5 -106
  40. package/dist/backend/components/timeline.mjs +3 -2
  41. package/dist/backend/util/index.d.mts +7 -0
  42. package/dist/backend/util/index.d.ts +7 -0
  43. package/dist/backend/util/index.js +7 -0
  44. package/dist/backend/util/index.mjs +7 -0
  45. package/dist/{chunk-L243ZOAR.mjs → chunk-3O4P67DM.mjs} +2 -4
  46. package/dist/chunk-3RG5ZIWI.js +10 -0
  47. package/dist/{chunk-37VNFO5S.mjs → chunk-APCR3ITH.mjs} +1 -1
  48. package/dist/chunk-EABM5X65.js +17 -0
  49. package/dist/{chunk-P6X5GIDT.mjs → chunk-HNEUZVCX.mjs} +1 -1
  50. package/dist/{chunk-6LL3X7ZZ.mjs → chunk-IXTM35YM.mjs} +1 -1
  51. package/dist/{chunk-HVFTRNLQ.mjs → chunk-JW4GXS54.mjs} +1 -1
  52. package/dist/chunk-K24YPCR5.js +104 -0
  53. package/dist/chunk-KVJU3EAD.js +66 -0
  54. package/dist/chunk-M6EFK4GP.js +42 -0
  55. package/dist/chunk-MDFDWKGW.js +44 -0
  56. package/dist/chunk-OEIGZ3NQ.js +33 -0
  57. package/dist/chunk-P43QUQ4T.js +29 -0
  58. package/dist/chunk-RGHJEMWG.mjs +17 -0
  59. package/dist/chunk-RGIB65TI.js +29 -0
  60. package/dist/chunk-RJS32OOA.js +55 -0
  61. package/dist/{chunk-DBW4OPGN.mjs → chunk-SOC4TF3J.mjs} +1 -1
  62. package/dist/chunk-T2PJEXYO.js +59 -0
  63. package/dist/{chunk-DP3QFYSS.mjs → chunk-TAZH4BBH.mjs} +1 -1
  64. package/dist/{chunk-3ZBM7Q4A.mjs → chunk-TQ27Y7F4.mjs} +1 -1
  65. package/dist/chunk-UBWCVW2U.js +163 -0
  66. package/dist/chunk-Y6FXYEAI.mjs +10 -0
  67. package/dist/{chunk-HF77PS7J.mjs → chunk-ZCHM3JJJ.mjs} +0 -8
  68. package/dist/{chunk-GQZA5K4M.mjs → chunk-ZU5H6SVA.mjs} +1 -1
  69. package/dist/frontend.js +1345 -398
  70. package/dist/frontend.js.map +4 -4
  71. package/dist/index.d.mts +4 -2
  72. package/dist/index.d.ts +4 -2
  73. package/dist/index.js +82 -658
  74. package/dist/index.mjs +14 -24
  75. package/package.json +10 -2
  76. package/dist/base-BJAPu0O1.d.mts +0 -234
  77. package/dist/base-BJAPu0O1.d.ts +0 -234
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 _chunkRJS32OOAjs = require('./chunk-RJS32OOA.js');
5
+
6
+
7
+ var _chunkMDFDWKGWjs = require('./chunk-MDFDWKGW.js');
8
+
9
+
10
+ var _chunkOEIGZ3NQjs = require('./chunk-OEIGZ3NQ.js');
11
+
12
+
13
+ var _chunkEABM5X65js = require('./chunk-EABM5X65.js');
14
+
15
+
16
+ var _chunkKVJU3EADjs = require('./chunk-KVJU3EAD.js');
17
+
18
+
19
+
20
+ var _chunkK24YPCR5js = require('./chunk-K24YPCR5.js');
21
+
22
+
23
+ var _chunkP43QUQ4Tjs = require('./chunk-P43QUQ4T.js');
24
+
25
+
26
+ var _chunkRGIB65TIjs = require('./chunk-RGIB65TI.js');
27
+
28
+
29
+ var _chunkT2PJEXYOjs = require('./chunk-T2PJEXYO.js');
30
+
31
+
32
+ var _chunkM6EFK4GPjs = require('./chunk-M6EFK4GP.js');
33
+ require('./chunk-UBWCVW2U.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,19 +75,19 @@ 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
82
  console.log("STATIC_FILES", STATIC_FILES);
93
- var Server = class {
94
- constructor(options, onNewConnection, onClosedConnection, onMessage) {
83
+ var Server = (_class = class {
84
+ constructor(options, onNewConnection, onClosedConnection, onMessage) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);
95
85
  this.options = options;
96
86
  this.onNewConnection = onNewConnection;
97
87
  this.onClosedConnection = onClosedConnection;
98
88
  this.onMessage = onMessage;
99
89
  }
100
- handleHttpRequest = async (req, res) => {
90
+ __init() {this.handleHttpRequest = async (req, res) => {
101
91
  console.log("handleHttpRequest", req.url);
102
92
  if (req.url === this.options.path) {
103
93
  const content = `
@@ -133,8 +123,8 @@ var Server = class {
133
123
  }
134
124
  res.writeHead(404, { "Content-Type": "text/plain" });
135
125
  res.end("not found", "utf-8");
136
- };
137
- sendStaticFile = (file, response, contentType) => {
126
+ }}
127
+ __init2() {this.sendStaticFile = (file, response, contentType) => {
138
128
  fs.readFile(file, function(error, content) {
139
129
  if (error) {
140
130
  if (error.code === "ENOENT") {
@@ -150,8 +140,8 @@ var Server = class {
150
140
  response.end(content, "utf-8");
151
141
  }
152
142
  });
153
- };
154
- handleWsConnection = (ws) => {
143
+ }}
144
+ __init3() {this.handleWsConnection = (ws) => {
155
145
  const connection = {
156
146
  sendMessage: (msg) => ws.send(JSON.stringify(msg))
157
147
  };
@@ -162,36 +152,22 @@ var Server = class {
162
152
  (msg) => this.onMessage(connection, JSON.parse(msg.toString()))
163
153
  );
164
154
  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
- };
155
+ }}
156
+ }, _class);
181
157
 
182
158
  // 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;
159
+ var _ws = require('ws');
160
+ var _http = require('http');
161
+ console.log(_diff.diffJson);
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,7 +178,7 @@ 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,
@@ -210,8 +186,8 @@ var Toolkit = class {
210
186
  this.onMessage
211
187
  );
212
188
  if (opts.mode === "automatic") {
213
- const httpServer = (0, import_http.createServer)(server.handleHttpRequest);
214
- const wss = new import_ws.WebSocketServer({
189
+ const httpServer = _http.createServer.call(void 0, server.handleHttpRequest);
190
+ const wss = new (0, _ws.WebSocketServer)({
215
191
  server: httpServer
216
192
  });
217
193
  wss.on("connection", server.handleWsConnection);
@@ -221,7 +197,7 @@ var Toolkit = class {
221
197
  );
222
198
  });
223
199
  } else if (opts.mode === "express") {
224
- const wss = new import_ws.WebSocketServer({
200
+ const wss = new (0, _ws.WebSocketServer)({
225
201
  server: opts.server
226
202
  });
227
203
  wss.on("connection", server.handleWsConnection);
@@ -231,15 +207,15 @@ var Toolkit = class {
231
207
  } else {
232
208
  throw new Error(`Unsupported mode`);
233
209
  }
234
- };
235
- setRoot = (group) => {
210
+ }}
211
+ __init8() {this.setRoot = (group) => {
236
212
  if (this.rootGroup) {
237
213
  throw new Error("Can only set root group once");
238
214
  }
239
215
  this.rootGroup = group;
240
216
  this.rootGroup.setParent(this);
241
- };
242
- updateTree = import_lodash.default.throttle(
217
+ }}
218
+ __init9() {this.updateTree = _lodash2.default.throttle(
243
219
  () => {
244
220
  setImmediate(() => {
245
221
  if (!this.rootGroup) return;
@@ -247,7 +223,7 @@ var Toolkit = class {
247
223
  for (const [connection, meta] of this.connections.entries()) {
248
224
  connection.sendMessage({
249
225
  type: "tree-diff",
250
- diff: (0, import_diff.diffJson)(meta.lastTreeSent, root)
226
+ diff: _diff.diffJson.call(void 0, meta.lastTreeSent, root)
251
227
  });
252
228
  meta.lastTreeSent = root;
253
229
  }
@@ -255,15 +231,15 @@ var Toolkit = class {
255
231
  },
256
232
  10,
257
233
  { leading: true, trailing: true }
258
- );
259
- removeChild = (component) => {
234
+ )}
235
+ __init10() {this.removeChild = (component) => {
260
236
  if (this.rootGroup === component) {
261
237
  this.rootGroup = null;
262
238
  component.setParent(null);
263
239
  }
264
- };
265
- onNewConnection = (connection) => {
266
- const lastTreeSent = this.rootGroup?.getProtoInfo(this.componentIDMap) ?? void 0;
240
+ }}
241
+ __init11() {this.onNewConnection = (connection) => {
242
+ const lastTreeSent = _nullishCoalesce(_optionalChain([this, 'access', _5 => _5.rootGroup, 'optionalAccess', _6 => _6.getProtoInfo, 'call', _7 => _7(this.componentIDMap)]), () => ( void 0));
267
243
  this.connections.set(connection, { lastTreeSent });
268
244
  if (lastTreeSent) {
269
245
  connection.sendMessage({
@@ -271,12 +247,12 @@ var Toolkit = class {
271
247
  root: lastTreeSent
272
248
  });
273
249
  }
274
- };
275
- onClosedConnection = (connection) => {
250
+ }}
251
+ __init12() {this.onClosedConnection = (connection) => {
276
252
  console.log("removing connection");
277
253
  this.connections.delete(connection);
278
- };
279
- onMessage = (_connection, message) => {
254
+ }}
255
+ __init13() {this.onMessage = (_connection, message) => {
280
256
  console.log("got message", message);
281
257
  switch (message.type) {
282
258
  case "component-message":
@@ -284,571 +260,19 @@ var Toolkit = class {
284
260
  this.rootGroup.routeMessage(this.componentIDMap, message);
285
261
  break;
286
262
  }
287
- };
288
- };
263
+ }}
264
+ }, _class2);
289
265
 
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
266
 
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
267
 
506
- // src/shared/styles.ts
507
- var GROUP_DEFAULT_STYLE = {
508
- direction: "horizontal"
509
- };
510
268
 
511
- // src/backend/components/group.ts
512
- var DEFAULT_PROPS2 = {
513
- ...GROUP_DEFAULT_STYLE,
514
- title: null,
515
- labels: null
516
- };
517
- var GroupHeader = class extends BaseParent {
518
- validateChildren = () => {
519
- };
520
- /** @hidden */
521
- getProtoInfo = (idMap) => ({
522
- component: "group-header",
523
- key: idMap.getId(this),
524
- children: this.getChildren().map((c) => c.getProtoInfo(idMap))
525
- });
526
- };
527
- var Group = class extends BaseParent {
528
- /** @hidden */
529
- events = new EventEmitter();
530
- constructor(props) {
531
- super(DEFAULT_PROPS2, props);
532
- }
533
- addListener = this.events.addListener;
534
- removeListener = this.events.removeListener;
535
- validateChildren = () => {
536
- };
537
- setOptions = (options) => {
538
- this.updateProps(options);
539
- };
540
- setTitle = (title) => {
541
- this.updateProps({ title });
542
- };
543
- addLabel = (label) => {
544
- this.updateProps({ labels: [...this.props.labels || [], label] });
545
- };
546
- setLabels = (labels) => {
547
- this.updateProps({ labels });
548
- };
549
- addHeaderChild = (child) => {
550
- const header = new GroupHeader({});
551
- header.appendChild(child);
552
- this.appendChild(header);
553
- return child;
554
- };
555
- removeHeaderChild = (child) => {
556
- for (const c of this.getChildren()) {
557
- if (c instanceof GroupHeader) {
558
- c.removeChild(child);
559
- }
560
- }
561
- };
562
- removeAllHeaderChildren = () => {
563
- for (const child of this.getChildren()) {
564
- if (child instanceof GroupHeader) {
565
- child.removeAllChildren();
566
- }
567
- }
568
- };
569
- /** @hidden */
570
- getProtoInfo = (idMap) => {
571
- const children = [];
572
- const headers = [];
573
- for (const c of this.getChildren()) {
574
- const childProto = c.getProtoInfo(idMap);
575
- if (childProto.component === "group-header") {
576
- headers.push(childProto);
577
- } else {
578
- children.push(childProto);
579
- }
580
- }
581
- return {
582
- component: "group",
583
- key: idMap.getId(this),
584
- title: this.props.title ?? void 0,
585
- direction: this.props.direction,
586
- border: this.props.border,
587
- wrap: this.props.wrap,
588
- children,
589
- headers: headers.length > 0 ? headers : void 0,
590
- labels: this.props.labels ?? void 0,
591
- editableTitle: this.props.editableTitle || false,
592
- defaultCollapsibleState: this.props.defaultCollapsibleState
593
- };
594
- };
595
- /** @hidden */
596
- handleMessage = (message) => {
597
- if (message.component === "group") {
598
- this.events.emit("title-changed", message.title);
599
- }
600
- };
601
- };
602
269
 
603
- // src/backend/components/label.ts
604
- var Label = class extends Base {
605
- constructor(props) {
606
- super({ text: null }, props);
607
- }
608
- /** @hidden */
609
- getProtoInfo(idMap) {
610
- return {
611
- component: "label",
612
- key: idMap.getId(this),
613
- bold: this.props.bold,
614
- text: this.props.text ?? ""
615
- };
616
- }
617
- setText(text) {
618
- this.updateProps({
619
- text
620
- });
621
- return this;
622
- }
623
- };
624
270
 
625
- // src/backend/components/rect.ts
626
- var DEFAULT_PROPS3 = {
627
- color: "rgba(0, 0, 0, 0)"
628
- };
629
- var Rect = class extends Base {
630
- constructor(props) {
631
- super(DEFAULT_PROPS3, props);
632
- }
633
- /** @hidden */
634
- getProtoInfo(idMap) {
635
- return {
636
- component: "rect",
637
- key: idMap.getId(this),
638
- color: this.props.color
639
- };
640
- }
641
- setColor(color) {
642
- this.updateProps({ color });
643
- return this;
644
- }
645
- };
646
271
 
647
- // src/backend/components/slider-button.ts
648
- var DEFAULT_PROPS4 = {
649
- value: null,
650
- min: 0,
651
- max: 255,
652
- step: 5,
653
- mode: "writeBack"
654
- };
655
- var SliderButton = class extends Base {
656
- /** @hidden */
657
- events = new EventEmitter();
658
- constructor(props) {
659
- super(DEFAULT_PROPS4, props);
660
- }
661
- addListener = this.events.addListener;
662
- removeListener = this.events.removeListener;
663
- /** @hidden */
664
- getProtoInfo(idMap) {
665
- return {
666
- component: "slider_button",
667
- key: idMap.getId(this),
668
- min: this.props.min,
669
- max: this.props.max,
670
- step: this.props.step,
671
- value: this.props.value
672
- };
673
- }
674
- /** @hidden */
675
- handleMessage(message) {
676
- if (message.component !== "slider_button") return;
677
- const newValue = this.sanitizeNumber(message.value);
678
- if (this.props.value === newValue) return;
679
- if (this.props.mode === "writeBack") {
680
- this.updateProps({ value: newValue });
681
- }
682
- this.events.emit("change", newValue);
683
- }
684
- setValue(value) {
685
- const newValue = this.sanitizeNumber(value);
686
- if (newValue === this.props.value) return;
687
- this.updateProps({ value });
688
- this.updateTree();
689
- }
690
- sanitizeNumber(value) {
691
- const i = Math.round((value - this.props.min) / this.props.step);
692
- const v = i * this.props.step + this.props.min;
693
- const clampedValue = Math.max(this.props.min, Math.min(this.props.max, v));
694
- return clampedValue;
695
- }
696
- };
697
272
 
698
- // src/backend/components/switch.ts
699
- var DEFAULT_PROPS5 = {
700
- state: "off"
701
- };
702
- var Switch = class extends Base {
703
- /** @hidden */
704
- events = new EventEmitter();
705
- constructor(props) {
706
- super(DEFAULT_PROPS5, props);
707
- }
708
- addListener = this.events.addListener;
709
- removeListener = this.events.removeListener;
710
- /** @hidden */
711
- getProtoInfo(idMap) {
712
- return {
713
- component: "switch",
714
- key: idMap.getId(this),
715
- state: this.props.state
716
- };
717
- }
718
- /** @hidden */
719
- handleMessage(message) {
720
- if (message.component === "switch") {
721
- const state = this.props.state === "on" ? "off" : "on";
722
- this.updateProps({ state });
723
- this.events.emit("change", state);
724
- }
725
- }
726
- setValue(state) {
727
- if (state === this.props.state) return;
728
- this.updateProps({ state });
729
- }
730
- };
731
273
 
732
- // src/backend/components/tabs.ts
733
- var Tab = class extends BaseParent {
734
- validateChildren = (children) => {
735
- if (children.length > 1) {
736
- throw new Error("Tab can only have one child");
737
- }
738
- };
739
- /** @hidden */
740
- getProtoInfo = (idMap) => ({
741
- component: "tab",
742
- key: idMap.getId(this),
743
- name: this.props.name,
744
- child: this.getChildren().slice(0, 1).map((c) => c.getProtoInfo(idMap))[0]
745
- });
746
- };
747
- var Tabs = class extends BaseParent {
748
- validateChildren = (children) => {
749
- for (const child of children) {
750
- if (!(child instanceof Tab)) {
751
- throw new Error("Tabs can only have Tab children");
752
- }
753
- }
754
- };
755
- constructor(props) {
756
- super({}, { ...props });
757
- }
758
- addTabs(...tabs) {
759
- for (const t of tabs) {
760
- const tab = new Tab({ name: t.name });
761
- tab.appendChildren(t.component);
762
- this.appendChild(tab);
763
- }
764
- }
765
- addTab(name, component) {
766
- this.addTabs({ name, component });
767
- return component;
768
- }
769
- /** @hidden */
770
- getProtoInfo(idMap) {
771
- return {
772
- component: "tabs",
773
- key: idMap.getId(this),
774
- tabs: this.getChildren().map((c) => c.getProtoInfo(idMap))
775
- };
776
- }
777
- };
778
274
 
779
- // src/backend/components/text-input.ts
780
- var DEFAULT_PROPS6 = {
781
- value: null
782
- };
783
- var TextInput = class extends Base {
784
- /** @hidden */
785
- events = new EventEmitter();
786
- constructor(props) {
787
- super(DEFAULT_PROPS6, props);
788
- }
789
- addListener = this.events.addListener;
790
- removeListener = this.events.removeListener;
791
- /** @hidden */
792
- getProtoInfo = (idMap) => {
793
- return {
794
- component: "text-input",
795
- key: idMap.getId(this),
796
- value: this.props.value ?? ""
797
- };
798
- };
799
- /** @hidden */
800
- handleMessage = (message) => {
801
- if (message.component === "text-input") {
802
- if (this.props.value !== message.value) {
803
- this.updateProps({ value: message.value });
804
- this.events.emit("change", message.value);
805
- }
806
- }
807
- };
808
- getValue = () => this.props.value;
809
- getValidatedValue = (validator) => this.props.value === "" ? null : validator(this.props.value || "");
810
- setValue = (value) => {
811
- this.updateProps({ value });
812
- };
813
- };
814
275
 
815
- // src/backend/components/timeline.ts
816
- var DEFAULT_PROPS7 = {
817
- state: {
818
- state: "stopped",
819
- totalTimeMillis: 0,
820
- currentTimeMillis: 0
821
- },
822
- title: null,
823
- subtitles: null,
824
- source: null
825
- };
826
- var Timeline = class extends Base {
827
- constructor(props) {
828
- super(DEFAULT_PROPS7, props);
829
- }
830
- /** @hidden */
831
- getProtoInfo = (idMap) => ({
832
- component: "timeline",
833
- key: idMap.getId(this),
834
- state: this.props.state,
835
- title: this.props.title ?? void 0,
836
- subtitles: this.props.subtitles ?? void 0,
837
- source: this.props.source ?? void 0
838
- });
839
- };
840
- // Annotate the CommonJS export names for ESM import in node:
841
- 0 && (module.exports = {
842
- Button,
843
- Group,
844
- GroupHeader,
845
- Label,
846
- Rect,
847
- SliderButton,
848
- Switch,
849
- Tab,
850
- Tabs,
851
- TextInput,
852
- Timeline,
853
- Toolkit
854
- });
276
+
277
+
278
+ exports.Button = _chunkKVJU3EADjs.Button; exports.Group = _chunkK24YPCR5js.Group; exports.GroupHeader = _chunkK24YPCR5js.GroupHeader; exports.Label = _chunkP43QUQ4Tjs.Label; exports.Rect = _chunkRGIB65TIjs.Rect; exports.SliderButton = _chunkT2PJEXYOjs.SliderButton; exports.Switch = _chunkM6EFK4GPjs.Switch; exports.Tab = _chunkRJS32OOAjs.Tab; exports.Tabs = _chunkRJS32OOAjs.Tabs; exports.TextInput = _chunkMDFDWKGWjs.TextInput; exports.Timeline = _chunkOEIGZ3NQjs.Timeline; exports.Toolkit = Toolkit;