@lightningjs/blits 1.51.0 → 2.0.0-beta.10

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 (45) hide show
  1. package/element-test-full.txt +0 -0
  2. package/index.d.ts +35 -50
  3. package/package.json +6 -6
  4. package/scripts/lint.js +17 -0
  5. package/scripts/prepublishOnly.js +2 -2
  6. package/scripts/prepush.js +4 -6
  7. package/src/component/base/methods.js +16 -76
  8. package/src/component/base/utils.js +18 -4
  9. package/src/component/setup/props.js +37 -28
  10. package/src/component/setup/state.js +5 -5
  11. package/src/component.js +28 -19
  12. package/src/components/Circle.js +52 -9
  13. package/src/components/FPScounter.js +224 -88
  14. package/src/components/RouterView.js +58 -6
  15. package/src/components/Sprite.js +72 -8
  16. package/src/constants.js +17 -0
  17. package/src/engine.js +17 -0
  18. package/src/engines/L3/element.js +109 -86
  19. package/src/engines/L3/fontLoader.js +43 -31
  20. package/src/engines/L3/index.js +17 -0
  21. package/src/engines/L3/launch.js +1 -0
  22. package/src/engines/L3/shaderLoader.js +73 -6
  23. package/src/engines/index.js +17 -0
  24. package/src/focus/focus.js +7 -7
  25. package/src/focus/helpers.js +4 -2
  26. package/src/focus/hover.js +7 -6
  27. package/src/helpers/fetchJson.js +4 -6
  28. package/src/launch.js +1 -2
  29. package/src/lib/codegenerator/generator.js +127 -16
  30. package/src/lib/colors/colors.js +0 -1
  31. package/src/lib/lifecycle.js +8 -10
  32. package/src/lib/log.js +4 -4
  33. package/src/lib/reactivityguard/computedprops.js +27 -13
  34. package/src/lib/shaders/shaders.js +164 -0
  35. package/src/lib/symbols.js +25 -0
  36. package/src/lib/templateparser/parser.js +6 -2
  37. package/src/lib/utils.js +53 -0
  38. package/src/plugin.js +17 -0
  39. package/src/plugins/storage/localCookie.js +4 -6
  40. package/src/router/router.js +23 -15
  41. package/test-output.txt +0 -0
  42. package/vite/blitsTips.js +57 -0
  43. package/vite/inject-dev-config.js +17 -0
  44. package/vite/msdfGenerator.js +52 -6
  45. package/vscode/data/template-attributes.json +112 -0
package/src/component.js CHANGED
@@ -138,7 +138,7 @@ export const componentMap = new WeakMap()
138
138
  * @property {any[]} [stateKeys] - The keys of the state of the component instance
139
139
  * Single props:
140
140
  * @property {object} activeView - The active view of the component instance
141
- * @property {boolean} hasFocus - Indicates if the component has focus
141
+ * @property {boolean} $hasFocus - Indicates if the component has focus
142
142
  * @property {string} ref - The reference name of the component instance
143
143
  * @property {number|undefined} index - The index in a for loop
144
144
  * @property {number|undefined} activeRow - The active row in a for loop
@@ -197,22 +197,23 @@ const Component = (name = required('name'), config = required('config')) => {
197
197
 
198
198
  const component = function (opts, parentEl, parentComponent, rootComponent) {
199
199
  // generate a human readable ID for the component instance (i.e. Blits::ComponentName1)
200
- this.componentId = createHumanReadableId(name)
200
+ this.$componentId = createHumanReadableId(name)
201
+
202
+ this[symbols.effects] = []
201
203
 
202
204
  this[symbols.effects] = []
203
205
 
204
206
  // instantiate a lifecycle object for this instance
205
- this.lifecycle = Object.assign(Object.create(Lifecycle), {
207
+ this[symbols.lifecycle] = Object.assign(Object.create(Lifecycle), {
206
208
  component: this,
207
209
  previous: null,
208
210
  current: null,
209
211
  })
210
212
 
211
213
  // set a reference to the parent component
212
- this.parent = parentComponent
214
+ this[symbols.parent] = parentComponent
213
215
 
214
- //
215
- this.rootParent = rootComponent
216
+ this[symbols.rootParent] = rootComponent
216
217
 
217
218
  // set a reference to the holder / parentElement
218
219
  // Components are wrapped in a holder node (used to apply positioning and transforms
@@ -242,22 +243,22 @@ const Component = (name = required('name'), config = required('config')) => {
242
243
  // and store a reference to this original state
243
244
  this[symbols.originalState] =
244
245
  (config.state && typeof config.state === 'function' && config.state.apply(this)) || {}
245
- // add hasFocus key in
246
- this[symbols.originalState]['hasFocus'] = false
246
+ // add $hasFocus key in
247
+ this[symbols.originalState]['$hasFocus'] = false
247
248
 
248
- // add isHovered key in
249
- this[symbols.originalState]['isHovered'] = false
249
+ // add $isHovered key in
250
+ this[symbols.originalState]['$isHovered'] = false
250
251
 
251
252
  // generate a reactive state (using the result of previously execute state function)
252
253
  // and store it
253
254
  this[symbols.state] = reactive(this[symbols.originalState], Settings.get('reactivityMode'))
254
255
 
255
256
  // all basic setup has been done now, set the lifecycle to state 'init'
256
- this.lifecycle.state = 'init'
257
+ this[symbols.lifecycle].state = 'init'
257
258
 
258
259
  // execute the render code that constructs the initial state of the component
259
260
  // and store the children result (a flat map of elements and components)
260
- const { elms, cleanup } = config.code.render.apply(stage, [
261
+ const { elms, cleanup, skips } = config.code.render.apply(stage, [
261
262
  parentEl,
262
263
  this,
263
264
  config,
@@ -334,28 +335,28 @@ const Component = (name = required('name'), config = required('config')) => {
334
335
  // inBounds event emiting a lifecycle attach event
335
336
  if (config.hooks.attach) {
336
337
  this[symbols.wrapper].node.on('inBounds', () => {
337
- this.lifecycle.state = 'attach'
338
+ this[symbols.lifecycle].state = 'attach'
338
339
  })
339
340
  }
340
341
 
341
342
  // outOfBounds event emiting a lifeycle detach event
342
343
  if (config.hooks.detach) {
343
344
  this[symbols.wrapper].node.on('outOfBounds', (node, { previous }) => {
344
- if (previous > 0) this.lifecycle.state = 'detach'
345
+ if (previous > 0) this[symbols.lifecycle].state = 'detach'
345
346
  })
346
347
  }
347
348
 
348
349
  // inViewport event emiting a lifecycle enter event
349
350
  if (config.hooks.enter) {
350
351
  this[symbols.wrapper].node.on('inViewport', () => {
351
- this.lifecycle.state = 'enter'
352
+ this[symbols.lifecycle].state = 'enter'
352
353
  })
353
354
  }
354
355
 
355
356
  // outOfViewport event emitting a lifecycle exit event
356
357
  if (config.hooks.exit) {
357
358
  this[symbols.wrapper].node.on('outOfBounds', () => {
358
- this.lifecycle.state = 'exit'
359
+ this[symbols.lifecycle].state = 'exit'
359
360
  })
360
361
  }
361
362
  }
@@ -365,7 +366,15 @@ const Component = (name = required('name'), config = required('config')) => {
365
366
  const effects = config.code.effects
366
367
  for (let i = 0; i < effects.length; i++) {
367
368
  const eff = () => {
368
- effects[i](this, this[symbols.children], config, globalComponents, rootComponent, effect)
369
+ effects[i](
370
+ this,
371
+ this[symbols.children],
372
+ config,
373
+ globalComponents,
374
+ rootComponent,
375
+ skips,
376
+ effect
377
+ )
369
378
  }
370
379
  // store reference to the effect
371
380
  this[symbols.effects].push(eff)
@@ -389,7 +398,7 @@ const Component = (name = required('name'), config = required('config')) => {
389
398
  }
390
399
  }
391
400
 
392
- let old = this[key]
401
+ let old = target[key]
393
402
 
394
403
  const eff = (force = false) => {
395
404
  const newValue = target[key]
@@ -406,7 +415,7 @@ const Component = (name = required('name'), config = required('config')) => {
406
415
  }
407
416
 
408
417
  // finaly set the lifecycle state to ready (in the next tick)
409
- setTimeout(() => (this.lifecycle.state = 'ready'))
418
+ setTimeout(() => (this[symbols.lifecycle].state = 'ready'))
410
419
 
411
420
  // and return this
412
421
  return this
@@ -23,6 +23,48 @@ export default () =>
23
23
  code: {
24
24
  render: function anonymous(parent, component, context, components, effect, getRaw, Log) {
25
25
  const elms = []
26
+ const validAttributes = [
27
+ 'parent',
28
+ 'rotation',
29
+ 'w',
30
+ 'width',
31
+ 'h',
32
+ 'height',
33
+ 'x',
34
+ 'y',
35
+ 'z',
36
+ 'zIndex',
37
+ 'color',
38
+ 'src',
39
+ 'texture',
40
+ 'fit',
41
+ 'rtt',
42
+ 'mount',
43
+ 'pivot',
44
+ 'scale',
45
+ 'show',
46
+ 'alpha',
47
+ 'rounded',
48
+ 'border',
49
+ 'shadow',
50
+ 'shader',
51
+ 'clipping',
52
+ 'overflow',
53
+ 'font',
54
+ 'size',
55
+ 'maxwidth',
56
+ 'maxheight',
57
+ 'maxlines',
58
+ 'textoverflow',
59
+ 'letterspacing',
60
+ 'lineheight',
61
+ 'contain',
62
+ 'align',
63
+ 'content',
64
+ 'placement',
65
+ 'inspector-data',
66
+ 'holder',
67
+ ]
26
68
  const elementConfigs = []
27
69
  const forloops = []
28
70
  const props = []
@@ -44,10 +86,10 @@ export default () =>
44
86
  inSlot === true ? slotComponent : component
45
87
  )
46
88
 
47
- elementConfigs[0]['color'] = component.color
89
+ elementConfigs[0]['color'] = component.bgColor
48
90
  elementConfigs[0]['w'] = component.size
49
91
  elementConfigs[0]['h'] = component.size
50
- elementConfigs[0]['effects'] = [component.shader('radius', { radius: component.radius })]
92
+ elementConfigs[0]['rounded'] = component.radius
51
93
  elms[0].populate(elementConfigs[0])
52
94
 
53
95
  if (inSlot === true) {
@@ -70,25 +112,26 @@ export default () =>
70
112
  props.length = 0
71
113
  skips.length = 0
72
114
  },
115
+ skips,
73
116
  }
74
117
  },
75
118
  effects: [
76
- function anonymous(component, elms, context, components, rootComponent, effect) {
77
- elms[0].set('color', component.color)
119
+ function anonymous(component, elms, context, components, rootComponent, skips, effect) {
120
+ elms[0].set('color', component.bgColor)
78
121
  },
79
- function anonymous(component, elms, context, components, rootComponent, effect) {
122
+ function anonymous(component, elms, context, components, rootComponent, skips, effect) {
80
123
  elms[0].set('w', component.size)
81
124
  },
82
- function anonymous(component, elms, context, components, rootComponent, effect) {
125
+ function anonymous(component, elms, context, components, rootComponent, skips, effect) {
83
126
  elms[0].set('h', component.size)
84
127
  },
85
- function anonymous(component, elms, context, components, rootComponent, effect) {
86
- elms[0].set('effects', [component.shader('radius', { radius: component.radius })])
128
+ function anonymous(component, elms, context, components, rootComponent, skips, effect) {
129
+ elms[0].set('rounded', component.radius)
87
130
  },
88
131
  ],
89
132
  context: {},
90
133
  },
91
- props: [{ key: 'size', default: 40 }, 'color'],
134
+ props: { size: 40, bgColor: 'white' },
92
135
  computed: {
93
136
  radius() {
94
137
  return this.size / 2