@mulsense/xnew 0.3.5 → 0.3.7
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/addons/xmatter.js +1 -1
- package/dist/addons/xmatter.mjs +1 -1
- package/dist/addons/xpixi.js +6 -6
- package/dist/addons/xpixi.mjs +6 -6
- package/dist/addons/xrapier2d.js +1 -1
- package/dist/addons/xrapier2d.mjs +1 -1
- package/dist/addons/xrapier3d.js +5 -10
- package/dist/addons/xrapier3d.mjs +5 -10
- package/dist/addons/xthree.js +4 -6
- package/dist/addons/xthree.mjs +4 -6
- package/dist/xnew.d.ts +1 -4
- package/dist/xnew.js +26 -91
- package/dist/xnew.mjs +26 -91
- package/package.json +1 -1
package/dist/addons/xmatter.js
CHANGED
package/dist/addons/xmatter.mjs
CHANGED
|
@@ -18,7 +18,7 @@ function Root(unit, { engine }) {
|
|
|
18
18
|
const root = {};
|
|
19
19
|
xnew.context('xmatter.root', root);
|
|
20
20
|
root.engine = engine !== null && engine !== void 0 ? engine : Matter.Engine.create();
|
|
21
|
-
unit.on('
|
|
21
|
+
unit.on('process', () => {
|
|
22
22
|
Matter.Engine.update(root.engine);
|
|
23
23
|
});
|
|
24
24
|
}
|
package/dist/addons/xpixi.js
CHANGED
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
return (_a = xnew.context('xpixi.root')) === null || _a === void 0 ? void 0 : _a.canvas;
|
|
52
52
|
},
|
|
53
53
|
};
|
|
54
|
-
function Root(
|
|
54
|
+
function Root(unit, { canvas }) {
|
|
55
55
|
const root = {};
|
|
56
56
|
xnew.context('xpixi.root', root);
|
|
57
57
|
root.canvas = canvas;
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
root.updates = [];
|
|
64
64
|
root.scene = new PIXI__namespace.Container();
|
|
65
65
|
xnew.context('xpixi.object', root.scene);
|
|
66
|
-
|
|
66
|
+
unit.on('update', () => {
|
|
67
67
|
root.updates.forEach((update) => {
|
|
68
68
|
update();
|
|
69
69
|
});
|
|
@@ -72,18 +72,18 @@
|
|
|
72
72
|
}
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
|
-
function Nest(
|
|
75
|
+
function Nest(unit, { object }) {
|
|
76
76
|
const parent = xnew.context('xpixi.object');
|
|
77
77
|
xnew.context('xpixi.object', object);
|
|
78
78
|
parent.addChild(object);
|
|
79
|
-
|
|
79
|
+
unit.on('finalize', () => {
|
|
80
80
|
parent.removeChild(object);
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
|
-
function PreUpdate(
|
|
83
|
+
function PreUpdate(unit, callback) {
|
|
84
84
|
const root = xnew.context('xpixi.root');
|
|
85
85
|
root.updates.push(callback);
|
|
86
|
-
|
|
86
|
+
unit.on('finalize', () => {
|
|
87
87
|
root.updates = root.updates.filter((update) => update !== callback);
|
|
88
88
|
});
|
|
89
89
|
}
|
package/dist/addons/xpixi.mjs
CHANGED
|
@@ -29,7 +29,7 @@ var xpixi = {
|
|
|
29
29
|
return (_a = xnew.context('xpixi.root')) === null || _a === void 0 ? void 0 : _a.canvas;
|
|
30
30
|
},
|
|
31
31
|
};
|
|
32
|
-
function Root(
|
|
32
|
+
function Root(unit, { canvas }) {
|
|
33
33
|
const root = {};
|
|
34
34
|
xnew.context('xpixi.root', root);
|
|
35
35
|
root.canvas = canvas;
|
|
@@ -41,7 +41,7 @@ function Root(self, { canvas }) {
|
|
|
41
41
|
root.updates = [];
|
|
42
42
|
root.scene = new PIXI.Container();
|
|
43
43
|
xnew.context('xpixi.object', root.scene);
|
|
44
|
-
|
|
44
|
+
unit.on('update', () => {
|
|
45
45
|
root.updates.forEach((update) => {
|
|
46
46
|
update();
|
|
47
47
|
});
|
|
@@ -50,18 +50,18 @@ function Root(self, { canvas }) {
|
|
|
50
50
|
}
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
|
-
function Nest(
|
|
53
|
+
function Nest(unit, { object }) {
|
|
54
54
|
const parent = xnew.context('xpixi.object');
|
|
55
55
|
xnew.context('xpixi.object', object);
|
|
56
56
|
parent.addChild(object);
|
|
57
|
-
|
|
57
|
+
unit.on('finalize', () => {
|
|
58
58
|
parent.removeChild(object);
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
|
-
function PreUpdate(
|
|
61
|
+
function PreUpdate(unit, callback) {
|
|
62
62
|
const root = xnew.context('xpixi.root');
|
|
63
63
|
root.updates.push(callback);
|
|
64
|
-
|
|
64
|
+
unit.on('finalize', () => {
|
|
65
65
|
root.updates = root.updates.filter((update) => update !== callback);
|
|
66
66
|
});
|
|
67
67
|
}
|
package/dist/addons/xrapier2d.js
CHANGED
package/dist/addons/xrapier3d.js
CHANGED
|
@@ -5,27 +5,22 @@
|
|
|
5
5
|
})(this, (function (xnew, RAPIER) { 'use strict';
|
|
6
6
|
|
|
7
7
|
var xrapier3d = {
|
|
8
|
-
initialize({ gravity = { x: 0.0, y: 9.81, z: 0.0 }
|
|
9
|
-
xnew.extend(Root, { gravity
|
|
8
|
+
initialize({ gravity = { x: 0.0, y: 9.81, z: 0.0 } } = {}) {
|
|
9
|
+
xnew.extend(Root, { gravity });
|
|
10
10
|
},
|
|
11
11
|
get world() {
|
|
12
12
|
var _a;
|
|
13
13
|
return (_a = xnew.context('xrapier3d.root')) === null || _a === void 0 ? void 0 : _a.world;
|
|
14
14
|
},
|
|
15
15
|
};
|
|
16
|
-
function Root(self, { gravity
|
|
16
|
+
function Root(self, { gravity }) {
|
|
17
17
|
const root = {};
|
|
18
18
|
xnew.context('xrapier3d.root', root);
|
|
19
19
|
xnew.promise(RAPIER.init()).then(() => {
|
|
20
20
|
root.world = new RAPIER.World(gravity);
|
|
21
|
-
if (timestep !== null) {
|
|
22
|
-
root.world.timestep = timestep;
|
|
23
|
-
}
|
|
24
21
|
});
|
|
25
|
-
self.on('
|
|
26
|
-
|
|
27
|
-
root.world.step();
|
|
28
|
-
}
|
|
22
|
+
self.on('process', () => {
|
|
23
|
+
root.world.step();
|
|
29
24
|
});
|
|
30
25
|
}
|
|
31
26
|
|
|
@@ -2,27 +2,22 @@ import xnew from '@mulsense/xnew';
|
|
|
2
2
|
import RAPIER from '@dimforge/rapier3d-compat';
|
|
3
3
|
|
|
4
4
|
var xrapier3d = {
|
|
5
|
-
initialize({ gravity = { x: 0.0, y: 9.81, z: 0.0 }
|
|
6
|
-
xnew.extend(Root, { gravity
|
|
5
|
+
initialize({ gravity = { x: 0.0, y: 9.81, z: 0.0 } } = {}) {
|
|
6
|
+
xnew.extend(Root, { gravity });
|
|
7
7
|
},
|
|
8
8
|
get world() {
|
|
9
9
|
var _a;
|
|
10
10
|
return (_a = xnew.context('xrapier3d.root')) === null || _a === void 0 ? void 0 : _a.world;
|
|
11
11
|
},
|
|
12
12
|
};
|
|
13
|
-
function Root(self, { gravity
|
|
13
|
+
function Root(self, { gravity }) {
|
|
14
14
|
const root = {};
|
|
15
15
|
xnew.context('xrapier3d.root', root);
|
|
16
16
|
xnew.promise(RAPIER.init()).then(() => {
|
|
17
17
|
root.world = new RAPIER.World(gravity);
|
|
18
|
-
if (timestep !== null) {
|
|
19
|
-
root.world.timestep = timestep;
|
|
20
|
-
}
|
|
21
18
|
});
|
|
22
|
-
self.on('
|
|
23
|
-
|
|
24
|
-
root.world.step();
|
|
25
|
-
}
|
|
19
|
+
self.on('process', () => {
|
|
20
|
+
root.world.step();
|
|
26
21
|
});
|
|
27
22
|
}
|
|
28
23
|
|
package/dist/addons/xthree.js
CHANGED
|
@@ -64,12 +64,10 @@
|
|
|
64
64
|
function Nest(unit, { object }) {
|
|
65
65
|
const parent = xnew.context('xthree.object');
|
|
66
66
|
xnew.context('xthree.object', object);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
});
|
|
72
|
-
}
|
|
67
|
+
parent.add(object);
|
|
68
|
+
unit.on('finalize', () => {
|
|
69
|
+
parent.remove(object);
|
|
70
|
+
});
|
|
73
71
|
}
|
|
74
72
|
|
|
75
73
|
return xthree;
|
package/dist/addons/xthree.mjs
CHANGED
|
@@ -42,12 +42,10 @@ function Root(unit, { canvas, camera }) {
|
|
|
42
42
|
function Nest(unit, { object }) {
|
|
43
43
|
const parent = xnew.context('xthree.object');
|
|
44
44
|
xnew.context('xthree.object', object);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
}
|
|
45
|
+
parent.add(object);
|
|
46
|
+
unit.on('finalize', () => {
|
|
47
|
+
parent.remove(object);
|
|
48
|
+
});
|
|
51
49
|
}
|
|
52
50
|
|
|
53
51
|
export { xthree as default };
|
package/dist/xnew.d.ts
CHANGED
|
@@ -81,6 +81,7 @@ declare class Unit {
|
|
|
81
81
|
static start(unit: Unit): void;
|
|
82
82
|
static stop(unit: Unit): void;
|
|
83
83
|
static update(unit: Unit): void;
|
|
84
|
+
static process(unit: Unit): void;
|
|
84
85
|
static root: Unit;
|
|
85
86
|
static current: Unit;
|
|
86
87
|
static ticker: Ticker;
|
|
@@ -276,8 +277,6 @@ declare function AccordionContent(content: Unit, {}?: {}): {
|
|
|
276
277
|
|
|
277
278
|
declare function ResizeEvent(resize: Unit): void;
|
|
278
279
|
declare function DirectEvent(unit: Unit): void;
|
|
279
|
-
declare function KeyboardEvent(keyboard: Unit): void;
|
|
280
|
-
declare function PointerEvent(unit: Unit): void;
|
|
281
280
|
|
|
282
281
|
declare function Screen(screen: Unit, { width, height, fit }?: {
|
|
283
282
|
width?: number | undefined;
|
|
@@ -729,10 +728,8 @@ declare class Synthesizer {
|
|
|
729
728
|
|
|
730
729
|
declare const basics: {
|
|
731
730
|
Screen: typeof Screen;
|
|
732
|
-
PointerEvent: typeof PointerEvent;
|
|
733
731
|
DirectEvent: typeof DirectEvent;
|
|
734
732
|
ResizeEvent: typeof ResizeEvent;
|
|
735
|
-
KeyboardEvent: typeof KeyboardEvent;
|
|
736
733
|
ModalFrame: typeof ModalFrame;
|
|
737
734
|
ModalContent: typeof ModalContent;
|
|
738
735
|
AccordionFrame: typeof AccordionFrame;
|
package/dist/xnew.js
CHANGED
|
@@ -209,7 +209,7 @@
|
|
|
209
209
|
//----------------------------------------------------------------------------------------------------
|
|
210
210
|
// utils
|
|
211
211
|
//----------------------------------------------------------------------------------------------------
|
|
212
|
-
const SYSTEM_EVENTS = ['start', 'update', 'stop', 'finalize'];
|
|
212
|
+
const SYSTEM_EVENTS = ['start', 'process', 'update', 'stop', 'finalize'];
|
|
213
213
|
//----------------------------------------------------------------------------------------------------
|
|
214
214
|
// unit
|
|
215
215
|
//----------------------------------------------------------------------------------------------------
|
|
@@ -302,7 +302,7 @@
|
|
|
302
302
|
components: [],
|
|
303
303
|
listeners: new MapMap(),
|
|
304
304
|
defines: {},
|
|
305
|
-
systems: { start: [], update: [], stop: [], finalize: [] },
|
|
305
|
+
systems: { start: [], process: [], update: [], stop: [], finalize: [] },
|
|
306
306
|
});
|
|
307
307
|
// nest html element
|
|
308
308
|
if (typeof unit._.target === 'string') {
|
|
@@ -412,11 +412,17 @@
|
|
|
412
412
|
}
|
|
413
413
|
}
|
|
414
414
|
static update(unit) {
|
|
415
|
-
if (unit._.state === 'started') {
|
|
415
|
+
if (unit._.state === 'started' || unit._.state === 'stopped') {
|
|
416
416
|
unit._.children.forEach((child) => Unit.update(child));
|
|
417
417
|
unit._.systems.update.forEach((listener) => Unit.scope(Unit.snapshot(unit), listener));
|
|
418
418
|
}
|
|
419
419
|
}
|
|
420
|
+
static process(unit) {
|
|
421
|
+
if (unit._.state === 'started') {
|
|
422
|
+
unit._.children.forEach((child) => Unit.process(child));
|
|
423
|
+
unit._.systems.process.forEach((listener) => Unit.scope(Unit.snapshot(unit), listener));
|
|
424
|
+
}
|
|
425
|
+
}
|
|
420
426
|
static reset() {
|
|
421
427
|
var _a, _b;
|
|
422
428
|
(_a = Unit.root) === null || _a === void 0 ? void 0 : _a.finalize();
|
|
@@ -424,6 +430,7 @@
|
|
|
424
430
|
(_b = Unit.ticker) === null || _b === void 0 ? void 0 : _b.clear();
|
|
425
431
|
Unit.ticker = new Ticker(() => {
|
|
426
432
|
Unit.start(Unit.root);
|
|
433
|
+
Unit.process(Unit.root);
|
|
427
434
|
Unit.update(Unit.root);
|
|
428
435
|
});
|
|
429
436
|
}
|
|
@@ -935,6 +942,8 @@
|
|
|
935
942
|
function DirectEvent(unit) {
|
|
936
943
|
const state = {};
|
|
937
944
|
const keydown = xnew$1.scope((event) => {
|
|
945
|
+
if (event.repeat)
|
|
946
|
+
return;
|
|
938
947
|
state[event.code] = 1;
|
|
939
948
|
xnew$1.emit('-keydown', { event, type: '-keydown', code: event.code });
|
|
940
949
|
if (['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(event.code)) {
|
|
@@ -1002,78 +1011,6 @@
|
|
|
1002
1011
|
gesture.on('-gestureend', (...args) => xnew$1.emit('-gestureend', ...args));
|
|
1003
1012
|
gesture.on('-gesturecancel', (...args) => xnew$1.emit('-gesturecancel', ...args));
|
|
1004
1013
|
}
|
|
1005
|
-
function KeyboardEvent(keyboard) {
|
|
1006
|
-
const state = {};
|
|
1007
|
-
const keydown = xnew$1.scope((event) => {
|
|
1008
|
-
state[event.code] = 1;
|
|
1009
|
-
xnew$1.emit('-keydown', { event, type: '-keydown', code: event.code });
|
|
1010
|
-
if (['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(event.code)) {
|
|
1011
|
-
xnew$1.emit('-keydown.arrow', { event, type: '-keydown.arrow', code: event.code, vector: getVector() });
|
|
1012
|
-
}
|
|
1013
|
-
});
|
|
1014
|
-
const keyup = xnew$1.scope((event) => {
|
|
1015
|
-
state[event.code] = 0;
|
|
1016
|
-
xnew$1.emit('-keyup', { event, type: '-keyup', code: event.code });
|
|
1017
|
-
if (['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(event.code)) {
|
|
1018
|
-
xnew$1.emit('-keyup.arrow', { event, type: '-keyup.arrow', code: event.code, vector: getVector() });
|
|
1019
|
-
}
|
|
1020
|
-
});
|
|
1021
|
-
window.addEventListener('keydown', keydown);
|
|
1022
|
-
window.addEventListener('keyup', keyup);
|
|
1023
|
-
keyboard.on('finalize', () => {
|
|
1024
|
-
window.removeEventListener('keydown', keydown);
|
|
1025
|
-
window.removeEventListener('keyup', keyup);
|
|
1026
|
-
});
|
|
1027
|
-
function getVector() {
|
|
1028
|
-
return {
|
|
1029
|
-
x: (state['ArrowLeft'] ? -1 : 0) + (state['ArrowRight'] ? +1 : 0),
|
|
1030
|
-
y: (state['ArrowUp'] ? -1 : 0) + (state['ArrowDown'] ? +1 : 0)
|
|
1031
|
-
};
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
function PointerEvent(unit) {
|
|
1035
|
-
const internal = xnew$1();
|
|
1036
|
-
internal.on('pointerdown', (event) => xnew$1.emit('-pointerdown', { event, position: getPosition(unit.element, event) }));
|
|
1037
|
-
internal.on('pointermove', (event) => xnew$1.emit('-pointermove', { event, position: getPosition(unit.element, event) }));
|
|
1038
|
-
internal.on('pointerup', (event) => xnew$1.emit('-pointerup', { event, position: getPosition(unit.element, event) }));
|
|
1039
|
-
internal.on('wheel', (event) => xnew$1.emit('-wheel', { event, delta: { x: event.wheelDeltaX, y: event.wheelDeltaY } }));
|
|
1040
|
-
internal.on('click', (event) => xnew$1.emit('-click', { event, position: getPosition(unit.element, event) }));
|
|
1041
|
-
internal.on('pointerover', (event) => xnew$1.emit('-pointerover', { event, position: getPosition(unit.element, event) }));
|
|
1042
|
-
internal.on('pointerout', (event) => xnew$1.emit('-pointerout', { event, position: getPosition(unit.element, event) }));
|
|
1043
|
-
const pointerdownoutside = xnew$1.scope((event) => {
|
|
1044
|
-
if (unit.element.contains(event.target) === false) {
|
|
1045
|
-
xnew$1.emit('-pointerdown.outside', { event, position: getPosition(unit.element, event) });
|
|
1046
|
-
}
|
|
1047
|
-
});
|
|
1048
|
-
const pointerupoutside = xnew$1.scope((event) => {
|
|
1049
|
-
if (unit.element.contains(event.target) === false) {
|
|
1050
|
-
xnew$1.emit('-pointerup.outside', { event, position: getPosition(unit.element, event) });
|
|
1051
|
-
}
|
|
1052
|
-
});
|
|
1053
|
-
const clickoutside = xnew$1.scope((event) => {
|
|
1054
|
-
if (unit.element.contains(event.target) === false) {
|
|
1055
|
-
xnew$1.emit('-click.outside', { event, position: getPosition(unit.element, event) });
|
|
1056
|
-
}
|
|
1057
|
-
});
|
|
1058
|
-
document.addEventListener('pointerdown', pointerdownoutside);
|
|
1059
|
-
document.addEventListener('pointerup', pointerupoutside);
|
|
1060
|
-
document.addEventListener('click', clickoutside);
|
|
1061
|
-
unit.on('finalize', () => {
|
|
1062
|
-
document.removeEventListener('pointerdown', pointerdownoutside);
|
|
1063
|
-
document.removeEventListener('pointerup', pointerupoutside);
|
|
1064
|
-
document.removeEventListener('click', clickoutside);
|
|
1065
|
-
});
|
|
1066
|
-
const drag = xnew$1(DragEvent);
|
|
1067
|
-
drag.on('-dragstart', (...args) => xnew$1.emit('-dragstart', ...args));
|
|
1068
|
-
drag.on('-dragmove', (...args) => xnew$1.emit('-dragmove', ...args));
|
|
1069
|
-
drag.on('-dragend', (...args) => xnew$1.emit('-dragend', ...args));
|
|
1070
|
-
drag.on('-dragcancel', (...args) => xnew$1.emit('-dragcancel', ...args));
|
|
1071
|
-
const gesture = xnew$1(GestureEvent);
|
|
1072
|
-
gesture.on('-gesturestart', (...args) => xnew$1.emit('-gesturestart', ...args));
|
|
1073
|
-
gesture.on('-gesturemove', (...args) => xnew$1.emit('-gesturemove', ...args));
|
|
1074
|
-
gesture.on('-gestureend', (...args) => xnew$1.emit('-gestureend', ...args));
|
|
1075
|
-
gesture.on('-gesturecancel', (...args) => xnew$1.emit('-gesturecancel', ...args));
|
|
1076
|
-
}
|
|
1077
1014
|
function DragEvent(unit) {
|
|
1078
1015
|
const pointerdown = xnew$1.scope((event) => {
|
|
1079
1016
|
const id = event.pointerId;
|
|
@@ -1332,11 +1269,11 @@
|
|
|
1332
1269
|
function DragTarget(target, {} = {}) {
|
|
1333
1270
|
const { frame, absolute } = xnew$1.context('xnew.dragframe');
|
|
1334
1271
|
xnew$1.nest('<div>');
|
|
1335
|
-
const
|
|
1272
|
+
const direct = xnew$1(absolute.parentElement, DirectEvent);
|
|
1336
1273
|
const current = { x: 0, y: 0 };
|
|
1337
1274
|
const offset = { x: 0, y: 0 };
|
|
1338
1275
|
let dragged = false;
|
|
1339
|
-
|
|
1276
|
+
direct.on('-dragstart', ({ event, position }) => {
|
|
1340
1277
|
if (target.element.contains(event.target) === false)
|
|
1341
1278
|
return;
|
|
1342
1279
|
dragged = true;
|
|
@@ -1345,7 +1282,7 @@
|
|
|
1345
1282
|
current.x = position.x - offset.x;
|
|
1346
1283
|
current.y = position.y - offset.y;
|
|
1347
1284
|
});
|
|
1348
|
-
|
|
1285
|
+
direct.on('-dragmove', ({ event, delta }) => {
|
|
1349
1286
|
if (dragged !== true)
|
|
1350
1287
|
return;
|
|
1351
1288
|
current.x += delta.x;
|
|
@@ -1353,7 +1290,7 @@
|
|
|
1353
1290
|
absolute.style.left = `${current.x}px`;
|
|
1354
1291
|
absolute.style.top = `${current.y}px`;
|
|
1355
1292
|
});
|
|
1356
|
-
|
|
1293
|
+
direct.on('-dragcancel -dragend', ({ event }) => {
|
|
1357
1294
|
dragged = false;
|
|
1358
1295
|
});
|
|
1359
1296
|
}
|
|
@@ -1390,22 +1327,22 @@
|
|
|
1390
1327
|
xnew$1.extend(SVGTemplate, { fill, fillOpacity, stroke, strokeOpacity, strokeWidth, strokeLinejoin });
|
|
1391
1328
|
xnew$1('<circle cx="50" cy="50" r="23">');
|
|
1392
1329
|
});
|
|
1393
|
-
const
|
|
1394
|
-
|
|
1330
|
+
const direct = xnew$1(DirectEvent);
|
|
1331
|
+
direct.on('-dragstart', ({ event, position }) => {
|
|
1395
1332
|
const vector = getVector(position);
|
|
1396
1333
|
target.element.style.filter = 'brightness(90%)';
|
|
1397
1334
|
target.element.style.left = vector.x * newsize / 4 + 'px';
|
|
1398
1335
|
target.element.style.top = vector.y * newsize / 4 + 'px';
|
|
1399
1336
|
xnew$1.emit('-down', { vector });
|
|
1400
1337
|
});
|
|
1401
|
-
|
|
1338
|
+
direct.on('-dragmove', ({ event, position }) => {
|
|
1402
1339
|
const vector = getVector(position);
|
|
1403
1340
|
target.element.style.filter = 'brightness(90%)';
|
|
1404
1341
|
target.element.style.left = vector.x * newsize / 4 + 'px';
|
|
1405
1342
|
target.element.style.top = vector.y * newsize / 4 + 'px';
|
|
1406
1343
|
xnew$1.emit('-move', { vector });
|
|
1407
1344
|
});
|
|
1408
|
-
|
|
1345
|
+
direct.on('-dragend', ({ event }) => {
|
|
1409
1346
|
const vector = { x: 0, y: 0 };
|
|
1410
1347
|
target.element.style.filter = '';
|
|
1411
1348
|
target.element.style.left = vector.x * newsize / 4 + 'px';
|
|
@@ -1457,8 +1394,8 @@
|
|
|
1457
1394
|
xnew$1('<polygon points="11 50 20 42 20 58">');
|
|
1458
1395
|
xnew$1('<polygon points="89 50 80 42 80 58">');
|
|
1459
1396
|
});
|
|
1460
|
-
const
|
|
1461
|
-
|
|
1397
|
+
const direct = xnew$1(DirectEvent);
|
|
1398
|
+
direct.on('-dragstart', ({ event, position }) => {
|
|
1462
1399
|
const vector = getVector(position);
|
|
1463
1400
|
targets[0].element.style.filter = (vector.y < 0) ? 'brightness(90%)' : '';
|
|
1464
1401
|
targets[1].element.style.filter = (vector.y > 0) ? 'brightness(90%)' : '';
|
|
@@ -1466,7 +1403,7 @@
|
|
|
1466
1403
|
targets[3].element.style.filter = (vector.x > 0) ? 'brightness(90%)' : '';
|
|
1467
1404
|
xnew$1.emit('-down', { vector });
|
|
1468
1405
|
});
|
|
1469
|
-
|
|
1406
|
+
direct.on('-dragmove', ({ event, position }) => {
|
|
1470
1407
|
const vector = getVector(position);
|
|
1471
1408
|
targets[0].element.style.filter = (vector.y < 0) ? 'brightness(90%)' : '';
|
|
1472
1409
|
targets[1].element.style.filter = (vector.y > 0) ? 'brightness(90%)' : '';
|
|
@@ -1474,7 +1411,7 @@
|
|
|
1474
1411
|
targets[3].element.style.filter = (vector.x > 0) ? 'brightness(90%)' : '';
|
|
1475
1412
|
xnew$1.emit('-move', { vector });
|
|
1476
1413
|
});
|
|
1477
|
-
|
|
1414
|
+
direct.on('-dragend', ({ event }) => {
|
|
1478
1415
|
const vector = { x: 0, y: 0 };
|
|
1479
1416
|
targets[0].element.style.filter = '';
|
|
1480
1417
|
targets[1].element.style.filter = '';
|
|
@@ -1536,7 +1473,7 @@
|
|
|
1536
1473
|
});
|
|
1537
1474
|
xnew$1.timeout(() => {
|
|
1538
1475
|
xnew$1(document.body).on('click wheel', action);
|
|
1539
|
-
xnew$1(
|
|
1476
|
+
xnew$1(DirectEvent).on('-keydown', action);
|
|
1540
1477
|
}, 100);
|
|
1541
1478
|
function action() {
|
|
1542
1479
|
if (state === 0) {
|
|
@@ -3417,7 +3354,7 @@
|
|
|
3417
3354
|
|
|
3418
3355
|
function VolumeController(unit, {} = {}) {
|
|
3419
3356
|
xnew$1.nest(`<div style="position: relative; width: 100%; height: 100%; display: flex; align-items: center; justify-content: flex-end; pointer-events: none; container-type: size;">`);
|
|
3420
|
-
xnew$1.extend(
|
|
3357
|
+
xnew$1.extend(DirectEvent);
|
|
3421
3358
|
unit.on('-pointerdown', ({ event }) => event.stopPropagation());
|
|
3422
3359
|
const slider = xnew$1(`<input type="range" min="0" max="100" value="${master.gain.value * 100}"
|
|
3423
3360
|
style="display: none; width: calc(96cqw - 100cqh); margin: 0 2cqw; cursor: pointer; pointer-events: auto;"
|
|
@@ -3442,10 +3379,8 @@
|
|
|
3442
3379
|
|
|
3443
3380
|
const basics = {
|
|
3444
3381
|
Screen,
|
|
3445
|
-
PointerEvent,
|
|
3446
3382
|
DirectEvent,
|
|
3447
3383
|
ResizeEvent,
|
|
3448
|
-
KeyboardEvent,
|
|
3449
3384
|
ModalFrame,
|
|
3450
3385
|
ModalContent,
|
|
3451
3386
|
AccordionFrame,
|
package/dist/xnew.mjs
CHANGED
|
@@ -203,7 +203,7 @@ class Timer {
|
|
|
203
203
|
//----------------------------------------------------------------------------------------------------
|
|
204
204
|
// utils
|
|
205
205
|
//----------------------------------------------------------------------------------------------------
|
|
206
|
-
const SYSTEM_EVENTS = ['start', 'update', 'stop', 'finalize'];
|
|
206
|
+
const SYSTEM_EVENTS = ['start', 'process', 'update', 'stop', 'finalize'];
|
|
207
207
|
//----------------------------------------------------------------------------------------------------
|
|
208
208
|
// unit
|
|
209
209
|
//----------------------------------------------------------------------------------------------------
|
|
@@ -296,7 +296,7 @@ class Unit {
|
|
|
296
296
|
components: [],
|
|
297
297
|
listeners: new MapMap(),
|
|
298
298
|
defines: {},
|
|
299
|
-
systems: { start: [], update: [], stop: [], finalize: [] },
|
|
299
|
+
systems: { start: [], process: [], update: [], stop: [], finalize: [] },
|
|
300
300
|
});
|
|
301
301
|
// nest html element
|
|
302
302
|
if (typeof unit._.target === 'string') {
|
|
@@ -406,11 +406,17 @@ class Unit {
|
|
|
406
406
|
}
|
|
407
407
|
}
|
|
408
408
|
static update(unit) {
|
|
409
|
-
if (unit._.state === 'started') {
|
|
409
|
+
if (unit._.state === 'started' || unit._.state === 'stopped') {
|
|
410
410
|
unit._.children.forEach((child) => Unit.update(child));
|
|
411
411
|
unit._.systems.update.forEach((listener) => Unit.scope(Unit.snapshot(unit), listener));
|
|
412
412
|
}
|
|
413
413
|
}
|
|
414
|
+
static process(unit) {
|
|
415
|
+
if (unit._.state === 'started') {
|
|
416
|
+
unit._.children.forEach((child) => Unit.process(child));
|
|
417
|
+
unit._.systems.process.forEach((listener) => Unit.scope(Unit.snapshot(unit), listener));
|
|
418
|
+
}
|
|
419
|
+
}
|
|
414
420
|
static reset() {
|
|
415
421
|
var _a, _b;
|
|
416
422
|
(_a = Unit.root) === null || _a === void 0 ? void 0 : _a.finalize();
|
|
@@ -418,6 +424,7 @@ class Unit {
|
|
|
418
424
|
(_b = Unit.ticker) === null || _b === void 0 ? void 0 : _b.clear();
|
|
419
425
|
Unit.ticker = new Ticker(() => {
|
|
420
426
|
Unit.start(Unit.root);
|
|
427
|
+
Unit.process(Unit.root);
|
|
421
428
|
Unit.update(Unit.root);
|
|
422
429
|
});
|
|
423
430
|
}
|
|
@@ -929,6 +936,8 @@ function ResizeEvent(resize) {
|
|
|
929
936
|
function DirectEvent(unit) {
|
|
930
937
|
const state = {};
|
|
931
938
|
const keydown = xnew$1.scope((event) => {
|
|
939
|
+
if (event.repeat)
|
|
940
|
+
return;
|
|
932
941
|
state[event.code] = 1;
|
|
933
942
|
xnew$1.emit('-keydown', { event, type: '-keydown', code: event.code });
|
|
934
943
|
if (['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(event.code)) {
|
|
@@ -996,78 +1005,6 @@ function DirectEvent(unit) {
|
|
|
996
1005
|
gesture.on('-gestureend', (...args) => xnew$1.emit('-gestureend', ...args));
|
|
997
1006
|
gesture.on('-gesturecancel', (...args) => xnew$1.emit('-gesturecancel', ...args));
|
|
998
1007
|
}
|
|
999
|
-
function KeyboardEvent(keyboard) {
|
|
1000
|
-
const state = {};
|
|
1001
|
-
const keydown = xnew$1.scope((event) => {
|
|
1002
|
-
state[event.code] = 1;
|
|
1003
|
-
xnew$1.emit('-keydown', { event, type: '-keydown', code: event.code });
|
|
1004
|
-
if (['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(event.code)) {
|
|
1005
|
-
xnew$1.emit('-keydown.arrow', { event, type: '-keydown.arrow', code: event.code, vector: getVector() });
|
|
1006
|
-
}
|
|
1007
|
-
});
|
|
1008
|
-
const keyup = xnew$1.scope((event) => {
|
|
1009
|
-
state[event.code] = 0;
|
|
1010
|
-
xnew$1.emit('-keyup', { event, type: '-keyup', code: event.code });
|
|
1011
|
-
if (['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(event.code)) {
|
|
1012
|
-
xnew$1.emit('-keyup.arrow', { event, type: '-keyup.arrow', code: event.code, vector: getVector() });
|
|
1013
|
-
}
|
|
1014
|
-
});
|
|
1015
|
-
window.addEventListener('keydown', keydown);
|
|
1016
|
-
window.addEventListener('keyup', keyup);
|
|
1017
|
-
keyboard.on('finalize', () => {
|
|
1018
|
-
window.removeEventListener('keydown', keydown);
|
|
1019
|
-
window.removeEventListener('keyup', keyup);
|
|
1020
|
-
});
|
|
1021
|
-
function getVector() {
|
|
1022
|
-
return {
|
|
1023
|
-
x: (state['ArrowLeft'] ? -1 : 0) + (state['ArrowRight'] ? +1 : 0),
|
|
1024
|
-
y: (state['ArrowUp'] ? -1 : 0) + (state['ArrowDown'] ? +1 : 0)
|
|
1025
|
-
};
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
function PointerEvent(unit) {
|
|
1029
|
-
const internal = xnew$1();
|
|
1030
|
-
internal.on('pointerdown', (event) => xnew$1.emit('-pointerdown', { event, position: getPosition(unit.element, event) }));
|
|
1031
|
-
internal.on('pointermove', (event) => xnew$1.emit('-pointermove', { event, position: getPosition(unit.element, event) }));
|
|
1032
|
-
internal.on('pointerup', (event) => xnew$1.emit('-pointerup', { event, position: getPosition(unit.element, event) }));
|
|
1033
|
-
internal.on('wheel', (event) => xnew$1.emit('-wheel', { event, delta: { x: event.wheelDeltaX, y: event.wheelDeltaY } }));
|
|
1034
|
-
internal.on('click', (event) => xnew$1.emit('-click', { event, position: getPosition(unit.element, event) }));
|
|
1035
|
-
internal.on('pointerover', (event) => xnew$1.emit('-pointerover', { event, position: getPosition(unit.element, event) }));
|
|
1036
|
-
internal.on('pointerout', (event) => xnew$1.emit('-pointerout', { event, position: getPosition(unit.element, event) }));
|
|
1037
|
-
const pointerdownoutside = xnew$1.scope((event) => {
|
|
1038
|
-
if (unit.element.contains(event.target) === false) {
|
|
1039
|
-
xnew$1.emit('-pointerdown.outside', { event, position: getPosition(unit.element, event) });
|
|
1040
|
-
}
|
|
1041
|
-
});
|
|
1042
|
-
const pointerupoutside = xnew$1.scope((event) => {
|
|
1043
|
-
if (unit.element.contains(event.target) === false) {
|
|
1044
|
-
xnew$1.emit('-pointerup.outside', { event, position: getPosition(unit.element, event) });
|
|
1045
|
-
}
|
|
1046
|
-
});
|
|
1047
|
-
const clickoutside = xnew$1.scope((event) => {
|
|
1048
|
-
if (unit.element.contains(event.target) === false) {
|
|
1049
|
-
xnew$1.emit('-click.outside', { event, position: getPosition(unit.element, event) });
|
|
1050
|
-
}
|
|
1051
|
-
});
|
|
1052
|
-
document.addEventListener('pointerdown', pointerdownoutside);
|
|
1053
|
-
document.addEventListener('pointerup', pointerupoutside);
|
|
1054
|
-
document.addEventListener('click', clickoutside);
|
|
1055
|
-
unit.on('finalize', () => {
|
|
1056
|
-
document.removeEventListener('pointerdown', pointerdownoutside);
|
|
1057
|
-
document.removeEventListener('pointerup', pointerupoutside);
|
|
1058
|
-
document.removeEventListener('click', clickoutside);
|
|
1059
|
-
});
|
|
1060
|
-
const drag = xnew$1(DragEvent);
|
|
1061
|
-
drag.on('-dragstart', (...args) => xnew$1.emit('-dragstart', ...args));
|
|
1062
|
-
drag.on('-dragmove', (...args) => xnew$1.emit('-dragmove', ...args));
|
|
1063
|
-
drag.on('-dragend', (...args) => xnew$1.emit('-dragend', ...args));
|
|
1064
|
-
drag.on('-dragcancel', (...args) => xnew$1.emit('-dragcancel', ...args));
|
|
1065
|
-
const gesture = xnew$1(GestureEvent);
|
|
1066
|
-
gesture.on('-gesturestart', (...args) => xnew$1.emit('-gesturestart', ...args));
|
|
1067
|
-
gesture.on('-gesturemove', (...args) => xnew$1.emit('-gesturemove', ...args));
|
|
1068
|
-
gesture.on('-gestureend', (...args) => xnew$1.emit('-gestureend', ...args));
|
|
1069
|
-
gesture.on('-gesturecancel', (...args) => xnew$1.emit('-gesturecancel', ...args));
|
|
1070
|
-
}
|
|
1071
1008
|
function DragEvent(unit) {
|
|
1072
1009
|
const pointerdown = xnew$1.scope((event) => {
|
|
1073
1010
|
const id = event.pointerId;
|
|
@@ -1326,11 +1263,11 @@ function DragFrame(frame, { x = 0, y = 0 } = {}) {
|
|
|
1326
1263
|
function DragTarget(target, {} = {}) {
|
|
1327
1264
|
const { frame, absolute } = xnew$1.context('xnew.dragframe');
|
|
1328
1265
|
xnew$1.nest('<div>');
|
|
1329
|
-
const
|
|
1266
|
+
const direct = xnew$1(absolute.parentElement, DirectEvent);
|
|
1330
1267
|
const current = { x: 0, y: 0 };
|
|
1331
1268
|
const offset = { x: 0, y: 0 };
|
|
1332
1269
|
let dragged = false;
|
|
1333
|
-
|
|
1270
|
+
direct.on('-dragstart', ({ event, position }) => {
|
|
1334
1271
|
if (target.element.contains(event.target) === false)
|
|
1335
1272
|
return;
|
|
1336
1273
|
dragged = true;
|
|
@@ -1339,7 +1276,7 @@ function DragTarget(target, {} = {}) {
|
|
|
1339
1276
|
current.x = position.x - offset.x;
|
|
1340
1277
|
current.y = position.y - offset.y;
|
|
1341
1278
|
});
|
|
1342
|
-
|
|
1279
|
+
direct.on('-dragmove', ({ event, delta }) => {
|
|
1343
1280
|
if (dragged !== true)
|
|
1344
1281
|
return;
|
|
1345
1282
|
current.x += delta.x;
|
|
@@ -1347,7 +1284,7 @@ function DragTarget(target, {} = {}) {
|
|
|
1347
1284
|
absolute.style.left = `${current.x}px`;
|
|
1348
1285
|
absolute.style.top = `${current.y}px`;
|
|
1349
1286
|
});
|
|
1350
|
-
|
|
1287
|
+
direct.on('-dragcancel -dragend', ({ event }) => {
|
|
1351
1288
|
dragged = false;
|
|
1352
1289
|
});
|
|
1353
1290
|
}
|
|
@@ -1384,22 +1321,22 @@ function AnalogStick(unit, { stroke = 'currentColor', strokeOpacity = 0.8, strok
|
|
|
1384
1321
|
xnew$1.extend(SVGTemplate, { fill, fillOpacity, stroke, strokeOpacity, strokeWidth, strokeLinejoin });
|
|
1385
1322
|
xnew$1('<circle cx="50" cy="50" r="23">');
|
|
1386
1323
|
});
|
|
1387
|
-
const
|
|
1388
|
-
|
|
1324
|
+
const direct = xnew$1(DirectEvent);
|
|
1325
|
+
direct.on('-dragstart', ({ event, position }) => {
|
|
1389
1326
|
const vector = getVector(position);
|
|
1390
1327
|
target.element.style.filter = 'brightness(90%)';
|
|
1391
1328
|
target.element.style.left = vector.x * newsize / 4 + 'px';
|
|
1392
1329
|
target.element.style.top = vector.y * newsize / 4 + 'px';
|
|
1393
1330
|
xnew$1.emit('-down', { vector });
|
|
1394
1331
|
});
|
|
1395
|
-
|
|
1332
|
+
direct.on('-dragmove', ({ event, position }) => {
|
|
1396
1333
|
const vector = getVector(position);
|
|
1397
1334
|
target.element.style.filter = 'brightness(90%)';
|
|
1398
1335
|
target.element.style.left = vector.x * newsize / 4 + 'px';
|
|
1399
1336
|
target.element.style.top = vector.y * newsize / 4 + 'px';
|
|
1400
1337
|
xnew$1.emit('-move', { vector });
|
|
1401
1338
|
});
|
|
1402
|
-
|
|
1339
|
+
direct.on('-dragend', ({ event }) => {
|
|
1403
1340
|
const vector = { x: 0, y: 0 };
|
|
1404
1341
|
target.element.style.filter = '';
|
|
1405
1342
|
target.element.style.left = vector.x * newsize / 4 + 'px';
|
|
@@ -1451,8 +1388,8 @@ function DirectionalPad(unit, { diagonal = true, stroke = 'currentColor', stroke
|
|
|
1451
1388
|
xnew$1('<polygon points="11 50 20 42 20 58">');
|
|
1452
1389
|
xnew$1('<polygon points="89 50 80 42 80 58">');
|
|
1453
1390
|
});
|
|
1454
|
-
const
|
|
1455
|
-
|
|
1391
|
+
const direct = xnew$1(DirectEvent);
|
|
1392
|
+
direct.on('-dragstart', ({ event, position }) => {
|
|
1456
1393
|
const vector = getVector(position);
|
|
1457
1394
|
targets[0].element.style.filter = (vector.y < 0) ? 'brightness(90%)' : '';
|
|
1458
1395
|
targets[1].element.style.filter = (vector.y > 0) ? 'brightness(90%)' : '';
|
|
@@ -1460,7 +1397,7 @@ function DirectionalPad(unit, { diagonal = true, stroke = 'currentColor', stroke
|
|
|
1460
1397
|
targets[3].element.style.filter = (vector.x > 0) ? 'brightness(90%)' : '';
|
|
1461
1398
|
xnew$1.emit('-down', { vector });
|
|
1462
1399
|
});
|
|
1463
|
-
|
|
1400
|
+
direct.on('-dragmove', ({ event, position }) => {
|
|
1464
1401
|
const vector = getVector(position);
|
|
1465
1402
|
targets[0].element.style.filter = (vector.y < 0) ? 'brightness(90%)' : '';
|
|
1466
1403
|
targets[1].element.style.filter = (vector.y > 0) ? 'brightness(90%)' : '';
|
|
@@ -1468,7 +1405,7 @@ function DirectionalPad(unit, { diagonal = true, stroke = 'currentColor', stroke
|
|
|
1468
1405
|
targets[3].element.style.filter = (vector.x > 0) ? 'brightness(90%)' : '';
|
|
1469
1406
|
xnew$1.emit('-move', { vector });
|
|
1470
1407
|
});
|
|
1471
|
-
|
|
1408
|
+
direct.on('-dragend', ({ event }) => {
|
|
1472
1409
|
const vector = { x: 0, y: 0 };
|
|
1473
1410
|
targets[0].element.style.filter = '';
|
|
1474
1411
|
targets[1].element.style.filter = '';
|
|
@@ -1530,7 +1467,7 @@ function TextStream(unit, { text = '', speed = 50, fade = 300 } = {}) {
|
|
|
1530
1467
|
});
|
|
1531
1468
|
xnew$1.timeout(() => {
|
|
1532
1469
|
xnew$1(document.body).on('click wheel', action);
|
|
1533
|
-
xnew$1(
|
|
1470
|
+
xnew$1(DirectEvent).on('-keydown', action);
|
|
1534
1471
|
}, 100);
|
|
1535
1472
|
function action() {
|
|
1536
1473
|
if (state === 0) {
|
|
@@ -3411,7 +3348,7 @@ const icons = {
|
|
|
3411
3348
|
|
|
3412
3349
|
function VolumeController(unit, {} = {}) {
|
|
3413
3350
|
xnew$1.nest(`<div style="position: relative; width: 100%; height: 100%; display: flex; align-items: center; justify-content: flex-end; pointer-events: none; container-type: size;">`);
|
|
3414
|
-
xnew$1.extend(
|
|
3351
|
+
xnew$1.extend(DirectEvent);
|
|
3415
3352
|
unit.on('-pointerdown', ({ event }) => event.stopPropagation());
|
|
3416
3353
|
const slider = xnew$1(`<input type="range" min="0" max="100" value="${master.gain.value * 100}"
|
|
3417
3354
|
style="display: none; width: calc(96cqw - 100cqh); margin: 0 2cqw; cursor: pointer; pointer-events: auto;"
|
|
@@ -3436,10 +3373,8 @@ function VolumeController(unit, {} = {}) {
|
|
|
3436
3373
|
|
|
3437
3374
|
const basics = {
|
|
3438
3375
|
Screen,
|
|
3439
|
-
PointerEvent,
|
|
3440
3376
|
DirectEvent,
|
|
3441
3377
|
ResizeEvent,
|
|
3442
|
-
KeyboardEvent,
|
|
3443
3378
|
ModalFrame,
|
|
3444
3379
|
ModalContent,
|
|
3445
3380
|
AccordionFrame,
|