@mulsense/xnew 0.5.1 → 0.5.3
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 +55 -183
- package/dist/xnew.js +208 -196
- package/dist/xnew.mjs +208 -196
- 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
|
-
|
|
24
|
-
|
|
25
|
-
declare class EventManager {
|
|
23
|
+
declare class Eventor {
|
|
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,15 @@ declare class EventManager {
|
|
|
41
39
|
private key_arrow;
|
|
42
40
|
}
|
|
43
41
|
|
|
42
|
+
type UnitElement = HTMLElement | SVGElement;
|
|
43
|
+
declare class UnitPromise {
|
|
44
|
+
promise: Promise<any>;
|
|
45
|
+
component: Function | null;
|
|
46
|
+
constructor(promise: Promise<any>, component: Function | null);
|
|
47
|
+
then(callback: Function): UnitPromise;
|
|
48
|
+
catch(callback: Function): UnitPromise;
|
|
49
|
+
finally(callback: Function): UnitPromise;
|
|
50
|
+
}
|
|
44
51
|
interface Context {
|
|
45
52
|
stack: Context | null;
|
|
46
53
|
key?: string;
|
|
@@ -56,9 +63,6 @@ interface Internal {
|
|
|
56
63
|
parent: Unit | null;
|
|
57
64
|
target: Object | null;
|
|
58
65
|
props?: Object;
|
|
59
|
-
config: {
|
|
60
|
-
protect: boolean;
|
|
61
|
-
};
|
|
62
66
|
baseElement: UnitElement;
|
|
63
67
|
baseContext: Context;
|
|
64
68
|
baseComponent: Function;
|
|
@@ -68,6 +72,7 @@ interface Internal {
|
|
|
68
72
|
anchor: UnitElement | null;
|
|
69
73
|
state: string;
|
|
70
74
|
tostart: boolean;
|
|
75
|
+
protected: boolean;
|
|
71
76
|
ancestors: Unit[];
|
|
72
77
|
children: Unit[];
|
|
73
78
|
promises: UnitPromise[];
|
|
@@ -83,12 +88,12 @@ interface Internal {
|
|
|
83
88
|
listener: Function;
|
|
84
89
|
execute: Function;
|
|
85
90
|
}[]>;
|
|
86
|
-
|
|
91
|
+
eventor: Eventor;
|
|
87
92
|
}
|
|
88
93
|
declare class Unit {
|
|
89
94
|
[key: string]: any;
|
|
90
95
|
_: Internal;
|
|
91
|
-
constructor(parent: Unit | null, target: UnitElement | string | null, component?: Function | string, props?: Object
|
|
96
|
+
constructor(parent: Unit | null, target: UnitElement | string | null, component?: Function | string | number, props?: Object);
|
|
92
97
|
get element(): UnitElement;
|
|
93
98
|
start(): void;
|
|
94
99
|
stop(): void;
|
|
@@ -96,7 +101,7 @@ declare class Unit {
|
|
|
96
101
|
reboot(): void;
|
|
97
102
|
static initialize(unit: Unit, anchor: UnitElement | null): void;
|
|
98
103
|
static finalize(unit: Unit): void;
|
|
99
|
-
static nest(unit: Unit, tag: string): UnitElement;
|
|
104
|
+
static nest(unit: Unit, tag: string, textContent?: string | number): UnitElement;
|
|
100
105
|
static currentComponent: Function;
|
|
101
106
|
static extend(unit: Unit, component: Function, props?: Object): {
|
|
102
107
|
[key: string]: any;
|
|
@@ -108,7 +113,6 @@ declare class Unit {
|
|
|
108
113
|
static rootUnit: Unit;
|
|
109
114
|
static currentUnit: Unit;
|
|
110
115
|
static reset(): void;
|
|
111
|
-
static wrap(unit: Unit, listener: Function): (...args: any[]) => any;
|
|
112
116
|
static scope(snapshot: Snapshot, func: Function, ...args: any[]): any;
|
|
113
117
|
static snapshot(unit: Unit): Snapshot;
|
|
114
118
|
static context(unit: Unit, key: string, value?: any): any;
|
|
@@ -121,14 +125,6 @@ declare class Unit {
|
|
|
121
125
|
static off(unit: Unit, type: string, listener?: Function): void;
|
|
122
126
|
static emit(type: string, ...args: any[]): void;
|
|
123
127
|
}
|
|
124
|
-
declare class UnitPromise {
|
|
125
|
-
promise: Promise<any>;
|
|
126
|
-
component: Function | null;
|
|
127
|
-
constructor(promise: Promise<any>, component: Function | null);
|
|
128
|
-
then(callback: Function): UnitPromise;
|
|
129
|
-
catch(callback: Function): UnitPromise;
|
|
130
|
-
finally(callback: Function): UnitPromise;
|
|
131
|
-
}
|
|
132
128
|
|
|
133
129
|
interface CreateUnit {
|
|
134
130
|
/**
|
|
@@ -142,171 +138,42 @@ interface CreateUnit {
|
|
|
142
138
|
(Component?: Function | string, props?: Object): Unit;
|
|
143
139
|
/**
|
|
144
140
|
* Creates a new Unit component
|
|
145
|
-
* @param target - HTMLElement
|
|
141
|
+
* @param target - HTMLElement | SVGElement, or HTML tag for new element
|
|
146
142
|
* @param Component - component function
|
|
147
143
|
* @param props - properties for component function
|
|
148
144
|
* @returns A new Unit instance
|
|
149
145
|
* @example
|
|
150
146
|
* const unit = xnew(element, MyComponent, { data: 0 })
|
|
151
|
-
* const unit = xnew('#selector', MyComponent, { data: 0 })
|
|
152
147
|
* const unit = xnew('<div>', MyComponent, { data: 0 })
|
|
153
148
|
*/
|
|
154
149
|
(target: HTMLElement | SVGElement | string, Component?: Function | string, props?: Object): Unit;
|
|
155
150
|
}
|
|
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
151
|
|
|
282
152
|
declare function Accordion(unit: Unit, { open, duration, easing }?: {
|
|
283
153
|
open?: boolean;
|
|
284
154
|
duration?: number;
|
|
285
155
|
easing?: string;
|
|
286
156
|
}): {
|
|
287
|
-
state: number;
|
|
288
157
|
toggle(): void;
|
|
289
158
|
open(): void;
|
|
290
159
|
close(): void;
|
|
291
160
|
};
|
|
292
|
-
|
|
293
|
-
declare function Screen(unit: Unit, { width, height, fit }?: {
|
|
294
|
-
width?: number | undefined;
|
|
295
|
-
height?: number | undefined;
|
|
296
|
-
fit?: string | undefined;
|
|
297
|
-
}): {
|
|
298
|
-
readonly canvas: UnitElement;
|
|
299
|
-
resize(width: number, height: number): void;
|
|
300
|
-
};
|
|
301
|
-
|
|
302
161
|
declare function Modal(unit: Unit, { duration, easing }?: {
|
|
303
162
|
duration?: number;
|
|
304
163
|
easing?: string;
|
|
305
164
|
}): {
|
|
306
|
-
state: number;
|
|
307
165
|
close(): void;
|
|
308
166
|
};
|
|
309
167
|
|
|
168
|
+
type ScreenFit = 'contain' | 'cover' | 'fill' | 'resize';
|
|
169
|
+
declare function Screen(unit: Unit, { width, height, fit }?: {
|
|
170
|
+
width?: number;
|
|
171
|
+
height?: number;
|
|
172
|
+
fit?: ScreenFit;
|
|
173
|
+
}): {
|
|
174
|
+
readonly canvas: UnitElement;
|
|
175
|
+
};
|
|
176
|
+
|
|
310
177
|
declare function AnalogStick(unit: Unit, { stroke, strokeOpacity, strokeWidth, strokeLinejoin, fill, fillOpacity }?: {
|
|
311
178
|
stroke?: string;
|
|
312
179
|
strokeOpacity?: number;
|
|
@@ -316,7 +183,7 @@ declare function AnalogStick(unit: Unit, { stroke, strokeOpacity, strokeWidth, s
|
|
|
316
183
|
fill?: string;
|
|
317
184
|
fillOpacity?: number;
|
|
318
185
|
}): void;
|
|
319
|
-
declare function
|
|
186
|
+
declare function DPad(unit: Unit, { diagonal, stroke, strokeOpacity, strokeWidth, strokeLinejoin, fill, fillOpacity }?: {
|
|
320
187
|
diagonal?: boolean;
|
|
321
188
|
stroke?: string;
|
|
322
189
|
strokeOpacity?: number;
|
|
@@ -326,12 +193,6 @@ declare function DirectionalPad(unit: Unit, { diagonal, stroke, strokeOpacity, s
|
|
|
326
193
|
fillOpacity?: number;
|
|
327
194
|
}): void;
|
|
328
195
|
|
|
329
|
-
declare function TextStream(unit: Unit, { text, speed, fade }?: {
|
|
330
|
-
text?: string;
|
|
331
|
-
speed?: number;
|
|
332
|
-
fade?: number;
|
|
333
|
-
}): void;
|
|
334
|
-
|
|
335
196
|
type SynthesizerOptions = {
|
|
336
197
|
oscillator: OscillatorOptions;
|
|
337
198
|
amp: AmpOptions;
|
|
@@ -372,28 +233,39 @@ declare class Synthesizer {
|
|
|
372
233
|
} | undefined;
|
|
373
234
|
}
|
|
374
235
|
|
|
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
236
|
declare namespace xnew {
|
|
390
237
|
type Unit = InstanceType<typeof Unit>;
|
|
391
238
|
}
|
|
392
|
-
declare const xnew:
|
|
393
|
-
|
|
394
|
-
|
|
239
|
+
declare const xnew: CreateUnit & {
|
|
240
|
+
nest(tag: string, textContent?: string | number): HTMLElement | SVGElement;
|
|
241
|
+
extend(component: Function, props?: Object): {
|
|
242
|
+
[key: string]: any;
|
|
243
|
+
};
|
|
244
|
+
context(key: string, value?: any): any;
|
|
245
|
+
promise(promise: Promise<any>): UnitPromise;
|
|
246
|
+
then(callback: Function): UnitPromise;
|
|
247
|
+
catch(callback: Function): UnitPromise;
|
|
248
|
+
finally(callback: Function): UnitPromise;
|
|
249
|
+
scope(callback: any): any;
|
|
250
|
+
find(component: Function): Unit[];
|
|
251
|
+
emit(type: string, ...args: any[]): void;
|
|
252
|
+
timeout(timeout: Function, duration?: number): any;
|
|
253
|
+
interval(timeout: Function, duration: number, iterations?: number): any;
|
|
254
|
+
transition(transition: Function, duration?: number, easing?: string): any;
|
|
255
|
+
protect(): void;
|
|
395
256
|
} & {
|
|
396
|
-
|
|
257
|
+
basics: {
|
|
258
|
+
Screen: typeof Screen;
|
|
259
|
+
Modal: typeof Modal;
|
|
260
|
+
Accordion: typeof Accordion;
|
|
261
|
+
AnalogStick: typeof AnalogStick;
|
|
262
|
+
DPad: typeof DPad;
|
|
263
|
+
};
|
|
264
|
+
audio: {
|
|
265
|
+
load(path: string): UnitPromise;
|
|
266
|
+
synthesizer(props: SynthesizerOptions): Synthesizer;
|
|
267
|
+
volume: number;
|
|
268
|
+
};
|
|
397
269
|
};
|
|
398
270
|
|
|
399
271
|
export { xnew as default };
|