llms-py 3.0.0b6__py3-none-any.whl → 3.0.0b8__py3-none-any.whl

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 (181) hide show
  1. llms/__pycache__/main.cpython-314.pyc +0 -0
  2. llms/{ui/modules/analytics.mjs → extensions/analytics/ui/index.mjs} +55 -164
  3. llms/extensions/app/__init__.py +519 -0
  4. llms/extensions/app/__pycache__/__init__.cpython-314.pyc +0 -0
  5. llms/extensions/app/__pycache__/db.cpython-314.pyc +0 -0
  6. llms/extensions/app/__pycache__/db_manager.cpython-314.pyc +0 -0
  7. llms/extensions/app/db.py +641 -0
  8. llms/extensions/app/db_manager.py +195 -0
  9. llms/extensions/app/requests.json +9073 -0
  10. llms/extensions/app/threads.json +15290 -0
  11. llms/{ui/modules/threads → extensions/app/ui}/Recents.mjs +82 -55
  12. llms/{ui/modules/threads → extensions/app/ui}/index.mjs +83 -20
  13. llms/extensions/app/ui/threadStore.mjs +407 -0
  14. llms/extensions/core_tools/__init__.py +598 -0
  15. llms/extensions/core_tools/__pycache__/__init__.cpython-314.pyc +0 -0
  16. llms/extensions/core_tools/ui/codemirror/addon/edit/closebrackets.js +201 -0
  17. llms/extensions/core_tools/ui/codemirror/addon/edit/closetag.js +185 -0
  18. llms/extensions/core_tools/ui/codemirror/addon/edit/continuelist.js +101 -0
  19. llms/extensions/core_tools/ui/codemirror/addon/edit/matchbrackets.js +160 -0
  20. llms/extensions/core_tools/ui/codemirror/addon/edit/matchtags.js +66 -0
  21. llms/extensions/core_tools/ui/codemirror/addon/edit/trailingspace.js +27 -0
  22. llms/extensions/core_tools/ui/codemirror/addon/selection/active-line.js +72 -0
  23. llms/extensions/core_tools/ui/codemirror/addon/selection/mark-selection.js +119 -0
  24. llms/extensions/core_tools/ui/codemirror/addon/selection/selection-pointer.js +98 -0
  25. llms/extensions/core_tools/ui/codemirror/doc/docs.css +225 -0
  26. llms/extensions/core_tools/ui/codemirror/doc/source_sans.woff +0 -0
  27. llms/extensions/core_tools/ui/codemirror/lib/codemirror.css +344 -0
  28. llms/extensions/core_tools/ui/codemirror/lib/codemirror.js +9884 -0
  29. llms/extensions/core_tools/ui/codemirror/mode/clike/clike.js +942 -0
  30. llms/extensions/core_tools/ui/codemirror/mode/javascript/index.html +118 -0
  31. llms/extensions/core_tools/ui/codemirror/mode/javascript/javascript.js +962 -0
  32. llms/extensions/core_tools/ui/codemirror/mode/javascript/typescript.html +62 -0
  33. llms/extensions/core_tools/ui/codemirror/mode/python/python.js +402 -0
  34. llms/extensions/core_tools/ui/codemirror/theme/dracula.css +40 -0
  35. llms/extensions/core_tools/ui/codemirror/theme/mocha.css +135 -0
  36. llms/extensions/core_tools/ui/index.mjs +650 -0
  37. llms/extensions/gallery/__init__.py +61 -0
  38. llms/extensions/gallery/__pycache__/__init__.cpython-314.pyc +0 -0
  39. llms/extensions/gallery/__pycache__/db.cpython-314.pyc +0 -0
  40. llms/extensions/gallery/db.py +298 -0
  41. llms/extensions/gallery/ui/index.mjs +481 -0
  42. llms/extensions/katex/__init__.py +6 -0
  43. llms/extensions/katex/__pycache__/__init__.cpython-314.pyc +0 -0
  44. llms/extensions/katex/ui/README.md +125 -0
  45. llms/extensions/katex/ui/contrib/auto-render.js +338 -0
  46. llms/extensions/katex/ui/contrib/auto-render.min.js +1 -0
  47. llms/extensions/katex/ui/contrib/auto-render.mjs +244 -0
  48. llms/extensions/katex/ui/contrib/copy-tex.js +127 -0
  49. llms/extensions/katex/ui/contrib/copy-tex.min.js +1 -0
  50. llms/extensions/katex/ui/contrib/copy-tex.mjs +105 -0
  51. llms/extensions/katex/ui/contrib/mathtex-script-type.js +109 -0
  52. llms/extensions/katex/ui/contrib/mathtex-script-type.min.js +1 -0
  53. llms/extensions/katex/ui/contrib/mathtex-script-type.mjs +24 -0
  54. llms/extensions/katex/ui/contrib/mhchem.js +3213 -0
  55. llms/extensions/katex/ui/contrib/mhchem.min.js +1 -0
  56. llms/extensions/katex/ui/contrib/mhchem.mjs +3109 -0
  57. llms/extensions/katex/ui/contrib/render-a11y-string.js +887 -0
  58. llms/extensions/katex/ui/contrib/render-a11y-string.min.js +1 -0
  59. llms/extensions/katex/ui/contrib/render-a11y-string.mjs +800 -0
  60. llms/extensions/katex/ui/fonts/KaTeX_AMS-Regular.ttf +0 -0
  61. llms/extensions/katex/ui/fonts/KaTeX_AMS-Regular.woff +0 -0
  62. llms/extensions/katex/ui/fonts/KaTeX_AMS-Regular.woff2 +0 -0
  63. llms/extensions/katex/ui/fonts/KaTeX_Caligraphic-Bold.ttf +0 -0
  64. llms/extensions/katex/ui/fonts/KaTeX_Caligraphic-Bold.woff +0 -0
  65. llms/extensions/katex/ui/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
  66. llms/extensions/katex/ui/fonts/KaTeX_Caligraphic-Regular.ttf +0 -0
  67. llms/extensions/katex/ui/fonts/KaTeX_Caligraphic-Regular.woff +0 -0
  68. llms/extensions/katex/ui/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
  69. llms/extensions/katex/ui/fonts/KaTeX_Fraktur-Bold.ttf +0 -0
  70. llms/extensions/katex/ui/fonts/KaTeX_Fraktur-Bold.woff +0 -0
  71. llms/extensions/katex/ui/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
  72. llms/extensions/katex/ui/fonts/KaTeX_Fraktur-Regular.ttf +0 -0
  73. llms/extensions/katex/ui/fonts/KaTeX_Fraktur-Regular.woff +0 -0
  74. llms/extensions/katex/ui/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
  75. llms/extensions/katex/ui/fonts/KaTeX_Main-Bold.ttf +0 -0
  76. llms/extensions/katex/ui/fonts/KaTeX_Main-Bold.woff +0 -0
  77. llms/extensions/katex/ui/fonts/KaTeX_Main-Bold.woff2 +0 -0
  78. llms/extensions/katex/ui/fonts/KaTeX_Main-BoldItalic.ttf +0 -0
  79. llms/extensions/katex/ui/fonts/KaTeX_Main-BoldItalic.woff +0 -0
  80. llms/extensions/katex/ui/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
  81. llms/extensions/katex/ui/fonts/KaTeX_Main-Italic.ttf +0 -0
  82. llms/extensions/katex/ui/fonts/KaTeX_Main-Italic.woff +0 -0
  83. llms/extensions/katex/ui/fonts/KaTeX_Main-Italic.woff2 +0 -0
  84. llms/extensions/katex/ui/fonts/KaTeX_Main-Regular.ttf +0 -0
  85. llms/extensions/katex/ui/fonts/KaTeX_Main-Regular.woff +0 -0
  86. llms/extensions/katex/ui/fonts/KaTeX_Main-Regular.woff2 +0 -0
  87. llms/extensions/katex/ui/fonts/KaTeX_Math-BoldItalic.ttf +0 -0
  88. llms/extensions/katex/ui/fonts/KaTeX_Math-BoldItalic.woff +0 -0
  89. llms/extensions/katex/ui/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
  90. llms/extensions/katex/ui/fonts/KaTeX_Math-Italic.ttf +0 -0
  91. llms/extensions/katex/ui/fonts/KaTeX_Math-Italic.woff +0 -0
  92. llms/extensions/katex/ui/fonts/KaTeX_Math-Italic.woff2 +0 -0
  93. llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Bold.ttf +0 -0
  94. llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Bold.woff +0 -0
  95. llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
  96. llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Italic.ttf +0 -0
  97. llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Italic.woff +0 -0
  98. llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
  99. llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Regular.ttf +0 -0
  100. llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Regular.woff +0 -0
  101. llms/extensions/katex/ui/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
  102. llms/extensions/katex/ui/fonts/KaTeX_Script-Regular.ttf +0 -0
  103. llms/extensions/katex/ui/fonts/KaTeX_Script-Regular.woff +0 -0
  104. llms/extensions/katex/ui/fonts/KaTeX_Script-Regular.woff2 +0 -0
  105. llms/extensions/katex/ui/fonts/KaTeX_Size1-Regular.ttf +0 -0
  106. llms/extensions/katex/ui/fonts/KaTeX_Size1-Regular.woff +0 -0
  107. llms/extensions/katex/ui/fonts/KaTeX_Size1-Regular.woff2 +0 -0
  108. llms/extensions/katex/ui/fonts/KaTeX_Size2-Regular.ttf +0 -0
  109. llms/extensions/katex/ui/fonts/KaTeX_Size2-Regular.woff +0 -0
  110. llms/extensions/katex/ui/fonts/KaTeX_Size2-Regular.woff2 +0 -0
  111. llms/extensions/katex/ui/fonts/KaTeX_Size3-Regular.ttf +0 -0
  112. llms/extensions/katex/ui/fonts/KaTeX_Size3-Regular.woff +0 -0
  113. llms/extensions/katex/ui/fonts/KaTeX_Size3-Regular.woff2 +0 -0
  114. llms/extensions/katex/ui/fonts/KaTeX_Size4-Regular.ttf +0 -0
  115. llms/extensions/katex/ui/fonts/KaTeX_Size4-Regular.woff +0 -0
  116. llms/extensions/katex/ui/fonts/KaTeX_Size4-Regular.woff2 +0 -0
  117. llms/extensions/katex/ui/fonts/KaTeX_Typewriter-Regular.ttf +0 -0
  118. llms/extensions/katex/ui/fonts/KaTeX_Typewriter-Regular.woff +0 -0
  119. llms/extensions/katex/ui/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
  120. llms/extensions/katex/ui/index.mjs +92 -0
  121. llms/extensions/katex/ui/katex-swap.css +1230 -0
  122. llms/extensions/katex/ui/katex-swap.min.css +1 -0
  123. llms/extensions/katex/ui/katex.css +1230 -0
  124. llms/extensions/katex/ui/katex.js +19080 -0
  125. llms/extensions/katex/ui/katex.min.css +1 -0
  126. llms/extensions/katex/ui/katex.min.js +1 -0
  127. llms/extensions/katex/ui/katex.min.mjs +1 -0
  128. llms/extensions/katex/ui/katex.mjs +18547 -0
  129. llms/extensions/providers/__init__.py +18 -0
  130. llms/extensions/providers/__pycache__/__init__.cpython-314.pyc +0 -0
  131. llms/extensions/providers/__pycache__/anthropic.cpython-314.pyc +0 -0
  132. llms/extensions/providers/__pycache__/chutes.cpython-314.pyc +0 -0
  133. llms/extensions/providers/__pycache__/google.cpython-314.pyc +0 -0
  134. llms/{providers → extensions/providers}/__pycache__/nvidia.cpython-314.pyc +0 -0
  135. llms/{providers → extensions/providers}/__pycache__/openai.cpython-314.pyc +0 -0
  136. llms/extensions/providers/__pycache__/openrouter.cpython-314.pyc +0 -0
  137. llms/{providers → extensions/providers}/anthropic.py +45 -5
  138. llms/{providers → extensions/providers}/chutes.py +21 -18
  139. llms/{providers → extensions/providers}/google.py +99 -27
  140. llms/{providers → extensions/providers}/nvidia.py +6 -8
  141. llms/{providers → extensions/providers}/openai.py +3 -6
  142. llms/{providers → extensions/providers}/openrouter.py +12 -10
  143. llms/extensions/system_prompts/__init__.py +45 -0
  144. llms/extensions/system_prompts/__pycache__/__init__.cpython-314.pyc +0 -0
  145. llms/extensions/system_prompts/ui/index.mjs +285 -0
  146. llms/extensions/system_prompts/ui/prompts.json +1067 -0
  147. llms/extensions/tools/__init__.py +5 -0
  148. llms/extensions/tools/__pycache__/__init__.cpython-314.pyc +0 -0
  149. llms/{ui/modules/tools.mjs → extensions/tools/ui/index.mjs} +12 -10
  150. llms/index.html +26 -38
  151. llms/llms.json +20 -1
  152. llms/main.py +845 -245
  153. llms/providers-extra.json +0 -32
  154. llms/ui/App.mjs +18 -20
  155. llms/ui/ai.mjs +38 -15
  156. llms/ui/app.css +1440 -59
  157. llms/ui/ctx.mjs +154 -18
  158. llms/ui/index.mjs +17 -14
  159. llms/ui/lib/vue.min.mjs +10 -9
  160. llms/ui/lib/vue.mjs +1796 -1635
  161. llms/ui/markdown.mjs +4 -2
  162. llms/ui/modules/chat/ChatBody.mjs +101 -334
  163. llms/ui/modules/chat/HomeTools.mjs +12 -0
  164. llms/ui/modules/chat/SettingsDialog.mjs +1 -1
  165. llms/ui/modules/chat/index.mjs +351 -314
  166. llms/ui/modules/layout.mjs +2 -26
  167. llms/ui/modules/model-selector.mjs +3 -3
  168. llms/ui/tailwind.input.css +35 -1
  169. llms/ui/utils.mjs +33 -3
  170. {llms_py-3.0.0b6.dist-info → llms_py-3.0.0b8.dist-info}/METADATA +1 -1
  171. llms_py-3.0.0b8.dist-info/RECORD +198 -0
  172. llms/providers/__pycache__/anthropic.cpython-314.pyc +0 -0
  173. llms/providers/__pycache__/chutes.cpython-314.pyc +0 -0
  174. llms/providers/__pycache__/google.cpython-314.pyc +0 -0
  175. llms/providers/__pycache__/openrouter.cpython-314.pyc +0 -0
  176. llms/ui/modules/threads/threadStore.mjs +0 -586
  177. llms_py-3.0.0b6.dist-info/RECORD +0 -66
  178. {llms_py-3.0.0b6.dist-info → llms_py-3.0.0b8.dist-info}/WHEEL +0 -0
  179. {llms_py-3.0.0b6.dist-info → llms_py-3.0.0b8.dist-info}/entry_points.txt +0 -0
  180. {llms_py-3.0.0b6.dist-info → llms_py-3.0.0b8.dist-info}/licenses/LICENSE +0 -0
  181. {llms_py-3.0.0b6.dist-info → llms_py-3.0.0b8.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,338 @@
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if(typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory(require("katex"));
4
+ else if(typeof define === 'function' && define.amd)
5
+ define(["katex"], factory);
6
+ else if(typeof exports === 'object')
7
+ exports["renderMathInElement"] = factory(require("katex"));
8
+ else
9
+ root["renderMathInElement"] = factory(root["katex"]);
10
+ })((typeof self !== 'undefined' ? self : this), function(__WEBPACK_EXTERNAL_MODULE__757__) {
11
+ return /******/ (function() { // webpackBootstrap
12
+ /******/ "use strict";
13
+ /******/ var __webpack_modules__ = ({
14
+
15
+ /***/ 757:
16
+ /***/ (function(module) {
17
+
18
+ module.exports = __WEBPACK_EXTERNAL_MODULE__757__;
19
+
20
+ /***/ })
21
+
22
+ /******/ });
23
+ /************************************************************************/
24
+ /******/ // The module cache
25
+ /******/ var __webpack_module_cache__ = {};
26
+ /******/
27
+ /******/ // The require function
28
+ /******/ function __webpack_require__(moduleId) {
29
+ /******/ // Check if module is in cache
30
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
31
+ /******/ if (cachedModule !== undefined) {
32
+ /******/ return cachedModule.exports;
33
+ /******/ }
34
+ /******/ // Create a new module (and put it into the cache)
35
+ /******/ var module = __webpack_module_cache__[moduleId] = {
36
+ /******/ // no module.id needed
37
+ /******/ // no module.loaded needed
38
+ /******/ exports: {}
39
+ /******/ };
40
+ /******/
41
+ /******/ // Execute the module function
42
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
43
+ /******/
44
+ /******/ // Return the exports of the module
45
+ /******/ return module.exports;
46
+ /******/ }
47
+ /******/
48
+ /************************************************************************/
49
+ /******/ /* webpack/runtime/compat get default export */
50
+ /******/ !function() {
51
+ /******/ // getDefaultExport function for compatibility with non-harmony modules
52
+ /******/ __webpack_require__.n = function(module) {
53
+ /******/ var getter = module && module.__esModule ?
54
+ /******/ function() { return module['default']; } :
55
+ /******/ function() { return module; };
56
+ /******/ __webpack_require__.d(getter, { a: getter });
57
+ /******/ return getter;
58
+ /******/ };
59
+ /******/ }();
60
+ /******/
61
+ /******/ /* webpack/runtime/define property getters */
62
+ /******/ !function() {
63
+ /******/ // define getter functions for harmony exports
64
+ /******/ __webpack_require__.d = function(exports, definition) {
65
+ /******/ for(var key in definition) {
66
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
67
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
68
+ /******/ }
69
+ /******/ }
70
+ /******/ };
71
+ /******/ }();
72
+ /******/
73
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
74
+ /******/ !function() {
75
+ /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
76
+ /******/ }();
77
+ /******/
78
+ /************************************************************************/
79
+ var __webpack_exports__ = {};
80
+
81
+ // EXPORTS
82
+ __webpack_require__.d(__webpack_exports__, {
83
+ "default": function() { return /* binding */ auto_render; }
84
+ });
85
+
86
+ // EXTERNAL MODULE: external "katex"
87
+ var external_katex_ = __webpack_require__(757);
88
+ var external_katex_default = /*#__PURE__*/__webpack_require__.n(external_katex_);
89
+ ;// CONCATENATED MODULE: ./contrib/auto-render/splitAtDelimiters.js
90
+ /* eslint no-constant-condition:0 */
91
+ const findEndOfMath = function (delimiter, text, startIndex) {
92
+ // Adapted from
93
+ // https://github.com/Khan/perseus/blob/master/src/perseus-markdown.jsx
94
+ let index = startIndex;
95
+ let braceLevel = 0;
96
+ const delimLength = delimiter.length;
97
+
98
+ while (index < text.length) {
99
+ const character = text[index];
100
+
101
+ if (braceLevel <= 0 && text.slice(index, index + delimLength) === delimiter) {
102
+ return index;
103
+ } else if (character === "\\") {
104
+ index++;
105
+ } else if (character === "{") {
106
+ braceLevel++;
107
+ } else if (character === "}") {
108
+ braceLevel--;
109
+ }
110
+
111
+ index++;
112
+ }
113
+
114
+ return -1;
115
+ };
116
+
117
+ const escapeRegex = function (string) {
118
+ return string.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
119
+ };
120
+
121
+ const amsRegex = /^\\begin{/;
122
+
123
+ const splitAtDelimiters = function (text, delimiters) {
124
+ let index;
125
+ const data = [];
126
+ const regexLeft = new RegExp("(" + delimiters.map(x => escapeRegex(x.left)).join("|") + ")");
127
+
128
+ while (true) {
129
+ index = text.search(regexLeft);
130
+
131
+ if (index === -1) {
132
+ break;
133
+ }
134
+
135
+ if (index > 0) {
136
+ data.push({
137
+ type: "text",
138
+ data: text.slice(0, index)
139
+ });
140
+ text = text.slice(index); // now text starts with delimiter
141
+ } // ... so this always succeeds:
142
+
143
+
144
+ const i = delimiters.findIndex(delim => text.startsWith(delim.left));
145
+ index = findEndOfMath(delimiters[i].right, text, delimiters[i].left.length);
146
+
147
+ if (index === -1) {
148
+ break;
149
+ }
150
+
151
+ const rawData = text.slice(0, index + delimiters[i].right.length);
152
+ const math = amsRegex.test(rawData) ? rawData : text.slice(delimiters[i].left.length, index);
153
+ data.push({
154
+ type: "math",
155
+ data: math,
156
+ rawData,
157
+ display: delimiters[i].display
158
+ });
159
+ text = text.slice(index + delimiters[i].right.length);
160
+ }
161
+
162
+ if (text !== "") {
163
+ data.push({
164
+ type: "text",
165
+ data: text
166
+ });
167
+ }
168
+
169
+ return data;
170
+ };
171
+
172
+ /* harmony default export */ var auto_render_splitAtDelimiters = (splitAtDelimiters);
173
+ ;// CONCATENATED MODULE: ./contrib/auto-render/auto-render.js
174
+ /* eslint no-console:0 */
175
+
176
+
177
+ /* Note: optionsCopy is mutated by this method. If it is ever exposed in the
178
+ * API, we should copy it before mutating.
179
+ */
180
+
181
+ const renderMathInText = function (text, optionsCopy) {
182
+ const data = auto_render_splitAtDelimiters(text, optionsCopy.delimiters);
183
+
184
+ if (data.length === 1 && data[0].type === 'text') {
185
+ // There is no formula in the text.
186
+ // Let's return null which means there is no need to replace
187
+ // the current text node with a new one.
188
+ return null;
189
+ }
190
+
191
+ const fragment = document.createDocumentFragment();
192
+
193
+ for (let i = 0; i < data.length; i++) {
194
+ if (data[i].type === "text") {
195
+ fragment.appendChild(document.createTextNode(data[i].data));
196
+ } else {
197
+ const span = document.createElement("span");
198
+ let math = data[i].data; // Override any display mode defined in the settings with that
199
+ // defined by the text itself
200
+
201
+ optionsCopy.displayMode = data[i].display;
202
+
203
+ try {
204
+ if (optionsCopy.preProcess) {
205
+ math = optionsCopy.preProcess(math);
206
+ }
207
+
208
+ external_katex_default().render(math, span, optionsCopy);
209
+ } catch (e) {
210
+ if (!(e instanceof (external_katex_default()).ParseError)) {
211
+ throw e;
212
+ }
213
+
214
+ optionsCopy.errorCallback("KaTeX auto-render: Failed to parse `" + data[i].data + "` with ", e);
215
+ fragment.appendChild(document.createTextNode(data[i].rawData));
216
+ continue;
217
+ }
218
+
219
+ fragment.appendChild(span);
220
+ }
221
+ }
222
+
223
+ return fragment;
224
+ };
225
+
226
+ const renderElem = function (elem, optionsCopy) {
227
+ for (let i = 0; i < elem.childNodes.length; i++) {
228
+ const childNode = elem.childNodes[i];
229
+
230
+ if (childNode.nodeType === 3) {
231
+ // Text node
232
+ // Concatenate all sibling text nodes.
233
+ // Webkit browsers split very large text nodes into smaller ones,
234
+ // so the delimiters may be split across different nodes.
235
+ let textContentConcat = childNode.textContent;
236
+ let sibling = childNode.nextSibling;
237
+ let nSiblings = 0;
238
+
239
+ while (sibling && sibling.nodeType === Node.TEXT_NODE) {
240
+ textContentConcat += sibling.textContent;
241
+ sibling = sibling.nextSibling;
242
+ nSiblings++;
243
+ }
244
+
245
+ const frag = renderMathInText(textContentConcat, optionsCopy);
246
+
247
+ if (frag) {
248
+ // Remove extra text nodes
249
+ for (let j = 0; j < nSiblings; j++) {
250
+ childNode.nextSibling.remove();
251
+ }
252
+
253
+ i += frag.childNodes.length - 1;
254
+ elem.replaceChild(frag, childNode);
255
+ } else {
256
+ // If the concatenated text does not contain math
257
+ // the siblings will not either
258
+ i += nSiblings;
259
+ }
260
+ } else if (childNode.nodeType === 1) {
261
+ // Element node
262
+ const className = ' ' + childNode.className + ' ';
263
+ const shouldRender = optionsCopy.ignoredTags.indexOf(childNode.nodeName.toLowerCase()) === -1 && optionsCopy.ignoredClasses.every(x => className.indexOf(' ' + x + ' ') === -1);
264
+
265
+ if (shouldRender) {
266
+ renderElem(childNode, optionsCopy);
267
+ }
268
+ } // Otherwise, it's something else, and ignore it.
269
+
270
+ }
271
+ };
272
+
273
+ const renderMathInElement = function (elem, options) {
274
+ if (!elem) {
275
+ throw new Error("No element provided to render");
276
+ }
277
+
278
+ const optionsCopy = {}; // Object.assign(optionsCopy, option)
279
+
280
+ for (const option in options) {
281
+ if (options.hasOwnProperty(option)) {
282
+ optionsCopy[option] = options[option];
283
+ }
284
+ } // default options
285
+
286
+
287
+ optionsCopy.delimiters = optionsCopy.delimiters || [{
288
+ left: "$$",
289
+ right: "$$",
290
+ display: true
291
+ }, {
292
+ left: "\\(",
293
+ right: "\\)",
294
+ display: false
295
+ }, // LaTeX uses $…$, but it ruins the display of normal `$` in text:
296
+ // {left: "$", right: "$", display: false},
297
+ // $ must come after $$
298
+ // Render AMS environments even if outside $$…$$ delimiters.
299
+ {
300
+ left: "\\begin{equation}",
301
+ right: "\\end{equation}",
302
+ display: true
303
+ }, {
304
+ left: "\\begin{align}",
305
+ right: "\\end{align}",
306
+ display: true
307
+ }, {
308
+ left: "\\begin{alignat}",
309
+ right: "\\end{alignat}",
310
+ display: true
311
+ }, {
312
+ left: "\\begin{gather}",
313
+ right: "\\end{gather}",
314
+ display: true
315
+ }, {
316
+ left: "\\begin{CD}",
317
+ right: "\\end{CD}",
318
+ display: true
319
+ }, {
320
+ left: "\\[",
321
+ right: "\\]",
322
+ display: true
323
+ }];
324
+ optionsCopy.ignoredTags = optionsCopy.ignoredTags || ["script", "noscript", "style", "textarea", "pre", "code", "option"];
325
+ optionsCopy.ignoredClasses = optionsCopy.ignoredClasses || [];
326
+ optionsCopy.errorCallback = optionsCopy.errorCallback || console.error; // Enable sharing of global macros defined via `\gdef` between different
327
+ // math elements within a single call to `renderMathInElement`.
328
+
329
+ optionsCopy.macros = optionsCopy.macros || {};
330
+ renderElem(elem, optionsCopy);
331
+ };
332
+
333
+ /* harmony default export */ var auto_render = (renderMathInElement);
334
+ __webpack_exports__ = __webpack_exports__["default"];
335
+ /******/ return __webpack_exports__;
336
+ /******/ })()
337
+ ;
338
+ });
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("katex")):"function"==typeof define&&define.amd?define(["katex"],t):"object"==typeof exports?exports.renderMathInElement=t(require("katex")):e.renderMathInElement=t(e.katex)}("undefined"!=typeof self?self:this,(function(e){return function(){"use strict";var t={757:function(t){t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)};var o={};r.d(o,{default:function(){return p}});var i=r(757),a=r.n(i);const l=function(e,t,n){let r=n,o=0;const i=e.length;for(;r<t.length;){const n=t[r];if(o<=0&&t.slice(r,r+i)===e)return r;"\\"===n?r++:"{"===n?o++:"}"===n&&o--,r++}return-1},s=/^\\begin{/;var d=function(e,t){let n;const r=[],o=new RegExp("("+t.map((e=>e.left.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&"))).join("|")+")");for(;n=e.search(o),-1!==n;){n>0&&(r.push({type:"text",data:e.slice(0,n)}),e=e.slice(n));const o=t.findIndex((t=>e.startsWith(t.left)));if(n=l(t[o].right,e,t[o].left.length),-1===n)break;const i=e.slice(0,n+t[o].right.length),a=s.test(i)?i:e.slice(t[o].left.length,n);r.push({type:"math",data:a,rawData:i,display:t[o].display}),e=e.slice(n+t[o].right.length)}return""!==e&&r.push({type:"text",data:e}),r};const c=function(e,t){const n=d(e,t.delimiters);if(1===n.length&&"text"===n[0].type)return null;const r=document.createDocumentFragment();for(let e=0;e<n.length;e++)if("text"===n[e].type)r.appendChild(document.createTextNode(n[e].data));else{const o=document.createElement("span");let i=n[e].data;t.displayMode=n[e].display;try{t.preProcess&&(i=t.preProcess(i)),a().render(i,o,t)}catch(o){if(!(o instanceof a().ParseError))throw o;t.errorCallback("KaTeX auto-render: Failed to parse `"+n[e].data+"` with ",o),r.appendChild(document.createTextNode(n[e].rawData));continue}r.appendChild(o)}return r},f=function(e,t){for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(3===r.nodeType){let o=r.textContent,i=r.nextSibling,a=0;for(;i&&i.nodeType===Node.TEXT_NODE;)o+=i.textContent,i=i.nextSibling,a++;const l=c(o,t);if(l){for(let e=0;e<a;e++)r.nextSibling.remove();n+=l.childNodes.length-1,e.replaceChild(l,r)}else n+=a}else if(1===r.nodeType){const e=" "+r.className+" ";-1===t.ignoredTags.indexOf(r.nodeName.toLowerCase())&&t.ignoredClasses.every((t=>-1===e.indexOf(" "+t+" ")))&&f(r,t)}}};var p=function(e,t){if(!e)throw new Error("No element provided to render");const n={};for(const e in t)t.hasOwnProperty(e)&&(n[e]=t[e]);n.delimiters=n.delimiters||[{left:"$$",right:"$$",display:!0},{left:"\\(",right:"\\)",display:!1},{left:"\\begin{equation}",right:"\\end{equation}",display:!0},{left:"\\begin{align}",right:"\\end{align}",display:!0},{left:"\\begin{alignat}",right:"\\end{alignat}",display:!0},{left:"\\begin{gather}",right:"\\end{gather}",display:!0},{left:"\\begin{CD}",right:"\\end{CD}",display:!0},{left:"\\[",right:"\\]",display:!0}],n.ignoredTags=n.ignoredTags||["script","noscript","style","textarea","pre","code","option"],n.ignoredClasses=n.ignoredClasses||[],n.errorCallback=n.errorCallback||console.error,n.macros=n.macros||{},f(e,n)};return o=o.default}()}));
@@ -0,0 +1,244 @@
1
+ import katex from '../katex.mjs';
2
+
3
+ /* eslint no-constant-condition:0 */
4
+ var findEndOfMath = function findEndOfMath(delimiter, text, startIndex) {
5
+ // Adapted from
6
+ // https://github.com/Khan/perseus/blob/master/src/perseus-markdown.jsx
7
+ var index = startIndex;
8
+ var braceLevel = 0;
9
+ var delimLength = delimiter.length;
10
+
11
+ while (index < text.length) {
12
+ var character = text[index];
13
+
14
+ if (braceLevel <= 0 && text.slice(index, index + delimLength) === delimiter) {
15
+ return index;
16
+ } else if (character === "\\") {
17
+ index++;
18
+ } else if (character === "{") {
19
+ braceLevel++;
20
+ } else if (character === "}") {
21
+ braceLevel--;
22
+ }
23
+
24
+ index++;
25
+ }
26
+
27
+ return -1;
28
+ };
29
+
30
+ var escapeRegex = function escapeRegex(string) {
31
+ return string.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
32
+ };
33
+
34
+ var amsRegex = /^\\begin{/;
35
+
36
+ var splitAtDelimiters = function splitAtDelimiters(text, delimiters) {
37
+ var index;
38
+ var data = [];
39
+ var regexLeft = new RegExp("(" + delimiters.map(x => escapeRegex(x.left)).join("|") + ")");
40
+
41
+ while (true) {
42
+ index = text.search(regexLeft);
43
+
44
+ if (index === -1) {
45
+ break;
46
+ }
47
+
48
+ if (index > 0) {
49
+ data.push({
50
+ type: "text",
51
+ data: text.slice(0, index)
52
+ });
53
+ text = text.slice(index); // now text starts with delimiter
54
+ } // ... so this always succeeds:
55
+
56
+
57
+ var i = delimiters.findIndex(delim => text.startsWith(delim.left));
58
+ index = findEndOfMath(delimiters[i].right, text, delimiters[i].left.length);
59
+
60
+ if (index === -1) {
61
+ break;
62
+ }
63
+
64
+ var rawData = text.slice(0, index + delimiters[i].right.length);
65
+ var math = amsRegex.test(rawData) ? rawData : text.slice(delimiters[i].left.length, index);
66
+ data.push({
67
+ type: "math",
68
+ data: math,
69
+ rawData,
70
+ display: delimiters[i].display
71
+ });
72
+ text = text.slice(index + delimiters[i].right.length);
73
+ }
74
+
75
+ if (text !== "") {
76
+ data.push({
77
+ type: "text",
78
+ data: text
79
+ });
80
+ }
81
+
82
+ return data;
83
+ };
84
+
85
+ /* eslint no-console:0 */
86
+ /* Note: optionsCopy is mutated by this method. If it is ever exposed in the
87
+ * API, we should copy it before mutating.
88
+ */
89
+
90
+ var renderMathInText = function renderMathInText(text, optionsCopy) {
91
+ var data = splitAtDelimiters(text, optionsCopy.delimiters);
92
+
93
+ if (data.length === 1 && data[0].type === 'text') {
94
+ // There is no formula in the text.
95
+ // Let's return null which means there is no need to replace
96
+ // the current text node with a new one.
97
+ return null;
98
+ }
99
+
100
+ var fragment = document.createDocumentFragment();
101
+
102
+ for (var i = 0; i < data.length; i++) {
103
+ if (data[i].type === "text") {
104
+ fragment.appendChild(document.createTextNode(data[i].data));
105
+ } else {
106
+ var span = document.createElement("span");
107
+ var math = data[i].data; // Override any display mode defined in the settings with that
108
+ // defined by the text itself
109
+
110
+ optionsCopy.displayMode = data[i].display;
111
+
112
+ try {
113
+ if (optionsCopy.preProcess) {
114
+ math = optionsCopy.preProcess(math);
115
+ }
116
+
117
+ katex.render(math, span, optionsCopy);
118
+ } catch (e) {
119
+ if (!(e instanceof katex.ParseError)) {
120
+ throw e;
121
+ }
122
+
123
+ optionsCopy.errorCallback("KaTeX auto-render: Failed to parse `" + data[i].data + "` with ", e);
124
+ fragment.appendChild(document.createTextNode(data[i].rawData));
125
+ continue;
126
+ }
127
+
128
+ fragment.appendChild(span);
129
+ }
130
+ }
131
+
132
+ return fragment;
133
+ };
134
+
135
+ var renderElem = function renderElem(elem, optionsCopy) {
136
+ for (var i = 0; i < elem.childNodes.length; i++) {
137
+ var childNode = elem.childNodes[i];
138
+
139
+ if (childNode.nodeType === 3) {
140
+ // Text node
141
+ // Concatenate all sibling text nodes.
142
+ // Webkit browsers split very large text nodes into smaller ones,
143
+ // so the delimiters may be split across different nodes.
144
+ var textContentConcat = childNode.textContent;
145
+ var sibling = childNode.nextSibling;
146
+ var nSiblings = 0;
147
+
148
+ while (sibling && sibling.nodeType === Node.TEXT_NODE) {
149
+ textContentConcat += sibling.textContent;
150
+ sibling = sibling.nextSibling;
151
+ nSiblings++;
152
+ }
153
+
154
+ var frag = renderMathInText(textContentConcat, optionsCopy);
155
+
156
+ if (frag) {
157
+ // Remove extra text nodes
158
+ for (var j = 0; j < nSiblings; j++) {
159
+ childNode.nextSibling.remove();
160
+ }
161
+
162
+ i += frag.childNodes.length - 1;
163
+ elem.replaceChild(frag, childNode);
164
+ } else {
165
+ // If the concatenated text does not contain math
166
+ // the siblings will not either
167
+ i += nSiblings;
168
+ }
169
+ } else if (childNode.nodeType === 1) {
170
+ (function () {
171
+ // Element node
172
+ var className = ' ' + childNode.className + ' ';
173
+ var shouldRender = optionsCopy.ignoredTags.indexOf(childNode.nodeName.toLowerCase()) === -1 && optionsCopy.ignoredClasses.every(x => className.indexOf(' ' + x + ' ') === -1);
174
+
175
+ if (shouldRender) {
176
+ renderElem(childNode, optionsCopy);
177
+ }
178
+ })();
179
+ } // Otherwise, it's something else, and ignore it.
180
+
181
+ }
182
+ };
183
+
184
+ var renderMathInElement = function renderMathInElement(elem, options) {
185
+ if (!elem) {
186
+ throw new Error("No element provided to render");
187
+ }
188
+
189
+ var optionsCopy = {}; // Object.assign(optionsCopy, option)
190
+
191
+ for (var option in options) {
192
+ if (options.hasOwnProperty(option)) {
193
+ optionsCopy[option] = options[option];
194
+ }
195
+ } // default options
196
+
197
+
198
+ optionsCopy.delimiters = optionsCopy.delimiters || [{
199
+ left: "$$",
200
+ right: "$$",
201
+ display: true
202
+ }, {
203
+ left: "\\(",
204
+ right: "\\)",
205
+ display: false
206
+ }, // LaTeX uses $…$, but it ruins the display of normal `$` in text:
207
+ // {left: "$", right: "$", display: false},
208
+ // $ must come after $$
209
+ // Render AMS environments even if outside $$…$$ delimiters.
210
+ {
211
+ left: "\\begin{equation}",
212
+ right: "\\end{equation}",
213
+ display: true
214
+ }, {
215
+ left: "\\begin{align}",
216
+ right: "\\end{align}",
217
+ display: true
218
+ }, {
219
+ left: "\\begin{alignat}",
220
+ right: "\\end{alignat}",
221
+ display: true
222
+ }, {
223
+ left: "\\begin{gather}",
224
+ right: "\\end{gather}",
225
+ display: true
226
+ }, {
227
+ left: "\\begin{CD}",
228
+ right: "\\end{CD}",
229
+ display: true
230
+ }, {
231
+ left: "\\[",
232
+ right: "\\]",
233
+ display: true
234
+ }];
235
+ optionsCopy.ignoredTags = optionsCopy.ignoredTags || ["script", "noscript", "style", "textarea", "pre", "code", "option"];
236
+ optionsCopy.ignoredClasses = optionsCopy.ignoredClasses || [];
237
+ optionsCopy.errorCallback = optionsCopy.errorCallback || console.error; // Enable sharing of global macros defined via `\gdef` between different
238
+ // math elements within a single call to `renderMathInElement`.
239
+
240
+ optionsCopy.macros = optionsCopy.macros || {};
241
+ renderElem(elem, optionsCopy);
242
+ };
243
+
244
+ export { renderMathInElement as default };