@bagelink/vue 1.20.39 → 1.20.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/vue",
3
3
  "type": "module",
4
- "version": "1.20.39",
4
+ "version": "1.20.45",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Bagel Studio",
@@ -63,7 +63,7 @@
63
63
  "@types/signature_pad": "^4.0.0",
64
64
  "vue": "^3.5.43",
65
65
  "vue-component-type-helpers": "^2.2.12",
66
- "@bagelink/sdk": "1.20.39"
66
+ "@bagelink/sdk": "1.20.45"
67
67
  },
68
68
  "peerDependencies": {
69
69
  "@bagelink/sdk": "*",
@@ -1,6 +1,7 @@
1
1
  import type { EditorState } from '../richTextTypes'
2
2
  import { createCommandExecutor, createCommandRegistry } from '../utils/commands'
3
3
  import { computeActiveStyles } from '../utils/selection'
4
+ import { toggleFullscreen, toggleSplitView } from '../utils/viewMode'
4
5
 
5
6
  export function useCommands(state: EditorState, debug?: { logCommand: (command: string, value?: string) => void }) {
6
7
  const commands = createCommandRegistry(state)
@@ -26,13 +27,13 @@ export function useCommands(state: EditorState, debug?: { logCommand: (command:
26
27
  if (['splitView', 'codeView', 'fullScreen'].includes(command)) {
27
28
  switch (command) {
28
29
  case 'splitView':
29
- state.isSplitView = !state.isSplitView
30
+ toggleSplitView(state)
30
31
  return
31
32
  case 'codeView':
32
33
  state.isCodeView = !state.isCodeView
33
34
  return
34
35
  case 'fullScreen':
35
- state.isFullscreen = !state.isFullscreen
36
+ toggleFullscreen(state)
36
37
  return
37
38
  }
38
39
  }
@@ -210,22 +210,41 @@ th {
210
210
  getCleanHTML(), which strips the editor-only .image-figure class from output. */
211
211
  .richtext-editor-content figure.align-full {
212
212
  float: none;
213
+ /* See rich-content.css: without clearing, a full-width figure's box starts at
214
+ the float's top and its badge is painted over the floated media. */
215
+ clear: both;
213
216
  width: 100%;
214
217
  margin-inline: auto;
215
218
  }
216
219
 
220
+ /* The gap is reserved inside the 50% so two opposing floats fit one line:
221
+ 2 × (50% - gap) + 2 × gap = 100%. See rich-content.css for the rationale. */
222
+ .richtext-editor-content figure.align-start,
223
+ .richtext-editor-content figure.align-end {
224
+ --rich-figure-gap: 1.5rem;
225
+ width: 50%;
226
+ max-width: calc(50% - var(--rich-figure-gap) - 1px);
227
+ margin-block: 0.25rem 0.75rem;
228
+ }
229
+
217
230
  .richtext-editor-content figure.align-start {
218
231
  float: inline-start;
219
- max-width: 50%;
220
- margin-block: 0.25rem 0.75rem;
221
- margin-inline: 0 1.5rem;
232
+ margin-inline: 0 var(--rich-figure-gap);
222
233
  }
223
234
 
224
235
  .richtext-editor-content figure.align-end {
225
236
  float: inline-end;
226
- max-width: 50%;
227
- margin-block: 0.25rem 0.75rem;
228
- margin-inline: 1.5rem 0;
237
+ margin-inline: var(--rich-figure-gap) 0;
238
+ }
239
+
240
+ /* Floats collapse their wrapper's height — see rich-content.css. */
241
+ .richtext-editor-content p:has(> figure.align-start),
242
+ .richtext-editor-content p:has(> figure.align-end),
243
+ .richtext-editor-content li:has(> figure.align-start),
244
+ .richtext-editor-content li:has(> figure.align-end),
245
+ .richtext-editor-content div:has(> figure.align-start),
246
+ .richtext-editor-content div:has(> figure.align-end) {
247
+ display: flow-root;
229
248
  }
230
249
 
231
250
  .richtext-editor-content figure.align-start img,
@@ -5,6 +5,7 @@ import type { DropdownItem } from '../../../../index'
5
5
  import { CodeEditor, copyText, Btn, ContextMenu, Dialog, Divider, BglVideo, Icon, Card, ColorInput, pathKeyToURL, usePointerSession } from '../../../../index'
6
6
  import { watch, onUnmounted, onBeforeUnmount, onMounted, ref, computed, useAttrs, inject } from 'vue'
7
7
  import { getRichTextMetrics } from './utils/contentMetrics'
8
+ import { collapseBlockWhitespace, formatBlockHtml } from './utils/htmlFormat'
8
9
  import { insertPastedContent } from './utils/sanitizePaste'
9
10
  import { buildImageFigure, createDefaultImageData, hydrateImageFigures, readImageData } from './utils/image'
10
11
  import { buildVideoFigure, createDefaultVideoData, hydrateVideoFigures, readVideoData, serializeVideoFigures } from './utils/video'
@@ -41,7 +42,7 @@ defineOptions({
41
42
  inheritAttrs: false
42
43
  })
43
44
 
44
- const props = defineProps<{
45
+ const props = withDefaults(defineProps<{
45
46
  modelValue?: string | null
46
47
  toolbarConfig?: ToolbarConfig
47
48
  customToolbarButtons?: CustomToolbarButton[]
@@ -80,7 +81,18 @@ const props = defineProps<{
80
81
  contentStyles?: string
81
82
  // Optional image uploader. Must resolve to a persistent path key or URL.
82
83
  uploadImage?: (file: File) => Promise<string>
83
- } & BagelInputShellProps>()
84
+ /**
85
+ * Indent the HTML in split view for readability. Breaks are added between
86
+ * block-level siblings only — never inside paragraphs or inline markup — and
87
+ * are collapsed again before the value reaches the document, so the rendered
88
+ * and emitted content is unchanged. Set to `false` to show the raw markup.
89
+ */
90
+ splitViewFormat?: boolean
91
+ } & BagelInputShellProps>(), {
92
+ // Boolean props default to `false` at runtime when absent, so the opt-out
93
+ // needs an explicit default to keep formatting on by default.
94
+ splitViewFormat: true,
95
+ })
84
96
 
85
97
  const emit = defineEmits(['update:modelValue', 'limit-exceeded'])
86
98
 
@@ -2947,6 +2959,10 @@ async function initEditor() {
2947
2959
  margin: 0;
2948
2960
  padding: 14px 8px 8px 8px;
2949
2961
  min-height: 200px;
2962
+ /* Floated figures do not contribute height, so without a block
2963
+ formatting context the editable body collapses and content below
2964
+ overlaps the floats. */
2965
+ display: flow-root;
2950
2966
  font-family: ${currentFontFamily.value};
2951
2967
  line-height: 1.5;
2952
2968
  color: ${currentTextColor.value};
@@ -3289,22 +3305,32 @@ async function initEditor() {
3289
3305
  /* Default: full width block. */
3290
3306
  figure.align-full {
3291
3307
  float: none;
3308
+ /* A block box following a float starts at the float's top, which paints
3309
+ this figure's edit badge over the floated media above it. Clearing
3310
+ forces the new row that "full width" implies. */
3311
+ clear: both;
3292
3312
  width: 100%;
3293
3313
  margin-inline: 0;
3294
3314
  }
3295
3315
 
3316
+ /* Gap reserved inside the 50% so two opposing floats share a line:
3317
+ 2 × (50% - gap) + 2 × gap = 100%. */
3318
+ figure.align-start,
3319
+ figure.align-end {
3320
+ --rich-figure-gap: 1.25em;
3321
+ width: 50%;
3322
+ max-width: calc(50% - var(--rich-figure-gap) - 1px);
3323
+ margin-block: 0.25em 0.75em;
3324
+ }
3325
+
3296
3326
  figure.align-start {
3297
3327
  float: inline-start;
3298
- max-width: 50%;
3299
- margin-block: 0.25em 0.75em;
3300
- margin-inline: 0 1.25em;
3328
+ margin-inline: 0 var(--rich-figure-gap);
3301
3329
  }
3302
3330
 
3303
3331
  figure.align-end {
3304
3332
  float: inline-end;
3305
- max-width: 50%;
3306
- margin-block: 0.25em 0.75em;
3307
- margin-inline: 1.25em 0;
3333
+ margin-inline: var(--rich-figure-gap) 0;
3308
3334
  }
3309
3335
 
3310
3336
  figure.align-start img,
@@ -3314,7 +3340,20 @@ async function initEditor() {
3314
3340
 
3315
3341
  figure.video-figure.align-start,
3316
3342
  figure.video-figure.align-end {
3317
- max-width: 50%;
3343
+ max-width: calc(50% - var(--rich-figure-gap) - 1px);
3344
+ }
3345
+
3346
+ /* Floats remove themselves from flow, so a paragraph whose only children
3347
+ are floated figures collapses to zero height and the next block is
3348
+ painted over them. flow-root gives the wrapper back its height
3349
+ without clipping the edit badges or captions. */
3350
+ p:has(> figure.align-start),
3351
+ p:has(> figure.align-end),
3352
+ li:has(> figure.align-start),
3353
+ li:has(> figure.align-end),
3354
+ div:has(> figure.align-start),
3355
+ div:has(> figure.align-end) {
3356
+ display: flow-root;
3318
3357
  }
3319
3358
 
3320
3359
  figure.video-figure .video-container {
@@ -3705,20 +3744,26 @@ watch(normalizedModelValue, (newValue) => {
3705
3744
  editor.state.content = doc.body.innerHTML
3706
3745
  })
3707
3746
 
3708
- // Clean HTML model for Split View (CodeEditor) so internal editor chrome is never exposed
3747
+ // Clean HTML model for Split View (CodeEditor) so internal editor chrome is never exposed.
3748
+ // The pretty form is cosmetic: it only adds line breaks between block-level siblings,
3749
+ // where HTML discards whitespace, and every write is collapsed back to the canonical
3750
+ // single-line form so the document and the emitted model never change.
3751
+ const splitViewFormatting = computed(() => props.splitViewFormat !== false)
3709
3752
  const splitViewHtml = computed({
3710
3753
  get: () => {
3711
3754
  void editor.state.content
3712
- return editor.state.doc ? getCleanHTML(editor.state.doc) : editor.state.content
3755
+ const html = editor.state.doc ? getCleanHTML(editor.state.doc) : editor.state.content
3756
+ return splitViewFormatting.value ? formatBlockHtml(html) : html
3713
3757
  },
3714
3758
  set: (val: string) => {
3759
+ const next = splitViewFormatting.value ? collapseBlockWhitespace(val) : val
3715
3760
  const doc = editor.state.doc
3716
3761
  if (!doc?.body) {
3717
- editor.state.content = val
3762
+ editor.state.content = next
3718
3763
  return
3719
3764
  }
3720
3765
  pushHistorySnapshot(editor.state, editor.state.content)
3721
- doc.body.innerHTML = val
3766
+ doc.body.innerHTML = next
3722
3767
  setupTableEditButtons(doc)
3723
3768
  editor.state.content = doc.body.innerHTML
3724
3769
  }
@@ -3850,7 +3895,7 @@ const imgTransform = computed({
3850
3895
  />
3851
3896
  </div>
3852
3897
  <CodeEditor
3853
- v-if="editor.state.isSplitView" v-model="splitViewHtml" language="html" wrap
3898
+ v-if="editor.state.isSplitView" v-model="splitViewHtml" language="html" :autodetect="false" wrap
3854
3899
  :height="editor.state.isFullscreen ? 'calc(100vh - 4rem)' : editorHeight"
3855
3900
  />
3856
3901
  </div>
@@ -2,6 +2,7 @@ import type { EditorState } from '../richTextTypes'
2
2
  import { pushHistorySnapshot, restoreHistoryNodes } from '../composables/useEditor'
3
3
  import { insertLink } from './media'
4
4
  import { isStyleActive } from './selection'
5
+ import { toggleFullscreen, toggleSplitView } from './viewMode'
5
6
  import {
6
7
  addRow,
7
8
  alignColumn,
@@ -1484,8 +1485,8 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
1484
1485
  }
1485
1486
 
1486
1487
  const viewCommands: CommandRegistry = {
1487
- fullScreen: createCommand('Full Screen', (s) => { s.isFullscreen = !s.isFullscreen }, s => s.isFullscreen, { skipHistory: true }),
1488
- splitView: createCommand('Split View', (s) => { s.isSplitView = !s.isSplitView }, s => s.isSplitView, { skipHistory: true }),
1488
+ fullScreen: createCommand('Full Screen', toggleFullscreen, s => s.isFullscreen, { skipHistory: true }),
1489
+ splitView: createCommand('Split View', toggleSplitView, s => s.isSplitView, { skipHistory: true }),
1489
1490
  codeView: createCommand('Code View', (s) => { s.isCodeView = !s.isCodeView }, s => s.isCodeView, { skipHistory: true })
1490
1491
  }
1491
1492
 
@@ -0,0 +1,268 @@
1
+ /**
2
+ * Block-aware HTML formatting for the rich-text split view.
3
+ *
4
+ * The split view is a plain `<textarea>` laid transparently over highlighted
5
+ * output, so every line break the user *sees* is a line break in the model. There
6
+ * is no "display only" formatting to be had — which is why this module only ever
7
+ * touches whitespace, and only where HTML guarantees it is invisible: between two
8
+ * block-level siblings. Collapsible whitespace there generates no box at all, so
9
+ * the rendered document is unchanged.
10
+ *
11
+ * Deliberately string-based rather than DOM-based. Round-tripping through
12
+ * `DOMParser`/`innerHTML` would silently rewrite the document (entity references,
13
+ * attribute quoting, `<br/>` → `<br>`, tag case, invalid nesting), which is far
14
+ * worse than an unformatted view. Here every byte that is not removed whitespace
15
+ * is copied verbatim, and the two functions are exact inverses:
16
+ *
17
+ * collapseBlockWhitespace(formatBlockHtml(html)) === collapseBlockWhitespace(html)
18
+ *
19
+ * `formatBlockHtml` is cosmetic; `collapseBlockWhitespace` runs on every write
20
+ * back to the document, so stored and emitted content stays in the same canonical
21
+ * form as before.
22
+ */
23
+
24
+ /** Elements whose sibling boundaries are whitespace-insensitive. */
25
+ const BLOCK_TAGS = new Set([
26
+ 'address', 'article', 'aside', 'blockquote', 'body', 'canvas', 'caption',
27
+ 'colgroup', 'dd', 'details', 'dialog', 'div', 'dl', 'dt', 'fieldset',
28
+ 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
29
+ 'head', 'header', 'hgroup', 'hr', 'html', 'legend', 'li', 'main', 'nav',
30
+ 'noscript', 'object', 'ol', 'p', 'pre', 'script', 'section', 'style',
31
+ 'summary', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'ul',
32
+ ])
33
+
34
+ /** Copied verbatim as a single unit — whitespace inside is meaningful or raw text. */
35
+ const OPAQUE_TAGS = new Set([
36
+ 'audio', 'canvas', 'iframe', 'math', 'noscript', 'object', 'pre', 'script',
37
+ 'style', 'svg', 'template', 'textarea', 'video',
38
+ ])
39
+
40
+ const VOID_TAGS = new Set([
41
+ 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta',
42
+ 'param', 'source', 'track', 'wbr',
43
+ ])
44
+
45
+ type TokenType = 'text' | 'tag' | 'opaque'
46
+
47
+ interface Token {
48
+ type: TokenType
49
+ raw: string
50
+ /** Lowercase tag name; `undefined` for text tokens. */
51
+ name?: string
52
+ /** Only meaningful for `tag` tokens. */
53
+ kind?: 'open' | 'close'
54
+ }
55
+
56
+ const TAG_PATTERN = /^<\s*(\/?)\s*([a-zA-Z][a-zA-Z0-9:-]*)/
57
+ /**
58
+ * Only ASCII whitespace is collapsible. `\s` also matches U+00A0 and other
59
+ * Unicode spaces, which *do* render — a non-breaking space between two blocks is
60
+ * how authors force an extra visible line — so it must never be treated as
61
+ * removable. Zero-width characters are deliberate too and are left alone.
62
+ */
63
+ const WHITESPACE_PATTERN = /^[ \t\n\r\f]*$/
64
+
65
+ function isWhitespaceOnly(value: string): boolean {
66
+ return WHITESPACE_PATTERN.test(value)
67
+ }
68
+
69
+ function isBlockToken(token: Token | undefined): boolean {
70
+ return Boolean(token?.name && BLOCK_TAGS.has(token.name))
71
+ }
72
+
73
+ /** Position right after this token is a block boundary. */
74
+ function endsBlock(token: Token | undefined): boolean {
75
+ if (!token?.name) { return false }
76
+ if (!isBlockToken(token)) { return false }
77
+ // An opening tag of a void/self-closed block (`<hr>`) also ends a block.
78
+ return token.type === 'opaque' || token.kind !== 'open' || VOID_TAGS.has(token.name)
79
+ }
80
+
81
+ /** Position right before this token is a block boundary. */
82
+ function startsBlock(token: Token | undefined): boolean {
83
+ return Boolean(token?.name && BLOCK_TAGS.has(token.name) && (token.type === 'opaque' || token.kind === 'open'))
84
+ }
85
+
86
+ /** Finds the end of an opaque element, honouring same-name nesting. */
87
+ function findOpaqueEnd(html: string, from: number, name: string): number {
88
+ const lower = html.toLowerCase()
89
+ let depth = 1
90
+ let cursor = from
91
+
92
+ while (depth > 0) {
93
+ const open = lower.indexOf(`<${name}`, cursor)
94
+ const close = lower.indexOf(`</${name}`, cursor)
95
+ if (close === -1) { return html.length }
96
+ if (open !== -1 && open < close) {
97
+ depth++
98
+ cursor = open + name.length + 1
99
+ continue
100
+ }
101
+ depth--
102
+ const gt = findTagEnd(html, close)
103
+ cursor = gt === -1 ? html.length : gt + 1
104
+ }
105
+
106
+ return cursor
107
+ }
108
+
109
+ /**
110
+ * Locates the `>` that closes a tag, skipping any `>` inside a quoted attribute
111
+ * value (`<p title="a > b">`). Returns -1 when the tag is never closed.
112
+ */
113
+ function findTagEnd(html: string, from: number): number {
114
+ let quote = ''
115
+ for (let i = from; i < html.length; i++) {
116
+ const char = html[i]
117
+ if (quote) {
118
+ if (char === quote) { quote = '' }
119
+ continue
120
+ }
121
+ if (char === '"' || char === '\'') {
122
+ quote = char
123
+ continue
124
+ }
125
+ if (char === '>') { return i }
126
+ }
127
+ return -1
128
+ }
129
+
130
+ function tokenize(html: string): Token[] {
131
+ const tokens: Token[] = []
132
+ const pushText = (raw: string) => {
133
+ if (raw) { tokens.push({ type: 'text', raw }) }
134
+ }
135
+
136
+ let cursor = 0
137
+ while (cursor < html.length) {
138
+ const lt = html.indexOf('<', cursor)
139
+ if (lt === -1) {
140
+ pushText(html.slice(cursor))
141
+ break
142
+ }
143
+ pushText(html.slice(cursor, lt))
144
+
145
+ if (html.startsWith('<!--', lt)) {
146
+ const end = html.indexOf('-->', lt + 4)
147
+ const stop = end === -1 ? html.length : end + 3
148
+ tokens.push({ type: 'opaque', raw: html.slice(lt, stop) })
149
+ cursor = stop
150
+ continue
151
+ }
152
+ // Doctype, processing instructions and CDATA carry no block semantics.
153
+ if (html.startsWith('<!', lt) || html.startsWith('<?', lt)) {
154
+ const end = findTagEnd(html, lt)
155
+ const stop = end === -1 ? html.length : end + 1
156
+ tokens.push({ type: 'opaque', raw: html.slice(lt, stop) })
157
+ cursor = stop
158
+ continue
159
+ }
160
+
161
+ const match = TAG_PATTERN.exec(html.slice(lt, lt + 80))
162
+ const gt = match ? findTagEnd(html, lt) : -1
163
+ if (!match || gt === -1) {
164
+ // A stray `<` in text: keep it as text rather than guessing.
165
+ pushText('<')
166
+ cursor = lt + 1
167
+ continue
168
+ }
169
+
170
+ const name = (match[2] ?? '').toLowerCase()
171
+ const closing = match[1] === '/'
172
+ const raw = html.slice(lt, gt + 1)
173
+ cursor = gt + 1
174
+
175
+ if (!closing && OPAQUE_TAGS.has(name) && !VOID_TAGS.has(name)) {
176
+ const end = findOpaqueEnd(html, cursor, name)
177
+ tokens.push({ type: 'opaque', raw: html.slice(lt, end), name })
178
+ cursor = end
179
+ continue
180
+ }
181
+
182
+ tokens.push({ type: 'tag', raw, name, kind: closing ? 'close' : 'open' })
183
+ }
184
+
185
+ return tokens
186
+ }
187
+
188
+ /**
189
+ * Walks the tokens once. Removable whitespace is either dropped (`compact`) or
190
+ * replaced by a line break plus indentation for the current block depth
191
+ * (`pretty`); everything else is copied byte for byte.
192
+ */
193
+ function transform(tokens: Token[], mode: 'pretty' | 'compact', indent: string): string {
194
+ // Indices of tokens that are not pure whitespace, used to decide whether a
195
+ // whitespace run sits at a block boundary.
196
+ const significant: number[] = []
197
+ for (let i = 0; i < tokens.length; i++) {
198
+ const token = tokens[i]!
199
+ if (!(token.type === 'text' && isWhitespaceOnly(token.raw))) { significant.push(i) }
200
+ }
201
+
202
+ const nextSignificantAfter = (index: number): Token | undefined => {
203
+ for (const candidate of significant) {
204
+ if (candidate > index) { return tokens[candidate] }
205
+ }
206
+ return undefined
207
+ }
208
+
209
+ let out = ''
210
+ let depth = 0
211
+ let previous: Token | undefined
212
+
213
+ for (let i = 0; i < tokens.length; i++) {
214
+ const token = tokens[i]!
215
+ const isBlank = token.type === 'text' && isWhitespaceOnly(token.raw)
216
+
217
+ if (isBlank) {
218
+ const next = nextSignificantAfter(i)
219
+ const removable = endsBlock(previous) || startsBlock(next)
220
+ if (removable) { continue }
221
+ out += token.raw
222
+ previous = token
223
+ continue
224
+ }
225
+
226
+ // Closing a block drops one level before the tag's own line is written.
227
+ if (token.type === 'tag' && token.kind === 'close' && isBlockToken(token) && depth > 0) { depth-- }
228
+
229
+ if (mode === 'pretty' && out && (endsBlock(previous) || startsBlock(token))) {
230
+ out += `\n${indent.repeat(depth)}`
231
+ }
232
+
233
+ out += token.raw
234
+
235
+ if (token.type === 'tag' && token.kind === 'open' && isBlockToken(token) && !VOID_TAGS.has(token.name!)) { depth++ }
236
+ previous = token
237
+ }
238
+
239
+ return out
240
+ }
241
+
242
+ /**
243
+ * Adds indentation between block-level siblings only.
244
+ * Returns the input untouched when the result cannot be proven equivalent.
245
+ */
246
+ export function formatBlockHtml(html: string, indent = ' '): string {
247
+ if (!html) { return html }
248
+
249
+ const tokens = tokenize(html)
250
+ const pretty = transform(tokens, 'pretty', indent)
251
+ if (pretty === html) { return html }
252
+
253
+ // The only intended difference is the breaks we added, so collapsing both
254
+ // sides must give the same string. Anything else means a tokenizer bug and
255
+ // the formatting is discarded rather than applied.
256
+ if (transform(tokens, 'compact', indent) !== collapseBlockWhitespace(html)) { return html }
257
+
258
+ return pretty
259
+ }
260
+
261
+ /**
262
+ * Inverse of {@link formatBlockHtml}: removes whitespace that sits at a block
263
+ * boundary and copies every other byte unchanged.
264
+ */
265
+ export function collapseBlockWhitespace(html: string): string {
266
+ if (!html) { return html }
267
+ return transform(tokenize(html), 'compact', '')
268
+ }
@@ -0,0 +1,28 @@
1
+ import type { EditorState } from '../richTextTypes'
2
+
3
+ /**
4
+ * Split-view state captured when fullscreen was entered, so leaving fullscreen
5
+ * restores the layout the author had before rather than leaving the code pane
6
+ * open. Split view is only meaningful with the room fullscreen provides; when it
7
+ * survives the exit it reads as a glitch, not as an intent.
8
+ */
9
+ const splitViewBeforeFullscreen = new WeakMap<object, boolean>()
10
+
11
+ export function toggleSplitView(state: EditorState) {
12
+ state.isSplitView = !state.isSplitView
13
+ }
14
+
15
+ export function toggleFullscreen(state: EditorState) {
16
+ if (!state.isFullscreen) {
17
+ splitViewBeforeFullscreen.set(state, state.isSplitView)
18
+ state.isFullscreen = true
19
+ return
20
+ }
21
+
22
+ state.isFullscreen = false
23
+ const restore = splitViewBeforeFullscreen.get(state)
24
+ splitViewBeforeFullscreen.delete(state)
25
+ // Split view turned on *inside* fullscreen does not outlive it; one that was
26
+ // already open before entering stays open.
27
+ state.isSplitView = restore ?? false
28
+ }
@@ -165,18 +165,24 @@ defineExpose({ open, close })
165
165
  padding: 0;
166
166
  }
167
167
 
168
- .bgl-lightbox:has(.bgl_vid) {
169
- width: 90vw;
170
- }
171
-
172
- .bgl-lightbox:has(.vid_short) {
173
- width: auto;
174
- aspect-ratio: 9/16;
175
- height: 90vh;
176
- }
177
-
178
- .bgl-lightbox:has(.vid_short) .bgl-lightbox-item * {
179
- max-height: unset !important;
168
+ /* Shorts are portrait (9:16). Size the frame from the available HEIGHT and let the
169
+ width follow from the aspect ratio — pinning a width (90vw) and clamping only the
170
+ height distorts the frame into a wider box, which makes YouTube letterbox the
171
+ vertical clip with black bars on both sides. */
172
+ .bgl-lightbox-overlay:has(.vid_short) .bgl-lightbox-item .lightbox-video,
173
+ .bgl-lightbox-overlay:has(.vid_short) .bgl-lightbox-item .lightbox-video iframe {
174
+ width: auto;
175
+ height: 100%;
176
+ max-width: none;
177
+ max-height: none;
178
+ }
179
+
180
+ .bgl-lightbox-overlay:has(.vid_short) .bgl-lightbox-item .lightbox-video iframe {
181
+ aspect-ratio: 9 / 16;
182
+ /* On narrow screens the height-driven width would exceed the viewport, so cap the
183
+ height instead (90vw wide → ×16/9 = 160vw tall) — the width then re-derives from
184
+ the ratio, keeping a true 9:16 frame. */
185
+ max-height: min(100%, 160vw);
180
186
  }
181
187
 
182
188
  .lightbox-image {
@@ -37,26 +37,52 @@ figure[data-media-type='video'] video {
37
37
 
38
38
  figure.align-full {
39
39
  float: none;
40
- width: 100% !important;
40
+ /* A block box that follows a float starts at the float's top, so a full-width
41
+ figure would paint its box (and its edit badge) over the floated media while
42
+ its image stays below. Clearing forces the new row the width implies. */
43
+ clear: both;
44
+ width: 100%;
41
45
  max-width: 100%;
42
46
  margin-inline: 0;
43
47
  }
44
48
 
49
+ /* Floats only share a line while their outer widths fit. The gap is reserved
50
+ *inside* the 50% instead of being added on top of it, so a pair of opposing
51
+ floats fits exactly once:
52
+ 2 × (50% - gap) + 2 × gap = 100%
53
+ Without that, 50% + gap twice always overflows and the second figure drops to
54
+ the next line. The extra 1px absorbs sub-pixel rounding.
55
+ `!important` is deliberately absent so an explicit width from the author (the
56
+ inline style written from `data-width`) still wins. */
45
57
  figure.align-start,
46
58
  figure.align-end {
47
- width: 50% !important;
48
- max-width: 50%;
59
+ --rich-figure-gap: 1.25em;
60
+ width: 50%;
61
+ max-width: calc(50% - var(--rich-figure-gap) - 1px);
49
62
  margin-block: 0.25em 0.75em;
50
63
  }
51
64
 
52
65
  figure.align-start {
53
66
  float: inline-start;
54
- margin-inline: 0 1.25em;
67
+ margin-inline: 0 var(--rich-figure-gap);
55
68
  }
56
69
 
57
70
  figure.align-end {
58
71
  float: inline-end;
59
- margin-inline: 1.25em 0;
72
+ margin-inline: var(--rich-figure-gap) 0;
73
+ }
74
+
75
+ /* Floated figures take themselves out of flow, so a wrapper whose only children
76
+ are floats collapses to zero height and whatever follows is painted on top of
77
+ them. `flow-root` establishes a block formatting context without clipping the
78
+ overlapping badges or captions. */
79
+ p:has(> figure.align-start),
80
+ p:has(> figure.align-end),
81
+ li:has(> figure.align-start),
82
+ li:has(> figure.align-end),
83
+ div:has(> figure.align-start),
84
+ div:has(> figure.align-end) {
85
+ display: flow-root;
60
86
  }
61
87
 
62
88
  .video-responsive {