Bento, the office suite that fits in a file
TypeScript mit-licenseofficeoffice-365office-suiteoffice-toolsoffice365open-sourcepowerpointself-hostedsingle-page-appslidesslideshareslideshowslideshow-galleryslideshow-makerslideshows
Canvas zoom control; state thumbs smaller-centred instead of indented
nyblnet8f56ea95504d
diff --git a/slides/src/editor/canvas.ts b/slides/src/editor/canvas.tsindex ec65561e..b465b526 100644--- a/slides/src/editor/canvas.ts+++ b/slides/src/editor/canvas.ts@@ -11,22 +11,37 @@ import { renderSlide, sanitizeHtml } from '../render'export class SlideCanvas {private stage: HTMLElementprivate scaleHost: HTMLElement+ private scroller: HTMLElementprivate surface: HTMLElement | null = nullprivate moveable: Moveableprivate selecto: Selectoprivate scale = 1+ private fitScale = 1+ /** user zoom, multiplier on the fitted scale (1 = fit to window) */+ private zoom = 1+ private zoomLabel: HTMLElement | null = nullprivate editing: HTMLElement | null = nullconstructor(private wrap: HTMLElement,private store: Store,) {+ this.scroller = document.createElement('div')+ this.scroller.className = 'ed-scroll'this.stage = document.createElement('div')this.stage.className = 'ed-stage'this.scaleHost = document.createElement('div')this.scaleHost.className = 'ed-stage-scale'this.stage.appendChild(this.scaleHost)- wrap.appendChild(this.stage)+ this.scroller.appendChild(this.stage)+ wrap.appendChild(this.scroller)+ this.buildZoomBar()+ // pinch / ctrl+wheel zooms like every design tool+ this.scroller.addEventListener('wheel', (ev) => {+ if (!ev.ctrlKey && !ev.metaKey) return+ ev.preventDefault()+ this.setZoom(this.zoom * (ev.deltaY < 0 ? 1.12 : 1 / 1.12))+ }, { passive: false })// Control box lives INSIDE the scaled host with rootContainer at body:// Moveable then works in slide-local coordinates (e.left/e.top are model@@ -78,15 +93,53 @@ export class SlideCanvas {relayout() {const { width, height } = this.store.doc.size- const availW = this.wrap.clientWidth - 64- const availH = this.wrap.clientHeight - 64+ const availW = this.scroller.clientWidth - 64+ const availH = this.scroller.clientHeight - 64if (availW <= 0 || availH <= 0) return- this.scale = Math.min(availW / width, availH / height)+ this.fitScale = Math.min(availW / width, availH / height)+ this.scale = this.fitScale * this.zoomthis.stage.style.width = `${width * this.scale}px`this.stage.style.height = `${height * this.scale}px`this.scaleHost.style.transform = `scale(${this.scale})`this.moveable.zoom = 1 / this.scalethis.moveable.updateRect()+ if (this.zoomLabel) this.zoomLabel.textContent = `${Math.round(this.scale * 100)}%`+ }++ // --- zoom ------------------------------------------------------------------++ setZoom(zoom: number) {+ this.zoom = Math.min(Math.max(zoom, 0.5), 8)+ this.relayout()+ // keep the view centred on the slide as it grows/shrinks+ this.scroller.scrollLeft = (this.scroller.scrollWidth - this.scroller.clientWidth) / 2+ this.scroller.scrollTop = (this.scroller.scrollHeight - this.scroller.clientHeight) / 2+ }++ zoomIn() { this.setZoom(this.zoom * 1.25) }+ zoomOut() { this.setZoom(this.zoom / 1.25) }+ zoomReset() { this.setZoom(1) }++ private buildZoomBar() {+ const bar = document.createElement('div')+ bar.className = 'ed-zoombar'+ const mk = (label: string, title: string, onClick: () => void) => {+ const b = document.createElement('button')+ b.className = 'ed-zoombtn'+ b.textContent = label+ b.title = title+ b.addEventListener('click', onClick)+ return b+ }+ const label = mk('100%', 'Reset zoom to fit (⌘0)', () => this.zoomReset())+ label.classList.add('ed-zoomlabel')+ this.zoomLabel = label+ bar.append(+ mk('−', 'Zoom out (⌘−)', () => this.zoomOut()),+ label,+ mk('+', 'Zoom in (⌘+)', () => this.zoomIn()),+ )+ this.wrap.appendChild(bar)}render() {diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.tsindex efce34f2..0c3bc5f3 100644--- a/slides/src/editor/editor.ts+++ b/slides/src/editor/editor.ts@@ -132,7 +132,7 @@ export class Editor {} else {num.textContent = String(this.linearNumber(i))}- const surface = renderThumbnail(slide, this.store.doc, 148)+ const surface = renderThumbnail(slide, this.store.doc, isState ? 124 : 148)const tools = div('ed-thumb-tools')tools.append(btn(ICONS.copy, '', (ev) => { ev.stopPropagation(); this.duplicateSlide(i) }, 'Duplicate slide'),@@ -306,6 +306,21 @@ export class Editor {this.save(false)return}+ if (mod && (ev.key === '=' || ev.key === '+')) {+ ev.preventDefault()+ this.canvas.zoomIn()+ return+ }+ if (mod && ev.key === '-') {+ ev.preventDefault()+ this.canvas.zoomOut()+ return+ }+ if (mod && ev.key === '0') {+ ev.preventDefault()+ this.canvas.zoomReset()+ return+ }if (ev.key === 'F5') {ev.preventDefault()this.present(!ev.shiftKey)diff --git a/slides/src/styles.css b/slides/src/styles.cssindex 61a1dad8..52ddc82a 100644--- a/slides/src/styles.css+++ b/slides/src/styles.css@@ -166,18 +166,17 @@ html, body {.ed-add-slide { border: 1.5px dashed var(--line); justify-content: center; color: var(--muted); }-/* interactive-state thumbs nest under their parent slide */+/* interactive-state thumbs: slightly smaller, centred under their parent */.ed-thumb-state {- width: 116px;- margin-left: 32px;- margin-top: -4px;+ width: 124px;+ margin: -2px auto 0;opacity: 0.72;border-style: dashed;}.ed-thumb-state:hover, .ed-thumb-state.active { opacity: 1; }.ed-thumb-state .ed-thumb-num {font-size: 9px;- max-width: 90px;+ max-width: 96px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;@@ -205,9 +204,6 @@ html, body {.ed-canvas-wrap {flex: 1;min-width: 0;- display: flex;- align-items: center;- justify-content: center;background:radial-gradient(circle at 1px 1px, #d5dbe4 1px, transparent 0) 0 0 / 22px 22px,var(--chrome);@@ -215,13 +211,52 @@ html, body {position: relative;}+/* scrollable viewport: auto-margins centre the stage when it fits and+ allow proper scrolling in every direction when zoomed past the window */+.ed-scroll {+ position: absolute;+ inset: 0;+ overflow: auto;+ display: flex;+}+.ed-stage {position: relative;flex: none;+ margin: auto;box-shadow: 0 10px 40px rgb(20 30 45 / 0.18), 0 2px 8px rgb(20 30 45 / 0.10);border-radius: 2px;}+/* zoom controls, bottom-right of the canvas */+.ed-zoombar {+ position: absolute;+ right: 14px;+ bottom: 14px;+ display: flex;+ align-items: center;+ gap: 2px;+ background: #fff;+ border: 1px solid var(--line);+ border-radius: 999px;+ padding: 3px 6px;+ box-shadow: 0 4px 14px rgb(20 30 45 / 0.10);+ z-index: 10;+}+.ed-zoombtn {+ font: inherit;+ font-size: 14px;+ line-height: 1;+ color: var(--ink-2);+ background: transparent;+ border: none;+ border-radius: 999px;+ padding: 5px 9px;+ cursor: pointer;+}+.ed-zoombtn:hover { background: var(--chrome-2); }+.ed-zoomlabel { font-size: 11.5px; min-width: 44px; text-align: center; color: var(--muted); }+.ed-stage-scale { position: absolute; top: 0; left: 0; transform-origin: 0 0; }/* hover-set switcher chips, floating above the canvas */