@lightningjs/blits 2.0.0-beta.1 → 2.0.0-beta.11

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/README.md +2 -0
  3. package/element-test-full.txt +0 -0
  4. package/index.d.ts +169 -41
  5. package/package.json +28 -8
  6. package/scripts/lint.js +17 -0
  7. package/scripts/prepublishOnly.js +15 -6
  8. package/scripts/prepush.js +25 -7
  9. package/src/announcer/announcer.js +54 -6
  10. package/src/announcer/speechSynthesis.js +156 -37
  11. package/src/application.js +98 -3
  12. package/src/component/base/methods.js +5 -2
  13. package/src/component/base/router.js +6 -0
  14. package/src/component/base/timeouts_intervals.js +56 -0
  15. package/src/component/setup/routes.js +5 -0
  16. package/src/component/setup/state.js +2 -0
  17. package/src/component.js +64 -24
  18. package/src/components/Circle.js +5 -3
  19. package/src/components/FPScounter.js +1591 -1577
  20. package/src/components/RouterView.js +141 -124
  21. package/src/components/Sprite.js +65 -8
  22. package/src/components/index.js +0 -2
  23. package/src/constants.js +17 -0
  24. package/src/engine.js +17 -0
  25. package/src/engines/L3/element.js +101 -7
  26. package/src/engines/L3/fontLoader.js +17 -0
  27. package/src/engines/L3/index.js +17 -0
  28. package/src/engines/L3/launch.js +4 -1
  29. package/src/engines/L3/shaderLoader.js +17 -0
  30. package/src/engines/index.js +17 -0
  31. package/src/{focus.js → focus/focus.js} +6 -18
  32. package/src/focus/helpers.js +31 -0
  33. package/src/focus/hover.js +94 -0
  34. package/src/helpers/fetchJson.js +4 -6
  35. package/src/launch.js +1 -0
  36. package/src/lib/codegenerator/generator.js +55 -9
  37. package/src/lib/lifecycle.js +34 -3
  38. package/src/lib/log.js +4 -4
  39. package/src/lib/precompiler/precompiler.js +23 -14
  40. package/src/lib/reactivity/effect.js +3 -2
  41. package/src/lib/reactivityguard/computedprops.js +113 -28
  42. package/src/lib/shaders/shaders.js +2 -1
  43. package/src/lib/symbols.js +19 -0
  44. package/src/lib/utils.js +17 -0
  45. package/src/plugin.js +17 -0
  46. package/src/plugins/appstate.d.ts +26 -0
  47. package/src/plugins/index.d.ts +28 -0
  48. package/src/plugins/language.d.ts +37 -0
  49. package/src/plugins/storage/localCookie.js +4 -6
  50. package/src/plugins/storage/storage.d.ts +31 -0
  51. package/src/plugins/theme.d.ts +43 -0
  52. package/src/plugins/theme.js +30 -3
  53. package/src/router/router.js +78 -14
  54. package/test-output.txt +0 -0
  55. package/vite/inject-dev-config.js +17 -0
  56. package/vite/preCompiler.js +15 -5
  57. package/vscode/data/template-attributes.json +335 -86
package/src/component.js CHANGED
@@ -43,6 +43,9 @@ const required = (name) => {
43
43
  throw new Error(`Parameter ${name} is required`)
44
44
  }
45
45
 
46
+ // map that holds component to their holder node
47
+ export const componentMap = new WeakMap()
48
+
46
49
  /**
47
50
  * @typedef {function} BlitsComponentFactory
48
51
  * @param {object} opts - The options for the component instance
@@ -217,6 +220,10 @@ const Component = (name = required('name'), config = required('config')) => {
217
220
  // such as rotation and scale to components)
218
221
  this[symbols.holder] = parentEl
219
222
 
223
+ if (parentEl !== undefined && parentEl.node !== undefined) {
224
+ componentMap.set(parentEl.node, this)
225
+ }
226
+
220
227
  // generate an internal id (simple counter)
221
228
  this[symbols.id] = createInternalId()
222
229
 
@@ -229,6 +236,9 @@ const Component = (name = required('name'), config = required('config')) => {
229
236
  // create an empty array for storing intervals created by this component (via this.$setInterval)
230
237
  this[symbols.intervals] = []
231
238
 
239
+ // create a Map for storing debounced functions (via this.$debounce)
240
+ this[symbols.debounces] = new Map()
241
+
232
242
  // apply the state function (passing in the this reference to utilize configured props)
233
243
  // and store a reference to this original state
234
244
  this[symbols.originalState] =
@@ -236,6 +246,9 @@ const Component = (name = required('name'), config = required('config')) => {
236
246
  // add $hasFocus key in
237
247
  this[symbols.originalState]['$hasFocus'] = false
238
248
 
249
+ // add $isHovered key in
250
+ this[symbols.originalState]['$isHovered'] = false
251
+
239
252
  // generate a reactive state (using the result of previously execute state function)
240
253
  // and store it
241
254
  this[symbols.state] = reactive(this[symbols.originalState], Settings.get('reactivityMode'))
@@ -265,35 +278,59 @@ const Component = (name = required('name'), config = required('config')) => {
265
278
  this[symbols.slots] = this[symbols.children].filter((child) => child[symbols.isSlot])
266
279
 
267
280
  this[symbols.rendererEventListeners] = []
281
+
282
+ if (this[symbols.holder] !== undefined && Settings.get('inspector', false)) {
283
+ this[symbols.holder].setInspectorMetadata({ 'blits-hasFocus': false })
284
+ }
285
+
286
+ // setup inspector data for render state
287
+ if (name === 'App' && Settings.get('inspector', false)) {
288
+ this.$setTimeout(() => {
289
+ const wrapperEl = this[symbols.wrapper]
290
+ const idleCb = () => {
291
+ wrapperEl.setInspectorMetadata({ 'blits-renderState': 'idle' })
292
+ }
293
+ const activeCb = () => {
294
+ wrapperEl.setInspectorMetadata({ 'blits-renderState': 'active' })
295
+ }
296
+ renderer.on('idle', idleCb)
297
+ renderer.on('active', activeCb)
298
+ this[symbols.rendererEventListeners].push({ event: 'idle', cb: idleCb })
299
+ this[symbols.rendererEventListeners].push({ event: 'active', cb: activeCb })
300
+ })
301
+ }
302
+
268
303
  // register hooks if component has hooks specified
269
304
  if (config.hooks) {
270
- // push to next tick to ensure
271
- setTimeout(() => {
272
- // frame tick event
273
- if (config.hooks.frameTick) {
274
- const cb = (r, data) => emit('frameTick', this[symbols.identifier], this, [data])
275
- this[symbols.rendererEventListeners].push({ event: 'frameTick', cb })
276
- renderer.on('frameTick', cb)
277
- }
305
+ // frame tick event
306
+ if (config.hooks.frameTick) {
307
+ const cb = (_r, data) => emit('frameTick', this[symbols.identifier], this, [data])
308
+ renderer.on('frameTick', cb)
309
+ this[symbols.rendererEventListeners].push({ event: 'frameTick', cb })
310
+ }
278
311
 
279
- // idle event
280
- if (config.hooks.idle) {
281
- const cb = () => {
282
- emit('idle', this[symbols.identifier], this)
283
- }
284
- this[symbols.rendererEventListeners].push({ event: 'idle', cb })
285
- renderer.on('idle', cb)
312
+ // idle event
313
+ if (config.hooks.idle) {
314
+ const idleCb = () => {
315
+ emit('idle', this[symbols.identifier], this, [true])
316
+ }
317
+ const activeCb = () => {
318
+ emit('idle', this[symbols.identifier], this, [false])
286
319
  }
320
+ renderer.on('idle', idleCb)
321
+ renderer.on('active', activeCb)
322
+ this[symbols.rendererEventListeners].push({ event: 'idle', cb: idleCb })
323
+ this[symbols.rendererEventListeners].push({ event: 'active', cb: activeCb })
324
+ }
287
325
 
288
- // fpsUpdate event
289
- if (config.hooks.fpsUpdate) {
290
- const cb = (r, data) => {
291
- emit('fpsUpdate', this[symbols.identifier], this, [data.fps])
292
- }
293
- this[symbols.rendererEventListeners].push({ event: 'fpsUpdate', cb })
294
- renderer.on('fpsUpdate', cb)
326
+ // fpsUpdate event
327
+ if (config.hooks.fpsUpdate) {
328
+ const cb = (_r, data) => {
329
+ emit('fpsUpdate', this[symbols.identifier], this, [data.fps])
295
330
  }
296
- })
331
+ renderer.on('fpsUpdate', cb)
332
+ this[symbols.rendererEventListeners].push({ event: 'fpsUpdate', cb })
333
+ }
297
334
 
298
335
  // inBounds event emiting a lifecycle attach event
299
336
  if (config.hooks.attach) {
@@ -361,7 +398,7 @@ const Component = (name = required('name'), config = required('config')) => {
361
398
  }
362
399
  }
363
400
 
364
- let old = this[key]
401
+ let old = target[key]
365
402
 
366
403
  const eff = (force = false) => {
367
404
  const newValue = target[key]
@@ -456,6 +493,9 @@ const Component = (name = required('name'), config = required('config')) => {
456
493
  // during the code generation step
457
494
  factory[Symbol.for('config')] = config
458
495
 
496
+ // Display name for inspector
497
+ factory[Symbol.for('componentType')] = name
498
+
459
499
  // To determine whether dynamic component is actual Blits component or not
460
500
  factory[symbols.isComponent] = true
461
501
 
@@ -63,6 +63,7 @@ export default () =>
63
63
  'content',
64
64
  'placement',
65
65
  'inspector-data',
66
+ 'holder',
66
67
  ]
67
68
  const elementConfigs = []
68
69
  const forloops = []
@@ -78,13 +79,14 @@ export default () =>
78
79
  let slotChildCounter = 0
79
80
  let cmps = []
80
81
  elementConfigs[0] = {}
82
+ elementConfigs[0]['___wrapper'] = true
81
83
 
82
84
  elms[0] = this.element(
83
85
  { parent: parent || 'root' },
84
86
  inSlot === true ? slotComponent : component
85
87
  )
86
88
 
87
- elementConfigs[0]['color'] = component.color
89
+ elementConfigs[0]['color'] = component.bgColor
88
90
  elementConfigs[0]['w'] = component.size
89
91
  elementConfigs[0]['h'] = component.size
90
92
  elementConfigs[0]['rounded'] = component.radius
@@ -115,7 +117,7 @@ export default () =>
115
117
  },
116
118
  effects: [
117
119
  function anonymous(component, elms, context, components, rootComponent, skips, effect) {
118
- elms[0].set('color', component.color)
120
+ elms[0].set('color', component.bgColor)
119
121
  },
120
122
  function anonymous(component, elms, context, components, rootComponent, skips, effect) {
121
123
  elms[0].set('w', component.size)
@@ -129,7 +131,7 @@ export default () =>
129
131
  ],
130
132
  context: {},
131
133
  },
132
- props: { size: 40, color: 'white' },
134
+ props: { size: 40, bgColor: 'white' },
133
135
  computed: {
134
136
  radius() {
135
137
  return this.size / 2