@aegis-framework/pandora 0.1.7 → 0.3.0
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/LICENSE +1 -1
- package/README.md +746 -27
- package/dist/pandora.browser.js +10 -0
- package/dist/pandora.browser.js.map +14 -0
- package/dist/pandora.js +10 -806
- package/dist/pandora.js.map +13 -1
- package/dist/types/Component.d.ts +266 -0
- package/dist/types/Component.d.ts.map +1 -0
- package/dist/types/Registry.d.ts +276 -0
- package/dist/types/Registry.d.ts.map +1 -0
- package/dist/types/ShadowComponent.d.ts +35 -0
- package/dist/types/ShadowComponent.d.ts.map +1 -0
- package/dist/types/Types.d.ts +9 -0
- package/dist/types/Types.d.ts.map +1 -0
- package/dist/types/Util.d.ts +16 -0
- package/dist/types/Util.d.ts.map +1 -0
- package/dist/types/browser.d.ts +7 -0
- package/dist/types/browser.d.ts.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +41 -22
- package/dist/pandora.min.js +0 -10
- package/dist/pandora.min.js.map +0 -1
- package/index.js +0 -3
- package/src/Component.js +0 -502
- package/src/Registry.js +0 -74
- package/src/ShadowComponent.js +0 -47
- package/src/Util.js +0 -66
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import Component from './Component';
|
|
2
|
+
type ComponentClass = typeof Component & {
|
|
3
|
+
tag: string;
|
|
4
|
+
_registered?: boolean;
|
|
5
|
+
};
|
|
6
|
+
type StateSubscriber<T = unknown> = (newValue: T, oldValue: T | undefined) => void;
|
|
7
|
+
type LifecycleCallback = (component: Component, tag: string) => void;
|
|
8
|
+
type ErrorCallback = (error: Error, component: Component, tag: string, lifecycle: string) => void;
|
|
9
|
+
type MiddlewareType = 'props' | 'state' | 'render';
|
|
10
|
+
type Middleware = (component: Component, value: any) => any;
|
|
11
|
+
type ComponentLoader = () => Promise<ComponentClass | {
|
|
12
|
+
default: ComponentClass;
|
|
13
|
+
}>;
|
|
14
|
+
interface ComponentStats {
|
|
15
|
+
tag: string;
|
|
16
|
+
instanceCount: number;
|
|
17
|
+
isRegistered: boolean;
|
|
18
|
+
isLazy: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Registry for managing web components and global state
|
|
22
|
+
*/
|
|
23
|
+
declare class Registry {
|
|
24
|
+
private static _debug;
|
|
25
|
+
private static components;
|
|
26
|
+
private static implementations;
|
|
27
|
+
private static state;
|
|
28
|
+
private static subscribers;
|
|
29
|
+
private static mountCallbacks;
|
|
30
|
+
private static unmountCallbacks;
|
|
31
|
+
private static errorCallbacks;
|
|
32
|
+
private static aliases;
|
|
33
|
+
private static lazyLoaders;
|
|
34
|
+
private static middleware;
|
|
35
|
+
private static _initialized;
|
|
36
|
+
/**
|
|
37
|
+
* Initialize Registry hooks on the Component class. Called automatically on first use
|
|
38
|
+
*/
|
|
39
|
+
private static _init;
|
|
40
|
+
/**
|
|
41
|
+
* Register a new component with a specific tag name
|
|
42
|
+
*
|
|
43
|
+
* @param tag - The tag name for the component
|
|
44
|
+
* @param component - The component constructor
|
|
45
|
+
*/
|
|
46
|
+
static register(tag: string, component: ComponentClass): void;
|
|
47
|
+
/**
|
|
48
|
+
* Get the current implementation for a tag
|
|
49
|
+
*
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
static getImplementation(tag: string): ComponentClass | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Update an existing component with a new implementation
|
|
55
|
+
*
|
|
56
|
+
* @param tag - The tag name of the component to update
|
|
57
|
+
* @param component - The new component constructor
|
|
58
|
+
* @param rerender - Whether to re-render all existing instances (default: false)
|
|
59
|
+
*/
|
|
60
|
+
static evolve(tag: string, component: ComponentClass, rerender?: boolean): void;
|
|
61
|
+
/**
|
|
62
|
+
* Get all instances of a component or execute a callback on them
|
|
63
|
+
*
|
|
64
|
+
* @param tag - The tag name of the component
|
|
65
|
+
* @param callback - Optional callback to execute on each instance
|
|
66
|
+
*/
|
|
67
|
+
static instances(tag: string, callback?: (instance: Element) => void): NodeListOf<Element> | void;
|
|
68
|
+
/**
|
|
69
|
+
* Create a new instance of a component
|
|
70
|
+
*
|
|
71
|
+
* @param tag - The tag name of the component
|
|
72
|
+
* @param props - Properties to set on the component
|
|
73
|
+
* @returns The created component instance
|
|
74
|
+
*/
|
|
75
|
+
static instantiate(tag: string, props: Record<string, any>): Component;
|
|
76
|
+
/**
|
|
77
|
+
* Check if a component is registered with the given tag
|
|
78
|
+
*
|
|
79
|
+
* @param tag - The tag name to check
|
|
80
|
+
* @returns True if a component is registered with the tag
|
|
81
|
+
*/
|
|
82
|
+
static has(tag: string): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Get the component class registered with the given tag
|
|
85
|
+
*
|
|
86
|
+
* @param tag - The tag name of the component
|
|
87
|
+
* @returns The component class or undefined if not registered
|
|
88
|
+
*/
|
|
89
|
+
static get(tag: string): ComponentClass | undefined;
|
|
90
|
+
/**
|
|
91
|
+
* Set a global state value
|
|
92
|
+
*
|
|
93
|
+
* @param key - The state key
|
|
94
|
+
* @param value - The value to set
|
|
95
|
+
*/
|
|
96
|
+
static setState<T>(key: string, value: T): void;
|
|
97
|
+
/**
|
|
98
|
+
* Get a global state value
|
|
99
|
+
*
|
|
100
|
+
* @param key - The state key
|
|
101
|
+
* @returns The state value or undefined if not set
|
|
102
|
+
*/
|
|
103
|
+
static getState<T>(key: string): T | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* Check if a global state key exists
|
|
106
|
+
*
|
|
107
|
+
* @param key - The state key to check
|
|
108
|
+
* @returns True if the state key exists
|
|
109
|
+
*/
|
|
110
|
+
static hasState(key: string): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Delete a global state value
|
|
113
|
+
*
|
|
114
|
+
* @param key - The state key to delete
|
|
115
|
+
* @returns True if the key existed and was deleted
|
|
116
|
+
*/
|
|
117
|
+
static deleteState(key: string): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Subscribe to changes on a global state key
|
|
120
|
+
*
|
|
121
|
+
* @param key - The state key to subscribe to
|
|
122
|
+
* @param callback - Function called when the state changes
|
|
123
|
+
* @returns An unsubscribe function
|
|
124
|
+
*/
|
|
125
|
+
static subscribe<T>(key: string, callback: StateSubscriber<T>): () => void;
|
|
126
|
+
/**
|
|
127
|
+
* Unsubscribe from changes on a global state key
|
|
128
|
+
*
|
|
129
|
+
* @param key - The state key to unsubscribe from
|
|
130
|
+
* @param callback - The callback function to remove
|
|
131
|
+
*/
|
|
132
|
+
static unsubscribe<T>(key: string, callback: StateSubscriber<T>): void;
|
|
133
|
+
/**
|
|
134
|
+
* Get all global state as an object
|
|
135
|
+
*
|
|
136
|
+
* @returns A copy of the global state object
|
|
137
|
+
*/
|
|
138
|
+
static getAllState(): Record<string, unknown>;
|
|
139
|
+
/**
|
|
140
|
+
* Clear all global state and notify subscribers
|
|
141
|
+
*/
|
|
142
|
+
static clearState(): void;
|
|
143
|
+
/**
|
|
144
|
+
* Enable or disable debug mode.
|
|
145
|
+
* When enabled, lifecycle events are logged to the console.
|
|
146
|
+
*/
|
|
147
|
+
static get debug(): boolean;
|
|
148
|
+
static set debug(value: boolean);
|
|
149
|
+
/**
|
|
150
|
+
* Log a debug message if debug mode is enabled
|
|
151
|
+
*
|
|
152
|
+
* @param message - The message to log
|
|
153
|
+
* @param data - Optional data to include
|
|
154
|
+
*/
|
|
155
|
+
static log(message: string, data?: unknown): void;
|
|
156
|
+
/**
|
|
157
|
+
* List all registered component tags
|
|
158
|
+
*
|
|
159
|
+
* @returns Array of registered component tag names
|
|
160
|
+
*/
|
|
161
|
+
static list(): string[];
|
|
162
|
+
/**
|
|
163
|
+
* Get statistics for a specific component or all components
|
|
164
|
+
*
|
|
165
|
+
* @param tag - Optional tag to get stats for a specific component
|
|
166
|
+
* @returns Component stats or array of all component stats
|
|
167
|
+
*/
|
|
168
|
+
static stats(tag?: string): ComponentStats | ComponentStats[];
|
|
169
|
+
/**
|
|
170
|
+
* Register a callback to be called when any component mounts
|
|
171
|
+
*
|
|
172
|
+
* @param callback - Function called with (component, tag) when a component mounts
|
|
173
|
+
* @returns Unsubscribe function
|
|
174
|
+
*/
|
|
175
|
+
static onMount(callback: LifecycleCallback): () => void;
|
|
176
|
+
/**
|
|
177
|
+
* Register a callback to be called when any component unmounts
|
|
178
|
+
*
|
|
179
|
+
* @param callback - Function called with (component, tag) when a component unmounts
|
|
180
|
+
* @returns Unsubscribe function
|
|
181
|
+
*/
|
|
182
|
+
static onUnmount(callback: LifecycleCallback): () => void;
|
|
183
|
+
/**
|
|
184
|
+
* Notify Registry that a component has mounted
|
|
185
|
+
* @internal
|
|
186
|
+
*/
|
|
187
|
+
static _notifyMount(component: Component, tag: string): void;
|
|
188
|
+
/**
|
|
189
|
+
* Notify Registry that a component has unmounted
|
|
190
|
+
*
|
|
191
|
+
* @internal
|
|
192
|
+
*/
|
|
193
|
+
static _notifyUnmount(component: Component, tag: string): void;
|
|
194
|
+
/**
|
|
195
|
+
* Register a global error handler for component errors
|
|
196
|
+
*
|
|
197
|
+
* @param callback - Function called with (error, component, tag, lifecycle) when an error occurs
|
|
198
|
+
* @returns Unsubscribe function
|
|
199
|
+
*/
|
|
200
|
+
static onError(callback: ErrorCallback): () => void;
|
|
201
|
+
/**
|
|
202
|
+
* Notify Registry that an error occurred in a component
|
|
203
|
+
*
|
|
204
|
+
* @internal
|
|
205
|
+
*/
|
|
206
|
+
static _notifyError(error: Error, component: Component, tag: string, lifecycle: string): void;
|
|
207
|
+
/**
|
|
208
|
+
* Create an alias for an existing component tag
|
|
209
|
+
*
|
|
210
|
+
* @param aliasTag - The new tag name to use as an alias
|
|
211
|
+
* @param originalTag - The original component tag name
|
|
212
|
+
*/
|
|
213
|
+
static alias(aliasTag: string, originalTag: string): void;
|
|
214
|
+
/**
|
|
215
|
+
* Get the original tag for an alias
|
|
216
|
+
*
|
|
217
|
+
* @param aliasTag - The alias tag name
|
|
218
|
+
* @returns The original tag name or undefined if not an alias
|
|
219
|
+
*/
|
|
220
|
+
static getOriginalTag(aliasTag: string): string | undefined;
|
|
221
|
+
/**
|
|
222
|
+
* Check if a tag is an alias
|
|
223
|
+
*
|
|
224
|
+
* @param tag - The tag name to check
|
|
225
|
+
* @returns True if the tag is an alias
|
|
226
|
+
*/
|
|
227
|
+
static isAlias(tag: string): boolean;
|
|
228
|
+
/**
|
|
229
|
+
* Register a component to be lazily loaded on first use
|
|
230
|
+
*
|
|
231
|
+
* @param tag - The tag name for the component
|
|
232
|
+
* @param loader - Async function that returns the component class
|
|
233
|
+
*/
|
|
234
|
+
static lazy(tag: string, loader: ComponentLoader): void;
|
|
235
|
+
/**
|
|
236
|
+
* Load a lazy component
|
|
237
|
+
*
|
|
238
|
+
* @internal
|
|
239
|
+
*/
|
|
240
|
+
static _loadLazyComponent(tag: string): Promise<void>;
|
|
241
|
+
/**
|
|
242
|
+
* Check if a component is lazy (not yet loaded)
|
|
243
|
+
*
|
|
244
|
+
* @param tag - The tag name to check
|
|
245
|
+
* @returns True if the component is registered as lazy and not yet loaded
|
|
246
|
+
*/
|
|
247
|
+
static isLazy(tag: string): boolean;
|
|
248
|
+
/**
|
|
249
|
+
* Preload a lazy component without mounting it
|
|
250
|
+
*
|
|
251
|
+
* @param tag - The tag name of the lazy component to preload
|
|
252
|
+
*/
|
|
253
|
+
static preload(tag: string): Promise<void>;
|
|
254
|
+
/**
|
|
255
|
+
* Register middleware to intercept props, state, or render operations
|
|
256
|
+
*
|
|
257
|
+
* @param type - The type of middleware: 'props', 'state', or 'render'
|
|
258
|
+
* @param middleware - Function that receives (component, value) and returns the modified value
|
|
259
|
+
* @returns Unsubscribe function
|
|
260
|
+
*/
|
|
261
|
+
static use(type: MiddlewareType, middleware: Middleware): () => void;
|
|
262
|
+
/**
|
|
263
|
+
* Apply middleware to a value
|
|
264
|
+
*
|
|
265
|
+
* @internal
|
|
266
|
+
*/
|
|
267
|
+
static _applyMiddleware(type: MiddlewareType, component: Component, value: any): any;
|
|
268
|
+
/**
|
|
269
|
+
* Check if there are any middleware registered for a type
|
|
270
|
+
*
|
|
271
|
+
* @internal
|
|
272
|
+
*/
|
|
273
|
+
static _hasMiddleware(type: MiddlewareType): boolean;
|
|
274
|
+
}
|
|
275
|
+
export default Registry;
|
|
276
|
+
//# sourceMappingURL=Registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Registry.d.ts","sourceRoot":"","sources":["../../src/Registry.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,aAAa,CAAC;AAEpC,KAAK,cAAc,GAAG,OAAO,SAAS,GAAG;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,KAAK,eAAe,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,SAAS,KAAK,IAAI,CAAC;AACnF,KAAK,iBAAiB,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;AACrE,KAAK,aAAa,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;AAClG,KAAK,cAAc,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;AACnD,KAAK,UAAU,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC;AAC5D,KAAK,eAAe,GAAG,MAAM,OAAO,CAAC,cAAc,GAAG;IAAE,OAAO,EAAE,cAAc,CAAA;CAAE,CAAC,CAAC;AAEnF,UAAU,cAAc;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,OAAO,CAAC;IACtB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,c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OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYhD;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,GAAG,MAAM,IAAI;IAOpE;;;;OAIG;IACH,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,GAAG,GAAG;IAcpF;;;;OAIG;IACH,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO;CAGrD;AAED,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import Component from './Component';
|
|
2
|
+
import { Properties, Style } from './Types';
|
|
3
|
+
/**
|
|
4
|
+
* A component that uses Shadow DOM for encapsulation
|
|
5
|
+
*
|
|
6
|
+
* @template P - The type of the component's props (defaults to Properties)
|
|
7
|
+
* @template S - The type of the component's state (defaults to Properties)
|
|
8
|
+
*/
|
|
9
|
+
declare class ShadowComponent<P extends Properties = Properties, S extends Properties = Properties> extends Component<P, S> {
|
|
10
|
+
protected _shadowDOM: ShadowRoot;
|
|
11
|
+
constructor();
|
|
12
|
+
setStyle(style: Style | string, reset?: boolean): Style;
|
|
13
|
+
protected _createStyleElement(): void;
|
|
14
|
+
protected _render(): Promise<string>;
|
|
15
|
+
get dom(): HTMLElement;
|
|
16
|
+
set dom(value: HTMLElement);
|
|
17
|
+
get shadowRoot(): ShadowRoot;
|
|
18
|
+
set shadowRoot(value: ShadowRoot);
|
|
19
|
+
/**
|
|
20
|
+
* Queries for a single element within the shadow DOM.
|
|
21
|
+
*
|
|
22
|
+
* @param selector - CSS selector to query for
|
|
23
|
+
* @returns The first matching element or null
|
|
24
|
+
*/
|
|
25
|
+
query<E extends Element = Element>(selector: string): E | null;
|
|
26
|
+
/**
|
|
27
|
+
* Queries for all matching elements within the shadow DOM.
|
|
28
|
+
*
|
|
29
|
+
* @param selector - CSS selector to query for
|
|
30
|
+
* @returns A NodeList of all matching elements
|
|
31
|
+
*/
|
|
32
|
+
queryAll<E extends Element = Element>(selector: string): NodeListOf<E>;
|
|
33
|
+
}
|
|
34
|
+
export default ShadowComponent;
|
|
35
|
+
//# sourceMappingURL=ShadowComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ShadowComponent.d.ts","sourceRoot":"","sources":["../../src/ShadowComponent.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAE5C;;;;;GAKG;AACH,cAAM,eAAe,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EAAE,CAAC,SAAS,UAAU,GAAG,UAAU,CAAE,SAAQ,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC;IACjH,SAAS,CAAC,UAAU,EAAE,UAAU,CAAC;;IASjC,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,GAAE,OAAe,GAAG,KAAK;IAsB9D,SAAS,CAAC,mBAAmB,IAAI,IAAI;cASrB,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IA+B1C,IAAI,GAAG,IAAI,WAAW,CAErB;IAED,IAAI,GAAG,CAAC,KAAK,EAAE,WAAW,EAEzB;IAED,IAAI,UAAU,IAAI,UAAU,CAE3B;IAED,IAAI,UAAU,CAAC,KAAK,EAAE,UAAU,EAE/B;IAED;;;;;OAKG;IACM,KAAK,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI;IAIvE;;;;;OAKG;IACM,QAAQ,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC;CAGhF;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type Properties = Record<string, unknown>;
|
|
2
|
+
export type CSSValue = string | number;
|
|
3
|
+
export type CSSProperties = Record<string, CSSValue>;
|
|
4
|
+
export interface CSSObject {
|
|
5
|
+
[key: string]: CSSValue | CSSProperties | CSSObject;
|
|
6
|
+
}
|
|
7
|
+
export type Style = CSSObject;
|
|
8
|
+
export type ReadyCallback = () => void;
|
|
9
|
+
//# sourceMappingURL=Types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Types.d.ts","sourceRoot":"","sources":["../../src/Types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEjD,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AACvC,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAErD,MAAM,WAAW,SAAS;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,GAAG,aAAa,GAAG,SAAS,CAAC;CACrD;AAED,MAAM,MAAM,KAAK,GAAG,SAAS,CAAC;AAE9B,MAAM,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CSSObject } from './Types';
|
|
2
|
+
/**
|
|
3
|
+
* Calls a function asynchronously and returns a Promise with its result
|
|
4
|
+
* @param callable - The function to call
|
|
5
|
+
* @param context - The context (this) to use when calling the function
|
|
6
|
+
* @param args - Additional arguments to pass to the function
|
|
7
|
+
*/
|
|
8
|
+
export declare function callAsync<T>(callable: (...args: any[]) => T, context: any, ...args: any[]): Promise<T>;
|
|
9
|
+
/**
|
|
10
|
+
* Converts a CSS object to a CSS string
|
|
11
|
+
* @param object - The CSS object to convert
|
|
12
|
+
* @param encapsulation - Optional selector to encapsulate the CSS
|
|
13
|
+
* @param level - Current nesting level for indentation
|
|
14
|
+
*/
|
|
15
|
+
export declare function deserializeCSS(object: CSSObject, encapsulation?: string, level?: number): string;
|
|
16
|
+
//# sourceMappingURL=Util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Util.d.ts","sourceRoot":"","sources":["../../src/Util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAOtG;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,EAAE,aAAa,GAAE,MAAW,EAAE,KAAK,GAAE,MAAU,GAAG,MAAM,CAuCvG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/browser.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,OAAO,EAAE,OAAO,OAAO,CAAC;KACzB;CACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as Component } from './Component';
|
|
2
|
+
export { default as ShadowComponent } from './ShadowComponent';
|
|
3
|
+
export { default as Registry } from './Registry';
|
|
4
|
+
export * as Util from './Util';
|
|
5
|
+
export * as Types from './Types';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aegis-framework/pandora",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Aegis Framework Web Components Library",
|
|
5
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/pandora.js",
|
|
6
7
|
"module": "./dist/pandora.js",
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/types/index.d.ts",
|
|
12
|
+
"import": "./dist/pandora.js",
|
|
13
|
+
"default": "./dist/pandora.js"
|
|
14
|
+
},
|
|
15
|
+
"./browser": {
|
|
16
|
+
"types": "./dist/types/index.d.ts",
|
|
17
|
+
"import": "./dist/pandora.browser.js",
|
|
18
|
+
"default": "./dist/pandora.browser.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"sideEffects": false,
|
|
7
22
|
"repository": {
|
|
8
23
|
"type": "git",
|
|
9
24
|
"url": "https://gitlab.com/AegisFramework/Pandora.git"
|
|
@@ -12,7 +27,7 @@
|
|
|
12
27
|
"url": "https://gitlab.com/AegisFramework/Pandora/issues"
|
|
13
28
|
},
|
|
14
29
|
"homepage": "https://aegisframework.com/",
|
|
15
|
-
"author": "
|
|
30
|
+
"author": "Diana Islas Ocampo <dev@hyuchia.com>",
|
|
16
31
|
"license": "MIT",
|
|
17
32
|
"keywords": [
|
|
18
33
|
"pandora",
|
|
@@ -24,28 +39,32 @@
|
|
|
24
39
|
"library"
|
|
25
40
|
],
|
|
26
41
|
"scripts": {
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"build": "
|
|
30
|
-
"
|
|
42
|
+
"build": "yarn clean && yarn lint && yarn check && yarn build:module && yarn build:legacy && yarn build:types",
|
|
43
|
+
"build:module": "bun build ./src/index.ts --target browser --format esm --outdir ./dist --sourcemap=linked --minify && mv ./dist/index.js ./dist/pandora.js && mv ./dist/index.js.map ./dist/pandora.js.map && sed -i 's/index.js.map/pandora.js.map/' ./dist/pandora.js",
|
|
44
|
+
"build:legacy": "bun build ./src/browser.ts --target browser --format esm --outdir ./dist --sourcemap=linked --minify && mv ./dist/browser.js ./dist/pandora.browser.js && mv ./dist/browser.js.map ./dist/pandora.browser.js.map && sed -i 's/browser.js.map/pandora.browser.js.map/' ./dist/pandora.browser.js",
|
|
45
|
+
"build:types": "tsc --emitDeclarationOnly --declarationDir ./dist/types",
|
|
46
|
+
"check": "tsc --noEmit",
|
|
47
|
+
"lint": "eslint ./src/**/*.ts",
|
|
48
|
+
"clean": "rm -rf dist",
|
|
49
|
+
"test": "http-server -p 3000 -c-1"
|
|
31
50
|
},
|
|
32
51
|
"devDependencies": {
|
|
33
|
-
"@babel/
|
|
34
|
-
"@
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
37
|
-
"
|
|
38
|
-
"eslint": "^
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
52
|
+
"@babel/eslint-parser": "^7.28.5",
|
|
53
|
+
"@eslint/js": "^9.39.1",
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^8.48.1",
|
|
55
|
+
"@typescript-eslint/parser": "^8.48.1",
|
|
56
|
+
"bun": "^1.3.3",
|
|
57
|
+
"eslint": "^9.39.1",
|
|
58
|
+
"http-server": "^14.1.1",
|
|
59
|
+
"typescript": "^5.9.3",
|
|
60
|
+
"typescript-eslint": "^8.48.1"
|
|
42
61
|
},
|
|
43
62
|
"files": [
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
63
|
+
"dist/",
|
|
64
|
+
"LICENSE",
|
|
65
|
+
"README.md",
|
|
66
|
+
"package.json"
|
|
47
67
|
],
|
|
48
|
-
"browserslist":
|
|
49
|
-
|
|
50
|
-
]
|
|
68
|
+
"browserslist": "> 0.5%, last 2 versions, not dead",
|
|
69
|
+
"packageManager": "yarn@4.12.0"
|
|
51
70
|
}
|
package/dist/pandora.min.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"yzgE":[function(require,module,exports) {
|
|
2
|
-
"use strict";function e(e,t,...o){try{const r=e.apply(t,o);return r instanceof Promise?r:Promise.resolve(r)}catch(n){return Promise.reject(n)}}function t(e,o="",n=0){const r=Object.keys(e);let s="";for(const c of r)if("object"==typeof e[c]){o?0===c.indexOf("&")?s+=`${c.replace(/&/g,o)} {\n`:s+=`${o} ${c} {\n`:s+=`${c} {\n`;const r=Object.keys(e[c]);for(const f of r)if(s+="\t".repeat(n),"object"==typeof e[c][f]){const r={};r[f]=e[c][f],s+=t(r,o,n+1)}else s+=`\t${f}: ${e[c][f]};\n`;s+="}\n"}else s+="\t".repeat(n),s+=`\t${c}: ${e[c]};\n`;return s}Object.defineProperty(exports,"__esModule",{value:!0}),exports.callAsync=e,exports.deserializeCSS=t;
|
|
3
|
-
},{}],"Simw":[function(require,module,exports) {
|
|
4
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Component=void 0;var t=require("./Util");function e(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}class s extends HTMLElement{static get tag(){if(void 0===this._tag){let t=this.name;const e=t.match(/([A-Z])/g);if(null!==e)for(const s of e)t=t.replace(s,`-${s}`.toLowerCase());this._tag=t.slice(1)}return this._tag}static set tag(t){this._tag=t}static template(t=null,e=null){if(null===t)return"function"==typeof this._template?this._template.call(e):this._template;this._template=t,document.querySelectorAll(this.tag).forEach(t=>{t._isReady&&t.forceRender()})}constructor(){super(),this._children=this.innerHTML.trim(),this._state={},this._props={},this._ready=[],this._connected=!1,this._isReady=!1,this._style={},this._styleElement=null}get width(){return parseInt(getComputedStyle(this).width.replace("px",""))}set width(t){this.style.width=t}get height(){return parseInt(getComputedStyle(this).height.replace("px",""))}set height(t){this.style.height=t}get static(){return new Proxy(this.constructor,{})}set static(t){throw new Error("Component static properties cannot be reassigned.")}get props(){return new Proxy(this,{get:(t,e)=>{if(this.hasAttribute(e)){let t=this.getAttribute(e);return"string"==typeof t&&("false"===t?t=!1:"true"===t||""===t?t=!0:isNaN(t)||(t=t.indexOf(".")>0?parseFloat(t):parseInt(t))),t}return e in this._props?this._props[e]:null},set:(t,e,s)=>{throw new Error("Component props should be set using the `setProps` function.")}})}set props(t){if(!1!==this._connected)throw new Error("Component props cannot be directly assigned. Use the `setProps` function instead.");this._props=Object.assign({},this._props,t)}get state(){return new Proxy(this._state,{get:(t,e)=>t[e],set:(t,e,s)=>{if(!1===this._connected)return t[e]=s;throw new Error("Component state should be set using the `setState` function instead.")}})}set state(t){if(!1!==this._connected)throw new Error("Component state should be set using the `setState` function instead.");this._state=Object.assign({},this._state,t)}get dom(){return this}set dom(t){throw new Error("Component DOM can not be overwritten.")}static register(){window.customElements.define(this.tag,this)}template(t=null){return this.static.template(t,this)}_createStyleElement(){const t=document.body.querySelector(`style#${this.static.tag}`);null!==t&&(this._styleElement=t),this._styleElement instanceof HTMLStyleElement||(this._styleElement=document.createElement("style"),this._styleElement.id=this.static.tag,document.body.prepend(this._styleElement))}setStyle(e,s=!1){return this._createStyleElement(),"object"==typeof e?(this._style=!1===s?Object.assign({},this._style,e):Object.assign({},e),this._styleElement.innerHTML=(0,t.deserializeCSS)(this._style,this.static.tag)):"string"==typeof e&&(!1===s?this._styleElement.innerHTML+=e:this._styleElement.innerHTML=e),this._style}setState(t){if("object"!=typeof t)throw new TypeError(`A state must be an object. Received ${typeof t}.`);{const e=Object.assign({},this._state);this._state=Object.assign({},this._state,t);for(const s of Object.keys(t))this.updateCallback(s,e[s],this._state[s],"state",e,this._state)}}setProps(t){if("object"!=typeof t)throw new TypeError(`Props must be an object. Received ${typeof state}.`);{const e=Object.assign({},this._props);this._props=Object.assign({},this._props,t);for(const s of Object.keys(t))this.updateCallback(s,e[s],this._props[s],"props",e,this._props);this._setPropAttributes(!0)}}_setPropAttributes(t=!1){for(const e of Object.keys(this._props)){const s=this._props[e];this.static._explicitPropTypes.indexOf(typeof s)>-1&&(!0===t?this.setAttribute(e,this._props[e]):(this._props[e]=this.props[e],this.setAttribute(e,this.props[e])))}}willUpdate(t,e,s,i,r,n){return Promise.resolve()}update(t,e,s,i,r,n){return Promise.resolve()}didUpdate(t,e,s,i,r,n){return Promise.resolve()}onStateUpdate(t,e,s,i,r){return Promise.resolve()}onPropsUpdate(t,e,s,i,r){return Promise.resolve()}willMount(){return Promise.resolve()}didMount(){return Promise.resolve()}willUnmount(){return Promise.resolve()}unmount(){return Promise.resolve()}didUnmount(){return Promise.resolve()}forceRender(){return this._render()}render(){return""}_render(){let e=this.render;return null!==this.static._template&&(e=this.template),(0,t.callAsync)(e,this).then(t=>{const e=this.dom.querySelector("slot");"string"==typeof t&&""===(t=t.trim())||null!=t&&(null!==e?e.replaceWith(t):(this.innerHTML=t,""!==this._children&&-1===t.indexOf(this._children)&&(this.innerHTML+=this._children)))})}connectedCallback(){if(this._connected=!0,this.dataset.component=this.static.tag,void 0===this.static._template){const t=document.querySelector(`template#${this.static.tag}`);null!==t?this.template(t.innerHTML):this.static._template=null}return this._setPropAttributes(),this.willMount().then(()=>this._render().then(()=>this.didMount().then(()=>{this._isReady=!0;for(const t of this._ready)t.call(this)})))}ready(t){this._ready.push(t)}disconnectedCallback(){return this.willUnmount().then(()=>this.unmount().then(()=>this.didUnmount()))}updateCallback(t,e,s,i="props",r={},n={}){return this.willUpdate(i,t,e,s,r,n).then(()=>this.update(i,t,e,s,r,n).then(()=>{let o;return(o="state"===i?this.onStateUpdate(t,e,s,r,n):this.onPropsUpdate(t,e,s,r,n)).then(()=>this.didUpdate(i,t,e,s,r,n))})).catch(t=>{console.error(t)})}attributeChangedCallback(t,e,s){}}exports.Component=s,e(s,"_tag",void 0),e(s,"_explicitPropTypes",["boolean","string","number"]),e(s,"_template",void 0);
|
|
5
|
-
},{"./Util":"yzgE"}],"Lecv":[function(require,module,exports) {
|
|
6
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShadowComponent=void 0;var e=require("./Component"),t=require("./Util");class s extends e.Component{constructor(...e){super(...e),this._shadowDOM=this.attachShadow({mode:"open"})}_createStyleElement(){this._styleElement instanceof HTMLStyleElement||(this._styleElement=document.createElement("style"),this.dom.prepend(this._styleElement))}_render(){let e=this.render;return null!==this.static._template&&(e=this.template),(0,t.callAsync)(e,this).then(e=>{this._shadowDOM.innerHTML="",this._styleElement instanceof HTMLStyleElement&&this._shadowDOM.appendChild(this._styleElement),this._shadowDOM.innerHTML+=e})}get dom(){return this._shadowDOM}}exports.ShadowComponent=s;
|
|
7
|
-
},{"./Component":"Simw","./Util":"yzgE"}],"Focm":[function(require,module,exports) {
|
|
8
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./src/Component");Object.keys(e).forEach(function(r){"default"!==r&&"__esModule"!==r&&Object.defineProperty(exports,r,{enumerable:!0,get:function(){return e[r]}})});var r=require("./src/ShadowComponent");Object.keys(r).forEach(function(e){"default"!==e&&"__esModule"!==e&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return r[e]}})});var t=require("./src/Util");Object.keys(t).forEach(function(e){"default"!==e&&"__esModule"!==e&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})});
|
|
9
|
-
},{"./src/Component":"Simw","./src/ShadowComponent":"Lecv","./src/Util":"yzgE"}]},{},["Focm"], "Pandora")
|
|
10
|
-
//# sourceMappingURL=pandora.min.js.map
|
package/dist/pandora.min.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["src/Util.js","src/Component.js","src/ShadowComponent.js","index.js"],"names":["callAsync","callable","context","args","result","apply","Promise","resolve","e","reject","deserializeCSS","object","encapsulation","level","keys","Object","css","key","indexOf","replace","properties","property","repeat","temp","undefined","Component","HTMLElement","tag","_tag","name","matches","match","toLowerCase","slice","value","template","html","_template","call","document","querySelectorAll","forEach","instance","_isReady","forceRender","constructor","_children","innerHTML","trim","_state","_props","_ready","_connected","_style","_styleElement","width","parseInt","getComputedStyle","style","height","static","Proxy","Error","props","get","target","hasAttribute","getAttribute","isNaN","parseFloat","set","assign","state","dom","register","window","customElements","define","_createStyleElement","sharedStyle","body","querySelector","HTMLStyleElement","createElement","id","prepend","setStyle","reset","setState","TypeError","oldState","updateCallback","setProps","oldProps","_setPropAttributes","update","_explicitPropTypes","setAttribute","willUpdate","origin","oldValue","newValue","oldObject","newObject","didUpdate","onStateUpdate","onPropsUpdate","willMount","didMount","willUnmount","unmount","didUnmount","_render","render","then","slot","replaceWith","connectedCallback","dataset","component","callback","ready","push","disconnectedCallback","promise","catch","console","error","attributeChanged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AEC,KAAM,SAG9CtD,sBACO,KAAKxB,yBAAyB4B,mBAC9B5B,KAAAA,cAAgBf,SAAS4C,cAAe,SACxCV,KAAAA,IAAIY,QAAS,KAAK/B,gBAIzB0D,UACKC,IAAAA,EAAS,KAAKA,OAWX,OANuB,OAA1B,KAAKrD,OAAOvB,YACf4E,EAAS,KAAK9E,WAKR,EAAW8E,EAAAA,WAAAA,EAAQ,MAAMC,KAAO9E,IACjC8F,KAAAA,WAAWnF,UAAY,GACxB,KAAKO,yBAAyB4B,kBAC5BgD,KAAAA,WAAWG,YAAa,KAAK/E,eAE9B4E,KAAAA,WAAWnF,WAAaX,IAI3BqC,UACI,OAAA,KAAKyD,YApCiC,QAAA,gBAAA;;ACJ/C,aAAA,OAAA,eAAA,QAAA,aAAA,CAAA,OAAA,IAFA,IAAA,EAAA,QAAA,mBAAA,OAAA,KAAA,GAAA,QAAA,SAAA,GAAA,YAAA,GAAA,eAAA,GAAA,OAAA,eAAA,QAAA,EAAA,CAAA,YAAA,EAAA,IAAA,WAAA,OAAA,EAAA,QACA,IAAA,EAAA,QAAA,yBAAA,OAAA,KAAA,GAAA,QAAA,SAAA,GAAA,YAAA,GAAA,eAAA,GAAA,OAAA,eAAA,QAAA,EAAA,CAAA,YAAA,EAAA,IAAA,WAAA,OAAA,EAAA,QACA,IAAA,EAAA,QAAA,cAAA,OAAA,KAAA,GAAA,QAAA,SAAA,GAAA,YAAA,GAAA,eAAA,GAAA,OAAA,eAAA,QAAA,EAAA,CAAA,YAAA,EAAA,IAAA,WAAA,OAAA,EAAA","file":"pandora.min.js","sourceRoot":"..","sourcesContent":["/**\n *\n * @param {*} callable\n * @param {*} context\n * @param {...any} args\n */\nexport function callAsync (callable, context, ...args) {\n\ttry {\n\t\t// Call the provided function using the context and arguments given\n\t\tconst result = callable.apply (context, args);\n\n\t\t// Check if the function returned a simple value or a Promise\n\t\tif (result instanceof Promise) {\n\t\t\treturn result;\n\t\t} else {\n\t\t\treturn Promise.resolve (result);\n\t\t}\n\t} catch (e) {\n\t\treturn Promise.reject (e);\n\t}\n}\n\n/**\n *\n * @param {*} object\n * @param {*} encapsulation\n * @param {*} level\n */\nexport function deserializeCSS (object, encapsulation = '', level = 0, ) {\n\tconst keys = Object.keys (object);\n\n\tlet css = '';\n\n\tfor (const key of keys) {\n\t\tif (typeof object[key] === 'object') {\n\t\t\tif (encapsulation) {\n\t\t\t\tif (key.indexOf ('&') === 0) {\n\t\t\t\t\tcss += `${key.replace(/&/g, encapsulation)} {\\n`;\n\t\t\t\t} else {\n\t\t\t\t\tcss += `${encapsulation} ${key} {\\n`;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tcss += `${key} {\\n`;\n\t\t\t}\n\n\t\t\tconst properties = Object.keys (object[key]);\n\t\t\tfor (const property of properties) {\n\t\t\t\tcss += '\\t'.repeat (level);\n\t\t\t\tif (typeof object[key][property] === 'object') {\n\t\t\t\t\tconst temp = {};\n\t\t\t\t\ttemp[property] = object[key][property];\n\n\t\t\t\t\tcss += deserializeCSS (temp, encapsulation, level + 1);\n\t\t\t\t} else {\n\t\t\t\t\tcss += `\\t${property}: ${object[key][property]};\\n`;\n\t\t\t\t}\n\t\t\t}\n\t\t\tcss += '}\\n';\n\t\t} else {\n\t\t\tcss += '\\t'.repeat (level);\n\t\t\tcss += `\\t${key}: ${object[key]};\\n`;\n\t\t}\n\t}\n\n\treturn css;\n}\n","/* eslint-disable no-unused-vars */\nimport { callAsync, deserializeCSS } from './Util';\n\n/**\n * A component represents a custom HTML element, and has all of its functionality\n * as well as its general structure and representation self contained on it.\n *\n * @class Component\n */\nexport class Component extends HTMLElement {\n\n\t/**\n\t * _tag {String} - The tag name for the component\n\t *\n\t * @static\n\t */\n\tstatic _tag;\n\n\tstatic get tag () {\n\t\tif (typeof this._tag === 'undefined') {\n\t\t\tlet tag = this.name;\n\t\t\tconst matches = tag.match (/([A-Z])/g);\n\t\t\tif (matches !== null) {\n\t\t\t\tfor (const match of matches) {\n\t\t\t\t\ttag = tag.replace (match, `-${match}`.toLowerCase ());\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis._tag = tag.slice (1);\n\t\t}\n\t\treturn this._tag;\n\t}\n\n\tstatic set tag (value) {\n\t\tthis._tag = value;\n\t}\n\n\t/**\n\t * These are the types that can be set as properties on the HTML code of the\n\t * element.\n\t */\n\tstatic _explicitPropTypes = ['boolean', 'string', 'number'];\n\n\t/**\n\t *\n\t *\n\t * @static\n\t */\n\tstatic _template = undefined;\n\n\tstatic template (html = null, context = null) {\n\t\tif (html !== null) {\n\t\t\tthis._template = html;\n\t\t\tdocument.querySelectorAll(this.tag).forEach((instance) => {\n\t\t\t\tif (instance._isReady) {\n\t\t\t\t\tinstance.forceRender ();\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\n\t\t\t// Check if no parameters were set but the HTML is still a function to be called\n\t\t\tif (typeof this._template === 'function') {\n\t\t\t\treturn this._template.call (context);\n\t\t\t}\n\n\t\t\t// If this is reached, the HTML was just a string\n\t\t\treturn this._template;\n\t\t}\n\t}\n\n\tconstructor () {\n\t\tsuper ();\n\t\tthis._children = this.innerHTML.trim ();\n\n\t\t// State Object for the component\n\t\tthis._state = {};\n\n\t\t// Props Object for the component\n\t\tthis._props = {};\n\n\t\t// List of callbacks to run once the component has been mounted successfully\n\t\tthis._ready = [];\n\n\t\tthis._connected = false;\n\t\tthis._isReady = false;\n\n\t\tthis._style = {};\n\n\t\tthis._styleElement = null;\n\t}\n\n\t/**\n\t * width - Determines the real (computed) width of the element\n\t *\n\t * @return {int} - Computed Width of the element on pixels\n\t */\n\tget width () {\n\t\treturn parseInt (getComputedStyle (this).width.replace ('px', ''));\n\t}\n\n\tset width (value) {\n\t\tthis.style.width = value;\n\t}\n\n\t/**\n\t * height - Determines the real (computed) height of the element\n\t *\n\t * @return {int} - Computed height of the element on pixels\n\t */\n\tget height () {\n\t\treturn parseInt (getComputedStyle(this).height.replace ('px', ''));\n\t}\n\n\tset height (value) {\n\t\tthis.style.height = value;\n\t}\n\n\tget static () {\n\t\treturn new Proxy (this.constructor, {});\n\t}\n\n\tset static (value) {\n\t\tthrow new Error ('Component static properties cannot be reassigned.');\n\t}\n\n\tget props () {\n\t\treturn new Proxy (this, {\n\t\t\tget: (target, key) => {\n\t\t\t\tif (this.hasAttribute (key)) {\n\t\t\t\t\tlet value = this.getAttribute (key);\n\t\t\t\t\tif (typeof value === 'string') {\n\t\t\t\t\t\tif (value === 'false') {\n\t\t\t\t\t\t\tvalue = false;\n\t\t\t\t\t\t} else if (value === 'true' || value === '') {\n\t\t\t\t\t\t\tvalue = true;\n\t\t\t\t\t\t} else if (!isNaN (value)) {\n\t\t\t\t\t\t\tif (value.indexOf ('.') > 0) {\n\t\t\t\t\t\t\t\tvalue = parseFloat (value);\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tvalue = parseInt (value);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn value;\n\t\t\t\t} else if (key in this._props) {\n\t\t\t\t\treturn this._props[key];\n\t\t\t\t}\n\t\t\t\treturn null;\n\t\t\t},\n\t\t\tset: (target, key, value) => {\n\t\t\t\tthrow new Error ('Component props should be set using the `setProps` function.');\n\t\t\t}\n\t\t});\n\t}\n\n\tset props (value) {\n\t\tif (this._connected === false) {\n\t\t\tthis._props = Object.assign ({}, this._props, value);\n\t\t} else {\n\t\t\tthrow new Error ('Component props cannot be directly assigned. Use the `setProps` function instead.');\n\t\t}\n\t}\n\n\tget state () {\n\t\treturn new Proxy (this._state, {\n\t\t\tget: (target, key) => {\n\t\t\t\treturn target[key];\n\t\t\t},\n\t\t\tset: (target, key, value) => {\n\t\t\t\tif (this._connected === false) {\n\t\t\t\t\treturn target[key] = value;\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error ('Component state should be set using the `setState` function instead.');\n\t\t\t\t}\n\n\t\t\t}\n\t\t});\n\t}\n\n\tset state (value) {\n\t\tif (this._connected === false) {\n\t\t\tthis._state = Object.assign ({}, this._state, value);\n\t\t} else {\n\t\t\tthrow new Error ('Component state should be set using the `setState` function instead.');\n\t\t}\n\t}\n\n\tget dom () {\n\t\treturn this;\n\t}\n\n\tset dom (value) {\n\t\tthrow new Error ('Component DOM can not be overwritten.');\n\t}\n\n\t/**\n\t * register - Register the component as a custom HTML element\n\t * using the component's tag as the actual element tag.\n\t *\n\t * This action cannot be reverted nor the controller class for\n\t * the element can be changed.\n\t */\n\tstatic register () {\n\t\twindow.customElements.define (this.tag, this);\n\t}\n\n\t/**\n\t * template - A simple function providing access to the basic HTML\n\t * structure of the component.\n\t *\n\t * @param {function|string} html - A string or function that renders the\n\t * component into a valid HTML structure.\n\t *\n\t * @returns {void|string} - Void or the HTML structure in a string\n\t */\n\ttemplate (html = null) {\n\t\treturn this.static.template (html, this);\n\t}\n\n\t_createStyleElement () {\n\t\tconst sharedStyle = document.body.querySelector (`style#${this.static.tag}`);\n\n\t\tif (sharedStyle !== null) {\n\t\t\tthis._styleElement = sharedStyle;\n\t\t}\n\n\t\tif (!(this._styleElement instanceof HTMLStyleElement)) {\n\t\t\tthis._styleElement = document.createElement ('style');\n\t\t\tthis._styleElement.id = this.static.tag;\n\t\t\tdocument.body.prepend (this._styleElement);\n\t\t}\n\t}\n\n\tsetStyle (style, reset = false) {\n\t\tthis._createStyleElement ();\n\n\t\tif (typeof style === 'object') {\n\t\t\tif (reset === false) {\n\t\t\t\tthis._style = Object.assign ({}, this._style, style);\n\t\t\t} else {\n\t\t\t\tthis._style = Object.assign ({}, style);\n\t\t\t}\n\t\t\tthis._styleElement.innerHTML = deserializeCSS (this._style, this.static.tag);\n\t\t} else if (typeof style === 'string') {\n\t\t\tif (reset === false) {\n\t\t\t\tthis._styleElement.innerHTML += style;\n\t\t\t} else {\n\t\t\t\tthis._styleElement.innerHTML = style;\n\t\t\t}\n\t\t}\n\n\t\treturn this._style;\n\t}\n\n\tsetState (state) {\n\t\tif (typeof state === 'object') {\n\t\t\tconst oldState = Object.assign ({}, this._state);\n\n\t\t\tthis._state = Object.assign ({}, this._state, state);\n\n\t\t\tfor (const key of Object.keys (state)) {\n\t\t\t\tthis.updateCallback (key, oldState[key], this._state[key], 'state', oldState, this._state);\n\t\t\t}\n\t\t} else {\n\t\t\tthrow new TypeError(`A state must be an object. Received ${typeof state}.`);\n\t\t}\n\t}\n\n\tsetProps (props) {\n\t\tif (typeof props === 'object') {\n\t\t\tconst oldProps = Object.assign ({}, this._props);\n\n\t\t\tthis._props = Object.assign ({}, this._props, props);\n\n\t\t\tfor (const key of Object.keys (props)) {\n\t\t\t\tthis.updateCallback (key, oldProps[key], this._props[key], 'props', oldProps, this._props);\n\t\t\t}\n\t\t\tthis._setPropAttributes (true);\n\t\t} else {\n\t\t\tthrow new TypeError(`Props must be an object. Received ${typeof state}.`);\n\t\t}\n\t}\n\n\t_setPropAttributes (update = false) {\n\t\tfor (const key of Object.keys (this._props)) {\n\t\t\tconst value = this._props[key];\n\t\t\tif (this.static._explicitPropTypes.indexOf (typeof value) > -1) {\n\t\t\t\tif (update === true) {\n\t\t\t\t\tthis.setAttribute (key, this._props[key]);\n\t\t\t\t} else {\n\t\t\t\t\tthis._props[key] = this.props[key];\n\t\t\t\t\tthis.setAttribute (key, this.props[key]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/*\n\t * =========================\n\t * Update Cycle\n\t * =========================\n */\n\n\twillUpdate (origin, property, oldValue, newValue, oldObject, newObject) {\n\t\treturn Promise.resolve ();\n\t}\n\n\tupdate (origin, property, oldValue, newValue, oldObject, newObject) {\n\t\treturn Promise.resolve ();\n\t}\n\n\tdidUpdate (origin, property, oldValue, newValue, oldObject, newObject) {\n\t\treturn Promise.resolve ();\n\t}\n\n\tonStateUpdate (property, oldValue, newValue, oldObject, newObject) {\n\t\treturn Promise.resolve ();\n\t}\n\n\tonPropsUpdate (property, oldValue, newValue, oldObject, newObject) {\n\t\treturn Promise.resolve ();\n\t}\n\n\t/*\n\t * =========================\n\t * Mount Cycle\n\t * =========================\n */\n\n\twillMount () {\n\t\treturn Promise.resolve ();\n\t}\n\n\tdidMount () {\n\t\treturn Promise.resolve ();\n\t}\n\n\t/*\n\t * =========================\n\t * Unmount Cycle\n\t * =========================\n */\n\n\twillUnmount () {\n\t\treturn Promise.resolve ();\n\t}\n\n\tunmount () {\n\t\treturn Promise.resolve ();\n\t}\n\n\tdidUnmount () {\n\t\treturn Promise.resolve ();\n\t}\n\n\t/*\n\t * =========================\n\t * Render Cycle\n\t * =========================\n */\n\n\t/**\n\t * Forces the component to be rendered again.\n\t *\n\t * @returns {string|Promise<string>} - The HTML to render on the component\n\t */\n\tforceRender () {\n\t\treturn this._render ();\n\t}\n\n\t/**\n\t * This function is the one that defines the HTML that will be rendered\n\t * inside the component. Since some content may need to be loaded before the\n\t * component is rendered, this function can also return a promise.\n\t *\n\t * @returns {string|Promise<string>} - The HTML to render on the component\n\t */\n\trender () {\n\t\treturn '';\n\t}\n\n\t_render () {\n\t\tlet render = this.render;\n\n\t\t// Check if a template has been set to this component, and if that's the\n\t\t// case, use that instead of the render function to render the component's\n\t\t// HTML code.\n\t\tif (this.static._template !== null) {\n\t\t\trender = this.template;\n\t\t}\n\n\t\t// Call the render function asynchronously and set the HTML from it to the\n\t\t// component.\n\t\treturn callAsync (render, this).then ((html) => {\n\t\t\tconst slot = this.dom.querySelector ('slot');\n\n\t\t\tif (typeof html === 'string') {\n\t\t\t\thtml = html.trim ();\n\n\t\t\t\tif (html === '') {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (html === null || typeof html === 'undefined') {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (slot !== null) {\n\t\t\t\tslot.replaceWith (html);\n\t\t\t} else {\n\t\t\t\tthis.innerHTML = html;\n\n\t\t\t\tif (this._children !== '' && html.indexOf(this._children) === -1) {\n\t\t\t\t\tthis.innerHTML += this._children;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tconnectedCallback () {\n\t\t// Set the state as connected\n\t\tthis._connected = true;\n\n\t\t// Add a data property with the tag of the component\n\t\tthis.dataset.component = this.static.tag;\n\n\t\t// Check if a template for this component was set. The contents on this\n\t\t// if block will only be run once.\n\t\tif (typeof this.static._template === 'undefined') {\n\n\t\t\t// Check if there is an HTML template for this component\n\t\t\tconst template = document.querySelector (`template#${this.static.tag}`);\n\n\t\t\tif (template !== null) {\n\t\t\t\t// If there is, set is as the template for the component\n\t\t\t\tthis.template (template.innerHTML);\n\t\t\t} else {\n\t\t\t\t// If not, set is as null\n\t\t\t\tthis.static._template = null;\n\t\t\t}\n\t\t}\n\n\t\t// Set the initial prop attributes for the component using the given\n\t\t// props\n\t\tthis._setPropAttributes ();\n\n\t\t// Start the Mount Cycle\n\t\treturn this.willMount ().then (() => {\n\n\t\t\treturn this._render ().then (() => {\n\t\t\t\treturn this.didMount ().then (() => {\n\n\t\t\t\t\tthis._isReady = true;\n\t\t\t\t\tfor (const callback of this._ready) {\n\t\t\t\t\t\tcallback.call (this);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Adds a callback to be run once the component has been mounted successfully\n\t *\n\t * @param {function} callback - Callback to run once the component is ready\n\t */\n\tready (callback) {\n\t\tthis._ready.push (callback);\n\t}\n\n\n\tdisconnectedCallback () {\n\t\treturn this.willUnmount ().then (() => {\n\t\t\treturn this.unmount ().then (() => {\n\t\t\t\treturn this.didUnmount ();\n\t\t\t});\n\t\t});\n\t}\n\n\tupdateCallback (property, oldValue, newValue, origin = 'props', oldObject = {}, newObject = {}) {\n\t\treturn this.willUpdate (origin, property, oldValue, newValue, oldObject, newObject).then (() => {\n\t\t\treturn this.update (origin, property, oldValue, newValue, oldObject, newObject).then (() => {\n\t\t\t\tlet promise;\n\t\t\t\tif (origin === 'state') {\n\t\t\t\t\tpromise = this.onStateUpdate (property, oldValue, newValue, oldObject, newObject);\n\t\t\t\t} else {\n\t\t\t\t\tpromise = this.onPropsUpdate (property, oldValue, newValue, oldObject, newObject);\n\t\t\t\t}\n\t\t\t\treturn promise.then (() => {\n\t\t\t\t\treturn this.didUpdate (origin, property, oldValue, newValue, oldObject, newObject);\n\t\t\t\t});\n\t\t\t});\n\t\t}).catch ((e) => {\n\t\t\tconsole.error (e);\n\t\t\t// Component should not update\n\t\t});\n\t}\n\n\tattributeChangedCallback (property, oldValue, newValue) {\n\n\t}\n}\n","import { Component } from './Component';\nimport { callAsync } from './Util';\n\n/**\n * @class ShadowComponent\n */\nexport class ShadowComponent extends Component {\n\tconstructor (...props) {\n\t\tsuper (...props);\n\n\t\tthis._shadowDOM = this.attachShadow ({ mode: 'open' });\n\t}\n\n\t_createStyleElement () {\n\t\tif (!(this._styleElement instanceof HTMLStyleElement)) {\n\t\t\tthis._styleElement = document.createElement ('style');\n\t\t\tthis.dom.prepend (this._styleElement);\n\t\t}\n\t}\n\n\t_render () {\n\t\tlet render = this.render;\n\n\t\t// Check if a template has been set to this component, and if that's the\n\t\t// case, use that instead of the render function to render the component's\n\t\t// HTML code.\n\t\tif (this.static._template !== null) {\n\t\t\trender = this.template;\n\t\t}\n\n\t\t// Call the render function asynchronously and set the HTML from it to the\n\t\t// component.\n\t\treturn callAsync (render, this).then ((html) => {\n\t\t\tthis._shadowDOM.innerHTML = '';\n\t\t\tif (this._styleElement instanceof HTMLStyleElement) {\n\t\t\t\tthis._shadowDOM.appendChild (this._styleElement);\n\t\t\t}\n\t\t\tthis._shadowDOM.innerHTML += html;\n\t\t});\n\t}\n\n\tget dom () {\n\t\treturn this._shadowDOM;\n\t}\n\n\n}\n","export * from './src/Component';\nexport * from './src/ShadowComponent';\nexport * from './src/Util';"]}
|
package/index.js
DELETED