Bento, the office suite that fits in a file
TypeScript mit-licenseofficeoffice-365office-suiteoffice-toolsoffice365open-sourcepowerpointself-hostedsingle-page-appslidesslideshareslideshowslideshow-galleryslideshow-makerslideshows
Fix #54: a manually-set morph id never morphed
nyblnet8c297b01f4ce
diff --git a/slides/src/editor/panels.ts b/slides/src/editor/panels.tsindex 57c07c18..250a1896 100644--- a/slides/src/editor/panels.ts+++ b/slides/src/editor/panels.ts@@ -5,7 +5,7 @@// into a single undo checkpoint.import type { Store } from '../store'-import { MEDIA_EMBED_BUDGET, applyChartPalette, defaultChart, uid, type ChartElement, type LineEnding, type MediaElement, type ShapeElement, type Slide, type SlideElement, type TableElement, type TextElement, type TransitionKind } from '../model'+import { MEDIA_EMBED_BUDGET, applyChartPalette, defaultChart, morphKey, uid, type ChartElement, type LineEnding, type MediaElement, type ShapeElement, type Slide, type SlideElement, type TableElement, type TextElement, type TransitionKind } from '../model'import { isMacOS } from '../screens'import { CHART_PRESETS } from '../charts'import { FONT_CHOICES, firstFamily, injectFonts } from '../fonts'@@ -459,7 +459,7 @@ export class PropsPanel {*/private buildMorphProps(el: SlideElement) {this.section(t('Morph'))- const effective = el.morphId || el.id+ const effective = morphKey(el)const warn = document.createElement('p')warn.className = 'ed-hint ed-morph-warn'@@ -515,7 +515,7 @@ export class PropsPanel {const next = clean === el.id ? undefined : cleanconst effective = next ?? el.idconst clash = this.store.slide.elements.some(- (e) => e.id !== el.id && (e.morphId || e.id) === effective)+ (e) => e.id !== el.id && morphKey(e) === effective)if (clash) return t('Another element on this slide already uses that morph id.')this.mutate(el.id, (e) => {if (next === undefined) delete e.morphId@@ -529,12 +529,12 @@ export class PropsPanel {* (they'd collide) and our own default key. */private morphTargets(el: SlideElement): Array<{ key: string; label: string }> {const here = new Set(- this.store.slide.elements.filter((e) => e.id !== el.id).map((e) => e.morphId || e.id))+ this.store.slide.elements.filter((e) => e.id !== el.id).map(morphKey))const seen = new Map<string, string>()this.store.doc.slides.forEach((s, i) => {if (s.id === this.store.slide.id) returnfor (const e of s.elements) {- const key = e.morphId || e.id+ const key = morphKey(e)if (key === el.id || here.has(key) || seen.has(key)) continueseen.set(key, `${t('Slide')} ${i + 1} · ${this.morphElDesc(e)}`)}diff --git a/slides/src/model.ts b/slides/src/model.tsindex 76ffc1d8..7966f3c3 100644--- a/slides/src/model.ts+++ b/slides/src/model.ts@@ -479,6 +479,19 @@ export const uid = (prefix = 'el') =>export const FONT_STACK ="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif"+/**+ * An element's effective morph key: the `morphId` override when set, else its+ * own `id`. THE single definition — render.ts stamps it into `data-flip-id`,+ * present.ts pairs and looks up model frames by it, and the panel uses it for+ * collision checks. Computing it inline in more than one place is exactly how+ * issue #54 happened: present.ts's model map keyed by `id` while every lookup+ * passed a flip id, so any element carrying a `morphId` silently missed and+ * never morphed. Route every morph-key read through here.+ */+export function morphKey(el: Pick<ElementBase, 'id' | 'morphId'>): string {+ return el.morphId || el.id+}+/** True when a background reads as light (so it wants dark text on top). Accepts* a #rrggbb hex; for a gradient/CSS string it samples the first hex it finds and* falls back to "light" (the safe assumption for the model's dark default ink). */diff --git a/slides/src/present.ts b/slides/src/present.tsindex d57bfae6..e223b351 100644--- a/slides/src/present.ts+++ b/slides/src/present.ts@@ -9,6 +9,7 @@ import 'reveal.js/dist/reveal.css'import { anim, resetXform } from './anim'import { chartSnapshotSvg, mountChart } from './charts'import type { BentoDoc, GradientFill, ShapeElement, Slide, SlideElement } from './model'+import { morphKey } from './model'import { applyElementFrame, gradientLineCoords, renderSlide } from './render'import { paintSpeaker, setSpeakerWindow, speakerIdleBody, speakerWindow } from './screens'import { t } from './i18n'@@ -921,9 +922,17 @@ function elementsById(root: HTMLElement): Map<string, HTMLElement> {return map}-function modelById(doc: BentoDoc, index: number): Map<string, SlideElement> {+/**+ * Model frames keyed by MORPH KEY, not by `id` — every caller looks these up+ * with a `data-flip-id`, which is `morphId || id`. Keying by `id` meant any+ * element carrying a `morphId` missed its own model entry, so `runMorph` hit+ * `if (!a || !b) continue` and skipped the tween: the DOM paired correctly and+ * then nothing animated (issue #54). Same-slide keys are unique — the panel+ * rejects a `morphId` that collides on the slide — so this stays 1:1.+ */+function modelByMorphKey(doc: BentoDoc, index: number): Map<string, SlideElement> {const map = new Map<string, SlideElement>()- for (const el of doc.slides[index]?.elements ?? []) map.set(el.id, el)+ for (const el of doc.slides[index]?.elements ?? []) map.set(morphKey(el), el)return map}@@ -936,8 +945,8 @@ function runMorph() {const fromEls = elementsById(fromSection)const toEls = elementsById(toSection)- const fromModel = modelById(doc, fromIdx)- const toModel = modelById(doc, toIdx)+ const fromModel = modelByMorphKey(doc, fromIdx)+ const toModel = modelByMorphKey(doc, toIdx)const matchedFrom: HTMLElement[] = []const matchedTo: HTMLElement[] = []diff --git a/slides/src/render.ts b/slides/src/render.tsindex 490a8bd1..c3df9445 100644--- a/slides/src/render.ts+++ b/slides/src/render.ts@@ -4,6 +4,7 @@// editor canvas, sidebar thumbnails, and Reveal.js sections.import type { BentoDoc, ShapeElement, Slide, SlideElement, SvgElement, TableElement } from './model'+import { morphKey } from './model'import { chartSnapshotSvg } from './charts'const SVG_NS = 'http://www.w3.org/2000/svg'@@ -412,7 +413,7 @@ export function renderElement(el: SlideElement, doc: BentoDoc, opts: RenderOptsconst node = document.createElement('div')node.className = `bento-el bento-el-${el.type}`node.dataset.elId = el.id- node.dataset.flipId = el.morphId || el.id+ node.dataset.flipId = morphKey(el)if (el.link) node.dataset.link = el.linkif (el.group) node.dataset.group = el.groupif (el.showOnHover) node.dataset.showOnHover = el.showOnHover