Bento, the office suite that fits in a file
TypeScript mit-licenseofficeoffice-365office-suiteoffice-toolsoffice365open-sourcepowerpointself-hostedsingle-page-appslidesslideshareslideshowslideshow-galleryslideshow-makerslideshows
Replace GSAP with in-house animation engine; ship license NOTICE
nyblnet721c2b58f3a2
diff --git a/CLAUDE.md b/CLAUDE.mdindex 1a16a062..c540e861 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -11,11 +11,18 @@ One HTML file = the document + viewer + editor. See `README.md` for the vision.never contain `</script>`. File System Access API first, download fallback.- `src/render.ts` — single model→DOM renderer shared by editor canvas, thumbnails, andReveal sections. Elements carry `data-el-id` (editing) and `data-flip-id` (morph).-- `src/present.ts` — Reveal.js overlay; slides with `transition:'morph'` use GSAP Flip:- matched `data-flip-id` elements animate geometry via Flip, style props (fill/color)- tween straight from the model values — including gradients (stop colors + line- coords tween; solid⇄gradient fabricates/collapses a temp gradient; from-colors- are the other side sampled at matching stop positions). Elements carry `fx` (enter stagger — equal+- `src/anim.ts` — in-house animation engine (no GSAP): to/fromTo tweens with+ channels opacity/y/scale/color/strokeDashoffset/attr{}/motionPath, delay/+ repeat/yoyo/ease, per-channel overwrite, killTweensOf/getTweensOf, manual+ clock for tests (window.bento.anim). Transform channels compose via a+ per-element registry that preserves the model's rotate() — call resetXform+ after applyElementFrame or stale y/scale re-emerge on the next tween.+- `src/present.ts` — Reveal.js overlay; slides with `transition:'morph'` morph+ matched `data-flip-id` elements MODEL-driven (both frames are in the doc —+ no DOM measuring): translate+scale about top-left, PowerPoint scale mode.+ Style props (fill/color) tween straight from the model values — including+ gradients (stop colors + line coords tween; solid⇄gradient fabricates/+ collapses a temp gradient; from-colors sampled at matching stop positions). Elements carry `fx` (enter stagger — equal`order` = simultaneous, countUp, ken-burns (`fx.ken` dir drift/out/in + zoom %/secs;out/in are one-shot settles per slide entry), `loop` dash-march/motion-path), `link`(click → slide id) and `group`; slides can set `hover:'focus-group'` (dim otherdiff --git a/slides/index.html b/slides/index.htmlindex 845f47b6..7ae72503 100644--- a/slides/index.html+++ b/slides/index.html@@ -6,6 +6,31 @@<meta name="generator" content="bento-slides" /><link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect x='2' y='2' width='28' height='28' rx='6' fill='%231E2A3A'/%3E%3Crect x='6' y='6' width='6' height='20' rx='2' fill='%235B8DEF'/%3E%3Crect x='14' y='6' width='12' height='9' rx='2' fill='%23F7A600'/%3E%3Crect x='14' y='17' width='12' height='9' rx='2' fill='%23E9EDF3'/%3E%3C/svg%3E" /><title>Bento Slides</title>+ <!--+ NOTICE — bundled open-source components. This file embeds the following+ libraries, whose licenses require that these notices accompany copies+ (every saved Bento document carries this block):++ reveal.js — Copyright (C) Hakim El Hattab and contributors — MIT License+ moveable, selecto and their @daybrush/@scena/@egjs/@cfcs modules —+ Copyright (c) Daybrush (Younkue Choi) — MIT License++ MIT License: Permission is hereby granted, free of charge, to any person+ obtaining a copy of this software and associated documentation files (the+ "Software"), to deal in the Software without restriction, including+ without limitation the rights to use, copy, modify, merge, publish,+ distribute, sublicense, and/or sell copies of the Software, and to permit+ persons to whom the Software is furnished to do so, subject to the+ following conditions: The above copyright notice and this permission+ notice shall be included in all copies or substantial portions of the+ Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.+ --><!--Bento document data lives in the script block below. The runtime replaces itscontents on every save, so this one file is both the app and the document.diff --git a/slides/package-lock.json b/slides/package-lock.jsonindex d9ff7251..fba6b2d4 100644--- a/slides/package-lock.json+++ b/slides/package-lock.json@@ -8,7 +8,6 @@"name": "bento-slides","version": "0.1.0","dependencies": {- "gsap": "^3.12.7","moveable": "^0.53.0","reveal.js": "^5.2.1","selecto": "^1.26.3"@@ -1128,12 +1127,6 @@"@scena/event-emitter": "^1.0.2"}},- "node_modules/gsap": {- "version": "3.15.0",- "resolved": "https://registry.npmjs.org/gsap/-/gsap-3.15.0.tgz",- "integrity": "sha512-dMW4CWBTUK1AEEDeZc1g4xpPGIrSf9fJF960qbTZmN/QwZIWY5wgliS6JWl9/25fpTGJrMRtSjGtOmPnfjZB+A==",- "license": "Standard 'no charge' license: https://gsap.com/standard-license."- },"node_modules/is-number": {"version": "7.0.0","resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",diff --git a/slides/package.json b/slides/package.jsonindex a702a88f..f76ee764 100644--- a/slides/package.json+++ b/slides/package.json@@ -10,7 +10,6 @@"preview": "vite preview"},"dependencies": {- "gsap": "^3.12.7","moveable": "^0.53.0","reveal.js": "^5.2.1","selecto": "^1.26.3"diff --git a/slides/src/anim.ts b/slides/src/anim.tsnew file mode 100644index 00000000..8f15a186--- /dev/null+++ b/slides/src/anim.ts@@ -0,0 +1,384 @@+// Bento's animation engine — the in-house replacement for GSAP, sized to+// exactly what the presenter and editor use:+// anim.to / anim.fromTo(target, vars) with channels:+// opacity, y (translate px), scale, color, strokeDashoffset,+// attr: { fill, stop-color, offset, x1..y2, … } (colors interpolate),+// motionPath: { path } (translate along an SVG path, relative),+// plain numeric props on non-element targets (countUp state objects)+// vars: duration (s), delay (s), ease ('none'|'linear'|'power1..3.in/out/+// inOut'|'sine.inOut'), repeat (-1 = forever), yoyo, transformOrigin,+// onUpdate, onComplete+// anim.killTweensOf(target | targets), anim.getTweensOf(target) → .progress()+// anim.setTimeScale(n) and manual clock (anim.manual/tick) for tests.+//+// Transform channels (y/scale/motionPath) compose through a per-element+// registry and PRESERVE the model's rotate() applied by applyElementFrame.++type EaseFn = (t: number) => number++const pow = (n: number) => ({+ in: (t: number) => t ** n,+ out: (t: number) => 1 - (1 - t) ** n,+ inOut: (t: number) => (t < 0.5 ? (2 * t) ** n / 2 : 1 - (2 - 2 * t) ** n / 2),+})++const EASES: Record<string, EaseFn> = {+ none: (t) => t,+ linear: (t) => t,+ 'power1.in': pow(2).in, 'power1.out': pow(2).out, 'power1.inOut': pow(2).inOut,+ 'power2.in': pow(3).in, 'power2.out': pow(3).out, 'power2.inOut': pow(3).inOut,+ 'power3.in': pow(4).in, 'power3.out': pow(4).out, 'power3.inOut': pow(4).inOut,+ 'sine.in': (t) => 1 - Math.cos((t * Math.PI) / 2),+ 'sine.out': (t) => Math.sin((t * Math.PI) / 2),+ 'sine.inOut': (t) => -(Math.cos(Math.PI * t) - 1) / 2,+}++// --- color + number interpolation --------------------------------------------++const parseColor = (v: string): [number, number, number, number] | null => {+ const m = v?.match(/rgba?\(([^)]+)\)/)+ if (m) {+ const p = m[1].split(/[\s,/]+/).map(Number)+ return [p[0] || 0, p[1] || 0, p[2] || 0, Number.isFinite(p[3]) ? p[3] : 1]+ }+ let hex = (v ?? '').trim()+ if (/^#[0-9a-fA-F]{3}$/.test(hex)) hex = '#' + [...hex.slice(1)].map((c) => c + c).join('')+ if (/^#[0-9a-fA-F]{6,8}$/.test(hex)) {+ return [+ parseInt(hex.slice(1, 3), 16), parseInt(hex.slice(3, 5), 16), parseInt(hex.slice(5, 7), 16),+ hex.length === 9 ? parseInt(hex.slice(7, 9), 16) / 255 : 1,+ ]+ }+ if (v === 'transparent' || v === 'none') return [0, 0, 0, 0]+ return null+}++const mixColor = (a: [number, number, number, number], b: [number, number, number, number], t: number) =>+ `rgba(${Math.round(a[0] + (b[0] - a[0]) * t)}, ${Math.round(a[1] + (b[1] - a[1]) * t)}, ${Math.round(+ a[2] + (b[2] - a[2]) * t,+ )}, ${Math.round((a[3] + (b[3] - a[3]) * t) * 1000) / 1000})`++/** value-pair → interpolator string|number */+function lerper(from: unknown, to: unknown): (t: number) => string | number {+ if (typeof from === 'number' && typeof to === 'number') return (t) => from + (to - from) * t+ const fc = parseColor(String(from))+ const tc = parseColor(String(to))+ if (fc && tc) return (t) => mixColor(fc, tc, t)+ const fn = parseFloat(String(from))+ const tn = parseFloat(String(to))+ if (Number.isFinite(fn) && Number.isFinite(tn)) return (t) => fn + (tn - fn) * t+ return (t) => (t < 1 ? String(from) : String(to))+}++// --- element transform composition --------------------------------------------++interface XForm { x: number; y: number; scaleX: number; scaleY: number; baseRotate: string }+const xforms = new WeakMap<Element, XForm>()++function xformOf(el: HTMLElement | SVGElement): XForm {+ let x = xforms.get(el)+ if (!x) {+ // preserve whatever rotate() the model frame applied (origin: center)+ const m = (el.style.transform ?? '').match(/rotate\([^)]*\)/)+ x = { x: 0, y: 0, scaleX: 1, scaleY: 1, baseRotate: m ? m[0] : '' }+ xforms.set(el, x)+ }+ return x+}++function writeXform(el: HTMLElement | SVGElement) {+ const x = xformOf(el)+ const parts: string[] = []+ if (x.x || x.y) parts.push(`translate(${x.x}px, ${x.y}px)`)+ if (x.baseRotate) parts.push(x.baseRotate)+ if (x.scaleX !== 1 || x.scaleY !== 1) parts.push(`scale(${x.scaleX}, ${x.scaleY})`)+ el.style.transform = parts.join(' ')+}++/** applyElementFrame resets style.transform — forget our composition state. */+export function resetXform(el: Element) {+ xforms.delete(el)+}++// --- motion path sampling ------------------------------------------------------++const SVG_NS = 'http://www.w3.org/2000/svg'++function samplePath(d: string): ((t: number) => { x: number; y: number }) | null {+ const svg = document.createElementNS(SVG_NS, 'svg')+ svg.style.cssText = 'position:absolute;width:0;height:0;overflow:hidden'+ const path = document.createElementNS(SVG_NS, 'path')+ path.setAttribute('d', d)+ svg.appendChild(path)+ document.body.appendChild(svg)+ let total = 0+ try { total = path.getTotalLength() } catch { /* bad path */ }+ if (!Number.isFinite(total) || total <= 0) { svg.remove(); return null }+ // pre-sample; keeps the probe svg out of the DOM during the animation+ const N = Math.min(512, Math.max(64, Math.ceil(total / 3)))+ const pts: Array<{ x: number; y: number }> = []+ for (let i = 0; i <= N; i++) {+ const p = path.getPointAtLength((total * i) / N)+ pts.push({ x: p.x, y: p.y })+ }+ svg.remove()+ return (t) => {+ const f = Math.min(Math.max(t, 0), 1) * N+ const i = Math.min(Math.floor(f), N - 1)+ const k = f - i+ return { x: pts[i].x + (pts[i + 1].x - pts[i].x) * k, y: pts[i].y + (pts[i + 1].y - pts[i].y) * k }+ }+}++// --- the tween -----------------------------------------------------------------++export interface TweenVars {+ duration?: number+ delay?: number+ ease?: string+ repeat?: number+ yoyo?: boolean+ overwrite?: string // accepted for call-site compat; overwrite is always per-channel+ transformOrigin?: string+ onUpdate?: () => void+ onComplete?: () => void+ [channel: string]: unknown+}++const CONTROL = new Set(['duration', 'delay', 'ease', 'repeat', 'yoyo', 'overwrite', 'transformOrigin', 'onUpdate', 'onComplete'])++type Apply = (t: number) => void++export class Tween {+ private applies: Apply[] = []+ private channels = new Set<string>()+ private elapsed = 0 // seconds, excludes delay+ private delay: number+ private duration: number+ private repeat: number+ private yoyo: boolean+ private ease: EaseFn+ private vars: TweenVars+ private from: Record<string, unknown> | null+ private started = false+ private dead = false+ target: unknown++ constructor(target: unknown, from: Record<string, unknown> | null, to: TweenVars) {+ this.target = target+ this.vars = to+ this.from = from+ this.duration = Math.max(to.duration ?? 0.5, 0.0001)+ this.delay = to.delay ?? 0+ this.repeat = to.repeat ?? 0+ this.yoyo = !!to.yoyo+ this.ease = EASES[to.ease ?? 'power1.out'] ?? EASES.linear+ register(this)+ // fromTo renders its from-state immediately (gsap immediateRender parity)+ if (from) this.start()+ tickerOn()+ }++ /** Build interpolators. With explicit from-values this runs at creation;+ * otherwise lazily when the delay elapses (reading current values). */+ private start() {+ if (this.started || this.dead) return+ this.started = true+ const t = this.target+ const from = this.from ?? {}+ const isEl = t instanceof HTMLElement || t instanceof SVGElement+ for (const [key, toVal] of Object.entries(this.vars)) {+ if (CONTROL.has(key) || toVal === undefined) continue+ this.channels.add(key)+ if (!isEl) {+ // plain object tween (countUp state)+ const obj = t as Record<string, number>+ const f = (from[key] as number) ?? obj[key] ?? 0+ const lerp = lerper(f, toVal as number)+ this.applies.push((p) => { obj[key] = lerp(p) as number })+ continue+ }+ const el = t as HTMLElement+ if (key === 'opacity') {+ const f = from.opacity ?? parseFloat(getComputedStyle(el).opacity) ?? 1+ const lerp = lerper(Number(f), Number(toVal))+ this.applies.push((p) => { el.style.opacity = String(lerp(p)) })+ } else if (key === 'y') {+ const x = xformOf(el)+ const f = Number(from.y ?? x.y)+ const lerp = lerper(f, Number(toVal))+ this.applies.push((p) => { x.y = lerp(p) as number; writeXform(el) })+ } else if (key === 'scale') {+ const x = xformOf(el)+ const f = Number(from.scale ?? x.scaleX)+ const lerp = lerper(f, Number(toVal))+ if (this.vars.transformOrigin) el.style.transformOrigin = String(this.vars.transformOrigin)+ this.applies.push((p) => { const s = lerp(p) as number; x.scaleX = s; x.scaleY = s; writeXform(el) })+ } else if (key === 'color') {+ const f = String(from.color ?? getComputedStyle(el).color)+ const lerp = lerper(f, String(toVal))+ this.applies.push((p) => { el.style.color = String(lerp(p)) })+ } else if (key === 'strokeDashoffset') {+ const f = from.strokeDashoffset ?? getComputedStyle(el).strokeDashoffset+ const lerp = lerper(parseFloat(String(f)) || 0, Number(toVal))+ this.applies.push((p) => { el.style.strokeDashoffset = String(lerp(p)) })+ } else if (key === 'attr') {+ const toAttrs = toVal as Record<string, string | number>+ const fromAttrs = (from.attr ?? {}) as Record<string, string | number>+ for (const [name, tv] of Object.entries(toAttrs)) {+ const fv = fromAttrs[name] ?? el.getAttribute(name) ?? 0+ const lerp = lerper(fv, tv)+ this.applies.push((p) => el.setAttribute(name, String(lerp(p))))+ }+ } else if (key === 'motionPath') {+ const d = (toVal as { path: string }).path+ const sample = samplePath(d)+ if (sample) {+ const x = xformOf(el)+ this.applies.push((p) => {+ const pt = sample(p)+ x.x = pt.x+ x.y = pt.y+ writeXform(el)+ })+ }+ }+ }+ // per-channel overwrite: a newer tween on the same target owns its channels+ for (const other of tweensOf(this.target)) {+ if (other === this || other.dead) continue+ if ([...this.channels].some((c) => other.channels.has(c))) other.kill()+ }+ this.applies.forEach((a) => a(0))+ }++ /** 0..1 across the whole lifetime (repeats count as complete). */+ progress(): number {+ if (this.dead) return 1+ if (this.repeat === -1) return 0+ const total = this.duration * (1 + this.repeat)+ return Math.min(this.elapsed / total, 1)+ }++ /** advance by dt seconds; returns false when finished */+ tick(dt: number): boolean {+ if (this.dead) return false+ if (this.delay > 0) {+ this.delay -= dt+ if (this.delay > 0) return true+ dt = -this.delay+ this.delay = 0+ }+ if (!this.started) this.start()+ this.elapsed += dt+ const cycles = this.elapsed / this.duration+ const isForever = this.repeat === -1+ const done = !isForever && cycles >= 1 + this.repeat+ let t: number+ if (done) {+ t = this.yoyo && (1 + this.repeat) % 2 === 0 ? 0 : 1+ } else {+ const c = Math.floor(cycles)+ const frac = cycles - c+ t = this.yoyo && c % 2 === 1 ? 1 - frac : frac+ }+ const eased = this.ease(t)+ for (const a of this.applies) a(eased)+ this.vars.onUpdate?.()+ if (done) {+ this.dead = true+ unregister(this)+ this.vars.onComplete?.()+ return false+ }+ return true+ }++ kill() {+ if (this.dead) return+ this.dead = true+ unregister(this)+ }+}++// --- registry + ticker -----------------------------------------------------------++const live = new Set<Tween>()+const byTarget = new Map<unknown, Set<Tween>>()++function register(tw: Tween) {+ live.add(tw)+ let set = byTarget.get(tw.target)+ if (!set) byTarget.set(tw.target, (set = new Set()))+ set.add(tw)+}++function unregister(tw: Tween) {+ live.delete(tw)+ const set = byTarget.get(tw.target)+ set?.delete(tw)+ if (set && !set.size) byTarget.delete(tw.target)+}++function tweensOf(target: unknown): Tween[] {+ return [...(byTarget.get(target) ?? [])]+}++let running = false+let last = 0+let timeScale = 1+let manual = false++function tickerOn() {+ if (running || manual) return+ running = true+ last = performance.now()+ requestAnimationFrame(loop)+}++function loop(now: number) {+ if (manual) { running = false; return }+ // clamp long gaps (throttled tabs) so loops don't leap wildly+ const dt = Math.min((now - last) / 1000, 0.25) * timeScale+ last = now+ for (const tw of [...live]) tw.tick(dt)+ if (live.size) requestAnimationFrame(loop)+ else running = false+}++// --- public api --------------------------------------------------------------------++export const anim = {+ to(target: unknown, vars: TweenVars): Tween {+ return new Tween(target, null, vars)+ },+ fromTo(target: unknown, from: Record<string, unknown>, vars: TweenVars): Tween {+ return new Tween(target, from, vars)+ },+ killTweensOf(target: unknown) {+ const targets: unknown[] =+ target instanceof NodeList || Array.isArray(target) ? [...(target as Iterable<unknown>)] : [target]+ for (const t of targets) for (const tw of tweensOf(t)) tw.kill()+ },+ getTweensOf(target: unknown): Tween[] {+ return tweensOf(target)+ },+ killAll() {+ for (const tw of [...live]) tw.kill()+ },+ /** global playback rate (diagnostics/tests) */+ setTimeScale(n: number) {+ timeScale = n+ },+ /** manual clock for tests: stop the rAF loop and drive time by hand */+ setManual(on: boolean) {+ manual = on+ if (!on) tickerOn()+ },+ tick(seconds: number) {+ for (const tw of [...live]) tw.tick(seconds * timeScale)+ },+ get activeCount() {+ return live.size+ },+}diff --git a/slides/src/editor/patheditor.ts b/slides/src/editor/patheditor.tsindex 42409aca..1ef08f9f 100644--- a/slides/src/editor/patheditor.ts+++ b/slides/src/editor/patheditor.ts@@ -8,12 +8,9 @@// anchored at the element's centre; dragging the first anchor moves the// element itself.-import { gsap } from 'gsap'-import { MotionPathPlugin } from 'gsap/MotionPathPlugin'+import { anim } from '../anim'import type { Store } from '../store'-gsap.registerPlugin(MotionPathPlugin)-const SVG_NS = 'http://www.w3.org/2000/svg'type Pt = { x: number; y: number }@@ -215,7 +212,7 @@ export class PathEditor {cancel() {if (!this.overlay) return- gsap.killTweensOf(this.overlay.querySelectorAll('*'))+ anim.killTweensOf(this.overlay.querySelectorAll('*'))this.overlay.remove()this.overlay = nullthis.hint?.remove()@@ -227,7 +224,7 @@ export class PathEditor {private draw() {const svg = this.overlayif (!svg) return- gsap.killTweensOf(svg.querySelectorAll('.ed-pe-dot'))+ anim.killTweensOf(svg.querySelectorAll('.ed-pe-dot'))svg.innerHTML = ''const k = 1 / this.scale()const d = anchorsToPath(this.pts)@@ -277,7 +274,7 @@ export class PathEditor {preview.style.pointerEvents = 'none'preview.classList.add('ed-pe-dot')svg.appendChild(preview)- gsap.to(preview, { motionPath: { path: d }, duration: Math.max(dur, 0.5), ease: 'none', repeat: -1 })+ anim.to(preview, { motionPath: { path: d }, duration: Math.max(dur, 0.5), ease: 'none', repeat: -1 })}// --- interaction ------------------------------------------------------------diff --git a/slides/src/main.ts b/slides/src/main.tsindex f70081b1..dee90b2f 100644--- a/slides/src/main.ts+++ b/slides/src/main.ts@@ -2,7 +2,7 @@// mutation — the captured copy is what gets re-serialized on save.import './styles.css'-import { gsap } from 'gsap'+import { anim } from './anim'import { capturePristine, readEmbeddedDoc, serializeFile } from './save'import { parseDoc, starterDoc } from './model'import { injectFonts } from './fonts'@@ -57,5 +57,5 @@ if (location.hash === '#present') {return store.selection.slice()},/** animation engine, exposed for scripting/diagnostics */- gsap,+ anim,}diff --git a/slides/src/present.ts b/slides/src/present.tsindex 70563554..5616c9b6 100644--- a/slides/src/present.ts+++ b/slides/src/present.ts@@ -5,14 +5,10 @@import Reveal from 'reveal.js'import RevealNotes from 'reveal.js/plugin/notes/notes'import 'reveal.js/dist/reveal.css'-import { gsap } from 'gsap'-import { Flip } from 'gsap/Flip'-import { MotionPathPlugin } from 'gsap/MotionPathPlugin'+import { anim, resetXform } from './anim'import type { BentoDoc, GradientFill, ShapeElement, Slide, SlideElement } from './model'import { applyElementFrame, gradientLineCoords, renderSlide } from './render'-gsap.registerPlugin(Flip, MotionPathPlugin)-const MORPH_DURATION = 0.65const MORPH_EASE = 'power2.inOut'@@ -163,11 +159,14 @@ export function startPresentation(// Kill the outgoing slide's tweens, then restore model frames —// a tween killed during its delay would otherwise leave the element// stuck at its "from" state (invisible) for every future visit.- gsap.killTweensOf(from.querySelectorAll('.bento-el'))+ anim.killTweensOf(from.querySelectorAll('.bento-el'))const fromSlide = doc.slides[fromIdx]for (const el of fromSlide?.elements ?? []) {const node = from.querySelector<HTMLElement>(`[data-el-id="${CSS.escape(el.id)}"]`)- if (node) applyElementFrame(node, el)+ if (node) {+ applyElementFrame(node, el) // resets style.transform…+ resetXform(node) // …so the engine must forget its composed state+ }}if (fromSlide?.hover?.type === 'reveal') {applyRevealSet(from, null, fromSlide.hover.default)@@ -244,7 +243,7 @@ function runEnterFx(slide: Slide, section: HTMLElement) {// node would fight it and freeze the dot off its pathif (fx.loop?.type === 'motion-path') returnif (fx.enter) {- gsap.fromTo(+ anim.fromTo(node,{ opacity: 0, y: fx.enter === 'fade-up' ? 16 : 0 },{@@ -253,7 +252,6 @@ function runEnterFx(slide: Slide, section: HTMLElement) {duration: 0.55,delay: 0.12 + Math.min(step, 24) * 0.05,ease: 'power2.out',- overwrite: 'auto',},)}@@ -272,10 +270,11 @@ function settleGuarantee(pairs: Array<[HTMLElement, SlideElement]>) {setTimeout(() => {for (const [node, el] of pairs) {if (!node.isConnected) continue- const tweens = gsap.getTweensOf(node)+ const tweens = anim.getTweensOf(node)if (tweens.some((t) => t.progress() < 1)) {- gsap.killTweensOf(node)+ anim.killTweensOf(node)applyElementFrame(node, el)+ resetXform(node)}}}, 2800)@@ -288,7 +287,7 @@ function runCountUp(node: HTMLElement) {const tokens = [...final.matchAll(/\d+(?:[.,]\d+)?/g)]if (!tokens.length) returnconst state = { p: 0 }- gsap.to(state, {+ anim.to(state, {p: 1,duration: 1.15,delay: 0.15,@@ -326,7 +325,7 @@ function runAmbientFx(slide: Slide, section: HTMLElement) {const ken = fx.ken ?? {}const dir = ken.dir ?? 'drift'if (dir === 'drift') {- gsap.fromTo(+ anim.fromTo(node,{ scale: 1.02 },{ scale: ken.scale ?? 1.1, duration: ken.duration ?? 26, ease: 'none', repeat: -1, yoyo: true, transformOrigin: '50% 40%' },@@ -335,17 +334,17 @@ function runAmbientFx(slide: Slide, section: HTMLElement) {// one-shot settle, replayed on every slide entryconst far = ken.scale ?? 1.06const dur = ken.duration ?? 2.5- gsap.fromTo(+ anim.fromTo(node,{ scale: dir === 'out' ? far : 1 },- { scale: dir === 'out' ? 1 : far, duration: dur, ease: 'power2.out', transformOrigin: '50% 50%', overwrite: 'auto' },+ { scale: dir === 'out' ? 1 : far, duration: dur, ease: 'power2.out', transformOrigin: '50% 50%' },)}}if (fx.loop?.type === 'dash-march') {const target = node.querySelector('path, line, rect, ellipse, polygon')if (target) {- gsap.fromTo(+ anim.fromTo(target,{ strokeDashoffset: fx.loop.distance ?? 18 },{ strokeDashoffset: 0, duration: fx.loop.duration ?? 1.4, ease: 'none', repeat: -1 },@@ -353,7 +352,7 @@ function runAmbientFx(slide: Slide, section: HTMLElement) {}}if (fx.loop?.type === 'motion-path') {- gsap.to(node, {+ anim.to(node, {motionPath: { path: fx.loop.path },duration: fx.loop.duration,delay: fx.loop.delay ?? 0,@@ -460,7 +459,7 @@ function runMorph(if (entering.length) {const spread = Math.min(0.45, entering.length * 0.03)entering.forEach(([n, opacity], i) => {- gsap.fromTo(n,+ anim.fromTo(n,{ opacity: 0, y: 14 },{opacity, y: 0, duration: 0.45,@@ -475,33 +474,43 @@ function runMorph(}if (!matchedFrom.length) return- // Reveal has already hidden/transformed the outgoing section. Temporarily- // neutralize that so Flip can measure where the elements really were.- const saved = {- display: fromSection.style.display,- visibility: fromSection.style.visibility,- transform: fromSection.style.transform,- opacity: fromSection.style.opacity,+ // Geometry straight from the model — no DOM measuring needed (both sides'+ // frames are in the doc), so the outgoing section's Reveal styling is+ // irrelevant. Each matched node animates from the from-slide's frame to its+ // own via translate+scale about the top-left corner (scale mode like+ // PowerPoint: text scales instead of reflowing mid-morph). Rotating morphs+ // pivot slightly differently than center-origin — rare and acceptable.+ for (const node of matchedTo) {+ const id = node.dataset.flipId!+ const a = fromModel.get(id)+ const b = toModel.get(id)+ if (!a || !b) continue+ if (a.x === b.x && a.y === b.y && a.w === b.w && a.h === b.h && (a.rotation ?? 0) === (b.rotation ?? 0)) continue+ const state = { p: 0 }+ node.style.transformOrigin = '0 0'+ anim.to(state, {+ p: 1,+ duration: MORPH_DURATION,+ ease: MORPH_EASE,+ onUpdate() {+ const p = state.p+ const x = a.x + (b.x - a.x) * p+ const y = a.y + (b.y - a.y) * p+ const w = a.w + (b.w - a.w) * p+ const h = a.h + (b.h - a.h) * p+ const r = (a.rotation ?? 0) + ((b.rotation ?? 0) - (a.rotation ?? 0)) * p+ node.style.transform =+ `translate(${x - b.x}px, ${y - b.y}px)` ++ (r ? ` rotate(${r}deg)` : '') ++ ` scale(${w / Math.max(b.w, 0.01)}, ${h / Math.max(b.h, 0.01)})`+ },+ onComplete() {+ node.style.transformOrigin = ''+ node.style.transform = b.rotation ? `rotate(${b.rotation}deg)` : ''+ resetXform(node)+ },+ })}- fromSection.style.display = 'block'- fromSection.style.visibility = 'hidden'- fromSection.style.transform = 'none'- fromSection.style.opacity = '1'-- const state = Flip.getState(matchedFrom)-- fromSection.style.display = saved.display- fromSection.style.visibility = saved.visibility- fromSection.style.transform = saved.transform- fromSection.style.opacity = saved.opacity-- // Geometry via Flip (position/size/rotation, scale mode like PowerPoint).- Flip.from(state, {- targets: matchedTo,- duration: MORPH_DURATION,- ease: MORPH_EASE,- scale: true,- })// Styles morph straight from the model — exact values, no DOM sniffing.for (const to of matchedTo) {@@ -510,7 +519,7 @@ function runMorph(const b = toModel.get(id)if (!a || !b) continueif (a.opacity !== b.opacity) {- gsap.fromTo(to, { opacity: a.opacity }, { opacity: b.opacity, duration: MORPH_DURATION, ease: MORPH_EASE })+ anim.fromTo(to, { opacity: a.opacity }, { opacity: b.opacity, duration: MORPH_DURATION, ease: MORPH_EASE })}if (a.type === 'shape' && b.type === 'shape') {const target = to.querySelector<SVGElement>('rect,ellipse,polygon,line,path')@@ -519,7 +528,7 @@ function runMorph(if (a.type === 'text' && b.type === 'text' && a.color !== b.color) {const inner = to.querySelector<HTMLElement>('.bento-text-inner')if (inner) {- gsap.fromTo(inner, { color: a.color }, { color: b.color, duration: MORPH_DURATION, ease: MORPH_EASE })+ anim.fromTo(inner, { color: a.color }, { color: b.color, duration: MORPH_DURATION, ease: MORPH_EASE })}}}@@ -583,7 +592,7 @@ function morphShapeFill(target: SVGElement, a: ShapeElement, b: ShapeElement) {const bg = b.fillGradient?.stops.length ? b.fillGradient : undefinedif (!ag && !bg) {if (a.fill !== b.fill) {- gsap.fromTo(target, { attr: { fill: a.fill } }, { attr: { fill: b.fill }, duration: MORPH_DURATION, ease: MORPH_EASE })+ anim.fromTo(target, { attr: { fill: a.fill } }, { attr: { fill: b.fill }, duration: MORPH_DURATION, ease: MORPH_EASE })}return}@@ -614,7 +623,7 @@ function morphShapeFill(target: SVGElement, a: ShapeElement, b: ShapeElement) {const at = finals[i]?.at ?? 1const fromColor = ag ? sampleGradient(ag.stops, at) : rgbaStr(colorParts(a.fill))const toColor = finals[i]?.color ?? b.fill- gsap.fromTo(+ anim.fromTo(node,{ attr: { 'stop-color': fromColor } },{@@ -636,5 +645,5 @@ function morphShapeFill(target: SVGElement, a: ShapeElement, b: ShapeElement) {const fromLine = gradientLineCoords((ag ?? bg)!.angle)const toLine = gradientLineCoords((bg ?? ag)!.angle)- gsap.fromTo(lin, { attr: fromLine }, { attr: toLine, duration: MORPH_DURATION, ease: MORPH_EASE })+ anim.fromTo(lin, { attr: fromLine }, { attr: toLine, duration: MORPH_DURATION, ease: MORPH_EASE })}