minecodex 2.0.38 → 2.0.40
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/README.md +1 -0
- package/apps/dashboard/assets/preview-content.js +3 -0
- package/features/markdown-reading/src/adapters/codex/lists.mjs +0 -26
- package/features/markdown-reading/src/adapters/codex/reading-runtime.mjs +5 -3
- package/features/markdown-reading/src/adapters/codex/rich-text.mjs +1 -1
- package/features/markdown-reading/src/adapters/codex/table-actions.mjs +1 -108
- package/features/markdown-reading/src/adapters/codex/toc.mjs +1 -1
- package/features/markdown-reading/src/injection-source.mjs +8 -10
- package/features/markdown-reading/src/markdown-reading.mjs +5 -2
- package/features/mermaid-diagrams/assets/qv-dependencies.js +4412 -0
- package/features/mermaid-diagrams/assets/qv-export.js +2 -0
- package/features/mermaid-diagrams/assets/qv-loading.css +4 -0
- package/features/mermaid-diagrams/assets/qv-template.json +1 -0
- package/features/mermaid-diagrams/assets/workflow.svg +15 -0
- package/features/mermaid-diagrams/codex-feature.json +31 -0
- package/features/mermaid-diagrams/src/adapters/codex/mermaid-viewer.mjs +95 -0
- package/features/mermaid-diagrams/src/adapters/codex/mermaid.mjs +91 -0
- package/features/mermaid-diagrams/src/adapters/codex/native.mjs +34 -0
- package/features/mermaid-diagrams/src/adapters/codex/runtime.mjs +42 -0
- package/features/mermaid-diagrams/src/injection-source.mjs +26 -0
- package/features/mermaid-diagrams/src/mermaid/export.mjs +83 -0
- package/features/mermaid-diagrams/src/mermaid/frame.mjs +109 -0
- package/features/mermaid-diagrams/src/mermaid/loading.mjs +27 -0
- package/features/mermaid-diagrams/src/mermaid/theme.css +8 -0
- package/features/mermaid-diagrams/src/mermaid/viewport.mjs +75 -0
- package/features/mermaid-diagrams/src/mermaid-diagrams.mjs +85 -0
- package/features/mermaid-diagrams/vendor/lucide-LICENSE +43 -0
- package/features/mermaid-diagrams/vendor/qv/LICENSE +21 -0
- package/features/mermaid-diagrams/vendor/qv/THIRD_PARTY_NOTICES.txt +3009 -0
- package/features/mermaid-diagrams/vendor/qv/provenance.json +55 -0
- package/features/usage-meter/src/adapters/codex/renderer.mjs +11 -3
- package/features/usage-meter/src/usage-meter.mjs +19 -4
- package/package.json +19 -5
- package/packages/cli/src/config.mjs +2 -1
- package/packages/cli/src/control-server.mjs +1 -1
- package/packages/codex-adapter/src/markdown/block-actions.mjs +107 -0
- package/packages/codex-adapter/src/markdown/editor-api.mjs +26 -0
- package/{features/markdown-reading/src/adapters/codex → packages/codex-adapter/src/markdown}/preview.mjs +2 -8
- package/packages/plugin/assets/app.js +2 -2
- /package/{features/markdown-reading/src/adapters/codex → packages/codex-adapter/src/markdown}/markdown-native.mjs +0 -0
- /package/{features/markdown-reading/src/adapters/codex → packages/codex-adapter/src/markdown}/providers.mjs +0 -0
- /package/{features/markdown-reading/src/adapters/codex → packages/codex-adapter/src/markdown}/toc-native.mjs +0 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// 原生查看器负责缩放;此桥仅保留完整场景、转发 iframe 输入和恢复正文位置。
|
|
2
|
+
export function createMermaidViewport(root) {
|
|
3
|
+
if (root.__mcxViewport) return root.__mcxViewport;
|
|
4
|
+
let viewport = root.querySelector('.diagram-scroll'), scene = root.querySelector('.scene');
|
|
5
|
+
if (!viewport || !scene) {
|
|
6
|
+
viewport = document.createElement('div'); scene = document.createElement('div');
|
|
7
|
+
viewport.className = 'diagram-scroll'; scene.className = 'scene'; scene.style.width = root.clientWidth + 'px';
|
|
8
|
+
for (const child of [...root.children]) if (!['STYLE','H3'].includes(child.tagName)) scene.append(child);
|
|
9
|
+
viewport.append(scene); root.append(viewport); scene.style.position = 'relative'; viewport.style.width = '100%';
|
|
10
|
+
}
|
|
11
|
+
const positions = new Map(), inlinePositions = new Map();
|
|
12
|
+
let mode = window.openai?.displayMode || 'inline', restorePending = null, frame = 0, drag = null, suppressClick = false;
|
|
13
|
+
const scope = () => root.dataset.scope || 'diagram';
|
|
14
|
+
const expanded = () => mode === 'viewer';
|
|
15
|
+
const send = detail => root.dispatchEvent(new CustomEvent('mcx:qv-viewer-input',{bubbles:true,detail}));
|
|
16
|
+
function refresh() {
|
|
17
|
+
root.dataset.displayMode = mode;
|
|
18
|
+
if (expanded()) {
|
|
19
|
+
viewport.style.paddingBottom = '0'; viewport.style.height = scene.offsetHeight + 'px';
|
|
20
|
+
viewport.style.overflow = 'hidden'; viewport.style.cursor = 'grab'; viewport.style.touchAction = 'none'; viewport.scrollLeft = 0;
|
|
21
|
+
} else {
|
|
22
|
+
for (const key of ['height','overflow','touchAction','cursor','paddingBottom']) viewport.style[key] = '';
|
|
23
|
+
if (restorePending) {
|
|
24
|
+
viewport.scrollLeft = restorePending.left;
|
|
25
|
+
if (viewport.scrollLeft === restorePending.left || viewport.clientWidth === restorePending.width) restorePending = null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const schedule = () => { if (!frame) frame = requestAnimationFrame(() => { frame=0;refresh(); }); };
|
|
30
|
+
const captureInline = () => { if (!expanded()) inlinePositions.set(scope(),{left:viewport.scrollLeft,width:viewport.clientWidth}); };
|
|
31
|
+
captureInline();
|
|
32
|
+
viewport.addEventListener('scroll',() => {const saved=inlinePositions.get(scope());if (!expanded()&&!restorePending&&(!saved||saved.width===viewport.clientWidth)) captureInline();},{passive:true});
|
|
33
|
+
window.addEventListener('openai:set_globals',event => {
|
|
34
|
+
const next = event.detail?.globals?.displayMode || window.openai?.displayMode || mode;
|
|
35
|
+
if (next === mode) { schedule();return; }
|
|
36
|
+
if (next === 'viewer') {const saved=inlinePositions.get(scope());positions.set(scope(),saved&&saved.width!==viewport.clientWidth?saved:{left:viewport.scrollLeft,width:viewport.clientWidth});}
|
|
37
|
+
else restorePending = positions.get(scope()) || {left:0,width:viewport.clientWidth};
|
|
38
|
+
mode = next; refresh();
|
|
39
|
+
if (expanded()) root.getAnimations?.({subtree:true}).forEach(animation=>animation.cancel());
|
|
40
|
+
// 只让关闭后的正文恢复原版几何,缩放与拖拽不触发图型重绘。
|
|
41
|
+
if (!expanded()) root.dispatchEvent(new Event('qv:display-mode'));
|
|
42
|
+
});
|
|
43
|
+
viewport.addEventListener('wheel',event => {
|
|
44
|
+
if (!expanded()) {captureInline();return;}
|
|
45
|
+
event.preventDefault();event.stopPropagation();send({kind:'wheel',deltaY:event.deltaY,deltaMode:event.deltaMode,x:event.clientX,y:event.clientY});
|
|
46
|
+
},{passive:false});
|
|
47
|
+
viewport.addEventListener('pointerdown',event => {
|
|
48
|
+
if (!expanded()) {captureInline();return;}
|
|
49
|
+
if (event.button!==0 || event.target.closest('input,a')) return;
|
|
50
|
+
suppressClick=false;drag={id:event.pointerId,x:event.clientX,y:event.clientY,moved:false};send({kind:'start'});
|
|
51
|
+
},true);
|
|
52
|
+
viewport.addEventListener('pointermove',event => {
|
|
53
|
+
if (!drag || drag.id!==event.pointerId) return;
|
|
54
|
+
const dx=event.clientX-drag.x,dy=event.clientY-drag.y;
|
|
55
|
+
if (!drag.moved && Math.hypot(dx,dy)<5) return;
|
|
56
|
+
if (!drag.moved) {drag.moved=true;viewport.setPointerCapture(event.pointerId);}
|
|
57
|
+
event.preventDefault();event.stopImmediatePropagation();viewport.style.cursor='grabbing';send({kind:'drag',dx,dy});
|
|
58
|
+
},true);
|
|
59
|
+
const end=event => {
|
|
60
|
+
if (!drag || drag.id!==event.pointerId) return;
|
|
61
|
+
suppressClick=drag.moved;
|
|
62
|
+
if (viewport.hasPointerCapture(event.pointerId)) viewport.releasePointerCapture(event.pointerId);
|
|
63
|
+
if (drag.moved) {event.preventDefault();event.stopImmediatePropagation();}
|
|
64
|
+
drag=null;viewport.style.cursor=expanded()?'grab':'';send({kind:'end'});
|
|
65
|
+
};
|
|
66
|
+
viewport.addEventListener('pointerup',end,true);viewport.addEventListener('pointercancel',end,true);
|
|
67
|
+
viewport.addEventListener('click',event => {if(suppressClick){suppressClick=false;event.preventDefault();event.stopImmediatePropagation();}},true);
|
|
68
|
+
document.addEventListener('keydown',event => {
|
|
69
|
+
if (!expanded() || event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey || event.target.closest('input,textarea,[contenteditable=true]')) return;
|
|
70
|
+
if (['ArrowLeft','ArrowRight','ArrowUp','ArrowDown'].includes(event.key)) {event.preventDefault();send({kind:'pan',dx:event.key==='ArrowLeft'?-40:event.key==='ArrowRight'?40:0,dy:event.key==='ArrowUp'?-40:event.key==='ArrowDown'?40:0});}
|
|
71
|
+
});
|
|
72
|
+
const observer=new ResizeObserver(schedule);[root,viewport,scene].forEach(e=>observer.observe(e));
|
|
73
|
+
root.__mcxViewport={refresh,get expanded(){return expanded();},get scale(){return 1;},get savedInlinePosition(){const saved=positions.get(scope());return saved?{...saved}:null;}};
|
|
74
|
+
refresh();return root.__mcxViewport;
|
|
75
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const marker = 'data-minecodex-mermaid-diagrams';
|
|
2
|
+
const runtime = createMermaidRuntime(config.codex, config.resources);
|
|
3
|
+
const native = createMarkdownPreviewAdapter(config.codex, item => runtime.attach(item));
|
|
4
|
+
const styled = new Map();
|
|
5
|
+
const sessions = new Map();
|
|
6
|
+
const tokenNames = ['--font-content', '--text-document', '--leading-relaxed', '--font-weight-semibold',
|
|
7
|
+
'--color-token-main-surface-primary', '--color-token-bg-secondary', '--color-text-foreground',
|
|
8
|
+
'--color-text-foreground-secondary', '--color-border'];
|
|
9
|
+
const style = document.createElement('style');
|
|
10
|
+
style.setAttribute('data-minecodex-mermaid-diagrams-styles', '');
|
|
11
|
+
style.textContent = [config.resources.mermaidStyles, config.resources.qvLoadingStyles].join('\n');
|
|
12
|
+
document.head.append(style);
|
|
13
|
+
let disposed = false;
|
|
14
|
+
let pending = null;
|
|
15
|
+
|
|
16
|
+
function release(editor) {
|
|
17
|
+
const binding = styled.get(editor);
|
|
18
|
+
sessions.get(editor)?.dispose();
|
|
19
|
+
sessions.delete(editor);
|
|
20
|
+
editor.removeAttribute(marker);
|
|
21
|
+
binding?.();
|
|
22
|
+
styled.delete(editor);
|
|
23
|
+
}
|
|
24
|
+
function reconcile() {
|
|
25
|
+
pending = null;
|
|
26
|
+
if (disposed) return;
|
|
27
|
+
const previews = native.previews();
|
|
28
|
+
const editors = new Set(previews.map((item) => item.editor));
|
|
29
|
+
for (const editor of styled.keys()) if (!editors.has(editor)) release(editor);
|
|
30
|
+
for (const preview of previews) {
|
|
31
|
+
const { editor } = preview;
|
|
32
|
+
if (!styled.has(editor)) styled.set(editor, config.ui.theme.bindScope(editor, tokenNames));
|
|
33
|
+
if (!editor.hasAttribute(marker)) editor.setAttribute(marker, '');
|
|
34
|
+
if (!sessions.has(editor)) sessions.set(editor, native.attach(preview));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function schedule(records) {
|
|
39
|
+
// 忽略原生选区与逐行装饰更新;只在预览视图或其祖先变化时重新定位。
|
|
40
|
+
if (records.every((record) => record.target.closest?.('.cm-content, [data-mcx-reading-toc]'))) return;
|
|
41
|
+
if (!disposed && pending === null) pending = window.requestAnimationFrame(reconcile);
|
|
42
|
+
}
|
|
43
|
+
const observer = new MutationObserver(schedule);
|
|
44
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
45
|
+
reconcile();
|
|
46
|
+
config.registerSelfCheck?.(() => {
|
|
47
|
+
const previews = native.previews();
|
|
48
|
+
const styleAvailable =
|
|
49
|
+
style.isConnected && previews.length > 0 && previews.every(({ editor }) => editor.hasAttribute(marker));
|
|
50
|
+
const sessionChecks = previews.map(({ editor }) => sessions.get(editor)?.checks() ?? []);
|
|
51
|
+
const checks = previews.length
|
|
52
|
+
? [
|
|
53
|
+
{ name: 'mermaid-preview-styled', available: styleAvailable },
|
|
54
|
+
...(sessionChecks[0] ?? []).map((check) => ({
|
|
55
|
+
name: check.name,
|
|
56
|
+
available: sessionChecks.every((items) =>
|
|
57
|
+
items.some((item) => item.name === check.name && item.available),
|
|
58
|
+
),
|
|
59
|
+
})),
|
|
60
|
+
]
|
|
61
|
+
: [];
|
|
62
|
+
const available =
|
|
63
|
+
styleAvailable &&
|
|
64
|
+
sessionChecks.every((items) => items.length > 0) &&
|
|
65
|
+
checks.every((check) => check.available);
|
|
66
|
+
return {
|
|
67
|
+
state: previews.length ? (available ? 'available' : 'unavailable') : 'not-applicable',
|
|
68
|
+
reason: previews.length
|
|
69
|
+
? available
|
|
70
|
+
? null
|
|
71
|
+
: styleAvailable
|
|
72
|
+
? 'mermaid-diagrams-layout-unavailable'
|
|
73
|
+
: 'markdown-style-unavailable'
|
|
74
|
+
: 'no-markdown-preview',
|
|
75
|
+
checks,
|
|
76
|
+
scopes: previews.map(({ editor }) => ({ name: 'markdown-preview', element: editor })),
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
return () => {
|
|
80
|
+
disposed = true;
|
|
81
|
+
observer.disconnect();
|
|
82
|
+
if (pending !== null) window.cancelAnimationFrame(pending);
|
|
83
|
+
for (const editor of styled.keys()) release(editor);
|
|
84
|
+
style.remove();
|
|
85
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lucide Icons and Contributors
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
The following Lucide icons are derived from the Feather project:
|
|
20
|
+
|
|
21
|
+
airplay, alert-circle, alert-octagon, alert-triangle, aperture, arrow-down-circle, arrow-down-left, arrow-down-right, arrow-down, arrow-left-circle, arrow-left, arrow-right-circle, arrow-right, arrow-up-circle, arrow-up-left, arrow-up-right, arrow-up, at-sign, calendar, cast, check, chevron-down, chevron-left, chevron-right, chevron-up, chevrons-down, chevrons-left, chevrons-right, chevrons-up, circle, clipboard, clock, code, columns, command, compass, corner-down-left, corner-down-right, corner-left-down, corner-left-up, corner-right-down, corner-right-up, corner-up-left, corner-up-right, crosshair, database, divide-circle, divide-square, dollar-sign, download, external-link, feather, frown, hash, headphones, help-circle, info, italic, key, layout, life-buoy, link-2, link, loader, lock, log-in, log-out, maximize, meh, minimize, minimize-2, minus-circle, minus-square, minus, monitor, moon, more-horizontal, more-vertical, move, music, navigation-2, navigation, octagon, pause-circle, percent, plus-circle, plus-square, plus, power, radio, rss, search, server, share, shopping-bag, sidebar, smartphone, smile, square, table-2, tablet, target, terminal, trash-2, trash, triangle, tv, type, upload, x-circle, x-octagon, x-square, x, zoom-in, zoom-out
|
|
22
|
+
|
|
23
|
+
The MIT License (MIT) (for the icons listed above)
|
|
24
|
+
|
|
25
|
+
Copyright (c) 2013-present Cole Bemis
|
|
26
|
+
|
|
27
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
28
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
29
|
+
in the Software without restriction, including without limitation the rights
|
|
30
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
31
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
32
|
+
furnished to do so, subject to the following conditions:
|
|
33
|
+
|
|
34
|
+
The above copyright notice and this permission notice shall be included in all
|
|
35
|
+
copies or substantial portions of the Software.
|
|
36
|
+
|
|
37
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
38
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
39
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
40
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
41
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
42
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
43
|
+
SOFTWARE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vontean
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|