lib0 1.0.0-rc.2 → 1.0.0-rc.21

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 (141) hide show
  1. package/README.md +0 -1315
  2. package/{types → dist}/buffer.d.ts +2 -10
  3. package/{types → dist}/delta/delta.d.ts +582 -144
  4. package/dist/delta/position.d.ts +65 -0
  5. package/dist/delta/rdt/delta.d.ts +57 -0
  6. package/dist/delta/rdt/dom.d.ts +102 -0
  7. package/dist/delta/rdt.d.ts +180 -0
  8. package/dist/delta/transformer/attr.d.ts +64 -0
  9. package/dist/delta/transformer/attribution-to-format.d.ts +52 -0
  10. package/dist/delta/transformer/children.d.ts +69 -0
  11. package/dist/delta/transformer/conform.d.ts +83 -0
  12. package/dist/delta/transformer/core.d.ts +189 -0
  13. package/dist/delta/transformer/full-attributions.d.ts +37 -0
  14. package/dist/delta/transformer/id.d.ts +2 -0
  15. package/dist/delta/transformer/inline.d.ts +89 -0
  16. package/dist/delta/transformer/pipe.d.ts +182 -0
  17. package/dist/delta/transformer/project.d.ts +223 -0
  18. package/dist/delta/transformer/rename-attrs.d.ts +75 -0
  19. package/dist/delta/transformer/rename.d.ts +41 -0
  20. package/dist/delta/transformer/value.d.ts +92 -0
  21. package/dist/delta/transformer.d.ts +14 -0
  22. package/dist/diff/patience.d.ts +25 -0
  23. package/{types → dist}/environment.d.ts +10 -0
  24. package/dist/hash/fnv1a.d.ts +11 -0
  25. package/{types → dist}/schema.d.ts +49 -38
  26. package/{types → dist}/ts.d.ts +4 -0
  27. package/dist/webcrypto.d.ts +3 -0
  28. package/package.json +148 -82
  29. package/src/bin/0serve.js +11 -3
  30. package/src/broadcastchannel.js +6 -1
  31. package/src/buffer.js +35 -25
  32. package/src/decoding.js +1 -1
  33. package/src/delta/delta.js +2531 -564
  34. package/src/delta/position.js +165 -0
  35. package/src/delta/rdt/delta.js +105 -0
  36. package/src/delta/rdt/dom.js +307 -0
  37. package/src/delta/rdt.js +255 -0
  38. package/src/delta/transformer/attr.js +126 -0
  39. package/src/delta/transformer/attribution-to-format.js +335 -0
  40. package/src/delta/transformer/children.js +219 -0
  41. package/src/delta/transformer/conform.js +401 -0
  42. package/src/delta/transformer/core.js +323 -0
  43. package/src/delta/transformer/full-attributions.js +282 -0
  44. package/src/delta/transformer/id.js +13 -0
  45. package/src/delta/transformer/inline.js +818 -0
  46. package/src/delta/transformer/pipe.js +272 -0
  47. package/src/delta/transformer/project.js +526 -0
  48. package/src/delta/transformer/rename-attrs.js +152 -0
  49. package/src/delta/transformer/rename.js +84 -0
  50. package/src/delta/transformer/value.js +214 -0
  51. package/src/delta/transformer.js +38 -0
  52. package/src/diff/patience.js +22 -11
  53. package/src/dom.js +2 -2
  54. package/src/encoding.js +1 -1
  55. package/src/environment.js +15 -0
  56. package/src/hash/fnv1a.js +82 -0
  57. package/src/number.js +1 -3
  58. package/src/performance.node.js +3 -3
  59. package/src/schema.js +231 -177
  60. package/src/string.js +3 -5
  61. package/src/testing.js +1 -1
  62. package/src/trait/equality.js +1 -1
  63. package/src/trait/fingerprint.js +1 -1
  64. package/src/ts.js +11 -0
  65. package/src/bin/gendocs.js +0 -117
  66. package/src/component.js +0 -414
  67. package/src/delta/binding.js +0 -372
  68. package/src/tree.js +0 -546
  69. package/types/bin/gendocs.d.ts +0 -3
  70. package/types/component.d.ts +0 -86
  71. package/types/delta/binding.d.ts +0 -106
  72. package/types/diff/patience.d.ts +0 -16
  73. package/types/tree.d.ts +0 -96
  74. package/types/webcrypto.d.ts +0 -3
  75. /package/{types → dist}/array.d.ts +0 -0
  76. /package/{types → dist}/bin/0ecdsa-generate-keypair.d.ts +0 -0
  77. /package/{types → dist}/bin/0serve.d.ts +0 -0
  78. /package/{types → dist}/bin/gentesthtml.d.ts +0 -0
  79. /package/{types → dist}/binary.d.ts +0 -0
  80. /package/{types → dist}/broadcastchannel.d.ts +0 -0
  81. /package/{types → dist}/cache.d.ts +0 -0
  82. /package/{types → dist}/conditions.d.ts +0 -0
  83. /package/{types → dist}/crypto/aes-gcm.d.ts +0 -0
  84. /package/{types → dist}/crypto/common.d.ts +0 -0
  85. /package/{types → dist}/crypto/ecdsa.d.ts +0 -0
  86. /package/{types → dist}/crypto/jwt.d.ts +0 -0
  87. /package/{types → dist}/crypto/rsa-oaep.d.ts +0 -0
  88. /package/{types → dist}/decoding.d.ts +0 -0
  89. /package/{types → dist}/diff.d.ts +0 -0
  90. /package/{types → dist}/dom.d.ts +0 -0
  91. /package/{types → dist}/encoding.d.ts +0 -0
  92. /package/{types → dist}/error.d.ts +0 -0
  93. /package/{types → dist}/eventloop.d.ts +0 -0
  94. /package/{types → dist}/function.d.ts +0 -0
  95. /package/{types → dist}/hash/rabin-gf2-polynomial.d.ts +0 -0
  96. /package/{types → dist}/hash/rabin-uncached.d.ts +0 -0
  97. /package/{types → dist}/hash/rabin.d.ts +0 -0
  98. /package/{types → dist}/hash/sha256.d.ts +0 -0
  99. /package/{types → dist}/hash/sha256.node.d.ts +0 -0
  100. /package/{types → dist}/indexeddb.d.ts +0 -0
  101. /package/{types → dist}/indexeddbV2.d.ts +0 -0
  102. /package/{types → dist}/iterator.d.ts +0 -0
  103. /package/{types → dist}/json.d.ts +0 -0
  104. /package/{types → dist}/list.d.ts +0 -0
  105. /package/{types → dist}/logging.common.d.ts +0 -0
  106. /package/{types → dist}/logging.d.ts +0 -0
  107. /package/{types → dist}/logging.node.d.ts +0 -0
  108. /package/{types → dist}/map.d.ts +0 -0
  109. /package/{types → dist}/math.d.ts +0 -0
  110. /package/{types → dist}/metric.d.ts +0 -0
  111. /package/{types → dist}/mutex.d.ts +0 -0
  112. /package/{types → dist}/number.d.ts +0 -0
  113. /package/{types → dist}/object.d.ts +0 -0
  114. /package/{types → dist}/observable.d.ts +0 -0
  115. /package/{types → dist}/pair.d.ts +0 -0
  116. /package/{types → dist}/performance.d.ts +0 -0
  117. /package/{types → dist}/performance.node.d.ts +0 -0
  118. /package/{types → dist}/pledge.d.ts +0 -0
  119. /package/{types → dist}/prng/Mt19937.d.ts +0 -0
  120. /package/{types → dist}/prng/Xoroshiro128plus.d.ts +0 -0
  121. /package/{types → dist}/prng/Xorshift32.d.ts +0 -0
  122. /package/{types → dist}/prng.d.ts +0 -0
  123. /package/{types → dist}/promise.d.ts +0 -0
  124. /package/{types → dist}/queue.d.ts +0 -0
  125. /package/{types → dist}/random.d.ts +0 -0
  126. /package/{types → dist}/set.d.ts +0 -0
  127. /package/{types → dist}/sort.d.ts +0 -0
  128. /package/{types → dist}/statistics.d.ts +0 -0
  129. /package/{types → dist}/storage.d.ts +0 -0
  130. /package/{types → dist}/string.d.ts +0 -0
  131. /package/{types → dist}/symbol.d.ts +0 -0
  132. /package/{types → dist}/testing.d.ts +0 -0
  133. /package/{types → dist}/time.d.ts +0 -0
  134. /package/{types → dist}/trait/equality.d.ts +0 -0
  135. /package/{types → dist}/trait/fingerprint.d.ts +0 -0
  136. /package/{types → dist}/trait/traits.d.ts +0 -0
  137. /package/{types → dist}/url.d.ts +0 -0
  138. /package/{types → dist}/webcrypto.deno.d.ts +0 -0
  139. /package/{types → dist}/webcrypto.node.d.ts +0 -0
  140. /package/{types → dist}/webcrypto.react-native.d.ts +0 -0
  141. /package/{types → dist}/websocket.d.ts +0 -0
package/src/bin/0serve.js CHANGED
@@ -13,7 +13,7 @@ import * as env from '../environment.js'
13
13
  import * as number from '../number.js'
14
14
  import * as logging from 'lib0/logging'
15
15
 
16
- const host = env.getParam('--host', 'localhost')
16
+ const host = env.getParam('--host', '127.0.0.1')
17
17
  const port = number.parseInt(env.getParam('--port', '8000'))
18
18
  const paramOpenFile = env.getParam('-o', '')
19
19
  const debugBrowser = env.getConf('DEBUG_BROWSER')
@@ -89,9 +89,17 @@ const server = http.createServer((req, res) => {
89
89
  server.listen(port, host, () => {
90
90
  logging.print(logging.BOLD, logging.ORANGE, `Server is running on http://${host}:${port}`)
91
91
  if (paramOpenFile) {
92
- const start = debugBrowser || (process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open')
92
+ const url = `http://${host}:${port}/${paramOpenFile}`
93
93
  import('child_process').then(cp => {
94
- cp.exec(`${start} http://${host}:${port}/${paramOpenFile}`)
94
+ if (debugBrowser) {
95
+ cp.execFile(debugBrowser, [url])
96
+ } else if (process.platform === 'darwin') {
97
+ cp.execFile('open', [url])
98
+ } else if (process.platform === 'win32') {
99
+ cp.execFile('cmd', ['/c', 'start', '', url])
100
+ } else {
101
+ cp.execFile('xdg-open', [url])
102
+ }
95
103
  })
96
104
  }
97
105
  })
@@ -44,6 +44,10 @@ class LocalStoragePolyfill {
44
44
  * @type {null|function({data:Uint8Array}):void}
45
45
  */
46
46
  this.onmessage = null
47
+ /**
48
+ * @type {null|((this: BroadcastChannel, ev: MessageEvent) => any)}
49
+ */
50
+ this.onmessageerror = null
47
51
  /**
48
52
  * @param {any} e
49
53
  */
@@ -79,8 +83,9 @@ const getChannel = room =>
79
83
  /**
80
84
  * @param {{data:ArrayBuffer}} e
81
85
  */
82
- /* c8 ignore next */
86
+ /* c8 ignore next 3 */
83
87
  bc.onmessage = e => subs.forEach(sub => sub(e.data, 'broadcastchannel'))
88
+ bc.onmessageerror = e => console.error('broadcastchannel error', e)
84
89
  return {
85
90
  bc, subs
86
91
  }
package/src/buffer.js CHANGED
@@ -34,17 +34,24 @@ export const createUint8ArrayFromArrayBuffer = buffer => new Uint8Array(buffer)
34
34
 
35
35
  /* c8 ignore start */
36
36
  /**
37
- * @param {Uint8Array} bytes
38
- * @return {string}
39
- */
40
- const toBase64Browser = bytes => {
41
- let s = ''
42
- for (let i = 0; i < bytes.byteLength; i++) {
43
- s += string.fromCharCode(bytes[i])
44
- }
45
- // eslint-disable-next-line no-undef
46
- return btoa(s)
47
- }
37
+ * Prefer native `Uint8Array.prototype.toBase64` (TC39 "Uint8Array to/from
38
+ * base64") when available; fall back to the btoa char-code loop for older
39
+ * browsers.
40
+ *
41
+ * @type {(bytes: Uint8Array) => string}
42
+ */
43
+ const toBase64Browser = /* @__PURE__ */(() =>
44
+ typeof (/** @type {any} */ (Uint8Array.prototype).toBase64) === 'function'
45
+ ? bytes => /** @type {any} */ (bytes).toBase64()
46
+ : bytes => {
47
+ let s = ''
48
+ for (let i = 0; i < bytes.byteLength; i++) {
49
+ s += string.fromCharCode(bytes[i])
50
+ }
51
+ // eslint-disable-next-line no-undef
52
+ return btoa(s)
53
+ }
54
+ )()
48
55
  /* c8 ignore stop */
49
56
 
50
57
  /**
@@ -55,18 +62,21 @@ const toBase64Node = bytes => Buffer.from(bytes.buffer, bytes.byteOffset, bytes.
55
62
 
56
63
  /* c8 ignore start */
57
64
  /**
58
- * @param {string} s
59
- * @return {Uint8Array<ArrayBuffer>}
60
- */
61
- const fromBase64Browser = s => {
62
- // eslint-disable-next-line no-undef
63
- const a = atob(s)
64
- const bytes = createUint8ArrayFromLen(a.length)
65
- for (let i = 0; i < a.length; i++) {
66
- bytes[i] = a.charCodeAt(i)
67
- }
68
- return bytes
69
- }
65
+ * @type {(s: string) => Uint8Array<ArrayBuffer>}
66
+ */
67
+ const fromBase64Browser = /* @__PURE__ */(() =>
68
+ typeof (/** @type {any} */ (Uint8Array).fromBase64) === 'function'
69
+ ? s => /** @type {any} */ (Uint8Array).fromBase64(s)
70
+ : s => {
71
+ // eslint-disable-next-line no-undef
72
+ const a = atob(s)
73
+ const bytes = createUint8ArrayFromLen(a.length)
74
+ for (let i = 0; i < a.length; i++) {
75
+ bytes[i] = a.charCodeAt(i)
76
+ }
77
+ return bytes
78
+ }
79
+ )()
70
80
  /* c8 ignore stop */
71
81
 
72
82
  /**
@@ -78,10 +88,10 @@ const fromBase64Node = s => {
78
88
  }
79
89
 
80
90
  /* c8 ignore next */
81
- export const toBase64 = env.isBrowser ? toBase64Browser : toBase64Node
91
+ export const toBase64 = /* @__PURE__ */(() => env.isBrowser ? toBase64Browser : toBase64Node)()
82
92
 
83
93
  /* c8 ignore next */
84
- export const fromBase64 = env.isBrowser ? fromBase64Browser : fromBase64Node
94
+ export const fromBase64 = /* @__PURE__ */(() => env.isBrowser ? fromBase64Browser : fromBase64Node)()
85
95
 
86
96
  /**
87
97
  * Implements base64url - see https://datatracker.ietf.org/doc/html/rfc4648#section-5
package/src/decoding.js CHANGED
@@ -387,7 +387,7 @@ export const _readVarStringNative = decoder =>
387
387
  *
388
388
  */
389
389
  /* c8 ignore next */
390
- export const readVarString = string.utf8TextDecoder ? _readVarStringNative : _readVarStringPolyfill
390
+ export const readVarString = /* @__PURE__ */(() => string.utf8TextDecoder ? _readVarStringNative : _readVarStringPolyfill)()
391
391
 
392
392
  /**
393
393
  * @param {Decoder} decoder