@lightningjs/blits 0.5.5 → 0.5.7
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/.vscode/settings.json +1 -1
- package/CHANGELOG.md +14 -0
- package/boilerplate/package.json +1 -1
- package/package.json +2 -2
- package/src/component.js +3 -2
- package/src/components/RouterView.js +5 -0
- package/src/launch.d.ts +6 -1
- package/src/launch.js +3 -3
- package/src/lib/reactivity/reactive.js +19 -11
- package/src/lib/setup/base.js +8 -12
- package/src/router/router.js +13 -0
- package/src/router.js +0 -72
package/.vscode/settings.json
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
# v0.5.7
|
|
4
|
+
|
|
5
|
+
_13 dec 2023_
|
|
6
|
+
|
|
7
|
+
- Added history and backhandling to the router
|
|
8
|
+
- Linked effects directly to the available shaders exposed by the L3 renderer (starting 0.6.0)
|
|
9
|
+
- Added setting `reactivityMode` to control whether `Proxy` (default) or `defineProperty` is used to trigger reactive side effects
|
|
10
|
+
|
|
11
|
+
# v0.5.6
|
|
12
|
+
|
|
13
|
+
_11 dec 2023_
|
|
14
|
+
|
|
15
|
+
- Upgraded to version 0.6.0 of the Lightning 3 renderer
|
|
16
|
+
|
|
3
17
|
# v0.5.5
|
|
4
18
|
|
|
5
19
|
_5 dec 2023_
|
package/boilerplate/package.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightningjs/blits",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.7",
|
|
4
4
|
"description": "Blits: The Lightning 3 App Development Framework",
|
|
5
5
|
"bin": "bin/index.cjs",
|
|
6
6
|
"exports": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"tape": "^5.5.0"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@lightningjs/renderer": "^0.
|
|
45
|
+
"@lightningjs/renderer": "^0.6.0",
|
|
46
46
|
"@lightningjs/vite-plugin-import-chunk-url": "^0.3.0"
|
|
47
47
|
}
|
|
48
48
|
}
|
package/src/component.js
CHANGED
|
@@ -35,6 +35,7 @@ import setupWatch from './lib/setup/watch.js'
|
|
|
35
35
|
import { effect } from './lib/reactivity/effect.js'
|
|
36
36
|
import { Log } from './lib/log.js'
|
|
37
37
|
|
|
38
|
+
import Settings from './settings.js'
|
|
38
39
|
import symbols from './lib/symbols.js'
|
|
39
40
|
|
|
40
41
|
const stage = {
|
|
@@ -142,7 +143,7 @@ const Component = (name = required('name'), config = required('config')) => {
|
|
|
142
143
|
configurable: false,
|
|
143
144
|
},
|
|
144
145
|
[symbols.props]: {
|
|
145
|
-
value: reactive(opts.props || {}),
|
|
146
|
+
value: reactive(opts.props || {}, Settings.get('reactivityMode')),
|
|
146
147
|
writable: false,
|
|
147
148
|
enumerable: false,
|
|
148
149
|
configurable: false,
|
|
@@ -157,7 +158,7 @@ const Component = (name = required('name'), config = required('config')) => {
|
|
|
157
158
|
})
|
|
158
159
|
|
|
159
160
|
Object.defineProperty(this, symbols.state, {
|
|
160
|
-
value: reactive(this[symbols.originalState]),
|
|
161
|
+
value: reactive(this[symbols.originalState], Settings.get('reactivityMode')),
|
|
161
162
|
writable: false,
|
|
162
163
|
enumerable: false,
|
|
163
164
|
configurable: false,
|
package/src/launch.d.ts
CHANGED
|
@@ -55,6 +55,7 @@ type Font = WebFont | SdfFont
|
|
|
55
55
|
|
|
56
56
|
export type DebugLevel = 0 | 1 | 2
|
|
57
57
|
export type LogTypes = 'info' | 'warn' | 'error' | 'debug'
|
|
58
|
+
export type ReactivityModes = 'Proxy' | 'defineProperty'
|
|
58
59
|
|
|
59
60
|
/**
|
|
60
61
|
* Settings
|
|
@@ -90,7 +91,11 @@ export interface Settings {
|
|
|
90
91
|
/**
|
|
91
92
|
* Custom keymapping
|
|
92
93
|
*/
|
|
93
|
-
keymap?: object
|
|
94
|
+
keymap?: object,
|
|
95
|
+
/**
|
|
96
|
+
* Mode of reactivity (`Proxy` or `defineProperty`)
|
|
97
|
+
*/
|
|
98
|
+
reactivityMode?: ReactivityModes
|
|
94
99
|
}
|
|
95
100
|
|
|
96
101
|
/**
|
package/src/launch.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* SPDX-License-Identifier: Apache-2.0
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import {
|
|
18
|
+
import { MainCoreDriver, RendererMain } from '@lightningjs/renderer'
|
|
19
19
|
// import RendererWorker from '@lightningjs/renderer/workers/renderer?worker'
|
|
20
20
|
import Settings from './settings.js'
|
|
21
21
|
import { initLog, Log } from './lib/log.js'
|
|
@@ -29,12 +29,12 @@ export default (App, target, settings) => {
|
|
|
29
29
|
|
|
30
30
|
initLog()
|
|
31
31
|
|
|
32
|
-
const driver = new
|
|
32
|
+
const driver = new MainCoreDriver()
|
|
33
33
|
// settings.multithreaded === true
|
|
34
34
|
// ? new ThreadXRenderDriver({
|
|
35
35
|
// RendererWorker,
|
|
36
36
|
// })
|
|
37
|
-
// : new
|
|
37
|
+
// : new MainCoreDriver()
|
|
38
38
|
|
|
39
39
|
renderer = new RendererMain(
|
|
40
40
|
{
|
|
@@ -27,8 +27,12 @@ const arrayMethods = [
|
|
|
27
27
|
'shift',
|
|
28
28
|
'splice',
|
|
29
29
|
'unshift',
|
|
30
|
+
'sort',
|
|
31
|
+
'reverse',
|
|
30
32
|
]
|
|
31
33
|
|
|
34
|
+
const arrayPatchMethods = ['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse']
|
|
35
|
+
|
|
32
36
|
const proxyMap = new WeakMap()
|
|
33
37
|
|
|
34
38
|
const reactiveProxy = (target) => {
|
|
@@ -79,17 +83,22 @@ const reactiveDefineProperty = (target) => {
|
|
|
79
83
|
Object.keys(target).forEach((key) => {
|
|
80
84
|
let internalValue = target[key]
|
|
81
85
|
|
|
82
|
-
if (
|
|
83
|
-
target[key]
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
if (target[key] !== null && typeof target[key] === 'object') {
|
|
87
|
+
if (Object.getPrototypeOf(target[key]) === Object.prototype) {
|
|
88
|
+
return reactiveDefineProperty(target[key])
|
|
89
|
+
} else if (Array.isArray(target[key])) {
|
|
90
|
+
for (let i = 0; i < arrayPatchMethods.length - 1; i++) {
|
|
91
|
+
target[key][arrayPatchMethods[i]] = function (v) {
|
|
92
|
+
Array.prototype[arrayPatchMethods[i]].call(this, v)
|
|
93
|
+
trigger(target, key)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
88
97
|
}
|
|
89
98
|
|
|
90
99
|
Object.defineProperty(target, key, {
|
|
91
|
-
enumerable: true,
|
|
92
|
-
configurable: true,
|
|
100
|
+
enumerable: true,
|
|
101
|
+
configurable: true,
|
|
93
102
|
get() {
|
|
94
103
|
track(target, key)
|
|
95
104
|
return internalValue
|
|
@@ -107,9 +116,8 @@ const reactiveDefineProperty = (target) => {
|
|
|
107
116
|
return target
|
|
108
117
|
}
|
|
109
118
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return type === 'proxy' ? reactiveProxy(target) : reactiveDefineProperty(target)
|
|
119
|
+
export const reactive = (target, mode = 'Proxy') => {
|
|
120
|
+
return mode === 'defineProperty' ? reactiveDefineProperty(target) : reactiveProxy(target)
|
|
113
121
|
}
|
|
114
122
|
|
|
115
123
|
export const memo = (raw) => {
|
package/src/lib/setup/base.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import { renderer } from '../../launch.js'
|
|
19
19
|
import Focus from '../../focus.js'
|
|
20
|
-
import { to, currentRoute, navigating } from '../../router/router.js'
|
|
20
|
+
import { to, currentRoute, navigating, back } from '../../router/router.js'
|
|
21
21
|
import Image from '../../components/Image.js'
|
|
22
22
|
import Circle from '../../components/Circle.js'
|
|
23
23
|
import RouterView from '../../components/RouterView.js'
|
|
@@ -29,16 +29,8 @@ import symbols from '../symbols.js'
|
|
|
29
29
|
|
|
30
30
|
import { trigger } from '../reactivity/effect.js'
|
|
31
31
|
|
|
32
|
-
const
|
|
33
|
-
radius: 'radius',
|
|
32
|
+
const shaderAlias = {
|
|
34
33
|
rounded: 'radius',
|
|
35
|
-
border: 'border',
|
|
36
|
-
borderTop: 'borderTop',
|
|
37
|
-
borderBottom: 'borderBottom',
|
|
38
|
-
borderLeft: 'borderLeft',
|
|
39
|
-
borderRight: 'borderRight',
|
|
40
|
-
grayScale: 'grayscale',
|
|
41
|
-
glitch: 'glitch',
|
|
42
34
|
}
|
|
43
35
|
|
|
44
36
|
export default (component) => {
|
|
@@ -101,9 +93,12 @@ export default (component) => {
|
|
|
101
93
|
},
|
|
102
94
|
shader: {
|
|
103
95
|
value: function (type, args) {
|
|
104
|
-
|
|
96
|
+
const target = shaderAlias[type] || type
|
|
97
|
+
const shaders = renderer.driver.stage.shManager.getRegisteredEffects()
|
|
98
|
+
|
|
99
|
+
if (target in shaders) {
|
|
105
100
|
return {
|
|
106
|
-
type:
|
|
101
|
+
type: target,
|
|
107
102
|
props: args,
|
|
108
103
|
}
|
|
109
104
|
} else {
|
|
@@ -117,6 +112,7 @@ export default (component) => {
|
|
|
117
112
|
$router: {
|
|
118
113
|
value: {
|
|
119
114
|
to,
|
|
115
|
+
back,
|
|
120
116
|
get currentRoute() {
|
|
121
117
|
return currentRoute
|
|
122
118
|
},
|
package/src/router/router.js
CHANGED
|
@@ -26,6 +26,7 @@ export let currentRoute
|
|
|
26
26
|
export let navigating = false
|
|
27
27
|
|
|
28
28
|
const cacheMap = new WeakMap()
|
|
29
|
+
const history = []
|
|
29
30
|
|
|
30
31
|
export const getHash = () => {
|
|
31
32
|
return (document.location.hash || '/').replace(/^#/, '')
|
|
@@ -49,6 +50,7 @@ export const navigate = async function () {
|
|
|
49
50
|
const route = matchHash(hash, this.parent[symbols.routes])
|
|
50
51
|
|
|
51
52
|
if (route) {
|
|
53
|
+
if (history[history.length - 1] !== hash) history.push(hash)
|
|
52
54
|
// apply default transition if none specified
|
|
53
55
|
if (!('transition' in route)) {
|
|
54
56
|
route.transition = fadeInFadeOutTransition
|
|
@@ -171,7 +173,18 @@ export const to = (location) => {
|
|
|
171
173
|
window.location.hash = `#${location}`
|
|
172
174
|
}
|
|
173
175
|
|
|
176
|
+
export const back = () => {
|
|
177
|
+
if (history.length > 1) {
|
|
178
|
+
to(history[history.length - 2])
|
|
179
|
+
history.splice(-2, 2)
|
|
180
|
+
return true
|
|
181
|
+
} else {
|
|
182
|
+
return false
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
174
186
|
export default {
|
|
175
187
|
navigate,
|
|
176
188
|
to,
|
|
189
|
+
back,
|
|
177
190
|
}
|
package/src/router.js
DELETED
|
@@ -1,72 +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 { Log } from './lib/log.js'
|
|
19
|
-
|
|
20
|
-
import symbols from './lib/symbols.js'
|
|
21
|
-
|
|
22
|
-
export const getHash = () => {
|
|
23
|
-
return (document.location.hash || '/').replace(/^#/, '')
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const matchHash = (path, routes = []) => {
|
|
27
|
-
const route = routes
|
|
28
|
-
.filter((r) => {
|
|
29
|
-
return r.path === path
|
|
30
|
-
})
|
|
31
|
-
.pop()
|
|
32
|
-
return route
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export const navigate = function () {
|
|
36
|
-
if (this.parent[symbols.routes]) {
|
|
37
|
-
const hash = getHash()
|
|
38
|
-
const route = matchHash(hash, this.parent[symbols.routes])
|
|
39
|
-
if (route) {
|
|
40
|
-
if (this[symbols.currentView]) {
|
|
41
|
-
for (let i = 0; i < this[symbols.currentView][symbols.children].length - 1; i++) {
|
|
42
|
-
if (
|
|
43
|
-
this[symbols.currentView][symbols.children][i] &&
|
|
44
|
-
this[symbols.currentView][symbols.children][i].destroy
|
|
45
|
-
) {
|
|
46
|
-
this[symbols.currentView][symbols.children][i].destroy()
|
|
47
|
-
this[symbols.currentView][symbols.children][i] = null
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
this[symbols.currentView].destroy()
|
|
51
|
-
this[symbols.currentView] = null
|
|
52
|
-
}
|
|
53
|
-
this[symbols.children][1] = this[symbols.currentView] = route.component(
|
|
54
|
-
this[symbols.props],
|
|
55
|
-
this[symbols.children][0],
|
|
56
|
-
this
|
|
57
|
-
)
|
|
58
|
-
this[symbols.currentView].focus()
|
|
59
|
-
} else {
|
|
60
|
-
Log.error(`Route ${hash} not found`)
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export const to = (location) => {
|
|
66
|
-
window.location.hash = `#${location}`
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export default {
|
|
70
|
-
navigate,
|
|
71
|
-
to,
|
|
72
|
-
}
|