@bubo-squared/gyroview 0.1.0

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 (228) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/LICENSE +21 -0
  3. package/README.md +216 -0
  4. package/dist/define.d.ts +3 -0
  5. package/dist/define.js +4 -0
  6. package/dist/index.d.ts +959 -0
  7. package/dist/index.js +13 -0
  8. package/dist/packages/adapters/blob/src/BlobRandomAccessSource.js +37 -0
  9. package/dist/packages/adapters/blob/src/index.js +2 -0
  10. package/dist/packages/adapters/fetch/src/HttpRangeSource.js +194 -0
  11. package/dist/packages/adapters/fetch/src/HttpResourceLocator.js +35 -0
  12. package/dist/packages/adapters/fetch/src/httpRequest.js +126 -0
  13. package/dist/packages/adapters/fetch/src/index.js +3 -0
  14. package/dist/packages/adapters/mediabunny/src/MediabunnyAudioSegments.js +133 -0
  15. package/dist/packages/adapters/mediabunny/src/MediabunnyDemuxer.js +63 -0
  16. package/dist/packages/adapters/mediabunny/src/MediabunnyVideoTrackReader.js +84 -0
  17. package/dist/packages/adapters/mediabunny/src/SegmentChannel.js +84 -0
  18. package/dist/packages/adapters/mediabunny/src/bufferSources.js +12 -0
  19. package/dist/packages/adapters/mediabunny/src/index.js +2 -0
  20. package/dist/packages/adapters/mse-audio/src/MediaSourceAudioClock.js +139 -0
  21. package/dist/packages/adapters/mse-audio/src/SourceBufferFeeder.js +174 -0
  22. package/dist/packages/adapters/mse-audio/src/events.js +26 -0
  23. package/dist/packages/adapters/mse-audio/src/index.js +2 -0
  24. package/dist/packages/adapters/mse-audio/src/mediaSourceSupport.js +82 -0
  25. package/dist/packages/adapters/three/src/ThreeFrameRenderer.js +274 -0
  26. package/dist/packages/adapters/three/src/compileAndProve.js +14 -0
  27. package/dist/packages/adapters/three/src/fullscreenPass.js +52 -0
  28. package/dist/packages/adapters/three/src/index.js +2 -0
  29. package/dist/packages/adapters/three/src/lensTextures.js +25 -0
  30. package/dist/packages/adapters/three/src/pictureMaterials.js +44 -0
  31. package/dist/packages/adapters/three/src/renderInto.js +15 -0
  32. package/dist/packages/adapters/three/src/rendererUniforms.js +157 -0
  33. package/dist/packages/adapters/three/src/samplingStrategies.js +26 -0
  34. package/dist/packages/adapters/three/src/seamMeter/SeamMeterPass.js +79 -0
  35. package/dist/packages/adapters/three/src/seamMeter/rowMeans.js +38 -0
  36. package/dist/packages/adapters/three/src/shaderPrograms.js +66 -0
  37. package/dist/packages/adapters/three/src/shaders/analysis.frag.js +4 -0
  38. package/dist/packages/adapters/three/src/shaders/equirectangularRays.js +4 -0
  39. package/dist/packages/adapters/three/src/shaders/fixedJoin.js +4 -0
  40. package/dist/packages/adapters/three/src/shaders/fullscreen.vert.js +4 -0
  41. package/dist/packages/adapters/three/src/shaders/header.js +4 -0
  42. package/dist/packages/adapters/three/src/shaders/lensModels.js +4 -0
  43. package/dist/packages/adapters/three/src/shaders/lensSampling.js +4 -0
  44. package/dist/packages/adapters/three/src/shaders/lensTextures.js +4 -0
  45. package/dist/packages/adapters/three/src/shaders/rawLenses.frag.js +4 -0
  46. package/dist/packages/adapters/three/src/shaders/rectilinearRays.js +4 -0
  47. package/dist/packages/adapters/three/src/shaders/screenAreas.js +4 -0
  48. package/dist/packages/adapters/three/src/shaders/stitch.frag.js +4 -0
  49. package/dist/packages/adapters/three/src/webglRenderer.js +37 -0
  50. package/dist/packages/adapters/webcodecs/src/WebCodecsVideoDecoderPort.js +135 -0
  51. package/dist/packages/adapters/webcodecs/src/index.js +2 -0
  52. package/dist/packages/core/src/application/gainMatching/GainMatching.js +66 -0
  53. package/dist/packages/core/src/application/gainMatching/GainMatchingFrameSink.js +62 -0
  54. package/dist/packages/core/src/application/playback/ClockWatch.js +76 -0
  55. package/dist/packages/core/src/application/playback/DecodePipeline.js +188 -0
  56. package/dist/packages/core/src/application/playback/DecodeRun.js +93 -0
  57. package/dist/packages/core/src/application/playback/FramePairQueue.js +93 -0
  58. package/dist/packages/core/src/application/playback/FramePairer.js +60 -0
  59. package/dist/packages/core/src/application/playback/PlaybackSession.js +417 -0
  60. package/dist/packages/core/src/application/playback/SeekOrder.js +36 -0
  61. package/dist/packages/core/src/application/playback/SessionLifecycle.js +42 -0
  62. package/dist/packages/core/src/application/playback/StartGate.js +55 -0
  63. package/dist/packages/core/src/application/playback/TimeUpdates.js +31 -0
  64. package/dist/packages/core/src/application/playback/WallClock.js +46 -0
  65. package/dist/packages/core/src/application/playback/keyframeTimeAt.js +15 -0
  66. package/dist/packages/core/src/application/playback/probeDecoding.js +168 -0
  67. package/dist/packages/core/src/application/recording/frameTimesOf.js +22 -0
  68. package/dist/packages/core/src/application/recording/inspectLayout.js +21 -0
  69. package/dist/packages/core/src/application/recording/inspectRecording.js +124 -0
  70. package/dist/packages/core/src/application/recording/locateOtherLensFile.js +18 -0
  71. package/dist/packages/core/src/application/recording/motionOf.js +39 -0
  72. package/dist/packages/core/src/application/recording/readRecording.js +31 -0
  73. package/dist/packages/core/src/application/recording/timeRecording.js +57 -0
  74. package/dist/packages/core/src/application/stabilization/StabilizingFrameSink.js +31 -0
  75. package/dist/packages/core/src/domain/format/boxes/BoxLayout.js +7 -0
  76. package/dist/packages/core/src/domain/format/boxes/boxConstants.js +16 -0
  77. package/dist/packages/core/src/domain/format/boxes/scanBoxes.js +59 -0
  78. package/dist/packages/core/src/domain/format/calibration/CalibrationVersion.js +13 -0
  79. package/dist/packages/core/src/domain/format/calibration/layouts/CalibrationStringLayout.js +34 -0
  80. package/dist/packages/core/src/domain/format/calibration/layouts/LegacyCalibrationLayout.js +44 -0
  81. package/dist/packages/core/src/domain/format/calibration/layouts/MeiCalibrationLayout.js +45 -0
  82. package/dist/packages/core/src/domain/format/calibration/layouts/PolynomialCalibrationLayout.js +44 -0
  83. package/dist/packages/core/src/domain/format/calibration/offsetTokens.js +65 -0
  84. package/dist/packages/core/src/domain/format/calibration/parseOffsetString.js +52 -0
  85. package/dist/packages/core/src/domain/format/calibration/selectCalibration.js +46 -0
  86. package/dist/packages/core/src/domain/format/captureOrigin.js +20 -0
  87. package/dist/packages/core/src/domain/format/constants.js +33 -0
  88. package/dist/packages/core/src/domain/format/info/infoFields.js +110 -0
  89. package/dist/packages/core/src/domain/format/info/parseInfoRecord.js +90 -0
  90. package/dist/packages/core/src/domain/format/info/readInfoRecord.js +14 -0
  91. package/dist/packages/core/src/domain/format/layout/detectLensLayout.js +122 -0
  92. package/dist/packages/core/src/domain/format/naming/RecordingFileName.js +67 -0
  93. package/dist/packages/core/src/domain/format/records/TrailerRecords.js +83 -0
  94. package/dist/packages/core/src/domain/format/records/exposure/parseExposureRecord.js +48 -0
  95. package/dist/packages/core/src/domain/format/records/gyro/FloatGyroSampleLayout.js +39 -0
  96. package/dist/packages/core/src/domain/format/records/gyro/RawGyroSampleLayout.js +55 -0
  97. package/dist/packages/core/src/domain/format/records/gyro/SampleColumns.js +82 -0
  98. package/dist/packages/core/src/domain/format/records/gyro/gyroLayouts.js +12 -0
  99. package/dist/packages/core/src/domain/format/records/gyro/parseGyroRecord.js +129 -0
  100. package/dist/packages/core/src/domain/format/trailer/RecordHeader.js +23 -0
  101. package/dist/packages/core/src/domain/format/trailer/Trailer.js +23 -0
  102. package/dist/packages/core/src/domain/format/trailer/TrailerFooter.js +27 -0
  103. package/dist/packages/core/src/domain/format/trailer/locateRecords.js +80 -0
  104. package/dist/packages/core/src/domain/format/trailer/parseRecordIndex.js +28 -0
  105. package/dist/packages/core/src/domain/format/trailer/readTrailer.js +32 -0
  106. package/dist/packages/core/src/domain/motion/exposure/ExposureRecord.js +53 -0
  107. package/dist/packages/core/src/domain/motion/gyro/GyroTrack.js +60 -0
  108. package/dist/packages/core/src/domain/motion/gyro/medianStep.js +11 -0
  109. package/dist/packages/core/src/domain/motion/gyro/repairedTimeline.js +101 -0
  110. package/dist/packages/core/src/domain/motion/imu/ImuFrame.js +112 -0
  111. package/dist/packages/core/src/domain/motion/orientation/OrientationTrack.js +146 -0
  112. package/dist/packages/core/src/domain/motion/orientation/estimateGyroBias.js +64 -0
  113. package/dist/packages/core/src/domain/motion/orientation/gravity.js +97 -0
  114. package/dist/packages/core/src/domain/motion/stabilization/Stabilizer.js +13 -0
  115. package/dist/packages/core/src/domain/motion/stabilization/stabilizers.js +86 -0
  116. package/dist/packages/core/src/domain/motion/timing/CaptureClock.js +41 -0
  117. package/dist/packages/core/src/domain/motion/timing/FrameTimes.js +92 -0
  118. package/dist/packages/core/src/domain/motion/timing/frameTimeSources.js +61 -0
  119. package/dist/packages/core/src/domain/motion/timing/resolveFrameTimes.js +68 -0
  120. package/dist/packages/core/src/domain/optics/EquidistantModel.js +39 -0
  121. package/dist/packages/core/src/domain/optics/MeiModel.js +45 -0
  122. package/dist/packages/core/src/domain/optics/PolynomialModel.js +44 -0
  123. package/dist/packages/core/src/domain/optics/gainMatch.js +62 -0
  124. package/dist/packages/core/src/domain/optics/lensGeometry.js +18 -0
  125. package/dist/packages/core/src/domain/optics/lensPose.js +35 -0
  126. package/dist/packages/core/src/domain/optics/opticsConstants.js +5 -0
  127. package/dist/packages/core/src/domain/playback/PlayerState.js +83 -0
  128. package/dist/packages/core/src/domain/stitching/LensLayout.js +21 -0
  129. package/dist/packages/core/src/domain/stitching/StitchingSetup.js +78 -0
  130. package/dist/packages/core/src/domain/stitching/seamDisparity.js +4 -0
  131. package/dist/packages/core/src/domain/stitching/seamDisparityField.js +5 -0
  132. package/dist/packages/core/src/domain/stitching/seamJoin.js +16 -0
  133. package/dist/packages/core/src/domain/stitching/seamMismatch.js +1 -0
  134. package/dist/packages/core/src/domain/stitching/seamRing.js +4 -0
  135. package/dist/packages/core/src/domain/stitching/seamStrip.js +26 -0
  136. package/dist/packages/core/src/domain/view/Framing.js +31 -0
  137. package/dist/packages/core/src/domain/view/PictureQuality.js +26 -0
  138. package/dist/packages/core/src/domain/view/ViewMode.js +9 -0
  139. package/dist/packages/core/src/domain/view/ViewState.js +48 -0
  140. package/dist/packages/core/src/domain/view/lensTilesView.js +63 -0
  141. package/dist/packages/core/src/domain/view/magnification.js +103 -0
  142. package/dist/packages/core/src/domain/view/normalView.js +29 -0
  143. package/dist/packages/core/src/domain/view/panoramaView.js +99 -0
  144. package/dist/packages/core/src/domain/view/rectilinear.js +40 -0
  145. package/dist/packages/core/src/domain/view/screenLayout.js +113 -0
  146. package/dist/packages/core/src/domain/view/viewGestures.js +98 -0
  147. package/dist/packages/core/src/domain/view/viewModes.js +14 -0
  148. package/dist/packages/core/src/index.js +59 -0
  149. package/dist/packages/core/src/ports/FramePair.js +6 -0
  150. package/dist/packages/core/src/shared/async/Deferred.js +42 -0
  151. package/dist/packages/core/src/shared/async/RunStop.js +40 -0
  152. package/dist/packages/core/src/shared/binary/ByteRange.js +38 -0
  153. package/dist/packages/core/src/shared/binary/ByteReader.js +77 -0
  154. package/dist/packages/core/src/shared/errors/GyroViewError.js +81 -0
  155. package/dist/packages/core/src/shared/errors/reportLater.js +11 -0
  156. package/dist/packages/core/src/shared/events/Outbox.js +68 -0
  157. package/dist/packages/core/src/shared/events/TypedEmitter.js +55 -0
  158. package/dist/packages/core/src/shared/keysOf.js +10 -0
  159. package/dist/packages/core/src/shared/lazy.js +11 -0
  160. package/dist/packages/core/src/shared/math/Matrix3.js +93 -0
  161. package/dist/packages/core/src/shared/math/Quaternion.js +133 -0
  162. package/dist/packages/core/src/shared/math/Vector3.js +54 -0
  163. package/dist/packages/core/src/shared/math/clamp.js +9 -0
  164. package/dist/packages/core/src/shared/protobuf/ProtobufMessage.js +157 -0
  165. package/dist/packages/core/src/shared/text/urlPath.js +31 -0
  166. package/dist/packages/core/src/shared/text/utf8.js +12 -0
  167. package/dist/packages/core/src/shared/units/angle.js +22 -0
  168. package/dist/packages/core/src/shared/units/time.js +13 -0
  169. package/dist/packages/player/src/PlayerSource.js +15 -0
  170. package/dist/packages/player/src/browserPlayer.js +18 -0
  171. package/dist/packages/player/src/choices.js +25 -0
  172. package/dist/packages/player/src/composition/Disposables.js +31 -0
  173. package/dist/packages/player/src/composition/browserPorts.js +46 -0
  174. package/dist/packages/player/src/composition/buildPipeline.js +153 -0
  175. package/dist/packages/player/src/composition/ensureDecodable.js +63 -0
  176. package/dist/packages/player/src/composition/openInputs.js +179 -0
  177. package/dist/packages/player/src/composition/openRecording.js +42 -0
  178. package/dist/packages/player/src/controls/ChoiceMenu.js +113 -0
  179. package/dist/packages/player/src/controls/PictureMenus.js +47 -0
  180. package/dist/packages/player/src/controls/SeekBar.js +125 -0
  181. package/dist/packages/player/src/controls/SoundControls.js +41 -0
  182. package/dist/packages/player/src/controls/TransportButtons.js +31 -0
  183. package/dist/packages/player/src/controls/ViewGestures.js +136 -0
  184. package/dist/packages/player/src/controls/Wording.js +78 -0
  185. package/dist/packages/player/src/controls/controlParts.js +36 -0
  186. package/dist/packages/player/src/controls/controls.js +4 -0
  187. package/dist/packages/player/src/controls/controlsBar.js +23 -0
  188. package/dist/packages/player/src/controls/controlsMarkup.js +85 -0
  189. package/dist/packages/player/src/controls/customControls.js +59 -0
  190. package/dist/packages/player/src/controls/formatTime.js +19 -0
  191. package/dist/packages/player/src/controls/icons.js +40 -0
  192. package/dist/packages/player/src/controls/keyboard.js +118 -0
  193. package/dist/packages/player/src/controls/messages.js +94 -0
  194. package/dist/packages/player/src/controls/parseMarkup.js +31 -0
  195. package/dist/packages/player/src/controls/viewButtons.js +14 -0
  196. package/dist/packages/player/src/element/ElementLoads.js +119 -0
  197. package/dist/packages/player/src/element/FullscreenToggle.js +39 -0
  198. package/dist/packages/player/src/element/GyroViewElement.js +313 -0
  199. package/dist/packages/player/src/element/IdleWatcher.js +71 -0
  200. package/dist/packages/player/src/element/TypedEventElement.js +22 -0
  201. package/dist/packages/player/src/element/accessibleRegion.js +19 -0
  202. package/dist/packages/player/src/element/attributeNames.js +51 -0
  203. package/dist/packages/player/src/element/attributes.js +101 -0
  204. package/dist/packages/player/src/element/defineGyroView.js +21 -0
  205. package/dist/packages/player/src/element/earlyProperties.js +36 -0
  206. package/dist/packages/player/src/element/elementSource.js +23 -0
  207. package/dist/packages/player/src/element/liveSettings.js +138 -0
  208. package/dist/packages/player/src/element/playbackAttributes.js +53 -0
  209. package/dist/packages/player/src/element/playerEventMirror.js +33 -0
  210. package/dist/packages/player/src/element/reflectedProperties.js +78 -0
  211. package/dist/packages/player/src/element/styles.js +4 -0
  212. package/dist/packages/player/src/element/template.js +47 -0
  213. package/dist/packages/player/src/index.js +10 -0
  214. package/dist/packages/player/src/inspectRecording.js +22 -0
  215. package/dist/packages/player/src/player/DrawingBufferFit.js +77 -0
  216. package/dist/packages/player/src/player/FrameLoop.js +40 -0
  217. package/dist/packages/player/src/player/PictureSettings.js +60 -0
  218. package/dist/packages/player/src/player/Player.js +377 -0
  219. package/dist/packages/player/src/player/PlayerEvents.js +28 -0
  220. package/dist/packages/player/src/player/PlayerPhase.js +21 -0
  221. package/dist/packages/player/src/player/PlayerSound.js +61 -0
  222. package/dist/packages/player/src/player/PlayerView.js +113 -0
  223. package/dist/packages/player/src/player/SessionRelay.js +66 -0
  224. package/dist/packages/player/src/player/ensureFinite.js +26 -0
  225. package/dist/packages/player/src/player/loadRecording.js +65 -0
  226. package/dist/packages/player/src/player/transportEvents.js +29 -0
  227. package/dist/standalone.js +4919 -0
  228. package/package.json +73 -0
@@ -0,0 +1,81 @@
1
+ //#region ../../packages/core/src/shared/errors/GyroViewError.ts
2
+ /**
3
+ * Stable machine-readable failure categories. Embedders switch on these; messages are for humans.
4
+ */
5
+ var GYRO_VIEW_ERROR_CODES = [
6
+ "binary-out-of-bounds",
7
+ "binary-unsafe-integer",
8
+ "codec-unsupported",
9
+ "cors",
10
+ "decode",
11
+ "embed-destroyed",
12
+ "index-out-of-range",
13
+ "invalid-argument",
14
+ "invalid-byte-range",
15
+ "invalid-calibration",
16
+ "invalid-protobuf",
17
+ "invalid-trailer",
18
+ "invariant-violation",
19
+ "missing-second-file",
20
+ "no-calibration",
21
+ "no-info-record",
22
+ "no-key-frame",
23
+ "playback-blocked",
24
+ "range-unsupported",
25
+ "render-unavailable",
26
+ "source-truncated",
27
+ "source-unreadable",
28
+ "unsupported-calibration",
29
+ "unsupported-container",
30
+ "unsupported-gyro-record",
31
+ "unsupported-info-format",
32
+ "unsupported-layout"
33
+ ];
34
+ function isGyroViewErrorCode(value) {
35
+ return typeof value === "string" && GYRO_VIEW_ERROR_CODES.includes(value);
36
+ }
37
+ var GyroViewError = class extends Error {
38
+ code;
39
+ constructor(code, message, options) {
40
+ super(message, options);
41
+ this.code = code;
42
+ this.name = "GyroViewError";
43
+ }
44
+ };
45
+ /**
46
+ * `error` as a `GyroViewError`: one already typed as it is, anything else under `code`, kept as
47
+ * the cause, so a failure crosses a boundary typed without losing what it was.
48
+ */
49
+ function asGyroViewError(error, code, message) {
50
+ return error instanceof GyroViewError ? error : new GyroViewError(code, message, { cause: error });
51
+ }
52
+ /**
53
+ * A caller's abort, as `AbortSignal` reports it (a `DOMException` named `AbortError`): passed on
54
+ * as it is, never taken for a failure.
55
+ */
56
+ function isAbortError(error) {
57
+ return error instanceof Error && error.name === "AbortError";
58
+ }
59
+ function hasErrorCode(error, code) {
60
+ return error instanceof GyroViewError && error.code === code;
61
+ }
62
+ /**
63
+ * The human-readable part of anything thrown: an error's message, or the value as text.
64
+ */
65
+ function messageOf(error) {
66
+ return error instanceof Error ? error.message : String(error);
67
+ }
68
+ /**
69
+ * Guards a constructor or factory precondition with the shared error type.
70
+ */
71
+ function ensureInvariant(isSatisfied, message) {
72
+ if (!isSatisfied) throw new GyroViewError("invariant-violation", message);
73
+ }
74
+ /**
75
+ * Guards positional access into a fixed-length collection.
76
+ */
77
+ function ensureIndexInRange(index, length, subject) {
78
+ if (!Number.isSafeInteger(index) || index < 0 || index >= length) throw new GyroViewError("index-out-of-range", `${subject} index ${index} is outside 0..${length - 1}`);
79
+ }
80
+ //#endregion
81
+ export { GYRO_VIEW_ERROR_CODES, GyroViewError, asGyroViewError, ensureIndexInRange, ensureInvariant, hasErrorCode, isAbortError, isGyroViewErrorCode, messageOf };
@@ -0,0 +1,11 @@
1
+ //#region ../../packages/core/src/shared/errors/reportLater.ts
2
+ /**
3
+ * A failure nobody is waiting for surfaces as an unhandled rejection, where the platform reports
4
+ * it, and leaves whoever met it to carry on.
5
+ */
6
+ function reportLater(error) {
7
+ const reason = error instanceof Error ? error : new Error("a failure went unheard", { cause: error });
8
+ Promise.reject(reason);
9
+ }
10
+ //#endregion
11
+ export { reportLater };
@@ -0,0 +1,68 @@
1
+ //#region ../../packages/core/src/shared/events/Outbox.ts
2
+ /**
3
+ * Holds what a change announces until the change is complete, then delivers it in order. A
4
+ * listener never runs in the middle of the change it hears, so the code making a change reads its
5
+ * own state after announcing, never a state a listener left. A change a listener makes while it
6
+ * hears one supersedes the older change: once the newer change announces, whatever the older one
7
+ * still had to announce is dropped, since the newer change reports itself (ADR 0021).
8
+ */
9
+ var Outbox = class {
10
+ emitter;
11
+ queue = [];
12
+ depth = 0;
13
+ isDelivering = false;
14
+ /**
15
+ * A listener's change is under way and has announced nothing yet.
16
+ */
17
+ isSuperseding = false;
18
+ constructor(emitter) {
19
+ this.emitter = emitter;
20
+ }
21
+ /**
22
+ * Runs `make` as one change: what it announces goes out once the outermost change is complete.
23
+ */
24
+ change(make) {
25
+ if (this.depth === 0 && this.isDelivering) this.isSuperseding = true;
26
+ this.depth += 1;
27
+ try {
28
+ return make();
29
+ } finally {
30
+ this.depth -= 1;
31
+ if (this.depth === 0) {
32
+ this.isSuperseding = false;
33
+ this.deliver();
34
+ }
35
+ }
36
+ }
37
+ emit(name, payload) {
38
+ this.post(() => {
39
+ this.emitter.emit(name, payload);
40
+ });
41
+ }
42
+ /**
43
+ * Announces: at once outside a change, and once it is complete within one. What is announced
44
+ * is decided when it is delivered, for an announcement that reads the state then.
45
+ */
46
+ post(announce) {
47
+ if (this.isSuperseding) {
48
+ this.queue.length = 0;
49
+ this.isSuperseding = false;
50
+ }
51
+ this.queue.push(announce);
52
+ if (this.depth === 0) this.deliver();
53
+ }
54
+ /**
55
+ * Announcements made while delivering, by a listener, join the end of the line.
56
+ */
57
+ deliver() {
58
+ if (this.isDelivering) return;
59
+ this.isDelivering = true;
60
+ try {
61
+ for (let next = this.queue.shift(); next; next = this.queue.shift()) next();
62
+ } finally {
63
+ this.isDelivering = false;
64
+ }
65
+ }
66
+ };
67
+ //#endregion
68
+ export { Outbox };
@@ -0,0 +1,55 @@
1
+ import { reportLater } from "../errors/reportLater.js";
2
+ //#region ../../packages/core/src/shared/events/TypedEmitter.ts
3
+ /**
4
+ * Minimal typed observer: one payload type per event name, unsubscribe through the returned
5
+ * function. No platform EventTarget so it works in the dependency-free core.
6
+ *
7
+ * A listener that throws, a page's among them, is reported and skipped, as `dispatchEvent`
8
+ * does: the code that emitted, a frame loop or a load, carries on, and so do the other listeners.
9
+ *
10
+ * Listeners are stored with their payload type erased to `never`, which every listener type is
11
+ * assignable to; `emit` restores the type its event name guarantees.
12
+ */
13
+ var TypedEmitter = class {
14
+ reportListenerError;
15
+ listeners = /* @__PURE__ */ new Map();
16
+ constructor(reportListenerError = reportLater) {
17
+ this.reportListenerError = reportListenerError;
18
+ }
19
+ on(name, listener) {
20
+ const set = this.listeners.get(name) ?? /* @__PURE__ */ new Set();
21
+ set.add(listener);
22
+ this.listeners.set(name, set);
23
+ return () => {
24
+ set.delete(listener);
25
+ };
26
+ }
27
+ /**
28
+ * The listeners there when the emit began hear it, as `dispatchEvent` delivers: one added
29
+ * meanwhile waits for the next emit, so a listener that subscribes itself again runs once, and
30
+ * one removed meanwhile hears no more.
31
+ */
32
+ emit(name, payload) {
33
+ const listeners = this.listeners.get(name);
34
+ if (!listeners) return;
35
+ const listening = [...listeners];
36
+ for (const listener of listening) {
37
+ if (!listeners.has(listener)) continue;
38
+ try {
39
+ listener(payload);
40
+ } catch (error) {
41
+ this.reportListenerError(error);
42
+ }
43
+ }
44
+ }
45
+ /**
46
+ * The listeners of an event under way are dropped too, as an unsubscribe drops one: whoever
47
+ * removed them is past hearing from them.
48
+ */
49
+ removeAll() {
50
+ for (const set of this.listeners.values()) set.clear();
51
+ this.listeners.clear();
52
+ }
53
+ };
54
+ //#endregion
55
+ export { TypedEmitter };
@@ -0,0 +1,10 @@
1
+ //#region ../../packages/core/src/shared/keysOf.ts
2
+ /**
3
+ * The keys of a record that names each of `Key` once, as a list to use at run time: the record's
4
+ * type makes the compiler refuse a missing or an unknown key, which a list alone would not.
5
+ */
6
+ function keysOf(every) {
7
+ return Object.keys(every);
8
+ }
9
+ //#endregion
10
+ export { keysOf };
@@ -0,0 +1,11 @@
1
+ //#region ../../packages/core/src/shared/lazy.ts
2
+ /**
3
+ * A value made on first request and kept: for what costs work to build and may never be asked
4
+ * for, such as an element's parsed markup on a page that renders none.
5
+ */
6
+ function lazy(make) {
7
+ let made;
8
+ return () => (made ??= { value: make() }).value;
9
+ }
10
+ //#endregion
11
+ export { lazy };
@@ -0,0 +1,93 @@
1
+ //#region ../../packages/core/src/shared/math/Matrix3.ts
2
+ var IDENTITY_MATRIX3 = [
3
+ 1,
4
+ 0,
5
+ 0,
6
+ 0,
7
+ 1,
8
+ 0,
9
+ 0,
10
+ 0,
11
+ 1
12
+ ];
13
+ function rotationAboutX(angle) {
14
+ const c = Math.cos(angle);
15
+ const s = Math.sin(angle);
16
+ return [
17
+ 1,
18
+ 0,
19
+ 0,
20
+ 0,
21
+ c,
22
+ -s,
23
+ 0,
24
+ s,
25
+ c
26
+ ];
27
+ }
28
+ function rotationAboutY(angle) {
29
+ const c = Math.cos(angle);
30
+ const s = Math.sin(angle);
31
+ return [
32
+ c,
33
+ 0,
34
+ s,
35
+ 0,
36
+ 1,
37
+ 0,
38
+ -s,
39
+ 0,
40
+ c
41
+ ];
42
+ }
43
+ function rotationAboutZ(angle) {
44
+ const c = Math.cos(angle);
45
+ const s = Math.sin(angle);
46
+ return [
47
+ c,
48
+ -s,
49
+ 0,
50
+ s,
51
+ c,
52
+ 0,
53
+ 0,
54
+ 0,
55
+ 1
56
+ ];
57
+ }
58
+ /**
59
+ * `a * b`: applying the product to a vector applies `b` first, then `a`.
60
+ */
61
+ function multiplyMatrices(a, b) {
62
+ const [a00, a01, a02, a10, a11, a12, a20, a21, a22] = a;
63
+ const [b00, b01, b02, b10, b11, b12, b20, b21, b22] = b;
64
+ return [
65
+ a00 * b00 + a01 * b10 + a02 * b20,
66
+ a00 * b01 + a01 * b11 + a02 * b21,
67
+ a00 * b02 + a01 * b12 + a02 * b22,
68
+ a10 * b00 + a11 * b10 + a12 * b20,
69
+ a10 * b01 + a11 * b11 + a12 * b21,
70
+ a10 * b02 + a11 * b12 + a12 * b22,
71
+ a20 * b00 + a21 * b10 + a22 * b20,
72
+ a20 * b01 + a21 * b11 + a22 * b21,
73
+ a20 * b02 + a21 * b12 + a22 * b22
74
+ ];
75
+ }
76
+ function transformVector(m, v) {
77
+ const [m00, m01, m02, m10, m11, m12, m20, m21, m22] = m;
78
+ const [x, y, z] = v;
79
+ return [
80
+ m00 * x + m01 * y + m02 * z,
81
+ m10 * x + m11 * y + m12 * z,
82
+ m20 * x + m21 * y + m22 * z
83
+ ];
84
+ }
85
+ /**
86
+ * Positive one for a proper rotation, minus one for a reflection, zero when singular.
87
+ */
88
+ function determinantOf(m) {
89
+ const [m00, m01, m02, m10, m11, m12, m20, m21, m22] = m;
90
+ return m00 * (m11 * m22 - m12 * m21) - m01 * (m10 * m22 - m12 * m20) + m02 * (m10 * m21 - m11 * m20);
91
+ }
92
+ //#endregion
93
+ export { IDENTITY_MATRIX3, determinantOf, multiplyMatrices, rotationAboutX, rotationAboutY, rotationAboutZ, transformVector };
@@ -0,0 +1,133 @@
1
+ import { radians } from "../units/angle.js";
2
+ import { magnitudeOf } from "./Vector3.js";
3
+ //#region ../../packages/core/src/shared/math/Quaternion.ts
4
+ var IDENTITY_QUATERNION = [
5
+ 0,
6
+ 0,
7
+ 0,
8
+ 1
9
+ ];
10
+ /**
11
+ * Rotations smaller than this, in radians, are treated as no rotation by the exponential map.
12
+ */
13
+ var NEGLIGIBLE_ANGLE = 1e-12;
14
+ /**
15
+ * Below this dot product two quaternions are far enough apart for a real spherical interpolation.
16
+ */
17
+ var NEARLY_PARALLEL = .9995;
18
+ function quaternionFromAxisAngle(axis, angle) {
19
+ const length = magnitudeOf(axis);
20
+ if (length === 0) return IDENTITY_QUATERNION;
21
+ const half = angle / 2;
22
+ const scale = Math.sin(half) / length;
23
+ return [
24
+ axis[0] * scale,
25
+ axis[1] * scale,
26
+ axis[2] * scale,
27
+ Math.cos(half)
28
+ ];
29
+ }
30
+ /**
31
+ * Exponential map: the rotation of `|omega|` radians about `omega`, for example an angular
32
+ * velocity times a time step.
33
+ */
34
+ function quaternionFromRotationVector(omega) {
35
+ const angle = magnitudeOf(omega);
36
+ return angle < NEGLIGIBLE_ANGLE ? IDENTITY_QUATERNION : quaternionFromAxisAngle(omega, radians(angle));
37
+ }
38
+ /**
39
+ * `a * b`: applying the product to a vector applies `b` first, then `a`.
40
+ */
41
+ function multiplyQuaternions(a, b) {
42
+ const [ax, ay, az, aw] = a;
43
+ const [bx, by, bz, bw] = b;
44
+ return [
45
+ aw * bx + ax * bw + ay * bz - az * by,
46
+ aw * by - ax * bz + ay * bw + az * bx,
47
+ aw * bz + ax * by - ay * bx + az * bw,
48
+ aw * bw - ax * bx - ay * by - az * bz
49
+ ];
50
+ }
51
+ /**
52
+ * The inverse rotation of a unit quaternion.
53
+ */
54
+ function conjugateQuaternion(q) {
55
+ const [x, y, z, w] = q;
56
+ return [
57
+ -x,
58
+ -y,
59
+ -z,
60
+ w
61
+ ];
62
+ }
63
+ function normalizeQuaternion(q) {
64
+ const [x, y, z, w] = q;
65
+ const length = Math.hypot(x, y, z, w);
66
+ return length === 0 ? IDENTITY_QUATERNION : [
67
+ x / length,
68
+ y / length,
69
+ z / length,
70
+ w / length
71
+ ];
72
+ }
73
+ function rotateVector(q, v) {
74
+ const [qx, qy, qz, qw] = q;
75
+ const [vx, vy, vz] = v;
76
+ const tx = 2 * (qy * vz - qz * vy);
77
+ const ty = 2 * (qz * vx - qx * vz);
78
+ const tz = 2 * (qx * vy - qy * vx);
79
+ return [
80
+ vx + qw * tx + (qy * tz - qz * ty),
81
+ vy + qw * ty + (qz * tx - qx * tz),
82
+ vz + qw * tz + (qx * ty - qy * tx)
83
+ ];
84
+ }
85
+ /**
86
+ * Spherical interpolation from `a` (t = 0) to `b` (t = 1) along the shorter arc.
87
+ */
88
+ function slerpQuaternions(a, b, t) {
89
+ const [ax, ay, az, aw] = a;
90
+ let [bx, by, bz, bw] = b;
91
+ let dot = ax * bx + ay * by + az * bz + aw * bw;
92
+ if (dot < 0) {
93
+ dot = -dot;
94
+ [bx, by, bz, bw] = [
95
+ -bx,
96
+ -by,
97
+ -bz,
98
+ -bw
99
+ ];
100
+ }
101
+ if (dot > NEARLY_PARALLEL) return normalizeQuaternion([
102
+ ax + (bx - ax) * t,
103
+ ay + (by - ay) * t,
104
+ az + (bz - az) * t,
105
+ aw + (bw - aw) * t
106
+ ]);
107
+ const theta = Math.acos(dot);
108
+ const sinTheta = Math.sin(theta);
109
+ const weightA = Math.sin((1 - t) * theta) / sinTheta;
110
+ const weightB = Math.sin(t * theta) / sinTheta;
111
+ return [
112
+ ax * weightA + bx * weightB,
113
+ ay * weightA + by * weightB,
114
+ az * weightA + bz * weightB,
115
+ aw * weightA + bw * weightB
116
+ ];
117
+ }
118
+ function quaternionToMatrix(q) {
119
+ const [x, y, z, w] = q;
120
+ return [
121
+ 1 - 2 * (y * y + z * z),
122
+ 2 * (x * y - z * w),
123
+ 2 * (x * z + y * w),
124
+ 2 * (x * y + z * w),
125
+ 1 - 2 * (x * x + z * z),
126
+ 2 * (y * z - x * w),
127
+ 2 * (x * z - y * w),
128
+ 2 * (y * z + x * w),
129
+ 1 - 2 * (x * x + y * y)
130
+ ];
131
+ }
132
+ //#endregion
133
+ export { IDENTITY_QUATERNION, conjugateQuaternion, multiplyQuaternions, normalizeQuaternion, quaternionFromAxisAngle, quaternionFromRotationVector, quaternionToMatrix, rotateVector, slerpQuaternions };
@@ -0,0 +1,54 @@
1
+ //#region ../../packages/core/src/shared/math/Vector3.ts
2
+ var ZERO_VECTOR3 = [
3
+ 0,
4
+ 0,
5
+ 0
6
+ ];
7
+ function magnitudeOf(vector) {
8
+ return Math.hypot(vector[0], vector[1], vector[2]);
9
+ }
10
+ function dotProduct(a, b) {
11
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
12
+ }
13
+ /**
14
+ * Right-handed: x cross y is z.
15
+ */
16
+ function crossProduct(a, b) {
17
+ return [
18
+ a[1] * b[2] - a[2] * b[1],
19
+ a[2] * b[0] - a[0] * b[2],
20
+ a[0] * b[1] - a[1] * b[0]
21
+ ];
22
+ }
23
+ function isFiniteVector(vector) {
24
+ return vector.every((component) => Number.isFinite(component));
25
+ }
26
+ function addVectors(a, b) {
27
+ return [
28
+ a[0] + b[0],
29
+ a[1] + b[1],
30
+ a[2] + b[2]
31
+ ];
32
+ }
33
+ function subtractVectors(a, b) {
34
+ return [
35
+ a[0] - b[0],
36
+ a[1] - b[1],
37
+ a[2] - b[2]
38
+ ];
39
+ }
40
+ function scaleVector(vector, factor) {
41
+ return [
42
+ vector[0] * factor,
43
+ vector[1] * factor,
44
+ vector[2] * factor
45
+ ];
46
+ }
47
+ /**
48
+ * The point `weight` of the way from `from` to `to`: `from` at 0, `to` at 1.
49
+ */
50
+ function interpolateVectors(from, to, weight) {
51
+ return addVectors(from, scaleVector(subtractVectors(to, from), weight));
52
+ }
53
+ //#endregion
54
+ export { ZERO_VECTOR3, addVectors, crossProduct, dotProduct, interpolateVectors, isFiniteVector, magnitudeOf, scaleVector, subtractVectors };
@@ -0,0 +1,9 @@
1
+ //#region ../../packages/core/src/shared/math/clamp.ts
2
+ /**
3
+ * `value` held within `low` and `high`.
4
+ */
5
+ function clamp(value, low, high) {
6
+ return Math.min(Math.max(value, low), high);
7
+ }
8
+ //#endregion
9
+ export { clamp };
@@ -0,0 +1,157 @@
1
+ import { GyroViewError } from "../errors/GyroViewError.js";
2
+ import { ByteReader } from "../binary/ByteReader.js";
3
+ import { decodeUtf8 } from "../text/utf8.js";
4
+ //#region ../../packages/core/src/shared/protobuf/ProtobufMessage.ts
5
+ /**
6
+ * Protocol Buffers wire types this decoder understands. Groups (3, 4) are obsolete and rejected.
7
+ */
8
+ var WireType = {
9
+ Varint: 0,
10
+ Fixed64: 1,
11
+ LengthDelimited: 2,
12
+ Fixed32: 5
13
+ };
14
+ var FIELD_NUMBER_SHIFT = 3;
15
+ var WIRE_TYPE_MASK = 7;
16
+ var VARINT_PAYLOAD_BITS = 7n;
17
+ var VARINT_PAYLOAD_MASK = 127n;
18
+ var VARINT_CONTINUATION_BIT = 128;
19
+ var FIXED64_SIZE = 8;
20
+ var FIXED32_SIZE = 4;
21
+ var MAX_VARINT_BYTES = 10;
22
+ var MAX_SAFE = BigInt(Number.MAX_SAFE_INTEGER);
23
+ /**
24
+ * A schema-less view of one encoded protobuf message: fields are looked up by number and unknown
25
+ * fields are simply carried along. Varints stay exact (bigint) until a caller asks for a number,
26
+ * so an oversized value in a field nobody reads cannot break the whole record.
27
+ */
28
+ var ProtobufMessage = class ProtobufMessage {
29
+ decoded;
30
+ constructor(decoded) {
31
+ this.decoded = decoded;
32
+ }
33
+ static decode(bytes) {
34
+ const cursor = new Cursor(bytes);
35
+ const fields = [];
36
+ while (!cursor.atEnd) fields.push(cursor.readField());
37
+ return new ProtobufMessage(fields);
38
+ }
39
+ varint(number) {
40
+ const value = this.valueOf(number);
41
+ if (value === void 0) return void 0;
42
+ if (value.kind !== "varint") throw this.wrongType(number, "varint", value.kind);
43
+ if (value.value > MAX_SAFE) throw new GyroViewError("binary-unsafe-integer", `field ${number} holds ${value.value.toString()}, beyond the safe integer range`);
44
+ return Number(value.value);
45
+ }
46
+ boolean(number) {
47
+ const value = this.varint(number);
48
+ return value === void 0 ? void 0 : value !== 0;
49
+ }
50
+ double(number) {
51
+ const value = this.valueOf(number);
52
+ if (value === void 0) return void 0;
53
+ if (value.kind !== "fixed64") throw this.wrongType(number, "fixed64", value.kind);
54
+ return new ByteReader(value.bytes).float64LeAt(0);
55
+ }
56
+ bytes(number) {
57
+ const value = this.valueOf(number);
58
+ if (value === void 0) return void 0;
59
+ if (value.kind !== "bytes") throw this.wrongType(number, "bytes", value.kind);
60
+ return value.bytes;
61
+ }
62
+ string(number) {
63
+ const bytes = this.bytes(number);
64
+ return bytes === void 0 ? void 0 : decodeUtf8(bytes);
65
+ }
66
+ message(number) {
67
+ const bytes = this.bytes(number);
68
+ return bytes === void 0 ? void 0 : ProtobufMessage.decode(bytes);
69
+ }
70
+ /**
71
+ * Scalar accessors follow protobuf merge semantics: the last occurrence of a field wins.
72
+ */
73
+ valueOf(number) {
74
+ return this.decoded.findLast((field) => field.number === number)?.value;
75
+ }
76
+ wrongType(number, expected, actual) {
77
+ return new GyroViewError("invalid-protobuf", `field ${number} is encoded as ${actual}, expected ${expected}`);
78
+ }
79
+ };
80
+ /**
81
+ * Sequential reader over the wire format; kept private to the message decoder.
82
+ */
83
+ var Cursor = class {
84
+ bytes;
85
+ position = 0;
86
+ reader;
87
+ constructor(bytes) {
88
+ this.bytes = bytes;
89
+ this.reader = new ByteReader(bytes);
90
+ }
91
+ get atEnd() {
92
+ return this.position >= this.bytes.byteLength;
93
+ }
94
+ readField() {
95
+ const key = this.readVarint();
96
+ const number = Number(key >> BigInt(FIELD_NUMBER_SHIFT));
97
+ const wireType = Number(key & BigInt(WIRE_TYPE_MASK));
98
+ return {
99
+ number,
100
+ value: this.readValue(wireType, number)
101
+ };
102
+ }
103
+ readValue(wireType, fieldNumber) {
104
+ switch (wireType) {
105
+ case WireType.Varint: return {
106
+ kind: "varint",
107
+ value: this.readVarint()
108
+ };
109
+ case WireType.Fixed64: return {
110
+ kind: "fixed64",
111
+ bytes: this.readBytes(FIXED64_SIZE)
112
+ };
113
+ case WireType.Fixed32: return {
114
+ kind: "fixed32",
115
+ bytes: this.readBytes(FIXED32_SIZE)
116
+ };
117
+ case WireType.LengthDelimited: return {
118
+ kind: "bytes",
119
+ bytes: this.readBytes(this.readLength())
120
+ };
121
+ default: throw new GyroViewError("invalid-protobuf", `field ${fieldNumber} uses unsupported wire type ${wireType}`);
122
+ }
123
+ }
124
+ readVarint() {
125
+ let result = 0n;
126
+ let shift = 0n;
127
+ for (let consumed = 0; consumed < MAX_VARINT_BYTES; consumed += 1) {
128
+ const byte = this.readByte();
129
+ result |= (BigInt(byte) & VARINT_PAYLOAD_MASK) << shift;
130
+ if ((byte & VARINT_CONTINUATION_BIT) === 0) return result;
131
+ shift += VARINT_PAYLOAD_BITS;
132
+ }
133
+ throw new GyroViewError("invalid-protobuf", `varint longer than ${MAX_VARINT_BYTES} bytes at byte ${this.position}`);
134
+ }
135
+ readLength() {
136
+ const length = this.readVarint();
137
+ if (length > BigInt(this.bytes.byteLength)) throw new GyroViewError("invalid-protobuf", `length ${length.toString()} exceeds the message at byte ${this.position}`);
138
+ return Number(length);
139
+ }
140
+ readByte() {
141
+ this.ensureRemaining(1);
142
+ const byte = this.reader.uint8At(this.position);
143
+ this.position += 1;
144
+ return byte;
145
+ }
146
+ readBytes(length) {
147
+ this.ensureRemaining(length);
148
+ const bytes = this.reader.bytesAt(this.position, length);
149
+ this.position += length;
150
+ return bytes;
151
+ }
152
+ ensureRemaining(length) {
153
+ if (this.position + length > this.bytes.byteLength) throw new GyroViewError("invalid-protobuf", `message truncated at byte ${this.position}`);
154
+ }
155
+ };
156
+ //#endregion
157
+ export { ProtobufMessage };