@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.
@@ -12,486 +12,493 @@ 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
+ let lastScrollHeight = 0;
165
+ let lastScrollWidth = 0;
166
+ let lastClientWidth = 0;
167
+ const onDocumentResized = () => {
168
+ const container = document.getElementById("container");
169
+ if (container && Math.abs(lastScrollHeight - container.scrollHeight) +
170
+ Math.abs(lastScrollWidth - container.scrollWidth) + Math.abs(lastClientWidth - container.clientWidth) >= 15) {
171
+ lastScrollHeight = container.scrollHeight;
172
+ lastScrollWidth = container.scrollWidth;
173
+ lastClientWidth = container.clientWidth;
174
+ window.ReactNativeWebView.postMessage(
175
+ JSON.stringify({
176
+ event: "set-layout",
177
+ scrollHeight: container.scrollHeight,
178
+ scrollWidth: container.scrollWidth,
179
+ clientWidth: container.clientWidth
180
+ })
181
+ );
182
+ }
183
+ };
184
+
185
+ const scrollToTop = () => {
186
+ window.scrollTo(0, 0);
187
+ };
188
+
189
+ const setPhantomBoxVisibility = (index, state) => {
190
+ const box = document.getElementById("phantom-box-" + index);
191
+ const border = document.getElementById("phantom-box-border-" + index);
192
+ if (box && border) {
193
+ box.classList.remove("_cms_phantom_box_invisible", "_cms_phantom_box_visible", "_cms_phantom_no_box");
194
+ border.classList.remove("_cms_phantom_border_visible", "_cms_phantom_border_invisible");
195
+ if (state === "box_visible") {
196
+ box.classList.add("_cms_phantom_box_visible");
197
+ border.classList.add("_cms_phantom_border_visible");
198
+ } else if (state === "box_invisible") {
199
+ box.classList.add("_cms_phantom_box_invisible");
200
+ border.classList.add("_cms_phantom_border_visible");
201
+ } else {
202
+ box.classList.add("_cms_phantom_no_box");
203
+ border.classList.add("_cms_phantom_border_invisible");
150
204
  }
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);
205
+ }
206
+ };
207
+
208
+ const togglePhantomBoxVisibility = (index) => {
209
+ const box = document.getElementById("phantom-box-" + index);
210
+ if (box) {
211
+ if (box.classList.contains("_cms_phantom_box_invisible")) {
212
+ setPhantomBoxVisibility(index, "box_visible");
213
+ } else if (box.classList.contains("_cms_phantom_box_visible")) {
214
+ setPhantomBoxVisibility(index, "box_invisible");
215
+ } else {
216
+ // if no_box state, do nothing
217
+ }
218
+ }
219
+ };
220
+
221
+ const initializePhantomBoxes = (initialPhantomBoxVisibility, isPhantomBoxClickable) => {
222
+ let count = 0;
223
+ iteratePhantomBoxes((box, border, i) => {
224
+ count += 1;
225
+ initializeBox(box, border, i);
226
+ });
227
+ onPhantomBoxCountChanged(count);
228
+
229
+ function initializeBox (box, border, index) {
230
+ setPhantomBoxVisibility(index, initialPhantomBoxVisibility || "box_invisible");
231
+ if (isPhantomBoxClickable) {
232
+ box.onclick = () => {
233
+ togglePhantomBoxVisibility(index);
234
+ onPhantomBoxPressed(index);
235
+ };
236
+ }
237
+ }
238
+ };
239
+
240
+ const iteratePhantomBoxes = (callback) => {
241
+ try {
242
+ for (let i = 0; ; i++) {
243
+ const box = document.getElementById("phantom-box-" + i);
244
+ const border = document.getElementById("phantom-box-border-" + i);
185
245
  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
- }
246
+ callback(box, border, i);
247
+ } else {
248
+ break;
230
249
  }
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);
250
+ }
251
+ } catch (e) {}
252
+ };
253
+
254
+ const renderLaTex = ({
255
+ html,
256
+ paddingHorizontal,
257
+ initialPhantomBoxVisibility,
258
+ isPhantomBoxClickable,
259
+ paddingBottom,
260
+ paddingTop,
261
+ isAiAnimationEnable
262
+ }) => {
263
+ const container = document.getElementById("container");
264
+ const shadowContainer = document.getElementById("shadow-animation-container");
265
+
266
+ let delayHandler = -1;
267
+
268
+ function setPaddingForContentFrame (element) {
269
+ if (element instanceof HTMLElement) {
270
+ const paddingStyle =
271
+ (paddingTop || 0) +
272
+ "px " +
273
+ (paddingHorizontal || 0) +
274
+ "px " +
275
+ (paddingBottom || "0") +
276
+ "px " +
277
+ (paddingHorizontal || 0) +
278
+ "px";
279
+
280
+ element.style.padding = paddingStyle;
281
+ }
282
+ }
283
+
284
+ function renderContainer () {
285
+ container.innerHTML = html;
286
+ container.style.visibility = "visible";
287
+ shadowContainer.innerHTML = "";
288
+ clearTimeout(delayHandler);
289
+ setPaddingForContentFrame(container.querySelector("." + CONTENT_FRAME_CLASS));
290
+ setTimeout(function() {
291
+ relayout();
292
+ }, 100);
293
+ initializePhantomBoxes(initialPhantomBoxVisibility, isPhantomBoxClickable);
294
+ onRenderSuccess();
295
+ }
296
+
297
+ function onAiAnimationRenderFailed () {
298
+ clearTimeout(delayHandler);
299
+ shadowContainer.innerHTML = "";
300
+ /** @type {HTMLDivElement} */
301
+ const cursor = document.querySelector(".typewriter-cursor");
302
+ if (cursor) {
303
+ cursor.style.visibility = "hidden";
304
+ }
305
+ renderContainer();
306
+ }
307
+
308
+ function renderContainerWithAiAnimation () {
309
+ try {
310
+ container.innerHTML = "";
311
+ const mockedContentFrame = document.createElement("div");
312
+ mockedContentFrame.className = CONTENT_FRAME_CLASS;
313
+ setPaddingForContentFrame(mockedContentFrame);
314
+ container.appendChild(mockedContentFrame);
315
+ shadowContainer.innerHTML = html;
316
+ const root = shadowContainer.querySelector("." + CONTENT_FRAME_CLASS);
317
+ if (root) {
318
+ root.style.visibility = "hidden";
319
+ /** @type {Node[]} */
320
+ const replacedElements = [];
321
+ /** @type {HTMLElement[]} */
322
+ const animatedElements = [];
323
+
324
+ for (let node = root.firstChild; node; node = node.nextSibling) {
325
+ if (node.nodeType === 3 /* text */ && typeof node.textContent === "string" && node.textContent.trim()) {
326
+ for (let i = 0; i < node.textContent.length; i++) {
327
+ /** @type {HTMLSpanElement} */
328
+ const newSpan = document.createElement("span");
329
+ newSpan.textContent = node.textContent.charAt(i);
330
+ newSpan.style.visibility = "hidden";
331
+ newSpan.className += " splitted-text";
332
+ animatedElements.push(newSpan);
333
+ replacedElements.push(newSpan);
334
+ }
335
+ } else if (
336
+ node.firstChild &&
337
+ node.firstChild.firstChild &&
338
+ node.firstChild.firstChild.classList.contains("base")
339
+ ) {
340
+ /** @type {HTMLElement} */
341
+ const katexHtml = node.firstChild;
342
+ for (let i = 0; i < katexHtml.children.length; i++) {
343
+ /** @type {HTMLElement} */
344
+ const baseElement = katexHtml.children[i];
345
+ if (baseElement.classList.contains("base")) {
346
+ baseElement.style.visibility = "hidden";
347
+ animatedElements.push(baseElement);
348
+ }
349
+ }
350
+ replacedElements.push(node);
240
351
  } else {
241
- break;
352
+ if (node.nodeType === 1 /* element */) {
353
+ node.style.visibility = "hidden";
354
+ animatedElements.push(node);
355
+ }
356
+ replacedElements.push(node);
242
357
  }
243
358
  }
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;
359
+ root.innerHTML = "";
360
+ for (const el of replacedElements) {
361
+ root.appendChild(el);
274
362
  }
275
- }
276
-
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
363
 
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
- }
364
+ // 구성된 root를 contianer에 넣어준다.
365
+ mockedContentFrame.appendChild(root);
366
+ shadowContainer.innerHTML = "";
367
+
368
+ /** @type {number[]} */
369
+ const durations = [];
370
+ for (let i = 0, j = 0, k = 0; i < animatedElements.length; i++) {
371
+ const el = animatedElements[i];
372
+ if (el.className && el.className.includes("splitted-text")) {
373
+ k++;
374
+ if (el.textContent === " " && k % 10 === 0 && Math.random() < 0.5) {
375
+ durations.push(400 + Math.random() * 200 - 200);
376
+ } else {
377
+ durations.push(20 + Math.random() * 10 - 10);
351
378
  }
352
- root.innerHTML = '';
353
- for (const el of replacedElements) {
354
- root.appendChild(el);
355
- }
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
- }
379
+ } else {
380
+ j++;
381
+ if (j % 20 === 0 && Math.random() < 0.5) {
382
+ durations.push(250);
383
+ } else {
384
+ durations.push(80 + Math.random() * 40 - 40);
380
385
  }
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];
386
+ }
387
+ }
388
+ const runAnimation = (index) => {
389
+ if (animatedElements.length <= index || animatedElements.length !== durations.length) {
390
+ // setContainerVisible(false);
391
+ // clearTimeout(delayHandler.current);
392
+ onAiAnimationRenderFailed();
393
+ return;
394
+ }
395
+ const el = animatedElements[index];
389
396
 
390
- el.style.visibility = 'visible';
391
- if (el.tagName === 'IMG') {
392
- el.style.animation = '.5s fade-in ease-in';
393
- }
397
+ el.style.visibility = "visible";
398
+ if (el.tagName === "IMG") {
399
+ el.style.animation = ".5s fade-in ease-in";
400
+ }
394
401
 
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
- }
402
+ /** @type {HTMLDivElement} */
403
+ const cursor = document.querySelector(".typewriter-cursor");
404
+ if (cursor && el.tagName === "SPAN") {
405
+ cursor.style.visibility = "visible";
406
+ const rect = el.getBoundingClientRect();
407
+ cursor.style.top = rect.y + (rect.height - 14) / 2 + "px";
408
+ cursor.style.left = rect.right + 4 + "px";
409
+ }
403
410
 
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);
411
+ if (index === durations.length - 1) {
412
+ // 애니메이션 종료
413
+ clearTimeout(delayHandler);
414
+ if (cursor) {
415
+ const anim = cursor.animate([{ opacity: 0 }, { opacity: 1 }], {
416
+ duration: 500,
417
+ iterations: Infinity,
418
+ direction: "alternate-reverse",
419
+ easing: "ease-in-out"
420
+ });
421
+ delayHandler = setTimeout(() => {
422
+ anim.cancel();
423
+ cursor.style.visibility = "hidden";
424
+ cursor.style.animation = "";
425
+ }, 1500);
426
+ }
428
427
  } else {
429
- onAiAnimationRenderFailed();
428
+ // 다음 요소 애니메이션
429
+ delayHandler = setTimeout(() => {
430
+ runAnimation(index + 1);
431
+ }, durations[index]);
430
432
  }
431
- } catch (e) {
432
- onAiAnimationRenderFailed();
433
- }
433
+ };
434
+ runAnimation(0);
435
+ } else {
436
+ onAiAnimationRenderFailed();
434
437
  }
438
+ } catch (e) {
439
+ onAiAnimationRenderFailed();
440
+ }
441
+ }
435
442
 
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
- }),
443
+ try {
444
+ if (isAiAnimationEnable) {
445
+ renderContainerWithAiAnimation();
446
+ } else {
447
+ renderContainer();
448
+ }
449
+ } catch (e) {
450
+ reportErrorWithSlackWebhook(e);
451
+ onRenderFailed();
452
+ }
453
+ };
454
+
455
+ function reportErrorWithSlackWebhook (e) {
456
+ fetch("https://hooks.slack.com/services/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", {
457
+ method: "POST",
458
+ headers: {
459
+ "Content-type": "application/json"
460
+ },
461
+ body: JSON.stringify({
462
+ text: "*Tex Rendering Issue*\`\`\`" + ("" + e) + "\n\`\`\`"
463
+ })
464
+ });
465
+ }
466
+
467
+ const MessageTypes = ["render_tex", "set_phantom_boxes_visibility", "scroll_to_top"];
468
+
469
+ const checkIsValidArgument = (type) => {
470
+ return MessageTypes.includes(type);
471
+ };
472
+
473
+ const handleMessage = ({ type, data }) => {
474
+ if (!checkIsValidArgument(type)) return;
475
+
476
+ try {
477
+ if (type === "render_tex") {
478
+ renderLaTex(data);
479
+ } else if (type === "set_phantom_boxes_visibility") {
480
+ iteratePhantomBoxes((box, border, i) => {
481
+ setPhantomBoxVisibility(i, data.visibility);
457
482
  });
483
+ } else if (type === "scroll_to_top") {
484
+ scrollToTop();
458
485
  }
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>
486
+ } catch (e) {}
487
+ };
488
+
489
+ /**
490
+ * For Android, use document and use window for iOS
491
+ * @link https://github.com/react-native-community/react-native-webview/issues/356#issuecomment-467430141
492
+ */
493
+ document.addEventListener("message", (event) => {
494
+ handleMessage(event.data);
495
+ });
496
+
497
+ window.addEventListener("message", (event) => {
498
+ handleMessage(event.data);
499
+ });
500
+ </script>
501
+ </body>
495
502
  </html>
496
503
  `;
497
504
  var _default = exports.default = text;