@mulsense/xnew 0.1.6 → 0.1.8

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.
@@ -1,10 +1,7 @@
1
1
  export declare class Ticker {
2
- static animation: number | null;
3
- static callbacks: Set<Function>;
4
- static previous: number;
5
- static ticker(): void;
6
- static set(callback: (time: number) => void): void;
7
- static clear(callback: (time: number) => void): void;
2
+ private id;
3
+ constructor(callback: Function);
4
+ clear(): void;
8
5
  }
9
6
  export declare class Timer {
10
7
  private timeout;
@@ -15,7 +12,7 @@ export declare class Timer {
15
12
  private time;
16
13
  private offset;
17
14
  private status;
18
- private visibilitychange?;
15
+ private visibilitychange;
19
16
  private ticker;
20
17
  constructor(timeout: Function, transition: Function | null, delay: number, loop?: boolean);
21
18
  clear(): void;
@@ -1,4 +1,5 @@
1
1
  import { MapSet, MapMap } from './map';
2
+ import { Ticker } from './time';
2
3
  export type UnitElement = HTMLElement | SVGElement;
3
4
  interface Context {
4
5
  stack: Context | null;
@@ -10,17 +11,6 @@ interface Snapshot {
10
11
  context: Context;
11
12
  element: UnitElement;
12
13
  }
13
- interface Capture {
14
- checker: (unit: Unit) => boolean;
15
- execute: (unit: Unit) => any;
16
- }
17
- export declare class UnitPromise {
18
- private promise;
19
- constructor(promise: Promise<any>);
20
- then(callback: Function): UnitPromise;
21
- catch(callback: Function): UnitPromise;
22
- finally(callback: Function): UnitPromise;
23
- }
24
14
  interface UnitInternal {
25
15
  parent: Unit | null;
26
16
  target: Object | null;
@@ -35,7 +25,7 @@ interface UnitInternal {
35
25
  tostart: boolean;
36
26
  children: Unit[];
37
27
  promises: Promise<any>[];
38
- captures: Capture[];
28
+ captures: ((unit: Unit) => boolean | void)[];
39
29
  elements: UnitElement[];
40
30
  components: Function[];
41
31
  listeners1: MapMap<string, Function, [UnitElement, Function]>;
@@ -43,10 +33,16 @@ interface UnitInternal {
43
33
  defines: Record<string, any>;
44
34
  systems: Record<string, Function[]>;
45
35
  }
36
+ export declare class UnitPromise {
37
+ private promise;
38
+ constructor(promise: Promise<any>);
39
+ then(callback: Function): UnitPromise;
40
+ catch(callback: Function): UnitPromise;
41
+ finally(callback: Function): UnitPromise;
42
+ }
46
43
  export declare class Unit {
47
44
  [key: string]: any;
48
45
  _: UnitInternal;
49
- static current: Unit;
50
46
  constructor(parent: Unit | null, target: Object | null, component?: Function | string, props?: Object);
51
47
  get element(): UnitElement;
52
48
  get components(): Function[];
@@ -57,18 +53,20 @@ export declare class Unit {
57
53
  static initialize(unit: Unit, anchor: UnitElement | null): void;
58
54
  static finalize(unit: Unit): void;
59
55
  static nest(unit: Unit, tag: string): UnitElement;
60
- static extend(unit: Unit, component: Function, props?: Object): void;
61
- static start(unit: Unit, time: number): void;
56
+ static extend(unit: Unit, component: Function, props?: Object): {
57
+ [key: string]: any;
58
+ };
59
+ static start(unit: Unit): void;
62
60
  static stop(unit: Unit): void;
63
- static update(unit: Unit, time: number): void;
64
- static root: Unit | null;
65
- static ticker(time: number): void;
61
+ static update(unit: Unit): void;
62
+ static root: Unit;
63
+ static current: Unit;
64
+ static ticker: Ticker;
66
65
  static reset(): void;
67
66
  static wrap(unit: Unit, listener: Function): (...args: any[]) => any;
68
67
  static scope(snapshot: Snapshot, func: Function, ...args: any[]): any;
69
68
  static snapshot(unit: Unit): Snapshot;
70
- static stack(unit: Unit, key: string, value: any): void;
71
- static trace(unit: Unit, key: string): any;
69
+ static context(unit: Unit, key: string, value?: any): any;
72
70
  static componentUnits: MapSet<Function, Unit>;
73
71
  static find(component: Function): Unit[];
74
72
  static typeUnits: MapSet<string, Unit>;
@@ -1,5 +1,190 @@
1
- import { Unit } from './unit';
2
- export declare namespace xnew {
3
- type Unit = InstanceType<typeof Unit>;
1
+ import { Unit, UnitPromise } from './unit';
2
+ interface CreateUnit {
3
+ /**
4
+ * Creates a new Unit component
5
+ * @param Component - component function
6
+ * @param props - properties for component function
7
+ * @returns A new Unit instance
8
+ * @example
9
+ * const unit = xnew(MyComponent, { data: 0 })
10
+ */
11
+ (Component?: Function | string, props?: Object): Unit;
12
+ /**
13
+ * Creates a new Unit component
14
+ * @param target - HTMLElement, SVGElement, selector string, or HTML tag for new element
15
+ * @param Component - component function
16
+ * @param props - properties for component function
17
+ * @returns A new Unit instance
18
+ * @example
19
+ * const unit = xnew(element, MyComponent, { data: 0 })
20
+ * const unit = xnew('#selector', MyComponent, { data: 0 })
21
+ * const unit = xnew('<div>', MyComponent, { data: 0 })
22
+ */
23
+ (target: HTMLElement | SVGElement, Component?: Function | string, props?: Object): Unit;
4
24
  }
5
- export declare const xnew: any;
25
+ export declare const xnew: CreateUnit & {
26
+ /**
27
+ * Creates a nested HTML/SVG element within the current component
28
+ * @param tag - HTML or SVG tag name (e.g., '<div>', '<span>', '<svg>')
29
+ * @returns The created HTML/SVG element
30
+ * @throws Error if called after component initialization
31
+ * @example
32
+ * const div = xnew.nest('<div>')
33
+ * div.textContent = 'Hello'
34
+ */
35
+ nest(tag: string): HTMLElement | SVGElement;
36
+ /**
37
+ * Extends the current component with another component's functionality
38
+ * @param component - Component function to extend with
39
+ * @param props - Optional properties to pass to the extended component
40
+ * @returns The extended component's return value
41
+ * @throws Error if called after component initialization
42
+ * @example
43
+ * const api = xnew.extend(BaseComponent, { data: {} })
44
+ */
45
+ extend(component: Function, props?: Object): {
46
+ [key: string]: any;
47
+ };
48
+ /**
49
+ * Gets or sets a context value that can be accessed by child components
50
+ * @param key - Context key
51
+ * @param value - Optional value to set (if undefined, gets the value)
52
+ * @returns The context value if getting, undefined if setting
53
+ * @example
54
+ * // Set context in parent
55
+ * xnew.context('theme', 'dark')
56
+ *
57
+ * // Get context in child
58
+ * const theme = xnew.context('theme')
59
+ */
60
+ context(key: string, value?: any): any;
61
+ /**
62
+ * Registers a promise with the current component for lifecycle management
63
+ * @param promise - Promise to register
64
+ * @returns UnitPromise wrapper for chaining
65
+ * @example
66
+ * xnew.promise(fetchData()).then(data => console.log(data))
67
+ */
68
+ promise(promise: Promise<any>): UnitPromise;
69
+ /**
70
+ * Handles successful resolution of all registered promises in the current component
71
+ * @param callback - Function to call when all promises resolve
72
+ * @returns UnitPromise for chaining
73
+ * @example
74
+ * xnew.then(results => console.log('All promises resolved', results))
75
+ */
76
+ then(callback: Function): UnitPromise;
77
+ /**
78
+ * Handles rejection of any registered promise in the current component
79
+ * @param callback - Function to call if any promise rejects
80
+ * @returns UnitPromise for chaining
81
+ * @example
82
+ * xnew.catch(error => console.error('Promise failed', error))
83
+ */
84
+ catch(callback: Function): UnitPromise;
85
+ /**
86
+ * Executes callback after all registered promises settle (resolve or reject)
87
+ * @param callback - Function to call after promises settle
88
+ * @returns UnitPromise for chaining
89
+ * @example
90
+ * xnew.finally(() => console.log('All promises settled'))
91
+ */
92
+ finally(callback: Function): UnitPromise;
93
+ /**
94
+ * Fetches a resource and registers the promise with the current component
95
+ * @param url - URL to fetch
96
+ * @param options - Optional fetch options (method, headers, body, etc.)
97
+ * @returns UnitPromise wrapping the fetch promise
98
+ * @example
99
+ * xnew.fetch('/api/users').then(res => res.json()).then(data => console.log(data))
100
+ */
101
+ fetch(url: string, options?: object): UnitPromise;
102
+ /**
103
+ * Creates a scoped callback that captures the current component context
104
+ * @param callback - Function to wrap with current scope
105
+ * @returns Function that executes callback in the captured scope
106
+ * @example
107
+ * setTimeout(xnew.scope(() => {
108
+ * console.log('This runs in the xnew component scope')
109
+ * }), 1000)
110
+ */
111
+ scope(callback: any): any;
112
+ /**
113
+ * Finds all instances of a component in the component tree
114
+ * @param component - Component function to search for
115
+ * @returns Array of Unit instances matching the component
116
+ * @throws Error if component parameter is invalid
117
+ * @example
118
+ * const buttons = xnew.find(ButtonComponent)
119
+ * buttons.forEach(btn => btn.finalize())
120
+ */
121
+ find(component: Function): Unit[];
122
+ /**
123
+ * Appends new components to existing component(s) in the tree
124
+ * @param anchor - Component function or Unit instance to append to
125
+ * @param args - Arguments to pass to xnew for creating child components
126
+ * @throws Error if anchor parameter is invalid
127
+ * @example
128
+ * xnew.append(MyContainer, ChildComponent, { prop: 'value' })
129
+ * xnew.append(unitInstance, AnotherComponent)
130
+ */
131
+ append(anchor: Unit, ...args: any[]): void;
132
+ /**
133
+ * Executes a callback once after a delay, managed by component lifecycle
134
+ * @param callback - Function to execute after delay
135
+ * @param delay - Delay in milliseconds
136
+ * @returns Object with clear() method to cancel the timeout
137
+ * @example
138
+ * const timer = xnew.timeout(() => console.log('Delayed'), 1000)
139
+ * // Cancel if needed: timer.clear()
140
+ */
141
+ timeout(callback: Function, delay: number): any;
142
+ /**
143
+ * Executes a callback repeatedly at specified intervals, managed by component lifecycle
144
+ * @param callback - Function to execute at each interval
145
+ * @param delay - Interval duration in milliseconds
146
+ * @returns Object with clear() method to stop the interval
147
+ * @example
148
+ * const timer = xnew.interval(() => console.log('Tick'), 1000)
149
+ * // Stop when needed: timer.clear()
150
+ */
151
+ interval(callback: Function, delay: number): any;
152
+ /**
153
+ * Creates a transition animation with easing, executing callback with progress values
154
+ * @param callback - Function called with progress value (0.0 to 1.0)
155
+ * @param interval - Duration of transition in milliseconds
156
+ * @param easing - Easing function: 'linear', 'ease', 'ease-in', 'ease-out', 'ease-in-out' (default: 'linear')
157
+ * @returns Object with clear() and next() methods for controlling transitions
158
+ * @example
159
+ * xnew.transition(progress => {
160
+ * element.style.opacity = progress
161
+ * }, 500, 'ease-out').next(progress => {
162
+ * element.style.transform = `scale(${progress})`
163
+ * }, 300)
164
+ */
165
+ transition(callback: Function, interval: number, easing?: string): any;
166
+ /**
167
+ * Creates an event listener manager for a target element with automatic cleanup
168
+ * @param target - Element, Window, or Document to attach listeners to
169
+ * @returns Object with on() and off() methods for managing event listeners
170
+ * @example
171
+ * const mouse = xnew.listener(window)
172
+ * mouse.on('mousemove', (e) => console.log(e.clientX, e.clientY))
173
+ * // Automatically cleaned up when component finalizes
174
+ */
175
+ listener(target: HTMLElement | SVGElement | Window | Document): {
176
+ on(type: string, listener: Function, options?: boolean | AddEventListenerOptions): void;
177
+ off(type?: string, listener?: Function): void;
178
+ };
179
+ /**
180
+ * Registers a capture function that can intercept and handle child component events
181
+ * @param execute - Function that receives child unit and returns boolean (true to stop propagation)
182
+ * @example
183
+ * xnew.capture((childUnit) => {
184
+ * console.log('Child component created:', childUnit)
185
+ * return false // Continue propagation
186
+ * })
187
+ */
188
+ capture(execute: (unit: Unit) => boolean | void): void;
189
+ };
190
+ export {};
@@ -1,18 +1,22 @@
1
+ import { xnew as base } from './core/xnew';
2
+ import { Unit } from './core/unit';
1
3
  import { ResizeEvent } from './basics/ResizeEvent';
2
- import { UserEvent } from './basics/UserEvent';
4
+ import { PointerEvent } from './basics/PointerEvent';
5
+ import { KeyboardEvent } from './basics/KeyboardEvent';
3
6
  import { Screen } from './basics/Screen';
4
7
  import { InputFrame } from './basics/Input';
5
8
  import { ModalFrame, ModalContent } from './basics/Modal';
6
9
  import { TabFrame, TabButton, TabContent } from './basics/Tab';
7
10
  import { AccordionFrame, AccordionHeader, AccordionBullet, AccordionContent } from './basics/Accordion';
8
- import { DragFrame, DragTarget } from './basics/SubWIndow';
9
- import { TouchStick, TouchDPad, TouchButton } from './basics/Touch';
10
- import { Unit } from './core/unit';
11
+ import { DragFrame, DragTarget } from './basics/Drag';
12
+ import { AnalogStick, DirectionalPad } from './basics/Controller';
13
+ import { load } from './audio/file';
11
14
  import { synthesizer } from './audio/synthesizer';
12
15
  declare const basics: {
13
16
  Screen: typeof Screen;
14
- UserEvent: typeof UserEvent;
17
+ PointerEvent: typeof PointerEvent;
15
18
  ResizeEvent: typeof ResizeEvent;
19
+ KeyboardEvent: typeof KeyboardEvent;
16
20
  ModalFrame: typeof ModalFrame;
17
21
  ModalContent: typeof ModalContent;
18
22
  AccordionFrame: typeof AccordionFrame;
@@ -25,21 +29,20 @@ declare const basics: {
25
29
  InputFrame: typeof InputFrame;
26
30
  DragFrame: typeof DragFrame;
27
31
  DragTarget: typeof DragTarget;
28
- TouchStick: typeof TouchStick;
29
- TouchDPad: typeof TouchDPad;
30
- TouchButton: typeof TouchButton;
32
+ AnalogStick: typeof AnalogStick;
33
+ DirectionalPad: typeof DirectionalPad;
31
34
  };
32
35
  declare const audio: {
36
+ master: GainNode;
37
+ context: AudioContext;
33
38
  synthesizer: typeof synthesizer;
39
+ load: typeof load;
34
40
  };
35
- export interface xnew_interface {
36
- (...args: any[]): Unit;
37
- [key: string]: any;
38
- basics: typeof basics;
39
- audio: typeof audio;
40
- }
41
41
  declare namespace xnew {
42
42
  type Unit = InstanceType<typeof Unit>;
43
43
  }
44
- declare const xnew: xnew_interface;
44
+ declare const xnew: (typeof base) & {
45
+ basics: typeof basics;
46
+ audio: typeof audio;
47
+ };
45
48
  export default xnew;