@teamturing/react-native-tex 1.1.6 → 1.1.8

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