|
@@ -173,6 +173,7 @@ export function getAiPptImageAspectRatios(templateId: AiCoursewareTemplateId): R
|
|
|
ratios.model_design_v3 = 1 // 完整示范、判断标准及结构化教学图示。
|
|
ratios.model_design_v3 = 1 // 完整示范、判断标准及结构化教学图示。
|
|
|
ratios.model_design_v4 = 1 // 整课一致性复核与内容驱动的图片尺寸。
|
|
ratios.model_design_v4 = 1 // 整课一致性复核与内容驱动的图片尺寸。
|
|
|
ratios.model_design_v5 = 1 // 按拍分组、学生范例和内容复核完成状态。
|
|
ratios.model_design_v5 = 1 // 按拍分组、学生范例和内容复核完成状态。
|
|
|
|
|
+ ratios.model_design_v6 = 1 // 学生文字预算、去重及混合声音属性检查。
|
|
|
return ratios
|
|
return ratios
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -188,13 +189,19 @@ function fillDesignedPage(master: TemplateMaster, layout: TemplateMasterPage, pa
|
|
|
const composition = page.visualPlan!.composition
|
|
const composition = page.visualPlan!.composition
|
|
|
const presentation = page.visualPlan!.textPresentation || 'plain'
|
|
const presentation = page.visualPlan!.textPresentation || 'plain'
|
|
|
const paintText = (slot: TemplateSlot | undefined, values: string[], format = presentation) => {
|
|
const paintText = (slot: TemplateSlot | undefined, values: string[], format = presentation) => {
|
|
|
|
|
+ if (!slot || !values.length) return
|
|
|
if (slot?.textFlow === 'columns' && values.length) {
|
|
if (slot?.textFlow === 'columns' && values.length) {
|
|
|
const width = (slot.width - 28 * (values.length - 1)) / values.length
|
|
const width = (slot.width - 28 * (values.length - 1)) / values.length
|
|
|
for (let index = 0; index < values.length; index++) addSlotText(elements, { ...slot, left: slot.left + index * (width + 28), width,
|
|
for (let index = 0; index < values.length; index++) addSlotText(elements, { ...slot, left: slot.left + index * (width + 28), width,
|
|
|
preferredFontSize: 38 }, values[index], master.textColor)
|
|
preferredFontSize: 38 }, values[index], master.textColor)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- if (slot) slot = compactTextSlot(slot, values, format)
|
|
|
|
|
|
|
+ // 卡片放不下时改成按文字高度排布的列表,不再把最小字号塞进过小的卡片。
|
|
|
|
|
+ if (aiPptBlockHeight(values, slot.width, format) > slot.height || format === 'plain') {
|
|
|
|
|
+ addMeasuredFlow(elements, slot, values, master.textColor, format === 'steps')
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ slot = compactTextSlot(slot, values, format)
|
|
|
if (format === 'steps') addStepGrid(elements, slot, values, master, palette)
|
|
if (format === 'steps') addStepGrid(elements, slot, values, master, palette)
|
|
|
else if (format === 'grid') addCardGrid(elements, slot, values, master, palette)
|
|
else if (format === 'grid') addCardGrid(elements, slot, values, master, palette)
|
|
|
else if (format === 'cards' && values.length === 4 && slot && slot.width >= 1000) addCardGrid(elements, slot, values, master, palette, 2)
|
|
else if (format === 'cards' && values.length === 4 && slot && slot.width >= 1000) addCardGrid(elements, slot, values, master, palette, 2)
|
|
@@ -205,9 +212,29 @@ function fillDesignedPage(master: TemplateMaster, layout: TemplateMasterPage, pa
|
|
|
const paintBody = (slot: TemplateSlot) => {
|
|
const paintBody = (slot: TemplateSlot) => {
|
|
|
if (!content.steps.length || !points.length) { paintText(slot, [...content.steps, ...points]); return }
|
|
if (!content.steps.length || !points.length) { paintText(slot, [...content.steps, ...points]); return }
|
|
|
const pointsHeight = aiPptBlockHeight(points, slot.width, 'plain')
|
|
const pointsHeight = aiPptBlockHeight(points, slot.width, 'plain')
|
|
|
- const stepsHeight = Math.min(aiPptBlockHeight(content.steps, slot.width, presentation), slot.height - pointsHeight - 24)
|
|
|
|
|
- paintText({ ...slot, height: stepsHeight }, content.steps)
|
|
|
|
|
- paintText({ ...slot, top: slot.top + stepsHeight + 24, height: slot.height - stepsHeight - 24 }, points, 'plain')
|
|
|
|
|
|
|
+ const stepsHeight = aiPptBlockHeight(content.steps, slot.width, presentation)
|
|
|
|
|
+ if (stepsHeight + pointsHeight + 24 <= slot.height) {
|
|
|
|
|
+ paintText({ ...slot, height: stepsHeight }, content.steps)
|
|
|
|
|
+ paintText({ ...slot, top: slot.top + stepsHeight + 24, height: pointsHeight }, points, 'plain')
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ // 长步骤与分工并列,完整范例占底部一行;同一次测量同时决定坐标和字号。
|
|
|
|
|
+ const examples = points.filter(text => text.startsWith('例子:'))
|
|
|
|
|
+ const details = points.filter(text => !text.startsWith('例子:'))
|
|
|
|
|
+ const leftWidth = (slot.width - 40) * .55, rightWidth = slot.width - leftWidth - 40
|
|
|
|
|
+ if (details.length && leftWidth >= 400 && rightWidth >= 360) {
|
|
|
|
|
+ for (const font of [38, 36, 34, 32, 30, 28]) {
|
|
|
|
|
+ const exampleHeight = flowHeight(examples, slot.width, font)
|
|
|
|
|
+ const available = slot.height - exampleHeight - (examples.length ? 24 : 0)
|
|
|
|
|
+ if (Math.max(flowHeight(content.steps, leftWidth, font, true), flowHeight(details, rightWidth, font)) > available) continue
|
|
|
|
|
+ addMeasuredFlow(elements, { ...slot, width: leftWidth, height: available }, content.steps, master.textColor, true, font)
|
|
|
|
|
+ addMeasuredFlow(elements, { ...slot, left: slot.left + leftWidth + 40, width: rightWidth, height: available }, details, master.textColor, false, font)
|
|
|
|
|
+ if (examples.length) addMeasuredFlow(elements, { ...slot, top: slot.top + available + 24, height: exampleHeight }, examples, master.textColor, false, font)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 最后使用全宽短行;绝不截字。容量仍不足时,最终几何检查拒绝写入编辑器。
|
|
|
|
|
+ addMeasuredFlow(elements, slot, [...content.steps.map((text, i) => `${i + 1}. ${text}`), ...points], master.textColor)
|
|
|
}
|
|
}
|
|
|
const focusBody = slotOf(layout, 'body')
|
|
const focusBody = slotOf(layout, 'body')
|
|
|
if (composition === 'focus_question' && page.interaction?.options?.length && !hasImage(page)
|
|
if (composition === 'focus_question' && page.interaction?.options?.length && !hasImage(page)
|
|
@@ -269,6 +296,23 @@ function fillDesignedPage(master: TemplateMaster, layout: TemplateMasterPage, pa
|
|
|
return elements
|
|
return elements
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function flowHeight(values: string[], width: number, font: number, numbered = false) {
|
|
|
|
|
+ return values.reduce((sum, text, i) => sum + measureAiPptText(numbered ? `${i + 1}. ${text}` : text, width, font), 0)
|
|
|
|
|
+ + Math.max(0, values.length - 1) * 16
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function addMeasuredFlow(elements: PPTElement[], slot: TemplateSlot, values: string[], color: string, numbered = false, preferred = 38) {
|
|
|
|
|
+ const font = Array.from({ length: Math.max(1, Math.floor((preferred - 28) / 2) + 1) }, (_, i) => preferred - i * 2)
|
|
|
|
|
+ .find(size => flowHeight(values, slot.width, size, numbered) <= slot.height) || 28
|
|
|
|
|
+ let top = slot.top
|
|
|
|
|
+ values.forEach((value, i) => {
|
|
|
|
|
+ const text = numbered ? `${i + 1}. ${value}` : value
|
|
|
|
|
+ const height = measureAiPptText(text, slot.width, font)
|
|
|
|
|
+ elements.push(textElement({ left: slot.left, top, width: slot.width, height, content: text, fontSize: font, minimumFontSize: font, color }))
|
|
|
|
|
+ top += height + 16
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
export function validTeachingDiagram(diagram: NonNullable<AiCoursewarePage['diagram']>) {
|
|
export function validTeachingDiagram(diagram: NonNullable<AiCoursewarePage['diagram']>) {
|
|
|
return ['beats', 'rhythm', 'duration', 'pitch', 'sequence'].includes(diagram.kind) && Array.isArray(diagram.items) && diagram.items.length >= 2 && diagram.items.length <= 6
|
|
return ['beats', 'rhythm', 'duration', 'pitch', 'sequence'].includes(diagram.kind) && Array.isArray(diagram.items) && diagram.items.length >= 2 && diagram.items.length <= 6
|
|
|
&& diagram.items.every(item => item?.label?.trim() && item.label.length <= 12)
|
|
&& diagram.items.every(item => item?.label?.trim() && item.label.length <= 12)
|
|
@@ -285,13 +329,18 @@ function addTeachingDiagram(elements: PPTElement[], slot: TemplateSlot, diagram:
|
|
|
const min = Math.min(...diagram.items.map(item => item.value || 1))
|
|
const min = Math.min(...diagram.items.map(item => item.value || 1))
|
|
|
const column = (slot.width - gap * (count - 1)) / count
|
|
const column = (slot.width - gap * (count - 1)) / count
|
|
|
const shapeHeight = Math.min(150, area.height - 80)
|
|
const shapeHeight = Math.min(150, area.height - 80)
|
|
|
|
|
+ const labels = diagram.items.map(item => item.label)
|
|
|
|
|
+ // 兼容已生成的混合概念图:强弱用大小,长短用长度;不同属性不能共用圆面积或数值比例。
|
|
|
|
|
+ const mixedSoundConcepts = labels.every(label => ['强', '弱', '长', '短'].includes(label))
|
|
|
|
|
+ && labels.some(label => ['强', '弱'].includes(label)) && labels.some(label => ['长', '短'].includes(label))
|
|
|
let left = slot.left
|
|
let left = slot.left
|
|
|
diagram.items.forEach((item, index) => {
|
|
diagram.items.forEach((item, index) => {
|
|
|
- const width = diagram.kind === 'duration' ? (slot.width - gap * (count - 1)) * item.value! / total : column
|
|
|
|
|
- const size = diagram.kind === 'beats' ? Math.min(width - 24, shapeHeight) * Math.sqrt(item.value! / max) : shapeHeight
|
|
|
|
|
|
|
+ const kind = mixedSoundConcepts ? ['强', '弱'].includes(item.label) ? 'beats' : 'duration' : diagram.kind
|
|
|
|
|
+ const width = !mixedSoundConcepts && kind === 'duration' ? (slot.width - gap * (count - 1)) * item.value! / total : column
|
|
|
|
|
+ const size = kind === 'beats' ? Math.min(width - 24, shapeHeight) * (mixedSoundConcepts ? item.label === '强' ? 1 : .5 : Math.sqrt(item.value! / max)) : shapeHeight
|
|
|
const top = area.top + Math.max(0, (area.height - shapeHeight - 68) / 2)
|
|
const top = area.top + Math.max(0, (area.height - shapeHeight - 68) / 2)
|
|
|
const color = index % 2 ? palette.secondary : palette.primary
|
|
const color = index % 2 ? palette.secondary : palette.primary
|
|
|
- if (diagram.kind === 'rhythm') {
|
|
|
|
|
|
|
+ if (kind === 'rhythm') {
|
|
|
// 每个等宽格是一拍;圆点数只表示该拍内的发声次数,不用大小或颜色暗示强弱。
|
|
// 每个等宽格是一拍;圆点数只表示该拍内的发声次数,不用大小或颜色暗示强弱。
|
|
|
const sounds = item.value!, dotSize = Math.min(54, (width - 32) / (sounds * 1.5), shapeHeight - 18)
|
|
const sounds = item.value!, dotSize = Math.min(54, (width - 32) / (sounds * 1.5), shapeHeight - 18)
|
|
|
elements.push(shapeElement({ left, top, width, height: shapeHeight, fill: palette.soft, radius: 10 }))
|
|
elements.push(shapeElement({ left, top, width, height: shapeHeight, fill: palette.soft, radius: 10 }))
|
|
@@ -301,18 +350,19 @@ function addTeachingDiagram(elements: PPTElement[], slot: TemplateSlot, diagram:
|
|
|
circle.path = 'M100,0 A100,100 0 1,1 99.99,0 Z'
|
|
circle.path = 'M100,0 A100,100 0 1,1 99.99,0 Z'
|
|
|
elements.push(circle)
|
|
elements.push(circle)
|
|
|
}
|
|
}
|
|
|
- } else if (diagram.kind === 'pitch') {
|
|
|
|
|
|
|
+ } else if (kind === 'pitch') {
|
|
|
const y = area.top + 28 + (max - item.value!) / Math.max(1, max - min) * Math.max(0, area.height - 146)
|
|
const y = area.top + 28 + (max - item.value!) / Math.max(1, max - min) * Math.max(0, area.height - 146)
|
|
|
elements.push(shapeElement({ left, top: y, width, height: 10, fill: color }))
|
|
elements.push(shapeElement({ left, top: y, width, height: 10, fill: color }))
|
|
|
addSlotText(elements, { ...slot, left, top: y + 16, width, height: 64, preferredFontSize: 40 }, item.label, master.textColor, true, 'center')
|
|
addSlotText(elements, { ...slot, left, top: y + 16, width, height: 64, preferredFontSize: 40 }, item.label, master.textColor, true, 'center')
|
|
|
left += width + gap
|
|
left += width + gap
|
|
|
return
|
|
return
|
|
|
- } else if (diagram.kind === 'beats') {
|
|
|
|
|
|
|
+ } else if (kind === 'beats') {
|
|
|
const circle = shapeElement({ left: left + (width - size) / 2, top: top + (shapeHeight - size) / 2, width: size, height: size, fill: color })
|
|
const circle = shapeElement({ left: left + (width - size) / 2, top: top + (shapeHeight - size) / 2, width: size, height: size, fill: color })
|
|
|
circle.path = 'M100,0 A100,100 0 1,1 99.99,0 Z'
|
|
circle.path = 'M100,0 A100,100 0 1,1 99.99,0 Z'
|
|
|
elements.push(circle)
|
|
elements.push(circle)
|
|
|
- } else if (diagram.kind === 'duration') {
|
|
|
|
|
- elements.push(shapeElement({ left, top: top + shapeHeight * .25, width, height: shapeHeight * .5, fill: color, radius: 8 }))
|
|
|
|
|
|
|
+ } else if (kind === 'duration') {
|
|
|
|
|
+ const barWidth = mixedSoundConcepts ? width * (item.label === '长' ? .95 : .4) : width
|
|
|
|
|
+ elements.push(shapeElement({ left: left + (width - barWidth) / 2, top: top + shapeHeight * .25, width: barWidth, height: shapeHeight * .5, fill: color, radius: 8 }))
|
|
|
} else {
|
|
} else {
|
|
|
elements.push(lineElement(left, top + shapeHeight / 2, left + width, top + shapeHeight / 2, palette.secondary, 4))
|
|
elements.push(lineElement(left, top + shapeHeight / 2, left + width, top + shapeHeight / 2, palette.secondary, 4))
|
|
|
addSlotText(elements, { ...slot, left, top, width, height: 65, preferredFontSize: 44 }, String(index + 1).padStart(2, '0'), palette.primary, true)
|
|
addSlotText(elements, { ...slot, left, top, width, height: 65, preferredFontSize: 44 }, String(index + 1).padStart(2, '0'), palette.primary, true)
|