@lightningjs/blits 0.9.2 → 0.9.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ # v0.9.4
4
+
5
+ _28 mar 2024_
6
+
7
+ - Upgraded Lightning renderer to v0.8.0
8
+ - Fixed issue with reactivity in a forloop when initial array is empty
9
+ - Introduced new `gpuMemoryLimit` launch setting
10
+
11
+
12
+ # v0.9.3
13
+
14
+ _25 mar 2024_
15
+
16
+ - Added support for mount / pivot on Text elements and Sprites.
17
+
3
18
  # v0.9.2
4
19
 
5
20
  _21 mar 2024_
@@ -2,3 +2,9 @@
2
2
 
3
3
  ## Utilities
4
4
 
5
+ - focus()
6
+ - $router()
7
+ - select()
8
+ - parent
9
+ - Log
10
+ - setTimeout
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightningjs/blits",
3
- "version": "0.9.2",
3
+ "version": "0.9.4",
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.6",
48
+ "@lightningjs/renderer": "^0.8.0",
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.js CHANGED
@@ -18,8 +18,7 @@
18
18
  import parser from './lib/templateparser/parser.js'
19
19
  import codegenerator from './lib/codegenerator/generator.js'
20
20
 
21
- import element from './element.js'
22
- import { renderer } from './launch.js'
21
+ import { stage, renderer } from './launch.js'
23
22
 
24
23
  import { createHumanReadableId, createInternalId } from './lib/componentId.js'
25
24
  import { registerHooks, emit } from './lib/hooks.js'
@@ -42,10 +41,6 @@ import symbols from './lib/symbols.js'
42
41
 
43
42
  let counter = 0
44
43
 
45
- const stage = {
46
- element,
47
- }
48
-
49
44
  const required = (name) => {
50
45
  throw new Error(`Parameter ${name} is required`)
51
46
  }
@@ -31,8 +31,8 @@ export default () =>
31
31
  }
32
32
  const elementConfig0 = {}
33
33
 
34
- elementConfig0['w'] = component.w
35
- elementConfig0['h'] = component.h
34
+ elementConfig0['w'] = parent.node.width * (100 / 100)
35
+ elementConfig0['h'] = parent.node.height * (100 / 100)
36
36
 
37
37
  if (!elms[0].nodeId) {
38
38
  elms[0].populate(elementConfig0)
@@ -50,7 +50,7 @@ export default () =>
50
50
  ],
51
51
  context: {},
52
52
  },
53
- props: ['image', 'map', 'frame', 'w', 'h', 'color'],
53
+ props: ['image', 'map', 'frame', 'color'],
54
54
  state() {
55
55
  return {
56
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" :color="$color" />
25
+ <Element w="100%" h="100%" :texture="$texture" :color="$color" />
26
26
  `,
27
- props: ['image', 'map', 'frame', 'w', 'h', 'color'],
27
+ props: ['image', 'map', 'frame', 'color'],
28
28
  state() {
29
29
  return {
30
30
  spriteTexture: false,
package/src/engine.js ADDED
@@ -0,0 +1 @@
1
+ export { L3 as default } from './engines'
@@ -16,10 +16,10 @@
16
16
  */
17
17
 
18
18
  import { renderer } from './launch.js'
19
- import colors from './lib/colors/colors.js'
19
+ import colors from '../../lib/colors/colors.js'
20
20
 
21
- import { Log } from './lib/log.js'
22
- import symbols from './lib/symbols.js'
21
+ import { Log } from '../../lib/log.js'
22
+ import symbols from '../../lib/symbols.js'
23
23
 
24
24
  const deprecationMsg = `
25
25
  ----------------------------------------------------------------------------------------------------
@@ -275,6 +275,13 @@ const Element = {
275
275
  ? renderer.createTextNode(this.props._props)
276
276
  : renderer.createNode(this.props._props)
277
277
 
278
+ if (props.__textnode) {
279
+ this.node.on('loaded', (el, { dimensions }) => {
280
+ this.node.parent.width = dimensions.width
281
+ this.node.parent.height = dimensions.height
282
+ })
283
+ }
284
+
278
285
  if (props['@loaded']) {
279
286
  this.node.on('loaded', (el, { type, dimensions }) => {
280
287
  props['@loaded']({ w: dimensions.width, h: dimensions.height, type }, this)
@@ -1,6 +1,6 @@
1
1
  import { WebTrFontFace, SdfTrFontFace } from '@lightningjs/renderer/core'
2
2
 
3
- import Settings from './settings'
3
+ import Settings from '../../settings'
4
4
  import { renderer } from './launch'
5
5
 
6
6
  export default () => {
@@ -0,0 +1,7 @@
1
+ import Element from './element'
2
+ import Launch from './launch'
3
+
4
+ export default {
5
+ Element,
6
+ Launch,
7
+ }
@@ -0,0 +1,83 @@
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 { MainCoreDriver, RendererMain } from '@lightningjs/renderer'
19
+ // import RendererWorker from '@lightningjs/renderer/workers/renderer?worker'
20
+ import { Log } from '../../lib/log.js'
21
+ import { screenResolutions } from '../../lib/utils.js'
22
+ import colors from '../../lib/colors/colors.js'
23
+ import fontLoader from './fontLoader.js'
24
+
25
+ export let renderer
26
+
27
+ export default (App, target, settings) => {
28
+ const driver = new MainCoreDriver()
29
+ // settings.multithreaded === true
30
+ // ? new ThreadXRenderDriver({
31
+ // RendererWorker,
32
+ // })
33
+ // : new MainRenderDriver()
34
+
35
+ if ('fontLoader' in settings) {
36
+ Log.warn(
37
+ `
38
+
39
+ Starting version 0.9.0 of Blits, the Launch setting \`fontLoader\` is not supported / required anymore.
40
+ You can remove the option from your \`src/index.js\`-file. And you can safely remove the file \`src/fontLoader.js\` from your project.
41
+ `
42
+ )
43
+ }
44
+
45
+ renderer = new RendererMain(
46
+ {
47
+ appWidth: settings.w || 1920,
48
+ appHeight: settings.h || 1080,
49
+ fpsUpdateInterval: settings.fpsInterval || 1000,
50
+ deviceLogicalPixelRatio:
51
+ settings.pixelRatio ||
52
+ screenResolutions[settings.screenResolution] ||
53
+ screenResolutions[window.innerHeight] ||
54
+ 1,
55
+ numImageWorkers:
56
+ 'webWorkersLimit' in settings
57
+ ? settings.webWorkersLimit
58
+ : window.navigator.hardwareConcurrency || 2,
59
+ clearColor: (settings.canvasColor && colors.normalize(settings.canvasColor)) || 0x00000000,
60
+ enableInspector: settings.inspector || false,
61
+ boundsMargin: settings.viewportMargin || 0,
62
+ // gpu memory limit, converted from mb to bytes - defaults to 200mb
63
+ txMemByteThreshold:
64
+ 'gpuMemoryLimit' in settings ? settings.gpuMemoryLimit * 1024 * 1024 : 200 * 1024 * 1024,
65
+ },
66
+ target,
67
+ driver
68
+ )
69
+
70
+ const initApp = () => {
71
+ let app = App()
72
+ app.quit = () => {
73
+ Log.info('Closing App')
74
+ app.destroy()
75
+ app = null
76
+ renderer = null
77
+ }
78
+ }
79
+
80
+ renderer.init().then(fontLoader).then(initApp)
81
+
82
+ return renderer
83
+ }
@@ -0,0 +1 @@
1
+ export { default as L3 } from './L3'
package/src/launch.d.ts CHANGED
@@ -206,7 +206,17 @@ export interface Settings {
206
206
  *
207
207
  * Defaults to `0`
208
208
  */
209
- viewportMargin?: number | [number, number, number, number]
209
+ viewportMargin?: number | [number, number, number, number],
210
+ /**
211
+ * Threshold in `Megabytes` after which all the textures that are currently not visible
212
+ * within the configured viewport margin will be be freed and cleaned up
213
+ *
214
+ * When passed `0` the threshold is disabled and textures will not be actively freed
215
+ * and cleaned up
216
+ *
217
+ * Defaults to `200` (mb)
218
+ */
219
+ gpuMemoryLimit?: number
210
220
  }
211
221
 
212
222
  /**
package/src/launch.js CHANGED
@@ -15,69 +15,19 @@
15
15
  * SPDX-License-Identifier: Apache-2.0
16
16
  */
17
17
 
18
- import { MainCoreDriver, RendererMain } from '@lightningjs/renderer'
19
- // import RendererWorker from '@lightningjs/renderer/workers/renderer?worker'
20
18
  import Settings from './settings.js'
21
- import { initLog, Log } from './lib/log.js'
22
- import { screenResolutions } from './lib/utils.js'
23
- import colors from './lib/colors/colors.js'
24
- import fontLoader from './fontLoader.js'
19
+ import { initLog } from './lib/log.js'
20
+ import engine from './engine.js'
25
21
 
26
22
  export let renderer
23
+ export const stage = {}
27
24
 
28
25
  export default (App, target, settings) => {
29
26
  Settings.set(settings)
30
27
 
31
28
  initLog()
32
29
 
33
- const driver = new MainCoreDriver()
34
- // settings.multithreaded === true
35
- // ? new ThreadXRenderDriver({
36
- // RendererWorker,
37
- // })
38
- // : new MainCoreDriver()
30
+ stage.element = engine.Element
39
31
 
40
- if ('fontLoader' in settings) {
41
- Log.warn(
42
- `
43
-
44
- Starting version 0.9.0 of Blits, the Launch setting \`fontLoader\` is not supported / required anymore.
45
- You can remove the option from your \`src/index.js\`-file. And you can safely remove the file \`src/fontLoader.js\` from your project.
46
- `
47
- )
48
- }
49
-
50
- renderer = new RendererMain(
51
- {
52
- appWidth: settings.w || 1920,
53
- appHeight: settings.h || 1080,
54
- fpsUpdateInterval: settings.fpsInterval || 1000,
55
- deviceLogicalPixelRatio:
56
- settings.pixelRatio ||
57
- screenResolutions[settings.screenResolution] ||
58
- screenResolutions[window.innerHeight] ||
59
- 1,
60
- numImageWorkers:
61
- 'webWorkersLimit' in settings
62
- ? settings.webWorkersLimit
63
- : window.navigator.hardwareConcurrency || 2,
64
- clearColor: (settings.canvasColor && colors.normalize(settings.canvasColor)) || 0x00000000,
65
- enableInspector: settings.inspector || false,
66
- boundsMargin: settings.viewportMargin || 0,
67
- },
68
- target,
69
- driver
70
- )
71
-
72
- const initApp = () => {
73
- let app = App()
74
- app.quit = () => {
75
- Log.info('Closing App')
76
- app.destroy()
77
- app = null
78
- renderer = null
79
- }
80
- }
81
-
82
- renderer.init().then(fontLoader).then(initApp)
32
+ renderer = engine.Launch(App, target, settings)
83
33
  }
@@ -76,6 +76,7 @@ const generateElementCode = function (
76
76
  }
77
77
 
78
78
  if (isReactiveKey(key)) {
79
+ if (options.holder && key === ':color') return
79
80
  this.effectsCode.push(
80
81
  `${elm}.set('${key.substring(1)}', ${interpolate(templateObject[key], options.component)})`
81
82
  )
@@ -90,7 +91,7 @@ const generateElementCode = function (
90
91
  renderCode.push(`
91
92
  if(typeof cmp${counter} !== 'undefined') {
92
93
  for(let key in cmp${counter}.config.props) {
93
- delete elementConfig${counter}[cmp${counter}.config.props[key]]
94
+ delete elementConfig${counter}[cmp${counter}.config.props[key]]
94
95
  }
95
96
  }
96
97
  `)
@@ -218,6 +219,17 @@ const generateForLoopCode = function (templateObject, parent) {
218
219
  }
219
220
 
220
221
  const forCounter = counter
222
+
223
+ // reference all reactive attributes (except those referencing the iterator item),
224
+ // to ensure that reactivity is registered, even when the initial array is empty
225
+ Object.keys(templateObject).forEach((k) => {
226
+ if (isReactiveKey(k) && templateObject[k].indexOf('$' + item) === -1) {
227
+ ctx.renderCode.push(`
228
+ void ${interpolate(templateObject[k], 'component.')}
229
+ `)
230
+ }
231
+ })
232
+
221
233
  ctx.renderCode.push(`
222
234
  const collection = ${cast(result[2], ':for')} || []
223
235
  const keys = []
@@ -35,7 +35,7 @@ const shaderAlias = {
35
35
  rounded: 'radius',
36
36
  }
37
37
 
38
- export default (component, name, identifier) => {
38
+ export default (component, name) => {
39
39
  Object.defineProperties(component.prototype, {
40
40
  name: {
41
41
  value: name,
@@ -25,7 +25,7 @@ export default (component, computeds) => {
25
25
  for (let computed in computeds) {
26
26
  // test for reserved keys?
27
27
  if (component[symbols.stateKeys] && component[symbols.stateKeys].indexOf(computed) > -1) {
28
- Log.error(`${computed} already exists as a prop`)
28
+ Log.error(`${computed} already exists as a state variable`)
29
29
  } else if (component[symbols.propKeys] && component[symbols.propKeys].indexOf(computed) > -1) {
30
30
  Log.error(`${computed} already exists as a prop`)
31
31
  } else if (
@@ -19,7 +19,7 @@ import { default as fadeInFadeOutTransition } from './transitions/fadeInOut.js'
19
19
 
20
20
  import symbols from '../lib/symbols.js'
21
21
  import { Log } from '../lib/log.js'
22
- import Element from '../element.js'
22
+ import { stage } from '../launch.js'
23
23
  import Focus from '../focus.js'
24
24
  import Announcer from '../announcer/announcer.js'
25
25
 
@@ -130,7 +130,7 @@ export const navigate = async function () {
130
130
 
131
131
  if (!view) {
132
132
  // create a holder element for the new view
133
- holder = Element({ parent: this[symbols.children][0] })
133
+ holder = stage.element({ parent: this[symbols.children][0] })
134
134
  holder.populate({})
135
135
  holder.set('w', '100%')
136
136
  holder.set('h', '100%')