vitepress-plugin-diagrams 1.2.0 → 1.2.2
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.es.md +4 -0
- package/README.md +4 -0
- package/README.ru.md +4 -0
- package/README.uk.md +4 -0
- package/README.zh.md +4 -0
- package/dist/__tests__/file-import-integration.test.d.ts +1 -0
- package/dist/__tests__/file-import-utils.test.d.ts +1 -0
- package/dist/index.cjs +6 -5
- package/dist/index.d.ts +4 -2
- package/dist/index.js +254 -142
- package/dist/types.d.ts +12 -0
- package/dist/utils.d.ts +51 -1
- package/package.json +1 -1
package/README.es.md
CHANGED
|
@@ -24,6 +24,10 @@ Los diagramas están diseñados para ser generados en el tiempo __DEV__ debido a
|
|
|
24
24
|
- Posibilidad de usar cualquier editor para crear diagramas (por ejemplo, VS Code con extensión Mermaid)
|
|
25
25
|
- **Importar diagramas desde archivos externos** usando la sintaxis `@file:`
|
|
26
26
|
|
|
27
|
+
## Demo
|
|
28
|
+
|
|
29
|
+
Consulta la [demo en vivo](https://vuesence.github.io/vitepress-plugin-diagrams/demo/) para ver el plugin en acción.
|
|
30
|
+
|
|
27
31
|

|
|
28
32
|
|
|
29
33
|
## Instalación
|
package/README.md
CHANGED
|
@@ -25,6 +25,10 @@ The diagrams are meant to be generated at __DEV time__ because:
|
|
|
25
25
|
- Use can use any editor to create diagrams (for example `VS Code` with `Mermaid` extension)
|
|
26
26
|
- **Import diagrams from external files** using `@file:` syntax
|
|
27
27
|
|
|
28
|
+
## Demo
|
|
29
|
+
|
|
30
|
+
Check out the [live demo](https://vuesence.github.io/vitepress-plugin-diagrams/demo/) to see the plugin in action.
|
|
31
|
+
|
|
28
32
|

|
|
29
33
|
|
|
30
34
|
## Installation
|
package/README.ru.md
CHANGED
|
@@ -24,6 +24,10 @@
|
|
|
24
24
|
- Возможность использования любого редактора для создания диаграмм (например, `VS Code` с расширением `Mermaid`)
|
|
25
25
|
- **Импорт диаграмм из внешних файлов** с использованием синтаксиса `@file:`
|
|
26
26
|
|
|
27
|
+
## Демо
|
|
28
|
+
|
|
29
|
+
Посмотрите на [живое демо](https://vuesence.github.io/vitepress-plugin-diagrams/demo/), чтобы увидеть плагин в действии.
|
|
30
|
+
|
|
27
31
|

|
|
28
32
|
|
|
29
33
|
## Установка
|
package/README.uk.md
CHANGED
|
@@ -24,6 +24,10 @@
|
|
|
24
24
|
- Можливість використання будь-якого редактора для створення діаграм (наприклад, VS Code з розширенням Mermaid)
|
|
25
25
|
- **Імпорт діаграм із зовнішніх файлів** за допомогою синтаксису `@file:`
|
|
26
26
|
|
|
27
|
+
## Демо
|
|
28
|
+
|
|
29
|
+
Перегляньте [живе демо](https://vuesence.github.io/vitepress-plugin-diagrams/demo/), щоб побачити плагін у дії.
|
|
30
|
+
|
|
27
31
|

|
|
28
32
|
|
|
29
33
|
## Встановлення
|
package/README.zh.md
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=require("node:fs"),q=require("node:path"),j=require("node:crypto"),O=require("node:process");function B(t){const u=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const e in t)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(u,e,s.get?s:{enumerable:!0,get:()=>t[e]})}}return u.default=t,Object.freeze(u)}const C=B(z),x=B(q),_=B(j),A=B(O),v=["blockdiag","bpmn","bytefield","seqdiag","actdiag","nwdiag","packetdiag","rackdiag","c4plantuml","d2","dbml","ditaa","erd","excalidraw","graphviz","mermaid","nomnoml","pikchr","plantuml","structurizr","svgbob","symbolator","tikz","umlet","vega","vega-lite","wavedrom","wireviz"],R=/[!-#%-\*,-\/:;\?@\[-\]_\{\}\xA1\xA7\xAB\xB6\xB7\xBB\xBF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061D-\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u09FD\u0A76\u0AF0\u0C77\u0C84\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1B7D\u1B7E\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E4F\u2E52-\u2E5D\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]|\uD800[\uDD00-\uDD02\uDF9F\uDFD0]|\uD801\uDD6F|\uD802[\uDC57\uDD1F\uDD3F\uDE50-\uDE58\uDE7F\uDEF0-\uDEF6\uDF39-\uDF3F\uDF99-\uDF9C]|\uD803[\uDEAD\uDF55-\uDF59\uDF86-\uDF89]|\uD804[\uDC47-\uDC4D\uDCBB\uDCBC\uDCBE-\uDCC1\uDD40-\uDD43\uDD74\uDD75\uDDC5-\uDDC8\uDDCD\uDDDB\uDDDD-\uDDDF\uDE38-\uDE3D\uDEA9]|\uD805[\uDC4B-\uDC4F\uDC5A\uDC5B\uDC5D\uDCC6\uDDC1-\uDDD7\uDE41-\uDE43\uDE60-\uDE6C\uDEB9\uDF3C-\uDF3E]|\uD806[\uDC3B\uDD44-\uDD46\uDDE2\uDE3F-\uDE46\uDE9A-\uDE9C\uDE9E-\uDEA2\uDF00-\uDF09]|\uD807[\uDC41-\uDC45\uDC70\uDC71\uDEF7\uDEF8\uDF43-\uDF4F\uDFFF]|\uD809[\uDC70-\uDC74]|\uD80B[\uDFF1\uDFF2]|\uD81A[\uDE6E\uDE6F\uDEF5\uDF37-\uDF3B\uDF44]|\uD81B[\uDE97-\uDE9A\uDFE2]|\uD82F\uDC9F|\uD836[\uDE87-\uDE8B]|\uD83A[\uDD5E\uDD5F]/,I=/[\$\+<->\^`\|~\xA2-\xA6\xA8\xA9\xAC\xAE-\xB1\xB4\xB8\xD7\xF7\u02C2-\u02C5\u02D2-\u02DF\u02E5-\u02EB\u02ED\u02EF-\u02FF\u0375\u0384\u0385\u03F6\u0482\u058D-\u058F\u0606-\u0608\u060B\u060E\u060F\u06DE\u06E9\u06FD\u06FE\u07F6\u07FE\u07FF\u0888\u09F2\u09F3\u09FA\u09FB\u0AF1\u0B70\u0BF3-\u0BFA\u0C7F\u0D4F\u0D79\u0E3F\u0F01-\u0F03\u0F13\u0F15-\u0F17\u0F1A-\u0F1F\u0F34\u0F36\u0F38\u0FBE-\u0FC5\u0FC7-\u0FCC\u0FCE\u0FCF\u0FD5-\u0FD8\u109E\u109F\u1390-\u1399\u166D\u17DB\u1940\u19DE-\u19FF\u1B61-\u1B6A\u1B74-\u1B7C\u1FBD\u1FBF-\u1FC1\u1FCD-\u1FCF\u1FDD-\u1FDF\u1FED-\u1FEF\u1FFD\u1FFE\u2044\u2052\u207A-\u207C\u208A-\u208C\u20A0-\u20C0\u2100\u2101\u2103-\u2106\u2108\u2109\u2114\u2116-\u2118\u211E-\u2123\u2125\u2127\u2129\u212E\u213A\u213B\u2140-\u2144\u214A-\u214D\u214F\u218A\u218B\u2190-\u2307\u230C-\u2328\u232B-\u2426\u2440-\u244A\u249C-\u24E9\u2500-\u2767\u2794-\u27C4\u27C7-\u27E5\u27F0-\u2982\u2999-\u29D7\u29DC-\u29FB\u29FE-\u2B73\u2B76-\u2B95\u2B97-\u2BFF\u2CE5-\u2CEA\u2E50\u2E51\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFF\u3004\u3012\u3013\u3020\u3036\u3037\u303E\u303F\u309B\u309C\u3190\u3191\u3196-\u319F\u31C0-\u31E3\u31EF\u3200-\u321E\u322A-\u3247\u3250\u3260-\u327F\u328A-\u32B0\u32C0-\u33FF\u4DC0-\u4DFF\uA490-\uA4C6\uA700-\uA716\uA720\uA721\uA789\uA78A\uA828-\uA82B\uA836-\uA839\uAA77-\uAA79\uAB5B\uAB6A\uAB6B\uFB29\uFBB2-\uFBC2\uFD40-\uFD4F\uFDCF\uFDFC-\uFDFF\uFE62\uFE64-\uFE66\uFE69\uFF04\uFF0B\uFF1C-\uFF1E\uFF3E\uFF40\uFF5C\uFF5E\uFFE0-\uFFE6\uFFE8-\uFFEE\uFFFC\uFFFD]|\uD800[\uDD37-\uDD3F\uDD79-\uDD89\uDD8C-\uDD8E\uDD90-\uDD9C\uDDA0\uDDD0-\uDDFC]|\uD802[\uDC77\uDC78\uDEC8]|\uD805\uDF3F|\uD807[\uDFD5-\uDFF1]|\uD81A[\uDF3C-\uDF3F\uDF45]|\uD82F\uDC9C|\uD833[\uDF50-\uDFC3]|\uD834[\uDC00-\uDCF5\uDD00-\uDD26\uDD29-\uDD64\uDD6A-\uDD6C\uDD83\uDD84\uDD8C-\uDDA9\uDDAE-\uDDEA\uDE00-\uDE41\uDE45\uDF00-\uDF56]|\uD835[\uDEC1\uDEDB\uDEFB\uDF15\uDF35\uDF4F\uDF6F\uDF89\uDFA9\uDFC3]|\uD836[\uDC00-\uDDFF\uDE37-\uDE3A\uDE6D-\uDE74\uDE76-\uDE83\uDE85\uDE86]|\uD838[\uDD4F\uDEFF]|\uD83B[\uDCAC\uDCB0\uDD2E\uDEF0\uDEF1]|\uD83C[\uDC00-\uDC2B\uDC30-\uDC93\uDCA0-\uDCAE\uDCB1-\uDCBF\uDCC1-\uDCCF\uDCD1-\uDCF5\uDD0D-\uDDAD\uDDE6-\uDE02\uDE10-\uDE3B\uDE40-\uDE48\uDE50\uDE51\uDE60-\uDE65\uDF00-\uDFFF]|\uD83D[\uDC00-\uDED7\uDEDC-\uDEEC\uDEF0-\uDEFC\uDF00-\uDF76\uDF7B-\uDFD9\uDFE0-\uDFEB\uDFF0]|\uD83E[\uDC00-\uDC0B\uDC10-\uDC47\uDC50-\uDC59\uDC60-\uDC87\uDC90-\uDCAD\uDCB0\uDCB1\uDD00-\uDE53\uDE60-\uDE6D\uDE70-\uDE7C\uDE80-\uDE88\uDE90-\uDEBD\uDEBF-\uDEC5\uDECE-\uDEDB\uDEE0-\uDEE8\uDEF0-\uDEF8\uDF00-\uDF92\uDF94-\uDFCA]/;function m(t){switch(t){case 9:case 32:return!0}return!1}function S(t){if(t>=8192&&t<=8202)return!0;switch(t){case 9:case 10:case 11:case 12:case 13:case 32:case 160:case 5760:case 8239:case 8287:case 12288:return!0}return!1}function b(t){return R.test(t)||I.test(t)}function y(t){switch(t){case 33:case 34:case 35:case 36:case 37:case 38:case 39:case 40:case 41:case 42:case 43:case 44:case 45:case 46:case 47:case 58:case 59:case 60:case 61:case 62:case 63:case 64:case 91:case 92:case 93:case 94:case 95:case 96:case 123:case 124:case 125:case 126:return!0;default:return!1}}function h(t,u,e){this.type=t,this.tag=u,this.attrs=null,this.map=null,this.nesting=e,this.level=0,this.children=null,this.content="",this.markup="",this.info="",this.meta=null,this.block=!1,this.hidden=!1}h.prototype.attrIndex=function(u){if(!this.attrs)return-1;const e=this.attrs;for(let s=0,i=e.length;s<i;s++)if(e[s][0]===u)return s;return-1};h.prototype.attrPush=function(u){this.attrs?this.attrs.push(u):this.attrs=[u]};h.prototype.attrSet=function(u,e){const s=this.attrIndex(u),i=[u,e];s<0?this.attrPush(i):this.attrs[s]=i};h.prototype.attrGet=function(u){const e=this.attrIndex(u);let s=null;return e>=0&&(s=this.attrs[e][1]),s};h.prototype.attrJoin=function(u,e){const s=this.attrIndex(u);s<0?this.attrPush([u,e]):this.attrs[s][1]=this.attrs[s][1]+" "+e};function G(t,u,e){this.src=t,this.env=e,this.tokens=[],this.inlineMode=!1,this.md=u}G.prototype.Token=h;function E(t,u,e,s){this.src=t,this.md=u,this.env=e,this.tokens=s,this.bMarks=[],this.eMarks=[],this.tShift=[],this.sCount=[],this.bsCount=[],this.blkIndent=0,this.line=0,this.lineMax=0,this.tight=!1,this.ddIndent=-1,this.listIndent=-1,this.parentType="root",this.level=0;const i=this.src;for(let F=0,r=0,n=0,D=0,c=i.length,a=!1;r<c;r++){const o=i.charCodeAt(r);if(!a)if(m(o)){n++,o===9?D+=4-D%4:D++;continue}else a=!0;(o===10||r===c-1)&&(o!==10&&r++,this.bMarks.push(F),this.eMarks.push(r),this.tShift.push(n),this.sCount.push(D),this.bsCount.push(0),a=!1,n=0,D=0,F=r+1)}this.bMarks.push(i.length),this.eMarks.push(i.length),this.tShift.push(0),this.sCount.push(0),this.bsCount.push(0),this.lineMax=this.bMarks.length-1}E.prototype.push=function(t,u,e){const s=new h(t,u,e);return s.block=!0,e<0&&this.level--,s.level=this.level,e>0&&this.level++,this.tokens.push(s),s};E.prototype.isEmpty=function(u){return this.bMarks[u]+this.tShift[u]>=this.eMarks[u]};E.prototype.skipEmptyLines=function(u){for(let e=this.lineMax;u<e&&!(this.bMarks[u]+this.tShift[u]<this.eMarks[u]);u++);return u};E.prototype.skipSpaces=function(u){for(let e=this.src.length;u<e;u++){const s=this.src.charCodeAt(u);if(!m(s))break}return u};E.prototype.skipSpacesBack=function(u,e){if(u<=e)return u;for(;u>e;)if(!m(this.src.charCodeAt(--u)))return u+1;return u};E.prototype.skipChars=function(u,e){for(let s=this.src.length;u<s&&this.src.charCodeAt(u)===e;u++);return u};E.prototype.skipCharsBack=function(u,e,s){if(u<=s)return u;for(;u>s;)if(e!==this.src.charCodeAt(--u))return u+1;return u};E.prototype.getLines=function(u,e,s,i){if(u>=e)return"";const F=new Array(e-u);for(let r=0,n=u;n<e;n++,r++){let D=0;const c=this.bMarks[n];let a=c,o;for(n+1<e||i?o=this.eMarks[n]+1:o=this.eMarks[n];a<o&&D<s;){const l=this.src.charCodeAt(a);if(m(l))l===9?D+=4-(D+this.bsCount[n])%4:D++;else if(a-c<this.tShift[n])D++;else break;a++}D>s?F[r]=new Array(D-s+1).join(" ")+this.src.slice(a,o):F[r]=this.src.slice(a,o)}return F.join("")};E.prototype.Token=h;const T=["address","article","aside","base","basefont","blockquote","body","caption","center","col","colgroup","dd","details","dialog","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],U="[a-zA-Z_:][a-zA-Z0-9:._-]*",W="[^\"'=<>`\\x00-\\x20]+",Z="'[^']*'",N='"[^"]*"',H="(?:"+W+"|"+Z+"|"+N+")",J="(?:\\s+"+U+"(?:\\s*=\\s*"+H+")?)",Y="<[A-Za-z][A-Za-z0-9\\-]*"+J+"*\\s*\\/?>",K="<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>",Q=new RegExp("^(?:"+Y+"|"+K+")");new RegExp("^</?("+T.join("|")+")(?=(\\s|/?>|$))","i"),new RegExp(Q.source+"\\s*$");function k(t,u,e,s){this.src=t,this.env=e,this.md=u,this.tokens=s,this.tokens_meta=Array(s.length),this.pos=0,this.posMax=this.src.length,this.level=0,this.pending="",this.pendingLevel=0,this.cache={},this.delimiters=[],this._prev_delimiters=[],this.backticks={},this.backticksScanned=!1,this.linkLevel=0}k.prototype.pushPending=function(){const t=new h("text","",0);return t.content=this.pending,t.level=this.pendingLevel,this.tokens.push(t),this.pending="",t};k.prototype.push=function(t,u,e){this.pending&&this.pushPending();const s=new h(t,u,e);let i=null;return e<0&&(this.level--,this.delimiters=this._prev_delimiters.pop()),s.level=this.level,e>0&&(this.level++,this._prev_delimiters.push(this.delimiters),this.delimiters=[],i={delimiters:this.delimiters}),this.pendingLevel=this.level,this.tokens.push(s),this.tokens_meta.push(i),s};k.prototype.scanDelims=function(t,u){const e=this.posMax,s=this.src.charCodeAt(t),i=t>0?this.src.charCodeAt(t-1):32;let F=t;for(;F<e&&this.src.charCodeAt(F)===s;)F++;const r=F-t,n=F<e?this.src.charCodeAt(F):32,D=y(i)||b(String.fromCharCode(i)),c=y(n)||b(String.fromCharCode(n)),a=S(i),o=S(n),l=!o&&(!c||a||D),f=!a&&(!D||o||c);return{can_open:l&&(u||!f||D),can_close:f&&(u||!l||c),length:r}};k.prototype.Token=h;const $=[];for(let t=0;t<256;t++)$.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(t){$[t.charCodeAt(0)]=1});function V(t,u){var s,i;const e=t[u+1];if(e&&e.type==="html_block"){const F=e.content.match(/<!--\s*diagram(?:\s+id="([^"]+)")?/),r=e.content.match(/\s+caption="([^"]+)"/);return{id:(s=F==null?void 0:F[1])==null?void 0:s.trim(),caption:((i=r==null?void 0:r[1])==null?void 0:i.trim())||""}}return{caption:"",id:void 0}}function w(t,u,e,s){const i=_.createHash("md5").update(u).digest("hex");return e?`${t}-${e}-${i}.svg`:s?`${t}-${s}-${i}.svg`:`${t}-${i}.svg`}function X(t){var e;const u=((e=A==null?void 0:A.cwd)==null?void 0:e.call(A))||A.env.PWD||A.env.INIT_CWD||".";return t?x.resolve(u,t):x.resolve(u,"docs/public/diagrams")}function P(t,u,e,s,i,F){try{const r=C.readdirSync(t);let n=[];if(e)n=r.filter(D=>D.startsWith(`${u}-${e}-`)&&D!==s);else if(F)n=r.filter(D=>D.startsWith(`${u}-${F}-`)&&D!==s);else if(i){const D=_.createHash("md5").update(i).digest("hex"),c=`${u}-${D}.svg`;n=r.filter(a=>{if(!a.startsWith(`${u}-`)||!a.endsWith(".svg")||a===s||a===c)return!1;const l=a.slice(0,-4).split("-");return l.length===2&&l[0]===u})}n.forEach(D=>{const c=x.join(t,D);C.existsSync(c)&&(C.unlinkSync(c),console.log(`Removed old diagram file: ${D}`))})}catch(r){console.warn(`Failed to remove old diagram files: ${r}`)}}function M(t,u,e,s,i={},F){try{const r=t.replaceAll(`\r
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const J=require("node:fs"),Y=require("node:path"),X=require("node:crypto"),K=require("node:process");function v(t){const u=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const e in t)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(u,e,s.get?s:{enumerable:!0,get:()=>t[e]})}}return u.default=t,Object.freeze(u)}const E=v(J),l=v(Y),I=v(X),m=v(K),w=["blockdiag","bpmn","bytefield","seqdiag","actdiag","nwdiag","packetdiag","rackdiag","c4plantuml","d2","dbml","ditaa","erd","excalidraw","graphviz","mermaid","nomnoml","pikchr","plantuml","structurizr","svgbob","symbolator","tikz","umlet","vega","vega-lite","wavedrom","wireviz"],Q=/[!-#%-\*,-\/:;\?@\[-\]_\{\}\xA1\xA7\xAB\xB6\xB7\xBB\xBF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061D-\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u09FD\u0A76\u0AF0\u0C77\u0C84\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1B7D\u1B7E\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E4F\u2E52-\u2E5D\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]|\uD800[\uDD00-\uDD02\uDF9F\uDFD0]|\uD801\uDD6F|\uD802[\uDC57\uDD1F\uDD3F\uDE50-\uDE58\uDE7F\uDEF0-\uDEF6\uDF39-\uDF3F\uDF99-\uDF9C]|\uD803[\uDEAD\uDF55-\uDF59\uDF86-\uDF89]|\uD804[\uDC47-\uDC4D\uDCBB\uDCBC\uDCBE-\uDCC1\uDD40-\uDD43\uDD74\uDD75\uDDC5-\uDDC8\uDDCD\uDDDB\uDDDD-\uDDDF\uDE38-\uDE3D\uDEA9]|\uD805[\uDC4B-\uDC4F\uDC5A\uDC5B\uDC5D\uDCC6\uDDC1-\uDDD7\uDE41-\uDE43\uDE60-\uDE6C\uDEB9\uDF3C-\uDF3E]|\uD806[\uDC3B\uDD44-\uDD46\uDDE2\uDE3F-\uDE46\uDE9A-\uDE9C\uDE9E-\uDEA2\uDF00-\uDF09]|\uD807[\uDC41-\uDC45\uDC70\uDC71\uDEF7\uDEF8\uDF43-\uDF4F\uDFFF]|\uD809[\uDC70-\uDC74]|\uD80B[\uDFF1\uDFF2]|\uD81A[\uDE6E\uDE6F\uDEF5\uDF37-\uDF3B\uDF44]|\uD81B[\uDE97-\uDE9A\uDFE2]|\uD82F\uDC9F|\uD836[\uDE87-\uDE8B]|\uD83A[\uDD5E\uDD5F]/,V=/[\$\+<->\^`\|~\xA2-\xA6\xA8\xA9\xAC\xAE-\xB1\xB4\xB8\xD7\xF7\u02C2-\u02C5\u02D2-\u02DF\u02E5-\u02EB\u02ED\u02EF-\u02FF\u0375\u0384\u0385\u03F6\u0482\u058D-\u058F\u0606-\u0608\u060B\u060E\u060F\u06DE\u06E9\u06FD\u06FE\u07F6\u07FE\u07FF\u0888\u09F2\u09F3\u09FA\u09FB\u0AF1\u0B70\u0BF3-\u0BFA\u0C7F\u0D4F\u0D79\u0E3F\u0F01-\u0F03\u0F13\u0F15-\u0F17\u0F1A-\u0F1F\u0F34\u0F36\u0F38\u0FBE-\u0FC5\u0FC7-\u0FCC\u0FCE\u0FCF\u0FD5-\u0FD8\u109E\u109F\u1390-\u1399\u166D\u17DB\u1940\u19DE-\u19FF\u1B61-\u1B6A\u1B74-\u1B7C\u1FBD\u1FBF-\u1FC1\u1FCD-\u1FCF\u1FDD-\u1FDF\u1FED-\u1FEF\u1FFD\u1FFE\u2044\u2052\u207A-\u207C\u208A-\u208C\u20A0-\u20C0\u2100\u2101\u2103-\u2106\u2108\u2109\u2114\u2116-\u2118\u211E-\u2123\u2125\u2127\u2129\u212E\u213A\u213B\u2140-\u2144\u214A-\u214D\u214F\u218A\u218B\u2190-\u2307\u230C-\u2328\u232B-\u2426\u2440-\u244A\u249C-\u24E9\u2500-\u2767\u2794-\u27C4\u27C7-\u27E5\u27F0-\u2982\u2999-\u29D7\u29DC-\u29FB\u29FE-\u2B73\u2B76-\u2B95\u2B97-\u2BFF\u2CE5-\u2CEA\u2E50\u2E51\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFF\u3004\u3012\u3013\u3020\u3036\u3037\u303E\u303F\u309B\u309C\u3190\u3191\u3196-\u319F\u31C0-\u31E3\u31EF\u3200-\u321E\u322A-\u3247\u3250\u3260-\u327F\u328A-\u32B0\u32C0-\u33FF\u4DC0-\u4DFF\uA490-\uA4C6\uA700-\uA716\uA720\uA721\uA789\uA78A\uA828-\uA82B\uA836-\uA839\uAA77-\uAA79\uAB5B\uAB6A\uAB6B\uFB29\uFBB2-\uFBC2\uFD40-\uFD4F\uFDCF\uFDFC-\uFDFF\uFE62\uFE64-\uFE66\uFE69\uFF04\uFF0B\uFF1C-\uFF1E\uFF3E\uFF40\uFF5C\uFF5E\uFFE0-\uFFE6\uFFE8-\uFFEE\uFFFC\uFFFD]|\uD800[\uDD37-\uDD3F\uDD79-\uDD89\uDD8C-\uDD8E\uDD90-\uDD9C\uDDA0\uDDD0-\uDDFC]|\uD802[\uDC77\uDC78\uDEC8]|\uD805\uDF3F|\uD807[\uDFD5-\uDFF1]|\uD81A[\uDF3C-\uDF3F\uDF45]|\uD82F\uDC9C|\uD833[\uDF50-\uDFC3]|\uD834[\uDC00-\uDCF5\uDD00-\uDD26\uDD29-\uDD64\uDD6A-\uDD6C\uDD83\uDD84\uDD8C-\uDDA9\uDDAE-\uDDEA\uDE00-\uDE41\uDE45\uDF00-\uDF56]|\uD835[\uDEC1\uDEDB\uDEFB\uDF15\uDF35\uDF4F\uDF6F\uDF89\uDFA9\uDFC3]|\uD836[\uDC00-\uDDFF\uDE37-\uDE3A\uDE6D-\uDE74\uDE76-\uDE83\uDE85\uDE86]|\uD838[\uDD4F\uDEFF]|\uD83B[\uDCAC\uDCB0\uDD2E\uDEF0\uDEF1]|\uD83C[\uDC00-\uDC2B\uDC30-\uDC93\uDCA0-\uDCAE\uDCB1-\uDCBF\uDCC1-\uDCCF\uDCD1-\uDCF5\uDD0D-\uDDAD\uDDE6-\uDE02\uDE10-\uDE3B\uDE40-\uDE48\uDE50\uDE51\uDE60-\uDE65\uDF00-\uDFFF]|\uD83D[\uDC00-\uDED7\uDEDC-\uDEEC\uDEF0-\uDEFC\uDF00-\uDF76\uDF7B-\uDFD9\uDFE0-\uDFEB\uDFF0]|\uD83E[\uDC00-\uDC0B\uDC10-\uDC47\uDC50-\uDC59\uDC60-\uDC87\uDC90-\uDCAD\uDCB0\uDCB1\uDD00-\uDE53\uDE60-\uDE6D\uDE70-\uDE7C\uDE80-\uDE88\uDE90-\uDEBD\uDEBF-\uDEC5\uDECE-\uDEDB\uDEE0-\uDEE8\uDEF0-\uDEF8\uDF00-\uDF92\uDF94-\uDFCA]/;function k(t){switch(t){case 9:case 32:return!0}return!1}function P(t){if(t>=8192&&t<=8202)return!0;switch(t){case 9:case 10:case 11:case 12:case 13:case 32:case 160:case 5760:case 8239:case 8287:case 12288:return!0}return!1}function _(t){return Q.test(t)||V.test(t)}function M(t){switch(t){case 33:case 34:case 35:case 36:case 37:case 38:case 39:case 40:case 41:case 42:case 43:case 44:case 45:case 46:case 47:case 58:case 59:case 60:case 61:case 62:case 63:case 64:case 91:case 92:case 93:case 94:case 95:case 96:case 123:case 124:case 125:case 126:return!0;default:return!1}}function d(t,u,e){this.type=t,this.tag=u,this.attrs=null,this.map=null,this.nesting=e,this.level=0,this.children=null,this.content="",this.markup="",this.info="",this.meta=null,this.block=!1,this.hidden=!1}d.prototype.attrIndex=function(u){if(!this.attrs)return-1;const e=this.attrs;for(let s=0,r=e.length;s<r;s++)if(e[s][0]===u)return s;return-1};d.prototype.attrPush=function(u){this.attrs?this.attrs.push(u):this.attrs=[u]};d.prototype.attrSet=function(u,e){const s=this.attrIndex(u),r=[u,e];s<0?this.attrPush(r):this.attrs[s]=r};d.prototype.attrGet=function(u){const e=this.attrIndex(u);let s=null;return e>=0&&(s=this.attrs[e][1]),s};d.prototype.attrJoin=function(u,e){const s=this.attrIndex(u);s<0?this.attrPush([u,e]):this.attrs[s][1]=this.attrs[s][1]+" "+e};function uu(t,u,e){this.src=t,this.env=e,this.tokens=[],this.inlineMode=!1,this.md=u}uu.prototype.Token=d;function f(t,u,e,s){this.src=t,this.md=u,this.env=e,this.tokens=s,this.bMarks=[],this.eMarks=[],this.tShift=[],this.sCount=[],this.bsCount=[],this.blkIndent=0,this.line=0,this.lineMax=0,this.tight=!1,this.ddIndent=-1,this.listIndent=-1,this.parentType="root",this.level=0;const r=this.src;for(let o=0,i=0,D=0,n=0,c=r.length,a=!1;i<c;i++){const F=r.charCodeAt(i);if(!a)if(k(F)){D++,F===9?n+=4-n%4:n++;continue}else a=!0;(F===10||i===c-1)&&(F!==10&&i++,this.bMarks.push(o),this.eMarks.push(i),this.tShift.push(D),this.sCount.push(n),this.bsCount.push(0),a=!1,D=0,n=0,o=i+1)}this.bMarks.push(r.length),this.eMarks.push(r.length),this.tShift.push(0),this.sCount.push(0),this.bsCount.push(0),this.lineMax=this.bMarks.length-1}f.prototype.push=function(t,u,e){const s=new d(t,u,e);return s.block=!0,e<0&&this.level--,s.level=this.level,e>0&&this.level++,this.tokens.push(s),s};f.prototype.isEmpty=function(u){return this.bMarks[u]+this.tShift[u]>=this.eMarks[u]};f.prototype.skipEmptyLines=function(u){for(let e=this.lineMax;u<e&&!(this.bMarks[u]+this.tShift[u]<this.eMarks[u]);u++);return u};f.prototype.skipSpaces=function(u){for(let e=this.src.length;u<e;u++){const s=this.src.charCodeAt(u);if(!k(s))break}return u};f.prototype.skipSpacesBack=function(u,e){if(u<=e)return u;for(;u>e;)if(!k(this.src.charCodeAt(--u)))return u+1;return u};f.prototype.skipChars=function(u,e){for(let s=this.src.length;u<s&&this.src.charCodeAt(u)===e;u++);return u};f.prototype.skipCharsBack=function(u,e,s){if(u<=s)return u;for(;u>s;)if(e!==this.src.charCodeAt(--u))return u+1;return u};f.prototype.getLines=function(u,e,s,r){if(u>=e)return"";const o=new Array(e-u);for(let i=0,D=u;D<e;D++,i++){let n=0;const c=this.bMarks[D];let a=c,F;for(D+1<e||r?F=this.eMarks[D]+1:F=this.eMarks[D];a<F&&n<s;){const h=this.src.charCodeAt(a);if(k(h))h===9?n+=4-(n+this.bsCount[D])%4:n++;else if(a-c<this.tShift[D])n++;else break;a++}n>s?o[i]=new Array(n-s+1).join(" ")+this.src.slice(a,F):o[i]=this.src.slice(a,F)}return o.join("")};f.prototype.Token=d;const tu=["address","article","aside","base","basefont","blockquote","body","caption","center","col","colgroup","dd","details","dialog","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],eu="[a-zA-Z_:][a-zA-Z0-9:._-]*",su="[^\"'=<>`\\x00-\\x20]+",ru="'[^']*'",iu='"[^"]*"',nu="(?:"+su+"|"+ru+"|"+iu+")",ou="(?:\\s+"+eu+"(?:\\s*=\\s*"+nu+")?)",Du="<[A-Za-z][A-Za-z0-9\\-]*"+ou+"*\\s*\\/?>",au="<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>",cu=new RegExp("^(?:"+Du+"|"+au+")");new RegExp("^</?("+tu.join("|")+")(?=(\\s|/?>|$))","i"),new RegExp(cu.source+"\\s*$");function S(t,u,e,s){this.src=t,this.env=e,this.md=u,this.tokens=s,this.tokens_meta=Array(s.length),this.pos=0,this.posMax=this.src.length,this.level=0,this.pending="",this.pendingLevel=0,this.cache={},this.delimiters=[],this._prev_delimiters=[],this.backticks={},this.backticksScanned=!1,this.linkLevel=0}S.prototype.pushPending=function(){const t=new d("text","",0);return t.content=this.pending,t.level=this.pendingLevel,this.tokens.push(t),this.pending="",t};S.prototype.push=function(t,u,e){this.pending&&this.pushPending();const s=new d(t,u,e);let r=null;return e<0&&(this.level--,this.delimiters=this._prev_delimiters.pop()),s.level=this.level,e>0&&(this.level++,this._prev_delimiters.push(this.delimiters),this.delimiters=[],r={delimiters:this.delimiters}),this.pendingLevel=this.level,this.tokens.push(s),this.tokens_meta.push(r),s};S.prototype.scanDelims=function(t,u){const e=this.posMax,s=this.src.charCodeAt(t),r=t>0?this.src.charCodeAt(t-1):32;let o=t;for(;o<e&&this.src.charCodeAt(o)===s;)o++;const i=o-t,D=o<e?this.src.charCodeAt(o):32,n=M(r)||_(String.fromCharCode(r)),c=M(D)||_(String.fromCharCode(D)),a=P(r),F=P(D),h=!F&&(!c||a||n),C=!a&&(!n||F||c);return{can_open:h&&(u||!C||n),can_close:C&&(u||!h||c),length:i}};S.prototype.Token=d;const L=[];for(let t=0;t<256;t++)L.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(t){L[t.charCodeAt(0)]=1});function Fu(t,u){var s,r;const e=t[u+1];if(e&&e.type==="html_block"){const o=e.content.match(/<!--\s*diagram(?:\s+id="([^"]+)")?/),i=e.content.match(/\s+caption="([^"]+)"/);return{id:(s=o==null?void 0:o[1])==null?void 0:s.trim(),caption:((r=i==null?void 0:i[1])==null?void 0:r.trim())||""}}return{caption:"",id:void 0}}function z(t,u,e,s,r){const o=r!==void 0?`${u}${r}`:u,i=I.createHash("md5").update(o).digest("hex");return e?`${t}-${e}-${i}.svg`:s?`${t}-${s}-${i}.svg`:`${t}-${i}.svg`}function lu(t){var e;const u=((e=m==null?void 0:m.cwd)==null?void 0:e.call(m))||m.env.PWD||m.env.INIT_CWD||".";return t?l.resolve(u,t):l.resolve(u,"docs/public/diagrams")}function q(t,u,e,s,r,o){try{const i=E.readdirSync(t);let D=[];if(e)D=i.filter(n=>n.startsWith(`${u}-${e}-`)&&n!==s);else if(o)D=i.filter(n=>n.startsWith(`${u}-${o}-`)&&n!==s);else if(r){const n=I.createHash("md5").update(r).digest("hex"),c=`${u}-${n}.svg`;D=i.filter(a=>{if(!a.startsWith(`${u}-`)||!a.endsWith(".svg")||a===s||a===c)return!1;const h=a.slice(0,-4).split("-");return h.length===2&&h[0]===u})}D.forEach(n=>{const c=l.join(t,n);E.existsSync(c)&&(E.unlinkSync(c),console.log(`Removed old diagram file: ${n}`))})}catch(i){console.warn(`Failed to remove old diagram files: ${i}`)}}const hu=[".exe",".bat",".cmd",".sh",".bash",".ps1",".vbs",".js",".ts",".php",".py",".rb",".pl",".com",".msi",".jar",".pif",".scr",".wsf",".wsc",".wsh",".hta",".cpl",".inf",".reg",".lnk"];function W(t){const u=l.extname(t).toLowerCase();return hu.includes(u)}function j(t){return t.trim().startsWith("@file:")}function R(t){const u=t.trim();return u.startsWith("@file:")&&u.split(`
|
|
2
|
+
`)[0].slice(6).trim()||null}function O(t,u){if(t.startsWith("/"))return t;const e=l.dirname(u);return l.resolve(e,t)}function G(t,u){if(!u||u.length===0)return!0;try{const e=E.realpathSync(l.resolve(t));for(const s of u){const r=l.resolve(s),o=E.realpathSync(r);if(e.startsWith(o+l.sep)||e===o)return!0}}catch{const s=l.resolve(t);for(const r of u){const o=l.resolve(r);if(s.startsWith(o+l.sep)||s===o)return!0}}return!1}function T(t){try{if(W(t))throw new Error(`File extension not allowed: ${l.extname(t)}`);const u=E.statSync(t);if(!u.isFile())throw new Error(`Path is not a file: ${t}`);const e=E.realpathSync(t);return{content:E.readFileSync(e,"utf-8"),filePath:e,mtime:u.mtimeMs}}catch(u){const e=u instanceof Error?u.message:String(u);throw new Error(`Failed to read file import: ${e}`)}}function U(t,u,e,s,r={},o,i){try{const D=t.replaceAll(`\r
|
|
2
3
|
`,`
|
|
3
|
-
`);if(!
|
|
4
|
+
`);if(!w.includes(u))throw new Error(`Unsupported diagram type: ${u}`);const n=lu(r.diagramsDir);E.mkdirSync(n,{recursive:!0});const c=z(u,D,s,o,i),a=l.join(n,c),F=E.existsSync(a);let h=!1;if(F&&(h=E.readFileSync(a,"utf-8").includes("<!-- vpd-placeholder -->")),!F||h){q(n,u,s,c,D,o);const x=`<?xml version="1.0" encoding="UTF-8"?>
|
|
4
5
|
<svg width="100%" height="120" xmlns="http://www.w3.org/2000/svg">
|
|
5
6
|
<!-- vpd-placeholder -->
|
|
6
7
|
<rect width="100%" height="120" fill="#f5f5f5"/>
|
|
@@ -10,7 +11,7 @@
|
|
|
10
11
|
<text x="50%" y="65%" font-family="system-ui" font-size="14" fill="#666" text-anchor="middle" dominant-baseline="middle">
|
|
11
12
|
Refresh the page.
|
|
12
13
|
</text>
|
|
13
|
-
</svg>`;
|
|
14
|
+
</svg>`;E.writeFileSync(a,x);const y=r.krokiServerUrl??"https://kroki.io";fetch(`${y}/${u}`,{method:"POST",headers:{Accept:"image/svg+xml","Content-Type":"text/plain"},body:D}).then(p=>p.text()).then(p=>(E.writeFileSync(a,p),p))}const g=r.publicPath??"/diagrams";return`<figure
|
|
14
15
|
class="vpd-diagram vpd-diagram--${u}"
|
|
15
16
|
onclick="
|
|
16
17
|
const figure = this;
|
|
@@ -26,11 +27,11 @@
|
|
|
26
27
|
"
|
|
27
28
|
>
|
|
28
29
|
<img
|
|
29
|
-
:src="\`${
|
|
30
|
+
:src="\`${g}/${c}\`"
|
|
30
31
|
alt="${u} Diagram"
|
|
31
32
|
class="vpd-diagram-image"
|
|
32
33
|
/>
|
|
33
34
|
${e?`<figcaption class="vpd-diagram-caption">
|
|
34
35
|
${e}
|
|
35
36
|
</figcaption>`:""}
|
|
36
|
-
</figure>`}catch(
|
|
37
|
+
</figure>`}catch(D){const n=D instanceof Error?D.message:String(D);return console.error(`Error converting ${u} diagram:`,n),`<div class="diagram-error">Error converting diagram: ${n}</div>`}}function Eu(t,u={}){const e=t.renderer.rules.fence;t.renderer.rules.fence=(s,r,o,i,D)=>{const n=s[r],c=n.info.trim().toLowerCase(),a=u.excludedDiagramTypes??[],F=w.includes(c),h=a.includes(c);if(F&&!h){let C=n.content.trim();const{caption:g,id:x}=Fu(s,r),y=u.enableFileImports??!0;let p;if(y&&j(C))try{const A=R(C);if(A){const B=(i==null?void 0:i.path)||"";if(!B)return'<div class="diagram-error">Cannot resolve file import: markdown file path is not available</div>';const b=O(A,B),H=u.allowedImportDirs;if(!G(b,H))return`<div class="diagram-error">File import not allowed: ${A}. Path is outside allowed directories.</div>`;const $=T(b);C=$.content,p=$.mtime}}catch(A){const B=A instanceof Error?A.message:String(A);return`<div class="diagram-error">Error loading diagram file in ${(i==null?void 0:i.path)||"unknown"}: ${B}</div>`}const N=(i==null?void 0:i.path)||"unknown",Z=`${l.basename(N,".md")}-${r}`;return U(C,c,g,x,u,Z,p)}return e(s,r,o,i,D)}}exports.SUPPORTED_DIAGRAM_TYPES=w;exports.configureDiagramsPlugin=Eu;exports.diagramToSvg=U;exports.generateUniqueFilename=z;exports.hasDangerousExtension=W;exports.isFileImportSyntax=j;exports.parseFileImportPath=R;exports.readFileImport=T;exports.removeOldDiagramFiles=q;exports.resolveFileImportPath=O;exports.validateFileImportPath=G;
|
package/dist/index.d.ts
CHANGED
|
@@ -7,9 +7,11 @@ import type { MarkdownRenderer } from "vitepress";
|
|
|
7
7
|
* @param caption Optional diagram caption
|
|
8
8
|
* @param diagramId Optional diagram identifier
|
|
9
9
|
* @param diagramsPluginOptions Plugin configuration options
|
|
10
|
+
* @param positionId Optional position-based identifier
|
|
11
|
+
* @param sourceFileMtime Optional modification time of source file (for cache invalidation)
|
|
10
12
|
* @returns HTML string with diagram and optional caption
|
|
11
13
|
*/
|
|
12
|
-
export declare function diagramToSvg(diagram: string, diagramType: string, caption?: string, diagramId?: string, diagramsPluginOptions?: DiagramPluginOptions, positionId?: string): string;
|
|
14
|
+
export declare function diagramToSvg(diagram: string, diagramType: string, caption?: string, diagramId?: string, diagramsPluginOptions?: DiagramPluginOptions, positionId?: string, sourceFileMtime?: number): string;
|
|
13
15
|
/**
|
|
14
16
|
* Configure VitePress markdown renderer to support diagram generation
|
|
15
17
|
* @param md Markdown renderer
|
|
@@ -18,4 +20,4 @@ export declare function diagramToSvg(diagram: string, diagramType: string, capti
|
|
|
18
20
|
export declare function configureDiagramsPlugin(md: MarkdownRenderer, diagramsPluginOptions?: DiagramPluginOptions): void;
|
|
19
21
|
export { SUPPORTED_DIAGRAM_TYPES } from "./constants";
|
|
20
22
|
export type { DiagramMetadata, DiagramPluginOptions } from "./types";
|
|
21
|
-
export { generateUniqueFilename, removeOldDiagramFiles } from "./utils";
|
|
23
|
+
export { generateUniqueFilename, removeOldDiagramFiles, isFileImportSyntax, parseFileImportPath, resolveFileImportPath, validateFileImportPath, readFileImport, hasDangerousExtension, type FileImportResult, } from "./utils";
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
5
|
-
const
|
|
1
|
+
import * as E from "node:fs";
|
|
2
|
+
import * as l from "node:path";
|
|
3
|
+
import * as P from "node:crypto";
|
|
4
|
+
import * as m from "node:process";
|
|
5
|
+
const M = [
|
|
6
6
|
"blockdiag",
|
|
7
7
|
"bpmn",
|
|
8
8
|
"bytefield",
|
|
@@ -31,8 +31,8 @@ const b = [
|
|
|
31
31
|
"vega-lite",
|
|
32
32
|
"wavedrom",
|
|
33
33
|
"wireviz"
|
|
34
|
-
],
|
|
35
|
-
function
|
|
34
|
+
], R = /[!-#%-\*,-\/:;\?@\[-\]_\{\}\xA1\xA7\xAB\xB6\xB7\xBB\xBF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061D-\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u09FD\u0A76\u0AF0\u0C77\u0C84\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1B7D\u1B7E\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E4F\u2E52-\u2E5D\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]|\uD800[\uDD00-\uDD02\uDF9F\uDFD0]|\uD801\uDD6F|\uD802[\uDC57\uDD1F\uDD3F\uDE50-\uDE58\uDE7F\uDEF0-\uDEF6\uDF39-\uDF3F\uDF99-\uDF9C]|\uD803[\uDEAD\uDF55-\uDF59\uDF86-\uDF89]|\uD804[\uDC47-\uDC4D\uDCBB\uDCBC\uDCBE-\uDCC1\uDD40-\uDD43\uDD74\uDD75\uDDC5-\uDDC8\uDDCD\uDDDB\uDDDD-\uDDDF\uDE38-\uDE3D\uDEA9]|\uD805[\uDC4B-\uDC4F\uDC5A\uDC5B\uDC5D\uDCC6\uDDC1-\uDDD7\uDE41-\uDE43\uDE60-\uDE6C\uDEB9\uDF3C-\uDF3E]|\uD806[\uDC3B\uDD44-\uDD46\uDDE2\uDE3F-\uDE46\uDE9A-\uDE9C\uDE9E-\uDEA2\uDF00-\uDF09]|\uD807[\uDC41-\uDC45\uDC70\uDC71\uDEF7\uDEF8\uDF43-\uDF4F\uDFFF]|\uD809[\uDC70-\uDC74]|\uD80B[\uDFF1\uDFF2]|\uD81A[\uDE6E\uDE6F\uDEF5\uDF37-\uDF3B\uDF44]|\uD81B[\uDE97-\uDE9A\uDFE2]|\uD82F\uDC9F|\uD836[\uDE87-\uDE8B]|\uD83A[\uDD5E\uDD5F]/, q = /[\$\+<->\^`\|~\xA2-\xA6\xA8\xA9\xAC\xAE-\xB1\xB4\xB8\xD7\xF7\u02C2-\u02C5\u02D2-\u02DF\u02E5-\u02EB\u02ED\u02EF-\u02FF\u0375\u0384\u0385\u03F6\u0482\u058D-\u058F\u0606-\u0608\u060B\u060E\u060F\u06DE\u06E9\u06FD\u06FE\u07F6\u07FE\u07FF\u0888\u09F2\u09F3\u09FA\u09FB\u0AF1\u0B70\u0BF3-\u0BFA\u0C7F\u0D4F\u0D79\u0E3F\u0F01-\u0F03\u0F13\u0F15-\u0F17\u0F1A-\u0F1F\u0F34\u0F36\u0F38\u0FBE-\u0FC5\u0FC7-\u0FCC\u0FCE\u0FCF\u0FD5-\u0FD8\u109E\u109F\u1390-\u1399\u166D\u17DB\u1940\u19DE-\u19FF\u1B61-\u1B6A\u1B74-\u1B7C\u1FBD\u1FBF-\u1FC1\u1FCD-\u1FCF\u1FDD-\u1FDF\u1FED-\u1FEF\u1FFD\u1FFE\u2044\u2052\u207A-\u207C\u208A-\u208C\u20A0-\u20C0\u2100\u2101\u2103-\u2106\u2108\u2109\u2114\u2116-\u2118\u211E-\u2123\u2125\u2127\u2129\u212E\u213A\u213B\u2140-\u2144\u214A-\u214D\u214F\u218A\u218B\u2190-\u2307\u230C-\u2328\u232B-\u2426\u2440-\u244A\u249C-\u24E9\u2500-\u2767\u2794-\u27C4\u27C7-\u27E5\u27F0-\u2982\u2999-\u29D7\u29DC-\u29FB\u29FE-\u2B73\u2B76-\u2B95\u2B97-\u2BFF\u2CE5-\u2CEA\u2E50\u2E51\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFF\u3004\u3012\u3013\u3020\u3036\u3037\u303E\u303F\u309B\u309C\u3190\u3191\u3196-\u319F\u31C0-\u31E3\u31EF\u3200-\u321E\u322A-\u3247\u3250\u3260-\u327F\u328A-\u32B0\u32C0-\u33FF\u4DC0-\u4DFF\uA490-\uA4C6\uA700-\uA716\uA720\uA721\uA789\uA78A\uA828-\uA82B\uA836-\uA839\uAA77-\uAA79\uAB5B\uAB6A\uAB6B\uFB29\uFBB2-\uFBC2\uFD40-\uFD4F\uFDCF\uFDFC-\uFDFF\uFE62\uFE64-\uFE66\uFE69\uFF04\uFF0B\uFF1C-\uFF1E\uFF3E\uFF40\uFF5C\uFF5E\uFFE0-\uFFE6\uFFE8-\uFFEE\uFFFC\uFFFD]|\uD800[\uDD37-\uDD3F\uDD79-\uDD89\uDD8C-\uDD8E\uDD90-\uDD9C\uDDA0\uDDD0-\uDDFC]|\uD802[\uDC77\uDC78\uDEC8]|\uD805\uDF3F|\uD807[\uDFD5-\uDFF1]|\uD81A[\uDF3C-\uDF3F\uDF45]|\uD82F\uDC9C|\uD833[\uDF50-\uDFC3]|\uD834[\uDC00-\uDCF5\uDD00-\uDD26\uDD29-\uDD64\uDD6A-\uDD6C\uDD83\uDD84\uDD8C-\uDDA9\uDDAE-\uDDEA\uDE00-\uDE41\uDE45\uDF00-\uDF56]|\uD835[\uDEC1\uDEDB\uDEFB\uDF15\uDF35\uDF4F\uDF6F\uDF89\uDFA9\uDFC3]|\uD836[\uDC00-\uDDFF\uDE37-\uDE3A\uDE6D-\uDE74\uDE76-\uDE83\uDE85\uDE86]|\uD838[\uDD4F\uDEFF]|\uD83B[\uDCAC\uDCB0\uDD2E\uDEF0\uDEF1]|\uD83C[\uDC00-\uDC2B\uDC30-\uDC93\uDCA0-\uDCAE\uDCB1-\uDCBF\uDCC1-\uDCCF\uDCD1-\uDCF5\uDD0D-\uDDAD\uDDE6-\uDE02\uDE10-\uDE3B\uDE40-\uDE48\uDE50\uDE51\uDE60-\uDE65\uDF00-\uDFFF]|\uD83D[\uDC00-\uDED7\uDEDC-\uDEEC\uDEF0-\uDEFC\uDF00-\uDF76\uDF7B-\uDFD9\uDFE0-\uDFEB\uDFF0]|\uD83E[\uDC00-\uDC0B\uDC10-\uDC47\uDC50-\uDC59\uDC60-\uDC87\uDC90-\uDCAD\uDCB0\uDCB1\uDD00-\uDE53\uDE60-\uDE6D\uDE70-\uDE7C\uDE80-\uDE88\uDE90-\uDEBD\uDEBF-\uDEC5\uDECE-\uDEDB\uDEE0-\uDEE8\uDEF0-\uDEF8\uDF00-\uDF92\uDF94-\uDFCA]/;
|
|
35
|
+
function k(t) {
|
|
36
36
|
switch (t) {
|
|
37
37
|
case 9:
|
|
38
38
|
case 32:
|
|
@@ -40,7 +40,7 @@ function m(t) {
|
|
|
40
40
|
}
|
|
41
41
|
return !1;
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function b(t) {
|
|
44
44
|
if (t >= 8192 && t <= 8202)
|
|
45
45
|
return !0;
|
|
46
46
|
switch (t) {
|
|
@@ -64,10 +64,10 @@ function k(t) {
|
|
|
64
64
|
}
|
|
65
65
|
return !1;
|
|
66
66
|
}
|
|
67
|
-
function
|
|
68
|
-
return
|
|
67
|
+
function $(t) {
|
|
68
|
+
return R.test(t) || q.test(t);
|
|
69
69
|
}
|
|
70
|
-
function
|
|
70
|
+
function _(t) {
|
|
71
71
|
switch (t) {
|
|
72
72
|
case 33:
|
|
73
73
|
case 34:
|
|
@@ -106,87 +106,87 @@ function y(t) {
|
|
|
106
106
|
return !1;
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
function
|
|
109
|
+
function C(t, u, e) {
|
|
110
110
|
this.type = t, this.tag = u, this.attrs = null, this.map = null, this.nesting = e, this.level = 0, this.children = null, this.content = "", this.markup = "", this.info = "", this.meta = null, this.block = !1, this.hidden = !1;
|
|
111
111
|
}
|
|
112
|
-
|
|
112
|
+
C.prototype.attrIndex = function(u) {
|
|
113
113
|
if (!this.attrs)
|
|
114
114
|
return -1;
|
|
115
115
|
const e = this.attrs;
|
|
116
|
-
for (let s = 0,
|
|
116
|
+
for (let s = 0, r = e.length; s < r; s++)
|
|
117
117
|
if (e[s][0] === u)
|
|
118
118
|
return s;
|
|
119
119
|
return -1;
|
|
120
120
|
};
|
|
121
|
-
|
|
121
|
+
C.prototype.attrPush = function(u) {
|
|
122
122
|
this.attrs ? this.attrs.push(u) : this.attrs = [u];
|
|
123
123
|
};
|
|
124
|
-
|
|
125
|
-
const s = this.attrIndex(u),
|
|
126
|
-
s < 0 ? this.attrPush(
|
|
124
|
+
C.prototype.attrSet = function(u, e) {
|
|
125
|
+
const s = this.attrIndex(u), r = [u, e];
|
|
126
|
+
s < 0 ? this.attrPush(r) : this.attrs[s] = r;
|
|
127
127
|
};
|
|
128
|
-
|
|
128
|
+
C.prototype.attrGet = function(u) {
|
|
129
129
|
const e = this.attrIndex(u);
|
|
130
130
|
let s = null;
|
|
131
131
|
return e >= 0 && (s = this.attrs[e][1]), s;
|
|
132
132
|
};
|
|
133
|
-
|
|
133
|
+
C.prototype.attrJoin = function(u, e) {
|
|
134
134
|
const s = this.attrIndex(u);
|
|
135
135
|
s < 0 ? this.attrPush([u, e]) : this.attrs[s][1] = this.attrs[s][1] + " " + e;
|
|
136
136
|
};
|
|
137
|
-
function
|
|
137
|
+
function G(t, u, e) {
|
|
138
138
|
this.src = t, this.env = e, this.tokens = [], this.inlineMode = !1, this.md = u;
|
|
139
139
|
}
|
|
140
|
-
|
|
141
|
-
function
|
|
140
|
+
G.prototype.Token = C;
|
|
141
|
+
function d(t, u, e, s) {
|
|
142
142
|
this.src = t, this.md = u, this.env = e, this.tokens = s, this.bMarks = [], this.eMarks = [], this.tShift = [], this.sCount = [], this.bsCount = [], this.blkIndent = 0, this.line = 0, this.lineMax = 0, this.tight = !1, this.ddIndent = -1, this.listIndent = -1, this.parentType = "root", this.level = 0;
|
|
143
|
-
const
|
|
144
|
-
for (let
|
|
145
|
-
const
|
|
143
|
+
const r = this.src;
|
|
144
|
+
for (let D = 0, i = 0, o = 0, n = 0, c = r.length, a = !1; i < c; i++) {
|
|
145
|
+
const F = r.charCodeAt(i);
|
|
146
146
|
if (!a)
|
|
147
|
-
if (
|
|
148
|
-
|
|
147
|
+
if (k(F)) {
|
|
148
|
+
o++, F === 9 ? n += 4 - n % 4 : n++;
|
|
149
149
|
continue;
|
|
150
150
|
} else
|
|
151
151
|
a = !0;
|
|
152
|
-
(
|
|
152
|
+
(F === 10 || i === c - 1) && (F !== 10 && i++, this.bMarks.push(D), this.eMarks.push(i), this.tShift.push(o), this.sCount.push(n), this.bsCount.push(0), a = !1, o = 0, n = 0, D = i + 1);
|
|
153
153
|
}
|
|
154
|
-
this.bMarks.push(
|
|
154
|
+
this.bMarks.push(r.length), this.eMarks.push(r.length), this.tShift.push(0), this.sCount.push(0), this.bsCount.push(0), this.lineMax = this.bMarks.length - 1;
|
|
155
155
|
}
|
|
156
|
-
|
|
157
|
-
const s = new
|
|
156
|
+
d.prototype.push = function(t, u, e) {
|
|
157
|
+
const s = new C(t, u, e);
|
|
158
158
|
return s.block = !0, e < 0 && this.level--, s.level = this.level, e > 0 && this.level++, this.tokens.push(s), s;
|
|
159
159
|
};
|
|
160
|
-
|
|
160
|
+
d.prototype.isEmpty = function(u) {
|
|
161
161
|
return this.bMarks[u] + this.tShift[u] >= this.eMarks[u];
|
|
162
162
|
};
|
|
163
|
-
|
|
163
|
+
d.prototype.skipEmptyLines = function(u) {
|
|
164
164
|
for (let e = this.lineMax; u < e && !(this.bMarks[u] + this.tShift[u] < this.eMarks[u]); u++)
|
|
165
165
|
;
|
|
166
166
|
return u;
|
|
167
167
|
};
|
|
168
|
-
|
|
168
|
+
d.prototype.skipSpaces = function(u) {
|
|
169
169
|
for (let e = this.src.length; u < e; u++) {
|
|
170
170
|
const s = this.src.charCodeAt(u);
|
|
171
|
-
if (!
|
|
171
|
+
if (!k(s))
|
|
172
172
|
break;
|
|
173
173
|
}
|
|
174
174
|
return u;
|
|
175
175
|
};
|
|
176
|
-
|
|
176
|
+
d.prototype.skipSpacesBack = function(u, e) {
|
|
177
177
|
if (u <= e)
|
|
178
178
|
return u;
|
|
179
179
|
for (; u > e; )
|
|
180
|
-
if (!
|
|
180
|
+
if (!k(this.src.charCodeAt(--u)))
|
|
181
181
|
return u + 1;
|
|
182
182
|
return u;
|
|
183
183
|
};
|
|
184
|
-
|
|
184
|
+
d.prototype.skipChars = function(u, e) {
|
|
185
185
|
for (let s = this.src.length; u < s && this.src.charCodeAt(u) === e; u++)
|
|
186
186
|
;
|
|
187
187
|
return u;
|
|
188
188
|
};
|
|
189
|
-
|
|
189
|
+
d.prototype.skipCharsBack = function(u, e, s) {
|
|
190
190
|
if (u <= s)
|
|
191
191
|
return u;
|
|
192
192
|
for (; u > s; )
|
|
@@ -194,30 +194,30 @@ E.prototype.skipCharsBack = function(u, e, s) {
|
|
|
194
194
|
return u + 1;
|
|
195
195
|
return u;
|
|
196
196
|
};
|
|
197
|
-
|
|
197
|
+
d.prototype.getLines = function(u, e, s, r) {
|
|
198
198
|
if (u >= e)
|
|
199
199
|
return "";
|
|
200
|
-
const
|
|
201
|
-
for (let
|
|
202
|
-
let
|
|
203
|
-
const c = this.bMarks[
|
|
204
|
-
let a = c,
|
|
205
|
-
for (
|
|
200
|
+
const D = new Array(e - u);
|
|
201
|
+
for (let i = 0, o = u; o < e; o++, i++) {
|
|
202
|
+
let n = 0;
|
|
203
|
+
const c = this.bMarks[o];
|
|
204
|
+
let a = c, F;
|
|
205
|
+
for (o + 1 < e || r ? F = this.eMarks[o] + 1 : F = this.eMarks[o]; a < F && n < s; ) {
|
|
206
206
|
const h = this.src.charCodeAt(a);
|
|
207
|
-
if (
|
|
208
|
-
h === 9 ?
|
|
209
|
-
else if (a - c < this.tShift[
|
|
210
|
-
|
|
207
|
+
if (k(h))
|
|
208
|
+
h === 9 ? n += 4 - (n + this.bsCount[o]) % 4 : n++;
|
|
209
|
+
else if (a - c < this.tShift[o])
|
|
210
|
+
n++;
|
|
211
211
|
else
|
|
212
212
|
break;
|
|
213
213
|
a++;
|
|
214
214
|
}
|
|
215
|
-
|
|
215
|
+
n > s ? D[i] = new Array(n - s + 1).join(" ") + this.src.slice(a, F) : D[i] = this.src.slice(a, F);
|
|
216
216
|
}
|
|
217
|
-
return
|
|
217
|
+
return D.join("");
|
|
218
218
|
};
|
|
219
|
-
|
|
220
|
-
const
|
|
219
|
+
d.prototype.Token = C;
|
|
220
|
+
const j = [
|
|
221
221
|
"address",
|
|
222
222
|
"article",
|
|
223
223
|
"aside",
|
|
@@ -280,74 +280,74 @@ const L = [
|
|
|
280
280
|
"tr",
|
|
281
281
|
"track",
|
|
282
282
|
"ul"
|
|
283
|
-
],
|
|
284
|
-
new RegExp("^</?(" +
|
|
285
|
-
function
|
|
283
|
+
], N = "[a-zA-Z_:][a-zA-Z0-9:._-]*", U = "[^\"'=<>`\\x00-\\x20]+", Z = "'[^']*'", H = '"[^"]*"', T = "(?:" + U + "|" + Z + "|" + H + ")", J = "(?:\\s+" + N + "(?:\\s*=\\s*" + T + ")?)", O = "<[A-Za-z][A-Za-z0-9\\-]*" + J + "*\\s*\\/?>", X = "<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>", Y = new RegExp("^(?:" + O + "|" + X + ")");
|
|
284
|
+
new RegExp("^</?(" + j.join("|") + ")(?=(\\s|/?>|$))", "i"), new RegExp(Y.source + "\\s*$");
|
|
285
|
+
function v(t, u, e, s) {
|
|
286
286
|
this.src = t, this.env = e, this.md = u, this.tokens = s, this.tokens_meta = Array(s.length), this.pos = 0, this.posMax = this.src.length, this.level = 0, this.pending = "", this.pendingLevel = 0, this.cache = {}, this.delimiters = [], this._prev_delimiters = [], this.backticks = {}, this.backticksScanned = !1, this.linkLevel = 0;
|
|
287
287
|
}
|
|
288
|
-
|
|
289
|
-
const t = new
|
|
288
|
+
v.prototype.pushPending = function() {
|
|
289
|
+
const t = new C("text", "", 0);
|
|
290
290
|
return t.content = this.pending, t.level = this.pendingLevel, this.tokens.push(t), this.pending = "", t;
|
|
291
291
|
};
|
|
292
|
-
|
|
292
|
+
v.prototype.push = function(t, u, e) {
|
|
293
293
|
this.pending && this.pushPending();
|
|
294
|
-
const s = new
|
|
295
|
-
let
|
|
296
|
-
return e < 0 && (this.level--, this.delimiters = this._prev_delimiters.pop()), s.level = this.level, e > 0 && (this.level++, this._prev_delimiters.push(this.delimiters), this.delimiters = [],
|
|
294
|
+
const s = new C(t, u, e);
|
|
295
|
+
let r = null;
|
|
296
|
+
return e < 0 && (this.level--, this.delimiters = this._prev_delimiters.pop()), s.level = this.level, e > 0 && (this.level++, this._prev_delimiters.push(this.delimiters), this.delimiters = [], r = { delimiters: this.delimiters }), this.pendingLevel = this.level, this.tokens.push(s), this.tokens_meta.push(r), s;
|
|
297
297
|
};
|
|
298
|
-
|
|
299
|
-
const e = this.posMax, s = this.src.charCodeAt(t),
|
|
300
|
-
let
|
|
301
|
-
for (;
|
|
302
|
-
|
|
303
|
-
const
|
|
304
|
-
return { can_open: h && (u || !f ||
|
|
298
|
+
v.prototype.scanDelims = function(t, u) {
|
|
299
|
+
const e = this.posMax, s = this.src.charCodeAt(t), r = t > 0 ? this.src.charCodeAt(t - 1) : 32;
|
|
300
|
+
let D = t;
|
|
301
|
+
for (; D < e && this.src.charCodeAt(D) === s; )
|
|
302
|
+
D++;
|
|
303
|
+
const i = D - t, o = D < e ? this.src.charCodeAt(D) : 32, n = _(r) || $(String.fromCharCode(r)), c = _(o) || $(String.fromCharCode(o)), a = b(r), F = b(o), h = !F && (!c || a || n), f = !a && (!n || F || c);
|
|
304
|
+
return { can_open: h && (u || !f || n), can_close: f && (u || !h || c), length: i };
|
|
305
305
|
};
|
|
306
|
-
|
|
307
|
-
const
|
|
306
|
+
v.prototype.Token = C;
|
|
307
|
+
const I = [];
|
|
308
308
|
for (let t = 0; t < 256; t++)
|
|
309
|
-
|
|
309
|
+
I.push(0);
|
|
310
310
|
"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(t) {
|
|
311
|
-
|
|
311
|
+
I[t.charCodeAt(0)] = 1;
|
|
312
312
|
});
|
|
313
|
-
function
|
|
314
|
-
var s,
|
|
313
|
+
function K(t, u) {
|
|
314
|
+
var s, r;
|
|
315
315
|
const e = t[u + 1];
|
|
316
316
|
if (e && e.type === "html_block") {
|
|
317
|
-
const
|
|
317
|
+
const D = e.content.match(
|
|
318
318
|
/<!--\s*diagram(?:\s+id="([^"]+)")?/
|
|
319
|
-
),
|
|
319
|
+
), i = e.content.match(/\s+caption="([^"]+)"/);
|
|
320
320
|
return {
|
|
321
|
-
id: (s =
|
|
322
|
-
caption: ((
|
|
321
|
+
id: (s = D == null ? void 0 : D[1]) == null ? void 0 : s.trim(),
|
|
322
|
+
caption: ((r = i == null ? void 0 : i[1]) == null ? void 0 : r.trim()) || ""
|
|
323
323
|
};
|
|
324
324
|
}
|
|
325
325
|
return { caption: "", id: void 0 };
|
|
326
326
|
}
|
|
327
|
-
function
|
|
328
|
-
const i =
|
|
327
|
+
function Q(t, u, e, s, r) {
|
|
328
|
+
const D = r !== void 0 ? `${u}${r}` : u, i = P.createHash("md5").update(D).digest("hex");
|
|
329
329
|
return e ? `${t}-${e}-${i}.svg` : s ? `${t}-${s}-${i}.svg` : `${t}-${i}.svg`;
|
|
330
330
|
}
|
|
331
|
-
function
|
|
331
|
+
function V(t) {
|
|
332
332
|
var e;
|
|
333
|
-
const u = ((e =
|
|
334
|
-
return t ?
|
|
333
|
+
const u = ((e = m == null ? void 0 : m.cwd) == null ? void 0 : e.call(m)) || m.env.PWD || m.env.INIT_CWD || ".";
|
|
334
|
+
return t ? l.resolve(u, t) : l.resolve(u, "docs/public/diagrams");
|
|
335
335
|
}
|
|
336
|
-
function
|
|
336
|
+
function uu(t, u, e, s, r, D) {
|
|
337
337
|
try {
|
|
338
|
-
const
|
|
339
|
-
let
|
|
338
|
+
const i = E.readdirSync(t);
|
|
339
|
+
let o = [];
|
|
340
340
|
if (e)
|
|
341
|
-
|
|
342
|
-
(
|
|
341
|
+
o = i.filter(
|
|
342
|
+
(n) => n.startsWith(`${u}-${e}-`) && n !== s
|
|
343
343
|
);
|
|
344
|
-
else if (
|
|
345
|
-
|
|
346
|
-
(
|
|
344
|
+
else if (D)
|
|
345
|
+
o = i.filter(
|
|
346
|
+
(n) => n.startsWith(`${u}-${D}-`) && n !== s
|
|
347
347
|
);
|
|
348
|
-
else if (
|
|
349
|
-
const
|
|
350
|
-
|
|
348
|
+
else if (r) {
|
|
349
|
+
const n = P.createHash("md5").update(r).digest("hex"), c = `${u}-${n}.svg`;
|
|
350
|
+
o = i.filter(
|
|
351
351
|
(a) => {
|
|
352
352
|
if (!a.startsWith(`${u}-`) || !a.endsWith(".svg") || a === s || a === c)
|
|
353
353
|
return !1;
|
|
@@ -356,42 +356,127 @@ function J(t, u, e, s, i, F) {
|
|
|
356
356
|
}
|
|
357
357
|
);
|
|
358
358
|
}
|
|
359
|
-
|
|
360
|
-
const c =
|
|
361
|
-
|
|
359
|
+
o.forEach((n) => {
|
|
360
|
+
const c = l.join(t, n);
|
|
361
|
+
E.existsSync(c) && (E.unlinkSync(c), console.log(`Removed old diagram file: ${n}`));
|
|
362
362
|
});
|
|
363
|
-
} catch (
|
|
364
|
-
console.warn(`Failed to remove old diagram files: ${
|
|
363
|
+
} catch (i) {
|
|
364
|
+
console.warn(`Failed to remove old diagram files: ${i}`);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
const tu = [
|
|
368
|
+
".exe",
|
|
369
|
+
".bat",
|
|
370
|
+
".cmd",
|
|
371
|
+
".sh",
|
|
372
|
+
".bash",
|
|
373
|
+
".ps1",
|
|
374
|
+
".vbs",
|
|
375
|
+
".js",
|
|
376
|
+
".ts",
|
|
377
|
+
".php",
|
|
378
|
+
".py",
|
|
379
|
+
".rb",
|
|
380
|
+
".pl",
|
|
381
|
+
".com",
|
|
382
|
+
".msi",
|
|
383
|
+
".jar",
|
|
384
|
+
".pif",
|
|
385
|
+
".scr",
|
|
386
|
+
".wsf",
|
|
387
|
+
".wsc",
|
|
388
|
+
".wsh",
|
|
389
|
+
".hta",
|
|
390
|
+
".cpl",
|
|
391
|
+
".inf",
|
|
392
|
+
".reg",
|
|
393
|
+
".lnk"
|
|
394
|
+
];
|
|
395
|
+
function eu(t) {
|
|
396
|
+
const u = l.extname(t).toLowerCase();
|
|
397
|
+
return tu.includes(u);
|
|
398
|
+
}
|
|
399
|
+
function su(t) {
|
|
400
|
+
return t.trim().startsWith("@file:");
|
|
401
|
+
}
|
|
402
|
+
function ru(t) {
|
|
403
|
+
const u = t.trim();
|
|
404
|
+
return u.startsWith("@file:") && u.split(`
|
|
405
|
+
`)[0].slice(6).trim() || null;
|
|
406
|
+
}
|
|
407
|
+
function iu(t, u) {
|
|
408
|
+
if (t.startsWith("/"))
|
|
409
|
+
return t;
|
|
410
|
+
const e = l.dirname(u);
|
|
411
|
+
return l.resolve(e, t);
|
|
412
|
+
}
|
|
413
|
+
function nu(t, u) {
|
|
414
|
+
if (!u || u.length === 0)
|
|
415
|
+
return !0;
|
|
416
|
+
try {
|
|
417
|
+
const e = E.realpathSync(l.resolve(t));
|
|
418
|
+
for (const s of u) {
|
|
419
|
+
const r = l.resolve(s), D = E.realpathSync(r);
|
|
420
|
+
if (e.startsWith(D + l.sep) || e === D)
|
|
421
|
+
return !0;
|
|
422
|
+
}
|
|
423
|
+
} catch {
|
|
424
|
+
const s = l.resolve(t);
|
|
425
|
+
for (const r of u) {
|
|
426
|
+
const D = l.resolve(r);
|
|
427
|
+
if (s.startsWith(D + l.sep) || s === D)
|
|
428
|
+
return !0;
|
|
429
|
+
}
|
|
365
430
|
}
|
|
431
|
+
return !1;
|
|
366
432
|
}
|
|
367
|
-
function
|
|
433
|
+
function Du(t) {
|
|
368
434
|
try {
|
|
369
|
-
|
|
435
|
+
if (eu(t))
|
|
436
|
+
throw new Error(`File extension not allowed: ${l.extname(t)}`);
|
|
437
|
+
const u = E.statSync(t);
|
|
438
|
+
if (!u.isFile())
|
|
439
|
+
throw new Error(`Path is not a file: ${t}`);
|
|
440
|
+
const e = E.realpathSync(t);
|
|
441
|
+
return {
|
|
442
|
+
content: E.readFileSync(e, "utf-8"),
|
|
443
|
+
filePath: e,
|
|
444
|
+
mtime: u.mtimeMs
|
|
445
|
+
};
|
|
446
|
+
} catch (u) {
|
|
447
|
+
const e = u instanceof Error ? u.message : String(u);
|
|
448
|
+
throw new Error(`Failed to read file import: ${e}`);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
function ou(t, u, e, s, r = {}, D, i) {
|
|
452
|
+
try {
|
|
453
|
+
const o = t.replaceAll(`\r
|
|
370
454
|
`, `
|
|
371
455
|
`);
|
|
372
|
-
if (!
|
|
456
|
+
if (!M.includes(u))
|
|
373
457
|
throw new Error(`Unsupported diagram type: ${u}`);
|
|
374
|
-
const n =
|
|
375
|
-
|
|
458
|
+
const n = V(
|
|
459
|
+
r.diagramsDir
|
|
376
460
|
);
|
|
377
|
-
|
|
378
|
-
const
|
|
461
|
+
E.mkdirSync(n, { recursive: !0 });
|
|
462
|
+
const c = Q(
|
|
379
463
|
u,
|
|
380
|
-
|
|
464
|
+
o,
|
|
381
465
|
s,
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
466
|
+
D,
|
|
467
|
+
i
|
|
468
|
+
), a = l.join(n, c), F = E.existsSync(a);
|
|
469
|
+
let h = !1;
|
|
470
|
+
if (F && (h = E.readFileSync(a, "utf-8").includes("<!-- vpd-placeholder -->")), !F || h) {
|
|
471
|
+
uu(
|
|
387
472
|
n,
|
|
388
473
|
u,
|
|
389
474
|
s,
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
475
|
+
c,
|
|
476
|
+
o,
|
|
477
|
+
D
|
|
393
478
|
);
|
|
394
|
-
const
|
|
479
|
+
const x = `<?xml version="1.0" encoding="UTF-8"?>
|
|
395
480
|
<svg width="100%" height="120" xmlns="http://www.w3.org/2000/svg">
|
|
396
481
|
<!-- vpd-placeholder -->
|
|
397
482
|
<rect width="100%" height="120" fill="#f5f5f5"/>
|
|
@@ -402,18 +487,18 @@ function O(t, u, e, s, i = {}, F) {
|
|
|
402
487
|
Refresh the page.
|
|
403
488
|
</text>
|
|
404
489
|
</svg>`;
|
|
405
|
-
|
|
406
|
-
const
|
|
407
|
-
fetch(`${
|
|
490
|
+
E.writeFileSync(a, x);
|
|
491
|
+
const w = r.krokiServerUrl ?? "https://kroki.io";
|
|
492
|
+
fetch(`${w}/${u}`, {
|
|
408
493
|
method: "POST",
|
|
409
494
|
headers: {
|
|
410
495
|
Accept: "image/svg+xml",
|
|
411
496
|
"Content-Type": "text/plain"
|
|
412
497
|
},
|
|
413
|
-
body:
|
|
414
|
-
}).then((
|
|
498
|
+
body: o
|
|
499
|
+
}).then((A) => A.text()).then((A) => (E.writeFileSync(a, A), A));
|
|
415
500
|
}
|
|
416
|
-
const
|
|
501
|
+
const B = r.publicPath ?? "/diagrams";
|
|
417
502
|
return `<figure
|
|
418
503
|
class="vpd-diagram vpd-diagram--${u}"
|
|
419
504
|
onclick="
|
|
@@ -430,7 +515,7 @@ function O(t, u, e, s, i = {}, F) {
|
|
|
430
515
|
"
|
|
431
516
|
>
|
|
432
517
|
<img
|
|
433
|
-
:src="\`${
|
|
518
|
+
:src="\`${B}/${c}\`"
|
|
434
519
|
alt="${u} Diagram"
|
|
435
520
|
class="vpd-diagram-image"
|
|
436
521
|
/>
|
|
@@ -438,33 +523,60 @@ function O(t, u, e, s, i = {}, F) {
|
|
|
438
523
|
${e}
|
|
439
524
|
</figcaption>` : ""}
|
|
440
525
|
</figure>`;
|
|
441
|
-
} catch (
|
|
442
|
-
const n =
|
|
526
|
+
} catch (o) {
|
|
527
|
+
const n = o instanceof Error ? o.message : String(o);
|
|
443
528
|
return console.error(`Error converting ${u} diagram:`, n), `<div class="diagram-error">Error converting diagram: ${n}</div>`;
|
|
444
529
|
}
|
|
445
530
|
}
|
|
446
|
-
function
|
|
531
|
+
function au(t, u = {}) {
|
|
447
532
|
const e = t.renderer.rules.fence;
|
|
448
|
-
t.renderer.rules.fence = (s,
|
|
449
|
-
const
|
|
450
|
-
if (
|
|
451
|
-
|
|
452
|
-
|
|
533
|
+
t.renderer.rules.fence = (s, r, D, i, o) => {
|
|
534
|
+
const n = s[r], c = n.info.trim().toLowerCase(), a = u.excludedDiagramTypes ?? [], F = M.includes(c), h = a.includes(c);
|
|
535
|
+
if (F && !h) {
|
|
536
|
+
let f = n.content.trim();
|
|
537
|
+
const { caption: B, id: x } = K(s, r), w = u.enableFileImports ?? !0;
|
|
538
|
+
let A;
|
|
539
|
+
if (w && su(f))
|
|
540
|
+
try {
|
|
541
|
+
const p = ru(f);
|
|
542
|
+
if (p) {
|
|
543
|
+
const g = (i == null ? void 0 : i.path) || "";
|
|
544
|
+
if (!g)
|
|
545
|
+
return '<div class="diagram-error">Cannot resolve file import: markdown file path is not available</div>';
|
|
546
|
+
const S = iu(p, g), W = u.allowedImportDirs;
|
|
547
|
+
if (!nu(S, W))
|
|
548
|
+
return `<div class="diagram-error">File import not allowed: ${p}. Path is outside allowed directories.</div>`;
|
|
549
|
+
const y = Du(S);
|
|
550
|
+
f = y.content, A = y.mtime;
|
|
551
|
+
}
|
|
552
|
+
} catch (p) {
|
|
553
|
+
const g = p instanceof Error ? p.message : String(p);
|
|
554
|
+
return `<div class="diagram-error">Error loading diagram file in ${(i == null ? void 0 : i.path) || "unknown"}: ${g}</div>`;
|
|
555
|
+
}
|
|
556
|
+
const L = (i == null ? void 0 : i.path) || "unknown", z = `${l.basename(L, ".md")}-${r}`;
|
|
557
|
+
return ou(
|
|
453
558
|
f,
|
|
454
559
|
c,
|
|
455
|
-
p,
|
|
456
560
|
B,
|
|
561
|
+
x,
|
|
457
562
|
u,
|
|
458
|
-
|
|
563
|
+
z,
|
|
564
|
+
A
|
|
459
565
|
);
|
|
460
566
|
}
|
|
461
|
-
return e(s,
|
|
567
|
+
return e(s, r, D, i, o);
|
|
462
568
|
};
|
|
463
569
|
}
|
|
464
570
|
export {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
571
|
+
M as SUPPORTED_DIAGRAM_TYPES,
|
|
572
|
+
au as configureDiagramsPlugin,
|
|
573
|
+
ou as diagramToSvg,
|
|
574
|
+
Q as generateUniqueFilename,
|
|
575
|
+
eu as hasDangerousExtension,
|
|
576
|
+
su as isFileImportSyntax,
|
|
577
|
+
ru as parseFileImportPath,
|
|
578
|
+
Du as readFileImport,
|
|
579
|
+
uu as removeOldDiagramFiles,
|
|
580
|
+
iu as resolveFileImportPath,
|
|
581
|
+
nu as validateFileImportPath
|
|
470
582
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -23,6 +23,18 @@ export interface DiagramPluginOptions {
|
|
|
23
23
|
* If a code block's language matches any of these types, it will be rendered as a normal code block.
|
|
24
24
|
*/
|
|
25
25
|
excludedDiagramTypes?: DiagramType[];
|
|
26
|
+
/**
|
|
27
|
+
* Enable file import syntax (@file:path/to/file)
|
|
28
|
+
* When enabled, diagrams can be imported from external files
|
|
29
|
+
* @default true
|
|
30
|
+
*/
|
|
31
|
+
enableFileImports?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* List of allowed base directories for file imports (security feature)
|
|
34
|
+
* If empty or undefined, all paths are allowed (relative to markdown file)
|
|
35
|
+
* @default undefined
|
|
36
|
+
*/
|
|
37
|
+
allowedImportDirs?: string[];
|
|
26
38
|
}
|
|
27
39
|
/**
|
|
28
40
|
* Extracted diagram metadata from markdown tokens
|
package/dist/utils.d.ts
CHANGED
|
@@ -12,9 +12,11 @@ export declare function extractDiagramMetadata(tokens: any[], idx: number): Diag
|
|
|
12
12
|
* @param diagramType Type of diagram
|
|
13
13
|
* @param diagramContent Diagram content
|
|
14
14
|
* @param diagramId Optional diagram identifier
|
|
15
|
+
* @param positionId Optional position-based identifier
|
|
16
|
+
* @param sourceFileMtime Optional modification time of source file (for cache invalidation)
|
|
15
17
|
* @returns Unique filename
|
|
16
18
|
*/
|
|
17
|
-
export declare function generateUniqueFilename(diagramType: DiagramType, diagramContent: string, diagramId?: string, positionId?: string): string;
|
|
19
|
+
export declare function generateUniqueFilename(diagramType: DiagramType, diagramContent: string, diagramId?: string, positionId?: string, sourceFileMtime?: number): string;
|
|
18
20
|
/**
|
|
19
21
|
* Resolve the base directory for diagram storage
|
|
20
22
|
* @param customDir Optional custom directory
|
|
@@ -51,3 +53,51 @@ export declare function extractDiagramsMetadataFromMarkdown(filepath: string): A
|
|
|
51
53
|
* @returns Set of unique diagram filenames (hashes)
|
|
52
54
|
*/
|
|
53
55
|
export declare function getAllDiagramsHashes(docsRoot?: string): Set<string>;
|
|
56
|
+
/**
|
|
57
|
+
* Check if a file extension is considered dangerous
|
|
58
|
+
* @param filePath File path to check
|
|
59
|
+
* @returns true if the file has a dangerous extension
|
|
60
|
+
*/
|
|
61
|
+
export declare function hasDangerousExtension(filePath: string): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Result of reading a file import, including content and metadata
|
|
64
|
+
*/
|
|
65
|
+
export interface FileImportResult {
|
|
66
|
+
content: string;
|
|
67
|
+
filePath: string;
|
|
68
|
+
mtime: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Check if content uses @file: syntax for importing diagram from file
|
|
72
|
+
* @param content Code block content
|
|
73
|
+
* @returns true if content starts with @file: syntax
|
|
74
|
+
*/
|
|
75
|
+
export declare function isFileImportSyntax(content: string): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Parse the file path from @file: syntax
|
|
78
|
+
* @param content Code block content
|
|
79
|
+
* @returns File path or null if not @file: syntax
|
|
80
|
+
*/
|
|
81
|
+
export declare function parseFileImportPath(content: string): string | null;
|
|
82
|
+
/**
|
|
83
|
+
* Resolve file import path relative to the markdown file location
|
|
84
|
+
* @param importPath The path from @file: syntax
|
|
85
|
+
* @param markdownFilePath The path of the markdown file containing the import
|
|
86
|
+
* @returns Resolved absolute path
|
|
87
|
+
*/
|
|
88
|
+
export declare function resolveFileImportPath(importPath: string, markdownFilePath: string): string;
|
|
89
|
+
/**
|
|
90
|
+
* Validate that a file path is within allowed directories (security check)
|
|
91
|
+
* Uses realpath to prevent symlink-based path traversal attacks
|
|
92
|
+
* @param filePath The resolved file path to validate
|
|
93
|
+
* @param allowedDirs Array of allowed base directories (empty means allow all)
|
|
94
|
+
* @returns true if path is safe
|
|
95
|
+
*/
|
|
96
|
+
export declare function validateFileImportPath(filePath: string, allowedDirs?: string[]): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Read content from a file import with metadata for cache invalidation
|
|
99
|
+
* @param filePath Absolute path to the file
|
|
100
|
+
* @returns FileImportResult with content, path, and modification time
|
|
101
|
+
* @throws Error if file cannot be read or has dangerous extension
|
|
102
|
+
*/
|
|
103
|
+
export declare function readFileImport(filePath: string): FileImportResult;
|
package/package.json
CHANGED