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

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.25",
3
+ "version": "1.0.0-rc.27",
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": {
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './contracts.ts'
2
+ export { randomUUID } from './random-uuid.ts'
2
3
  export { applyDocumentOperations } from './document-operations.ts'
3
4
  export { validateDocumentChange, DOCUMENT_CHANGE_JSON_SCHEMA } from './authoring.ts'
4
5
  export { allocateDocumentPage, createDocumentPage, documentPageDefaults, DOCUMENT_PAGE_DEFAULT_TIMING, duplicateDocumentPage, moveDocumentPage, pageContents, pageDeletion, pageDeletionImpact, removeDocumentPage, renameDocumentPage } from './document-pages.ts'
@@ -1,6 +1,7 @@
1
1
  import { PREVIEW_EVENTS_PARAM, previewEnvelope } from './contracts/preview.ts'
2
2
  import type { PreviewCommand, PreviewEventSubscription, PreviewEventTarget, PreviewEventMessage } from './contracts/preview.ts'
3
3
  import { parentOrigins, previewNonce } from './preview-frame.ts'
4
+ import { randomUUID } from './random-uuid.ts'
4
5
 
5
6
  /** Uses the existing preview-ready handshake, origin fence and nonce; never opens a network connection. */
6
7
  export interface PreviewEvents {
@@ -14,7 +15,7 @@ export function createPreviewEvents(origins: readonly string[], document: string
14
15
  if (typeof window === 'undefined' || window.parent === window || !origins.length || new URL(location.href).searchParams.get(PREVIEW_EVENTS_PARAM) !== 'shared') return
15
16
  const nonce = previewNonce()
16
17
  if (!nonce) return
17
- const connection = crypto.randomUUID()
18
+ const connection = randomUUID()
18
19
  const readers = new Map<string, { target: PreviewEventTarget, received(message: PreviewEventMessage): void }>()
19
20
  let ready = false, stopped = false, parked = false
20
21
  const targets = parentOrigins(origins)
@@ -36,7 +37,7 @@ export function createPreviewEvents(origins: readonly string[], document: string
36
37
  connection,
37
38
  subscribe(target, received) {
38
39
  if (stopped || target.document !== document) return () => {}
39
- const id = crypto.randomUUID()
40
+ const id = randomUUID()
40
41
  readers.set(id, { target, received })
41
42
  if (ready && !parked) subscribe(id, target)
42
43
  return () => { if (readers.delete(id)) post({ type: 'events-unsubscribe', connection, id }) }
@@ -0,0 +1,8 @@
1
+ /** Random v4 UUID from crypto.getRandomValues, which browsers expose outside secure contexts. */
2
+ export function randomUUID(): string {
3
+ const bytes = crypto.getRandomValues(new Uint8Array(16))
4
+ bytes[6] = bytes[6]! & 0x0f | 0x40
5
+ bytes[8] = bytes[8]! & 0x3f | 0x80
6
+ const hex = Array.from(bytes, byte => byte.toString(16).padStart(2, '0')).join('')
7
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`
8
+ }