@lightningjs/blits 1.45.1 → 2.0.0-beta.1

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 (38) hide show
  1. package/CHANGELOG.md +0 -17
  2. package/README.md +0 -2
  3. package/index.d.ts +23 -86
  4. package/package.json +5 -24
  5. package/scripts/prepublishOnly.js +1 -4
  6. package/src/component/base/methods.js +16 -76
  7. package/src/component/base/utils.js +18 -4
  8. package/src/component/setup/props.js +37 -28
  9. package/src/component/setup/state.js +4 -4
  10. package/src/component.js +25 -16
  11. package/src/components/Circle.js +49 -7
  12. package/src/components/FPScounter.js +226 -88
  13. package/src/components/RouterView.js +50 -5
  14. package/src/components/Sprite.js +61 -20
  15. package/src/engines/L3/element.js +109 -86
  16. package/src/engines/L3/fontLoader.js +26 -31
  17. package/src/engines/L3/shaderLoader.js +56 -6
  18. package/src/focus.js +9 -9
  19. package/src/launch.js +1 -2
  20. package/src/lib/codegenerator/generator.js +117 -16
  21. package/src/lib/colors/colors.js +0 -1
  22. package/src/lib/lifecycle.js +3 -3
  23. package/src/lib/precompiler/precompiler.js +14 -23
  24. package/src/lib/reactivityguard/computedprops.js +1 -6
  25. package/src/lib/shaders/shaders.js +163 -0
  26. package/src/lib/symbols.js +8 -0
  27. package/src/lib/templateparser/parser.js +6 -2
  28. package/src/lib/utils.js +36 -0
  29. package/src/router/router.js +7 -7
  30. package/vite/blitsTips.js +57 -0
  31. package/vite/msdfGenerator.js +52 -6
  32. package/vite/preCompiler.js +5 -15
  33. package/vscode/data/template-attributes.json +112 -0
  34. package/src/plugins/appstate.d.ts +0 -29
  35. package/src/plugins/index.d.ts +0 -29
  36. package/src/plugins/language.d.ts +0 -34
  37. package/src/plugins/storage/storage.d.ts +0 -29
  38. package/src/plugins/theme.d.ts +0 -35
package/src/component.js CHANGED
@@ -135,7 +135,7 @@ const required = (name) => {
135
135
  * @property {any[]} [stateKeys] - The keys of the state of the component instance
136
136
  * Single props:
137
137
  * @property {object} activeView - The active view of the component instance
138
- * @property {boolean} hasFocus - Indicates if the component has focus
138
+ * @property {boolean} $hasFocus - Indicates if the component has focus
139
139
  * @property {string} ref - The reference name of the component instance
140
140
  * @property {number|undefined} index - The index in a for loop
141
141
  * @property {number|undefined} activeRow - The active row in a for loop
@@ -194,22 +194,23 @@ const Component = (name = required('name'), config = required('config')) => {
194
194
 
195
195
  const component = function (opts, parentEl, parentComponent, rootComponent) {
196
196
  // generate a human readable ID for the component instance (i.e. Blits::ComponentName1)
197
- this.componentId = createHumanReadableId(name)
197
+ this.$componentId = createHumanReadableId(name)
198
+
199
+ this[symbols.effects] = []
198
200
 
199
201
  this[symbols.effects] = []
200
202
 
201
203
  // instantiate a lifecycle object for this instance
202
- this.lifecycle = Object.assign(Object.create(Lifecycle), {
204
+ this[symbols.lifecycle] = Object.assign(Object.create(Lifecycle), {
203
205
  component: this,
204
206
  previous: null,
205
207
  current: null,
206
208
  })
207
209
 
208
210
  // set a reference to the parent component
209
- this.parent = parentComponent
211
+ this[symbols.parent] = parentComponent
210
212
 
211
- //
212
- this.rootParent = rootComponent
213
+ this[symbols.rootParent] = rootComponent
213
214
 
214
215
  // set a reference to the holder / parentElement
215
216
  // Components are wrapped in a holder node (used to apply positioning and transforms
@@ -232,19 +233,19 @@ const Component = (name = required('name'), config = required('config')) => {
232
233
  // and store a reference to this original state
233
234
  this[symbols.originalState] =
234
235
  (config.state && typeof config.state === 'function' && config.state.apply(this)) || {}
235
- // add hasFocus key in
236
- this[symbols.originalState]['hasFocus'] = false
236
+ // add $hasFocus key in
237
+ this[symbols.originalState]['$hasFocus'] = false
237
238
 
238
239
  // generate a reactive state (using the result of previously execute state function)
239
240
  // and store it
240
241
  this[symbols.state] = reactive(this[symbols.originalState], Settings.get('reactivityMode'))
241
242
 
242
243
  // all basic setup has been done now, set the lifecycle to state 'init'
243
- this.lifecycle.state = 'init'
244
+ this[symbols.lifecycle].state = 'init'
244
245
 
245
246
  // execute the render code that constructs the initial state of the component
246
247
  // and store the children result (a flat map of elements and components)
247
- const { elms, cleanup } = config.code.render.apply(stage, [
248
+ const { elms, cleanup, skips } = config.code.render.apply(stage, [
248
249
  parentEl,
249
250
  this,
250
251
  config,
@@ -297,28 +298,28 @@ const Component = (name = required('name'), config = required('config')) => {
297
298
  // inBounds event emiting a lifecycle attach event
298
299
  if (config.hooks.attach) {
299
300
  this[symbols.wrapper].node.on('inBounds', () => {
300
- this.lifecycle.state = 'attach'
301
+ this[symbols.lifecycle].state = 'attach'
301
302
  })
302
303
  }
303
304
 
304
305
  // outOfBounds event emiting a lifeycle detach event
305
306
  if (config.hooks.detach) {
306
307
  this[symbols.wrapper].node.on('outOfBounds', (node, { previous }) => {
307
- if (previous > 0) this.lifecycle.state = 'detach'
308
+ if (previous > 0) this[symbols.lifecycle].state = 'detach'
308
309
  })
309
310
  }
310
311
 
311
312
  // inViewport event emiting a lifecycle enter event
312
313
  if (config.hooks.enter) {
313
314
  this[symbols.wrapper].node.on('inViewport', () => {
314
- this.lifecycle.state = 'enter'
315
+ this[symbols.lifecycle].state = 'enter'
315
316
  })
316
317
  }
317
318
 
318
319
  // outOfViewport event emitting a lifecycle exit event
319
320
  if (config.hooks.exit) {
320
321
  this[symbols.wrapper].node.on('outOfBounds', () => {
321
- this.lifecycle.state = 'exit'
322
+ this[symbols.lifecycle].state = 'exit'
322
323
  })
323
324
  }
324
325
  }
@@ -328,7 +329,15 @@ const Component = (name = required('name'), config = required('config')) => {
328
329
  const effects = config.code.effects
329
330
  for (let i = 0; i < effects.length; i++) {
330
331
  const eff = () => {
331
- effects[i](this, this[symbols.children], config, globalComponents, rootComponent, effect)
332
+ effects[i](
333
+ this,
334
+ this[symbols.children],
335
+ config,
336
+ globalComponents,
337
+ rootComponent,
338
+ skips,
339
+ effect
340
+ )
332
341
  }
333
342
  // store reference to the effect
334
343
  this[symbols.effects].push(eff)
@@ -369,7 +378,7 @@ const Component = (name = required('name'), config = required('config')) => {
369
378
  }
370
379
 
371
380
  // finaly set the lifecycle state to ready (in the next tick)
372
- setTimeout(() => (this.lifecycle.state = 'ready'))
381
+ setTimeout(() => (this[symbols.lifecycle].state = 'ready'))
373
382
 
374
383
  // and return this
375
384
  return this
@@ -23,6 +23,47 @@ 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
+ ]
26
67
  const elementConfigs = []
27
68
  const forloops = []
28
69
  const props = []
@@ -46,7 +87,7 @@ export default () =>
46
87
  elementConfigs[0]['color'] = component.color
47
88
  elementConfigs[0]['w'] = component.size
48
89
  elementConfigs[0]['h'] = component.size
49
- elementConfigs[0]['effects'] = [component.shader('radius', { radius: component.radius })]
90
+ elementConfigs[0]['rounded'] = component.radius
50
91
  elms[0].populate(elementConfigs[0])
51
92
 
52
93
  if (inSlot === true) {
@@ -69,25 +110,26 @@ export default () =>
69
110
  props.length = 0
70
111
  skips.length = 0
71
112
  },
113
+ skips,
72
114
  }
73
115
  },
74
116
  effects: [
75
- function anonymous(component, elms, context, components, rootComponent, effect) {
117
+ function anonymous(component, elms, context, components, rootComponent, skips, effect) {
76
118
  elms[0].set('color', component.color)
77
119
  },
78
- function anonymous(component, elms, context, components, rootComponent, effect) {
120
+ function anonymous(component, elms, context, components, rootComponent, skips, effect) {
79
121
  elms[0].set('w', component.size)
80
122
  },
81
- function anonymous(component, elms, context, components, rootComponent, effect) {
123
+ function anonymous(component, elms, context, components, rootComponent, skips, effect) {
82
124
  elms[0].set('h', component.size)
83
125
  },
84
- function anonymous(component, elms, context, components, rootComponent, effect) {
85
- elms[0].set('effects', [component.shader('radius', { radius: component.radius })])
126
+ function anonymous(component, elms, context, components, rootComponent, skips, effect) {
127
+ elms[0].set('rounded', component.radius)
86
128
  },
87
129
  ],
88
130
  context: {},
89
131
  },
90
- props: [{ key: 'size', default: 40 }, 'color'],
132
+ props: { size: 40, color: 'white' },
91
133
  computed: {
92
134
  radius() {
93
135
  return this.size / 2