@lightningjs/blits 1.7.1 → 1.8.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.
@@ -1,455 +0,0 @@
1
- /*
2
- * Copyright 2023 Comcast Cable Communications Management, LLC
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License.
5
- * You may obtain a copy of the License at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software
10
- * distributed under the License is distributed on an "AS IS" BASIS,
11
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- * See the License for the specific language governing permissions and
13
- * limitations under the License.
14
- *
15
- * SPDX-License-Identifier: Apache-2.0
16
- */
17
-
18
- declare namespace Component {
19
-
20
- /**
21
- * Name of the Component
22
- */
23
- type Name = string
24
-
25
-
26
- interface Announcer {
27
- /**
28
- * Announce a message to screen readers by specifying the politeness level
29
- */
30
- speak: (message: string, politeness?: 'polite' | 'assertive') => void
31
-
32
- /**
33
- * Announce a message to screen readers with a polite politeness level
34
- */
35
- polite: (message: string) => void
36
-
37
- /**
38
- * Announce a message to screen readers with an assertive politeness level
39
- */
40
- assertive: (message: string) => void
41
-
42
- /**
43
- * Stop all announcements
44
- */
45
- stop: () => void
46
- }
47
-
48
- interface Log {
49
- /**
50
- * Log an info message
51
- */
52
- info(...args): typeof console.info
53
- /**
54
- * Log an error message
55
- */
56
- error(...args): typeof console.error
57
- /**
58
- * Log a warning
59
- */
60
- warn(...args): typeof console.warn
61
- /**
62
- * Log a debug message
63
- */
64
- debug(...args): typeof console.debug
65
- }
66
- interface AdvancedProp {
67
- /**
68
- * Name of the prop
69
- */
70
- key: string,
71
- /**
72
- * Whether the prop is required to be passed
73
- */
74
- required?: boolean,
75
- /**
76
- * Default value for the prop when omited
77
- */
78
- default?: any,
79
- /**
80
- * Cast the value of the prop
81
- *
82
- * @example
83
- * ```js
84
- * {
85
- * cast: Number, // casts to a number
86
- * cast: (v) => v.toUpperCase() // casts to uppercase
87
- * }
88
- * ```
89
- */
90
- cast?: () => any
91
- }
92
- type PropsArray<T extends string> = T[]
93
- type AdvancedProps = AdvancedProp[]
94
- type MixedProps<T extends string> = (T | AdvancedProp)[];
95
-
96
- // type ExtractPropNames<T extends Prop[]> = T extends (infer U)[]
97
- // ? U extends string
98
- // ? U
99
- // : U extends AdvancedProp
100
- // ? U['key']
101
- // : never
102
- // : never;
103
-
104
- type NotFunction<T> = T extends Function ? never : T;
105
-
106
- /**
107
- * Internal state of a Component instance
108
- */
109
- interface State {
110
- [key: string]: any
111
- }
112
-
113
- interface Computed<S, M, P> {
114
- [key: string]: (this: ComponentInstance & S & M & P) => any
115
- }
116
-
117
- interface Watch<S, M, P> {
118
- [key: string]: (this: ComponentInstance & S & M & P, value: any, oldValue: any) => void
119
- }
120
-
121
- interface Methods {
122
- [key: string]: (this: ComponentInstance & State & Methods, ...args: any) => any;
123
- }
124
-
125
- // interface MethodsExtended<S, M, P> extends Methods {
126
- // [key: string]: (this: ComponentInstance & S & M & P) => any;
127
- // }
128
-
129
- interface Input<S, M, P> {
130
- [key: string]: ((this: ComponentInstance & S & M & P, event: KeyboardEvent) => void) | undefined,
131
-
132
- /**
133
- * Catch all input function
134
- *
135
- * Will be invoked when there is no dedicated function for a certain key
136
- */
137
- any?: (this: ComponentInstance & S & M & P, event: KeyboardEvent) => void,
138
- }
139
-
140
- interface Log {
141
- /**
142
- * Log an info message
143
- */
144
- info(...args): typeof console.info
145
- /**
146
- * Log an error message
147
- */
148
- error(...args): typeof console.error
149
- /**
150
- * Log a warning
151
- */
152
- warn(...args): typeof console.warn
153
- /**
154
- * Log a debug message
155
- */
156
- debug(...args): typeof console.debug
157
- }
158
-
159
- interface Hooks<S, M, P> {
160
- /**
161
- * Fires when the Component is being instantiated.
162
- * At this moment child elements will not be available yet
163
- */
164
- init?: (this: ComponentInstance & S & M & P, ...args: any) => void
165
- /**
166
- * Fires when the Component is fully initialized and ready for interaction.
167
- */
168
- ready?: (this: ComponentInstance & S & M & P, ...args: any) => void
169
- /**
170
- * Triggers when the Component receives focus.
171
- *
172
- * This event can fire multiple times during the component's lifecycle
173
- */
174
- focus?: (this: ComponentInstance & S & M & P, ...args: any) => void
175
- /**
176
- * Triggers when the Component loses focus.
177
- *
178
- * This event can fire multiple times during the component's lifecycle
179
- */
180
- unfocus?: (this: ComponentInstance & S & M & P, ...args: any) => void
181
- /**
182
- * Fires when the Component is being destroyed and removed.
183
- */
184
- destroy?: (this: ComponentInstance & S & M & P, ...args: any) => void,
185
- /**
186
- * Fires upon each frame start (allowing you to tap directly into the renderloop)
187
- *
188
- * Note: This hook will fire continuously, multiple times per second!
189
- */
190
- frameTick?: (this: ComponentInstance & S & M & P, ...args: any) => void,
191
- /**
192
- * Fires when the component enters the viewport _margin_ and is attached to the render tree
193
- *
194
- * This event can fire multiple times during the component's lifecycle
195
- */
196
- attach?: (this: ComponentInstance & S & M & P, ...args: any) => void,
197
- /**
198
- * Fires when the component leaves the viewport _margin_ and is detached from the render tree
199
- *
200
- * This event can fire multiple times during the component's lifecycle
201
- */
202
- detach?: (this: ComponentInstance & S & M & P, ...args: any) => void,
203
- /**
204
- * Fires when the component enters the visible viewport
205
- *
206
- * This event can fire multiple times during the component's lifecycle
207
- */
208
- enter?: (this: ComponentInstance & S & M & P, ...args: any) => void,
209
- /**
210
- * Fires when the component leaves the visible viewport
211
- *
212
- * This event can fire multiple times during the component's lifecycle
213
- */
214
- exit?: (this: ComponentInstance & S & M & P, ...args: any) => void,
215
- }
216
-
217
- /**
218
- * Route object
219
- */
220
- interface Route {
221
- path: string,
222
- params: Record<string, string>,
223
- options?: {
224
- inHistory?: boolean,
225
- keepAlive?: boolean,
226
- [key: string]: any,
227
- },
228
- data?: Record<string, any>,
229
- component?: (args: { props: any }, holder: any, context: any) => Promise<any>,
230
- hooks?: {
231
- before?: (route: Route, previousRoute: Route) => Promise<string | Route | void>,
232
- }
233
- }
234
-
235
-
236
- interface Router {
237
- /**
238
- * Navigate to a different location
239
- */
240
- to(location: string, data?: Record<string, any>, options?: Record<string, any>): void;
241
-
242
- /**
243
- * Navigate to the previous location
244
- */
245
- back(): boolean;
246
-
247
- /**
248
- * Get the current route read-only
249
- */
250
- readonly currentRoute: Route;
251
-
252
- /**
253
- * Get the list of all routes
254
- */
255
- readonly routes: Route[];
256
-
257
- /**
258
- * Get navigating state
259
- */
260
- readonly navigating: boolean;
261
-
262
- }
263
-
264
- export interface ComponentInstance {
265
- /**
266
- * Listen to events emitted by other components
267
- */
268
- $listen: {
269
- (event: string, callback: (args: any) => void, priority?: number): void;
270
- }
271
-
272
- /**
273
- * Emit events that other components can listen to
274
- */
275
- $emit: (event: string, args?: any) => void
276
-
277
- /**
278
- * Set a timeout that is automatically cleaned upon component destroy
279
- */
280
- $setTimeout: (callback: (args: any) => void, ms?: number | undefined) => ReturnType<typeof setTimeout>
281
-
282
- /**
283
- * Clear a timeout
284
- */
285
- $clearTimeout: (id: ReturnType<typeof setTimeout>) => void
286
-
287
- /**
288
- * Set an interval that is automatically cleaned upon component destroy
289
- */
290
- $setInterval: (callback: (args: any) => void, ms?: number | undefined) => ReturnType<typeof setInterval>
291
-
292
- /**
293
- * Clear a interval
294
- */
295
- $clearInterval: (id: ReturnType<typeof setInterval>) => void
296
-
297
- /**
298
- * Log to the console with prettier output and configurable debug levels in Settings
299
- */
300
- $log: Log
301
-
302
- /**
303
- * Set focus to the Component, optionally pass a KeyboardEvent for instant event bubbling
304
- */
305
- $focus: (event?: KeyboardEvent) => void
306
- /**
307
- * @deprecated
308
- * Deprecated: use `this.$focus()` instead
309
- */
310
- focus: (event?: KeyboardEvent) => void
311
-
312
- /**
313
- * Select a child Element or Component by ref
314
- *
315
- * Elements and Components in the template can have an optional ref argument.
316
- * Returns an Element Instance or Component Instance.
317
- * Useful for passing on the focus to a Child component.
318
- *
319
- * @example
320
- * ```js
321
- * const menu = this.select('Menu')
322
- * if(menu) {
323
- * menu.focus()
324
- * }
325
- * ```
326
- */
327
- $select: (ref: string) => ComponentInstance | ElementInstance
328
-
329
- /**
330
- * @deprecated
331
- * Deprecated: use `this.$select()` instead
332
- */
333
- select: (ref: string) => ComponentInstance | ElementInstance
334
-
335
- /**
336
- * Announcer methods for screen reader support
337
- */
338
- $announcer: Announcer
339
-
340
- /**
341
- * Triggers a forced update on state variables.
342
- */
343
- $trigger: (key: string) => void
344
- /**
345
- * @deprecated
346
- *
347
- * Triggers a forced update on state variables.
348
- * Deprecated: use `this.$trigger()` instead
349
- */
350
- trigger: (key: string) => void
351
-
352
- /**
353
- * Router instance
354
- */
355
- $router: Router
356
-
357
- }
358
-
359
- export interface ElementInstance {
360
- focus?: () => void
361
- $focus?: () => void
362
- }
363
-
364
- export interface ComponentConfig<Props extends string, S, M> {
365
- components?: any,
366
- /**
367
- * XML-based template string of the Component
368
- *
369
- * @example
370
- * ```xml
371
- * <Element :x="$x" w="400" h="1080" color="#64748b">
372
- * <Element x="50" y="40">
373
- * <Button color="#e4e4e7" />
374
- * <Button color="#e4e4e7" y="100" />
375
- * <Button color="#e4e4e7" y="200" />
376
- * <Button color="#e4e4e7" y="300" />
377
- * </Element>
378
- * </Element>
379
- * ```
380
- */
381
- template?: String,
382
- /**
383
- * Reactive internal state of the Component instance
384
- *
385
- * Should return an object (literal) with key value pairs.
386
- * Can contain nested objects, but beware that too deep nesting can have
387
- * a negative impact on performance
388
- *
389
- * @example
390
- * ```js
391
- * state() {
392
- * return {
393
- * items: [],
394
- * color: 'red',
395
- * alpha: 0.1
396
- * }
397
- * }
398
- * ```
399
- */
400
- state?: (this: { [K in Props]: any}) => S,
401
- /**
402
- * Allowed props to be passed into the Component by the parent
403
- *
404
- * Can be a simple array with `prop` keys as strings.
405
- * Alternatively objects can be used to specify `required` props and `default` values
406
- *
407
- * @example
408
- * ```js
409
- * props: ['index', {
410
- * key: 'alpha',
411
- * required: true
412
- * }, {
413
- * key: 'color',
414
- * default: 'red'
415
- * }]
416
- * ```
417
- */
418
- props?: PropsArray<Props> | AdvancedProps | MixedProps<Props>
419
- /**
420
- * Computed properties
421
- */
422
- computed?: Computed<S, M, { [K in Props]: any}>,
423
- /**
424
- * Watchers for changes to state variables, props or computed properties
425
- */
426
- watch?: Watch<S, M, { [K in Props]: any}>,
427
- /**
428
- * Hooking into Lifecycle events
429
- */
430
- hooks?: Hooks<S, M, { [K in Props]: any}>,
431
- /**
432
- * Methods for abstracting more complex business logic into separate function
433
- */
434
- methods?: M //MethodsExtended<S, M, { [K in Props]: any}>,
435
- /**
436
- * Tapping into user input
437
- */
438
- input?: Input<S, M, { [K in Props]: any}>
439
- }
440
- }
441
-
442
-
443
- /**
444
- * Blits.Component()
445
- */
446
- declare function Component<
447
- Props extends string,
448
- S extends Component.State,
449
- M extends Component.Methods
450
- >(
451
- name: Component.Name,
452
- config: Component.ComponentConfig<Props, S, M>
453
- ) : Component.ComponentInstance
454
-
455
- export default Component;
package/src/launch.d.ts DELETED
@@ -1,273 +0,0 @@
1
- /*
2
- * Copyright 2023 Comcast Cable Communications Management, LLC
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License.
5
- * You may obtain a copy of the License at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software
10
- * distributed under the License is distributed on an "AS IS" BASIS,
11
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- * See the License for the specific language governing permissions and
13
- * limitations under the License.
14
- *
15
- * SPDX-License-Identifier: Apache-2.0
16
- */
17
-
18
- import ApplicationInstance from './application'
19
- import {type Stage, type ShaderEffect as RendererShaderEffect, type WebGlCoreShader} from '@lightningjs/renderer'
20
- interface WebFont {
21
- /**
22
- * Name of the font family
23
- */
24
- family: string,
25
- /**
26
- * Type of font (web)
27
- */
28
- type: 'web',
29
- /**
30
- * Location to the font file (i.e. `/fonts/OpenSans-Medium.ttf`)
31
- */
32
- file: string
33
- }
34
-
35
- interface SdfFontWithFile {
36
- /**
37
- * Location of the font file (i.e. `/fonts/OpenSans-Medium.ttf`)
38
- */
39
- file: string
40
- }
41
-
42
- interface SdfFontWithPngJson {
43
- /**
44
- * Location of the font map (i.e. `'/fonts/Lato-Regular.msdf.json'`)
45
- */
46
- json: string,
47
- /**
48
- * Location of the font png (i.e. `'/fonts/Lato-Regular.msdf.png'`)
49
- */
50
- png: string
51
- }
52
-
53
- type SdfFont = {
54
- /**
55
- * Name of the font family
56
- */
57
- family: string,
58
- /**
59
- * Type of font (msdf or sdf)
60
- */
61
- type: 'msdf' | 'sdf',
62
- } & (SdfFontWithFile | SdfFontWithPngJson)
63
-
64
- type Shader = {
65
- name: string,
66
- type: WebGlCoreShader
67
- }
68
-
69
- type ShaderEffect = {
70
- name: string,
71
- type: RendererShaderEffect
72
- }
73
-
74
- type ScreenResolutions = 'hd' | '720p' | 720 | 'fhd' | 'fullhd' | '1080p' | 1080 | '4k' | '2160p' | 2160
75
-
76
- type Font = WebFont | SdfFont
77
-
78
- export type DebugLevel = 0 | 1 | 2
79
- export type LogTypes = 'info' | 'warn' | 'error' | 'debug'
80
- export type ReactivityModes = 'Proxy' | 'defineProperty'
81
- export type RenderModes = 'webgl' | 'canvas'
82
-
83
- interface ExtensionLoader {
84
- async (stage: Stage): void
85
- }
86
- /**
87
- * Settings
88
- *
89
- * Launcher function that sets up the Lightning renderer and instantiates
90
- * the Blits App
91
- */
92
- export interface Settings {
93
- /**
94
- * Width of the Application
95
- */
96
- w?: number,
97
- /**
98
- * Height of the Application
99
- */
100
- h?: number,
101
- /**
102
- * Whether to enable multithreaded
103
- */
104
- multithreaded?: boolean,
105
- /**
106
- * Debug level for console log messages
107
- */
108
- debugLevel?: DebugLevel | LogTypes[],
109
- /**
110
- * Fonts to be used in the Application
111
- */
112
- fonts?: Font[],
113
- /**
114
- * Effects to be used by DynamicShader
115
- */
116
- effects?: ShaderEffect[],
117
- /**
118
- * Shaders to be used in the application
119
- */
120
- shaders?: Shader[],
121
- /**
122
- * Default font family to use in the Application when no font attribute is specified
123
- * on a Text-component
124
- *
125
- * The default font must be registered in the `fonts` array in the settings.
126
- *
127
- * Defaults to `sans-serif` font family, which is the default of the Lightning Renderer
128
- */
129
- defaultFont?: string,
130
- /**
131
- * Custom keymapping
132
- */
133
- keymap?: object,
134
- /**
135
- * Mode of reactivity (`Proxy` or `defineProperty`)
136
- */
137
- reactivityMode?: ReactivityModes,
138
- /**
139
- * Screen resolution of the device, defining the pixelRatio used to convert dimensions
140
- * and positions in the App code to the actual device logical coordinates
141
- *
142
- * If not supplied, Blits will try to autodetect the device screen resolution. Otherwise
143
- * the exact dimensions and positions used the app code are used.
144
- *
145
- * Note: If the option `pixelRatio` is specified in the Settings object, this value will take presedence
146
- * over the screen resolution setting.
147
- *
148
- * Currently 3 screen resolutions are supported, which can be defined with different alias values:
149
- *
150
- * For 720x1080 (1px = 0.66666667px)
151
- * - hd
152
- * - 720p
153
- * - 720
154
- *
155
- * For 1080x1920 (1px = 1px)
156
- * - fhd
157
- * - fullhd
158
- * - 1080p
159
- * - 1080
160
- *
161
- * For 2160x3840 (1px = 2px)
162
- * - 4k
163
- * - 2160p
164
- * - 2160
165
- */
166
- screenResolution?: ScreenResolutions,
167
- /**
168
- * Custom pixel ratio of the device used to convert dimensions
169
- * and positions in the App code to the actual device logical coordinates
170
- *
171
- * Takes presedence over the `screenResolution` setting
172
- *
173
- * Defaults to 1 if not specified
174
- */
175
- pixelRatio?: number
176
- /**
177
- * Interval in milliseconds to receive FPS updates
178
- *
179
- * @remarks
180
- * If set to `0`, FPS updates will be disabled.
181
- *
182
- * @defaultValue `1000` (disabled)
183
- */
184
- fpsInterval?: number
185
- /**
186
- * Maximum number of web workers to spin up simultaneously for offloading functionality such
187
- * as image loading to separate threads (when supported by the browser)
188
- *
189
- * If not specified defaults to the number of logical processers available as reported by
190
- * `navigator.hardwareConcurrency` (or 2 if `navigator.hardwareConcurrency` is not supported)
191
- */
192
- webWorkersLimit?: number
193
- /**
194
- * Background color of the canvas (also known as the clearColor)
195
- *
196
- * Can be a color name (red, blue, silver), a hexadecimal color (`#000000`, `#ccc`),
197
- * or a color number in rgba order (`0xff0033ff`)
198
- *
199
- * Defauls to transparent (`0x00000000`)
200
- *
201
- */
202
- canvasColor?: string,
203
- /**
204
- * Enable inspector
205
- *
206
- * Enables the inspector tool for debugging and inspecting the application, the node tree
207
- * will be replicated in the DOM and can be inspected using the browser's developer tools
208
- *
209
- * Defaults to `false`
210
- */
211
- inspector?: boolean,
212
- /**
213
- * Add an extra margin to the viewport for earlier pre-loading of elements and components
214
- *
215
- * By default the Lightning renderer, only renders elements that are inside the defined viewport.
216
- * Everything outside of these bounds is removed from the render tree.
217
- *
218
- * With the viewportMargin you have the option to _virtually_ increase the viewport area,
219
- * to expedite the pre-loading of elements and / or delay the unloading of elements depending
220
- * on their position in the (virtual) viewport
221
- *
222
- * The margin can be specified in 4 directions by defining an array [top, right, bottom, left],
223
- * or as a single number which is then applied to all 4 directions equally.
224
- *
225
- * Defaults to `0`
226
- */
227
- viewportMargin?: number | [number, number, number, number],
228
- /**
229
- * Threshold in `Megabytes` after which all the textures that are currently not visible
230
- * within the configured viewport margin will be be freed and cleaned up
231
- *
232
- * When passed `0` the threshold is disabled and textures will not be actively freed
233
- * and cleaned up
234
- *
235
- * Defaults to `200` (mb)
236
- */
237
- gpuMemoryLimit?: number,
238
- /**
239
- * Defines which mode the renderer should operate in: `webgl` or `canvas`
240
- *
241
- * SDF fonts are not supported in _canvas_ renderMode. Instead, _web_ fonts should
242
- * be used. Also note that Canvas2d rendering doesnt support the use of shaders.
243
- *
244
- * Defaults to `webgl`
245
- */
246
- renderMode?: RenderModes,
247
-
248
- /**
249
- * The time, in milliseconds, after which Blits considers a key press a _hold_ key press
250
- *
251
- * During a hold key press the focus delegation behaviour is different: when scrolling
252
- * through a long list, focus is not handed over to each individual list item, creating a
253
- * smoother experience
254
- *
255
- * Defaults to `50` (ms)
256
- */
257
- holdTimeout?: number
258
- }
259
-
260
- /**
261
- * Blits.Launch()
262
- *
263
- * Launcher function that sets up the Lightning renderer and instantiates
264
- * the Blits App
265
- */
266
- declare function Launch(
267
- App: ApplicationInstance,
268
- target: HTMLElement | string,
269
- settings?: Settings,
270
- ) : void
271
-
272
-
273
- export default Launch;