@lincyaw/host 1.0.0-rc.15 → 1.0.0-rc.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -3
- package/src/contracts.ts +2 -0
- package/src/step-clock.ts +12 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lincyaw/host",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.18",
|
|
4
4
|
"description": "Presmium's host interface for plugin components in every form: step state, services, interface text, and the design system (tokens, components, fonts)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"src"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
+
"@fontsource-variable/hanken-grotesk": "5.3.0",
|
|
36
37
|
"@fontsource/ibm-plex-mono": "5.3.0",
|
|
37
38
|
"@fontsource/ibm-plex-sans": "5.3.0",
|
|
38
39
|
"@fontsource/source-serif-4": "5.3.1",
|
|
@@ -44,8 +45,8 @@
|
|
|
44
45
|
"@radix-ui/react-tooltip": "^1.2.8",
|
|
45
46
|
"react": "18.3.1",
|
|
46
47
|
"react-dom": "18.3.1",
|
|
47
|
-
"@lincyaw/
|
|
48
|
-
"@lincyaw/
|
|
48
|
+
"@lincyaw/design": "1.0.0-rc.18",
|
|
49
|
+
"@lincyaw/kernel": "1.0.0-rc.18"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
52
|
"@types/react": "18.3.28",
|
package/src/contracts.ts
CHANGED
|
@@ -156,6 +156,8 @@ export const PAGE_READINESS = defineService<PageReadiness>('presmium.pageReadine
|
|
|
156
156
|
export interface StepClockDriver {
|
|
157
157
|
readonly elapsed: Store<number | undefined>
|
|
158
158
|
readonly recording?: boolean
|
|
159
|
+
/** Holds the clock until it is released (a capture of the page): other drivers wait until then. */
|
|
160
|
+
readonly exclusive?: boolean
|
|
159
161
|
}
|
|
160
162
|
|
|
161
163
|
export interface StepClock {
|
package/src/step-clock.ts
CHANGED
|
@@ -22,16 +22,24 @@ export function createStepClock(navigation: Navigation): { clock: StepClock, sto
|
|
|
22
22
|
const rethrow = () => { const failed = failure; failure = undefined; if (failed) throw failed.error }
|
|
23
23
|
const stop = observe(navigation.position, position => { const before = change.getSnapshot(); if (before && before.slide === position.slide && before.step === position.step) return; change.set({ slide: position.slide, step: position.step, at: clockNow(), forward: isForward(position, before) }); ensureTicking() }, true)
|
|
24
24
|
let unfollow: Unsubscribe | undefined
|
|
25
|
+
// A driver that comes while an exclusive one holds the clock waits for it, the latest one only.
|
|
26
|
+
let waiting: StepClockDriver | undefined
|
|
27
|
+
const activate = (next: StepClockDriver) => { unfollow?.(); driver.set(next); unfollow = observe(next.elapsed, (now, before) => { if (now === undefined && before !== undefined) handOff(before) }) }
|
|
25
28
|
const clock: StepClock = {
|
|
26
29
|
drive(next) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return () => {
|
|
30
|
+
if (driver.getSnapshot()?.exclusive && !next.exclusive) waiting = next
|
|
31
|
+
else activate(next)
|
|
32
|
+
return () => {
|
|
33
|
+
if (waiting === next) { waiting = undefined; return }
|
|
34
|
+
if (driver.getSnapshot() !== next) return
|
|
35
|
+
const last = next.elapsed.getSnapshot(); unfollow?.(); unfollow = undefined; driver.set(undefined)
|
|
36
|
+
if (waiting) { const held = waiting; waiting = undefined; activate(held) } else if (last !== undefined) handOff(last)
|
|
37
|
+
}
|
|
30
38
|
},
|
|
31
39
|
wait(work) { if (!stopped) pending.add(work); void work.catch(error => { if (!stopped) failure ??= { error } }).finally(() => pending.delete(work)) },
|
|
32
40
|
async settled() { let waited = false; for (let round = 0; round < 100; round++) { if (stopped) return; if (!pending.size) { if (waited) { waited = false; await nextFrame() } if (!pending.size) return rethrow() } await Promise.allSettled([...pending]); waited = true } throw new Error('the page kept preparing its picture: settled() stopped waiting after 100 rounds') },
|
|
33
41
|
}
|
|
34
|
-
return { clock, stop() { if (stopped) return; stopped = true; stop(); unfollow?.(); driver.set(undefined); change.set(undefined); pending.clear(); failure = undefined } }
|
|
42
|
+
return { clock, stop() { if (stopped) return; stopped = true; stop(); unfollow?.(); waiting = undefined; driver.set(undefined); change.set(undefined); pending.clear(); failure = undefined } }
|
|
35
43
|
}
|
|
36
44
|
export interface StepTimeOptions { until?: number }
|
|
37
45
|
const settle = (time: number, until: number | undefined) => until !== undefined && time >= until ? Infinity : Math.max(0, time)
|