@lincyaw/host 1.0.0-rc.15 → 1.0.0-rc.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lincyaw/host",
3
- "version": "1.0.0-rc.15",
3
+ "version": "1.0.0-rc.16",
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": {
@@ -44,8 +44,8 @@
44
44
  "@radix-ui/react-tooltip": "^1.2.8",
45
45
  "react": "18.3.1",
46
46
  "react-dom": "18.3.1",
47
- "@lincyaw/kernel": "1.0.0-rc.15",
48
- "@lincyaw/design": "1.0.0-rc.15"
47
+ "@lincyaw/kernel": "1.0.0-rc.16",
48
+ "@lincyaw/design": "1.0.0-rc.16"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@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
- unfollow?.(); driver.set(next)
28
- unfollow = observe(next.elapsed, (now, before) => { if (now === undefined && before !== undefined) handOff(before) })
29
- return () => { if (driver.getSnapshot() !== next) return; const last = next.elapsed.getSnapshot(); unfollow?.(); unfollow = undefined; driver.set(undefined); if (last !== undefined) handOff(last) }
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)