Skip to content

Edge-Drop is a clipboard shelf on the edge of your screen. Hover to open it. Drag files and images into any app, click to copy text and links. Free and open-source for Windows.

feat(onboarding): eight steps, real-size edge choice, clear copy

Deepender25d3ac689a0e50
diff --git a/src/Onboarding.tsx b/src/Onboarding.tsx
index ec1b9d6..dd637df 100644
--- a/src/Onboarding.tsx
+++ b/src/Onboarding.tsx
@@ -6,7 +6,8 @@
* across the whole window with a laptop frame laid over it; "Take the tour"
* flies the frame out past the window edges, and each step then plays the
* real shelf (Panel, cards, stacks, edge light, preview) on example items.
- * The last step brings the frame back for the few settings that matter.
+ * The last step brings the frame back: the real shelf plays on each edge of
+ * the laptop, then the user picks theirs (and the few settings that matter).
*
* The example items live only in this window's store. The user's history is
* never loaded here, and the shelf is inert (no clicks reach it), so nothing
@@ -21,9 +22,9 @@ import { applyReduceMotion } from './lib/theme'
import { useTranslation } from './i18n'
import { DEFAULT_SETTINGS, type Settings, type StickPosition } from '../shared/types'
import { PEN_PATH, PEN_TRANSFORM, PEN_WIDTH, GLASS_BOX, SHADOW_BOX, BLUR_BOX, penProgress } from './onboarding/lettering'
-import { DEMOS, PREVIEW_PAN, Run, STOP, itemsFor, playLooped, resetDemoState, watchActivity, type Stage } from './onboarding/tour'
-import { laptopBar, tourBar, shelfTransform, topBarLength, SHELF_SCALE, TOUR_SCREEN_TOP } from './onboarding/edgeBar'
-import { PAGE_LINES, STACK_FILES } from './onboarding/demoItems'
+import { CHOICE_VIEW, DEMOS, PREVIEW_PAN, Run, STOP, demoEdges, itemsFor, playLooped, resetDemoState, showEdge, watchActivity, type Stage } from './onboarding/tour'
+import { realScreenTransform, realSidePanel, tourBar, shelfTransform, topBarLength, SHELF_SCALE, TOUR_SCREEN_TOP } from './onboarding/edgeBar'
+import { otherFiles, pageLines, pageTitle, stackFiles } from './onboarding/demoItems'
import { Autoplay, readingMs } from './onboarding/autoplay'
import { fileIconUrl, fileKindOf } from './lib/fileKind'
import skyUrl from './assets/onboarding/sky.png'
@@ -48,8 +49,12 @@ const TOUCH_MS = 450
const WRITE_MS = 3200
const HOLD_MS = 600
-/** File Explorer in the drag-in demo: the PDF it drags in, and the files the stack demos copy later. */
-const FOLDER: Array<[string, number]> = [['Itinerary.pdf', 412_000], ...STACK_FILES]
+/** The demo taskbar's clock: a fixed moment, written the way the language writes it (24-hour, as it fits). */
+const taskbarClock = (lang: string): [string, string] => {
+ if (lang === 'en') return ['12:01', '27-10-2026']
+ const at = new Date(2026, 9, 27, 12, 1)
+ return [at.toLocaleTimeString(lang, { hour: '2-digit', minute: '2-digit', hourCycle: 'h23' }), at.toLocaleDateString(lang)]
+}
/** A Windows 11 window's caption buttons: minimize, maximize, close. */
const Caption = () => (
@@ -61,18 +66,15 @@ const Caption = () => (
)
export function Onboarding() {
- const { t } = useTranslation()
+ const { t, resolvedLang } = useTranslation()
const steps: Step[] = [
{ key: 'welcome', view: 'frame', open: false, title: t('onboarding.welcomeTitle'), body: t('onboarding.welcomeDesc') },
{ key: 'collect', view: 'full', open: false, title: t('onboarding.collectTitle'), body: t('onboarding.collectDesc') },
{ key: 'dropin', view: 'full', open: false, title: t('onboarding.dropInTitle'), body: t('onboarding.dropInDesc') },
- { key: 'stacks', view: 'full', open: true, title: t('onboarding.stacksTitle'), body: t('onboarding.stacksDesc') },
{ key: 'drag', view: 'full', open: true, title: t('onboarding.dragTitle'), body: t('onboarding.dragDesc') },
- { key: 'ungroup', view: 'full', open: true, title: t('onboarding.ungroupTitle'), body: t('onboarding.ungroupDesc') },
- { key: 'merge', view: 'full', open: true, title: t('onboarding.mergeTitle'), body: t('onboarding.mergeDesc') },
+ { key: 'stacks', view: 'full', open: true, title: t('onboarding.stacksTitle'), body: t('onboarding.stacksDesc') },
{ key: 'preview', view: 'full', open: true, title: t('onboarding.previewTitle'), body: t('onboarding.previewDesc') },
- { key: 'note', view: 'full', open: true, title: t('onboarding.noteTitle'), body: t('onboarding.noteDesc') },
- { key: 'search', view: 'full', open: true, title: t('onboarding.searchTitle'), body: t('onboarding.searchDesc') },
+ { key: 'find', view: 'full', open: true, title: t('onboarding.findTitle'), body: t('onboarding.findDesc') },
{ key: 'settings', view: 'frame', open: false, title: t('onboarding.configTitle'), body: t('onboarding.configDesc') }
]
const last = steps.length - 1
@@ -86,10 +88,8 @@ export function Onboarding() {
const [shelf, setShelf] = useState(false)
/** The drawn edge bar on the laptop's top edge; hidden while the real shelf's bar is in its place. */
const [barShown, setBarShown] = useState(true)
- /** Settings frame: the bar moves to the user's real edge once the frame is back in place. */
- const [realEdge, setRealEdge] = useState(false)
- /** Settings frame: the camera moves in on the screen, as on the user's own desktop. */
- const [closeUp, setCloseUp] = useState(false)
+ /** The last step: the shelf has shown every edge, and the choice is up. */
+ const [asking, setAsking] = useState(false)
const [real, setReal] = useState<Settings | null>(null)
/** Autoplay: on unless the user asked for reduced motion; the button by the progress dots toggles it. */
const [playing, setPlaying] = useState(true)
@@ -107,6 +107,10 @@ export function Onboarding() {
const lettersRef = useRef<HTMLDivElement>(null)
const shadowRef = useRef<SVGImageElement>(null)
const runRef = useRef<Run | null>(null)
+ /** The last step: the shelf showing the edge just picked. */
+ const pickRunRef = useRef<Run | null>(null)
+ /** The user's settings, for the demos (which outlive a render). */
+ const realRef = useRef<Settings | null>(null)
const timers = useRef<number[]>([])
const later = (ms: number, fn: () => void) => timers.current.push(window.setTimeout(fn, ms))
@@ -130,7 +134,9 @@ export function Onboarding() {
document.addEventListener('visibilitychange', vis)
return () => {
document.removeEventListener('visibilitychange', vis)
- autoplay.current!.stop()
+ // held, not torn down: in development React runs this and then the effect again on the same
+ // elements (the step's fill is attached once, by its ref), and autoplay must carry on from there
+ autoplay.current!.setHidden(true)
}
}, [])
@@ -153,6 +159,14 @@ export function Onboarding() {
/** Plays step i's demo after `delay` ms, again and again while the step is up. */
const play = (run: Run, i: number, delay: number) => {
const s = steps[i]
+ if (s.key === 'settings') {
+ // once: every edge, then the choice stays up
+ run.sleep(delay)
+ .then(() => demoEdges(run, stage(), realRef.current?.stickPosition ?? 'left'))
+ .then(() => { if (!run.dead) setAsking(true) })
+ .catch((e) => { if (e !== STOP) console.error(e) })
+ return
+ }
const demo = DEMOS[s.key]
if (!demo) return
run.sleep(delay)
@@ -170,6 +184,8 @@ export function Onboarding() {
document.body.style.setProperty('--ob-shelf-scale', String(SHELF_SCALE))
document.body.style.setProperty('--ob-shelf-top', `${TOUR_SCREEN_TOP}px`)
document.body.style.setProperty('--ob-preview-pan', `${-PREVIEW_PAN}px`)
+ document.body.style.setProperty('--ob-choice-zoom', String(CHOICE_VIEW.k))
+ document.body.style.setProperty('--ob-choice-move', `translate(${CHOICE_VIEW.x / CHOICE_VIEW.k}px, ${CHOICE_VIEW.y / CHOICE_VIEW.k}px)`)
void edge.loadState().then(async ({ settings }) => {
if (cancelled) return
setReal(settings)
@@ -203,6 +219,8 @@ export function Onboarding() {
document.body.style.removeProperty('--ob-shelf-top')
document.body.style.removeProperty('--ob-preview-pan')
document.body.style.removeProperty('--ob-menu-scale')
+ document.body.style.removeProperty('--ob-choice-zoom')
+ document.body.style.removeProperty('--ob-choice-move')
runRef.current?.cancel()
timers.current.forEach(clearTimeout)
}
@@ -253,18 +271,32 @@ export function Onboarding() {
const s = steps[i]
const prev = steps[at]
runRef.current?.cancel()
+ pickRunRef.current?.cancel()
resetDemoState(stage(), s.key)
const run = new Run()
runRef.current = run
setAt(i)
- setRealEdge(false)
- setCloseUp(false)
+ setAsking(false)
const flying = prev.view !== s.view
if (s.view === 'full' && prev.view === 'frame') {
// Into the screen: the camera pushes in on the laptop's top edge with the
// bar attached to it (the wallpaper stays still); once there, the real
// shelf's closed bar is exactly where the drawn one is and takes over.
+ // (Back from the last step: the shelf, laid out on the monitor there, gives
+ // way to the drawn bar first and is docked at the top again out of sight.)
+ if (prev.key === 'settings') {
+ setShelf(false)
+ setBarShown(true)
+ useStore.setState({
+ settings: {
+ ...useStore.getState().settings,
+ stickPosition: 'top',
+ hotZoneHeight: DEFAULT_SETTINGS.hotZoneHeight,
+ hotZoneWidth: realRef.current?.hotZoneWidth ?? DEFAULT_SETTINGS.hotZoneWidth
+ }
+ })
+ }
setCam('tour')
useStore.setState({ items: itemsFor(s.key), open: false })
later(900, () => { setShelf(true); setBarShown(false) })
@@ -277,8 +309,10 @@ export function Onboarding() {
setBarShown(true)
setShelf(false)
setCam('frame')
+ // out of sight now: a search empties (resetDemoState leaves it while the shelf folds), and the
+ // cards the last step's shelf shows (the welcome's demo sets its own)
+ if (!run.dead) useStore.setState({ query: '', items: itemsFor(s.key) })
})
- if (s.key === 'settings') later(1250, () => { if (!run.dead) { setCloseUp(true); setRealEdge(true) } })
} else if (s.view === 'full') {
useStore.setState({ items: itemsFor(s.key), open: s.open })
}
@@ -312,15 +346,27 @@ export function Onboarding() {
setReal(saved)
}
+ /** The user's edge: saved, and the shelf on the laptop goes there and opens once to show it. */
+ const choose = (pos: StickPosition) => {
+ void pick({ stickPosition: pos })
+ pickRunRef.current?.cancel()
+ const run = new Run()
+ pickRunRef.current = run
+ showEdge(run, stage(), pos).catch((e) => { if (e !== STOP) console.error(e) })
+ }
+
const s = steps[at]
const barPos: StickPosition = real?.stickPosition ?? 'left'
const locked = intro !== 'done'
- // The tour's shelf is docked at the top; the settings frame shows the user's real choice.
+ // The tour's shelf: docked at the top, except on the last step, where it plays every edge of the laptop.
const demo = useStore((st) => st.settings)
const shelfOpen = useStore((st) => st.open)
- const showReal = at === last && realEdge && !!real
- const edgeNow: StickPosition = showReal ? barPos : 'top'
- const barStyle = showReal && real ? laptopBar(edgeNow, real) : tourBar(demo)
+ const dock: StickPosition = demo.stickPosition ?? 'top'
+ // The last step lays the shelf out on a real monitor drawn on the laptop (edgeBar REAL_SCREEN).
+ const onMonitor = at === last && cam === 'frame'
+ const side = realSidePanel(demo.panelHeight || 0.6, demo.verticalOffset ?? 0.5)
+ const barStyle = tourBar(demo)
+ realRef.current = real
const primary = (
<button type="button" className="ob-primary" onClick={next}>
{at === last ? t('onboarding.getStarted') : t('onboarding.next')}
@@ -328,7 +374,7 @@ export function Onboarding() {
)
return (
- <div className={`ob${intro === 'writing' ? '' : ' ob-focus'}${intro === 'done' ? ' ob-done' : ''}`}>
+ <div className={`ob${intro === 'writing' ? '' : ' ob-focus'}${intro === 'done' ? ' ob-done' : ''}${asking ? ' ob-choosing' : ''}`}>
<div className="ob-stage" ref={stageRef}>
<div className="ob-scene">
{/* The cloud wallpaper: one pixel per 2px dither cell, drawn crisp (it never moves, not even with the camera). */}
@@ -337,45 +383,52 @@ export function Onboarding() {
{/* The camera: the laptop, what is on its screen and the pointer, pushed in on the action (lens.ts). */}
<div className="ob-lens" ref={lensRef}>
- {/* A web page, for the copy demo: a sentence, the address and the photo get copied. */}
+ {/* A web page, for the copy demo: a sentence and the photo get copied. */}
<div className="ob-win ob-browser" ref={browserRef}>
<div className="ob-win-bar">
- <span className="ob-tab"><i>W</i>Sea of clouds - Wikipedia</span>
+ <span className="ob-tab"><i>W</i>{pageTitle()} - Wikipedia</span>
<Caption />
</div>
<div className="ob-address">
- <span className="ob-url"><i className="ob-hl" />en.wikipedia.org/wiki/Sea_of_clouds</span>
+ {/* the site's icon: links are dragged out of the address bar by it */}
+ <svg className="ob-site" width="11" height="11" viewBox="0 0 11 11" fill="none" stroke="currentColor" strokeWidth="1.2" strokeLinecap="round">
+ <path d="M1.5 3.5h5M8.5 3.5h1M1.5 7.5h1M4.5 7.5h5" />
+ <circle cx="7.5" cy="3.5" r="1.2" />
+ <circle cx="3.5" cy="7.5" r="1.2" />
+ </svg>
+ <span className="ob-url">en.wikipedia.org/wiki/Sea_of_clouds</span>
</div>
<div className="ob-page">
<div className="ob-article">
- <b>Sea of clouds</b>
- {PAGE_LINES.map((line) => <span key={line} className="ob-line"><i className="ob-hl" />{line}</span>)}
- <span className="ob-rest">It is most often seen on cold, clear mornings.</span>
+ <b>{pageTitle()}</b>
+ {pageLines().map((line, i) => <span key={i} className="ob-line"><i className="ob-hl" />{line}</span>)}
+ <span className="ob-rest">{t('tour.pageMore')}</span>
</div>
<div className="ob-photo" />
</div>
<div className="ob-menu">
- <span>Open image in new tab</span>
- <span>Save image as…</span>
- <span className="is-copy">Copy image</span>
- <span>Copy image link</span>
+ <span>{t('tour.menuOpenTab')}</span>
+ <span>{t('tour.menuSaveImage')}</span>
+ <span className="is-copy">{t('tour.menuCopyImage')}</span>
+ <span>{t('tour.menuCopyLink')}</span>
</div>
</div>
{/* File Explorer, for the drag-in demo. */}
<div className="ob-win ob-explorer" ref={explorerRef}>
<div className="ob-win-bar">
- <span className="ob-notes-title"><i className="ob-folder" />Documents</span>
+ <span className="ob-notes-title"><i className="ob-folder" />{t('tour.folder')}</span>
<Caption />
</div>
<div className="ob-files">
- <div className="ob-files-head"><span>Name</span><span>Size</span></div>
+ <div className="ob-files-head"><span>{t('tour.colName')}</span><span>{t('tour.colSize')}</span></div>
<i className="ob-band" />
- {FOLDER.map(([name, size]) => (
- <div key={name} className={`ob-file${name.endsWith('.pdf') ? ' is-pdf' : ''}`}>
+ {/* the rest of the folder, then the three files it selects and drags in */}
+ {[...otherFiles(), ...stackFiles()].map(([name, size], i) => (
+ <div key={i} className={`ob-file${i >= 3 ? ' is-pick' : ''}`}>
<img src={fileIconUrl(fileKindOf(name))} alt="" />
<span>{name}</span>
- <em>{Math.round(size / 1024).toLocaleString('en-US')} KB</em>
+ <em>{t('units.kb', { n: Math.round(size / 1024).toLocaleString(resolvedLang) })}</em>
</div>
))}
</div>
@@ -384,13 +437,13 @@ export function Onboarding() {
{/* Another app, for the drag demo. */}
<div className="ob-notes" ref={notesRef}>
<div className="ob-notes-bar">
- <span className="ob-notes-title"><i />Trip plan</span>
+ <span className="ob-notes-title"><i />{t('tour.notesApp')}</span>
<Caption />
</div>
<div className="ob-notes-body">
- <b>Weekend at the summit</b>
- <p>Sat · Trailhead 6:30, top by noon</p>
- <p>Sun · Ridge walk above the clouds</p>
+ <b>{t('tour.notesHeading')}</b>
+ <p>{t('tour.notesLine1')}</p>
+ <p>{t('tour.notesLine2')}</p>
<div className="ob-notes-image" ref={notesImageRef} />
</div>
</div>
@@ -398,8 +451,15 @@ export function Onboarding() {
{/* The real shelf, inert: the tour drives it. */}
{ready && (
<div
- className={`ob-shelf${shelf ? '' : ' is-hidden'}${shelfOpen ? ' is-open' : ''}`}
- style={{ transform: shelfTransform(cam), '--ob-bar-w': `${topBarLength(demo.hotZoneHeight)}px` } as React.CSSProperties}
+ className={`ob-shelf${shelf ? '' : ' is-hidden'}${shelfOpen ? ' is-open' : ''}${onMonitor ? ' is-real' : ''}`}
+ style={{
+ transform: onMonitor ? realScreenTransform(dock) : shelfTransform(cam),
+ // the last step moves it between edges while it is out of sight: at once, not gliding
+ transition: onMonitor ? 'none' : undefined,
+ '--ob-bar-w': `${topBarLength(demo.hotZoneHeight)}px`,
+ '--ob-real-h': `${side.height}px`,
+ '--ob-real-mid': `${side.middle}px`
+ } as React.CSSProperties}
aria-hidden
>
<Panel />
@@ -409,9 +469,9 @@ export function Onboarding() {
{/* The welcome and settings frames dim only below the laptop, so its screen stays the lit object. */}
<div className={`ob-below${cam === 'frame' ? '' : ' is-off'}`} aria-hidden />
- {/* The camera on the laptop: the whole laptop; the tour's push-in on its top edge; or (settings) a
- close-up framed on the user's edge. The bar is inside, so it stays attached to the screen edge. */}
- <div className={`ob-cam${cam === 'tour' ? ' is-tour' : ''}${closeUp ? ` is-close is-${edgeNow}` : ''}`} aria-hidden>
+ {/* The camera on the laptop: the whole laptop, or the tour's push-in on its top edge. The bar is
+ inside, so it stays attached to the screen edge. */}
+ <div className={`ob-cam${cam === 'tour' ? ' is-tour' : ''}`} aria-hidden>
<div className="ob-laptop">
<div className="ob-bezel" />
<div className="ob-base" />
@@ -439,12 +499,11 @@ export function Onboarding() {
<div className="ob-task-tray">
<svg width="9" height="7" viewBox="0 0 9 7"><path d="M.5 2.6a5.6 5.6 0 0 1 8 0M2 4.1a3.4 3.4 0 0 1 5 0M3.5 5.6a1.3 1.3 0 0 1 2 0" fill="none" stroke="#fff" strokeWidth=".9" strokeLinecap="round" /></svg>
<svg width="11" height="6" viewBox="0 0 11 6"><rect x=".5" y=".5" width="9" height="5" rx="1.2" fill="none" stroke="#fff" strokeWidth=".8" /><rect x="1.6" y="1.6" width="6" height="2.8" rx=".5" fill="#fff" /><rect x="9.8" y="2" width=".8" height="2" rx=".3" fill="#fff" /></svg>
- <span><b>12:01</b><b>27-10-2026</b></span>
+ <span>{taskbarClock(resolvedLang).map((s, i) => <b key={i}>{s}</b>)}</span>
</div>
</div>
</div>
- {/* Keyed by edge: moving to another edge fades in there instead of morphing across the screen. */}
- <div key={edgeNow} className={`ob-bar${barShown ? '' : ' is-hidden'}`} style={barStyle} />
+ <div className={`ob-bar${barShown ? '' : ' is-hidden'}`} style={barStyle} />
</div>
<div className="ob-cursor" ref={cursorRef} aria-hidden>
@@ -463,7 +522,7 @@ export function Onboarding() {
{/* Ctrl+C, outside the camera: placed beside a window as it is framed on screen (tour.ts keys). */}
<div className="ob-keys" ref={keysRef} aria-hidden>
- <div><kbd>Ctrl</kbd><b>+</b><kbd>C</kbd></div>
+ <div><kbd>{t('tour.ctrl')}</kbd><b>+</b><kbd>C</kbd></div>
<span ref={keysLabelRef} />
</div>
@@ -494,26 +553,56 @@ export function Onboarding() {
)}
</div>
<div className="ob-copy" key={s.key}>
- <h1>{s.title}</h1>
- <p>{s.body}</p>
- {/* Settings carries the options too: its button sits at the end of their row, so the step
- stays short enough to clear the laptop above it. */}
+ {s.key === 'settings' ? (
+ <>
+ <h1>{s.title}</h1>
+ <p>{s.body}</p>
+ </>
+ ) : (
+ // Every step's text in the same place, only this step's shown: the box is as tall as the
+ // longest in this language, so the button under it stays put from step to step. (This
+ // step's first, for anything that reads the heading.)
+ <div className="ob-text">
+ {[s, ...steps.slice(0, last).filter((st) => st.key !== s.key)].map((st) => (
+ <div key={st.key} className={st.key === s.key ? undefined : 'is-ghost'} aria-hidden={st.key === s.key ? undefined : true}>
+ <h1>{st.title}</h1>
+ <p>{st.body}</p>
+ </div>
+ ))}
+ </div>
+ )}
+ {/* The last step: once the shelf has shown every edge, the choice opens out under the text (the
+ camera pulls back to make room): the three edges, each a small screen with its bar, then
+ the two settings that matter and Get Started. */}
{s.key === 'settings' && real ? (
- <div className="ob-controls">
- <div className="ob-seg" role="group" aria-label={t('onboarding.configTitle')}>
- {(['left', 'top', 'right'] as const).map((pos) => (
- <button key={pos} type="button" aria-pressed={barPos === pos} onClick={() => void pick({ stickPosition: pos })}>
- {t(`position.${pos}`)}
+ <div className={`ob-choose${asking ? ' is-up' : ''}`} aria-hidden={!asking}>
+ <div>
+ <div className="ob-edges" role="radiogroup" aria-label={s.title}>
+ {(['left', 'top', 'right'] as const).map((pos) => (
+ <button
+ key={pos}
+ type="button"
+ role="radio"
+ aria-checked={barPos === pos}
+ tabIndex={asking ? 0 : -1}
+ className="ob-edge"
+ onClick={() => choose(pos)}
+ >
+ <span className={`ob-edge-screen is-${pos}`}><i /></span>
+ {t(`position.${pos}`)}
+ </button>
+ ))}
+ </div>
+ <div className="ob-controls">
+ <button type="button" className="ob-toggle" tabIndex={asking ? 0 : -1} aria-pressed={real.soundEffects !== false} onClick={() => void pick({ soundEffects: real.soundEffects === false })}>
+ <i />{t('behaviour.soundEffectsTitle')}
+ </button>
+ <button type="button" className="ob-toggle" tabIndex={asking ? 0 : -1} aria-pressed={real.launchAtLogin} onClick={() => void pick({ launchAtLogin: !real.launchAtLogin })}>
+ <i />{t('behaviour.launchAtLoginTitle')}
</button>
- ))}
+ {primary}
+ </div>
</div>
- <button type="button" className="ob-toggle" aria-pressed={real.soundEffects !== false} onClick={() => void pick({ soundEffects: real.soundEffects === false })}>
- <i />{t('behaviour.soundEffectsTitle')}
- </button>
- <button type="button" className="ob-toggle" aria-pressed={real.launchAtLogin} onClick={() => void pick({ launchAtLogin: !real.launchAtLogin })}>
- <i />{t('behaviour.launchAtLoginTitle')}
- </button>
- {primary}
</div>
) : primary}
{at === 0 && <button type="button" className="ob-skip" onClick={() => void finish()}>{t('onboarding.skip')}</button>}
diff --git a/src/onboarding/autoplay.ts b/src/onboarding/autoplay.ts
index 76dd689..8579248 100644
--- a/src/onboarding/autoplay.ts
+++ b/src/onboarding/autoplay.ts
@@ -19,16 +19,13 @@ const MAX_REST = 6000
/** How long each step's demo runs, from the step appearing to its end (measured), for pacing the fill. */
const DEMO_MS: Record<string, number> = {
- welcome: 4200,
- collect: 11600,
- dropin: 5750,
- stacks: 5150,
- drag: 3850,
- ungroup: 4900,
- merge: 3650,
- preview: 3750,
- note: 9650,
- search: 3400
+ welcome: 4100,
+ collect: 8950,
+ dropin: 10850,
+ drag: 3750,
+ stacks: 7500,
+ preview: 6000,
+ find: 9200
}
/** Han, kana and Hangul: one character carries about a word. */
diff --git a/src/onboarding/demoItems.ts b/src/onboarding/demoItems.ts
index 37a5137..f501269 100644
--- a/src/onboarding/demoItems.ts
+++ b/src/onboarding/demoItems.ts
@@ -4,19 +4,21 @@
* Paths are made up and never opened: the shelf is inert during the tour.
*
* They tell one small story (a weekend in the mountains), and the pictures are
- * drawn in the wallpaper's own style, so the demo feels like one world.
+ * drawn in the wallpaper's own style, so the demo feels like one world. Their
+ * words are in the user's language (`tour.*`), read each time they are used.
*/
import type { ClipboardItemDto, FileEntry } from '../../shared/types'
+import { getResolvedLanguage, t } from '../i18n'
import summitUrl from '../assets/onboarding/summit.png'
export const DEMO_DIR = 'C:\\Users\\You\\Documents\\'
const DIR = DEMO_DIR
-/** Pictures carry their own thumbnail (the app would make one from the file, which does not exist here). */
-const PICTURES: Record<string, string> = { 'Summit.png': summitUrl }
+/** The photo of the summit (it carries its own thumbnail: the app would make one from the file). */
+export const photoName = () => `${t('tour.filePhoto')}.png`
function file(name: string, size: number): FileEntry {
- const preview = PICTURES[name]
+ const preview = name === photoName() ? summitUrl : undefined
return { name, ext: name.split('.').pop() ?? '', size, isImage: !!preview, ...(preview ? { preview } : {}) }
}
@@ -30,12 +32,17 @@ function files(id: string, names: Array<[string, number]>, at: number): Clipboar
}
}
+/** The web page's title (also the link card's). */
+export const pageTitle = () => t('tour.pageTitle')
+
/** The sentence selected on the web page in the copy demo, line by line as the page lays it out. */
-export const PAGE_LINES = [
- 'A sea of clouds forms when cloud fills the',
- 'valleys below a summit, and the peaks stand',
- 'above it like islands.'
-]
+export const pageLines = () => [t('tour.line1'), t('tour.line2'), t('tour.line3')]
+
+/** The sentence as one text: Chinese and Japanese lines join without a space. */
+export function pageText(): string {
+ const joiner = /^(zh|ja)/.test(getResolvedLanguage()) ? '' : ' '
+ return pageLines().join(joiner)
+}
export function demoText(at: number): ClipboardItemDto {
return {
@@ -43,17 +50,18 @@ export function demoText(at: number): ClipboardItemDto {
capturedAt: at,
hitCount: 1,
pinned: false,
- data: { kind: 'text', isUrl: false, text: PAGE_LINES.join(' ') }
+ data: { kind: 'text', isUrl: false, text: pageText() }
}
}
+/** The page's address, dragged in from the browser's address bar (with its title, as browsers give it). */
export function demoLink(at: number): ClipboardItemDto {
return {
id: 'demo-link',
capturedAt: at,
hitCount: 1,
pinned: false,
- data: { kind: 'text', isUrl: true, text: 'https://en.wikipedia.org/wiki/Sea_of_clouds' }
+ data: { kind: 'text', isUrl: true, text: 'https://en.wikipedia.org/wiki/Sea_of_clouds', linkTitle: pageTitle() }
}
}
@@ -63,56 +71,51 @@ export function demoImage(at: number): ClipboardItemDto {
capturedAt: at,
hitCount: 1,
pinned: false,
- data: { kind: 'image', preview: summitUrl, imageId: 'demo-summit', width: 1920, height: 1200, bytes: 1_284_600, ext: 'png', fileName: 'Summit.png' }
+ data: { kind: 'image', preview: summitUrl, imageId: 'demo-summit', width: 1920, height: 1200, bytes: 1_284_600, ext: 'png', fileName: photoName() }
}
}
-export function demoPdf(at: number, note?: string): ClipboardItemDto {
- const it = files('demo-pdf', [['Itinerary.pdf', 412_000]], at)
- return note ? { ...it, note } : it
-}
-
/**
- * The note the tour adds to the itinerary from its right-click menu, and what it then types in search to
- * find it: a word only the note has, so the shelf narrows to that card as it is typed.
+ * The three files selected in File Explorer and dragged in at once: they land as one stack. The itinerary
+ * is the one later pulled out of it (the expanded stack's first row); the slides' orange folder then
+ * stands in front of what is left, ahead of the (blue) photo dropped onto it, where Word's blue would
+ * blend in.
*/
-export const DEMO_NOTE = 'Train tickets, Friday 6 pm'
-export const DEMO_QUERY = 'train'
+export const stackFiles = (): Array<[string, number]> => [
+ [`${t('tour.fileItinerary')}.pdf`, 412_000],
+ [`${t('tour.fileSlides')}.pptx`, 2_318_400],
+ [`${t('tour.fileBudget')}.xlsx`, 144_639]
+]
-/**
- * Five files of different kinds, selected in File Explorer and copied at once: they arrive as one stack.
- * The first is the one pulled out and then combined with the (blue) photo: the slides' orange folder
- * stands in front of it, where Word's blue would blend in. The four left are the stack the preview
- * opens.
- */
-export const STACK_FILES: Array<[string, number]> = [
- ['Trip slides.pptx', 2_318_400],
- ['Budget.xlsx', 144_639],
- ['Packing list.docx', 96_426],
- ['Summit photos.zip', 18_874_368],
- ['Checklist.txt', 2_150]
+/** The rest of the folder in File Explorer, above the three that are dragged in. */
+export const otherFiles = (): Array<[string, number]> => [
+ [`${t('tour.fileChecklist')}.txt`, 2_150],
+ [`${t('tour.filePacking')}.docx`, 96_426],
+ [`${t('tour.filePhotos')}.zip`, 18_874_368]
]
-export function demoStack(at: number, names = STACK_FILES): ClipboardItemDto {
+/** The three files as they land: one stack (`names`: what is left in it). */
+export function demoStack(at: number, names = stackFiles()): ClipboardItemDto {
return files('demo-stack', names, at)
}
-/** One file pulled out of the stack becomes a card of its own. */
-export function demoSingle(at: number, name: [string, number]): ClipboardItemDto {
- return files('demo-single', [name], at)
+/** The itinerary pulled out of the stack: a card of its own (with the note the tour gives it later). */
+export function demoPdf(at: number, note?: string): ClipboardItemDto {
+ const it = files('demo-pdf', [stackFiles()[0]], at)
+ return note ? { ...it, note } : it
}
-/** The image dropped onto the single file: one stack holding both, the file first (main: the target's files, then the dropped one's). */
-export function demoMerged(at: number, name: [string, number]): ClipboardItemDto {
- return {
- id: 'demo-single',
- capturedAt: at,
- hitCount: 1,
- pinned: false,
- data: {
- kind: 'files',
- paths: [DIR + name[0], DIR + 'Summit.png'],
- entries: [file(name[0], name[1]), file('Summit.png', 1_284_600)]
- }
- }
+/**
+ * What is left of the stack once the itinerary is out, with the photo dropped onto it (main's merge: the
+ * target's files, then the dropped one's).
+ */
+export function demoStackWithPhoto(at: number): ClipboardItemDto {
+ return files('demo-stack', [...stackFiles().slice(1), [photoName(), 1_284_600]], at)
}
+
+/**
+ * The note the tour adds to the itinerary from its right-click menu, and what it then types in search to
+ * find it: a word only the note has, so the shelf narrows to that card as it is typed.
+ */
+export const demoNote = () => t('tour.note')
+export const demoQuery = () => t('tour.query')
diff --git a/src/onboarding/edgeBar.ts b/src/onboarding/edgeBar.ts
index 0bdd37e..8ace40e 100644
--- a/src/onboarding/edgeBar.ts
+++ b/src/onboarding/edgeBar.ts
@@ -44,18 +44,72 @@ export const shelfTransform = (cam: 'frame' | 'tour') =>
? `translateY(${TOUR_SCREEN_TOP}px) scale(${SHELF_SCALE})`
: `translateY(${LAPTOP_SCREEN.top}px) scale(${SHELF_SCALE / TOUR.scale})`
+/**
+ * The screen the last step shows the shelf on, on each edge: a 1920 x 1080 monitor at 100% display
+ * scale, drawn on the laptop's screen. The shelf is laid out as on that monitor (.ob-shelf.is-real), so
+ * on every edge it is the size it really is there, in proportion to the screen.
+ */
+export const REAL_SCREEN = { width: 1920, height: 1080 }
+
+/** The laptop screen's height is that monitor's: everything on it at this scale. */
+const REAL_SCALE = LAPTOP_SCREEN.height / REAL_SCREEN.height
+
+/**
+ * How far (window pixels) the shelf is tucked under the bezel on the edge it is docked to. Edge to edge,
+ * the bezel's and the shelf's edges each cover part of the same row of pixels wherever that falls between
+ * pixels (any display scale but 100% and 200%, or mid camera move), and the wallpaper behind showed
+ * through between them as a line. Tucked under, the bezel's edge always lies over the shelf's black.
+ * The closed bar is that much thicker (realHotZoneWidth), so what shows of it is its real thickness.
+ */
+const TUCK = 1
+
+/**
+ * The shelf layer, laid out as that monitor, on the laptop's screen: its top on the screen's top, and its
+ * side on the screen's side for a side edge (the monitor is a touch narrower than the laptop's wide
+ * screen), its middle on the screen's middle for the top; tucked under the bezel on its edge (TUCK). It
+ * scales from the middle of its top edge (see .ob-shelf).
+ */
+export function realScreenTransform(dock: StickPosition): string {
+ const k = REAL_SCALE
+ const half = REAL_SCREEN.width / 2
+ const x =
+ dock === 'left'
+ ? LAPTOP_SCREEN.left - TUCK - half * (1 - k)
+ : dock === 'right'
+ ? LAPTOP_SCREEN.left + LAPTOP_SCREEN.width + TUCK - half * (1 + k)
+ : LAPTOP_SCREEN.left + LAPTOP_SCREEN.width / 2 - half
+ const y = LAPTOP_SCREEN.top - (dock === 'top' ? TUCK : 0)
+ return `translate(${x}px, ${y}px) scale(${k})`
+}
+
+/** The closed bar's thickness laid out on that monitor, with the part tucked under the bezel added. */
+export const realHotZoneWidth = (hotZoneWidth: number) => hotZoneWidth + TUCK / REAL_SCALE
+
+/**
+ * Where a side edge's shelf sits on that monitor (Panel lays it out from the window's height: its height
+ * and its middle, from panelHeight and verticalOffset, are given to .ob-shelf.is-real here instead).
+ */
+export function realSidePanel(panelHeight: number, verticalOffset: number): { height: number; middle: number } {
+ const height = panelHeight * REAL_SCREEN.height
+ return { height, middle: height / 2 + verticalOffset * (REAL_SCREEN.height - height) }
+}
+
+/**
+ * The tour's trigger zone length for a side edge laid out as that monitor: Panel takes it as a share of
+ * the window's height, the window being shorter than the monitor (`windowHeight`).
+ */
+export const realSideHotZone = (hotZoneHeight: number, windowHeight: number) =>
+ Math.min(1, (hotZoneHeight * REAL_SCREEN.height) / windowHeight)
+
/** Length of the top dock's bar (Panel: triggerWidthPx). */
export function topBarLength(hotZoneHeight: number): number {
return hotZoneHeight >= 0.55 ? 575 : hotZoneHeight >= 0.35 ? 400 : 275
}
-function radius(pos: StickPosition, corner: number): string {
- if (pos === 'top') return `0 0 ${corner}px ${corner}px / 0 0 100% 100%`
- if (pos === 'left') return `0 100% 100% 0 / 0 ${corner}px ${corner}px 0`
- return `100% 0 0 100% / ${corner}px 0 0 ${corner}px`
-}
+/** The top bar's tapered ends (Panel's closed blade clip). */
+const topRadius = (corner: number) => `0 0 ${corner}px ${corner}px / 0 0 100% 100%`
-type BarSettings = Pick<Settings, 'hotZoneHeight' | 'hotZoneWidth'> & Partial<Pick<Settings, 'panelHeight' | 'verticalOffset'>>
+type BarSettings = Pick<Settings, 'hotZoneHeight' | 'hotZoneWidth'>
/**
* The bar on the laptop's top edge in the welcome frame, sized so that after
@@ -71,7 +125,7 @@ export function tourBar(s: BarSettings): CSSProperties {
top: LAPTOP_SCREEN.top,
width: length,
height: (s.hotZoneWidth || 3) * k,
- borderRadius: radius('top', 24 * k)
+ borderRadius: topRadius(24 * k)
}
}
@@ -85,34 +139,3 @@ export function toShelfLayer(r: { left: number; top: number; width: number; heig
height: r.height / SHELF_SCALE
}
}
-
-/** The bar on the laptop's screen: the user's screen scaled down to the frame. */
-export function laptopBar(pos: StickPosition, s: BarSettings): CSSProperties {
- const screenW = window.screen?.width || 1920
- const screenH = window.screen?.height || 1080
- const k = LAPTOP_SCREEN.width / screenW
- // Scaled 1:1 the bar would be ~1px thick; keep it visible.
- const thick = Math.max(2, Math.round((s.hotZoneWidth || 3) * k * 1.4))
- const corner = 24 * k
- if (pos === 'top') {
- const length = topBarLength(s.hotZoneHeight) * k
- return {
- left: LAPTOP_SCREEN.left + LAPTOP_SCREEN.width / 2 - length / 2,
- top: LAPTOP_SCREEN.top,
- width: length,
- height: thick,
- borderRadius: radius('top', corner)
- }
- }
- // Side docks: the bar is centred on the shelf's middle, as in Panel.
- const length = screenH * s.hotZoneHeight * k
- const panelH = (s.panelHeight || 0.6) * LAPTOP_SCREEN.height
- const mid = panelH / 2 + (s.verticalOffset ?? 0.5) * (LAPTOP_SCREEN.height - panelH)
- return {
- left: pos === 'left' ? LAPTOP_SCREEN.left : LAPTOP_SCREEN.left + LAPTOP_SCREEN.width - thick,
- top: LAPTOP_SCREEN.top + mid - length / 2,
- width: thick,
- height: length,
- borderRadius: radius(pos, corner)
- }
-}
diff --git a/src/onboarding/tour.ts b/src/onboarding/tour.ts
index 581b8d8..e7bcef9 100644
--- a/src/onboarding/tour.ts
+++ b/src/onboarding/tour.ts
@@ -1,7 +1,7 @@
/**
* The tour's demos: each step plays the real shelf (Panel and its cards) on
* example items, by writing the same store state the app itself sets while a
- * user copies, drags, stacks, splits, merges and previews. Store actions that
+ * user copies, drags in and out, splits, combines, previews, notes and searches. Store actions that
* talk to main are never called (they would act on the user's real panel
* window); state is written with useStore.setState directly.
*
@@ -19,13 +19,14 @@
import { useStore } from '../store/appStore'
import { t } from '../i18n'
import { setEdgeDragPull } from '../lib/edgeDrag'
-import type { ClipboardItemDto } from '../../shared/types'
+import type { ClipboardItemDto, StickPosition } from '../../shared/types'
import { dragGhostSvg } from '../../shared/dragGhost'
import { fileIconUrl, fileKindOf, type FileKind } from '../lib/fileKind'
-import { LAPTOP_SCREEN, SHELF_SCALE, TOUR_SCREEN_TOP, toShelfLayer } from './edgeBar'
+import { LAPTOP_SCREEN, SHELF_SCALE, TOUR_SCREEN_TOP, realHotZoneWidth, realSideHotZone, toShelfLayer } from './edgeBar'
+import { DEFAULT_SETTINGS } from '../../shared/types'
import { aim, REST, toLocal, toScreen, zoomRest, zoomTo, type Rect, type View } from './lens'
import {
- demoText, demoLink, demoImage, demoPdf, demoStack, demoSingle, demoMerged, STACK_FILES, DEMO_DIR, DEMO_NOTE, DEMO_QUERY
+ demoText, demoLink, demoImage, demoPdf, demoStack, demoStackWithPhoto, stackFiles, pageTitle, DEMO_DIR, demoNote, demoQuery
} from './demoItems'
export const STOP = Symbol('stop')
@@ -85,32 +86,29 @@ export interface Stage {
const MOVE = 'cubic-bezier(.45,0,.25,1)'
const set = useStore.setState
-/** Item states each step starts from, so Back and Continue land on a consistent shelf. */
+/**
+ * Item states each step starts from, so Back and Continue land on a consistent shelf: each is where the
+ * step before leaves it, in the order main keeps (a new card at the front, a split's card where its stack
+ * was, a combined stack in its place).
+ */
export function itemsFor(step: string, now = Date.now()): ClipboardItemDto[] {
- // Copied from the page (text, link, image), then the PDF dragged in from File Explorer.
- const three = [demoImage(now - 9000), demoLink(now - 14000), demoText(now - 19000)]
- const four = [demoPdf(now - 4000), ...three]
- // Dragged out into another app, the image counts as used and moves to the front (as in the app).
- const used = [demoImage(now - 500), ...four.filter((it) => it.id !== 'demo-image')]
- const split = [demoSingle(now - 2000, STACK_FILES[0]), demoStack(now - 3000, STACK_FILES.slice(1))]
- // the shelf the preview leaves: the slides and the photo in one stack, the four files in another
- const kept = (note?: string) => [
- demoMerged(now - 2000, STACK_FILES[0]), split[1], demoPdf(now - 4000, note), ...three.filter((it) => it.id !== 'demo-image')
- ]
+ // copied from the web page: the sentence, then the photo
+ const copied = [demoImage(now - 9000), demoText(now - 14000)]
+ // then dragged in: the page's link from the browser, and three files from File Explorer as one stack
+ const dropped = [demoStack(now - 4000), demoLink(now - 6000), ...copied]
+ // the itinerary pulled out of the stack, the photo dropped into it
+ const sorted = (note?: string) => [demoPdf(now - 3000, note), demoStackWithPhoto(now - 2000), demoLink(now - 6000), demoText(now - 14000)]
switch (step) {
- case 'welcome': return four
+ case 'welcome': return dropped
case 'collect': return []
- case 'dropin': return three
- case 'stacks': return four
- case 'drag': return [demoStack(now - 1000), ...four]
- case 'ungroup': return [used[0], demoStack(now - 1000), ...used.slice(1)]
- case 'merge': return [...split, ...used]
+ case 'dropin': return copied
+ case 'drag': return dropped
+ // dragged out into another app, the photo counts as used and moves to the front (main: movePastedToTop)
+ case 'stacks': return [demoImage(now - 500), demoStack(now - 4000), demoLink(now - 6000), demoText(now - 14000)]
case 'preview':
- case 'note':
- return kept()
- case 'search':
- case 'settings':
- return kept(DEMO_NOTE)
+ case 'find':
+ return sorted()
+ case 'settings': return sorted(demoNote())
default: return []
}
}
@@ -118,8 +116,7 @@ export function itemsFor(step: string, now = Date.now()): ClipboardItemDto[] {
/** The other app each step plays in; a step that follows in the same app keeps it up. */
const WINDOW_OF: Record<string, (stage: Stage) => HTMLElement> = {
collect: (s) => s.browser,
- dropin: (s) => s.explorer,
- stacks: (s) => s.explorer,
+ dropin: (s) => s.browser,
drag: (s) => s.notes
}
@@ -131,18 +128,28 @@ export function resetDemoState(stage: Stage, next?: string): void {
leaveField()
set({
internalDragReq: null, dropTargetId: null, expandedStackId: null, previewItemId: null, previewItemRect: null,
- copyFlareActive: false, externalDrag: false, dragActive: false, cardMenu: null, cardMenuRect: null, query: ''
+ copyFlareActive: false, externalDrag: false, dragActive: false, cardMenu: null, cardMenuRect: null,
+ edgeTransition: null
})
+ // a search empties at once, except when the shelf is folding away for a step on the laptop (the welcome,
+ // the last step): there the shelf would fill back up as it closes, so Onboarding empties it once the
+ // shelf is out of sight
+ if (next !== 'welcome' && next !== 'settings') set({ query: '' })
setEdgeDragPull(0)
stage.cursor.getAnimations().forEach((a) => a.cancel())
document.body.classList.remove('ob-preview-pan')
stage.keys.getAnimations().forEach((a) => a.cancel())
- stage.notesImage.getAnimations().forEach((a) => a.cancel())
clearMarks(stage)
stage.root.querySelector('.ob-cam')?.classList.remove('is-push')
const view = openingView(next)
if (view) zoomTo(stage.lens, view, 900)
const keep = next ? WINDOW_OF[next]?.(stage) : undefined
+ // the picture dropped into the notes app (a class, .is-in, not one of the run's animations, which a step
+ // change stops at once) goes with its window: at once if the window stays, or once the window has faded
+ // out (.ob-notes, 0.26s), instead of vanishing from it as it fades
+ const picture = stage.notesImage
+ if (keep === stage.notes) picture.classList.remove('is-in')
+ else window.setTimeout(() => { if (!stage.notes.classList.contains('is-up')) picture.classList.remove('is-in') }, 300)
for (const w of [stage.notes, stage.browser, stage.explorer]) if (w !== keep) hideWindow(w)
stage.root.querySelector('.ob-shelf')?.getAnimations().forEach((a) => a.cancel())
}
@@ -183,7 +190,7 @@ const onWindow = (box: Rect): View => aim(PUSH, { x: box.left + box.width / 2, y
* pulls back as its pointer comes in (its flyout opens outside the camera, at rest).
*/
function openingView(step?: string): View | null {
- if (step === 'ungroup' || step === 'merge') return SHELF_CLOSE
+ if (step === 'stacks') return SHELF_CLOSE
if (step === 'preview') return null
return REST
}
@@ -287,15 +294,16 @@ class DragImage {
}
/**
- * What Windows shows while a file is dragged out of File Explorer: the file's icon, see-through, riding
- * just above the pointer, and a "+ Copy" label once it is over a place that takes it.
+ * What Windows shows while something is dragged out of another app, riding just above the pointer: files'
+ * icons, see-through (several: a small pile with their count), or a link's page; and a "+ Copy" label
+ * once over a place that takes it.
*/
-class FileGhost {
+class AppGhost {
readonly el: HTMLDivElement
- constructor(private run: Run, stage: Stage, kind: FileKind, private at: { x: number; y: number }) {
+ constructor(private run: Run, stage: Stage, html: string, private at: { x: number; y: number }) {
this.el = document.createElement('div')
this.el.className = 'ob-ghost ob-file-ghost'
- this.el.innerHTML = `<img src="${fileIconUrl(kind)}" alt=""><span>+ Copy</span>`
+ this.el.innerHTML = `${html}<span>+ ${esc(t('tour.dragCopy'))}</span>`
this.el.style.transform = this.tf(at)
stage.lens.append(this.el)
run.animate(this.el, [{ opacity: 0 }, { opacity: 1 }], { duration: 140, fill: 'none' }).catch(() => {})
@@ -316,6 +324,53 @@ class FileGhost {
}
}
+/** Files from File Explorer: the first in front (last drawn), the others a step behind it each. */
+function filesGhost(kinds: FileKind[]): string {
+ const pile = kinds.slice(0, 3).map((k, i) => `<img src="${fileIconUrl(k)}" alt="" style="--i:${i}">`).reverse().join('')
+ return `${pile}${kinds.length > 1 ? `<b>${kinds.length}</b>` : ''}`
+}
+
+/** A link from the browser's address bar: the page's icon, title and address, as the browser draws it. */
+const linkGhost = () =>
+ `<div class="ob-link-ghost"><i>W</i><div><strong>${esc(pageTitle())} - Wikipedia</strong><em>en.wikipedia.org</em></div></div>`
+
+/** Text for innerHTML. */
+const esc = (s: string) => s.replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' })[c] as string)
+
+/**
+ * Something dragged in from another app, from `from` to the edge: as it nears the edge the bar swells (the
+ * app's own pull, in steps), at the bar the shelf opens into its drop zone, over the shelf the zone
+ * lights, and it is dropped. `pace` scales the glide (a short trip from near the edge is quicker).
+ */
+async function dropAtEdge(run: Run, p: Pointer, g: AppGhost, from: { x: number; y: number }, pace = 1) {
+ const bar = { x: 400, y: TOUR_SCREEN_TOP + 6 }
+ const legs: Array<[number, number, string, number]> = [
+ [0.4, 420, 'cubic-bezier(.45,0,1,1)', 0.3],
+ [0.75, 300, 'linear', 0.6],
+ [1, 360, 'cubic-bezier(0,0,.3,1)', 0.9]
+ ]
+ for (const [t, ms, easing, pull] of legs) {
+ const x = from.x + (bar.x - from.x) * t
+ const y = from.y + (bar.y - from.y) * t
+ await Promise.all([p.move(x, y, ms * pace, easing), g.move(x, y, ms * pace, easing)])
+ setEdgeDragPull(pull)
+ }
+ // at the bar: the shelf opens straight into its drop zone
+ set({ open: true })
+ await run.sleep(400)
+ const over = { x: 400, y: TOUR_SCREEN_TOP + 62 }
+ await Promise.all([p.move(over.x, over.y, 360), g.move(over.x, over.y, 360)])
+ set({ dragActive: true })
+ g.copying(true)
+ await run.sleep(400)
+ // the drop: the zone takes it in (DropOverlay listens for the drop), then the card is there
+ g.drop()
+ document.dispatchEvent(new Event('drop'))
+ set({ externalDrag: false, dragActive: false })
+ setEdgeDragPull(0)
+ await run.sleep(260)
+}
+
/**
* Ctrl+C on screen: centred, or beside the window being copied from (`beside`, in scene pixels), as that
* window is framed on screen: to its right, or to its left where the right has no room.
@@ -418,9 +473,9 @@ function deselect(run: Run, el: HTMLElement) {
}
/**
- * Copy from a web page the way people do, with the shelf closed: select a sentence and press Ctrl+C,
- * click the address and press Ctrl+C, right-click the photo and choose Copy image. Each copy lights the
- * edge; then the pointer opens the shelf and all three are there.
+ * Copy from a web page the way people do, with the shelf closed: select a sentence and press Ctrl+C, then
+ * right-click the photo and choose Copy image. Each copy lights the edge; then the pointer opens the
+ * shelf and both are there.
*/
export async function demoCollect(run: Run, stage: Stage) {
const p = new Pointer(run, stage.cursor)
@@ -452,26 +507,13 @@ export async function demoCollect(run: Run, stage: Stage) {
copyFlare(run)
await run.sleep(450)
- // 2. the link: a click in the address bar selects it all
- const url = page.querySelector<HTMLElement>('.ob-url')!
- const u = rect(stage, url)
- await p.move(u.left + u.width * 0.6, u.top + u.height / 2, 600)
- await p.press()
- // a click elsewhere ends the page's selection; the address selects all at once
- lines.forEach((l) => deselect(run, hl(l)))
- run.animate(hl(url), [{ transform: 'scaleX(0)', opacity: 0 }, { transform: 'scaleX(1)', opacity: 1 }], { duration: 140 }).catch(() => {})
- await run.sleep(250)
- await keys(run, stage, '', box)
- capture(demoLink(now))
- copyFlare(run)
- await run.sleep(450)
-
- // 3. the photo: right-click, Copy image
+ // 2. the photo: right-click, Copy image
const photo = page.querySelector<HTMLElement>('.ob-photo')!
const ph = rect(stage, photo)
- await p.move(ph.left + ph.width * 0.45, ph.top + ph.height * 0.55, 600)
+ await p.move(ph.left + ph.width * 0.45, ph.top + ph.height * 0.55, 650)
await p.press()
- deselect(run, hl(url))
+ // a click elsewhere ends the page's selection
+ lines.forEach((l) => deselect(run, hl(l)))
const menu = page.querySelector<HTMLElement>('.ob-menu')!
// at the pointer, flipped to the other side where it would not fit in the window (as real menus do)
const mx = ph.left + ph.width * 0.45 - box.left
@@ -493,73 +535,92 @@ export async function demoCollect(run: Run, stage: Stage) {
item.classList.remove('is-hover')
capture(demoImage(now))
copyFlare(run)
- await run.sleep(700)
+ await run.sleep(500)
// all of it is on the shelf: the camera pulls back as the pointer rides up, so the shelf opens in full view
zoomRest(stage.lens, 750, MOVE)
await p.move(400, TOUR_SCREEN_TOP + 5, 750)
set({ open: true })
- await run.sleep(900)
- await p.move(560, 380, 600)
+ await run.sleep(750)
+ await p.move(560, 380, 500)
await p.hide()
}
/**
- * Drag a file in from File Explorer: as it nears the edge the bar swells (the app's own pull, in steps),
- * at the bar the shelf opens into its drop zone, over the shelf the zone lights, and the drop lands as a card.
+ * Drag things in from other apps. First the page's link, by the icon in the browser's address bar: it
+ * lands as a card. Then, as the pointer heads to File Explorer, the shelf folds away; three files are
+ * selected there (a selection box drawn across them, as on the desktop) and dragged in at once: they land
+ * as one stack.
*/
export async function demoDropIn(run: Run, stage: Stage) {
const p = new Pointer(run, stage.cursor)
+ const page = stage.browser
const win = stage.explorer
clearMarks(stage)
- showWindow(win)
+ hideWindow(win)
+ showWindow(page)
await run.sleep(250)
- const row = win.querySelector<HTMLElement>('.ob-file.is-pdf')!
- const icon = row.querySelector('img')!
- const c = centre(stage, icon)
+
+ // 1. the link
+ const site = centre(stage, page.querySelector('.ob-site')!)
+ // the camera pushes in on the address bar, the screen's edge in frame
+ zoomTo(stage.lens, withEdge(PUSH, site.x + 110), 900)
+ await p.show(site.x + 150, site.y + 80)
+ await p.move(site.x, site.y, 600)
+ await p.press()
+ await p.move(site.x + 6, site.y + 8, 120)
+ set({ externalDrag: true })
+ const link = new AppGhost(run, stage, linkGhost(), { x: site.x + 6, y: site.y + 8 })
+ await dropAtEdge(run, p, link, { x: site.x + 6, y: site.y + 8 }, 0.75)
+ capture(demoLink(Date.now()))
+ await run.sleep(450)
+
+ // 2. the files: off to File Explorer (the shelf folds away as the pointer leaves it)
+ set({ open: false })
+ hideWindow(page)
+ showWindow(win)
+ const list = win.querySelector<HTMLElement>('.ob-files')!
+ const band = list.querySelector<HTMLElement>('.ob-band')!
+ const rows = [...list.querySelectorAll<HTMLElement>('.ob-file.is-pick')]
+ const lb = rect(stage, list)
const box = rect(stage, win)
- zoomTo(stage.lens, onWindow(box), 1000)
- await p.show(560, 380)
- await p.move(c.x, c.y, 650)
- row.classList.add('is-on')
+ const first = rect(stage, rows[0])
+ const last = rect(stage, rows[rows.length - 1])
+ // the box: from the empty space under the list, up and to the left across the three files
+ const from = { x: lb.right - 24, y: last.bottom + 14 }
+ const to = { x: first.left + first.width * 0.42, y: first.top + first.height * 0.5 }
+ zoomTo(stage.lens, onWindow(box), 900)
+ await p.move(from.x, from.y, 900)
+ await p.press()
+ const T = 700
+ const bandAt = (x: number, y: number) => ({ left: `${x - lb.left}px`, top: `${y - lb.top}px` })
+ run.animate(band, [
+ { ...bandAt(from.x, from.y), width: '0px', height: '0px', opacity: 1 },
+ { ...bandAt(to.x, to.y), width: `${from.x - to.x}px`, height: `${from.y - to.y}px`, opacity: 1 }
+ ], { duration: T, easing: 'linear' }).catch(() => {})
+ // each file joins the selection as the box's edge reaches it
+ for (const row of rows) {
+ const reach = (from.y - (rect(stage, row).bottom - 4)) / (from.y - to.y)
+ run.sleep(Math.max(0, reach) * T).then(() => row.classList.add('is-on')).catch(() => {})
+ }
+ await p.move(to.x, to.y, T, 'linear')
+ // let go: the box goes, the three stay selected
+ run.animate(band, [{ opacity: 1 }, { opacity: 0 }], { duration: 160 }).catch(() => {})
+ await run.sleep(200)
+ // press on the selection and drag all three out
+ const c = centre(stage, rows[0].querySelector('img')!)
+ await p.move(c.x, c.y, 280)
await p.press()
await p.move(c.x + 6, c.y + 8, 120)
set({ externalDrag: true })
- const g = new FileGhost(run, stage, 'pdf', { x: c.x + 6, y: c.y + 8 })
- // toward the bar: one smooth glide in three legs, the swell growing at each
- const from = { x: c.x + 6, y: c.y + 8 }
- const bar = { x: 400, y: TOUR_SCREEN_TOP + 6 }
- const legs: Array<[number, number, string, number]> = [
- [0.4, 420, 'cubic-bezier(.45,0,1,1)', 0.3],
- [0.75, 300, 'linear', 0.6],
- [1, 360, 'cubic-bezier(0,0,.3,1)', 0.9]
- ]
- // the camera pulls back as the file rides up, so the bar swelling and the shelf opening are in full view
+ const g = new AppGhost(run, stage, filesGhost(stackFiles().map(([name]) => fileKindOf(name))), { x: c.x + 6, y: c.y + 8 })
+ // the camera pulls back as the files ride up, so the bar swelling and the shelf opening are in full view
zoomRest(stage.lens, 1080, MOVE)
- for (const [t, ms, easing, pull] of legs) {
- const x = from.x + (bar.x - from.x) * t
- const y = from.y + (bar.y - from.y) * t
- await Promise.all([p.move(x, y, ms, easing), g.move(x, y, ms, easing)])
- setEdgeDragPull(pull)
- }
- // at the bar: the shelf opens straight into its drop zone
- set({ open: true })
- await run.sleep(420)
- const over = { x: 400, y: TOUR_SCREEN_TOP + 62 }
- await Promise.all([p.move(over.x, over.y, 380), g.move(over.x, over.y, 380)])
- set({ dragActive: true })
- g.copying(true)
- await run.sleep(420)
- // the drop: the zone takes it in (DropOverlay listens for the drop), then the card is there
- g.drop()
- document.dispatchEvent(new Event('drop'))
- set({ externalDrag: false, dragActive: false })
- setEdgeDragPull(0)
- await run.sleep(260)
- capture(demoPdf(Date.now()))
- await run.sleep(500)
- row.classList.remove('is-on')
- await p.move(560, 380, 600)
+ await dropAtEdge(run, p, g, { x: c.x + 6, y: c.y + 8 })
+ capture(demoStack(Date.now()))
+ await run.sleep(400)
+ rows.forEach((row) => row.classList.remove('is-on'))
+ await p.move(560, 380, 500)
await p.hide()
}
@@ -570,7 +631,9 @@ export async function demoDrag(run: Run, stage: Stage) {
await p.show(600, 400)
const src = card(stage, 'demo-image')
const c = centre(stage, src)
- zoomTo(stage.lens, withEdge(PUSH, c.x, c.x), 900)
+ const notes = rect(stage, stage.notes)
+ // in on the card, but not so far that the document below slides under the step's text
+ zoomTo(stage.lens, withEdge(Math.min(PUSH, (430 + 15) / notes.bottom), c.x, c.x), 900)
await p.move(c.x, c.y, 700)
await p.press()
set({ internalDragReq: { id: 'demo-image' } })
@@ -578,13 +641,13 @@ export async function demoDrag(run: Run, stage: Stage) {
const g = new DragImage(run, stage, ['image'], 1, { x: c.x + 6, y: c.y + 8 })
// drop where the picture lands in the document, the camera following the drag down to it
const { x: tx, y: ty } = centre(stage, stage.notesImage)
- const notes = rect(stage, stage.notes)
const nx = notes.left + notes.width / 2
zoomTo(stage.lens, aim(PUSH, { x: nx, y: notes.bottom }, { x: nx, y: 430 }), 850, MOVE)
await Promise.all([p.move(tx, ty, 850), g.move(tx, ty, 850)])
g.drop()
set({ internalDragReq: null })
- await run.animate(stage.notesImage, [{ opacity: 0, transform: 'scale(.8)' }, { opacity: 1, transform: 'none' }], { duration: 300 })
+ stage.notesImage.classList.add('is-in')
+ await run.sleep(300)
// a card dragged out into another app counts as used: it moves to the front (main: movePastedToTop)
const items = useStore.getState().items
set({ items: [...items.filter((it) => it.id === 'demo-image').map((it) => ({ ...it, capturedAt: Date.now() })), ...items.filter((it) => it.id !== 'demo-image')] })
@@ -595,108 +658,59 @@ export async function demoDrag(run: Run, stage: Stage) {
}
/**
- * Select three files in File Explorer (a selection box drawn across them, as on the desktop) and press
- * Ctrl+C: they land on the shelf as one stack.
+ * Split and combine: open the stack and drag the itinerary to the light on the edge, and it becomes a card
+ * of its own (main puts it where the stack was); then drop the photo onto the stack, and it joins it.
*/
export async function demoStacks(run: Run, stage: Stage) {
- const p = new Pointer(run, stage.cursor)
- const win = stage.explorer
- clearMarks(stage)
- showWindow(win)
- await run.sleep(250)
- const list = win.querySelector<HTMLElement>('.ob-files')!
- const band = list.querySelector<HTMLElement>('.ob-band')!
- const rows = [...list.querySelectorAll<HTMLElement>('.ob-file:not(.is-pdf)')]
- const lb = rect(stage, list)
- const box = rect(stage, win)
- const top = rect(stage, rows[0])
- const bottom = rect(stage, rows[rows.length - 1])
- // from the empty space under the list, up and to the left across the three files
- const from = { x: lb.right - 24, y: bottom.bottom + 14 }
- const to = { x: top.left + top.width * 0.42, y: top.top + top.height * 0.5 }
- zoomTo(stage.lens, onWindow(box), 1000)
- await p.show(box.right - 40, box.bottom + 30)
- await p.move(from.x, from.y, 600)
- await p.press()
- const T = 900
- const bandAt = (x: number, y: number) => ({ left: `${x - lb.left}px`, top: `${y - lb.top}px` })
- run.animate(band, [
- { ...bandAt(from.x, from.y), width: '0px', height: '0px', opacity: 1 },
- { ...bandAt(to.x, to.y), width: `${from.x - to.x}px`, height: `${from.y - to.y}px`, opacity: 1 }
- ], { duration: T, easing: 'linear' }).catch(() => {})
- // each file joins the selection as the box's edge reaches it
- for (const row of rows) {
- const reach = (from.y - (rect(stage, row).bottom - 4)) / (from.y - to.y)
- run.sleep(Math.max(0, reach) * T).then(() => row.classList.add('is-on')).catch(() => {})
- }
- await p.move(to.x, to.y, T, 'linear')
- // let go: the box goes, the three stay selected
- run.animate(band, [{ opacity: 1 }, { opacity: 0 }], { duration: 160 }).catch(() => {})
- await run.sleep(300)
- await keys(run, stage, '', box)
- capture(demoStack(Date.now()))
- copyFlare(run)
- // the stack lands at the front of the shelf: the camera pulls back to show it there
- zoomRest(stage.lens, 900)
- await run.sleep(900)
- await p.move(box.right - 40, box.bottom + 30, 600)
- await p.hide()
-}
-
-/** Open the stack, drag one file to the edge light, and it becomes its own card. */
-export async function demoUngroup(run: Run, stage: Stage) {
const p = new Pointer(run, stage.cursor)
await p.show(560, 380)
- const stackCard = card(stage, 'demo-stack')
- const c = centre(stage, stackCard)
+ const stack = card(stage, 'demo-stack')
+ const c = centre(stage, stack)
await p.move(c.x, c.y, 650)
await p.press()
set({ expandedStackId: 'demo-stack' })
await run.sleep(550)
- // The expanded stack's first file row (StackItems).
+ // the expanded stack's first file row (StackItems): the itinerary
const tile = stage.root.querySelector<HTMLElement>('.item-main[data-id="demo-stack"] .stack-row')
if (!tile) throw STOP
- const t = centre(stage, tile)
- await p.move(t.x, t.y, 500)
+ const f = centre(stage, tile)
+ await p.move(f.x, f.y, 450)
await p.press()
- const path = DEMO_DIR + STACK_FILES[0][0]
+ const path = DEMO_DIR + stackFiles()[0][0]
set({ internalDragReq: { id: 'demo-stack', paths: [path] } })
- await p.move(t.x + 6, t.y + 8, 120)
- const g = new DragImage(run, stage, [fileKindOf(path)], 1, { x: t.x + 6, y: t.y + 8 })
+ await p.move(f.x + 6, f.y + 8, 120)
+ const g = new DragImage(run, stage, [fileKindOf(path)], 1, { x: f.x + 6, y: f.y + 8 })
// up to the light on the edge (in frame: the close-up keeps the screen's edge)
const ex = 400, ey = TOUR_SCREEN_TOP + 5
- await Promise.all([p.move(ex, ey, 900), g.move(ex, ey, 900)])
- await run.sleep(500) // the edge light answers the drag
+ await Promise.all([p.move(ex, ey, 850), g.move(ex, ey, 850)])
+ await run.sleep(450) // the edge light answers the drag
g.drop()
set({ internalDragReq: null, expandedStackId: null })
+ // main's split: the file becomes a card where its stack was, the stack keeps the rest
const now = Date.now()
- set({ items: [demoSingle(now, STACK_FILES[0]), demoStack(now - 1000, STACK_FILES.slice(1)), ...useStore.getState().items.filter((it) => it.id !== 'demo-stack')] })
- await run.sleep(400)
- await p.hide()
-}
+ set({
+ items: useStore.getState().items.flatMap((it) => (it.id === 'demo-stack' ? [demoPdf(now), demoStack(now - 1000, stackFiles().slice(1))] : [it]))
+ })
+ await run.sleep(550)
-/** Drop the image onto the single file: they become one stack. */
-export async function demoMerge(run: Run, stage: Stage) {
- const p = new Pointer(run, stage.cursor)
- await p.show(600, 380)
+ // combine: the photo onto the stack
const src = card(stage, 'demo-image')
- const c = centre(stage, src)
- await p.move(c.x, c.y, 650)
+ const s = centre(stage, src)
+ await p.move(s.x, s.y, 600)
await p.press()
set({ internalDragReq: { id: 'demo-image' } })
- await p.move(c.x + 6, c.y + 8, 120)
- const g = new DragImage(run, stage, ['image'], 1, { x: c.x + 6, y: c.y + 8 })
- const target = card(stage, 'demo-single')
- const tc = centre(stage, target)
- await Promise.all([p.move(tc.x, tc.y, 950), g.move(tc.x, tc.y, 950)])
- set({ dropTargetId: 'demo-single' })
- await run.sleep(450)
- g.drop()
- const now = Date.now()
+ await p.move(s.x + 6, s.y + 8, 120)
+ const g2 = new DragImage(run, stage, ['image'], 1, { x: s.x + 6, y: s.y + 8 })
+ const tc = centre(stage, card(stage, 'demo-stack'))
+ await Promise.all([p.move(tc.x, tc.y, 850), g2.move(tc.x, tc.y, 850)])
+ set({ dropTargetId: 'demo-stack' })
+ await run.sleep(420)
+ g2.drop()
+ // main's merge: the stack stays where it is with the photo added, the photo's card goes
set({
internalDragReq: null,
dropTargetId: null,
- items: [demoMerged(now, STACK_FILES[0]), ...useStore.getState().items.filter((it) => it.id !== 'demo-single' && it.id !== 'demo-image')]
+ items: useStore.getState().items.flatMap((it) => (it.id === 'demo-image' ? [] : it.id === 'demo-stack' ? [demoStackWithPhoto(Date.now())] : [it]))
})
await run.sleep(400)
await p.hide()
@@ -728,16 +742,61 @@ export async function demoPreview(run: Run, stage: Stage) {
await p.press()
const r = target.getBoundingClientRect()
set({ previewItemId: 'demo-stack', previewItemRect: toShelfLayer(r) })
- await run.sleep(450)
+ await run.sleep(80)
+ // the photo further down is drawn lazily (once scrolled near); here it is fetched as the preview opens,
+ // so the scroll down to it finds it there at its size
+ const photos = [...document.querySelectorAll<HTMLImageElement>('.pf-wrap img.thumb')]
+ photos.forEach((img) => { img.loading = 'eager' })
+ await run.sleep(370)
target.classList.remove('force-actions')
await p.hide()
// the camera pans the screen up so the whole preview is in view, and stays there while the step is up
// (a replay or the next step brings it back)
- if (document.documentElement.dataset.motion !== 'reduce') {
+ const moving = document.documentElement.dataset.motion !== 'reduce'
+ const panned: View = moving ? { k: 1, x: 0, y: -PREVIEW_PAN } : REST
+ if (moving) {
document.body.classList.add('ob-preview-pan')
- zoomTo(stage.lens, { k: 1, x: 0, y: -PREVIEW_PAN }, 900)
+ zoomTo(stage.lens, panned, 900)
await run.sleep(950)
}
+ // the photo comes after the files: the pointer comes onto the list and scrolls down to it (the preview
+ // is drawn above the whole scene, so the pointer's twin above it does this)
+ const list = document.querySelector<HTMLElement>('.pf-wrap .pf-scroll')
+ if (!list) return
+ await loaded(run, photos, 1500)
+ if (list.scrollHeight <= list.clientHeight + 4) return
+ const top = twinPointer(run, stage, panned)
+ const box = list.getBoundingClientRect()
+ const at = { x: box.left + box.width * 0.64, y: box.top + box.height * 0.62 }
+ await top.show(at.x + 30, at.y + 40)
+ await top.move(at.x, at.y, 450)
+ await scrollTo(run, list, list.scrollHeight - list.clientHeight, 1100)
+ await run.sleep(250)
+ await top.hide()
+ top.el.remove()
+}
+
+/** Resolves once every image has its picture (a failed source falls back to the item's own preview), or after `ms`. */
+async function loaded(run: Run, imgs: HTMLImageElement[], ms: number) {
+ const t0 = performance.now()
+ while (imgs.some((img) => !(img.complete && img.naturalWidth > 0)) && performance.now() - t0 < ms) await run.sleep(50)
+}
+
+/** Scrolls `el` to `top` over `ms`, easing in and out (a wheel's smooth scroll). */
+function scrollTo(run: Run, el: HTMLElement, top: number, ms: number): Promise<void> {
+ const from = el.scrollTop
+ const t0 = performance.now()
+ return new Promise((resolve, reject) => {
+ const step = (now: number) => {
+ if (run.dead) return reject(STOP)
+ const k = Math.min(1, (now - t0) / ms)
+ const e = k < 0.5 ? 4 * k * k * k : 1 - Math.pow(-2 * k + 2, 3) / 2
+ el.scrollTop = from + (top - from) * e
+ if (k < 1) requestAnimationFrame(step)
+ else resolve()
+ }
+ requestAnimationFrame(step)
+ })
}
/** Types into one of the app's fields the way a keyboard does: its own input events, a character at a time. */
@@ -777,46 +836,75 @@ async function pick(run: Run, top: Pointer, el: HTMLElement, ms: number) {
await top.press()
}
+/** The card menu's sizes (cardMenu.css: the menu's narrowest, the note editor's width) and gaps (CardMenu). */
+const MENU_MIN_W = 212
+const EDITOR_W = 252
+const MENU_EDGE = 8
+const MENU_POINTER = 2
+
/**
- * Right-click a card: the app's own menu opens at the pointer. Add note… turns it into the note editor; a
- * note is typed and saved, and it shows on the card in place of its file name.
+ * Where on a card to right-click (its x, in scene pixels, near `x`) so that the menu and the note editor it
+ * turns into open on the same side of the pointer: in the top dock both stay within the shelf's width
+ * (CardMenu placeMenu and menuRegion, with their unscaled sizes against window pixels), and the editor is
+ * wider, so near the shelf's end the menu could open to the right and the editor then jump to the left.
+ * `v`: the camera's framing while the menu is open.
*/
-export async function demoNote(run: Run, stage: Stage) {
+function sameSide(stage: Stage, v: View, card: Rect, x: number): number {
+ const blade = stage.root.querySelector('.ob-shelf .blade')
+ if (!blade) return x
+ const b = rect(stage, blade)
+ const toWin = (sx: number) => sx * v.k + v.x
+ const toScene = (wx: number) => (wx - v.x) / v.k
+ const lo = Math.max(MENU_EDGE, toWin(b.left) + MENU_EDGE)
+ const hi = Math.min(800 - MENU_EDGE, toWin(b.right) - MENU_EDGE)
+ const from = card.left + card.width * 0.15
+ const to = card.right - card.width * 0.15
+ // both to the right: the editor fits between the pointer and the shelf's end
+ const rightMost = toScene(hi - MENU_POINTER - EDITOR_W)
+ if (rightMost >= from) return Math.min(Math.max(x, from), rightMost)
+ // both to the left: not even the narrowest menu fits on the right, and the editor fits on the left
+ const leftLeast = Math.max(toScene(hi - MENU_POINTER - MENU_MIN_W) + 1, toScene(lo + MENU_POINTER + EDITOR_W))
+ return leftLeast <= to ? Math.max(x, leftLeast) : x
+}
+
+/**
+ * Find it again: right-click the itinerary, and the app's own menu opens at the pointer; Add note… turns it
+ * into the note editor, a note is typed and saved, and it shows on the card in place of its file name. Then
+ * into search: a word only the note has, and the shelf narrows to that card as it is typed.
+ */
+export async function demoFind(run: Run, stage: Stage) {
const p = new Pointer(run, stage.cursor)
await p.show(600, 400)
const target = card(stage, 'demo-pdf')
const r = rect(stage, target)
- // the card's upper half, right of its middle: the shelf ends not far to the right, so the menu (which
- // stays within the shelf's width in the top dock) opens to the pointer's left, and so does the note
- // editor it turns into, both from the same corner; the card itself stays in view beside them, and both
- // end well above the step's text
- const at = { x: r.left + r.width * 0.62, y: r.top + r.height * 0.3 }
+ const at = { x: r.left + r.width * 0.5, y: r.top + r.height * 0.3 }
zoomTo(stage.lens, withEdge(PUSH, at.x), 900)
+ // the camera's framing while the menu is open (at rest under reduced motion)
+ const v = document.documentElement.dataset.motion === 'reduce' ? REST : withEdge(PUSH, at.x)
+ at.x = sameSide(stage, v, r, at.x)
await p.move(at.x, at.y, 900)
await run.sleep(80)
await p.press()
- // the menu at the pointer, at the camera's scale (at rest under reduced motion); the twin pointer takes
- // over above it
- const v = document.documentElement.dataset.motion === 'reduce' ? REST : withEdge(PUSH, at.x)
+ // the menu at the pointer, at the camera's scale; the twin pointer takes over above it
const s = toScreen(stage.lens, at)
document.body.style.setProperty('--ob-menu-scale', String(SHELF_SCALE * v.k))
const top = twinPointer(run, stage, v)
await Promise.all([top.set(s.x, s.y, true), p.set(at.x, at.y, false)])
useStore.getState().openCardMenu('demo-pdf', s.x, s.y)
- await run.sleep(500)
+ await run.sleep(400)
const label = t('menu.addNote')
const row = [...document.querySelectorAll<HTMLElement>('.card-menu .card-menu-row')].find((el) => el.textContent === label)
if (!row) throw STOP
- await pick(run, top, row, 520)
+ await pick(run, top, row, 450)
useStore.getState().editCardMeta()
- await run.sleep(420)
- const input = document.querySelector<HTMLInputElement>('.card-menu .card-meta-input')
- if (!input) throw STOP
- await typeInto(run, input, DEMO_NOTE)
await run.sleep(350)
+ const field = document.querySelector<HTMLInputElement>('.card-menu .card-meta-input')
+ if (!field) throw STOP
+ await typeInto(run, field, demoNote())
+ await run.sleep(250)
const save = document.querySelector<HTMLElement>('.card-menu .card-meta-btn.is-primary')
if (!save) throw STOP
- await pick(run, top, save, 480)
+ await pick(run, top, save, 420)
// the editor's own Save: the note goes onto the card (in the tour's store only) and the editor closes
save.closest('form')?.requestSubmit()
await run.sleep(80)
@@ -824,45 +912,119 @@ export async function demoNote(run: Run, stage: Stage) {
const back = top.pos
await Promise.all([p.set((back.x - v.x) / v.k, (back.y - v.y) / v.k, true), top.set(back.x, back.y, false)])
top.el.remove()
- await run.sleep(900)
- zoomRest(stage.lens, 900)
- await p.move(600, 400, 900)
- await p.hide()
-}
+ await run.sleep(600)
-/**
- * Click into the search box and type: the shelf narrows with every letter, down to the card the note
- * was added to (a word only its note has).
- */
-export async function demoSearch(run: Run, stage: Stage) {
- const p = new Pointer(run, stage.cursor)
- await p.show(600, 400)
+ // search: the camera takes in the row of cards as the pointer goes to the box
const input = stage.root.querySelector<HTMLInputElement>('.ob-shelf .search input')
if (!input) throw STOP
const c = centre(stage, input)
- zoomTo(stage.lens, SHELF_CLOSE, 900)
- await p.move(c.x - 40, c.y, 900)
+ zoomTo(stage.lens, SHELF_CLOSE, 850)
+ await p.move(c.x - 40, c.y, 850)
await p.press()
input.focus({ preventScroll: true })
- await run.sleep(350)
+ await run.sleep(300)
// the pointer moves off the field, out of the way of what is typed
p.move(c.x + 70, c.y + 60, 500).catch(() => {})
- await typeInto(run, input, DEMO_QUERY)
+ await typeInto(run, input, demoQuery())
await run.sleep(700)
await p.hide()
}
+// ---------- the last step: the shelf on each edge, then the user's own ----------
+
+/**
+ * Pulled back a little for the choice, so the whole laptop clears the options below it. (Under reduced
+ * motion the camera does not move, so .ob-choosing puts it there at once: --ob-choice-*, Onboarding.)
+ * The screen's edges land on whole pixels there (48k + x = 114, 752k + x = 686, 18k + y = 19), so the
+ * bezel and the shelf docked against it meet exactly, with no line of wallpaper between them; at rest
+ * (the edges shown at 100%) they do already.
+ */
+export const CHOICE_VIEW: View = { k: 0.8125, x: 75, y: 4.375 }
+
+/**
+ * The tour's shelf on an edge of the last step's monitor (edgeBar REAL_SCREEN): a side edge's trigger
+ * zone is the share of the monitor's height it is in the app, not of the window's, and the closed bar
+ * carries on under the bezel (realHotZoneWidth).
+ */
+function dockAt(pos: StickPosition) {
+ const hz = DEFAULT_SETTINGS.hotZoneHeight
+ set({
+ settings: {
+ ...useStore.getState().settings,
+ stickPosition: pos,
+ hotZoneHeight: pos === 'top' ? hz : realSideHotZone(hz, window.innerHeight),
+ hotZoneWidth: realHotZoneWidth(DEFAULT_SETTINGS.hotZoneWidth)
+ }
+ })
+}
+
+/**
+ * The shelf's bar moves to another edge the way the app moves it (Panel's edge change: the bar fades
+ * out, the shelf is laid out on the new edge, the bar fades in there), folding the shelf first if it is
+ * open. Only the tour's store changes: nothing is saved.
+ */
+async function moveBar(run: Run, to: StickPosition) {
+ if (useStore.getState().open) {
+ set({ open: false })
+ await run.sleep(420)
+ }
+ const from = useStore.getState().settings.stickPosition
+ if (from === to) return
+ set({ edgeTransition: { active: true, from, to, stage: 'bar_fade_out' } })
+ await run.sleep(120)
+ dockAt(to)
+ await run.sleep(40)
+ set({ edgeTransition: { active: true, from, to, stage: 'bar_fade_in' } })
+ await run.sleep(140)
+ set({ edgeTransition: null })
+}
+
+/** The shelf on one edge: its bar there, closed a moment, then it opens, holds, and folds back. */
+async function playEdge(run: Run, to: StickPosition, hold: number) {
+ await moveBar(run, to)
+ await run.sleep(500)
+ set({ open: true })
+ await run.sleep(hold)
+ set({ open: false })
+ await run.sleep(450)
+}
+
+/**
+ * Make it yours: the shelf plays on the left edge, then the top, then the right, on the whole laptop at
+ * 100% (the camera still: only the shelf moves), and settles on the user's own edge as the camera pulls
+ * back for the choice. The real shelf, on the laptop (the frame view lays it out on whichever edge the
+ * tour's store says).
+ */
+export async function demoEdges(run: Run, stage: Stage, mine: StickPosition) {
+ zoomRest(stage.lens, 600)
+ // the drawn bar (the tour's) goes; the shelf, laid out on the monitor now, comes in on the left edge
+ set({ edgeTransition: { active: true, from: 'top', to: 'left', stage: 'bar_fade_out' } })
+ dockAt('left')
+ stage.showShelf(true)
+ await run.sleep(250)
+ set({ edgeTransition: { active: true, from: 'top', to: 'left', stage: 'bar_fade_in' } })
+ await run.sleep(140)
+ set({ edgeTransition: null })
+ for (const pos of ['left', 'top', 'right'] as const) await playEdge(run, pos, 1300)
+ zoomTo(stage.lens, CHOICE_VIEW, 900)
+ await moveBar(run, mine)
+ await run.sleep(300)
+}
+
+/** The user picked an edge: the shelf goes there and opens once, to show it. */
+export async function showEdge(run: Run, stage: Stage, to: StickPosition) {
+ zoomTo(stage.lens, CHOICE_VIEW, 600)
+ await playEdge(run, to, 1100)
+}
+
export const DEMOS: Record<string, ((run: Run, stage: Stage) => Promise<void>) | undefined> = {
welcome: demoWelcome,
collect: demoCollect,
dropin: demoDropIn,
drag: demoDrag,
stacks: demoStacks,
- ungroup: demoUngroup,
- merge: demoMerge,
preview: demoPreview,
- note: demoNote,
- search: demoSearch
+ find: demoFind
}
// ---------- replays ----------
@@ -918,9 +1080,9 @@ async function rewind(run: Run, stage: Stage, step: string, open: boolean) {
run.animate(m, [{ transform: t, opacity: o }, { transform: t, opacity: 0 }], { duration: 400, easing: 'ease' }).catch(() => {})
}
stage.root.querySelectorAll('.ob-file.is-on').forEach((el) => el.classList.remove('is-on'))
- if (stage.notesImage.getAnimations().length) {
- stage.notesImage.getAnimations().forEach((a) => a.cancel())
- await run.animate(stage.notesImage, [{ opacity: 1 }, { opacity: 0 }], { duration: 400, easing: 'ease' })
+ if (stage.notesImage.classList.contains('is-in')) {
+ stage.notesImage.classList.remove('is-in')
+ await run.sleep(400)
}
const start = itemsFor(step)
const same = start.length === st.items.length && start.every((it, i) => it.id === st.items[i].id && it.note === st.items[i].note)
diff --git a/src/styles/onboarding.css b/src/styles/onboarding.css
index 0dde51f..7d11751 100644
--- a/src/styles/onboarding.css
+++ b/src/styles/onboarding.css
@@ -43,6 +43,12 @@
transition: none !important;
zoom: 1 !important;
}
+/* ...except the last step's pull-back for its choice (CHOICE_VIEW in tour.ts), which makes room for the
+ options: there at once. */
+[data-motion='reduce'] .ob-choosing .ob-lens {
+ transform: var(--ob-choice-move) !important;
+ zoom: var(--ob-choice-zoom) !important;
+}
.ob-sky {
position: absolute;
left: 0;
@@ -100,6 +106,40 @@
.ob-shelf.is-open::after {
width: calc(100% - 60px);
}
+/* The last step: the shelf laid out as a 1920 x 1080 monitor at 100% and drawn on the laptop's screen
+ (realScreenTransform), so on every edge it is the size it really is on such a screen. Panel sizes a few
+ things from the window, which here is not that monitor: the top blade's width (100vw), a side blade's
+ height (panelHeight in vh) and its middle (from the window's height); they get the monitor's here
+ (realSidePanel, --ob-real-*). The screen's edges land on whole pixels: no backing strips. */
+.ob-shelf.is-real {
+ right: auto;
+ bottom: auto;
+ width: 1920px;
+ height: 1080px;
+}
+.ob-shelf.is-real::before,
+.ob-shelf.is-real::after {
+ display: none;
+}
+.ob-shelf.is-real .blade-container.blade-top .blade {
+ width: 1080px !important;
+}
+.ob-shelf.is-real .blade-container:not(.blade-top) {
+ top: var(--ob-real-mid) !important;
+}
+.ob-shelf.is-real .blade-container:not(.blade-top) .blade {
+ height: var(--ob-real-h) !important;
+}
+/* A side edge's reverse curves sit just above and below the blade, edge to edge with it (the top edge's
+ overlap it): drawn this small, that edge falls between pixels and the wallpaper showed through as a
+ line between the curve and the body. Tucked 3px behind the blade (they are under it), the blade's
+ edge lies over their black. */
+.ob-shelf.is-real .blade-container .flare-top {
+ top: -27px;
+}
+.ob-shelf.is-real .blade-container .flare-bottom {
+ bottom: -27px;
+}
/* The cards' pictures (file icons, the folders and photos of a stack, the grain) are each kept on a
pre-drawn layer in the app, sharp there because the shelf is shown 1:1 (item.css). Here the shelf is
shown scaled (0.72, and the camera zooms it), so those layers were resampled and the glass folders read
@@ -184,12 +224,14 @@
/* Welcome and settings: dim only below the laptop, so its screen stays the lit object. */
.ob-below {
position: absolute;
- left: 0;
- right: 0;
+ /* past the window's sides and bottom: the last step's camera pulls back (lens.ts), and it must still
+ reach the window's edges */
+ left: -200px;
+ right: -200px;
top: 420px;
- bottom: 0;
+ bottom: -200px;
pointer-events: none;
- background: linear-gradient(rgba(4, 8, 40, 0), rgba(4, 8, 40, 0.5) 40%, rgba(4, 8, 40, 0.62));
+ background: linear-gradient(rgba(4, 8, 40, 0), rgba(4, 8, 40, 0.5) 88px, rgba(4, 8, 40, 0.62) 220px);
transition: opacity 0.5s ease;
}
.ob-below.is-off {
@@ -238,37 +280,18 @@
opacity: 0;
transition: opacity 0.4s ease;
}
-.ob-cam.is-close.is-top {
- transform-origin: 400px 10px;
- transform: scale(1.04);
-}
-/* Each framing keeps the whole laptop (its taskbar and base) above the step's text, which starts at
- about y = 473: the base ends at y = 460 or less. */
-.ob-cam.is-close.is-left {
- transform-origin: 40px 345px;
- transform: scale(1.3);
-}
-.ob-cam.is-close.is-right {
- transform-origin: 760px 345px;
- transform: scale(1.3);
-}
-.ob-cam.is-close {
- animation: ob-drift 8s cubic-bezier(0.25, 0.6, 0.3, 1) 0.9s both;
-}
-@keyframes ob-drift {
- from {
- translate: 0 0;
- }
- to {
- translate: 0 6px;
- }
-}
+/* The screen's taskbar runs 4px past the screen's sides and bottom, under the bezel (painted above it,
+ .ob-laptop), so its edges never meet the bezel's edge to edge: wherever that edge fell between pixels
+ (the last step's pulled-back camera, a display scale like 125%) the wallpaper showed through the
+ see-through bar as a line. What shows is the same 704 x 22 bar: its contents keep their places
+ (the extra bottom 4px is padding; the tray sits 4px further in). */
.ob-taskbar {
position: absolute;
- left: 48px;
+ left: 44px;
top: 386px;
- width: 704px;
- height: 22px;
+ width: 712px;
+ height: 26px;
+ padding-bottom: 4px;
box-sizing: border-box;
display: flex;
align-items: center;
@@ -308,9 +331,9 @@
}
.ob-task-tray {
position: absolute;
- right: 8px;
+ right: 12px;
top: 0;
- bottom: 0;
+ bottom: 4px;
display: flex;
align-items: center;
gap: 6px;
@@ -330,9 +353,11 @@
position: absolute;
inset: 0;
pointer-events: none;
+ isolation: isolate;
}
.ob-bezel {
position: absolute;
+ z-index: 1;
left: 40px;
top: 10px;
width: 720px;
@@ -446,6 +471,14 @@
opacity: 0;
background: url('../assets/onboarding/summit.png') center / cover;
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
+ transform: scale(0.8);
+ transition: opacity 0.3s cubic-bezier(0.3, 0.8, 0.2, 1), transform 0.3s cubic-bezier(0.3, 0.8, 0.2, 1);
+}
+/* The card's picture, dropped into the document (tour.ts demoDrag): a class, so a step change leaves it to
+ fade out with its window. */
+.ob-notes-image.is-in {
+ opacity: 1;
+ transform: none;
}
/* The browser (copy demo) and File Explorer (drag-in demo): the same dark Windows 11 windows as the notes app. */
.ob-win {
@@ -508,9 +541,13 @@
font-size: 10.5px;
}
.ob-url {
- position: relative;
white-space: nowrap;
}
+.ob-site {
+ flex: none;
+ margin-right: 8px;
+ color: #c9cbd2;
+}
/* A text selection: Windows' selection blue behind the text, grown from the left as the pointer drags. */
.ob-hl {
position: absolute;
@@ -521,7 +558,6 @@
transform: scaleX(0);
transform-origin: 0 50%;
}
-.ob-url,
.ob-line {
isolation: isolate;
}
@@ -728,14 +764,33 @@
.ob-ghost svg {
display: block;
}
-/* A file dragged out of File Explorer: its icon, see-through, and "+ Copy" once over a drop target. */
+/* Files dragged out of File Explorer: their icons, see-through (several: a pile, each a step up and to the
+ right behind the first, with their count), and "+ Copy" once over a drop target. */
.ob-file-ghost img {
- display: block;
+ position: absolute;
+ left: 0;
+ top: 0;
width: 40px;
height: 40px;
+ translate: calc(var(--i, 0) * 5px) calc(var(--i, 0) * -5px);
opacity: 0.78;
filter: drop-shadow(0 4px 8px rgba(0, 0, 30, 0.35));
}
+.ob-file-ghost b {
+ position: absolute;
+ left: 30px;
+ top: -9px;
+ min-width: 17px;
+ height: 17px;
+ padding: 0 4px;
+ box-sizing: border-box;
+ border-radius: 9px;
+ background: #0067c0;
+ box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.9);
+ color: #fff;
+ font: 600 10px/17px var(--font-ui);
+ text-align: center;
+}
.ob-file-ghost span {
position: absolute;
left: 30px;
@@ -753,6 +808,46 @@
.ob-file-ghost.is-copy span {
opacity: 1;
}
+/* A link dragged out of the browser's address bar: the page's icon, title and address. */
+.ob-link-ghost {
+ position: absolute;
+ left: 0;
+ top: 8px;
+ display: flex;
+ align-items: center;
+ gap: 7px;
+ padding: 6px 10px 6px 7px;
+ border-radius: 7px;
+ white-space: nowrap;
+ background: rgba(43, 45, 51, 0.88);
+ box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1), 0 6px 16px rgba(0, 0, 30, 0.35);
+}
+.ob-link-ghost i {
+ width: 16px;
+ height: 16px;
+ border-radius: 50%;
+ display: grid;
+ place-items: center;
+ background: #eceef2;
+ color: #222;
+ font: 700 9px Georgia, serif;
+ font-style: normal;
+}
+.ob-link-ghost div {
+ display: flex;
+ flex-direction: column;
+ line-height: 12px;
+}
+.ob-link-ghost strong {
+ font-size: 10px;
+ font-weight: 600;
+ color: #ececef;
+}
+.ob-link-ghost em {
+ font-size: 9px;
+ font-style: normal;
+ color: #a4a7b0;
+}
/* ---------- text ---------- */
.ob-ui {
@@ -849,6 +944,19 @@
filter: blur(6px);
}
}
+.ob-text {
+ display: grid;
+ justify-items: center;
+}
+.ob-text > div {
+ grid-area: 1 / 1;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+}
+.ob-text > .is-ghost {
+ visibility: hidden;
+}
.ob-copy h1 {
margin: 10px 0 0;
font-size: 23px;
@@ -896,7 +1004,7 @@
color: #fff;
}
.ob-controls {
- margin-top: 16px;
+ margin-top: 14px;
display: flex;
gap: 10px;
align-items: center;
@@ -912,25 +1020,115 @@
min-width: 0;
padding: 0 24px;
}
-.ob-seg {
+/* The last step's choice opens out under the text once the shelf has shown every edge (a row that grows
+ from nothing, so the text above glides up as the camera pulls back to make room). */
+.ob-choose {
+ display: grid;
+ grid-template-rows: 0fr;
+ opacity: 0;
+ visibility: hidden;
+ transition: grid-template-rows 0.9s cubic-bezier(0.5, 0, 0.25, 1), opacity 0.25s ease, visibility 0s linear 0.9s;
+}
+.ob-choose.is-up {
+ grid-template-rows: 1fr;
+ opacity: 1;
+ visibility: visible;
+ transition: grid-template-rows 0.9s cubic-bezier(0.5, 0, 0.25, 1), opacity 0.5s ease 0.4s, visibility 0s;
+}
+.ob-choose > div {
+ min-height: 0;
+ /* clipped while it grows; the padding keeps the focus rings and the picked outline inside */
+ overflow: hidden;
+ padding: 0 6px 4px;
+}
+.ob-edges {
display: flex;
- gap: 2px;
- padding: 2px;
- border-radius: 999px;
- background: rgba(255, 255, 255, 0.1);
+ /* the edges in the order they are on the screen, in every language (right-to-left ones too) */
+ direction: ltr;
+ justify-content: center;
+ gap: 12px;
+ margin-top: 16px;
+ padding-top: 3px;
}
-.ob-seg button {
+/* An edge: a small screen in the wallpaper's blue with the bar on that edge, and its name. */
+.ob-edge {
+ width: 104px;
+ padding: 11px 0 8px;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ gap: 8px;
border: 0;
- background: transparent;
+ border-radius: 14px;
+ background: rgba(255, 255, 255, 0.08);
+ box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
color: #d6dcf0;
- font: 600 11.5px var(--font-ui);
- padding: 5px 12px;
- border-radius: 999px;
+ font: 600 12px var(--font-ui);
cursor: pointer;
+ transition: background 0.2s, box-shadow 0.2s, color 0.2s, transform 0.1s;
}
-.ob-seg button[aria-pressed='true'] {
- background: #fff;
- color: #000;
+.ob-edge:hover {
+ background: rgba(255, 255, 255, 0.14);
+}
+.ob-edge:active {
+ transform: scale(0.97);
+}
+.ob-edge:focus-visible {
+ outline: 2px solid rgba(255, 255, 255, 0.8);
+ outline-offset: 2px;
+}
+.ob-edge[aria-checked='true'] {
+ background: rgba(255, 255, 255, 0.2);
+ box-shadow: inset 0 0 0 2px #fff;
+ color: #fff;
+}
+.ob-edge-screen {
+ position: relative;
+ width: 64px;
+ height: 40px;
+ border-radius: 4px;
+ background: linear-gradient(160deg, #4a6cff, #1f3bd6);
+ box-shadow: 0 0 0 2px #07080b;
+ overflow: hidden;
+}
+.ob-edge-screen i {
+ position: absolute;
+ background: #000;
+ transition: transform 0.25s ease;
+}
+.ob-edge-screen.is-left i,
+.ob-edge-screen.is-right i {
+ top: 10px;
+ width: 3px;
+ height: 20px;
+}
+.ob-edge-screen.is-left i {
+ left: 0;
+ border-radius: 0 3px 3px 0;
+}
+.ob-edge-screen.is-right i {
+ right: 0;
+ border-radius: 3px 0 0 3px;
+}
+.ob-edge-screen.is-top i {
+ top: 0;
+ left: 20px;
+ width: 24px;
+ height: 3px;
+ border-radius: 0 0 3px 3px;
+}
+/* the picked edge's bar stands out a little more */
+.ob-edge[aria-checked='true'] .ob-edge-screen.is-left i {
+ transform: scaleX(1.5);
+ transform-origin: 0 50%;
+}
+.ob-edge[aria-checked='true'] .ob-edge-screen.is-right i {
+ transform: scaleX(1.5);
+ transform-origin: 100% 50%;
+}
+.ob-edge[aria-checked='true'] .ob-edge-screen.is-top i {
+ transform: scaleY(1.5);
+ transform-origin: 50% 0;
}
.ob-toggle {
display: flex;
diff --git a/tests/i18nCoverage.test.ts b/tests/i18nCoverage.test.ts
new file mode 100644
index 0000000..0a981aa
--- /dev/null
+++ b/tests/i18nCoverage.test.ts
@@ -0,0 +1,169 @@
+import { describe, it, expect, beforeEach } from 'vitest'
+import { TRANSLATIONS, en, LANGUAGES } from '../src/i18n/translations'
+import { t, languageLabel } from '../src/i18n'
+import { useStore } from '../src/store/appStore'
+import { localizeLinkInfo } from '../src/lib/linkLabels'
+import { parseUrlPreview } from '../src/lib/urlPreview'
+import { formatBytes } from '../src/lib/format'
+import { kindBadge } from '../src/lib/fileType'
+import { matches } from '../src/hooks/useFilteredItems'
+import { queryWords } from '../src/lib/search'
+import { demoLink, demoNote, demoPdf, demoQuery, demoStackWithPhoto, demoText, pageLines } from '../src/onboarding/demoItems'
+
+type Tree = { [k: string]: string | Tree }
+const isPlural = (v: unknown): v is Record<string, string> =>
+ !!v && typeof v === 'object' && typeof (v as { other?: unknown }).other === 'string'
+
+/** Every leaf: 'section.key' -> string, or the plural group as a whole. */
+function leaves(o: Tree, prefix = '', out: Record<string, unknown> = {}): Record<string, unknown> {
+ for (const [k, v] of Object.entries(o)) {
+ const key = prefix ? `${prefix}.${k}` : k
+ if (typeof v === 'object' && !isPlural(v)) leaves(v as Tree, key, out)
+ else out[key] = v
+ }
+ return out
+}
+const params = (s: string) => [...s.matchAll(/\{(\w+)\}/g)].map((m) => m[1]).sort().join(',')
+const EN = leaves(en as unknown as Tree)
+const CODES = Object.keys(TRANSLATIONS).filter((c) => c !== 'en')
+
+function setLanguage(code: string) {
+ useStore.setState((s) => ({ settings: { ...s.settings, language: code } }))
+}
+
+describe('every language has every string', () => {
+ it('31 languages, each with the language picker entry', () => {
+ expect(Object.keys(TRANSLATIONS)).toHaveLength(31)
+ for (const code of Object.keys(TRANSLATIONS)) expect(LANGUAGES.some((l) => l.code === code), code).toBe(true)
+ })
+
+ it.each(CODES)('%s: no key missing, none extra, same placeholders', (code) => {
+ const L = leaves(TRANSLATIONS[code] as unknown as Tree)
+ for (const [key, enVal] of Object.entries(EN)) {
+ const v = L[key]
+ expect(v, `${code} ${key}`).toBeDefined()
+ if (isPlural(enVal)) {
+ expect(isPlural(v), `${code} ${key} is a plural group`).toBe(true)
+ continue
+ }
+ expect(typeof v, `${code} ${key}`).toBe('string')
+ expect((v as string).trim().length, `${code} ${key} empty`).toBeGreaterThan(0)
+ expect(params(v as string), `${code} ${key} placeholders`).toBe(params(enVal as string))
+ }
+ for (const key of Object.keys(L)) expect(key in EN, `${code} has unknown key ${key}`).toBe(true)
+ })
+
+ it.each(Object.keys(TRANSLATIONS))('%s: plural groups have exactly the language\'s plural forms, each with the number', (code) => {
+ const cats = new Intl.PluralRules(code).resolvedOptions().pluralCategories
+ const L = leaves(TRANSLATIONS[code] as unknown as Tree)
+ for (const [key, v] of Object.entries(L)) {
+ if (!isPlural(v)) continue
+ expect(Object.keys(v).sort(), `${code} ${key}`).toEqual([...cats].sort())
+ for (const [cat, form] of Object.entries(v)) expect(form, `${code} ${key}.${cat}`).toContain('{count}')
+ }
+ })
+})
+
+describe('plural forms are chosen by the number', () => {
+ beforeEach(() => setLanguage('en'))
+
+ it('English: one and other', () => {
+ expect(t('count.files', { count: 1 })).toBe('1 file')
+ expect(t('count.files', { count: 3 })).toBe('3 files')
+ expect(t('count.moreFiles', { count: 1 })).toBe('+1 more file')
+ })
+
+ it('Russian picks one / few / many', () => {
+ setLanguage('ru')
+ const forms = TRANSLATIONS.ru.count.files as unknown as Record<string, string>
+ expect(t('count.files', { count: 1 })).toBe(forms.one.replace('{count}', '1'))
+ expect(t('count.files', { count: 3 })).toBe(forms.few.replace('{count}', '3'))
+ expect(t('count.files', { count: 5 })).toBe(forms.many.replace('{count}', '5'))
+ expect(t('count.files', { count: 21 })).toBe(forms.one.replace('{count}', '21'))
+ })
+
+ it('Arabic picks zero / two / many', () => {
+ setLanguage('ar')
+ const forms = TRANSLATIONS.ar.count.images as unknown as Record<string, string>
+ expect(t('count.images', { count: 0 })).toBe(forms.zero.replace('{count}', '0'))
+ expect(t('count.images', { count: 2 })).toBe(forms.two.replace('{count}', '2'))
+ expect(t('count.images', { count: 11 })).toBe(forms.many.replace('{count}', '11'))
+ })
+})
+
+describe('the onboarding demo works in every language', () => {
+ it.each(Object.keys(TRANSLATIONS))('%s: searching the demo word finds only the noted card', (code) => {
+ setLanguage(code)
+ const words = queryWords(demoQuery())
+ expect(words.length, `${code} query is one word`).toBe(1)
+ const now = Date.now()
+ const items = [demoPdf(now, demoNote()), demoStackWithPhoto(now), demoLink(now), demoText(now)]
+ expect(items.filter((it) => matches(it, words)).map((it) => it.id), code).toEqual(['demo-pdf'])
+ })
+
+ it.each(Object.keys(TRANSLATIONS))('%s: the page sentence has three lines, demo file names are legal', (code) => {
+ setLanguage(code)
+ const lines = pageLines()
+ expect(lines).toHaveLength(3)
+ expect(new Set(lines).size).toBe(3)
+ for (const k of ['fileItinerary', 'fileSlides', 'fileBudget', 'fileChecklist', 'filePacking', 'filePhotos', 'filePhoto'] as const) {
+ expect(TRANSLATIONS[code].tour[k], `${code} tour.${k}`).not.toMatch(/[\\/:*?"<>|]/)
+ }
+ })
+})
+
+describe('names of files the app writes', () => {
+ it.each(Object.keys(TRANSLATIONS))('%s: Windows-legal, with the time stamp', (code) => {
+ const f = TRANSLATIONS[code].files
+ for (const v of [f.screenshotName, f.imageName, f.image, f.snippet]) expect(v, code).not.toMatch(/[\\/:*?"<>|]/)
+ expect(f.screenshotName).toContain('{stamp}')
+ expect(f.imageName).toContain('{stamp}')
+ expect(f.snippet, code).not.toMatch(/\s/)
+ })
+})
+
+describe('words built in code are in the language', () => {
+ beforeEach(() => setLanguage('en'))
+
+ it('link card words: generic words translated, site names kept', () => {
+ const gh = parseUrlPreview('https://github.com/Deepender25/Edge-Drop/issues/71')
+ expect(localizeLinkInfo(gh).subtitle).toBe('Issue')
+ setLanguage('de')
+ const de = localizeLinkInfo(gh)
+ expect(de.serviceName).toBe('GitHub')
+ expect(de.subtitle).toBe(TRANSLATIONS.de.link.issue)
+ const local = localizeLinkInfo(parseUrlPreview('http://localhost:3000/app'))
+ expect(local.serviceName).toBe(TRANSLATIONS.de.link.thisComputer)
+ expect(local.subtitle).toBe(TRANSLATIONS.de.link.port.replace('{port}', '3000'))
+ const yt = localizeLinkInfo(parseUrlPreview('https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=65'))
+ expect(yt.title).toBe(TRANSLATIONS.de.link.startsAt.replace('{time}', '1:05'))
+ })
+
+ it('sizes: English as before, other languages with their unit and decimal mark', () => {
+ expect(formatBytes(500)).toBe('500 B')
+ expect(formatBytes(412_000)).toBe('402.3 KB')
+ expect(formatBytes(2_318_400)).toBe('2.2 MB')
+ setLanguage('fr')
+ expect(formatBytes(412_000)).toBe(TRANSLATIONS.fr.units.kb.replace('{n}', '402,3'))
+ })
+
+ it('kind badges: English as before', () => {
+ expect(kindBadge('pdf')).toBe('pdf')
+ expect(kindBadge('powerpoint')).toBe('slides')
+ expect(kindBadge('executable')).toBe('installer')
+ expect(t('badge.links')).toBe('links')
+ expect(t('badge.image')).toBe('image')
+ })
+
+ it('language picker: English as before; other interfaces name languages in their own words', () => {
+ const de = LANGUAGES.find((l) => l.code === 'de')!
+ const system = LANGUAGES.find((l) => l.code === 'system')!
+ expect(languageLabel(de, 'en')).toBe('Deutsch (German)')
+ expect(languageLabel(system, 'en')).toBe(en.behaviour.systemDefault)
+ setLanguage('fr')
+ expect(languageLabel(de, 'fr')).toBe('Deutsch (allemand)')
+ expect(languageLabel(system, 'fr')).toBe(TRANSLATIONS.fr.behaviour.systemDefault)
+ // the interface's own language is not named twice
+ expect(languageLabel(LANGUAGES.find((l) => l.code === 'fr')!, 'fr')).toBe('Français')
+ })
+})