@pie-qti/default-components 1.0.0-beta.4 → 1.0.0-beta.6
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/README.md +13 -0
- package/dist/chunks/{mathlive.min-Cmxm6f5R.js → mathlive.min-DHkAtaP5.js} +15 -16
- package/dist/chunks/{mathlive.min-Cmxm6f5R.js.map → mathlive.min-DHkAtaP5.js.map} +1 -1
- package/dist/index.js +13 -110
- package/dist/index.js.map +1 -1
- package/dist/plugins/extended-text/textInput.d.ts +47 -0
- package/dist/plugins/extended-text/textInput.js +65 -0
- package/dist/plugins/extended-text/textInput.js.map +1 -0
- package/dist/plugins/media/mediaPlayback.d.ts +39 -0
- package/dist/plugins/media/mediaPlayback.js +49 -0
- package/dist/plugins/media/mediaPlayback.js.map +1 -0
- package/dist/plugins.js +13779 -21944
- package/dist/plugins.js.map +1 -1
- package/dist/shared/components/icons.d.ts +12 -0
- package/dist/shared/components/icons.js +13 -0
- package/dist/shared/components/icons.js.map +1 -0
- package/dist/shared/components/keyboardCrosshair.svelte.d.ts +37 -0
- package/dist/shared/components/keyboardCrosshair.svelte.js +67 -0
- package/dist/shared/components/keyboardCrosshair.svelte.js.map +1 -0
- package/dist/shared/components/pickUpPlace.svelte.d.ts +42 -0
- package/dist/shared/components/pickUpPlace.svelte.js +58 -0
- package/dist/shared/components/pickUpPlace.svelte.js.map +1 -0
- package/dist/shared/extensions/MathLiveEditor.d.ts +33 -6
- package/dist/shared/extensions/MathLiveEditor.js +354 -175
- package/dist/shared/extensions/MathLiveEditor.js.map +1 -1
- package/dist/shared/extensions/modalDialog.d.ts +31 -0
- package/dist/shared/extensions/modalDialog.js +165 -0
- package/dist/shared/extensions/modalDialog.js.map +1 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.js +2 -0
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/styles/qti-pnp.css +44 -0
- package/dist/shared/styles/qti-shared-vocabulary.css +6 -2
- package/dist/shared/styles/srOnly.d.ts +23 -0
- package/dist/shared/styles/srOnly.js +70 -0
- package/dist/shared/styles/srOnly.js.map +1 -0
- package/dist/shared/utils/accessibleText.d.ts +24 -0
- package/dist/shared/utils/accessibleText.js +72 -0
- package/dist/shared/utils/accessibleText.js.map +1 -0
- package/dist/shared/utils/announcer.svelte.d.ts +26 -0
- package/dist/shared/utils/announcer.svelte.js +30 -0
- package/dist/shared/utils/announcer.svelte.js.map +1 -0
- package/dist/shared/utils/capacity.d.ts +26 -0
- package/dist/shared/utils/capacity.js +37 -0
- package/dist/shared/utils/capacity.js.map +1 -0
- package/dist/shared/utils/choiceName.d.ts +44 -0
- package/dist/shared/utils/choiceName.js +28 -0
- package/dist/shared/utils/choiceName.js.map +1 -0
- package/dist/shared/utils/confirmationFlow.svelte.d.ts +31 -0
- package/dist/shared/utils/confirmationFlow.svelte.js +41 -0
- package/dist/shared/utils/confirmationFlow.svelte.js.map +1 -0
- package/dist/shared/utils/eliminationTool.svelte.d.ts +11 -0
- package/dist/shared/utils/eliminationTool.svelte.js +26 -0
- package/dist/shared/utils/eliminationTool.svelte.js.map +1 -0
- package/dist/shared/utils/graphicRegions.d.ts +78 -0
- package/dist/shared/utils/graphicRegions.js +169 -0
- package/dist/shared/utils/graphicRegions.js.map +1 -0
- package/dist/shared/utils/interactionAria.d.ts +18 -5
- package/dist/shared/utils/interactionAria.js +42 -3
- package/dist/shared/utils/interactionAria.js.map +1 -1
- package/dist/shared/utils/interactionProps.d.ts +52 -0
- package/dist/shared/utils/interactionProps.js +14 -0
- package/dist/shared/utils/interactionProps.js.map +1 -0
- package/dist/shared/utils/matchGroupUtils.d.ts +26 -4
- package/dist/shared/utils/matchGroupUtils.js +25 -8
- package/dist/shared/utils/matchGroupUtils.js.map +1 -1
- package/dist/shared/utils/minimumRequirement.d.ts +56 -0
- package/dist/shared/utils/minimumRequirement.js +50 -0
- package/dist/shared/utils/minimumRequirement.js.map +1 -0
- package/dist/shared/utils/pairHelpers.d.ts +46 -12
- package/dist/shared/utils/pairHelpers.js +64 -12
- package/dist/shared/utils/pairHelpers.js.map +1 -1
- package/dist/shared/utils/radioGroup.d.ts +13 -0
- package/dist/shared/utils/radioGroup.js +27 -0
- package/dist/shared/utils/radioGroup.js.map +1 -0
- package/dist/shared/utils/stageImage.svelte.d.ts +56 -0
- package/dist/shared/utils/stageImage.svelte.js +76 -0
- package/dist/shared/utils/stageImage.svelte.js.map +1 -0
- package/dist/shared/utils/webComponentHelpers.d.ts +37 -5
- package/dist/shared/utils/webComponentHelpers.js +72 -19
- package/dist/shared/utils/webComponentHelpers.js.map +1 -1
- package/dist/shared.css +1 -1
- package/package.json +18 -18
- package/dist/chunks/__vite-browser-external-DwKjyYZK.js +0 -9
- package/dist/chunks/__vite-browser-external-DwKjyYZK.js.map +0 -1
- package/dist/chunks/ar-Cqx9S4Im.js +0 -919
- package/dist/chunks/ar-Cqx9S4Im.js.map +0 -1
- package/dist/chunks/es-DjA7IQ-N.js +0 -864
- package/dist/chunks/es-DjA7IQ-N.js.map +0 -1
- package/dist/chunks/fr-BhV6wQNG.js +0 -864
- package/dist/chunks/fr-BhV6wQNG.js.map +0 -1
- package/dist/chunks/nl-B0JlnB-a.js +0 -863
- package/dist/chunks/nl-B0JlnB-a.js.map +0 -1
- package/dist/chunks/ro-ClR0jejm.js +0 -864
- package/dist/chunks/ro-ClR0jejm.js.map +0 -1
- package/dist/chunks/rolldown-runtime-Y_bBpyJl.js +0 -20
- package/dist/chunks/th-RfNMAg5z.js +0 -863
- package/dist/chunks/th-RfNMAg5z.js.map +0 -1
- package/dist/chunks/zh-Hans-DJ82CLmG.js +0 -863
- package/dist/chunks/zh-Hans-DJ82CLmG.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -5,112 +5,18 @@
|
|
|
5
5
|
* These components are packaged as web components that work with the
|
|
6
6
|
* framework-agnostic @pie-qti/item-player core.
|
|
7
7
|
*/
|
|
8
|
+
import { DEFAULT_COMPONENT_TAGS_BY_TYPE } from '@pie-qti/item-player';
|
|
8
9
|
// Export shared utilities and helpers
|
|
9
10
|
export * from './shared/index.js';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
name: 'default-slider',
|
|
18
|
-
description: 'Default Svelte-based slider interaction',
|
|
19
|
-
tagName: 'pie-qti-slider',
|
|
20
|
-
},
|
|
21
|
-
orderInteraction: {
|
|
22
|
-
name: 'default-order',
|
|
23
|
-
description: 'Default Svelte-based order interaction',
|
|
24
|
-
tagName: 'pie-qti-order',
|
|
25
|
-
},
|
|
26
|
-
matchInteraction: {
|
|
27
|
-
name: 'default-match',
|
|
28
|
-
description: 'Default Svelte-based match interaction',
|
|
29
|
-
tagName: 'pie-qti-match',
|
|
30
|
-
},
|
|
31
|
-
associateInteraction: {
|
|
32
|
-
name: 'default-associate',
|
|
33
|
-
description: 'Default Svelte-based associate interaction',
|
|
34
|
-
tagName: 'pie-qti-associate',
|
|
35
|
-
},
|
|
36
|
-
gapMatchInteraction: {
|
|
37
|
-
name: 'default-gap-match',
|
|
38
|
-
description: 'Default Svelte-based gap match interaction',
|
|
39
|
-
tagName: 'pie-qti-gap-match',
|
|
40
|
-
},
|
|
41
|
-
hotspotInteraction: {
|
|
42
|
-
name: 'default-hotspot',
|
|
43
|
-
description: 'Default Svelte-based hotspot interaction',
|
|
44
|
-
tagName: 'pie-qti-hotspot',
|
|
45
|
-
},
|
|
46
|
-
hottextInteraction: {
|
|
47
|
-
name: 'default-hottext',
|
|
48
|
-
description: 'Default Svelte-based hottext interaction',
|
|
49
|
-
tagName: 'pie-qti-hottext',
|
|
50
|
-
},
|
|
51
|
-
mediaInteraction: {
|
|
52
|
-
name: 'default-media',
|
|
53
|
-
description: 'Default Svelte-based media interaction',
|
|
54
|
-
tagName: 'pie-qti-media',
|
|
55
|
-
},
|
|
56
|
-
customInteraction: {
|
|
57
|
-
name: 'default-custom',
|
|
58
|
-
description: 'Default Svelte-based custom interaction',
|
|
59
|
-
tagName: 'pie-qti-custom',
|
|
60
|
-
},
|
|
61
|
-
portableCustomInteraction: {
|
|
62
|
-
name: 'default-portable-custom',
|
|
63
|
-
description: 'Default Portable Custom Interaction host',
|
|
64
|
-
tagName: 'pie-qti-portable-custom',
|
|
65
|
-
},
|
|
66
|
-
endAttemptInteraction: {
|
|
67
|
-
name: 'default-end-attempt',
|
|
68
|
-
description: 'Default Svelte-based end attempt interaction',
|
|
69
|
-
tagName: 'pie-qti-end-attempt',
|
|
70
|
-
},
|
|
71
|
-
positionObjectInteraction: {
|
|
72
|
-
name: 'default-position-object',
|
|
73
|
-
description: 'Default Svelte-based position object interaction',
|
|
74
|
-
tagName: 'pie-qti-position-object',
|
|
75
|
-
},
|
|
76
|
-
graphicGapMatchInteraction: {
|
|
77
|
-
name: 'default-graphic-gap-match',
|
|
78
|
-
description: 'Default Svelte-based graphic gap match interaction',
|
|
79
|
-
tagName: 'pie-qti-graphic-gap-match',
|
|
80
|
-
},
|
|
81
|
-
graphicOrderInteraction: {
|
|
82
|
-
name: 'default-graphic-order',
|
|
83
|
-
description: 'Default Svelte-based graphic order interaction',
|
|
84
|
-
tagName: 'pie-qti-graphic-order',
|
|
85
|
-
},
|
|
86
|
-
graphicAssociateInteraction: {
|
|
87
|
-
name: 'default-graphic-associate',
|
|
88
|
-
description: 'Default Svelte-based graphic associate interaction',
|
|
89
|
-
tagName: 'pie-qti-graphic-associate',
|
|
90
|
-
},
|
|
91
|
-
selectPointInteraction: {
|
|
92
|
-
name: 'default-select-point',
|
|
93
|
-
description: 'Default Svelte-based select point interaction',
|
|
94
|
-
tagName: 'pie-qti-select-point',
|
|
95
|
-
},
|
|
96
|
-
extendedTextInteraction: {
|
|
97
|
-
name: 'default-extended-text',
|
|
98
|
-
description: 'Default Svelte-based extended text interaction',
|
|
99
|
-
tagName: 'pie-qti-extended-text',
|
|
100
|
-
},
|
|
101
|
-
uploadInteraction: {
|
|
102
|
-
name: 'default-upload',
|
|
103
|
-
description: 'Default Svelte-based upload interaction',
|
|
104
|
-
tagName: 'pie-qti-upload',
|
|
105
|
-
},
|
|
106
|
-
drawingInteraction: {
|
|
107
|
-
name: 'default-drawing',
|
|
108
|
-
description: 'Default Svelte-based drawing interaction',
|
|
109
|
-
tagName: 'pie-qti-drawing',
|
|
110
|
-
},
|
|
111
|
-
};
|
|
11
|
+
/**
|
|
12
|
+
* The interaction components this package ships, by QTI interaction type: item-player's
|
|
13
|
+
* default tags without `catalogPopup`, which is not an interaction and registers on its own.
|
|
14
|
+
*/
|
|
15
|
+
function defaultInteractionTags() {
|
|
16
|
+
return Object.entries(DEFAULT_COMPONENT_TAGS_BY_TYPE).filter(([type]) => type !== 'catalogPopup');
|
|
17
|
+
}
|
|
112
18
|
export function getDefaultComponentTypes() {
|
|
113
|
-
return
|
|
19
|
+
return defaultInteractionTags().map(([type]) => type);
|
|
114
20
|
}
|
|
115
21
|
/**
|
|
116
22
|
* Register all default components with the ComponentRegistry.
|
|
@@ -120,13 +26,10 @@ export function getDefaultComponentTypes() {
|
|
|
120
26
|
* rendered in-flow by @pie-qti/item-player.
|
|
121
27
|
*/
|
|
122
28
|
export function registerDefaultComponents(registry) {
|
|
123
|
-
for (const [type,
|
|
124
|
-
registry.register(type, component);
|
|
29
|
+
for (const [type, { name, tagName }] of defaultInteractionTags()) {
|
|
30
|
+
registry.register(type, { name, description: `Default Svelte-based component for ${type}`, tagName });
|
|
125
31
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
description: 'Default Svelte-based catalog popup dialog',
|
|
129
|
-
tagName: 'pie-qti-catalog-popup',
|
|
130
|
-
});
|
|
32
|
+
const { name, tagName } = DEFAULT_COMPONENT_TAGS_BY_TYPE.catalogPopup;
|
|
33
|
+
registry.register('catalogPopup', { name, description: 'Default Svelte-based catalog popup dialog', tagName });
|
|
131
34
|
}
|
|
132
35
|
//# 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;;;;;;GAMG;AAEH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AAEtE,sCAAsC;AACtC,cAAc,mBAAmB,CAAC;AAYlC;;;GAGG;AACH,SAAS,sBAAsB;IAC9B,OAAO,MAAM,CAAC,OAAO,CAAC,8BAA8B,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC;AACnG,CAAC;AAED,MAAM,UAAU,wBAAwB;IACvC,OAAO,sBAAsB,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB,CAAC,QAAkC;IAC3E,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,sBAAsB,EAAE,EAAE,CAAC;QAClE,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,sCAAsC,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IACvG,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,8BAA8B,CAAC,YAAY,CAAC;IACtE,QAAQ,CAAC,QAAQ,CAAC,cAAc,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,2CAA2C,EAAE,OAAO,EAAE,CAAC,CAAC;AAChH,CAAC","sourcesContent":["/**\n * @pie-qti/default-components\n *\n * Default Svelte-based component implementations for the QTI player.\n * These components are packaged as web components that work with the\n * framework-agnostic @pie-qti/item-player core.\n */\n\nimport { DEFAULT_COMPONENT_TAGS_BY_TYPE } from '@pie-qti/item-player';\n\n// Export shared utilities and helpers\nexport * from './shared/index.js';\n\ninterface DefaultComponentRegistration {\n\tname: string;\n\tdescription: string;\n\ttagName: string;\n}\n\ninterface DefaultComponentRegistry {\n\tregister(type: string, component: DefaultComponentRegistration): void;\n}\n\n/**\n * The interaction components this package ships, by QTI interaction type: item-player's\n * default tags without `catalogPopup`, which is not an interaction and registers on its own.\n */\nfunction defaultInteractionTags() {\n\treturn Object.entries(DEFAULT_COMPONENT_TAGS_BY_TYPE).filter(([type]) => type !== 'catalogPopup');\n}\n\nexport function getDefaultComponentTypes(): string[] {\n\treturn defaultInteractionTags().map(([type]) => type);\n}\n\n/**\n * Register all default components with the ComponentRegistry.\n *\n * This function should be called once at application startup to make all default\n * block interaction components available to the player. Inline interactions are\n * rendered in-flow by @pie-qti/item-player.\n */\nexport function registerDefaultComponents(registry: DefaultComponentRegistry): void {\n\tfor (const [type, { name, tagName }] of defaultInteractionTags()) {\n\t\tregistry.register(type, { name, description: `Default Svelte-based component for ${type}`, tagName });\n\t}\n\n\tconst { name, tagName } = DEFAULT_COMPONENT_TAGS_BY_TYPE.catalogPopup;\n\tregistry.register('catalogPopup', { name, description: 'Default Svelte-based catalog popup dialog', tagName });\n}\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ExtendedTextInteractionData } from '@pie-qti/item-player';
|
|
2
|
+
import { type I18nProvider } from '@pie-qti/i18n';
|
|
3
|
+
/**
|
|
4
|
+
* Text-field helpers for the extended text interaction: writing assistance,
|
|
5
|
+
* the mobile keyboard, and the character count behind the QTI counters.
|
|
6
|
+
*/
|
|
7
|
+
/** Whether a `spellcheck` prop grants spelling help: `true`, `"true"`, or the bare attribute. */
|
|
8
|
+
export declare function isSpellcheckAllowed(value: unknown): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Writing-assistance attributes for a candidate's text field. Spell check and
|
|
11
|
+
* autocorrect follow the grant, so spelling and writing items give every
|
|
12
|
+
* candidate the same help; automatic capitalization stays off either way,
|
|
13
|
+
* since capitalization is itself assessed in writing.
|
|
14
|
+
*/
|
|
15
|
+
export interface WritingAssistanceAttributes {
|
|
16
|
+
spellcheck: 'true' | 'false';
|
|
17
|
+
autocorrect: 'on' | 'off';
|
|
18
|
+
autocapitalize: 'off';
|
|
19
|
+
}
|
|
20
|
+
export declare function writingAssistance(allowSpellcheck: boolean): WritingAssistanceAttributes;
|
|
21
|
+
/**
|
|
22
|
+
* The virtual keyboard a numeric response needs: digits for an integer, digits
|
|
23
|
+
* and a decimal separator for a float or a numeric record. A base above 10
|
|
24
|
+
* writes digits as letters, so it keeps the text keyboard (`undefined`).
|
|
25
|
+
*
|
|
26
|
+
* A numeric keyboard is only safe when the authored patternMask proves the
|
|
27
|
+
* answer cannot be negative: phone number pads offer no minus key (nor an
|
|
28
|
+
* exponent), so every other response keeps the default text keyboard. The
|
|
29
|
+
* pattern scan is the item player's `patternExcludesMinus`, re-exported here
|
|
30
|
+
* because this interaction owns the extended-text keyboard rules.
|
|
31
|
+
*/
|
|
32
|
+
export { patternExcludesMinus } from '@pie-qti/item-player';
|
|
33
|
+
export declare function responseInputMode(interaction: Pick<ExtendedTextInteractionData, 'baseType' | 'base' | 'cardinality' | 'patternMask'>): 'numeric' | 'decimal' | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* The characters a candidate typed, as the counters show them: rich text
|
|
36
|
+
* (`xhtml`) counts its text without markup, an entity counts as one character,
|
|
37
|
+
* and a character outside the Basic Multilingual Plane counts once.
|
|
38
|
+
*/
|
|
39
|
+
export declare function characterCount(value: string, format: string): number;
|
|
40
|
+
/** Whether an edit took the count from below `expectedLength` to at or above it. */
|
|
41
|
+
export declare function reachedExpectedLength(before: number, after: number, expectedLength: number): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* The message for a response that does not match the interaction's pattern mask: the author's
|
|
44
|
+
* own message when there is one, else a localized sentence. The mask itself is an XSD regular
|
|
45
|
+
* expression, which no candidate can be expected to read, so it is never shown.
|
|
46
|
+
*/
|
|
47
|
+
export declare function patternMaskMessage(i18n: I18nProvider | undefined, interaction: Pick<ExtendedTextInteractionData, 'patternMaskMessage'>): string;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { patternExcludesMinus } from '@pie-qti/item-player';
|
|
2
|
+
import { translate } from '@pie-qti/i18n';
|
|
3
|
+
/**
|
|
4
|
+
* Text-field helpers for the extended text interaction: writing assistance,
|
|
5
|
+
* the mobile keyboard, and the character count behind the QTI counters.
|
|
6
|
+
*/
|
|
7
|
+
/** Whether a `spellcheck` prop grants spelling help: `true`, `"true"`, or the bare attribute. */
|
|
8
|
+
export function isSpellcheckAllowed(value) {
|
|
9
|
+
if (value === true || value === '')
|
|
10
|
+
return true;
|
|
11
|
+
return typeof value === 'string' && value.trim().toLowerCase() === 'true';
|
|
12
|
+
}
|
|
13
|
+
export function writingAssistance(allowSpellcheck) {
|
|
14
|
+
return {
|
|
15
|
+
spellcheck: allowSpellcheck ? 'true' : 'false',
|
|
16
|
+
autocorrect: allowSpellcheck ? 'on' : 'off',
|
|
17
|
+
autocapitalize: 'off',
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The virtual keyboard a numeric response needs: digits for an integer, digits
|
|
22
|
+
* and a decimal separator for a float or a numeric record. A base above 10
|
|
23
|
+
* writes digits as letters, so it keeps the text keyboard (`undefined`).
|
|
24
|
+
*
|
|
25
|
+
* A numeric keyboard is only safe when the authored patternMask proves the
|
|
26
|
+
* answer cannot be negative: phone number pads offer no minus key (nor an
|
|
27
|
+
* exponent), so every other response keeps the default text keyboard. The
|
|
28
|
+
* pattern scan is the item player's `patternExcludesMinus`, re-exported here
|
|
29
|
+
* because this interaction owns the extended-text keyboard rules.
|
|
30
|
+
*/
|
|
31
|
+
export { patternExcludesMinus } from '@pie-qti/item-player';
|
|
32
|
+
export function responseInputMode(interaction) {
|
|
33
|
+
if (Number.isFinite(interaction.base) && interaction.base > 10)
|
|
34
|
+
return undefined;
|
|
35
|
+
if (interaction.baseType !== 'integer' && interaction.baseType !== 'float' && interaction.cardinality !== 'record') {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
if (!interaction.patternMask || !patternExcludesMinus(interaction.patternMask))
|
|
39
|
+
return undefined;
|
|
40
|
+
return interaction.baseType === 'float' || interaction.cardinality === 'record' ? 'decimal' : 'numeric';
|
|
41
|
+
}
|
|
42
|
+
const HTML_ENTITY = /&(?:#\d+|#x[0-9a-f]+|[a-z][a-z0-9]*);/gi;
|
|
43
|
+
/**
|
|
44
|
+
* The characters a candidate typed, as the counters show them: rich text
|
|
45
|
+
* (`xhtml`) counts its text without markup, an entity counts as one character,
|
|
46
|
+
* and a character outside the Basic Multilingual Plane counts once.
|
|
47
|
+
*/
|
|
48
|
+
export function characterCount(value, format) {
|
|
49
|
+
const text = format === 'xhtml' ? value.replace(/<[^>]*>/g, '').replace(HTML_ENTITY, '_') : value;
|
|
50
|
+
return Array.from(text).length;
|
|
51
|
+
}
|
|
52
|
+
/** Whether an edit took the count from below `expectedLength` to at or above it. */
|
|
53
|
+
export function reachedExpectedLength(before, after, expectedLength) {
|
|
54
|
+
return expectedLength > 0 && before < expectedLength && after >= expectedLength;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The message for a response that does not match the interaction's pattern mask: the author's
|
|
58
|
+
* own message when there is one, else a localized sentence. The mask itself is an XSD regular
|
|
59
|
+
* expression, which no candidate can be expected to read, so it is never shown.
|
|
60
|
+
*/
|
|
61
|
+
export function patternMaskMessage(i18n, interaction) {
|
|
62
|
+
return (interaction.patternMaskMessage?.trim() ||
|
|
63
|
+
translate(i18n, 'interactions.extendedText.patternMismatch', 'This answer is not in the expected format.'));
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=textInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textInput.js","sourceRoot":"","sources":["../../../src/plugins/extended-text/textInput.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAqB,MAAM,eAAe,CAAC;AAE7D;;;GAGG;AAEH,iGAAiG;AACjG,MAAM,UAAU,mBAAmB,CAAC,KAAc;IACjD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC;IAChD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC;AAC3E,CAAC;AAcD,MAAM,UAAU,iBAAiB,CAAC,eAAwB;IACzD,OAAO;QACN,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;QAC9C,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK;QAC3C,cAAc,EAAE,KAAK;KACrB,CAAC;AACH,CAAC;AAED;;;;;;;;;;GAUG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,MAAM,UAAU,iBAAiB,CAChC,WAAmG;IAEnG,IAAI,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,IAAI,GAAG,EAAE;QAAE,OAAO,SAAS,CAAC;IACjF,IAAI,WAAW,CAAC,QAAQ,KAAK,SAAS,IAAI,WAAW,CAAC,QAAQ,KAAK,OAAO,IAAI,WAAW,CAAC,WAAW,KAAK,QAAQ,EAAE,CAAC;QACpH,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,IAAI,CAAC,WAAW,CAAC,WAAW,IAAI,CAAC,oBAAoB,CAAC,WAAW,CAAC,WAAW,CAAC;QAAE,OAAO,SAAS,CAAC;IACjG,OAAO,WAAW,CAAC,QAAQ,KAAK,OAAO,IAAI,WAAW,CAAC,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AACzG,CAAC;AAED,MAAM,WAAW,GAAG,yCAAyC,CAAC;AAE9D;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa,EAAE,MAAc;IAC3D,MAAM,IAAI,GAAG,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAClG,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;AAChC,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,qBAAqB,CAAC,MAAc,EAAE,KAAa,EAAE,cAAsB;IAC1F,OAAO,cAAc,GAAG,CAAC,IAAI,MAAM,GAAG,cAAc,IAAI,KAAK,IAAI,cAAc,CAAC;AACjF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CACjC,IAA8B,EAC9B,WAAoE;IAEpE,OAAO,CACN,WAAW,CAAC,kBAAkB,EAAE,IAAI,EAAE;QACtC,SAAS,CAAC,IAAI,EAAE,2CAA2C,EAAE,4CAA4C,CAAC,CAC1G,CAAC;AACH,CAAC","sourcesContent":["import type { ExtendedTextInteractionData } from '@pie-qti/item-player';\nimport { patternExcludesMinus } from '@pie-qti/item-player';\nimport { translate, type I18nProvider } from '@pie-qti/i18n';\n\n/**\n * Text-field helpers for the extended text interaction: writing assistance,\n * the mobile keyboard, and the character count behind the QTI counters.\n */\n\n/** Whether a `spellcheck` prop grants spelling help: `true`, `\"true\"`, or the bare attribute. */\nexport function isSpellcheckAllowed(value: unknown): boolean {\n\tif (value === true || value === '') return true;\n\treturn typeof value === 'string' && value.trim().toLowerCase() === 'true';\n}\n\n/**\n * Writing-assistance attributes for a candidate's text field. Spell check and\n * autocorrect follow the grant, so spelling and writing items give every\n * candidate the same help; automatic capitalization stays off either way,\n * since capitalization is itself assessed in writing.\n */\nexport interface WritingAssistanceAttributes {\n\tspellcheck: 'true' | 'false';\n\tautocorrect: 'on' | 'off';\n\tautocapitalize: 'off';\n}\n\nexport function writingAssistance(allowSpellcheck: boolean): WritingAssistanceAttributes {\n\treturn {\n\t\tspellcheck: allowSpellcheck ? 'true' : 'false',\n\t\tautocorrect: allowSpellcheck ? 'on' : 'off',\n\t\tautocapitalize: 'off',\n\t};\n}\n\n/**\n * The virtual keyboard a numeric response needs: digits for an integer, digits\n * and a decimal separator for a float or a numeric record. A base above 10\n * writes digits as letters, so it keeps the text keyboard (`undefined`).\n *\n * A numeric keyboard is only safe when the authored patternMask proves the\n * answer cannot be negative: phone number pads offer no minus key (nor an\n * exponent), so every other response keeps the default text keyboard. The\n * pattern scan is the item player's `patternExcludesMinus`, re-exported here\n * because this interaction owns the extended-text keyboard rules.\n */\nexport { patternExcludesMinus } from '@pie-qti/item-player';\n\nexport function responseInputMode(\n\tinteraction: Pick<ExtendedTextInteractionData, 'baseType' | 'base' | 'cardinality' | 'patternMask'>,\n): 'numeric' | 'decimal' | undefined {\n\tif (Number.isFinite(interaction.base) && interaction.base > 10) return undefined;\n\tif (interaction.baseType !== 'integer' && interaction.baseType !== 'float' && interaction.cardinality !== 'record') {\n\t\treturn undefined;\n\t}\n\tif (!interaction.patternMask || !patternExcludesMinus(interaction.patternMask)) return undefined;\n\treturn interaction.baseType === 'float' || interaction.cardinality === 'record' ? 'decimal' : 'numeric';\n}\n\nconst HTML_ENTITY = /&(?:#\\d+|#x[0-9a-f]+|[a-z][a-z0-9]*);/gi;\n\n/**\n * The characters a candidate typed, as the counters show them: rich text\n * (`xhtml`) counts its text without markup, an entity counts as one character,\n * and a character outside the Basic Multilingual Plane counts once.\n */\nexport function characterCount(value: string, format: string): number {\n\tconst text = format === 'xhtml' ? value.replace(/<[^>]*>/g, '').replace(HTML_ENTITY, '_') : value;\n\treturn Array.from(text).length;\n}\n\n/** Whether an edit took the count from below `expectedLength` to at or above it. */\nexport function reachedExpectedLength(before: number, after: number, expectedLength: number): boolean {\n\treturn expectedLength > 0 && before < expectedLength && after >= expectedLength;\n}\n\n/**\n * The message for a response that does not match the interaction's pattern mask: the author's\n * own message when there is one, else a localized sentence. The mask itself is an XSD regular\n * expression, which no candidate can be expected to read, so it is never shown.\n */\nexport function patternMaskMessage(\n\ti18n: I18nProvider | undefined,\n\tinteraction: Pick<ExtendedTextInteractionData, 'patternMaskMessage'>,\n): string {\n\treturn (\n\t\tinteraction.patternMaskMessage?.trim() ||\n\t\ttranslate(i18n, 'interactions.extendedText.patternMismatch', 'This answer is not in the expected format.')\n\t);\n}\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { MediaElement, MediaElementSource, MediaElementTrack } from '@pie-qti/item-player';
|
|
2
|
+
/**
|
|
3
|
+
* Playback helpers for the media interaction.
|
|
4
|
+
*
|
|
5
|
+
* A *play* starts when playback begins at the start of the media: the first
|
|
6
|
+
* time, after the media has ended, or after a paused player was returned to the
|
|
7
|
+
* beginning. It counts once the media is actually playing (the `playing` event),
|
|
8
|
+
* so a source that fails to load costs nothing. Pausing and resuming within a
|
|
9
|
+
* play does not start a new one. The play count (the interaction's response)
|
|
10
|
+
* counts plays started, so `maxPlays` bounds how many times the media can be
|
|
11
|
+
* heard, however each play ends.
|
|
12
|
+
*/
|
|
13
|
+
/** A text track the candidate can switch on: a caption or subtitle track and its position. */
|
|
14
|
+
export interface SelectableTextTrack {
|
|
15
|
+
/** Position among the rendered `<track>` elements, which is the `textTracks` index. */
|
|
16
|
+
index: number;
|
|
17
|
+
track: MediaElementTrack;
|
|
18
|
+
}
|
|
19
|
+
/** A play count from a response value: a non-negative integer, else 0. */
|
|
20
|
+
export declare function normalizePlayCount(value: unknown): number;
|
|
21
|
+
/** A play limit from interaction data: a positive integer, or 0 for unlimited. */
|
|
22
|
+
export declare function normalizePlayLimit(value: unknown): number;
|
|
23
|
+
/** Whether another play may start under `maxPlays`: only a positive limit restricts, so 0 and a non-numeric limit are unlimited. */
|
|
24
|
+
export declare function canStartPlay(playCount: number, maxPlays: number): boolean;
|
|
25
|
+
/** Plays still available under `maxPlays`; `null` when plays are unlimited. */
|
|
26
|
+
export declare function playsLeft(playCount: number, maxPlays: number): number | null;
|
|
27
|
+
/**
|
|
28
|
+
* The sources to render, in document order. A URL the delivery policy blocked
|
|
29
|
+
* arrives empty and is dropped; data built without `sources` falls back to `src`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function playableSources(media: MediaElement): MediaElementSource[];
|
|
32
|
+
/** The text tracks to render, in document order, without tracks whose URL was blocked. */
|
|
33
|
+
export declare function renderableTracks(media: MediaElement): MediaElementTrack[];
|
|
34
|
+
/** The caption and subtitle tracks among `tracks`, which a candidate can turn on. */
|
|
35
|
+
export declare function selectableTextTracks(tracks: readonly MediaElementTrack[]): SelectableTextTrack[];
|
|
36
|
+
/** The selectable track a browser shows by default (the first marked `default`), or `null`. */
|
|
37
|
+
export declare function defaultTextTrackIndex(tracks: readonly SelectableTextTrack[]): number | null;
|
|
38
|
+
/** A media time as `m:ss` (or `h:mm:ss`); `--:--` while the duration is unknown. */
|
|
39
|
+
export declare function formatPlaybackTime(seconds: number): string;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { isAtLimit } from '../../shared/utils/capacity';
|
|
2
|
+
/** A play count from a response value: a non-negative integer, else 0. */
|
|
3
|
+
export function normalizePlayCount(value) {
|
|
4
|
+
const count = typeof value === 'string' && value.trim() !== '' ? Number(value) : value;
|
|
5
|
+
return typeof count === 'number' && Number.isFinite(count) && count > 0 ? Math.floor(count) : 0;
|
|
6
|
+
}
|
|
7
|
+
/** A play limit from interaction data: a positive integer, or 0 for unlimited. */
|
|
8
|
+
export function normalizePlayLimit(value) {
|
|
9
|
+
return typeof value === 'number' && Number.isFinite(value) && value > 0 ? Math.floor(value) : 0;
|
|
10
|
+
}
|
|
11
|
+
/** Whether another play may start under `maxPlays`: only a positive limit restricts, so 0 and a non-numeric limit are unlimited. */
|
|
12
|
+
export function canStartPlay(playCount, maxPlays) {
|
|
13
|
+
return !isAtLimit(playCount, maxPlays);
|
|
14
|
+
}
|
|
15
|
+
/** Plays still available under `maxPlays`; `null` when plays are unlimited. */
|
|
16
|
+
export function playsLeft(playCount, maxPlays) {
|
|
17
|
+
return maxPlays > 0 ? Math.max(0, maxPlays - playCount) : null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The sources to render, in document order. A URL the delivery policy blocked
|
|
21
|
+
* arrives empty and is dropped; data built without `sources` falls back to `src`.
|
|
22
|
+
*/
|
|
23
|
+
export function playableSources(media) {
|
|
24
|
+
const sources = media.sources ?? [{ src: media.src, mimeType: media.mimeType }];
|
|
25
|
+
return sources.filter((source) => typeof source.src === 'string' && source.src !== '');
|
|
26
|
+
}
|
|
27
|
+
/** The text tracks to render, in document order, without tracks whose URL was blocked. */
|
|
28
|
+
export function renderableTracks(media) {
|
|
29
|
+
return (media.tracks ?? []).filter((track) => typeof track.src === 'string' && track.src !== '');
|
|
30
|
+
}
|
|
31
|
+
/** The caption and subtitle tracks among `tracks`, which a candidate can turn on. */
|
|
32
|
+
export function selectableTextTracks(tracks) {
|
|
33
|
+
return tracks.flatMap((track, index) => track.kind === 'captions' || track.kind === 'subtitles' ? [{ index, track }] : []);
|
|
34
|
+
}
|
|
35
|
+
/** The selectable track a browser shows by default (the first marked `default`), or `null`. */
|
|
36
|
+
export function defaultTextTrackIndex(tracks) {
|
|
37
|
+
return tracks.find((entry) => entry.track.default)?.index ?? null;
|
|
38
|
+
}
|
|
39
|
+
/** A media time as `m:ss` (or `h:mm:ss`); `--:--` while the duration is unknown. */
|
|
40
|
+
export function formatPlaybackTime(seconds) {
|
|
41
|
+
if (!Number.isFinite(seconds) || seconds < 0)
|
|
42
|
+
return '--:--';
|
|
43
|
+
const whole = Math.floor(seconds);
|
|
44
|
+
const hours = Math.floor(whole / 3600);
|
|
45
|
+
const minutes = Math.floor((whole % 3600) / 60);
|
|
46
|
+
const secs = String(whole % 60).padStart(2, '0');
|
|
47
|
+
return hours > 0 ? `${hours}:${String(minutes).padStart(2, '0')}:${secs}` : `${minutes}:${secs}`;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=mediaPlayback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mediaPlayback.js","sourceRoot":"","sources":["../../../src/plugins/media/mediaPlayback.ts"],"names":[],"mappings":"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","sourcesContent":["import type { MediaElement, MediaElementSource, MediaElementTrack } from '@pie-qti/item-player';\nimport { isAtLimit } from '../../shared/utils/capacity';\n\n/**\n * Playback helpers for the media interaction.\n *\n * A *play* starts when playback begins at the start of the media: the first\n * time, after the media has ended, or after a paused player was returned to the\n * beginning. It counts once the media is actually playing (the `playing` event),\n * so a source that fails to load costs nothing. Pausing and resuming within a\n * play does not start a new one. The play count (the interaction's response)\n * counts plays started, so `maxPlays` bounds how many times the media can be\n * heard, however each play ends.\n */\n\n/** A text track the candidate can switch on: a caption or subtitle track and its position. */\nexport interface SelectableTextTrack {\n\t/** Position among the rendered `<track>` elements, which is the `textTracks` index. */\n\tindex: number;\n\ttrack: MediaElementTrack;\n}\n\n/** A play count from a response value: a non-negative integer, else 0. */\nexport function normalizePlayCount(value: unknown): number {\n\tconst count = typeof value === 'string' && value.trim() !== '' ? Number(value) : value;\n\treturn typeof count === 'number' && Number.isFinite(count) && count > 0 ? Math.floor(count) : 0;\n}\n\n/** A play limit from interaction data: a positive integer, or 0 for unlimited. */\nexport function normalizePlayLimit(value: unknown): number {\n\treturn typeof value === 'number' && Number.isFinite(value) && value > 0 ? Math.floor(value) : 0;\n}\n\n/** Whether another play may start under `maxPlays`: only a positive limit restricts, so 0 and a non-numeric limit are unlimited. */\nexport function canStartPlay(playCount: number, maxPlays: number): boolean {\n\treturn !isAtLimit(playCount, maxPlays);\n}\n\n/** Plays still available under `maxPlays`; `null` when plays are unlimited. */\nexport function playsLeft(playCount: number, maxPlays: number): number | null {\n\treturn maxPlays > 0 ? Math.max(0, maxPlays - playCount) : null;\n}\n\n/**\n * The sources to render, in document order. A URL the delivery policy blocked\n * arrives empty and is dropped; data built without `sources` falls back to `src`.\n */\nexport function playableSources(media: MediaElement): MediaElementSource[] {\n\tconst sources = media.sources ?? [{ src: media.src, mimeType: media.mimeType }];\n\treturn sources.filter((source) => typeof source.src === 'string' && source.src !== '');\n}\n\n/** The text tracks to render, in document order, without tracks whose URL was blocked. */\nexport function renderableTracks(media: MediaElement): MediaElementTrack[] {\n\treturn (media.tracks ?? []).filter((track) => typeof track.src === 'string' && track.src !== '');\n}\n\n/** The caption and subtitle tracks among `tracks`, which a candidate can turn on. */\nexport function selectableTextTracks(tracks: readonly MediaElementTrack[]): SelectableTextTrack[] {\n\treturn tracks.flatMap((track, index) =>\n\t\ttrack.kind === 'captions' || track.kind === 'subtitles' ? [{ index, track }] : [],\n\t);\n}\n\n/** The selectable track a browser shows by default (the first marked `default`), or `null`. */\nexport function defaultTextTrackIndex(tracks: readonly SelectableTextTrack[]): number | null {\n\treturn tracks.find((entry) => entry.track.default)?.index ?? null;\n}\n\n/** A media time as `m:ss` (or `h:mm:ss`); `--:--` while the duration is unknown. */\nexport function formatPlaybackTime(seconds: number): string {\n\tif (!Number.isFinite(seconds) || seconds < 0) return '--:--';\n\tconst whole = Math.floor(seconds);\n\tconst hours = Math.floor(whole / 3600);\n\tconst minutes = Math.floor((whole % 3600) / 60);\n\tconst secs = String(whole % 60).padStart(2, '0');\n\treturn hours > 0 ? `${hours}:${String(minutes).padStart(2, '0')}:${secs}` : `${minutes}:${secs}`;\n}\n"]}
|