@teamturing/react-native-tex 1.1.6 → 1.1.7
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.
- package/lib/commonjs/html/LaTexHtml.html +442 -435
- package/lib/commonjs/html/LaTexHtmlText.js +442 -435
- package/lib/commonjs/html/LaTexHtmlText.js.map +1 -1
- package/lib/module/html/LaTexHtml.html +442 -435
- package/lib/module/html/LaTexHtmlText.js +442 -435
- package/lib/module/html/LaTexHtmlText.js.map +1 -1
- package/lib/typescript/commonjs/src/html/LaTexHtmlText.d.ts.map +1 -1
- package/lib/typescript/module/src/html/LaTexHtmlText.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/html/LaTexHtml.html +442 -435
- package/src/html/LaTexHtmlText.ts +442 -435
|
@@ -8,486 +8,493 @@ const text = ({
|
|
|
8
8
|
}) => String.raw`
|
|
9
9
|
<!DOCTYPE html>
|
|
10
10
|
<html lang="ko">
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
11
|
+
<head>
|
|
12
|
+
<title>MathKing</title>
|
|
13
|
+
<meta
|
|
14
|
+
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
|
|
15
|
+
name="viewport"
|
|
16
|
+
id="latex_viewport"
|
|
17
|
+
charset="UTF-8"
|
|
18
|
+
/>
|
|
19
|
+
|
|
20
|
+
<script async src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
|
|
21
|
+
<link
|
|
22
|
+
rel="stylesheet"
|
|
23
|
+
href="https://cdn.jsdelivr.net/npm/@teamturing/katex-utils@2.19.0/dist/mathking-katex.css"
|
|
24
|
+
crossorigin="anonymous"
|
|
25
|
+
/>
|
|
26
|
+
|
|
27
|
+
<style>
|
|
28
28
|
._cms_content-frame {
|
|
29
|
-
|
|
29
|
+
font-size: ${fontSize}px;
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
</style>
|
|
32
|
+
|
|
33
|
+
<style>
|
|
34
34
|
*,
|
|
35
35
|
*::after,
|
|
36
36
|
*::before {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
-webkit-user-select: none;
|
|
38
|
+
-webkit-user-drag: none;
|
|
39
|
+
cursor: default;
|
|
40
|
+
-webkit-touch-callout: none;
|
|
41
|
+
-moz-user-select: none;
|
|
42
|
+
-ms-user-select: none;
|
|
43
|
+
user-select: none;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
html {
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
padding: 0 0;
|
|
48
|
+
margin: 0;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
body {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
padding: 0;
|
|
53
|
+
margin: 0 0 0 0;
|
|
54
|
+
position: relative;
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
</style>
|
|
57
|
+
<style>
|
|
58
58
|
#container {
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
background-color: white;
|
|
60
|
+
width: 100%;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
#shadow-animation-container {
|
|
64
|
-
|
|
64
|
+
visibility: hidden;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
@keyframes fade-in {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
to {
|
|
69
|
+
opacity: 1;
|
|
70
|
+
}
|
|
71
|
+
from {
|
|
72
|
+
opacity: 0;
|
|
73
|
+
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
@keyframes cursor-blink {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
77
|
+
0% {
|
|
78
|
+
opacity: 0;
|
|
79
|
+
}
|
|
80
|
+
50% {
|
|
81
|
+
opacity: 1;
|
|
82
|
+
}
|
|
83
|
+
100% {
|
|
84
|
+
opacity: 0;
|
|
85
|
+
}
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
.typewriter-cursor {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
border-radius: 1px;
|
|
90
|
+
width: 1.5px;
|
|
91
|
+
height: 14px;
|
|
92
|
+
/*border: 1px solid black;*/
|
|
93
|
+
background: black;
|
|
94
|
+
visibility: hidden;
|
|
95
|
+
position: absolute;
|
|
96
96
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
97
|
+
</style>
|
|
98
|
+
</head>
|
|
99
|
+
<body>
|
|
100
|
+
<div id="container" onmousedown="return false;"></div>
|
|
101
|
+
<div id="shadow-animation-container" onmousedown="return false;" aria-hidden="true"></div>
|
|
102
|
+
<div class="typewriter-cursor"></div>
|
|
103
|
+
<script>
|
|
104
|
+
const CONTENT_FRAME_CLASS = "_cms_content-frame";
|
|
105
|
+
|
|
106
|
+
const documentResizeObserver = new ResizeObserver(() => {
|
|
107
|
+
onDocumentResized();
|
|
108
|
+
});
|
|
109
|
+
documentResizeObserver.observe(document.getElementById("container"));
|
|
110
|
+
|
|
111
|
+
const renderChoiceLayout = (container) => {
|
|
112
|
+
const choiceBox = container.querySelector("._cms_choice-box");
|
|
113
|
+
if (!choiceBox) return;
|
|
114
|
+
|
|
115
|
+
const choiceBoxWidth = choiceBox.getBoundingClientRect().width;
|
|
116
|
+
choiceBox.classList.remove("strip");
|
|
117
|
+
choiceBox.classList.remove("third");
|
|
118
|
+
choiceBox.classList.remove("half");
|
|
119
|
+
choiceBox.classList.remove("full");
|
|
120
|
+
|
|
121
|
+
const maxChoiceWidth = Array.from(choiceBox.querySelectorAll("._cms_choice")).reduce((pre, choice) => {
|
|
122
|
+
const width = choice.getBoundingClientRect().width;
|
|
123
|
+
return pre > width ? pre : width;
|
|
124
|
+
}, 0);
|
|
125
|
+
|
|
126
|
+
if (maxChoiceWidth > (choiceBoxWidth / 100) * 50) {
|
|
127
|
+
choiceBox.classList.add("full");
|
|
128
|
+
} else if (maxChoiceWidth > (choiceBoxWidth / 100) * 33) {
|
|
129
|
+
choiceBox.classList.add("half");
|
|
130
|
+
} else if (maxChoiceWidth > (choiceBoxWidth / 100) * 25) {
|
|
131
|
+
choiceBox.classList.add("third");
|
|
132
|
+
} else if (maxChoiceWidth < (choiceBoxWidth / 100) * 20) {
|
|
133
|
+
choiceBox.classList.add("strip");
|
|
134
|
+
} else {
|
|
135
|
+
choiceBox.classList.add("third");
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
function relayout () {
|
|
140
|
+
try {
|
|
141
|
+
const container = document.getElementById("container");
|
|
142
|
+
if (container) renderChoiceLayout(container);
|
|
143
|
+
} catch (e) {
|
|
144
|
+
reportErrorWithSlackWebhook(e);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const onRenderSuccess = () => {
|
|
149
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({ event: "render-success" }));
|
|
150
|
+
};
|
|
151
|
+
const onRenderFailed = () => {
|
|
152
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({ event: "render-fail" }));
|
|
153
|
+
};
|
|
154
|
+
const onPhantomBoxCountChanged = (count) => {
|
|
155
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({ event: "phantom-box-count-changed", count }));
|
|
156
|
+
};
|
|
157
|
+
const onPhantomBoxPressed = (index) => {
|
|
158
|
+
window.ReactNativeWebView.postMessage(JSON.stringify({ event: "phantom-box-pressed", index }));
|
|
159
|
+
};
|
|
160
|
+
let lastScrollHeight = 0;
|
|
161
|
+
let lastScrollWidth = 0;
|
|
162
|
+
let lastClientWidth = 0;
|
|
163
|
+
const onDocumentResized = () => {
|
|
164
|
+
const container = document.getElementById("container");
|
|
165
|
+
if (container && Math.abs(lastScrollHeight - container.scrollHeight) +
|
|
166
|
+
Math.abs(lastScrollWidth - container.scrollWidth) + Math.abs(lastClientWidth - container.clientWidth) >= 15) {
|
|
167
|
+
lastScrollHeight = container.scrollHeight;
|
|
168
|
+
lastScrollWidth = container.scrollWidth;
|
|
169
|
+
lastClientWidth = container.clientWidth;
|
|
170
|
+
window.ReactNativeWebView.postMessage(
|
|
171
|
+
JSON.stringify({
|
|
172
|
+
event: "set-layout",
|
|
173
|
+
scrollHeight: container.scrollHeight,
|
|
174
|
+
scrollWidth: container.scrollWidth,
|
|
175
|
+
clientWidth: container.clientWidth
|
|
176
|
+
})
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const scrollToTop = () => {
|
|
182
|
+
window.scrollTo(0, 0);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const setPhantomBoxVisibility = (index, state) => {
|
|
186
|
+
const box = document.getElementById("phantom-box-" + index);
|
|
187
|
+
const border = document.getElementById("phantom-box-border-" + index);
|
|
188
|
+
if (box && border) {
|
|
189
|
+
box.classList.remove("_cms_phantom_box_invisible", "_cms_phantom_box_visible", "_cms_phantom_no_box");
|
|
190
|
+
border.classList.remove("_cms_phantom_border_visible", "_cms_phantom_border_invisible");
|
|
191
|
+
if (state === "box_visible") {
|
|
192
|
+
box.classList.add("_cms_phantom_box_visible");
|
|
193
|
+
border.classList.add("_cms_phantom_border_visible");
|
|
194
|
+
} else if (state === "box_invisible") {
|
|
195
|
+
box.classList.add("_cms_phantom_box_invisible");
|
|
196
|
+
border.classList.add("_cms_phantom_border_visible");
|
|
197
|
+
} else {
|
|
198
|
+
box.classList.add("_cms_phantom_no_box");
|
|
199
|
+
border.classList.add("_cms_phantom_border_invisible");
|
|
146
200
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const togglePhantomBoxVisibility = (index) => {
|
|
205
|
+
const box = document.getElementById("phantom-box-" + index);
|
|
206
|
+
if (box) {
|
|
207
|
+
if (box.classList.contains("_cms_phantom_box_invisible")) {
|
|
208
|
+
setPhantomBoxVisibility(index, "box_visible");
|
|
209
|
+
} else if (box.classList.contains("_cms_phantom_box_visible")) {
|
|
210
|
+
setPhantomBoxVisibility(index, "box_invisible");
|
|
211
|
+
} else {
|
|
212
|
+
// if no_box state, do nothing
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const initializePhantomBoxes = (initialPhantomBoxVisibility, isPhantomBoxClickable) => {
|
|
218
|
+
let count = 0;
|
|
219
|
+
iteratePhantomBoxes((box, border, i) => {
|
|
220
|
+
count += 1;
|
|
221
|
+
initializeBox(box, border, i);
|
|
222
|
+
});
|
|
223
|
+
onPhantomBoxCountChanged(count);
|
|
224
|
+
|
|
225
|
+
function initializeBox (box, border, index) {
|
|
226
|
+
setPhantomBoxVisibility(index, initialPhantomBoxVisibility || "box_invisible");
|
|
227
|
+
if (isPhantomBoxClickable) {
|
|
228
|
+
box.onclick = () => {
|
|
229
|
+
togglePhantomBoxVisibility(index);
|
|
230
|
+
onPhantomBoxPressed(index);
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const iteratePhantomBoxes = (callback) => {
|
|
237
|
+
try {
|
|
238
|
+
for (let i = 0; ; i++) {
|
|
239
|
+
const box = document.getElementById("phantom-box-" + i);
|
|
240
|
+
const border = document.getElementById("phantom-box-border-" + i);
|
|
181
241
|
if (box && border) {
|
|
182
|
-
box
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
box.classList.add('_cms_phantom_box_visible');
|
|
186
|
-
border.classList.add('_cms_phantom_border_visible');
|
|
187
|
-
} else if (state === 'box_invisible') {
|
|
188
|
-
box.classList.add('_cms_phantom_box_invisible');
|
|
189
|
-
border.classList.add('_cms_phantom_border_visible');
|
|
190
|
-
} else {
|
|
191
|
-
box.classList.add('_cms_phantom_no_box');
|
|
192
|
-
border.classList.add('_cms_phantom_border_invisible');
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
const togglePhantomBoxVisibility = (index) => {
|
|
198
|
-
const box = document.getElementById('phantom-box-' + index);
|
|
199
|
-
if (box) {
|
|
200
|
-
if (box.classList.contains('_cms_phantom_box_invisible')) {
|
|
201
|
-
setPhantomBoxVisibility(index, 'box_visible');
|
|
202
|
-
} else if (box.classList.contains('_cms_phantom_box_visible')) {
|
|
203
|
-
setPhantomBoxVisibility(index, 'box_invisible');
|
|
204
|
-
} else {
|
|
205
|
-
// if no_box state, do nothing
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
const initializePhantomBoxes = (initialPhantomBoxVisibility, isPhantomBoxClickable) => {
|
|
211
|
-
let count = 0;
|
|
212
|
-
iteratePhantomBoxes((box, border, i) => {
|
|
213
|
-
count += 1;
|
|
214
|
-
initializeBox(box, border, i);
|
|
215
|
-
});
|
|
216
|
-
onPhantomBoxCountChanged(count);
|
|
217
|
-
|
|
218
|
-
function initializeBox(box, border, index) {
|
|
219
|
-
setPhantomBoxVisibility(index, initialPhantomBoxVisibility || 'box_invisible');
|
|
220
|
-
if (isPhantomBoxClickable) {
|
|
221
|
-
box.onclick = () => {
|
|
222
|
-
togglePhantomBoxVisibility(index);
|
|
223
|
-
onPhantomBoxPressed(index);
|
|
224
|
-
};
|
|
225
|
-
}
|
|
242
|
+
callback(box, border, i);
|
|
243
|
+
} else {
|
|
244
|
+
break;
|
|
226
245
|
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
246
|
+
}
|
|
247
|
+
} catch (e) {}
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const renderLaTex = ({
|
|
251
|
+
html,
|
|
252
|
+
paddingHorizontal,
|
|
253
|
+
initialPhantomBoxVisibility,
|
|
254
|
+
isPhantomBoxClickable,
|
|
255
|
+
paddingBottom,
|
|
256
|
+
paddingTop,
|
|
257
|
+
isAiAnimationEnable
|
|
258
|
+
}) => {
|
|
259
|
+
const container = document.getElementById("container");
|
|
260
|
+
const shadowContainer = document.getElementById("shadow-animation-container");
|
|
261
|
+
|
|
262
|
+
let delayHandler = -1;
|
|
263
|
+
|
|
264
|
+
function setPaddingForContentFrame (element) {
|
|
265
|
+
if (element instanceof HTMLElement) {
|
|
266
|
+
const paddingStyle =
|
|
267
|
+
(paddingTop || 0) +
|
|
268
|
+
"px " +
|
|
269
|
+
(paddingHorizontal || 0) +
|
|
270
|
+
"px " +
|
|
271
|
+
(paddingBottom || "0") +
|
|
272
|
+
"px " +
|
|
273
|
+
(paddingHorizontal || 0) +
|
|
274
|
+
"px";
|
|
275
|
+
|
|
276
|
+
element.style.padding = paddingStyle;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function renderContainer () {
|
|
281
|
+
container.innerHTML = html;
|
|
282
|
+
container.style.visibility = "visible";
|
|
283
|
+
shadowContainer.innerHTML = "";
|
|
284
|
+
clearTimeout(delayHandler);
|
|
285
|
+
setPaddingForContentFrame(container.querySelector("." + CONTENT_FRAME_CLASS));
|
|
286
|
+
setTimeout(function() {
|
|
287
|
+
relayout();
|
|
288
|
+
}, 100);
|
|
289
|
+
initializePhantomBoxes(initialPhantomBoxVisibility, isPhantomBoxClickable);
|
|
290
|
+
onRenderSuccess();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function onAiAnimationRenderFailed () {
|
|
294
|
+
clearTimeout(delayHandler);
|
|
295
|
+
shadowContainer.innerHTML = "";
|
|
296
|
+
/** @type {HTMLDivElement} */
|
|
297
|
+
const cursor = document.querySelector(".typewriter-cursor");
|
|
298
|
+
if (cursor) {
|
|
299
|
+
cursor.style.visibility = "hidden";
|
|
300
|
+
}
|
|
301
|
+
renderContainer();
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function renderContainerWithAiAnimation () {
|
|
305
|
+
try {
|
|
306
|
+
container.innerHTML = "";
|
|
307
|
+
const mockedContentFrame = document.createElement("div");
|
|
308
|
+
mockedContentFrame.className = CONTENT_FRAME_CLASS;
|
|
309
|
+
setPaddingForContentFrame(mockedContentFrame);
|
|
310
|
+
container.appendChild(mockedContentFrame);
|
|
311
|
+
shadowContainer.innerHTML = html;
|
|
312
|
+
const root = shadowContainer.querySelector("." + CONTENT_FRAME_CLASS);
|
|
313
|
+
if (root) {
|
|
314
|
+
root.style.visibility = "hidden";
|
|
315
|
+
/** @type {Node[]} */
|
|
316
|
+
const replacedElements = [];
|
|
317
|
+
/** @type {HTMLElement[]} */
|
|
318
|
+
const animatedElements = [];
|
|
319
|
+
|
|
320
|
+
for (let node = root.firstChild; node; node = node.nextSibling) {
|
|
321
|
+
if (node.nodeType === 3 /* text */ && typeof node.textContent === "string" && node.textContent.trim()) {
|
|
322
|
+
for (let i = 0; i < node.textContent.length; i++) {
|
|
323
|
+
/** @type {HTMLSpanElement} */
|
|
324
|
+
const newSpan = document.createElement("span");
|
|
325
|
+
newSpan.textContent = node.textContent.charAt(i);
|
|
326
|
+
newSpan.style.visibility = "hidden";
|
|
327
|
+
newSpan.className += " splitted-text";
|
|
328
|
+
animatedElements.push(newSpan);
|
|
329
|
+
replacedElements.push(newSpan);
|
|
330
|
+
}
|
|
331
|
+
} else if (
|
|
332
|
+
node.firstChild &&
|
|
333
|
+
node.firstChild.firstChild &&
|
|
334
|
+
node.firstChild.firstChild.classList.contains("base")
|
|
335
|
+
) {
|
|
336
|
+
/** @type {HTMLElement} */
|
|
337
|
+
const katexHtml = node.firstChild;
|
|
338
|
+
for (let i = 0; i < katexHtml.children.length; i++) {
|
|
339
|
+
/** @type {HTMLElement} */
|
|
340
|
+
const baseElement = katexHtml.children[i];
|
|
341
|
+
if (baseElement.classList.contains("base")) {
|
|
342
|
+
baseElement.style.visibility = "hidden";
|
|
343
|
+
animatedElements.push(baseElement);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
replacedElements.push(node);
|
|
236
347
|
} else {
|
|
237
|
-
|
|
348
|
+
if (node.nodeType === 1 /* element */) {
|
|
349
|
+
node.style.visibility = "hidden";
|
|
350
|
+
animatedElements.push(node);
|
|
351
|
+
}
|
|
352
|
+
replacedElements.push(node);
|
|
238
353
|
}
|
|
239
354
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const renderLaTex = ({
|
|
244
|
-
html,
|
|
245
|
-
paddingHorizontal,
|
|
246
|
-
initialPhantomBoxVisibility,
|
|
247
|
-
isPhantomBoxClickable,
|
|
248
|
-
paddingBottom,
|
|
249
|
-
paddingTop,
|
|
250
|
-
isAiAnimationEnable,
|
|
251
|
-
}) => {
|
|
252
|
-
const container = document.getElementById('container');
|
|
253
|
-
const shadowContainer = document.getElementById('shadow-animation-container');
|
|
254
|
-
|
|
255
|
-
let delayHandler = -1;
|
|
256
|
-
|
|
257
|
-
function setPaddingForContentFrame(element) {
|
|
258
|
-
if (element instanceof HTMLElement) {
|
|
259
|
-
const paddingStyle =
|
|
260
|
-
(paddingTop || 0) +
|
|
261
|
-
'px ' +
|
|
262
|
-
(paddingHorizontal || 0) +
|
|
263
|
-
'px ' +
|
|
264
|
-
(paddingBottom || '0') +
|
|
265
|
-
'px ' +
|
|
266
|
-
(paddingHorizontal || 0) +
|
|
267
|
-
'px';
|
|
268
|
-
|
|
269
|
-
element.style.padding = paddingStyle;
|
|
355
|
+
root.innerHTML = "";
|
|
356
|
+
for (const el of replacedElements) {
|
|
357
|
+
root.appendChild(el);
|
|
270
358
|
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function renderContainer() {
|
|
274
|
-
container.innerHTML = html;
|
|
275
|
-
container.style.visibility = 'visible';
|
|
276
|
-
shadowContainer.innerHTML = '';
|
|
277
|
-
clearTimeout(delayHandler);
|
|
278
|
-
setPaddingForContentFrame(container.querySelector('.' + CONTENT_FRAME_CLASS));
|
|
279
|
-
setTimeout(function () {
|
|
280
|
-
relayout();
|
|
281
|
-
}, 100);
|
|
282
|
-
initializePhantomBoxes(initialPhantomBoxVisibility, isPhantomBoxClickable);
|
|
283
|
-
onRenderSuccess();
|
|
284
|
-
}
|
|
285
359
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
shadowContainer.innerHTML =
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
const mockedContentFrame = document.createElement('div');
|
|
301
|
-
mockedContentFrame.className = CONTENT_FRAME_CLASS;
|
|
302
|
-
setPaddingForContentFrame(mockedContentFrame);
|
|
303
|
-
container.appendChild(mockedContentFrame);
|
|
304
|
-
shadowContainer.innerHTML = html;
|
|
305
|
-
const root = shadowContainer.querySelector('.' + CONTENT_FRAME_CLASS);
|
|
306
|
-
if (root) {
|
|
307
|
-
root.style.visibility = 'hidden';
|
|
308
|
-
/** @type {Node[]} */
|
|
309
|
-
const replacedElements = [];
|
|
310
|
-
/** @type {HTMLElement[]} */
|
|
311
|
-
const animatedElements = [];
|
|
312
|
-
|
|
313
|
-
for (let node = root.firstChild; node; node = node.nextSibling) {
|
|
314
|
-
if (node.nodeType === 3 /* text */ && typeof node.textContent === 'string' && node.textContent.trim()) {
|
|
315
|
-
for (let i = 0; i < node.textContent.length; i++) {
|
|
316
|
-
/** @type {HTMLSpanElement} */
|
|
317
|
-
const newSpan = document.createElement('span');
|
|
318
|
-
newSpan.textContent = node.textContent.charAt(i);
|
|
319
|
-
newSpan.style.visibility = 'hidden';
|
|
320
|
-
newSpan.className += ' splitted-text';
|
|
321
|
-
animatedElements.push(newSpan);
|
|
322
|
-
replacedElements.push(newSpan);
|
|
323
|
-
}
|
|
324
|
-
} else if (
|
|
325
|
-
node.firstChild &&
|
|
326
|
-
node.firstChild.firstChild &&
|
|
327
|
-
node.firstChild.firstChild.classList.contains('base')
|
|
328
|
-
) {
|
|
329
|
-
/** @type {HTMLElement} */
|
|
330
|
-
const katexHtml = node.firstChild;
|
|
331
|
-
for (let i = 0; i < katexHtml.children.length; i++) {
|
|
332
|
-
/** @type {HTMLElement} */
|
|
333
|
-
const baseElement = katexHtml.children[i];
|
|
334
|
-
if (baseElement.classList.contains('base')) {
|
|
335
|
-
baseElement.style.visibility = 'hidden';
|
|
336
|
-
animatedElements.push(baseElement);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
replacedElements.push(node);
|
|
340
|
-
} else {
|
|
341
|
-
if (node.nodeType === 1 /* element */) {
|
|
342
|
-
node.style.visibility = 'hidden';
|
|
343
|
-
animatedElements.push(node);
|
|
344
|
-
}
|
|
345
|
-
replacedElements.push(node);
|
|
346
|
-
}
|
|
360
|
+
// 구성된 root를 contianer에 넣어준다.
|
|
361
|
+
mockedContentFrame.appendChild(root);
|
|
362
|
+
shadowContainer.innerHTML = "";
|
|
363
|
+
|
|
364
|
+
/** @type {number[]} */
|
|
365
|
+
const durations = [];
|
|
366
|
+
for (let i = 0, j = 0, k = 0; i < animatedElements.length; i++) {
|
|
367
|
+
const el = animatedElements[i];
|
|
368
|
+
if (el.className && el.className.includes("splitted-text")) {
|
|
369
|
+
k++;
|
|
370
|
+
if (el.textContent === " " && k % 10 === 0 && Math.random() < 0.5) {
|
|
371
|
+
durations.push(400 + Math.random() * 200 - 200);
|
|
372
|
+
} else {
|
|
373
|
+
durations.push(20 + Math.random() * 10 - 10);
|
|
347
374
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
mockedContentFrame.appendChild(root);
|
|
355
|
-
shadowContainer.innerHTML = '';
|
|
356
|
-
|
|
357
|
-
/** @type {number[]} */
|
|
358
|
-
const durations = [];
|
|
359
|
-
for (let i = 0, j = 0, k = 0; i < animatedElements.length; i++) {
|
|
360
|
-
const el = animatedElements[i];
|
|
361
|
-
if (el.className && el.className.includes('splitted-text')) {
|
|
362
|
-
k++;
|
|
363
|
-
if (el.textContent === ' ' && k % 10 === 0 && Math.random() < 0.5) {
|
|
364
|
-
durations.push(400 + Math.random() * 200 - 200);
|
|
365
|
-
} else {
|
|
366
|
-
durations.push(20 + Math.random() * 10 - 10);
|
|
367
|
-
}
|
|
368
|
-
} else {
|
|
369
|
-
j++;
|
|
370
|
-
if (j % 20 === 0 && Math.random() < 0.5) {
|
|
371
|
-
durations.push(250);
|
|
372
|
-
} else {
|
|
373
|
-
durations.push(80 + Math.random() * 40 - 40);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
375
|
+
} else {
|
|
376
|
+
j++;
|
|
377
|
+
if (j % 20 === 0 && Math.random() < 0.5) {
|
|
378
|
+
durations.push(250);
|
|
379
|
+
} else {
|
|
380
|
+
durations.push(80 + Math.random() * 40 - 40);
|
|
376
381
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
const runAnimation = (index) => {
|
|
385
|
+
if (animatedElements.length <= index || animatedElements.length !== durations.length) {
|
|
386
|
+
// setContainerVisible(false);
|
|
387
|
+
// clearTimeout(delayHandler.current);
|
|
388
|
+
onAiAnimationRenderFailed();
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
const el = animatedElements[index];
|
|
385
392
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
393
|
+
el.style.visibility = "visible";
|
|
394
|
+
if (el.tagName === "IMG") {
|
|
395
|
+
el.style.animation = ".5s fade-in ease-in";
|
|
396
|
+
}
|
|
390
397
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
398
|
+
/** @type {HTMLDivElement} */
|
|
399
|
+
const cursor = document.querySelector(".typewriter-cursor");
|
|
400
|
+
if (cursor && el.tagName === "SPAN") {
|
|
401
|
+
cursor.style.visibility = "visible";
|
|
402
|
+
const rect = el.getBoundingClientRect();
|
|
403
|
+
cursor.style.top = rect.y + (rect.height - 14) / 2 + "px";
|
|
404
|
+
cursor.style.left = rect.right + 4 + "px";
|
|
405
|
+
}
|
|
399
406
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
} else {
|
|
417
|
-
// 다음 요소 애니메이션
|
|
418
|
-
delayHandler = setTimeout(() => {
|
|
419
|
-
runAnimation(index + 1);
|
|
420
|
-
}, durations[index]);
|
|
421
|
-
}
|
|
422
|
-
};
|
|
423
|
-
runAnimation(0);
|
|
407
|
+
if (index === durations.length - 1) {
|
|
408
|
+
// 애니메이션 종료
|
|
409
|
+
clearTimeout(delayHandler);
|
|
410
|
+
if (cursor) {
|
|
411
|
+
const anim = cursor.animate([{ opacity: 0 }, { opacity: 1 }], {
|
|
412
|
+
duration: 500,
|
|
413
|
+
iterations: Infinity,
|
|
414
|
+
direction: "alternate-reverse",
|
|
415
|
+
easing: "ease-in-out"
|
|
416
|
+
});
|
|
417
|
+
delayHandler = setTimeout(() => {
|
|
418
|
+
anim.cancel();
|
|
419
|
+
cursor.style.visibility = "hidden";
|
|
420
|
+
cursor.style.animation = "";
|
|
421
|
+
}, 1500);
|
|
422
|
+
}
|
|
424
423
|
} else {
|
|
425
|
-
|
|
424
|
+
// 다음 요소 애니메이션
|
|
425
|
+
delayHandler = setTimeout(() => {
|
|
426
|
+
runAnimation(index + 1);
|
|
427
|
+
}, durations[index]);
|
|
426
428
|
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
|
|
429
|
+
};
|
|
430
|
+
runAnimation(0);
|
|
431
|
+
} else {
|
|
432
|
+
onAiAnimationRenderFailed();
|
|
430
433
|
}
|
|
434
|
+
} catch (e) {
|
|
435
|
+
onAiAnimationRenderFailed();
|
|
436
|
+
}
|
|
437
|
+
}
|
|
431
438
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
439
|
+
try {
|
|
440
|
+
if (isAiAnimationEnable) {
|
|
441
|
+
renderContainerWithAiAnimation();
|
|
442
|
+
} else {
|
|
443
|
+
renderContainer();
|
|
444
|
+
}
|
|
445
|
+
} catch (e) {
|
|
446
|
+
reportErrorWithSlackWebhook(e);
|
|
447
|
+
onRenderFailed();
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
function reportErrorWithSlackWebhook (e) {
|
|
452
|
+
fetch("https://hooks.slack.com/services/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", {
|
|
453
|
+
method: "POST",
|
|
454
|
+
headers: {
|
|
455
|
+
"Content-type": "application/json"
|
|
456
|
+
},
|
|
457
|
+
body: JSON.stringify({
|
|
458
|
+
text: "*Tex Rendering Issue*\`\`\`" + ("" + e) + "\n\`\`\`"
|
|
459
|
+
})
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
const MessageTypes = ["render_tex", "set_phantom_boxes_visibility", "scroll_to_top"];
|
|
464
|
+
|
|
465
|
+
const checkIsValidArgument = (type) => {
|
|
466
|
+
return MessageTypes.includes(type);
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
const handleMessage = ({ type, data }) => {
|
|
470
|
+
if (!checkIsValidArgument(type)) return;
|
|
471
|
+
|
|
472
|
+
try {
|
|
473
|
+
if (type === "render_tex") {
|
|
474
|
+
renderLaTex(data);
|
|
475
|
+
} else if (type === "set_phantom_boxes_visibility") {
|
|
476
|
+
iteratePhantomBoxes((box, border, i) => {
|
|
477
|
+
setPhantomBoxVisibility(i, data.visibility);
|
|
453
478
|
});
|
|
479
|
+
} else if (type === "scroll_to_top") {
|
|
480
|
+
scrollToTop();
|
|
454
481
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
});
|
|
472
|
-
} else if (type === 'scroll_to_top') {
|
|
473
|
-
scrollToTop();
|
|
474
|
-
}
|
|
475
|
-
} catch (e) {}
|
|
476
|
-
};
|
|
477
|
-
|
|
478
|
-
/**
|
|
479
|
-
* For Android, use document and use window for iOS
|
|
480
|
-
* @link https://github.com/react-native-community/react-native-webview/issues/356#issuecomment-467430141
|
|
481
|
-
*/
|
|
482
|
-
document.addEventListener('message', (event) => {
|
|
483
|
-
handleMessage(event.data);
|
|
484
|
-
});
|
|
485
|
-
|
|
486
|
-
window.addEventListener('message', (event) => {
|
|
487
|
-
handleMessage(event.data);
|
|
488
|
-
});
|
|
489
|
-
</script>
|
|
490
|
-
</body>
|
|
482
|
+
} catch (e) {}
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* For Android, use document and use window for iOS
|
|
487
|
+
* @link https://github.com/react-native-community/react-native-webview/issues/356#issuecomment-467430141
|
|
488
|
+
*/
|
|
489
|
+
document.addEventListener("message", (event) => {
|
|
490
|
+
handleMessage(event.data);
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
window.addEventListener("message", (event) => {
|
|
494
|
+
handleMessage(event.data);
|
|
495
|
+
});
|
|
496
|
+
</script>
|
|
497
|
+
</body>
|
|
491
498
|
</html>
|
|
492
499
|
`;
|
|
493
500
|
export default text;
|