@mujian/js-sdk 0.0.6-beta.17 → 0.0.6-beta.19

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.
@@ -6,4 +6,4 @@ export declare const replaceVhInContent: (content: string) => string;
6
6
  * @returns 转义后的值
7
7
  */
8
8
  export declare function escapeHtmlAttribute(value: string): string;
9
- export declare function createSrcContent(content: string, use_blob_url?: boolean): string;
9
+ export declare function createSrcContent(content: string): string;
@@ -0,0 +1,4 @@
1
+ export declare const iframeDOMLoaded = "\n(function () {\n function emit_loaded_event() {\n window.parent.postMessage({ type: 'MJ_DOM_CONTENT_LOADED', iframeId: '123' }, '*');\n }\n\n if (window.document.readyState === 'loading') {\n window.document.addEventListener('DOMContentLoaded', emit_loaded_event, { once: true });\n } else {\n emit_loaded_event();\n }\n})();\n";
2
+ export declare const iframeAdjustViewport: string;
3
+ export declare const init = "\n(async function () {\n\nwindow.$mujian2 = window.parent.$mujian;\nconst result = await $mujian2?.ai.chat.project.getInfo();\nconsole.log('result', result);\n\n})();\n";
4
+ export declare const thirdParty = "\n<script src=\"https://cdn.jsdmirror.com/npm/@fortawesome/fontawesome-free/js/all.min.js\"></script>\n<script src=\"https://cdn.jsdmirror.com/npm/@tailwindcss/browser/dist/index.global.min.js\"></script>\n<script src=\"https://cdn.jsdmirror.com/npm/jquery/dist/jquery.min.js\"></script>\n<script src=\"https://cdn.jsdmirror.com/npm/jquery-ui/dist/jquery-ui.min.js\"></script>\n<link rel=\"stylesheet\" href=\"https://cdn.jsdmirror.com/npm/jquery-ui/themes/base/theme.min.css\" />\n<script src=\"https://cdn.jsdmirror.com/npm/jquery-ui-touch-punch\"></script>\n";
package/dist/react.css CHANGED
@@ -89,6 +89,69 @@
89
89
  -moz-osx-font-smoothing: grayscale;
90
90
  }
91
91
 
92
+ .spin-overlay {
93
+ background-color: #000;
94
+ animation: 3s ease-in-out infinite breath;
95
+ }
96
+
97
+ @keyframes breath {
98
+ 0% {
99
+ background-color: #0009;
100
+ }
101
+
102
+ 50% {
103
+ background-color: #00000080;
104
+ }
105
+
106
+ 100% {
107
+ background-color: #0009;
108
+ }
109
+ }
110
+
111
+ .wave-text span {
112
+ font-family: var(--mainFontFamily);
113
+ animation: 2s ease-in-out infinite wave;
114
+ display: inline-block;
115
+ }
116
+
117
+ .wave-text span:first-child {
118
+ animation-delay: 0s;
119
+ }
120
+
121
+ .wave-text span:nth-child(2) {
122
+ animation-delay: .2s;
123
+ }
124
+
125
+ .wave-text span:nth-child(3) {
126
+ animation-delay: .4s;
127
+ }
128
+
129
+ .wave-text span:nth-child(4) {
130
+ animation-delay: .6s;
131
+ }
132
+
133
+ .wave-text span:nth-child(5) {
134
+ animation-delay: .8s;
135
+ }
136
+
137
+ .wave-text span:nth-child(6) {
138
+ animation-delay: 1s;
139
+ }
140
+
141
+ .wave-text span:nth-child(7) {
142
+ animation-delay: 1.2s;
143
+ }
144
+
145
+ @keyframes wave {
146
+ 0%, 100% {
147
+ transform: translateY(0);
148
+ }
149
+
150
+ 50% {
151
+ transform: translateY(-8px);
152
+ }
153
+ }
154
+
92
155
  body {
93
156
  font-size: var(--mainFontSize);
94
157
  color: var(--SmartThemeBodyColor);
package/dist/react.js CHANGED
@@ -235,6 +235,24 @@ function messageFormatting(mes, sanitizerOverrides = {}) {
235
235
  });
236
236
  return mes;
237
237
  }
238
+ window.parent.innerHeight, window.parent.innerHeight;
239
+ const init = `
240
+ (async function () {
241
+
242
+ window.$mujian2 = window.parent.$mujian;
243
+ const result = await $mujian2?.ai.chat.project.getInfo();
244
+ console.log('result', result);
245
+
246
+ })();
247
+ `;
248
+ const thirdParty = `
249
+ <script src="https://cdn.jsdmirror.com/npm/@fortawesome/fontawesome-free/js/all.min.js"></script>
250
+ <script src="https://cdn.jsdmirror.com/npm/@tailwindcss/browser/dist/index.global.min.js"></script>
251
+ <script src="https://cdn.jsdmirror.com/npm/jquery/dist/jquery.min.js"></script>
252
+ <script src="https://cdn.jsdmirror.com/npm/jquery-ui/dist/jquery-ui.min.js"></script>
253
+ <link rel="stylesheet" href="https://cdn.jsdmirror.com/npm/jquery-ui/themes/base/theme.min.css" />
254
+ <script src="https://cdn.jsdmirror.com/npm/jquery-ui-touch-punch"></script>
255
+ `;
238
256
  const unescapeHTML = (str)=>{
239
257
  const named = {
240
258
  amp: "&",
@@ -291,27 +309,24 @@ const replaceVhInContent = (content)=>{
291
309
  function escapeHtmlAttribute(value) {
292
310
  return value.replace(/"/g, "&quot;").replace(/'/g, "&#39;");
293
311
  }
294
- function createSrcContent(content, use_blob_url = false) {
312
+ function createSrcContent(content) {
295
313
  content = replaceVhInContent(content);
296
314
  const getUserAvatarPath = ()=>"https://www.mujian.com/avatar.png";
297
315
  const getCharAvatarPath = ()=>"https://www.mujian.com/avatar.png";
298
- const third_party = "";
299
- const predefine_url = "";
300
- const emit_loaded_event_url = "";
301
- const adjust_viewport_url = "";
302
316
  return `
303
317
  <html>
304
318
  <head>
305
319
  <style>
320
+
306
321
  html,body{margin:0;padding:0;overflow:hidden!important;max-width:100%!important;box-sizing:border-box}
307
322
  .user_avatar,.user-avatar{background-image:url('${getUserAvatarPath()}')}
308
323
  .char_avatar,.char-avatar{background-image:url('${getCharAvatarPath()}')}
324
+
309
325
  </style>
310
- ${third_party}
311
- ${use_blob_url ? `<base href="${window.location.origin}"/>` : ""}
312
- <script src="${predefine_url}"></script>
313
- <script src="${emit_loaded_event_url}"></script>
314
- <script src="${adjust_viewport_url}"></script>
326
+ ${thirdParty}
327
+ <script>
328
+ ${init}
329
+ </script>
315
330
  </head>
316
331
  <body>
317
332
  ${content}
@@ -325,9 +340,6 @@ function adjustIframeHeight(iframe) {
325
340
  const height = Math.max(document1.body.offsetHeight, document1.documentElement.offsetHeight);
326
341
  if (!Number.isFinite(height) || height <= 0) return;
327
342
  iframe.style.height = `${height}px`;
328
- iframe.contentWindow.postMessage({
329
- type: "MJ_UPDATE_VIEWPORT_HEIGHT"
330
- }, "*");
331
343
  }
332
344
  const observed_elements = new Map();
333
345
  const observer = new ResizeObserver((entries)=>{
@@ -356,27 +368,34 @@ function useHeightObserver() {
356
368
  }
357
369
  const MdRendererBase = ({ content })=>{
358
370
  const containerRef = useRef(null);
359
- useRef([]);
360
371
  const [iframeIdList, setIframeIdList] = useState([]);
361
372
  const { observe, unobserve } = useHeightObserver();
362
373
  useEffect(()=>{
363
374
  let mes = messageFormatting(content);
364
- mes = mes.replace(/<code(.*)>[\s\S]*?<\/code>/g, (match)=>{
365
- const code = match.replace("<code>", "").replace("</code>", "");
375
+ mes = mes.replace(/<pre><code(.*)>[\s\S]*?<\/code><\/pre>/g, (match)=>{
376
+ if (!match.includes("&lt;body&gt;") && !match.includes("&lt;/body&gt;")) return match;
377
+ const code = match.replace("<pre><code>", "").replace("</code></pre>", "");
366
378
  const srcdoc = createSrcContent(unescapeHTML(code));
367
379
  const id = v4();
368
- setIframeIdList([
369
- ...iframeIdList,
370
- id
371
- ]);
380
+ setIframeIdList((prev)=>[
381
+ ...prev,
382
+ id
383
+ ]);
372
384
  const escapedSrcdoc = escapeHtmlAttribute(srcdoc);
373
385
  return `
374
- <div class="MJ-iframe-container" id="MJ-iframe-container-${id}" style="display:flex;width:100%;height:100%;position:relative;">
375
- <div class="spin-overlay" id="MJ-spin-${id}" style="width:100%;height:100%;position:absolute;top:0;left:0;z-index:1000;background-color:rgba(0,0,0,0.3);display:flex;justify-content:center;align-items:center;">
376
- <div class="spin-inner" style="font-weight:500;font-size:16px;color:white;display:flex;justify-content:center;align-items:center;">加载中...</div>
377
- </div>
378
- <iframe id="MJ-iframe-${id}" sandbox="allow-scripts allow-same-origin" loading="lazy" referrerpolicy="no-referrer" style="width:100%;height:100%;border:none;" srcdoc="` + escapedSrcdoc + `"></iframe>
379
- </div>
386
+ <div class="MJ-iframe-container" id="MJ-iframe-container-${id}" style="display:flex;width:100%;height:100%;position:relative;">
387
+ <div class="spin-overlay" id="MJ-spin-${id}" style="width:100%;height:100%;position:absolute;top:0;left:0;z-index:1000;background-color:rgba(0,0,0,0.5);display:flex;justify-content:center;align-items:center;">
388
+ <div class="spin-inner wave-text" style="font-weight:500;font-size:16px;color:white;display:flex;justify-content:center;align-items:center;">
389
+ <span>加</span>
390
+ <span>载</span>
391
+ <span>中</span>
392
+ <span>.</span>
393
+ <span>.</span>
394
+ <span>.</span>
395
+ </div>
396
+ </div>
397
+ <iframe id="MJ-iframe-${id}" sandbox="allow-scripts allow-same-origin" loading="lazy" referrerpolicy="no-referrer" style="width:100%;height:100%;border:none;" srcdoc="` + escapedSrcdoc + `"></iframe>
398
+ </div>
380
399
  `;
381
400
  });
382
401
  if (containerRef.current) containerRef.current.innerHTML = mes;
@@ -384,7 +403,6 @@ const MdRendererBase = ({ content })=>{
384
403
  content
385
404
  ]);
386
405
  useEffect(()=>{
387
- console.log("iframeIdList", iframeIdList);
388
406
  iframeIdList.forEach((id)=>{
389
407
  const iframe = document.getElementById("MJ-iframe-" + id);
390
408
  if (!iframe) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mujian/js-sdk",
3
- "version": "0.0.6-beta.17",
3
+ "version": "0.0.6-beta.19",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
File without changes