@lincyaw/kernel 0.0.0-stage → 1.0.0-rc.1

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.
Files changed (128) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +32 -2
  3. package/package.json +41 -3
  4. package/src/access.ts +18 -0
  5. package/src/anchors.ts +58 -0
  6. package/src/authoring.ts +56 -0
  7. package/src/blocks.ts +19 -0
  8. package/src/checks.ts +35 -0
  9. package/src/component-code.ts +6 -0
  10. package/src/contracts/agent.ts +76 -0
  11. package/src/contracts/anchors.ts +46 -0
  12. package/src/contracts/authoring-actions.ts +60 -0
  13. package/src/contracts/authoring-clients.ts +213 -0
  14. package/src/contracts/authoring.ts +180 -0
  15. package/src/contracts/checks.ts +29 -0
  16. package/src/contracts/classroom.ts +49 -0
  17. package/src/contracts/diagnostics.ts +37 -0
  18. package/src/contracts/document-audio.ts +150 -0
  19. package/src/contracts/document-comments.ts +31 -0
  20. package/src/contracts/document-history.ts +63 -0
  21. package/src/contracts/document-image.ts +32 -0
  22. package/src/contracts/document-reads.ts +57 -0
  23. package/src/contracts/document-voice.ts +44 -0
  24. package/src/contracts/document.ts +240 -0
  25. package/src/contracts/execution.ts +118 -0
  26. package/src/contracts/locale.ts +3 -0
  27. package/src/contracts/offline.ts +2 -0
  28. package/src/contracts/operations.ts +8 -0
  29. package/src/contracts/plugin.ts +183 -0
  30. package/src/contracts/presenter-panels.ts +17 -0
  31. package/src/contracts/preview.ts +386 -0
  32. package/src/contracts/production-assets.ts +61 -0
  33. package/src/contracts/production.ts +109 -0
  34. package/src/contracts/projects.ts +59 -0
  35. package/src/contracts/server.ts +108 -0
  36. package/src/contracts/service.ts +8 -0
  37. package/src/contracts/speech-settings.ts +16 -0
  38. package/src/contracts/speech.ts +149 -0
  39. package/src/contracts/steps.ts +15 -0
  40. package/src/contracts/transcription-adoption.ts +79 -0
  41. package/src/contracts/transcription.ts +112 -0
  42. package/src/contracts/voice.ts +97 -0
  43. package/src/contracts/voiceover-execution.ts +68 -0
  44. package/src/contracts/workspace.ts +458 -0
  45. package/src/contracts.ts +35 -0
  46. package/src/diagnostics.ts +7 -0
  47. package/src/document-authoring-actions.ts +47 -0
  48. package/src/document-caption-timings.ts +64 -0
  49. package/src/document-colors.ts +25 -0
  50. package/src/document-comments.ts +118 -0
  51. package/src/document-components.ts +251 -0
  52. package/src/document-operations.ts +132 -0
  53. package/src/document-pages.ts +215 -0
  54. package/src/document-reads.ts +81 -0
  55. package/src/document-schema.ts +85 -0
  56. package/src/document-voices.ts +153 -0
  57. package/src/document.ts +252 -0
  58. package/src/durations.ts +7 -0
  59. package/src/errors.ts +15 -0
  60. package/src/events.ts +32 -0
  61. package/src/execution.ts +25 -0
  62. package/src/fingerprint.ts +31 -0
  63. package/src/follow.ts +33 -0
  64. package/src/git.ts +12 -0
  65. package/src/html.ts +41 -0
  66. package/src/index.ts +82 -0
  67. package/src/ir.ts +367 -0
  68. package/src/jupyter-kernel.ts +9 -0
  69. package/src/kernel.ts +190 -0
  70. package/src/keyboard.ts +43 -0
  71. package/src/locale.ts +13 -0
  72. package/src/lock.ts +81 -0
  73. package/src/logging.ts +11 -0
  74. package/src/lower-myst.ts +312 -0
  75. package/src/node/assets.ts +23 -0
  76. package/src/node/authoring-actions.ts +50 -0
  77. package/src/node/authoring-clients.ts +14 -0
  78. package/src/node/document-audio.ts +22 -0
  79. package/src/node/document-history.ts +11 -0
  80. package/src/node/document-image.ts +8 -0
  81. package/src/node/document-reads.ts +10 -0
  82. package/src/node/document-voice.ts +7 -0
  83. package/src/node/ffmpeg.ts +29 -0
  84. package/src/node/file-version.ts +6 -0
  85. package/src/node/fonts.ts +22 -0
  86. package/src/node/index.ts +29 -0
  87. package/src/node/installed-packages.ts +11 -0
  88. package/src/node/lines.ts +24 -0
  89. package/src/node/locale.ts +7 -0
  90. package/src/node/network.ts +11 -0
  91. package/src/node/operator-speech.ts +91 -0
  92. package/src/node/packages.ts +74 -0
  93. package/src/node/paths.ts +7 -0
  94. package/src/node/projects.ts +7 -0
  95. package/src/node/resources.ts +86 -0
  96. package/src/node/revision.ts +6 -0
  97. package/src/node/run-directory.ts +70 -0
  98. package/src/node/strip-types.mjs +15 -0
  99. package/src/node/transcription-adoption.ts +9 -0
  100. package/src/node/transcription.ts +10 -0
  101. package/src/node/voiceover-routes.ts +73 -0
  102. package/src/node/voiceover.ts +199 -0
  103. package/src/page-source.ts +359 -0
  104. package/src/parameters.ts +81 -0
  105. package/src/preview-edit.ts +18 -0
  106. package/src/preview-events.ts +57 -0
  107. package/src/preview-frame.ts +1220 -0
  108. package/src/props.ts +17 -0
  109. package/src/published.ts +11 -0
  110. package/src/push-stream.ts +67 -0
  111. package/src/reading.ts +96 -0
  112. package/src/recording.ts +38 -0
  113. package/src/renderer-components.ts +30 -0
  114. package/src/requests.ts +28 -0
  115. package/src/responses.ts +49 -0
  116. package/src/run-outputs.ts +15 -0
  117. package/src/runner.py +454 -0
  118. package/src/services.ts +146 -0
  119. package/src/slides.ts +36 -0
  120. package/src/speech-words.ts +76 -0
  121. package/src/speech.ts +13 -0
  122. package/src/step-keys.ts +38 -0
  123. package/src/steps.ts +7 -0
  124. package/src/transcription-adoption.ts +105 -0
  125. package/src/uri-decoding.ts +8 -0
  126. package/src/urls.ts +13 -0
  127. package/src/views.ts +47 -0
  128. package/src/voice.ts +86 -0
@@ -0,0 +1,18 @@
1
+ import { irBlocks } from './blocks.ts'
2
+ import { fnv1a64 } from './fingerprint.ts'
3
+ import type { IRDocument } from './ir.ts'
4
+ import type { PreviewAnchor } from './contracts/preview.ts'
5
+
6
+ /** A native text draft follows its IR target, independently from unrelated source-line shifts. */
7
+ export function previewEditBinding(doc: IRDocument, target: PreviewAnchor): string | undefined {
8
+ const section = doc.sections.find(section => section.id === target.section)
9
+ if (!section) return undefined
10
+ if (!target.block) return fnv1a64(JSON.stringify({
11
+ section: section.id, file: section.source.file, title: section.title,
12
+ depth: section.depth, audience: section.audience,
13
+ }))
14
+ const block = [...irBlocks(section.blocks)].find(block => block.id === target.block)
15
+ if (!block || block.node.type !== 'markdown') return undefined
16
+ const { source, ...meaning } = block
17
+ return fnv1a64(JSON.stringify([section.id, source.file, meaning], (key, value) => key === 'position' ? undefined : value))
18
+ }
@@ -0,0 +1,57 @@
1
+ import { PREVIEW_EVENTS_PARAM, previewEnvelope } from './contracts/preview.ts'
2
+ import type { PreviewCommand, PreviewEventSubscription, PreviewEventTarget, PreviewEventMessage } from './contracts/preview.ts'
3
+ import { previewNonce } from './preview-frame.ts'
4
+
5
+ /** Uses the existing preview-ready handshake, origin fence and nonce; never opens a network connection. */
6
+ export interface PreviewEvents {
7
+ connection: string
8
+ subscribe: PreviewEventSubscription
9
+ receive(command: Extract<PreviewCommand, { type: 'events-ready' | 'events-message' }>): void
10
+ stop(): void
11
+ }
12
+
13
+ export function createPreviewEvents(origins: readonly string[], document: string): PreviewEvents | undefined {
14
+ if (typeof window === 'undefined' || window.parent === window || !origins.length || new URL(location.href).searchParams.get(PREVIEW_EVENTS_PARAM) !== 'shared') return
15
+ const nonce = previewNonce()
16
+ if (!nonce) return
17
+ const connection = crypto.randomUUID()
18
+ const readers = new Map<string, { target: PreviewEventTarget, received(message: PreviewEventMessage): void }>()
19
+ let ready = false, stopped = false, parked = false
20
+ const post = (message: Parameters<typeof previewEnvelope>[1]) => {
21
+ if (!stopped) for (const origin of origins) window.parent.postMessage(previewEnvelope(nonce, message), origin)
22
+ }
23
+ const subscribe = (id: string, target: PreviewEventTarget) => post({ type: 'events-subscribe', connection, id, target })
24
+ const park = () => {
25
+ parked = true
26
+ for (const id of readers.keys()) post({ type: 'events-unsubscribe', connection, id })
27
+ }
28
+ const resume = () => {
29
+ parked = false
30
+ if (ready) for (const [id, reader] of readers) subscribe(id, reader.target)
31
+ }
32
+ window.addEventListener('pagehide', park)
33
+ window.addEventListener('pageshow', resume)
34
+ return {
35
+ connection,
36
+ subscribe(target, received) {
37
+ if (stopped || target.document !== document) return () => {}
38
+ const id = crypto.randomUUID()
39
+ readers.set(id, { target, received })
40
+ if (ready && !parked) subscribe(id, target)
41
+ return () => { if (readers.delete(id)) post({ type: 'events-unsubscribe', connection, id }) }
42
+ },
43
+ receive(command) {
44
+ if (stopped || command.connection !== connection) return
45
+ if (command.type === 'events-ready') {
46
+ if (ready) return
47
+ ready = true
48
+ if (!parked) for (const [id, reader] of readers) subscribe(id, reader.target)
49
+ } else if (!parked) readers.get(command.id)?.received(command.message)
50
+ },
51
+ stop() {
52
+ park(); readers.clear(); stopped = true
53
+ window.removeEventListener('pagehide', park)
54
+ window.removeEventListener('pageshow', resume)
55
+ },
56
+ }
57
+ }