@lincyaw/kernel 1.0.0-rc.23 → 1.0.0-rc.25

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/kernel",
3
- "version": "1.0.0-rc.23",
3
+ "version": "1.0.0-rc.25",
4
4
  "description": "Presmium's shared kernel: the IR and plugin contracts, the service registry, anchors and checks",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -204,8 +204,6 @@ export type PreviewReport =
204
204
  | { type: 'selection', selection: (PreviewAnchor & { text: string, rect?: PreviewRect, obstacles?: PreviewRect[] }) | null }
205
205
  /** Where the picked block or the selection is after the page scrolled or resized; null when it is out of sight. */
206
206
  | { type: 'rect', rect: PreviewRect | null, obstacles?: PreviewRect[] }
207
- /** Where the blocks the AI changed are in the preview's viewport while they blink, and again as the page scrolls (at most 16). */
208
- | { type: 'flashed', rects: PreviewRect[] }
209
207
  | { type: 'editing', target: PreviewAnchor, active: boolean }
210
208
  /** The text of a block edited in place, before and after (its `textContent`); sent only when it changed. */
211
209
  | { type: 'edited', target: PreviewAnchor, before: string, after: string, request?: number, revision?: string, binding?: string }
@@ -374,7 +372,6 @@ export function toPreviewReport(data: unknown, nonce: string): PreviewReport | u
374
372
  ? { type: 'selection', selection: { ...toAnchor(selected), text: selected.text, ...selected.rect ? { rect: toRect(selected.rect as PreviewRect) } : {}, ...selected.obstacles !== undefined ? { obstacles: (selected.obstacles as PreviewRect[]).map(toRect) } : {} } }
375
373
  : undefined
376
374
  }
377
- case 'flashed': return Array.isArray(m.rects) && m.rects.length <= 16 && m.rects.every(rect) ? { type: 'flashed', rects: (m.rects as PreviewRect[]).map(toRect) } : undefined
378
375
  case 'rect': return (m.rect === null || rect(m.rect)) && optional(m.obstacles, obstacles) ? { type: 'rect', rect: m.rect === null ? null : toRect(m.rect), ...m.obstacles !== undefined ? { obstacles: (m.obstacles as PreviewRect[]).map(toRect) } : {} } : undefined
379
376
  case 'editing': return anchor(m.target) && typeof m.active === 'boolean' ? { type: 'editing', target: toAnchor(m.target), active: m.active } : undefined
380
377
  case 'edited': return anchor(m.target) && text(m.before) && text(m.after) && m.before.length <= MAX_EDITED && m.after.length <= MAX_EDITED && editedRequest(m) ? { type: 'edited', target: toAnchor(m.target), before: m.before, after: m.after, ...m.request === undefined ? {} : { request: m.request as number, revision: m.revision as string, binding: m.binding as string } } : undefined
@@ -20,8 +20,6 @@ const PIN_LABELS = 'data-preview-pin-labels'
20
20
  const FLASH = 'data-preview-flash'
21
21
  // Three blinks of 0.8 s, the length of the animation below.
22
22
  const FLASH_MS = 2400
23
- /** How long the changed blocks' boxes keep being reported after they blink. */
24
- const TRAIL_MS = 15000
25
23
  const PIN_CLASS = 'pm-preview-pin'
26
24
  const CONTROLS = 'a, button, input, select, textarea, label, summary, [role="dialog"], [role="menu"], [role="menuitem"], [role="listbox"], [role="option"]'
27
25
  const HEADINGS = 'h1, h2, h3, h4, h5, h6'
@@ -222,22 +220,10 @@ function createHighlight(page: PreviewPage, state: FrameState, locate: Locator)
222
220
  * Makes the blocks the workbench names blink (a steady tint when the reader asks for less motion), after bringing the first
223
221
  * into view; retries while the page brings it there, as the highlight does.
224
222
  */
225
- function createFlash(page: PreviewPage, state: FrameState, locate: Locator, post: (message: PreviewReport) => void) {
223
+ function createFlash(page: PreviewPage, state: FrameState, locate: Locator) {
226
224
  let ending: ReturnType<typeof setTimeout> | undefined
227
225
  let retrying: ReturnType<typeof setTimeout> | undefined
228
226
  let frame = 0
229
- // The changed blocks' boxes go to the workbench while they blink and for a while after, as the page scrolls, so its
230
- // kitten can walk to them.
231
- let trail: HTMLElement[] = [], trailUntil = 0, trailFrame = 0
232
- const reportTrail = () => {
233
- trailFrame = 0
234
- if (!isLive(state) || Date.now() > trailUntil) return
235
- const rects = trail.filter(element => element.isConnected).slice(0, 16).map(element => toRect(element.getBoundingClientRect()))
236
- post({ type: 'flashed', rects })
237
- }
238
- const trailMoved = () => { if (!trailFrame && Date.now() <= trailUntil) trailFrame = requestAnimationFrame(reportTrail) }
239
- window.addEventListener('scroll', trailMoved, { capture: true, passive: true })
240
- window.addEventListener('resize', trailMoved, { passive: true })
241
227
  const clear = () => {
242
228
  clearTimeout(ending)
243
229
  cancelAnimationFrame(frame)
@@ -254,8 +240,6 @@ function createFlash(page: PreviewPage, state: FrameState, locate: Locator, post
254
240
  frame = requestAnimationFrame(() => {
255
241
  for (const element of elements) element.setAttribute(FLASH, '')
256
242
  ending = setTimeout(clear, FLASH_MS)
257
- trail = elements; trailUntil = Date.now() + TRAIL_MS
258
- reportTrail()
259
243
  })
260
244
  return true
261
245
  }
@@ -272,13 +256,10 @@ function createFlash(page: PreviewPage, state: FrameState, locate: Locator, post
272
256
  }
273
257
  retrying = setTimeout(retry, 50)
274
258
  },
275
- cancel() {
276
- clearTimeout(retrying)
277
- clear()
278
- trailUntil = 0
279
- cancelAnimationFrame(trailFrame)
280
- trailFrame = 0
281
- },
259
+ cancel() {
260
+ clearTimeout(retrying)
261
+ clear()
262
+ },
282
263
  }
283
264
  }
284
265
 
@@ -937,7 +918,7 @@ export function connectPreviewFrame(page: PreviewPage): PreviewFrame | undefined
937
918
  const locate = createLocator(page)
938
919
  const highlight = createHighlight(page, state, locate)
939
920
  const pins = createPins(locate)
940
- const flash = createFlash(page, state, locate, post)
921
+ const flash = createFlash(page, state, locate)
941
922
  const rects = createRectReport(page, state, locate, post)
942
923
  const picking = createPicking(page, state, locate, rects, post)
943
924
  const editing = createEditing(page, state, locate, picking, post)