@pie-players/pie-tool-theme 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 CHANGED
@@ -1,37 +1,84 @@
1
1
  # @pie-players/pie-tool-theme
2
2
 
3
- Accessible color scheme selection tool for PIE assessment players.
3
+ The color-scheme tool (`theme`): a picker in which a learner chooses one of the
4
+ color schemes in the `@pie-players/pie-theme` catalog. It registers
5
+ `<pie-tool-theme>` and changes the `scheme` of the `<pie-theme>` element that
6
+ hosts the player. Theming itself, the tokens, base themes and `<pie-theme>`,
7
+ belongs to [`@pie-players/pie-theme`](../theme/README.md). The picker addresses
8
+ the WCAG 2.2 Level AA color, contrast, focus and keyboard requirements.
4
9
 
5
- ## Overview
10
+ ## Installation
6
11
 
7
- Provides a theme/color scheme picker that applies accessible color schemes via the `<pie-theme>` provider. It is designed for the relevant WCAG 2.2 Level AA color, contrast, focus, and keyboard requirements.
12
+ ```bash
13
+ bun add @pie-players/pie-tool-theme
14
+ ```
8
15
 
9
- ## Custom Element
16
+ ## Usage
10
17
 
11
- Tag: `pie-tool-theme`
18
+ The packaged tool set registers the tool as `theme` and loads the element on
19
+ demand; hosts place it through `tools.placement`. It supports the assessment
20
+ and section levels, and the section toolbar is its recommended placement. It
21
+ opens in a fixed-size overlay, 520×380px initially and at least 420×300px. A
22
+ host that registers the element itself imports the package:
12
23
 
13
- | Attribute | Type | Default | Description |
14
- |---|---|---|---|
15
- | `visible` | `boolean` | `false` | Controls visibility |
16
- | `tool-id` | `string` | `'theme'` | Identifier used by the ToolCoordinator |
24
+ ```ts
25
+ import "@pie-players/pie-tool-theme";
26
+ ```
17
27
 
18
- ## Features
28
+ | Property | Attribute | Default | Purpose |
29
+ | --- | --- | --- | --- |
30
+ | `visible` | `visible` | `false` | Shows the picker. `"false"`, `"0"`, `"off"` and `"no"` read as false. |
31
+ | `toolId` | `tool-id` | `"theme"` | The id the tool registers under with the tool coordinator. |
19
32
 
20
- - Dropdown scheme selector with color previews
21
- - Reads the shared `@pie-players/pie-theme` scheme catalog and updates immediately when a custom scheme is registered or unregistered
22
- - Uses centrally derived catalog previews instead of carrying a duplicate palette; custom previews use PIE's canonical light-base resolution on a stable opaque swatch
23
- - Retains a requested custom scheme when it is temporarily unavailable, clearly labels it as unavailable, and restores it automatically if it is registered again
24
- - Persists selection to `localStorage` (key: `pie-color-scheme`)
25
- - Applies scheme by setting the `scheme` attribute on the nearest `<pie-theme>` element
26
- - Focus trap when visible; keyboard navigation with arrow keys and Escape
27
- - Connects to `AssessmentToolkitRuntimeContext` for ToolCoordinator integration
33
+ The element has an open shadow root and takes its tool coordinator and
34
+ interface locale from the toolkit runtime context.
28
35
 
29
- ## Integration
36
+ ## Scheme selection
30
37
 
31
- Registered through the `ToolRegistry` as `theme`. Managed by `ToolkitCoordinator` via `tools.placement`.
38
+ The picker lists every scheme in the shared catalog and follows registrations
39
+ and unregistrations as they happen. Previews come from the catalog; a custom
40
+ scheme's preview resolves against PIE's light base on an opaque swatch.
32
41
 
33
- Register custom schemes globally with `registerPieColorSchemes` from `@pie-players/pie-theme`. Every mounted theme picker observes the same immutable catalog; per-element scheme catalogs are not supported.
42
+ Choosing a scheme sets `scheme` on the theme host and closes the tool. The theme
43
+ host is the nearest `<pie-theme>` ancestor, searched across shadow roots, else
44
+ `<pie-theme scope="document">`, else the first `<pie-theme>` in the document.
45
+ With no `<pie-theme>` at all, the picker sets `data-color-scheme` on the
46
+ document element. The picker writes nothing to `localStorage`.
34
47
 
35
- ## License
48
+ Until a learner chooses, the picker shows the host's scheme, and it re-reads the
49
+ host each time it opens. A chosen custom scheme that is no longer registered
50
+ stays selected, labeled unavailable with a status message, and is listed as
51
+ available again once registered.
36
52
 
37
- MIT
53
+ ## Learner choice
54
+
55
+ The picker records the choice in the toolkit's `elementToolStateStore` under
56
+ tool id `theme`, keyed by assessment, section and attempt, and reapplies it when
57
+ the tool mounts again in that section attempt. Without a store, an
58
+ `assessmentId` or a `sectionId` in the runtime context, the choice lasts only on
59
+ the theme host. Nothing is kept for the device, so one learner's choice never
60
+ overrides the scheme a host sets for the next. The host persists the store as
61
+ [State persistence pattern](../../docs/tools-and-accomodations/architecture.md#state-persistence-pattern)
62
+ describes.
63
+
64
+ ## Custom schemes
65
+
66
+ Hosts register custom schemes globally with `registerPieColorSchemes` from
67
+ `@pie-players/pie-theme`
68
+ ([Registered custom schemes](../theme/README.md#registered-custom-schemes)).
69
+ Every mounted picker observes the same immutable catalog; there are no
70
+ per-element catalogs. Scheme names and descriptions come from the registration,
71
+ so the party that registers a scheme localizes them.
72
+
73
+ ## Keyboard and focus
74
+
75
+ The picker is a dialog that traps focus while visible. With the scheme menu
76
+ open, ArrowDown and ArrowUp move between schemes, Escape closes the menu and
77
+ returns focus to its trigger, and a click outside closes it.
78
+
79
+ ## Styling
80
+
81
+ The picker reads the canonical semantic tokens `--pie-background`, `--pie-text`,
82
+ `--pie-border`, `--pie-button-bg`, `--pie-button-border`, `--pie-button-color`,
83
+ `--pie-button-hover-bg`, `--pie-button-hover-border`, `--pie-button-hover-color`,
84
+ `--pie-button-active-bg` and `--pie-button-focus-outline`.
@@ -0,0 +1,77 @@
1
+ {
2
+ "schemaVersion": "2.1.0",
3
+ "modules": [
4
+ {
5
+ "kind": "javascript-module",
6
+ "path": "dist/tool-color-scheme.js",
7
+ "declarations": [
8
+ {
9
+ "kind": "class",
10
+ "description": "Colour scheme picker: a dropdown of the schemes registered with `@pie-players/pie-theme`, each with a preview, that applies the chosen scheme to the nearest `<pie-theme>`. The choice is recorded per section and attempt in the runtime context's element tool state store and reapplied when the tool mounts again in that attempt. The host shows it with `visible`; it registers `tool-id` with the tool coordinator on the modal layer, traps focus while open, and hides itself there once a scheme is chosen.",
11
+ "name": "ToolColorScheme",
12
+ "tagName": "pie-tool-theme",
13
+ "customElement": true,
14
+ "members": [
15
+ {
16
+ "kind": "field",
17
+ "name": "visible",
18
+ "type": {
19
+ "text": "boolean"
20
+ },
21
+ "default": "false",
22
+ "attribute": "visible"
23
+ },
24
+ {
25
+ "kind": "field",
26
+ "name": "toolId",
27
+ "type": {
28
+ "text": "string"
29
+ },
30
+ "default": "'theme'",
31
+ "attribute": "tool-id"
32
+ }
33
+ ],
34
+ "attributes": [
35
+ {
36
+ "name": "visible",
37
+ "type": {
38
+ "text": "boolean"
39
+ },
40
+ "default": "false",
41
+ "fieldName": "visible"
42
+ },
43
+ {
44
+ "name": "tool-id",
45
+ "type": {
46
+ "text": "string"
47
+ },
48
+ "default": "'theme'",
49
+ "fieldName": "toolId"
50
+ }
51
+ ],
52
+ "x-pie": {
53
+ "shadow": "open"
54
+ }
55
+ }
56
+ ],
57
+ "exports": [
58
+ {
59
+ "kind": "custom-element-definition",
60
+ "name": "pie-theme",
61
+ "declaration": {
62
+ "name": "PieThemeElement",
63
+ "module": "dist/index.js",
64
+ "package": "@pie-players/pie-theme"
65
+ }
66
+ },
67
+ {
68
+ "kind": "custom-element-definition",
69
+ "name": "pie-tool-theme",
70
+ "declaration": {
71
+ "name": "ToolColorScheme"
72
+ }
73
+ }
74
+ ]
75
+ }
76
+ ]
77
+ }