@lightningjs/blits 2.0.0-beta.4 → 2.0.0-beta.5

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,12 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.51.0
4
+
5
+ _04 mar 2026_
6
+
7
+ - Fixed wrong message from being interrupted in announcer
8
+ - Added `@loaded` and `@error` callbacks to Sprites
9
+
3
10
  ## v1.50.0
4
11
 
5
12
  _27 feb 2026_
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightningjs/blits",
3
- "version": "2.0.0-beta.4",
3
+ "version": "2.0.0-beta.5",
4
4
  "description": "Blits: The Lightning 3 App Development Framework",
5
5
  "bin": "bin/index.js",
6
6
  "exports": {
@@ -149,9 +149,11 @@ const processQueue = async () => {
149
149
  processQueue()
150
150
  })
151
151
  .catch((e) => {
152
- currentId = null
153
- currentResolveFn = null
154
- isProcessing = false
152
+ if (id === currentId) {
153
+ currentId = null
154
+ currentResolveFn = null
155
+ isProcessing = false
156
+ }
155
157
  Log.debug(`Announcer - error ("${e.error}") while speaking: "${message}" (id: ${id})`)
156
158
  resolveFn(e.error)
157
159
  processQueue()
@@ -45,6 +45,9 @@ const Application = (config) => {
45
45
  let mouseListenersAdded = false
46
46
 
47
47
  config.hooks[symbols.destroy] = function () {
48
+ // Cancel pending key-hold timeout and reset hold state so focus is not left in hold mode after teardown
49
+ clearTimeout(holdTimeout)
50
+ Focus.hold = false
48
51
  document.removeEventListener('keydown', keyDownHandler)
49
52
  document.removeEventListener('keyup', keyUpHandler)
50
53
  if (mouseListenersAdded) {
@@ -147,6 +147,8 @@ export default () =>
147
147
  rounded: undefined,
148
148
  border: undefined,
149
149
  shadow: undefined,
150
+ '@loaded': undefined,
151
+ '@error': undefined,
150
152
  },
151
153
  state() {
152
154
  return {
@@ -155,6 +157,33 @@ export default () =>
155
157
  }
156
158
  },
157
159
 
160
+ hooks: {
161
+ ready() {
162
+ const loaded = this['@loaded']
163
+ if (loaded && typeof loaded === 'function') {
164
+ const cb = (payload) => loaded({ w: payload?.w, h: payload?.h }, this[symbols.wrapper])
165
+ this._loadedCb = cb
166
+ if (this.spriteTexture !== undefined && this.spriteTexture !== null) {
167
+ this.spriteTexture.on('loaded', cb)
168
+ }
169
+ }
170
+ const error = this['@error']
171
+ if (error && typeof error === 'function') {
172
+ const cb = (payload) => error(payload, this[symbols.wrapper])
173
+ this._failedCb = cb
174
+ if (this.spriteTexture !== undefined && this.spriteTexture !== null) {
175
+ this.spriteTexture.on('failed', cb)
176
+ }
177
+ }
178
+ },
179
+ destroy() {
180
+ if (this.spriteTexture !== undefined && this.spriteTexture !== null) {
181
+ if (this._loadedCb) this.spriteTexture.off('loaded', this._loadedCb)
182
+ if (this._failedCb) this.spriteTexture.off('failed', this._failedCb)
183
+ }
184
+ },
185
+ },
186
+
158
187
  computed: {
159
188
  texture() {
160
189
  // If no image - nothing to render
@@ -174,10 +203,17 @@ export default () =>
174
203
  this.spriteTexture === null ||
175
204
  this.currentSrc !== this.image
176
205
  ) {
206
+ const prevTexture = this.spriteTexture
207
+ if (prevTexture !== undefined && prevTexture !== null) {
208
+ if (this._loadedCb) prevTexture.off('loaded', this._loadedCb)
209
+ if (this._failedCb) prevTexture.off('failed', this._failedCb)
210
+ }
177
211
  this.spriteTexture = renderer.createTexture('ImageTexture', {
178
212
  src: this.image,
179
213
  })
180
214
  this.currentSrc = this.image
215
+ if (this._loadedCb) this.spriteTexture.on('loaded', this._loadedCb)
216
+ if (this._failedCb) this.spriteTexture.on('failed', this._failedCb)
181
217
  }
182
218
 
183
219
  // Resolve frame data from sprite map
@@ -664,11 +664,21 @@ const generateForLoopCode = function (templateObject, parent) {
664
664
  const forEndCounter = counter
665
665
 
666
666
  for (let i = forStartCounter; i <= forEndCounter; i++) {
667
- destroyCode.push(`
667
+ if (i == forStartCounter) {
668
+ destroyCode.push(`
668
669
  elms[${i}][key] && elms[${i}][key].destroy()
669
670
  elms[${i}][key] = null
670
671
  delete elms[${i}][key]
671
672
  `)
673
+ } else {
674
+ destroyCode.push(`
675
+ if (elms[${i}][key] && elms[${i}][key].$componentId !== undefined) {
676
+ elms[${i}][key] && elms[${i}][key].destroy()
677
+ }
678
+ elms[${i}][key] = null
679
+ delete elms[${i}][key]
680
+ `)
681
+ }
672
682
  }
673
683
  destroyCode.push(`
674
684
  }