bloggie 0.4.4 → 0.4.5
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/astro.config.js +2 -1
- package/components/Embed.astro +35 -0
- package/components/YouTube.astro +15 -0
- package/components/slides/Slide.astro +14 -4
- package/e2e/editor.js +41 -6
- package/editor/client.js +56 -24
- package/lib/math-punctuation.js +44 -0
- package/lib/slides.js +10 -0
- package/package.json +1 -1
- package/skills/bloggie-slides/SKILL.md +12 -2
- package/styles/site.css +47 -0
- package/styles/slides.css +37 -0
- package/template/package.json +1 -1
package/astro.config.js
CHANGED
|
@@ -16,6 +16,7 @@ import { root } from './lib/blog.js'
|
|
|
16
16
|
import { katexMacros, remarkRoles } from './lib/roles.js'
|
|
17
17
|
import remarkPostTables from './lib/post-tables.js'
|
|
18
18
|
import remarkSlideHeadings, { rehypeSlideBoxes } from './lib/slide-headings.js'
|
|
19
|
+
import rehypeMathPunctuation from './lib/math-punctuation.js'
|
|
19
20
|
import postDownloads from './scripts/export/dev.js'
|
|
20
21
|
import slideEditor from './editor/integration.js'
|
|
21
22
|
import liveUpdate from './live/integration.js'
|
|
@@ -126,7 +127,7 @@ export default defineConfig({
|
|
|
126
127
|
macros: katexMacros,
|
|
127
128
|
trust: (context) => context.command === '\\htmlClass',
|
|
128
129
|
strict: (code) => (code === 'htmlExtension' ? 'ignore' : 'warn'),
|
|
129
|
-
}], rehypeSlideBoxes, rehypeSourcePositions], // slide-boxes: a <Box style> in slides.mdx styles the element it holds; source-positions: dev only, last (jump/annotate.js)
|
|
130
|
+
}], rehypeMathPunctuation, rehypeSlideBoxes, rehypeSourcePositions], // math-punctuation: no line break between inline math and its punctuation; slide-boxes: a <Box style> in slides.mdx styles the element it holds; source-positions: dev only, last (jump/annotate.js)
|
|
130
131
|
}),
|
|
131
132
|
},
|
|
132
133
|
})
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
// A live web page inside the post or the deck, for an interactive article or a demo that lives on another site. In a
|
|
3
|
+
// post it fills the column at 16:9 and loads when the reader scrolls to it. On an `embed` slide it fills the stage, and
|
|
4
|
+
// it loads only when its slide or the one before it is shown (components/slides/Slide.astro, lib/slides.js), so the
|
|
5
|
+
// pages of a deck do not all run at once. The site must allow framing (no X-Frame-Options or frame-ancestors block).
|
|
6
|
+
//
|
|
7
|
+
// <Embed src="https://distill.pub/2020/growing-ca/" title="Growing Neural Cellular Automata" />
|
|
8
|
+
//
|
|
9
|
+
// With `crop`, only one rectangle of the page shows, such as the demo of an article that has no page of its own: the
|
|
10
|
+
// page is laid out `layout` CSS pixels wide, does not scroll, and the rectangle is scaled to fill the frame.
|
|
11
|
+
//
|
|
12
|
+
// <Embed src="https://distill.pub/2020/growing-ca/" title="Growing NCA, the demo" crop="260 236 920 650" />
|
|
13
|
+
//
|
|
14
|
+
// src the page's URL
|
|
15
|
+
// title the page's title, for screen readers
|
|
16
|
+
// crop optional: "x y width height", the rectangle to show, in CSS pixels of the page laid out `layout` wide
|
|
17
|
+
// layout optional, with crop: the width the page is laid out at (default 1440)
|
|
18
|
+
const { src, title, crop, layout = 1440 } = Astro.props
|
|
19
|
+
const allow = 'fullscreen; clipboard-write; accelerometer; gyroscope'
|
|
20
|
+
const [x, y, w, h] = crop ? crop.trim().split(/\s+/).map(Number) : []
|
|
21
|
+
---
|
|
22
|
+
{crop ? (
|
|
23
|
+
<div class="embed-crop" data-crop-width={w} style={`aspect-ratio: ${w} / ${h}`}>
|
|
24
|
+
<iframe class="embed" src={src} title={title} loading="lazy" allow={allow} allowfullscreen referrerpolicy="strict-origin-when-cross-origin" scrolling="no" style={`width: ${layout}px; height: ${y + h}px; transform: scale(var(--crop-scale, 1)) translate(${-x}px, ${-y}px)`}></iframe>
|
|
25
|
+
</div>
|
|
26
|
+
) : (
|
|
27
|
+
<iframe class="embed" src={src} title={title} loading="lazy" allow={allow} allowfullscreen referrerpolicy="strict-origin-when-cross-origin"></iframe>
|
|
28
|
+
)}
|
|
29
|
+
|
|
30
|
+
<script>
|
|
31
|
+
// A cropped page is scaled so that its rectangle fills the frame's width, in a post or on a slide.
|
|
32
|
+
const fit = (frame: HTMLElement) => frame.style.setProperty('--crop-scale', String(frame.clientWidth / Number(frame.dataset.cropWidth)))
|
|
33
|
+
const observer = new ResizeObserver((entries) => entries.forEach((entry) => fit(entry.target as HTMLElement)))
|
|
34
|
+
document.querySelectorAll<HTMLElement>('.embed-crop').forEach((frame) => { fit(frame); observer.observe(frame) })
|
|
35
|
+
</script>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
// A YouTube video in YouTube's own player, for a talk or a demo that lives on YouTube rather than in the post's
|
|
3
|
+
// media/. In a post it fills the text column at 16:9; on a `video` slide it fills the stage. The player loads from
|
|
4
|
+
// youtube-nocookie.com, which sets no cookie until the reader plays the video. Its JavaScript API is on
|
|
5
|
+
// (enablejsapi=1) so that the deck can pause it when its slide is left (lib/slides.js).
|
|
6
|
+
//
|
|
7
|
+
// <YouTube id="dQw4w9WgXcQ" title="The video's title" />
|
|
8
|
+
//
|
|
9
|
+
// id the video's id: the v= of its watch URL
|
|
10
|
+
// title the video's title, for screen readers
|
|
11
|
+
// start optional: the second to start at
|
|
12
|
+
const { id, title, start } = Astro.props
|
|
13
|
+
const src = `https://www.youtube-nocookie.com/embed/${id}?enablejsapi=1&rel=0${start ? `&start=${start}` : ''}`
|
|
14
|
+
---
|
|
15
|
+
<iframe class="youtube" src={src} title={title} allow="autoplay; encrypted-media; fullscreen; picture-in-picture" allowfullscreen referrerpolicy="strict-origin-when-cross-origin"></iframe>
|
|
@@ -23,7 +23,10 @@
|
|
|
23
23
|
// description placed over the figure's empty region (`noteTop`, from the top
|
|
24
24
|
// of the figure area, in stage pixels; default 440px)
|
|
25
25
|
// table a title over a table from the post: <PostTable id="tbl-…" /> (bloggie/lib/post-tables.js)
|
|
26
|
-
// video only the video, full bleed, on `bg` (the video's own background color)
|
|
26
|
+
// video only the video (a <video>, or a <YouTube id=…> player), full bleed, on `bg` (the video's own background color)
|
|
27
|
+
// embed only a live web page (<Embed src=…>), the full width of the stage, on `bg` (default white); a
|
|
28
|
+
// thin band at the bottom stays the deck's, so the pointer there shows the nav in full screen and a
|
|
29
|
+
// click there gives the keys back to the deck. The page loads when its slide or the one before it is shown.
|
|
27
30
|
// title the slide's title, as HTML (a `title` slot, from a heading, may also hold Markdown math)
|
|
28
31
|
// label the name the speaker view shows for this slide; defaults to the title, untagged
|
|
29
32
|
// zoom demo: figure zoom so its labels read from the back of the room (default 1.6)
|
|
@@ -33,14 +36,15 @@
|
|
|
33
36
|
// size divider: the phrase's font size in px, for a long phrase (default 112); a paragraph under a
|
|
34
37
|
// divider's heading is a one-line subtitle; table: the table's font size in px for a short table (default
|
|
35
38
|
// 34, with headers at 0.8 of it); with a size, the headers take the same size
|
|
39
|
+
// build reveal the slide's list items one at a time, one per click (lib/slides.js); `## [text build=true] Title`
|
|
36
40
|
// eyebrow a small line over the title that names the part of the talk, e.g. "What's next"
|
|
37
41
|
// titleStyle CSS for the title, e.g. "font-size: 60px" (the slide editor writes it)
|
|
38
42
|
// edit set under `npm run dev` only: the slide's index, for the slide editor (bloggie/editor/)
|
|
39
|
-
const { kind = 'text', title: titleProp = '', byline, label, zoom, svgMax, eqSize, size, noteTop, bg, titleStyle, edit, cols, eyebrow } = Astro.props
|
|
43
|
+
const { kind = 'text', title: titleProp = '', byline, label, zoom, svgMax, eqSize, size, noteTop, bg, titleStyle, edit, cols, eyebrow, build } = Astro.props
|
|
40
44
|
const titleEdit = edit == null ? undefined : `${edit}/t`
|
|
41
45
|
const title = Astro.slots.has('title') ? await Astro.slots.render('title') : titleProp
|
|
42
46
|
|
|
43
|
-
const kindClass = { title: 'title-slide', divider: 'divider', text: 'text', reasons: 'text reasons', equation: 'equation', problem: 'problem', demo: 'demo-slide', table: 'table-slide', video: 'video-slide' }[kind]
|
|
47
|
+
const kindClass = { title: 'title-slide', divider: 'divider', text: 'text', reasons: 'text reasons', equation: 'equation', problem: 'problem', demo: 'demo-slide', table: 'table-slide', video: 'video-slide', embed: 'embed-slide' }[kind]
|
|
44
48
|
if (!kindClass) throw new Error(`Slide: unknown kind "${kind}"`)
|
|
45
49
|
const plainTitle = label ?? title.replace(/<br\s*\/?>/g, ' ').replace(/<[^>]+>/g, '').replace(/\$/g, '')
|
|
46
50
|
const style = [
|
|
@@ -53,6 +57,11 @@ const style = [
|
|
|
53
57
|
].filter(Boolean).join('; ') || undefined
|
|
54
58
|
const hasNote = Astro.slots.has('note')
|
|
55
59
|
|
|
60
|
+
// An embed slide's page waits in data-src until lib/slides.js loads it, a slide before it is shown.
|
|
61
|
+
const embedBody = kind === 'embed' && Astro.slots.has('default')
|
|
62
|
+
? (await Astro.slots.render('default')).replace(/<iframe class="embed" src=/g, '<iframe class="embed" data-src=')
|
|
63
|
+
: ''
|
|
64
|
+
|
|
56
65
|
// Body kinds render their Markdown here so a list item that *starts* with $math$ or **bold** can be
|
|
57
66
|
// tagged: `sym` (an equation legend's symbol column) and `lead` (a reason's main idea). CSS alone
|
|
58
67
|
// cannot tell "starts with" from "contains": :first-child ignores the text before an element.
|
|
@@ -63,7 +72,7 @@ const body = bodyKinds.includes(kind) && Astro.slots.has('default')
|
|
|
63
72
|
.replace(/<li>(\s*)<strong>/g, '<li>$1<strong class="lead">')
|
|
64
73
|
: ''
|
|
65
74
|
---
|
|
66
|
-
<section class={`slide ${kindClass}${cols ? ' cols' : ''}`} data-title={plainTitle} style={style} data-edit-slide={edit}>
|
|
75
|
+
<section class={`slide ${kindClass}${cols ? ' cols' : ''}`} data-title={plainTitle} style={style} data-edit-slide={edit} data-build={build && build !== 'false' ? '' : undefined}>
|
|
67
76
|
{kind === 'title' && (
|
|
68
77
|
<>
|
|
69
78
|
<h1 set:html={title} style={titleStyle} data-edit={titleEdit} />
|
|
@@ -78,6 +87,7 @@ const body = bodyKinds.includes(kind) && Astro.slots.has('default')
|
|
|
78
87
|
</>
|
|
79
88
|
)}
|
|
80
89
|
{kind === 'video' && <slot />}
|
|
90
|
+
{kind === 'embed' && <Fragment set:html={embedBody} />}
|
|
81
91
|
{kind === 'demo' && (
|
|
82
92
|
<>
|
|
83
93
|
{eyebrow && <p class="slide-eyebrow">{eyebrow}</p>}
|
package/e2e/editor.js
CHANGED
|
@@ -76,11 +76,12 @@ function inputs(page) {
|
|
|
76
76
|
await mouse('mouseReleased', x, y, { clickCount })
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
|
-
async drag(x0, y0, x1, y1) {
|
|
80
|
-
|
|
81
|
-
await mouse('
|
|
82
|
-
|
|
83
|
-
await mouse('
|
|
79
|
+
async drag(x0, y0, x1, y1, mods = []) {
|
|
80
|
+
const modifiers = bits(mods)
|
|
81
|
+
await mouse('mouseMoved', x0, y0, { button: 'none', modifiers })
|
|
82
|
+
await mouse('mousePressed', x0, y0, { buttons: 1, modifiers })
|
|
83
|
+
for (let i = 1; i <= 10; i++) await mouse('mouseMoved', x0 + ((x1 - x0) * i) / 10, y0 + ((y1 - y0) * i) / 10, { buttons: 1, modifiers })
|
|
84
|
+
await mouse('mouseReleased', x1, y1, { modifiers })
|
|
84
85
|
},
|
|
85
86
|
// A key by its name ('e', 'Enter', 'ArrowDown') or, with `code`, by its place on the keyboard
|
|
86
87
|
// (⌥A types "å", but its code is KeyA).
|
|
@@ -212,7 +213,7 @@ export async function editorChecks({ check, launch, root }) {
|
|
|
212
213
|
const state = await ev(`({ blocked: document.querySelector('.se-toolbar').classList.contains('se-blocked'), status: document.querySelector('.se-status').textContent, blocks: document.querySelectorAll('.deck [data-edit]').length })`)
|
|
213
214
|
if (state.blocked) throw new Error(`${slug}: ${state.status}`)
|
|
214
215
|
observed[slug] = `${state.blocks} blocks and titles`
|
|
215
|
-
await key('
|
|
216
|
+
await key('Escape')
|
|
216
217
|
}
|
|
217
218
|
if (page.problems.length) throw new Error(page.problems.join('\n'))
|
|
218
219
|
return observed
|
|
@@ -251,6 +252,40 @@ export async function editorChecks({ check, launch, root }) {
|
|
|
251
252
|
return `translate: ${found[1]}px ${found[2]}px, in the file and the page`
|
|
252
253
|
})
|
|
253
254
|
|
|
255
|
+
await step('Shift keeps a drag on a straight line: horizontal, then 45°', async () => {
|
|
256
|
+
const at = async () => (await ev(`document.querySelector(${JSON.stringify(paragraph)}).style.translate`)).split(' ').map(parseFloat)
|
|
257
|
+
const [x0, y0] = await at()
|
|
258
|
+
let p = await center(paragraph)
|
|
259
|
+
await drag(p.x, p.y, p.x + 90, p.y + 25, ['shift'])
|
|
260
|
+
await saved()
|
|
261
|
+
const [x1, y1] = await at()
|
|
262
|
+
if (y1 !== y0 || x1 === x0) throw new Error(`a Shift-drag right and a little down moved it from ${x0}, ${y0} to ${x1}, ${y1}: it should move right only`)
|
|
263
|
+
p = await center(paragraph)
|
|
264
|
+
await drag(p.x, p.y, p.x + 40, p.y + 30, ['shift'])
|
|
265
|
+
await saved()
|
|
266
|
+
const [x2, y2] = await at()
|
|
267
|
+
if (Math.abs(Math.abs(x2 - x1) - Math.abs(y2 - y1)) > 1 || y2 === y1) throw new Error(`a Shift-drag down and right moved it by ${x2 - x1}, ${y2 - y1}: it should move as far across as down`)
|
|
268
|
+
return `right only (${x0} -> ${x1}), then 45° (${x2 - x1}, ${y2 - y1})`
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
await step('E while editing leaves editing on; a letter typed with a paragraph selected opens its Markdown', async () => {
|
|
272
|
+
let p = await center(paragraph)
|
|
273
|
+
await click(p.x, p.y)
|
|
274
|
+
await key('Escape') // the paragraph selected: Esc selects nothing, and editing stays on
|
|
275
|
+
await key('e')
|
|
276
|
+
await sleep(300)
|
|
277
|
+
if (!(await ev(`document.body.classList.contains('se-on')`))) throw new Error('E turned editing off')
|
|
278
|
+
p = await center(paragraph)
|
|
279
|
+
await click(p.x, p.y)
|
|
280
|
+
await key('e')
|
|
281
|
+
// The editor opens once the dev server has sent the block's Markdown.
|
|
282
|
+
for (let i = 0; i < 40 && !(await ev(`!!document.querySelector('.se-source textarea')`)); i++) await sleep(100)
|
|
283
|
+
const open = await ev(`({ source: !!document.querySelector('.se-source textarea'), on: document.body.classList.contains('se-on') })`)
|
|
284
|
+
if (!open.source || !open.on) throw new Error(`after E on a selected paragraph: ${JSON.stringify(open)}`)
|
|
285
|
+
await key('Escape') // closes the Markdown editor, unchanged
|
|
286
|
+
return 'editing stays on; E on the paragraph opened its Markdown'
|
|
287
|
+
})
|
|
288
|
+
|
|
254
289
|
await step('⌘⇧> twice and ⌘B are written to the Box; undo brings slides.mdx back byte for byte', async () => {
|
|
255
290
|
const size = await ev(`parseFloat(getComputedStyle(document.querySelector(${JSON.stringify(paragraph)})).fontSize)`)
|
|
256
291
|
await key('.', ['meta', 'shift'])
|
package/editor/client.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
// change into its slides.mdx. Slides.astro loads this file only when import.meta.env.DEV is set,
|
|
3
3
|
// so a built deck has no trace of it. The keys follow Figma's where they can.
|
|
4
4
|
//
|
|
5
|
-
// E, or Edit in the deck's nav turn editing on; Esc with nothing selected turns it off
|
|
5
|
+
// E, or Edit in the deck's nav turn editing on; Esc with nothing selected (or ✕, or Edit) turns it off.
|
|
6
|
+
// While editing, E does not turn it off: in selected text, a letter
|
|
7
|
+
// opens the block's Markdown, as Enter does
|
|
6
8
|
// click, Shift+click, drag select a block (the title, a paragraph, a list, an equation, code,
|
|
7
9
|
// a figure, a demo note), add one to the selection, draw a box
|
|
8
10
|
// around several on the slide's background
|
|
@@ -11,7 +13,8 @@
|
|
|
11
13
|
// its source, as ⌘⇧+click does (bloggie/jump/)
|
|
12
14
|
// Option+click use the figure under the pointer as a reader does
|
|
13
15
|
// drag move; it snaps to where it started and to the stage's center
|
|
14
|
-
// lines (hold ⌘ to place it freely
|
|
16
|
+
// lines (hold ⌘ to place it freely, Shift to keep it on a horizontal,
|
|
17
|
+
// vertical or 45° line, as in Figma)
|
|
15
18
|
// side / corner handle width; text size and width together
|
|
16
19
|
// ←↑→↓, Shift+←↑→↓ move 1 px, 10 px
|
|
17
20
|
// ⌘B, ⌘I, ⌘⇧> ⌘⇧< bold, italic, larger, smaller text
|
|
@@ -76,12 +79,12 @@ const RECENT_KEY = 'slide-editor:colors'
|
|
|
76
79
|
const RECENT = 10
|
|
77
80
|
|
|
78
81
|
const KEYS = [
|
|
79
|
-
['E, Esc', 'edit on; off (with nothing selected)'],
|
|
82
|
+
['E, Esc', 'edit on; off (Esc, with nothing selected)'],
|
|
80
83
|
['click, Shift+click', 'select, add to the selection'],
|
|
81
84
|
['drag the background', 'select the blocks in a box'],
|
|
82
85
|
['⌘+click, double-click', 'an element inside a block or figure'],
|
|
83
86
|
['Option+click', 'use the figure as a reader does'],
|
|
84
|
-
['drag (⌘: free)', 'move, snapping to guides'],
|
|
87
|
+
['drag (⌘: free, Shift: straight)', 'move, snapping to guides'],
|
|
85
88
|
['side / corner handle', 'width / scale'],
|
|
86
89
|
['← ↑ → ↓ (Shift)', 'move 1 px (10 px)'],
|
|
87
90
|
['⌘B, ⌘I, ⌘⇧> ⌘⇧<', 'bold, italic, text size'],
|
|
@@ -740,7 +743,7 @@ export function initEditor(deck) {
|
|
|
740
743
|
|
|
741
744
|
// Move the selected blocks together (or the element inside a block) by the pointer's travel. The
|
|
742
745
|
// one under the pointer snaps to where it started and to the stage's center lines.
|
|
743
|
-
function startMove(event, lead) {
|
|
746
|
+
function startMove(event, lead, onClick) {
|
|
744
747
|
const movers = targets().map((el) => {
|
|
745
748
|
const [x, y] = readTranslate(el)
|
|
746
749
|
return { el, unit: unitOf(el), x, y, initial: el.style.getPropertyValue('translate') || null }
|
|
@@ -752,15 +755,27 @@ export function initEditor(deck) {
|
|
|
752
755
|
const start = { x: event.clientX, y: event.clientY }
|
|
753
756
|
const within = inner
|
|
754
757
|
let moved = false
|
|
755
|
-
|
|
758
|
+
let last = null // the last pointer event, to move again when Shift goes down or up mid-drag
|
|
759
|
+
const move = (ev) => {
|
|
760
|
+
last = { clientX: ev.clientX, clientY: ev.clientY, shiftKey: ev.shiftKey, metaKey: ev.metaKey, ctrlKey: ev.ctrlKey }
|
|
756
761
|
if (!moved && Math.hypot(ev.clientX - start.x, ev.clientY - start.y) < 3) return
|
|
757
762
|
moved = true
|
|
758
763
|
dragging = true
|
|
759
|
-
let
|
|
760
|
-
let
|
|
764
|
+
let tx = ev.clientX - start.x
|
|
765
|
+
let ty = ev.clientY - start.y
|
|
766
|
+
// Shift keeps the move on a straight line: horizontal, vertical or 45°, whichever is nearest (as in Figma).
|
|
767
|
+
let diagonal = false
|
|
768
|
+
if (ev.shiftKey) {
|
|
769
|
+
const [ax, ay] = [Math.abs(tx), Math.abs(ty)]
|
|
770
|
+
if (ax > ay * Math.tan(Math.PI * 3 / 8)) ty = 0
|
|
771
|
+
else if (ay > ax * Math.tan(Math.PI * 3 / 8)) tx = 0
|
|
772
|
+
else { const d = (ax + ay) / 2; tx = Math.sign(tx) * d; ty = Math.sign(ty) * d; diagonal = true }
|
|
773
|
+
}
|
|
774
|
+
let dx = leader.x * leader.unit + tx
|
|
775
|
+
let dy = leader.y * leader.unit + ty
|
|
761
776
|
let gx = null
|
|
762
777
|
let gy = null
|
|
763
|
-
if (!(ev.metaKey || ev.ctrlKey)) {
|
|
778
|
+
if (!(ev.metaKey || ev.ctrlKey) && !diagonal) {
|
|
764
779
|
const d = deck.getBoundingClientRect()
|
|
765
780
|
const scale = stageScale()
|
|
766
781
|
const near = SNAP * scale
|
|
@@ -768,22 +783,32 @@ export function initEditor(deck) {
|
|
|
768
783
|
const centerY = d.top + (STAGE.height / 2) * scale
|
|
769
784
|
const toCenterX = centerX - home.left - home.width / 2
|
|
770
785
|
const toCenterY = centerY - home.top - home.height / 2
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
786
|
+
// A locked axis stays where it is; only the axis that moves snaps.
|
|
787
|
+
const lockX = ev.shiftKey && tx === 0
|
|
788
|
+
const lockY = ev.shiftKey && ty === 0
|
|
789
|
+
if (!lockX && Math.abs(dx) < near && Math.abs(dx) <= Math.abs(dx - toCenterX)) { dx = 0; gx = home.left }
|
|
790
|
+
else if (!lockX && Math.abs(dx - toCenterX) < near) { dx = toCenterX; gx = centerX }
|
|
791
|
+
if (!lockY && Math.abs(dy) < near && Math.abs(dy) <= Math.abs(dy - toCenterY)) { dy = 0; gy = home.top }
|
|
792
|
+
else if (!lockY && Math.abs(dy - toCenterY) < near) { dy = toCenterY; gy = centerY }
|
|
775
793
|
}
|
|
776
794
|
showGuide(guideV, gx)
|
|
777
795
|
showGuide(guideH, gy)
|
|
778
796
|
// Every element moves by the leader's travel on screen, in its own CSS px.
|
|
779
|
-
const
|
|
780
|
-
const
|
|
781
|
-
for (const m of movers) m.el.style.setProperty('translate', `${round(m.x +
|
|
782
|
-
}
|
|
797
|
+
const ox = dx - leader.x * leader.unit
|
|
798
|
+
const oy = dy - leader.y * leader.unit
|
|
799
|
+
for (const m of movers) m.el.style.setProperty('translate', `${round(m.x + ox / m.unit)}px ${round(m.y + oy / m.unit)}px`)
|
|
800
|
+
}
|
|
801
|
+
// Shift pressed or released without moving the pointer: move again with the new constraint.
|
|
802
|
+
const shift = (ev) => { if (ev.key === 'Shift' && last) move({ ...last, shiftKey: ev.type === 'keydown' }) }
|
|
803
|
+
window.addEventListener('keydown', shift, true)
|
|
804
|
+
window.addEventListener('keyup', shift, true)
|
|
805
|
+
listen(move, () => {
|
|
806
|
+
window.removeEventListener('keydown', shift, true)
|
|
807
|
+
window.removeEventListener('keyup', shift, true)
|
|
783
808
|
showGuide(guideV, null)
|
|
784
809
|
showGuide(guideH, null)
|
|
785
810
|
dragging = false
|
|
786
|
-
if (!moved) return
|
|
811
|
+
if (!moved) return onClick?.()
|
|
787
812
|
for (const m of movers) {
|
|
788
813
|
const translate = translateValue(...readTranslate(m.el))
|
|
789
814
|
applyStyle(m.el, { translate: m.initial }) // so that stage() records the value from before the drag
|
|
@@ -1430,10 +1455,11 @@ export function initEditor(deck) {
|
|
|
1430
1455
|
selectInner(block, target)
|
|
1431
1456
|
return startMove(event, inner?.el)
|
|
1432
1457
|
}
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1458
|
+
// Shift adds a block to the selection when pressed; a selected one leaves it only on a click, not a drag, so
|
|
1459
|
+
// that Shift can also keep the drag of a selection straight (startMove).
|
|
1460
|
+
if (event.shiftKey && selection.includes(block)) return startMove(event, block, () => select(selection.filter((el) => el !== block)))
|
|
1461
|
+
if (event.shiftKey) select([...selection, block])
|
|
1462
|
+
else if (!selection.includes(block) || inner) select([block])
|
|
1437
1463
|
startMove(event, block)
|
|
1438
1464
|
}, true)
|
|
1439
1465
|
|
|
@@ -1474,13 +1500,19 @@ export function initEditor(deck) {
|
|
|
1474
1500
|
if (picking || editor || typing(event.target)) return
|
|
1475
1501
|
// The palette's opacity slider keeps its arrow keys; Esc still closes the palette.
|
|
1476
1502
|
if (event.target instanceof Element && event.target.closest('.se-palette') && event.key !== 'Escape') return
|
|
1477
|
-
if (code === 'KeyE' && !mod && !alt) {
|
|
1503
|
+
if (code === 'KeyE' && !mod && !alt && !on) {
|
|
1478
1504
|
event.preventDefault()
|
|
1479
1505
|
event.stopPropagation()
|
|
1480
|
-
return
|
|
1506
|
+
return turnOn()
|
|
1481
1507
|
}
|
|
1482
1508
|
if (!on) return
|
|
1483
1509
|
const handled = () => { event.preventDefault(); event.stopPropagation() }
|
|
1510
|
+
// A letter typed into selected text edits it, as in a text box: in selected words, or with one text block
|
|
1511
|
+
// selected, it opens the block's Markdown (the letter itself is not typed, so a stray key changes nothing).
|
|
1512
|
+
const letter = key.length === 1 && /\p{L}/u.test(key) && !mod && !alt
|
|
1513
|
+
const textBlock = words ?? (!inner && selection.length === 1 && !isFigure(selection[0]) ? selection[0] : null)
|
|
1514
|
+
if (letter && textBlock) { handled(); const el = textBlock; exitWords(); return openEditor(el) }
|
|
1515
|
+
if (code === 'KeyE' && !mod && !alt) return handled() // editing stays on: Esc turns it off
|
|
1484
1516
|
// Esc goes out one level: from an element inside a block to the block, from the selection to
|
|
1485
1517
|
// nothing, and from nothing out of editing. It never leaves the deck while editing.
|
|
1486
1518
|
if (key === 'Escape') {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// rehype plugin, after KaTeX: keep inline math on one line with the punctuation that touches it.
|
|
2
|
+
//
|
|
3
|
+
// KaTeX draws inline math as inline-block boxes, and a browser may break the line between the last box and a "." or ","
|
|
4
|
+
// that follows it, so the punctuation starts the next line. This wraps the math, the closing punctuation right after it
|
|
5
|
+
// and an opening bracket right before it in <span class="math-nowrap">, an inline-block (site.css), so that no line breaks between them.
|
|
6
|
+
// `white-space: nowrap` on the following text, or a word joiner (U+2060), does not stop Chrome from breaking there.
|
|
7
|
+
// Display math is left alone.
|
|
8
|
+
|
|
9
|
+
const CLOSING = /^[.,;:!?)\]}’”…]+/
|
|
10
|
+
const OPENING = /[([{‘“]$/
|
|
11
|
+
|
|
12
|
+
const isInlineMath = (node) => node?.type === 'element' && node.properties?.className?.includes?.('katex')
|
|
13
|
+
|
|
14
|
+
function visit(node) {
|
|
15
|
+
if (!node.children) return
|
|
16
|
+
if (node.properties?.className?.includes?.('katex-display')) return
|
|
17
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
18
|
+
const math = node.children[i]
|
|
19
|
+
if (!isInlineMath(math)) {
|
|
20
|
+
visit(math)
|
|
21
|
+
continue
|
|
22
|
+
}
|
|
23
|
+
const before = node.children[i - 1]
|
|
24
|
+
const after = node.children[i + 1]
|
|
25
|
+
const closing = after?.type === 'text' ? after.value.match(CLOSING)?.[0] : null
|
|
26
|
+
const opening = before?.type === 'text' ? before.value.match(OPENING)?.[0] : null
|
|
27
|
+
if (!closing && !opening) continue
|
|
28
|
+
const held = [math]
|
|
29
|
+
if (closing) {
|
|
30
|
+
held.push({ type: 'text', value: closing })
|
|
31
|
+
after.value = after.value.slice(closing.length)
|
|
32
|
+
}
|
|
33
|
+
if (opening) {
|
|
34
|
+
held.unshift({ type: 'text', value: opening })
|
|
35
|
+
before.value = before.value.slice(0, -opening.length)
|
|
36
|
+
}
|
|
37
|
+
node.children[i] = { type: 'element', tagName: 'span', properties: { className: ['math-nowrap'] }, children: held }
|
|
38
|
+
}
|
|
39
|
+
node.children = node.children.filter((child) => child.type !== 'text' || child.value !== '')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default function rehypeMathPunctuation() {
|
|
43
|
+
return (tree) => visit(tree)
|
|
44
|
+
}
|
package/lib/slides.js
CHANGED
|
@@ -37,6 +37,8 @@ export function initDeck(deck) {
|
|
|
37
37
|
const count = document.querySelector('.deck-count')
|
|
38
38
|
const progress = document.querySelector('.deck-progress > div')
|
|
39
39
|
const notesPanel = document.querySelector('.deck-notes')
|
|
40
|
+
// The YouTube player's command to pause, through its iframe API (components/YouTube.astro).
|
|
41
|
+
const YOUTUBE_PAUSE = JSON.stringify({ event: 'command', func: 'pauseVideo', args: [] })
|
|
40
42
|
let index = 0
|
|
41
43
|
let step = 0
|
|
42
44
|
|
|
@@ -57,6 +59,9 @@ export function initDeck(deck) {
|
|
|
57
59
|
slide.inert = k !== index
|
|
58
60
|
// A video keeps playing only on its own slide.
|
|
59
61
|
if (k !== index) slide.querySelectorAll('video').forEach((v) => v.pause())
|
|
62
|
+
if (k !== index) slide.querySelectorAll('iframe.youtube').forEach((f) => f.contentWindow?.postMessage(YOUTUBE_PAUSE, '*'))
|
|
63
|
+
// An embedded page (components/Embed.astro) loads one slide early, so it is ready when its slide comes.
|
|
64
|
+
if (k === index || k === index + 1) slide.querySelectorAll('iframe.embed[data-src]').forEach((f) => { f.src = f.dataset.src; f.removeAttribute('data-src') })
|
|
60
65
|
})
|
|
61
66
|
steps.forEach((els, k) => els.forEach((el) => el.classList.toggle('shown', k < step)))
|
|
62
67
|
count.textContent = `${index + 1} / ${slides.length}`
|
|
@@ -94,6 +99,11 @@ export function initDeck(deck) {
|
|
|
94
99
|
// A focused control keeps the keys it uses. Text fields, sliders, selects and videos use the
|
|
95
100
|
// arrows, Space, Home and End; a button, a <summary>, a checkbox or a clickable node uses only
|
|
96
101
|
// Space and Enter, so the arrows still move the deck after a figure's button is clicked.
|
|
102
|
+
// A click in a YouTube player (components/YouTube.astro) moves the keyboard focus into its frame, where the deck's
|
|
103
|
+
// keys never arrive. Take the focus back, so that → still moves the deck; the video keeps playing.
|
|
104
|
+
addEventListener('blur', () => setTimeout(() => {
|
|
105
|
+
if (document.activeElement?.matches('.deck iframe.youtube')) document.activeElement.blur()
|
|
106
|
+
}))
|
|
97
107
|
const ALL_KEYS = 'input:not([type="checkbox"], [type="radio"], [type="button"]), select, textarea, [role="slider"], [contenteditable], video'
|
|
98
108
|
const PRESS_KEYS = 'button, summary, a[href], input[type="checkbox"], input[type="radio"], [role="button"]'
|
|
99
109
|
const ownsKey = (target, key) => target instanceof Element &&
|
package/package.json
CHANGED
|
@@ -75,7 +75,8 @@ a time, with the post's own interactive figures.
|
|
|
75
75
|
- do not repeat a symbol explained on the previous slide or very recently; if it returns
|
|
76
76
|
much later, give a one-line reminder.
|
|
77
77
|
7. **Minimize builds.** Every animation is overhead for the presenter. Default to none. Use a
|
|
78
|
-
build only when the slide asks a question and the build reveals the answer.
|
|
78
|
+
build only when the slide asks a question and the build reveals the answer, or when the author asks for one.
|
|
79
|
+
`## [text build=true] Title` reveals the slide's list items one per click.
|
|
79
80
|
8. **Prefer a short list to cards.** Use cards only when items need a visual group that a list
|
|
80
81
|
cannot give. When an item has a main idea and a description, make the size difference
|
|
81
82
|
large: main idea 56px bold, description 40px in the secondary color.
|
|
@@ -170,7 +171,16 @@ its figure components the same way: the deck must run the post's real interactiv
|
|
|
170
171
|
`<p slot="note">…</p>`, placed with `noteTop=310px` (from the top of the figure area); one
|
|
171
172
|
sentence. It scrolls with the figure, so it never covers text the figure scrolls up.
|
|
172
173
|
- `video`: only the `<video>`, full bleed on `bg` (sample the color from the poster image);
|
|
173
|
-
the heading is not shown, and names the slide in the speaker view.
|
|
174
|
+
the heading is not shown, and names the slide in the speaker view. A video on YouTube is
|
|
175
|
+
`<YouTube id="…" title="…" />` (import it from `@bloggie/components/YouTube.astro`) on `bg=#000`:
|
|
176
|
+
YouTube's own player fills the stage, and the deck pauses it when the slide is left.
|
|
177
|
+
- `embed`: only a live web page, `<Embed src="…" title="…" />` (import it from
|
|
178
|
+
`@bloggie/components/Embed.astro`), the full width of the stage, for an interactive article the
|
|
179
|
+
presenter explores in the talk. The page loads when its slide or the one before it is shown. A
|
|
180
|
+
24px band at the bottom stays the deck's: a click there gives the keys back to the deck, and the
|
|
181
|
+
pointer there shows the nav in full screen. Check first that the site allows framing. To show
|
|
182
|
+
only an article's demo, give `crop="x y width height"`: the rectangle of the page, laid out
|
|
183
|
+
1440 px wide (`layout` changes it), that the slide shows; measure it in a headless browser.
|
|
174
184
|
- A `title` prop on a hand-written `<Slide>` is HTML, not Markdown; a heading title can hold math.
|
|
175
185
|
- Code blocks are highlighted by Shiki at build time; the fence's language picks the grammar
|
|
176
186
|
(rule 16), and the syntax a slide teaches must be the part that is colored. Fence MDX source as
|
package/styles/site.css
CHANGED
|
@@ -757,6 +757,12 @@ blockquote {
|
|
|
757
757
|
overflow-y: hidden;
|
|
758
758
|
}
|
|
759
759
|
|
|
760
|
+
/* Inline math with the punctuation that touches it (lib/math-punctuation.js), as one box, so that a line never breaks
|
|
761
|
+
between them. As an inline-block, math wider than the line still wraps inside the box. */
|
|
762
|
+
.math-nowrap {
|
|
763
|
+
display: inline-block;
|
|
764
|
+
}
|
|
765
|
+
|
|
760
766
|
/* --- post index ---------------------------------------------------------- */
|
|
761
767
|
|
|
762
768
|
.post-list {
|
|
@@ -998,6 +1004,47 @@ figure video {
|
|
|
998
1004
|
border-radius: 4px;
|
|
999
1005
|
}
|
|
1000
1006
|
|
|
1007
|
+
/* A YouTube player in a post (components/YouTube.astro), the width of the text column at 16:9. */
|
|
1008
|
+
iframe.youtube {
|
|
1009
|
+
display: block;
|
|
1010
|
+
width: 100%;
|
|
1011
|
+
aspect-ratio: 16 / 9;
|
|
1012
|
+
border: 0;
|
|
1013
|
+
border-radius: 4px;
|
|
1014
|
+
background: #000;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
/* A live web page in a post (components/Embed.astro), the width of the figure at 16:9. */
|
|
1018
|
+
iframe.embed {
|
|
1019
|
+
display: block;
|
|
1020
|
+
width: 100%;
|
|
1021
|
+
aspect-ratio: 16 / 9;
|
|
1022
|
+
border: 1px solid var(--rule);
|
|
1023
|
+
border-radius: 4px;
|
|
1024
|
+
background: #fff;
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
/* A cropped page (Embed crop="…"): only its rectangle shows, scaled to the frame's width by the component's script. */
|
|
1028
|
+
.embed-crop {
|
|
1029
|
+
position: relative;
|
|
1030
|
+
width: 100%;
|
|
1031
|
+
overflow: hidden;
|
|
1032
|
+
border: 1px solid var(--rule);
|
|
1033
|
+
border-radius: 4px;
|
|
1034
|
+
background: #fff;
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
.embed-crop iframe.embed {
|
|
1038
|
+
position: absolute;
|
|
1039
|
+
top: 0;
|
|
1040
|
+
left: 0;
|
|
1041
|
+
max-width: none;
|
|
1042
|
+
aspect-ratio: auto;
|
|
1043
|
+
border: 0;
|
|
1044
|
+
border-radius: 0;
|
|
1045
|
+
transform-origin: 0 0;
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1001
1048
|
/* A picture in a post, such as a screenshot (How this blog works), framed so it stands off the page. */
|
|
1002
1049
|
figure img {
|
|
1003
1050
|
display: block;
|
package/styles/slides.css
CHANGED
|
@@ -496,6 +496,43 @@
|
|
|
496
496
|
background: var(--video-bg, #101826);
|
|
497
497
|
}
|
|
498
498
|
|
|
499
|
+
/* An embed slide is a live web page (components/Embed.astro) the full width of the stage. A 24px band at the bottom
|
|
500
|
+
stays the deck's: the page takes every pointer and key event over it, so the pointer in the band shows the nav in
|
|
501
|
+
full screen, and a click in the band gives the keys back to the deck. */
|
|
502
|
+
.slide.embed-slide {
|
|
503
|
+
padding: 0 0 24px;
|
|
504
|
+
gap: 0;
|
|
505
|
+
background: var(--video-bg, #fff);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
.slide.embed-slide > iframe.embed {
|
|
509
|
+
display: block;
|
|
510
|
+
flex: 1;
|
|
511
|
+
width: 100%;
|
|
512
|
+
min-height: 0;
|
|
513
|
+
border: 0;
|
|
514
|
+
border-radius: 0;
|
|
515
|
+
background: #fff;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/* A cropped page fills the stage's height at its own aspect ratio, centered. */
|
|
519
|
+
.slide.embed-slide .embed-crop {
|
|
520
|
+
height: 100%;
|
|
521
|
+
width: auto;
|
|
522
|
+
max-width: 100%;
|
|
523
|
+
align-self: center;
|
|
524
|
+
border: 0;
|
|
525
|
+
border-radius: 0;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/* A YouTube player (components/YouTube.astro) fills the 16:9 stage; the slide's background is black, as is YouTube's. */
|
|
529
|
+
.slide.video-slide iframe.youtube {
|
|
530
|
+
width: 100%;
|
|
531
|
+
height: 100%;
|
|
532
|
+
border: 0;
|
|
533
|
+
border-radius: 0;
|
|
534
|
+
}
|
|
535
|
+
|
|
499
536
|
.slide.video-slide video {
|
|
500
537
|
display: block;
|
|
501
538
|
height: 100%;
|