@lightningjs/blits 2.8.9 → 2.9.0

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,7 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.9.0
4
+
5
+ _9 sep 2026_
6
+
7
+ - Added DOM based Aria announcer implementation
8
+
9
+
3
10
  ## 2.8.9
4
11
 
12
+ _12 aug 2026_
13
+
5
14
  - Fixed focus issue related to multiple named router views
6
15
 
7
16
  ## 2.8.8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightningjs/blits",
3
- "version": "2.8.9",
3
+ "version": "2.9.0",
4
4
  "description": "Blits: The Lightning 3 App Development Framework",
5
5
  "bin": "bin/index.js",
6
6
  "exports": {
@@ -36,6 +36,10 @@
36
36
  "types": "./src/platforms/webOS/announcer.d.ts",
37
37
  "default": "./src/platforms/webOS/announcer.js"
38
38
  },
39
+ "./platforms/dom/announcer": {
40
+ "types": "./src/platforms/dom/announcer.d.ts",
41
+ "default": "./src/platforms/dom/announcer.js"
42
+ },
39
43
  "./testing": {
40
44
  "types": "./src/testing/index.d.ts",
41
45
  "default": "./src/testing/index.js"
@@ -81,15 +81,30 @@ const addToQueue = (message, politeness, delay = false, options = {}) => {
81
81
 
82
82
  // setup a promise to allow developer to chain functionality
83
83
  // when specific utterances are done
84
- let resolveFn
84
+ let resolvePromise
85
+ let settled = false
85
86
  const done = new Promise((resolve) => {
86
- resolveFn = resolve
87
+ resolvePromise = resolve
87
88
  })
88
89
 
90
+ const resolveFn = (status) => {
91
+ if (settled === true) return
92
+ settled = true
93
+ resolvePromise(status)
94
+ }
95
+
89
96
  // augment the promise with a cancel / remove function
90
97
  done.remove = done.cancel = () => {
91
98
  const index = queue.findIndex((item) => item.id === id)
92
- if (index !== -1) queue.splice(index, 1)
99
+ if (index !== -1) {
100
+ queue.splice(index, 1)
101
+ } else if (id === currentId && debounce !== null) {
102
+ clearDebounceTimer()
103
+ currentId = null
104
+ currentResolveFn = null
105
+ isProcessing = false
106
+ processQueue()
107
+ }
93
108
  Log.debug(`Announcer - removed from queue: "${message}" (id: ${id})`)
94
109
  resolveFn('canceled')
95
110
  }
@@ -0,0 +1,28 @@
1
+ import type { AnnouncerDriver } from '@lightningjs/blits'
2
+
3
+ export interface DOMAnnouncerOptions {
4
+ /**
5
+ * Document in which the live region is created. Defaults to the global document.
6
+ */
7
+ document?: Document | null
8
+ /**
9
+ * Element that receives the live region. Defaults to document.body.
10
+ */
11
+ container?: HTMLElement
12
+ /**
13
+ * ID used to find or create the single live region.
14
+ *
15
+ * @default 'blits-announcer'
16
+ */
17
+ id?: string
18
+ /**
19
+ * Delay between clearing the region and inserting the next message.
20
+ *
21
+ * @default 0
22
+ */
23
+ updateDelay?: number
24
+ }
25
+
26
+ declare function createAnnouncer(options?: DOMAnnouncerOptions): AnnouncerDriver
27
+
28
+ export default createAnnouncer
@@ -0,0 +1,111 @@
1
+ /*
2
+ * Copyright 2026 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
+ const globalScope = globalThis
19
+ const defaultId = 'blits-announcer'
20
+
21
+ const visuallyHiddenStyles = {
22
+ position: 'absolute',
23
+ width: '1px',
24
+ height: '1px',
25
+ padding: '0',
26
+ margin: '-1px',
27
+ overflow: 'hidden',
28
+ clip: 'rect(0, 0, 0, 0)',
29
+ whiteSpace: 'nowrap',
30
+ border: '0',
31
+ }
32
+
33
+ const createAnnouncer = (options = {}) => {
34
+ const documentRef = Object.prototype.hasOwnProperty.call(options, 'document')
35
+ ? options.document
36
+ : globalScope.document
37
+ const id = options.id || defaultId
38
+ const updateDelay = options.updateDelay === undefined ? 0 : options.updateDelay
39
+
40
+ let region
41
+ let pendingUpdate
42
+
43
+ const getRegion = () => {
44
+ if (!documentRef || typeof documentRef.createElement !== 'function') return
45
+ if (region && region.isConnected !== false) return region
46
+
47
+ region = typeof documentRef.getElementById === 'function' && documentRef.getElementById(id)
48
+
49
+ if (!region) {
50
+ const parent = options.container || documentRef.body || documentRef.documentElement
51
+ if (!parent || typeof parent.appendChild !== 'function') return
52
+
53
+ region = documentRef.createElement('div')
54
+ region.id = id
55
+ parent.appendChild(region)
56
+ }
57
+
58
+ Object.assign(region.style, visuallyHiddenStyles)
59
+ region.setAttribute('role', 'alert')
60
+ region.setAttribute('aria-live', 'assertive')
61
+ region.setAttribute('aria-atomic', 'true')
62
+
63
+ return region
64
+ }
65
+
66
+ const cancelPendingUpdate = (error = 'canceled') => {
67
+ if (pendingUpdate === undefined) return
68
+ clearTimeout(pendingUpdate.timer)
69
+ pendingUpdate.reject({ error })
70
+ pendingUpdate = undefined
71
+ }
72
+
73
+ // Create the empty region before the first announcement so assistive
74
+ // technology can observe subsequent content changes reliably.
75
+ getRegion()
76
+
77
+ return {
78
+ speak(announcement) {
79
+ if (!announcement || announcement.message === undefined || announcement.message === null) {
80
+ return Promise.reject({ error: 'Missing message' })
81
+ }
82
+
83
+ const liveRegion = getRegion()
84
+ if (!liveRegion) {
85
+ return Promise.reject({ error: 'unavailable' })
86
+ }
87
+
88
+ cancelPendingUpdate()
89
+ liveRegion.textContent = ''
90
+
91
+ return new Promise((resolve, reject) => {
92
+ const update = {
93
+ reject,
94
+ timer: setTimeout(() => {
95
+ if (pendingUpdate !== update) return
96
+ liveRegion.textContent = String(announcement.message)
97
+ pendingUpdate = undefined
98
+ resolve()
99
+ }, updateDelay),
100
+ }
101
+ pendingUpdate = update
102
+ })
103
+ },
104
+ cancel() {
105
+ cancelPendingUpdate()
106
+ if (region) region.textContent = ''
107
+ },
108
+ }
109
+ }
110
+
111
+ export default createAnnouncer