Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

RTL chrome: viewer-scoped direction, with every slide surface pinned LTR

nyblnetaa12698ad87d
diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.ts
index 3a97fb2d..4a90d5f4 100644
--- a/slides/src/editor/editor.ts
+++ b/slides/src/editor/editor.ts
@@ -23,7 +23,7 @@ import { insertElements, insertSlides, parseClip, serializeElements, serializeSl
import { openSpeakerWindow, speakerIdleBody } from '../screens'
import { borderPoint, boxCenter, lineEndpoints, setLineEndpoints, sideMidpoint } from './lineedit'
import { ICONS } from '../icons'
-import { t, setLocale, locale, LOCALE_CHOICES } from '../i18n'
+import { t, setLocale, locale, LOCALE_CHOICES, applyDirection } from '../i18n'
import { appConfig } from '../../../kernel/src/app.ts'
import { disconnectOnline, joinFromDoc, mintCollab, mintInvite, onlineTransport, rotateKeys, sharingOn, startSharing, stopSharing } from '../sync/online'
@@ -987,6 +987,8 @@ export class Editor {
const b = btn('', c.label, () => {
wrap.classList.remove('open')
setLocale(c.code)
+ // switching to (or away from) Arabic/Hebrew/… turns the chrome around
+ applyDirection()
this.build()
this.rebuildSidebar()
})
diff --git a/slides/src/i18n.ts b/slides/src/i18n.ts
index ee23e2e0..8a90cf20 100644
--- a/slides/src/i18n.ts
+++ b/slides/src/i18n.ts
@@ -18,7 +18,7 @@
// node scripts/build-i18n.mjs
//
import { PACKED, PACKED_LOCALES } from './i18n/packed'
-import { registerI18n } from '../../kernel/src/i18n.ts'
+import { registerI18n, locale as localeCode } from '../../kernel/src/i18n.ts'
import type { LocaleChoice } from '../../kernel/src/i18n.ts'
export type { Catalog } from '../../kernel/src/i18n.ts'
@@ -59,3 +59,51 @@ registerI18n({
export const LOCALE_CHOICES = CHOICES
export { t, locale, setLocale, i18nApi, localeChoices } from '../../kernel/src/i18n.ts'
+
+// --- writing direction -------------------------------------------------------
+//
+// Direction is a property of the VIEWER's language, exactly like the language
+// itself: it follows navigator.language / the 'bento-lang' override and NEVER
+// enters the document format. A deck authored in Cairo must open in Chicago
+// looking byte-identical — only the chrome around it turns around.
+//
+// Base-language matching (not a full locale table) so a runtime language pack
+// (docs/i18n-packs.md) adding Arabic or Hebrew gets an RTL chrome for free,
+// with no release: 'ar', 'ar-EG' and 'he-IL' all resolve here.
+const RTL_LANGS = new Set([
+ 'ar', // Arabic
+ 'he', // Hebrew
+ 'fa', // Persian
+ 'ur', // Urdu
+ 'ps', // Pashto
+ 'sd', // Sindhi
+ 'ug', // Uyghur
+ 'yi', // Yiddish
+ 'dv', // Divehi
+ 'ckb', // Central Kurdish
+ 'ku', // Kurdish (Sorani conventions)
+ 'nqo', // N'Ko
+])
+
+/** Does this locale (default: the active one) write right-to-left? */
+export function isRtl(code?: string): boolean {
+ return RTL_LANGS.has((code ?? localeCode()).split('-')[0])
+}
+
+/**
+ * Point the CHROME at the viewer's writing direction.
+ *
+ * Set on <html> so body-mounted chrome (dialogs, menus, popovers, toasts)
+ * turns around with the editor. Everything that draws the DOCUMENT is pinned
+ * back to `direction: ltr` in styles.css — the slide surface carries absolute
+ * x/y model coordinates, so mirroring it would move every element of every
+ * existing deck. See the "never mirror the document" block there.
+ *
+ * Safe to call any time AFTER capturePristine(): saves re-serialize the
+ * pristine boot clone, so this attribute can never reach a saved file.
+ */
+export function applyDirection(): void {
+ const el = document.documentElement
+ el.dir = isRtl() ? 'rtl' : 'ltr'
+ el.lang = localeCode()
+}
diff --git a/slides/src/main.ts b/slides/src/main.ts
index bf5039df..783b4028 100644
--- a/slides/src/main.ts
+++ b/slides/src/main.ts
@@ -11,7 +11,7 @@ import {
suggestedFileName, parseEnvelope, decryptEnvelope, setEncryptionPassword,
} from './save'
import { APP_VERSION, checkForUpdates, buildUpdatedFile, applyUpdate } from './update'
-import { i18nApi, t } from './i18n'
+import { i18nApi, t, applyDirection } from './i18n'
import { parseDoc, type BentoDoc } from './model'
import { starterDoc } from './starterdeck'
import { injectFonts } from './fonts'
@@ -31,6 +31,13 @@ configureApp({
capturePristine()
+// Chrome direction follows the VIEWER's language (Arabic/Hebrew/… get an RTL
+// interface). Deliberately AFTER capturePristine: saves re-serialize the
+// pristine clone, so the dir/lang attributes never reach a saved file — the
+// same viewer-scoped rule as 'bento-lang' and reduced motion. The DOCUMENT
+// never mirrors; styles.css pins every slide surface back to direction: ltr.
+applyDirection()
+
// --- boot gates: password-encrypted files, read-only player files -----------
const embedded = readEmbeddedDoc()
diff --git a/slides/src/styles.css b/slides/src/styles.css
index 5e7b8c78..755c9120 100644
--- a/slides/src/styles.css
+++ b/slides/src/styles.css
@@ -51,6 +51,40 @@ select, .ed-row input, .ed-row textarea {
}
option { background: #fff; color: #1e2a3a; }
+/* ————— THE DOCUMENT NEVER MIRRORS —————————————————————————————————————————
+ An Arabic/Hebrew viewer gets an RTL *chrome* (i18n.ts applyDirection sets
+ dir on <html>). The DOCUMENT must be immune to that: slide elements carry
+ absolute x/y model coordinates, so a mirrored surface would move every
+ element of every existing deck, and the same file would look different
+ depending on who opened it — a format-level bug, far worse than an
+ unmirrored panel.
+
+ So every surface that draws slide content is pinned back to LTR:
+
+ - .bento-slide is the SHARED root of the canvas stage, sidebar thumbnails,
+ present sections, print pages and the speaker view's frames (render.ts
+ renderSlide), so this one rule covers all four surfaces at once. The
+ containers are pinned too, belt and braces, because they also carry
+ positioned chrome of their own.
+ - .ed-scroll additionally protects the canvas COORDINATE MATH: direction
+ changes what scrollLeft means (0 at the right edge, negative leftwards),
+ and canvas.ts reads/writes scrollLeft to centre and to pin the stage
+ during Moveable gestures. Pinned, none of that math can shift.
+ - .moveable-control-box is mounted with rootContainer: document.body, i.e.
+ outside the canvas subtree — it needs its own pin.
+
+ Text INSIDE elements still resolves its own direction per element, from the
+ content the author typed (render.ts sets dir="auto"). That is the content
+ half of RTL and is unaffected by any of this. */
+.bento-slide,
+.bento-thumb-surface,
+.ed-scroll,
+.bento-present-overlay,
+.moveable-control-box,
+#bento-print {
+ direction: ltr;
+}
+
/* ————— topbar ————— */
.ed-topbar {