canvasengine 2.0.0-beta.23 → 2.0.0-beta.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DebugRenderer-LPVGoCBJ.js +172 -0
- package/dist/DebugRenderer-LPVGoCBJ.js.map +1 -0
- package/dist/components/Canvas.d.ts +18 -0
- package/dist/components/Canvas.d.ts.map +1 -0
- package/dist/components/Container.d.ts +79 -0
- package/dist/components/Container.d.ts.map +1 -0
- package/dist/components/DOMContainer.d.ts +76 -0
- package/dist/components/DOMContainer.d.ts.map +1 -0
- package/dist/components/DOMElement.d.ts +44 -0
- package/dist/components/DOMElement.d.ts.map +1 -0
- package/dist/components/DisplayObject.d.ts +81 -0
- package/dist/components/DisplayObject.d.ts.map +1 -0
- package/dist/components/Graphic.d.ts +65 -0
- package/dist/components/Graphic.d.ts.map +1 -0
- package/dist/components/Mesh.d.ts +201 -0
- package/dist/components/Mesh.d.ts.map +1 -0
- package/dist/components/NineSliceSprite.d.ts +17 -0
- package/dist/components/NineSliceSprite.d.ts.map +1 -0
- package/dist/components/ParticleEmitter.d.ts +5 -0
- package/dist/components/ParticleEmitter.d.ts.map +1 -0
- package/dist/components/Scene.d.ts +2 -0
- package/dist/components/Scene.d.ts.map +1 -0
- package/dist/components/Sprite.d.ts +173 -0
- package/dist/components/Sprite.d.ts.map +1 -0
- package/dist/components/Text.d.ts +21 -0
- package/dist/components/Text.d.ts.map +1 -0
- package/dist/components/TilingSprite.d.ts +18 -0
- package/dist/components/TilingSprite.d.ts.map +1 -0
- package/dist/components/Video.d.ts +15 -0
- package/dist/components/Video.d.ts.map +1 -0
- package/dist/components/Viewport.d.ts +105 -0
- package/dist/components/Viewport.d.ts.map +1 -0
- package/dist/components/index.d.ts +16 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/types/DisplayObject.d.ts +106 -0
- package/dist/components/types/DisplayObject.d.ts.map +1 -0
- package/dist/components/types/MouseEvent.d.ts +4 -0
- package/dist/components/types/MouseEvent.d.ts.map +1 -0
- package/dist/components/types/Spritesheet.d.ts +366 -0
- package/dist/components/types/Spritesheet.d.ts.map +1 -0
- package/dist/components/types/index.d.ts +5 -0
- package/dist/components/types/index.d.ts.map +1 -0
- package/dist/directives/Drag.d.ts +70 -0
- package/dist/directives/Drag.d.ts.map +1 -0
- package/dist/directives/KeyboardControls.d.ts +530 -0
- package/dist/directives/KeyboardControls.d.ts.map +1 -0
- package/dist/directives/Scheduler.d.ts +36 -0
- package/dist/directives/Scheduler.d.ts.map +1 -0
- package/dist/directives/Sound.d.ts +26 -0
- package/dist/directives/Sound.d.ts.map +1 -0
- package/dist/directives/Transition.d.ts +11 -0
- package/dist/directives/Transition.d.ts.map +1 -0
- package/dist/directives/ViewportCull.d.ts +12 -0
- package/dist/directives/ViewportCull.d.ts.map +1 -0
- package/dist/directives/ViewportFollow.d.ts +19 -0
- package/dist/directives/ViewportFollow.d.ts.map +1 -0
- package/dist/directives/index.d.ts +2 -0
- package/dist/directives/index.d.ts.map +1 -0
- package/dist/engine/animation.d.ts +59 -0
- package/dist/engine/animation.d.ts.map +1 -0
- package/dist/engine/bootstrap.d.ts +16 -0
- package/dist/engine/bootstrap.d.ts.map +1 -0
- package/dist/engine/directive.d.ts +14 -0
- package/dist/engine/directive.d.ts.map +1 -0
- package/dist/engine/reactive.d.ts +68 -0
- package/dist/engine/reactive.d.ts.map +1 -0
- package/dist/engine/signal.d.ts +72 -0
- package/dist/engine/signal.d.ts.map +1 -0
- package/dist/engine/trigger.d.ts +51 -0
- package/dist/engine/trigger.d.ts.map +1 -0
- package/dist/engine/utils.d.ts +90 -0
- package/dist/engine/utils.d.ts.map +1 -0
- package/dist/hooks/addContext.d.ts +2 -0
- package/dist/hooks/addContext.d.ts.map +1 -0
- package/dist/hooks/useProps.d.ts +42 -0
- package/dist/hooks/useProps.d.ts.map +1 -0
- package/dist/hooks/useRef.d.ts +5 -0
- package/dist/hooks/useRef.d.ts.map +1 -0
- package/dist/index-5TTorHyA.js +10931 -0
- package/dist/index-5TTorHyA.js.map +1 -0
- package/dist/index.d.ts +15 -1287
- package/dist/index.d.ts.map +1 -0
- package/dist/index.global.js +29 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +61 -4258
- package/dist/index.js.map +1 -1
- package/dist/utils/Ease.d.ts +17 -0
- package/dist/utils/Ease.d.ts.map +1 -0
- package/dist/utils/RadialGradient.d.ts +58 -0
- package/dist/utils/RadialGradient.d.ts.map +1 -0
- package/dist/utils/functions.d.ts +2 -0
- package/dist/utils/functions.d.ts.map +1 -0
- package/package.json +6 -4
- package/tsconfig.json +17 -0
- package/vite.config.ts +39 -0
package/dist/index.js
CHANGED
|
@@ -1,4259 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
10
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
11
|
-
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
12
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
13
|
-
|
|
14
|
-
// src/engine/directive.ts
|
|
15
|
-
var directives = {};
|
|
16
|
-
var Directive = class {
|
|
17
|
-
};
|
|
18
|
-
function registerDirective(name, directive) {
|
|
19
|
-
directives[name] = directive;
|
|
20
|
-
}
|
|
21
|
-
function applyDirective(element, directiveName) {
|
|
22
|
-
if (!directives[directiveName]) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
const directive = new directives[directiveName]();
|
|
26
|
-
directive.onInit?.(element);
|
|
27
|
-
return directive;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// src/engine/utils.ts
|
|
31
|
-
var utils_exports = {};
|
|
32
|
-
__export(utils_exports, {
|
|
33
|
-
arrayEquals: () => arrayEquals,
|
|
34
|
-
calculateDistance: () => calculateDistance,
|
|
35
|
-
error: () => error,
|
|
36
|
-
fps2ms: () => fps2ms,
|
|
37
|
-
get: () => get,
|
|
38
|
-
isBrowser: () => isBrowser,
|
|
39
|
-
isFunction: () => isFunction,
|
|
40
|
-
isObject: () => isObject,
|
|
41
|
-
isObservable: () => isObservable,
|
|
42
|
-
isPromise: () => isPromise,
|
|
43
|
-
log: () => log,
|
|
44
|
-
preciseNow: () => preciseNow,
|
|
45
|
-
set: () => set,
|
|
46
|
-
setObservablePoint: () => setObservablePoint
|
|
47
|
-
});
|
|
48
|
-
import { Observable } from "rxjs";
|
|
49
|
-
function isBrowser() {
|
|
50
|
-
return typeof window !== "undefined";
|
|
51
|
-
}
|
|
52
|
-
function preciseNow() {
|
|
53
|
-
return typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
54
|
-
}
|
|
55
|
-
function fps2ms(fps) {
|
|
56
|
-
return 1e3 / fps;
|
|
57
|
-
}
|
|
58
|
-
function isPromise(value) {
|
|
59
|
-
return value && value instanceof Promise;
|
|
60
|
-
}
|
|
61
|
-
function arrayEquals(a, b) {
|
|
62
|
-
if (a.length !== b.length) return false;
|
|
63
|
-
for (let i = 0; i < a.length; i++) {
|
|
64
|
-
const v = a[i];
|
|
65
|
-
const bv = b[i];
|
|
66
|
-
if (typeof v === "object" && v !== null) {
|
|
67
|
-
if (typeof bv !== "object" || bv === null) return false;
|
|
68
|
-
if (Array.isArray(v)) {
|
|
69
|
-
if (!Array.isArray(bv) || !arrayEquals(v, bv)) return false;
|
|
70
|
-
} else if (!objectEquals(v, bv)) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
} else if (v !== bv) {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
function objectEquals(a, b) {
|
|
80
|
-
const keysA = Object.keys(a);
|
|
81
|
-
const keysB = Object.keys(b);
|
|
82
|
-
if (keysA.length !== keysB.length) return false;
|
|
83
|
-
for (let key of keysA) {
|
|
84
|
-
if (!b.hasOwnProperty(key)) return false;
|
|
85
|
-
if (!deepEquals(a[key], b[key])) return false;
|
|
86
|
-
}
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
function deepEquals(a, b) {
|
|
90
|
-
if (a === b) return true;
|
|
91
|
-
if (typeof a !== typeof b) return false;
|
|
92
|
-
if (typeof a === "object" && a !== null) {
|
|
93
|
-
if (Array.isArray(a)) {
|
|
94
|
-
return Array.isArray(b) && arrayEquals(a, b);
|
|
95
|
-
}
|
|
96
|
-
return objectEquals(a, b);
|
|
97
|
-
}
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
function isFunction(val) {
|
|
101
|
-
return {}.toString.call(val) === "[object Function]";
|
|
102
|
-
}
|
|
103
|
-
function isObject(val) {
|
|
104
|
-
return typeof val == "object" && val != null && !Array.isArray(val) && val.constructor === Object;
|
|
105
|
-
}
|
|
106
|
-
function isObservable(val) {
|
|
107
|
-
return val instanceof Observable;
|
|
108
|
-
}
|
|
109
|
-
function set(obj, path, value, onlyPlainObject = false) {
|
|
110
|
-
if (Object(obj) !== obj) return obj;
|
|
111
|
-
if (typeof path === "string") {
|
|
112
|
-
path = path.split(".");
|
|
113
|
-
}
|
|
114
|
-
let len = path.length;
|
|
115
|
-
if (!len) return obj;
|
|
116
|
-
let current = obj;
|
|
117
|
-
for (let i = 0; i < len - 1; i++) {
|
|
118
|
-
let segment = path[i];
|
|
119
|
-
let nextSegment = path[i + 1];
|
|
120
|
-
let isNextNumeric = !isNaN(Number(nextSegment)) && isFinite(Number(nextSegment));
|
|
121
|
-
if (!current[segment] || typeof current[segment] !== "object") {
|
|
122
|
-
current[segment] = isNextNumeric && !onlyPlainObject ? [] : {};
|
|
123
|
-
}
|
|
124
|
-
current = current[segment];
|
|
125
|
-
}
|
|
126
|
-
current[path[len - 1]] = value;
|
|
127
|
-
return obj;
|
|
128
|
-
}
|
|
129
|
-
function get(obj, path) {
|
|
130
|
-
const keys = path.split(".");
|
|
131
|
-
let current = obj;
|
|
132
|
-
for (let key of keys) {
|
|
133
|
-
if (current[key] === void 0) {
|
|
134
|
-
return void 0;
|
|
135
|
-
}
|
|
136
|
-
current = current[key];
|
|
137
|
-
}
|
|
138
|
-
return current;
|
|
139
|
-
}
|
|
140
|
-
function log(text) {
|
|
141
|
-
console.log(text);
|
|
142
|
-
}
|
|
143
|
-
function error(text) {
|
|
144
|
-
console.error(text);
|
|
145
|
-
}
|
|
146
|
-
function setObservablePoint(observablePoint, point) {
|
|
147
|
-
if (typeof point === "number") {
|
|
148
|
-
observablePoint.set(point);
|
|
149
|
-
} else if (Array.isArray(point)) {
|
|
150
|
-
observablePoint.set(point[0], point[1]);
|
|
151
|
-
} else {
|
|
152
|
-
observablePoint.set(point.x, point.y);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
function calculateDistance(x1, y1, x2, y2) {
|
|
156
|
-
const dx = x1 - x2;
|
|
157
|
-
const dy = y1 - y2;
|
|
158
|
-
return Math.sqrt(dx * dx + dy * dy);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// src/directives/KeyboardControls.ts
|
|
162
|
-
var keyCodeTable = {
|
|
163
|
-
3: "break",
|
|
164
|
-
8: "backspace",
|
|
165
|
-
// backspace / delete
|
|
166
|
-
9: "tab",
|
|
167
|
-
12: "clear",
|
|
168
|
-
13: "enter",
|
|
169
|
-
16: "shift",
|
|
170
|
-
17: "ctrl",
|
|
171
|
-
18: "alt",
|
|
172
|
-
19: "pause/break",
|
|
173
|
-
20: "caps lock",
|
|
174
|
-
27: "escape",
|
|
175
|
-
28: "conversion",
|
|
176
|
-
29: "non-conversion",
|
|
177
|
-
32: "space",
|
|
178
|
-
33: "page up",
|
|
179
|
-
34: "page down",
|
|
180
|
-
35: "end",
|
|
181
|
-
36: "home",
|
|
182
|
-
37: "left",
|
|
183
|
-
38: "up",
|
|
184
|
-
39: "right",
|
|
185
|
-
40: "down",
|
|
186
|
-
41: "select",
|
|
187
|
-
42: "print",
|
|
188
|
-
43: "execute",
|
|
189
|
-
44: "Print Screen",
|
|
190
|
-
45: "insert",
|
|
191
|
-
46: "delete",
|
|
192
|
-
48: "n0",
|
|
193
|
-
49: "n1",
|
|
194
|
-
50: "n2",
|
|
195
|
-
51: "n3",
|
|
196
|
-
52: "n4",
|
|
197
|
-
53: "n5",
|
|
198
|
-
54: "n6",
|
|
199
|
-
55: "n7",
|
|
200
|
-
56: "n8",
|
|
201
|
-
57: "n9",
|
|
202
|
-
58: ":",
|
|
203
|
-
59: "semicolon (firefox), equals",
|
|
204
|
-
60: "<",
|
|
205
|
-
61: "equals (firefox)",
|
|
206
|
-
63: "\xDF",
|
|
207
|
-
64: "@",
|
|
208
|
-
65: "a",
|
|
209
|
-
66: "b",
|
|
210
|
-
67: "c",
|
|
211
|
-
68: "d",
|
|
212
|
-
69: "e",
|
|
213
|
-
70: "f",
|
|
214
|
-
71: "g",
|
|
215
|
-
72: "h",
|
|
216
|
-
73: "i",
|
|
217
|
-
74: "j",
|
|
218
|
-
75: "k",
|
|
219
|
-
76: "l",
|
|
220
|
-
77: "m",
|
|
221
|
-
78: "n",
|
|
222
|
-
79: "o",
|
|
223
|
-
80: "p",
|
|
224
|
-
81: "q",
|
|
225
|
-
82: "r",
|
|
226
|
-
83: "s",
|
|
227
|
-
84: "t",
|
|
228
|
-
85: "u",
|
|
229
|
-
86: "v",
|
|
230
|
-
87: "w",
|
|
231
|
-
88: "x",
|
|
232
|
-
89: "y",
|
|
233
|
-
90: "z",
|
|
234
|
-
91: "Windows Key / Left \u2318 / Chromebook Search key",
|
|
235
|
-
92: "right window key",
|
|
236
|
-
93: "Windows Menu / Right \u2318",
|
|
237
|
-
96: "numpad 0",
|
|
238
|
-
97: "numpad 1",
|
|
239
|
-
98: "numpad 2",
|
|
240
|
-
99: "numpad 3",
|
|
241
|
-
100: "numpad 4",
|
|
242
|
-
101: "numpad 5",
|
|
243
|
-
102: "numpad 6",
|
|
244
|
-
103: "numpad 7",
|
|
245
|
-
104: "numpad 8",
|
|
246
|
-
105: "numpad 9",
|
|
247
|
-
106: "multiply",
|
|
248
|
-
107: "add",
|
|
249
|
-
108: "numpad period (firefox)",
|
|
250
|
-
109: "subtract",
|
|
251
|
-
110: "decimal point",
|
|
252
|
-
111: "divide",
|
|
253
|
-
112: "f1",
|
|
254
|
-
113: "f2",
|
|
255
|
-
114: "f3",
|
|
256
|
-
115: "f4",
|
|
257
|
-
116: "f5",
|
|
258
|
-
117: "f6",
|
|
259
|
-
118: "f7",
|
|
260
|
-
119: "f8",
|
|
261
|
-
120: "f9",
|
|
262
|
-
121: "f10",
|
|
263
|
-
122: "f11",
|
|
264
|
-
123: "f12",
|
|
265
|
-
124: "f13",
|
|
266
|
-
125: "f14",
|
|
267
|
-
126: "f15",
|
|
268
|
-
127: "f16",
|
|
269
|
-
128: "f17",
|
|
270
|
-
129: "f18",
|
|
271
|
-
130: "f19",
|
|
272
|
-
131: "f20",
|
|
273
|
-
132: "f21",
|
|
274
|
-
133: "f22",
|
|
275
|
-
134: "f23",
|
|
276
|
-
135: "f24",
|
|
277
|
-
144: "num lock",
|
|
278
|
-
145: "scroll lock",
|
|
279
|
-
160: "^",
|
|
280
|
-
161: "!",
|
|
281
|
-
163: "#",
|
|
282
|
-
164: "$",
|
|
283
|
-
165: "\xF9",
|
|
284
|
-
166: "page backward",
|
|
285
|
-
167: "page forward",
|
|
286
|
-
169: "closing paren (AZERTY)",
|
|
287
|
-
170: "*",
|
|
288
|
-
171: "~ + * key",
|
|
289
|
-
173: "minus (firefox), mute/unmute",
|
|
290
|
-
174: "decrease volume level",
|
|
291
|
-
175: "increase volume level",
|
|
292
|
-
176: "next",
|
|
293
|
-
177: "previous",
|
|
294
|
-
178: "stop",
|
|
295
|
-
179: "play/pause",
|
|
296
|
-
180: "e-mail",
|
|
297
|
-
181: "mute/unmute (firefox)",
|
|
298
|
-
182: "decrease volume level (firefox)",
|
|
299
|
-
183: "increase volume level (firefox)",
|
|
300
|
-
186: "semi-colon / \xF1",
|
|
301
|
-
187: "equal sign",
|
|
302
|
-
188: "comma",
|
|
303
|
-
189: "dash",
|
|
304
|
-
190: "period",
|
|
305
|
-
191: "forward slash / \xE7",
|
|
306
|
-
192: "grave accent / \xF1 / \xE6",
|
|
307
|
-
193: "?, / or \xB0",
|
|
308
|
-
194: "numpad period (chrome)",
|
|
309
|
-
219: "open bracket",
|
|
310
|
-
220: "back slash",
|
|
311
|
-
221: "close bracket / \xE5",
|
|
312
|
-
222: "single quote / \xF8",
|
|
313
|
-
223: "`",
|
|
314
|
-
224: "left or right \u2318 key (firefox)",
|
|
315
|
-
225: "altgr",
|
|
316
|
-
226: "< /git >",
|
|
317
|
-
230: "GNOME Compose Key",
|
|
318
|
-
231: "\xE7",
|
|
319
|
-
233: "XF86Forward",
|
|
320
|
-
234: "XF86Back",
|
|
321
|
-
240: "alphanumeric",
|
|
322
|
-
242: "hiragana/katakana",
|
|
323
|
-
243: "half-width/full-width",
|
|
324
|
-
244: "kanji",
|
|
325
|
-
255: "toggle touchpad"
|
|
326
|
-
};
|
|
327
|
-
var inverse = (obj) => {
|
|
328
|
-
const newObj = {};
|
|
329
|
-
for (let key in obj) {
|
|
330
|
-
const val = obj[key];
|
|
331
|
-
newObj[val] = key;
|
|
332
|
-
}
|
|
333
|
-
return newObj;
|
|
334
|
-
};
|
|
335
|
-
var inverseKeyCodeTable = inverse(keyCodeTable);
|
|
336
|
-
var KeyboardControls = class extends Directive {
|
|
337
|
-
constructor() {
|
|
338
|
-
super(...arguments);
|
|
339
|
-
this.keyState = {};
|
|
340
|
-
this.boundKeys = {};
|
|
341
|
-
this.stop = false;
|
|
342
|
-
this.lastKeyPressed = null;
|
|
343
|
-
this._controlsOptions = {};
|
|
344
|
-
// TODO: This should be dynamic
|
|
345
|
-
this.serverFps = 60;
|
|
346
|
-
this.directionState = {
|
|
347
|
-
up: false,
|
|
348
|
-
down: false,
|
|
349
|
-
left: false,
|
|
350
|
-
right: false
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
onInit(element) {
|
|
354
|
-
const value = element.props.controls.value ?? element.props.controls;
|
|
355
|
-
if (!value) return;
|
|
356
|
-
this.setupListeners();
|
|
357
|
-
this.setInputs(value);
|
|
358
|
-
this.interval = setInterval(() => {
|
|
359
|
-
this.preStep();
|
|
360
|
-
}, fps2ms(this.serverFps ?? 60));
|
|
361
|
-
}
|
|
362
|
-
onMount(element) {
|
|
363
|
-
}
|
|
364
|
-
onUpdate(props) {
|
|
365
|
-
this.setInputs(props);
|
|
366
|
-
}
|
|
367
|
-
onDestroy() {
|
|
368
|
-
clearInterval(this.interval);
|
|
369
|
-
document.removeEventListener("keydown", (e) => {
|
|
370
|
-
this.onKeyChange(e, true);
|
|
371
|
-
});
|
|
372
|
-
document.removeEventListener("keyup", (e) => {
|
|
373
|
-
this.onKeyChange(e, false);
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
/** @internal */
|
|
377
|
-
preStep() {
|
|
378
|
-
if (this.stop) return;
|
|
379
|
-
const direction = this.getDirection();
|
|
380
|
-
if (direction !== "none") {
|
|
381
|
-
const directionControl = this.boundKeys[direction];
|
|
382
|
-
if (directionControl) {
|
|
383
|
-
const { keyDown } = directionControl.options;
|
|
384
|
-
if (keyDown) {
|
|
385
|
-
this.applyInput(direction);
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
} else {
|
|
389
|
-
const boundKeys = Object.keys(this.boundKeys);
|
|
390
|
-
for (let keyName of boundKeys) {
|
|
391
|
-
this.applyInput(keyName);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
applyInput(keyName) {
|
|
396
|
-
const keyState = this.keyState[keyName];
|
|
397
|
-
if (!keyState) return;
|
|
398
|
-
const { isDown, count } = keyState;
|
|
399
|
-
if (isDown) {
|
|
400
|
-
const { repeat, keyDown } = this.boundKeys[keyName].options;
|
|
401
|
-
if (repeat || count == 0) {
|
|
402
|
-
let parameters = this.boundKeys[keyName].parameters;
|
|
403
|
-
if (typeof parameters === "function") {
|
|
404
|
-
parameters = parameters();
|
|
405
|
-
}
|
|
406
|
-
if (keyDown) {
|
|
407
|
-
keyDown(this.boundKeys[keyName]);
|
|
408
|
-
}
|
|
409
|
-
this.keyState[keyName].count++;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
setupListeners() {
|
|
414
|
-
document.addEventListener("keydown", (e) => {
|
|
415
|
-
this.onKeyChange(e, true);
|
|
416
|
-
});
|
|
417
|
-
document.addEventListener("keyup", (e) => {
|
|
418
|
-
this.onKeyChange(e, false);
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
bindKey(keys, actionName, options, parameters) {
|
|
422
|
-
if (!Array.isArray(keys)) keys = [keys];
|
|
423
|
-
const keyOptions = Object.assign({
|
|
424
|
-
repeat: false
|
|
425
|
-
}, options);
|
|
426
|
-
keys.forEach((keyName) => {
|
|
427
|
-
this.boundKeys[keyName] = { actionName, options: keyOptions, parameters };
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
applyKeyDown(name) {
|
|
431
|
-
const code = inverseKeyCodeTable[name];
|
|
432
|
-
const e = new Event("keydown");
|
|
433
|
-
e.keyCode = code;
|
|
434
|
-
this.onKeyChange(e, true);
|
|
435
|
-
}
|
|
436
|
-
applyKeyUp(name) {
|
|
437
|
-
const code = inverseKeyCodeTable[name];
|
|
438
|
-
const e = new Event("keyup");
|
|
439
|
-
e.keyCode = code;
|
|
440
|
-
this.onKeyChange(e, false);
|
|
441
|
-
}
|
|
442
|
-
applyKeyPress(name) {
|
|
443
|
-
return new Promise((resolve) => {
|
|
444
|
-
this.applyKeyDown(name);
|
|
445
|
-
setTimeout(() => {
|
|
446
|
-
this.applyKeyUp(name);
|
|
447
|
-
resolve();
|
|
448
|
-
}, 200);
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
onKeyChange(e, isDown) {
|
|
452
|
-
e = e || window.event;
|
|
453
|
-
const keyName = keyCodeTable[e.keyCode];
|
|
454
|
-
if (keyName && this.boundKeys[keyName]) {
|
|
455
|
-
if (this.keyState[keyName] == null) {
|
|
456
|
-
this.keyState[keyName] = {
|
|
457
|
-
count: 0,
|
|
458
|
-
isDown: true
|
|
459
|
-
};
|
|
460
|
-
}
|
|
461
|
-
this.keyState[keyName].isDown = isDown;
|
|
462
|
-
if (!isDown) {
|
|
463
|
-
this.keyState[keyName].count = 0;
|
|
464
|
-
const { keyUp } = this.boundKeys[keyName].options;
|
|
465
|
-
if (keyUp) {
|
|
466
|
-
keyUp(this.boundKeys[keyName]);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
this.lastKeyPressed = isDown ? e.keyCode : null;
|
|
470
|
-
}
|
|
471
|
-
if (keyName) {
|
|
472
|
-
this.updateDirectionState(keyName, isDown);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
updateDirectionState(keyName, isDown) {
|
|
476
|
-
switch (keyName) {
|
|
477
|
-
case "up":
|
|
478
|
-
this.directionState.up = isDown;
|
|
479
|
-
break;
|
|
480
|
-
case "down":
|
|
481
|
-
this.directionState.down = isDown;
|
|
482
|
-
break;
|
|
483
|
-
case "left":
|
|
484
|
-
this.directionState.left = isDown;
|
|
485
|
-
break;
|
|
486
|
-
case "right":
|
|
487
|
-
this.directionState.right = isDown;
|
|
488
|
-
break;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
getDirection() {
|
|
492
|
-
const { up, down, left, right } = this.directionState;
|
|
493
|
-
if (up && left) return "up_left";
|
|
494
|
-
if (up && right) return "up_right";
|
|
495
|
-
if (down && left) return "down_left";
|
|
496
|
-
if (down && right) return "down_right";
|
|
497
|
-
if (up) return "up";
|
|
498
|
-
if (down) return "down";
|
|
499
|
-
if (left) return "left";
|
|
500
|
-
if (right) return "right";
|
|
501
|
-
return "none";
|
|
502
|
-
}
|
|
503
|
-
/**
|
|
504
|
-
* From the name of the entry, we retrieve the control information
|
|
505
|
-
*
|
|
506
|
-
* ```ts
|
|
507
|
-
* import { Input, inject, KeyboardControls } from '@rpgjs/client'
|
|
508
|
-
*
|
|
509
|
-
* const controls = inject(KeyboardControls)
|
|
510
|
-
* controls.getControl(Input.Enter)
|
|
511
|
-
|
|
512
|
-
* if (control) {
|
|
513
|
-
* console.log(control.actionName) // action
|
|
514
|
-
* }
|
|
515
|
-
* ```
|
|
516
|
-
* @title Get Control
|
|
517
|
-
* @method getControl(inputName)
|
|
518
|
-
* @param {string} inputName
|
|
519
|
-
* @returns { { actionName: string, options: any } | undefined }
|
|
520
|
-
* @memberof KeyboardControls
|
|
521
|
-
*/
|
|
522
|
-
getControl(inputName) {
|
|
523
|
-
return this.boundKeys[inputName];
|
|
524
|
-
}
|
|
525
|
-
/**
|
|
526
|
-
* Returns all controls
|
|
527
|
-
*
|
|
528
|
-
* @method getControls()
|
|
529
|
-
* @since 4.2.0
|
|
530
|
-
* @returns { { [key: string]: BoundKey } }
|
|
531
|
-
* @memberof KeyboardControls
|
|
532
|
-
*/
|
|
533
|
-
getControls() {
|
|
534
|
-
return this.boundKeys;
|
|
535
|
-
}
|
|
536
|
-
/**
|
|
537
|
-
* Triggers an input according to the name of the control
|
|
538
|
-
*
|
|
539
|
-
* ```ts
|
|
540
|
-
* import { Control, inject, KeyboardControls } from '@rpgjs/client'
|
|
541
|
-
*
|
|
542
|
-
* const controls = inject(KeyboardControls)
|
|
543
|
-
* controls.applyControl(Control.Action)
|
|
544
|
-
* ```
|
|
545
|
-
*
|
|
546
|
-
* You can put a second parameter or indicate on whether the key is pressed or released
|
|
547
|
-
*
|
|
548
|
-
* ```ts
|
|
549
|
-
* import { Control, inject, KeyboardControls } from '@rpgjs/client'
|
|
550
|
-
*
|
|
551
|
-
* const controls = inject(KeyboardControls)
|
|
552
|
-
* controls.applyControl(Control.Up, true) // keydown
|
|
553
|
-
* controls.applyControl(Control.Up, false) // keyup
|
|
554
|
-
* ```
|
|
555
|
-
* @title Apply Control
|
|
556
|
-
* @method applyControl(controlName,isDown)
|
|
557
|
-
* @param {string} controlName
|
|
558
|
-
* @param {boolean} [isDown]
|
|
559
|
-
* @returns {Promise<void>}
|
|
560
|
-
* @memberof KeyboardControls
|
|
561
|
-
*/
|
|
562
|
-
async applyControl(controlName, isDown) {
|
|
563
|
-
const control = this._controlsOptions[controlName];
|
|
564
|
-
if (control) {
|
|
565
|
-
const input = Array.isArray(control.bind) ? control.bind[0] : control.bind;
|
|
566
|
-
if (isDown === void 0) {
|
|
567
|
-
await this.applyKeyPress(input);
|
|
568
|
-
} else if (isDown) {
|
|
569
|
-
this.applyKeyDown(input);
|
|
570
|
-
} else {
|
|
571
|
-
this.applyKeyUp(input);
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
/**
|
|
576
|
-
* Stop listening to the inputs. Pressing a key won't do anything
|
|
577
|
-
*
|
|
578
|
-
* @title Stop Inputs
|
|
579
|
-
* @method stopInputs()
|
|
580
|
-
* @returns {void}
|
|
581
|
-
* @memberof KeyboardControls
|
|
582
|
-
*/
|
|
583
|
-
stopInputs() {
|
|
584
|
-
this.stop = true;
|
|
585
|
-
}
|
|
586
|
-
/**
|
|
587
|
-
* Listen to the inputs again
|
|
588
|
-
*
|
|
589
|
-
* @title Listen Inputs
|
|
590
|
-
* @method listenInputs()
|
|
591
|
-
* @returns {void}
|
|
592
|
-
* @memberof KeyboardControls
|
|
593
|
-
*/
|
|
594
|
-
listenInputs() {
|
|
595
|
-
this.stop = false;
|
|
596
|
-
this.keyState = {};
|
|
597
|
-
}
|
|
598
|
-
/**
|
|
599
|
-
* Assign custom inputs to the scene
|
|
600
|
-
*
|
|
601
|
-
* The object is the following:
|
|
602
|
-
*
|
|
603
|
-
* * the key of the object is the name of the control. Either it is existing controls (Up, Dow, Left, Right, Action, Back) or customized controls
|
|
604
|
-
* * The value is an object representing control information:
|
|
605
|
-
* * repeat {boolean} The key can be held down to repeat the action. (false by default)
|
|
606
|
-
* * bind {string | string[]} To which key is linked the control
|
|
607
|
-
* * method {Function} Function to be triggered. If you do not set this property, the name of the control is sent directly to the server.
|
|
608
|
-
* * delay {object|number} (since v3.2.0) Indicates how long (in milliseconds) the player can press the key again to perform the action
|
|
609
|
-
* * delay.duration
|
|
610
|
-
* * delay.otherControls {string | string[]} Indicates the other controls that will also have the delay at the same time
|
|
611
|
-
*
|
|
612
|
-
* ```ts
|
|
613
|
-
* import { Control, Input, inject, KeyboardControls } from '@rpgjs/client'
|
|
614
|
-
*
|
|
615
|
-
* const controls = inject(KeyboardControls)
|
|
616
|
-
* controls.setInputs({
|
|
617
|
-
[Control.Up]: {
|
|
618
|
-
repeat: true,
|
|
619
|
-
bind: Input.Up
|
|
620
|
-
},
|
|
621
|
-
[Control.Down]: {
|
|
622
|
-
repeat: true,
|
|
623
|
-
bind: Input.Down
|
|
624
|
-
},
|
|
625
|
-
[Control.Right]: {
|
|
626
|
-
repeat: true,
|
|
627
|
-
bind: Input.Right
|
|
628
|
-
},
|
|
629
|
-
[Control.Left]: {
|
|
630
|
-
repeat: true,
|
|
631
|
-
bind: Input.Left
|
|
632
|
-
},
|
|
633
|
-
[Control.Action]: {
|
|
634
|
-
bind: [Input.Space, Input.Enter]
|
|
635
|
-
},
|
|
636
|
-
[Control.Back]: {
|
|
637
|
-
bind: Input.Escape
|
|
638
|
-
},
|
|
639
|
-
|
|
640
|
-
// The myscustom1 control is sent to the server when the A key is pressed.
|
|
641
|
-
mycustom1: {
|
|
642
|
-
bind: Input.A
|
|
643
|
-
},
|
|
644
|
-
|
|
645
|
-
// the myAction method is executed when the B key is pressed
|
|
646
|
-
mycustom2: {
|
|
647
|
-
bind: Input.B,
|
|
648
|
-
method({ actionName }) {
|
|
649
|
-
console.log('cool', actionName)
|
|
650
|
-
}
|
|
651
|
-
},
|
|
652
|
-
|
|
653
|
-
// The player can redo the action after 400ms
|
|
654
|
-
mycustom3: {
|
|
655
|
-
bind: Input.C,
|
|
656
|
-
delay: 400 // ms
|
|
657
|
-
},
|
|
658
|
-
|
|
659
|
-
// The player can redo the action (mycustom4) and the directions after 400ms
|
|
660
|
-
mycustom4: {
|
|
661
|
-
bind: Input.C,
|
|
662
|
-
delay: {
|
|
663
|
-
duration: 400,
|
|
664
|
-
otherControls: [Control.Up, Control.Down, Control.Left, Control.Right]
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
})
|
|
668
|
-
*
|
|
669
|
-
* ```
|
|
670
|
-
* @enum {string} Control
|
|
671
|
-
*
|
|
672
|
-
* Control.Up | up
|
|
673
|
-
* Control.Down | down
|
|
674
|
-
* Control.Left | left
|
|
675
|
-
* Control.Right | right
|
|
676
|
-
* Control.Action | action
|
|
677
|
-
* Control.Back | back
|
|
678
|
-
*
|
|
679
|
-
* @enum {string} Mouse Event
|
|
680
|
-
*
|
|
681
|
-
* click | Click
|
|
682
|
-
* dblclick | Double Click
|
|
683
|
-
* mousedown | Mouse Down
|
|
684
|
-
* mouseup | Mouse Up
|
|
685
|
-
* mouseover | Mouse Over
|
|
686
|
-
* mousemove | Mouse Move
|
|
687
|
-
* mouseout | Mouse Out
|
|
688
|
-
* contextmenu | Context Menu
|
|
689
|
-
*
|
|
690
|
-
*
|
|
691
|
-
* @enum {string} Input
|
|
692
|
-
*
|
|
693
|
-
* break | Pause
|
|
694
|
-
* backspace | Backspace / Delete
|
|
695
|
-
* tab | Tab
|
|
696
|
-
* clear | Clear
|
|
697
|
-
* enter | Enter
|
|
698
|
-
* shift | Shift
|
|
699
|
-
* ctrl | Control
|
|
700
|
-
* alt | Alt
|
|
701
|
-
* pause/break | Pause / Break
|
|
702
|
-
* caps lock | Caps Lock
|
|
703
|
-
* escape | Escape
|
|
704
|
-
* conversion | Conversion
|
|
705
|
-
* non-conversion | Non-conversion
|
|
706
|
-
* space | Space
|
|
707
|
-
* page up | Page Up
|
|
708
|
-
* page down | Page Down
|
|
709
|
-
* end | End
|
|
710
|
-
* home | Home
|
|
711
|
-
* left | Left Arrow
|
|
712
|
-
* up | Up Arrow
|
|
713
|
-
* right | Right Arrow
|
|
714
|
-
* down | Down Arrow
|
|
715
|
-
* select | Select
|
|
716
|
-
* print | Print
|
|
717
|
-
* execute | Execute
|
|
718
|
-
* Print Screen | Print Screen
|
|
719
|
-
* insert | Insert
|
|
720
|
-
* delete | Delete
|
|
721
|
-
* n0 | 0
|
|
722
|
-
* n1 | 1
|
|
723
|
-
* n2 | 2
|
|
724
|
-
* n3 | 3
|
|
725
|
-
* n4 | 4
|
|
726
|
-
* n5 | 5
|
|
727
|
-
* n6 | 6
|
|
728
|
-
* n7 | 7
|
|
729
|
-
* n8 | 8
|
|
730
|
-
* n9 | 9
|
|
731
|
-
* : | Colon
|
|
732
|
-
* semicolon (firefox), equals | Semicolon (Firefox), Equals
|
|
733
|
-
* < | Less Than
|
|
734
|
-
* equals (firefox) | Equals (Firefox)
|
|
735
|
-
* ß | Eszett
|
|
736
|
-
* @ | At
|
|
737
|
-
* a | A
|
|
738
|
-
* b | B
|
|
739
|
-
* c | C
|
|
740
|
-
* d | D
|
|
741
|
-
* e | E
|
|
742
|
-
* f | F
|
|
743
|
-
* g | G
|
|
744
|
-
* h | H
|
|
745
|
-
* i | I
|
|
746
|
-
* j | J
|
|
747
|
-
* k | K
|
|
748
|
-
* l | L
|
|
749
|
-
* m | M
|
|
750
|
-
* n | N
|
|
751
|
-
* o | O
|
|
752
|
-
* p | P
|
|
753
|
-
* q | Q
|
|
754
|
-
* r | R
|
|
755
|
-
* s | S
|
|
756
|
-
* t | T
|
|
757
|
-
* u | U
|
|
758
|
-
* v | V
|
|
759
|
-
* w | W
|
|
760
|
-
* x | X
|
|
761
|
-
* y | Y
|
|
762
|
-
* z | Z
|
|
763
|
-
* Windows Key / Left ⌘ / Chromebook Search key | Windows Key / Left Command ⌘ / Chromebook Search Key
|
|
764
|
-
* right window key | Right Windows Key
|
|
765
|
-
* Windows Menu / Right ⌘ | Windows Menu / Right Command ⌘
|
|
766
|
-
* numpad 0 | Numpad 0
|
|
767
|
-
* numpad 1 | Numpad 1
|
|
768
|
-
* numpad 2 | Numpad 2
|
|
769
|
-
* numpad 3 | Numpad 3
|
|
770
|
-
* numpad 4 | Numpad 4
|
|
771
|
-
* numpad 5 | Numpad 5
|
|
772
|
-
* numpad 6 | Numpad 6
|
|
773
|
-
* numpad 7 | Numpad 7
|
|
774
|
-
* numpad 8 | Numpad 8
|
|
775
|
-
* numpad 9 | Numpad 9
|
|
776
|
-
* multiply | Multiply
|
|
777
|
-
* add | Add
|
|
778
|
-
* numpad period (firefox) | Numpad Period (Firefox)
|
|
779
|
-
* subtract | Subtract
|
|
780
|
-
* decimal point | Decimal Point
|
|
781
|
-
* divide | Divide
|
|
782
|
-
* f1 | F1
|
|
783
|
-
* f2 | F2
|
|
784
|
-
* f3 | F3
|
|
785
|
-
* f4 | F4
|
|
786
|
-
* f5 | F5
|
|
787
|
-
* f6 | F6
|
|
788
|
-
* f7 | F7
|
|
789
|
-
* f8 | F8
|
|
790
|
-
* f9 | F9
|
|
791
|
-
* f10 | F10
|
|
792
|
-
* f11 | F11
|
|
793
|
-
* f12 | F12
|
|
794
|
-
* f13 | F13
|
|
795
|
-
* f14 | F14
|
|
796
|
-
* f15 | F15
|
|
797
|
-
* f16 | F16
|
|
798
|
-
* f17 | F17
|
|
799
|
-
* f18 | F18
|
|
800
|
-
* f19 | F19
|
|
801
|
-
* f20 | F20
|
|
802
|
-
* f21 | F21
|
|
803
|
-
* f22 | F22
|
|
804
|
-
* f23 | F23
|
|
805
|
-
* f24 | F24
|
|
806
|
-
* num lock | Num Lock
|
|
807
|
-
* scroll lock | Scroll Lock
|
|
808
|
-
* ^ | Caret
|
|
809
|
-
* ! | Exclamation Point
|
|
810
|
-
* # | Hash
|
|
811
|
-
* $ | Dollar Sign
|
|
812
|
-
* ù | Grave Accent U
|
|
813
|
-
* page backward | Page Backward
|
|
814
|
-
* page forward | Page Forward
|
|
815
|
-
* closing paren (AZERTY) | Closing Parenthesis (AZERTY)
|
|
816
|
-
* * | Asterisk
|
|
817
|
-
* ~ + * key | Tilde + Asterisk Key
|
|
818
|
-
* minus (firefox), mute/unmute | Minus (Firefox), Mute/Unmute
|
|
819
|
-
* decrease volume level | Decrease Volume Level
|
|
820
|
-
* increase volume level | Increase Volume Level
|
|
821
|
-
* next | Next
|
|
822
|
-
* previous | Previous
|
|
823
|
-
* stop | Stop
|
|
824
|
-
* play/pause | Play/Pause
|
|
825
|
-
* e-mail | Email
|
|
826
|
-
* mute/unmute (firefox) | Mute/Unmute (Firefox)
|
|
827
|
-
* decrease volume level (firefox) | Decrease Volume Level (Firefox)
|
|
828
|
-
* increase volume level (firefox) | Increase Volume Level (Firefox)
|
|
829
|
-
* semi-colon / ñ | Semicolon / ñ
|
|
830
|
-
* equal sign | Equal Sign
|
|
831
|
-
* comma | Comma
|
|
832
|
-
* dash | Dash
|
|
833
|
-
* period | Period
|
|
834
|
-
* forward slash / ç | Forward Slash / ç
|
|
835
|
-
* grave accent / ñ / æ | Grave Accent / ñ / æ
|
|
836
|
-
* ?, / or ° | ?, / or °
|
|
837
|
-
* numpad period (chrome) | Numpad Period (Chrome)
|
|
838
|
-
* open bracket | Open Bracket
|
|
839
|
-
* back slash | Backslash
|
|
840
|
-
* close bracket / å | Close Bracket / å
|
|
841
|
-
* single quote / ø | Single Quote / ø
|
|
842
|
-
* \` | Backtick
|
|
843
|
-
* left or right ⌘ key (firefox) | Left or Right Command Key (Firefox)
|
|
844
|
-
* altgr | AltGr
|
|
845
|
-
* < /git > | < /git >
|
|
846
|
-
* GNOME Compose Key | GNOME Compose Key
|
|
847
|
-
* ç | ç
|
|
848
|
-
* XF86Forward | XF86Forward
|
|
849
|
-
* XF86Back | XF86Back
|
|
850
|
-
* alphanumeric | Alphanumeric
|
|
851
|
-
* hiragana/katakana | Hiragana/Katakana
|
|
852
|
-
* half-width/full-width | Half-Width/Full-Width
|
|
853
|
-
* kanji | Kanji
|
|
854
|
-
* toggle touchpad | Toggle Touchpad
|
|
855
|
-
*
|
|
856
|
-
* @title Set Inputs
|
|
857
|
-
* @method setInputs(inputs)
|
|
858
|
-
* @param {object} inputs
|
|
859
|
-
* @memberof KeyboardControls
|
|
860
|
-
*/
|
|
861
|
-
setInputs(inputs) {
|
|
862
|
-
if (!inputs) return;
|
|
863
|
-
this.boundKeys = {};
|
|
864
|
-
let inputsTransformed = {};
|
|
865
|
-
for (let control in inputs) {
|
|
866
|
-
const option = inputs[control];
|
|
867
|
-
const { bind } = option;
|
|
868
|
-
let inputsKey = bind;
|
|
869
|
-
if (!Array.isArray(inputsKey)) {
|
|
870
|
-
inputsKey = [bind];
|
|
871
|
-
}
|
|
872
|
-
for (let input of inputsKey) {
|
|
873
|
-
this.bindKey(input, control, option);
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
this._controlsOptions = inputs;
|
|
877
|
-
}
|
|
878
|
-
get options() {
|
|
879
|
-
return this._controlsOptions;
|
|
880
|
-
}
|
|
881
|
-
};
|
|
882
|
-
registerDirective("controls", KeyboardControls);
|
|
883
|
-
|
|
884
|
-
// src/directives/Scheduler.ts
|
|
885
|
-
var Scheduler = class extends Directive {
|
|
886
|
-
constructor() {
|
|
887
|
-
super(...arguments);
|
|
888
|
-
this.fps = 60;
|
|
889
|
-
this.deltaTime = 0;
|
|
890
|
-
this.frame = 0;
|
|
891
|
-
this.timestamp = 0;
|
|
892
|
-
this.requestedDelay = 0;
|
|
893
|
-
this.lastTimestamp = 0;
|
|
894
|
-
this._stop = false;
|
|
895
|
-
}
|
|
896
|
-
onInit(element) {
|
|
897
|
-
this.tick = element.propObservables?.tick;
|
|
898
|
-
}
|
|
899
|
-
onDestroy() {
|
|
900
|
-
}
|
|
901
|
-
onMount(element) {
|
|
902
|
-
}
|
|
903
|
-
onUpdate(props) {
|
|
904
|
-
}
|
|
905
|
-
nextTick(timestamp) {
|
|
906
|
-
this.lastTimestamp = this.lastTimestamp || this.timestamp;
|
|
907
|
-
this.deltaTime = preciseNow() - this.timestamp;
|
|
908
|
-
this.timestamp = timestamp;
|
|
909
|
-
this.tick.set({
|
|
910
|
-
timestamp: this.timestamp,
|
|
911
|
-
deltaTime: this.deltaTime,
|
|
912
|
-
frame: this.frame,
|
|
913
|
-
deltaRatio: ~~this.deltaTime / ~~fps2ms(this.fps)
|
|
914
|
-
});
|
|
915
|
-
this.lastTimestamp = this.timestamp;
|
|
916
|
-
this.frame++;
|
|
917
|
-
}
|
|
918
|
-
/**
|
|
919
|
-
* start the schedule
|
|
920
|
-
* @return {Scheduler} returns this scheduler instance
|
|
921
|
-
*/
|
|
922
|
-
start(options = {}) {
|
|
923
|
-
if (options.maxFps) this.maxFps = options.maxFps;
|
|
924
|
-
if (options.fps) this.fps = options.fps;
|
|
925
|
-
if (options.delay) this.requestedDelay = options.delay;
|
|
926
|
-
const requestAnimationFrame = (fn) => {
|
|
927
|
-
if (isBrowser()) {
|
|
928
|
-
window.requestAnimationFrame(fn.bind(this));
|
|
929
|
-
} else {
|
|
930
|
-
setTimeout(() => {
|
|
931
|
-
this.requestedDelay = 0;
|
|
932
|
-
fn(preciseNow());
|
|
933
|
-
}, fps2ms(this.fps) + this.requestedDelay);
|
|
934
|
-
}
|
|
935
|
-
};
|
|
936
|
-
if (!this.maxFps) {
|
|
937
|
-
const loop2 = (timestamp) => {
|
|
938
|
-
requestAnimationFrame(loop2);
|
|
939
|
-
this.nextTick(timestamp);
|
|
940
|
-
};
|
|
941
|
-
requestAnimationFrame(loop2);
|
|
942
|
-
} else {
|
|
943
|
-
const msInterval = fps2ms(this.maxFps);
|
|
944
|
-
let now = preciseNow();
|
|
945
|
-
let then = preciseNow();
|
|
946
|
-
const loop2 = (timestamp) => {
|
|
947
|
-
if (this._stop) return;
|
|
948
|
-
requestAnimationFrame(loop2);
|
|
949
|
-
now = preciseNow();
|
|
950
|
-
const elapsed = now - then;
|
|
951
|
-
if (elapsed > msInterval) {
|
|
952
|
-
then = now - elapsed % msInterval;
|
|
953
|
-
this.nextTick(timestamp);
|
|
954
|
-
}
|
|
955
|
-
};
|
|
956
|
-
requestAnimationFrame(loop2);
|
|
957
|
-
}
|
|
958
|
-
return this;
|
|
959
|
-
}
|
|
960
|
-
stop() {
|
|
961
|
-
this._stop = true;
|
|
962
|
-
}
|
|
963
|
-
};
|
|
964
|
-
registerDirective("tick", Scheduler);
|
|
965
|
-
|
|
966
|
-
// src/hooks/useProps.ts
|
|
967
|
-
import { isSignal as isSignal2, signal as signal2 } from "@signe/reactive";
|
|
968
|
-
|
|
969
|
-
// src/engine/reactive.ts
|
|
970
|
-
import { isComputed, isSignal, signal } from "@signe/reactive";
|
|
971
|
-
import {
|
|
972
|
-
Observable as Observable2,
|
|
973
|
-
Subject,
|
|
974
|
-
defer,
|
|
975
|
-
from,
|
|
976
|
-
map,
|
|
977
|
-
of,
|
|
978
|
-
share
|
|
979
|
-
} from "rxjs";
|
|
980
|
-
var components = {};
|
|
981
|
-
var isElement = (value) => {
|
|
982
|
-
return value && typeof value === "object" && "tag" in value && "props" in value && "componentInstance" in value;
|
|
983
|
-
};
|
|
984
|
-
var isPrimitive = (value) => {
|
|
985
|
-
return typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null || value === void 0;
|
|
986
|
-
};
|
|
987
|
-
function registerComponent(name, component) {
|
|
988
|
-
components[name] = component;
|
|
989
|
-
}
|
|
990
|
-
function destroyElement(element) {
|
|
991
|
-
if (Array.isArray(element)) {
|
|
992
|
-
element.forEach((e) => destroyElement(e));
|
|
993
|
-
return;
|
|
994
|
-
}
|
|
995
|
-
if (!element) {
|
|
996
|
-
return;
|
|
997
|
-
}
|
|
998
|
-
if (element.props?.children) {
|
|
999
|
-
for (let child of element.props.children) {
|
|
1000
|
-
destroyElement(child);
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
for (let name in element.directives) {
|
|
1004
|
-
element.directives[name].onDestroy?.(element);
|
|
1005
|
-
}
|
|
1006
|
-
if (element.componentInstance && element.componentInstance.onDestroy) {
|
|
1007
|
-
element.componentInstance.onDestroy(element.parent, () => {
|
|
1008
|
-
element.propSubscriptions?.forEach((sub) => sub.unsubscribe());
|
|
1009
|
-
element.effectSubscriptions?.forEach((sub) => sub.unsubscribe());
|
|
1010
|
-
element.effectUnmounts?.forEach((fn) => fn?.());
|
|
1011
|
-
});
|
|
1012
|
-
} else {
|
|
1013
|
-
element.propSubscriptions?.forEach((sub) => sub.unsubscribe());
|
|
1014
|
-
element.effectSubscriptions?.forEach((sub) => sub.unsubscribe());
|
|
1015
|
-
element.effectUnmounts?.forEach((fn) => fn?.());
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
function createComponent(tag, props) {
|
|
1019
|
-
if (!components[tag]) {
|
|
1020
|
-
throw new Error(`Component ${tag} is not registered`);
|
|
1021
|
-
}
|
|
1022
|
-
const instance = new components[tag]();
|
|
1023
|
-
const element = {
|
|
1024
|
-
tag,
|
|
1025
|
-
props: {},
|
|
1026
|
-
componentInstance: instance,
|
|
1027
|
-
propSubscriptions: [],
|
|
1028
|
-
propObservables: props,
|
|
1029
|
-
parent: null,
|
|
1030
|
-
directives: {},
|
|
1031
|
-
effectUnmounts: [],
|
|
1032
|
-
effectSubscriptions: [],
|
|
1033
|
-
effectMounts: [],
|
|
1034
|
-
destroy() {
|
|
1035
|
-
destroyElement(this);
|
|
1036
|
-
},
|
|
1037
|
-
allElements: new Subject()
|
|
1038
|
-
};
|
|
1039
|
-
if (props) {
|
|
1040
|
-
const recursiveProps = (props2, path = "") => {
|
|
1041
|
-
const _set = (path2, key, value) => {
|
|
1042
|
-
if (path2 == "") {
|
|
1043
|
-
element.props[key] = value;
|
|
1044
|
-
return;
|
|
1045
|
-
}
|
|
1046
|
-
set(element.props, path2 + "." + key, value);
|
|
1047
|
-
};
|
|
1048
|
-
Object.entries(props2).forEach(([key, value]) => {
|
|
1049
|
-
if (isSignal(value)) {
|
|
1050
|
-
const _value = value;
|
|
1051
|
-
if ("dependencies" in _value && _value.dependencies.size == 0) {
|
|
1052
|
-
_set(path, key, _value());
|
|
1053
|
-
return;
|
|
1054
|
-
}
|
|
1055
|
-
element.propSubscriptions.push(
|
|
1056
|
-
_value.observable.subscribe((value2) => {
|
|
1057
|
-
_set(path, key, value2);
|
|
1058
|
-
if (element.directives[key]) {
|
|
1059
|
-
element.directives[key].onUpdate?.(value2, element);
|
|
1060
|
-
}
|
|
1061
|
-
if (key == "tick") {
|
|
1062
|
-
return;
|
|
1063
|
-
}
|
|
1064
|
-
instance.onUpdate?.(
|
|
1065
|
-
path == "" ? {
|
|
1066
|
-
[key]: value2
|
|
1067
|
-
} : set({}, path + "." + key, value2)
|
|
1068
|
-
);
|
|
1069
|
-
})
|
|
1070
|
-
);
|
|
1071
|
-
} else {
|
|
1072
|
-
if (isObject(value) && key != "context" && !isElement(value)) {
|
|
1073
|
-
recursiveProps(value, (path ? path + "." : "") + key);
|
|
1074
|
-
} else {
|
|
1075
|
-
_set(path, key, value);
|
|
1076
|
-
}
|
|
1077
|
-
}
|
|
1078
|
-
});
|
|
1079
|
-
};
|
|
1080
|
-
recursiveProps(props);
|
|
1081
|
-
}
|
|
1082
|
-
instance.onInit?.(element.props);
|
|
1083
|
-
const elementsListen = new Subject();
|
|
1084
|
-
if (props?.isRoot) {
|
|
1085
|
-
element.allElements = elementsListen;
|
|
1086
|
-
element.props.context.rootElement = element;
|
|
1087
|
-
element.componentInstance.onMount?.(element);
|
|
1088
|
-
propagateContext(element);
|
|
1089
|
-
}
|
|
1090
|
-
if (props) {
|
|
1091
|
-
for (let key in props) {
|
|
1092
|
-
const directive = applyDirective(element, key);
|
|
1093
|
-
if (directive) element.directives[key] = directive;
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
function onMount(parent, element2, index) {
|
|
1097
|
-
element2.props.context = parent.props.context;
|
|
1098
|
-
element2.parent = parent;
|
|
1099
|
-
element2.componentInstance.onMount?.(element2, index);
|
|
1100
|
-
for (let name in element2.directives) {
|
|
1101
|
-
element2.directives[name].onMount?.(element2);
|
|
1102
|
-
}
|
|
1103
|
-
element2.effectMounts.forEach((fn) => {
|
|
1104
|
-
element2.effectUnmounts.push(fn(element2));
|
|
1105
|
-
});
|
|
1106
|
-
}
|
|
1107
|
-
;
|
|
1108
|
-
async function propagateContext(element2) {
|
|
1109
|
-
if (element2.props.attach) {
|
|
1110
|
-
const isReactiveAttach = isSignal(element2.propObservables?.attach);
|
|
1111
|
-
if (!isReactiveAttach) {
|
|
1112
|
-
element2.props.children.push(element2.props.attach);
|
|
1113
|
-
} else {
|
|
1114
|
-
await new Promise((resolve) => {
|
|
1115
|
-
let lastElement = null;
|
|
1116
|
-
element2.propSubscriptions.push(element2.propObservables.attach.observable.subscribe(async (args) => {
|
|
1117
|
-
const value = args?.value ?? args;
|
|
1118
|
-
if (!value) {
|
|
1119
|
-
throw new Error(`attach in ${element2.tag} is undefined or null, add a component`);
|
|
1120
|
-
}
|
|
1121
|
-
if (lastElement) {
|
|
1122
|
-
destroyElement(lastElement);
|
|
1123
|
-
}
|
|
1124
|
-
lastElement = value;
|
|
1125
|
-
await createElement(element2, value);
|
|
1126
|
-
resolve(void 0);
|
|
1127
|
-
}));
|
|
1128
|
-
});
|
|
1129
|
-
}
|
|
1130
|
-
}
|
|
1131
|
-
if (!element2.props.children) {
|
|
1132
|
-
return;
|
|
1133
|
-
}
|
|
1134
|
-
for (let child of element2.props.children) {
|
|
1135
|
-
if (!child) continue;
|
|
1136
|
-
await createElement(element2, child);
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
;
|
|
1140
|
-
async function createElement(parent, child) {
|
|
1141
|
-
if (isPromise(child)) {
|
|
1142
|
-
child = await child;
|
|
1143
|
-
}
|
|
1144
|
-
if (child instanceof Observable2) {
|
|
1145
|
-
child.subscribe(
|
|
1146
|
-
({
|
|
1147
|
-
elements: comp,
|
|
1148
|
-
prev
|
|
1149
|
-
}) => {
|
|
1150
|
-
const components2 = comp.filter((c) => c !== null);
|
|
1151
|
-
if (prev) {
|
|
1152
|
-
components2.forEach((c) => {
|
|
1153
|
-
const index = parent.props.children.indexOf(prev.props.key);
|
|
1154
|
-
onMount(parent, c, index + 1);
|
|
1155
|
-
propagateContext(c);
|
|
1156
|
-
});
|
|
1157
|
-
return;
|
|
1158
|
-
}
|
|
1159
|
-
components2.forEach((component) => {
|
|
1160
|
-
if (!Array.isArray(component)) {
|
|
1161
|
-
onMount(parent, component);
|
|
1162
|
-
propagateContext(component);
|
|
1163
|
-
} else {
|
|
1164
|
-
component.forEach((comp2) => {
|
|
1165
|
-
onMount(parent, comp2);
|
|
1166
|
-
propagateContext(comp2);
|
|
1167
|
-
});
|
|
1168
|
-
}
|
|
1169
|
-
});
|
|
1170
|
-
elementsListen.next(void 0);
|
|
1171
|
-
}
|
|
1172
|
-
);
|
|
1173
|
-
} else {
|
|
1174
|
-
onMount(parent, child);
|
|
1175
|
-
await propagateContext(child);
|
|
1176
|
-
}
|
|
1177
|
-
}
|
|
1178
|
-
return element;
|
|
1179
|
-
}
|
|
1180
|
-
function loop(itemsSubject, createElementFn) {
|
|
1181
|
-
if (isComputed(itemsSubject) && itemsSubject.dependencies.size == 0) {
|
|
1182
|
-
itemsSubject = signal(itemsSubject());
|
|
1183
|
-
} else if (!isSignal(itemsSubject)) {
|
|
1184
|
-
itemsSubject = signal(itemsSubject);
|
|
1185
|
-
}
|
|
1186
|
-
return defer(() => {
|
|
1187
|
-
let elements = [];
|
|
1188
|
-
let elementMap = /* @__PURE__ */ new Map();
|
|
1189
|
-
let isFirstSubscription = true;
|
|
1190
|
-
const isArraySignal = (signal10) => Array.isArray(signal10());
|
|
1191
|
-
return new Observable2((subscriber) => {
|
|
1192
|
-
const subscription = isArraySignal(itemsSubject) ? itemsSubject.observable.subscribe((change) => {
|
|
1193
|
-
if (isFirstSubscription) {
|
|
1194
|
-
isFirstSubscription = false;
|
|
1195
|
-
elements.forEach((el) => el.destroy());
|
|
1196
|
-
elements = [];
|
|
1197
|
-
elementMap.clear();
|
|
1198
|
-
const items = itemsSubject();
|
|
1199
|
-
if (items) {
|
|
1200
|
-
items.forEach((item, index) => {
|
|
1201
|
-
const element = createElementFn(item, index);
|
|
1202
|
-
if (element) {
|
|
1203
|
-
elements.push(element);
|
|
1204
|
-
elementMap.set(index, element);
|
|
1205
|
-
}
|
|
1206
|
-
});
|
|
1207
|
-
}
|
|
1208
|
-
subscriber.next({
|
|
1209
|
-
elements: [...elements]
|
|
1210
|
-
});
|
|
1211
|
-
return;
|
|
1212
|
-
}
|
|
1213
|
-
if (change.type === "init" || change.type === "reset") {
|
|
1214
|
-
elements.forEach((el) => el.destroy());
|
|
1215
|
-
elements = [];
|
|
1216
|
-
elementMap.clear();
|
|
1217
|
-
const items = itemsSubject();
|
|
1218
|
-
if (items) {
|
|
1219
|
-
items.forEach((item, index) => {
|
|
1220
|
-
const element = createElementFn(item, index);
|
|
1221
|
-
if (element) {
|
|
1222
|
-
elements.push(element);
|
|
1223
|
-
elementMap.set(index, element);
|
|
1224
|
-
}
|
|
1225
|
-
});
|
|
1226
|
-
}
|
|
1227
|
-
} else if (change.type === "add" && change.index !== void 0) {
|
|
1228
|
-
const newElements = change.items.map((item, i) => {
|
|
1229
|
-
const element = createElementFn(item, change.index + i);
|
|
1230
|
-
if (element) {
|
|
1231
|
-
elementMap.set(change.index + i, element);
|
|
1232
|
-
}
|
|
1233
|
-
return element;
|
|
1234
|
-
}).filter((el) => el !== null);
|
|
1235
|
-
elements.splice(change.index, 0, ...newElements);
|
|
1236
|
-
} else if (change.type === "remove" && change.index !== void 0) {
|
|
1237
|
-
const removed = elements.splice(change.index, 1);
|
|
1238
|
-
removed.forEach((el) => {
|
|
1239
|
-
el.destroy();
|
|
1240
|
-
elementMap.delete(change.index);
|
|
1241
|
-
});
|
|
1242
|
-
} else if (change.type === "update" && change.index !== void 0 && change.items.length === 1) {
|
|
1243
|
-
const index = change.index;
|
|
1244
|
-
const newItem = change.items[0];
|
|
1245
|
-
if (index >= elements.length || elements[index] === void 0 || !elementMap.has(index)) {
|
|
1246
|
-
const newElement = createElementFn(newItem, index);
|
|
1247
|
-
if (newElement) {
|
|
1248
|
-
elements.splice(index, 0, newElement);
|
|
1249
|
-
elementMap.set(index, newElement);
|
|
1250
|
-
} else {
|
|
1251
|
-
console.warn(`Element creation returned null for index ${index} during add-like update.`);
|
|
1252
|
-
}
|
|
1253
|
-
} else {
|
|
1254
|
-
const oldElement = elements[index];
|
|
1255
|
-
oldElement.destroy();
|
|
1256
|
-
const newElement = createElementFn(newItem, index);
|
|
1257
|
-
if (newElement) {
|
|
1258
|
-
elements[index] = newElement;
|
|
1259
|
-
elementMap.set(index, newElement);
|
|
1260
|
-
} else {
|
|
1261
|
-
elements.splice(index, 1);
|
|
1262
|
-
elementMap.delete(index);
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
subscriber.next({
|
|
1267
|
-
elements: [...elements]
|
|
1268
|
-
// Create a new array to ensure change detection
|
|
1269
|
-
});
|
|
1270
|
-
}) : itemsSubject.observable.subscribe((change) => {
|
|
1271
|
-
const key = change.key;
|
|
1272
|
-
if (isFirstSubscription) {
|
|
1273
|
-
isFirstSubscription = false;
|
|
1274
|
-
elements.forEach((el) => el.destroy());
|
|
1275
|
-
elements = [];
|
|
1276
|
-
elementMap.clear();
|
|
1277
|
-
const items = itemsSubject();
|
|
1278
|
-
if (items) {
|
|
1279
|
-
Object.entries(items).forEach(([key2, value]) => {
|
|
1280
|
-
const element = createElementFn(value, key2);
|
|
1281
|
-
if (element) {
|
|
1282
|
-
elements.push(element);
|
|
1283
|
-
elementMap.set(key2, element);
|
|
1284
|
-
}
|
|
1285
|
-
});
|
|
1286
|
-
}
|
|
1287
|
-
subscriber.next({
|
|
1288
|
-
elements: [...elements]
|
|
1289
|
-
});
|
|
1290
|
-
return;
|
|
1291
|
-
}
|
|
1292
|
-
if (change.type === "init" || change.type === "reset") {
|
|
1293
|
-
elements.forEach((el) => el.destroy());
|
|
1294
|
-
elements = [];
|
|
1295
|
-
elementMap.clear();
|
|
1296
|
-
const items = itemsSubject();
|
|
1297
|
-
if (items) {
|
|
1298
|
-
Object.entries(items).forEach(([key2, value]) => {
|
|
1299
|
-
const element = createElementFn(value, key2);
|
|
1300
|
-
if (element) {
|
|
1301
|
-
elements.push(element);
|
|
1302
|
-
elementMap.set(key2, element);
|
|
1303
|
-
}
|
|
1304
|
-
});
|
|
1305
|
-
}
|
|
1306
|
-
} else if (change.type === "add" && change.key && change.value !== void 0) {
|
|
1307
|
-
const element = createElementFn(change.value, key);
|
|
1308
|
-
if (element) {
|
|
1309
|
-
elements.push(element);
|
|
1310
|
-
elementMap.set(key, element);
|
|
1311
|
-
}
|
|
1312
|
-
} else if (change.type === "remove" && change.key) {
|
|
1313
|
-
const index = elements.findIndex((el) => elementMap.get(key) === el);
|
|
1314
|
-
if (index !== -1) {
|
|
1315
|
-
const [removed] = elements.splice(index, 1);
|
|
1316
|
-
removed.destroy();
|
|
1317
|
-
elementMap.delete(key);
|
|
1318
|
-
}
|
|
1319
|
-
} else if (change.type === "update" && change.key && change.value !== void 0) {
|
|
1320
|
-
const index = elements.findIndex((el) => elementMap.get(key) === el);
|
|
1321
|
-
if (index !== -1) {
|
|
1322
|
-
const oldElement = elements[index];
|
|
1323
|
-
oldElement.destroy();
|
|
1324
|
-
const newElement = createElementFn(change.value, key);
|
|
1325
|
-
if (newElement) {
|
|
1326
|
-
elements[index] = newElement;
|
|
1327
|
-
elementMap.set(key, newElement);
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
subscriber.next({
|
|
1332
|
-
elements: [...elements]
|
|
1333
|
-
// Create a new array to ensure change detection
|
|
1334
|
-
});
|
|
1335
|
-
});
|
|
1336
|
-
return subscription;
|
|
1337
|
-
});
|
|
1338
|
-
});
|
|
1339
|
-
}
|
|
1340
|
-
function cond(condition, createElementFn) {
|
|
1341
|
-
let element = null;
|
|
1342
|
-
if (isSignal(condition)) {
|
|
1343
|
-
const signalCondition = condition;
|
|
1344
|
-
return new Observable2((subscriber) => {
|
|
1345
|
-
return signalCondition.observable.subscribe((bool) => {
|
|
1346
|
-
if (bool) {
|
|
1347
|
-
let _el = createElementFn();
|
|
1348
|
-
if (isPromise(_el)) {
|
|
1349
|
-
from(_el).subscribe((el) => {
|
|
1350
|
-
element = el;
|
|
1351
|
-
subscriber.next({
|
|
1352
|
-
type: "init",
|
|
1353
|
-
elements: [el]
|
|
1354
|
-
});
|
|
1355
|
-
});
|
|
1356
|
-
} else {
|
|
1357
|
-
element = _el;
|
|
1358
|
-
subscriber.next({
|
|
1359
|
-
type: "init",
|
|
1360
|
-
elements: [element]
|
|
1361
|
-
});
|
|
1362
|
-
}
|
|
1363
|
-
} else if (element) {
|
|
1364
|
-
destroyElement(element);
|
|
1365
|
-
subscriber.next({
|
|
1366
|
-
elements: []
|
|
1367
|
-
});
|
|
1368
|
-
} else {
|
|
1369
|
-
subscriber.next({
|
|
1370
|
-
elements: []
|
|
1371
|
-
});
|
|
1372
|
-
}
|
|
1373
|
-
});
|
|
1374
|
-
}).pipe(share());
|
|
1375
|
-
} else {
|
|
1376
|
-
if (condition) {
|
|
1377
|
-
let _el = createElementFn();
|
|
1378
|
-
if (isPromise(_el)) {
|
|
1379
|
-
return from(_el).pipe(
|
|
1380
|
-
map((el) => ({
|
|
1381
|
-
type: "init",
|
|
1382
|
-
elements: [el]
|
|
1383
|
-
}))
|
|
1384
|
-
);
|
|
1385
|
-
}
|
|
1386
|
-
return of({
|
|
1387
|
-
type: "init",
|
|
1388
|
-
elements: [_el]
|
|
1389
|
-
});
|
|
1390
|
-
}
|
|
1391
|
-
return of({
|
|
1392
|
-
elements: []
|
|
1393
|
-
});
|
|
1394
|
-
}
|
|
1395
|
-
}
|
|
1396
|
-
|
|
1397
|
-
// src/hooks/useProps.ts
|
|
1398
|
-
var useProps = (props, defaults = {}) => {
|
|
1399
|
-
if (isSignal2(props)) {
|
|
1400
|
-
return props();
|
|
1401
|
-
}
|
|
1402
|
-
const obj = {};
|
|
1403
|
-
for (let key in props) {
|
|
1404
|
-
const value = props[key];
|
|
1405
|
-
obj[key] = isPrimitive(value) ? signal2(value) : value;
|
|
1406
|
-
}
|
|
1407
|
-
for (let key in defaults) {
|
|
1408
|
-
if (!(key in obj)) {
|
|
1409
|
-
obj[key] = isPrimitive(defaults[key]) ? signal2(defaults[key]) : defaults[key];
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
return obj;
|
|
1413
|
-
};
|
|
1414
|
-
var useDefineProps = (props) => {
|
|
1415
|
-
return (schema) => {
|
|
1416
|
-
const rawProps = isSignal2(props) ? props() : props;
|
|
1417
|
-
const validatedProps = {};
|
|
1418
|
-
for (const key in schema) {
|
|
1419
|
-
const propConfig = schema[key];
|
|
1420
|
-
const value = rawProps[key];
|
|
1421
|
-
let validatedValue;
|
|
1422
|
-
if (typeof propConfig === "function") {
|
|
1423
|
-
validateType(key, value, [propConfig]);
|
|
1424
|
-
validatedValue = value;
|
|
1425
|
-
} else if (Array.isArray(propConfig)) {
|
|
1426
|
-
validateType(key, value, propConfig);
|
|
1427
|
-
validatedValue = value;
|
|
1428
|
-
} else if (propConfig && typeof propConfig === "object") {
|
|
1429
|
-
if (propConfig.required && value === void 0) {
|
|
1430
|
-
throw new Error(`Missing required prop: ${key}`);
|
|
1431
|
-
}
|
|
1432
|
-
if (propConfig.type) {
|
|
1433
|
-
const types = Array.isArray(propConfig.type) ? propConfig.type : [propConfig.type];
|
|
1434
|
-
validateType(key, value, types);
|
|
1435
|
-
}
|
|
1436
|
-
if (propConfig.validator && !propConfig.validator(value, rawProps)) {
|
|
1437
|
-
throw new Error(`Invalid prop: custom validation failed for prop "${key}"`);
|
|
1438
|
-
}
|
|
1439
|
-
if (value === void 0 && "default" in propConfig) {
|
|
1440
|
-
validatedValue = typeof propConfig.default === "function" ? propConfig.default(rawProps) : propConfig.default;
|
|
1441
|
-
} else {
|
|
1442
|
-
validatedValue = value;
|
|
1443
|
-
}
|
|
1444
|
-
}
|
|
1445
|
-
validatedProps[key] = isSignal2(validatedValue) ? validatedValue : signal2(validatedValue);
|
|
1446
|
-
}
|
|
1447
|
-
return {
|
|
1448
|
-
...useProps(rawProps),
|
|
1449
|
-
...validatedProps
|
|
1450
|
-
};
|
|
1451
|
-
};
|
|
1452
|
-
};
|
|
1453
|
-
function validateType(key, value, types) {
|
|
1454
|
-
if (value === void 0 || value === null) return;
|
|
1455
|
-
const valueToCheck = isSignal2(value) ? value() : value;
|
|
1456
|
-
const valid = types.some((type) => {
|
|
1457
|
-
if (type === Number) return typeof valueToCheck === "number";
|
|
1458
|
-
if (type === String) return typeof valueToCheck === "string";
|
|
1459
|
-
if (type === Boolean) return typeof valueToCheck === "boolean";
|
|
1460
|
-
if (type === Function) return typeof valueToCheck === "function";
|
|
1461
|
-
if (type === Object) return typeof valueToCheck === "object";
|
|
1462
|
-
if (type === Array) return Array.isArray(valueToCheck);
|
|
1463
|
-
if (type === null) return valueToCheck === null;
|
|
1464
|
-
return valueToCheck instanceof type;
|
|
1465
|
-
});
|
|
1466
|
-
if (!valid) {
|
|
1467
|
-
throw new Error(
|
|
1468
|
-
`Invalid prop: type check failed for prop "${key}". Expected ${types.map((t) => t.name).join(" or ")}`
|
|
1469
|
-
);
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
|
-
|
|
1473
|
-
// src/directives/ViewportFollow.ts
|
|
1474
|
-
var ViewportFollow = class extends Directive {
|
|
1475
|
-
onInit(element) {
|
|
1476
|
-
}
|
|
1477
|
-
onMount(element) {
|
|
1478
|
-
this.onUpdate(element.props.viewportFollow, element);
|
|
1479
|
-
}
|
|
1480
|
-
onUpdate(viewportFollow, element) {
|
|
1481
|
-
const { viewport } = element.props.context;
|
|
1482
|
-
if (!viewport) {
|
|
1483
|
-
throw error("ViewportFollow directive requires a Viewport component to be mounted in the same context");
|
|
1484
|
-
}
|
|
1485
|
-
if (viewportFollow) {
|
|
1486
|
-
if (viewportFollow === true) {
|
|
1487
|
-
viewport.follow(element.componentInstance);
|
|
1488
|
-
} else {
|
|
1489
|
-
const options = useProps(viewportFollow, {
|
|
1490
|
-
speed: void 0,
|
|
1491
|
-
acceleration: void 0,
|
|
1492
|
-
radius: void 0
|
|
1493
|
-
});
|
|
1494
|
-
viewport.follow(element.componentInstance, {
|
|
1495
|
-
speed: options.speed(),
|
|
1496
|
-
acceleration: options.acceleration(),
|
|
1497
|
-
radius: options.radius()
|
|
1498
|
-
});
|
|
1499
|
-
}
|
|
1500
|
-
} else if (viewportFollow === null) {
|
|
1501
|
-
viewport.plugins.remove("follow");
|
|
1502
|
-
}
|
|
1503
|
-
}
|
|
1504
|
-
onDestroy(element) {
|
|
1505
|
-
const { viewportFollow } = element.props;
|
|
1506
|
-
const { viewport } = element.props.context;
|
|
1507
|
-
if (viewportFollow) viewport.plugins.remove("follow");
|
|
1508
|
-
}
|
|
1509
|
-
};
|
|
1510
|
-
registerDirective("viewportFollow", ViewportFollow);
|
|
1511
|
-
|
|
1512
|
-
// src/directives/Sound.ts
|
|
1513
|
-
import { effect } from "@signe/reactive";
|
|
1514
|
-
import { Howl } from "howler";
|
|
1515
|
-
var EVENTS = ["load", "loaderror", "playerror", "play", "end", "pause", "stop", "mute", "volume", "rate", "seek", "fade", "unlock"];
|
|
1516
|
-
var Sound = class extends Directive {
|
|
1517
|
-
constructor() {
|
|
1518
|
-
super(...arguments);
|
|
1519
|
-
this.sounds = [];
|
|
1520
|
-
this.eventsFn = [];
|
|
1521
|
-
this.maxVolume = 1;
|
|
1522
|
-
this.maxDistance = 100;
|
|
1523
|
-
}
|
|
1524
|
-
onInit(element) {
|
|
1525
|
-
}
|
|
1526
|
-
onMount(element) {
|
|
1527
|
-
const { props } = element;
|
|
1528
|
-
const tick2 = props.context.tick;
|
|
1529
|
-
const propsSound = props.sound.value ?? props.sound;
|
|
1530
|
-
if (!propsSound.src) {
|
|
1531
|
-
return;
|
|
1532
|
-
}
|
|
1533
|
-
const { src, autoplay, loop: loop2, volume, spatial } = propsSound;
|
|
1534
|
-
const sources = Array.isArray(src) ? src : [src];
|
|
1535
|
-
for (const source of sources) {
|
|
1536
|
-
if (!source) continue;
|
|
1537
|
-
const sound = new Howl({
|
|
1538
|
-
src: source,
|
|
1539
|
-
autoplay,
|
|
1540
|
-
loop: loop2,
|
|
1541
|
-
volume
|
|
1542
|
-
});
|
|
1543
|
-
for (let event of EVENTS) {
|
|
1544
|
-
if (!propsSound[event]) continue;
|
|
1545
|
-
const fn = propsSound[event];
|
|
1546
|
-
this.eventsFn.push(fn);
|
|
1547
|
-
sound.on(event, fn);
|
|
1548
|
-
}
|
|
1549
|
-
this.sounds.push(sound);
|
|
1550
|
-
}
|
|
1551
|
-
if (spatial && this.sounds.length > 0) {
|
|
1552
|
-
const { soundListenerPosition } = props.context;
|
|
1553
|
-
if (!soundListenerPosition) {
|
|
1554
|
-
throw new error("SoundListenerPosition directive is required for spatial sound in component parent");
|
|
1555
|
-
}
|
|
1556
|
-
const { x: listenerX, y: listenerY } = soundListenerPosition;
|
|
1557
|
-
this.tickSubscription = effect(() => {
|
|
1558
|
-
tick2();
|
|
1559
|
-
const { x, y } = element.componentInstance;
|
|
1560
|
-
const distance = calculateDistance(x, y, listenerX(), listenerY());
|
|
1561
|
-
const volume2 = Math.max(this.maxVolume - distance / this.maxDistance, 0);
|
|
1562
|
-
this.sounds.forEach((sound) => sound.volume(volume2));
|
|
1563
|
-
}).subscription;
|
|
1564
|
-
}
|
|
1565
|
-
this.onUpdate(propsSound);
|
|
1566
|
-
}
|
|
1567
|
-
onUpdate(props) {
|
|
1568
|
-
const soundProps = props.value ?? props;
|
|
1569
|
-
const { volume, loop: loop2, mute, seek, playing, rate, spatial } = soundProps;
|
|
1570
|
-
this.sounds.forEach((sound) => {
|
|
1571
|
-
if (volume !== void 0) sound.volume(volume);
|
|
1572
|
-
if (loop2 !== void 0) sound.loop(loop2);
|
|
1573
|
-
if (mute !== void 0) sound.mute(mute);
|
|
1574
|
-
if (seek !== void 0) sound.seek(seek);
|
|
1575
|
-
if (playing !== void 0) {
|
|
1576
|
-
if (playing) sound.play();
|
|
1577
|
-
else sound.pause();
|
|
1578
|
-
}
|
|
1579
|
-
if (rate !== void 0) sound.rate(rate);
|
|
1580
|
-
});
|
|
1581
|
-
if (spatial) {
|
|
1582
|
-
this.maxVolume = spatial.maxVolume ?? this.maxVolume;
|
|
1583
|
-
this.maxDistance = spatial.maxDistance ?? this.maxDistance;
|
|
1584
|
-
}
|
|
1585
|
-
}
|
|
1586
|
-
onDestroy() {
|
|
1587
|
-
this.sounds.forEach((sound) => {
|
|
1588
|
-
sound.stop();
|
|
1589
|
-
for (let event of EVENTS) {
|
|
1590
|
-
const eventFn = this.eventsFn.find((fn) => fn === this.eventsFn[event]);
|
|
1591
|
-
if (eventFn) {
|
|
1592
|
-
sound.off(event, eventFn);
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
|
-
});
|
|
1596
|
-
this.sounds = [];
|
|
1597
|
-
this.eventsFn = [];
|
|
1598
|
-
this.tickSubscription?.unsubscribe();
|
|
1599
|
-
}
|
|
1600
|
-
};
|
|
1601
|
-
var SoundListenerPosition = class extends Directive {
|
|
1602
|
-
onMount(element) {
|
|
1603
|
-
element.props.context.soundListenerPosition = element.propObservables?.soundListenerPosition;
|
|
1604
|
-
}
|
|
1605
|
-
onInit(element) {
|
|
1606
|
-
}
|
|
1607
|
-
onUpdate(props) {
|
|
1608
|
-
}
|
|
1609
|
-
onDestroy() {
|
|
1610
|
-
}
|
|
1611
|
-
};
|
|
1612
|
-
registerDirective("sound", Sound);
|
|
1613
|
-
registerDirective("soundListenerPosition", SoundListenerPosition);
|
|
1614
|
-
|
|
1615
|
-
// src/directives/Drag.ts
|
|
1616
|
-
import { effect as effect2, isComputed as isComputed2, isSignal as isSignal3 } from "@signe/reactive";
|
|
1617
|
-
import { Rectangle, Point } from "pixi.js";
|
|
1618
|
-
import { snap } from "popmotion";
|
|
1619
|
-
|
|
1620
|
-
// src/hooks/addContext.ts
|
|
1621
|
-
var addContext = (element, key, value) => {
|
|
1622
|
-
element.props.context = {
|
|
1623
|
-
...element.props.context ?? {},
|
|
1624
|
-
[key]: value
|
|
1625
|
-
};
|
|
1626
|
-
};
|
|
1627
|
-
|
|
1628
|
-
// src/directives/Drag.ts
|
|
1629
|
-
var Drop = class extends Directive {
|
|
1630
|
-
constructor() {
|
|
1631
|
-
super(...arguments);
|
|
1632
|
-
this.elementRef = null;
|
|
1633
|
-
}
|
|
1634
|
-
onInit(element) {
|
|
1635
|
-
this.elementRef = element;
|
|
1636
|
-
}
|
|
1637
|
-
onMount(element) {
|
|
1638
|
-
addContext(element, "drop", element);
|
|
1639
|
-
}
|
|
1640
|
-
onUpdate() {
|
|
1641
|
-
}
|
|
1642
|
-
onDestroy() {
|
|
1643
|
-
this.elementRef = null;
|
|
1644
|
-
}
|
|
1645
|
-
};
|
|
1646
|
-
var Drag = class extends Directive {
|
|
1647
|
-
constructor() {
|
|
1648
|
-
super(...arguments);
|
|
1649
|
-
this.elementRef = null;
|
|
1650
|
-
this.stageRef = null;
|
|
1651
|
-
this.offsetInParent = new Point();
|
|
1652
|
-
this.isDragging = false;
|
|
1653
|
-
this.viewport = null;
|
|
1654
|
-
this.animationFrameId = null;
|
|
1655
|
-
this.lastPointerPosition = new Point();
|
|
1656
|
-
this.pressedKeys = /* @__PURE__ */ new Set();
|
|
1657
|
-
this.pointerIsDown = false;
|
|
1658
|
-
this.onDragMoveHandler = () => {
|
|
1659
|
-
};
|
|
1660
|
-
this.onDragEndHandler = () => {
|
|
1661
|
-
};
|
|
1662
|
-
this.onDragStartHandler = () => {
|
|
1663
|
-
};
|
|
1664
|
-
this.onKeyDownHandler = () => {
|
|
1665
|
-
};
|
|
1666
|
-
this.onKeyUpHandler = () => {
|
|
1667
|
-
};
|
|
1668
|
-
this.subscriptions = [];
|
|
1669
|
-
}
|
|
1670
|
-
onInit(element) {
|
|
1671
|
-
this.elementRef = element;
|
|
1672
|
-
this.onDragMoveHandler = this.onDragMove.bind(this);
|
|
1673
|
-
this.onDragEndHandler = this.onDragEnd.bind(this);
|
|
1674
|
-
this.onDragStartHandler = this.onPointerDown.bind(this);
|
|
1675
|
-
this.onKeyDownHandler = this.onKeyDown.bind(this);
|
|
1676
|
-
this.onKeyUpHandler = this.onKeyUp.bind(this);
|
|
1677
|
-
}
|
|
1678
|
-
onMount(element) {
|
|
1679
|
-
const { rootElement, canvasSize, viewport, tick: tick2 } = element.props.context;
|
|
1680
|
-
const instance = element.componentInstance;
|
|
1681
|
-
const dragProps = this.dragProps;
|
|
1682
|
-
const haveNotProps = Object.keys(dragProps).length === 0;
|
|
1683
|
-
if (haveNotProps) {
|
|
1684
|
-
this.onDestroy();
|
|
1685
|
-
return;
|
|
1686
|
-
}
|
|
1687
|
-
if (!instance) return;
|
|
1688
|
-
this.stageRef = rootElement.componentInstance;
|
|
1689
|
-
if (!this.stageRef) return;
|
|
1690
|
-
this.viewport = viewport;
|
|
1691
|
-
instance.eventMode = "static";
|
|
1692
|
-
this.stageRef.eventMode = "static";
|
|
1693
|
-
const _effect = effect2(() => {
|
|
1694
|
-
if (this.stageRef) {
|
|
1695
|
-
this.stageRef.hitArea = new Rectangle(0, 0, canvasSize().width, canvasSize().height);
|
|
1696
|
-
}
|
|
1697
|
-
});
|
|
1698
|
-
instance.on("pointerdown", this.onDragStartHandler);
|
|
1699
|
-
this.stageRef.on("pointerup", this.onDragEndHandler);
|
|
1700
|
-
this.stageRef.on("pointerupoutside", this.onDragEndHandler);
|
|
1701
|
-
const keysToPress = dragProps.keyToPress ? dragProps.keyToPress : [];
|
|
1702
|
-
window.addEventListener("keydown", this.onKeyDownHandler);
|
|
1703
|
-
window.addEventListener("keyup", this.onKeyUpHandler);
|
|
1704
|
-
this.subscriptions = [
|
|
1705
|
-
tick2.observable.subscribe(() => {
|
|
1706
|
-
if (this.isDragging && this.viewport) {
|
|
1707
|
-
this.updateViewportPosition(this.lastPointerPosition);
|
|
1708
|
-
}
|
|
1709
|
-
}),
|
|
1710
|
-
_effect.subscription
|
|
1711
|
-
];
|
|
1712
|
-
}
|
|
1713
|
-
get dragProps() {
|
|
1714
|
-
const drag = this.elementRef?.props.drag;
|
|
1715
|
-
const options = useProps(drag?.value ?? drag, {
|
|
1716
|
-
snap: 0,
|
|
1717
|
-
viewport: {},
|
|
1718
|
-
direction: "all",
|
|
1719
|
-
keyToPress: []
|
|
1720
|
-
});
|
|
1721
|
-
options.viewport = useProps(options.viewport, {
|
|
1722
|
-
edgeThreshold: 300,
|
|
1723
|
-
maxSpeed: 40
|
|
1724
|
-
});
|
|
1725
|
-
return options;
|
|
1726
|
-
}
|
|
1727
|
-
get axis() {
|
|
1728
|
-
const direction = this.dragProps.direction();
|
|
1729
|
-
const axis = {
|
|
1730
|
-
x: true,
|
|
1731
|
-
y: true
|
|
1732
|
-
};
|
|
1733
|
-
if (direction === "x") {
|
|
1734
|
-
axis.y = false;
|
|
1735
|
-
}
|
|
1736
|
-
if (direction === "y") {
|
|
1737
|
-
axis.x = false;
|
|
1738
|
-
}
|
|
1739
|
-
return axis;
|
|
1740
|
-
}
|
|
1741
|
-
/**
|
|
1742
|
-
* Updates element position when dragging and starts continuous viewport movement
|
|
1743
|
-
* @param event The pointer event that triggered the drag move
|
|
1744
|
-
*/
|
|
1745
|
-
onDragMove(event) {
|
|
1746
|
-
if (!this.isDragging || !this.elementRef?.componentInstance || !this.elementRef.componentInstance.parent) return;
|
|
1747
|
-
const instance = this.elementRef.componentInstance;
|
|
1748
|
-
const parent = instance.parent;
|
|
1749
|
-
const dragProps = this.dragProps;
|
|
1750
|
-
const propObservables = this.elementRef.propObservables;
|
|
1751
|
-
const snapTo = snap(dragProps?.snap() ?? 0);
|
|
1752
|
-
dragProps?.move?.(event);
|
|
1753
|
-
const currentParentLocalPointer = parent.toLocal(event.global);
|
|
1754
|
-
const newX = currentParentLocalPointer.x - this.offsetInParent.x;
|
|
1755
|
-
const newY = currentParentLocalPointer.y - this.offsetInParent.y;
|
|
1756
|
-
if (dragProps?.snap()) {
|
|
1757
|
-
instance.position.x = snapTo(newX);
|
|
1758
|
-
instance.position.y = snapTo(newY);
|
|
1759
|
-
} else {
|
|
1760
|
-
if (this.axis.x) instance.position.x = newX;
|
|
1761
|
-
if (this.axis.y) instance.position.y = newY;
|
|
1762
|
-
}
|
|
1763
|
-
this.lastPointerPosition.copyFrom(event.global);
|
|
1764
|
-
const { x: xProp, y: yProp } = propObservables;
|
|
1765
|
-
const updatePosition = (prop, value) => {
|
|
1766
|
-
if (isComputed2(prop)) {
|
|
1767
|
-
prop.dependencies.forEach((dependency) => {
|
|
1768
|
-
dependency.set(value);
|
|
1769
|
-
});
|
|
1770
|
-
} else if (isSignal3(prop)) {
|
|
1771
|
-
prop.set(value);
|
|
1772
|
-
}
|
|
1773
|
-
};
|
|
1774
|
-
if (xProp !== void 0) updatePosition(xProp, instance.position.x);
|
|
1775
|
-
if (yProp !== void 0) updatePosition(yProp, instance.position.y);
|
|
1776
|
-
}
|
|
1777
|
-
/**
|
|
1778
|
-
* Moves the viewport if the dragged element is near screen edges
|
|
1779
|
-
* @param globalPosition The global pointer position
|
|
1780
|
-
*/
|
|
1781
|
-
updateViewportPosition(globalPosition) {
|
|
1782
|
-
if (!this.viewport || !this.elementRef) return;
|
|
1783
|
-
const dragProps = this.dragProps;
|
|
1784
|
-
const edgeThreshold = dragProps?.viewport?.edgeThreshold();
|
|
1785
|
-
const maxSpeed = dragProps?.viewport?.maxSpeed();
|
|
1786
|
-
const screenLeft = 0;
|
|
1787
|
-
const screenRight = this.viewport.screenWidth;
|
|
1788
|
-
const screenTop = 0;
|
|
1789
|
-
const screenBottom = this.viewport.screenHeight;
|
|
1790
|
-
const instance = this.elementRef.componentInstance;
|
|
1791
|
-
const distanceFromLeft = globalPosition.x - screenLeft;
|
|
1792
|
-
const distanceFromRight = screenRight - globalPosition.x;
|
|
1793
|
-
const distanceFromTop = globalPosition.y - screenTop;
|
|
1794
|
-
const distanceFromBottom = screenBottom - globalPosition.y;
|
|
1795
|
-
let moveX = 0;
|
|
1796
|
-
let moveY = 0;
|
|
1797
|
-
if (distanceFromLeft < edgeThreshold) {
|
|
1798
|
-
const velocity = maxSpeed * (1 - distanceFromLeft / edgeThreshold);
|
|
1799
|
-
moveX = -velocity;
|
|
1800
|
-
} else if (distanceFromRight < edgeThreshold) {
|
|
1801
|
-
const velocity = maxSpeed * (1 - distanceFromRight / edgeThreshold);
|
|
1802
|
-
moveX = velocity;
|
|
1803
|
-
}
|
|
1804
|
-
if (distanceFromTop < edgeThreshold) {
|
|
1805
|
-
const velocity = maxSpeed * (1 - distanceFromTop / edgeThreshold);
|
|
1806
|
-
moveY = -velocity;
|
|
1807
|
-
} else if (distanceFromBottom < edgeThreshold) {
|
|
1808
|
-
const velocity = maxSpeed * (1 - distanceFromBottom / edgeThreshold);
|
|
1809
|
-
moveY = velocity;
|
|
1810
|
-
}
|
|
1811
|
-
if (moveX !== 0 || moveY !== 0) {
|
|
1812
|
-
const lastViewValue = this.viewport.center;
|
|
1813
|
-
this.viewport.moveCenter(
|
|
1814
|
-
this.viewport.center.x + moveX,
|
|
1815
|
-
this.viewport.center.y + moveY
|
|
1816
|
-
);
|
|
1817
|
-
if (this.axis.x && lastViewValue.x !== this.viewport.center.x) {
|
|
1818
|
-
instance.position.x += moveX;
|
|
1819
|
-
}
|
|
1820
|
-
if (this.axis.y && lastViewValue.y !== this.viewport.center.y) {
|
|
1821
|
-
instance.position.y += moveY;
|
|
1822
|
-
}
|
|
1823
|
-
}
|
|
1824
|
-
}
|
|
1825
|
-
/**
|
|
1826
|
-
* Handles drag end event and stops viewport movement
|
|
1827
|
-
*/
|
|
1828
|
-
onDragEnd() {
|
|
1829
|
-
this.pointerIsDown = false;
|
|
1830
|
-
if (!this.isDragging) return;
|
|
1831
|
-
const dragProps = this.dragProps;
|
|
1832
|
-
this.isDragging = false;
|
|
1833
|
-
dragProps?.end?.();
|
|
1834
|
-
if (this.stageRef) {
|
|
1835
|
-
this.stageRef.off("pointermove", this.onDragMoveHandler);
|
|
1836
|
-
}
|
|
1837
|
-
}
|
|
1838
|
-
onKeyDown(event) {
|
|
1839
|
-
this.pressedKeys.add(event.code);
|
|
1840
|
-
this.pressedKeys.add(event.key.toLowerCase());
|
|
1841
|
-
if (this.pointerIsDown && !this.isDragging && this.areRequiredKeysPressed()) {
|
|
1842
|
-
this.startDrag();
|
|
1843
|
-
}
|
|
1844
|
-
}
|
|
1845
|
-
onKeyUp(event) {
|
|
1846
|
-
this.pressedKeys.delete(event.code);
|
|
1847
|
-
this.pressedKeys.delete(event.key.toLowerCase());
|
|
1848
|
-
if (this.isDragging && !this.areRequiredKeysPressed()) {
|
|
1849
|
-
this.onDragEnd();
|
|
1850
|
-
}
|
|
1851
|
-
}
|
|
1852
|
-
areRequiredKeysPressed() {
|
|
1853
|
-
const keyToPress = this.dragProps.keyToPress ? this.dragProps.keyToPress : [];
|
|
1854
|
-
if (!keyToPress || keyToPress.length === 0) {
|
|
1855
|
-
return true;
|
|
1856
|
-
}
|
|
1857
|
-
return keyToPress.some((key) => {
|
|
1858
|
-
if (this.pressedKeys.has(key)) {
|
|
1859
|
-
return true;
|
|
1860
|
-
}
|
|
1861
|
-
if (key.toLowerCase() === "space") {
|
|
1862
|
-
return this.pressedKeys.has("Space") || this.pressedKeys.has(" ");
|
|
1863
|
-
}
|
|
1864
|
-
if (key.toLowerCase() === "shift") {
|
|
1865
|
-
return this.pressedKeys.has("ShiftLeft") || this.pressedKeys.has("ShiftRight");
|
|
1866
|
-
}
|
|
1867
|
-
if (key.toLowerCase() === "control" || key.toLowerCase() === "ctrl") {
|
|
1868
|
-
return this.pressedKeys.has("ControlLeft") || this.pressedKeys.has("ControlRight");
|
|
1869
|
-
}
|
|
1870
|
-
if (key.toLowerCase() === "alt") {
|
|
1871
|
-
return this.pressedKeys.has("AltLeft") || this.pressedKeys.has("AltRight");
|
|
1872
|
-
}
|
|
1873
|
-
return false;
|
|
1874
|
-
});
|
|
1875
|
-
}
|
|
1876
|
-
onPointerDown(event) {
|
|
1877
|
-
if (!this.elementRef?.componentInstance || !this.stageRef || !this.elementRef.componentInstance.parent) return;
|
|
1878
|
-
this.pointerIsDown = true;
|
|
1879
|
-
const instance = this.elementRef.componentInstance;
|
|
1880
|
-
const parent = instance.parent;
|
|
1881
|
-
const parentLocalPointer = parent.toLocal(event.global);
|
|
1882
|
-
this.offsetInParent.x = parentLocalPointer.x - instance.position.x;
|
|
1883
|
-
this.offsetInParent.y = parentLocalPointer.y - instance.position.y;
|
|
1884
|
-
this.lastPointerPosition.copyFrom(event.global);
|
|
1885
|
-
if (this.areRequiredKeysPressed()) {
|
|
1886
|
-
this.startDrag();
|
|
1887
|
-
}
|
|
1888
|
-
}
|
|
1889
|
-
startDrag() {
|
|
1890
|
-
if (this.isDragging || !this.stageRef) return;
|
|
1891
|
-
this.isDragging = true;
|
|
1892
|
-
const dragProps = this.dragProps;
|
|
1893
|
-
dragProps?.start?.();
|
|
1894
|
-
this.stageRef.on("pointermove", this.onDragMoveHandler);
|
|
1895
|
-
}
|
|
1896
|
-
onUpdate(props) {
|
|
1897
|
-
if (props.type && props.type === "reset") {
|
|
1898
|
-
this.onDestroy();
|
|
1899
|
-
this.onMount(this.elementRef);
|
|
1900
|
-
}
|
|
1901
|
-
}
|
|
1902
|
-
onDestroy() {
|
|
1903
|
-
this.subscriptions.forEach((subscription) => subscription.unsubscribe());
|
|
1904
|
-
const instance = this.elementRef?.componentInstance;
|
|
1905
|
-
if (instance) {
|
|
1906
|
-
instance.off("pointerdown", this.onDragStartHandler);
|
|
1907
|
-
}
|
|
1908
|
-
if (this.stageRef) {
|
|
1909
|
-
this.stageRef.off("pointermove", this.onDragMoveHandler);
|
|
1910
|
-
this.stageRef.off("pointerup", this.onDragEndHandler);
|
|
1911
|
-
this.stageRef.off("pointerupoutside", this.onDragEndHandler);
|
|
1912
|
-
}
|
|
1913
|
-
window.removeEventListener("keydown", this.onKeyDownHandler);
|
|
1914
|
-
window.removeEventListener("keyup", this.onKeyUpHandler);
|
|
1915
|
-
this.stageRef = null;
|
|
1916
|
-
this.viewport = null;
|
|
1917
|
-
this.pressedKeys.clear();
|
|
1918
|
-
this.pointerIsDown = false;
|
|
1919
|
-
}
|
|
1920
|
-
};
|
|
1921
|
-
registerDirective("drag", Drag);
|
|
1922
|
-
registerDirective("drop", Drop);
|
|
1923
|
-
|
|
1924
|
-
// src/directives/Transition.ts
|
|
1925
|
-
import { DisplacementFilter, Sprite, Texture, WRAP_MODES } from "pixi.js";
|
|
1926
|
-
import { animate } from "popmotion";
|
|
1927
|
-
var Transition = class extends Directive {
|
|
1928
|
-
onInit(element) {
|
|
1929
|
-
}
|
|
1930
|
-
onMount(element) {
|
|
1931
|
-
const { image } = element.props.transition;
|
|
1932
|
-
const displacementSprite = new Sprite(Texture.from(image));
|
|
1933
|
-
displacementSprite.texture.baseTexture.wrapMode = WRAP_MODES.REPEAT;
|
|
1934
|
-
const displacementFilter = new DisplacementFilter(displacementSprite);
|
|
1935
|
-
const instance = element.componentInstance;
|
|
1936
|
-
instance.filters = [displacementFilter];
|
|
1937
|
-
instance.addChild(displacementSprite);
|
|
1938
|
-
setTimeout(() => {
|
|
1939
|
-
animate({
|
|
1940
|
-
from: 0,
|
|
1941
|
-
to: 1,
|
|
1942
|
-
duration: 500,
|
|
1943
|
-
onUpdate: (progress) => {
|
|
1944
|
-
displacementFilter.scale.x = progress;
|
|
1945
|
-
displacementFilter.scale.y = progress;
|
|
1946
|
-
}
|
|
1947
|
-
});
|
|
1948
|
-
}, 5e3);
|
|
1949
|
-
}
|
|
1950
|
-
onUpdate(props) {
|
|
1951
|
-
}
|
|
1952
|
-
onDestroy() {
|
|
1953
|
-
}
|
|
1954
|
-
};
|
|
1955
|
-
registerDirective("transition", Transition);
|
|
1956
|
-
|
|
1957
|
-
// src/index.ts
|
|
1958
|
-
export * from "@signe/reactive";
|
|
1959
|
-
import { Howler } from "howler";
|
|
1960
|
-
|
|
1961
|
-
// src/components/Canvas.ts
|
|
1962
|
-
import { effect as effect3, signal as signal5 } from "@signe/reactive";
|
|
1963
|
-
import { Container as Container3 } from "pixi.js";
|
|
1964
|
-
|
|
1965
|
-
// src/components/DisplayObject.ts
|
|
1966
|
-
import { signal as signal4 } from "@signe/reactive";
|
|
1967
|
-
import { BlurFilter, ObservablePoint } from "pixi.js";
|
|
1968
|
-
|
|
1969
|
-
// src/utils/functions.ts
|
|
1970
|
-
function isPercent(value) {
|
|
1971
|
-
if (!value) return false;
|
|
1972
|
-
if (typeof value === "string") {
|
|
1973
|
-
return value.endsWith("%");
|
|
1974
|
-
}
|
|
1975
|
-
return false;
|
|
1976
|
-
}
|
|
1977
|
-
|
|
1978
|
-
// src/components/DisplayObject.ts
|
|
1979
|
-
import { BehaviorSubject } from "rxjs";
|
|
1980
|
-
var EVENTS2 = [
|
|
1981
|
-
"added",
|
|
1982
|
-
"childAdded",
|
|
1983
|
-
"childRemoved",
|
|
1984
|
-
"click",
|
|
1985
|
-
"clickcapture",
|
|
1986
|
-
"destroyed",
|
|
1987
|
-
"globalmousemove",
|
|
1988
|
-
"globalpointermove",
|
|
1989
|
-
"globaltouchmove",
|
|
1990
|
-
"mousedown",
|
|
1991
|
-
"mousedowncapture",
|
|
1992
|
-
"mouseenter",
|
|
1993
|
-
"mouseentercapture",
|
|
1994
|
-
"mouseleave",
|
|
1995
|
-
"mouseleavecapture",
|
|
1996
|
-
"mousemove",
|
|
1997
|
-
"mousemovecapture",
|
|
1998
|
-
"mouseout",
|
|
1999
|
-
"mouseoutcapture",
|
|
2000
|
-
"mouseover",
|
|
2001
|
-
"mouseovercapture",
|
|
2002
|
-
"mouseup",
|
|
2003
|
-
"mouseupcapture",
|
|
2004
|
-
"mouseupoutside",
|
|
2005
|
-
"mouseupoutsidecapture",
|
|
2006
|
-
"pointercancel",
|
|
2007
|
-
"pointercancelcapture",
|
|
2008
|
-
"pointerdown",
|
|
2009
|
-
"pointerdowncapture",
|
|
2010
|
-
"pointerenter",
|
|
2011
|
-
"pointerentercapture",
|
|
2012
|
-
"pointerleave",
|
|
2013
|
-
"pointerleavecapture",
|
|
2014
|
-
"pointermove",
|
|
2015
|
-
"pointermovecapture",
|
|
2016
|
-
"pointerout",
|
|
2017
|
-
"pointeroutcapture",
|
|
2018
|
-
"pointerover",
|
|
2019
|
-
"pointerovercapture",
|
|
2020
|
-
"pointertap",
|
|
2021
|
-
"pointertapcapture",
|
|
2022
|
-
"pointerup",
|
|
2023
|
-
"pointerupcapture",
|
|
2024
|
-
"pointerupoutside",
|
|
2025
|
-
"pointerupoutsidecapture",
|
|
2026
|
-
"removed",
|
|
2027
|
-
"rightclick",
|
|
2028
|
-
"rightclickcapture",
|
|
2029
|
-
"rightdown",
|
|
2030
|
-
"rightdowncapture",
|
|
2031
|
-
"rightup",
|
|
2032
|
-
"rightupcapture",
|
|
2033
|
-
"rightupoutside",
|
|
2034
|
-
"rightupoutsidecapture",
|
|
2035
|
-
"tap",
|
|
2036
|
-
"tapcapture",
|
|
2037
|
-
"touchcancel",
|
|
2038
|
-
"touchcancelcapture",
|
|
2039
|
-
"touchend",
|
|
2040
|
-
"touchendcapture",
|
|
2041
|
-
"touchendoutside",
|
|
2042
|
-
"touchendoutsidecapture",
|
|
2043
|
-
"touchmove",
|
|
2044
|
-
"touchmovecapture",
|
|
2045
|
-
"touchstart",
|
|
2046
|
-
"touchstartcapture",
|
|
2047
|
-
"wheel",
|
|
2048
|
-
"wheelcapture"
|
|
2049
|
-
];
|
|
2050
|
-
function DisplayObject(extendClass) {
|
|
2051
|
-
var _canvasContext, _a;
|
|
2052
|
-
return _a = class extends extendClass {
|
|
2053
|
-
constructor() {
|
|
2054
|
-
super(...arguments);
|
|
2055
|
-
__privateAdd(this, _canvasContext, null);
|
|
2056
|
-
this.isFlex = false;
|
|
2057
|
-
this.fullProps = {};
|
|
2058
|
-
this.isMounted = false;
|
|
2059
|
-
this._anchorPoints = new ObservablePoint({ _onUpdate: () => {
|
|
2060
|
-
} }, 0, 0);
|
|
2061
|
-
this.isCustomAnchor = false;
|
|
2062
|
-
this.displayWidth = signal4(0);
|
|
2063
|
-
this.displayHeight = signal4(0);
|
|
2064
|
-
this.overrideProps = [];
|
|
2065
|
-
this.layout = null;
|
|
2066
|
-
this.onBeforeDestroy = null;
|
|
2067
|
-
this.onAfterMount = null;
|
|
2068
|
-
this.subjectInit = new BehaviorSubject(null);
|
|
2069
|
-
this.disableLayout = false;
|
|
2070
|
-
}
|
|
2071
|
-
get deltaRatio() {
|
|
2072
|
-
return __privateGet(this, _canvasContext)?.scheduler?.tick.value.deltaRatio;
|
|
2073
|
-
}
|
|
2074
|
-
get parentIsFlex() {
|
|
2075
|
-
if (this.disableLayout) return false;
|
|
2076
|
-
return this.parent?.isFlex;
|
|
2077
|
-
}
|
|
2078
|
-
onInit(props) {
|
|
2079
|
-
this._id = props.id;
|
|
2080
|
-
for (let event of EVENTS2) {
|
|
2081
|
-
if (props[event] && !this.overrideProps.includes(event)) {
|
|
2082
|
-
this.eventMode = "static";
|
|
2083
|
-
this.on(event, props[event]);
|
|
2084
|
-
}
|
|
2085
|
-
}
|
|
2086
|
-
if (props.onBeforeDestroy || props["on-before-destroy"]) {
|
|
2087
|
-
this.onBeforeDestroy = props.onBeforeDestroy || props["on-before-destroy"];
|
|
2088
|
-
}
|
|
2089
|
-
if (props.onAfterMount || props["on-after-mount"]) {
|
|
2090
|
-
this.onAfterMount = props.onAfterMount || props["on-after-mount"];
|
|
2091
|
-
}
|
|
2092
|
-
if (props.justifyContent || props.alignItems || props.flexDirection || props.flexWrap || props.alignContent || props.display == "flex" || isPercent(props.width) || isPercent(props.height) || props.isRoot) {
|
|
2093
|
-
this.layout = {};
|
|
2094
|
-
this.isFlex = true;
|
|
2095
|
-
}
|
|
2096
|
-
this.subjectInit.next(this);
|
|
2097
|
-
}
|
|
2098
|
-
async onMount({ parent, props }, index) {
|
|
2099
|
-
__privateSet(this, _canvasContext, props.context);
|
|
2100
|
-
if (parent) {
|
|
2101
|
-
const instance = parent.componentInstance;
|
|
2102
|
-
if (instance.isFlex && !this.layout && !this.disableLayout) {
|
|
2103
|
-
try {
|
|
2104
|
-
this.layout = {};
|
|
2105
|
-
} catch (error2) {
|
|
2106
|
-
console.warn("Failed to set layout:", error2);
|
|
2107
|
-
}
|
|
2108
|
-
}
|
|
2109
|
-
if (index === void 0) {
|
|
2110
|
-
instance.addChild(this);
|
|
2111
|
-
} else {
|
|
2112
|
-
instance.addChildAt(this, index);
|
|
2113
|
-
}
|
|
2114
|
-
this.isMounted = true;
|
|
2115
|
-
this.onUpdate(props);
|
|
2116
|
-
if (this.onAfterMount) {
|
|
2117
|
-
await this.onAfterMount();
|
|
2118
|
-
}
|
|
2119
|
-
}
|
|
2120
|
-
}
|
|
2121
|
-
onUpdate(props) {
|
|
2122
|
-
this.fullProps = {
|
|
2123
|
-
...this.fullProps,
|
|
2124
|
-
...props
|
|
2125
|
-
};
|
|
2126
|
-
if (!__privateGet(this, _canvasContext) || !this.parent) return;
|
|
2127
|
-
if (props.x !== void 0) this.setX(props.x);
|
|
2128
|
-
if (props.y !== void 0) this.setY(props.y);
|
|
2129
|
-
if (props.scale !== void 0)
|
|
2130
|
-
setObservablePoint(this.scale, props.scale);
|
|
2131
|
-
if (props.anchor !== void 0 && !this.isCustomAnchor) {
|
|
2132
|
-
setObservablePoint(this.anchor, props.anchor);
|
|
2133
|
-
}
|
|
2134
|
-
if (props.width !== void 0) this.setWidth(props.width);
|
|
2135
|
-
if (props.height !== void 0) this.setHeight(props.height);
|
|
2136
|
-
if (props.minWidth !== void 0) this.setMinWidth(props.minWidth);
|
|
2137
|
-
if (props.minHeight !== void 0) this.setMinHeight(props.minHeight);
|
|
2138
|
-
if (props.maxWidth !== void 0) this.setMaxWidth(props.maxWidth);
|
|
2139
|
-
if (props.maxHeight !== void 0) this.setMaxHeight(props.maxHeight);
|
|
2140
|
-
if (props.aspectRatio !== void 0)
|
|
2141
|
-
this.setAspectRatio(props.aspectRatio);
|
|
2142
|
-
if (props.flexGrow !== void 0) this.setFlexGrow(props.flexGrow);
|
|
2143
|
-
if (props.flexShrink !== void 0) this.setFlexShrink(props.flexShrink);
|
|
2144
|
-
if (props.flexBasis !== void 0) this.setFlexBasis(props.flexBasis);
|
|
2145
|
-
if (props.rowGap !== void 0) this.setRowGap(props.rowGap);
|
|
2146
|
-
if (props.columnGap !== void 0) this.setColumnGap(props.columnGap);
|
|
2147
|
-
if (props.top !== void 0) this.setTop(props.top);
|
|
2148
|
-
if (props.left !== void 0) this.setLeft(props.left);
|
|
2149
|
-
if (props.right !== void 0) this.setRight(props.right);
|
|
2150
|
-
if (props.bottom !== void 0) this.setBottom(props.bottom);
|
|
2151
|
-
if (props.objectFit !== void 0) this.setObjectFit(props.objectFit);
|
|
2152
|
-
if (props.objectPosition !== void 0)
|
|
2153
|
-
this.setObjectPosition(props.objectPosition);
|
|
2154
|
-
if (props.transformOrigin !== void 0)
|
|
2155
|
-
this.setTransformOrigin(props.transformOrigin);
|
|
2156
|
-
if (props.skew !== void 0) setObservablePoint(this.skew, props.skew);
|
|
2157
|
-
if (props.tint) this.tint = props.tint;
|
|
2158
|
-
if (props.rotation !== void 0) this.rotation = props.rotation;
|
|
2159
|
-
if (props.angle !== void 0) this.angle = props.angle;
|
|
2160
|
-
if (props.zIndex !== void 0) this.zIndex = props.zIndex;
|
|
2161
|
-
if (props.roundPixels !== void 0) this.roundPixels = props.roundPixels;
|
|
2162
|
-
if (props.cursor) this.cursor = props.cursor;
|
|
2163
|
-
if (props.visible !== void 0) this.visible = props.visible;
|
|
2164
|
-
if (props.alpha !== void 0) this.alpha = props.alpha;
|
|
2165
|
-
if (props.pivot) setObservablePoint(this.pivot, props.pivot);
|
|
2166
|
-
if (props.flexDirection) this.setFlexDirection(props.flexDirection);
|
|
2167
|
-
if (props.flexWrap) this.setFlexWrap(props.flexWrap);
|
|
2168
|
-
if (props.justifyContent) this.setJustifyContent(props.justifyContent);
|
|
2169
|
-
if (props.alignItems) this.setAlignItems(props.alignItems);
|
|
2170
|
-
if (props.alignContent) this.setAlignContent(props.alignContent);
|
|
2171
|
-
if (props.alignSelf) this.setAlignSelf(props.alignSelf);
|
|
2172
|
-
if (props.margin) this.setMargin(props.margin);
|
|
2173
|
-
if (props.padding) this.setPadding(props.padding);
|
|
2174
|
-
if (props.gap) this.setGap(props.gap);
|
|
2175
|
-
if (props.border) this.setBorder(props.border);
|
|
2176
|
-
if (props.positionType) this.setPositionType(props.positionType);
|
|
2177
|
-
if (props.filters) this.filters = props.filters;
|
|
2178
|
-
if (props.maskOf) {
|
|
2179
|
-
if (isElement(props.maskOf)) {
|
|
2180
|
-
props.maskOf.componentInstance.mask = this;
|
|
2181
|
-
}
|
|
2182
|
-
}
|
|
2183
|
-
if (props.blendMode) this.blendMode = props.blendMode;
|
|
2184
|
-
if (props.filterArea) this.filterArea = props.filterArea;
|
|
2185
|
-
const currentFilters = this.filters || [];
|
|
2186
|
-
if (props.blur) {
|
|
2187
|
-
let blurFilter = currentFilters.find(
|
|
2188
|
-
(filter2) => filter2 instanceof BlurFilter
|
|
2189
|
-
);
|
|
2190
|
-
if (!blurFilter) {
|
|
2191
|
-
const options = typeof props.blur === "number" ? {
|
|
2192
|
-
strength: props.blur
|
|
2193
|
-
} : props.blur;
|
|
2194
|
-
blurFilter = new BlurFilter(options);
|
|
2195
|
-
currentFilters.push(blurFilter);
|
|
2196
|
-
}
|
|
2197
|
-
Object.assign(blurFilter, props.blur);
|
|
2198
|
-
}
|
|
2199
|
-
this.filters = currentFilters;
|
|
2200
|
-
}
|
|
2201
|
-
async onDestroy(parent, afterDestroy) {
|
|
2202
|
-
if (this.onBeforeDestroy) {
|
|
2203
|
-
await this.onBeforeDestroy();
|
|
2204
|
-
}
|
|
2205
|
-
super.destroy();
|
|
2206
|
-
if (afterDestroy) afterDestroy();
|
|
2207
|
-
}
|
|
2208
|
-
setFlexDirection(direction) {
|
|
2209
|
-
this.layout = { flexDirection: direction };
|
|
2210
|
-
}
|
|
2211
|
-
setFlexWrap(wrap) {
|
|
2212
|
-
this.layout = { flexWrap: wrap };
|
|
2213
|
-
}
|
|
2214
|
-
setAlignContent(align) {
|
|
2215
|
-
this.layout = { alignContent: align };
|
|
2216
|
-
}
|
|
2217
|
-
setAlignSelf(align) {
|
|
2218
|
-
this.layout = { alignSelf: align };
|
|
2219
|
-
}
|
|
2220
|
-
setAlignItems(align) {
|
|
2221
|
-
this.layout = { alignItems: align };
|
|
2222
|
-
}
|
|
2223
|
-
setJustifyContent(justifyContent) {
|
|
2224
|
-
this.layout = { justifyContent };
|
|
2225
|
-
}
|
|
2226
|
-
setPosition(position) {
|
|
2227
|
-
if (position instanceof Array) {
|
|
2228
|
-
if (position.length === 2) {
|
|
2229
|
-
this.layout = {
|
|
2230
|
-
positionY: position[0],
|
|
2231
|
-
positionX: position[1]
|
|
2232
|
-
};
|
|
2233
|
-
} else if (position.length === 4) {
|
|
2234
|
-
this.layout = {
|
|
2235
|
-
positionTop: position[0],
|
|
2236
|
-
positionRight: position[1],
|
|
2237
|
-
positionBottom: position[2],
|
|
2238
|
-
positionLeft: position[3]
|
|
2239
|
-
};
|
|
2240
|
-
}
|
|
2241
|
-
} else {
|
|
2242
|
-
this.layout = { position };
|
|
2243
|
-
}
|
|
2244
|
-
}
|
|
2245
|
-
setX(x) {
|
|
2246
|
-
x = x + this.getWidth() * this._anchorPoints.x;
|
|
2247
|
-
if (!this.parentIsFlex) {
|
|
2248
|
-
this.x = x;
|
|
2249
|
-
} else {
|
|
2250
|
-
this.x = x;
|
|
2251
|
-
this.layout = { x };
|
|
2252
|
-
}
|
|
2253
|
-
}
|
|
2254
|
-
setY(y) {
|
|
2255
|
-
y = y + this.getHeight() * this._anchorPoints.y;
|
|
2256
|
-
if (!this.parentIsFlex) {
|
|
2257
|
-
this.y = y;
|
|
2258
|
-
} else {
|
|
2259
|
-
this.y = y;
|
|
2260
|
-
this.layout = { y };
|
|
2261
|
-
}
|
|
2262
|
-
}
|
|
2263
|
-
setPadding(padding) {
|
|
2264
|
-
if (padding instanceof Array) {
|
|
2265
|
-
if (padding.length === 2) {
|
|
2266
|
-
this.layout = {
|
|
2267
|
-
paddingVertical: padding[0],
|
|
2268
|
-
paddingHorizontal: padding[1]
|
|
2269
|
-
};
|
|
2270
|
-
} else if (padding.length === 4) {
|
|
2271
|
-
this.layout = {
|
|
2272
|
-
paddingTop: padding[0],
|
|
2273
|
-
paddingRight: padding[1],
|
|
2274
|
-
paddingBottom: padding[2],
|
|
2275
|
-
paddingLeft: padding[3]
|
|
2276
|
-
};
|
|
2277
|
-
}
|
|
2278
|
-
} else {
|
|
2279
|
-
this.layout = { padding };
|
|
2280
|
-
}
|
|
2281
|
-
}
|
|
2282
|
-
setMargin(margin) {
|
|
2283
|
-
if (margin instanceof Array) {
|
|
2284
|
-
if (margin.length === 2) {
|
|
2285
|
-
this.layout = {
|
|
2286
|
-
marginVertical: margin[0],
|
|
2287
|
-
marginHorizontal: margin[1]
|
|
2288
|
-
};
|
|
2289
|
-
} else if (margin.length === 4) {
|
|
2290
|
-
this.layout = {
|
|
2291
|
-
marginTop: margin[0],
|
|
2292
|
-
marginRight: margin[1],
|
|
2293
|
-
marginBottom: margin[2],
|
|
2294
|
-
marginLeft: margin[3]
|
|
2295
|
-
};
|
|
2296
|
-
}
|
|
2297
|
-
} else {
|
|
2298
|
-
this.layout = { margin };
|
|
2299
|
-
}
|
|
2300
|
-
}
|
|
2301
|
-
setGap(gap) {
|
|
2302
|
-
this.layout = { gap };
|
|
2303
|
-
}
|
|
2304
|
-
setBorder(border) {
|
|
2305
|
-
if (border instanceof Array) {
|
|
2306
|
-
if (border.length === 2) {
|
|
2307
|
-
this.layout = {
|
|
2308
|
-
borderVertical: border[0],
|
|
2309
|
-
borderHorizontal: border[1]
|
|
2310
|
-
};
|
|
2311
|
-
} else if (border.length === 4) {
|
|
2312
|
-
this.layout = {
|
|
2313
|
-
borderTop: border[0],
|
|
2314
|
-
borderRight: border[1],
|
|
2315
|
-
borderBottom: border[2],
|
|
2316
|
-
borderLeft: border[3]
|
|
2317
|
-
};
|
|
2318
|
-
}
|
|
2319
|
-
} else {
|
|
2320
|
-
this.layout = { border };
|
|
2321
|
-
}
|
|
2322
|
-
}
|
|
2323
|
-
setPositionType(positionType) {
|
|
2324
|
-
this.layout = { position: positionType };
|
|
2325
|
-
}
|
|
2326
|
-
setWidth(width) {
|
|
2327
|
-
this.displayWidth.set(width);
|
|
2328
|
-
if (!this.parentIsFlex) {
|
|
2329
|
-
this.width = width;
|
|
2330
|
-
} else {
|
|
2331
|
-
this.layout = { width };
|
|
2332
|
-
}
|
|
2333
|
-
}
|
|
2334
|
-
setHeight(height) {
|
|
2335
|
-
this.displayHeight.set(height);
|
|
2336
|
-
if (!this.parentIsFlex) {
|
|
2337
|
-
this.height = height;
|
|
2338
|
-
} else {
|
|
2339
|
-
this.layout = { height };
|
|
2340
|
-
}
|
|
2341
|
-
}
|
|
2342
|
-
getWidth() {
|
|
2343
|
-
return this.displayWidth();
|
|
2344
|
-
}
|
|
2345
|
-
getHeight() {
|
|
2346
|
-
return this.displayHeight();
|
|
2347
|
-
}
|
|
2348
|
-
// Min/Max constraints
|
|
2349
|
-
setMinWidth(minWidth) {
|
|
2350
|
-
this.layout = { minWidth };
|
|
2351
|
-
}
|
|
2352
|
-
setMinHeight(minHeight) {
|
|
2353
|
-
this.layout = { minHeight };
|
|
2354
|
-
}
|
|
2355
|
-
setMaxWidth(maxWidth) {
|
|
2356
|
-
this.layout = { maxWidth };
|
|
2357
|
-
}
|
|
2358
|
-
setMaxHeight(maxHeight) {
|
|
2359
|
-
this.layout = { maxHeight };
|
|
2360
|
-
}
|
|
2361
|
-
// Aspect ratio
|
|
2362
|
-
setAspectRatio(aspectRatio) {
|
|
2363
|
-
this.layout = { aspectRatio };
|
|
2364
|
-
}
|
|
2365
|
-
// Flex properties
|
|
2366
|
-
setFlexGrow(flexGrow) {
|
|
2367
|
-
this.layout = { flexGrow };
|
|
2368
|
-
}
|
|
2369
|
-
setFlexShrink(flexShrink) {
|
|
2370
|
-
this.layout = { flexShrink };
|
|
2371
|
-
}
|
|
2372
|
-
setFlexBasis(flexBasis) {
|
|
2373
|
-
this.layout = { flexBasis };
|
|
2374
|
-
}
|
|
2375
|
-
// Gap properties
|
|
2376
|
-
setRowGap(rowGap) {
|
|
2377
|
-
this.layout = { rowGap };
|
|
2378
|
-
}
|
|
2379
|
-
setColumnGap(columnGap) {
|
|
2380
|
-
this.layout = { columnGap };
|
|
2381
|
-
}
|
|
2382
|
-
// Position insets
|
|
2383
|
-
setTop(top) {
|
|
2384
|
-
this.layout = { top };
|
|
2385
|
-
}
|
|
2386
|
-
setLeft(left) {
|
|
2387
|
-
this.layout = { left };
|
|
2388
|
-
}
|
|
2389
|
-
setRight(right) {
|
|
2390
|
-
this.layout = { right };
|
|
2391
|
-
}
|
|
2392
|
-
setBottom(bottom) {
|
|
2393
|
-
this.layout = { bottom };
|
|
2394
|
-
}
|
|
2395
|
-
// Object properties
|
|
2396
|
-
setObjectFit(objectFit) {
|
|
2397
|
-
this.layout = { objectFit };
|
|
2398
|
-
}
|
|
2399
|
-
setObjectPosition(objectPosition) {
|
|
2400
|
-
this.layout = { objectPosition };
|
|
2401
|
-
}
|
|
2402
|
-
setTransformOrigin(transformOrigin) {
|
|
2403
|
-
this.layout = { transformOrigin };
|
|
2404
|
-
}
|
|
2405
|
-
}, _canvasContext = new WeakMap(), _a;
|
|
2406
|
-
}
|
|
2407
|
-
|
|
2408
|
-
// src/components/Canvas.ts
|
|
2409
|
-
registerComponent("Canvas", class Canvas extends DisplayObject(Container3) {
|
|
2410
|
-
});
|
|
2411
|
-
var Canvas2 = async (props = {}) => {
|
|
2412
|
-
let { cursorStyles, width, height, class: className } = useProps(props);
|
|
2413
|
-
if (!props.width) width = signal5(800);
|
|
2414
|
-
if (!props.height) height = signal5(600);
|
|
2415
|
-
const canvasSize = signal5({
|
|
2416
|
-
width: 0,
|
|
2417
|
-
height: 0
|
|
2418
|
-
});
|
|
2419
|
-
props.isRoot = true;
|
|
2420
|
-
const options = {
|
|
2421
|
-
...props,
|
|
2422
|
-
context: {
|
|
2423
|
-
canvasSize,
|
|
2424
|
-
app: signal5(null)
|
|
2425
|
-
},
|
|
2426
|
-
width: width?.(),
|
|
2427
|
-
height: height?.()
|
|
2428
|
-
};
|
|
2429
|
-
if (!props.tick) {
|
|
2430
|
-
options.context.tick = options.tick = signal5({
|
|
2431
|
-
timestamp: 0,
|
|
2432
|
-
deltaTime: 0,
|
|
2433
|
-
frame: 0,
|
|
2434
|
-
deltaRatio: 1
|
|
2435
|
-
});
|
|
2436
|
-
}
|
|
2437
|
-
const canvasElement = createComponent("Canvas", options);
|
|
2438
|
-
canvasElement.render = (rootElement, app) => {
|
|
2439
|
-
if (!app) {
|
|
2440
|
-
return;
|
|
2441
|
-
}
|
|
2442
|
-
const renderer = app.renderer;
|
|
2443
|
-
const canvasEl = renderer.view.canvas;
|
|
2444
|
-
globalThis.__PIXI_STAGE__ = canvasElement.componentInstance;
|
|
2445
|
-
globalThis.__PIXI_RENDERER__ = renderer;
|
|
2446
|
-
if (props.tickStart !== false) canvasElement.directives.tick.start();
|
|
2447
|
-
effect3(() => {
|
|
2448
|
-
canvasElement.propObservables.tick();
|
|
2449
|
-
renderer.render(canvasElement.componentInstance);
|
|
2450
|
-
});
|
|
2451
|
-
app.stage = canvasElement.componentInstance;
|
|
2452
|
-
app.stage.layout = {
|
|
2453
|
-
width: app.screen.width,
|
|
2454
|
-
height: app.screen.height,
|
|
2455
|
-
justifyContent: props.justifyContent,
|
|
2456
|
-
alignItems: props.alignItems
|
|
2457
|
-
};
|
|
2458
|
-
canvasSize.set({ width: app.screen.width, height: app.screen.height });
|
|
2459
|
-
app.renderer.on("resize", (width2, height2) => {
|
|
2460
|
-
canvasSize.set({ width: width2, height: height2 });
|
|
2461
|
-
if (app.stage.layout) {
|
|
2462
|
-
app.stage.layout = {
|
|
2463
|
-
width: width2,
|
|
2464
|
-
height: height2
|
|
2465
|
-
};
|
|
2466
|
-
}
|
|
2467
|
-
});
|
|
2468
|
-
if (props.tickStart !== false) canvasElement.directives.tick.start();
|
|
2469
|
-
app.ticker.add(() => {
|
|
2470
|
-
canvasElement.propObservables.tick();
|
|
2471
|
-
});
|
|
2472
|
-
if (cursorStyles) {
|
|
2473
|
-
effect3(() => {
|
|
2474
|
-
renderer.events.cursorStyles = cursorStyles();
|
|
2475
|
-
});
|
|
2476
|
-
}
|
|
2477
|
-
if (className) {
|
|
2478
|
-
effect3(() => {
|
|
2479
|
-
canvasEl.classList.add(className());
|
|
2480
|
-
});
|
|
2481
|
-
}
|
|
2482
|
-
const existingCanvas = rootElement.querySelector("canvas");
|
|
2483
|
-
if (existingCanvas) {
|
|
2484
|
-
rootElement.replaceChild(canvasEl, existingCanvas);
|
|
2485
|
-
} else {
|
|
2486
|
-
rootElement.appendChild(canvasEl);
|
|
2487
|
-
}
|
|
2488
|
-
options.context.app.set(app);
|
|
2489
|
-
};
|
|
2490
|
-
return canvasElement;
|
|
2491
|
-
};
|
|
2492
|
-
|
|
2493
|
-
// src/components/Container.ts
|
|
2494
|
-
import { Container as PixiContainer } from "pixi.js";
|
|
2495
|
-
var CanvasContainer = class extends DisplayObject(PixiContainer) {
|
|
2496
|
-
constructor() {
|
|
2497
|
-
super(...arguments);
|
|
2498
|
-
this.isCustomAnchor = true;
|
|
2499
|
-
}
|
|
2500
|
-
onUpdate(props) {
|
|
2501
|
-
if (props.anchor) {
|
|
2502
|
-
setObservablePoint(this._anchorPoints, props.anchor);
|
|
2503
|
-
props.pivot = [
|
|
2504
|
-
this.getWidth() * this._anchorPoints.x,
|
|
2505
|
-
this.getHeight() * this._anchorPoints.y
|
|
2506
|
-
];
|
|
2507
|
-
}
|
|
2508
|
-
super.onUpdate(props);
|
|
2509
|
-
if (props.sortableChildren != void 0) {
|
|
2510
|
-
this.sortableChildren = props.sortableChildren;
|
|
2511
|
-
}
|
|
2512
|
-
}
|
|
2513
|
-
async onMount(args) {
|
|
2514
|
-
await super.onMount(args);
|
|
2515
|
-
const { componentInstance, props } = args;
|
|
2516
|
-
const { pixiChildren } = props;
|
|
2517
|
-
if (pixiChildren) {
|
|
2518
|
-
pixiChildren.forEach((child) => {
|
|
2519
|
-
componentInstance.addChild(child);
|
|
2520
|
-
});
|
|
2521
|
-
}
|
|
2522
|
-
}
|
|
2523
|
-
};
|
|
2524
|
-
registerComponent("Container", CanvasContainer);
|
|
2525
|
-
var Container4 = (props) => {
|
|
2526
|
-
return createComponent("Container", props);
|
|
2527
|
-
};
|
|
2528
|
-
|
|
2529
|
-
// src/components/Graphic.ts
|
|
2530
|
-
import { effect as effect4, isSignal as isSignal4, signal as signal6 } from "@signe/reactive";
|
|
2531
|
-
import { Assets, Graphics as PixiGraphics } from "pixi.js";
|
|
2532
|
-
var CanvasGraphics = class extends DisplayObject(PixiGraphics) {
|
|
2533
|
-
/**
|
|
2534
|
-
* Initializes the graphics component with reactive width and height handling.
|
|
2535
|
-
*
|
|
2536
|
-
* This method handles different types of width and height props:
|
|
2537
|
-
* - **Numbers**: Direct pixel values
|
|
2538
|
-
* - **Strings with %**: Percentage values that trigger flex layout and use layout box dimensions
|
|
2539
|
-
* - **Signals**: Reactive values that update automatically
|
|
2540
|
-
*
|
|
2541
|
-
* When percentage values are detected, the component:
|
|
2542
|
-
* 1. Sets `display: 'flex'` to enable layout calculations
|
|
2543
|
-
* 2. Listens to layout events to get computed dimensions
|
|
2544
|
-
* 3. Updates internal width/height signals with layout box values
|
|
2545
|
-
*
|
|
2546
|
-
* The draw function receives the reactive width and height signals as parameters.
|
|
2547
|
-
*
|
|
2548
|
-
* @param props - Component properties including width, height, and draw function
|
|
2549
|
-
* @example
|
|
2550
|
-
* ```typescript
|
|
2551
|
-
* // With pixel values
|
|
2552
|
-
* Graphics({ width: 100, height: 50, draw: (g, w, h) => g.rect(0, 0, w(), h()) });
|
|
2553
|
-
*
|
|
2554
|
-
* // With percentage values (uses layout box)
|
|
2555
|
-
* Graphics({ width: "50%", height: "100%", draw: (g, w, h) => g.rect(0, 0, w(), h()) });
|
|
2556
|
-
*
|
|
2557
|
-
* // With signals
|
|
2558
|
-
* const width = signal(100);
|
|
2559
|
-
* Graphics({ width, height: 50, draw: (g, w, h) => g.rect(0, 0, w(), h()) });
|
|
2560
|
-
* ```
|
|
2561
|
-
*/
|
|
2562
|
-
async onInit(props) {
|
|
2563
|
-
await super.onInit(props);
|
|
2564
|
-
}
|
|
2565
|
-
/**
|
|
2566
|
-
* Called when the component is mounted to the scene graph.
|
|
2567
|
-
* Creates the reactive effect for drawing using the original signals from propObservables.
|
|
2568
|
-
* @param {Element<DisplayObject>} element - The element being mounted with props and propObservables.
|
|
2569
|
-
* @param {number} [index] - The index of the component among its siblings.
|
|
2570
|
-
*/
|
|
2571
|
-
async onMount(element, index) {
|
|
2572
|
-
await super.onMount(element, index);
|
|
2573
|
-
const { props, propObservables } = element;
|
|
2574
|
-
const width = isSignal4(propObservables?.width) ? propObservables.width : signal6(props.width || 0);
|
|
2575
|
-
const height = isSignal4(propObservables?.height) ? propObservables.height : signal6(props.height || 0);
|
|
2576
|
-
this.width = width;
|
|
2577
|
-
this.height = height;
|
|
2578
|
-
const isWidthPercentage = isPercent(width());
|
|
2579
|
-
const isHeightPercentage = isPercent(height());
|
|
2580
|
-
if (props.draw) {
|
|
2581
|
-
this.clearEffect = effect4(() => {
|
|
2582
|
-
const w = width();
|
|
2583
|
-
const h2 = height();
|
|
2584
|
-
if (typeof w == "string" || typeof h2 == "string") {
|
|
2585
|
-
return;
|
|
2586
|
-
}
|
|
2587
|
-
if (w == 0 || h2 == 0) {
|
|
2588
|
-
return;
|
|
2589
|
-
}
|
|
2590
|
-
this.clear();
|
|
2591
|
-
props.draw?.(this, w, h2);
|
|
2592
|
-
this.subjectInit.next(this);
|
|
2593
|
-
});
|
|
2594
|
-
}
|
|
2595
|
-
this.on("layout", (event) => {
|
|
2596
|
-
const layoutBox = event.computedLayout;
|
|
2597
|
-
if (isWidthPercentage && isSignal4(width)) {
|
|
2598
|
-
width.set(layoutBox.width);
|
|
2599
|
-
}
|
|
2600
|
-
if (isHeightPercentage && isSignal4(height)) {
|
|
2601
|
-
height.set(layoutBox.height);
|
|
2602
|
-
}
|
|
2603
|
-
});
|
|
2604
|
-
}
|
|
2605
|
-
/**
|
|
2606
|
-
* Called when component props are updated.
|
|
2607
|
-
* Updates the internal width and height signals when props change.
|
|
2608
|
-
* @param props - Updated properties
|
|
2609
|
-
*/
|
|
2610
|
-
onUpdate(props) {
|
|
2611
|
-
super.onUpdate(props);
|
|
2612
|
-
if (props.width !== void 0 && this.width) {
|
|
2613
|
-
if (isSignal4(props.width)) {
|
|
2614
|
-
this.width = props.width;
|
|
2615
|
-
} else {
|
|
2616
|
-
this.width.set(props.width);
|
|
2617
|
-
}
|
|
2618
|
-
}
|
|
2619
|
-
if (props.height !== void 0 && this.height) {
|
|
2620
|
-
if (isSignal4(props.height)) {
|
|
2621
|
-
this.height = props.height;
|
|
2622
|
-
} else {
|
|
2623
|
-
this.height.set(props.height);
|
|
2624
|
-
}
|
|
2625
|
-
}
|
|
2626
|
-
}
|
|
2627
|
-
/**
|
|
2628
|
-
* Called when the component is about to be destroyed.
|
|
2629
|
-
* This method should be overridden by subclasses to perform any cleanup.
|
|
2630
|
-
* It ensures that the clearEffect subscription is unsubscribed before calling the original afterDestroy callback.
|
|
2631
|
-
* @param parent The parent element.
|
|
2632
|
-
* @param afterDestroy A callback function to be executed after the component's own destruction logic.
|
|
2633
|
-
* @example
|
|
2634
|
-
* // This method is typically called by the engine internally.
|
|
2635
|
-
* // await component.onDestroy(parentElement, () => console.log('Component destroyed'));
|
|
2636
|
-
*/
|
|
2637
|
-
async onDestroy(parent, afterDestroy) {
|
|
2638
|
-
const _afterDestroyCallback = async () => {
|
|
2639
|
-
this.clearEffect.subscription.unsubscribe();
|
|
2640
|
-
afterDestroy();
|
|
2641
|
-
};
|
|
2642
|
-
await super.onDestroy(parent, _afterDestroyCallback);
|
|
2643
|
-
}
|
|
2644
|
-
};
|
|
2645
|
-
registerComponent("Graphics", CanvasGraphics);
|
|
2646
|
-
function Graphics(props) {
|
|
2647
|
-
return createComponent("Graphics", props);
|
|
2648
|
-
}
|
|
2649
|
-
function Rect(props) {
|
|
2650
|
-
const { color, borderRadius, border } = useProps(props, {
|
|
2651
|
-
borderRadius: null,
|
|
2652
|
-
border: null
|
|
2653
|
-
});
|
|
2654
|
-
return Graphics({
|
|
2655
|
-
draw: (g, width, height) => {
|
|
2656
|
-
if (borderRadius()) {
|
|
2657
|
-
g.roundRect(0, 0, width, height, borderRadius());
|
|
2658
|
-
} else {
|
|
2659
|
-
g.rect(0, 0, width, height);
|
|
2660
|
-
}
|
|
2661
|
-
if (border) {
|
|
2662
|
-
g.stroke(border);
|
|
2663
|
-
}
|
|
2664
|
-
g.fill(color());
|
|
2665
|
-
},
|
|
2666
|
-
...props
|
|
2667
|
-
});
|
|
2668
|
-
}
|
|
2669
|
-
function drawShape(g, shape, props) {
|
|
2670
|
-
const { color, border } = props;
|
|
2671
|
-
if ("radius" in props) {
|
|
2672
|
-
g.circle(0, 0, props.radius());
|
|
2673
|
-
} else {
|
|
2674
|
-
g.ellipse(0, 0, props.width() / 2, props.height() / 2);
|
|
2675
|
-
}
|
|
2676
|
-
if (border()) {
|
|
2677
|
-
g.stroke(border());
|
|
2678
|
-
}
|
|
2679
|
-
g.fill(color());
|
|
2680
|
-
}
|
|
2681
|
-
function Circle(props) {
|
|
2682
|
-
const { radius, color, border } = useProps(props, {
|
|
2683
|
-
border: null
|
|
2684
|
-
});
|
|
2685
|
-
return Graphics({
|
|
2686
|
-
draw: (g) => drawShape(g, "circle", { radius, color, border }),
|
|
2687
|
-
...props
|
|
2688
|
-
});
|
|
2689
|
-
}
|
|
2690
|
-
function Ellipse(props) {
|
|
2691
|
-
const { width, height, color, border } = useProps(props, {
|
|
2692
|
-
border: null
|
|
2693
|
-
});
|
|
2694
|
-
return Graphics({
|
|
2695
|
-
draw: (g, gWidth, gHeight) => drawShape(g, "ellipse", { width: signal6(gWidth), height: signal6(gHeight), color, border }),
|
|
2696
|
-
...props
|
|
2697
|
-
});
|
|
2698
|
-
}
|
|
2699
|
-
function Triangle(props) {
|
|
2700
|
-
const { width, height, color, border } = useProps(props, {
|
|
2701
|
-
border: null,
|
|
2702
|
-
color: "#000"
|
|
2703
|
-
});
|
|
2704
|
-
return Graphics({
|
|
2705
|
-
draw: (g, gWidth, gHeight) => {
|
|
2706
|
-
g.moveTo(0, gHeight);
|
|
2707
|
-
g.lineTo(gWidth / 2, 0);
|
|
2708
|
-
g.lineTo(gWidth, gHeight);
|
|
2709
|
-
g.lineTo(0, gHeight);
|
|
2710
|
-
g.fill(color());
|
|
2711
|
-
if (border) {
|
|
2712
|
-
g.stroke(border);
|
|
2713
|
-
}
|
|
2714
|
-
},
|
|
2715
|
-
...props
|
|
2716
|
-
});
|
|
2717
|
-
}
|
|
2718
|
-
function Svg(props) {
|
|
2719
|
-
return Graphics({
|
|
2720
|
-
draw: async (g) => {
|
|
2721
|
-
if (props.src) {
|
|
2722
|
-
const svgData = await Assets.load({
|
|
2723
|
-
src: props.src,
|
|
2724
|
-
data: {
|
|
2725
|
-
parseAsGraphicsContext: true
|
|
2726
|
-
}
|
|
2727
|
-
});
|
|
2728
|
-
const graphics = new PixiGraphics(svgData);
|
|
2729
|
-
g.context = graphics.context;
|
|
2730
|
-
} else if (props.content) {
|
|
2731
|
-
g.svg(props.content);
|
|
2732
|
-
} else if (props.svg) {
|
|
2733
|
-
g.svg(props.svg);
|
|
2734
|
-
}
|
|
2735
|
-
},
|
|
2736
|
-
...props
|
|
2737
|
-
});
|
|
2738
|
-
}
|
|
2739
|
-
|
|
2740
|
-
// src/components/Mesh.ts
|
|
2741
|
-
import { Mesh as PixiMesh, Geometry, Assets as Assets2 } from "pixi.js";
|
|
2742
|
-
var CanvasMesh = class extends DisplayObject(PixiMesh) {
|
|
2743
|
-
/**
|
|
2744
|
-
* Constructor for the CanvasMesh component.
|
|
2745
|
-
* Initializes the PixiMesh with default geometry and shader to prevent errors.
|
|
2746
|
-
*
|
|
2747
|
-
* @example
|
|
2748
|
-
* ```typescript
|
|
2749
|
-
* // This constructor is called internally by the engine
|
|
2750
|
-
* const mesh = new CanvasMesh();
|
|
2751
|
-
* ```
|
|
2752
|
-
*/
|
|
2753
|
-
constructor() {
|
|
2754
|
-
super({
|
|
2755
|
-
geometry: new Geometry()
|
|
2756
|
-
});
|
|
2757
|
-
}
|
|
2758
|
-
/**
|
|
2759
|
-
* Initializes the mesh component with the provided properties.
|
|
2760
|
-
* This method is called before onUpdate to set up initial state.
|
|
2761
|
-
*
|
|
2762
|
-
* @param props - The initial properties
|
|
2763
|
-
* @example
|
|
2764
|
-
* ```typescript
|
|
2765
|
-
* // This method is called internally when the component is created
|
|
2766
|
-
* mesh.onInit({
|
|
2767
|
-
* geometry: myGeometry,
|
|
2768
|
-
* texture: "texture.png"
|
|
2769
|
-
* });
|
|
2770
|
-
* ```
|
|
2771
|
-
*/
|
|
2772
|
-
onInit(props) {
|
|
2773
|
-
super.onInit(props);
|
|
2774
|
-
if (props.geometry) {
|
|
2775
|
-
try {
|
|
2776
|
-
this.geometry = props.geometry;
|
|
2777
|
-
} catch (error2) {
|
|
2778
|
-
console.warn("Failed to set geometry:", error2);
|
|
2779
|
-
}
|
|
2780
|
-
}
|
|
2781
|
-
if (props.shader) {
|
|
2782
|
-
this.shader = props.shader;
|
|
2783
|
-
}
|
|
2784
|
-
}
|
|
2785
|
-
/**
|
|
2786
|
-
* Updates the mesh component when properties change.
|
|
2787
|
-
* Handles texture loading, shader updates, and other property changes.
|
|
2788
|
-
*
|
|
2789
|
-
* @param props - The updated properties
|
|
2790
|
-
* @example
|
|
2791
|
-
* ```typescript
|
|
2792
|
-
* // This method is called internally when props change
|
|
2793
|
-
* mesh.onUpdate({
|
|
2794
|
-
* tint: 0x00ff00,
|
|
2795
|
-
* texture: "new-texture.png"
|
|
2796
|
-
* });
|
|
2797
|
-
* ```
|
|
2798
|
-
*/
|
|
2799
|
-
async onUpdate(props) {
|
|
2800
|
-
super.onUpdate(props);
|
|
2801
|
-
if (props.geometry) {
|
|
2802
|
-
try {
|
|
2803
|
-
this.geometry = props.geometry;
|
|
2804
|
-
} catch (error2) {
|
|
2805
|
-
console.warn("Failed to update geometry:", error2);
|
|
2806
|
-
}
|
|
2807
|
-
}
|
|
2808
|
-
if (props.shader) {
|
|
2809
|
-
this.shader = props.shader;
|
|
2810
|
-
}
|
|
2811
|
-
if (props.texture) {
|
|
2812
|
-
if (typeof props.texture === "string") {
|
|
2813
|
-
this.texture = await Assets2.load(props.texture);
|
|
2814
|
-
} else {
|
|
2815
|
-
this.texture = props.texture;
|
|
2816
|
-
}
|
|
2817
|
-
} else if (props.image) {
|
|
2818
|
-
this.texture = await Assets2.load(props.image);
|
|
2819
|
-
}
|
|
2820
|
-
if (props.tint !== void 0) {
|
|
2821
|
-
this.tint = props.tint;
|
|
2822
|
-
}
|
|
2823
|
-
if (props.blendMode !== void 0) {
|
|
2824
|
-
this.blendMode = props.blendMode;
|
|
2825
|
-
}
|
|
2826
|
-
if (props.roundPixels !== void 0) {
|
|
2827
|
-
this.roundPixels = props.roundPixels;
|
|
2828
|
-
}
|
|
2829
|
-
}
|
|
2830
|
-
/**
|
|
2831
|
-
* Called when the component is about to be destroyed.
|
|
2832
|
-
* Cleans up the draw effect subscription and calls the parent destroy method.
|
|
2833
|
-
*
|
|
2834
|
-
* @param parent - The parent element
|
|
2835
|
-
* @param afterDestroy - Callback function to execute after destruction
|
|
2836
|
-
* @example
|
|
2837
|
-
* ```typescript
|
|
2838
|
-
* // This method is typically called by the engine internally
|
|
2839
|
-
* await mesh.onDestroy(parentElement, () => console.log('Mesh destroyed'));
|
|
2840
|
-
* ```
|
|
2841
|
-
*/
|
|
2842
|
-
async onDestroy(parent, afterDestroy) {
|
|
2843
|
-
const _afterDestroyCallback = async () => {
|
|
2844
|
-
afterDestroy();
|
|
2845
|
-
};
|
|
2846
|
-
await super.onDestroy(parent, _afterDestroyCallback);
|
|
2847
|
-
}
|
|
2848
|
-
};
|
|
2849
|
-
registerComponent("Mesh", CanvasMesh);
|
|
2850
|
-
var Mesh = (props) => {
|
|
2851
|
-
return createComponent("Mesh", props);
|
|
2852
|
-
};
|
|
2853
|
-
|
|
2854
|
-
// src/engine/signal.ts
|
|
2855
|
-
var currentSubscriptionsTracker = null;
|
|
2856
|
-
var mountTracker = null;
|
|
2857
|
-
function mount(fn) {
|
|
2858
|
-
mountTracker?.(fn);
|
|
2859
|
-
}
|
|
2860
|
-
function tick(fn) {
|
|
2861
|
-
mount((el) => {
|
|
2862
|
-
const { context } = el.props;
|
|
2863
|
-
let subscription;
|
|
2864
|
-
if (context.tick) {
|
|
2865
|
-
subscription = context.tick.observable.subscribe(({ value }) => {
|
|
2866
|
-
fn(value, el);
|
|
2867
|
-
});
|
|
2868
|
-
}
|
|
2869
|
-
return () => {
|
|
2870
|
-
subscription?.unsubscribe();
|
|
2871
|
-
};
|
|
2872
|
-
});
|
|
2873
|
-
}
|
|
2874
|
-
function h(componentFunction, props = {}, ...children) {
|
|
2875
|
-
const allSubscriptions = /* @__PURE__ */ new Set();
|
|
2876
|
-
const allMounts = /* @__PURE__ */ new Set();
|
|
2877
|
-
currentSubscriptionsTracker = (subscription) => {
|
|
2878
|
-
allSubscriptions.add(subscription);
|
|
2879
|
-
};
|
|
2880
|
-
mountTracker = (fn) => {
|
|
2881
|
-
allMounts.add(fn);
|
|
2882
|
-
};
|
|
2883
|
-
if (children[0] instanceof Array) {
|
|
2884
|
-
children = children[0];
|
|
2885
|
-
}
|
|
2886
|
-
let component = componentFunction({ ...props, children });
|
|
2887
|
-
if (!component) {
|
|
2888
|
-
component = {};
|
|
2889
|
-
}
|
|
2890
|
-
component.effectSubscriptions = Array.from(allSubscriptions);
|
|
2891
|
-
component.effectMounts = [
|
|
2892
|
-
...Array.from(allMounts),
|
|
2893
|
-
...component.effectMounts ?? []
|
|
2894
|
-
];
|
|
2895
|
-
if (component instanceof Promise) {
|
|
2896
|
-
component.then((component2) => {
|
|
2897
|
-
if (component2.props.isRoot) {
|
|
2898
|
-
allMounts.forEach((fn) => fn(component2));
|
|
2899
|
-
}
|
|
2900
|
-
});
|
|
2901
|
-
}
|
|
2902
|
-
currentSubscriptionsTracker = null;
|
|
2903
|
-
mountTracker = null;
|
|
2904
|
-
return component;
|
|
2905
|
-
}
|
|
2906
|
-
|
|
2907
|
-
// src/components/Scene.ts
|
|
2908
|
-
function Scene(props) {
|
|
2909
|
-
return h(Container4);
|
|
2910
|
-
}
|
|
2911
|
-
|
|
2912
|
-
// src/components/ParticleEmitter.ts
|
|
2913
|
-
import * as particles from "@barvynkoa/particle-emitter";
|
|
2914
|
-
var CanvasParticlesEmitter = class extends CanvasContainer {
|
|
2915
|
-
constructor() {
|
|
2916
|
-
super(...arguments);
|
|
2917
|
-
this.elapsed = Date.now();
|
|
2918
|
-
}
|
|
2919
|
-
async onMount(params) {
|
|
2920
|
-
await super.onMount(params);
|
|
2921
|
-
const { props } = params;
|
|
2922
|
-
const tick2 = props.context.tick;
|
|
2923
|
-
this.emitter = new particles.Emitter(this, props.config);
|
|
2924
|
-
this.subscriptionTick = tick2.observable.subscribe((value) => {
|
|
2925
|
-
if (!this.emitter) return;
|
|
2926
|
-
const now = Date.now();
|
|
2927
|
-
this.emitter.update((now - this.elapsed) * 1e-3);
|
|
2928
|
-
this.elapsed = now;
|
|
2929
|
-
});
|
|
2930
|
-
}
|
|
2931
|
-
onUpdate(props) {
|
|
2932
|
-
}
|
|
2933
|
-
async onDestroy(parent, afterDestroy) {
|
|
2934
|
-
const _afterDestroy = async () => {
|
|
2935
|
-
this.emitter?.destroy();
|
|
2936
|
-
this.emitter = null;
|
|
2937
|
-
this.subscriptionTick.unsubscribe();
|
|
2938
|
-
afterDestroy();
|
|
2939
|
-
};
|
|
2940
|
-
await super.onDestroy(parent, _afterDestroy);
|
|
2941
|
-
}
|
|
2942
|
-
};
|
|
2943
|
-
registerComponent("ParticlesEmitter", CanvasParticlesEmitter);
|
|
2944
|
-
function ParticlesEmitter(props) {
|
|
2945
|
-
return createComponent("ParticlesEmitter", props);
|
|
2946
|
-
}
|
|
2947
|
-
|
|
2948
|
-
// src/components/Sprite.ts
|
|
2949
|
-
import { Howl as Howl2 } from "howler";
|
|
2950
|
-
import { computed, effect as effect6, isSignal as isSignal5 } from "@signe/reactive";
|
|
2951
|
-
import {
|
|
2952
|
-
Assets as Assets3,
|
|
2953
|
-
Container as Container5,
|
|
2954
|
-
Sprite as PixiSprite,
|
|
2955
|
-
Rectangle as Rectangle2,
|
|
2956
|
-
Texture as Texture3
|
|
2957
|
-
} from "pixi.js";
|
|
2958
|
-
|
|
2959
|
-
// src/engine/animation.ts
|
|
2960
|
-
import { effect as effect5, signal as signal7 } from "@signe/reactive";
|
|
2961
|
-
import { animate as animatePopmotion } from "popmotion";
|
|
2962
|
-
function isAnimatedSignal(signal10) {
|
|
2963
|
-
return signal10.animatedState !== void 0;
|
|
2964
|
-
}
|
|
2965
|
-
function animatedSignal(initialValue, options = {}) {
|
|
2966
|
-
const state = {
|
|
2967
|
-
current: initialValue,
|
|
2968
|
-
start: initialValue,
|
|
2969
|
-
end: initialValue
|
|
2970
|
-
};
|
|
2971
|
-
let animation;
|
|
2972
|
-
const publicSignal = signal7(initialValue);
|
|
2973
|
-
const privateSignal = signal7(state);
|
|
2974
|
-
effect5(() => {
|
|
2975
|
-
const currentState = privateSignal();
|
|
2976
|
-
publicSignal.set(currentState.current);
|
|
2977
|
-
});
|
|
2978
|
-
function animatedSignal2(newValue, animationConfig = {}) {
|
|
2979
|
-
if (newValue === void 0) {
|
|
2980
|
-
return privateSignal();
|
|
2981
|
-
}
|
|
2982
|
-
const prevState = privateSignal();
|
|
2983
|
-
const newState = {
|
|
2984
|
-
current: prevState.current,
|
|
2985
|
-
start: prevState.current,
|
|
2986
|
-
end: newValue
|
|
2987
|
-
};
|
|
2988
|
-
privateSignal.set(newState);
|
|
2989
|
-
if (animation) {
|
|
2990
|
-
animation.stop();
|
|
2991
|
-
}
|
|
2992
|
-
animation = animatePopmotion({
|
|
2993
|
-
// TODO
|
|
2994
|
-
duration: 20,
|
|
2995
|
-
...options,
|
|
2996
|
-
...animationConfig,
|
|
2997
|
-
from: prevState.current,
|
|
2998
|
-
to: newValue,
|
|
2999
|
-
onUpdate: (value) => {
|
|
3000
|
-
privateSignal.update((s) => ({ ...s, current: value }));
|
|
3001
|
-
if (options.onUpdate) {
|
|
3002
|
-
options.onUpdate(value);
|
|
3003
|
-
}
|
|
3004
|
-
}
|
|
3005
|
-
});
|
|
3006
|
-
}
|
|
3007
|
-
const fn = function() {
|
|
3008
|
-
return privateSignal().current;
|
|
3009
|
-
};
|
|
3010
|
-
for (const key in publicSignal) {
|
|
3011
|
-
fn[key] = publicSignal[key];
|
|
3012
|
-
}
|
|
3013
|
-
fn.animatedState = privateSignal;
|
|
3014
|
-
fn.update = (updater) => {
|
|
3015
|
-
animatedSignal2(updater(privateSignal().current));
|
|
3016
|
-
};
|
|
3017
|
-
fn.set = async (newValue, animationConfig = {}) => {
|
|
3018
|
-
return new Promise((resolve) => {
|
|
3019
|
-
animatedSignal2(newValue, {
|
|
3020
|
-
...animationConfig,
|
|
3021
|
-
onComplete: resolve
|
|
3022
|
-
});
|
|
3023
|
-
});
|
|
3024
|
-
};
|
|
3025
|
-
return fn;
|
|
3026
|
-
}
|
|
3027
|
-
async function animatedSequence(sequence) {
|
|
3028
|
-
for (const item of sequence) {
|
|
3029
|
-
if (Array.isArray(item)) {
|
|
3030
|
-
await Promise.all(item.map((fn) => fn()));
|
|
3031
|
-
} else {
|
|
3032
|
-
await item();
|
|
3033
|
-
}
|
|
3034
|
-
}
|
|
3035
|
-
}
|
|
3036
|
-
|
|
3037
|
-
// src/components/Sprite.ts
|
|
3038
|
-
var log2 = console.log;
|
|
3039
|
-
var CanvasSprite = class extends DisplayObject(PixiSprite) {
|
|
3040
|
-
constructor() {
|
|
3041
|
-
super(...arguments);
|
|
3042
|
-
this.currentAnimation = null;
|
|
3043
|
-
this.time = 0;
|
|
3044
|
-
this.frameIndex = 0;
|
|
3045
|
-
this.animations = /* @__PURE__ */ new Map();
|
|
3046
|
-
this.subscriptionSheet = [];
|
|
3047
|
-
this.sheetParams = {};
|
|
3048
|
-
this.sheetCurrentAnimation = "stand" /* Stand */;
|
|
3049
|
-
this.app = null;
|
|
3050
|
-
this.currentAnimationContainer = null;
|
|
3051
|
-
}
|
|
3052
|
-
get renderer() {
|
|
3053
|
-
return this.app?.renderer;
|
|
3054
|
-
}
|
|
3055
|
-
async createTextures(options) {
|
|
3056
|
-
const { width, height, framesHeight, framesWidth, image, offset } = options;
|
|
3057
|
-
if (!image || typeof image !== "string" || image.trim() === "") {
|
|
3058
|
-
console.warn("Invalid image path provided to createTextures:", image);
|
|
3059
|
-
return [];
|
|
3060
|
-
}
|
|
3061
|
-
const texture = await Assets3.load(image);
|
|
3062
|
-
const spriteWidth = options.spriteWidth;
|
|
3063
|
-
const spriteHeight = options.spriteHeight;
|
|
3064
|
-
const frames = [];
|
|
3065
|
-
const offsetX = offset && offset.x || 0;
|
|
3066
|
-
const offsetY = offset && offset.y || 0;
|
|
3067
|
-
for (let i = 0; i < framesHeight; i++) {
|
|
3068
|
-
frames[i] = [];
|
|
3069
|
-
for (let j = 0; j < framesWidth; j++) {
|
|
3070
|
-
const rectX = j * spriteWidth + offsetX;
|
|
3071
|
-
const rectY = i * spriteHeight + offsetY;
|
|
3072
|
-
if (rectY > height) {
|
|
3073
|
-
throw log2(
|
|
3074
|
-
`Warning, there is a problem with the height of the "${this.id}" spritesheet. When cutting into frames, the frame exceeds the height of the image.`
|
|
3075
|
-
);
|
|
3076
|
-
}
|
|
3077
|
-
if (rectX > width) {
|
|
3078
|
-
throw log2(
|
|
3079
|
-
`Warning, there is a problem with the width of the "${this.id}" spritesheet. When cutting into frames, the frame exceeds the width of the image.`
|
|
3080
|
-
);
|
|
3081
|
-
}
|
|
3082
|
-
frames[i].push(
|
|
3083
|
-
new Texture3({
|
|
3084
|
-
source: texture.source,
|
|
3085
|
-
frame: new Rectangle2(rectX, rectY, spriteWidth, spriteHeight)
|
|
3086
|
-
})
|
|
3087
|
-
);
|
|
3088
|
-
}
|
|
3089
|
-
}
|
|
3090
|
-
return frames;
|
|
3091
|
-
}
|
|
3092
|
-
async createAnimations() {
|
|
3093
|
-
const { textures } = this.spritesheet;
|
|
3094
|
-
if (!textures) {
|
|
3095
|
-
return;
|
|
3096
|
-
}
|
|
3097
|
-
for (let animationName in textures) {
|
|
3098
|
-
const props = [
|
|
3099
|
-
"width",
|
|
3100
|
-
"height",
|
|
3101
|
-
"framesHeight",
|
|
3102
|
-
"framesWidth",
|
|
3103
|
-
"rectWidth",
|
|
3104
|
-
"rectHeight",
|
|
3105
|
-
"offset",
|
|
3106
|
-
"image",
|
|
3107
|
-
"sound"
|
|
3108
|
-
];
|
|
3109
|
-
const parentObj = props.reduce(
|
|
3110
|
-
(prev, val) => ({ ...prev, [val]: this.spritesheet[val] }),
|
|
3111
|
-
{}
|
|
3112
|
-
);
|
|
3113
|
-
const optionsTextures = {
|
|
3114
|
-
...parentObj,
|
|
3115
|
-
...textures[animationName]
|
|
3116
|
-
};
|
|
3117
|
-
const {
|
|
3118
|
-
rectWidth,
|
|
3119
|
-
width = 0,
|
|
3120
|
-
framesWidth = 1,
|
|
3121
|
-
rectHeight,
|
|
3122
|
-
height = 0,
|
|
3123
|
-
framesHeight = 1
|
|
3124
|
-
} = optionsTextures;
|
|
3125
|
-
optionsTextures.spriteWidth = rectWidth ? rectWidth : width / framesWidth;
|
|
3126
|
-
optionsTextures.spriteHeight = rectHeight ? rectHeight : height / framesHeight;
|
|
3127
|
-
this.animations.set(animationName, {
|
|
3128
|
-
frames: await this.createTextures(
|
|
3129
|
-
optionsTextures
|
|
3130
|
-
),
|
|
3131
|
-
name: animationName,
|
|
3132
|
-
animations: textures[animationName].animations,
|
|
3133
|
-
params: [],
|
|
3134
|
-
data: optionsTextures,
|
|
3135
|
-
sprites: []
|
|
3136
|
-
});
|
|
3137
|
-
}
|
|
3138
|
-
}
|
|
3139
|
-
async onMount(params) {
|
|
3140
|
-
const { props, propObservables } = params;
|
|
3141
|
-
const tick2 = props.context.tick;
|
|
3142
|
-
const sheet = props.sheet ?? {};
|
|
3143
|
-
this.app = props.context.app();
|
|
3144
|
-
if (sheet?.onFinish) {
|
|
3145
|
-
this.onFinish = sheet.onFinish;
|
|
3146
|
-
}
|
|
3147
|
-
this.subscriptionTick = tick2.observable.subscribe((value) => {
|
|
3148
|
-
this.update(value);
|
|
3149
|
-
});
|
|
3150
|
-
if (props.sheet?.definition) {
|
|
3151
|
-
this.spritesheet = props.sheet.definition;
|
|
3152
|
-
await this.createAnimations();
|
|
3153
|
-
}
|
|
3154
|
-
if (sheet.params) {
|
|
3155
|
-
for (let key in propObservables?.sheet["params"]) {
|
|
3156
|
-
const value = propObservables?.sheet["params"][key];
|
|
3157
|
-
if (isSignal5(value)) {
|
|
3158
|
-
this.subscriptionSheet.push(
|
|
3159
|
-
value.observable.subscribe((value2) => {
|
|
3160
|
-
if (this.animations.size == 0) return;
|
|
3161
|
-
this.play(this.sheetCurrentAnimation, [{ [key]: value2 }]);
|
|
3162
|
-
})
|
|
3163
|
-
);
|
|
3164
|
-
} else {
|
|
3165
|
-
this.play(this.sheetCurrentAnimation, [{ [key]: value }]);
|
|
3166
|
-
}
|
|
3167
|
-
}
|
|
3168
|
-
}
|
|
3169
|
-
const isMoving = computed(() => {
|
|
3170
|
-
const { x, y } = propObservables ?? {};
|
|
3171
|
-
if (!x || !y) return false;
|
|
3172
|
-
const xSignal = x;
|
|
3173
|
-
const ySignal = y;
|
|
3174
|
-
const isMovingX = isAnimatedSignal(xSignal) && xSignal.animatedState().current !== xSignal.animatedState().end;
|
|
3175
|
-
const isMovingY = isAnimatedSignal(ySignal) && ySignal.animatedState().current !== ySignal.animatedState().end;
|
|
3176
|
-
return isMovingX || isMovingY;
|
|
3177
|
-
});
|
|
3178
|
-
effect6(() => {
|
|
3179
|
-
const _isMoving = isMoving();
|
|
3180
|
-
if (!this.isMounted) return;
|
|
3181
|
-
if (_isMoving) {
|
|
3182
|
-
this.sheetCurrentAnimation = "walk" /* Walk */;
|
|
3183
|
-
} else {
|
|
3184
|
-
this.sheetCurrentAnimation = "stand" /* Stand */;
|
|
3185
|
-
}
|
|
3186
|
-
if (this.spritesheet) this.play(this.sheetCurrentAnimation, [this.sheetParams]);
|
|
3187
|
-
});
|
|
3188
|
-
super.onMount(params);
|
|
3189
|
-
}
|
|
3190
|
-
async onUpdate(props) {
|
|
3191
|
-
super.onUpdate(props);
|
|
3192
|
-
const setTexture = async (image) => {
|
|
3193
|
-
if (!image || typeof image !== "string" || image.trim() === "") {
|
|
3194
|
-
console.warn("Invalid image path provided to setTexture:", image);
|
|
3195
|
-
return null;
|
|
3196
|
-
}
|
|
3197
|
-
const onProgress = this.fullProps.loader?.onProgress;
|
|
3198
|
-
const texture = await Assets3.load(image, (progress) => {
|
|
3199
|
-
if (onProgress) onProgress(progress);
|
|
3200
|
-
if (progress == 1) {
|
|
3201
|
-
const onComplete = this.fullProps.loader?.onComplete;
|
|
3202
|
-
if (onComplete) {
|
|
3203
|
-
setTimeout(() => {
|
|
3204
|
-
onComplete(texture);
|
|
3205
|
-
});
|
|
3206
|
-
}
|
|
3207
|
-
}
|
|
3208
|
-
});
|
|
3209
|
-
return texture;
|
|
3210
|
-
};
|
|
3211
|
-
const sheet = props.sheet;
|
|
3212
|
-
if (sheet?.params) this.sheetParams = sheet?.params;
|
|
3213
|
-
if (sheet?.playing && this.isMounted) {
|
|
3214
|
-
this.sheetCurrentAnimation = sheet?.playing;
|
|
3215
|
-
this.play(this.sheetCurrentAnimation, [this.sheetParams]);
|
|
3216
|
-
}
|
|
3217
|
-
if (props.hitbox) this.hitbox = props.hitbox;
|
|
3218
|
-
if (props.scaleMode) this.baseTexture.scaleMode = props.scaleMode;
|
|
3219
|
-
else if (props.image && this.fullProps.rectangle === void 0) {
|
|
3220
|
-
const texture = await setTexture(this.fullProps.image);
|
|
3221
|
-
if (texture) {
|
|
3222
|
-
this.texture = texture;
|
|
3223
|
-
}
|
|
3224
|
-
} else if (props.texture) {
|
|
3225
|
-
if (isElement(props.texture)) {
|
|
3226
|
-
const textureInstance = props.texture.componentInstance;
|
|
3227
|
-
textureInstance.subjectInit.subscribe((value) => {
|
|
3228
|
-
console.log("a", value?.width);
|
|
3229
|
-
});
|
|
3230
|
-
this.texture = this.renderer?.generateTexture(props.texture.componentInstance);
|
|
3231
|
-
} else {
|
|
3232
|
-
this.texture = props.texture;
|
|
3233
|
-
}
|
|
3234
|
-
}
|
|
3235
|
-
if (props.rectangle !== void 0) {
|
|
3236
|
-
const { x, y, width, height } = props.rectangle?.value ?? props.rectangle;
|
|
3237
|
-
const texture = await setTexture(this.fullProps.image);
|
|
3238
|
-
if (texture) {
|
|
3239
|
-
this.texture = new Texture3({
|
|
3240
|
-
source: texture.source,
|
|
3241
|
-
frame: new Rectangle2(x, y, width, height)
|
|
3242
|
-
});
|
|
3243
|
-
}
|
|
3244
|
-
}
|
|
3245
|
-
}
|
|
3246
|
-
async onDestroy(parent, afterDestroy) {
|
|
3247
|
-
await super.onDestroy(parent);
|
|
3248
|
-
this.subscriptionSheet.forEach((sub) => sub.unsubscribe());
|
|
3249
|
-
this.subscriptionTick.unsubscribe();
|
|
3250
|
-
if (this.currentAnimationContainer && this.parent instanceof Container5) {
|
|
3251
|
-
this.parent.removeChild(this.currentAnimationContainer);
|
|
3252
|
-
}
|
|
3253
|
-
}
|
|
3254
|
-
has(name) {
|
|
3255
|
-
return this.animations.has(name);
|
|
3256
|
-
}
|
|
3257
|
-
get(name) {
|
|
3258
|
-
return this.animations.get(name);
|
|
3259
|
-
}
|
|
3260
|
-
isPlaying(name) {
|
|
3261
|
-
if (!name) return !!this.currentAnimation;
|
|
3262
|
-
if (this.currentAnimation == null) return false;
|
|
3263
|
-
return this.currentAnimation.name == name;
|
|
3264
|
-
}
|
|
3265
|
-
stop() {
|
|
3266
|
-
this.currentAnimation = null;
|
|
3267
|
-
this.destroy();
|
|
3268
|
-
}
|
|
3269
|
-
play(name, params = []) {
|
|
3270
|
-
const animParams = this.currentAnimation?.params;
|
|
3271
|
-
if (this.isPlaying(name) && arrayEquals(params, animParams || [])) return;
|
|
3272
|
-
const animation = this.get(name);
|
|
3273
|
-
if (!animation) {
|
|
3274
|
-
throw new Error(
|
|
3275
|
-
`Impossible to play the ${name} animation because it doesn't exist on the "${this.id}" spritesheet`
|
|
3276
|
-
);
|
|
3277
|
-
}
|
|
3278
|
-
const cloneParams = structuredClone(params);
|
|
3279
|
-
this.removeChildren();
|
|
3280
|
-
animation.sprites = [];
|
|
3281
|
-
this.currentAnimation = animation;
|
|
3282
|
-
this.currentAnimation.params = cloneParams;
|
|
3283
|
-
this.time = 0;
|
|
3284
|
-
this.frameIndex = 0;
|
|
3285
|
-
let animations = animation.animations;
|
|
3286
|
-
animations = isFunction(animations) ? animations(...cloneParams) : animations;
|
|
3287
|
-
this.currentAnimationContainer = new Container5();
|
|
3288
|
-
for (let container of animations) {
|
|
3289
|
-
const sprite = new PixiSprite();
|
|
3290
|
-
for (let frame of container) {
|
|
3291
|
-
this.currentAnimation.sprites.push(frame);
|
|
3292
|
-
}
|
|
3293
|
-
this.currentAnimationContainer.addChild(sprite);
|
|
3294
|
-
}
|
|
3295
|
-
const sound = this.currentAnimation.data.sound;
|
|
3296
|
-
if (sound) {
|
|
3297
|
-
new Howl2({
|
|
3298
|
-
src: sound,
|
|
3299
|
-
autoplay: true,
|
|
3300
|
-
loop: false,
|
|
3301
|
-
volume: 1
|
|
3302
|
-
});
|
|
3303
|
-
}
|
|
3304
|
-
this.update({
|
|
3305
|
-
deltaRatio: 1
|
|
3306
|
-
});
|
|
3307
|
-
}
|
|
3308
|
-
update({ deltaRatio }) {
|
|
3309
|
-
if (!this.isPlaying() || !this.currentAnimation || !this.currentAnimationContainer)
|
|
3310
|
-
return;
|
|
3311
|
-
const self = this;
|
|
3312
|
-
const { frames, sprites, data } = this.currentAnimation;
|
|
3313
|
-
let frame = sprites[this.frameIndex];
|
|
3314
|
-
const nextFrame = sprites[this.frameIndex + 1];
|
|
3315
|
-
for (let _sprite of this.currentAnimationContainer.children) {
|
|
3316
|
-
let applyTransformValue = function(prop, alias) {
|
|
3317
|
-
const optionProp = alias || prop;
|
|
3318
|
-
const val = getVal(optionProp);
|
|
3319
|
-
if (val !== void 0) {
|
|
3320
|
-
self[prop] = val;
|
|
3321
|
-
}
|
|
3322
|
-
};
|
|
3323
|
-
const sprite = _sprite;
|
|
3324
|
-
if (!frame || frame.frameY == void 0 || frame.frameX == void 0) {
|
|
3325
|
-
continue;
|
|
3326
|
-
}
|
|
3327
|
-
this.texture = frames[frame.frameY][frame.frameX];
|
|
3328
|
-
const getVal = (prop) => {
|
|
3329
|
-
return frame[prop] ?? data[prop] ?? this.spritesheet[prop];
|
|
3330
|
-
};
|
|
3331
|
-
const applyTransform = (prop) => {
|
|
3332
|
-
const val = getVal(prop);
|
|
3333
|
-
if (val) {
|
|
3334
|
-
this[prop].set(...val);
|
|
3335
|
-
}
|
|
3336
|
-
};
|
|
3337
|
-
if (this.applyTransform) {
|
|
3338
|
-
frame = {
|
|
3339
|
-
...frame,
|
|
3340
|
-
...this.applyTransform(frame, data, this.spritesheet)
|
|
3341
|
-
};
|
|
3342
|
-
}
|
|
3343
|
-
const realSize = getVal("spriteRealSize");
|
|
3344
|
-
const heightOfSprite = typeof realSize == "number" ? realSize : realSize?.height;
|
|
3345
|
-
const widthOfSprite = typeof realSize == "number" ? realSize : realSize?.width;
|
|
3346
|
-
const applyAnchorBySize = () => {
|
|
3347
|
-
if (heightOfSprite && this.hitbox) {
|
|
3348
|
-
const { spriteWidth, spriteHeight } = data;
|
|
3349
|
-
const w = (spriteWidth - this.hitbox.w) / 2 / spriteWidth;
|
|
3350
|
-
const gap = (spriteHeight - heightOfSprite) / 2;
|
|
3351
|
-
const h2 = (spriteHeight - this.hitbox.h - gap) / spriteHeight;
|
|
3352
|
-
this.anchor.set(w, h2);
|
|
3353
|
-
}
|
|
3354
|
-
};
|
|
3355
|
-
if (frame.sound) {
|
|
3356
|
-
}
|
|
3357
|
-
applyAnchorBySize();
|
|
3358
|
-
applyTransform("anchor");
|
|
3359
|
-
applyTransform("scale");
|
|
3360
|
-
applyTransform("skew");
|
|
3361
|
-
applyTransform("pivot");
|
|
3362
|
-
applyTransformValue("alpha", "opacity");
|
|
3363
|
-
applyTransformValue("x");
|
|
3364
|
-
applyTransformValue("y");
|
|
3365
|
-
applyTransformValue("angle");
|
|
3366
|
-
applyTransformValue("rotation");
|
|
3367
|
-
applyTransformValue("visible");
|
|
3368
|
-
}
|
|
3369
|
-
if (!nextFrame) {
|
|
3370
|
-
this.time = 0;
|
|
3371
|
-
this.frameIndex = 0;
|
|
3372
|
-
if (this.onFinish && sprites.length > 1) this.onFinish();
|
|
3373
|
-
return;
|
|
3374
|
-
}
|
|
3375
|
-
this.time += deltaRatio ?? 1;
|
|
3376
|
-
if (this.time >= nextFrame.time) {
|
|
3377
|
-
this.frameIndex++;
|
|
3378
|
-
}
|
|
3379
|
-
}
|
|
3380
|
-
};
|
|
3381
|
-
registerComponent("Sprite", CanvasSprite);
|
|
3382
|
-
var Sprite2 = (props) => {
|
|
3383
|
-
return createComponent("Sprite", props);
|
|
3384
|
-
};
|
|
3385
|
-
|
|
3386
|
-
// src/components/Video.ts
|
|
3387
|
-
import { effect as effect7, signal as signal8 } from "@signe/reactive";
|
|
3388
|
-
function Video(props) {
|
|
3389
|
-
const eventsMap = {
|
|
3390
|
-
audioprocess: null,
|
|
3391
|
-
canplay: null,
|
|
3392
|
-
canplaythrough: null,
|
|
3393
|
-
complete: null,
|
|
3394
|
-
durationchange: null,
|
|
3395
|
-
emptied: null,
|
|
3396
|
-
ended: null,
|
|
3397
|
-
loadeddata: null,
|
|
3398
|
-
loadedmetadata: null,
|
|
3399
|
-
pause: null,
|
|
3400
|
-
play: null,
|
|
3401
|
-
playing: null,
|
|
3402
|
-
progress: null,
|
|
3403
|
-
ratechange: null,
|
|
3404
|
-
seeked: null,
|
|
3405
|
-
seeking: null,
|
|
3406
|
-
stalled: null,
|
|
3407
|
-
suspend: null,
|
|
3408
|
-
timeupdate: null,
|
|
3409
|
-
volumechange: null,
|
|
3410
|
-
waiting: null
|
|
3411
|
-
};
|
|
3412
|
-
const video = signal8(null);
|
|
3413
|
-
const defineProps = useDefineProps(props);
|
|
3414
|
-
const { play, loop: loop2, muted } = defineProps({
|
|
3415
|
-
play: {
|
|
3416
|
-
type: Boolean,
|
|
3417
|
-
default: true
|
|
3418
|
-
},
|
|
3419
|
-
loop: {
|
|
3420
|
-
type: Boolean,
|
|
3421
|
-
default: false
|
|
3422
|
-
},
|
|
3423
|
-
muted: {
|
|
3424
|
-
type: Boolean,
|
|
3425
|
-
default: false
|
|
3426
|
-
}
|
|
3427
|
-
});
|
|
3428
|
-
effect7(() => {
|
|
3429
|
-
const _video = video();
|
|
3430
|
-
const state = play();
|
|
3431
|
-
if (_video && state !== void 0) {
|
|
3432
|
-
if (state) {
|
|
3433
|
-
_video.play();
|
|
3434
|
-
} else {
|
|
3435
|
-
_video.pause();
|
|
3436
|
-
}
|
|
3437
|
-
}
|
|
3438
|
-
if (_video && loop2()) {
|
|
3439
|
-
_video.loop = loop2();
|
|
3440
|
-
}
|
|
3441
|
-
if (_video && muted()) {
|
|
3442
|
-
_video.muted = muted();
|
|
3443
|
-
}
|
|
3444
|
-
});
|
|
3445
|
-
mount(() => {
|
|
3446
|
-
return () => {
|
|
3447
|
-
for (let event in eventsMap) {
|
|
3448
|
-
if (eventsMap[event]) {
|
|
3449
|
-
video().removeEventListener(event, eventsMap[event]);
|
|
3450
|
-
}
|
|
3451
|
-
}
|
|
3452
|
-
};
|
|
3453
|
-
});
|
|
3454
|
-
return h(Sprite2, {
|
|
3455
|
-
...props,
|
|
3456
|
-
image: props.src,
|
|
3457
|
-
loader: {
|
|
3458
|
-
onComplete: (texture) => {
|
|
3459
|
-
const source = texture.source.resource;
|
|
3460
|
-
video.set(source);
|
|
3461
|
-
if (props?.loader?.onComplete) {
|
|
3462
|
-
props.loader.onComplete(texture);
|
|
3463
|
-
}
|
|
3464
|
-
for (let event in eventsMap) {
|
|
3465
|
-
if (props[event]) {
|
|
3466
|
-
const cb = (ev) => {
|
|
3467
|
-
props[event](ev);
|
|
3468
|
-
};
|
|
3469
|
-
eventsMap[event] = cb;
|
|
3470
|
-
source.addEventListener(event, cb);
|
|
3471
|
-
}
|
|
3472
|
-
}
|
|
3473
|
-
}
|
|
3474
|
-
}
|
|
3475
|
-
});
|
|
3476
|
-
}
|
|
3477
|
-
|
|
3478
|
-
// src/components/Text.ts
|
|
3479
|
-
import { Text as PixiText } from "pixi.js";
|
|
3480
|
-
|
|
3481
|
-
// src/engine/trigger.ts
|
|
3482
|
-
import { effect as effect8, signal as signal9 } from "@signe/reactive";
|
|
3483
|
-
function isTrigger(arg) {
|
|
3484
|
-
return arg?.start && arg?.listen;
|
|
3485
|
-
}
|
|
3486
|
-
function trigger(globalConfig) {
|
|
3487
|
-
const _signal = signal9({
|
|
3488
|
-
config: globalConfig,
|
|
3489
|
-
value: 0,
|
|
3490
|
-
resolve: (value) => void 0
|
|
3491
|
-
});
|
|
3492
|
-
return {
|
|
3493
|
-
start: (config) => {
|
|
3494
|
-
return new Promise((resolve) => {
|
|
3495
|
-
_signal.set({
|
|
3496
|
-
config: {
|
|
3497
|
-
...globalConfig,
|
|
3498
|
-
...config
|
|
3499
|
-
},
|
|
3500
|
-
resolve,
|
|
3501
|
-
value: Math.random()
|
|
3502
|
-
});
|
|
3503
|
-
});
|
|
3504
|
-
},
|
|
3505
|
-
listen: () => {
|
|
3506
|
-
return {
|
|
3507
|
-
config: globalConfig,
|
|
3508
|
-
seed: _signal()
|
|
3509
|
-
};
|
|
3510
|
-
}
|
|
3511
|
-
};
|
|
3512
|
-
}
|
|
3513
|
-
function on(triggerSignal, callback) {
|
|
3514
|
-
if (!isTrigger(triggerSignal)) {
|
|
3515
|
-
throw new Error("In 'on(arg)' must have a trigger signal type");
|
|
3516
|
-
}
|
|
3517
|
-
effect8(() => {
|
|
3518
|
-
const result = triggerSignal.listen();
|
|
3519
|
-
if (result?.seed.value) {
|
|
3520
|
-
const ret = callback(result?.seed.config);
|
|
3521
|
-
if (ret && typeof ret.then === "function") {
|
|
3522
|
-
ret.then(result?.seed.resolve);
|
|
3523
|
-
}
|
|
3524
|
-
}
|
|
3525
|
-
});
|
|
3526
|
-
}
|
|
3527
|
-
|
|
3528
|
-
// src/components/Text.ts
|
|
3529
|
-
var CanvasText = class extends DisplayObject(PixiText) {
|
|
3530
|
-
constructor() {
|
|
3531
|
-
super(...arguments);
|
|
3532
|
-
this.fullText = "";
|
|
3533
|
-
this.currentIndex = 0;
|
|
3534
|
-
this.typewriterSpeed = 1;
|
|
3535
|
-
// Default speed
|
|
3536
|
-
this._wordWrapWidth = 0;
|
|
3537
|
-
this.typewriterOptions = {};
|
|
3538
|
-
}
|
|
3539
|
-
/**
|
|
3540
|
-
* Called when the component is mounted to the scene graph.
|
|
3541
|
-
* Initializes the typewriter effect if configured.
|
|
3542
|
-
* @param {Element<CanvasText>} element - The element being mounted with parent and props.
|
|
3543
|
-
* @param {number} [index] - The index of the component among its siblings.
|
|
3544
|
-
*/
|
|
3545
|
-
async onMount(element, index) {
|
|
3546
|
-
const { props } = element;
|
|
3547
|
-
await super.onMount(element, index);
|
|
3548
|
-
const tick2 = props.context.tick;
|
|
3549
|
-
if (props.text && props.typewriter) {
|
|
3550
|
-
this.fullText = props.text;
|
|
3551
|
-
this.text = "";
|
|
3552
|
-
this.currentIndex = 0;
|
|
3553
|
-
if (props.typewriter) {
|
|
3554
|
-
this.typewriterOptions = props.typewriter;
|
|
3555
|
-
if (this.typewriterOptions.skip && isTrigger(this.typewriterOptions.skip)) {
|
|
3556
|
-
on(this.typewriterOptions.skip, () => {
|
|
3557
|
-
this.skipTypewriter();
|
|
3558
|
-
});
|
|
3559
|
-
}
|
|
3560
|
-
}
|
|
3561
|
-
}
|
|
3562
|
-
this.subscriptionTick = tick2.observable.subscribe(() => {
|
|
3563
|
-
if (props.typewriter) {
|
|
3564
|
-
this.typewriterEffect();
|
|
3565
|
-
}
|
|
3566
|
-
});
|
|
3567
|
-
}
|
|
3568
|
-
onUpdate(props) {
|
|
3569
|
-
super.onUpdate(props);
|
|
3570
|
-
if (props.typewriter) {
|
|
3571
|
-
if (props.typewriter) {
|
|
3572
|
-
this.typewriterOptions = props.typewriter;
|
|
3573
|
-
}
|
|
3574
|
-
}
|
|
3575
|
-
if (props.text !== void 0) {
|
|
3576
|
-
this.text = "" + props.text;
|
|
3577
|
-
}
|
|
3578
|
-
if (props.text !== void 0 && props.text !== this.fullText && this.fullProps.typewriter) {
|
|
3579
|
-
this.text = "";
|
|
3580
|
-
this.currentIndex = 0;
|
|
3581
|
-
this.fullText = props.text;
|
|
3582
|
-
}
|
|
3583
|
-
if (props.style) {
|
|
3584
|
-
for (const key in props.style) {
|
|
3585
|
-
this.style[key] = props.style[key];
|
|
3586
|
-
}
|
|
3587
|
-
if (props.style.wordWrapWidth) {
|
|
3588
|
-
this._wordWrapWidth = props.style.wordWrapWidth;
|
|
3589
|
-
}
|
|
3590
|
-
}
|
|
3591
|
-
if (props.color) {
|
|
3592
|
-
this.style.fill = props.color;
|
|
3593
|
-
}
|
|
3594
|
-
if (props.size) {
|
|
3595
|
-
this.style.fontSize = props.size;
|
|
3596
|
-
}
|
|
3597
|
-
if (props.fontFamily) {
|
|
3598
|
-
this.style.fontFamily = props.fontFamily;
|
|
3599
|
-
}
|
|
3600
|
-
if (this._wordWrapWidth) {
|
|
3601
|
-
this.setWidth(this._wordWrapWidth);
|
|
3602
|
-
} else {
|
|
3603
|
-
this.setWidth(this.width);
|
|
3604
|
-
}
|
|
3605
|
-
this.setHeight(this.height);
|
|
3606
|
-
}
|
|
3607
|
-
get onCompleteCallback() {
|
|
3608
|
-
return this.typewriterOptions.onComplete;
|
|
3609
|
-
}
|
|
3610
|
-
typewriterEffect() {
|
|
3611
|
-
if (this.currentIndex < this.fullText.length) {
|
|
3612
|
-
const nextIndex = Math.min(
|
|
3613
|
-
this.currentIndex + (this.typewriterOptions.speed ?? 1),
|
|
3614
|
-
this.fullText.length
|
|
3615
|
-
);
|
|
3616
|
-
this.text = this.fullText.slice(0, nextIndex);
|
|
3617
|
-
this.currentIndex = nextIndex;
|
|
3618
|
-
if (this.currentIndex === this.fullText.length && this.onCompleteCallback) {
|
|
3619
|
-
this.onCompleteCallback();
|
|
3620
|
-
}
|
|
3621
|
-
}
|
|
3622
|
-
}
|
|
3623
|
-
// Add a method to skip the typewriter effect
|
|
3624
|
-
skipTypewriter() {
|
|
3625
|
-
if (this.skipSignal) {
|
|
3626
|
-
this.skipSignal();
|
|
3627
|
-
}
|
|
3628
|
-
this.text = this.fullText;
|
|
3629
|
-
this.currentIndex = this.fullText.length;
|
|
3630
|
-
}
|
|
3631
|
-
/**
|
|
3632
|
-
* Called when the component is about to be destroyed.
|
|
3633
|
-
* Unsubscribes from the tick observable.
|
|
3634
|
-
* @param {Element<any>} parent - The parent element.
|
|
3635
|
-
* @param {() => void} [afterDestroy] - An optional callback function to be executed after the component's own destruction logic.
|
|
3636
|
-
*/
|
|
3637
|
-
async onDestroy(parent, afterDestroy) {
|
|
3638
|
-
const _afterDestroy = async () => {
|
|
3639
|
-
if (this.subscriptionTick) {
|
|
3640
|
-
this.subscriptionTick.unsubscribe();
|
|
3641
|
-
}
|
|
3642
|
-
if (afterDestroy) {
|
|
3643
|
-
afterDestroy();
|
|
3644
|
-
}
|
|
3645
|
-
};
|
|
3646
|
-
await super.onDestroy(parent, _afterDestroy);
|
|
3647
|
-
}
|
|
3648
|
-
};
|
|
3649
|
-
registerComponent("Text", CanvasText);
|
|
3650
|
-
function Text(props) {
|
|
3651
|
-
return createComponent("Text", props);
|
|
3652
|
-
}
|
|
3653
|
-
|
|
3654
|
-
// src/components/TilingSprite.ts
|
|
3655
|
-
import { TilingSprite as PixiTilingSprite, Texture as Texture4 } from "pixi.js";
|
|
3656
|
-
var CanvasTilingSprite = class extends DisplayObject(PixiTilingSprite) {
|
|
3657
|
-
onUpdate(props) {
|
|
3658
|
-
super.onUpdate(props);
|
|
3659
|
-
if (props.image) {
|
|
3660
|
-
this.texture = Texture4.from(props.image);
|
|
3661
|
-
}
|
|
3662
|
-
if (props.tileScale) {
|
|
3663
|
-
this.tileScale.set(props.tileScale.x, props.tileScale.y);
|
|
3664
|
-
}
|
|
3665
|
-
if (props.tilePosition) {
|
|
3666
|
-
this.tilePosition.set(props.tilePosition.x, props.tilePosition.y);
|
|
3667
|
-
}
|
|
3668
|
-
if (props.width !== void 0) {
|
|
3669
|
-
this.width = props.width;
|
|
3670
|
-
}
|
|
3671
|
-
if (props.height !== void 0) {
|
|
3672
|
-
this.height = props.height;
|
|
3673
|
-
}
|
|
3674
|
-
}
|
|
3675
|
-
};
|
|
3676
|
-
registerComponent("TilingSprite", CanvasTilingSprite);
|
|
3677
|
-
function TilingSprite(props) {
|
|
3678
|
-
return createComponent("TilingSprite", props);
|
|
3679
|
-
}
|
|
3680
|
-
|
|
3681
|
-
// src/components/Viewport.ts
|
|
3682
|
-
import { Viewport as PixiViewport } from "pixi-viewport";
|
|
3683
|
-
import { effect as effect9 } from "@signe/reactive";
|
|
3684
|
-
var EVENTS3 = [
|
|
3685
|
-
"bounce-x-end",
|
|
3686
|
-
"bounce-x-start",
|
|
3687
|
-
"bounce-y-end",
|
|
3688
|
-
"bounce-y-start",
|
|
3689
|
-
"clicked",
|
|
3690
|
-
"drag-end",
|
|
3691
|
-
"drag-start",
|
|
3692
|
-
"frame-end",
|
|
3693
|
-
"mouse-edge-end",
|
|
3694
|
-
"mouse-edge-start",
|
|
3695
|
-
"moved",
|
|
3696
|
-
"moved-end",
|
|
3697
|
-
"pinch-end",
|
|
3698
|
-
"pinch-start",
|
|
3699
|
-
"snap-end",
|
|
3700
|
-
"snap-start",
|
|
3701
|
-
"snap-zoom-end",
|
|
3702
|
-
"snap-zoom-start",
|
|
3703
|
-
"wheel-scroll",
|
|
3704
|
-
"zoomed",
|
|
3705
|
-
"zoomed-end"
|
|
3706
|
-
];
|
|
3707
|
-
var CanvasViewport = class extends DisplayObject(PixiViewport) {
|
|
3708
|
-
constructor() {
|
|
3709
|
-
const defaultOptions = {
|
|
3710
|
-
noTicker: true,
|
|
3711
|
-
events: {
|
|
3712
|
-
domElement: {
|
|
3713
|
-
addEventListener: () => {
|
|
3714
|
-
}
|
|
3715
|
-
}
|
|
3716
|
-
}
|
|
3717
|
-
};
|
|
3718
|
-
super(defaultOptions);
|
|
3719
|
-
this.overrideProps = ["wheel"];
|
|
3720
|
-
}
|
|
3721
|
-
onInit(props) {
|
|
3722
|
-
super.onInit(props);
|
|
3723
|
-
for (let event of EVENTS3) {
|
|
3724
|
-
if (props[event]) this.on(event, props[event]);
|
|
3725
|
-
}
|
|
3726
|
-
}
|
|
3727
|
-
/**
|
|
3728
|
-
* Called when the component is mounted to the scene graph.
|
|
3729
|
-
* Initializes viewport settings and subscriptions.
|
|
3730
|
-
* @param {Element<CanvasViewport>} element - The element being mounted. Its `props` property (of type ViewportProps) contains component properties and context.
|
|
3731
|
-
* @param {number} [index] - The index of the component among its siblings.
|
|
3732
|
-
*/
|
|
3733
|
-
async onMount(element, index) {
|
|
3734
|
-
await super.onMount(element, index);
|
|
3735
|
-
const { props } = element;
|
|
3736
|
-
const { tick: tick2, app, canvasSize } = props.context;
|
|
3737
|
-
let isDragging = false;
|
|
3738
|
-
effect9(() => {
|
|
3739
|
-
this.screenWidth = canvasSize().width;
|
|
3740
|
-
this.screenHeight = canvasSize().height;
|
|
3741
|
-
});
|
|
3742
|
-
effect9(() => {
|
|
3743
|
-
const _app = app();
|
|
3744
|
-
if (!_app) return;
|
|
3745
|
-
const renderer = _app.renderer;
|
|
3746
|
-
renderer.events.domElement.addEventListener(
|
|
3747
|
-
"wheel",
|
|
3748
|
-
this.input.wheelFunction
|
|
3749
|
-
);
|
|
3750
|
-
this.options.events = renderer.events;
|
|
3751
|
-
});
|
|
3752
|
-
this.tickSubscription = tick2.observable.subscribe(({ value }) => {
|
|
3753
|
-
this.update(value.timestamp);
|
|
3754
|
-
});
|
|
3755
|
-
element.props.context.viewport = this;
|
|
3756
|
-
this.updateViewportSettings(props);
|
|
3757
|
-
}
|
|
3758
|
-
onUpdate(props) {
|
|
3759
|
-
super.onUpdate(props);
|
|
3760
|
-
this.updateViewportSettings(props);
|
|
3761
|
-
}
|
|
3762
|
-
updateViewportSettings(props) {
|
|
3763
|
-
if (props.screenWidth !== void 0) {
|
|
3764
|
-
this.screenWidth = props.screenWidth;
|
|
3765
|
-
}
|
|
3766
|
-
if (props.screenHeight !== void 0) {
|
|
3767
|
-
this.screenHeight = props.screenHeight;
|
|
3768
|
-
}
|
|
3769
|
-
if (props.worldWidth !== void 0) {
|
|
3770
|
-
this.worldWidth = props.worldWidth;
|
|
3771
|
-
}
|
|
3772
|
-
if (props.worldHeight !== void 0) {
|
|
3773
|
-
this.worldHeight = props.worldHeight;
|
|
3774
|
-
}
|
|
3775
|
-
if (props.drag) {
|
|
3776
|
-
this.drag(props.drag);
|
|
3777
|
-
}
|
|
3778
|
-
if (props.clamp) {
|
|
3779
|
-
this.clamp(props.clamp.value ?? props.clamp);
|
|
3780
|
-
}
|
|
3781
|
-
if (props.wheel) {
|
|
3782
|
-
if (props.wheel === true) {
|
|
3783
|
-
this.wheel();
|
|
3784
|
-
} else {
|
|
3785
|
-
this.wheel(props.wheel);
|
|
3786
|
-
}
|
|
3787
|
-
}
|
|
3788
|
-
if (props.decelerate) {
|
|
3789
|
-
if (props.decelerate === true) {
|
|
3790
|
-
this.decelerate();
|
|
3791
|
-
} else {
|
|
3792
|
-
this.decelerate(props.decelerate);
|
|
3793
|
-
}
|
|
3794
|
-
}
|
|
3795
|
-
if (props.pinch) {
|
|
3796
|
-
if (props.pinch === true) {
|
|
3797
|
-
this.pinch();
|
|
3798
|
-
} else {
|
|
3799
|
-
this.pinch(props.pinch);
|
|
3800
|
-
}
|
|
3801
|
-
}
|
|
3802
|
-
}
|
|
3803
|
-
/**
|
|
3804
|
-
* Called when the component is about to be destroyed.
|
|
3805
|
-
* Unsubscribes from the tick observable.
|
|
3806
|
-
* @param {Element<any>} parent - The parent element.
|
|
3807
|
-
* @param {() => void} [afterDestroy] - An optional callback function to be executed after the component's own destruction logic.
|
|
3808
|
-
*/
|
|
3809
|
-
async onDestroy(parent, afterDestroy) {
|
|
3810
|
-
const _afterDestroy = async () => {
|
|
3811
|
-
this.tickSubscription.unsubscribe();
|
|
3812
|
-
afterDestroy();
|
|
3813
|
-
};
|
|
3814
|
-
await super.onDestroy(parent, _afterDestroy);
|
|
3815
|
-
}
|
|
3816
|
-
};
|
|
3817
|
-
registerComponent("Viewport", CanvasViewport);
|
|
3818
|
-
function Viewport(props) {
|
|
3819
|
-
return createComponent("Viewport", props);
|
|
3820
|
-
}
|
|
3821
|
-
|
|
3822
|
-
// src/components/NineSliceSprite.ts
|
|
3823
|
-
import { Assets as Assets4, NineSliceSprite as PixiNineSliceSprite } from "pixi.js";
|
|
3824
|
-
var CanvasNineSliceSprite = class extends DisplayObject(PixiNineSliceSprite) {
|
|
3825
|
-
constructor() {
|
|
3826
|
-
super({
|
|
3827
|
-
width: 0,
|
|
3828
|
-
height: 0
|
|
3829
|
-
});
|
|
3830
|
-
}
|
|
3831
|
-
async onUpdate(props) {
|
|
3832
|
-
for (const [key, value] of Object.entries(props)) {
|
|
3833
|
-
if (value !== void 0) {
|
|
3834
|
-
if (key === "image") {
|
|
3835
|
-
this.texture = await Assets4.load(value);
|
|
3836
|
-
} else if (key in this) {
|
|
3837
|
-
this[key] = value;
|
|
3838
|
-
}
|
|
3839
|
-
}
|
|
3840
|
-
}
|
|
3841
|
-
}
|
|
3842
|
-
};
|
|
3843
|
-
registerComponent("NineSliceSprite", CanvasNineSliceSprite);
|
|
3844
|
-
function NineSliceSprite(props) {
|
|
3845
|
-
return createComponent("NineSliceSprite", props);
|
|
3846
|
-
}
|
|
3847
|
-
|
|
3848
|
-
// src/components/DOMContainer.ts
|
|
3849
|
-
import { DOMContainer as PixiDOMContainer } from "pixi.js";
|
|
3850
|
-
|
|
3851
|
-
// src/components/DOMElement.ts
|
|
3852
|
-
import { isSignal as isSignal6 } from "@signe/reactive";
|
|
3853
|
-
var EVENTS4 = [
|
|
3854
|
-
"click",
|
|
3855
|
-
"mouseover",
|
|
3856
|
-
"mouseout",
|
|
3857
|
-
"mouseenter",
|
|
3858
|
-
"mouseleave",
|
|
3859
|
-
"mousemove",
|
|
3860
|
-
"mouseup",
|
|
3861
|
-
"mousedown",
|
|
3862
|
-
"touchstart",
|
|
3863
|
-
"touchend",
|
|
3864
|
-
"touchmove",
|
|
3865
|
-
"touchcancel",
|
|
3866
|
-
"wheel",
|
|
3867
|
-
"scroll",
|
|
3868
|
-
"resize",
|
|
3869
|
-
"focus",
|
|
3870
|
-
"blur",
|
|
3871
|
-
"change",
|
|
3872
|
-
"input",
|
|
3873
|
-
"submit",
|
|
3874
|
-
"reset",
|
|
3875
|
-
"keydown",
|
|
3876
|
-
"keyup",
|
|
3877
|
-
"keypress",
|
|
3878
|
-
"contextmenu",
|
|
3879
|
-
"drag",
|
|
3880
|
-
"dragend",
|
|
3881
|
-
"dragenter",
|
|
3882
|
-
"dragleave",
|
|
3883
|
-
"dragover",
|
|
3884
|
-
"drop",
|
|
3885
|
-
"dragstart",
|
|
3886
|
-
"select",
|
|
3887
|
-
"selectstart",
|
|
3888
|
-
"selectend",
|
|
3889
|
-
"selectall",
|
|
3890
|
-
"selectnone"
|
|
3891
|
-
];
|
|
3892
|
-
var CanvasDOMElement = class {
|
|
3893
|
-
constructor() {
|
|
3894
|
-
this.eventListeners = /* @__PURE__ */ new Map();
|
|
3895
|
-
this.onBeforeDestroy = null;
|
|
3896
|
-
this.valueSignal = null;
|
|
3897
|
-
this.isFormElementType = false;
|
|
3898
|
-
}
|
|
3899
|
-
/**
|
|
3900
|
-
* Checks if the element is a form element that supports the value attribute
|
|
3901
|
-
* @param elementType - The element type string from props
|
|
3902
|
-
* @returns true if the element is a form element with value support
|
|
3903
|
-
*/
|
|
3904
|
-
isFormElement(elementType) {
|
|
3905
|
-
const formElements = ["input", "textarea", "select"];
|
|
3906
|
-
return formElements.includes(elementType.toLowerCase());
|
|
3907
|
-
}
|
|
3908
|
-
onInit(props) {
|
|
3909
|
-
if (typeof props.element === "string") {
|
|
3910
|
-
this.element = document.createElement(props.element);
|
|
3911
|
-
this.isFormElementType = this.isFormElement(props.element);
|
|
3912
|
-
} else {
|
|
3913
|
-
this.element = props.element.value;
|
|
3914
|
-
this.isFormElementType = this.isFormElement(this.element.tagName);
|
|
3915
|
-
}
|
|
3916
|
-
if (props.onBeforeDestroy || props["on-before-destroy"]) {
|
|
3917
|
-
this.onBeforeDestroy = props.onBeforeDestroy || props["on-before-destroy"];
|
|
3918
|
-
}
|
|
3919
|
-
for (const event of EVENTS4) {
|
|
3920
|
-
if (props.attrs?.[event]) {
|
|
3921
|
-
const eventHandler = (e) => {
|
|
3922
|
-
if (event === "submit" && this.element.tagName.toLowerCase() === "form") {
|
|
3923
|
-
e.preventDefault();
|
|
3924
|
-
const formData = new FormData(this.element);
|
|
3925
|
-
const formObject = {};
|
|
3926
|
-
formData.forEach((value, key) => {
|
|
3927
|
-
if (formObject[key]) {
|
|
3928
|
-
if (Array.isArray(formObject[key])) {
|
|
3929
|
-
formObject[key].push(value);
|
|
3930
|
-
} else {
|
|
3931
|
-
formObject[key] = [formObject[key], value];
|
|
3932
|
-
}
|
|
3933
|
-
} else {
|
|
3934
|
-
formObject[key] = value;
|
|
3935
|
-
}
|
|
3936
|
-
});
|
|
3937
|
-
props.attrs[event]?.(e, formObject);
|
|
3938
|
-
} else {
|
|
3939
|
-
props.attrs[event]?.(e);
|
|
3940
|
-
}
|
|
3941
|
-
};
|
|
3942
|
-
this.eventListeners.set(event, eventHandler);
|
|
3943
|
-
this.element.addEventListener(event, eventHandler, false);
|
|
3944
|
-
}
|
|
3945
|
-
}
|
|
3946
|
-
if (props.children) {
|
|
3947
|
-
for (const child of props.children) {
|
|
3948
|
-
if (isObservable(child)) {
|
|
3949
|
-
child.subscribe(({ elements }) => {
|
|
3950
|
-
for (const element of elements) {
|
|
3951
|
-
this.element.appendChild(element.componentInstance.element);
|
|
3952
|
-
}
|
|
3953
|
-
});
|
|
3954
|
-
} else {
|
|
3955
|
-
this.element.appendChild(child.componentInstance.element);
|
|
3956
|
-
}
|
|
3957
|
-
}
|
|
3958
|
-
}
|
|
3959
|
-
this.onUpdate(props);
|
|
3960
|
-
}
|
|
3961
|
-
onMount(context) {
|
|
3962
|
-
const props = context.propObservables;
|
|
3963
|
-
const attrs = props.attrs;
|
|
3964
|
-
if (this.isFormElementType && attrs?.value && isSignal6(attrs.value)) {
|
|
3965
|
-
this.valueSignal = attrs.value;
|
|
3966
|
-
this.element.value = this.valueSignal();
|
|
3967
|
-
const inputHandler = (e) => {
|
|
3968
|
-
const target = e.target;
|
|
3969
|
-
this.valueSignal.set(target.value);
|
|
3970
|
-
};
|
|
3971
|
-
this.eventListeners.set("input", inputHandler);
|
|
3972
|
-
this.element.addEventListener("input", inputHandler, false);
|
|
3973
|
-
}
|
|
3974
|
-
}
|
|
3975
|
-
onUpdate(props) {
|
|
3976
|
-
if (!this.element) return;
|
|
3977
|
-
for (const [key, value] of Object.entries(props.attrs || {})) {
|
|
3978
|
-
if (key === "class") {
|
|
3979
|
-
const classList = value.items || value.value || value;
|
|
3980
|
-
this.element.className = "";
|
|
3981
|
-
if (typeof classList === "string") {
|
|
3982
|
-
this.element.className = classList;
|
|
3983
|
-
} else if (Array.isArray(classList)) {
|
|
3984
|
-
this.element.classList.add(...classList);
|
|
3985
|
-
} else if (typeof classList === "object" && classList !== null) {
|
|
3986
|
-
for (const [className, shouldAdd] of Object.entries(classList)) {
|
|
3987
|
-
if (shouldAdd) {
|
|
3988
|
-
this.element.classList.add(className);
|
|
3989
|
-
}
|
|
3990
|
-
}
|
|
3991
|
-
}
|
|
3992
|
-
} else if (key === "style") {
|
|
3993
|
-
const styleValue = value.items || value.value || value;
|
|
3994
|
-
if (typeof styleValue === "string") {
|
|
3995
|
-
this.element.setAttribute("style", styleValue);
|
|
3996
|
-
} else if (typeof styleValue === "object" && styleValue !== null) {
|
|
3997
|
-
for (const [styleProp, styleVal] of Object.entries(styleValue)) {
|
|
3998
|
-
if (styleVal !== null && styleVal !== void 0) {
|
|
3999
|
-
this.element.style[styleProp] = styleVal;
|
|
4000
|
-
}
|
|
4001
|
-
}
|
|
4002
|
-
}
|
|
4003
|
-
} else if (key === "value" && this.isFormElementType) {
|
|
4004
|
-
if (isSignal6(value)) {
|
|
4005
|
-
const currentValue = this.element.value;
|
|
4006
|
-
const signalValue = value();
|
|
4007
|
-
if (currentValue !== signalValue) {
|
|
4008
|
-
this.element.value = signalValue;
|
|
4009
|
-
}
|
|
4010
|
-
} else {
|
|
4011
|
-
this.element.value = value;
|
|
4012
|
-
}
|
|
4013
|
-
} else if (!EVENTS4.includes(key)) {
|
|
4014
|
-
this.element.setAttribute(key, value);
|
|
4015
|
-
}
|
|
4016
|
-
}
|
|
4017
|
-
if (props.textContent) {
|
|
4018
|
-
this.element.textContent = props.textContent;
|
|
4019
|
-
}
|
|
4020
|
-
}
|
|
4021
|
-
async onDestroy(parent, afterDestroy) {
|
|
4022
|
-
if (this.element) {
|
|
4023
|
-
if (this.onBeforeDestroy) {
|
|
4024
|
-
await this.onBeforeDestroy();
|
|
4025
|
-
}
|
|
4026
|
-
for (const [event, handler] of this.eventListeners) {
|
|
4027
|
-
this.element.removeEventListener(event, handler, false);
|
|
4028
|
-
}
|
|
4029
|
-
this.eventListeners.clear();
|
|
4030
|
-
this.element.remove();
|
|
4031
|
-
if (afterDestroy) {
|
|
4032
|
-
afterDestroy();
|
|
4033
|
-
}
|
|
4034
|
-
}
|
|
4035
|
-
}
|
|
4036
|
-
};
|
|
4037
|
-
registerComponent("DOMElement", CanvasDOMElement);
|
|
4038
|
-
var DOMElement = (props) => {
|
|
4039
|
-
return createComponent("DOMElement", props);
|
|
4040
|
-
};
|
|
4041
|
-
|
|
4042
|
-
// src/components/DOMContainer.ts
|
|
4043
|
-
var CanvasDOMContainer = class extends DisplayObject(PixiDOMContainer) {
|
|
4044
|
-
constructor() {
|
|
4045
|
-
super(...arguments);
|
|
4046
|
-
this.disableLayout = true;
|
|
4047
|
-
}
|
|
4048
|
-
onInit(props) {
|
|
4049
|
-
const div = h(DOMElement, { element: "div" }, props.children);
|
|
4050
|
-
this.element = div.componentInstance.element;
|
|
4051
|
-
}
|
|
4052
|
-
};
|
|
4053
|
-
registerComponent("DOMContainer", CanvasDOMContainer);
|
|
4054
|
-
var DOMContainer = (props) => {
|
|
4055
|
-
return createComponent("DOMContainer", props);
|
|
4056
|
-
};
|
|
4057
|
-
|
|
4058
|
-
// src/engine/bootstrap.ts
|
|
4059
|
-
import "@pixi/layout";
|
|
4060
|
-
import { Application as Application3 } from "pixi.js";
|
|
4061
|
-
var bootstrapCanvas = async (rootElement, canvas, options) => {
|
|
4062
|
-
const app = new Application3();
|
|
4063
|
-
await app.init({
|
|
4064
|
-
resizeTo: rootElement,
|
|
4065
|
-
autoStart: false,
|
|
4066
|
-
...options ?? {}
|
|
4067
|
-
});
|
|
4068
|
-
const canvasElement = await h(canvas);
|
|
4069
|
-
if (canvasElement.tag != "Canvas") {
|
|
4070
|
-
throw new Error("Canvas is required");
|
|
4071
|
-
}
|
|
4072
|
-
canvasElement.render(rootElement, app);
|
|
4073
|
-
const { backgroundColor } = useProps(canvasElement.props, {
|
|
4074
|
-
backgroundColor: "black"
|
|
4075
|
-
});
|
|
4076
|
-
app.renderer.background.color = backgroundColor();
|
|
4077
|
-
return {
|
|
4078
|
-
canvasElement,
|
|
4079
|
-
app
|
|
4080
|
-
};
|
|
4081
|
-
};
|
|
4082
|
-
|
|
4083
|
-
// src/utils/Ease.ts
|
|
4084
|
-
import {
|
|
4085
|
-
linear,
|
|
4086
|
-
easeIn,
|
|
4087
|
-
easeInOut,
|
|
4088
|
-
easeOut,
|
|
4089
|
-
circIn,
|
|
4090
|
-
circInOut,
|
|
4091
|
-
circOut,
|
|
4092
|
-
backIn,
|
|
4093
|
-
backInOut,
|
|
4094
|
-
backOut,
|
|
4095
|
-
anticipate,
|
|
4096
|
-
bounceIn,
|
|
4097
|
-
bounceInOut,
|
|
4098
|
-
bounceOut
|
|
4099
|
-
} from "popmotion";
|
|
4100
|
-
var Easing = {
|
|
4101
|
-
linear,
|
|
4102
|
-
easeIn,
|
|
4103
|
-
easeInOut,
|
|
4104
|
-
easeOut,
|
|
4105
|
-
circIn,
|
|
4106
|
-
circInOut,
|
|
4107
|
-
circOut,
|
|
4108
|
-
backIn,
|
|
4109
|
-
backInOut,
|
|
4110
|
-
backOut,
|
|
4111
|
-
anticipate,
|
|
4112
|
-
bounceIn,
|
|
4113
|
-
bounceInOut,
|
|
4114
|
-
bounceOut
|
|
4115
|
-
};
|
|
4116
|
-
|
|
4117
|
-
// src/utils/RadialGradient.ts
|
|
4118
|
-
import { Texture as Texture6, ImageSource, DOMAdapter, Matrix } from "pixi.js";
|
|
4119
|
-
var RadialGradient = class {
|
|
4120
|
-
/**
|
|
4121
|
-
* Creates a new RadialGradient instance
|
|
4122
|
-
* @param x0 - The x-coordinate of the starting circle
|
|
4123
|
-
* @param y0 - The y-coordinate of the starting circle
|
|
4124
|
-
* @param x1 - The x-coordinate of the ending circle
|
|
4125
|
-
* @param y1 - The y-coordinate of the ending circle
|
|
4126
|
-
* @param x2 - The x-coordinate for gradient transformation
|
|
4127
|
-
* @param y2 - The y-coordinate for gradient transformation
|
|
4128
|
-
* @param focalPoint - The focal point of the gradient (0-1), defaults to 0
|
|
4129
|
-
*/
|
|
4130
|
-
constructor(x0, y0, x1, y1, x2, y2, focalPoint = 0) {
|
|
4131
|
-
this.x0 = x0;
|
|
4132
|
-
this.y0 = y0;
|
|
4133
|
-
this.x1 = x1;
|
|
4134
|
-
this.y1 = y1;
|
|
4135
|
-
this.x2 = x2;
|
|
4136
|
-
this.y2 = y2;
|
|
4137
|
-
this.focalPoint = focalPoint;
|
|
4138
|
-
this.gradient = null;
|
|
4139
|
-
this.texture = null;
|
|
4140
|
-
this.size = 600;
|
|
4141
|
-
this.size = x0;
|
|
4142
|
-
const halfSize = this.size * 0.5;
|
|
4143
|
-
this.canvas = DOMAdapter.get().createCanvas();
|
|
4144
|
-
this.canvas.width = this.size;
|
|
4145
|
-
this.canvas.height = this.size;
|
|
4146
|
-
this.ctx = this.canvas.getContext("2d");
|
|
4147
|
-
if (this.ctx) {
|
|
4148
|
-
this.gradient = this.ctx.createRadialGradient(
|
|
4149
|
-
halfSize * (1 - focalPoint),
|
|
4150
|
-
halfSize,
|
|
4151
|
-
0,
|
|
4152
|
-
halfSize,
|
|
4153
|
-
halfSize,
|
|
4154
|
-
halfSize - 0.5
|
|
4155
|
-
);
|
|
4156
|
-
}
|
|
4157
|
-
}
|
|
4158
|
-
/**
|
|
4159
|
-
* Adds a color stop to the gradient
|
|
4160
|
-
* @param offset - The position of the color stop (0-1)
|
|
4161
|
-
* @param color - The color value (any valid CSS color string)
|
|
4162
|
-
*/
|
|
4163
|
-
addColorStop(offset, color) {
|
|
4164
|
-
if (this.gradient) {
|
|
4165
|
-
this.gradient.addColorStop(offset, color);
|
|
4166
|
-
}
|
|
4167
|
-
}
|
|
4168
|
-
/**
|
|
4169
|
-
* Renders the gradient and returns the texture with its transformation matrix
|
|
4170
|
-
* @param options - Render options
|
|
4171
|
-
* @param options.translate - Optional translation coordinates
|
|
4172
|
-
* @returns Object containing the texture and transformation matrix
|
|
4173
|
-
*/
|
|
4174
|
-
render({ translate } = {}) {
|
|
4175
|
-
const { x0, y0, x1, y1, x2, y2, focalPoint } = this;
|
|
4176
|
-
const defaultSize = this.size;
|
|
4177
|
-
if (this.ctx && this.gradient) {
|
|
4178
|
-
this.ctx.fillStyle = this.gradient;
|
|
4179
|
-
this.ctx.fillRect(0, 0, defaultSize, defaultSize);
|
|
4180
|
-
this.texture = new Texture6({
|
|
4181
|
-
source: new ImageSource({
|
|
4182
|
-
resource: this.canvas,
|
|
4183
|
-
addressModeU: "clamp-to-edge",
|
|
4184
|
-
addressModeV: "clamp-to-edge"
|
|
4185
|
-
})
|
|
4186
|
-
});
|
|
4187
|
-
const m = new Matrix();
|
|
4188
|
-
const dx = Math.sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
|
|
4189
|
-
const dy = Math.sqrt((x2 - x0) * (x2 - x0) + (y2 - y0) * (y2 - y0));
|
|
4190
|
-
const angle = Math.atan2(y1 - y0, x1 - x0);
|
|
4191
|
-
const scaleX = dx / defaultSize;
|
|
4192
|
-
const scaleY = dy / defaultSize;
|
|
4193
|
-
m.rotate(-angle);
|
|
4194
|
-
m.scale(scaleX, scaleY);
|
|
4195
|
-
if (translate) {
|
|
4196
|
-
m.translate(translate.x, translate.y);
|
|
4197
|
-
}
|
|
4198
|
-
this.transform = m;
|
|
4199
|
-
}
|
|
4200
|
-
return {
|
|
4201
|
-
texture: this.texture,
|
|
4202
|
-
matrix: this.transform
|
|
4203
|
-
};
|
|
4204
|
-
}
|
|
4205
|
-
};
|
|
4206
|
-
|
|
4207
|
-
// src/index.ts
|
|
4208
|
-
import { isObservable as isObservable2 } from "rxjs";
|
|
4209
|
-
import * as Howl3 from "howler";
|
|
1
|
+
import { h as a } from "./index-5TTorHyA.js";
|
|
2
|
+
import { A as r, C as n, m as o, l as c, D as l, v as p, a3 as m, a2 as S, a0 as g, n as u, G as b, c as d, M as C, N as j, O as T, P as E, a1 as O, R as f, o as v, p as w, S as h, q as D, r as P, T as k, b as x, V as y, t as A, $ as H, _ as M, Y as V, d as G, H as N, z as R, I as q, e as U, Q as z, Z as B, f as I, g as J, w as K, j as L, i as Q, x as W, k as X, U as Y, B as Z, K as _, J as $, X as F, y as aa, s as sa, L as ea, W as ia, a as ta, u as ra } from "./index-5TTorHyA.js";
|
|
3
|
+
const e = a.Howler;
|
|
4210
4
|
export {
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
5
|
+
r as ArraySubject,
|
|
6
|
+
n as Canvas,
|
|
7
|
+
o as Circle,
|
|
8
|
+
c as Container,
|
|
9
|
+
l as DOMContainer,
|
|
10
|
+
p as DOMElement,
|
|
11
|
+
m as DisplayObject,
|
|
12
|
+
S as EVENTS,
|
|
13
|
+
g as Easing,
|
|
14
|
+
u as Ellipse,
|
|
15
|
+
b as Graphics,
|
|
16
|
+
d as Howl,
|
|
17
|
+
e as Howler,
|
|
18
|
+
C as Mesh,
|
|
19
|
+
j as NineSliceSprite,
|
|
20
|
+
T as ObjectSubject,
|
|
21
|
+
E as ParticlesEmitter,
|
|
22
|
+
O as RadialGradient,
|
|
23
|
+
f as Rect,
|
|
24
|
+
v as Scene,
|
|
25
|
+
w as Sprite,
|
|
26
|
+
h as Svg,
|
|
27
|
+
D as Text,
|
|
28
|
+
P as TilingSprite,
|
|
29
|
+
k as Triangle,
|
|
30
|
+
x as Utils,
|
|
31
|
+
y as Video,
|
|
32
|
+
A as Viewport,
|
|
33
|
+
H as animatedSequence,
|
|
34
|
+
M as animatedSignal,
|
|
35
|
+
V as bootstrapCanvas,
|
|
36
|
+
G as computed,
|
|
37
|
+
N as cond,
|
|
38
|
+
R as createComponent,
|
|
39
|
+
q as currentSubscriptionsTracker,
|
|
40
|
+
U as effect,
|
|
41
|
+
z as h,
|
|
42
|
+
B as isAnimatedSignal,
|
|
43
|
+
I as isArraySubject,
|
|
44
|
+
J as isComputed,
|
|
45
|
+
K as isElement,
|
|
46
|
+
L as isObjectSubject,
|
|
47
|
+
Q as isObservable,
|
|
48
|
+
W as isPrimitive,
|
|
49
|
+
X as isSignal,
|
|
50
|
+
Y as isTrigger,
|
|
51
|
+
Z as loop,
|
|
52
|
+
_ as mount,
|
|
53
|
+
$ as mountTracker,
|
|
54
|
+
F as on,
|
|
55
|
+
aa as registerComponent,
|
|
56
|
+
sa as signal,
|
|
57
|
+
ea as tick,
|
|
58
|
+
ia as trigger,
|
|
59
|
+
ta as useDefineProps,
|
|
60
|
+
ra as useProps
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=index.js.map
|