@pie-qti/default-components 0.1.1

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.
Files changed (146) hide show
  1. package/.turbo/turbo-build.log +1 -0
  2. package/CHANGELOG.md +9 -0
  3. package/STYLING.md +226 -0
  4. package/dist/index.d.ts +35 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +190 -0
  7. package/dist/plugins/associate/index.d.ts +8 -0
  8. package/dist/plugins/associate/index.d.ts.map +1 -0
  9. package/dist/plugins/associate/index.js +8 -0
  10. package/dist/plugins/choice/index.d.ts +8 -0
  11. package/dist/plugins/choice/index.d.ts.map +1 -0
  12. package/dist/plugins/choice/index.js +8 -0
  13. package/dist/plugins/custom/index.d.ts +8 -0
  14. package/dist/plugins/custom/index.d.ts.map +1 -0
  15. package/dist/plugins/custom/index.js +8 -0
  16. package/dist/plugins/end-attempt/index.d.ts +8 -0
  17. package/dist/plugins/end-attempt/index.d.ts.map +1 -0
  18. package/dist/plugins/end-attempt/index.js +8 -0
  19. package/dist/plugins/extended-text/index.d.ts +8 -0
  20. package/dist/plugins/extended-text/index.d.ts.map +1 -0
  21. package/dist/plugins/extended-text/index.js +8 -0
  22. package/dist/plugins/gap-match/index.d.ts +8 -0
  23. package/dist/plugins/gap-match/index.d.ts.map +1 -0
  24. package/dist/plugins/gap-match/index.js +8 -0
  25. package/dist/plugins/graphic-associate/index.d.ts +8 -0
  26. package/dist/plugins/graphic-associate/index.d.ts.map +1 -0
  27. package/dist/plugins/graphic-associate/index.js +8 -0
  28. package/dist/plugins/graphic-gap-match/index.d.ts +8 -0
  29. package/dist/plugins/graphic-gap-match/index.d.ts.map +1 -0
  30. package/dist/plugins/graphic-gap-match/index.js +8 -0
  31. package/dist/plugins/graphic-order/index.d.ts +8 -0
  32. package/dist/plugins/graphic-order/index.d.ts.map +1 -0
  33. package/dist/plugins/graphic-order/index.js +8 -0
  34. package/dist/plugins/hotspot/index.d.ts +8 -0
  35. package/dist/plugins/hotspot/index.d.ts.map +1 -0
  36. package/dist/plugins/hotspot/index.js +8 -0
  37. package/dist/plugins/hottext/index.d.ts +8 -0
  38. package/dist/plugins/hottext/index.d.ts.map +1 -0
  39. package/dist/plugins/hottext/index.js +8 -0
  40. package/dist/plugins/index.d.ts +30 -0
  41. package/dist/plugins/index.d.ts.map +1 -0
  42. package/dist/plugins/index.js +30 -0
  43. package/dist/plugins/match/index.d.ts +8 -0
  44. package/dist/plugins/match/index.d.ts.map +1 -0
  45. package/dist/plugins/match/index.js +8 -0
  46. package/dist/plugins/media/index.d.ts +8 -0
  47. package/dist/plugins/media/index.d.ts.map +1 -0
  48. package/dist/plugins/media/index.js +8 -0
  49. package/dist/plugins/order/index.d.ts +8 -0
  50. package/dist/plugins/order/index.d.ts.map +1 -0
  51. package/dist/plugins/order/index.js +8 -0
  52. package/dist/plugins/position-object/index.d.ts +8 -0
  53. package/dist/plugins/position-object/index.d.ts.map +1 -0
  54. package/dist/plugins/position-object/index.js +8 -0
  55. package/dist/plugins/select-point/index.d.ts +8 -0
  56. package/dist/plugins/select-point/index.d.ts.map +1 -0
  57. package/dist/plugins/select-point/index.js +8 -0
  58. package/dist/plugins/slider/index.d.ts +8 -0
  59. package/dist/plugins/slider/index.d.ts.map +1 -0
  60. package/dist/plugins/slider/index.js +8 -0
  61. package/dist/shared/actions/typesetAction.d.ts +26 -0
  62. package/dist/shared/actions/typesetAction.d.ts.map +1 -0
  63. package/dist/shared/actions/typesetAction.js +70 -0
  64. package/dist/shared/extensions/MathLiveEditor.d.ts +19 -0
  65. package/dist/shared/extensions/MathLiveEditor.d.ts.map +1 -0
  66. package/dist/shared/extensions/MathLiveEditor.js +239 -0
  67. package/dist/shared/index.d.ts +11 -0
  68. package/dist/shared/index.d.ts.map +1 -0
  69. package/dist/shared/index.js +15 -0
  70. package/dist/shared/utils/eventHelpers.d.ts +18 -0
  71. package/dist/shared/utils/eventHelpers.d.ts.map +1 -0
  72. package/dist/shared/utils/eventHelpers.js +30 -0
  73. package/dist/shared/utils/pairHelpers.d.ts +55 -0
  74. package/dist/shared/utils/pairHelpers.d.ts.map +1 -0
  75. package/dist/shared/utils/pairHelpers.js +76 -0
  76. package/dist/shared/utils/touchDragHelper.d.ts +33 -0
  77. package/dist/shared/utils/touchDragHelper.d.ts.map +1 -0
  78. package/dist/shared/utils/touchDragHelper.js +168 -0
  79. package/dist/shared/utils/webComponentHelpers.d.ts +9 -0
  80. package/dist/shared/utils/webComponentHelpers.d.ts.map +1 -0
  81. package/dist/shared/utils/webComponentHelpers.js +26 -0
  82. package/package.json +93 -0
  83. package/src/index.ts +213 -0
  84. package/src/plugins/associate/AssociateInteraction.svelte +273 -0
  85. package/src/plugins/associate/index.ts +9 -0
  86. package/src/plugins/choice/ChoiceInteraction.svelte +212 -0
  87. package/src/plugins/choice/index.ts +9 -0
  88. package/src/plugins/custom/CustomInteraction.svelte +61 -0
  89. package/src/plugins/custom/index.ts +9 -0
  90. package/src/plugins/drawing/DrawingInteraction.svelte +90 -0
  91. package/src/plugins/end-attempt/EndAttemptInteraction.svelte +142 -0
  92. package/src/plugins/end-attempt/index.ts +9 -0
  93. package/src/plugins/extended-text/ExtendedTextInteraction.svelte +77 -0
  94. package/src/plugins/extended-text/index.ts +9 -0
  95. package/src/plugins/gap-match/GapMatchInteraction.svelte +379 -0
  96. package/src/plugins/gap-match/index.ts +9 -0
  97. package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +427 -0
  98. package/src/plugins/graphic-associate/index.ts +9 -0
  99. package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +508 -0
  100. package/src/plugins/graphic-gap-match/index.ts +9 -0
  101. package/src/plugins/graphic-order/GraphicOrderInteraction.svelte +241 -0
  102. package/src/plugins/graphic-order/index.ts +9 -0
  103. package/src/plugins/hotspot/HotspotInteraction.svelte +244 -0
  104. package/src/plugins/hotspot/index.ts +9 -0
  105. package/src/plugins/hottext/HottextInteraction.svelte +296 -0
  106. package/src/plugins/hottext/index.ts +9 -0
  107. package/src/plugins/index.ts +31 -0
  108. package/src/plugins/match/MatchInteraction.svelte +70 -0
  109. package/src/plugins/match/index.ts +9 -0
  110. package/src/plugins/media/MediaInteraction.svelte +213 -0
  111. package/src/plugins/media/index.ts +9 -0
  112. package/src/plugins/order/OrderInteraction.svelte +159 -0
  113. package/src/plugins/order/index.ts +9 -0
  114. package/src/plugins/position-object/PositionObjectInteraction.svelte +671 -0
  115. package/src/plugins/position-object/README.md +130 -0
  116. package/src/plugins/position-object/index.ts +9 -0
  117. package/src/plugins/select-point/SelectPointInteraction.svelte +453 -0
  118. package/src/plugins/select-point/index.ts +9 -0
  119. package/src/plugins/slider/SliderInteraction.svelte +141 -0
  120. package/src/plugins/slider/index.ts +9 -0
  121. package/src/plugins/upload/UploadInteraction.svelte +59 -0
  122. package/src/shared/actions/typesetAction.ts +87 -0
  123. package/src/shared/components/CustomInteractionFallback.svelte +153 -0
  124. package/src/shared/components/DragHandle.svelte +44 -0
  125. package/src/shared/components/DrawingCanvas.svelte +243 -0
  126. package/src/shared/components/FileUpload.svelte +153 -0
  127. package/src/shared/components/GraphicGapMatch.svelte +316 -0
  128. package/src/shared/components/GraphicGapMatchAdapter.svelte +36 -0
  129. package/src/shared/components/InlineInteractionRenderer.svelte +124 -0
  130. package/src/shared/components/MatchDragDrop.svelte +434 -0
  131. package/src/shared/components/MathContent.svelte +18 -0
  132. package/src/shared/components/ModalFeedbackDisplay.svelte +81 -0
  133. package/src/shared/components/RichTextEditor.svelte +316 -0
  134. package/src/shared/components/ShadowBaseStyles.svelte +391 -0
  135. package/src/shared/components/SortableList.svelte +297 -0
  136. package/src/shared/extensions/MathLiveEditor.ts +304 -0
  137. package/src/shared/index.ts +17 -0
  138. package/src/shared/styles/shared.css +16 -0
  139. package/src/shared/utils/eventHelpers.ts +36 -0
  140. package/src/shared/utils/pairHelpers.ts +86 -0
  141. package/src/shared/utils/touchDragHelper.ts +211 -0
  142. package/src/shared/utils/webComponentHelpers.ts +27 -0
  143. package/src/svelte-shims.d.ts +9 -0
  144. package/svelte.config.js +9 -0
  145. package/tests/index.test.ts +8 -0
  146. package/tsconfig.json +20 -0
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Utility functions for working with QTI pair responses
3
+ * Pairs are represented as space-separated strings: "sourceId targetId"
4
+ */
5
+
6
+ /**
7
+ * Gets the target ID matched with a source ID
8
+ * @param pairs - Array of "sourceId targetId" pair strings
9
+ * @param sourceId - The source identifier to search for
10
+ * @returns The matched target ID, or null if not found
11
+ */
12
+ export function getTargetForSource(pairs: string[], sourceId: string): string | null {
13
+ const pair = pairs.find((p) => p.startsWith(`${sourceId} `));
14
+ return pair ? pair.split(' ')[1] : null;
15
+ }
16
+
17
+ /**
18
+ * Gets the source ID matched with a target ID
19
+ * @param pairs - Array of "sourceId targetId" pair strings
20
+ * @param targetId - The target identifier to search for
21
+ * @returns The matched source ID, or null if not found
22
+ */
23
+ export function getSourceForTarget(pairs: string[], targetId: string): string | null {
24
+ const pair = pairs.find((p) => p.endsWith(` ${targetId}`));
25
+ return pair ? pair.split(' ')[0] : null;
26
+ }
27
+
28
+ /**
29
+ * Creates or updates a pair, removing any existing pairs for the source or target
30
+ * @param pairs - Array of existing pair strings
31
+ * @param sourceId - The source identifier
32
+ * @param targetId - The target identifier
33
+ * @returns A new array with the pair created/updated
34
+ */
35
+ export function createOrUpdatePair(pairs: string[], sourceId: string, targetId: string): string[] {
36
+ // Remove any existing pair for this source
37
+ let newPairs = pairs.filter((p) => !p.startsWith(`${sourceId} `));
38
+
39
+ // Remove any existing pair for this target
40
+ newPairs = newPairs.filter((p) => !p.endsWith(` ${targetId}`));
41
+
42
+ // Add new pair
43
+ newPairs.push(`${sourceId} ${targetId}`);
44
+
45
+ return newPairs;
46
+ }
47
+
48
+ /**
49
+ * Removes a pair by source ID
50
+ * @param pairs - Array of existing pair strings
51
+ * @param sourceId - The source identifier to remove
52
+ * @returns A new array without the pair
53
+ */
54
+ export function removePairBySource(pairs: string[], sourceId: string): string[] {
55
+ return pairs.filter((p) => !p.startsWith(`${sourceId} `));
56
+ }
57
+
58
+ /**
59
+ * Removes a pair by target ID
60
+ * @param pairs - Array of existing pair strings
61
+ * @param targetId - The target identifier to remove
62
+ * @returns A new array without the pair
63
+ */
64
+ export function removePairByTarget(pairs: string[], targetId: string): string[] {
65
+ return pairs.filter((p) => !p.endsWith(` ${targetId}`));
66
+ }
67
+
68
+ /**
69
+ * Checks if a source is paired
70
+ * @param pairs - Array of pair strings
71
+ * @param sourceId - The source identifier
72
+ * @returns True if the source has a pair
73
+ */
74
+ export function isSourcePaired(pairs: string[], sourceId: string): boolean {
75
+ return pairs.some((p) => p.startsWith(`${sourceId} `));
76
+ }
77
+
78
+ /**
79
+ * Checks if a target is paired
80
+ * @param pairs - Array of pair strings
81
+ * @param targetId - The target identifier
82
+ * @returns True if the target has a pair
83
+ */
84
+ export function isTargetPaired(pairs: string[], targetId: string): boolean {
85
+ return pairs.some((p) => p.endsWith(` ${targetId}`));
86
+ }
@@ -0,0 +1,211 @@
1
+ /**
2
+ * Touch-enabled drag helper for making HTML5 drag-and-drop work with touch devices
3
+ *
4
+ * HTML5 drag-and-drop API doesn't work on touch devices by default.
5
+ * This helper translates touch events to pointer events for unified handling.
6
+ *
7
+ * Usage:
8
+ * ```svelte
9
+ * <div
10
+ * use:touchDrag
11
+ * draggable="true"
12
+ * ondragstart={...}
13
+ * >
14
+ * ```
15
+ */
16
+
17
+ interface TouchDragState {
18
+ element: HTMLElement;
19
+ touchId: number | null;
20
+ isDragging: boolean;
21
+ startX: number;
22
+ startY: number;
23
+ currentX: number;
24
+ currentY: number;
25
+ dragThreshold: number;
26
+ }
27
+
28
+ /**
29
+ * Svelte action to enable touch drag on draggable elements
30
+ */
31
+ export function touchDrag(node: HTMLElement) {
32
+ const state: TouchDragState = {
33
+ element: node,
34
+ touchId: null,
35
+ isDragging: false,
36
+ startX: 0,
37
+ startY: 0,
38
+ currentX: 0,
39
+ currentY: 0,
40
+ dragThreshold: 10 // px movement to initiate drag
41
+ };
42
+
43
+ function handleTouchStart(e: TouchEvent) {
44
+ // Only handle single touch
45
+ if (e.touches.length !== 1) return;
46
+
47
+ // Check if element is draggable
48
+ const draggable = node.getAttribute('draggable');
49
+ if (draggable !== 'true') return;
50
+
51
+ const touch = e.touches[0];
52
+ state.touchId = touch.identifier;
53
+ state.startX = touch.clientX;
54
+ state.startY = touch.clientY;
55
+ state.currentX = touch.clientX;
56
+ state.currentY = touch.clientY;
57
+ state.isDragging = false;
58
+
59
+ // Add move and end listeners to document for consistent tracking
60
+ document.addEventListener('touchmove', handleTouchMove, { passive: false });
61
+ document.addEventListener('touchend', handleTouchEnd);
62
+ document.addEventListener('touchcancel', handleTouchCancel);
63
+ }
64
+
65
+ function handleTouchMove(e: TouchEvent) {
66
+ if (state.touchId === null) return;
67
+
68
+ // Find the touch we're tracking
69
+ const touch = Array.from(e.changedTouches).find(t => t.identifier === state.touchId);
70
+ if (!touch) return;
71
+
72
+ state.currentX = touch.clientX;
73
+ state.currentY = touch.clientY;
74
+
75
+ // Check if we've moved enough to start dragging
76
+ const deltaX = state.currentX - state.startX;
77
+ const deltaY = state.currentY - state.startY;
78
+ const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
79
+
80
+ if (!state.isDragging && distance > state.dragThreshold) {
81
+ // Start drag
82
+ state.isDragging = true;
83
+
84
+ // Trigger dragstart event
85
+ const dragStartEvent = new DragEvent('dragstart', {
86
+ bubbles: true,
87
+ cancelable: true,
88
+ clientX: state.startX,
89
+ clientY: state.startY
90
+ });
91
+
92
+ node.dispatchEvent(dragStartEvent);
93
+
94
+ // Add visual feedback
95
+ node.style.opacity = '0.5';
96
+ e.preventDefault(); // Prevent scrolling
97
+ }
98
+
99
+ if (state.isDragging) {
100
+ e.preventDefault(); // Prevent scrolling while dragging
101
+
102
+ // Find element under touch point
103
+ const elementUnder = document.elementFromPoint(state.currentX, state.currentY);
104
+
105
+ if (elementUnder && elementUnder !== node) {
106
+ // Trigger dragover on the element under touch
107
+ const dragOverEvent = new DragEvent('dragover', {
108
+ bubbles: true,
109
+ cancelable: true,
110
+ clientX: state.currentX,
111
+ clientY: state.currentY
112
+ });
113
+
114
+ elementUnder.dispatchEvent(dragOverEvent);
115
+ }
116
+ }
117
+ }
118
+
119
+ function handleTouchEnd(e: TouchEvent) {
120
+ if (state.touchId === null) return;
121
+
122
+ // Find the touch we're tracking
123
+ const touch = Array.from(e.changedTouches).find(t => t.identifier === state.touchId);
124
+ if (!touch) return;
125
+
126
+ if (state.isDragging) {
127
+ // Find element under touch point at drop location
128
+ const elementUnder = document.elementFromPoint(touch.clientX, touch.clientY);
129
+
130
+ if (elementUnder) {
131
+ // Trigger drop event
132
+ const dropEvent = new DragEvent('drop', {
133
+ bubbles: true,
134
+ cancelable: true,
135
+ clientX: touch.clientX,
136
+ clientY: touch.clientY
137
+ });
138
+
139
+ elementUnder.dispatchEvent(dropEvent);
140
+ }
141
+
142
+ // Trigger dragend
143
+ const dragEndEvent = new DragEvent('dragend', {
144
+ bubbles: true,
145
+ cancelable: true
146
+ });
147
+
148
+ node.dispatchEvent(dragEndEvent);
149
+
150
+ // Reset visual feedback
151
+ node.style.opacity = '';
152
+ }
153
+
154
+ cleanup();
155
+ }
156
+
157
+ function handleTouchCancel() {
158
+ if (state.isDragging) {
159
+ // Trigger dragend
160
+ const dragEndEvent = new DragEvent('dragend', {
161
+ bubbles: true,
162
+ cancelable: true
163
+ });
164
+
165
+ node.dispatchEvent(dragEndEvent);
166
+
167
+ // Reset visual feedback
168
+ node.style.opacity = '';
169
+ }
170
+
171
+ cleanup();
172
+ }
173
+
174
+ function cleanup() {
175
+ state.touchId = null;
176
+ state.isDragging = false;
177
+
178
+ document.removeEventListener('touchmove', handleTouchMove);
179
+ document.removeEventListener('touchend', handleTouchEnd);
180
+ document.removeEventListener('touchcancel', handleTouchCancel);
181
+ }
182
+
183
+ // Attach initial touch listener
184
+ node.addEventListener('touchstart', handleTouchStart, { passive: true });
185
+
186
+ return {
187
+ destroy() {
188
+ node.removeEventListener('touchstart', handleTouchStart);
189
+ cleanup();
190
+ }
191
+ };
192
+ }
193
+
194
+ /**
195
+ * CSS helper for touch-friendly drag interactions
196
+ * Returns CSS that should be applied to draggable elements
197
+ */
198
+ export const touchDragStyles = {
199
+ /* Prevent text selection during drag */
200
+ userSelect: 'none',
201
+ webkitUserSelect: 'none',
202
+
203
+ /* Allow touch events */
204
+ touchAction: 'none',
205
+
206
+ /* Cursor feedback */
207
+ cursor: 'grab',
208
+
209
+ /* Smooth transitions */
210
+ transition: 'opacity 0.2s ease'
211
+ } as const;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Helper utilities for web component prop handling
3
+ */
4
+
5
+ /**
6
+ * Parse a prop that may be a JSON string or an object
7
+ * Used when components are used as web components and receive JSON strings
8
+ */
9
+ export function parseJsonProp<T>(prop: T | string | null | undefined): T | null {
10
+ if (prop === null || prop === undefined) return null;
11
+
12
+ if (typeof prop === 'string') {
13
+ // Handle "null" string
14
+ if (prop === 'null') return null;
15
+
16
+ // Try to parse as JSON
17
+ try {
18
+ return JSON.parse(prop);
19
+ } catch (e) {
20
+ // If it's not valid JSON, return the string as-is
21
+ // This handles simple string identifiers
22
+ return prop as unknown as T;
23
+ }
24
+ }
25
+
26
+ return prop as T;
27
+ }
@@ -0,0 +1,9 @@
1
+ declare module '*.svelte' {
2
+ import type { Component } from 'svelte';
3
+ const component: Component<any>;
4
+ export default component;
5
+ }
6
+
7
+
8
+
9
+
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Svelte config for default-components
3
+ * Enables custom element compilation for web components
4
+ */
5
+ export default {
6
+ compilerOptions: {
7
+ customElement: true,
8
+ },
9
+ };
@@ -0,0 +1,8 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+
3
+ describe('default-components', () => {
4
+ it('should export registerDefaultComponents', () => {
5
+ const { registerDefaultComponents } = require('../src/index');
6
+ expect(typeof registerDefaultComponents).toBe('function');
7
+ });
8
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "lib": ["ES2020", "DOM"],
6
+ "declaration": true,
7
+ "declarationMap": true,
8
+ "outDir": "./dist",
9
+ "rootDir": "./src",
10
+ "strict": true,
11
+ "esModuleInterop": true,
12
+ "skipLibCheck": true,
13
+ "forceConsistentCasingInFileNames": true,
14
+ "moduleResolution": "bundler",
15
+ "resolveJsonModule": true,
16
+ "allowSyntheticDefaultImports": true
17
+ },
18
+ "include": ["src/**/*.ts", "src/**/*.d.ts"],
19
+ "exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.spec.ts", "**/*.svelte"]
20
+ }