@mulsense/xnew 0.1.9 → 0.1.10
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/README.md +46 -46
- package/dist/types/audio/loader.d.ts +6 -2
- package/dist/types/basics/Event.d.ts +4 -3
- package/dist/types/basics/Touch.d.ts +9 -8
- package/dist/types/core/time.d.ts +6 -2
- package/dist/types/core/unit.d.ts +37 -7
- package/dist/types/core/xnew.d.ts +11 -11
- package/dist/types/index.d.ts +2 -4
- package/dist/xnew.d.ts +39 -41
- package/dist/xnew.js +296 -293
- package/dist/xnew.mjs +296 -293
- package/package.json +78 -78
- package/dist/addons/xmatter.d.ts +0 -6
- package/dist/addons/xmatter.js +0 -43
- package/dist/addons/xmatter.mjs +0 -38
- package/dist/addons/xpixi.d.ts +0 -10
- package/dist/addons/xpixi.js +0 -99
- package/dist/addons/xpixi.mjs +0 -75
- package/dist/addons/xrapier2d.d.ts +0 -6
- package/dist/addons/xrapier2d.js +0 -69
- package/dist/addons/xrapier2d.mjs +0 -64
- package/dist/addons/xthree.d.ts +0 -9
- package/dist/addons/xthree.js +0 -77
- package/dist/addons/xthree.mjs +0 -53
- package/dist/types/basics/Block.d.ts +0 -24
- package/dist/types/basics/Bullet.d.ts +0 -7
- package/dist/types/basics/ControlPanel.d.ts +0 -7
- package/dist/types/basics/Navigation.d.ts +0 -1
- package/dist/types/basics/Panel.d.ts +0 -6
- package/dist/types/basics/Popup.d.ts +0 -8
- package/dist/types/basics/TabView.d.ts +0 -18
- package/dist/types/basics/Tabs.d.ts +0 -8
- package/dist/types/basics/Transition.d.ts +0 -17
- package/dist/types/basics/WorkSpace.d.ts +0 -16
- package/dist/types/core/util.d.ts +0 -1
- package/dist/types/xnew.d.ts +0 -8
package/dist/xnew.js
CHANGED
|
@@ -4,102 +4,6 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.xnew = factory());
|
|
5
5
|
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
|
-
//----------------------------------------------------------------------------------------------------
|
|
8
|
-
// ticker
|
|
9
|
-
//----------------------------------------------------------------------------------------------------
|
|
10
|
-
class Ticker {
|
|
11
|
-
constructor(callback) {
|
|
12
|
-
const self = this;
|
|
13
|
-
this.id = null;
|
|
14
|
-
let previous = 0;
|
|
15
|
-
ticker();
|
|
16
|
-
function ticker() {
|
|
17
|
-
const time = Date.now();
|
|
18
|
-
const interval = 1000 / 60;
|
|
19
|
-
if (time - previous > interval * 0.9) {
|
|
20
|
-
callback(time);
|
|
21
|
-
previous = time;
|
|
22
|
-
}
|
|
23
|
-
self.id = requestAnimationFrame(ticker);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
clear() {
|
|
27
|
-
if (this.id !== null) {
|
|
28
|
-
cancelAnimationFrame(this.id);
|
|
29
|
-
this.id = null;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
//----------------------------------------------------------------------------------------------------
|
|
34
|
-
// timer
|
|
35
|
-
//----------------------------------------------------------------------------------------------------
|
|
36
|
-
class Timer {
|
|
37
|
-
constructor(timeout, transition, delay, loop = false) {
|
|
38
|
-
var _a;
|
|
39
|
-
this.timeout = timeout;
|
|
40
|
-
this.transition = transition;
|
|
41
|
-
this.delay = delay;
|
|
42
|
-
this.loop = loop;
|
|
43
|
-
this.id = null;
|
|
44
|
-
this.time = 0.0;
|
|
45
|
-
this.offset = 0.0;
|
|
46
|
-
this.status = 0;
|
|
47
|
-
this.ticker = new Ticker((time) => { var _a; return (_a = this.transition) === null || _a === void 0 ? void 0 : _a.call(this, this.elapsed() / this.delay); });
|
|
48
|
-
this.visibilitychange = () => document.hidden === false ? this._start() : this._stop();
|
|
49
|
-
document.addEventListener('visibilitychange', this.visibilitychange);
|
|
50
|
-
if (this.delay > 0.0) {
|
|
51
|
-
(_a = this.transition) === null || _a === void 0 ? void 0 : _a.call(this, 0.0);
|
|
52
|
-
}
|
|
53
|
-
this.start();
|
|
54
|
-
}
|
|
55
|
-
clear() {
|
|
56
|
-
if (this.id !== null) {
|
|
57
|
-
clearTimeout(this.id);
|
|
58
|
-
this.id = null;
|
|
59
|
-
}
|
|
60
|
-
document.removeEventListener('visibilitychange', this.visibilitychange);
|
|
61
|
-
this.ticker.clear();
|
|
62
|
-
}
|
|
63
|
-
elapsed() {
|
|
64
|
-
return this.offset + (this.id !== null ? (Date.now() - this.time) : 0);
|
|
65
|
-
}
|
|
66
|
-
start() {
|
|
67
|
-
this.status = 1;
|
|
68
|
-
this._start();
|
|
69
|
-
}
|
|
70
|
-
stop() {
|
|
71
|
-
this._stop();
|
|
72
|
-
this.status = 0;
|
|
73
|
-
}
|
|
74
|
-
_start() {
|
|
75
|
-
if (this.status === 1 && this.id === null) {
|
|
76
|
-
this.id = setTimeout(() => {
|
|
77
|
-
var _a;
|
|
78
|
-
this.timeout();
|
|
79
|
-
(_a = this.transition) === null || _a === void 0 ? void 0 : _a.call(this, 1.0);
|
|
80
|
-
this.id = null;
|
|
81
|
-
this.time = 0.0;
|
|
82
|
-
this.offset = 0.0;
|
|
83
|
-
if (this.loop) {
|
|
84
|
-
this.start();
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
this.clear();
|
|
88
|
-
}
|
|
89
|
-
}, this.delay - this.offset);
|
|
90
|
-
this.time = Date.now();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
_stop() {
|
|
94
|
-
if (this.status === 1 && this.id !== null) {
|
|
95
|
-
this.offset = this.offset + Date.now() - this.time;
|
|
96
|
-
clearTimeout(this.id);
|
|
97
|
-
this.id = null;
|
|
98
|
-
this.time = 0.0;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
7
|
//----------------------------------------------------------------------------------------------------
|
|
104
8
|
// map set
|
|
105
9
|
//----------------------------------------------------------------------------------------------------
|
|
@@ -198,24 +102,117 @@
|
|
|
198
102
|
}
|
|
199
103
|
|
|
200
104
|
//----------------------------------------------------------------------------------------------------
|
|
201
|
-
//
|
|
105
|
+
// ticker
|
|
202
106
|
//----------------------------------------------------------------------------------------------------
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
107
|
+
class Ticker {
|
|
108
|
+
constructor(callback) {
|
|
109
|
+
const self = this;
|
|
110
|
+
this.id = null;
|
|
111
|
+
let previous = 0;
|
|
112
|
+
ticker();
|
|
113
|
+
function ticker() {
|
|
114
|
+
const time = Date.now();
|
|
115
|
+
const interval = 1000 / 60;
|
|
116
|
+
if (time - previous > interval * 0.9) {
|
|
117
|
+
callback(time);
|
|
118
|
+
previous = time;
|
|
119
|
+
}
|
|
120
|
+
self.id = requestAnimationFrame(ticker);
|
|
121
|
+
}
|
|
209
122
|
}
|
|
210
|
-
|
|
211
|
-
this.
|
|
212
|
-
|
|
123
|
+
clear() {
|
|
124
|
+
if (this.id !== null) {
|
|
125
|
+
cancelAnimationFrame(this.id);
|
|
126
|
+
this.id = null;
|
|
127
|
+
}
|
|
213
128
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
129
|
+
}
|
|
130
|
+
//----------------------------------------------------------------------------------------------------
|
|
131
|
+
// timer
|
|
132
|
+
//----------------------------------------------------------------------------------------------------
|
|
133
|
+
class Timer {
|
|
134
|
+
constructor(transition, timeout, interval, { loop = false, easing = 'linear' } = {}) {
|
|
135
|
+
var _a;
|
|
136
|
+
this.transition = transition;
|
|
137
|
+
this.timeout = timeout;
|
|
138
|
+
this.interval = interval !== null && interval !== void 0 ? interval : 0;
|
|
139
|
+
this.loop = loop;
|
|
140
|
+
this.easing = easing;
|
|
141
|
+
this.id = null;
|
|
142
|
+
this.time = 0.0;
|
|
143
|
+
this.offset = 0.0;
|
|
144
|
+
this.status = 0;
|
|
145
|
+
this.ticker = new Ticker((time) => {
|
|
146
|
+
var _a;
|
|
147
|
+
let p = Math.min(this.elapsed() / this.interval, 1.0);
|
|
148
|
+
if (easing === 'ease-out') {
|
|
149
|
+
p = Math.pow((1.0 - Math.pow((1.0 - p), 2.0)), 0.5);
|
|
150
|
+
}
|
|
151
|
+
else if (easing === 'ease-in') {
|
|
152
|
+
p = Math.pow((1.0 - Math.pow((1.0 - p), 0.5)), 2.0);
|
|
153
|
+
}
|
|
154
|
+
else if (easing === 'ease') {
|
|
155
|
+
p = (1.0 - Math.cos(p * Math.PI)) / 2.0;
|
|
156
|
+
}
|
|
157
|
+
else if (easing === 'ease-in-out') {
|
|
158
|
+
p = (1.0 - Math.cos(p * Math.PI)) / 2.0;
|
|
159
|
+
}
|
|
160
|
+
(_a = this.transition) === null || _a === void 0 ? void 0 : _a.call(this, p);
|
|
161
|
+
});
|
|
162
|
+
this.visibilitychange = () => document.hidden === false ? this._start() : this._stop();
|
|
163
|
+
document.addEventListener('visibilitychange', this.visibilitychange);
|
|
164
|
+
if (this.interval > 0.0) {
|
|
165
|
+
(_a = this.transition) === null || _a === void 0 ? void 0 : _a.call(this, 0.0);
|
|
166
|
+
}
|
|
167
|
+
this.start();
|
|
168
|
+
}
|
|
169
|
+
clear() {
|
|
170
|
+
if (this.id !== null) {
|
|
171
|
+
clearTimeout(this.id);
|
|
172
|
+
this.id = null;
|
|
173
|
+
}
|
|
174
|
+
document.removeEventListener('visibilitychange', this.visibilitychange);
|
|
175
|
+
this.ticker.clear();
|
|
176
|
+
}
|
|
177
|
+
elapsed() {
|
|
178
|
+
return this.offset + (this.id !== null ? (Date.now() - this.time) : 0);
|
|
179
|
+
}
|
|
180
|
+
start() {
|
|
181
|
+
this.status = 1;
|
|
182
|
+
this._start();
|
|
183
|
+
}
|
|
184
|
+
stop() {
|
|
185
|
+
this._stop();
|
|
186
|
+
this.status = 0;
|
|
187
|
+
}
|
|
188
|
+
_start() {
|
|
189
|
+
if (this.status === 1 && this.id === null) {
|
|
190
|
+
this.id = setTimeout(() => {
|
|
191
|
+
var _a, _b;
|
|
192
|
+
(_a = this.timeout) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
193
|
+
(_b = this.transition) === null || _b === void 0 ? void 0 : _b.call(this, 1.0);
|
|
194
|
+
this.id = null;
|
|
195
|
+
this.time = 0.0;
|
|
196
|
+
this.offset = 0.0;
|
|
197
|
+
this.loop ? this.start() : this.clear();
|
|
198
|
+
}, this.interval - this.offset);
|
|
199
|
+
this.time = Date.now();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
_stop() {
|
|
203
|
+
if (this.status === 1 && this.id !== null) {
|
|
204
|
+
this.offset = this.offset + Date.now() - this.time;
|
|
205
|
+
clearTimeout(this.id);
|
|
206
|
+
this.id = null;
|
|
207
|
+
this.time = 0.0;
|
|
208
|
+
}
|
|
217
209
|
}
|
|
218
210
|
}
|
|
211
|
+
|
|
212
|
+
//----------------------------------------------------------------------------------------------------
|
|
213
|
+
// utils
|
|
214
|
+
//----------------------------------------------------------------------------------------------------
|
|
215
|
+
const SYSTEM_EVENTS = ['start', 'update', 'stop', 'finalize'];
|
|
219
216
|
//----------------------------------------------------------------------------------------------------
|
|
220
217
|
// unit
|
|
221
218
|
//----------------------------------------------------------------------------------------------------
|
|
@@ -555,6 +552,76 @@
|
|
|
555
552
|
// event
|
|
556
553
|
//----------------------------------------------------------------------------------------------------
|
|
557
554
|
Unit.type2units = new MapSet();
|
|
555
|
+
//----------------------------------------------------------------------------------------------------
|
|
556
|
+
// unit promise
|
|
557
|
+
//----------------------------------------------------------------------------------------------------
|
|
558
|
+
class UnitPromise {
|
|
559
|
+
constructor(promise) { this.promise = promise; }
|
|
560
|
+
then(callback) {
|
|
561
|
+
this.promise = this.promise.then(Unit.wrap(Unit.current, callback));
|
|
562
|
+
return this;
|
|
563
|
+
}
|
|
564
|
+
catch(callback) {
|
|
565
|
+
this.promise = this.promise.catch(Unit.wrap(Unit.current, callback));
|
|
566
|
+
return this;
|
|
567
|
+
}
|
|
568
|
+
finally(callback) {
|
|
569
|
+
this.promise = this.promise.finally(Unit.wrap(Unit.current, callback));
|
|
570
|
+
return this;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
//----------------------------------------------------------------------------------------------------
|
|
574
|
+
// unit timer
|
|
575
|
+
//----------------------------------------------------------------------------------------------------
|
|
576
|
+
class UnitTimer {
|
|
577
|
+
constructor({ transition, timeout, interval, easing, loop }) {
|
|
578
|
+
this.stack = [];
|
|
579
|
+
this.unit = new Unit(Unit.current, UnitTimer.Component, { snapshot: Unit.snapshot(Unit.current), transition, timeout, interval, easing, loop });
|
|
580
|
+
}
|
|
581
|
+
clear() {
|
|
582
|
+
this.unit.off();
|
|
583
|
+
this.unit.finalize();
|
|
584
|
+
}
|
|
585
|
+
timeout(timeout, interval = 0) {
|
|
586
|
+
UnitTimer.execute(this, { timeout, interval });
|
|
587
|
+
return this;
|
|
588
|
+
}
|
|
589
|
+
transition(transition, interval = 0, easing = 'linear') {
|
|
590
|
+
UnitTimer.execute(this, { transition, interval, easing });
|
|
591
|
+
return this;
|
|
592
|
+
}
|
|
593
|
+
static execute(timer, { transition, timeout, interval, easing, loop }) {
|
|
594
|
+
if (timer.unit._.state === 'finalized') {
|
|
595
|
+
timer.unit = new Unit(Unit.current, UnitTimer.Component, { snapshot: Unit.snapshot(Unit.current), transition, timeout, interval, easing, loop });
|
|
596
|
+
}
|
|
597
|
+
else if (timer.stack.length === 0) {
|
|
598
|
+
timer.stack.push({ snapshot: Unit.snapshot(Unit.current), transition, timeout, interval, easing, loop });
|
|
599
|
+
timer.unit.on('finalize', () => { UnitTimer.next(timer); });
|
|
600
|
+
}
|
|
601
|
+
else {
|
|
602
|
+
timer.stack.push({ snapshot: Unit.snapshot(Unit.current), transition, timeout, interval, easing, loop });
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
static next(timer) {
|
|
606
|
+
if (timer.stack.length > 0) {
|
|
607
|
+
timer.unit = new Unit(Unit.current, UnitTimer.Component, timer.stack.shift());
|
|
608
|
+
timer.unit.on('finalize', () => { UnitTimer.next(timer); });
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
static Component(unit, { snapshot, transition, timeout, interval, loop, easing }) {
|
|
612
|
+
const timer = new Timer((x) => {
|
|
613
|
+
if (transition !== undefined)
|
|
614
|
+
Unit.scope(snapshot, transition, x);
|
|
615
|
+
}, () => {
|
|
616
|
+
if (transition !== undefined)
|
|
617
|
+
Unit.scope(snapshot, transition, 1.0);
|
|
618
|
+
if (timeout !== undefined)
|
|
619
|
+
Unit.scope(snapshot, timeout);
|
|
620
|
+
unit.finalize();
|
|
621
|
+
}, interval, { loop, easing });
|
|
622
|
+
unit.on('finalize', () => timer.clear());
|
|
623
|
+
}
|
|
624
|
+
}
|
|
558
625
|
|
|
559
626
|
const xnew$1 = Object.assign(function (...args) {
|
|
560
627
|
if (Unit.root === undefined) {
|
|
@@ -735,42 +802,27 @@
|
|
|
735
802
|
},
|
|
736
803
|
/**
|
|
737
804
|
* Executes a callback once after a delay, managed by component lifecycle
|
|
738
|
-
* @param
|
|
739
|
-
* @param
|
|
805
|
+
* @param timeout - Function to execute after Interval
|
|
806
|
+
* @param interval - Interval duration in milliseconds
|
|
740
807
|
* @returns Object with clear() method to cancel the timeout
|
|
741
808
|
* @example
|
|
742
809
|
* const timer = xnew.timeout(() => console.log('Delayed'), 1000)
|
|
743
810
|
* // Cancel if needed: timer.clear()
|
|
744
811
|
*/
|
|
745
|
-
timeout(
|
|
746
|
-
|
|
747
|
-
const unit = xnew$1((self) => {
|
|
748
|
-
const timer = new Timer(() => {
|
|
749
|
-
Unit.scope(snapshot, callback);
|
|
750
|
-
self.finalize();
|
|
751
|
-
}, null, delay, false);
|
|
752
|
-
self.on('finalize', () => timer.clear());
|
|
753
|
-
});
|
|
754
|
-
return { clear: () => unit.finalize() };
|
|
812
|
+
timeout(timeout, interval = 0) {
|
|
813
|
+
return new UnitTimer({ timeout, interval });
|
|
755
814
|
},
|
|
756
815
|
/**
|
|
757
816
|
* Executes a callback repeatedly at specified intervals, managed by component lifecycle
|
|
758
|
-
* @param
|
|
759
|
-
* @param
|
|
817
|
+
* @param timeout - Function to execute at each interval
|
|
818
|
+
* @param interval - Interval duration in milliseconds
|
|
760
819
|
* @returns Object with clear() method to stop the interval
|
|
761
820
|
* @example
|
|
762
821
|
* const timer = xnew.interval(() => console.log('Tick'), 1000)
|
|
763
822
|
* // Stop when needed: timer.clear()
|
|
764
823
|
*/
|
|
765
|
-
interval(
|
|
766
|
-
|
|
767
|
-
const unit = xnew$1((self) => {
|
|
768
|
-
const timer = new Timer(() => {
|
|
769
|
-
Unit.scope(snapshot, callback);
|
|
770
|
-
}, null, delay, true);
|
|
771
|
-
self.on('finalize', () => timer.clear());
|
|
772
|
-
});
|
|
773
|
-
return { clear: () => unit.finalize() };
|
|
824
|
+
interval(timeout, interval) {
|
|
825
|
+
return new UnitTimer({ timeout, interval, loop: true });
|
|
774
826
|
},
|
|
775
827
|
/**
|
|
776
828
|
* Creates a transition animation with easing, executing callback with progress values
|
|
@@ -779,61 +831,14 @@
|
|
|
779
831
|
* @param easing - Easing function: 'linear', 'ease', 'ease-in', 'ease-out', 'ease-in-out' (default: 'linear')
|
|
780
832
|
* @returns Object with clear() and next() methods for controlling transitions
|
|
781
833
|
* @example
|
|
782
|
-
* xnew.transition(
|
|
783
|
-
* element.style.opacity =
|
|
784
|
-
* }, 500, 'ease-out').
|
|
785
|
-
* element.style.transform = `scale(${
|
|
834
|
+
* xnew.transition(p => {
|
|
835
|
+
* element.style.opacity = p
|
|
836
|
+
* }, 500, 'ease-out').transition(p => {
|
|
837
|
+
* element.style.transform = `scale(${p})`
|
|
786
838
|
* }, 300)
|
|
787
839
|
*/
|
|
788
|
-
transition(
|
|
789
|
-
|
|
790
|
-
let stacks = [];
|
|
791
|
-
let unit = xnew$1(Local, { callback, interval, easing });
|
|
792
|
-
let isRunning = true;
|
|
793
|
-
const timer = { clear, next };
|
|
794
|
-
return timer;
|
|
795
|
-
function execute() {
|
|
796
|
-
if (isRunning === false && stacks.length > 0) {
|
|
797
|
-
unit = xnew$1(Local, stacks.shift());
|
|
798
|
-
isRunning = true;
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
function clear() {
|
|
802
|
-
stacks = [];
|
|
803
|
-
unit.finalize();
|
|
804
|
-
}
|
|
805
|
-
function next(callback, interval = 0, easing = 'linear') {
|
|
806
|
-
stacks.push({ callback, interval, easing });
|
|
807
|
-
execute();
|
|
808
|
-
return timer;
|
|
809
|
-
}
|
|
810
|
-
function Local(self, { callback, interval, easing }) {
|
|
811
|
-
const timer = new Timer(() => {
|
|
812
|
-
Unit.scope(snapshot, callback, 1.0);
|
|
813
|
-
self.finalize();
|
|
814
|
-
}, (x) => {
|
|
815
|
-
if (x < 1.0) {
|
|
816
|
-
if (easing === 'ease-out') {
|
|
817
|
-
x = Math.pow((1.0 - Math.pow((1.0 - x), 2.0)), 0.5);
|
|
818
|
-
}
|
|
819
|
-
else if (easing === 'ease-in') {
|
|
820
|
-
x = Math.pow((1.0 - Math.pow((1.0 - x), 0.5)), 2.0);
|
|
821
|
-
}
|
|
822
|
-
else if (easing === 'ease') {
|
|
823
|
-
x = (1.0 - Math.cos(x * Math.PI)) / 2.0;
|
|
824
|
-
}
|
|
825
|
-
else if (easing === 'ease-in-out') {
|
|
826
|
-
x = (1.0 - Math.cos(x * Math.PI)) / 2.0;
|
|
827
|
-
}
|
|
828
|
-
Unit.scope(snapshot, callback, x);
|
|
829
|
-
}
|
|
830
|
-
}, interval);
|
|
831
|
-
self.on('finalize', () => {
|
|
832
|
-
timer.clear();
|
|
833
|
-
isRunning = false;
|
|
834
|
-
execute();
|
|
835
|
-
});
|
|
836
|
-
}
|
|
840
|
+
transition(transition, interval = 0, easing = 'linear') {
|
|
841
|
+
return new UnitTimer({ transition, interval, easing });
|
|
837
842
|
},
|
|
838
843
|
/**
|
|
839
844
|
* Creates an event listener manager for a target element with automatic cleanup
|
|
@@ -868,6 +873,84 @@
|
|
|
868
873
|
},
|
|
869
874
|
});
|
|
870
875
|
|
|
876
|
+
function AccordionFrame(frame, { open = false, duration = 200, easing = 'ease' } = {}) {
|
|
877
|
+
const internal = xnew$1((internal) => {
|
|
878
|
+
return { frame, open, rate: 0.0, };
|
|
879
|
+
});
|
|
880
|
+
xnew$1.context('xnew.accordionframe', internal);
|
|
881
|
+
internal.on('-transition', ({ rate }) => internal.rate = rate);
|
|
882
|
+
internal.emit('-transition', { rate: open ? 1.0 : 0.0 });
|
|
883
|
+
return {
|
|
884
|
+
toggle() {
|
|
885
|
+
if (internal.rate === 1.0) {
|
|
886
|
+
frame.close();
|
|
887
|
+
}
|
|
888
|
+
else if (internal.rate === 0.0) {
|
|
889
|
+
frame.open();
|
|
890
|
+
}
|
|
891
|
+
},
|
|
892
|
+
open() {
|
|
893
|
+
if (internal.rate === 0.0) {
|
|
894
|
+
xnew$1.transition((x) => internal.emit('-transition', { rate: x }), duration, easing);
|
|
895
|
+
}
|
|
896
|
+
},
|
|
897
|
+
close() {
|
|
898
|
+
if (internal.rate === 1.0) {
|
|
899
|
+
xnew$1.transition((x) => internal.emit('-transition', { rate: 1.0 - x }), duration, easing);
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
function AccordionHeader(header, {} = {}) {
|
|
905
|
+
const internal = xnew$1.context('xnew.accordionframe');
|
|
906
|
+
xnew$1.nest('<button style="display: flex; align-items: center; margin: 0; padding: 0; width: 100%; text-align: left; border: none; font: inherit; color: inherit; background: none; cursor: pointer;">');
|
|
907
|
+
header.on('click', () => internal.frame.toggle());
|
|
908
|
+
}
|
|
909
|
+
function AccordionBullet(bullet, { type = 'arrow' } = {}) {
|
|
910
|
+
const internal = xnew$1.context('xnew.accordionframe');
|
|
911
|
+
xnew$1.nest('<div style="display:inline-block; position: relative; width: 0.55em; margin: 0 0.3em;">');
|
|
912
|
+
if (type === 'arrow') {
|
|
913
|
+
const arrow = xnew$1(`<div style="width: 100%; height: 0.55em; border-right: 0.12em solid currentColor; border-bottom: 0.12em solid currentColor; box-sizing: border-box; transform-origin: center;">`);
|
|
914
|
+
arrow.element.style.transform = `rotate(${internal.rate * 90 - 45}deg)`;
|
|
915
|
+
internal.on('-transition', ({ rate }) => {
|
|
916
|
+
arrow.element.style.transform = `rotate(${rate * 90 - 45}deg)`;
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
else if (type === 'plusminus') {
|
|
920
|
+
const line1 = xnew$1(`<div style="position: absolute; width: 100%; border-top: 0.06em solid currentColor; border-bottom: 0.06em solid currentColor; box-sizing: border-box; transform-origin: center;">`);
|
|
921
|
+
const line2 = xnew$1(`<div style="position: absolute; width: 100%; border-top: 0.06em solid currentColor; border-bottom: 0.06em solid currentColor; box-sizing: border-box; transform-origin: center;">`);
|
|
922
|
+
line2.element.style.transform = `rotate(90deg)`;
|
|
923
|
+
line2.element.style.opacity = `${1.0 - internal.rate}`;
|
|
924
|
+
internal.on('-transition', ({ rate }) => {
|
|
925
|
+
line1.element.style.transform = `rotate(${90 + rate * 90}deg)`;
|
|
926
|
+
line2.element.style.transform = `rotate(${rate * 180}deg)`;
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
function AccordionContent(content, {} = {}) {
|
|
931
|
+
const internal = xnew$1.context('xnew.accordionframe');
|
|
932
|
+
xnew$1.nest(`<div style="display: ${internal.open ? 'block' : 'none'};">`);
|
|
933
|
+
xnew$1.nest('<div style="padding: 0; display: flex; flex-direction: column; box-sizing: border-box;">');
|
|
934
|
+
internal.on('-transition', ({ rate }) => {
|
|
935
|
+
content.transition({ element: content.element, rate });
|
|
936
|
+
});
|
|
937
|
+
return {
|
|
938
|
+
transition({ element, rate }) {
|
|
939
|
+
const wrapper = element.parentElement;
|
|
940
|
+
wrapper.style.display = 'block';
|
|
941
|
+
if (rate === 0.0) {
|
|
942
|
+
wrapper.style.display = 'none';
|
|
943
|
+
}
|
|
944
|
+
else if (rate < 1.0) {
|
|
945
|
+
Object.assign(wrapper.style, { height: element.offsetHeight * rate + 'px', overflow: 'hidden', opacity: rate });
|
|
946
|
+
}
|
|
947
|
+
else {
|
|
948
|
+
Object.assign(wrapper.style, { height: 'auto', overflow: 'visible', opacity: 1.0 });
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
|
|
871
954
|
function ResizeEvent(resize) {
|
|
872
955
|
const observer = new ResizeObserver((entries) => {
|
|
873
956
|
for (const entry of entries) {
|
|
@@ -884,7 +967,29 @@
|
|
|
884
967
|
}
|
|
885
968
|
});
|
|
886
969
|
}
|
|
887
|
-
|
|
970
|
+
function KeyboardEvent(unit) {
|
|
971
|
+
const state = {};
|
|
972
|
+
xnew$1.listener(window).on('keydown', (event) => {
|
|
973
|
+
state[event.code] = 1;
|
|
974
|
+
unit.emit('-keydown', { event, type: '-keydown', code: event.code });
|
|
975
|
+
});
|
|
976
|
+
xnew$1.listener(window).on('keyup', (event) => {
|
|
977
|
+
state[event.code] = 0;
|
|
978
|
+
unit.emit('-keyup', { event, type: '-keyup', code: event.code });
|
|
979
|
+
});
|
|
980
|
+
xnew$1.listener(window).on('keydown', (event) => {
|
|
981
|
+
unit.emit('-arrowkeydown', { event, type: '-arrowkeydown', code: event.code, vector: getVector() });
|
|
982
|
+
});
|
|
983
|
+
xnew$1.listener(window).on('keyup', (event) => {
|
|
984
|
+
unit.emit('-arrowkeyup', { event, type: '-arrowkeyup', code: event.code, vector: getVector() });
|
|
985
|
+
});
|
|
986
|
+
function getVector() {
|
|
987
|
+
return {
|
|
988
|
+
x: (state['ArrowLeft'] ? -1 : 0) + (state['ArrowRight'] ? +1 : 0),
|
|
989
|
+
y: (state['ArrowUp'] ? -1 : 0) + (state['ArrowDown'] ? +1 : 0)
|
|
990
|
+
};
|
|
991
|
+
}
|
|
992
|
+
}
|
|
888
993
|
function PointerEvent(unit) {
|
|
889
994
|
const internal = xnew$1();
|
|
890
995
|
internal.on('pointerdown', (event) => unit.emit('-pointerdown', { event, position: getPosition(unit.element, event) }));
|
|
@@ -1001,30 +1106,6 @@
|
|
|
1001
1106
|
return { x: event.clientX - rect.left, y: event.clientY - rect.top };
|
|
1002
1107
|
}
|
|
1003
1108
|
|
|
1004
|
-
function KeyboardEvent(unit) {
|
|
1005
|
-
const state = {};
|
|
1006
|
-
xnew$1.listener(window).on('keydown', (event) => {
|
|
1007
|
-
state[event.code] = 1;
|
|
1008
|
-
unit.emit('-keydown', { event, type: '-keydown', code: event.code });
|
|
1009
|
-
});
|
|
1010
|
-
xnew$1.listener(window).on('keyup', (event) => {
|
|
1011
|
-
state[event.code] = 0;
|
|
1012
|
-
unit.emit('-keyup', { event, type: '-keyup', code: event.code });
|
|
1013
|
-
});
|
|
1014
|
-
xnew$1.listener(window).on('keydown', (event) => {
|
|
1015
|
-
unit.emit('-arrowkeydown', { event, type: '-arrowkeydown', code: event.code, vector: getVector() });
|
|
1016
|
-
});
|
|
1017
|
-
xnew$1.listener(window).on('keyup', (event) => {
|
|
1018
|
-
unit.emit('-arrowkeyup', { event, type: '-arrowkeyup', code: event.code, vector: getVector() });
|
|
1019
|
-
});
|
|
1020
|
-
function getVector() {
|
|
1021
|
-
return {
|
|
1022
|
-
x: (state['ArrowLeft'] ? -1 : 0) + (state['ArrowRight'] ? +1 : 0),
|
|
1023
|
-
y: (state['ArrowUp'] ? -1 : 0) + (state['ArrowDown'] ? +1 : 0)
|
|
1024
|
-
};
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
|
|
1028
1109
|
function Screen(screen, { width = 640, height = 480, fit = 'contain' } = {}) {
|
|
1029
1110
|
const size = { width, height };
|
|
1030
1111
|
const wrapper = xnew$1.nest('<div style="position: relative; width: 100%; height: 100%; overflow: hidden;">');
|
|
@@ -1181,84 +1262,6 @@
|
|
|
1181
1262
|
};
|
|
1182
1263
|
}
|
|
1183
1264
|
|
|
1184
|
-
function AccordionFrame(frame, { open = false, duration = 200, easing = 'ease' } = {}) {
|
|
1185
|
-
const internal = xnew$1((internal) => {
|
|
1186
|
-
return { frame, open, rate: 0.0, };
|
|
1187
|
-
});
|
|
1188
|
-
xnew$1.context('xnew.accordionframe', internal);
|
|
1189
|
-
internal.on('-transition', ({ rate }) => internal.rate = rate);
|
|
1190
|
-
internal.emit('-transition', { rate: open ? 1.0 : 0.0 });
|
|
1191
|
-
return {
|
|
1192
|
-
toggle() {
|
|
1193
|
-
if (internal.rate === 1.0) {
|
|
1194
|
-
frame.close();
|
|
1195
|
-
}
|
|
1196
|
-
else if (internal.rate === 0.0) {
|
|
1197
|
-
frame.open();
|
|
1198
|
-
}
|
|
1199
|
-
},
|
|
1200
|
-
open() {
|
|
1201
|
-
if (internal.rate === 0.0) {
|
|
1202
|
-
xnew$1.transition((x) => internal.emit('-transition', { rate: x }), duration, easing);
|
|
1203
|
-
}
|
|
1204
|
-
},
|
|
1205
|
-
close() {
|
|
1206
|
-
if (internal.rate === 1.0) {
|
|
1207
|
-
xnew$1.transition((x) => internal.emit('-transition', { rate: 1.0 - x }), duration, easing);
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
};
|
|
1211
|
-
}
|
|
1212
|
-
function AccordionHeader(header, {} = {}) {
|
|
1213
|
-
const internal = xnew$1.context('xnew.accordionframe');
|
|
1214
|
-
xnew$1.nest('<button style="display: flex; align-items: center; margin: 0; padding: 0; width: 100%; text-align: left; border: none; font: inherit; color: inherit; background: none; cursor: pointer;">');
|
|
1215
|
-
header.on('click', () => internal.frame.toggle());
|
|
1216
|
-
}
|
|
1217
|
-
function AccordionBullet(bullet, { type = 'arrow' } = {}) {
|
|
1218
|
-
const internal = xnew$1.context('xnew.accordionframe');
|
|
1219
|
-
xnew$1.nest('<div style="display:inline-block; position: relative; width: 0.55em; margin: 0 0.3em;">');
|
|
1220
|
-
if (type === 'arrow') {
|
|
1221
|
-
const arrow = xnew$1(`<div style="width: 100%; height: 0.55em; border-right: 0.12em solid currentColor; border-bottom: 0.12em solid currentColor; box-sizing: border-box; transform-origin: center;">`);
|
|
1222
|
-
arrow.element.style.transform = `rotate(${internal.rate * 90 - 45}deg)`;
|
|
1223
|
-
internal.on('-transition', ({ rate }) => {
|
|
1224
|
-
arrow.element.style.transform = `rotate(${rate * 90 - 45}deg)`;
|
|
1225
|
-
});
|
|
1226
|
-
}
|
|
1227
|
-
else if (type === 'plusminus') {
|
|
1228
|
-
const line1 = xnew$1(`<div style="position: absolute; width: 100%; border-top: 0.06em solid currentColor; border-bottom: 0.06em solid currentColor; box-sizing: border-box; transform-origin: center;">`);
|
|
1229
|
-
const line2 = xnew$1(`<div style="position: absolute; width: 100%; border-top: 0.06em solid currentColor; border-bottom: 0.06em solid currentColor; box-sizing: border-box; transform-origin: center;">`);
|
|
1230
|
-
line2.element.style.transform = `rotate(90deg)`;
|
|
1231
|
-
line2.element.style.opacity = `${1.0 - internal.rate}`;
|
|
1232
|
-
internal.on('-transition', ({ rate }) => {
|
|
1233
|
-
line1.element.style.transform = `rotate(${90 + rate * 90}deg)`;
|
|
1234
|
-
line2.element.style.transform = `rotate(${rate * 180}deg)`;
|
|
1235
|
-
});
|
|
1236
|
-
}
|
|
1237
|
-
}
|
|
1238
|
-
function AccordionContent(content, {} = {}) {
|
|
1239
|
-
const internal = xnew$1.context('xnew.accordionframe');
|
|
1240
|
-
xnew$1.nest(`<div style="display: ${internal.open ? 'block' : 'none'};">`);
|
|
1241
|
-
xnew$1.nest('<div style="padding: 0; display: flex; flex-direction: column; box-sizing: border-box;">');
|
|
1242
|
-
internal.on('-transition', ({ rate }) => {
|
|
1243
|
-
content.transition({ element: content.element, rate });
|
|
1244
|
-
});
|
|
1245
|
-
return {
|
|
1246
|
-
transition({ element, rate }) {
|
|
1247
|
-
const wrapper = element.parentElement;
|
|
1248
|
-
wrapper.style.display = 'block';
|
|
1249
|
-
if (rate === 0.0) {
|
|
1250
|
-
wrapper.style.display = 'none';
|
|
1251
|
-
}
|
|
1252
|
-
else if (rate < 1.0) {
|
|
1253
|
-
Object.assign(wrapper.style, { height: element.offsetHeight * rate + 'px', overflow: 'hidden', opacity: rate });
|
|
1254
|
-
}
|
|
1255
|
-
else {
|
|
1256
|
-
Object.assign(wrapper.style, { height: 'auto', overflow: 'visible', opacity: 1.0 });
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
|
-
};
|
|
1260
|
-
}
|
|
1261
|
-
|
|
1262
1265
|
function DragFrame(frame, { x = 0, y = 0 } = {}) {
|
|
1263
1266
|
const absolute = xnew$1.nest(`<div style="position: absolute; top: ${y}px; left: ${x}px;">`);
|
|
1264
1267
|
xnew$1.context('xnew.dragframe', { frame, absolute });
|
|
@@ -1296,11 +1299,11 @@
|
|
|
1296
1299
|
// controller
|
|
1297
1300
|
//----------------------------------------------------------------------------------------------------
|
|
1298
1301
|
function SVGTemplate(self, { fill = null, fillOpacity = 0.8, stroke = null, strokeOpacity = 0.8, strokeWidth = 2, strokeLinejoin = 'round' }) {
|
|
1299
|
-
xnew$1.nest(`<svg
|
|
1300
|
-
viewBox="0 0 100 100"
|
|
1301
|
-
style="position: absolute; width: 100%; height: 100%; pointer-select: none;
|
|
1302
|
-
${fill ? `fill: ${fill}; fill-opacity: ${fillOpacity};` : ''}
|
|
1303
|
-
${stroke ? `stroke: ${stroke}; stroke-opacity: ${strokeOpacity}; stroke-width: ${strokeWidth}; stroke-linejoin: ${strokeLinejoin};` : ''}
|
|
1302
|
+
xnew$1.nest(`<svg
|
|
1303
|
+
viewBox="0 0 100 100"
|
|
1304
|
+
style="position: absolute; width: 100%; height: 100%; pointer-select: none;
|
|
1305
|
+
${fill ? `fill: ${fill}; fill-opacity: ${fillOpacity};` : ''}
|
|
1306
|
+
${stroke ? `stroke: ${stroke}; stroke-opacity: ${strokeOpacity}; stroke-width: ${strokeWidth}; stroke-linejoin: ${strokeLinejoin};` : ''}
|
|
1304
1307
|
">`);
|
|
1305
1308
|
}
|
|
1306
1309
|
function AnalogStick(self, { size, fill = '#FFF', fillOpacity = 0.8, stroke = '#000', strokeOpacity = 0.8, strokeWidth = 2, strokeLinejoin = 'round' } = {}) {
|