@mulsense/xnew 0.5.1 → 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 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: UnitElement, type: string, listener: Function, options?: boolean | AddEventListenerOptions): void;
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, tag: string): UnitElement;
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, SVGElement, selector string, or HTML tag for new element
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: (typeof xnew$1) & {
393
- basics: typeof basics;
394
- audio: typeof audio;
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
- global: any;
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
- (_b = (_a = this.options).transition) === null || _b === void 0 ? void 0 : _b.call(_a, 0.0);
156
+ // this.options.transition?.(0.0);
158
157
  this.start();
159
158
  }
160
159
  clear() {
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
- (_b = (_a = this.options).transition) === null || _b === void 0 ? void 0 : _b.call(_a, 0.0);
150
+ // this.options.transition?.(0.0);
152
151
  this.start();
153
152
  }
154
153
  clear() {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "keywords": [
5
5
  "Component-Oriented Programming"
6
6
  ],
7
- "version": "0.5.1",
7
+ "version": "0.5.2",
8
8
  "main": "dist/xnew.js",
9
9
  "module": "dist/xnew.mjs",
10
10
  "types": "dist/xnew.d.ts",