@lightningjs/blits 0.3.7 → 0.3.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.
@@ -2,5 +2,6 @@
2
2
  "recommendations": [
3
3
  "editorconfig.editorconfig",
4
4
  "dbaeumer.vscode-eslint",
5
+ "LightningJS.lightning-blits"
5
6
  ]
6
7
  }
@@ -2,6 +2,7 @@
2
2
  "recommendations": [
3
3
  "editorconfig.editorconfig",
4
4
  "dbaeumer.vscode-eslint",
5
- "naumovs.color-highlight"
5
+ "naumovs.color-highlight",
6
+ "LightningJS.lightning-blits"
6
7
  ]
7
8
  }
@@ -5,5 +5,6 @@
5
5
  ],
6
6
  "editor.codeActionsOnSave": {
7
7
  "source.fixAll.eslint": true
8
- }
8
+ },
9
+ "js/ts.implicitProjectConfig.checkJs": true
9
10
  }
@@ -1,3 +1,4 @@
1
1
  // temporary workaround for Vite importChunkUrl plugin
2
+ // @ts-ignore
2
3
  import FontLoader from '@lightningjs/blits/fontloader'
3
4
  export default FontLoader
@@ -1,9 +1,10 @@
1
1
  import Blits from '@lightningjs/blits'
2
+ // @ts-ignore
2
3
  import fontLoader from './fontloader.js?importChunkUrl'
3
4
 
4
5
  import App from './App.js'
5
6
 
6
- const settings = {
7
+ Blits.Launch(App, 'app', {
7
8
  w: 1920,
8
9
  h: 1080,
9
10
  multithreaded: false,
@@ -14,6 +15,4 @@ const settings = {
14
15
  {family: 'raleway', type: 'msdf', png: '/fonts/Raleway-ExtraBold.msdf.png', json: '/fonts/Raleway-ExtraBold.msdf.json'},
15
16
  {family: 'opensans', type: 'web', file: '/fonts/OpenSans-Medium.ttf'}
16
17
  ],
17
- }
18
-
19
- Blits.Launch(App, 'app', settings)
18
+ })
@@ -1,3 +1,4 @@
1
+ // @ts-ignore
1
2
  import renderer from '@lightningjs/blits/renderer'
2
3
 
3
4
  renderer()
package/index.d.ts ADDED
@@ -0,0 +1,31 @@
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 Component from './src/component.js'
19
+ import Application from './src/application.js'
20
+ import Launch from './src/launch.js'
21
+
22
+ /**
23
+ * Blits - The Lightning 3 App Development Framework
24
+ */
25
+ declare module Blits {
26
+ export { Component }
27
+ export { Application }
28
+ export { Launch }
29
+ }
30
+
31
+ export default Blits
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightningjs/blits",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "description": "Blits: The Lightning 3 App Development Framework",
5
5
  "bin": "bin/index.cjs",
6
6
  "exports": {
@@ -0,0 +1,62 @@
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 {default as Component, ComponentInstance} from './component'
19
+
20
+ declare namespace Application {
21
+
22
+ interface Route {
23
+ /**
24
+ * URI path for the route
25
+ */
26
+ path: string,
27
+ /**
28
+ * Component to load when activating the route
29
+ */
30
+ component: typeof ComponentInstance
31
+ }
32
+
33
+ export interface ApplicationInstance extends ComponentInstance {}
34
+
35
+ export interface ApplicationConfig extends Component.ComponentConfig {
36
+ /**
37
+ * Routes definition
38
+ *
39
+ * @example
40
+ *
41
+ * ```js
42
+ * routes: [
43
+ * { path: '/', component: Home },
44
+ * { path: '/details', component: Details },
45
+ * { path: '/account', component: Account },
46
+ * ]
47
+ * ```
48
+ */
49
+ routes: Route[]
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Blits.Application()
55
+ *
56
+ * Root App component
57
+ */
58
+ declare function Application(
59
+ config: Application.ApplicationConfig
60
+ ) : Application.ApplicationInstance
61
+
62
+ export default Application;
@@ -0,0 +1,273 @@
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
+ interface AdvancedProp {
26
+ /**
27
+ * Name of the prop
28
+ */
29
+ key: string,
30
+ /**
31
+ * Whether the prop is required to be passed
32
+ */
33
+ required?: boolean,
34
+ /**
35
+ * Default value for the prop when omited
36
+ */
37
+ default?: any,
38
+ /**
39
+ * Cast the value of the prop
40
+ *
41
+ * @example
42
+ * ```js
43
+ * {
44
+ * cast: Number, // casts to a number
45
+ * cast: (v) => v.toUpperCase() // casts to uppercase
46
+ * }
47
+ * ```
48
+ */
49
+ cast?: () => any
50
+ }
51
+
52
+ type Props = string | AdvancedProp
53
+
54
+ type NotFunction<T> = T extends Function ? never : T;
55
+
56
+ /**
57
+ * Internal state of a Component instance
58
+ */
59
+ interface StateObject {
60
+ [key: string]: any
61
+ }
62
+
63
+ interface Computed {
64
+ [key: string]: (this: ComponentInstance) => any
65
+ }
66
+
67
+ interface Watch {
68
+ [key: string]: (this: ComponentInstance, value: any, oldValue: any) => void
69
+ }
70
+
71
+ interface Methods {
72
+ [key: string]: (this: ComponentInstance) => any
73
+ }
74
+
75
+ interface Input {
76
+ [key: string]: (this: ComponentInstance, event: KeyboardEvent) => void,
77
+ /**
78
+ * Catch all input function
79
+ *
80
+ * Will be invoked when there is no dedicated function for a certain key
81
+ */
82
+ 'any'?: (this: ComponentInstance, event: KeyboardEvent) => void,
83
+ }
84
+
85
+ interface Log {
86
+ /**
87
+ * Log an info message
88
+ */
89
+ info: typeof console.info
90
+ /**
91
+ * Log an error message
92
+ */
93
+ error: typeof console.error
94
+ /**
95
+ * Log a warning
96
+ */
97
+ warn: typeof console.warn
98
+ /**
99
+ * Log a debug message
100
+ */
101
+ debug: typeof console.debug
102
+ }
103
+
104
+ interface Hooks {
105
+ /**
106
+ * Fires when the Component is being instantiated.
107
+ * At this moment child elements will not be available yet
108
+ */
109
+ init?: (this: ComponentInstance) => void
110
+ /**
111
+ * Fires when the Component is fully initialized and ready for interaction.
112
+ */
113
+ ready?: (this: ComponentInstance) => void
114
+ /**
115
+ * Triggers when the Component receives focus.
116
+ * This event can fire multiple times during the component's lifecycle
117
+ */
118
+ focus?: (this: ComponentInstance) => void
119
+ /**
120
+ * Triggers when the Component loses focus.
121
+ * This event can fire multiple times during the component's lifecycle
122
+ */
123
+ unfocus?: (this: ComponentInstance) => void
124
+ /**
125
+ * Fires when the Component is being destroyed and removed.
126
+ */
127
+ destroy?: (this: ComponentInstance) => void
128
+ }
129
+
130
+ export interface ComponentInstance {
131
+ /**
132
+ * Listen to events emitted by other components
133
+ */
134
+ $listen: (event: string, callback: (args: any) => void) => void
135
+
136
+ /**
137
+ * Emit events that other components can listen to
138
+ */
139
+ $emit: (event: string, args?: any) => void
140
+
141
+ /**
142
+ * Set a timeout that is automatically cleaned upon component destroy
143
+ */
144
+ $setTimeout: (callback: (args: any) => void, ms?: number | undefined) => typeof setTimeout
145
+
146
+ /**
147
+ * Set an interval that is automatically cleaned upon component destroy
148
+ */
149
+ $setInterval: (callback: (args: any) => void, ms?: number | undefined) => typeof setInterval
150
+
151
+ /**
152
+ * Log to the console with prettier output and configurable debug levels in Settings
153
+ */
154
+ $log: Log
155
+
156
+ /**
157
+ * Set focus to the Component, optionally pass a KeyboardEvent for instant event bubbling
158
+ */
159
+ focus: (event?: KeyboardEvent) => void
160
+
161
+ /**
162
+ * Select a child Element or Component by ref
163
+ *
164
+ * Elements and Components in the template can have an optional ref argument.
165
+ * Returns an Element Instance or Component Instance.
166
+ * Useful for passing on the focus to a Child component.
167
+ *
168
+ * @example
169
+ * ```js
170
+ * const menu = this.select('Menu')
171
+ * if(menu) {
172
+ * menu.focus()
173
+ * }
174
+ * ```
175
+ */
176
+ select: (ref: string) => ComponentInstance | ElementInstance
177
+
178
+ // tmp
179
+ [key: string]: any
180
+ }
181
+
182
+ export interface ElementInstance {
183
+ focus?: () => void
184
+ }
185
+
186
+ export interface ComponentConfig {
187
+ components?: any,
188
+ /**
189
+ * XML-based template string of the Component
190
+ *
191
+ * @example
192
+ * ```xml
193
+ * <Element :x="$x" w="400" h="1080" color="#64748b">
194
+ * <Element x="50" y="40">
195
+ * <Button color="#e4e4e7" />
196
+ * <Button color="#e4e4e7" y="100" />
197
+ * <Button color="#e4e4e7" y="200" />
198
+ * <Button color="#e4e4e7" y="300" />
199
+ * </Element>
200
+ * </Element>
201
+ * ```
202
+ */
203
+ template?: String,
204
+ /**
205
+ * Reactive internal state of the Component instance
206
+ *
207
+ * Should return an object (literal) with key value pairs.
208
+ * Can contain nested objects, but beware that too deep nesting can have
209
+ * a negative impact on performance
210
+ *
211
+ * @example
212
+ * ```js
213
+ * state() {
214
+ * return {
215
+ * items: [],
216
+ * color: 'red',
217
+ * alpha: 0.1
218
+ * }
219
+ * }
220
+ * ```
221
+ */
222
+ state?: (this: ComponentInstance) => StateObject,
223
+ /**
224
+ * Allowed props to be passed into the Component by the parent
225
+ *
226
+ * Can be a simple array with `prop` keys as strings.
227
+ * Alternatively objects can be used to specify `required` props and `default` values
228
+ *
229
+ * @example
230
+ * ```js
231
+ * props: ['index', {
232
+ * key: 'alpha',
233
+ * required: true
234
+ * }, {
235
+ * key: 'color',
236
+ * default: 'red'
237
+ * }]
238
+ * ```
239
+ */
240
+ props?: Props[],
241
+ /**
242
+ * Computed properties
243
+ */
244
+ computed?: Computed,
245
+ /**
246
+ * Watchers for changes to state variables, props or computed properties
247
+ */
248
+ watch?: Watch,
249
+ /**
250
+ * Hooking into Lifecycle events
251
+ */
252
+ hooks?: Hooks,
253
+ /**
254
+ * Methods for abstracting more complex business logic into separate function
255
+ */
256
+ methods?: Methods,
257
+ /**
258
+ * Tapping into user input
259
+ */
260
+ input?: Input
261
+ }
262
+ }
263
+
264
+
265
+ /**
266
+ * Blits.Component()
267
+ */
268
+ declare function Component(
269
+ name: Component.Name,
270
+ config: Component.ComponentConfig,
271
+ ) : Component.ComponentInstance
272
+
273
+ export default Component;
@@ -0,0 +1,105 @@
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
+
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 SdfFont {
36
+ /**
37
+ * Name of the font family
38
+ */
39
+ family: string,
40
+ /**
41
+ * Type of font (msdf or sdf)
42
+ */
43
+ type: 'msdf' | 'sdf',
44
+ /**
45
+ * Location of the font map (i.e. `'/fonts/Lato-Regular.msdf.json'`)
46
+ */
47
+ json: string,
48
+ /**
49
+ * Location of the font png (i.e. `'/fonts/Lato-Regular.msdf.png'`)
50
+ */
51
+ png: string
52
+ }
53
+
54
+ type Font = WebFont | SdfFont
55
+
56
+ export type DebugLevel = 0 | 1 | 2
57
+ export type LogTypes = 'info' | 'warn' | 'error' | 'debug'
58
+
59
+ /**
60
+ * Settings
61
+ *
62
+ * Launcher function that sets up the Lightning renderer and instantiates
63
+ * the Blits App
64
+ */
65
+ export interface Settings {
66
+ /**
67
+ * Width of the Application
68
+ */
69
+ w?: number,
70
+ /**
71
+ * Height of the Application
72
+ */
73
+ h?: number,
74
+ /**
75
+ * Whether to enable multithreaded
76
+ */
77
+ multithreaded?: boolean,
78
+ /**
79
+ * Debug level for console log messages
80
+ */
81
+ debugLevel?: DebugLevel | LogType[]
82
+ /**
83
+ * Font loader file
84
+ */
85
+ fontLoader?: any
86
+ /**
87
+ * Fonts to be used in the Application
88
+ */
89
+ fonts?: Font[]
90
+ }
91
+
92
+ /**
93
+ * Blits.Launch()
94
+ *
95
+ * Launcher function that sets up the Lightning renderer and instantiates
96
+ * the Blits App
97
+ */
98
+ declare function Launch(
99
+ App: ApplicationInstance,
100
+ target: HTMLElement | string,
101
+ settings?: Settings,
102
+ ) : void
103
+
104
+
105
+ export default Launch;