Bento, the office suite that fits in a file
TypeScript mit-licenseofficeoffice-365office-suiteoffice-toolsoffice365open-sourcepowerpointself-hostedsingle-page-appslidesslideshareslideshowslideshow-galleryslideshow-makerslideshows
Collapsible panels + the flagged-limitations batch
nyblneta4add7e6e869
diff --git a/slides/src/editor/canvas.ts b/slides/src/editor/canvas.tsindex b465b526..1641f741 100644--- a/slides/src/editor/canvas.ts+++ b/slides/src/editor/canvas.ts@@ -240,6 +240,12 @@ export class SlideCanvas {e.target.style.left = `${e.drag.left}px`e.target.style.top = `${e.drag.top}px`})+ mv.on('resizeGroup', (e) => e.events.forEach((ev) => {+ ev.target.style.width = `${ev.width}px`+ ev.target.style.height = `${ev.height}px`+ ev.target.style.left = `${ev.drag.left}px`+ ev.target.style.top = `${ev.drag.top}px`+ }))mv.on('rotate', (e) => {e.target.style.transform = `rotate(${e.rotation}deg)`})@@ -251,6 +257,7 @@ export class SlideCanvas {mv.on('dragEnd', ({ isDrag }) => isDrag && commitFrames())mv.on('dragGroupEnd', ({ isDrag }) => isDrag && commitFrames())mv.on('resizeEnd', ({ isDrag }) => isDrag && commitFrames())+ mv.on('resizeGroupEnd', ({ isDrag }) => isDrag && commitFrames())mv.on('rotateEnd', ({ isDrag }) => isDrag && commitFrames())mv.on('rotateGroupEnd', ({ isDrag }) => isDrag && commitFrames())}diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.tsindex 5446db6a..c8e5c8ed 100644--- a/slides/src/editor/editor.ts+++ b/slides/src/editor/editor.ts@@ -6,7 +6,7 @@ import {defaultImage, defaultShape, defaultText, emptySlide, uid,type ShapeKind, type SlideElement,} from '../model'-import { renderThumbnail } from '../render'+import { renderSlide, renderThumbnail } from '../render'import { SlideCanvas } from './canvas'import { PropsPanel } from './panels'import { startPresentation } from '../present'@@ -24,6 +24,7 @@ const SHAPE_MENU: Array<{ kind: ShapeKind; label: string; icon: string }> = [export class Editor {private canvas!: SlideCanvasprivate sidebar!: HTMLElement+ private props!: HTMLElementprivate dirtyDot!: HTMLElementprivate thumbTimer = 0private clipboard: SlideElement[] = []@@ -88,7 +89,10 @@ export class Editor {presentB.classList.add('ed-btn-primary')const saveB = btn(ICONS.save, 'Save', () => this.save(false), 'Save (⌘S)')const saveAsB = btn(ICONS.download, '', () => this.save(true), 'Save a copy…')- actions.append(undoB, redoB, presentB, saveB, saveAsB)+ const pdfB = btn(ICONS.pdf, '', () => this.exportPdf(), 'Export PDF (print)')+ const leftT = btn(ICONS.panelLeft, '', () => this.togglePanel('left'), 'Toggle slide list ([)')+ const rightT = btn(ICONS.panelRight, '', () => this.togglePanel('right'), 'Toggle properties (])')+ actions.append(undoB, redoB, pdfB, leftT, rightT, presentB, saveB, saveAsB)bar.append(logo, title, this.dirtyDot, insert, actions)@@ -96,13 +100,20 @@ export class Editor {const main = div('ed-main')this.sidebar = div('ed-sidebar')const canvasWrap = div('ed-canvas-wrap')- const props = div('ed-props')- main.append(this.sidebar, canvasWrap, props)+ this.props = div('ed-props')+ main.append(this.sidebar, canvasWrap, this.props)this.root.append(bar, main)this.canvas = new SlideCanvas(canvasWrap, this.store)- new PropsPanel(props, this.store)+ new PropsPanel(this.props, this.store)+ }++ /** Collapse/expand the slide list or the properties panel. */+ togglePanel(side: 'left' | 'right') {+ const el = side === 'left' ? this.sidebar : this.props+ el.classList.toggle('ed-collapsed')+ // the canvas wrap resizes; its ResizeObserver re-fits the stage}private shapeDropdown(): HTMLElement {@@ -237,13 +248,65 @@ export class Editor {private deleteSlide(i: number) {if (this.store.doc.slides.length <= 1) return this.toast('A deck needs at least one slide')+ const target = this.store.doc.slides[i]+ // dependents: states of this slide, and element links pointing at it+ const states = this.store.doc.slides.filter((s) => s.stateOf === target.id)+ const doomedIds = new Set([target.id, ...states.map((s) => s.id)])+ let linkCount = 0+ for (const s of this.store.doc.slides) {+ if (doomedIds.has(s.id)) continue+ for (const el of s.elements) if (el.link && doomedIds.has(el.link)) linkCount+++ }+ if (states.length || linkCount) {+ const parts = [+ states.length ? `${states.length} interactive state${states.length > 1 ? 's' : ''} will be deleted with it` : '',+ linkCount ? `${linkCount} element link${linkCount > 1 ? 's' : ''} will be cleared` : '',+ ].filter(Boolean).join('; ')+ if (!window.confirm(`Delete this slide? ${parts}.`)) return+ }this.store.commit(() => {- this.store.doc.slides.splice(i, 1)+ this.store.doc.slides = this.store.doc.slides.filter((s) => !doomedIds.has(s.id))+ for (const s of this.store.doc.slides) {+ for (const el of s.elements) {+ if (el.link && doomedIds.has(el.link)) delete el.link+ }+ }}, 'slides')this.store.goTo(Math.min(i, this.store.doc.slides.length - 1))this.store.emit('current')}+ /**+ * Export the deck to PDF via the browser's print pipeline: every linear+ * slide becomes one exact 1600×900 page (states are reachable only through+ * interaction, so they stay out of the paper trail).+ */+ exportPdf() {+ this.canvas.commitTextEdit()+ document.getElementById('bento-print')?.remove()+ const box = div('')+ box.id = 'bento-print'+ for (const slide of this.store.doc.slides) {+ if (slide.stateOf) continue+ const page = div('bp-page')+ const surface = renderSlide(slide, this.store.doc, { svgAsImage: true })+ // normalise to the print page size regardless of doc size+ const s = 1600 / this.store.doc.size.width+ surface.style.transformOrigin = '0 0'+ if (s !== 1) surface.style.transform = `scale(${s})`+ page.appendChild(surface)+ box.appendChild(page)+ }+ document.body.appendChild(box)+ const cleanup = () => {+ box.remove()+ window.removeEventListener('afterprint', cleanup)+ }+ window.addEventListener('afterprint', cleanup)+ // give the freshly-inserted images a beat to decode before printing+ setTimeout(() => window.print(), 250)+ }+// --- insert image ------------------------------------------------------------------private pickImage() {@@ -290,7 +353,9 @@ export class Editor {const result = await saveFile(this.store.doc, forcePicker)if (result === 'cancelled') returnthis.store.setDirty(false)- this.toast(result === 'downloaded' ? 'Saved a copy to Downloads' : 'Saved')+ this.toast(result === 'downloaded'+ ? 'This browser can’t rewrite files in place — a fresh copy went to Downloads'+ : 'Saved')} catch (err) {console.error(err)this.toast('Save failed — see console')@@ -387,6 +452,14 @@ export class Editor {})return}+ if (ev.key === '[') {+ this.togglePanel('left')+ return+ }+ if (ev.key === ']') {+ this.togglePanel('right')+ return+ }if (ev.key === 'Escape') {this.store.select([])returndiff --git a/slides/src/editor/panels.ts b/slides/src/editor/panels.tsindex 3f124dc7..5c0e2289 100644--- a/slides/src/editor/panels.ts+++ b/slides/src/editor/panels.ts@@ -92,6 +92,15 @@ export class PropsPanel {'A <b>state</b> is hidden from arrow-key flow — viewers reach it by clicking a linked element. Shared element ids morph between states.'this.host.appendChild(stateHint)+ if (slide.stateOf) {+ const sync = document.createElement('button')+ sync.className = 'ed-btn ed-btn-block'+ sync.innerHTML = `${ICONS.sync}<span>Sync from parent slide</span>`+ sync.title = 'Pull elements added to the parent into this state and adopt its ordering — your changes to shared elements are kept'+ sync.addEventListener('click', () => this.syncStateFromParent())+ this.host.appendChild(sync)+ }+this.row('Hover', this.select(['none', 'focus-group', 'reveal'],slide.hover?.type ?? 'none',@@ -273,6 +282,57 @@ export class PropsPanel {this.host.appendChild(makeState)}+ /**+ * Re-sync an interactive state with its parent: parent elements missing+ * here (added since the state was created) come in, ordering follows the+ * parent, and this state's own versions of shared elements — its whole+ * point — stay untouched. Elements unique to this state stay on top.+ */+ private syncStateFromParent() {+ const state = this.store.slide+ const parent = this.store.doc.slides.find((s) => s.id === state.stateOf)+ if (!parent) return+ const own = new Map(state.elements.map((e) => [e.id, e]))+ // sync only makes sense for states that share lineage with the parent —+ // otherwise "merging" would just stack two full copies of everything+ const shared = parent.elements.filter((pe) => own.has(pe.id)).length+ if (state.elements.length && !shared) {+ this.toast('This state shares no element ids with its parent — nothing to sync against')+ return+ }+ let added = 0+ const merged: SlideElement[] = parent.elements.map((pe) => {+ const mine = own.get(pe.id)+ if (mine) {+ own.delete(pe.id)+ return mine+ }+ added+++ return JSON.parse(JSON.stringify(pe))+ })+ const extras = [...own.values()] // this state's additions, kept on top+ this.store.commit(() => {+ this.store.slide.elements = [...merged, ...extras]+ })+ this.store.select([])+ const bits = [added ? `${added} new element${added > 1 ? 's' : ''} pulled in` : 'nothing new in the parent']+ if (extras.length) bits.push(`${extras.length} state-only element${extras.length > 1 ? 's' : ''} kept`)+ this.toast(`Synced — ${bits.join('; ')}`)+ }++ private toast(message: string) {+ document.querySelector('.ed-toast')?.remove()+ const t = document.createElement('div')+ t.className = 'ed-toast'+ t.textContent = message+ document.body.appendChild(t)+ setTimeout(() => t.classList.add('show'))+ setTimeout(() => {+ t.classList.remove('show')+ setTimeout(() => t.remove(), 300)+ }, 2600)+ }+/** Duplicate the current slide as a hidden state and link `el` to it. */private createLinkedState(el: SlideElement) {const src = this.store.slidediff --git a/slides/src/icons.ts b/slides/src/icons.tsindex 46e44a57..029aed1b 100644--- a/slides/src/icons.ts+++ b/slides/src/icons.ts@@ -17,6 +17,10 @@ export const ICONS = {copy: svg('<rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>'),front: svg('<rect x="8" y="8" width="12" height="12" rx="2" fill="currentColor" stroke="none" opacity="0.35"/><rect x="4" y="4" width="12" height="12" rx="2"/>'),back: svg('<rect x="4" y="4" width="12" height="12" rx="2" fill="currentColor" stroke="none" opacity="0.35"/><rect x="8" y="8" width="12" height="12" rx="2"/>'),+ panelLeft: svg('<rect x="3" y="4" width="18" height="16" rx="2"/><line x1="9" y1="4" x2="9" y2="20"/>'),+ panelRight: svg('<rect x="3" y="4" width="18" height="16" rx="2"/><line x1="15" y1="4" x2="15" y2="20"/>'),+ pdf: svg('<polyline points="6 9 6 3 18 3 18 9"/><path d="M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"/><rect x="6" y="14" width="12" height="8"/>'),+ sync: svg('<path d="M21 12a9 9 0 1 1-2.64-6.36"/><polyline points="21 3 21 9 15 9"/>'),// shape menu entriesrect: svg('<rect x="3" y="5" width="18" height="14" rx="2"/>'),ellipse: svg('<ellipse cx="12" cy="12" rx="9" ry="7"/>'),diff --git a/slides/src/main.ts b/slides/src/main.tsindex e6aff491..d5e62cd6 100644--- a/slides/src/main.ts+++ b/slides/src/main.ts@@ -14,6 +14,23 @@ const doc = (embedded && parseDoc(embedded)) || starterDoc()document.title = `${doc.title} — Bento Slides`+// Embedded fonts: register @font-face rules from the asset table so text+// elements can use bundled families in the editor, presenter and thumbnails.+if (doc.fonts?.length) {+ const css = doc.fonts+ .map((f) => {+ const src = doc.assets?.[f.asset]+ if (!src) return ''+ return `@font-face{font-family:${JSON.stringify(f.family)};src:url(${JSON.stringify(src)});` ++ `font-weight:${f.weight ?? 'normal'};font-style:${f.style ?? 'normal'};font-display:swap}`+ })+ .join('\n')+ const style = document.createElement('style')+ style.id = 'bento-fonts'+ style.textContent = css+ document.head.appendChild(style)+}+const store = new Store(doc)const editor = new Editor(document.getElementById('app')!, store)diff --git a/slides/src/model.ts b/slides/src/model.tsindex 8a0da961..9073266d 100644--- a/slides/src/model.ts+++ b/slides/src/model.ts@@ -144,6 +144,11 @@ export interface BentoDoc {}/** shared assets (raw SVG markup or data URIs), referenced by key */assets?: Record<string, string>+ /**+ * embedded fonts: each entry becomes an @font-face at boot, with the font+ * data living in assets (data: URI). Elements then use `family` normally.+ */+ fonts?: Array<{ family: string; asset: string; weight?: string; style?: string }>slides: Slide[]modified: string}diff --git a/slides/src/present.ts b/slides/src/present.tsindex d5d0b4de..7523426f 100644--- a/slides/src/present.ts+++ b/slides/src/present.ts@@ -43,6 +43,7 @@ export function startPresentation(const section = document.createElement('section')// Morph slides swap instantly; the Flip animation supplies the motion.section.dataset.transition = slide.transition === 'morph' ? 'none' : slide.transition+ if (slide.stateOf) section.dataset.bentoState = '1' // dimmed in overviewconst surface = renderSlide(slide, doc)// reveal slides start with only the default hover set visibleif (slide.hover?.type === 'reveal') applyRevealSet(surface, slide.hover.default ?? null, slide.hover.default)diff --git a/slides/src/styles.css b/slides/src/styles.cssindex 22779546..13cbeaaa 100644--- a/slides/src/styles.css+++ b/slides/src/styles.css@@ -464,6 +464,40 @@ html, body {border-radius: 999px;}+/* collapsible side panels */+.ed-sidebar, .ed-props { transition: width .18s ease, padding .18s ease; }+.ed-sidebar.ed-collapsed, .ed-props.ed-collapsed {+ width: 0;+ min-width: 0; /* flex items floor at min-content without this */+ padding-left: 0;+ padding-right: 0;+ border-width: 0;+ overflow: hidden;+}++/* interactive states read as secondary in Reveal's overview grid+ (!important: Reveal positions overview sections with inline styles) */+.bento-present-overlay .reveal.overview section[data-bento-state] {+ opacity: 0.35 !important;+ outline: 2px dashed rgb(255 255 255 / 0.35);+ outline-offset: -2px;+}++/* PDF export: each linear slide is one exact 1600×900 page */+#bento-print { display: none; }+@media print {+ #app, #bento-splash, .bento-present-overlay, .ed-toast { display: none !important; }+ #bento-print { display: block; }+ @page { size: 1600px 900px; margin: 0; }+ #bento-print .bp-page {+ width: 1600px;+ height: 900px;+ overflow: hidden;+ page-break-after: always;+ break-after: page;+ }+}+/* moveable accents */.moveable-control-box {--moveable-color: var(--blue);