@arcanejs/toolkit 0.2.1 → 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.
@@ -0,0 +1,66 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
2
+
3
+
4
+ var _chunkUBWCVW2Ujs = require('./chunk-UBWCVW2U.js');
5
+
6
+ // src/backend/components/button.ts
7
+ var DEFAULT_PROPS = {
8
+ text: null,
9
+ icon: null,
10
+ mode: "normal",
11
+ error: null
12
+ };
13
+ var Button = (_class = class extends _chunkUBWCVW2Ujs.Base {
14
+ /** @hidden */
15
+ __init() {this.events = new (0, _chunkUBWCVW2Ujs.EventEmitter)()}
16
+ constructor(props) {
17
+ super(DEFAULT_PROPS, props);_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);_class.prototype.__init6.call(this);_class.prototype.__init7.call(this);_class.prototype.__init8.call(this);;
18
+ }
19
+ __init2() {this.addListener = this.events.addListener}
20
+ __init3() {this.removeListener = this.events.removeListener}
21
+ __init4() {this.setText = (text) => {
22
+ this.updateProps({ text });
23
+ return this;
24
+ }}
25
+ __init5() {this.setIcon = (icon) => {
26
+ this.updateProps({ icon: _nullishCoalesce(icon, () => ( null)) });
27
+ return this;
28
+ }}
29
+ __init6() {this.setMode = (mode) => {
30
+ this.updateProps({
31
+ mode,
32
+ error: null
33
+ });
34
+ return this;
35
+ }}
36
+ /** @hidden */
37
+ __init7() {this.getProtoInfo = (idMap) => {
38
+ return {
39
+ component: "button",
40
+ key: idMap.getId(this),
41
+ text: this.props.text || "",
42
+ state: this.props.error ? { state: "error", error: this.props.error } : { state: this.props.mode },
43
+ icon: _nullishCoalesce(this.props.icon, () => ( void 0))
44
+ };
45
+ }}
46
+ /** @hidden */
47
+ __init8() {this.handleMessage = (message) => {
48
+ if (message.component === "button") {
49
+ this.events.emit("click").then(() => {
50
+ if (this.props.error) {
51
+ this.updateProps({
52
+ error: null
53
+ });
54
+ }
55
+ }).catch((e) => {
56
+ this.updateProps({
57
+ error: `${e}`
58
+ });
59
+ });
60
+ }
61
+ }}
62
+ }, _class);
63
+
64
+
65
+
66
+ exports.Button = Button;
@@ -0,0 +1,42 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
2
+
3
+
4
+ var _chunkUBWCVW2Ujs = require('./chunk-UBWCVW2U.js');
5
+
6
+ // src/backend/components/switch.ts
7
+ var DEFAULT_PROPS = {
8
+ state: "off"
9
+ };
10
+ var Switch = (_class = class extends _chunkUBWCVW2Ujs.Base {
11
+ /** @hidden */
12
+ __init() {this.events = new (0, _chunkUBWCVW2Ujs.EventEmitter)()}
13
+ constructor(props) {
14
+ super(DEFAULT_PROPS, props);_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);;
15
+ }
16
+ __init2() {this.addListener = this.events.addListener}
17
+ __init3() {this.removeListener = this.events.removeListener}
18
+ /** @hidden */
19
+ getProtoInfo(idMap) {
20
+ return {
21
+ component: "switch",
22
+ key: idMap.getId(this),
23
+ state: this.props.state
24
+ };
25
+ }
26
+ /** @hidden */
27
+ handleMessage(message) {
28
+ if (message.component === "switch") {
29
+ const state = this.props.state === "on" ? "off" : "on";
30
+ this.updateProps({ state });
31
+ this.events.emit("change", state);
32
+ }
33
+ }
34
+ setValue(state) {
35
+ if (state === this.props.state) return;
36
+ this.updateProps({ state });
37
+ }
38
+ }, _class);
39
+
40
+
41
+
42
+ exports.Switch = Switch;
@@ -0,0 +1,44 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
2
+
3
+
4
+ var _chunkUBWCVW2Ujs = require('./chunk-UBWCVW2U.js');
5
+
6
+ // src/backend/components/text-input.ts
7
+ var DEFAULT_PROPS = {
8
+ value: null
9
+ };
10
+ var TextInput = (_class = class extends _chunkUBWCVW2Ujs.Base {
11
+ /** @hidden */
12
+ __init() {this.events = new (0, _chunkUBWCVW2Ujs.EventEmitter)()}
13
+ constructor(props) {
14
+ super(DEFAULT_PROPS, props);_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);_class.prototype.__init6.call(this);_class.prototype.__init7.call(this);_class.prototype.__init8.call(this);;
15
+ }
16
+ __init2() {this.addListener = this.events.addListener}
17
+ __init3() {this.removeListener = this.events.removeListener}
18
+ /** @hidden */
19
+ __init4() {this.getProtoInfo = (idMap) => {
20
+ return {
21
+ component: "text-input",
22
+ key: idMap.getId(this),
23
+ value: _nullishCoalesce(this.props.value, () => ( ""))
24
+ };
25
+ }}
26
+ /** @hidden */
27
+ __init5() {this.handleMessage = (message) => {
28
+ if (message.component === "text-input") {
29
+ if (this.props.value !== message.value) {
30
+ this.updateProps({ value: message.value });
31
+ this.events.emit("change", message.value);
32
+ }
33
+ }
34
+ }}
35
+ __init6() {this.getValue = () => this.props.value}
36
+ __init7() {this.getValidatedValue = (validator) => this.props.value === "" ? null : validator(this.props.value || "")}
37
+ __init8() {this.setValue = (value) => {
38
+ this.updateProps({ value });
39
+ }}
40
+ }, _class);
41
+
42
+
43
+
44
+ exports.TextInput = TextInput;
@@ -0,0 +1,33 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
2
+
3
+ var _chunkUBWCVW2Ujs = require('./chunk-UBWCVW2U.js');
4
+
5
+ // src/backend/components/timeline.ts
6
+ var DEFAULT_PROPS = {
7
+ state: {
8
+ state: "stopped",
9
+ totalTimeMillis: 0,
10
+ currentTimeMillis: 0
11
+ },
12
+ title: null,
13
+ subtitles: null,
14
+ source: null
15
+ };
16
+ var Timeline = (_class = class extends _chunkUBWCVW2Ujs.Base {
17
+ constructor(props) {
18
+ super(DEFAULT_PROPS, props);_class.prototype.__init.call(this);;
19
+ }
20
+ /** @hidden */
21
+ __init() {this.getProtoInfo = (idMap) => ({
22
+ component: "timeline",
23
+ key: idMap.getId(this),
24
+ state: this.props.state,
25
+ title: _nullishCoalesce(this.props.title, () => ( void 0)),
26
+ subtitles: _nullishCoalesce(this.props.subtitles, () => ( void 0)),
27
+ source: _nullishCoalesce(this.props.source, () => ( void 0))
28
+ })}
29
+ }, _class);
30
+
31
+
32
+
33
+ exports.Timeline = Timeline;
@@ -0,0 +1,29 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+ var _chunkUBWCVW2Ujs = require('./chunk-UBWCVW2U.js');
4
+
5
+ // src/backend/components/label.ts
6
+ var Label = class extends _chunkUBWCVW2Ujs.Base {
7
+ constructor(props) {
8
+ super({ text: null }, props);
9
+ }
10
+ /** @hidden */
11
+ getProtoInfo(idMap) {
12
+ return {
13
+ component: "label",
14
+ key: idMap.getId(this),
15
+ bold: this.props.bold,
16
+ text: _nullishCoalesce(this.props.text, () => ( ""))
17
+ };
18
+ }
19
+ setText(text) {
20
+ this.updateProps({
21
+ text
22
+ });
23
+ return this;
24
+ }
25
+ };
26
+
27
+
28
+
29
+ exports.Label = Label;
@@ -0,0 +1,29 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkUBWCVW2Ujs = require('./chunk-UBWCVW2U.js');
4
+
5
+ // src/backend/components/rect.ts
6
+ var DEFAULT_PROPS = {
7
+ color: "rgba(0, 0, 0, 0)"
8
+ };
9
+ var Rect = class extends _chunkUBWCVW2Ujs.Base {
10
+ constructor(props) {
11
+ super(DEFAULT_PROPS, props);
12
+ }
13
+ /** @hidden */
14
+ getProtoInfo(idMap) {
15
+ return {
16
+ component: "rect",
17
+ key: idMap.getId(this),
18
+ color: this.props.color
19
+ };
20
+ }
21
+ setColor(color) {
22
+ this.updateProps({ color });
23
+ return this;
24
+ }
25
+ };
26
+
27
+
28
+
29
+ exports.Rect = Rect;
@@ -0,0 +1,55 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class; var _class2;
2
+
3
+ var _chunkUBWCVW2Ujs = require('./chunk-UBWCVW2U.js');
4
+
5
+ // src/backend/components/tabs.ts
6
+ var Tab = (_class = class extends _chunkUBWCVW2Ujs.BaseParent {constructor(...args) { super(...args); _class.prototype.__init.call(this);_class.prototype.__init2.call(this); }
7
+ __init() {this.validateChildren = (children) => {
8
+ if (children.length > 1) {
9
+ throw new Error("Tab can only have one child");
10
+ }
11
+ }}
12
+ /** @hidden */
13
+ __init2() {this.getProtoInfo = (idMap) => ({
14
+ component: "tab",
15
+ key: idMap.getId(this),
16
+ name: this.props.name,
17
+ child: this.getChildren().slice(0, 1).map((c) => c.getProtoInfo(idMap))[0]
18
+ })}
19
+ }, _class);
20
+ var Tabs = (_class2 = class extends _chunkUBWCVW2Ujs.BaseParent {
21
+ __init3() {this.validateChildren = (children) => {
22
+ for (const child of children) {
23
+ if (!(child instanceof Tab)) {
24
+ throw new Error("Tabs can only have Tab children");
25
+ }
26
+ }
27
+ }}
28
+ constructor(props) {
29
+ super({}, { ...props });_class2.prototype.__init3.call(this);;
30
+ }
31
+ addTabs(...tabs) {
32
+ for (const t of tabs) {
33
+ const tab = new Tab({ name: t.name });
34
+ tab.appendChildren(t.component);
35
+ this.appendChild(tab);
36
+ }
37
+ }
38
+ addTab(name, component) {
39
+ this.addTabs({ name, component });
40
+ return component;
41
+ }
42
+ /** @hidden */
43
+ getProtoInfo(idMap) {
44
+ return {
45
+ component: "tabs",
46
+ key: idMap.getId(this),
47
+ tabs: this.getChildren().map((c) => c.getProtoInfo(idMap))
48
+ };
49
+ }
50
+ }, _class2);
51
+
52
+
53
+
54
+
55
+ exports.Tab = Tab; exports.Tabs = Tabs;
@@ -0,0 +1,59 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
2
+
3
+
4
+ var _chunkUBWCVW2Ujs = require('./chunk-UBWCVW2U.js');
5
+
6
+ // src/backend/components/slider-button.ts
7
+ var DEFAULT_PROPS = {
8
+ value: null,
9
+ min: 0,
10
+ max: 255,
11
+ step: 5,
12
+ mode: "writeBack"
13
+ };
14
+ var SliderButton = (_class = class extends _chunkUBWCVW2Ujs.Base {
15
+ /** @hidden */
16
+ __init() {this.events = new (0, _chunkUBWCVW2Ujs.EventEmitter)()}
17
+ constructor(props) {
18
+ super(DEFAULT_PROPS, props);_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);;
19
+ }
20
+ __init2() {this.addListener = this.events.addListener}
21
+ __init3() {this.removeListener = this.events.removeListener}
22
+ /** @hidden */
23
+ getProtoInfo(idMap) {
24
+ return {
25
+ component: "slider_button",
26
+ key: idMap.getId(this),
27
+ min: this.props.min,
28
+ max: this.props.max,
29
+ step: this.props.step,
30
+ value: this.props.value
31
+ };
32
+ }
33
+ /** @hidden */
34
+ handleMessage(message) {
35
+ if (message.component !== "slider_button") return;
36
+ const newValue = this.sanitizeNumber(message.value);
37
+ if (this.props.value === newValue) return;
38
+ if (this.props.mode === "writeBack") {
39
+ this.updateProps({ value: newValue });
40
+ }
41
+ this.events.emit("change", newValue);
42
+ }
43
+ setValue(value) {
44
+ const newValue = this.sanitizeNumber(value);
45
+ if (newValue === this.props.value) return;
46
+ this.updateProps({ value });
47
+ this.updateTree();
48
+ }
49
+ sanitizeNumber(value) {
50
+ const i = Math.round((value - this.props.min) / this.props.step);
51
+ const v = i * this.props.step + this.props.min;
52
+ const clampedValue = Math.max(this.props.min, Math.min(this.props.max, v));
53
+ return clampedValue;
54
+ }
55
+ }, _class);
56
+
57
+
58
+
59
+ exports.SliderButton = SliderButton;
@@ -0,0 +1,163 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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; var _class3;// src/backend/components/base.ts
2
+ var Base = (_class = class {
3
+ /** @hidden */
4
+ __init() {this.parent = null}
5
+ /** @hidden */
6
+
7
+ /** @hidden */
8
+
9
+ constructor(defaultProps, props) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);
10
+ this.defaultProps = defaultProps;
11
+ this._props = Object.freeze({
12
+ ...defaultProps,
13
+ ...props
14
+ });
15
+ }
16
+ get props() {
17
+ return this._props;
18
+ }
19
+ set props(props) {
20
+ this.setProps(props);
21
+ }
22
+ __init2() {this.setProps = (props) => {
23
+ this._props = Object.freeze({
24
+ ...this.defaultProps,
25
+ ...props
26
+ });
27
+ this.updateTree();
28
+ }}
29
+ __init3() {this.updateProps = (updates) => {
30
+ this._props = Object.freeze({
31
+ ...this._props,
32
+ ...updates
33
+ });
34
+ this.updateTree();
35
+ }}
36
+ /** @hidden */
37
+ setParent(parent) {
38
+ if (this.parent && this.parent !== parent) {
39
+ this.parent.removeChild(this);
40
+ }
41
+ this.parent = parent;
42
+ }
43
+ /** @hidden */
44
+ updateTree() {
45
+ if (this.parent) this.parent.updateTree();
46
+ }
47
+ /** @hidden */
48
+ handleMessage(message) {
49
+ console.log("Component Received Message:", message);
50
+ }
51
+ routeMessage(_idMap, _message) {
52
+ }
53
+ }, _class);
54
+ var BaseParent = (_class2 = class extends Base {constructor(...args2) { super(...args2); _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); }
55
+ /** @hidden */
56
+ __init4() {this.children = []}
57
+ __init5() {this.appendChildren = (...children) => {
58
+ for (const c of children) {
59
+ const newChildren = [...this.children.filter((ch) => ch !== c), c];
60
+ this.validateChildren(newChildren);
61
+ this.children = Object.freeze(newChildren);
62
+ c.setParent(this);
63
+ }
64
+ this.updateTree();
65
+ return children;
66
+ }}
67
+ __init6() {this.appendChild = (child) => {
68
+ this.appendChildren(child);
69
+ return child;
70
+ }}
71
+ __init7() {this.removeChild = (component) => {
72
+ const match = this.children.findIndex((c) => c === component);
73
+ if (match >= 0) {
74
+ const removingChild = this.children[match];
75
+ const newChildren = [
76
+ ...this.children.slice(0, match),
77
+ ...this.children.slice(match + 1)
78
+ ];
79
+ this.validateChildren(newChildren);
80
+ this.children = Object.freeze(newChildren);
81
+ _optionalChain([removingChild, 'optionalAccess', _3 => _3.setParent, 'call', _4 => _4(null)]);
82
+ this.updateTree();
83
+ }
84
+ }}
85
+ __init8() {this.removeAllChildren = () => {
86
+ this.children.map((c) => c.setParent(null));
87
+ this.children = Object.freeze([]);
88
+ this.updateTree();
89
+ }}
90
+ /**
91
+ * Return all children components that messages need to be routed to
92
+ */
93
+ __init9() {this.getChildren = () => this.children}
94
+ /**
95
+ * TODO: we can do this better, right now it broadcasts the message to all
96
+ * components of the tree
97
+ *
98
+ * @hidden
99
+ */
100
+ routeMessage(idMap, message) {
101
+ if (idMap.getId(this) === message.componentKey) {
102
+ this.handleMessage(message);
103
+ } else {
104
+ for (const c of this.children) {
105
+ if (idMap.getId(c) === message.componentKey) {
106
+ c.handleMessage(message);
107
+ } else {
108
+ c.routeMessage(idMap, message);
109
+ }
110
+ }
111
+ }
112
+ }
113
+ insertBefore(child, beforeChild) {
114
+ const filteredChildren = this.children.filter((c) => c !== child);
115
+ let match = filteredChildren.findIndex((c) => c === beforeChild);
116
+ console.log("match", match);
117
+ if (match === -1) {
118
+ match = filteredChildren.length;
119
+ }
120
+ const newChildren = [
121
+ ...filteredChildren.slice(0, match),
122
+ child,
123
+ ...filteredChildren.slice(match)
124
+ ];
125
+ this.validateChildren(newChildren);
126
+ this.children = Object.freeze(newChildren);
127
+ child.setParent(this);
128
+ this.updateTree();
129
+ }
130
+ }, _class2);
131
+ var EventEmitter = (_class3 = class {constructor() { _class3.prototype.__init10.call(this);_class3.prototype.__init11.call(this);_class3.prototype.__init12.call(this);_class3.prototype.__init13.call(this); }
132
+ __init10() {this.listeners = /* @__PURE__ */ new Map()}
133
+ __init11() {this.addListener = (type, listener) => {
134
+ let set = this.listeners.get(type);
135
+ if (!set) {
136
+ set = /* @__PURE__ */ new Set();
137
+ this.listeners.set(type, set);
138
+ }
139
+ set.add(listener);
140
+ }}
141
+ __init12() {this.removeListener = (type, listener) => {
142
+ _optionalChain([this, 'access', _10 => _10.listeners, 'access', _11 => _11.get, 'call', _12 => _12(type), 'optionalAccess', _13 => _13.delete, 'call', _14 => _14(listener)]);
143
+ }}
144
+ __init13() {this.emit = (type, ...args) => {
145
+ return Promise.all(
146
+ [...this.listeners.get(type) || []].map(
147
+ (l) => new Promise((resolve, reject) => {
148
+ try {
149
+ resolve(l(...args));
150
+ } catch (e) {
151
+ reject(e);
152
+ }
153
+ })
154
+ )
155
+ );
156
+ }}
157
+ }, _class3);
158
+
159
+
160
+
161
+
162
+
163
+ exports.Base = Base; exports.BaseParent = BaseParent; exports.EventEmitter = EventEmitter;