@pie-players/pie-default-tool-loaders 0.3.73 → 0.3.74

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 (31) hide show
  1. package/README.md +18 -10
  2. package/dist/calculator-providers/CortexToolProvider.d.ts +13 -0
  3. package/dist/calculator-providers/CortexToolProvider.js +32 -0
  4. package/dist/calculator-providers/DesmosToolProvider.d.ts +14 -0
  5. package/dist/calculator-providers/DesmosToolProvider.js +32 -0
  6. package/dist/calculator-providers/GeoGebraToolProvider.d.ts +16 -0
  7. package/dist/calculator-providers/GeoGebraToolProvider.js +32 -0
  8. package/dist/calculator-providers/LazyCalculatorToolProvider.d.ts +35 -0
  9. package/dist/calculator-providers/LazyCalculatorToolProvider.js +95 -0
  10. package/dist/packaged-capability-composition.d.ts +2 -2
  11. package/dist/packaged-capability-composition.js +1 -1
  12. package/dist/registrations/accessibility-tools.js +1 -2
  13. package/dist/registrations/calculator.js +9 -42
  14. package/dist/registrations/dictionary-tools.js +2 -1
  15. package/dist/registrations/interaction-tools.js +3 -2
  16. package/dist/registrations/measurement-tools.js +0 -2
  17. package/dist/registrations/overlay-element-cache.d.ts +21 -0
  18. package/dist/registrations/overlay-element-cache.js +47 -0
  19. package/dist/registrations/overlay-toolbar-render.js +2 -1
  20. package/dist/registrations/subject-specific-tools.d.ts +2 -3
  21. package/dist/registrations/subject-specific-tools.js +11 -13
  22. package/dist/registrations/tts.js +6 -2
  23. package/package.json +24 -20
  24. package/dist/packaged-tool-registry.d.ts +0 -2
  25. package/dist/packaged-tool-registry.js +0 -1
  26. package/dist/tool-placement.d.ts +0 -1
  27. package/dist/tool-placement.js +0 -1
  28. package/dist/tool-tag-map.d.ts +0 -1
  29. package/dist/tool-tag-map.js +0 -1
  30. package/dist/universal-supports.d.ts +0 -1
  31. package/dist/universal-supports.js +0 -1
package/README.md CHANGED
@@ -3,7 +3,8 @@
3
3
  Composition layer for the packaged PIE assessment tools: which capabilities exist
4
4
  in a deployment, and how a program tiers them.
5
5
 
6
- It owns the concrete `pie-tool-*` dependencies so toolkit core can stay
6
+ It owns the concrete `pie-tool-*` dependencies and the calculator engines
7
+ (`pie-calculator-cortex`, `-desmos` and `-geogebra`) so toolkit core can stay
7
8
  dependency-light and cycle-safe, and it is the layer above core — core knows
8
9
  `featureId`, placement levels, activation kinds and precedence rules, and knows
9
10
  no capability ids.
@@ -89,24 +90,31 @@ For an offline-capable calculator with no API key or runtime CDN, use
89
90
  history, evaluation limit, allowed functions, clipboard policy, and graph
90
91
  viewport options documented by `@pie-players/pie-calculator-cortex`.
91
92
 
92
- `createDefaultToolRegistry()` in the toolkit is the other end of that choice: it
93
- builds an empty registry, and a host composing its own set registers into it.
93
+ The toolkit's `ToolRegistry` is the other end of that choice: it starts empty,
94
+ and a host composing its own set registers into it and installs the tag map its
95
+ registrations create elements from.
94
96
 
95
97
  ```ts
96
- import { createDefaultToolRegistry } from "@pie-players/pie-assessment-toolkit";
98
+ import { ToolRegistry } from "@pie-players/pie-assessment-toolkit";
97
99
  import {
98
100
  calculatorToolRegistration,
99
- registerSectionToolModuleLoaders,
101
+ PACKAGED_TOOL_TAG_MAP,
102
+ registerDefaultToolModuleLoaders,
100
103
  ttsToolRegistration,
101
104
  } from "@pie-players/pie-default-tool-loaders";
102
105
 
103
- const registry = createDefaultToolRegistry({
104
- registrations: [calculatorToolRegistration, ttsToolRegistration],
105
- });
106
- // Section-only loaders, for section toolbar bootstrap points.
107
- registerSectionToolModuleLoaders(registry);
106
+ const registry = new ToolRegistry();
107
+ registry.register(calculatorToolRegistration);
108
+ registry.register(ttsToolRegistration);
109
+ registry.setComponentOverrides({ toolTagMap: PACKAGED_TOOL_TAG_MAP });
110
+ registerDefaultToolModuleLoaders(registry);
108
111
  ```
109
112
 
113
+ `registerDefaultToolModuleLoaders` installs a loader for every packaged tool.
114
+ `registerSectionToolModuleLoaders` installs only the section-bootstrap subset,
115
+ which has no text-to-speech loader, so a registry that places item-level text to
116
+ speech needs the full set.
117
+
110
118
  ## Content-dependent capabilities require an explicit packaging decision
111
119
 
112
120
  A content-dependent capability is never inferred into
@@ -0,0 +1,13 @@
1
+ /** Fully bundled open-source calculator adapter for the tool-provider registry. */
2
+ import type { CalculatorToolProviderInitConfig, LazyCalculatorProviderDefinition } from "./LazyCalculatorToolProvider.js";
3
+ import { LazyCalculatorToolProvider } from "./LazyCalculatorToolProvider.js";
4
+ import type { ToolProviderCapabilities } from "@pie-players/pie-assessment-toolkit/tools/internal";
5
+ export type CortexToolProviderConfig = CalculatorToolProviderInitConfig;
6
+ export declare class CortexToolProvider extends LazyCalculatorToolProvider<CortexToolProviderConfig> {
7
+ readonly providerId = "cortex-calculator";
8
+ readonly providerName = "PIE Open-Source Calculator";
9
+ readonly version = "1";
10
+ readonly requiresAuth = false;
11
+ protected getDefinition(): LazyCalculatorProviderDefinition<CortexToolProviderConfig>;
12
+ getCapabilities(): ToolProviderCapabilities;
13
+ }
@@ -0,0 +1,32 @@
1
+ /** Fully bundled open-source calculator adapter for the tool-provider registry. */
2
+ import { LazyCalculatorToolProvider } from "./LazyCalculatorToolProvider.js";
3
+ export class CortexToolProvider extends LazyCalculatorToolProvider {
4
+ providerId = "cortex-calculator";
5
+ providerName = "PIE Open-Source Calculator";
6
+ version = "1";
7
+ requiresAuth = false;
8
+ getDefinition() {
9
+ return {
10
+ backend: "cortex",
11
+ moduleImportOperation: "cortex-provider-module-import",
12
+ loadProvider: async () => {
13
+ const module = await import("@pie-players/pie-calculator-cortex");
14
+ return module.CortexCalculatorProvider;
15
+ },
16
+ initializationErrorMessage: "Failed to initialize the PIE open-source calculator provider. Confirm that this browser supports module workers and that the bundled worker assets are available.",
17
+ };
18
+ }
19
+ getCapabilities() {
20
+ return {
21
+ supportsOffline: true,
22
+ requiresAuth: false,
23
+ maxInstances: null,
24
+ features: {
25
+ basic: true,
26
+ scientific: true,
27
+ graphing: true,
28
+ fourFunction: true,
29
+ },
30
+ };
31
+ }
32
+ }
@@ -0,0 +1,14 @@
1
+ /** Desmos calculator adapter for the generic tool-provider registry. */
2
+ import type { CalculatorProviderInit } from "@pie-players/pie-calculator";
3
+ import { LazyCalculatorToolProvider, type LazyCalculatorProviderDefinition } from "./LazyCalculatorToolProvider.js";
4
+ import type { ToolProviderCapabilities } from "@pie-players/pie-assessment-toolkit/tools/internal";
5
+ /** Provider initialization is the provider-neutral calculator contract. */
6
+ export type DesmosToolProviderConfig = CalculatorProviderInit;
7
+ export declare class DesmosToolProvider extends LazyCalculatorToolProvider<DesmosToolProviderConfig> {
8
+ readonly providerId = "desmos-calculator";
9
+ readonly providerName = "Desmos Calculator";
10
+ readonly version = "1.12";
11
+ readonly requiresAuth = true;
12
+ protected getDefinition(): LazyCalculatorProviderDefinition<DesmosToolProviderConfig>;
13
+ getCapabilities(): ToolProviderCapabilities;
14
+ }
@@ -0,0 +1,32 @@
1
+ /** Desmos calculator adapter for the generic tool-provider registry. */
2
+ import { LazyCalculatorToolProvider, } from "./LazyCalculatorToolProvider.js";
3
+ export class DesmosToolProvider extends LazyCalculatorToolProvider {
4
+ providerId = "desmos-calculator";
5
+ providerName = "Desmos Calculator";
6
+ version = "1.12";
7
+ requiresAuth = true;
8
+ getDefinition() {
9
+ return {
10
+ backend: "desmos",
11
+ moduleImportOperation: "desmos-provider-module-import",
12
+ loadProvider: async () => {
13
+ const module = await import("@pie-players/pie-calculator-desmos");
14
+ return module.DesmosCalculatorProvider;
15
+ },
16
+ initializationErrorMessage: "Failed to initialize Desmos calculator provider. Check the application key, preloaded API, runtime endpoint, or network access.",
17
+ };
18
+ }
19
+ getCapabilities() {
20
+ return {
21
+ supportsOffline: false,
22
+ requiresAuth: true,
23
+ maxInstances: null,
24
+ features: {
25
+ basic: true,
26
+ scientific: true,
27
+ graphing: true,
28
+ fourFunction: true,
29
+ },
30
+ };
31
+ }
32
+ }
@@ -0,0 +1,16 @@
1
+ /** GeoGebra calculator adapter for the generic tool-provider registry. */
2
+ import type { CalculatorToolProviderInitConfig, LazyCalculatorProviderDefinition } from "./LazyCalculatorToolProvider.js";
3
+ import { LazyCalculatorToolProvider } from "./LazyCalculatorToolProvider.js";
4
+ import type { ToolProviderCapabilities } from "@pie-players/pie-assessment-toolkit/tools/internal";
5
+ export interface GeoGebraToolProviderConfig extends CalculatorToolProviderInitConfig {
6
+ scriptUrl?: string;
7
+ appletTimeoutMs?: number;
8
+ }
9
+ export declare class GeoGebraToolProvider extends LazyCalculatorToolProvider<GeoGebraToolProviderConfig> {
10
+ readonly providerId = "geogebra-calculator";
11
+ readonly providerName = "GeoGebra Calculator";
12
+ readonly version = "6";
13
+ readonly requiresAuth = false;
14
+ protected getDefinition(): LazyCalculatorProviderDefinition<GeoGebraToolProviderConfig>;
15
+ getCapabilities(): ToolProviderCapabilities;
16
+ }
@@ -0,0 +1,32 @@
1
+ /** GeoGebra calculator adapter for the generic tool-provider registry. */
2
+ import { LazyCalculatorToolProvider } from "./LazyCalculatorToolProvider.js";
3
+ export class GeoGebraToolProvider extends LazyCalculatorToolProvider {
4
+ providerId = "geogebra-calculator";
5
+ providerName = "GeoGebra Calculator";
6
+ version = "6";
7
+ requiresAuth = false;
8
+ getDefinition() {
9
+ return {
10
+ backend: "geogebra",
11
+ moduleImportOperation: "geogebra-provider-module-import",
12
+ loadProvider: async () => {
13
+ const module = await import("@pie-players/pie-calculator-geogebra");
14
+ return module.GeoGebraCalculatorProvider;
15
+ },
16
+ initializationErrorMessage: "Failed to initialize GeoGebra calculator provider. Confirm that the deployment may load GeoGebra and that its script URL is reachable.",
17
+ };
18
+ }
19
+ getCapabilities() {
20
+ return {
21
+ supportsOffline: false,
22
+ requiresAuth: false,
23
+ maxInstances: null,
24
+ features: {
25
+ basic: true,
26
+ scientific: true,
27
+ graphing: true,
28
+ fourFunction: false,
29
+ },
30
+ };
31
+ }
32
+ }
@@ -0,0 +1,35 @@
1
+ import type { CalculatorProvider, CalculatorProviderInit } from "@pie-players/pie-calculator";
2
+ import type { ToolProviderApi, ToolProviderCapabilities } from "@pie-players/pie-assessment-toolkit/tools/internal";
3
+ export type CalculatorToolProviderInitConfig = Pick<CalculatorProviderInit, "onTelemetry">;
4
+ type InitializableCalculatorProvider<TConfig> = CalculatorProvider & {
5
+ initialize(config: TConfig): Promise<void>;
6
+ };
7
+ export interface LazyCalculatorProviderDefinition<TConfig> {
8
+ backend: string;
9
+ moduleImportOperation: string;
10
+ loadProvider: () => Promise<new () => InitializableCalculatorProvider<TConfig>>;
11
+ initializationErrorMessage: string;
12
+ }
13
+ /**
14
+ * Shared lazy-module and lifecycle implementation for calculator tool adapters.
15
+ * Concrete adapters own only their metadata, capabilities and provider import.
16
+ */
17
+ export declare abstract class LazyCalculatorToolProvider<TConfig extends CalculatorToolProviderInitConfig> implements ToolProviderApi<TConfig, CalculatorProvider> {
18
+ abstract readonly providerId: string;
19
+ abstract readonly providerName: string;
20
+ readonly category: "calculator";
21
+ abstract readonly version: string;
22
+ abstract readonly requiresAuth: boolean;
23
+ protected abstract getDefinition(): LazyCalculatorProviderDefinition<TConfig>;
24
+ abstract getCapabilities(): ToolProviderCapabilities;
25
+ private calculatorProvider;
26
+ private initializationPromise;
27
+ private lifecycleGeneration;
28
+ private emitTelemetry;
29
+ initialize(config?: TConfig): Promise<void>;
30
+ private initializeProvider;
31
+ createInstance(): Promise<CalculatorProvider>;
32
+ isReady(): boolean;
33
+ destroy(): void;
34
+ }
35
+ export {};
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Shared lazy-module and lifecycle implementation for calculator tool adapters.
3
+ * Concrete adapters own only their metadata, capabilities and provider import.
4
+ */
5
+ export class LazyCalculatorToolProvider {
6
+ category = "calculator";
7
+ calculatorProvider = null;
8
+ initializationPromise = null;
9
+ lifecycleGeneration = 0;
10
+ async emitTelemetry(config, eventName, payload) {
11
+ try {
12
+ await config.onTelemetry?.(eventName, payload);
13
+ }
14
+ catch (error) {
15
+ console.warn(`[${this.providerName}] telemetry callback failed:`, error);
16
+ }
17
+ }
18
+ async initialize(config = {}) {
19
+ if (this.calculatorProvider)
20
+ return;
21
+ if (this.initializationPromise)
22
+ return this.initializationPromise;
23
+ const generation = ++this.lifecycleGeneration;
24
+ const initializationPromise = this.initializeProvider(config, generation);
25
+ this.initializationPromise = initializationPromise;
26
+ try {
27
+ await initializationPromise;
28
+ }
29
+ finally {
30
+ if (this.initializationPromise === initializationPromise) {
31
+ this.initializationPromise = null;
32
+ }
33
+ }
34
+ }
35
+ async initializeProvider(config, generation) {
36
+ const definition = this.getDefinition();
37
+ const moduleLoadStartedAt = Date.now();
38
+ await this.emitTelemetry(config, "pie-tool-library-load-start", {
39
+ toolId: "calculator",
40
+ operation: definition.moduleImportOperation,
41
+ backend: definition.backend,
42
+ });
43
+ let ProviderConstructor;
44
+ try {
45
+ ProviderConstructor = await definition.loadProvider();
46
+ await this.emitTelemetry(config, "pie-tool-library-load-success", {
47
+ toolId: "calculator",
48
+ operation: definition.moduleImportOperation,
49
+ backend: definition.backend,
50
+ duration: Date.now() - moduleLoadStartedAt,
51
+ });
52
+ }
53
+ catch (error) {
54
+ await this.emitTelemetry(config, "pie-tool-library-load-error", {
55
+ toolId: "calculator",
56
+ operation: definition.moduleImportOperation,
57
+ backend: definition.backend,
58
+ duration: Date.now() - moduleLoadStartedAt,
59
+ errorType: "ToolLibraryLoadError",
60
+ message: error instanceof Error ? error.message : String(error),
61
+ });
62
+ throw new Error(definition.initializationErrorMessage, { cause: error });
63
+ }
64
+ if (generation !== this.lifecycleGeneration) {
65
+ throw new Error(`${this.providerName} initialization was cancelled`);
66
+ }
67
+ const candidate = new ProviderConstructor();
68
+ try {
69
+ await candidate.initialize(config);
70
+ if (generation !== this.lifecycleGeneration) {
71
+ throw new Error(`${this.providerName} initialization was cancelled`);
72
+ }
73
+ this.calculatorProvider = candidate;
74
+ }
75
+ catch (error) {
76
+ candidate.destroy();
77
+ throw new Error(definition.initializationErrorMessage, { cause: error });
78
+ }
79
+ }
80
+ async createInstance() {
81
+ if (!this.calculatorProvider) {
82
+ throw new Error(`[${this.providerName}] Provider not initialized. Call initialize() first.`);
83
+ }
84
+ return this.calculatorProvider;
85
+ }
86
+ isReady() {
87
+ return this.calculatorProvider !== null;
88
+ }
89
+ destroy() {
90
+ this.lifecycleGeneration += 1;
91
+ this.initializationPromise = null;
92
+ this.calculatorProvider?.destroy();
93
+ this.calculatorProvider = null;
94
+ }
95
+ }
@@ -7,7 +7,7 @@
7
7
  * Public constants are projections of this composition so adding a capability
8
8
  * cannot leave a second hand-maintained catalogue silently behind.
9
9
  */
10
- import { ToolRegistry, type ToolComponentFactory, type ToolComponentFactoryMap, type ToolRegistration, type ToolTagMap, type ToolProviderConfig } from "@pie-players/pie-assessment-toolkit/tools/internal";
10
+ import { ToolRegistry, type CalculatorToolProviderConfig, type ToolComponentFactory, type ToolComponentFactoryMap, type ToolRegistration, type ToolTagMap } from "@pie-players/pie-assessment-toolkit/tools/internal";
11
11
  import type { PersonalNeedsProfile } from "@pie-players/pie-players-shared/types";
12
12
  export type ToolModuleLoader = () => Promise<unknown>;
13
13
  export interface ToolRegistryLike {
@@ -19,7 +19,7 @@ export interface PackagedCalculatorCompositionOptions {
19
19
  * Selects the matching packaged element and default loader. Omit it to retain
20
20
  * the existing Desmos delivery.
21
21
  */
22
- calculatorProviderConfig?: ToolProviderConfig;
22
+ calculatorProviderConfig?: CalculatorToolProviderConfig;
23
23
  }
24
24
  export interface PackagedToolRegistryOptions extends PackagedCalculatorCompositionOptions {
25
25
  /** Override packaged registrations by toolId. */
@@ -69,7 +69,7 @@ const PACKAGED_CAPABILITY_DEFINITIONS = [
69
69
  },
70
70
  {
71
71
  registration: ttsToolRegistration,
72
- tagName: "pie-tool-text-to-speech",
72
+ tagName: "pie-tool-tts-inline",
73
73
  loadModule: loadTtsModule,
74
74
  loaderTargets: ["item"],
75
75
  placementOrder: { item: 10, passage: 10, rubric: 10, element: 30 },
@@ -11,8 +11,7 @@
11
11
  * - reading category: readingMask, readingGuide, highlighting
12
12
  */
13
13
  import { hasReadableText } from "@pie-players/pie-assessment-toolkit/tools/internal";
14
- import { createToolElement, resolveToolTag, } from "@pie-players/pie-assessment-toolkit/tools/internal";
15
- import { applyOverlaySurface, createScopedVisibilityBinding, syncButtonAndOverlayVisibility, } from "@pie-players/pie-assessment-toolkit/tools/internal";
14
+ import { resolveToolTag, } from "@pie-players/pie-assessment-toolkit/tools/internal";
16
15
  import { buildSelectionActions } from "./selection-actions.js";
17
16
  import { renderOverlayToolbar } from "./overlay-toolbar-render.js";
18
17
  /**
@@ -10,10 +10,11 @@
10
10
  */
11
11
  import { hasMathContent } from "@pie-players/pie-assessment-toolkit/tools/internal";
12
12
  import { createScopedToolId } from "@pie-players/pie-assessment-toolkit/tools/internal";
13
- import { DesmosToolProvider } from "@pie-players/pie-assessment-toolkit/tools/internal";
14
- import { CortexToolProvider } from "@pie-players/pie-assessment-toolkit/tools/internal";
15
- import { GeoGebraToolProvider } from "@pie-players/pie-assessment-toolkit/tools/internal";
16
13
  import { createToolElement } from "@pie-players/pie-assessment-toolkit/tools/internal";
14
+ import { CortexToolProvider } from "../calculator-providers/CortexToolProvider.js";
15
+ import { DesmosToolProvider } from "../calculator-providers/DesmosToolProvider.js";
16
+ import { GeoGebraToolProvider } from "../calculator-providers/GeoGebraToolProvider.js";
17
+ import { resolveOverlayElement } from "./overlay-element-cache.js";
17
18
  export const DEFAULT_CALCULATOR_PROVIDER_ID = "calculator-desmos";
18
19
  export function resolveCalculatorProviderId(config) {
19
20
  const configured = config?.provider?.id;
@@ -50,38 +51,6 @@ function getCalculatorInstanceConfig(config) {
50
51
  : undefined,
51
52
  };
52
53
  }
53
- // The toolbar parent re-derives `renderedTools` whenever item state changes
54
- // (e.g. the learner answers a question and `effectiveItem`/`renderContext`
55
- // recompute). Calculator initialization is expensive (Desmos boot, container
56
- // mount), so we cache the overlay element by coordinator + scoped tool id.
57
- // Reusing the same element keeps `mountContent` a no-op and avoids tearing
58
- // down and re-initializing the calculator on every re-render.
59
- const overlayElementCache = new WeakMap();
60
- function getCachedOverlay(coordinator, fullToolId) {
61
- if (!coordinator)
62
- return null;
63
- const scoped = overlayElementCache.get(coordinator);
64
- const element = scoped?.get(fullToolId);
65
- if (!element)
66
- return null;
67
- // Svelte custom elements destroy their component when disconnected.
68
- // A detached cached element is a dead instance — drop it and recreate.
69
- if (!element.isConnected) {
70
- scoped?.delete(fullToolId);
71
- return null;
72
- }
73
- return element;
74
- }
75
- function setCachedOverlay(coordinator, fullToolId, element) {
76
- if (!coordinator)
77
- return;
78
- let scoped = overlayElementCache.get(coordinator);
79
- if (!scoped) {
80
- scoped = new Map();
81
- overlayElementCache.set(coordinator, scoped);
82
- }
83
- scoped.set(fullToolId, element);
84
- }
85
54
  function normalizeCalculatorType(value) {
86
55
  return value === "basic" || value === "scientific" || value === "graphing"
87
56
  ? value
@@ -188,17 +157,15 @@ export const calculatorToolRegistration = {
188
157
  },
189
158
  renderToolbar(context, toolbarContext) {
190
159
  const { calculatorType, availableTypes, displayName } = getCalculatorRenderParams(toolbarContext);
191
- const calculatorToolConfig = toolbarContext.toolkitCoordinator?.config.tools?.providers?.calculator;
160
+ const calculatorToolConfig = toolbarContext.toolkitCoordinator?.getToolConfig(this.toolId) ||
161
+ undefined;
192
162
  const providerId = resolveCalculatorProviderId(calculatorToolConfig);
193
163
  const calculatorConfig = getCalculatorInstanceConfig(calculatorToolConfig);
194
164
  const fullToolId = createScopedToolId(this.toolId, toolbarContext.scope.level, toolbarContext.scope.scopeId);
195
165
  const componentOverrides = toolbarContext.componentOverrides;
196
- const cachedOverlay = getCachedOverlay(toolbarContext.toolCoordinator, fullToolId);
197
- const overlay = (cachedOverlay ??
198
- createToolElement(this.toolId, context, toolbarContext, componentOverrides));
199
- if (!cachedOverlay) {
200
- setCachedOverlay(toolbarContext.toolCoordinator, fullToolId, overlay);
201
- }
166
+ // Reused across renders: besides keeping state, this spares a Desmos boot
167
+ // and container mount on every re-render.
168
+ const overlay = resolveOverlayElement(toolbarContext, fullToolId, () => createToolElement(this.toolId, context, toolbarContext, componentOverrides));
202
169
  overlay.setAttribute("tool-id", fullToolId);
203
170
  overlay.toolkitCoordinator = toolbarContext.toolkitCoordinator;
204
171
  applyCalculatorParamsToElement(overlay, calculatorType, availableTypes, providerId, calculatorConfig);
@@ -16,6 +16,7 @@
16
16
  * dictionary is unreachable for them. The panel's own field is the keyboard route.
17
17
  */
18
18
  import { createScopedVisibilityBinding, createToolElement, hasReadableText, syncButtonAndOverlayVisibility, } from "@pie-players/pie-assessment-toolkit/tools/internal";
19
+ import { resolveOverlayElement } from "./overlay-element-cache.js";
19
20
  /**
20
21
  * Apply the host's per-tool render params to the panel.
21
22
  *
@@ -81,7 +82,7 @@ function renderDictionaryPanel(args) {
81
82
  };
82
83
  const componentOverrides = toolbarContext.componentOverrides ??
83
84
  {};
84
- const overlay = createToolElement(registration.toolId, context, toolbarContext, componentOverrides);
85
+ const overlay = resolveOverlayElement(toolbarContext, visibility.fullToolId, () => createToolElement(registration.toolId, context, toolbarContext, componentOverrides));
85
86
  overlay.setAttribute("tool-id", visibility.fullToolId);
86
87
  applyLookupParams(overlay, registration.toolId, toolbarContext, args.lookupLanguage);
87
88
  return {
@@ -10,9 +10,10 @@
10
10
  * - strikethrough (visual transformation)
11
11
  * - highlighting (cognitive/reading support)
12
12
  */
13
- import { hasChoiceInteraction, hasReadableText, } from "@pie-players/pie-assessment-toolkit/tools/internal";
13
+ import { hasChoiceInteraction } from "@pie-players/pie-assessment-toolkit/tools/internal";
14
14
  import { createToolElement, } from "@pie-players/pie-assessment-toolkit/tools/internal";
15
15
  import { createScopedVisibilityBinding, syncButtonAndOverlayVisibility, } from "@pie-players/pie-assessment-toolkit/tools/internal";
16
+ import { resolveOverlayElement } from "./overlay-element-cache.js";
16
17
  /**
17
18
  * Answer Eliminator tool registration
18
19
  *
@@ -55,7 +56,7 @@ export const answerEliminatorToolRegistration = {
55
56
  renderToolbar(context, toolbarContext) {
56
57
  const visibility = createScopedVisibilityBinding(this.toolId, toolbarContext);
57
58
  const componentOverrides = toolbarContext.componentOverrides ?? {};
58
- const overlay = createToolElement(this.toolId, context, toolbarContext, componentOverrides);
59
+ const overlay = resolveOverlayElement(toolbarContext, visibility.fullToolId, () => createToolElement(this.toolId, context, toolbarContext, componentOverrides));
59
60
  overlay.setAttribute("tool-id", visibility.fullToolId);
60
61
  overlay.setAttribute("strategy", "strikethrough");
61
62
  overlay.setAttribute("button-alignment", "inline");
@@ -8,8 +8,6 @@
8
8
  * - protractor (assessment tool)
9
9
  */
10
10
  import { hasMathContent } from "@pie-players/pie-assessment-toolkit/tools/internal";
11
- import { createToolElement, } from "@pie-players/pie-assessment-toolkit/tools/internal";
12
- import { applyOverlaySurface, createScopedVisibilityBinding, syncButtonAndOverlayVisibility, } from "@pie-players/pie-assessment-toolkit/tools/internal";
13
11
  import { renderOverlayToolbar } from "./overlay-toolbar-render.js";
14
12
  /**
15
13
  * Ruler tool registration
@@ -0,0 +1,21 @@
1
+ /**
2
+ * One overlay element per coordinator and scoped tool id, reused across renders.
3
+ *
4
+ * The toolbar re-derives its rendered tools whenever an input moves — a policy
5
+ * emit, a tool-config update, the interface locale — and mounts whichever
6
+ * element each render returns, swapping out one it has not seen. A registration
7
+ * that creates its overlay on every render therefore remounts it, and the
8
+ * learner loses the ruler's position, the graph's points or the eliminated
9
+ * choices while the tool stays open. Reusing the element keeps the mount a
10
+ * no-op, so per-render attributes are the registration's to re-apply.
11
+ *
12
+ * A Svelte custom element tears its component down once it leaves the document,
13
+ * so a cached element found disconnected is dropped and recreated.
14
+ */
15
+ import type { ToolbarContext } from "@pie-players/pie-assessment-toolkit/tools/internal";
16
+ /**
17
+ * The element cached for `fullToolId` under this toolbar's coordinator, or the
18
+ * one `create` returns, which is then cached. Without a coordinator there is no
19
+ * session to key by, and every render creates.
20
+ */
21
+ export declare function resolveOverlayElement<T extends HTMLElement>(toolbarContext: ToolbarContext, fullToolId: string, create: () => T): T;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * One overlay element per coordinator and scoped tool id, reused across renders.
3
+ *
4
+ * The toolbar re-derives its rendered tools whenever an input moves — a policy
5
+ * emit, a tool-config update, the interface locale — and mounts whichever
6
+ * element each render returns, swapping out one it has not seen. A registration
7
+ * that creates its overlay on every render therefore remounts it, and the
8
+ * learner loses the ruler's position, the graph's points or the eliminated
9
+ * choices while the tool stays open. Reusing the element keeps the mount a
10
+ * no-op, so per-render attributes are the registration's to re-apply.
11
+ *
12
+ * A Svelte custom element tears its component down once it leaves the document,
13
+ * so a cached element found disconnected is dropped and recreated.
14
+ */
15
+ import { TOOL_ELEMENT_UNMOUNT_CALLBACK_PROP } from "./tts.js";
16
+ const overlayElements = new WeakMap();
17
+ /**
18
+ * The element cached for `fullToolId` under this toolbar's coordinator, or the
19
+ * one `create` returns, which is then cached. Without a coordinator there is no
20
+ * session to key by, and every render creates.
21
+ */
22
+ export function resolveOverlayElement(toolbarContext, fullToolId, create) {
23
+ const coordinator = toolbarContext.toolCoordinator;
24
+ if (!coordinator)
25
+ return create();
26
+ let scoped = overlayElements.get(coordinator);
27
+ const cached = scoped?.get(fullToolId);
28
+ if (cached?.isConnected)
29
+ return cached;
30
+ const element = create();
31
+ if (!scoped) {
32
+ scoped = new Map();
33
+ overlayElements.set(coordinator, scoped);
34
+ }
35
+ scoped.set(fullToolId, element);
36
+ // The toolbar calls this as it unmounts the element, before detaching it, so
37
+ // the check waits a microtask: an element another toolbar has adopted in the
38
+ // meantime is still connected and stays cached.
39
+ element[TOOL_ELEMENT_UNMOUNT_CALLBACK_PROP] = () => {
40
+ queueMicrotask(() => {
41
+ if (!element.isConnected && scoped.get(fullToolId) === element) {
42
+ scoped.delete(fullToolId);
43
+ }
44
+ });
45
+ };
46
+ return element;
47
+ }
@@ -17,6 +17,7 @@
17
17
  * off one element — keeps its own renderer.
18
18
  */
19
19
  import { applyOverlaySurface, createScopedVisibilityBinding, createToolElement, resolveToolRegistrationName, syncButtonAndOverlayVisibility, } from "@pie-players/pie-assessment-toolkit/tools/internal";
20
+ import { resolveOverlayElement } from "./overlay-element-cache.js";
20
21
  export function renderOverlayToolbar(registration, context, toolbarContext, options = {}) {
21
22
  const { toolId } = registration;
22
23
  const visibility = createScopedVisibilityBinding(toolId, toolbarContext);
@@ -34,7 +35,7 @@ export function renderOverlayToolbar(registration, context, toolbarContext, opti
34
35
  };
35
36
  const componentOverrides = toolbarContext.componentOverrides ??
36
37
  {};
37
- const overlay = createToolElement(toolId, context, toolbarContext, componentOverrides);
38
+ const overlay = resolveOverlayElement(toolbarContext, visibility.fullToolId, () => createToolElement(toolId, context, toolbarContext, componentOverrides));
38
39
  overlay.setAttribute("tool-id", visibility.fullToolId);
39
40
  if (options.surface === "frameless") {
40
41
  applyOverlaySurface(overlay, "frameless");
@@ -2,11 +2,10 @@
2
2
  * Subject-Specific Tools Registrations
3
3
  *
4
4
  * Registers tools for specific subject areas:
5
- * - Graph (graphing calculator/coordinate plane)
5
+ * - Graph (coordinate plane)
6
6
  * - Periodic Table (chemistry reference)
7
7
  *
8
8
  * Maps to QTI 3.0 standard access features:
9
- * - graphingCalculator (assessment tool)
10
9
  * - graph (assessment tool)
11
10
  * - periodicTable (assessment tool)
12
11
  */
@@ -14,7 +13,7 @@ import type { ToolRegistration } from "@pie-players/pie-assessment-toolkit/tools
14
13
  /**
15
14
  * Graph tool registration
16
15
  *
17
- * Provides graphing calculator and coordinate plane functionality.
16
+ * Provides a coordinate plane.
18
17
  * Context-smart: appears automatically for math content or when explicitly enabled.
19
18
  */
20
19
  export declare const graphToolRegistration: ToolRegistration;
@@ -2,38 +2,35 @@
2
2
  * Subject-Specific Tools Registrations
3
3
  *
4
4
  * Registers tools for specific subject areas:
5
- * - Graph (graphing calculator/coordinate plane)
5
+ * - Graph (coordinate plane)
6
6
  * - Periodic Table (chemistry reference)
7
7
  *
8
8
  * Maps to QTI 3.0 standard access features:
9
- * - graphingCalculator (assessment tool)
10
9
  * - graph (assessment tool)
11
10
  * - periodicTable (assessment tool)
12
11
  */
13
12
  import { hasMathContent, hasScienceContent, } from "@pie-players/pie-assessment-toolkit/tools/internal";
14
- import { createToolElement, } from "@pie-players/pie-assessment-toolkit/tools/internal";
15
- import { createScopedVisibilityBinding, syncButtonAndOverlayVisibility, } from "@pie-players/pie-assessment-toolkit/tools/internal";
16
13
  import { renderOverlayToolbar } from "./overlay-toolbar-render.js";
17
14
  /**
18
15
  * Graph tool registration
19
16
  *
20
- * Provides graphing calculator and coordinate plane functionality.
17
+ * Provides a coordinate plane.
21
18
  * Context-smart: appears automatically for math content or when explicitly enabled.
22
19
  */
23
20
  export const graphToolRegistration = {
24
21
  toolId: "graph",
25
22
  name: "Graph",
26
- description: "Graphing calculator and coordinate plane",
23
+ description: "Coordinate plane",
27
24
  nameKey: "tools.graph.name",
28
25
  descriptionKey: "tools.graph.description",
29
26
  icon: "chart-bar",
30
- // Graph is a section-level floating tool.
31
- supportedLevels: ["section"],
32
- // PNP support IDs
33
- // Maps to QTI 3.0 standard features: graph, graphingCalculator
27
+ // A floating tool, placed on a section toolbar or on an item toolbar where
28
+ // the toolkit runs without a section.
29
+ supportedLevels: ["section", "item"],
30
+ // `graphingCalculator` grants the calculator, whose graphing type a host
31
+ // selects through render params; the coordinate plane is not that tool.
34
32
  pnpSupportIds: [
35
33
  "graph", // QTI 3.0 standard (assessment.graph)
36
- "graphingCalculator", // QTI 3.0 standard (assessment.graphingCalculator)
37
34
  ],
38
35
  /**
39
36
  * Pass 2: Graph is relevant when math content is present
@@ -66,8 +63,9 @@ export const periodicTableToolRegistration = {
66
63
  nameKey: "tools.periodicTable.name",
67
64
  descriptionKey: "tools.periodicTable.description",
68
65
  icon: "beaker",
69
- // Periodic table is a section-level floating tool.
70
- supportedLevels: ["section"],
66
+ // A floating tool, placed on a section toolbar or on an item toolbar where
67
+ // the toolkit runs without a section.
68
+ supportedLevels: ["section", "item"],
71
69
  // PNP support IDs
72
70
  // Maps to QTI 3.0 standard feature: periodicTable
73
71
  pnpSupportIds: [
@@ -11,6 +11,9 @@ import { hasReadableText } from "@pie-players/pie-assessment-toolkit/tools/inter
11
11
  import { createScopedToolId } from "@pie-players/pie-assessment-toolkit/tools/internal";
12
12
  import { buildRuntimeTTSConfig, normalizeTTSLayoutMode, normalizeTTSSpeedControlOptions, resolveTTSHostToolbarLayout, resolveTTSLayoutMode, resolveTTSBackend, resolveTTSRuntimeSettings, resolveRuntimeProvider, resolveTransportMode, } from "@pie-players/pie-assessment-toolkit/tools/internal";
13
13
  import { TTSToolProvider } from "@pie-players/pie-assessment-toolkit/tools/internal";
14
+ // This package owns the server adapter's import, so the toolkit never names it
15
+ // and a bundler building the toolkit alone has nothing to resolve.
16
+ const loadServerTTSProvider = async () => (await import("@pie-players/tts-client-server")).ServerTTSProvider;
14
17
  const inlineTTSControls = new Map();
15
18
  export const TOOL_ELEMENT_UNMOUNT_CALLBACK_PROP = "__pieToolElementUnmount";
16
19
  export const TOOL_ACTIVE_CHANGE_EVENT = "pie-tool-active-change";
@@ -33,7 +36,9 @@ export const ttsToolRegistration = {
33
36
  getProviderId: () => "tts",
34
37
  createProvider: (config) => {
35
38
  const settings = resolveTTSRuntimeSettings(config);
36
- return new TTSToolProvider(resolveTTSBackend(settings));
39
+ return new TTSToolProvider(resolveTTSBackend(settings), {
40
+ loadServerProvider: loadServerTTSProvider,
41
+ });
37
42
  },
38
43
  getInitConfig: (config) => {
39
44
  const settings = resolveTTSRuntimeSettings(config);
@@ -128,7 +133,6 @@ export const ttsToolRegistration = {
128
133
  };
129
134
  inlineTTSControls.set(fullToolId, element);
130
135
  }
131
- element.setAttribute("tool-id", fullToolId);
132
136
  element.setAttribute("catalog-id", toolbarContext.catalogId || toolbarContext.itemId);
133
137
  element.setAttribute("language", toolbarContext.language || "en-US");
134
138
  element.setAttribute("size", resolveControlSize());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-players/pie-default-tool-loaders",
3
- "version": "0.3.73",
3
+ "version": "0.3.74",
4
4
  "type": "module",
5
5
  "description": "Composition layer for the packaged PIE assessment tools: registrations, tag map, placement presets, universal supports and lazy module loaders",
6
6
  "repository": {
@@ -29,30 +29,34 @@
29
29
  "check:composition": "bun test tests/packaged-capability-composition.test.ts",
30
30
  "dev": "tsc -p tsconfig.json --watch",
31
31
  "typecheck": "tsc -p tsconfig.json --noEmit",
32
- "lint": "biome check .",
32
+ "lint": "biome lint .",
33
33
  "test": "bun test"
34
34
  },
35
35
  "dependencies": {
36
- "@pie-players/pie-assessment-toolkit": "0.3.73",
37
- "@pie-players/pie-players-shared": "0.3.73",
38
- "@pie-players/pie-tool-annotation-toolbar": "0.3.73",
39
- "@pie-players/pie-tool-answer-eliminator": "0.3.73",
40
- "@pie-players/pie-tool-calculator-desmos": "0.3.73",
41
- "@pie-players/pie-tool-calculator-cortex": "0.3.73",
42
- "@pie-players/pie-tool-calculator-geogebra": "0.3.73",
43
- "@pie-players/pie-tool-calculator-shared": "0.3.73",
44
- "@pie-players/pie-tool-dictionary": "0.3.73",
45
- "@pie-players/pie-tool-graph": "0.3.73",
46
- "@pie-players/pie-tool-line-reader": "0.3.73",
47
- "@pie-players/pie-tool-periodic-table": "0.3.73",
48
- "@pie-players/pie-tool-picture-dictionary": "0.3.73",
49
- "@pie-players/pie-tool-protractor": "0.3.73",
50
- "@pie-players/pie-tool-ruler": "0.3.73",
51
- "@pie-players/pie-tool-theme": "0.3.73",
52
- "@pie-players/pie-tool-tts-inline": "0.3.73"
36
+ "@pie-players/pie-assessment-toolkit": "0.3.74",
37
+ "@pie-players/pie-calculator": "0.3.74",
38
+ "@pie-players/pie-calculator-cortex": "0.3.74",
39
+ "@pie-players/pie-calculator-desmos": "0.3.74",
40
+ "@pie-players/pie-calculator-geogebra": "0.3.74",
41
+ "@pie-players/pie-players-shared": "0.3.74",
42
+ "@pie-players/pie-tool-annotation-toolbar": "0.3.74",
43
+ "@pie-players/pie-tool-answer-eliminator": "0.3.74",
44
+ "@pie-players/pie-tool-calculator-cortex": "0.3.74",
45
+ "@pie-players/pie-tool-calculator-geogebra": "0.3.74",
46
+ "@pie-players/pie-tool-calculator-shared": "0.3.74",
47
+ "@pie-players/pie-tool-dictionary": "0.3.74",
48
+ "@pie-players/pie-tool-graph": "0.3.74",
49
+ "@pie-players/pie-tool-line-reader": "0.3.74",
50
+ "@pie-players/pie-tool-periodic-table": "0.3.74",
51
+ "@pie-players/pie-tool-picture-dictionary": "0.3.74",
52
+ "@pie-players/pie-tool-protractor": "0.3.74",
53
+ "@pie-players/pie-tool-ruler": "0.3.74",
54
+ "@pie-players/pie-tool-theme": "0.3.74",
55
+ "@pie-players/pie-tool-tts-inline": "0.3.74",
56
+ "@pie-players/tts-client-server": "0.3.74"
53
57
  },
54
58
  "devDependencies": {
55
- "@biomejs/biome": "^2.5.13",
59
+ "@biomejs/biome": "^2.5.15",
56
60
  "typescript": "^5.9.3"
57
61
  },
58
62
  "homepage": "https://github.com/pie-framework/pie-players/tree/master/packages/default-tool-loaders#readme",
@@ -1,2 +0,0 @@
1
- export type { PackagedToolRegistryOptions, RegisterPackagedToolsOptions, } from "./packaged-capability-composition.js";
2
- export { createPackagedToolRegistry, PACKAGED_TOOL_ORDER, PACKAGED_TOOL_REGISTRATIONS, registerPackagedTools, } from "./packaged-capability-composition.js";
@@ -1 +0,0 @@
1
- export { createPackagedToolRegistry, PACKAGED_TOOL_ORDER, PACKAGED_TOOL_REGISTRATIONS, registerPackagedTools, } from "./packaged-capability-composition.js";
@@ -1 +0,0 @@
1
- export { PACKAGED_TOOL_PLACEMENT, SECTION_PLAYER_PREFERRED_TOOL_PLACEMENT, } from "./packaged-capability-composition.js";
@@ -1 +0,0 @@
1
- export { PACKAGED_TOOL_PLACEMENT, SECTION_PLAYER_PREFERRED_TOOL_PLACEMENT, } from "./packaged-capability-composition.js";
@@ -1 +0,0 @@
1
- export { PACKAGED_TOOL_TAG_MAP } from "./packaged-capability-composition.js";
@@ -1 +0,0 @@
1
- export { PACKAGED_TOOL_TAG_MAP } from "./packaged-capability-composition.js";
@@ -1 +0,0 @@
1
- export { UNIVERSAL_SUPPORTS_PRESET, createUniversalPersonalNeedsProfile, } from "./packaged-capability-composition.js";
@@ -1 +0,0 @@
1
- export { UNIVERSAL_SUPPORTS_PRESET, createUniversalPersonalNeedsProfile, } from "./packaged-capability-composition.js";