@pie-element/shared-types 0.2.0-next.1 → 0.2.0-next.20261002100925

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  /**
2
2
  * PIE Shared Types
3
3
  *
4
- * Framework-agnostic TypeScript types and events for PIE elements.
4
+ * Framework-agnostic TypeScript types for PIE elements.
5
5
  */
6
- export * from './events.js';
7
6
  export * from './docs-contract.js';
8
7
  export * from './types.js';
package/dist/index.js CHANGED
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * PIE Shared Types
3
3
  *
4
- * Framework-agnostic TypeScript types and events for PIE elements.
4
+ * Framework-agnostic TypeScript types for PIE elements.
5
5
  */
6
- export * from './events.js';
7
6
  export * from './docs-contract.js';
8
7
  export * from './types.js';
9
8
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC","sourcesContent":["/**\n * PIE Shared Types\n *\n * Framework-agnostic TypeScript types and events for PIE elements.\n */\n\nexport * from './events.js';\nexport * from './docs-contract.js';\nexport * from './types.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC","sourcesContent":["/**\n * PIE Shared Types\n *\n * Framework-agnostic TypeScript types for PIE elements.\n */\n\nexport * from './docs-contract.js';\nexport * from './types.js';\n"]}
package/dist/types.d.ts CHANGED
@@ -11,17 +11,21 @@
11
11
  * both read the same authored JSON, so structural typing is sufficient for
12
12
  * interop. Fixture parity — not a package edge — is what pins them together.
13
13
  *
14
- * Only the fields sign-language catalog cards need are declared. `poster`,
15
- * `thumbnail` and `durationSeconds` do not apply to a signing clip, and
16
- * `tracks`/`transcript` are meaningless for one: captions on a signing video
17
- * would be the English text already on screen. Add fields additively when a
18
- * second consumer (e.g. a video stimulus element) needs them.
14
+ * Sign-language catalog cards were the first consumer and use only the core
15
+ * source fields. The optional presentation, track, and transcript metadata is
16
+ * declared for broader consumers such as video stimuli; it remains meaningless
17
+ * for a signing clip, where captions would duplicate the text already on screen.
19
18
  */
20
19
  export interface MediaAssetRef {
21
20
  version: 1;
22
21
  id: string;
23
22
  kind: MediaKind;
24
23
  sources: MediaSource[];
24
+ poster?: string;
25
+ thumbnail?: string;
26
+ durationSeconds?: number;
27
+ tracks?: TextTrackRef[];
28
+ transcript?: TranscriptRef;
25
29
  label?: string;
26
30
  description?: string;
27
31
  /**
@@ -39,6 +43,28 @@ export interface MediaSource {
39
43
  type?: string;
40
44
  width?: number;
41
45
  height?: number;
46
+ bitrate?: number;
47
+ }
48
+ /** One authored text track associated with an audio or video asset. */
49
+ export interface TextTrackRef {
50
+ src: string;
51
+ kind: 'captions' | 'subtitles' | 'descriptions' | 'chapters' | 'metadata';
52
+ lang: string;
53
+ label: string;
54
+ default?: boolean;
55
+ }
56
+ /** Inline or externally hosted transcript content for a media asset. */
57
+ export interface TranscriptRef {
58
+ src?: string;
59
+ html?: string;
60
+ plainText?: string;
61
+ lang?: string;
62
+ }
63
+ /** Learner-facing strings for the transcript controls of a media element. */
64
+ export interface MediaUiText {
65
+ showTranscript: string;
66
+ hideTranscript: string;
67
+ viewTranscript: string;
42
68
  }
43
69
  /**
44
70
  * A time slice within a media asset, so one recording can serve several
@@ -69,7 +95,7 @@ export interface SignLanguageCardPayload {
69
95
  * only key on the generic field — and the player falls back to it when this is
70
96
  * absent. Author it only where the two differ: a card tagged with the item's
71
97
  * content language (`language: 'en-US'`, `signLang: 'ase'`) so resolution
72
- * reaches it by the default-language rung. The Learnosity importer emits
98
+ * reaches it by the default-language rung. The pie-api-aws importer emits
73
99
  * `language` alone.
74
100
  */
75
101
  signLang?: string;
@@ -163,7 +189,7 @@ export interface SignLanguageCatalogCard extends CatalogCard {
163
189
  * absent — belongs to the consuming player, per the sign-language PRD.
164
190
  *
165
191
  * Deliberately says nothing about `signLang`. It once required a non-empty one,
166
- * which would have rejected every card the Learnosity importer produces: the
192
+ * which would have rejected every card the pie-api-aws importer produces: the
167
193
  * adaptation language lives on the card's `language`, and a payload that omits
168
194
  * `signLang` is the normal shape rather than a malformed one.
169
195
  */
package/dist/types.js CHANGED
@@ -10,7 +10,7 @@
10
10
  * absent — belongs to the consuming player, per the sign-language PRD.
11
11
  *
12
12
  * Deliberately says nothing about `signLang`. It once required a non-empty one,
13
- * which would have rejected every card the Learnosity importer produces: the
13
+ * which would have rejected every card the pie-api-aws importer produces: the
14
14
  * adaptation language lives on the card's `language`, and a payload that omits
15
15
  * `signLang` is the normal shape rather than a malformed one.
16
16
  */
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAoKH;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAiB;IAClD,IAAI,IAAI,CAAC,OAAO,KAAK,eAAe,EAAE,CAAC;QACrC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;IAE7B,OAAO,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;AACpF,CAAC","sourcesContent":["/**\n * Core PIE specification types\n */\n\n/**\n * Reference to a media asset and its playable encodings.\n *\n * Structurally mirrors the `MediaAssetRef` in the pie-players\n * `media-asset-contract` PRD. The two definitions are deliberately kept as\n * separate declarations rather than a shared package dependency: this repo owns\n * the item-model side of the contract, pie-players owns the player side, and\n * both read the same authored JSON, so structural typing is sufficient for\n * interop. Fixture parity — not a package edge — is what pins them together.\n *\n * Only the fields sign-language catalog cards need are declared. `poster`,\n * `thumbnail` and `durationSeconds` do not apply to a signing clip, and\n * `tracks`/`transcript` are meaningless for one: captions on a signing video\n * would be the English text already on screen. Add fields additively when a\n * second consumer (e.g. a video stimulus element) needs them.\n */\nexport interface MediaAssetRef {\n version: 1;\n id: string;\n kind: MediaKind;\n sources: MediaSource[];\n label?: string;\n description?: string;\n /**\n * Language of the asset itself, as authored metadata. Sign-language cards\n * leave it unset: the card's `language` already states the adaptation\n * language, and a second copy is a second thing to keep in agreement.\n */\n lang?: string;\n}\n\nexport type MediaKind = 'image' | 'audio' | 'video' | 'other';\n\n/** One playable encoding of a media asset. */\nexport interface MediaSource {\n src: string;\n /** MIME type, e.g. \"video/mp4\". */\n type?: string;\n width?: number;\n height?: number;\n}\n\n/**\n * A time slice within a media asset, so one recording can serve several\n * content nodes. Mirrors QTI 3's Media Fragments URI usage.\n */\nexport interface MediaFragmentRange {\n startSeconds: number;\n endSeconds?: number;\n}\n\n/**\n * Payload for a `sign-language` catalog card: a signed translation of the\n * content node the card is docked to.\n */\nexport interface SignLanguageCardPayload {\n /**\n * Language tag for the signed translation — BCP 47, which admits ISO 639-3\n * subtags for languages with no 639-1/2 code. \"ase\" is ASL, matching QTI 3\n * `xml:lang`.\n *\n * This is the language of the *adaptation*, not the item's base content\n * language (AfA/PNP's `languageOfAdaptation`). The distinction is load\n * bearing: a Spanish item's signed alternate is LSM, not ASL, so `signLang`\n * must never be inferred from the item or assessment content language.\n *\n * Optional, and redundant on almost every card. The card's `language` states\n * the same code and is the only field pie-players resolves a card on —\n * resolution runs before anything knows the card is a signing card, so it can\n * only key on the generic field — and the player falls back to it when this is\n * absent. Author it only where the two differ: a card tagged with the item's\n * content language (`language: 'en-US'`, `signLang: 'ase'`) so resolution\n * reaches it by the default-language rung. The Learnosity importer emits\n * `language` alone.\n */\n signLang?: string;\n media: MediaAssetRef;\n fragment?: MediaFragmentRange;\n}\n\n/**\n * Payload for a `spoken` catalog card that is a recording rather than a script.\n *\n * QTI 3 treats recorded audio and synthesized speech as the same support: both\n * are `spoken`, so this is not a new accommodation, it is the other form the\n * existing one can take. A node commonly carries both this and a `content`\n * card in the same language — the script is both what the audio was generated\n * from and the fallback for when the audio cannot play; pie-players resolves\n * between them with `CatalogLookupOptions.form`.\n *\n * No `kind` discriminant, for the same reason `SignLanguageCardPayload` has\n * none: the card's `catalog` already says what this is.\n */\nexport interface SpokenAudioCardPayload {\n media: MediaAssetRef;\n fragment?: MediaFragmentRange;\n}\n\n/**\n * The structured forms a card's `payload` may take.\n *\n * Which one applies is decided by the card's `catalog`, so this union carries no\n * discriminant of its own — a second discriminant could contradict the first.\n * Consumers select a card by catalog type and then validate the payload\n * structurally, which they must do regardless: catalog data is authored,\n * wire-facing and untrusted.\n */\nexport type CatalogCardPayload = SignLanguageCardPayload | SpokenAudioCardPayload;\n\n/**\n * QTI-aligned accessibility catalog entry: one alternate representation of a\n * content node, docked to it by `data-catalog-idref`.\n *\n * Maps onto QTI 3's `qti-card`. `catalog` is QTI's `@support` and is the only\n * discriminant — there is deliberately no second `kind` field. `language` is the\n * card entry's `xml:lang`. QTI's single content slot is represented by exactly\n * one of two fields, never both, with nothing mirrored between them:\n *\n * - `content` — the string form, for alternates a string can express: SSML for\n * `spoken`, plain text for `simplified-language`.\n * - `payload` — the structured form, for what a string cannot express. Today\n * only a signing video.\n *\n * One generic payload slot rather than a field per accommodation\n * (`signLanguage`, `braille`, …), which is the shape pie-players canonicalises\n * and the shape this repo now follows. A field per accommodation makes every new\n * structured alternate a breaking widening of this type in every consumer that\n * reads cards, and it gives the same fact two names across repos — which\n * produced a real bug: a card carrying `signLanguage` rendered its video in the\n * player and was simultaneously reported as carrying no payload by the player's\n * \"what alternates exist\" path, because only one of the two read paths knew\n * about the alias.\n *\n * `catalog` is a bare `string` because the vocabulary is open-ended and unknown\n * tokens must be ignored rather than rejected. TypeScript therefore cannot\n * express \"a `sign-language` card must carry a payload\", so a\n * `{ catalog: 'sign-language', content: '<url>' }` object still satisfies this\n * type. That legacy bare-URL form is not supported: runtime validation on the\n * consuming side must reject it rather than render the URL as visible text.\n * Narrow with `isSignLanguageCard`.\n */\nexport interface CatalogCard {\n catalog: string;\n language?: string;\n content?: string;\n payload?: CatalogCardPayload;\n}\n\n/**\n * A `CatalogCard` narrowed to the signing case, where the payload is mandatory.\n *\n * Maps to QTI `qti-card support=\"sign-language\"`. This is a refinement of the\n * shared shape for authoring and narrowing, not a second card model: it adds\n * only what `CatalogCard` cannot state, which is that a signing card must carry\n * its payload and must not carry a bare URL in `content`.\n */\nexport interface SignLanguageCatalogCard extends CatalogCard {\n catalog: 'sign-language';\n payload: SignLanguageCardPayload;\n content?: never;\n}\n\n/**\n * Narrows a catalog card to its sign-language form.\n *\n * This is a structural narrowing guard, not a payload validator: it confirms\n * the card carries a signing payload with at least one media source. Full\n * payload validation — and the rule that an invalid payload is treated as\n * absent — belongs to the consuming player, per the sign-language PRD.\n *\n * Deliberately says nothing about `signLang`. It once required a non-empty one,\n * which would have rejected every card the Learnosity importer produces: the\n * adaptation language lives on the card's `language`, and a payload that omits\n * `signLang` is the normal shape rather than a malformed one.\n */\nexport function isSignLanguageCard(card: CatalogCard): card is SignLanguageCatalogCard {\n if (card.catalog !== 'sign-language') {\n return false;\n }\n\n const payload = card.payload;\n\n return Array.isArray(payload?.media?.sources) && payload.media.sources.length > 0;\n}\n\nexport interface AccessibilityCatalog {\n identifier: string;\n cards: CatalogCard[];\n}\n\n// Base PIE model (all elements extend this)\nexport interface PieModel {\n id: string;\n element: string; // e.g., \"@pie-element/multiple-choice\"\n accessibilityCatalogs?: AccessibilityCatalog[];\n}\n\n// Theme configuration (from DaisyUI or custom)\nexport interface PieTheme {\n primary?: string; // Primary brand color\n secondary?: string; // Secondary color\n accent?: string; // Accent color\n neutral?: string; // Neutral color\n 'base-100'?: string; // Base background color\n 'base-200'?: string; // Secondary background\n 'base-300'?: string; // Tertiary background\n 'base-content'?: string; // Base text color\n info?: string; // Info color\n success?: string; // Success/correct color\n warning?: string; // Warning color\n error?: string; // Error/incorrect color\n}\n\n// Environment configuration\nexport interface PieEnvironment {\n mode: 'gather' | 'view' | 'evaluate';\n role: 'student' | 'instructor';\n // Optional advanced features\n lockChoiceOrder?: boolean;\n partialScoring?: boolean;\n // Optional theme configuration\n theme?: PieTheme;\n}\n\n// Session data (student responses)\nexport interface PieSession {\n id?: string;\n [key: string]: unknown;\n}\n\n// View model (output from controller.model())\nexport interface ViewModel extends Record<string, unknown> {\n disabled: boolean;\n mode: PieEnvironment['mode'];\n}\n\n// Outcome result (output from controller.outcome())\nexport interface OutcomeResult {\n score: number; // 0-1 scale\n empty: boolean; // True if no response provided\n}\n\n// Validation result\nexport interface ValidationErrors {\n [key: string]: string;\n}\n\n// Common configuration settings\nexport interface CommonConfigSettings {\n settingsPanelDisabled?: boolean;\n spellCheck?: ConfigureProp;\n maxImageWidth?: ConfigureProp;\n maxImageHeight?: ConfigureProp;\n withRubric?: ConfigureProp;\n language?: ConfigureProp;\n languageChoices?: ConfigureLanguageOptions;\n}\n\nexport interface ConfigureProp {\n settings?: boolean;\n label?: string;\n enabled?: boolean;\n}\n\nexport interface ConfigureLanguageOptions {\n label: string;\n options: { label: string; value: string }[];\n}\n\n// Print options\nexport interface PrintOptions {\n role: 'student' | 'instructor';\n mode?: PieEnvironment['mode'];\n}\n\n/**\n * Persists `properties` into the stored session `id` of element `element`. A player passes it to\n * `model()`, which calls `updateSession(session.id, session.element, { shuffledValues })` to keep\n * the choice order it drew.\n */\nexport type PieUpdateSession = (\n id: string,\n element: string,\n properties: Partial<PieSession>\n) => Promise<void>;\n\n// Controller interface\nexport interface PieController {\n model(\n question: PieModel,\n session: PieSession | null,\n env: PieEnvironment,\n updateSession?: PieUpdateSession\n ): Promise<ViewModel>;\n\n outcome(model: PieModel, session: PieSession, env: PieEnvironment): Promise<OutcomeResult>;\n\n createDefaultModel(partial?: Partial<PieModel>): PieModel;\n\n validate(model: PieModel, config: CommonConfigSettings): ValidationErrors;\n\n createCorrectResponseSession(question: PieModel, env: PieEnvironment): PieSession;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAiMH;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAiB;IAClD,IAAI,IAAI,CAAC,OAAO,KAAK,eAAe,EAAE,CAAC;QACrC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;IAE7B,OAAO,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;AACpF,CAAC","sourcesContent":["/**\n * Core PIE specification types\n */\n\n/**\n * Reference to a media asset and its playable encodings.\n *\n * Structurally mirrors the `MediaAssetRef` in the pie-players\n * `media-asset-contract` PRD. The two definitions are deliberately kept as\n * separate declarations rather than a shared package dependency: this repo owns\n * the item-model side of the contract, pie-players owns the player side, and\n * both read the same authored JSON, so structural typing is sufficient for\n * interop. Fixture parity — not a package edge — is what pins them together.\n *\n * Sign-language catalog cards were the first consumer and use only the core\n * source fields. The optional presentation, track, and transcript metadata is\n * declared for broader consumers such as video stimuli; it remains meaningless\n * for a signing clip, where captions would duplicate the text already on screen.\n */\nexport interface MediaAssetRef {\n version: 1;\n id: string;\n kind: MediaKind;\n sources: MediaSource[];\n poster?: string;\n thumbnail?: string;\n durationSeconds?: number;\n tracks?: TextTrackRef[];\n transcript?: TranscriptRef;\n label?: string;\n description?: string;\n /**\n * Language of the asset itself, as authored metadata. Sign-language cards\n * leave it unset: the card's `language` already states the adaptation\n * language, and a second copy is a second thing to keep in agreement.\n */\n lang?: string;\n}\n\nexport type MediaKind = 'image' | 'audio' | 'video' | 'other';\n\n/** One playable encoding of a media asset. */\nexport interface MediaSource {\n src: string;\n /** MIME type, e.g. \"video/mp4\". */\n type?: string;\n width?: number;\n height?: number;\n bitrate?: number;\n}\n\n/** One authored text track associated with an audio or video asset. */\nexport interface TextTrackRef {\n src: string;\n kind: 'captions' | 'subtitles' | 'descriptions' | 'chapters' | 'metadata';\n lang: string;\n label: string;\n default?: boolean;\n}\n\n/** Inline or externally hosted transcript content for a media asset. */\nexport interface TranscriptRef {\n src?: string;\n html?: string;\n plainText?: string;\n lang?: string;\n}\n\n/** Learner-facing strings for the transcript controls of a media element. */\nexport interface MediaUiText {\n showTranscript: string;\n hideTranscript: string;\n viewTranscript: string;\n}\n\n/**\n * A time slice within a media asset, so one recording can serve several\n * content nodes. Mirrors QTI 3's Media Fragments URI usage.\n */\nexport interface MediaFragmentRange {\n startSeconds: number;\n endSeconds?: number;\n}\n\n/**\n * Payload for a `sign-language` catalog card: a signed translation of the\n * content node the card is docked to.\n */\nexport interface SignLanguageCardPayload {\n /**\n * Language tag for the signed translation — BCP 47, which admits ISO 639-3\n * subtags for languages with no 639-1/2 code. \"ase\" is ASL, matching QTI 3\n * `xml:lang`.\n *\n * This is the language of the *adaptation*, not the item's base content\n * language (AfA/PNP's `languageOfAdaptation`). The distinction is load\n * bearing: a Spanish item's signed alternate is LSM, not ASL, so `signLang`\n * must never be inferred from the item or assessment content language.\n *\n * Optional, and redundant on almost every card. The card's `language` states\n * the same code and is the only field pie-players resolves a card on —\n * resolution runs before anything knows the card is a signing card, so it can\n * only key on the generic field — and the player falls back to it when this is\n * absent. Author it only where the two differ: a card tagged with the item's\n * content language (`language: 'en-US'`, `signLang: 'ase'`) so resolution\n * reaches it by the default-language rung. The pie-api-aws importer emits\n * `language` alone.\n */\n signLang?: string;\n media: MediaAssetRef;\n fragment?: MediaFragmentRange;\n}\n\n/**\n * Payload for a `spoken` catalog card that is a recording rather than a script.\n *\n * QTI 3 treats recorded audio and synthesized speech as the same support: both\n * are `spoken`, so this is not a new accommodation, it is the other form the\n * existing one can take. A node commonly carries both this and a `content`\n * card in the same language — the script is both what the audio was generated\n * from and the fallback for when the audio cannot play; pie-players resolves\n * between them with `CatalogLookupOptions.form`.\n *\n * No `kind` discriminant, for the same reason `SignLanguageCardPayload` has\n * none: the card's `catalog` already says what this is.\n */\nexport interface SpokenAudioCardPayload {\n media: MediaAssetRef;\n fragment?: MediaFragmentRange;\n}\n\n/**\n * The structured forms a card's `payload` may take.\n *\n * Which one applies is decided by the card's `catalog`, so this union carries no\n * discriminant of its own — a second discriminant could contradict the first.\n * Consumers select a card by catalog type and then validate the payload\n * structurally, which they must do regardless: catalog data is authored,\n * wire-facing and untrusted.\n */\nexport type CatalogCardPayload = SignLanguageCardPayload | SpokenAudioCardPayload;\n\n/**\n * QTI-aligned accessibility catalog entry: one alternate representation of a\n * content node, docked to it by `data-catalog-idref`.\n *\n * Maps onto QTI 3's `qti-card`. `catalog` is QTI's `@support` and is the only\n * discriminant — there is deliberately no second `kind` field. `language` is the\n * card entry's `xml:lang`. QTI's single content slot is represented by exactly\n * one of two fields, never both, with nothing mirrored between them:\n *\n * - `content` — the string form, for alternates a string can express: SSML for\n * `spoken`, plain text for `simplified-language`.\n * - `payload` — the structured form, for what a string cannot express. Today\n * only a signing video.\n *\n * One generic payload slot rather than a field per accommodation\n * (`signLanguage`, `braille`, …), which is the shape pie-players canonicalises\n * and the shape this repo now follows. A field per accommodation makes every new\n * structured alternate a breaking widening of this type in every consumer that\n * reads cards, and it gives the same fact two names across repos — which\n * produced a real bug: a card carrying `signLanguage` rendered its video in the\n * player and was simultaneously reported as carrying no payload by the player's\n * \"what alternates exist\" path, because only one of the two read paths knew\n * about the alias.\n *\n * `catalog` is a bare `string` because the vocabulary is open-ended and unknown\n * tokens must be ignored rather than rejected. TypeScript therefore cannot\n * express \"a `sign-language` card must carry a payload\", so a\n * `{ catalog: 'sign-language', content: '<url>' }` object still satisfies this\n * type. That legacy bare-URL form is not supported: runtime validation on the\n * consuming side must reject it rather than render the URL as visible text.\n * Narrow with `isSignLanguageCard`.\n */\nexport interface CatalogCard {\n catalog: string;\n language?: string;\n content?: string;\n payload?: CatalogCardPayload;\n}\n\n/**\n * A `CatalogCard` narrowed to the signing case, where the payload is mandatory.\n *\n * Maps to QTI `qti-card support=\"sign-language\"`. This is a refinement of the\n * shared shape for authoring and narrowing, not a second card model: it adds\n * only what `CatalogCard` cannot state, which is that a signing card must carry\n * its payload and must not carry a bare URL in `content`.\n */\nexport interface SignLanguageCatalogCard extends CatalogCard {\n catalog: 'sign-language';\n payload: SignLanguageCardPayload;\n content?: never;\n}\n\n/**\n * Narrows a catalog card to its sign-language form.\n *\n * This is a structural narrowing guard, not a payload validator: it confirms\n * the card carries a signing payload with at least one media source. Full\n * payload validation — and the rule that an invalid payload is treated as\n * absent — belongs to the consuming player, per the sign-language PRD.\n *\n * Deliberately says nothing about `signLang`. It once required a non-empty one,\n * which would have rejected every card the pie-api-aws importer produces: the\n * adaptation language lives on the card's `language`, and a payload that omits\n * `signLang` is the normal shape rather than a malformed one.\n */\nexport function isSignLanguageCard(card: CatalogCard): card is SignLanguageCatalogCard {\n if (card.catalog !== 'sign-language') {\n return false;\n }\n\n const payload = card.payload;\n\n return Array.isArray(payload?.media?.sources) && payload.media.sources.length > 0;\n}\n\nexport interface AccessibilityCatalog {\n identifier: string;\n cards: CatalogCard[];\n}\n\n// Base PIE model (all elements extend this)\nexport interface PieModel {\n id: string;\n element: string; // Element tag, the key in the item config's `elements` map, e.g. \"multiple-choice\"\n accessibilityCatalogs?: AccessibilityCatalog[];\n}\n\n// Theme configuration (from DaisyUI or custom)\nexport interface PieTheme {\n primary?: string; // Primary brand color\n secondary?: string; // Secondary color\n accent?: string; // Accent color\n neutral?: string; // Neutral color\n 'base-100'?: string; // Base background color\n 'base-200'?: string; // Secondary background\n 'base-300'?: string; // Tertiary background\n 'base-content'?: string; // Base text color\n info?: string; // Info color\n success?: string; // Success/correct color\n warning?: string; // Warning color\n error?: string; // Error/incorrect color\n}\n\n// Environment configuration\nexport interface PieEnvironment {\n mode: 'gather' | 'view' | 'evaluate';\n role: 'student' | 'instructor';\n // Optional advanced features\n lockChoiceOrder?: boolean;\n partialScoring?: boolean;\n // Optional theme configuration\n theme?: PieTheme;\n}\n\n// Session data (student responses)\nexport interface PieSession {\n id?: string;\n [key: string]: unknown;\n}\n\n// View model (output from controller.model())\nexport interface ViewModel extends Record<string, unknown> {\n disabled: boolean;\n mode: PieEnvironment['mode'];\n}\n\n// Outcome result (output from controller.outcome())\nexport interface OutcomeResult {\n score: number; // 0-1 scale\n empty: boolean; // True if no response provided\n}\n\n// Validation result\nexport interface ValidationErrors {\n [key: string]: string;\n}\n\n// Common configuration settings\nexport interface CommonConfigSettings {\n settingsPanelDisabled?: boolean;\n spellCheck?: ConfigureProp;\n maxImageWidth?: ConfigureProp;\n maxImageHeight?: ConfigureProp;\n withRubric?: ConfigureProp;\n language?: ConfigureProp;\n languageChoices?: ConfigureLanguageOptions;\n}\n\nexport interface ConfigureProp {\n settings?: boolean;\n label?: string;\n enabled?: boolean;\n}\n\nexport interface ConfigureLanguageOptions {\n label: string;\n options: { label: string; value: string }[];\n}\n\n// Print options\nexport interface PrintOptions {\n role: 'student' | 'instructor';\n mode?: PieEnvironment['mode'];\n}\n\n/**\n * Persists `properties` into the stored session `id` of element `element`. A player passes it to\n * `model()`, which calls `updateSession(session.id, session.element, { shuffledValues })` to keep\n * the choice order it drew.\n */\nexport type PieUpdateSession = (\n id: string,\n element: string,\n properties: Partial<PieSession>\n) => Promise<void>;\n\n// Controller interface\nexport interface PieController {\n model(\n question: PieModel,\n session: PieSession | null,\n env: PieEnvironment,\n updateSession?: PieUpdateSession\n ): Promise<ViewModel>;\n\n outcome(model: PieModel, session: PieSession, env: PieEnvironment): Promise<OutcomeResult>;\n\n createDefaultModel(partial?: Partial<PieModel>): PieModel;\n\n validate(model: PieModel, config: CommonConfigSettings): ValidationErrors;\n\n createCorrectResponseSession(question: PieModel, env: PieEnvironment): PieSession;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-element/shared-types",
3
- "version": "0.2.0-next.1",
3
+ "version": "0.2.0-next.20261002100925",
4
4
  "description": "Shared TypeScript types for PIE elements",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -17,7 +17,7 @@
17
17
  "scripts": {
18
18
  "build": "rm -rf dist && tsc",
19
19
  "dev": "tsc --watch",
20
- "test": "vitest",
20
+ "test": "vitest run --config vitest.config.ts",
21
21
  "clean": "rm -rf dist"
22
22
  },
23
23
  "publishConfig": {
package/dist/events.d.ts DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * PIE Web Component events
3
- */
4
- export declare class ModelSetEvent extends Event {
5
- model: unknown;
6
- constructor(model: unknown, eventInitDict?: EventInit);
7
- }
8
- export declare class SessionChangedEvent extends Event {
9
- session: unknown;
10
- constructor(session: unknown, eventInitDict?: EventInit);
11
- }
12
- export declare class ModelUpdatedEvent extends Event {
13
- model: unknown;
14
- reset: boolean;
15
- constructor(model: unknown, reset?: boolean, eventInitDict?: EventInit);
16
- }
17
- export declare function isPieEvent(event: Event): event is ModelSetEvent | SessionChangedEvent | ModelUpdatedEvent;
package/dist/events.js DELETED
@@ -1,34 +0,0 @@
1
- /**
2
- * PIE Web Component events
3
- */
4
- // Dispatched when model is set on student view
5
- export class ModelSetEvent extends Event {
6
- model;
7
- constructor(model, eventInitDict) {
8
- super('pie.model_set', eventInitDict);
9
- this.model = model;
10
- }
11
- }
12
- // Dispatched when student changes response
13
- export class SessionChangedEvent extends Event {
14
- session;
15
- constructor(session, eventInitDict) {
16
- super('pie.session_changed', eventInitDict);
17
- this.session = session;
18
- }
19
- }
20
- // Dispatched when author updates configuration
21
- export class ModelUpdatedEvent extends Event {
22
- model;
23
- reset;
24
- constructor(model, reset = false, eventInitDict) {
25
- super('pie.model_updated', eventInitDict);
26
- this.model = model;
27
- this.reset = reset;
28
- }
29
- }
30
- // Type guard for PIE events
31
- export function isPieEvent(event) {
32
- return event.type.startsWith('pie.');
33
- }
34
- //# sourceMappingURL=events.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,+CAA+C;AAC/C,MAAM,OAAO,aAAc,SAAQ,KAAK;IAE7B;IADT,YACS,KAAc,EACrB,aAAyB;QAEzB,KAAK,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;QAH/B,UAAK,GAAL,KAAK,CAAS;IAIvB,CAAC;CACF;AAED,2CAA2C;AAC3C,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAEnC;IADT,YACS,OAAgB,EACvB,aAAyB;QAEzB,KAAK,CAAC,qBAAqB,EAAE,aAAa,CAAC,CAAC;QAHrC,YAAO,GAAP,OAAO,CAAS;IAIzB,CAAC;CACF;AAED,+CAA+C;AAC/C,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAEjC;IACA;IAFT,YACS,KAAc,EACd,QAAQ,KAAK,EACpB,aAAyB;QAEzB,KAAK,CAAC,mBAAmB,EAAE,aAAa,CAAC,CAAC;QAJnC,UAAK,GAAL,KAAK,CAAS;QACd,UAAK,GAAL,KAAK,CAAQ;IAItB,CAAC;CACF;AAED,4BAA4B;AAC5B,MAAM,UAAU,UAAU,CACxB,KAAY;IAEZ,OAAO,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AACvC,CAAC","sourcesContent":["/**\n * PIE Web Component events\n */\n\n// Dispatched when model is set on student view\nexport class ModelSetEvent extends Event {\n constructor(\n public model: unknown,\n eventInitDict?: EventInit\n ) {\n super('pie.model_set', eventInitDict);\n }\n}\n\n// Dispatched when student changes response\nexport class SessionChangedEvent extends Event {\n constructor(\n public session: unknown,\n eventInitDict?: EventInit\n ) {\n super('pie.session_changed', eventInitDict);\n }\n}\n\n// Dispatched when author updates configuration\nexport class ModelUpdatedEvent extends Event {\n constructor(\n public model: unknown,\n public reset = false,\n eventInitDict?: EventInit\n ) {\n super('pie.model_updated', eventInitDict);\n }\n}\n\n// Type guard for PIE events\nexport function isPieEvent(\n event: Event\n): event is ModelSetEvent | SessionChangedEvent | ModelUpdatedEvent {\n return event.type.startsWith('pie.');\n}\n"]}