@tinta-lang/syntax 0.0.0-stage → 0.1.0-dev.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 (245) hide show
  1. package/LICENSE +21 -0
  2. package/THIRD_PARTY_NOTICES.txt +13651 -0
  3. package/dist/directive.d.ts +40 -0
  4. package/dist/editing.d.ts +46 -0
  5. package/dist/enrichment.d.ts +5 -0
  6. package/dist/expression.d.ts +26 -0
  7. package/dist/image-destinations.d.ts +3 -0
  8. package/dist/index.d.ts +8 -0
  9. package/dist/index.js +10118 -0
  10. package/dist/parser.d.ts +40 -0
  11. package/dist/registry.d.ts +144 -0
  12. package/dist/source.d.ts +28 -0
  13. package/package.json +280 -3
  14. package/parser-provenance.json +1419 -0
  15. package/patches/README.md +5 -0
  16. package/patches/micromark.patch +84 -0
  17. package/vendor/@noble/hashes/LICENSE +21 -0
  18. package/vendor/@noble/hashes/_md.js +209 -0
  19. package/vendor/@noble/hashes/_u64.js +77 -0
  20. package/vendor/@noble/hashes/package.json +91 -0
  21. package/vendor/@noble/hashes/sha2.js +446 -0
  22. package/vendor/@noble/hashes/utils.js +687 -0
  23. package/vendor/character-entities/index.js +2132 -0
  24. package/vendor/character-entities/license +22 -0
  25. package/vendor/character-entities/package.json +78 -0
  26. package/vendor/decode-named-character-reference/index.js +19 -0
  27. package/vendor/decode-named-character-reference/license +22 -0
  28. package/vendor/decode-named-character-reference/package.json +90 -0
  29. package/vendor/devlop/lib/default.js +9 -0
  30. package/vendor/devlop/license +22 -0
  31. package/vendor/devlop/package.json +80 -0
  32. package/vendor/longest-streak/index.js +36 -0
  33. package/vendor/longest-streak/license +22 -0
  34. package/vendor/longest-streak/package.json +73 -0
  35. package/vendor/markdown-table/index.js +393 -0
  36. package/vendor/markdown-table/license +22 -0
  37. package/vendor/markdown-table/package.json +77 -0
  38. package/vendor/mdast-util-from-markdown/index.js +2 -0
  39. package/vendor/mdast-util-from-markdown/lib/index.js +1270 -0
  40. package/vendor/mdast-util-from-markdown/license +22 -0
  41. package/vendor/mdast-util-from-markdown/package.json +98 -0
  42. package/vendor/mdast-util-gfm-strikethrough/index.js +5 -0
  43. package/vendor/mdast-util-gfm-strikethrough/lib/index.js +133 -0
  44. package/vendor/mdast-util-gfm-strikethrough/license +22 -0
  45. package/vendor/mdast-util-gfm-strikethrough/package.json +84 -0
  46. package/vendor/mdast-util-gfm-table/index.js +2 -0
  47. package/vendor/mdast-util-gfm-table/lib/index.js +300 -0
  48. package/vendor/mdast-util-gfm-table/license +22 -0
  49. package/vendor/mdast-util-gfm-table/package.json +101 -0
  50. package/vendor/mdast-util-gfm-task-list-item/index.js +4 -0
  51. package/vendor/mdast-util-gfm-task-list-item/lib/index.js +141 -0
  52. package/vendor/mdast-util-gfm-task-list-item/license +22 -0
  53. package/vendor/mdast-util-gfm-task-list-item/package.json +90 -0
  54. package/vendor/mdast-util-phrasing/index.js +1 -0
  55. package/vendor/mdast-util-phrasing/lib/index.js +45 -0
  56. package/vendor/mdast-util-phrasing/license +23 -0
  57. package/vendor/mdast-util-phrasing/package.json +78 -0
  58. package/vendor/mdast-util-to-markdown/index.js +3 -0
  59. package/vendor/mdast-util-to-markdown/lib/configure.js +98 -0
  60. package/vendor/mdast-util-to-markdown/lib/handle/blockquote.js +40 -0
  61. package/vendor/mdast-util-to-markdown/lib/handle/break.js +41 -0
  62. package/vendor/mdast-util-to-markdown/lib/handle/code.js +86 -0
  63. package/vendor/mdast-util-to-markdown/lib/handle/definition.js +83 -0
  64. package/vendor/mdast-util-to-markdown/lib/handle/emphasis.js +67 -0
  65. package/vendor/mdast-util-to-markdown/lib/handle/heading.js +84 -0
  66. package/vendor/mdast-util-to-markdown/lib/handle/html.js +27 -0
  67. package/vendor/mdast-util-to-markdown/lib/handle/image-reference.js +78 -0
  68. package/vendor/mdast-util-to-markdown/lib/handle/image.js +92 -0
  69. package/vendor/mdast-util-to-markdown/lib/handle/index.js +45 -0
  70. package/vendor/mdast-util-to-markdown/lib/handle/inline-code.js +86 -0
  71. package/vendor/mdast-util-to-markdown/lib/handle/link-reference.js +78 -0
  72. package/vendor/mdast-util-to-markdown/lib/handle/link.js +129 -0
  73. package/vendor/mdast-util-to-markdown/lib/handle/list-item.js +73 -0
  74. package/vendor/mdast-util-to-markdown/lib/handle/list.js +107 -0
  75. package/vendor/mdast-util-to-markdown/lib/handle/paragraph.js +27 -0
  76. package/vendor/mdast-util-to-markdown/lib/handle/root.js +34 -0
  77. package/vendor/mdast-util-to-markdown/lib/handle/strong.js +67 -0
  78. package/vendor/mdast-util-to-markdown/lib/handle/text.js +30 -0
  79. package/vendor/mdast-util-to-markdown/lib/handle/thematic-break.js +27 -0
  80. package/vendor/mdast-util-to-markdown/lib/index.js +213 -0
  81. package/vendor/mdast-util-to-markdown/lib/join.js +56 -0
  82. package/vendor/mdast-util-to-markdown/lib/unsafe.js +160 -0
  83. package/vendor/mdast-util-to-markdown/lib/util/association.js +33 -0
  84. package/vendor/mdast-util-to-markdown/lib/util/character.js +32 -0
  85. package/vendor/mdast-util-to-markdown/lib/util/check-bullet-ordered.js +25 -0
  86. package/vendor/mdast-util-to-markdown/lib/util/check-bullet-other.js +42 -0
  87. package/vendor/mdast-util-to-markdown/lib/util/check-bullet.js +25 -0
  88. package/vendor/mdast-util-to-markdown/lib/util/check-emphasis.js +25 -0
  89. package/vendor/mdast-util-to-markdown/lib/util/check-fence.js +25 -0
  90. package/vendor/mdast-util-to-markdown/lib/util/check-list-item-indent.js +25 -0
  91. package/vendor/mdast-util-to-markdown/lib/util/check-quote.js +25 -0
  92. package/vendor/mdast-util-to-markdown/lib/util/check-rule-repetition.js +25 -0
  93. package/vendor/mdast-util-to-markdown/lib/util/check-rule.js +25 -0
  94. package/vendor/mdast-util-to-markdown/lib/util/check-strong.js +25 -0
  95. package/vendor/mdast-util-to-markdown/lib/util/compile-pattern.js +30 -0
  96. package/vendor/mdast-util-to-markdown/lib/util/container-flow.js +93 -0
  97. package/vendor/mdast-util-to-markdown/lib/util/container-phrasing.js +704 -0
  98. package/vendor/mdast-util-to-markdown/lib/util/encode-character-reference.js +11 -0
  99. package/vendor/mdast-util-to-markdown/lib/util/encode-info.js +82 -0
  100. package/vendor/mdast-util-to-markdown/lib/util/format-code-as-indented.js +27 -0
  101. package/vendor/mdast-util-to-markdown/lib/util/format-heading-as-setext.js +39 -0
  102. package/vendor/mdast-util-to-markdown/lib/util/format-link-as-autolink.js +39 -0
  103. package/vendor/mdast-util-to-markdown/lib/util/html-kind.js +63 -0
  104. package/vendor/mdast-util-to-markdown/lib/util/indent-lines.js +40 -0
  105. package/vendor/mdast-util-to-markdown/lib/util/pattern-in-scope.js +52 -0
  106. package/vendor/mdast-util-to-markdown/lib/util/safe.js +263 -0
  107. package/vendor/mdast-util-to-markdown/lib/util/track.js +55 -0
  108. package/vendor/mdast-util-to-markdown/license +22 -0
  109. package/vendor/mdast-util-to-markdown/package.json +88 -0
  110. package/vendor/mdast-util-to-string/index.js +5 -0
  111. package/vendor/mdast-util-to-string/lib/index.js +108 -0
  112. package/vendor/mdast-util-to-string/license +22 -0
  113. package/vendor/mdast-util-to-string/package.json +78 -0
  114. package/vendor/micromark/index.js +60 -0
  115. package/vendor/micromark/lib/compile.js +1068 -0
  116. package/vendor/micromark/lib/constructs.js +85 -0
  117. package/vendor/micromark/lib/create-tokenizer.js +615 -0
  118. package/vendor/micromark/lib/initialize/content.js +79 -0
  119. package/vendor/micromark/lib/initialize/document.js +370 -0
  120. package/vendor/micromark/lib/initialize/flow.js +58 -0
  121. package/vendor/micromark/lib/initialize/text.js +216 -0
  122. package/vendor/micromark/lib/parse.js +56 -0
  123. package/vendor/micromark/lib/postprocess.js +18 -0
  124. package/vendor/micromark/lib/preprocess.js +112 -0
  125. package/vendor/micromark/license +22 -0
  126. package/vendor/micromark/package.json +87 -0
  127. package/vendor/micromark-core-commonmark/index.js +22 -0
  128. package/vendor/micromark-core-commonmark/lib/attention.js +231 -0
  129. package/vendor/micromark-core-commonmark/lib/autolink.js +233 -0
  130. package/vendor/micromark-core-commonmark/lib/blank-line.js +61 -0
  131. package/vendor/micromark-core-commonmark/lib/block-quote.js +143 -0
  132. package/vendor/micromark-core-commonmark/lib/character-escape.js +64 -0
  133. package/vendor/micromark-core-commonmark/lib/character-reference.js +149 -0
  134. package/vendor/micromark-core-commonmark/lib/code-fenced.js +422 -0
  135. package/vendor/micromark-core-commonmark/lib/code-indented.js +159 -0
  136. package/vendor/micromark-core-commonmark/lib/code-text.js +225 -0
  137. package/vendor/micromark-core-commonmark/lib/content.js +163 -0
  138. package/vendor/micromark-core-commonmark/lib/definition.js +254 -0
  139. package/vendor/micromark-core-commonmark/lib/hard-break-escape.js +60 -0
  140. package/vendor/micromark-core-commonmark/lib/heading-atx.js +191 -0
  141. package/vendor/micromark-core-commonmark/lib/html-flow.js +827 -0
  142. package/vendor/micromark-core-commonmark/lib/html-text.js +678 -0
  143. package/vendor/micromark-core-commonmark/lib/label-end.js +561 -0
  144. package/vendor/micromark-core-commonmark/lib/label-start-image.js +110 -0
  145. package/vendor/micromark-core-commonmark/lib/label-start-link.js +63 -0
  146. package/vendor/micromark-core-commonmark/lib/line-ending.js +33 -0
  147. package/vendor/micromark-core-commonmark/lib/list.js +213 -0
  148. package/vendor/micromark-core-commonmark/lib/partial-non-lazy-continuation.js +61 -0
  149. package/vendor/micromark-core-commonmark/lib/setext-underline.js +187 -0
  150. package/vendor/micromark-core-commonmark/lib/thematic-break.js +102 -0
  151. package/vendor/micromark-core-commonmark/license +22 -0
  152. package/vendor/micromark-core-commonmark/package.json +62 -0
  153. package/vendor/micromark-extension-gfm-strikethrough/index.js +3 -0
  154. package/vendor/micromark-extension-gfm-strikethrough/lib/html.js +26 -0
  155. package/vendor/micromark-extension-gfm-strikethrough/lib/syntax.js +142 -0
  156. package/vendor/micromark-extension-gfm-strikethrough/license +22 -0
  157. package/vendor/micromark-extension-gfm-strikethrough/package.json +129 -0
  158. package/vendor/micromark-extension-gfm-table/index.js +2 -0
  159. package/vendor/micromark-extension-gfm-table/lib/edit-map.js +222 -0
  160. package/vendor/micromark-extension-gfm-table/lib/html.js +135 -0
  161. package/vendor/micromark-extension-gfm-table/lib/infer.js +52 -0
  162. package/vendor/micromark-extension-gfm-table/lib/syntax.js +846 -0
  163. package/vendor/micromark-extension-gfm-table/license +22 -0
  164. package/vendor/micromark-extension-gfm-table/package.json +86 -0
  165. package/vendor/micromark-extension-gfm-task-list-item/index.js +2 -0
  166. package/vendor/micromark-extension-gfm-task-list-item/lib/html.js +29 -0
  167. package/vendor/micromark-extension-gfm-task-list-item/lib/syntax.js +158 -0
  168. package/vendor/micromark-extension-gfm-task-list-item/license +22 -0
  169. package/vendor/micromark-extension-gfm-task-list-item/package.json +131 -0
  170. package/vendor/micromark-factory-destination/index.js +206 -0
  171. package/vendor/micromark-factory-destination/license +22 -0
  172. package/vendor/micromark-factory-destination/package.json +57 -0
  173. package/vendor/micromark-factory-label/index.js +148 -0
  174. package/vendor/micromark-factory-label/license +22 -0
  175. package/vendor/micromark-factory-label/package.json +60 -0
  176. package/vendor/micromark-factory-space/index.js +116 -0
  177. package/vendor/micromark-factory-space/license +22 -0
  178. package/vendor/micromark-factory-space/package.json +46 -0
  179. package/vendor/micromark-factory-title/index.js +158 -0
  180. package/vendor/micromark-factory-title/license +22 -0
  181. package/vendor/micromark-factory-title/package.json +58 -0
  182. package/vendor/micromark-factory-whitespace/index.js +44 -0
  183. package/vendor/micromark-factory-whitespace/license +22 -0
  184. package/vendor/micromark-factory-whitespace/package.json +57 -0
  185. package/vendor/micromark-util-character/index.js +246 -0
  186. package/vendor/micromark-util-character/license +22 -0
  187. package/vendor/micromark-util-character/package.json +57 -0
  188. package/vendor/micromark-util-chunked/index.js +81 -0
  189. package/vendor/micromark-util-chunked/license +22 -0
  190. package/vendor/micromark-util-chunked/package.json +57 -0
  191. package/vendor/micromark-util-classify-character/index.js +27 -0
  192. package/vendor/micromark-util-classify-character/license +22 -0
  193. package/vendor/micromark-util-classify-character/package.json +59 -0
  194. package/vendor/micromark-util-combine-extensions/index.js +143 -0
  195. package/vendor/micromark-util-combine-extensions/license +22 -0
  196. package/vendor/micromark-util-combine-extensions/package.json +52 -0
  197. package/vendor/micromark-util-decode-numeric-character-reference/index.js +32 -0
  198. package/vendor/micromark-util-decode-numeric-character-reference/license +22 -0
  199. package/vendor/micromark-util-decode-numeric-character-reference/package.json +59 -0
  200. package/vendor/micromark-util-decode-string/index.js +45 -0
  201. package/vendor/micromark-util-decode-string/license +22 -0
  202. package/vendor/micromark-util-decode-string/package.json +63 -0
  203. package/vendor/micromark-util-edit-map/index.js +225 -0
  204. package/vendor/micromark-util-edit-map/license +22 -0
  205. package/vendor/micromark-util-edit-map/package.json +48 -0
  206. package/vendor/micromark-util-encode/index.js +33 -0
  207. package/vendor/micromark-util-encode/license +22 -0
  208. package/vendor/micromark-util-encode/package.json +47 -0
  209. package/vendor/micromark-util-html-tag-name/index.js +93 -0
  210. package/vendor/micromark-util-html-tag-name/license +22 -0
  211. package/vendor/micromark-util-html-tag-name/package.json +47 -0
  212. package/vendor/micromark-util-normalize-identifier/index.js +33 -0
  213. package/vendor/micromark-util-normalize-identifier/license +22 -0
  214. package/vendor/micromark-util-normalize-identifier/package.json +58 -0
  215. package/vendor/micromark-util-resolve-all/index.js +32 -0
  216. package/vendor/micromark-util-resolve-all/license +22 -0
  217. package/vendor/micromark-util-resolve-all/package.json +48 -0
  218. package/vendor/micromark-util-sanitize-uri/index.js +107 -0
  219. package/vendor/micromark-util-sanitize-uri/license +22 -0
  220. package/vendor/micromark-util-sanitize-uri/package.json +59 -0
  221. package/vendor/micromark-util-subtokenize/index.js +228 -0
  222. package/vendor/micromark-util-subtokenize/lib/splice-buffer.js +251 -0
  223. package/vendor/micromark-util-subtokenize/license +22 -0
  224. package/vendor/micromark-util-subtokenize/package.json +60 -0
  225. package/vendor/unist-util-is/index.js +7 -0
  226. package/vendor/unist-util-is/lib/index.js +296 -0
  227. package/vendor/unist-util-is/license +22 -0
  228. package/vendor/unist-util-is/package.json +103 -0
  229. package/vendor/unist-util-stringify-position/index.js +1 -0
  230. package/vendor/unist-util-stringify-position/lib/index.js +84 -0
  231. package/vendor/unist-util-stringify-position/license +22 -0
  232. package/vendor/unist-util-stringify-position/package.json +80 -0
  233. package/vendor/unist-util-visit/index.js +2 -0
  234. package/vendor/unist-util-visit/lib/index.js +312 -0
  235. package/vendor/unist-util-visit/license +22 -0
  236. package/vendor/unist-util-visit/package.json +108 -0
  237. package/vendor/unist-util-visit-parents/index.js +2 -0
  238. package/vendor/unist-util-visit-parents/lib/color.js +7 -0
  239. package/vendor/unist-util-visit-parents/lib/index.js +399 -0
  240. package/vendor/unist-util-visit-parents/license +22 -0
  241. package/vendor/unist-util-visit-parents/package.json +106 -0
  242. package/vendor/zwitch/index.js +118 -0
  243. package/vendor/zwitch/license +22 -0
  244. package/vendor/zwitch/package.json +72 -0
  245. package/README.md +0 -3
@@ -0,0 +1,251 @@
1
+ /**
2
+ * Some of the internal operations of micromark do lots of editing
3
+ * operations on very large arrays. This runs into problems with two
4
+ * properties of most circa-2020 JavaScript interpreters:
5
+ *
6
+ * - Array-length modifications at the high end of an array (push/pop) are
7
+ * expected to be common and are implemented in (amortized) time
8
+ * proportional to the number of elements added or removed, whereas
9
+ * other operations (shift/unshift and splice) are much less efficient.
10
+ * - Function arguments are passed on the stack, so adding tens of thousands
11
+ * of elements to an array with `arr.push(...newElements)` will frequently
12
+ * cause stack overflows. (see <https://stackoverflow.com/questions/22123769/rangeerror-maximum-call-stack-size-exceeded-why>)
13
+ *
14
+ * SpliceBuffers are an implementation of gap buffers, which are a
15
+ * generalization of the "queue made of two stacks" idea. The splice buffer
16
+ * maintains a cursor, and moving the cursor has cost proportional to the
17
+ * distance the cursor moves, but inserting, deleting, or splicing in
18
+ * new information at the cursor is as efficient as the push/pop operation.
19
+ * This allows for an efficient sequence of splices (or pushes, pops, shifts,
20
+ * or unshifts) as long such edits happen at the same part of the array or
21
+ * generally sweep through the array from the beginning to the end.
22
+ *
23
+ * The interface for splice buffers also supports large numbers of inputs by
24
+ * passing a single array argument rather passing multiple arguments on the
25
+ * function call stack.
26
+ *
27
+ * @template T
28
+ * Item type.
29
+ */
30
+ export class SpliceBuffer {
31
+ /**
32
+ * @param {ReadonlyArray<T> | null | undefined} [initial]
33
+ * Initial items (optional).
34
+ * @returns
35
+ * Splice buffer.
36
+ */
37
+ constructor(initial) {
38
+ /** @type {Array<T>} */
39
+ this.left = initial ? [...initial] : [];
40
+ /** @type {Array<T>} */
41
+ this.right = [];
42
+ }
43
+
44
+ /**
45
+ * Array access;
46
+ * does not move the cursor.
47
+ *
48
+ * @param {number} index
49
+ * Index.
50
+ * @return {T}
51
+ * Item.
52
+ */
53
+ get(index) {
54
+ if (index < 0 || index >= this.left.length + this.right.length) {
55
+ throw new RangeError('Cannot access index `' + index + '` in a splice buffer of size `' + (this.left.length + this.right.length) + '`');
56
+ }
57
+ if (index < this.left.length) return this.left[index];
58
+ return this.right[this.right.length - index + this.left.length - 1];
59
+ }
60
+
61
+ /**
62
+ * The length of the splice buffer, one greater than the largest index in the
63
+ * array.
64
+ */
65
+ get length() {
66
+ return this.left.length + this.right.length;
67
+ }
68
+
69
+ /**
70
+ * Remove and return `list[0]`;
71
+ * moves the cursor to `0`.
72
+ *
73
+ * @returns {T | undefined}
74
+ * Item, optional.
75
+ */
76
+ shift() {
77
+ this.setCursor(0);
78
+ return this.right.pop();
79
+ }
80
+
81
+ /**
82
+ * Slice the buffer to get an array;
83
+ * does not move the cursor.
84
+ *
85
+ * @param {number} start
86
+ * Start.
87
+ * @param {number | null | undefined} [end]
88
+ * End (optional).
89
+ * @returns {Array<T>}
90
+ * Array of items.
91
+ */
92
+ slice(start, end) {
93
+ /** @type {number} */
94
+ const stop = end === null || end === undefined ? Number.POSITIVE_INFINITY : end;
95
+ if (stop < this.left.length) {
96
+ return this.left.slice(start, stop);
97
+ }
98
+ if (start > this.left.length) {
99
+ return this.right.slice(this.right.length - stop + this.left.length, this.right.length - start + this.left.length).reverse();
100
+ }
101
+ return this.left.slice(start).concat(this.right.slice(this.right.length - stop + this.left.length).reverse());
102
+ }
103
+
104
+ /**
105
+ * Mimics the behavior of Array.prototype.splice() except for the change of
106
+ * interface necessary to avoid segfaults when patching in very large arrays.
107
+ *
108
+ * This operation moves cursor is moved to `start` and results in the cursor
109
+ * placed after any inserted items.
110
+ *
111
+ * @param {number} start
112
+ * Start;
113
+ * zero-based index at which to start changing the array;
114
+ * negative numbers count backwards from the end of the array and values
115
+ * that are out-of bounds are clamped to the appropriate end of the array.
116
+ * @param {number | null | undefined} [deleteCount=0]
117
+ * Delete count (default: `0`);
118
+ * maximum number of elements to delete, starting from start.
119
+ * @param {Array<T> | null | undefined} [items=[]]
120
+ * Items to include in place of the deleted items (default: `[]`).
121
+ * @return {Array<T>}
122
+ * Any removed items.
123
+ */
124
+ splice(start, deleteCount, items) {
125
+ /** @type {number} */
126
+ const count = deleteCount || 0;
127
+ this.setCursor(Math.trunc(start));
128
+ const removed = this.right.splice(this.right.length - count, Number.POSITIVE_INFINITY);
129
+ if (items) chunkedPush(this.left, items);
130
+ return removed.reverse();
131
+ }
132
+
133
+ /**
134
+ * Remove and return the highest-numbered item in the array, so
135
+ * `list[list.length - 1]`;
136
+ * Moves the cursor to `length`.
137
+ *
138
+ * @returns {T | undefined}
139
+ * Item, optional.
140
+ */
141
+ pop() {
142
+ this.setCursor(Number.POSITIVE_INFINITY);
143
+ return this.left.pop();
144
+ }
145
+
146
+ /**
147
+ * Inserts a single item to the high-numbered side of the array;
148
+ * moves the cursor to `length`.
149
+ *
150
+ * @param {T} item
151
+ * Item.
152
+ * @returns {undefined}
153
+ * Nothing.
154
+ */
155
+ push(item) {
156
+ this.setCursor(Number.POSITIVE_INFINITY);
157
+ this.left.push(item);
158
+ }
159
+
160
+ /**
161
+ * Inserts many items to the high-numbered side of the array.
162
+ * Moves the cursor to `length`.
163
+ *
164
+ * @param {Array<T>} items
165
+ * Items.
166
+ * @returns {undefined}
167
+ * Nothing.
168
+ */
169
+ pushMany(items) {
170
+ this.setCursor(Number.POSITIVE_INFINITY);
171
+ chunkedPush(this.left, items);
172
+ }
173
+
174
+ /**
175
+ * Inserts a single item to the low-numbered side of the array;
176
+ * Moves the cursor to `0`.
177
+ *
178
+ * @param {T} item
179
+ * Item.
180
+ * @returns {undefined}
181
+ * Nothing.
182
+ */
183
+ unshift(item) {
184
+ this.setCursor(0);
185
+ this.right.push(item);
186
+ }
187
+
188
+ /**
189
+ * Inserts many items to the low-numbered side of the array;
190
+ * moves the cursor to `0`.
191
+ *
192
+ * @param {Array<T>} items
193
+ * Items.
194
+ * @returns {undefined}
195
+ * Nothing.
196
+ */
197
+ unshiftMany(items) {
198
+ this.setCursor(0);
199
+ chunkedPush(this.right, items.reverse());
200
+ }
201
+
202
+ /**
203
+ * Move the cursor to a specific position in the array. Requires
204
+ * time proportional to the distance moved.
205
+ *
206
+ * If `n < 0`, the cursor will end up at the beginning.
207
+ * If `n > length`, the cursor will end up at the end.
208
+ *
209
+ * @param {number} n
210
+ * Position.
211
+ * @return {undefined}
212
+ * Nothing.
213
+ */
214
+ setCursor(n) {
215
+ if (n === this.left.length || n > this.left.length && this.right.length === 0 || n < 0 && this.left.length === 0) return;
216
+ if (n < this.left.length) {
217
+ // Move cursor to the this.left
218
+ const removed = this.left.splice(n, Number.POSITIVE_INFINITY);
219
+ chunkedPush(this.right, removed.reverse());
220
+ } else {
221
+ // Move cursor to the this.right
222
+ const removed = this.right.splice(this.left.length + this.right.length - n, Number.POSITIVE_INFINITY);
223
+ chunkedPush(this.left, removed.reverse());
224
+ }
225
+ }
226
+ }
227
+
228
+ /**
229
+ * Avoid stack overflow by pushing items onto the stack in segments
230
+ *
231
+ * @template T
232
+ * Item type.
233
+ * @param {Array<T>} list
234
+ * List to inject into.
235
+ * @param {ReadonlyArray<T>} right
236
+ * Items to inject.
237
+ * @return {undefined}
238
+ * Nothing.
239
+ */
240
+ function chunkedPush(list, right) {
241
+ /** @type {number} */
242
+ let chunkStart = 0;
243
+ if (right.length < 10000) {
244
+ list.push(...right);
245
+ } else {
246
+ while (chunkStart < right.length) {
247
+ list.push(...right.slice(chunkStart, chunkStart + 10000));
248
+ chunkStart += 10000;
249
+ }
250
+ }
251
+ }
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) Titus Wormer <tituswormer@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "micromark-util-subtokenize",
3
+ "version": "2.1.0",
4
+ "description": "micromark utility to tokenize subtokens",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "micromark",
8
+ "util",
9
+ "utility",
10
+ "tokenize"
11
+ ],
12
+ "repository": "https://github.com/micromark/micromark/tree/main/packages/micromark-util-subtokenize",
13
+ "bugs": "https://github.com/micromark/micromark/issues",
14
+ "funding": [
15
+ {
16
+ "type": "GitHub Sponsors",
17
+ "url": "https://github.com/sponsors/unifiedjs"
18
+ },
19
+ {
20
+ "type": "OpenCollective",
21
+ "url": "https://opencollective.com/unified"
22
+ }
23
+ ],
24
+ "author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
25
+ "contributors": [
26
+ "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
27
+ ],
28
+ "sideEffects": false,
29
+ "type": "module",
30
+ "files": [
31
+ "dev/",
32
+ "lib/",
33
+ "index.d.ts.map",
34
+ "index.d.ts",
35
+ "index.js"
36
+ ],
37
+ "exports": {
38
+ "development": "./dev/index.js",
39
+ "default": "./index.js"
40
+ },
41
+ "dependencies": {
42
+ "devlop": "^1.0.0",
43
+ "micromark-util-chunked": "^2.0.0",
44
+ "micromark-util-symbol": "^2.0.0",
45
+ "micromark-util-types": "^2.0.0"
46
+ },
47
+ "scripts": {
48
+ "build": "micromark-build"
49
+ },
50
+ "xo": {
51
+ "envs": [
52
+ "shared-node-browser"
53
+ ],
54
+ "prettier": true,
55
+ "rules": {
56
+ "max-depth": "off",
57
+ "unicorn/prefer-code-point": "off"
58
+ }
59
+ }
60
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @typedef {import('./lib/index.js').Check} Check
3
+ * @typedef {import('./lib/index.js').Test} Test
4
+ * @typedef {import('./lib/index.js').TestFunction} TestFunction
5
+ */
6
+
7
+ export {is, convert} from './lib/index.js'
@@ -0,0 +1,296 @@
1
+ /**
2
+ * @import {Node, Parent} from 'unist'
3
+ */
4
+
5
+ /**
6
+ * @template Fn
7
+ * @template Fallback
8
+ * @typedef {Fn extends (value: any) => value is infer Thing ? Thing : Fallback} Predicate
9
+ */
10
+
11
+ /**
12
+ * @callback Check
13
+ * Check that an arbitrary value is a node.
14
+ * @param {unknown} this
15
+ * The given context.
16
+ * @param {unknown} [node]
17
+ * Anything (typically a node).
18
+ * @param {number | null | undefined} [index]
19
+ * The node’s position in its parent.
20
+ * @param {Parent | null | undefined} [parent]
21
+ * The node’s parent.
22
+ * @returns {boolean}
23
+ * Whether this is a node and passes a test.
24
+ *
25
+ * @typedef {Record<string, unknown> | Node} Props
26
+ * Object to check for equivalence.
27
+ *
28
+ * Note: `Node` is included as it is common but is not indexable.
29
+ *
30
+ * @typedef {Array<Props | TestFunction | string> | ReadonlyArray<Props | TestFunction | string> | Props | TestFunction | string | null | undefined} Test
31
+ * Check for an arbitrary node.
32
+ *
33
+ * @callback TestFunction
34
+ * Check if a node passes a test.
35
+ * @param {unknown} this
36
+ * The given context.
37
+ * @param {Node} node
38
+ * A node.
39
+ * @param {number | undefined} [index]
40
+ * The node’s position in its parent.
41
+ * @param {Parent | undefined} [parent]
42
+ * The node’s parent.
43
+ * @returns {boolean | undefined | void}
44
+ * Whether this node passes the test.
45
+ *
46
+ * Note: `void` is included until TS sees no return as `undefined`.
47
+ */
48
+
49
+ /**
50
+ * Check if `node` is a `Node` and whether it passes the given test.
51
+ *
52
+ * @param {unknown} node
53
+ * Thing to check, typically `Node`.
54
+ * @param {Test} test
55
+ * A check for a specific node.
56
+ * @param {number | null | undefined} index
57
+ * The node’s position in its parent.
58
+ * @param {Parent | null | undefined} parent
59
+ * The node’s parent.
60
+ * @param {unknown} context
61
+ * Context object (`this`) to pass to `test` functions.
62
+ * @returns {boolean}
63
+ * Whether `node` is a node and passes a test.
64
+ */
65
+ export const is =
66
+ // Note: overloads in JSDoc can’t yet use different `@template`s.
67
+ /**
68
+ * @type {(
69
+ * (<Condition extends ReadonlyArray<string>>(node: unknown, test: Condition, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition[number]}) &
70
+ * (<Condition extends Array<string>>(node: unknown, test: Condition, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition[number]}) &
71
+ * (<Condition extends string>(node: unknown, test: Condition, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) &
72
+ * (<Condition extends Props>(node: unknown, test: Condition, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) &
73
+ * (<Condition extends TestFunction>(node: unknown, test: Condition, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate<Condition, Node>) &
74
+ * ((node?: null | undefined) => false) &
75
+ * ((node: unknown, test?: null | undefined, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node) &
76
+ * ((node: unknown, test?: Test, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => boolean)
77
+ * )}
78
+ */
79
+ (
80
+ /**
81
+ * @param {unknown} [node]
82
+ * @param {Test} [test]
83
+ * @param {number | null | undefined} [index]
84
+ * @param {Parent | null | undefined} [parent]
85
+ * @param {unknown} [context]
86
+ * @returns {boolean}
87
+ */
88
+ // eslint-disable-next-line max-params
89
+ function (node, test, index, parent, context) {
90
+ const check = convert(test)
91
+
92
+ if (
93
+ index !== undefined &&
94
+ index !== null &&
95
+ (typeof index !== 'number' ||
96
+ index < 0 ||
97
+ index === Number.POSITIVE_INFINITY)
98
+ ) {
99
+ throw new Error('Expected positive finite index')
100
+ }
101
+
102
+ if (
103
+ parent !== undefined &&
104
+ parent !== null &&
105
+ (!is(parent) || !parent.children)
106
+ ) {
107
+ throw new Error('Expected parent node')
108
+ }
109
+
110
+ if (
111
+ (parent === undefined || parent === null) !==
112
+ (index === undefined || index === null)
113
+ ) {
114
+ throw new Error('Expected both parent and index')
115
+ }
116
+
117
+ return looksLikeANode(node)
118
+ ? check.call(context, node, index, parent)
119
+ : false
120
+ }
121
+ )
122
+
123
+ /**
124
+ * Generate an assertion from a test.
125
+ *
126
+ * Useful if you’re going to test many nodes, for example when creating a
127
+ * utility where something else passes a compatible test.
128
+ *
129
+ * The created function is a bit faster because it expects valid input only:
130
+ * a `node`, `index`, and `parent`.
131
+ *
132
+ * @param {Test} test
133
+ * * when nullish, checks if `node` is a `Node`.
134
+ * * when `string`, works like passing `(node) => node.type === test`.
135
+ * * when `function` checks if function passed the node is true.
136
+ * * when `object`, checks that all keys in test are in node, and that they have (strictly) equal values.
137
+ * * when `array`, checks if any one of the subtests pass.
138
+ * @returns {Check}
139
+ * An assertion.
140
+ */
141
+ export const convert =
142
+ // Note: overloads in JSDoc can’t yet use different `@template`s.
143
+ /**
144
+ * @type {(
145
+ * (<Condition extends string>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) &
146
+ * (<Condition extends Props>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) &
147
+ * (<Condition extends TestFunction>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate<Condition, Node>) &
148
+ * ((test?: null | undefined) => (node?: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node) &
149
+ * ((test?: Test) => Check)
150
+ * )}
151
+ */
152
+ (
153
+ /**
154
+ * @param {Test} [test]
155
+ * @returns {Check}
156
+ */
157
+ function (test) {
158
+ if (test === null || test === undefined) {
159
+ return ok
160
+ }
161
+
162
+ if (typeof test === 'function') {
163
+ return castFactory(test)
164
+ }
165
+
166
+ if (typeof test === 'object') {
167
+ return Array.isArray(test)
168
+ ? anyFactory(test)
169
+ : // Cast because `ReadonlyArray` goes into the above but `isArray`
170
+ // narrows to `Array`.
171
+ propertiesFactory(/** @type {Props} */ (test))
172
+ }
173
+
174
+ if (typeof test === 'string') {
175
+ return typeFactory(test)
176
+ }
177
+
178
+ throw new Error('Expected function, string, or object as test')
179
+ }
180
+ )
181
+
182
+ /**
183
+ * @param {Array<Props | TestFunction | string>} tests
184
+ * @returns {Check}
185
+ */
186
+ function anyFactory(tests) {
187
+ /** @type {Array<Check>} */
188
+ const checks = []
189
+ let index = -1
190
+
191
+ while (++index < tests.length) {
192
+ checks[index] = convert(tests[index])
193
+ }
194
+
195
+ return castFactory(any)
196
+
197
+ /**
198
+ * @this {unknown}
199
+ * @type {TestFunction}
200
+ */
201
+ function any(...parameters) {
202
+ let index = -1
203
+
204
+ while (++index < checks.length) {
205
+ if (checks[index].apply(this, parameters)) return true
206
+ }
207
+
208
+ return false
209
+ }
210
+ }
211
+
212
+ /**
213
+ * Turn an object into a test for a node with a certain fields.
214
+ *
215
+ * @param {Props} check
216
+ * @returns {Check}
217
+ */
218
+ function propertiesFactory(check) {
219
+ const checkAsRecord = /** @type {Record<string, unknown>} */ (check)
220
+
221
+ return castFactory(all)
222
+
223
+ /**
224
+ * @param {Node} node
225
+ * @returns {boolean}
226
+ */
227
+ function all(node) {
228
+ const nodeAsRecord = /** @type {Record<string, unknown>} */ (
229
+ /** @type {unknown} */ (node)
230
+ )
231
+
232
+ /** @type {string} */
233
+ let key
234
+
235
+ for (key in check) {
236
+ if (nodeAsRecord[key] !== checkAsRecord[key]) return false
237
+ }
238
+
239
+ return true
240
+ }
241
+ }
242
+
243
+ /**
244
+ * Turn a string into a test for a node with a certain type.
245
+ *
246
+ * @param {string} check
247
+ * @returns {Check}
248
+ */
249
+ function typeFactory(check) {
250
+ return castFactory(type)
251
+
252
+ /**
253
+ * @param {Node} node
254
+ */
255
+ function type(node) {
256
+ return node && node.type === check
257
+ }
258
+ }
259
+
260
+ /**
261
+ * Turn a custom test into a test for a node that passes that test.
262
+ *
263
+ * @param {TestFunction} testFunction
264
+ * @returns {Check}
265
+ */
266
+ function castFactory(testFunction) {
267
+ return check
268
+
269
+ /**
270
+ * @this {unknown}
271
+ * @type {Check}
272
+ */
273
+ function check(value, index, parent) {
274
+ return Boolean(
275
+ looksLikeANode(value) &&
276
+ testFunction.call(
277
+ this,
278
+ value,
279
+ typeof index === 'number' ? index : undefined,
280
+ parent || undefined
281
+ )
282
+ )
283
+ }
284
+ }
285
+
286
+ function ok() {
287
+ return true
288
+ }
289
+
290
+ /**
291
+ * @param {unknown} value
292
+ * @returns {value is Node}
293
+ */
294
+ function looksLikeANode(value) {
295
+ return value !== null && typeof value === 'object' && 'type' in value
296
+ }
@@ -0,0 +1,22 @@
1
+ (The MIT license)
2
+
3
+ Copyright (c) 2015 Titus Wormer <tituswormer@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.