@pie-players/pie-players-shared 1.0.0-beta.0 → 1.0.0-beta.2

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.
@@ -1,3 +1,4 @@
1
+ import { settleAll } from "../../promise/index.js";
1
2
  export class CompositeInstrumentationProvider {
2
3
  providerId = "composite";
3
4
  providerName = "Composite Provider";
@@ -7,7 +8,7 @@ export class CompositeInstrumentationProvider {
7
8
  this.providers = providers.filter(Boolean);
8
9
  }
9
10
  async initialize(config) {
10
- const results = await Promise.allSettled(this.providers.map((provider) => provider.initialize(config)));
11
+ const results = await settleAll(this.providers.map((provider) => provider.initialize(config)));
11
12
  this.initialized = true;
12
13
  if (config?.debug) {
13
14
  for (const [index, result] of results.entries()) {
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Shape check for the package specs an item config names in `elements`.
3
+ *
4
+ * Loaders that build CDN URLs from a spec run it through
5
+ * `isScopedPackageSpec` first: item configs are authored content, and a
6
+ * version such as `1.0.0/../../../gh/owner/repo@main` would otherwise
7
+ * resolve to a path outside the package.
8
+ */
9
+ /**
10
+ * A scoped npm package name with an optional semver version or dist-tag, as
11
+ * item configs store it: `@pie-element/rubric`, `@pie-element/rubric@latest`,
12
+ * `@pie-element/rubric@8.0.0-hotfix.2`.
13
+ */
14
+ export declare function isScopedPackageSpec(spec: unknown): spec is string;
15
+ /** Why a loader refused `spec`, for its failure reason. */
16
+ export declare function invalidPackageSpecMessage(spec: unknown): string;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Shape check for the package specs an item config names in `elements`.
3
+ *
4
+ * Loaders that build CDN URLs from a spec run it through
5
+ * `isScopedPackageSpec` first: item configs are authored content, and a
6
+ * version such as `1.0.0/../../../gh/owner/repo@main` would otherwise
7
+ * resolve to a path outside the package.
8
+ */
9
+ const SEMVER_VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
10
+ const DIST_TAG = /^[A-Za-z][A-Za-z0-9_-]*$/;
11
+ const SCOPED_PACKAGE_NAME = /^@[a-z0-9~-][a-z0-9._~-]*\/[a-z0-9~-][a-z0-9._~-]*$/;
12
+ /**
13
+ * A scoped npm package name with an optional semver version or dist-tag, as
14
+ * item configs store it: `@pie-element/rubric`, `@pie-element/rubric@latest`,
15
+ * `@pie-element/rubric@8.0.0-hotfix.2`.
16
+ */
17
+ export function isScopedPackageSpec(spec) {
18
+ if (typeof spec !== "string")
19
+ return false;
20
+ const versionAt = spec.indexOf("@", 1);
21
+ if (versionAt === -1)
22
+ return SCOPED_PACKAGE_NAME.test(spec);
23
+ const version = spec.slice(versionAt + 1);
24
+ return (SCOPED_PACKAGE_NAME.test(spec.slice(0, versionAt)) &&
25
+ (SEMVER_VERSION.test(version) || DIST_TAG.test(version)));
26
+ }
27
+ /** Why a loader refused `spec`, for its failure reason. */
28
+ export function invalidPackageSpecMessage(spec) {
29
+ return `Invalid element package spec ${JSON.stringify(String(spec))}: expected a scoped npm package name with an optional semver version or dist-tag`;
30
+ }
@@ -67,7 +67,8 @@ export declare function createEsmBackend(config: EsmBackendConfig): EsmBackend;
67
67
  export declare function mapEsmViewElements(elements: ElementMap, view?: string, viewConfig?: ViewConfig): ElementMap;
68
68
  /**
69
69
  * URL of a package's `./runtime-support` module on the ESM CDN the players load
70
- * elements from, or `undefined` when a custom provider names no package root.
70
+ * elements from, or `undefined` when a custom provider names no package root or
71
+ * `packageVersion` is not a scoped package spec.
71
72
  */
72
73
  export declare function resolveEsmRuntimeSupportUrl(packageVersion: string, options: {
73
74
  cdnBaseUrl: string;
@@ -21,6 +21,7 @@ import { BundleType, isCustomElementConstructor, Status, } from "../pie/types.js
21
21
  import { parsePackageName } from "../pie/utils.js";
22
22
  import { AdapterFailure, } from "./element-loader-types.js";
23
23
  import { isExactSemver } from "./element-package-policy.js";
24
+ import { invalidPackageSpecMessage, isScopedPackageSpec, } from "./element-package-spec.js";
24
25
  import { forwardMathjaxEvents } from "./mathjax-events.js";
25
26
  import { isPlainRecord } from "../object/index.js";
26
27
  export const BUILT_IN_VIEWS = {
@@ -80,12 +81,30 @@ export function createEsmBackend(config) {
80
81
  async function load(elements, context) {
81
82
  if (!elements || Object.keys(elements).length === 0)
82
83
  return;
84
+ // Refused before any URL is built from the spec; the other elements load.
85
+ const reasons = new Map();
86
+ const loadable = {};
87
+ for (const [tag, pkg] of Object.entries(elements)) {
88
+ if (isScopedPackageSpec(pkg)) {
89
+ loadable[tag] = pkg;
90
+ }
91
+ else {
92
+ reasons.set(tag, {
93
+ kind: "backend-rejected",
94
+ tag,
95
+ cause: invalidPackageSpecMessage(pkg),
96
+ });
97
+ }
98
+ }
99
+ if (Object.keys(loadable).length === 0) {
100
+ throw new AdapterFailure(reasons);
101
+ }
83
102
  if (moduleResolution === "import-map") {
84
103
  assertImportMapSupported();
85
104
  }
86
105
  forwardMathjaxEventsOf(context.doc);
87
106
  const newEntries = {};
88
- for (const [tag, pkg] of Object.entries(elements)) {
107
+ for (const [tag, pkg] of Object.entries(loadable)) {
89
108
  const packageName = parsePackageName(pkg).name;
90
109
  if (moduleResolution === "import-map") {
91
110
  const existingVersion = importMappedPackageVersions.get(packageName);
@@ -147,8 +166,7 @@ export function createEsmBackend(config) {
147
166
  await applyImportMap(imports, injectedMap, context.doc);
148
167
  }
149
168
  }
150
- const reasons = new Map();
151
- await Promise.all(Object.entries(elements).map(async ([tag, packageVersion]) => {
169
+ await Promise.all(Object.entries(loadable).map(async ([tag, packageVersion]) => {
152
170
  const packageName = parsePackageName(packageVersion).name;
153
171
  let actualTag;
154
172
  try {
@@ -609,9 +627,12 @@ async function fetchPackageMetadata(packageJsonUrl) {
609
627
  const RUNTIME_SUPPORT_PATH = "dist/runtime-support.js";
610
628
  /**
611
629
  * URL of a package's `./runtime-support` module on the ESM CDN the players load
612
- * elements from, or `undefined` when a custom provider names no package root.
630
+ * elements from, or `undefined` when a custom provider names no package root or
631
+ * `packageVersion` is not a scoped package spec.
613
632
  */
614
633
  export function resolveEsmRuntimeSupportUrl(packageVersion, options) {
634
+ if (!isScopedPackageSpec(packageVersion))
635
+ return undefined;
615
636
  const cdnBaseUrl = options.cdnBaseUrl.replace(/\/+$/, "");
616
637
  const provider = resolveCdnProvider(options.cdnProvider, cdnBaseUrl);
617
638
  if (typeof provider.runtimeSupportUrl === "function") {
@@ -34,6 +34,7 @@ export type { ElementMap } from "./ElementLoader.js";
34
34
  export { aggregateElements } from "./ElementLoader.js";
35
35
  export type { ElementPackagePolicy } from "./element-package-policy.js";
36
36
  export { assertElementPackagesAllowed, ElementPackagePolicyError, } from "./element-package-policy.js";
37
+ export { isScopedPackageSpec } from "./element-package-spec.js";
37
38
  export type { BackendContext, BackendOption, ElementLoaderBackend, ElementTag, EnsureRegisteredOptions, EsmBackendConfig, IifeBackendConfig, RegistrationFailureReason, } from "./element-loader.js";
38
39
  export { AdapterFailure, ElementAssertionError, ElementLoaderError, assertRegistered, describeRegistrationFailures, ensureRegistered, } from "./element-loader.js";
39
40
  export type { BuiltInEsmCdnProviderName, EsmBackend, EsmCdnProvider, EsmCdnProviderName, EsmCdnProviderOption, ViewConfig, } from "./esm-adapter.js";
@@ -32,6 +32,7 @@
32
32
  */
33
33
  export { aggregateElements } from "./ElementLoader.js";
34
34
  export { assertElementPackagesAllowed, ElementPackagePolicyError, } from "./element-package-policy.js";
35
+ export { isScopedPackageSpec } from "./element-package-spec.js";
35
36
  export { AdapterFailure, ElementAssertionError, ElementLoaderError, assertRegistered, describeRegistrationFailures, ensureRegistered, } from "./element-loader.js";
36
37
  export { BUILT_IN_VIEWS, createEsmBackend, mapEsmViewElements, resolveEsmAssetRoot, resolveEsmRuntimeSupportUrl, } from "./esm-adapter.js";
37
38
  export { forwardMathjaxEvents, MATHJAX_NO_ASSET_ROOT_EVENT, MATHJAX_VERSION_CONFLICT_EVENT, } from "./mathjax-events.js";
@@ -41,6 +41,7 @@ export { BundleType, defaultPieElementOptions, isCustomElementConstructor, isPie
41
41
  export { attemptCustomElementDefine, defineCustomElementSafely, type AttemptCustomElementDefineOptions, type SafeDefineAttempt, type SafeDefineOutcome, type SafeDefineResult, type SafeDefineStatus, } from "./custom-element-define.js";
42
42
  export { toPrintHashedTag, toViewTag, validateCustomElementTag, VIEW_TAG_SUFFIX, } from "./tag-names.js";
43
43
  export type { PieViewMode } from "./tag-names.js";
44
+ export { runtimeElementTags } from "./versioned-tag.js";
44
45
  export { updatePieElement, updatePieElements, updatePieElementWithRef, } from "./updates.js";
45
46
  export type { ElementOverrides } from "./overrides.js";
46
47
  export { addOrUpdateOverrideInUrl, applyElementOverrides, applyElementVersionOverridesPreserveTags, extractPackageInfo, formatElementOverrideParam, parseElementOverridesFromCurrentUrl, parseElementOverridesFromUrl, } from "./overrides.js";
package/dist/pie/index.js CHANGED
@@ -44,6 +44,7 @@ isPieAvailable, isPieRegistryAvailable, Status, } from "./types.js";
44
44
  // Tag naming helpers
45
45
  export { attemptCustomElementDefine, defineCustomElementSafely, } from "./custom-element-define.js";
46
46
  export { toPrintHashedTag, toViewTag, validateCustomElementTag, VIEW_TAG_SUFFIX, } from "./tag-names.js";
47
+ export { runtimeElementTags } from "./versioned-tag.js";
47
48
  // Updates
48
49
  export { updatePieElement, updatePieElements, updatePieElementWithRef, } from "./updates.js";
49
50
  export { addOrUpdateOverrideInUrl, applyElementOverrides, applyElementVersionOverridesPreserveTags, extractPackageInfo, formatElementOverrideParam, parseElementOverridesFromCurrentUrl, parseElementOverridesFromUrl, } from "./overrides.js";
@@ -17,3 +17,13 @@ export declare function parseVersionedTagName(tagName: string): {
17
17
  export declare function toPackageVersionedTag(tagName: string, packageSpec: string, options?: {
18
18
  preserveUnversionedTag?: boolean;
19
19
  }): string;
20
+ /**
21
+ * The tags a player can define an authored element under, most specific first:
22
+ * the versioned tag for its package spec, aligned to the page's preloaded
23
+ * registration, then the authored tag, which an unversioned spec keeps. With no
24
+ * spec the authored tag is the only candidate.
25
+ *
26
+ * For code that looks an element's class up by tag without rendering it, such as
27
+ * reading what the class declares before the element is in the DOM.
28
+ */
29
+ export declare function runtimeElementTags(tagName: string, packageSpec?: string): string[];
@@ -1,3 +1,4 @@
1
+ import { alignPreloadedElementVersions } from "../loaders/preloaded-alignment.js";
1
2
  import { parsePackageName } from "./utils.js";
2
3
  const VERSION_DELIMITER = "--version-";
3
4
  const TAG_VERSION_PATTERN = "[0-9A-Za-z-]+";
@@ -45,3 +46,29 @@ export function toPackageVersionedTag(tagName, packageSpec, options = {}) {
45
46
  // package versions at runtime, which requires updating the cloned runtime tag.
46
47
  return `${baseName}${VERSION_DELIMITER}${targetEncodedVersion}`;
47
48
  }
49
+ /**
50
+ * The tags a player can define an authored element under, most specific first:
51
+ * the versioned tag for its package spec, aligned to the page's preloaded
52
+ * registration, then the authored tag, which an unversioned spec keeps. With no
53
+ * spec the authored tag is the only candidate.
54
+ *
55
+ * For code that looks an element's class up by tag without rendering it, such as
56
+ * reading what the class declares before the element is in the DOM.
57
+ */
58
+ export function runtimeElementTags(tagName, packageSpec) {
59
+ if (!packageSpec)
60
+ return [tagName];
61
+ let versioned;
62
+ try {
63
+ const { elements } = alignPreloadedElementVersions({
64
+ elements: { [tagName]: packageSpec },
65
+ });
66
+ versioned = toPackageVersionedTag(tagName, elements[tagName], {
67
+ preserveUnversionedTag: true,
68
+ });
69
+ }
70
+ catch {
71
+ return [tagName];
72
+ }
73
+ return versioned === tagName ? [tagName] : [versioned, tagName];
74
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Waits for every value to settle and resolves with each outcome in input
3
+ * order, as the `allSettled` static does. Built on `Promise.all` and `then` alone:
4
+ * a host page can replace the global `Promise` with an implementation that
5
+ * predates `allSettled` (zone.js 0.9.1 does), so published code calls no
6
+ * `Promise` static beyond `all`, `race`, `resolve` and `reject`.
7
+ * `bun run check:bundle-safety` enforces that on every built bundle.
8
+ * @param values The promises or plain values to settle.
9
+ */
10
+ export declare const settleAll: <T>(values: Iterable<T | PromiseLike<T>>) => Promise<PromiseSettledResult<Awaited<T>>[]>;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Waits for every value to settle and resolves with each outcome in input
3
+ * order, as the `allSettled` static does. Built on `Promise.all` and `then` alone:
4
+ * a host page can replace the global `Promise` with an implementation that
5
+ * predates `allSettled` (zone.js 0.9.1 does), so published code calls no
6
+ * `Promise` static beyond `all`, `race`, `resolve` and `reject`.
7
+ * `bun run check:bundle-safety` enforces that on every built bundle.
8
+ * @param values The promises or plain values to settle.
9
+ */
10
+ export const settleAll = (values) => Promise.all(Array.from(values, (value) => Promise.resolve(value).then((result) => ({
11
+ status: "fulfilled",
12
+ value: result,
13
+ }), (reason) => ({
14
+ status: "rejected",
15
+ reason,
16
+ }))));
@@ -464,9 +464,25 @@ export interface AccessibilityCatalog {
464
464
  identifier: string;
465
465
  cards: CatalogCard[];
466
466
  }
467
+ /**
468
+ * A learner's personal needs profile, in tool ids. An AfA PNP 3.0 record maps to
469
+ * it through the AfA adapter the packaged tool set exports.
470
+ */
467
471
  export interface PersonalNeedsProfile {
472
+ /** Tools the learner may turn on. */
468
473
  supports: string[];
474
+ /** Tools withheld from the learner; a prohibition outranks a support. */
469
475
  prohibitedSupports?: string[];
476
+ /**
477
+ * Tools granted as `supports` grants them and turned on when the learner's
478
+ * toolbar first shows them. A block withdraws them as it withdraws a support.
479
+ */
480
+ activateAtInit?: string[];
481
+ /**
482
+ * Parameters by tool id, the lowest layer: the assessment's and an item's
483
+ * `toolParameters` override them key by key.
484
+ */
485
+ toolParameters?: ToolParameters;
470
486
  }
471
487
  export interface AssessmentEntity extends BaseEntity, SearchMetaDataEntity {
472
488
  name?: string;
@@ -509,8 +525,9 @@ export interface AssessmentSettings {
509
525
  toolOverrides?: Record<string, boolean>;
510
526
  };
511
527
  /**
512
- * Parameters by tool id, handed to the tool wherever policy shows it; an
513
- * item's `toolParameters` entry wins on that item's own toolbar. Provider
528
+ * Parameters by tool id, handed to the tool wherever policy shows it. They
529
+ * override the profile's `toolParameters` key by key, and an item's
530
+ * `toolParameters` override them on that item's own toolbar. Provider
514
531
  * configuration belongs in the toolkit's `tools.providers`.
515
532
  */
516
533
  toolParameters?: ToolParameters;
@@ -531,6 +548,15 @@ export interface ToolParameterMap {
531
548
  signLanguage: {
532
549
  signLang?: string;
533
550
  };
551
+ /**
552
+ * `rate` multiplies every playback speed, 1 being the provider's normal
553
+ * speed; `pitch` runs 0–2 with 1 normal; `volume` runs 0–1.
554
+ */
555
+ textToSpeech: {
556
+ rate?: number;
557
+ pitch?: number;
558
+ volume?: number;
559
+ };
534
560
  }
535
561
  /** The parameter shape of tool `K`: its {@link ToolParameterMap} entry, else open. */
536
562
  export type ToolParametersFor<K extends string> = K extends keyof ToolParameterMap ? ToolParameterMap[K] : Record<string, unknown>;
@@ -547,7 +573,7 @@ export type ToolParameters = {
547
573
  export interface ItemSettings {
548
574
  requiredTools?: string[];
549
575
  restrictedTools?: string[];
550
- /** Parameters by tool id; outranks the assessment's `toolParameters` entry. */
576
+ /** Parameters by tool id; override the assessment's key by key. */
551
577
  toolParameters?: ToolParameters;
552
578
  }
553
579
  export type PlayerMode = "gather" | "view" | "evaluate" | "author";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-players/pie-players-shared",
3
- "version": "1.0.0-beta.0",
3
+ "version": "1.0.0-beta.2",
4
4
  "type": "module",
5
5
  "description": "Shared runtime + UI utilities for PIE players",
6
6
  "license": "MIT",
@@ -33,6 +33,10 @@
33
33
  "types": "./dist/object/index.d.ts",
34
34
  "import": "./dist/object/index.js"
35
35
  },
36
+ "./promise": {
37
+ "types": "./dist/promise/index.d.ts",
38
+ "import": "./dist/promise/index.js"
39
+ },
36
40
  "./types": {
37
41
  "types": "./dist/types/index.d.ts",
38
42
  "import": "./dist/types/index.js"
@@ -121,12 +125,12 @@
121
125
  "@biomejs/biome": "^2.5.15",
122
126
  "@happy-dom/global-registrator": "^20.14.5",
123
127
  "@pie-element/shared-math-rendering-mathjax": "0.1.4",
124
- "@playwright/test": "^1.63.0",
128
+ "@playwright/test": "^1.64.0",
125
129
  "@types/semver": "^7.8.0",
126
130
  "es-module-shims": "^2.8.4",
127
131
  "esbuild": "^0.28.2",
128
132
  "glob": "^13.0.0",
129
- "svelte": "^5.57.1",
133
+ "svelte": "^5.57.2",
130
134
  "svelte-check": "^4.7.6",
131
135
  "typescript": "^5.9.3"
132
136
  },