Bento, the office suite that fits in a file
TypeScript mit-licenseofficeoffice-365office-suiteoffice-toolsoffice365open-sourcepowerpointself-hostedsingle-page-appslidesslideshareslideshowslideshow-galleryslideshow-makerslideshows
Arrange kit, grouping, inline text markup, insert slides anywhere
nyblnete855a344e62c
diff --git a/CLAUDE.md b/CLAUDE.mdindex 9c0b7b40..06930d07 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -49,7 +49,13 @@ One HTML file = the document + viewer + editor. See `README.md` for the vision.Moveable's control box). Fill/stroke colors carry alpha (color input + % pair,rgba round-trip); shapes support `fillGradient` (linear, CSS-convention angle,multi-stop) — rendered as per-instance svg `<defs>` gradients (unique ids:- url(#…) refs are document-global across canvas/thumbs/present).+ url(#…) refs are document-global across canvas/thumbs/present). Arrange kit in+ the panel: align/distribute/z-step + Group (⌘G/⇧⌘G — `groupId`, distinct from+ presentation `group`; click selects the group, Alt-click reaches a member;+ duplicate remaps groupIds). Text editing supports ⌘B/I/U inline markup.+ Sidebar has hover insert-gaps between thumbnails (never between a parent and+ its states). Selecto's continue-select list is synced in syncTargets — stale+ cross-slide shift-click selections were a real bug.## Hard-won details — do not regressdiff --git a/slides/src/editor/canvas.ts b/slides/src/editor/canvas.tsindex c6bb94ab..a7dad441 100644--- a/slides/src/editor/canvas.ts+++ b/slides/src/editor/canvas.ts@@ -166,6 +166,19 @@ export class SlideCanvas {this.wrap.appendChild(bar)}+ /** Grow a selection to whole groups: any member pulls in its groupId kin.+ * (Alt-click deep select bypasses this — that's how you reach a member.) */+ private expandGroups(ids: string[]): string[] {+ const els = this.store.slide.elements+ const groups = new Set(+ ids.map((id) => els.find((e) => e.id === id)?.groupId).filter((g): g is string => !!g),+ )+ if (!groups.size) return ids+ const out = new Set(ids)+ for (const el of els) if (el.groupId && groups.has(el.groupId)) out.add(el.id)+ return [...out]+ }+/** Alt-click: select the element under (px, py), digging one step deeper* below the current selection on each repeat. Coordinates in slide px. */private deepSelect(px: number, py: number) {@@ -285,6 +298,9 @@ export class SlideCanvas {const same = current.length === targets.length && targets.every((t, i) => current[i] === t)if (!same) this.moveable.target = targetsthis.moveable.updateRect()+ // Keep Selecto's continue-select memory in lockstep with the store —+ // otherwise shift-click resurrects targets from a previously shown slide.+ this.selecto.setSelectedTargets(targets)}// --- moveable -------------------------------------------------------------@@ -383,7 +399,7 @@ export class SlideCanvas {const ids = (e.selected as HTMLElement[]).map((n) => n.dataset.elId).filter((id): id is string => !!id)- this.store.select(ids)+ this.store.select(this.expandGroups(ids))if (e.isDragStartEnd) {e.inputEvent.preventDefault()this.moveable.waitToChangeTarget().then(() => {@@ -412,6 +428,16 @@ export class SlideCanvas {if (ev.key === 'Escape') {ev.preventDefault()this.commitTextEdit()+ return+ }+ // inline markup: ⌘/Ctrl+B/I/U toggle bold/italic/underline on the+ // selection (sanitize keeps b/i/u/strong/em, so it round-trips)+ if (ev.metaKey || ev.ctrlKey) {+ const cmd = { b: 'bold', i: 'italic', u: 'underline' }[ev.key.toLowerCase()]+ if (cmd) {+ ev.preventDefault()+ document.execCommand(cmd)+ }}})inner.addEventListener('blur', () => this.commitTextEdit(), { once: true })diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.tsindex d461c87f..c77fc57a 100644--- a/slides/src/editor/editor.ts+++ b/slides/src/editor/editor.ts@@ -23,6 +23,7 @@ const SHAPE_MENU: Array<{ kind: ShapeKind; label: string; icon: string }> = [export class Editor {private canvas!: SlideCanvas+ private panel!: PropsPanelprivate sidebar!: HTMLElementprivate props!: HTMLElementprivate dirtyDot!: HTMLElement@@ -109,7 +110,7 @@ export class Editor {this.restorePanelWidths()this.canvas = new SlideCanvas(canvasWrap, this.store)- new PropsPanel(this.props, this.store)+ this.panel = new PropsPanel(this.props, this.store)}// --- resizable side panels ------------------------------------------------@@ -239,10 +240,13 @@ export class Editor {this.sidebar.innerHTML = ''const slides = this.store.doc.slidesslides.forEach((slide, i) => {+ // hover gap = insert here; never between a parent and its states+ if (!slide.stateOf) this.sidebar.appendChild(this.insertGap(i))const item = this.makeThumb(slide, i, !!slide.stateOf)if (slide.stateOf) item.classList.add('ed-thumb-state')this.sidebar.appendChild(item)})+ this.sidebar.appendChild(this.insertGap(slides.length))const add = btn(ICONS.plus, 'New slide', () => this.addSlide())add.classList.add('ed-add-slide')this.sidebar.appendChild(add)@@ -250,6 +254,25 @@ export class Editor {this.highlightSidebar()}+ /** Slim hover strip between thumbnails — click inserts a blank slide there. */+ private insertGap(at: number): HTMLElement {+ const gap = div('ed-insertgap')+ gap.title = 'Insert slide here'+ const plus = document.createElement('button')+ plus.className = 'ed-insertgap-btn'+ plus.textContent = '+'+ plus.tabIndex = -1+ gap.appendChild(plus)+ gap.addEventListener('click', () => {+ const bg = this.store.slide.background+ this.store.commit(() => {+ this.store.doc.slides.splice(at, 0, emptySlide({ background: bg }))+ }, 'slides')+ this.store.goTo(at)+ })+ return gap+ }+private wireThumbDrag(item: HTMLElement, index: number) {item.addEventListener('dragstart', (ev) => {ev.dataTransfer!.setData('text/bento-slide', String(index))@@ -285,10 +308,12 @@ export class Editor {this.thumbTimer = window.setTimeout(() => {const thumbs = this.sidebar.querySelectorAll<HTMLElement>('.ed-thumb')if (thumbs.length !== this.store.doc.slides.length) return this.rebuildSidebar()+ const base = Math.max(96, this.panelW.left - 40)thumbs.forEach((item) => {const slide = this.store.doc.slides[Number(item.dataset.index)]if (!slide) return- item.querySelector('.bento-thumb-surface')?.replaceWith(renderThumbnail(slide, this.store.doc, 148))+ const w = slide.stateOf ? Math.round(base * 0.84) : base+ item.querySelector('.bento-thumb-surface')?.replaceWith(renderThumbnail(slide, this.store.doc, w))})}, 150)}@@ -467,6 +492,13 @@ export class Editor {}if (inField) return+ if (mod && ev.key.toLowerCase() === 'g') {+ ev.preventDefault()+ const els = this.store.selectedElements+ if (ev.shiftKey) this.panel.ungroup(els)+ else this.panel.group(els)+ return+ }if (mod && ev.key.toLowerCase() === 'z') {ev.preventDefault()ev.shiftKey ? this.store.redo() : this.store.undo()diff --git a/slides/src/editor/panels.ts b/slides/src/editor/panels.tsindex fb0008ad..79c7aef3 100644--- a/slides/src/editor/panels.ts+++ b/slides/src/editor/panels.ts@@ -599,14 +599,138 @@ export class PropsPanel {this.opBtn(ICONS.trash, 'Delete', () => this.deleteEls(els)),)this.host.appendChild(row)+ this.arrangeRows(els)+ }++ /** Align / distribute / step z-order / group — the classic arrange kit. */+ private arrangeRows(els: SlideElement[]) {+ const textBtn = (label: string, title: string, onClick: () => void, enabled = true) => {+ const b = document.createElement('button')+ b.className = 'ed-btn ed-arrange-btn'+ b.textContent = label+ b.title = title+ b.disabled = !enabled+ b.addEventListener('click', onClick)+ return b+ }+ const grid = document.createElement('div')+ grid.className = 'ed-ops ed-arrange'+ grid.append(+ textBtn('⇤', 'Align left', () => this.align(els, 'left')),+ textBtn('⇹', 'Align horizontal centers', () => this.align(els, 'centerX')),+ textBtn('⇥', 'Align right', () => this.align(els, 'right')),+ textBtn('⤒', 'Align top', () => this.align(els, 'top')),+ textBtn('⇳', 'Align vertical middles', () => this.align(els, 'middleY')),+ textBtn('⤓', 'Align bottom', () => this.align(els, 'bottom')),+ textBtn('⋯', 'Distribute horizontally (3+)', () => this.distribute(els, 'x'), els.length >= 3),+ textBtn('⋮', 'Distribute vertically (3+)', () => this.distribute(els, 'y'), els.length >= 3),+ textBtn('↑', 'Bring forward one step', () => this.step(els, +1)),+ textBtn('↓', 'Send backward one step', () => this.step(els, -1)),+ )+ this.host.appendChild(grid)++ const grouped = els.some((e) => e.groupId)+ if (els.length > 1 || grouped) {+ const g = document.createElement('button')+ g.className = 'ed-btn ed-btn-block'+ const allSame = els.length > 1 && els.every((e) => e.groupId && e.groupId === els[0].groupId)+ if (allSame || (grouped && els.length === 1)) {+ g.textContent = '⛓ Ungroup'+ g.title = 'Dissolve the group (⇧⌘G)'+ g.addEventListener('click', () => this.ungroup(els))+ } else {+ g.textContent = '⛓ Group'+ g.title = 'Elements select and move as one; Alt-click reaches a member (⌘G)'+ g.addEventListener('click', () => this.group(els))+ }+ this.host.appendChild(g)+ }+ }++ /** Single element aligns to the slide; a multi-selection aligns to its own bounds. */+ private align(els: SlideElement[], edge: 'left' | 'centerX' | 'right' | 'top' | 'middleY' | 'bottom') {+ const { width, height } = this.store.doc.size+ const box = els.length === 1+ ? { x0: 0, y0: 0, x1: width, y1: height }+ : {+ x0: Math.min(...els.map((e) => e.x)),+ y0: Math.min(...els.map((e) => e.y)),+ x1: Math.max(...els.map((e) => e.x + e.w)),+ y1: Math.max(...els.map((e) => e.y + e.h)),+ }+ this.edit(() => {+ for (const el of els) {+ if (edge === 'left') el.x = box.x0+ if (edge === 'right') el.x = box.x1 - el.w+ if (edge === 'centerX') el.x = (box.x0 + box.x1) / 2 - el.w / 2+ if (edge === 'top') el.y = box.y0+ if (edge === 'bottom') el.y = box.y1 - el.h+ if (edge === 'middleY') el.y = (box.y0 + box.y1) / 2 - el.h / 2+ }+ }, true)+ }++ /** Even gaps between elements, first and last stay put. */+ private distribute(els: SlideElement[], axis: 'x' | 'y') {+ if (els.length < 3) return+ const size = axis === 'x' ? 'w' : 'h'+ const sorted = [...els].sort((a, b) => a[axis] - b[axis])+ const first = sorted[0]+ const last = sorted[sorted.length - 1]+ const span = last[axis] + last[size] - first[axis]+ const total = sorted.reduce((s, e) => s + e[size], 0)+ const gap = (span - total) / (sorted.length - 1)+ this.edit(() => {+ let cursor = first[axis] + first[size] + gap+ for (const el of sorted.slice(1, -1)) {+ el[axis] = cursor+ cursor += el[size] + gap+ }+ }, true)+ }++ /** Move the selection one step up/down the paint order (adjacent swap). */+ private step(els: SlideElement[], dir: 1 | -1) {+ const ids = new Set(els.map((e) => e.id))+ this.store.commit(() => {+ const arr = this.store.slide.elements+ const idxs = arr.map((e, i) => (ids.has(e.id) ? i : -1)).filter((i) => i >= 0)+ const ordered = dir > 0 ? [...idxs].reverse() : idxs+ for (const i of ordered) {+ const j = i + dir+ if (j < 0 || j >= arr.length || ids.has(arr[j].id)) continue+ ;[arr[i], arr[j]] = [arr[j], arr[i]]+ }+ })+ }++ group(els: SlideElement[]) {+ if (els.length < 2) return+ const gid = `grp-${uid()}`+ this.edit(() => { for (const el of els) el.groupId = gid }, true)+ }++ ungroup(els: SlideElement[]) {+ const gids = new Set(els.map((e) => e.groupId).filter(Boolean))+ this.edit(() => {+ for (const el of this.store.slide.elements) {+ if (el.groupId && gids.has(el.groupId)) delete el.groupId+ }+ }, true)}duplicate(els: SlideElement[]) {+ // clones of grouped elements get fresh group ids (kept consistent within+ // the batch) so a duplicated group is its own group, not the original's+ const gidMap = new Map<string, string>()const clones = els.map((el) => ({...JSON.parse(JSON.stringify(el)),id: `${el.id.replace(/-copy\d*$/, '')}-copy${Math.floor(Math.random() * 1000)}`,x: el.x + 24,y: el.y + 24,+ ...(el.groupId+ ? { groupId: gidMap.get(el.groupId) ?? gidMap.set(el.groupId, `grp-${uid()}`).get(el.groupId)! }+ : {}),}))this.store.commit(() => this.store.slide.elements.push(...clones))this.store.select(clones.map((c) => c.id))diff --git a/slides/src/model.ts b/slides/src/model.tsindex 6cc471fa..f73765f8 100644--- a/slides/src/model.ts+++ b/slides/src/model.ts@@ -42,6 +42,12 @@ export interface ElementBase {link?: string/** semantic group tag — hover focus and multi-element behaviours target it */group?: string+ /**+ * Editor grouping: elements sharing a groupId select and move as one+ * (click any member → whole group; Alt-click digs to the individual).+ * Distinct from `group`, which carries presentation semantics.+ */+ groupId?: string/*** In-slide hover reveal: this element is only visible while an element* whose `group` equals this value is hovered (slide.hover type 'reveal').diff --git a/slides/src/styles.css b/slides/src/styles.cssindex 9e36ba28..9055e3ea 100644--- a/slides/src/styles.css+++ b/slides/src/styles.css@@ -464,6 +464,59 @@ html, body {border-radius: 999px;}+/* arrange kit: align/distribute/z-step buttons */+.ed-arrange { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }+.ed-arrange-btn {+ flex: 1 0 17%;+ min-width: 30px;+ padding: 4px 0;+ font-size: 13px;+ line-height: 1.1;+}+.ed-arrange-btn:disabled { opacity: 0.35; cursor: default; }++/* slide-insertion gaps between sidebar thumbnails */+.ed-insertgap {+ flex: none;+ width: 100%;+ height: 12px;+ margin: -11px 0; /* overlap the sidebar's flex gap so spacing stays as-is */+ position: relative;+ z-index: 3;+ display: flex;+ align-items: center;+ justify-content: center;+ cursor: pointer;+ opacity: 0;+ transition: opacity 0.12s ease;+}+.ed-insertgap:hover { opacity: 1; }+.ed-insertgap::before {+ content: '';+ position: absolute;+ left: 6%;+ right: 6%;+ top: 50%;+ height: 2px;+ margin-top: -1px;+ border-radius: 1px;+ background: #5b8def;+}+.ed-insertgap-btn {+ position: relative;+ z-index: 1;+ border: none;+ background: #5b8def;+ color: #fff;+ border-radius: 50%;+ width: 16px;+ height: 16px;+ font-size: 11px;+ line-height: 1;+ padding: 0;+ cursor: pointer;+}+/* color + alpha pair, and gradient stop rows */.ed-coloralpha { display: flex; align-items: center; gap: 6px; }.ed-coloralpha input[type='number'] { width: 52px; }