@pie-players/pie-tool-tts-inline 0.3.72 → 0.3.74

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/README.md CHANGED
@@ -8,20 +8,20 @@ focuses on the inline custom element API.
8
8
 
9
9
  ## Overview
10
10
 
11
- `pie-tool-tts-inline` is a web component that renders an inline speaker trigger with an expanded floating control panel for reading controls. Unlike floating modal tools, this component renders at its natural position in the DOM (typically in passage/item headers).
11
+ `pie-tool-tts-inline` is a web component that renders an inline play/pause trigger with an expanded floating control panel for reading controls. Unlike floating modal tools, this component renders at its natural position in the DOM (typically in passage/item headers).
12
12
 
13
13
  ## Features
14
14
 
15
- - Speaker trigger that toggles an expanded panel
16
- - Expanded controls: Play/Pause, Stop, Fast-forward, Rewind, configurable Speed options
15
+ - Play/pause trigger that opens the expanded panel when reading starts
16
+ - Expanded controls: configurable Speed options, Rewind, Fast-forward, Stop
17
17
  - Play button switches to Pause while reading
18
18
  - Panel remains open while reading and closes on Stop
19
19
  - Arrow-key navigation within the controls toolbar
20
- - Registers with `ToolCoordinator` for lifecycle management
20
+ - Takes its services from the toolkit runtime context and its reading scope from the enclosing item or passage shell
21
21
  - Integrates with `TTSService` for QTI 3.0 catalog-based TTS
22
22
  - Size variants: `sm`, `md`, `lg`
23
23
  - Full accessibility support (ARIA labels, `role="toolbar"`, live status updates)
24
- - Coordinator-controlled visibility via CSS `display` property
24
+ - Four panel layouts through `layout-mode`
25
25
 
26
26
  ## Installation
27
27
 
@@ -31,27 +31,24 @@ bun add @pie-players/pie-tool-tts-inline
31
31
 
32
32
  ## Usage
33
33
 
34
+ The element renders inside `<pie-item-shell>` or `<pie-passage-shell>` under
35
+ `<pie-assessment-toolkit>`. The toolkit runtime context supplies the TTS
36
+ service, the highlight coordinator and the toolkit coordinator, and the shell
37
+ supplies the content to read; section players provide both. The packaged
38
+ `textToSpeech` capability in `@pie-players/pie-default-tool-loaders` creates
39
+ this element in item and passage toolbars, takes `catalog-id`, `language` and
40
+ `size` from the toolbar, and takes `layout-mode`, `speedOptions` and
41
+ `showSingleSpeedOption` from the toolkit's `textToSpeech` tool configuration.
42
+
34
43
  ```javascript
35
44
  import '@pie-players/pie-tool-tts-inline';
36
- import { TTSService, BrowserTTSProvider, ToolCoordinator } from '@pie-players/pie-assessment-toolkit';
37
-
38
- // Initialize services
39
- const ttsService = new TTSService();
40
- await ttsService.initialize(new BrowserTTSProvider());
41
- const toolCoordinator = new ToolCoordinator();
42
45
 
43
- // Create element
46
+ // passageHeader: an element inside <pie-passage-shell>
44
47
  const ttsButton = document.createElement('pie-tool-tts-inline');
45
- ttsButton.setAttribute('tool-id', 'tts-passage-1');
46
48
  ttsButton.setAttribute('catalog-id', 'passage-1');
47
49
  ttsButton.setAttribute('size', 'md');
48
-
49
- // Bind services as JavaScript properties (not HTML attributes)
50
- ttsButton.ttsService = ttsService;
51
- ttsButton.coordinator = toolCoordinator;
52
-
53
- // Coordinator controls visibility
54
- toolCoordinator.showTool('tts-passage-1');
50
+ ttsButton.setAttribute('layout-mode', 'expanding-row');
51
+ passageHeader.append(ttsButton);
55
52
  ```
56
53
 
57
54
  ### With Svelte
@@ -59,29 +56,14 @@ toolCoordinator.showTool('tts-passage-1');
59
56
  ```svelte
60
57
  <script>
61
58
  import '@pie-players/pie-tool-tts-inline';
62
- import { ZIndexLayer } from '@pie-players/pie-assessment-toolkit';
63
-
64
- let ttsToolElement;
65
-
66
- $effect(() => {
67
- if (ttsToolElement && toolCoordinator) {
68
- ttsToolElement.ttsService = ttsService;
69
- ttsToolElement.coordinator = toolCoordinator;
70
-
71
- if (ttsService) {
72
- toolCoordinator.showTool('tts-passage-1');
73
- }
74
- }
75
- });
76
59
  </script>
77
60
 
78
61
  <div class="header">
79
62
  <h3>Passage Title</h3>
80
63
  <pie-tool-tts-inline
81
- bind:this={ttsToolElement}
82
- tool-id="tts-passage-1"
83
64
  catalog-id="passage-1"
84
65
  size="md"
66
+ layout-mode="expanding-row"
85
67
  ></pie-tool-tts-inline>
86
68
  </div>
87
69
  ```
@@ -90,18 +72,23 @@ toolCoordinator.showTool('tts-passage-1');
90
72
 
91
73
  ### HTML Attributes
92
74
 
93
- - `tool-id` - Unique identifier for tool registration (default: `'tts-inline'`)
94
75
  - `catalog-id` - QTI 3.0 accessibility catalog ID for SSML lookup (default: `''`)
95
76
  - `language` - Language code for TTS (default: `'en-US'`)
96
77
  - `size` - Icon size: `'sm'` (1.5rem), `'md'` (2rem), or `'lg'` (2.5rem) (default: `'md'`)
78
+ - `layout-mode` - Panel placement (default: `'expanding-row'`). `'reserved-row'`
79
+ and `'expanding-row'` drop the panel below the trigger; in the packaged toolbar
80
+ the first keeps the controls row reserved and the second expands it while the
81
+ panel is open. `'floating-overlay'` and `'left-aligned'` open the panel as an
82
+ overlay to the left of the trigger.
97
83
 
98
84
  ### JavaScript Properties
99
85
 
100
- - `ttsService` - ITTSService instance (required)
101
- - `coordinator` - IToolCoordinator instance (optional, for visibility management)
102
86
  - `speedOptions` - Optional speed options controlling inline speed button rendering
103
87
  - `showSingleSpeedOption` - Optional boolean to show a one-option speed group (hidden by default)
104
88
 
89
+ Both also read attributes: `speed-options` takes a JSON array, and
90
+ `show-single-speed-option` is true when present.
91
+
105
92
  ### `speedOptions` Configuration
106
93
 
107
94
  `speedOptions` is intended to be set as a JavaScript property (not as a
@@ -145,19 +132,19 @@ Semantics:
145
132
 
146
133
  ## Behavior
147
134
 
148
- 1. **Tool Registration**: Registers with ToolCoordinator on mount using the provided `tool-id`
149
- 2. **Text Extraction**: Finds nearest `.pie-section-player__passage-content` or `.pie-section-player__item-content` container
150
- 3. **TTS Trigger**: Calls `ttsService.speak(text, { catalogId, language })`
135
+ 1. **Services**: Reads `ttsService`, `highlightCoordinator` and `toolkitCoordinator` from the toolkit runtime context; the controls stay disabled until a `ttsService` arrives, and starting playback awaits `toolkitCoordinator.ensureTTSReady()`
136
+ 2. **Text Extraction**: Reads the `textContent` of the scope element (the region scope, else the shell scope) when it is `[data-region='content']`, else of its first `[data-region='content']` descendant, else of the scope element itself
137
+ 3. **TTS Trigger**: Calls `ttsService.speak(text, { catalogId, catalogContext, language, contentElement })`, where `contentElement` is that reading target and `catalogContext` names the owning item or passage
151
138
  4. **Catalog Resolution**: TTSService checks for SSML in accessibility catalogs (priority order):
152
139
  - **Extracted catalogs** (from embedded SSML) - generated before render by hosts that run `SSMLExtractor`
153
140
  - **Item-level catalogs** (manually authored)
154
141
  - **Assessment-level catalogs** (manually authored)
155
142
  - **Plain text fallback** (browser TTS)
156
143
  5. **Expanded Controls**:
157
- - Trigger button opens/closes the panel
158
- - Play/Pause toggles based on playback state
144
+ - The trigger starts, pauses and resumes reading; starting opens the panel
145
+ - Starting one instance stops playback another instance owns and closes that instance's panel
159
146
  - Stop halts playback and closes the panel
160
- - Fast-forward/Rewind invoke sentence-jump seek on `ITTSService`
147
+ - Fast-forward/Rewind call `seekForward(1)` / `seekBackward(1)` on the TTS service, one sentence per press, and are enabled only while reading
161
148
  - Speed buttons call `ttsService.setPlaybackRate(rate)` when available,
162
149
  otherwise `ttsService.updateSettings({ rate })`
163
150
  - Speed choices render as a named `Playback speed` radio group with
@@ -166,8 +153,9 @@ Semantics:
166
153
  - Clicking the currently active speed leaves the selection unchanged
167
154
  - If `speedOptions` is `[]`, speed controls are omitted and playback rate is
168
155
  reset to `1x` while rewind/forward/stop still render
169
- 6. **Keyboard Interaction**: Arrow keys move between controls; Tab enters/leaves the toolbar
170
- 7. **Cleanup**: Unregisters from coordinator on unmount
156
+ 6. **Keyboard Interaction**: Arrow keys, Home and End move focus within one cluster, either the speed radio group or the Rewind/Fast-forward/Stop buttons, and skip disabled controls; arrowing onto a speed also selects it. Every control is a Tab stop except the speed radios, which share one Tab stop on the checked option
157
+ 7. **Active State**: Opening or closing the panel dispatches a bubbling, composed `pie-tool-active-change` event with `{ active }` and mirrors the state in the host's `data-active` attribute
158
+ 8. **Cleanup**: Releases playback ownership and clears its highlight target resolver provider on unmount
171
159
 
172
160
  ## SSML Extraction Integration
173
161
 
@@ -202,8 +190,8 @@ when a host/import pipeline runs `SSMLExtractor` before render:
202
190
 
203
191
  The component uses scoped styles and doesn't require external CSS. Styling uses `--pie-*` token variables:
204
192
 
205
- - **Trigger**: Circular speaker button that indicates panel open state
206
- - **Panel**: Floating card with vertically stacked controls
193
+ - **Trigger**: Circular play/pause button that indicates panel open state
194
+ - **Panel**: Floating card with the controls in a row; in the compact `left-aligned` overlay the speed options stack below them
207
195
  - **Speed state**: Active speed button receives distinct token-driven styling
208
196
  - **Disabled**: Reduced opacity, no pointer
209
197
 
@@ -233,10 +221,9 @@ colors.
233
221
 
234
222
  ### Overlay panel colours
235
223
 
236
- The floating and left-aligned panels take their shape from the Knowledge-Check
237
- design and their colour from the active theme. Each surface resolves a
238
- component-scoped hook first, then a canonical token, then a literal that only
239
- applies when no theme is loaded:
224
+ The floating and left-aligned panels take their colour from the active theme.
225
+ Each surface resolves a component-scoped hook first, then a canonical token,
226
+ then a literal that only applies when no theme is loaded:
240
227
 
241
228
  ```css
242
229
  --pie-tts-button-color /* media glyphs, selected speed → --pie-button-color */
@@ -282,9 +269,11 @@ tokens.
282
269
  This tool follows the PIE Assessment Toolkit tool pattern:
283
270
 
284
271
  - Always rendered in DOM at natural position
285
- - ToolCoordinator controls visibility via `showTool()`/`hideTool()` (CSS `display` property)
286
- - Registers with `ZIndexLayer.TOOL` for proper layering
287
- - Services passed as JavaScript properties (objects can't be HTML attributes)
272
+ - Services arrive through `connectToolRuntimeContext`, and the reading scope
273
+ through `connectToolShellContext` and `connectToolRegionScopeContext`
274
+ - One instance owns playback at a time across the page
275
+ - Panel state is announced with `pie-tool-active-change`, which the packaged
276
+ toolbar registration subscribes to
288
277
 
289
278
  ## Example
290
279
 
package/dist/index.d.ts CHANGED
@@ -1 +1,8 @@
1
- export { default } from './tool-tts-inline.svelte';
1
+ /**
2
+ * pie-tool-tts-inline
3
+ *
4
+ * Importing this package registers `<pie-tool-tts-inline>`. The build entry is
5
+ * the component, so this file is the type entry alone and declares nothing: a
6
+ * runtime export here would not exist in the built bundle.
7
+ */
8
+ export type {};