@qti-components/elements 1.3.0
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/LICENSE.md +674 -0
- package/dist/components/qti-assessment-item/qti-assessment-item.d.ts +91 -0
- package/dist/components/qti-assessment-item/qti-assessment-item.js +427 -0
- package/dist/components/qti-assessment-item/qti-assessment-item.js.map +1 -0
- package/dist/components/qti-assessment-stimulus-ref/qti-assessment-stimulus-ref.d.ts +31 -0
- package/dist/components/qti-assessment-stimulus-ref/qti-assessment-stimulus-ref.js +70 -0
- package/dist/components/qti-assessment-stimulus-ref/qti-assessment-stimulus-ref.js.map +1 -0
- package/dist/components/qti-companion-materials-info/qti-companion-materials-info.d.ts +8 -0
- package/dist/components/qti-companion-materials-info/qti-companion-materials-info.js +15 -0
- package/dist/components/qti-companion-materials-info/qti-companion-materials-info.js.map +1 -0
- package/dist/components/qti-content-body/qti-content-body.d.ts +9 -0
- package/dist/components/qti-content-body/qti-content-body.js +18 -0
- package/dist/components/qti-content-body/qti-content-body.js.map +1 -0
- package/dist/components/qti-context-declaration/qti-context-declaration.d.ts +16 -0
- package/dist/components/qti-context-declaration/qti-context-declaration.js +40 -0
- package/dist/components/qti-context-declaration/qti-context-declaration.js.map +1 -0
- package/dist/components/qti-custom-operator/qti-custom-operator.d.ts +25 -0
- package/dist/components/qti-custom-operator/qti-custom-operator.js +78 -0
- package/dist/components/qti-custom-operator/qti-custom-operator.js.map +1 -0
- package/dist/components/qti-feedback-block/qti-feedback-block.d.ts +11 -0
- package/dist/components/qti-feedback-block/qti-feedback-block.js +34 -0
- package/dist/components/qti-feedback-block/qti-feedback-block.js.map +1 -0
- package/dist/components/qti-feedback-inline/qti-feedback-inline.d.ts +11 -0
- package/dist/components/qti-feedback-inline/qti-feedback-inline.js +33 -0
- package/dist/components/qti-feedback-inline/qti-feedback-inline.js.map +1 -0
- package/dist/components/qti-item-body/qti-item-body.d.ts +21 -0
- package/dist/components/qti-item-body/qti-item-body.js +30 -0
- package/dist/components/qti-item-body/qti-item-body.js.map +1 -0
- package/dist/components/qti-item-body/qti-item-body.styles.d.ts +2 -0
- package/dist/components/qti-item-body/qti-item-body.styles.js +7 -0
- package/dist/components/qti-item-body/qti-item-body.styles.js.map +1 -0
- package/dist/components/qti-modal-feedback/qti-modal-feedback.d.ts +14 -0
- package/dist/components/qti-modal-feedback/qti-modal-feedback.js +95 -0
- package/dist/components/qti-modal-feedback/qti-modal-feedback.js.map +1 -0
- package/dist/components/qti-outcome-declaration/qti-outcome-declaration.d.ts +19 -0
- package/dist/components/qti-outcome-declaration/qti-outcome-declaration.js +95 -0
- package/dist/components/qti-outcome-declaration/qti-outcome-declaration.js.map +1 -0
- package/dist/components/qti-response-declaration/qti-response-declaration.d.ts +18 -0
- package/dist/components/qti-response-declaration/qti-response-declaration.js +117 -0
- package/dist/components/qti-response-declaration/qti-response-declaration.js.map +1 -0
- package/dist/components/qti-response-processing/qti-response-processing.d.ts +14 -0
- package/dist/components/qti-response-processing/qti-response-processing.js +58 -0
- package/dist/components/qti-response-processing/qti-response-processing.js.map +1 -0
- package/dist/components/qti-rubric-block/qti-rubric-block.d.ts +15 -0
- package/dist/components/qti-rubric-block/qti-rubric-block.js +65 -0
- package/dist/components/qti-rubric-block/qti-rubric-block.js.map +1 -0
- package/dist/components/qti-stylesheet/qti-stylesheet.d.ts +12 -0
- package/dist/components/qti-stylesheet/qti-stylesheet.js +77 -0
- package/dist/components/qti-stylesheet/qti-stylesheet.js.map +1 -0
- package/dist/components/qti-template-constraint/qti-template-constraint.d.ts +33 -0
- package/dist/components/qti-template-constraint/qti-template-constraint.js +63 -0
- package/dist/components/qti-template-constraint/qti-template-constraint.js.map +1 -0
- package/dist/components/qti-template-declaration/qti-template-declaration.d.ts +27 -0
- package/dist/components/qti-template-declaration/qti-template-declaration.js +129 -0
- package/dist/components/qti-template-declaration/qti-template-declaration.js.map +1 -0
- package/dist/components/qti-template-processing/qti-template-processing.d.ts +21 -0
- package/dist/components/qti-template-processing/qti-template-processing.js +84 -0
- package/dist/components/qti-template-processing/qti-template-processing.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/event-types.d.ts +9 -0
- package/dist/internal/event-types.js +2 -0
- package/dist/internal/event-types.js.map +1 -0
- package/dist/internal/events/qti-register-variable.d.ts +10 -0
- package/dist/internal/events/qti-register-variable.js +2 -0
- package/dist/internal/events/qti-register-variable.js.map +1 -0
- package/dist/internal/template-strings.d.ts +3 -0
- package/dist/internal/template-strings.js +53 -0
- package/dist/internal/template-strings.js.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qti-modal-feedback.js","sourceRoot":"","sources":["../../../src/components/qti-modal-feedback/qti-modal-feedback.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAG5C,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,WAAW;aAC/B,WAAM,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuC3B,AAvCqB,CAuCpB;IAEO,MAAM;QACb,OAAO,IAAI,CAAA;0DAC2C,IAAI,CAAC,UAAU,KAAK,IAAI;;;wDAG1B,IAAI,CAAC,aAAa;;;KAGrE,CAAC;IACJ,CAAC;IAED,YAAY;QACV,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC,QAAQ,CAA6B,CAAC;QACpF,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YAC3B,MAAM,CAAC,SAAS,EAAE,CAAC;QACrB,CAAC;IACH,CAAC;IAED,aAAa;QACX,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC,QAAQ,CAA6B,CAAC;QACpF,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;YAC1B,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QAC1B,CAAC;IACH,CAAC;IAEe,iBAAiB;QAC/B,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC1B,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;YAC7B,IAAI,CAAC,YAAY,EAAE,CAAC;QACtB,CAAC;IACH,CAAC;IAEkB,OAAO,CAAC,iBAAyD;QAClF,IAAI,iBAAiB,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;YACxC,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;gBAC7B,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,aAAa,EAAE,CAAC;YACvB,CAAC;QACH,CAAC;IACH,CAAC;;AAnFU,gBAAgB;IAD5B,aAAa,CAAC,oBAAoB,CAAC;GACvB,gBAAgB,CAoF5B","sourcesContent":["import { css, html } from 'lit';\nimport { customElement } from 'lit/decorators.js';\n\nimport { QtiFeedback } from '@qti-components/base';\n\n@customElement('qti-modal-feedback')\nexport class QtiModalFeedback extends QtiFeedback {\n static override styles = css`\n .qti-dialog {\n background: var(--qti-bg);\n border: var(--qti-border-thickness) var(--qti-border-style) var(--qti-border-color);\n border-radius: var(--qti-border-radius);\n padding: var(--qti-padding-vertical) var(--qti-padding-horizontal);\n box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);\n position: fixed;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n z-index: 1000;\n width: auto;\n max-width: 90%;\n }\n\n .button {\n border-radius: var(--qti-border-radius);\n padding: var(--qti-padding-vertical) var(--qti-padding-horizontal);\n background-color: var(--qti-bg-active);\n border: var(--qti-border-active);\n cursor: pointer;\n position: relative;\n display: inline-block;\n }\n\n .button:hover {\n background-color: var(--qti-hover-bg);\n }\n\n .button:disabled {\n background-color: var(--qti-disabled-bg);\n color: var(--qti-disabled-color);\n cursor: not-allowed;\n }\n\n .button:focus {\n outline: var(--qti-focus-border-width) solid var(--qti-focus-color);\n }\n `;\n\n override render() {\n return html`\n <dialog class=\"qti-dialog\" part=\"feedback\" ?open=\"${this.showStatus === 'on'}\">\n <slot></slot>\n <div style=\"margin-top: var(--qti-gap-size); text-align: center;\">\n <button class=\"button close-button\" @click=\"${this.closeFeedback}\">Close</button>\n </div>\n </dialog>\n `;\n }\n\n openFeedback() {\n const dialog = this.shadowRoot?.querySelector('dialog') as HTMLDialogElement | null;\n if (dialog && !dialog.open) {\n dialog.showModal();\n }\n }\n\n closeFeedback() {\n const dialog = this.shadowRoot?.querySelector('dialog') as HTMLDialogElement | null;\n if (dialog && dialog.open) {\n dialog.close();\n this.showStatus = 'off';\n }\n }\n\n public override connectedCallback(): void {\n super.connectedCallback();\n if (this.showStatus === 'on') {\n this.openFeedback();\n }\n }\n\n protected override updated(changedProperties: Map<string | number | symbol, unknown>): void {\n if (changedProperties.has('showStatus')) {\n if (this.showStatus === 'on') {\n this.openFeedback();\n } else {\n this.closeFeedback();\n }\n }\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-modal-feedback': QtiModalFeedback;\n }\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { QtiVariableDeclaration } from '@qti-components/base';
|
|
2
|
+
import type { BaseType, Cardinality } from '@qti-components/base';
|
|
3
|
+
import type { ItemContext } from '@qti-components/base';
|
|
4
|
+
export declare class QtiOutcomeDeclaration extends QtiVariableDeclaration {
|
|
5
|
+
baseType: BaseType;
|
|
6
|
+
externalScored: 'human' | 'externalMachine' | null;
|
|
7
|
+
identifier: string;
|
|
8
|
+
cardinality: Cardinality;
|
|
9
|
+
itemContext?: ItemContext;
|
|
10
|
+
static styles: import("lit").CSSResult[];
|
|
11
|
+
render(): import("lit").TemplateResult<1>;
|
|
12
|
+
get interpolationTable(): Map<number, number> | null;
|
|
13
|
+
connectedCallback(): void;
|
|
14
|
+
}
|
|
15
|
+
declare global {
|
|
16
|
+
interface HTMLElementTagNameMap {
|
|
17
|
+
'qti-outcome-declaration': QtiOutcomeDeclaration;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { consume } from '@lit/context';
|
|
8
|
+
import { css, html } from 'lit';
|
|
9
|
+
import { customElement, property, state } from 'lit/decorators.js';
|
|
10
|
+
import { itemContext } from '@qti-components/base';
|
|
11
|
+
import { QtiVariableDeclaration } from '@qti-components/base';
|
|
12
|
+
let QtiOutcomeDeclaration = class QtiOutcomeDeclaration extends QtiVariableDeclaration {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments);
|
|
15
|
+
this.externalScored = null;
|
|
16
|
+
}
|
|
17
|
+
static { this.styles = [
|
|
18
|
+
css `
|
|
19
|
+
:host {
|
|
20
|
+
display: none;
|
|
21
|
+
}
|
|
22
|
+
`
|
|
23
|
+
]; }
|
|
24
|
+
render() {
|
|
25
|
+
const value = this.itemContext?.variables.find(v => v.identifier === this.identifier)?.value;
|
|
26
|
+
return html `${JSON.stringify(value, null, 2)}`;
|
|
27
|
+
}
|
|
28
|
+
get interpolationTable() {
|
|
29
|
+
const table = this.querySelector('qti-interpolation-table');
|
|
30
|
+
if (table) {
|
|
31
|
+
const entries = new Map();
|
|
32
|
+
for (const entry of table.querySelectorAll('qti-interpolation-table-entry')) {
|
|
33
|
+
if (!entry.getAttribute('source-value') && entry.getAttribute('target-value')) {
|
|
34
|
+
console.error('source-value or target-value is missing in qti-interpolation-table-entry');
|
|
35
|
+
}
|
|
36
|
+
const sourceValue = parseFloat(entry.getAttribute('source-value'));
|
|
37
|
+
const targetValue = parseFloat(entry.getAttribute('target-value'));
|
|
38
|
+
if (isNaN(sourceValue) || isNaN(targetValue)) {
|
|
39
|
+
console.error('source-value or target-value is not a number in qti-interpolation-table-entry');
|
|
40
|
+
}
|
|
41
|
+
entries.set(sourceValue, targetValue);
|
|
42
|
+
}
|
|
43
|
+
return entries;
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
connectedCallback() {
|
|
48
|
+
super.connectedCallback();
|
|
49
|
+
const defaultValue = this.defaultValues(this.cardinality);
|
|
50
|
+
const outcomeVariable = {
|
|
51
|
+
identifier: this.identifier,
|
|
52
|
+
cardinality: this.cardinality,
|
|
53
|
+
baseType: this.baseType,
|
|
54
|
+
defaultValue: defaultValue,
|
|
55
|
+
type: 'outcome',
|
|
56
|
+
value: null,
|
|
57
|
+
interpolationTable: this.interpolationTable,
|
|
58
|
+
externalScored: this.externalScored
|
|
59
|
+
};
|
|
60
|
+
// At runtime, outcome variables are instantiated as part of an item session.
|
|
61
|
+
// Their values may be initialized with a default value and/or set during response processing.
|
|
62
|
+
// If no default value is given in the declaration then the outcome variable is initialized to NULL unless the outcome is of a numeric type (integer or float) in which case it is initialized to 0.
|
|
63
|
+
outcomeVariable.value = defaultValue;
|
|
64
|
+
if ((outcomeVariable.value === null || outcomeVariable.value == undefined) &&
|
|
65
|
+
(outcomeVariable.baseType === 'integer' || outcomeVariable.baseType === 'float')) {
|
|
66
|
+
outcomeVariable.value = '0';
|
|
67
|
+
}
|
|
68
|
+
this.dispatchEvent(new CustomEvent('qti-register-variable', {
|
|
69
|
+
bubbles: true,
|
|
70
|
+
composed: true,
|
|
71
|
+
detail: { variable: outcomeVariable }
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
__decorate([
|
|
76
|
+
property({ type: String, attribute: 'base-type' })
|
|
77
|
+
], QtiOutcomeDeclaration.prototype, "baseType", void 0);
|
|
78
|
+
__decorate([
|
|
79
|
+
property({ type: String, attribute: 'external-scored' })
|
|
80
|
+
], QtiOutcomeDeclaration.prototype, "externalScored", void 0);
|
|
81
|
+
__decorate([
|
|
82
|
+
property({ type: String })
|
|
83
|
+
], QtiOutcomeDeclaration.prototype, "identifier", void 0);
|
|
84
|
+
__decorate([
|
|
85
|
+
property({ type: String })
|
|
86
|
+
], QtiOutcomeDeclaration.prototype, "cardinality", void 0);
|
|
87
|
+
__decorate([
|
|
88
|
+
consume({ context: itemContext, subscribe: true }),
|
|
89
|
+
state()
|
|
90
|
+
], QtiOutcomeDeclaration.prototype, "itemContext", void 0);
|
|
91
|
+
QtiOutcomeDeclaration = __decorate([
|
|
92
|
+
customElement('qti-outcome-declaration')
|
|
93
|
+
], QtiOutcomeDeclaration);
|
|
94
|
+
export { QtiOutcomeDeclaration };
|
|
95
|
+
//# sourceMappingURL=qti-outcome-declaration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qti-outcome-declaration.js","sourceRoot":"","sources":["../../../src/components/qti-outcome-declaration/qti-outcome-declaration.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEnE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,s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AAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,iBAAiB,EAAE,CAAC;6DAA2D;AACxF;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;yDAAoB;AACnB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;0DAA0B;AAI9C;IAFN,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAClD,KAAK,EAAE;0DACyB;AARtB,qBAAqB;IADjC,aAAa,CAAC,yBAAyB,CAAC;GAC5B,qBAAqB,CA4EjC","sourcesContent":["import { consume } from '@lit/context';\nimport { css, html } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\n\nimport { itemContext } from '@qti-components/base';\nimport { QtiVariableDeclaration } from '@qti-components/base';\n\nimport type { BaseType, Cardinality } from '@qti-components/base';\nimport type { OutcomeVariable } from '@qti-components/base';\nimport type { ItemContext } from '@qti-components/base';\n\n@customElement('qti-outcome-declaration')\nexport class QtiOutcomeDeclaration extends QtiVariableDeclaration {\n @property({ type: String, attribute: 'base-type' }) baseType: BaseType;\n @property({ type: String, attribute: 'external-scored' }) externalScored: 'human' | 'externalMachine' | null = null;\n @property({ type: String }) identifier: string;\n @property({ type: String }) cardinality: Cardinality;\n\n @consume({ context: itemContext, subscribe: true })\n @state()\n public itemContext?: ItemContext;\n\n static override styles = [\n css`\n :host {\n display: none;\n }\n `\n ];\n\n override render() {\n const value = this.itemContext?.variables.find(v => v.identifier === this.identifier)?.value;\n return html`${JSON.stringify(value, null, 2)}`;\n }\n\n get interpolationTable(): Map<number, number> | null {\n const table = this.querySelector('qti-interpolation-table');\n if (table) {\n const entries = new Map<number, number>();\n for (const entry of table.querySelectorAll('qti-interpolation-table-entry')) {\n if (!entry.getAttribute('source-value') && entry.getAttribute('target-value')) {\n console.error('source-value or target-value is missing in qti-interpolation-table-entry');\n }\n const sourceValue = parseFloat(entry.getAttribute('source-value'));\n const targetValue = parseFloat(entry.getAttribute('target-value'));\n if (isNaN(sourceValue) || isNaN(targetValue)) {\n console.error('source-value or target-value is not a number in qti-interpolation-table-entry');\n }\n entries.set(sourceValue, targetValue);\n }\n return entries;\n }\n return null;\n }\n\n public override connectedCallback() {\n super.connectedCallback();\n\n const defaultValue = this.defaultValues(this.cardinality);\n\n const outcomeVariable: OutcomeVariable = {\n identifier: this.identifier,\n cardinality: this.cardinality,\n baseType: this.baseType,\n defaultValue: defaultValue,\n type: 'outcome',\n value: null,\n interpolationTable: this.interpolationTable,\n externalScored: this.externalScored\n };\n // At runtime, outcome variables are instantiated as part of an item session.\n // Their values may be initialized with a default value and/or set during response processing.\n // If no default value is given in the declaration then the outcome variable is initialized to NULL unless the outcome is of a numeric type (integer or float) in which case it is initialized to 0.\n outcomeVariable.value = defaultValue;\n if (\n (outcomeVariable.value === null || outcomeVariable.value == undefined) &&\n (outcomeVariable.baseType === 'integer' || outcomeVariable.baseType === 'float')\n ) {\n outcomeVariable.value = '0';\n }\n this.dispatchEvent(\n new CustomEvent('qti-register-variable', {\n bubbles: true,\n composed: true,\n detail: { variable: outcomeVariable }\n })\n );\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-outcome-declaration': QtiOutcomeDeclaration;\n }\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { QtiVariableDeclaration } from '@qti-components/base';
|
|
2
|
+
import type { BaseType, Cardinality } from '@qti-components/base';
|
|
3
|
+
import type { ItemContext } from '@qti-components/base';
|
|
4
|
+
export declare class QtiResponseDeclaration extends QtiVariableDeclaration {
|
|
5
|
+
#private;
|
|
6
|
+
baseType: BaseType;
|
|
7
|
+
identifier: string;
|
|
8
|
+
cardinality: Cardinality;
|
|
9
|
+
itemContext?: ItemContext;
|
|
10
|
+
static styles: import("lit").CSSResult[];
|
|
11
|
+
render(): import("lit").TemplateResult<1>;
|
|
12
|
+
connectedCallback(): void;
|
|
13
|
+
}
|
|
14
|
+
declare global {
|
|
15
|
+
interface HTMLElementTagNameMap {
|
|
16
|
+
'qti-response-declaration': QtiResponseDeclaration;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { consume } from '@lit/context';
|
|
8
|
+
import { css, html } from 'lit';
|
|
9
|
+
import { customElement, property, state } from 'lit/decorators.js';
|
|
10
|
+
import { itemContext } from '@qti-components/base';
|
|
11
|
+
import { QtiVariableDeclaration } from '@qti-components/base';
|
|
12
|
+
let QtiResponseDeclaration = class QtiResponseDeclaration extends QtiVariableDeclaration {
|
|
13
|
+
static { this.styles = [
|
|
14
|
+
css `
|
|
15
|
+
:host {
|
|
16
|
+
display: none;
|
|
17
|
+
}
|
|
18
|
+
`
|
|
19
|
+
]; }
|
|
20
|
+
render() {
|
|
21
|
+
const value = this.itemContext?.variables.find(v => v.identifier === this.identifier)?.value;
|
|
22
|
+
return html `${JSON.stringify(value, null, 2)}`;
|
|
23
|
+
}
|
|
24
|
+
connectedCallback() {
|
|
25
|
+
super.connectedCallback();
|
|
26
|
+
const defaultValue = this.defaultValues(this.cardinality);
|
|
27
|
+
const responseVariable = {
|
|
28
|
+
baseType: this.baseType,
|
|
29
|
+
identifier: this.identifier,
|
|
30
|
+
correctResponse: this.#correctResponse,
|
|
31
|
+
cardinality: this.cardinality || 'single',
|
|
32
|
+
mapping: this.#mapping,
|
|
33
|
+
defaultValue,
|
|
34
|
+
areaMapping: this.#areaMapping,
|
|
35
|
+
value: null,
|
|
36
|
+
type: 'response',
|
|
37
|
+
candidateResponse: null
|
|
38
|
+
};
|
|
39
|
+
responseVariable.value = defaultValue;
|
|
40
|
+
this.dispatchEvent(new CustomEvent('qti-register-variable', {
|
|
41
|
+
bubbles: true,
|
|
42
|
+
composed: true,
|
|
43
|
+
detail: { variable: responseVariable }
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
get #correctResponse() {
|
|
47
|
+
let result;
|
|
48
|
+
const correctResponse = this.querySelector('qti-correct-response');
|
|
49
|
+
if (correctResponse) {
|
|
50
|
+
const values = correctResponse.querySelectorAll('qti-value');
|
|
51
|
+
if (this.cardinality === 'single' && values.length > 0) {
|
|
52
|
+
result = values[0].textContent.trim();
|
|
53
|
+
values[0].remove();
|
|
54
|
+
}
|
|
55
|
+
else if (this.cardinality !== 'single') {
|
|
56
|
+
result = [];
|
|
57
|
+
for (let i = 0; i < values.length; i++) {
|
|
58
|
+
result.push(values[i].textContent.trim());
|
|
59
|
+
values[i].remove();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
get #mapping() {
|
|
66
|
+
const mappingElement = this.querySelector('qti-mapping');
|
|
67
|
+
const lowerBound = parseFloat(mappingElement?.getAttribute('lower-bound'));
|
|
68
|
+
const uppperBound = parseFloat(mappingElement?.getAttribute('upper-bound'));
|
|
69
|
+
const mappingValue = {
|
|
70
|
+
defaultValue: Number(mappingElement?.getAttribute('default-value')) || 0,
|
|
71
|
+
lowerBound: isNaN(lowerBound) ? null : lowerBound,
|
|
72
|
+
upperBound: isNaN(uppperBound) ? null : uppperBound,
|
|
73
|
+
mapEntries: Array.from(mappingElement?.querySelectorAll('qti-map-entry') || []).map(el => ({
|
|
74
|
+
mapKey: el.getAttribute('map-key') || '',
|
|
75
|
+
mappedValue: Number(el.getAttribute('mapped-value')) || 0,
|
|
76
|
+
caseSensitive: el.hasAttribute('case-sensitive') ? el.getAttribute('case-sensitive') !== 'false' : false
|
|
77
|
+
}))
|
|
78
|
+
};
|
|
79
|
+
return mappingValue;
|
|
80
|
+
}
|
|
81
|
+
get #areaMapping() {
|
|
82
|
+
const areaMappingElement = this.querySelector('qti-area-mapping');
|
|
83
|
+
const defaultValue = Number(areaMappingElement?.getAttribute('default-value')) || 0;
|
|
84
|
+
const lowerBound = parseFloat(areaMappingElement?.getAttribute('lower-bound'));
|
|
85
|
+
const uppperBound = parseFloat(areaMappingElement?.getAttribute('upper-bound'));
|
|
86
|
+
const areaMapEntries = Array.from(areaMappingElement?.querySelectorAll('qti-area-map-entry') || []).map((el) => ({
|
|
87
|
+
shape: el.getAttribute('shape') || 'default',
|
|
88
|
+
coords: el.getAttribute('coords') || '',
|
|
89
|
+
mappedValue: Number(el.getAttribute('mapped-value')) || 0,
|
|
90
|
+
defaultValue: Number(el.getAttribute('default-value')) || 0
|
|
91
|
+
}));
|
|
92
|
+
return {
|
|
93
|
+
defaultValue,
|
|
94
|
+
lowerBound: isNaN(lowerBound) ? null : lowerBound,
|
|
95
|
+
upperBound: isNaN(uppperBound) ? null : uppperBound,
|
|
96
|
+
areaMapEntries
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
__decorate([
|
|
101
|
+
property({ type: String, attribute: 'base-type' })
|
|
102
|
+
], QtiResponseDeclaration.prototype, "baseType", void 0);
|
|
103
|
+
__decorate([
|
|
104
|
+
property({ type: String })
|
|
105
|
+
], QtiResponseDeclaration.prototype, "identifier", void 0);
|
|
106
|
+
__decorate([
|
|
107
|
+
property({ type: String })
|
|
108
|
+
], QtiResponseDeclaration.prototype, "cardinality", void 0);
|
|
109
|
+
__decorate([
|
|
110
|
+
consume({ context: itemContext, subscribe: true }),
|
|
111
|
+
state()
|
|
112
|
+
], QtiResponseDeclaration.prototype, "itemContext", void 0);
|
|
113
|
+
QtiResponseDeclaration = __decorate([
|
|
114
|
+
customElement('qti-response-declaration')
|
|
115
|
+
], QtiResponseDeclaration);
|
|
116
|
+
export { QtiResponseDeclaration };
|
|
117
|
+
//# sourceMappingURL=qti-response-declaration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qti-response-declaration.js","sourceRoot":"","sources":["../../../src/components/qti-response-declaration/qti-response-declaration.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEnE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AASvD,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,sBAAsB;aAWhD,WAAM,GAAG;QACvB,GAAG,CAAA;;;;KAIF;KACF,AANqB,CAMpB;IAEO,MAAM;QACb,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC;QAC7F,OAAO,IAAI,CAAA,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;IACjD,CAAC;IAEe,iBAAiB;QAC/B,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC1B,MAAM,YAAY,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAE1D,MAAM,gBAAgB,GAAqB;YACzC,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,eAAe,E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,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;2DAA0B;AAI9C;IAFN,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAClD,KAAK,EAAE;2DACyB;AATtB,sBAAsB;IADlC,aAAa,CAAC,0BAA0B,CAAC;GAC7B,sBAAsB,CA8GlC","sourcesContent":["import { consume } from '@lit/context';\nimport { css, html } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\n\nimport { itemContext } from '@qti-components/base';\nimport { QtiVariableDeclaration } from '@qti-components/base';\n\nimport type { QtiAreaMapping } from '@qti-components/base';\nimport type { BaseType, Cardinality } from '@qti-components/base';\nimport type { ResponseVariable } from '@qti-components/base';\nimport type { QtiMapping } from '@qti-components/base';\nimport type { ItemContext } from '@qti-components/base';\n\n@customElement('qti-response-declaration')\nexport class QtiResponseDeclaration extends QtiVariableDeclaration {\n @property({ type: String, attribute: 'base-type' }) baseType: BaseType;\n\n @property({ type: String }) identifier: string;\n\n @property({ type: String }) cardinality: Cardinality;\n\n @consume({ context: itemContext, subscribe: true })\n @state()\n public itemContext?: ItemContext;\n\n static override styles = [\n css`\n :host {\n display: none;\n }\n `\n ];\n\n override render() {\n const value = this.itemContext?.variables.find(v => v.identifier === this.identifier)?.value;\n return html`${JSON.stringify(value, null, 2)}`;\n }\n\n public override connectedCallback() {\n super.connectedCallback();\n const defaultValue = this.defaultValues(this.cardinality);\n\n const responseVariable: ResponseVariable = {\n baseType: this.baseType,\n identifier: this.identifier,\n correctResponse: this.#correctResponse,\n cardinality: this.cardinality || 'single',\n mapping: this.#mapping,\n defaultValue,\n areaMapping: this.#areaMapping,\n value: null,\n type: 'response',\n candidateResponse: null\n };\n responseVariable.value = defaultValue;\n\n this.dispatchEvent(\n new CustomEvent('qti-register-variable', {\n bubbles: true,\n composed: true,\n detail: { variable: responseVariable }\n })\n );\n }\n\n get #correctResponse(): string | string[] {\n let result: string | string[];\n const correctResponse = this.querySelector('qti-correct-response');\n if (correctResponse) {\n const values = correctResponse.querySelectorAll('qti-value');\n if (this.cardinality === 'single' && values.length > 0) {\n result = values[0].textContent.trim();\n values[0].remove();\n } else if (this.cardinality !== 'single') {\n result = [];\n for (let i = 0; i < values.length; i++) {\n result.push(values[i].textContent.trim());\n values[i].remove();\n }\n }\n }\n return result;\n }\n\n get #mapping(): QtiMapping {\n const mappingElement = this.querySelector('qti-mapping');\n const lowerBound = parseFloat(mappingElement?.getAttribute('lower-bound'));\n const uppperBound = parseFloat(mappingElement?.getAttribute('upper-bound'));\n const mappingValue = {\n defaultValue: Number(mappingElement?.getAttribute('default-value')) || 0,\n lowerBound: isNaN(lowerBound) ? null : lowerBound,\n upperBound: isNaN(uppperBound) ? null : uppperBound,\n mapEntries: Array.from(mappingElement?.querySelectorAll('qti-map-entry') || []).map(el => ({\n mapKey: el.getAttribute('map-key') || '',\n mappedValue: Number(el.getAttribute('mapped-value')) || 0,\n caseSensitive: el.hasAttribute('case-sensitive') ? el.getAttribute('case-sensitive') !== 'false' : false\n }))\n };\n return mappingValue;\n }\n\n get #areaMapping(): QtiAreaMapping {\n const areaMappingElement = this.querySelector('qti-area-mapping') as HTMLElement;\n\n const defaultValue = Number(areaMappingElement?.getAttribute('default-value')) || 0;\n const lowerBound = parseFloat(areaMappingElement?.getAttribute('lower-bound'));\n const uppperBound = parseFloat(areaMappingElement?.getAttribute('upper-bound'));\n\n const areaMapEntries = Array.from(areaMappingElement?.querySelectorAll('qti-area-map-entry') || []).map(\n (el: HTMLElement) => ({\n shape: (el.getAttribute('shape') as 'default' | 'circle' | 'rect' | 'ellipse' | 'poly') || 'default',\n coords: el.getAttribute('coords') || '',\n mappedValue: Number(el.getAttribute('mapped-value')) || 0,\n defaultValue: Number(el.getAttribute('default-value')) || 0\n })\n );\n\n return {\n defaultValue,\n lowerBound: isNaN(lowerBound) ? null : lowerBound,\n upperBound: isNaN(uppperBound) ? null : uppperBound,\n areaMapEntries\n };\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-response-declaration': QtiResponseDeclaration;\n }\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import type { PropertyValueMap } from 'lit';
|
|
3
|
+
export declare class QtiResponseProcessing extends LitElement {
|
|
4
|
+
#private;
|
|
5
|
+
static styles: import("lit").CSSResult[];
|
|
6
|
+
render(): import("lit").TemplateResult<1>;
|
|
7
|
+
process(): void;
|
|
8
|
+
firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void;
|
|
9
|
+
}
|
|
10
|
+
declare global {
|
|
11
|
+
interface HTMLElementTagNameMap {
|
|
12
|
+
'qti-response-processing': QtiResponseProcessing;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { css, html, LitElement } from 'lit';
|
|
8
|
+
import { customElement } from 'lit/decorators.js';
|
|
9
|
+
import { mapResponse, mapResponsePoint, matchCorrect } from '../../internal/template-strings';
|
|
10
|
+
let QtiResponseProcessing = class QtiResponseProcessing extends LitElement {
|
|
11
|
+
static { this.styles = [
|
|
12
|
+
css `
|
|
13
|
+
:host {
|
|
14
|
+
display: none;
|
|
15
|
+
}
|
|
16
|
+
`
|
|
17
|
+
]; }
|
|
18
|
+
render() {
|
|
19
|
+
return html `<slot></slot>`;
|
|
20
|
+
}
|
|
21
|
+
process() {
|
|
22
|
+
const assessmentItem = this.closest('qti-assessment-item');
|
|
23
|
+
if (!assessmentItem)
|
|
24
|
+
return;
|
|
25
|
+
const rules = [...this.children];
|
|
26
|
+
for (const rule of rules) {
|
|
27
|
+
rule.process();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
firstUpdated(_changedProperties) {
|
|
31
|
+
if (this.getAttribute('template')) {
|
|
32
|
+
const splittedTemplateName = this.getAttribute('template').split('/');
|
|
33
|
+
const templateName = splittedTemplateName[splittedTemplateName.length - 1].replace('.xml', '');
|
|
34
|
+
this.innerHTML = '';
|
|
35
|
+
switch (templateName) {
|
|
36
|
+
case 'map_response': {
|
|
37
|
+
this.appendChild(this.#fragmentFromString(mapResponse).firstElementChild.firstElementChild);
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
case 'map_response_point': {
|
|
41
|
+
this.appendChild(this.#fragmentFromString(mapResponsePoint).firstElementChild.firstElementChild);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
case 'match_correct':
|
|
45
|
+
this.appendChild(this.#fragmentFromString(matchCorrect).firstElementChild.firstElementChild);
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
#fragmentFromString(strHTML) {
|
|
51
|
+
return document.createRange().createContextualFragment(strHTML);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
QtiResponseProcessing = __decorate([
|
|
55
|
+
customElement('qti-response-processing')
|
|
56
|
+
], QtiResponseProcessing);
|
|
57
|
+
export { QtiResponseProcessing };
|
|
58
|
+
//# sourceMappingURL=qti-response-processing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qti-response-processing.js","sourceRoot":"","sources":["../../../src/components/qti-response-processing/qti-response-processing.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,K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AC,WAAW,CAAC,IAAI,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;oBACjG,MAAM;gBACR,CAAC;gBACD,KAAK,eAAe;oBAClB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;oBAC7F,MAAM;YACV,CAAC;QACH,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,OAAe;QACjC,OAAO,QAAQ,CAAC,WAAW,EAAE,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;IAClE,CAAC;;AA7CU,qBAAqB;IADjC,aAAa,CAAC,yBAAyB,CAAC;GAC5B,qBAAqB,CA8CjC","sourcesContent":["import { css, html, LitElement } from 'lit';\nimport { customElement } from 'lit/decorators.js';\n\nimport { type QtiRuleBase } from '@qti-components/base';\n\nimport { mapResponse, mapResponsePoint, matchCorrect } from '../../internal/template-strings';\n\nimport type { PropertyValueMap } from 'lit';\n\n@customElement('qti-response-processing')\nexport class QtiResponseProcessing extends LitElement {\n static override styles = [\n css`\n :host {\n display: none;\n }\n `\n ];\n\n override render() {\n return html`<slot></slot>`;\n }\n\n public process() {\n const assessmentItem = this.closest('qti-assessment-item');\n if (!assessmentItem) return;\n const rules = [...this.children] as unknown as QtiRuleBase[];\n for (const rule of rules) {\n rule.process();\n }\n }\n\n public override firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {\n if (this.getAttribute('template')) {\n const splittedTemplateName = this.getAttribute('template')!.split('/');\n const templateName = splittedTemplateName[splittedTemplateName.length - 1].replace('.xml', '');\n this.innerHTML = '';\n switch (templateName) {\n case 'map_response': {\n this.appendChild(this.#fragmentFromString(mapResponse).firstElementChild.firstElementChild);\n break;\n }\n case 'map_response_point': {\n this.appendChild(this.#fragmentFromString(mapResponsePoint).firstElementChild.firstElementChild);\n break;\n }\n case 'match_correct':\n this.appendChild(this.#fragmentFromString(matchCorrect).firstElementChild.firstElementChild);\n break;\n }\n }\n }\n\n #fragmentFromString(strHTML: string) {\n return document.createRange().createContextualFragment(strHTML);\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-response-processing': QtiResponseProcessing;\n }\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
export declare class QtiRubricBlock extends LitElement {
|
|
3
|
+
id: string;
|
|
4
|
+
use: 'instructions' | 'scoring' | 'navigation';
|
|
5
|
+
view: 'author' | 'candidate' | 'proctor' | 'scorer' | 'testConstructor' | 'tutor';
|
|
6
|
+
classNames: string;
|
|
7
|
+
handleclassNamesChange(): void;
|
|
8
|
+
static styles: import("lit").CSSResult;
|
|
9
|
+
render(): import("lit").TemplateResult<1>;
|
|
10
|
+
}
|
|
11
|
+
declare global {
|
|
12
|
+
interface HTMLElementTagNameMap {
|
|
13
|
+
'qti-rubric-block': QtiRubricBlock;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { LitElement, css, html } from 'lit';
|
|
8
|
+
import { customElement, property } from 'lit/decorators.js';
|
|
9
|
+
import { watch } from '@qti-components/utilities';
|
|
10
|
+
let QtiRubricBlock = class QtiRubricBlock extends LitElement {
|
|
11
|
+
handleclassNamesChange() {
|
|
12
|
+
const classNames = this.classNames.split(' ');
|
|
13
|
+
classNames.forEach((className) => {
|
|
14
|
+
switch (className) {
|
|
15
|
+
case 'qti-rubric-discretionary-placement':
|
|
16
|
+
{
|
|
17
|
+
const event = new CustomEvent('qti-rubric:discretionary-placement', {
|
|
18
|
+
detail: { className, element: this },
|
|
19
|
+
bubbles: true,
|
|
20
|
+
composed: true,
|
|
21
|
+
cancelable: true
|
|
22
|
+
});
|
|
23
|
+
const notCancelled = this.dispatchEvent(event);
|
|
24
|
+
if (!notCancelled)
|
|
25
|
+
return;
|
|
26
|
+
this.setAttribute('slot', 'qti-rubric-block');
|
|
27
|
+
}
|
|
28
|
+
break;
|
|
29
|
+
case 'qti-rubric-inline':
|
|
30
|
+
this.setAttribute('slot', '');
|
|
31
|
+
break;
|
|
32
|
+
default:
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
static { this.styles = css `
|
|
38
|
+
:host {
|
|
39
|
+
display: block;
|
|
40
|
+
}
|
|
41
|
+
`; }
|
|
42
|
+
render() {
|
|
43
|
+
return html `<slot></slot>`;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
__decorate([
|
|
47
|
+
property({ type: String })
|
|
48
|
+
], QtiRubricBlock.prototype, "id", void 0);
|
|
49
|
+
__decorate([
|
|
50
|
+
property({ type: String })
|
|
51
|
+
], QtiRubricBlock.prototype, "use", void 0);
|
|
52
|
+
__decorate([
|
|
53
|
+
property({ type: String })
|
|
54
|
+
], QtiRubricBlock.prototype, "view", void 0);
|
|
55
|
+
__decorate([
|
|
56
|
+
property({ type: String, attribute: 'class' })
|
|
57
|
+
], QtiRubricBlock.prototype, "classNames", void 0);
|
|
58
|
+
__decorate([
|
|
59
|
+
watch('classNames', { waitUntilFirstUpdate: true })
|
|
60
|
+
], QtiRubricBlock.prototype, "handleclassNamesChange", null);
|
|
61
|
+
QtiRubricBlock = __decorate([
|
|
62
|
+
customElement('qti-rubric-block')
|
|
63
|
+
], QtiRubricBlock);
|
|
64
|
+
export { QtiRubricBlock };
|
|
65
|
+
//# sourceMappingURL=qti-rubric-block.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qti-rubric-block.js","sourceRoot":"","sources":["../../../src/components/qti-rubric-block/qti-rubric-block.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAG3C,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,UAAU;IAS5C,sBAAsB;QACpB,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC9C,UAAU,CAAC,OAAO,CAAC,CAAC,SAAiB,EAAE,EAAE;YACvC,QAAQ,SAAS,EAAE,CAAC;gBAClB,KAAK,oCAAoC;oBACvC,CAAC;wBACC,MAAM,KAAK,GAAG,IAAI,WAAW,CAAC,oCAAoC,EAAE;4BAClE,MAAM,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE;4BACpC,OAAO,EAAE,IAAI;4BACb,QAAQ,EAAE,IAAI;4BACd,UAAU,EAAE,IAAI;yBACjB,CAAC,CAAC;wBACH,MAAM,YAAY,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;wBAC/C,IAAI,CAAC,YAAY;4BAAE,OAAO;wBAC1B,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;oBAChD,CAAC;oBACD,MAAM;gBACR,KAAK,mBAAmB;oBACtB,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;oBAC9B,MAAM;gBACR;oBACE,MAAM;YACV,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;aAEe,WAAM,GAAG,GAAG,CAAA;;;;GAI3B,AAJqB,CAIpB;IAEO,MAAM;QACb,OAAO,IAAI,CAAA,eAAe,CAAC;IAC7B,CAAC;;AA1CoC;IAApC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;0CAAqB;AAEpB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;2CAAgD;AAE/C;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;4CAAmF;AAE9D;IAA/C,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;kDAAoB;AAEnE;IADC,KAAK,CAAC,YAAY,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;4DAyBnD;AAjCU,cAAc;IAD1B,aAAa,CAAC,kBAAkB,CAAC;GACrB,cAAc,CA4C1B","sourcesContent":["import { LitElement, css, html } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\n\nimport { watch } from '@qti-components/utilities';\n\n@customElement('qti-rubric-block')\nexport class QtiRubricBlock extends LitElement {\n @property({ type: String }) override id: string; // =\"qtiAspectInhoudRubricBlock\"\n\n @property({ type: String }) use: 'instructions' | 'scoring' | 'navigation'; // = \"scoring\"\n\n @property({ type: String }) view: 'author' | 'candidate' | 'proctor' | 'scorer' | 'testConstructor' | 'tutor';\n\n @property({ type: String, attribute: 'class' }) classNames: string;\n @watch('classNames', { waitUntilFirstUpdate: true })\n handleclassNamesChange() {\n const classNames = this.classNames.split(' ');\n classNames.forEach((className: string) => {\n switch (className) {\n case 'qti-rubric-discretionary-placement':\n {\n const event = new CustomEvent('qti-rubric:discretionary-placement', {\n detail: { className, element: this },\n bubbles: true,\n composed: true,\n cancelable: true\n });\n const notCancelled = this.dispatchEvent(event);\n if (!notCancelled) return;\n this.setAttribute('slot', 'qti-rubric-block');\n }\n break;\n case 'qti-rubric-inline':\n this.setAttribute('slot', '');\n break;\n default:\n break;\n }\n });\n }\n\n static override styles = css`\n :host {\n display: block;\n }\n `;\n\n override render() {\n return html`<slot></slot>`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-rubric-block': QtiRubricBlock;\n }\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import type { PropertyValueMap } from 'lit';
|
|
3
|
+
export declare class QtiStylesheet extends LitElement {
|
|
4
|
+
#private;
|
|
5
|
+
protected firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void;
|
|
6
|
+
disconnectedCallback(): void;
|
|
7
|
+
}
|
|
8
|
+
declare global {
|
|
9
|
+
interface HTMLElementTagNameMap {
|
|
10
|
+
'qti-stylesheet': QtiStylesheet;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { LitElement } from 'lit';
|
|
8
|
+
import { customElement } from 'lit/decorators.js';
|
|
9
|
+
let QtiStylesheet = class QtiStylesheet extends LitElement {
|
|
10
|
+
#styleElement = null;
|
|
11
|
+
firstUpdated(_changedProperties) {
|
|
12
|
+
super.firstUpdated(_changedProperties);
|
|
13
|
+
const link = this.getAttribute('href');
|
|
14
|
+
if (link !== null) {
|
|
15
|
+
// Fetch the stylesheet content
|
|
16
|
+
fetch(link)
|
|
17
|
+
.then(response => response.text())
|
|
18
|
+
.then(cssContent => {
|
|
19
|
+
// Minify the CSS content by removing whitespace and comments
|
|
20
|
+
const minifiedCss = this.#minifyCss(cssContent);
|
|
21
|
+
// Create a <style> element with @scope surrounding the minified CSS
|
|
22
|
+
this.#styleElement = document.createElement('style');
|
|
23
|
+
this.#styleElement.media = 'screen';
|
|
24
|
+
this.#styleElement.textContent = `@scope {${minifiedCss}}`;
|
|
25
|
+
// Append the style element to the parent element of this component
|
|
26
|
+
if (this.parentElement) {
|
|
27
|
+
this.parentElement.appendChild(this.#styleElement);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
console.warn('No parent element to append the scoped stylesheet to.');
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
.catch(error => {
|
|
34
|
+
console.error('Failed to load stylesheet:', error);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (this.textContent !== null && this.textContent.trim() !== '') {
|
|
38
|
+
// Minify the inline CSS content
|
|
39
|
+
const minifiedCss = this.#minifyCss(this.textContent);
|
|
40
|
+
// Directly create a <style> element with the @scope surrounding the minified inline styles
|
|
41
|
+
this.#styleElement = document.createElement('style');
|
|
42
|
+
this.#styleElement.media = 'screen';
|
|
43
|
+
this.#styleElement.textContent = `@scope {${minifiedCss}}`;
|
|
44
|
+
// Append the style element to the parent element of this component
|
|
45
|
+
if (this.parentElement) {
|
|
46
|
+
this.parentElement.appendChild(this.#styleElement);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
console.warn('No parent element to append the scoped stylesheet to.');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
#minifyCss(cssContent) {
|
|
54
|
+
// Remove comments, whitespace, and newline characters
|
|
55
|
+
return cssContent
|
|
56
|
+
.replace(/\/\*[\s\S]*?\*\//g, '') // Remove comments
|
|
57
|
+
.replace(/\s+/g, ' ') // Collapse whitespace
|
|
58
|
+
.replace(/\s*([{}:;])\s*/g, '$1') // Remove spaces around {}, :, ;
|
|
59
|
+
.trim(); // Trim leading/trailing whitespace
|
|
60
|
+
}
|
|
61
|
+
disconnectedCallback() {
|
|
62
|
+
if (this.#styleElement) {
|
|
63
|
+
try {
|
|
64
|
+
this.#styleElement.remove();
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.error('Could not remove stylesheet:', error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
super.disconnectedCallback();
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
QtiStylesheet = __decorate([
|
|
74
|
+
customElement('qti-stylesheet')
|
|
75
|
+
], QtiStylesheet);
|
|
76
|
+
export { QtiStylesheet };
|
|
77
|
+
//# sourceMappingURL=qti-stylesheet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qti-stylesheet.js","sourceRoot":"","sources":["../../../src/components/qti-stylesheet/qti-stylesheet.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAK3C,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,UAAU;IAC3C,aAAa,GAA4B,IAAI,CAAC;IAE3B,YAAY,CAAC,kBAAqE;QACnG,KAAK,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC;QAEvC,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAEvC,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAClB,+BAA+B;YAC/B,KAAK,CAAC,IAAI,CAAC;iBACR,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;iBACjC,IAAI,CAAC,UAAU,CAAC,EAAE;gBACjB,6DAA6D;gBAC7D,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAA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;IACH,CAAC;IAED,UAAU,CAAC,UAAkB;QAC3B,sDAAsD;QACtD,OAAO,UAAU;aACd,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC,kBAAkB;aACnD,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,sBAAsB;aAC3C,OAAO,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC,gCAAgC;aACjE,IAAI,EAAE,CAAC,CAAC,mCAAmC;IAChD,CAAC;IAEQ,oBAAoB;QAC3B,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACvB,IAAI,CAAC;gBACH,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC;YAC9B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAC;YACvD,CAAC;QACH,CAAC;QACD,KAAK,CAAC,oBAAoB,EAAE,CAAC;IAC/B,CAAC;CACF,CAAA;AAtEY,aAAa;IADzB,aAAa,CAAC,gBAAgB,CAAC;GACnB,aAAa,CAsEzB","sourcesContent":["import { LitElement } from 'lit';\nimport { customElement } from 'lit/decorators.js';\n\nimport type { PropertyValueMap } from 'lit';\n\n@customElement('qti-stylesheet')\nexport class QtiStylesheet extends LitElement {\n #styleElement: HTMLStyleElement | null = null;\n\n protected override firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {\n super.firstUpdated(_changedProperties);\n\n const link = this.getAttribute('href');\n\n if (link !== null) {\n // Fetch the stylesheet content\n fetch(link)\n .then(response => response.text())\n .then(cssContent => {\n // Minify the CSS content by removing whitespace and comments\n const minifiedCss = this.#minifyCss(cssContent);\n\n // Create a <style> element with @scope surrounding the minified CSS\n this.#styleElement = document.createElement('style');\n this.#styleElement.media = 'screen';\n this.#styleElement.textContent = `@scope {${minifiedCss}}`;\n\n // Append the style element to the parent element of this component\n if (this.parentElement) {\n this.parentElement.appendChild(this.#styleElement);\n } else {\n console.warn('No parent element to append the scoped stylesheet to.');\n }\n })\n .catch(error => {\n console.error('Failed to load stylesheet:', error);\n });\n }\n\n if (this.textContent !== null && this.textContent.trim() !== '') {\n // Minify the inline CSS content\n const minifiedCss = this.#minifyCss(this.textContent);\n\n // Directly create a <style> element with the @scope surrounding the minified inline styles\n this.#styleElement = document.createElement('style');\n this.#styleElement.media = 'screen';\n this.#styleElement.textContent = `@scope {${minifiedCss}}`;\n\n // Append the style element to the parent element of this component\n if (this.parentElement) {\n this.parentElement.appendChild(this.#styleElement);\n } else {\n console.warn('No parent element to append the scoped stylesheet to.');\n }\n }\n }\n\n #minifyCss(cssContent: string): string {\n // Remove comments, whitespace, and newline characters\n return cssContent\n .replace(/\\/\\*[\\s\\S]*?\\*\\//g, '') // Remove comments\n .replace(/\\s+/g, ' ') // Collapse whitespace\n .replace(/\\s*([{}:;])\\s*/g, '$1') // Remove spaces around {}, :, ;\n .trim(); // Trim leading/trailing whitespace\n }\n\n override disconnectedCallback() {\n if (this.#styleElement) {\n try {\n this.#styleElement.remove();\n } catch (error) {\n console.error('Could not remove stylesheet:', error);\n }\n }\n super.disconnectedCallback();\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-stylesheet': QtiStylesheet;\n }\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import type { QtiRuleBase } from '@qti-components/base';
|
|
3
|
+
/**
|
|
4
|
+
* @summary The qti-template-constraint element is a processing rule available only in Template Processing.
|
|
5
|
+
* @documentation https://www.imsglobal.org/spec/qti/v3p0/impl#h.template-constraint
|
|
6
|
+
*
|
|
7
|
+
* It terminates Template Processing and re-runs it from the beginning if the condition
|
|
8
|
+
* specified in the template constraint is not satisfied. This can be used to iterate
|
|
9
|
+
* the Template Processing with different randomly-generated values until a predetermined
|
|
10
|
+
* condition is satisfied.
|
|
11
|
+
*/
|
|
12
|
+
export declare class QtiTemplateConstraint extends LitElement implements QtiRuleBase {
|
|
13
|
+
render(): import("lit").TemplateResult<1>;
|
|
14
|
+
/**
|
|
15
|
+
* Evaluates the constraint condition
|
|
16
|
+
* @returns true if constraint is satisfied, false if template processing should restart
|
|
17
|
+
*/
|
|
18
|
+
calculate(): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Template constraints don't have sub-rules like conditions
|
|
21
|
+
*/
|
|
22
|
+
getSubRules(): QtiRuleBase[];
|
|
23
|
+
/**
|
|
24
|
+
* Process the template constraint
|
|
25
|
+
* @returns true if constraint is satisfied, false if template processing should restart
|
|
26
|
+
*/
|
|
27
|
+
process(): boolean;
|
|
28
|
+
}
|
|
29
|
+
declare global {
|
|
30
|
+
interface HTMLElementTagNameMap {
|
|
31
|
+
'qti-template-constraint': QtiTemplateConstraint;
|
|
32
|
+
}
|
|
33
|
+
}
|