@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,8 @@
1
+ // Svelte component exported via web component
2
+ export const metadata = {
3
+ interactionType: 'graphicOrderInteraction',
4
+ tagName: 'pie-qti-graphic-order',
5
+ name: 'default-graphic-order',
6
+ description: 'Default Svelte-based graphic order interaction',
7
+ priority: 0,
8
+ };
@@ -0,0 +1,8 @@
1
+ export declare const metadata: {
2
+ interactionType: string;
3
+ tagName: string;
4
+ name: string;
5
+ description: string;
6
+ priority: number;
7
+ };
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/hotspot/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ;;;;;;CAMpB,CAAC"}
@@ -0,0 +1,8 @@
1
+ // Svelte component exported via web component
2
+ export const metadata = {
3
+ interactionType: 'hotspotInteraction',
4
+ tagName: 'pie-qti-hotspot',
5
+ name: 'default-hotspot',
6
+ description: 'Default Svelte-based hotspot interaction',
7
+ priority: 0,
8
+ };
@@ -0,0 +1,8 @@
1
+ export declare const metadata: {
2
+ interactionType: string;
3
+ tagName: string;
4
+ name: string;
5
+ description: string;
6
+ priority: number;
7
+ };
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/hottext/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ;;;;;;CAMpB,CAAC"}
@@ -0,0 +1,8 @@
1
+ // Svelte component exported via web component
2
+ export const metadata = {
3
+ interactionType: 'hottextInteraction',
4
+ tagName: 'pie-qti-hottext',
5
+ name: 'default-hottext',
6
+ description: 'Default Svelte-based hottext interaction',
7
+ priority: 0,
8
+ };
@@ -0,0 +1,30 @@
1
+ /**
2
+ * QTI Interaction Plugins
3
+ *
4
+ * Imports all interaction plugins to trigger web component registration.
5
+ * Each plugin directory contains a Svelte component that compiles to a
6
+ * custom element (web component).
7
+ *
8
+ * These imports have side effects: they register the custom elements
9
+ * with the browser's customElements registry.
10
+ */
11
+ import './choice/ChoiceInteraction.svelte';
12
+ import './slider/SliderInteraction.svelte';
13
+ import './order/OrderInteraction.svelte';
14
+ import './match/MatchInteraction.svelte';
15
+ import './associate/AssociateInteraction.svelte';
16
+ import './gap-match/GapMatchInteraction.svelte';
17
+ import './hotspot/HotspotInteraction.svelte';
18
+ import './hottext/HottextInteraction.svelte';
19
+ import './media/MediaInteraction.svelte';
20
+ import './custom/CustomInteraction.svelte';
21
+ import './end-attempt/EndAttemptInteraction.svelte';
22
+ import './position-object/PositionObjectInteraction.svelte';
23
+ import './graphic-gap-match/GraphicGapMatchInteraction.svelte';
24
+ import './graphic-order/GraphicOrderInteraction.svelte';
25
+ import './graphic-associate/GraphicAssociateInteraction.svelte';
26
+ import './select-point/SelectPointInteraction.svelte';
27
+ import './extended-text/ExtendedTextInteraction.svelte';
28
+ import './upload/UploadInteraction.svelte';
29
+ import './drawing/DrawingInteraction.svelte';
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,mCAAmC,CAAC;AAC3C,OAAO,mCAAmC,CAAC;AAC3C,OAAO,iCAAiC,CAAC;AACzC,OAAO,iCAAiC,CAAC;AACzC,OAAO,yCAAyC,CAAC;AACjD,OAAO,wCAAwC,CAAC;AAChD,OAAO,qCAAqC,CAAC;AAC7C,OAAO,qCAAqC,CAAC;AAC7C,OAAO,iCAAiC,CAAC;AACzC,OAAO,mCAAmC,CAAC;AAC3C,OAAO,4CAA4C,CAAC;AACpD,OAAO,oDAAoD,CAAC;AAC5D,OAAO,uDAAuD,CAAC;AAC/D,OAAO,gDAAgD,CAAC;AACxD,OAAO,wDAAwD,CAAC;AAChE,OAAO,8CAA8C,CAAC;AACtD,OAAO,gDAAgD,CAAC;AACxD,OAAO,mCAAmC,CAAC;AAC3C,OAAO,qCAAqC,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * QTI Interaction Plugins
3
+ *
4
+ * Imports all interaction plugins to trigger web component registration.
5
+ * Each plugin directory contains a Svelte component that compiles to a
6
+ * custom element (web component).
7
+ *
8
+ * These imports have side effects: they register the custom elements
9
+ * with the browser's customElements registry.
10
+ */
11
+ // Import all Svelte custom element components to trigger registration
12
+ import './choice/ChoiceInteraction.svelte';
13
+ import './slider/SliderInteraction.svelte';
14
+ import './order/OrderInteraction.svelte';
15
+ import './match/MatchInteraction.svelte';
16
+ import './associate/AssociateInteraction.svelte';
17
+ import './gap-match/GapMatchInteraction.svelte';
18
+ import './hotspot/HotspotInteraction.svelte';
19
+ import './hottext/HottextInteraction.svelte';
20
+ import './media/MediaInteraction.svelte';
21
+ import './custom/CustomInteraction.svelte';
22
+ import './end-attempt/EndAttemptInteraction.svelte';
23
+ import './position-object/PositionObjectInteraction.svelte';
24
+ import './graphic-gap-match/GraphicGapMatchInteraction.svelte';
25
+ import './graphic-order/GraphicOrderInteraction.svelte';
26
+ import './graphic-associate/GraphicAssociateInteraction.svelte';
27
+ import './select-point/SelectPointInteraction.svelte';
28
+ import './extended-text/ExtendedTextInteraction.svelte';
29
+ import './upload/UploadInteraction.svelte';
30
+ import './drawing/DrawingInteraction.svelte';
@@ -0,0 +1,8 @@
1
+ export declare const metadata: {
2
+ interactionType: string;
3
+ tagName: string;
4
+ name: string;
5
+ description: string;
6
+ priority: number;
7
+ };
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/match/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ;;;;;;CAMpB,CAAC"}
@@ -0,0 +1,8 @@
1
+ // Svelte component exported via web component
2
+ export const metadata = {
3
+ interactionType: 'matchInteraction',
4
+ tagName: 'pie-qti-match',
5
+ name: 'default-match',
6
+ description: 'Default Svelte-based match interaction',
7
+ priority: 0,
8
+ };
@@ -0,0 +1,8 @@
1
+ export declare const metadata: {
2
+ interactionType: string;
3
+ tagName: string;
4
+ name: string;
5
+ description: string;
6
+ priority: number;
7
+ };
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/media/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ;;;;;;CAMpB,CAAC"}
@@ -0,0 +1,8 @@
1
+ // Svelte component exported via web component
2
+ export const metadata = {
3
+ interactionType: 'mediaInteraction',
4
+ tagName: 'pie-qti-media',
5
+ name: 'default-media',
6
+ description: 'Default Svelte-based media interaction',
7
+ priority: 0,
8
+ };
@@ -0,0 +1,8 @@
1
+ export declare const metadata: {
2
+ interactionType: string;
3
+ tagName: string;
4
+ name: string;
5
+ description: string;
6
+ priority: number;
7
+ };
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/order/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ;;;;;;CAMpB,CAAC"}
@@ -0,0 +1,8 @@
1
+ // Svelte component exported via web component
2
+ export const metadata = {
3
+ interactionType: 'orderInteraction',
4
+ tagName: 'pie-qti-order',
5
+ name: 'default-order',
6
+ description: 'Default Svelte-based order interaction',
7
+ priority: 0,
8
+ };
@@ -0,0 +1,8 @@
1
+ export declare const metadata: {
2
+ interactionType: string;
3
+ tagName: string;
4
+ name: string;
5
+ description: string;
6
+ priority: number;
7
+ };
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/position-object/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ;;;;;;CAMpB,CAAC"}
@@ -0,0 +1,8 @@
1
+ // Svelte component exported via web component
2
+ export const metadata = {
3
+ interactionType: 'positionObjectInteraction',
4
+ tagName: 'pie-qti-position-object',
5
+ name: 'default-position-object',
6
+ description: 'Default Svelte-based position object interaction',
7
+ priority: 0,
8
+ };
@@ -0,0 +1,8 @@
1
+ export declare const metadata: {
2
+ interactionType: string;
3
+ tagName: string;
4
+ name: string;
5
+ description: string;
6
+ priority: number;
7
+ };
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/select-point/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ;;;;;;CAMpB,CAAC"}
@@ -0,0 +1,8 @@
1
+ // Svelte component exported via web component
2
+ export const metadata = {
3
+ interactionType: 'selectPointInteraction',
4
+ tagName: 'pie-qti-select-point',
5
+ name: 'default-select-point',
6
+ description: 'Default Svelte-based select point interaction',
7
+ priority: 0,
8
+ };
@@ -0,0 +1,8 @@
1
+ export declare const metadata: {
2
+ interactionType: string;
3
+ tagName: string;
4
+ name: string;
5
+ description: string;
6
+ priority: number;
7
+ };
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/slider/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ;;;;;;CAMpB,CAAC"}
@@ -0,0 +1,8 @@
1
+ // Svelte component exported via web component
2
+ export const metadata = {
3
+ interactionType: 'sliderInteraction',
4
+ tagName: 'pie-qti-slider',
5
+ name: 'default-slider',
6
+ description: 'Default Svelte-based slider interaction',
7
+ priority: 0,
8
+ };
@@ -0,0 +1,26 @@
1
+ export interface TypesetActionParams {
2
+ /**
3
+ * Typeset function provided by the host app (KaTeX, MathJax, etc).
4
+ * It should be idempotent or at least safe to call repeatedly on updates.
5
+ * Optional - if not provided, the action becomes a no-op.
6
+ */
7
+ typeset?: (root: HTMLElement) => void | Promise<void>;
8
+ /**
9
+ * Observe subtree changes and re-typeset automatically.
10
+ * Default: true
11
+ */
12
+ observe?: boolean;
13
+ }
14
+ /**
15
+ * Generic Svelte action that calls `params.typeset(node)` initially and on DOM updates.
16
+ *
17
+ * This is intentionally dependency-free so the player/components can be used
18
+ * outside the example app without pulling in a math engine.
19
+ *
20
+ * If typeset is undefined, the action becomes a no-op (returns immediately).
21
+ */
22
+ export declare function typesetAction(node: HTMLElement, params?: TypesetActionParams): {
23
+ update(next?: TypesetActionParams): void;
24
+ destroy(): void;
25
+ };
26
+ //# sourceMappingURL=typesetAction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typesetAction.d.ts","sourceRoot":"","sources":["../../../src/shared/actions/typesetAction.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,mBAAmB;IACnC;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtD;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,mBAAmB;kBA4C7D,mBAAmB;;EAelC"}
@@ -0,0 +1,70 @@
1
+ /// <reference lib="dom" />
2
+ /**
3
+ * Generic Svelte action that calls `params.typeset(node)` initially and on DOM updates.
4
+ *
5
+ * This is intentionally dependency-free so the player/components can be used
6
+ * outside the example app without pulling in a math engine.
7
+ *
8
+ * If typeset is undefined, the action becomes a no-op (returns immediately).
9
+ */
10
+ export function typesetAction(node, params) {
11
+ // No-op if no typeset function provided
12
+ if (!params?.typeset) {
13
+ return { update() { }, destroy() { } };
14
+ }
15
+ const isBrowser = typeof window !== 'undefined' && typeof MutationObserver !== 'undefined';
16
+ if (!isBrowser)
17
+ return { update() { }, destroy() { } };
18
+ let disposed = false;
19
+ let scheduled = false;
20
+ let observer = null;
21
+ let current = params;
22
+ const schedule = () => {
23
+ if (disposed || scheduled || !current.typeset)
24
+ return;
25
+ scheduled = true;
26
+ requestAnimationFrame(async () => {
27
+ scheduled = false;
28
+ if (disposed || !current.typeset)
29
+ return;
30
+ try {
31
+ await current.typeset(node);
32
+ }
33
+ catch {
34
+ // ignore typesetting errors; keep raw text
35
+ }
36
+ });
37
+ };
38
+ const startObserver = () => {
39
+ if (observer)
40
+ return;
41
+ observer = new MutationObserver(() => schedule());
42
+ observer.observe(node, { childList: true, subtree: true, characterData: true });
43
+ };
44
+ const stopObserver = () => {
45
+ observer?.disconnect();
46
+ observer = null;
47
+ };
48
+ // initial
49
+ schedule();
50
+ if (current.observe !== false)
51
+ startObserver();
52
+ return {
53
+ update(next) {
54
+ if (!next?.typeset) {
55
+ stopObserver();
56
+ return;
57
+ }
58
+ current = next;
59
+ if (current.observe === false)
60
+ stopObserver();
61
+ else
62
+ startObserver();
63
+ schedule();
64
+ },
65
+ destroy() {
66
+ disposed = true;
67
+ stopObserver();
68
+ },
69
+ };
70
+ }
@@ -0,0 +1,19 @@
1
+ export interface MathLiveEditorOptions {
2
+ /** Called when user confirms the LaTeX input */
3
+ onConfirm: (latex: string) => void;
4
+ /** Called when user cancels */
5
+ onCancel: () => void;
6
+ /** Initial LaTeX value */
7
+ initialLatex?: string;
8
+ /** Whether this is inline or block math */
9
+ isBlock?: boolean;
10
+ /** Optional i18n provider for translations */
11
+ i18n?: {
12
+ t: (key: string) => string | undefined;
13
+ };
14
+ }
15
+ /**
16
+ * Opens a modal dialog with MathLive editor for LaTeX input
17
+ */
18
+ export declare function openMathLiveEditor(options: MathLiveEditorOptions): Promise<() => void>;
19
+ //# sourceMappingURL=MathLiveEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MathLiveEditor.d.ts","sourceRoot":"","sources":["../../../src/shared/extensions/MathLiveEditor.ts"],"names":[],"mappings":"AAkCA,MAAM,WAAW,qBAAqB;IACrC,gDAAgD;IAChD,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,0BAA0B;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,2CAA2C;IAC3C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,8CAA8C;IAC9C,IAAI,CAAC,EAAE;QAAE,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;CAClD;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CA6P5F"}
@@ -0,0 +1,239 @@
1
+ /// <reference lib="dom" />
2
+ // Dynamically import MathLive to register the custom element
3
+ let mathLiveLoaded = null;
4
+ async function ensureMathLiveLoaded() {
5
+ if (!mathLiveLoaded && typeof window !== 'undefined') {
6
+ mathLiveLoaded = (async () => {
7
+ // Import MathLive to register the <math-field> custom element
8
+ await import('mathlive');
9
+ // Load MathLive CSS if not already loaded
10
+ if (!document.querySelector('link[href*="mathlive"]')) {
11
+ const link = document.createElement('link');
12
+ link.rel = 'stylesheet';
13
+ link.href = 'https://cdn.jsdelivr.net/npm/mathlive@0.108.2/dist/mathlive-static.css';
14
+ document.head.appendChild(link);
15
+ }
16
+ })();
17
+ }
18
+ return mathLiveLoaded || Promise.resolve();
19
+ }
20
+ /**
21
+ * Opens a modal dialog with MathLive editor for LaTeX input
22
+ */
23
+ export async function openMathLiveEditor(options) {
24
+ const { onConfirm, onCancel, initialLatex = '', isBlock = false } = options;
25
+ // Ensure MathLive is loaded and registered before creating the mathfield
26
+ await ensureMathLiveLoaded();
27
+ // Create modal overlay - use DaisyUI modal classes
28
+ const overlay = document.createElement('div');
29
+ overlay.className = 'modal modal-open';
30
+ overlay.style.cssText = `
31
+ position: fixed;
32
+ top: 0;
33
+ left: 0;
34
+ right: 0;
35
+ bottom: 0;
36
+ background: rgba(0, 0, 0, 0.5);
37
+ display: flex;
38
+ align-items: center;
39
+ justify-content: center;
40
+ z-index: 9999;
41
+ `;
42
+ // Create modal dialog - use DaisyUI modal-box class
43
+ const modal = document.createElement('div');
44
+ modal.className = 'modal-box max-w-2xl';
45
+ modal.style.cssText = `
46
+ padding: 1.5rem;
47
+ position: relative;
48
+ z-index: 10000;
49
+ `;
50
+ // Create header - use DaisyUI font-bold text-lg
51
+ const header = document.createElement('h3');
52
+ header.textContent = isBlock ? (options.i18n?.t('interactions.extendedText.insertBlockMath') ?? 'Insert Block Math') : (options.i18n?.t('interactions.extendedText.insertInlineMath') ?? 'Insert Inline Math');
53
+ header.className = 'font-bold text-lg mb-4';
54
+ // Create form control wrapper
55
+ const formControl = document.createElement('div');
56
+ formControl.className = 'form-control';
57
+ // Create label for mathfield
58
+ const label = document.createElement('label');
59
+ label.className = 'label';
60
+ const labelText = document.createElement('span');
61
+ labelText.className = 'label-text';
62
+ labelText.textContent = options.i18n?.t('interactions.extendedText.enterMathExpression') ?? 'Enter your math expression:';
63
+ label.appendChild(labelText);
64
+ // Create MathLive mathfield - style like DaisyUI input
65
+ const mathfield = document.createElement('math-field');
66
+ mathfield.value = initialLatex;
67
+ mathfield.className = 'input input-bordered w-full';
68
+ mathfield.style.cssText = `
69
+ display: block;
70
+ min-height: 100px;
71
+ padding: 0.75rem;
72
+ font-size: 1.125rem;
73
+ `;
74
+ // Set MathLive options for better UX via attributes
75
+ // Use 'manual' mode so keyboard only shows when explicitly requested
76
+ mathfield.setAttribute('virtual-keyboard-mode', 'manual');
77
+ mathfield.setAttribute('smart-mode', 'on');
78
+ // Explicitly enable virtual keyboard
79
+ mathfield.setAttribute('use-shared-virtual-keyboard', 'true');
80
+ // Hide the built-in virtual keyboard toggle
81
+ mathfield.setAttribute('virtual-keyboard-toggle-glyph', '');
82
+ // Inject CSS to ensure virtual keyboard appears above modal and accepts clicks
83
+ const style = document.createElement('style');
84
+ style.textContent = `
85
+ /* Ensure MathLive virtual keyboard appears above the modal and is clickable */
86
+ .ML__keyboard {
87
+ z-index: 10001 !important;
88
+ pointer-events: auto !important;
89
+ }
90
+ /* Hide the built-in keyboard toggle button in the mathfield - try multiple selectors */
91
+ .ML__virtual-keyboard-toggle,
92
+ .ML__keyboard-toggle,
93
+ math-field::part(virtual-keyboard-toggle) {
94
+ display: none !important;
95
+ visibility: hidden !important;
96
+ opacity: 0 !important;
97
+ pointer-events: none !important;
98
+ }
99
+ `;
100
+ document.head.appendChild(style);
101
+ // Create LaTeX preview label
102
+ const previewLabel = document.createElement('label');
103
+ previewLabel.className = 'label';
104
+ const previewLabelText = document.createElement('span');
105
+ previewLabelText.className = 'label-text';
106
+ previewLabelText.textContent = options.i18n?.t('interactions.extendedText.latexSource') ?? 'LaTeX source:';
107
+ previewLabel.appendChild(previewLabelText);
108
+ // Create LaTeX preview/source - use alert info styling
109
+ const latexPreview = document.createElement('div');
110
+ latexPreview.className = 'alert alert-info';
111
+ latexPreview.style.cssText = `
112
+ font-family: 'Monaco', 'Courier New', monospace;
113
+ font-size: 0.875rem;
114
+ word-break: break-all;
115
+ margin-bottom: 1rem;
116
+ `;
117
+ latexPreview.textContent = initialLatex || '(LaTeX will appear here)';
118
+ // Update preview when mathfield changes
119
+ mathfield.addEventListener('input', () => {
120
+ const latex = mathfield.value;
121
+ latexPreview.textContent = latex || '(LaTeX will appear here)';
122
+ });
123
+ // Create button container - use DaisyUI modal-action class
124
+ const buttons = document.createElement('div');
125
+ buttons.className = 'modal-action';
126
+ buttons.style.cssText = 'justify-content: space-between;';
127
+ // Create left-side buttons (keyboard toggle)
128
+ const leftButtons = document.createElement('div');
129
+ leftButtons.style.cssText = 'display: flex; gap: 0.5rem;';
130
+ // Create Keyboard Toggle button
131
+ const keyboardBtn = document.createElement('button');
132
+ keyboardBtn.textContent = `⌨️ ${options.i18n?.t('interactions.extendedText.keyboard') ?? 'Keyboard'}`;
133
+ keyboardBtn.type = 'button';
134
+ keyboardBtn.className = 'btn btn-sm btn-outline';
135
+ keyboardBtn.onclick = () => {
136
+ if (mathfield.executeCommand) {
137
+ mathfield.executeCommand('toggleVirtualKeyboard');
138
+ }
139
+ };
140
+ leftButtons.appendChild(keyboardBtn);
141
+ // Create right-side buttons (Cancel/Insert)
142
+ const rightButtons = document.createElement('div');
143
+ rightButtons.style.cssText = 'display: flex; gap: 0.5rem;';
144
+ // Create Cancel button - use DaisyUI classes
145
+ const cancelBtn = document.createElement('button');
146
+ cancelBtn.textContent = options.i18n?.t('common.cancel') ?? 'Cancel';
147
+ cancelBtn.type = 'button';
148
+ cancelBtn.className = 'btn btn-ghost';
149
+ // Create Insert button - use DaisyUI classes
150
+ const insertBtn = document.createElement('button');
151
+ insertBtn.textContent = initialLatex
152
+ ? (options.i18n?.t('interactions.extendedText.update') ?? 'Update')
153
+ : (options.i18n?.t('interactions.extendedText.insert') ?? 'Insert');
154
+ insertBtn.type = 'button';
155
+ insertBtn.className = 'btn btn-primary';
156
+ rightButtons.appendChild(cancelBtn);
157
+ rightButtons.appendChild(insertBtn);
158
+ // Assemble modal
159
+ buttons.appendChild(leftButtons);
160
+ buttons.appendChild(rightButtons);
161
+ // Assemble form-control
162
+ formControl.appendChild(label);
163
+ formControl.appendChild(mathfield);
164
+ formControl.appendChild(previewLabel);
165
+ formControl.appendChild(latexPreview);
166
+ modal.appendChild(header);
167
+ modal.appendChild(formControl);
168
+ modal.appendChild(buttons);
169
+ overlay.appendChild(modal);
170
+ // Cleanup function
171
+ const cleanup = () => {
172
+ // Remove event listeners to prevent memory leaks
173
+ cancelBtn.removeEventListener('click', handleCancel);
174
+ insertBtn.removeEventListener('click', handleConfirm);
175
+ document.removeEventListener('keydown', handleEscape);
176
+ overlay.removeEventListener('click', handleOverlayClick);
177
+ // Hide virtual keyboard before cleanup
178
+ if (mathfield.executeCommand) {
179
+ mathfield.executeCommand('hideVirtualKeyboard');
180
+ }
181
+ // Remove DOM elements
182
+ overlay.remove();
183
+ style.remove();
184
+ // Restore body scroll
185
+ document.body.style.overflow = '';
186
+ };
187
+ // Event handlers
188
+ const handleCancel = () => {
189
+ cleanup();
190
+ onCancel();
191
+ };
192
+ const handleConfirm = () => {
193
+ const latex = mathfield.value;
194
+ cleanup();
195
+ onConfirm(latex);
196
+ };
197
+ const handleEscape = (e) => {
198
+ if (e.key === 'Escape') {
199
+ handleCancel();
200
+ }
201
+ };
202
+ const handleOverlayClick = (e) => {
203
+ // Don't close if clicking on the modal content or virtual keyboard
204
+ const target = e.target;
205
+ // Check if click is on overlay background (not modal or keyboard)
206
+ if (target === overlay) {
207
+ // Additional check: don't close if virtual keyboard is open
208
+ // MathLive virtual keyboard has class 'ML__keyboard'
209
+ const virtualKeyboard = document.querySelector('.ML__keyboard');
210
+ if (!virtualKeyboard) {
211
+ handleCancel();
212
+ }
213
+ }
214
+ };
215
+ // Attach event listeners
216
+ cancelBtn.addEventListener('click', handleCancel);
217
+ insertBtn.addEventListener('click', handleConfirm);
218
+ document.addEventListener('keydown', handleEscape);
219
+ overlay.addEventListener('click', handleOverlayClick);
220
+ // Prevent body scroll when modal is open
221
+ document.body.style.overflow = 'hidden';
222
+ // Add to DOM
223
+ document.body.appendChild(overlay);
224
+ // Focus the mathfield (but don't auto-show keyboard)
225
+ setTimeout(() => {
226
+ mathfield.focus();
227
+ // Try to programmatically disable the built-in toggle via options
228
+ try {
229
+ mathfield.setOptions({
230
+ virtualKeyboardToggleGlyph: '',
231
+ });
232
+ }
233
+ catch (e) {
234
+ // Silently ignore if this API doesn't exist
235
+ }
236
+ }, 100);
237
+ // Return cleanup function
238
+ return cleanup;
239
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Shared utilities and helpers for QTI interaction plugins
3
+ *
4
+ * This module exports common utilities used across all interaction plugins.
5
+ */
6
+ export * from './actions/typesetAction.js';
7
+ export * from './extensions/MathLiveEditor.js';
8
+ export * from './utils/eventHelpers.js';
9
+ export * from './utils/pairHelpers.js';
10
+ export * from './utils/touchDragHelper.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,cAAc,4BAA4B,CAAC;AAE3C,cAAc,gCAAgC,CAAC;AAE/C,cAAc,yBAAyB,CAAC;AAExC,cAAc,wBAAwB,CAAC;AAEvC,cAAc,4BAA4B,CAAC"}