@pie-players/pie-tool-annotation-toolbar 0.3.75 → 1.0.0-beta.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/README.md +14 -32
- package/custom-elements.json +76 -0
- package/dist/tool-annotation-toolbar.js +1417 -1406
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @pie-players/pie-tool-annotation-toolbar
|
|
2
2
|
|
|
3
3
|
A text selection toolbar for highlighting and annotating text in PIE assessment players. Uses modern CSS Custom Highlight API for zero DOM mutation and optimal performance.
|
|
4
4
|
|
|
@@ -6,24 +6,19 @@ A text selection toolbar for highlighting and annotating text in PIE assessment
|
|
|
6
6
|
|
|
7
7
|
- **4-Color Highlighting**: Yellow, pink, blue, and green highlight swatches
|
|
8
8
|
- **Underline Annotation**: Underline selected text
|
|
9
|
-
- **Persistent Annotations**:
|
|
9
|
+
- **Persistent Annotations**: Kept per section and attempt in the toolkit's tool-state store
|
|
10
10
|
- **Clear Annotations**: Remove annotations from selected text or clear all
|
|
11
|
-
- **Text-to-Speech (Read Aloud)**: Read selected text aloud
|
|
11
|
+
- **Text-to-Speech (Read Aloud)**: Read selected text aloud through the toolkit's TTS service, which highlights by sentence on browser voices and by word on server voices that return speech marks ([TTS deep dive](../../docs/accessibility/tts-deep-dive.md))
|
|
12
12
|
- **Selection Actions**: Host-supplied actions on the current selection; see below
|
|
13
13
|
- **Viewport-Aware Placement**: Sits above the selection where it fits, flips below when it does not, and clamps so no control leaves the viewport. `data-pie-placement` on the strip reads `above` or `below`.
|
|
14
14
|
- **Modern CSS Custom Highlight API**:
|
|
15
15
|
- Zero DOM mutation (no `<span>` wrappers)
|
|
16
|
-
- 10-50x faster than traditional approaches
|
|
17
|
-
- 5-10x less memory usage
|
|
18
16
|
- Framework-compatible (works with React, Vue, Svelte)
|
|
19
17
|
- **Accessibility**:
|
|
20
18
|
- Full ARIA labels and screen reader support
|
|
21
19
|
- Keyboard navigation (Escape to close)
|
|
22
20
|
- Focus-visible outlines
|
|
23
|
-
|
|
24
|
-
- **Dark Mode**: Automatic adaptation to system color scheme
|
|
25
|
-
- **High Contrast Mode**: Enhanced visibility in high contrast settings
|
|
26
|
-
- **Responsive Design**: Optimized for mobile and desktop viewports
|
|
21
|
+
- **Theme-aware**: the outline follows the declared `color-scheme` through `light-dark()`, and the `data-color-scheme` palettes set all three tokens (see Theming)
|
|
27
22
|
|
|
28
23
|
## Usage
|
|
29
24
|
|
|
@@ -72,15 +67,17 @@ The toolbar takes its surface and text from the canonical `--pie-background` and
|
|
|
72
67
|
| `--pie-annotation-underline` | `#4221d5` | Underline mark on a light page |
|
|
73
68
|
| `--pie-annotation-underline-dark` | `#9c89ec` | Underline mark on a dark page |
|
|
74
69
|
|
|
70
|
+
All three are registered `component-public` tokens.
|
|
71
|
+
|
|
75
72
|
The underline tokens are applied by `HighlightCoordinator` in `@pie-players/pie-assessment-toolkit`, which owns the `::highlight()` rules. They exist as a pair because one value cannot serve both surfaces — `#4221d5` is 2.41:1 on black and `#9c89ec` is 2.85:1 on white — and as two separate tokens so overriding one never silently moves the other. Under `data-theme="light"` and `data-theme="dark"` the underline reads only its own token, because a theme accent is chosen against one background and is illegible on the other. Under any other `data-theme` value, such as a host or DaisyUI palette, it reads `--pie-annotation-underline` and falls back to that palette's `--pie-primary`.
|
|
76
73
|
|
|
77
74
|
Which of the pair applies is decided by `[data-theme]`, which reports what the **page** declares — not which color scheme is active. A host that declares itself light while running a dark scheme would otherwise pin the light value over a dark background, so the accessibility palettes hand both states their own accent (below).
|
|
78
75
|
|
|
79
|
-
The outline does **not** read `--pie-border`. Under the DaisyUI bridge that token resolves to `--color-base-300`, a surface tint rather than a boundary
|
|
76
|
+
The outline does **not** read `--pie-border`. Under the DaisyUI bridge that token resolves to `--color-base-300`, a surface tint rather than a boundary color, which renders the outline at 1.16:1 on the light base and 1.12:1 on the dark one — well short of the 3:1 that WCAG 2.2 SC 1.4.11 requires of a component boundary.
|
|
80
77
|
|
|
81
|
-
The defaults above are measured instead. A boundary on a light surface has to be dark and one on a dark surface has to be light, so the arms are the dark
|
|
78
|
+
The defaults above are measured instead. A boundary on a light surface has to be dark and one on a dark surface has to be light, so the arms are the dark gray first and the light gray second. Both are measured against the surfaces the toolbar is actually drawn on rather than against pure white and pure black — real theme bases are off-white and off-black, and a gray chosen at the edge of passing against an extreme drops under threshold on everything else. Across DaisyUI's 21 light and 14 dark themes plus the PIE light and dark palettes, every light surface needs a gray no lighter than `#828282` and every dark surface one no darker than `#878787`; the ranges are disjoint, so one value cannot serve both. `#5c5c5c` holds 5.22:1 as its worst case on the light surfaces and `#949494` holds 3.56:1 on the dark ones. `light-dark()` follows the declared `color-scheme`, so every dark DaisyUI theme picks the dark value rather than only the theme literally named `dark`.
|
|
82
79
|
|
|
83
|
-
Palettes that choose their own
|
|
80
|
+
Palettes that choose their own colors deliberately set all three tokens in `@pie-players/pie-theme`: the ten `data-color-scheme` accessibility schemes point the outline at their own `--pie-border` and both underline states at their own `--pie-primary`, and the PIE dark theme pins the outline to `#949494`. Several of those palettes use mid-tone backgrounds that no single gray clears 3:1 on, which is why they override rather than inherit.
|
|
84
81
|
|
|
85
82
|
Those per-scheme values arrive by either delivery route: `<pie-theme scheme="…">` applies them as inline styles with no CSS import needed, and importing `@pie-players/pie-theme/color-schemes.css` plus setting `data-color-scheme` yourself produces the same result. Prefer the element — a host that hand-maintains its own copy of the scheme blocks stops receiving tokens added later.
|
|
86
83
|
|
|
@@ -100,15 +97,15 @@ Requires CSS Custom Highlight API support:
|
|
|
100
97
|
|
|
101
98
|
- Chrome/Edge 105+
|
|
102
99
|
- Safari 17.2+
|
|
103
|
-
- Firefox
|
|
100
|
+
- Firefox 140+
|
|
104
101
|
|
|
105
102
|
For unsupported browsers, the component gracefully degrades (no highlights shown).
|
|
106
103
|
|
|
107
104
|
## Annotation Persistence
|
|
108
105
|
|
|
109
|
-
Annotations are
|
|
106
|
+
Annotations are recorded in the toolkit's `elementToolStateStore` after each change, under tool id `annotationToolbar` and a key naming the assessment, section and attempt (`attempt-id` on the toolkit), plus the item when the toolbar sits in an item's shell. Two seconds after the toolbar mounts, and whenever that key changes, the shown annotations are replaced by the key's record, so a new attempt starts without the previous one's. They last as long as the toolkit coordinator; a host keeps them across reloads with the coordinator's `loadToolState` and `saveToolState` hooks.
|
|
110
107
|
|
|
111
|
-
|
|
108
|
+
Recorded format, an array with one record per annotation:
|
|
112
109
|
|
|
113
110
|
```typescript
|
|
114
111
|
[
|
|
@@ -127,10 +124,7 @@ Storage format, an array with one record per annotation:
|
|
|
127
124
|
|
|
128
125
|
`startContainer` and `endContainer` are selector paths relative to the scope root, with ` >>> ` marking a step into a shadow root.
|
|
129
126
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
- The user presses "Clear all", which removes that item's key
|
|
133
|
-
- `sessionStorage` is cleared, for example when the tab closes
|
|
127
|
+
"Clear all" records an empty list under the key.
|
|
134
128
|
|
|
135
129
|
## Text-to-Speech Integration
|
|
136
130
|
|
|
@@ -141,7 +135,7 @@ The annotation toolbar includes a "Read" button that uses the TTS service to rea
|
|
|
141
135
|
1. **User selects text** in the assessment content
|
|
142
136
|
2. **Annotation toolbar appears** with highlight and read buttons
|
|
143
137
|
3. **User clicks "Read"** button (speaker icon)
|
|
144
|
-
4. **TTS service speaks the selected text** using
|
|
138
|
+
4. **TTS service speaks the selected text** using the toolkit's configured TTS backend
|
|
145
139
|
5. **Words are highlighted** in sync with speech using CSS Custom Highlight API
|
|
146
140
|
|
|
147
141
|
### Technical Implementation
|
|
@@ -175,16 +169,4 @@ under tts-inline; part of one reads as the selected text.
|
|
|
175
169
|
|
|
176
170
|
### TTS Browser Support
|
|
177
171
|
|
|
178
|
-
- **TTS (Web Speech API)**: 97%+ browser support
|
|
179
|
-
- **Word Highlighting**: 85-90% browser support (CSS Custom Highlight API)
|
|
180
172
|
- **Graceful degradation**: TTS works without highlighting in older browsers
|
|
181
|
-
|
|
182
|
-
## Based On
|
|
183
|
-
|
|
184
|
-
This implementation is inspired by production annotation toolbar patterns but uses modern 2025 web standards:
|
|
185
|
-
|
|
186
|
-
- CSS Custom Highlight API instead of DOM mutation
|
|
187
|
-
- Svelte 5 patterns and best practices
|
|
188
|
-
- Modern accessibility (WCAG 2.2)
|
|
189
|
-
- Dark mode and high contrast support
|
|
190
|
-
- Responsive design for mobile devices
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": "2.1.0",
|
|
3
|
+
"modules": [
|
|
4
|
+
{
|
|
5
|
+
"kind": "javascript-module",
|
|
6
|
+
"path": "dist/tool-annotation-toolbar.js",
|
|
7
|
+
"declarations": [
|
|
8
|
+
{
|
|
9
|
+
"kind": "class",
|
|
10
|
+
"description": "Toolbar that appears at a text selection, offering four highlight colours, underline, read-aloud, removal, clear-all and the host's `selectionActions`. Annotations are drawn through the runtime context's highlight coordinator and recorded per section and attempt in its element tool state store; read-aloud uses the context's TTS service. Under `<pie-assessment-toolkit>` the capability's registration supplies `enabled` and `selectionActions`.",
|
|
11
|
+
"name": "ToolAnnotationToolbar",
|
|
12
|
+
"tagName": "pie-tool-annotation-toolbar",
|
|
13
|
+
"customElement": true,
|
|
14
|
+
"members": [
|
|
15
|
+
{
|
|
16
|
+
"kind": "field",
|
|
17
|
+
"name": "enabled",
|
|
18
|
+
"type": {
|
|
19
|
+
"text": "boolean"
|
|
20
|
+
},
|
|
21
|
+
"default": "true",
|
|
22
|
+
"attribute": "enabled"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"kind": "field",
|
|
26
|
+
"name": "selectionActions",
|
|
27
|
+
"type": {
|
|
28
|
+
"text": "ToolSelectionAction[] | null"
|
|
29
|
+
},
|
|
30
|
+
"default": "null",
|
|
31
|
+
"description": "Actions on the current selection, supplied by whoever mounts this gateway. This strip does not know what they do — it renders the buttons and hands each one the selection. Pairing an action to a capability is the composer's job, which is what keeps a highlighter from naming a dictionary and lets a host contribute an action for a capability PIE does not ship.",
|
|
32
|
+
"attribute": "selectionactions"
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
"attributes": [
|
|
36
|
+
{
|
|
37
|
+
"name": "enabled",
|
|
38
|
+
"type": {
|
|
39
|
+
"text": "boolean"
|
|
40
|
+
},
|
|
41
|
+
"default": "true",
|
|
42
|
+
"fieldName": "enabled"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"name": "selectionactions",
|
|
46
|
+
"type": {
|
|
47
|
+
"text": "ToolSelectionAction[] | null"
|
|
48
|
+
},
|
|
49
|
+
"default": "null",
|
|
50
|
+
"description": "Actions on the current selection, supplied by whoever mounts this gateway. This strip does not know what they do — it renders the buttons and hands each one the selection. Pairing an action to a capability is the composer's job, which is what keeps a highlighter from naming a dictionary and lets a host contribute an action for a capability PIE does not ship.",
|
|
51
|
+
"fieldName": "selectionActions"
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
"cssProperties": [
|
|
55
|
+
{
|
|
56
|
+
"name": "--pie-tool-annotation-toolbar-border",
|
|
57
|
+
"description": "Outline of the floating annotation toolbar. Deliberately does not fall through --pie-border, which the DaisyUI bridge maps to the base-300 surface tint and which leaves the outline near 1.1:1; the component default is a measured light-dark(#5c5c5c, #949494) pair instead -- dark grey on light surfaces, light grey on dark ones, each measured against DaisyUI's real theme bases rather than pure white and black. The data-color-scheme accessibility palettes and the PIE dark theme set it explicitly so their own boundary colour wins. Hosts overriding it must keep 3:1 against both the toolbar surface and the content behind it (WCAG 2.2 SC 1.4.11)."
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
"x-pie": {
|
|
61
|
+
"shadow": "open"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
"exports": [
|
|
66
|
+
{
|
|
67
|
+
"kind": "custom-element-definition",
|
|
68
|
+
"name": "pie-tool-annotation-toolbar",
|
|
69
|
+
"declaration": {
|
|
70
|
+
"name": "ToolAnnotationToolbar"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
}
|