@lincyaw/kernel 1.0.0-rc.40 → 1.0.0-rc.41
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/package.json
CHANGED
|
@@ -8,7 +8,7 @@ import type { DocumentChangePlan } from './authoring.ts'
|
|
|
8
8
|
|
|
9
9
|
export const DOCUMENT_ACTION_MAX_REQUEST_CHARS = 4096
|
|
10
10
|
export const DOCUMENT_ACTION_MAX_RESPONSE_CHARS = 7168
|
|
11
|
-
export const DOCUMENT_AUTHORING_ACTION_TYPES = ['comment.create', 'comment.reply', 'comment.update', 'comment.react', 'comment.resolve', 'comment.reopen', 'comment.delete', 'voice.set', 'component.parameters.patch', 'component.step-parameters.patch', 'component.step-parameters.reset', 'component.definition.use', 'caption.timing.set', 'caption.timing.reset'] as const
|
|
11
|
+
export const DOCUMENT_AUTHORING_ACTION_TYPES = ['comment.create', 'comment.reply', 'comment.update', 'comment.react', 'comment.resolve', 'comment.reopen', 'comment.delete', 'voice.set', 'component.parameters.patch', 'component.step-parameters.patch', 'component.step-parameters.reset', 'component.definition.use', 'caption.timing.set', 'caption.timing.reset', 'caption.scale.set'] as const
|
|
12
12
|
export const DOCUMENT_PARAMETER_MAX_CHANGES = 32
|
|
13
13
|
export const DOCUMENT_PARAMETER_MAX_PATH_DEPTH = 16
|
|
14
14
|
/** Paths belong only to this component's parameters; set replaces an array item or appends at its length. */
|
|
@@ -39,9 +39,9 @@ export interface DocumentComponentImpactAnswer {
|
|
|
39
39
|
collection: DocumentComponentImpactCollection, offset: number, total: number, entries: string[], nextOffset?: number, complete: boolean
|
|
40
40
|
}
|
|
41
41
|
/** New recording adoption belongs to the real-media service, never a raw settings action. */
|
|
42
|
-
export type DocumentAuthoringAction = DocumentCommentAction | DocumentComponentAction | DocumentCaptionTimingAction | { type: 'voice.set', scope: DocumentVoiceScope, source: Exclude<VoiceSource, { type: 'recording' }> | null, replaceOverrides?: boolean }
|
|
42
|
+
export type DocumentAuthoringAction = DocumentCommentAction | DocumentComponentAction | DocumentCaptionTimingAction | { type: 'caption.scale.set', scale: number } | { type: 'voice.set', scope: DocumentVoiceScope, source: Exclude<VoiceSource, { type: 'recording' }> | null, replaceOverrides?: boolean }
|
|
43
43
|
export interface DocumentAuthoringActionRequest { id: string, source: CanonicalSource, action: DocumentAuthoringAction }
|
|
44
|
-
export type DocumentAuthoringActionEffect = { kind: 'caption', value: { stepId: string, segments: number, changed: boolean, mode: 'manual' | 'automatic' } } | { kind: 'comment', value: DocumentCommentEffect } | { kind: 'voice', scope: DocumentVoiceScope['kind'], value: DocumentVoiceImpact, recordings: { preserved: number, removed: number } } | { kind: 'component', value: DocumentComponentEffect }
|
|
44
|
+
export type DocumentAuthoringActionEffect = { kind: 'caption-scale', value: { scale: number, changed: boolean } } | { kind: 'caption', value: { stepId: string, segments: number, changed: boolean, mode: 'manual' | 'automatic' } } | { kind: 'comment', value: DocumentCommentEffect } | { kind: 'voice', scope: DocumentVoiceScope['kind'], value: DocumentVoiceImpact, recordings: { preserved: number, removed: number } } | { kind: 'component', value: DocumentComponentEffect }
|
|
45
45
|
export interface DocumentAuthoringActionPlan extends DocumentChangePlan {
|
|
46
46
|
action: DocumentAuthoringAction
|
|
47
47
|
effect: DocumentAuthoringActionEffect
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { applyDocumentCaptionTiming } from './document-caption-timings.ts'
|
|
2
|
+
import { captionScale, changeDocumentCaptionScale } from './document-caption-scale.ts'
|
|
2
3
|
import { hasRole } from './access.ts'
|
|
3
4
|
import { applyDocumentCommentAction, degradeDocumentCommentAnchor, DocumentCommentError, validateDocumentCommentAnchor } from './document-comments.ts'
|
|
4
5
|
import { documentAnchorKey } from './document-places.ts'
|
|
@@ -11,6 +12,10 @@ import type { TeachingDocument } from './contracts/document.ts'
|
|
|
11
12
|
/** Fixed context is supplied by the owning adapter exactly once per semantic plan. */
|
|
12
13
|
export function applyDocumentAuthoringAction(document: TeachingDocument, action: DocumentAuthoringAction, context: DocumentCommentContext): { content: TeachingDocument, effect: DocumentAuthoringActionEffect } {
|
|
13
14
|
if (!context.member || !hasRole(context.member, 'editor')) throw new DocumentCommentError(403, 'authoring-permission-denied')
|
|
15
|
+
if (action.type === 'caption.scale.set') {
|
|
16
|
+
const content = changeDocumentCaptionScale(document, action.scale)
|
|
17
|
+
return { content, effect: { kind: 'caption-scale', value: { scale: captionScale(content.production), changed: content !== document } } }
|
|
18
|
+
}
|
|
14
19
|
if (action.type === 'component.parameters.patch' || action.type === 'component.step-parameters.patch' || action.type === 'component.step-parameters.reset' || action.type === 'component.definition.use') {
|
|
15
20
|
const { content, effect } = applyDocumentComponentAction(document, action)
|
|
16
21
|
return { content, effect: { kind: 'component', value: effect } }
|
|
@@ -31,3 +31,27 @@ export function replaceStepNarrations(source: TeachingDocument, stepId: string,
|
|
|
31
31
|
for (const id of Object.keys(content.production.cueTimings ?? {})) if (!cues.has(id)) delete content.production.cueTimings![id]
|
|
32
32
|
return content
|
|
33
33
|
}
|
|
34
|
+
|
|
35
|
+
/** An exact, unique text edit keeps the existing pronunciation and cue atoms intact. */
|
|
36
|
+
export function replaceStepNarrationText(source: TeachingDocument, stepId: string, find: string, replacement: string): TeachingDocument {
|
|
37
|
+
const step = source.steps[stepId]
|
|
38
|
+
if (!step || !find) throw new Error('document-narration-target')
|
|
39
|
+
const narrations = step.narrationIds.map(id => source.narrations[id]!)
|
|
40
|
+
const matches: { narration: string, node: number, offset: number }[] = []
|
|
41
|
+
for (const narration of narrations) for (const [node, value] of narration.content.entries()) {
|
|
42
|
+
if (value.type !== 'text') continue
|
|
43
|
+
for (let at = value.text.indexOf(find); at !== -1; at = value.text.indexOf(find, at + 1)) {
|
|
44
|
+
matches.push({ narration: narration.id, node, offset: at })
|
|
45
|
+
if (matches.length > 1) throw new Error('document-narration-text-ambiguous')
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const found = matches[0]
|
|
49
|
+
if (!found) throw new Error('document-narration-text-missing')
|
|
50
|
+
return replaceStepNarrations(source, stepId, narrations.map(narration => narration.id !== found.narration ? narration : {
|
|
51
|
+
...narration, content: narration.content.flatMap((node, index) => {
|
|
52
|
+
if (index !== found.node || node.type !== 'text') return [node]
|
|
53
|
+
const text = node.text.slice(0, found.offset) + replacement + node.text.slice(found.offset + find.length)
|
|
54
|
+
return text ? [{ ...node, text }] : []
|
|
55
|
+
}),
|
|
56
|
+
}).filter(narration => narration.content.length > 0))
|
|
57
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './contracts.ts'
|
|
2
2
|
export { randomUUID } from './random-uuid.ts'
|
|
3
3
|
export { applyDocumentOperations } from './document-operations.ts'
|
|
4
|
-
export { replaceStepNarrations } from './document-narrations.ts'
|
|
4
|
+
export { replaceStepNarrations, replaceStepNarrationText } from './document-narrations.ts'
|
|
5
5
|
export { validateDocumentChange, DOCUMENT_CHANGE_JSON_SCHEMA } from './authoring.ts'
|
|
6
6
|
export { allocateDocumentPage, createDocumentPage, documentPageDefaults, DOCUMENT_PAGE_DEFAULT_TIMING, duplicateDocumentPage, moveDocumentPage, pageContents, pageDeletion, pageDeletionImpact, removeDocumentPage, renameDocumentPage } from './document-pages.ts'
|
|
7
7
|
export { documentOutline, documentPart, DocumentReadError } from './document-reads.ts'
|
|
@@ -33,6 +33,7 @@ export const DOCUMENT_AUTHORING_ACTION_SCHEMA: Schema = {
|
|
|
33
33
|
action('voice.set', { scope, source: voice, replaceOverrides: { type: 'boolean' } }, ['scope', 'source']),
|
|
34
34
|
action('caption.timing.set', { stepId: id, value: { $ref: '#/$defs/CaptionTiming' } }),
|
|
35
35
|
action('caption.timing.reset', { stepId: id }),
|
|
36
|
+
action('caption.scale.set', { scale: { type: 'number' } }),
|
|
36
37
|
action('component.parameters.patch', { blockId: id, changes }),
|
|
37
38
|
action('component.step-parameters.patch', { blockId: id, stepId: id, changes }),
|
|
38
39
|
action('component.step-parameters.reset', { blockId: id, stepId: id }),
|