@lightningjs/blits 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.cjs +1 -0
- package/CHANGELOG.md +23 -0
- package/package.json +2 -2
- package/src/component.d.ts +12 -6
- package/src/component.js +13 -29
- package/src/components/Sprite.js +4 -1
- package/src/components/Sprite.orig.js +2 -2
- package/src/element.js +23 -18
- package/src/launch.d.ts +9 -0
- package/src/launch.js +1 -0
- package/src/lib/codegenerator/generator.test.js +2582 -0
- package/src/lib/hooks.js +2 -2
- package/src/lib/lifecycle.js +42 -0
- package/src/lib/reactivity/reactive.js +12 -2
- package/src/lib/setup/base.js +7 -4
- package/src/router/router.js +1 -1
- package/src/lib/codegenerator/generator.test_.js +0 -974
package/.eslintrc.cjs
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,30 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
# v0.7.2
|
|
4
|
+
|
|
5
|
+
_23 feb 2024_
|
|
6
|
+
|
|
7
|
+
- Added small fix to support for (re)assigning an array used in a for-loop
|
|
8
|
+
- Added option to enable the Lightning inspector in launch setting (`inspector: true/false`)
|
|
9
|
+
|
|
10
|
+
# v0.7.1
|
|
11
|
+
|
|
12
|
+
_22 feb 2024_
|
|
13
|
+
|
|
14
|
+
- Fixed clean up of children nodes when routing to a new view
|
|
15
|
+
- Fixed test cases for code generator (100% coverage)
|
|
16
|
+
- Added support for colorizing sprites
|
|
17
|
+
- Removed before setup and setup lifecycle events and optimized lifecycle instance in components
|
|
18
|
+
- Added support for (re)assigning an array used in a for-loop
|
|
19
|
+
- Refactored delay of transitions (using the now available built-in delay in the renderer)
|
|
20
|
+
- Added preliminary support for frameTick hook
|
|
21
|
+
- Upgraded to latest version of the renderer (0.7.4)
|
|
22
|
+
|
|
3
23
|
# v0.7.0
|
|
4
24
|
|
|
25
|
+
_20 feb 2024_
|
|
26
|
+
|
|
27
|
+
|
|
5
28
|
- Added support for dynamic components through the `is`-attribute (`<Component is="Poster" />` or `<Component is="$dynamicComponent" />`)
|
|
6
29
|
- Added functionality to pass extra data / props when navigating to a new route ( _breaking change_ in signature of `router.to()` method - previously: `router.to(path, options)`, now: `router.to(path, data, options)`)
|
|
7
30
|
- Added configuration option to set the canvas color (aka clear color)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightningjs/blits",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "Blits: The Lightning 3 App Development Framework",
|
|
5
5
|
"bin": "bin/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"tape": "^5.5.0"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@lightningjs/renderer": "^0.7.
|
|
48
|
+
"@lightningjs/renderer": "^0.7.4",
|
|
49
49
|
"@lightningjs/vite-plugin-import-chunk-url": "^0.3.0",
|
|
50
50
|
"execa": "^8.0.1",
|
|
51
51
|
"kolorist": "^1.8.0",
|
package/src/component.d.ts
CHANGED
|
@@ -124,7 +124,13 @@ declare namespace Component {
|
|
|
124
124
|
/**
|
|
125
125
|
* Fires when the Component is being destroyed and removed.
|
|
126
126
|
*/
|
|
127
|
-
destroy?: (this: ComponentInstance) => void
|
|
127
|
+
destroy?: (this: ComponentInstance) => void,
|
|
128
|
+
/**
|
|
129
|
+
* Fires upon each frame start (allowing you to tap directly into the renderloop)
|
|
130
|
+
*
|
|
131
|
+
* Note: This hook will fire continuously, multiple times per second!
|
|
132
|
+
*/
|
|
133
|
+
frameTick?: (this: ComponentInstance) => void
|
|
128
134
|
}
|
|
129
135
|
|
|
130
136
|
export interface ComponentInstance {
|
|
@@ -142,9 +148,9 @@ declare namespace Component {
|
|
|
142
148
|
* Set a timeout that is automatically cleaned upon component destroy
|
|
143
149
|
*/
|
|
144
150
|
$setTimeout: (callback: (args: any) => void, ms?: number | undefined) => ReturnType<typeof setTimeout>
|
|
145
|
-
|
|
151
|
+
|
|
146
152
|
/**
|
|
147
|
-
* Clear a timeout
|
|
153
|
+
* Clear a timeout
|
|
148
154
|
*/
|
|
149
155
|
$clearTimeout: (id: ReturnType<typeof setTimeout>) => void
|
|
150
156
|
|
|
@@ -152,12 +158,12 @@ declare namespace Component {
|
|
|
152
158
|
* Set an interval that is automatically cleaned upon component destroy
|
|
153
159
|
*/
|
|
154
160
|
$setInterval: (callback: (args: any) => void, ms?: number | undefined) => ReturnType<typeof setInterval>
|
|
155
|
-
|
|
161
|
+
|
|
156
162
|
/**
|
|
157
|
-
* Clear a interval
|
|
163
|
+
* Clear a interval
|
|
158
164
|
*/
|
|
159
165
|
$clearInterval: (id: ReturnType<typeof setInterval>) => void
|
|
160
|
-
|
|
166
|
+
|
|
161
167
|
/**
|
|
162
168
|
* Log to the console with prettier output and configurable debug levels in Settings
|
|
163
169
|
*/
|
package/src/component.js
CHANGED
|
@@ -19,9 +19,10 @@ import parser from './lib/templateparser/parser.js'
|
|
|
19
19
|
import codegenerator from './lib/codegenerator/generator.js'
|
|
20
20
|
|
|
21
21
|
import element from './element.js'
|
|
22
|
+
import { renderer } from './launch.js'
|
|
22
23
|
|
|
23
24
|
import { createHumanReadableId, createInternalId } from './lib/componentId.js'
|
|
24
|
-
import { registerHooks, emit
|
|
25
|
+
import { registerHooks, emit } from './lib/hooks.js'
|
|
25
26
|
|
|
26
27
|
import { reactive } from './lib/reactivity/reactive.js'
|
|
27
28
|
import setupBase from './lib/setup/base.js'
|
|
@@ -34,6 +35,7 @@ import setupRoutes from './lib/setup/routes.js'
|
|
|
34
35
|
import setupWatch from './lib/setup/watch.js'
|
|
35
36
|
import { effect } from './lib/reactivity/effect.js'
|
|
36
37
|
import { Log } from './lib/log.js'
|
|
38
|
+
import lifecycle from './lib/lifecycle.js'
|
|
37
39
|
|
|
38
40
|
import Settings from './settings.js'
|
|
39
41
|
import symbols from './lib/symbols.js'
|
|
@@ -47,18 +49,17 @@ const required = (name) => {
|
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
const Component = (name = required('name'), config = required('config')) => {
|
|
50
|
-
const setupComponent = (
|
|
52
|
+
const setupComponent = (parentComponent) => {
|
|
51
53
|
// code generation
|
|
52
54
|
if (!config.code) {
|
|
53
55
|
Log.debug(`Generating code for ${name} component`)
|
|
54
56
|
config.code = codegenerator.call(config, parser(config.template, name, parentComponent))
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
setupBase(component)
|
|
59
|
+
setupBase(component, name)
|
|
58
60
|
|
|
59
61
|
// setup hooks
|
|
60
62
|
registerHooks(config.hooks, name)
|
|
61
|
-
lifecycle.state = 'beforeSetup'
|
|
62
63
|
|
|
63
64
|
// setup props
|
|
64
65
|
// if (config.props) // because of the default props like id - might change this
|
|
@@ -83,37 +84,20 @@ const Component = (name = required('name'), config = required('config')) => {
|
|
|
83
84
|
if (config.input) setupInput(component, config.input)
|
|
84
85
|
|
|
85
86
|
component.setup = true
|
|
86
|
-
lifecycle.state = 'setup'
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return {
|
|
89
|
+
const component = function (opts, parentEl, parentComponent) {
|
|
90
|
+
this.lifecycle = Object.assign(Object.create(lifecycle), {
|
|
91
|
+
component: this,
|
|
93
92
|
previous: null,
|
|
94
93
|
current: null,
|
|
95
|
-
|
|
96
|
-
return this.current
|
|
97
|
-
},
|
|
98
|
-
set state(v) {
|
|
99
|
-
if (states.indexOf(v) > -1 && v !== this.current) {
|
|
100
|
-
Log.debug(`Setting lifecycle state from ${this.current} to ${v} for ${scope.componentId}`)
|
|
101
|
-
this.previous = this.current
|
|
102
|
-
this.current = v
|
|
103
|
-
// emit 'private' hook
|
|
104
|
-
privateEmit(v, name, scope)
|
|
105
|
-
// emit 'public' hook
|
|
106
|
-
emit(v, name, scope)
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const component = function (opts, parentEl, parentComponent) {
|
|
113
|
-
this.lifecycle = createLifecycle(this)
|
|
94
|
+
})
|
|
114
95
|
|
|
115
96
|
if (!component.setup) {
|
|
116
|
-
setupComponent(
|
|
97
|
+
setupComponent(parentComponent)
|
|
98
|
+
}
|
|
99
|
+
if (config.hooks && config.hooks.frameTick) {
|
|
100
|
+
renderer.on('frameTick', (r, data) => emit('frameTick', name, this, [data]))
|
|
117
101
|
}
|
|
118
102
|
|
|
119
103
|
this.parent = parentComponent
|
package/src/components/Sprite.js
CHANGED
|
@@ -44,10 +44,13 @@ export default () =>
|
|
|
44
44
|
function anonymous(component, elms, context) {
|
|
45
45
|
elms[0].set('texture', component.texture)
|
|
46
46
|
},
|
|
47
|
+
function anonymous(component, elms, context) {
|
|
48
|
+
elms[0].set('color', component.color)
|
|
49
|
+
},
|
|
47
50
|
],
|
|
48
51
|
context: {},
|
|
49
52
|
},
|
|
50
|
-
props: ['image', 'map', 'frame', 'w', 'h'],
|
|
53
|
+
props: ['image', 'map', 'frame', 'w', 'h', 'color'],
|
|
51
54
|
state() {
|
|
52
55
|
return {
|
|
53
56
|
spriteTexture: false,
|
|
@@ -22,9 +22,9 @@ import symbols from '../lib/symbols.js'
|
|
|
22
22
|
export default () =>
|
|
23
23
|
Component('Sprite', {
|
|
24
24
|
template: `
|
|
25
|
-
<Element w="$w" h="$h" :texture="$texture" />
|
|
25
|
+
<Element w="$w" h="$h" :texture="$texture" :color="$color" />
|
|
26
26
|
`,
|
|
27
|
-
props: ['image', 'map', 'frame', 'w', 'h'],
|
|
27
|
+
props: ['image', 'map', 'frame', 'w', 'h', 'color'],
|
|
28
28
|
state() {
|
|
29
29
|
return {
|
|
30
30
|
spriteTexture: false,
|
package/src/element.js
CHANGED
|
@@ -304,39 +304,44 @@ const Element = {
|
|
|
304
304
|
? transition.function
|
|
305
305
|
: 'ease'
|
|
306
306
|
: 'ease',
|
|
307
|
+
delay: typeof transition === 'object' ? ('delay' in transition ? transition.delay : 0) : 0,
|
|
307
308
|
})
|
|
308
309
|
|
|
309
310
|
// schedule transition
|
|
310
311
|
return new Promise((resolve) => {
|
|
312
|
+
const startValue = this.node[prop]
|
|
311
313
|
this.scheduledTransitions[prop] = {
|
|
312
314
|
v: props[prop],
|
|
313
|
-
f
|
|
314
|
-
timeout: setTimeout(() => {
|
|
315
|
-
// fire transition start callback if specified
|
|
316
|
-
transition.start &&
|
|
317
|
-
typeof transition.start === 'function' &&
|
|
318
|
-
transition.start.call(this.component, this, prop, props[prop])
|
|
319
|
-
|
|
320
|
-
// start the animation
|
|
315
|
+
f: () => {
|
|
321
316
|
try {
|
|
322
317
|
f.start()
|
|
323
|
-
.
|
|
324
|
-
.then(() =>
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
318
|
+
.waitUntilStarted()
|
|
319
|
+
.then((animation) => {
|
|
320
|
+
// fire transition start callback if specified
|
|
321
|
+
transition.start &&
|
|
322
|
+
typeof transition.start === 'function' &&
|
|
323
|
+
transition.start.call(this.component, this, prop, startValue)
|
|
324
|
+
// continue the chain
|
|
325
|
+
animation
|
|
326
|
+
.waitUntilStopped()
|
|
327
|
+
.then(() => delete this.scheduledTransitions[prop])
|
|
328
|
+
.then(() => {
|
|
329
|
+
// fire transition end callback if specified
|
|
330
|
+
transition.end &&
|
|
331
|
+
typeof transition.end === 'function' &&
|
|
332
|
+
transition.end.call(this.component, this, prop, this.node[prop])
|
|
333
|
+
})
|
|
334
|
+
.then(resolve)
|
|
330
335
|
})
|
|
331
|
-
.then(resolve)
|
|
332
336
|
} catch (e) {
|
|
333
337
|
Log.error(e)
|
|
334
338
|
}
|
|
335
|
-
},
|
|
339
|
+
},
|
|
336
340
|
}
|
|
341
|
+
this.scheduledTransitions[prop].f()
|
|
337
342
|
})
|
|
338
343
|
},
|
|
339
|
-
|
|
344
|
+
destroy() {
|
|
340
345
|
Log.debug('Deleting Node', this.nodeId)
|
|
341
346
|
Object.values(this.scheduledTransitions).forEach((scheduledTransition) => {
|
|
342
347
|
clearTimeout(scheduledTransition.timeout)
|
package/src/launch.d.ts
CHANGED
|
@@ -172,6 +172,15 @@ export interface Settings {
|
|
|
172
172
|
*
|
|
173
173
|
*/
|
|
174
174
|
canvasColor?: string,
|
|
175
|
+
/**
|
|
176
|
+
* Enable inspector
|
|
177
|
+
*
|
|
178
|
+
* Enables the inspector tool for debugging and inspecting the application, the node tree
|
|
179
|
+
* will be replicated in the DOM and can be inspected using the browser's developer tools
|
|
180
|
+
*
|
|
181
|
+
* Defaults to `false`
|
|
182
|
+
*/
|
|
183
|
+
inspector?: boolean
|
|
175
184
|
}
|
|
176
185
|
|
|
177
186
|
/**
|
package/src/launch.js
CHANGED
|
@@ -52,6 +52,7 @@ export default (App, target, settings) => {
|
|
|
52
52
|
? settings.webWorkersLimit
|
|
53
53
|
: window.navigator.hardwareConcurrency || 2,
|
|
54
54
|
clearColor: (settings.canvasColor && colors.normalize(settings.canvasColor)) || 0x00000000,
|
|
55
|
+
enableInspector: settings.inspector || false,
|
|
55
56
|
},
|
|
56
57
|
target,
|
|
57
58
|
driver
|