@mulsense/xnew 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/xnew.d.ts +33 -155
- package/dist/xnew.js +17 -68
- package/dist/xnew.mjs +17 -68
- package/package.json +1 -1
package/dist/xnew.d.ts
CHANGED
|
@@ -20,11 +20,9 @@ declare class MapMap<Key1, Key2, Value> extends Map<Key1, Map<Key2, Value>> {
|
|
|
20
20
|
delete(key1: Key1, key2: Key2): boolean;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
type UnitElement = HTMLElement | SVGElement;
|
|
24
|
-
|
|
25
23
|
declare class EventManager {
|
|
26
24
|
private map;
|
|
27
|
-
add(element:
|
|
25
|
+
add(element: HTMLElement | SVGElement, type: string, listener: Function, options?: boolean | AddEventListenerOptions): void;
|
|
28
26
|
remove(type: string, listener: Function): void;
|
|
29
27
|
private basic;
|
|
30
28
|
private resize;
|
|
@@ -41,6 +39,7 @@ declare class EventManager {
|
|
|
41
39
|
private key_arrow;
|
|
42
40
|
}
|
|
43
41
|
|
|
42
|
+
type UnitElement = HTMLElement | SVGElement;
|
|
44
43
|
interface Context {
|
|
45
44
|
stack: Context | null;
|
|
46
45
|
key?: string;
|
|
@@ -96,7 +95,7 @@ declare class Unit {
|
|
|
96
95
|
reboot(): void;
|
|
97
96
|
static initialize(unit: Unit, anchor: UnitElement | null): void;
|
|
98
97
|
static finalize(unit: Unit): void;
|
|
99
|
-
static nest(unit: Unit,
|
|
98
|
+
static nest(unit: Unit, htmlString: string, textContent?: string): UnitElement;
|
|
100
99
|
static currentComponent: Function;
|
|
101
100
|
static extend(unit: Unit, component: Function, props?: Object): {
|
|
102
101
|
[key: string]: any;
|
|
@@ -142,142 +141,16 @@ interface CreateUnit {
|
|
|
142
141
|
(Component?: Function | string, props?: Object): Unit;
|
|
143
142
|
/**
|
|
144
143
|
* Creates a new Unit component
|
|
145
|
-
* @param target - HTMLElement
|
|
144
|
+
* @param target - HTMLElement | SVGElement, or HTML tag for new element
|
|
146
145
|
* @param Component - component function
|
|
147
146
|
* @param props - properties for component function
|
|
148
147
|
* @returns A new Unit instance
|
|
149
148
|
* @example
|
|
150
149
|
* const unit = xnew(element, MyComponent, { data: 0 })
|
|
151
|
-
* const unit = xnew('#selector', MyComponent, { data: 0 })
|
|
152
150
|
* const unit = xnew('<div>', MyComponent, { data: 0 })
|
|
153
151
|
*/
|
|
154
152
|
(target: HTMLElement | SVGElement | string, Component?: Function | string, props?: Object): Unit;
|
|
155
153
|
}
|
|
156
|
-
declare const xnew$1: CreateUnit & {
|
|
157
|
-
/**
|
|
158
|
-
* Creates a nested HTML/SVG element within the current component
|
|
159
|
-
* @param tag - HTML or SVG tag name (e.g., '<div>', '<span>', '<svg>')
|
|
160
|
-
* @returns The created HTML/SVG element
|
|
161
|
-
* @throws Error if called after component initialization
|
|
162
|
-
* @example
|
|
163
|
-
* const div = xnew.nest('<div>')
|
|
164
|
-
* div.textContent = 'Hello'
|
|
165
|
-
*/
|
|
166
|
-
nest(tag: string): HTMLElement | SVGElement;
|
|
167
|
-
/**
|
|
168
|
-
* Extends the current component with another component's functionality
|
|
169
|
-
* @param component - Component function to extend with
|
|
170
|
-
* @param props - Optional properties to pass to the extended component
|
|
171
|
-
* @returns The extended component's return value
|
|
172
|
-
* @throws Error if called after component initialization
|
|
173
|
-
* @example
|
|
174
|
-
* const api = xnew.extend(BaseComponent, { data: {} })
|
|
175
|
-
*/
|
|
176
|
-
extend(component: Function, props?: Object): {
|
|
177
|
-
[key: string]: any;
|
|
178
|
-
};
|
|
179
|
-
/**
|
|
180
|
-
* Gets or sets a context value that can be accessed by child components
|
|
181
|
-
* @param key - Context key
|
|
182
|
-
* @param value - Optional value to set (if undefined, gets the value)
|
|
183
|
-
* @returns The context value if getting, undefined if setting
|
|
184
|
-
* @example
|
|
185
|
-
* // Set context in parent
|
|
186
|
-
* xnew.context('theme', 'dark')
|
|
187
|
-
*
|
|
188
|
-
* // Get context in child
|
|
189
|
-
* const theme = xnew.context('theme')
|
|
190
|
-
*/
|
|
191
|
-
context(key: string, value?: any): any;
|
|
192
|
-
/**
|
|
193
|
-
* Registers a promise with the current component for lifecycle management
|
|
194
|
-
* @param promise - Promise to register
|
|
195
|
-
* @returns UnitPromise wrapper for chaining
|
|
196
|
-
* @example
|
|
197
|
-
* xnew.promise(fetchData()).then(data => console.log(data))
|
|
198
|
-
*/
|
|
199
|
-
promise(promise: Promise<any>): UnitPromise;
|
|
200
|
-
/**
|
|
201
|
-
* Handles successful resolution of all registered promises in the current component
|
|
202
|
-
* @param callback - Function to call when all promises resolve
|
|
203
|
-
* @returns UnitPromise for chaining
|
|
204
|
-
* @example
|
|
205
|
-
* xnew.then(results => console.log('All promises resolved', results))
|
|
206
|
-
*/
|
|
207
|
-
then(callback: Function): UnitPromise;
|
|
208
|
-
/**
|
|
209
|
-
* Handles rejection of any registered promise in the current component
|
|
210
|
-
* @param callback - Function to call if any promise rejects
|
|
211
|
-
* @returns UnitPromise for chaining
|
|
212
|
-
* @example
|
|
213
|
-
* xnew.catch(error => console.error('Promise failed', error))
|
|
214
|
-
*/
|
|
215
|
-
catch(callback: Function): UnitPromise;
|
|
216
|
-
/**
|
|
217
|
-
* Executes callback after all registered promises settle (resolve or reject)
|
|
218
|
-
* @param callback - Function to call after promises settle
|
|
219
|
-
* @returns UnitPromise for chaining
|
|
220
|
-
* @example
|
|
221
|
-
* xnew.finally(() => console.log('All promises settled'))
|
|
222
|
-
*/
|
|
223
|
-
finally(callback: Function): UnitPromise;
|
|
224
|
-
/**
|
|
225
|
-
* Creates a scoped callback that captures the current component context
|
|
226
|
-
* @param callback - Function to wrap with current scope
|
|
227
|
-
* @returns Function that executes callback in the captured scope
|
|
228
|
-
* @example
|
|
229
|
-
* setTimeout(xnew.scope(() => {
|
|
230
|
-
* console.log('This runs in the xnew component scope')
|
|
231
|
-
* }), 1000)
|
|
232
|
-
*/
|
|
233
|
-
scope(callback: any): any;
|
|
234
|
-
/**
|
|
235
|
-
* Finds all instances of a component in the component tree
|
|
236
|
-
* @param component - Component function to search for
|
|
237
|
-
* @returns Array of Unit instances matching the component
|
|
238
|
-
* @throws Error if component parameter is invalid
|
|
239
|
-
* @example
|
|
240
|
-
* const buttons = xnew.find(ButtonComponent)
|
|
241
|
-
* buttons.forEach(btn => btn.finalize())
|
|
242
|
-
*/
|
|
243
|
-
find(component: Function): Unit[];
|
|
244
|
-
emit(type: string, ...args: any[]): void;
|
|
245
|
-
/**
|
|
246
|
-
* Executes a callback once after a delay, managed by component lifecycle
|
|
247
|
-
* @param timeout - Function to execute after Duration
|
|
248
|
-
* @param duration - Duration in milliseconds
|
|
249
|
-
* @returns Object with clear() method to cancel the timeout
|
|
250
|
-
* @example
|
|
251
|
-
* const timer = xnew.timeout(() => console.log('Delayed'), 1000)
|
|
252
|
-
* // Cancel if needed: timer.clear()
|
|
253
|
-
*/
|
|
254
|
-
timeout(timeout: Function, duration?: number): any;
|
|
255
|
-
/**
|
|
256
|
-
* Executes a callback repeatedly at specified intervals, managed by component lifecycle
|
|
257
|
-
* @param timeout - Function to execute at each duration
|
|
258
|
-
* @param duration - Duration in milliseconds
|
|
259
|
-
* @returns Object with clear() method to stop the interval
|
|
260
|
-
* @example
|
|
261
|
-
* const timer = xnew.interval(() => console.log('Tick'), 1000)
|
|
262
|
-
* // Stop when needed: timer.clear()
|
|
263
|
-
*/
|
|
264
|
-
interval(timeout: Function, duration: number, iterations?: number): any;
|
|
265
|
-
/**
|
|
266
|
-
* Creates a transition animation with easing, executing callback with progress values
|
|
267
|
-
* @param callback - Function called with progress value (0.0 to 1.0)
|
|
268
|
-
* @param duration - Duration of transition in milliseconds
|
|
269
|
-
* @param easing - Easing function: 'linear', 'ease', 'ease-in', 'ease-out', 'ease-in-out' (default: 'linear')
|
|
270
|
-
* @returns Object with clear() and next() methods for controlling transitions
|
|
271
|
-
* @example
|
|
272
|
-
* xnew.transition(p => {
|
|
273
|
-
* element.style.opacity = p
|
|
274
|
-
* }, 500, 'ease-out').transition(p => {
|
|
275
|
-
* element.style.transform = `scale(${p})`
|
|
276
|
-
* }, 300)
|
|
277
|
-
*/
|
|
278
|
-
transition(transition: Function, duration?: number, easing?: string): any;
|
|
279
|
-
protect(...args: any[]): Unit;
|
|
280
|
-
};
|
|
281
154
|
|
|
282
155
|
declare function Accordion(unit: Unit, { open, duration, easing }?: {
|
|
283
156
|
open?: boolean;
|
|
@@ -326,12 +199,6 @@ declare function DirectionalPad(unit: Unit, { diagonal, stroke, strokeOpacity, s
|
|
|
326
199
|
fillOpacity?: number;
|
|
327
200
|
}): void;
|
|
328
201
|
|
|
329
|
-
declare function TextStream(unit: Unit, { text, speed, fade }?: {
|
|
330
|
-
text?: string;
|
|
331
|
-
speed?: number;
|
|
332
|
-
fade?: number;
|
|
333
|
-
}): void;
|
|
334
|
-
|
|
335
202
|
type SynthesizerOptions = {
|
|
336
203
|
oscillator: OscillatorOptions;
|
|
337
204
|
amp: AmpOptions;
|
|
@@ -372,28 +239,39 @@ declare class Synthesizer {
|
|
|
372
239
|
} | undefined;
|
|
373
240
|
}
|
|
374
241
|
|
|
375
|
-
declare const basics: {
|
|
376
|
-
Screen: typeof Screen;
|
|
377
|
-
Modal: typeof Modal;
|
|
378
|
-
Accordion: typeof Accordion;
|
|
379
|
-
TextStream: typeof TextStream;
|
|
380
|
-
AnalogStick: typeof AnalogStick;
|
|
381
|
-
DirectionalPad: typeof DirectionalPad;
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
declare const audio: {
|
|
385
|
-
load(path: string): UnitPromise;
|
|
386
|
-
synthesizer(props: SynthesizerOptions): Synthesizer;
|
|
387
|
-
volume: number;
|
|
388
|
-
};
|
|
389
242
|
declare namespace xnew {
|
|
390
243
|
type Unit = InstanceType<typeof Unit>;
|
|
391
244
|
}
|
|
392
|
-
declare const xnew:
|
|
393
|
-
|
|
394
|
-
|
|
245
|
+
declare const xnew: CreateUnit & {
|
|
246
|
+
nest(htmlString: string, textContent?: string): HTMLElement | SVGElement;
|
|
247
|
+
extend(component: Function, props?: Object): {
|
|
248
|
+
[key: string]: any;
|
|
249
|
+
};
|
|
250
|
+
context(key: string, value?: any): any;
|
|
251
|
+
promise(promise: Promise<any>): UnitPromise;
|
|
252
|
+
then(callback: Function): UnitPromise;
|
|
253
|
+
catch(callback: Function): UnitPromise;
|
|
254
|
+
finally(callback: Function): UnitPromise;
|
|
255
|
+
scope(callback: any): any;
|
|
256
|
+
find(component: Function): Unit[];
|
|
257
|
+
emit(type: string, ...args: any[]): void;
|
|
258
|
+
timeout(timeout: Function, duration?: number): any;
|
|
259
|
+
interval(timeout: Function, duration: number, iterations?: number): any;
|
|
260
|
+
transition(transition: Function, duration?: number, easing?: string): any;
|
|
261
|
+
protect(...args: any[]): Unit;
|
|
395
262
|
} & {
|
|
396
|
-
|
|
263
|
+
basics: {
|
|
264
|
+
Screen: typeof Screen;
|
|
265
|
+
Modal: typeof Modal;
|
|
266
|
+
Accordion: typeof Accordion;
|
|
267
|
+
AnalogStick: typeof AnalogStick;
|
|
268
|
+
DirectionalPad: typeof DirectionalPad;
|
|
269
|
+
};
|
|
270
|
+
audio: {
|
|
271
|
+
load(path: string): UnitPromise;
|
|
272
|
+
synthesizer(props: SynthesizerOptions): Synthesizer;
|
|
273
|
+
volume: number;
|
|
274
|
+
};
|
|
397
275
|
};
|
|
398
276
|
|
|
399
277
|
export { xnew as default };
|
package/dist/xnew.js
CHANGED
|
@@ -109,7 +109,6 @@
|
|
|
109
109
|
const self = this;
|
|
110
110
|
this.id = null;
|
|
111
111
|
let previous = 0;
|
|
112
|
-
ticker();
|
|
113
112
|
function ticker() {
|
|
114
113
|
const delta = Date.now() - previous;
|
|
115
114
|
if (delta > (1000 / fps) * 0.9) {
|
|
@@ -118,6 +117,7 @@
|
|
|
118
117
|
}
|
|
119
118
|
self.id = requestAnimationFrame(ticker);
|
|
120
119
|
}
|
|
120
|
+
self.id = requestAnimationFrame(ticker);
|
|
121
121
|
}
|
|
122
122
|
clear() {
|
|
123
123
|
if (this.id !== null) {
|
|
@@ -128,7 +128,6 @@
|
|
|
128
128
|
}
|
|
129
129
|
class Timer {
|
|
130
130
|
constructor(options) {
|
|
131
|
-
var _a, _b;
|
|
132
131
|
this.options = options;
|
|
133
132
|
this.id = null;
|
|
134
133
|
this.time = 0.0;
|
|
@@ -154,7 +153,7 @@
|
|
|
154
153
|
});
|
|
155
154
|
this.visibilitychange = () => document.hidden === false ? this._start() : this._stop();
|
|
156
155
|
document.addEventListener('visibilitychange', this.visibilitychange);
|
|
157
|
-
|
|
156
|
+
// this.options.transition?.(0.0);
|
|
158
157
|
this.start();
|
|
159
158
|
}
|
|
160
159
|
clear() {
|
|
@@ -206,8 +205,6 @@
|
|
|
206
205
|
}
|
|
207
206
|
}
|
|
208
207
|
|
|
209
|
-
const SYSTEM_EVENTS = ['start', 'update', 'render', 'stop', 'finalize'];
|
|
210
|
-
|
|
211
208
|
class EventManager {
|
|
212
209
|
constructor() {
|
|
213
210
|
this.map = new MapMap();
|
|
@@ -524,6 +521,10 @@
|
|
|
524
521
|
return { position };
|
|
525
522
|
}
|
|
526
523
|
|
|
524
|
+
//----------------------------------------------------------------------------------------------------
|
|
525
|
+
// utils
|
|
526
|
+
//----------------------------------------------------------------------------------------------------
|
|
527
|
+
const SYSTEM_EVENTS = ['start', 'update', 'render', 'stop', 'finalize'];
|
|
527
528
|
//----------------------------------------------------------------------------------------------------
|
|
528
529
|
// unit
|
|
529
530
|
//----------------------------------------------------------------------------------------------------
|
|
@@ -632,11 +633,11 @@
|
|
|
632
633
|
unit._.state = 'finalized';
|
|
633
634
|
}
|
|
634
635
|
}
|
|
635
|
-
static nest(unit,
|
|
636
|
+
static nest(unit, htmlString, textContent) {
|
|
636
637
|
if (unit._.state !== 'invoked') {
|
|
637
638
|
throw new Error('This function can not be called after initialized.');
|
|
638
639
|
}
|
|
639
|
-
const match =
|
|
640
|
+
const match = htmlString.match(/<((\w+)[^>]*?)\/?>/);
|
|
640
641
|
if (match !== null) {
|
|
641
642
|
let element;
|
|
642
643
|
if (unit._.anchor !== null) {
|
|
@@ -649,11 +650,14 @@
|
|
|
649
650
|
element = unit._.currentElement.children[unit._.currentElement.children.length - 1];
|
|
650
651
|
}
|
|
651
652
|
unit._.currentElement = element;
|
|
653
|
+
if (textContent !== undefined) {
|
|
654
|
+
element.textContent = textContent;
|
|
655
|
+
}
|
|
652
656
|
unit._.elements.push(element);
|
|
653
657
|
return element;
|
|
654
658
|
}
|
|
655
659
|
else {
|
|
656
|
-
throw new Error(`Invalid
|
|
660
|
+
throw new Error(`Invalid html string: ${htmlString}`);
|
|
657
661
|
}
|
|
658
662
|
}
|
|
659
663
|
static extend(unit, component, props) {
|
|
@@ -945,19 +949,19 @@
|
|
|
945
949
|
}, {
|
|
946
950
|
/**
|
|
947
951
|
* Creates a nested HTML/SVG element within the current component
|
|
948
|
-
* @param
|
|
952
|
+
* @param htmlString - HTML or SVG tag name (e.g., '<div>', '<span>', '<svg>')
|
|
949
953
|
* @returns The created HTML/SVG element
|
|
950
954
|
* @throws Error if called after component initialization
|
|
951
955
|
* @example
|
|
952
956
|
* const div = xnew.nest('<div>')
|
|
953
957
|
* div.textContent = 'Hello'
|
|
954
958
|
*/
|
|
955
|
-
nest(
|
|
959
|
+
nest(htmlString, textContent) {
|
|
956
960
|
try {
|
|
957
|
-
return Unit.nest(Unit.currentUnit,
|
|
961
|
+
return Unit.nest(Unit.currentUnit, htmlString, textContent);
|
|
958
962
|
}
|
|
959
963
|
catch (error) {
|
|
960
|
-
console.error('xnew.nest(
|
|
964
|
+
console.error('xnew.nest(htmlString: string): ', error);
|
|
961
965
|
throw error;
|
|
962
966
|
}
|
|
963
967
|
},
|
|
@@ -1370,51 +1374,6 @@
|
|
|
1370
1374
|
});
|
|
1371
1375
|
}
|
|
1372
1376
|
|
|
1373
|
-
function TextStream(unit, { text = '', speed = 50, fade = 300 } = {}) {
|
|
1374
|
-
const chars = [];
|
|
1375
|
-
for (let i = 0; i < text.length; i++) {
|
|
1376
|
-
const unit = xnew$1('<span>');
|
|
1377
|
-
unit.element.textContent = text[i];
|
|
1378
|
-
unit.element.style.opacity = '0';
|
|
1379
|
-
unit.element.style.transition = `opacity ${fade}ms ease-in-out`;
|
|
1380
|
-
chars.push(unit);
|
|
1381
|
-
}
|
|
1382
|
-
let start = 0;
|
|
1383
|
-
unit.on('start', () => {
|
|
1384
|
-
start = new Date().getTime();
|
|
1385
|
-
});
|
|
1386
|
-
let state = 0;
|
|
1387
|
-
unit.on('update', () => {
|
|
1388
|
-
const index = Math.floor((new Date().getTime() - start) / speed);
|
|
1389
|
-
// Display characters up to the current index (fade in)
|
|
1390
|
-
for (let i = 0; i < chars.length; i++) {
|
|
1391
|
-
if (i <= index) {
|
|
1392
|
-
chars[i].element.style.opacity = '1';
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
if (state === 0 && index >= text.length) {
|
|
1396
|
-
action();
|
|
1397
|
-
}
|
|
1398
|
-
});
|
|
1399
|
-
xnew$1.timeout(() => {
|
|
1400
|
-
xnew$1(document.body).on('click wheel', action);
|
|
1401
|
-
unit.on('keydown', action);
|
|
1402
|
-
}, 100);
|
|
1403
|
-
function action() {
|
|
1404
|
-
if (state === 0) {
|
|
1405
|
-
state = 1;
|
|
1406
|
-
for (let i = 0; i < chars.length; i++) {
|
|
1407
|
-
chars[i].element.style.opacity = '1';
|
|
1408
|
-
}
|
|
1409
|
-
xnew$1.emit('-complete');
|
|
1410
|
-
}
|
|
1411
|
-
else if (state === 1) {
|
|
1412
|
-
state = 2;
|
|
1413
|
-
xnew$1.emit('-next');
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
1416
|
-
}
|
|
1417
|
-
|
|
1418
1377
|
const context = new window.AudioContext();
|
|
1419
1378
|
const master = context.createGain();
|
|
1420
1379
|
//----------------------------------------------------------------------------------------------------
|
|
@@ -1643,7 +1602,6 @@
|
|
|
1643
1602
|
Screen,
|
|
1644
1603
|
Modal,
|
|
1645
1604
|
Accordion,
|
|
1646
|
-
TextStream,
|
|
1647
1605
|
AnalogStick,
|
|
1648
1606
|
DirectionalPad,
|
|
1649
1607
|
};
|
|
@@ -1674,16 +1632,7 @@
|
|
|
1674
1632
|
master.gain.value = value;
|
|
1675
1633
|
}
|
|
1676
1634
|
};
|
|
1677
|
-
const
|
|
1678
|
-
Object.defineProperty(temp, 'global', {
|
|
1679
|
-
get: function () {
|
|
1680
|
-
return temp.context('xnew.global');
|
|
1681
|
-
},
|
|
1682
|
-
set: function (value) {
|
|
1683
|
-
temp.context('xnew.global', value);
|
|
1684
|
-
}
|
|
1685
|
-
});
|
|
1686
|
-
const xnew = temp;
|
|
1635
|
+
const xnew = Object.assign(xnew$1, { basics, audio });
|
|
1687
1636
|
|
|
1688
1637
|
return xnew;
|
|
1689
1638
|
|
package/dist/xnew.mjs
CHANGED
|
@@ -103,7 +103,6 @@ class AnimationTicker {
|
|
|
103
103
|
const self = this;
|
|
104
104
|
this.id = null;
|
|
105
105
|
let previous = 0;
|
|
106
|
-
ticker();
|
|
107
106
|
function ticker() {
|
|
108
107
|
const delta = Date.now() - previous;
|
|
109
108
|
if (delta > (1000 / fps) * 0.9) {
|
|
@@ -112,6 +111,7 @@ class AnimationTicker {
|
|
|
112
111
|
}
|
|
113
112
|
self.id = requestAnimationFrame(ticker);
|
|
114
113
|
}
|
|
114
|
+
self.id = requestAnimationFrame(ticker);
|
|
115
115
|
}
|
|
116
116
|
clear() {
|
|
117
117
|
if (this.id !== null) {
|
|
@@ -122,7 +122,6 @@ class AnimationTicker {
|
|
|
122
122
|
}
|
|
123
123
|
class Timer {
|
|
124
124
|
constructor(options) {
|
|
125
|
-
var _a, _b;
|
|
126
125
|
this.options = options;
|
|
127
126
|
this.id = null;
|
|
128
127
|
this.time = 0.0;
|
|
@@ -148,7 +147,7 @@ class Timer {
|
|
|
148
147
|
});
|
|
149
148
|
this.visibilitychange = () => document.hidden === false ? this._start() : this._stop();
|
|
150
149
|
document.addEventListener('visibilitychange', this.visibilitychange);
|
|
151
|
-
|
|
150
|
+
// this.options.transition?.(0.0);
|
|
152
151
|
this.start();
|
|
153
152
|
}
|
|
154
153
|
clear() {
|
|
@@ -200,8 +199,6 @@ class Timer {
|
|
|
200
199
|
}
|
|
201
200
|
}
|
|
202
201
|
|
|
203
|
-
const SYSTEM_EVENTS = ['start', 'update', 'render', 'stop', 'finalize'];
|
|
204
|
-
|
|
205
202
|
class EventManager {
|
|
206
203
|
constructor() {
|
|
207
204
|
this.map = new MapMap();
|
|
@@ -518,6 +515,10 @@ function pointer(element, event) {
|
|
|
518
515
|
return { position };
|
|
519
516
|
}
|
|
520
517
|
|
|
518
|
+
//----------------------------------------------------------------------------------------------------
|
|
519
|
+
// utils
|
|
520
|
+
//----------------------------------------------------------------------------------------------------
|
|
521
|
+
const SYSTEM_EVENTS = ['start', 'update', 'render', 'stop', 'finalize'];
|
|
521
522
|
//----------------------------------------------------------------------------------------------------
|
|
522
523
|
// unit
|
|
523
524
|
//----------------------------------------------------------------------------------------------------
|
|
@@ -626,11 +627,11 @@ class Unit {
|
|
|
626
627
|
unit._.state = 'finalized';
|
|
627
628
|
}
|
|
628
629
|
}
|
|
629
|
-
static nest(unit,
|
|
630
|
+
static nest(unit, htmlString, textContent) {
|
|
630
631
|
if (unit._.state !== 'invoked') {
|
|
631
632
|
throw new Error('This function can not be called after initialized.');
|
|
632
633
|
}
|
|
633
|
-
const match =
|
|
634
|
+
const match = htmlString.match(/<((\w+)[^>]*?)\/?>/);
|
|
634
635
|
if (match !== null) {
|
|
635
636
|
let element;
|
|
636
637
|
if (unit._.anchor !== null) {
|
|
@@ -643,11 +644,14 @@ class Unit {
|
|
|
643
644
|
element = unit._.currentElement.children[unit._.currentElement.children.length - 1];
|
|
644
645
|
}
|
|
645
646
|
unit._.currentElement = element;
|
|
647
|
+
if (textContent !== undefined) {
|
|
648
|
+
element.textContent = textContent;
|
|
649
|
+
}
|
|
646
650
|
unit._.elements.push(element);
|
|
647
651
|
return element;
|
|
648
652
|
}
|
|
649
653
|
else {
|
|
650
|
-
throw new Error(`Invalid
|
|
654
|
+
throw new Error(`Invalid html string: ${htmlString}`);
|
|
651
655
|
}
|
|
652
656
|
}
|
|
653
657
|
static extend(unit, component, props) {
|
|
@@ -939,19 +943,19 @@ const xnew$1 = Object.assign(function (...args) {
|
|
|
939
943
|
}, {
|
|
940
944
|
/**
|
|
941
945
|
* Creates a nested HTML/SVG element within the current component
|
|
942
|
-
* @param
|
|
946
|
+
* @param htmlString - HTML or SVG tag name (e.g., '<div>', '<span>', '<svg>')
|
|
943
947
|
* @returns The created HTML/SVG element
|
|
944
948
|
* @throws Error if called after component initialization
|
|
945
949
|
* @example
|
|
946
950
|
* const div = xnew.nest('<div>')
|
|
947
951
|
* div.textContent = 'Hello'
|
|
948
952
|
*/
|
|
949
|
-
nest(
|
|
953
|
+
nest(htmlString, textContent) {
|
|
950
954
|
try {
|
|
951
|
-
return Unit.nest(Unit.currentUnit,
|
|
955
|
+
return Unit.nest(Unit.currentUnit, htmlString, textContent);
|
|
952
956
|
}
|
|
953
957
|
catch (error) {
|
|
954
|
-
console.error('xnew.nest(
|
|
958
|
+
console.error('xnew.nest(htmlString: string): ', error);
|
|
955
959
|
throw error;
|
|
956
960
|
}
|
|
957
961
|
},
|
|
@@ -1364,51 +1368,6 @@ function DirectionalPad(unit, { diagonal = true, stroke = 'currentColor', stroke
|
|
|
1364
1368
|
});
|
|
1365
1369
|
}
|
|
1366
1370
|
|
|
1367
|
-
function TextStream(unit, { text = '', speed = 50, fade = 300 } = {}) {
|
|
1368
|
-
const chars = [];
|
|
1369
|
-
for (let i = 0; i < text.length; i++) {
|
|
1370
|
-
const unit = xnew$1('<span>');
|
|
1371
|
-
unit.element.textContent = text[i];
|
|
1372
|
-
unit.element.style.opacity = '0';
|
|
1373
|
-
unit.element.style.transition = `opacity ${fade}ms ease-in-out`;
|
|
1374
|
-
chars.push(unit);
|
|
1375
|
-
}
|
|
1376
|
-
let start = 0;
|
|
1377
|
-
unit.on('start', () => {
|
|
1378
|
-
start = new Date().getTime();
|
|
1379
|
-
});
|
|
1380
|
-
let state = 0;
|
|
1381
|
-
unit.on('update', () => {
|
|
1382
|
-
const index = Math.floor((new Date().getTime() - start) / speed);
|
|
1383
|
-
// Display characters up to the current index (fade in)
|
|
1384
|
-
for (let i = 0; i < chars.length; i++) {
|
|
1385
|
-
if (i <= index) {
|
|
1386
|
-
chars[i].element.style.opacity = '1';
|
|
1387
|
-
}
|
|
1388
|
-
}
|
|
1389
|
-
if (state === 0 && index >= text.length) {
|
|
1390
|
-
action();
|
|
1391
|
-
}
|
|
1392
|
-
});
|
|
1393
|
-
xnew$1.timeout(() => {
|
|
1394
|
-
xnew$1(document.body).on('click wheel', action);
|
|
1395
|
-
unit.on('keydown', action);
|
|
1396
|
-
}, 100);
|
|
1397
|
-
function action() {
|
|
1398
|
-
if (state === 0) {
|
|
1399
|
-
state = 1;
|
|
1400
|
-
for (let i = 0; i < chars.length; i++) {
|
|
1401
|
-
chars[i].element.style.opacity = '1';
|
|
1402
|
-
}
|
|
1403
|
-
xnew$1.emit('-complete');
|
|
1404
|
-
}
|
|
1405
|
-
else if (state === 1) {
|
|
1406
|
-
state = 2;
|
|
1407
|
-
xnew$1.emit('-next');
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
|
|
1412
1371
|
const context = new window.AudioContext();
|
|
1413
1372
|
const master = context.createGain();
|
|
1414
1373
|
//----------------------------------------------------------------------------------------------------
|
|
@@ -1637,7 +1596,6 @@ const basics = {
|
|
|
1637
1596
|
Screen,
|
|
1638
1597
|
Modal,
|
|
1639
1598
|
Accordion,
|
|
1640
|
-
TextStream,
|
|
1641
1599
|
AnalogStick,
|
|
1642
1600
|
DirectionalPad,
|
|
1643
1601
|
};
|
|
@@ -1668,15 +1626,6 @@ const audio = {
|
|
|
1668
1626
|
master.gain.value = value;
|
|
1669
1627
|
}
|
|
1670
1628
|
};
|
|
1671
|
-
const
|
|
1672
|
-
Object.defineProperty(temp, 'global', {
|
|
1673
|
-
get: function () {
|
|
1674
|
-
return temp.context('xnew.global');
|
|
1675
|
-
},
|
|
1676
|
-
set: function (value) {
|
|
1677
|
-
temp.context('xnew.global', value);
|
|
1678
|
-
}
|
|
1679
|
-
});
|
|
1680
|
-
const xnew = temp;
|
|
1629
|
+
const xnew = Object.assign(xnew$1, { basics, audio });
|
|
1681
1630
|
|
|
1682
1631
|
export { xnew as default };
|