@pie-players/pie-tool-calculator-inline-desmos 0.3.3

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 ADDED
@@ -0,0 +1,190 @@
1
+ # @pie-players/pie-tool-calculator-inline-desmos
2
+
3
+ Inline calculator toggle button for PIE assessment player question headers.
4
+
5
+ ## Overview
6
+
7
+ This package provides a calculator button component that can be embedded in question headers. When clicked, it toggles the visibility of a full calculator tool instance (`@pie-players/pie-tool-calculator-desmos`).
8
+
9
+ ## Features
10
+
11
+ - **Web Component** - Custom element with no shadow DOM for better integration
12
+ - **Imperative API** - Services passed as JavaScript properties
13
+ - **Coordinator Integration** - Managed by ToolCoordinator for consistent state
14
+ - **Size Variants** - Supports sm, md, lg button sizes
15
+ - **WCAG 2.2 Level AA** - Fully accessible with proper ARIA attributes
16
+ - **Material Design Icon** - Calculator icon from Material Design
17
+
18
+ ## Usage
19
+
20
+ ### Basic Setup
21
+
22
+ ```svelte
23
+ <!-- Import the component -->
24
+ <script>
25
+ import '@pie-players/pie-tool-calculator-inline-desmos';
26
+ import '@pie-players/pie-tool-calculator-desmos';
27
+ import { ToolCoordinator } from '@pie-players/pie-assessment-toolkit';
28
+
29
+ const coordinator = new ToolCoordinator();
30
+ let calculatorInlineEl;
31
+ let calculatorEl;
32
+ let calculatorVisible = false;
33
+
34
+ // Bind services imperatively (after element creation)
35
+ $effect(() => {
36
+ if (calculatorInlineEl) {
37
+ calculatorInlineEl.coordinator = coordinator;
38
+ }
39
+ if (calculatorEl) {
40
+ calculatorEl.coordinator = coordinator;
41
+ }
42
+ });
43
+
44
+ // Subscribe to visibility changes
45
+ $effect(() => {
46
+ if (coordinator) {
47
+ const unsubscribe = coordinator.subscribe(() => {
48
+ calculatorVisible = coordinator.isToolVisible('calculator');
49
+ });
50
+ return unsubscribe;
51
+ }
52
+ });
53
+ </script>
54
+
55
+ <!-- Inline toggle button -->
56
+ <pie-tool-calculator-inline
57
+ bind:this={calculatorInlineEl}
58
+ tool-id="calculator-inline"
59
+ calculator-type="scientific"
60
+ available-types="basic,scientific,graphing"
61
+ size="md"
62
+ ></pie-tool-calculator-inline>
63
+
64
+ <!-- Calculator tool instance (hidden/shown by coordinator) -->
65
+ <pie-tool-calculator
66
+ bind:this={calculatorEl}
67
+ visible={calculatorVisible}
68
+ tool-id="calculator"
69
+ ></pie-tool-calculator>
70
+ ```
71
+
72
+ ### In ItemToolBar
73
+
74
+ The component is designed to work with `pie-item-toolbar`:
75
+
76
+ ```svelte
77
+ <pie-item-toolbar
78
+ item-id="question-1"
79
+ tools="tts,answerEliminator,calculator"
80
+ size="md"
81
+ ></pie-item-toolbar>
82
+ ```
83
+
84
+ The toolbar will automatically:
85
+ 1. Render the calculator inline button
86
+ 2. Bind the coordinator imperatively
87
+ 3. Manage the calculator visibility state
88
+
89
+ ### Props
90
+
91
+ #### Attributes (String)
92
+
93
+ - `tool-id` - Unique identifier for the tool (default: `'calculator-inline'`)
94
+ - `calculator-type` - Default calculator type (default: `'scientific'`)
95
+ - `available-types` - Comma-separated list of calculator types (default: `'basic,scientific,graphing'`)
96
+ - `size` - Button size: `'sm' | 'md' | 'lg'` (default: `'md'`)
97
+
98
+ #### JavaScript Properties
99
+
100
+ - `coordinator` - IToolCoordinator instance (required)
101
+
102
+ **Important:** The `coordinator` property must be set via JavaScript, not as an attribute:
103
+
104
+ ```javascript
105
+ element.coordinator = coordinatorInstance;
106
+ ```
107
+
108
+ ## Calculator Tool Integration
109
+
110
+ This component works in tandem with `@pie-players/pie-tool-calculator-desmos`. The flow is:
111
+
112
+ 1. **Button renders** - `pie-tool-calculator-inline` shows a toggle button
113
+ 2. **User clicks** - Button calls `coordinator.toggleTool('calculator')`
114
+ 3. **Calculator shows/hides** - `pie-tool-calculator` reacts to visibility state
115
+ 4. **Button updates** - Active state reflects calculator visibility
116
+
117
+ ## Tool ID Convention
118
+
119
+ The inline button typically uses a different tool ID than the calculator instance:
120
+
121
+ - Inline button: `calculator-inline` or `calculator-inline-{itemId}`
122
+ - Calculator tool: `calculator` or `calculator-{itemId}`
123
+
124
+ The component automatically strips `-inline` suffix when checking calculator visibility.
125
+
126
+ ## Accessibility
127
+
128
+ - **WCAG 2.2 Level AA compliant**
129
+ - **Keyboard accessible** - Full keyboard navigation support
130
+ - **Focus indicators** - Clear focus states (2.4.7, 2.4.13)
131
+ - **ARIA attributes** - `aria-label`, `aria-pressed`
132
+ - **Screen reader announcements** - Status changes announced
133
+ - **Reduced motion** - Respects `prefers-reduced-motion`
134
+ - **Touch targets** - Minimum 44px touch target (2.5.2)
135
+
136
+ ## Size Variants
137
+
138
+ ### Small (`sm`)
139
+ - Visual size: 1.5rem × 1.5rem
140
+ - Touch target: 44px × 44px (with padding)
141
+ - Icon: 1rem × 1rem
142
+
143
+ ### Medium (`md`) - Default
144
+ - Size: 2rem × 2rem
145
+ - Icon: 1.25rem × 1.25rem
146
+
147
+ ### Large (`lg`)
148
+ - Size: 2.5rem × 2.5rem
149
+ - Icon: 1.5rem × 1.5rem
150
+
151
+ ## Styling
152
+
153
+ The component uses CSS custom properties for theming:
154
+
155
+ ```css
156
+ --pie-border: Border color (default: #ccc)
157
+ --pie-background: Background color (default: white)
158
+ --pie-text: Text color (default: #333)
159
+ --pie-secondary-background: Hover background (default: #f5f5f5)
160
+ --pie-primary: Active state background (default: #1976d2)
161
+ --pie-primary-dark: Active hover background (default: #1565c0)
162
+ ```
163
+
164
+ ## Development
165
+
166
+ ```bash
167
+ # Install dependencies
168
+ bun install
169
+
170
+ # Build
171
+ bun run build
172
+
173
+ # Watch mode
174
+ bun run dev
175
+
176
+ # Type check
177
+ bun run typecheck
178
+
179
+ # Lint
180
+ bun run lint
181
+ ```
182
+
183
+ ## Dependencies
184
+
185
+ - `@pie-players/pie-assessment-toolkit` - Core toolkit services
186
+ - `svelte` - Framework (peer dependency)
187
+
188
+ ## License
189
+
190
+ MIT