Skip to content
28 changes: 25 additions & 3 deletions design/author.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,13 +455,35 @@ text to the content check's rules, and `apps/skills` plays every example untrust
answers, Multimedia Choice's options; Find the Hotspot's areas are refused already), two
answers or statements alike as a learner reads them, without tags or entities and in any case
(Multiple Choice, a Single Choice Set question, a Summary set), a text with no gap (Fill in the
Blanks, Drag the Words, Mark the Words), and a picture with no alt text where its field is
optional (`ALT_TEXTS`, held to the pack's fields by `build.test.ts`; H5P.Image's is required).
Blanks, Drag the Words, Mark the Words), a picture with no alt text where its field is
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
optional (`ALT_TEXTS`, held to the pack's fields by `build.test.ts`; H5P.Image's is required),
and what goes stale when a content is changed and a setting kept (#268): a number of items
drawn at random (Question Set's `poolSize`, Memory Game's `numCardsToUse`, Crossword's
`poolSize`) or to find (Find Multiple Hotspots' `numberHotspots`), said with both numbers below
the list's length, since it may be meant, and at or above it as drawing nothing now; and a part
named by what is not there: a Course Presentation button's slide, a Drag and Drop zone's right
element or an element's zone, and an element no zone it can reach takes as right, Agamotto's
start image, a Virtual Tour's scene id, a Personality Quiz answer's personality. Each note says
what its library does, read in the library's script, not its field's label: Find Multiple
Hotspots does not use a number above its hotspots, Agamotto holds a start image to those there
are, and Personality Quiz takes a name only as its personality has it, parted at ", ". In
ChatGPT a quiz of six questions came with `poolSize` 3 after the chat was asked to add
questions, and showed three (2026-11-23); whether its first source had it is not known. The
outline's first line says a draw's how many of how many. One function, `drawOf`, works
out what each draw shows, for the notes and the outline: Question Set shuffles whenever
`poolSize` is set, Memory Game draws pairs, at least 2, and Crossword keeps the words fixed on
the grid and draws only among the rest. Not looked for: a select tied to the
content, as Multiple Choice's single or multiple answers; Advanced Blanks' gaps against its
list and its snippets by name; a Game Map restriction's stage id; video times (#260).
Each says what to write. `lib/mistakes.mjs` runs in `checkContent`, so a build says them and so
does a check of saved content, and every type file's example says none. Of the owner's 88 real
packages, the 79 checked against their own libraries give 36 notes of a picture with no alt
text in 8 packages, and 4 of answers alike in one, a test whose answers all read "Test"; no
question with no answer marked correct, and no text with no gap.
question with no answer marked correct, and no text with no gap. The notes of #268 fire in none
of the 88, of which 18 hold a Course Presentation, 15 a Drag and Drop, 12 a Question Set, 2 a
Virtual Tour and 1 a Crossword; none holds a Memory Game, a Personality Quiz, an Agamotto or a
Find Multiple Hotspots, so for those four it says nothing. One Drag and Drop there names two
elements right in a zone they cannot be dropped in, beside the one they can: left unsaid.
- **A source names the version of its type it was built with, and the build writes that** (#219,
the owner's calls). A source handed over beside a package is built again later, on the build
page or by a newer release, with a newer pack. So a build hands back the source with
Expand Down
187 changes: 186 additions & 1 deletion packages/author/lib/mistakes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { blanksGaps } from './types.mjs'

/**
* What builds and is almost surely a mistake (#241, item 4 of #219): no answer marked correct, two
* answers alike, a text with no gap, a picture with no alt text where its field is optional. H5P
* answers alike, a text with no gap, a picture with no alt text where its field is optional. And
* what goes stale when a chat changes a content and leaves a setting as it was (#268): a number
* of items to draw or to find that is not below how many there are, and a part named by its
* number, id or name that is not there. H5P
* allows each, so each is a note and not a problem, and nothing about the content is judged: whether
* an answer is right stays the person's. Run by `checkContent` on content as H5P stores it, so a
* build says them, and so does a check of saved content.
Expand All @@ -23,6 +26,76 @@ function plain(value) {
return typeof value === 'string' ? decodeEntities(stripTags(value)).replace(/\s+/g, ' ').trim().toLowerCase() : ''
}

/** @param {unknown} value */
const count = (value) => (Array.isArray(value) ? value.length : 0)

/**
* What a draw shows, where a setting shows some of a list's items picked at random each time, as
* each library works it out (#268):
* - Question Set (questionset.js): `poolSize` above 0 shuffles the questions and keeps that many,
* so it also shows them in a random order where it keeps them all.
* - Memory Game (memory-game.js): `numCardsToUse` pairs, at least 2.
* - Crossword (h5p-crossword.js): `poolSize` 0 is all, else at least 2; the words fixed on the
* grid are always kept, and the others drawn to make up the rest; a word without an answer or
* a clue is left out first.
* @param {string} library
* @param {unknown} params as H5P stores them
* @returns {{ at: string, what: string, used: number, total: number, shown: number, fixed: number, shuffles: boolean } | null}
* `at`, the setting's path in the parameters; `used`, the number the library draws; null where
* nothing is drawn
* @internal
*/
export function drawOf(library, params) {
if (!isObject(params)) return null
if (library === 'H5P.QuestionSet') {
const total = count(params.questions)
if (typeof params.poolSize !== 'number' || !(params.poolSize > 0) || !total) return null
// `slice(0, poolSize)`, which drops a fraction.
const used = Math.trunc(params.poolSize)
return { at: 'poolSize', what: 'questions', used, total, shown: Math.min(used, total), fixed: 0, shuffles: true }
}
if (library === 'H5P.MemoryGame') {
const total = count(params.cards)
const setting = params.behaviour?.numCardsToUse
if (typeof setting !== 'number' || !(setting >= 1) || !total) return null
const used = Math.max(2, Math.trunc(setting))
return { at: 'behaviour.numCardsToUse', what: 'pairs', used, total, shown: Math.min(used, total), fixed: 0, shuffles: false }
}
if (library === 'H5P.Crossword') {
const setting = params.behaviour?.poolSize
const words = Array.isArray(params.words) ? params.words.filter((/** @type {any} */ word) => word?.answer && word?.clue) : []
if (typeof setting !== 'number' || !setting || !words.length) return null
// `Math.max(2, poolSize)`, then a `splice` that drops a fraction.
const used = Math.trunc(Math.max(2, setting))
const fixed = words.filter((/** @type {any} */ word) => word.fixWord && word.row !== undefined && word.column !== undefined && word.orientation !== undefined).length
const shown = fixed + Math.min(Math.max(0, used - fixed), words.length - fixed)
return { at: 'behaviour.poolSize', what: 'words', used, total: words.length, shown, fixed, shuffles: false }
}
return null
}

/**
* A draw's note: below the list's length, what it shows, since it may be meant; at or above it,
* that it leaves none out now and would once items are added, what a chat that adds items and
* keeps the setting gets.
* @param {string} library @param {Record<string, any>} params @param {string} path @param {Note} note
*/
function noteDraw(library, params, path, note) {
const draw = drawOf(library, params)
if (!draw) return
const { what, used, total, shown, fixed } = draw
const at = `${path}.${draw.at}`
const order = draw.shuffles ? ' but shows them in a random order' : ''
const random = draw.shuffles ? ', and set randomQuestions for a random order' : ''
if (shown < total) {
if (!fixed) note(at, `shows ${shown} of the ${total} ${what} each time, drawn at random, and leaves the rest out: leave it out to show them all, or tell the user that it draws`)
else if (shown === fixed) note(at, `shows only the ${fixed} ${what} fixed on the grid, and never the other ${total - fixed}: leave it out to show them all`)
else note(at, `shows ${shown} of the ${total} ${what} each time, the ${fixed} fixed on the grid and ${shown - fixed} of the other ${total - fixed} drawn at random, and leaves the rest out: leave it out to show them all, or tell the user that it draws`)
}
else if (used === total) note(at, `is the number of ${what}, ${total}, so it leaves none out${order}, and one added later would leave one out at random: leave it out${random}`)
else note(at, `is above the number of ${what}, ${total}, so it leaves none out${order} until more than ${used} are, and then leaves some out at random: leave it out${random}`)
}

/**
* Each item of a list that reads as an earlier one does.
* @param {unknown} items
Expand Down Expand Up @@ -100,6 +173,118 @@ const CHECKS = {
'H5P.MultiMediaChoice'(params, path, note) {
if (noneCorrect(params.options)) note(`${path}.options`, 'marks no option correct, so no learner can score: set "correct": true on the right one')
},
// `poolSize`, labelled "Number of questions to be shown", is how many are drawn at random: in
// ChatGPT a quiz of six came with it at 3 after the chat was asked to add questions (#268).
'H5P.QuestionSet'(params, path, note) {
noteDraw('H5P.QuestionSet', params, path, note)
},
'H5P.MemoryGame'(params, path, note) {
noteDraw('H5P.MemoryGame', params, path, note)
},
'H5P.Crossword'(params, path, note) {
noteDraw('H5P.Crossword', params, path, note)
},
// The task ends at this many found. Above the number of hotspots, right or not, the library
// does not use it (image-multiple-hotspot-question.js).
'H5P.ImageMultipleHotspotQuestion'(params, path, note) {
const settings = params.imageMultipleHotspotQuestion?.hotspotSettings
const wanted = settings?.numberHotspots
const spots = Array.isArray(settings?.hotspot) ? settings.hotspot : []
const correct = spots.filter((/** @type {any} */ spot) => spot?.userSettings?.correct === true).length
if (typeof wanted !== 'number' || wanted < 1 || !correct) return
const at = `${path}.imageMultipleHotspotQuestion.hotspotSettings.numberHotspots`
if (wanted > spots.length) note(at, `is above the number of hotspots, ${spots.length}, so it is not used: leave it out`)
else if (wanted > correct) note(at, `asks for ${wanted} hotspots, and ${correct} ${correct === 1 ? 'is' : 'are'} marked correct, so no learner can finish: leave it out, or mark more correct`)
else if (wanted < correct) note(at, `ends the task once ${wanted} of the ${correct} correct hotspots are found: leave it out to ask for all of them, or tell the user`)
else note(at, `is the number of correct hotspots, ${correct}, so it changes nothing, and one added later would not be asked for: leave it out`)
},
// A button that goes to a slide by its number: one that is not there goes nowhere.
'H5P.CoursePresentation'(params, path, note) {
const slides = params.presentation?.slides
if (!Array.isArray(slides)) return
slides.forEach((/** @type {any} */ slide, /** @type {number} */ i) => {
if (!Array.isArray(slide?.elements)) return
slide.elements.forEach((/** @type {any} */ element, /** @type {number} */ j) => {
const to = element?.goToSlide
if ((element?.goToSlideType ?? 'specified') !== 'specified' || typeof to !== 'number') return
if (!Number.isInteger(to) || to < 1 || to > slides.length) note(`${path}.presentation.slides[${i}].elements[${j}].goToSlide`, `goes to slide ${to}, and there ${slides.length === 1 ? 'is 1 slide' : `are ${slides.length} slides`}, so the button has no slide to go to: name a slide by its number, from 1`)
})
})
},
// A drop zone names its right elements, and an element the zones it can be dropped in, by
// their place in the other list, as text (h5p-drag-question.js reads both). An element that
// can be dropped in none of the zones it is right in can never be put right. One that can be
// in some of them is left: a real package of the owner's names two elements right in a zone
// they cannot reach, beside the one they can, and plays as meant.
'H5P.DragQuestion'(params, path, note) {
const task = params.question?.task
const elements = Array.isArray(task?.elements) ? task.elements : []
const zones = Array.isArray(task?.dropZones) ? task.dropZones : []
const at = `${path}.question.task`
/** @param {unknown} named @param {number} total */
const placed = (named, total) => { const index = Number(named); return typeof named !== 'boolean' && named !== '' && Number.isInteger(index) && index >= 0 && index < total }
const none = (/** @type {number} */ total, /** @type {string} */ one) => (total === 1 ? `is 1 ${one}` : `are ${total} ${one}s`)
zones.forEach((/** @type {any} */ zone, /** @type {number} */ i) => {
if (!Array.isArray(zone?.correctElements)) return
zone.correctElements.forEach((/** @type {any} */ named, /** @type {number} */ j) => {
if (!placed(named, elements.length)) return note(`${at}.dropZones[${i}].correctElements[${j}]`, `names element ${JSON.stringify(named)}, and there ${none(elements.length, 'element')}, counted from 0: name each by its place in elements`)
})
})
elements.forEach((/** @type {any} */ element, /** @type {number} */ e) => {
if (!Array.isArray(element?.dropZones)) return
const right = zones.flatMap((/** @type {any} */ zone, /** @type {number} */ i) => (Array.isArray(zone?.correctElements) && zone.correctElements.map(String).includes(String(e)) ? [i] : []))
const allowed = new Set(element.dropZones.map(String))
if (right.length && !right.some((/** @type {number} */ i) => allowed.has(String(i)))) note(`${at}.elements[${e}].dropZones`, `lets the element be dropped in ${element.dropZones.length ? `zone ${element.dropZones.join(', ')}` : 'no zone'}, and it is right only in zone ${right.join(', ')}, so no learner can put it right: name ${right.length === 1 ? 'that zone' : 'one of those zones'} in its dropZones`)
})
elements.forEach((/** @type {any} */ element, /** @type {number} */ i) => {
if (!Array.isArray(element?.dropZones)) return
element.dropZones.forEach((/** @type {any} */ named, /** @type {number} */ j) => {
if (!placed(named, zones.length)) note(`${at}.elements[${i}].dropZones[${j}]`, `names drop zone ${JSON.stringify(named)}, and there ${none(zones.length, 'drop zone')}, counted from 0: name each by its place in dropZones`)
})
})
},
// Held to the images there are (h5p-agamotto.js constrains it), so nothing breaks: it starts
// elsewhere than written. A fraction never gets here: its field takes a whole number, which
// the build holds it to.
'H5P.Agamotto'(params, path, note) {
const start = params.behaviour?.startImage
const items = count(params.items)
if (typeof start === 'number' && items && (start < 1 || start > items)) note(`${path}.behaviour.startImage`, `is image ${start}, and there ${items === 1 ? 'is 1 image' : `are ${items} images`}, so it starts at the ${start < 1 ? 'first' : 'last'}: name one by its number, from 1, or leave it out`)
},
// A tour's scenes are named by their ids: where it starts, and where a "go to scene" leads.
'H5P.ThreeImage'(params, path, note) {
const tour = params.threeImage
if (!Array.isArray(tour?.scenes)) return
const ids = new Set(tour.scenes.map((/** @type {any} */ scene) => scene?.sceneId).filter((/** @type {any} */ id) => id !== undefined))
const listed = [...ids].join(', ')
if (tour.startSceneId !== undefined && !ids.has(tour.startSceneId)) note(`${path}.threeImage.startSceneId`, `is ${tour.startSceneId}, which no scene has; the scenes' ids are ${listed}: name the scene the tour starts on by its sceneId`)
tour.scenes.forEach((/** @type {any} */ scene, /** @type {number} */ i) => {
if (!Array.isArray(scene?.interactions)) return
scene.interactions.forEach((/** @type {any} */ interaction, /** @type {number} */ j) => {
const action = interaction?.action
const to = action?.params?.nextSceneId
if (!/^H5P\.GoToScene\b/.test(String(action?.library ?? '')) || to === undefined || ids.has(to)) return
note(`${path}.threeImage.scenes[${i}].interactions[${j}].action.params.nextSceneId`, `is ${to}, which no scene has; the scenes' ids are ${listed}: name the scene it goes to by its sceneId`)
})
})
},
// An answer names its personalities by name. The library splits the text at ", " and counts a
// name only where it is a personality's exactly (personalityQuiz.js: `split(', ')`, `===`), so
// another capital, a comma with no space after it, or a personality renamed counts for none;
// the answer's other names still count.
'H5P.PersonalityQuiz'(params, path, note) {
if (!Array.isArray(params.personalities) || !Array.isArray(params.questions)) return
const names = new Set(params.personalities.map((/** @type {any} */ one) => one?.name).filter((/** @type {any} */ name) => typeof name === 'string' && name))
params.questions.forEach((/** @type {any} */ question, /** @type {number} */ i) => {
if (!Array.isArray(question?.answers)) return
question.answers.forEach((/** @type {any} */ answer, /** @type {number} */ j) => {
if (typeof answer?.personality !== 'string' || !answer.personality) return
// An empty part, after a comma at the end, names nothing and is not said.
const unknown = answer.personality.split(', ').filter((/** @type {any} */ name) => name && !names.has(name))
if (unknown.length) note(`${path}.questions[${i}].answers[${j}].personality`, `names ${unknown.map((/** @type {any} */ name) => JSON.stringify(name)).join(', ')}, which no personality is called exactly, so ${unknown.length === 1 ? 'that name counts' : 'those names count'} for none: write each name as its personality has it, capitals too, with a comma and a space between two`)
})
})
},
'H5P.SingleChoiceSet'(params, path, note) {
if (!Array.isArray(params.choices)) return
params.choices.forEach((choice, i) => alike(choice?.answers, (answer) => answer, `${path}.choices[${i}].answers`, 'answer', note))
Expand Down
14 changes: 13 additions & 1 deletion packages/author/lib/outline.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isInterfaceText } from './schema.mjs'
import { decodeEntities, editorWidget, tagsIn, takesMarkup } from './text.mjs'
import { drawOf } from './mistakes.mjs'
import { questionTitle } from './types.mjs'

/**
Expand Down Expand Up @@ -168,7 +169,18 @@ export function outlineOf(libraries, content, { limit = Infinity } = {}) {
*/
const walkFields = (fields, params, depth, type, path, bare = false) => {
if (!isObject(params)) return
if (!path) semanticsOf.set(type, fields)
if (!path) {
semanticsOf.set(type, fields)
// A setting that shows only some of a list's items, which a chat that adds items may keep
// as it was (#268): the type's first line says how many of how many, as its library draws.
const draw = drawOf(type, params)
if (draw && draw.shown < draw.total) {
const { shown, total, fixed, what } = draw
emit(depth, !fixed ? `Shows ${shown} of the ${total} ${what} each time, drawn at random`
: shown === fixed ? `Shows only the ${fixed} ${what} fixed on the grid, of ${total}`
: `Shows ${shown} of the ${total} ${what} each time: the ${fixed} fixed on the grid, and ${shown - fixed} drawn at random`)
}
}
for (const field of fields) walk(field, params[field.name], depth, type, path ? `${path}.${field.name}` : field.name, bare, params)
}

Expand Down
Loading