@andares/pdeditor 0.4.0 → 0.5.0
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 +359 -79
- package/dist/core.d.ts +68 -13
- package/dist/element-auto.cjs +46 -0
- package/dist/element-auto.d.ts +1 -0
- package/dist/element-auto.js +868 -0
- package/dist/element.cjs +46 -0
- package/dist/element.d.ts +43 -0
- package/dist/element.js +867 -0
- package/dist/highlighters.d.ts +1 -1
- package/dist/index.cjs +16 -16
- package/dist/index.d.ts +9 -2
- package/dist/index.js +864 -774
- package/dist/inline.d.ts +4 -23
- package/dist/pd-highlight.d.ts +1 -1
- package/dist/pd.cjs +14 -14
- package/dist/pd.d.ts +2 -2
- package/dist/pd.js +436 -352
- package/dist/plugins.d.ts +14 -2
- package/dist/react.cjs +46 -0
- package/dist/react.d.ts +30 -0
- package/dist/react.js +937 -0
- package/package.json +52 -12
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/pd.cjs.map +0 -1
- package/dist/pd.js.map +0 -1
package/dist/inline.d.ts
CHANGED
|
@@ -1,25 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* - 行内代码段内冒号/`:-` 不参与键值/转义判定
|
|
6
|
-
* - `:-` / `:-`(代码段外)使整行不是键值
|
|
2
|
+
* 行内代码(`...`)/ `:-` 整行转义 / 严格键值判定——**单一来源**:
|
|
3
|
+
* 直接复用共享语义包 @andares/pdfoundation 的 lexer 工具,组件不再保留副本
|
|
4
|
+
* (历史教训:两套判定漂移后,`-\t`、`//!pd` 的边界行为在主包/组件间不一致)。
|
|
7
5
|
*/
|
|
8
|
-
export
|
|
9
|
-
code: boolean;
|
|
10
|
-
seg: string;
|
|
11
|
-
}
|
|
12
|
-
/** 按反引号配对切分;未闭合段当普通字符(code:false) */
|
|
13
|
-
export declare function splitInlineCode(text: string): InlineSeg[];
|
|
14
|
-
/** 整行是否含 `:-` / `:-`(行内代码段外)→ 整行不是键值 */
|
|
15
|
-
export declare function hasLiteralColon(s: string): boolean;
|
|
16
|
-
/**
|
|
17
|
-
* 代码段外第一个半角冒号的位置(-1 = 无)。
|
|
18
|
-
* 供高亮层定位原始文本中的冒号位置(精确 slice,保证覆盖层对齐)。
|
|
19
|
-
*/
|
|
20
|
-
export declare function findKeyValueSeparator(s: string): number;
|
|
21
|
-
/** 严格键值判定(与 lexer 一致):键名不以空白结尾、冒号后跟空白或行尾、只认第一个半角冒号 */
|
|
22
|
-
export declare function matchKeyValue(s: string): {
|
|
23
|
-
key: string;
|
|
24
|
-
value: string | undefined;
|
|
25
|
-
} | null;
|
|
6
|
+
export { findKeyValueSeparator, hasLiteralColon, matchKeyValue, splitInlineCode, } from "@andares/pdfoundation";
|
package/dist/pd-highlight.d.ts
CHANGED
package/dist/pd.cjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=require("@andares/pdfoundation");function
|
|
2
|
-
`),
|
|
3
|
-
`)
|
|
4
|
-
|
|
5
|
-
`)
|
|
6
|
-
|
|
7
|
-
`),
|
|
8
|
-
`).
|
|
9
|
-
`).
|
|
10
|
-
`);
|
|
11
|
-
`),
|
|
12
|
-
`);
|
|
13
|
-
`)
|
|
14
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=require("@andares/pdfoundation");function Me(i,o,{signal:s,edges:e}={}){let l,r=null;const u=e!=null&&e.includes("leading"),p=e==null||e.includes("trailing"),b=()=>{r!==null&&(i.apply(l,r),l=void 0,r=null)},w=()=>{p&&b(),$()};let v=null;const S=()=>{v!=null&&clearTimeout(v),v=setTimeout(()=>{v=null,w()},o)},E=()=>{v!==null&&(clearTimeout(v),v=null)},$=()=>{E(),l=void 0,r=null},y=()=>{b()},L=function(...d){if(s!=null&&s.aborted)return;l=this,r=d;const h=v==null;S(),u&&h&&b()};return L.schedule=S,L.cancel=$,L.flush=y,s==null||s.addEventListener("abort",$,{once:!0}),L}function Q(i,o){const s=i,e=s.key.toLowerCase(),l=o.split("+"),r=l.slice(0,-1),u=l[l.length-1];return!(e!==u||r.includes("shift")!==s.shiftKey||r.includes("ctrl")!==s.ctrlKey||r.includes("alt")!==s.altKey||r.includes("meta")!==s.metaKey)}function be(i,o){var l;const e=i.slice(0,o).split(`
|
|
2
|
+
`);return{line:e.length-1,col:((l=e[e.length-1])==null?void 0:l.length)??0}}function I(i,o,s){var l;let e=0;for(let r=0;r<o;r++)e+=(((l=i[r])==null?void 0:l.length)??0)+1;return e+s}function ve(){return(i,o)=>{var w;if(o.type!=="keydown"||!Q(o,"enter"))return;const{value:s,selectionStart:e,selectionEnd:l}=i,r=s.slice(0,e).split(`
|
|
3
|
+
`).pop()??"",u=((w=/^\s*/.exec(r))==null?void 0:w[0])??"";o.preventDefault();const p=/^(\s*)-(?=[ ]|$)/.test(r),b=`
|
|
4
|
+
${u}${p?"- ":""}`;return{value:s.slice(0,e)+b+s.slice(l),selectionStart:e+b.length,selectionEnd:e+b.length}}}function Ne(i){return/^(\s*)-(?=[ ]|$)/.test(i)}function ye(i,o){return i.startsWith(o)?o.length:i.startsWith(" ")?1:0}function Le(i){return(o,s)=>{if(s.type!=="keydown")return;const{value:e,selectionStart:l,selectionEnd:r}=o,u=e.split(`
|
|
5
|
+
`),p=e.slice(0,l).split(`
|
|
6
|
+
`).length-1,b=e.slice(0,r).split(`
|
|
7
|
+
`).length-1,w=be(e,l),v=be(e,r);if(Q(s,"shift+tab")){s.preventDefault();const S=u.map((d,h)=>h>=p&&h<=b?d.slice(ye(d,i)):d),E=S.join(`
|
|
8
|
+
`);if(E===e)return;const $=d=>{const h=ye(u[d.line]??"",i);return{line:d.line,col:Math.max(0,d.col-h)}},y=$(w),L=$(v);return{value:E,selectionStart:I(S,y.line,y.col),selectionEnd:I(S,L.line,L.col)}}if(Q(s,"tab")){s.preventDefault();const S=u.map((y,L)=>({l:y,i:L})).filter(({i:y})=>y>=p&&y<=b);if(S.length>0&&S.every(({l:y})=>Ne(y))||l!==r){const y=u.map((x,g)=>g>=p&&g<=b&&x!==""?i+x:x),L=y.join(`
|
|
9
|
+
`),d=x=>{const g=u[x.line]??"",U=x.line>=p&&x.line<=b;return{line:x.line,col:U&&g!==""?x.col+i.length:x.col}},h=d(w),n=d(v);return{value:L,selectionStart:I(y,h.line,h.col),selectionEnd:I(y,n.line,n.col)}}const $=l+i.length;return{value:e.slice(0,l)+i+e.slice(r),selectionStart:$,selectionEnd:$}}}}function Te(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function O(i){return i.replace(/\r\n?/g,`
|
|
10
|
+
`)}function De(i,o){const s=document.createRange();s.selectNodeContents(i),i.replaceChildren(s.createContextualFragment(o))}function Oe(i,o){const s=Math.min(i.length,o.length);let e=0;for(;e<s&&i.charCodeAt(e)===o.charCodeAt(e);)e++;return e}const Fe=new Set(["padding","paddingTop","paddingRight","paddingBottom","paddingLeft"]);function xe(i){var e;const o={top:"0px",right:"0px",bottom:"0px",left:"0px"},s=(e=i.padding)==null?void 0:e.trim();if(s){const l=s.split(/\s+/);if(l.length===1){const r=l[0]??"0px";o.top=o.right=o.bottom=o.left=r}else l.length===2?(o.top=o.bottom=l[0]??"0px",o.right=o.left=l[1]??"0px"):l.length===3?(o.top=l[0]??"0px",o.right=o.left=l[1]??"0px",o.bottom=l[2]??"0px"):(o.top=l[0]??"0px",o.right=l[1]??"0px",o.bottom=l[2]??"0px",o.left=l[3]??"0px")}return i.paddingTop&&(o.top=i.paddingTop),i.paddingRight&&(o.right=i.paddingRight),i.paddingBottom&&(o.bottom=i.paddingBottom),i.paddingLeft&&(o.left=i.paddingLeft),o}function Ke(i){return i.startsWith("--")?i:i.replace(/[A-Z]/g,o=>`-${o.toLowerCase()}`)}const Se="position:relative;display:block;box-sizing:border-box;width:100%;height:auto;max-height:inherit;overflow:hidden;text-align:start;margin:0;border:0;font-family:var(--pd-font-family,inherit);font-size:var(--pd-font-size,inherit);line-height:var(--pd-line-height,1.5);letter-spacing:var(--pd-letter-spacing,inherit);color:var(--pd-color,inherit);background:var(--pd-background,transparent);tab-size:4;font-variant-ligatures:none;font-kerning:normal;",Ee="position:absolute;left:0;top:0;width:100%;height:100%;box-sizing:border-box;margin:0;border:0;outline:none;resize:none;background:transparent;-webkit-text-fill-color:transparent;caret-color:var(--pd-caret-color,currentColor);overflow:auto;scrollbar-gutter:stable;white-space:pre-wrap;overflow-wrap:break-word;word-break:normal;font:inherit;line-height:inherit;letter-spacing:inherit;tab-size:inherit;z-index:2;",$e="position:relative;left:auto;top:auto;width:100%;height:auto;box-sizing:border-box;margin:0;border:0;overflow:hidden;scrollbar-gutter:stable;pointer-events:none;user-select:none;white-space:pre-wrap;overflow-wrap:break-word;word-break:normal;font:inherit;line-height:inherit;letter-spacing:inherit;tab-size:inherit;color:inherit;z-index:1;",je="position:absolute;left:0;top:0;width:100%;height:100%;box-sizing:border-box;margin:0;border:0;overflow:hidden;scrollbar-gutter:stable;pointer-events:none;user-select:none;white-space:pre-wrap;overflow-wrap:break-word;word-break:normal;font:inherit;line-height:inherit;letter-spacing:inherit;tab-size:inherit;color:inherit;z-index:0;",ke="position:absolute;left:0;top:0;width:100%;height:100%;box-sizing:border-box;margin:0;border:0;overflow:hidden;scrollbar-gutter:stable;pointer-events:none;user-select:none;white-space:pre-wrap;overflow-wrap:break-word;word-break:normal;font:inherit;line-height:inherit;letter-spacing:inherit;tab-size:inherit;color:inherit;opacity:var(--pd-placeholder-opacity,0.5);z-index:1;";function V(i,o,s,e,l={}){const r=document.createElement(i);r.className=o,r.setAttribute("part",s),r.style.cssText=e;for(const[u,p]of Object.entries(l))r.setAttribute(u,p);return r}function Be(i,o,s){let e={...o},l=e.language??"pd",r=O(e.value??""),u=r,p=!1,b=!1,w=!1,v=e.lineNumbers??!1,S=G(),E="",$=!1,y=0,L=null;const d=V("div","pd-root","root",Se),h=V("pre","pd-highlight","highlight",$e,{"aria-hidden":"true"}),n=V("textarea","pd-input","input",Ee),x=V("div","pd-placeholder","placeholder",ke,{"aria-hidden":"true"});let g=null;n.spellcheck=e.spellcheck??!1,n.setAttribute("autocapitalize","off"),n.setAttribute("autocorrect","off"),n.setAttribute("autocomplete","off"),n.setAttribute("wrap","soft"),n.value=r,n.readOnly=e.readOnly??!1,n.disabled=e.disabled??!1,(t=>{t!==void 0&&t>=0?n.maxLength=t:n.removeAttribute("maxlength")})(e.maxLength),e.dir&&(n.dir=e.dir),B(),d.appendChild(h),d.appendChild(x),d.appendChild(n),i.appendChild(d),j(),J(),A(),q();function M(){p||(h.scrollTop=n.scrollTop,h.scrollLeft=n.scrollLeft,g&&(g.scrollTop=n.scrollTop,g.scrollLeft=n.scrollLeft))}function ze(){if(typeof getComputedStyle!="function")return 0;const t=getComputedStyle(i),a=Number.parseFloat(t.paddingTop)||0,c=Number.parseFloat(t.paddingBottom)||0;return Math.max(0,i.clientHeight-a-c)}function _(){$?(h.style.position="absolute",h.style.left="0",h.style.top="0",h.style.height="100%"):(h.style.position="relative",h.style.left="auto",h.style.top="auto",h.style.height="auto")}function q(){if(p)return;const t=ze(),a=h.scrollHeight;if(!$){t>0&&a>t+1&&($=!0,_(),d.style.height=`${t}px`,M());return}if(t<=0||a<=t+1){$=!1,_(),d.style.height="",n.scrollTop=0;return}const c=Number.parseFloat(d.style.height)||0;Math.abs(c-t)>.5&&(d.style.height=`${t}px`),M()}function ee(){if(!y){if(typeof requestAnimationFrame!="function"){q();return}y=requestAnimationFrame(()=>{y=0,q()})}}typeof ResizeObserver<"u"&&(L=new ResizeObserver(()=>ee()),L.observe(i),L.observe(d));const te=()=>M(),Pe=(t,a,c)=>{var f;r=t,u=t,W({value:t,selStart:a,selEnd:c}),(f=e.onValueChange)==null||f.call(e,t)},ne=t=>{if(p)return;const a=O(n.value);if(b||t!=null&&t.isComposing){r=a,A();return}a!==r&&(r=a,A()),a!==u&&Pe(a,n.selectionStart,n.selectionEnd)},ie=()=>{b=!0},re=()=>{b=!1;const t=O(n.value);t!==r&&(r=t,A())},Re=Math.max(0,e.historyLimit??5),oe=Math.max(0,e.historyDebounce??1e3),C=[{value:r,selStart:-1,selEnd:-1}],D=[],le=()=>{C.length>Re+1&&C.splice(1,1)},se=t=>{const a=C[0];if(a!==void 0&&a.selStart<0&&a.value!==t.value){const f=Oe(a.value,t.value);a.selStart=f,a.selEnd=f}const c=C.at(-1);c!==void 0&&c.value===t.value||(D.length=0,C.push(t),le())},F=Me(se,oe),W=t=>{oe===0?se(t):F(t)},ae=t=>{var f;const a=t.selStart>=0?t.selStart:Math.min(t.value.length,n.selectionStart),c=t.selEnd>=0?t.selEnd:a;r=t.value,u=t.value,n.value=t.value,n.setSelectionRange(Math.max(0,Math.min(a,t.value.length)),Math.max(0,Math.min(c,t.value.length))),A(),M(),(f=e.onValueChange)==null||f.call(e,t.value)},ce=()=>{if(F.flush(),C.length<=1)return!1;const t=C.pop();t!==void 0&&D.push(t);const a=C.at(-1);return a!==void 0&&ae(a),!0},ue=()=>{if(F.flush(),D.length===0)return!1;const t=D.pop();return t===void 0?!1:(C.push(t),le(),ae(t),!0)},de=t=>{var T;if(p||t.isComposing||b||n.readOnly||n.disabled)return;const a=t.ctrlKey||t.metaKey,c=t.key.toLowerCase();if(a&&(c==="z"||c==="y")){t.preventDefault(),c==="y"||c==="z"&&t.shiftKey?ue():ce();return}if(c==="escape"){(e.tabBehavior??"indent")==="indent"&&(w=!0);return}if(c==="tab"&&(e.tabBehavior??"indent")==="focus")return;if(c==="tab"&&w){w=!1;return}const f={value:r,selectionStart:n.selectionStart,selectionEnd:n.selectionEnd};let m=f;for(const N of Y){const P=N(m,t);P&&(m={...m,...P})}(m.value!==f.value||m.selectionStart!==f.selectionStart||m.selectionEnd!==f.selectionEnd)&&(t.preventDefault(),r=m.value,n.value=m.value,n.setSelectionRange(m.selectionStart,m.selectionEnd),u=m.value,A(),W({value:m.value,selStart:m.selectionStart,selEnd:m.selectionEnd}),(T=e.onValueChange)==null||T.call(e,m.value),M())},fe=()=>d.classList.add("pd-focused"),pe=()=>d.classList.remove("pd-focused");n.addEventListener("input",ne),n.addEventListener("compositionstart",ie),n.addEventListener("compositionend",re),n.addEventListener("scroll",te,{passive:!0}),n.addEventListener("keydown",de),n.addEventListener("focus",fe),n.addEventListener("blur",pe);function G(){return e.highlight?t=>{var a;return((a=e.highlight)==null?void 0:a.call(e,t,l))??""}:s(l)}function A(){if(p)return;const t=e.highlightThreshold??1e5,a=r.length>t?Te(r):S(r);De(h,`${a}<br/>`),v&&he(),J(),L||ee()}function he(){if(!v)return;g||(g=document.createElement("pre"),g.className="pd-lines",g.setAttribute("part","gutter"),g.setAttribute("aria-hidden","true"),d.insertBefore(g,x));const t=r.split(`
|
|
11
|
+
`),c=`${String(t.length).length+1}ch`,f=xe(e.styles??{}),m=`position:absolute;inset-inline-start:${f.left};width:${c};text-align:end;opacity:var(--pd-gutter-opacity,0.35);color:var(--pd-gutter-color,inherit)`,T=document.createDocumentFragment();t.forEach((N,P)=>{const H=document.createElement("span");H.className="pd-ln",H.style.cssText=m,H.textContent=String(P+1);const Z=document.createElement("span");Z.style.color="transparent",Z.textContent=N,T.append(H,Z),P<t.length-1&&T.append(document.createTextNode(`
|
|
12
|
+
`))}),T.append(document.createElement("br")),g.replaceChildren(T),c!==E&&(E=c,j(),g.style.cssText=me(f))}function J(){const t=e.placeholder??"";x.textContent=t,x.style.display=t&&r.length===0?"block":"none",t?n.setAttribute("aria-placeholder",t):n.removeAttribute("aria-placeholder")}function ge(t){const a=E?`calc(${t.left} + ${E})`:t.left;return`padding:${t.top} ${t.right} ${t.bottom} ${a};`}function X(t,a){return a+ge(t)}function me(t){return je+ge(t)}function j(){const t=e.styles??{},a=xe(t),c=Object.entries(t).filter(([f])=>!Fe.has(f)).map(([f,m])=>`${Ke(f)}:${m};`).join("");d.style.cssText=Se+c,h.style.cssText=X(a,$e),n.style.cssText=X(a,Ee),x.style.cssText=X(a,ke),g&&(g.style.cssText=me(a)),_(),e.dir&&(d.dir=e.dir,n.dir=e.dir,h.dir=e.dir,x.dir=e.dir,g&&(g.dir=e.dir))}function B(){e.ariaLabel?n.setAttribute("aria-label",e.ariaLabel):n.removeAttribute("aria-label"),e.ariaLabelledby?n.setAttribute("aria-labelledby",e.ariaLabelledby):n.removeAttribute("aria-labelledby"),e.ariaDescribedby?n.setAttribute("aria-describedby",e.ariaDescribedby):n.removeAttribute("aria-describedby"),e.readOnly?n.setAttribute("aria-readonly","true"):n.removeAttribute("aria-readonly"),e.disabled?n.setAttribute("aria-disabled","true"):n.removeAttribute("aria-disabled")}v&&he();const Y=[ve(),Le(e.indentUnit??" ")];return{setValue(t,a){if(p||b)return;let c=O(t);e.maxLength!==void 0&&e.maxLength>=0&&(c=c.slice(0,e.maxLength)),F.cancel(),r=c,u=c,n.value=c,n.setSelectionRange(c.length,c.length),((a==null?void 0:a.resetHistory)??!0)&&(C.length=0,C.push({value:c,selStart:-1,selEnd:-1}),D.length=0),A(),M()},getValue(){return r},setLanguage(t){l=t,e={...e,language:t},S=G(),A()},setPlaceholder(t){e={...e,placeholder:t},J()},setReadOnly(t){e={...e,readOnly:t},n.readOnly=t,B()},setDisabled(t){e={...e,disabled:t},n.disabled=t,B()},setLineNumbers(t){v!==t&&(v=t,!t&&g&&(g.remove(),g=null,E=""),j(),A())},update(t){p||(e={...e,...t},t.indentUnit!==void 0&&Y.splice(0,Y.length,ve(),Le(t.indentUnit)),t.language!==void 0&&(l=t.language),("highlight"in t||t.language!==void 0)&&(S=G()),t.lineNumbers!==void 0&&(v=t.lineNumbers,!v&&g&&(g.remove(),g=null,E="")),t.value!==void 0&&(r=O(t.value),u=r,n.value=r,C.length=0,C.push({value:r,selStart:-1,selEnd:-1}),D.length=0),t.readOnly!==void 0&&(n.readOnly=t.readOnly),t.disabled!==void 0&&(n.disabled=t.disabled),t.maxLength!==void 0&&(t.maxLength>=0?n.maxLength=t.maxLength:n.removeAttribute("maxlength")),t.spellcheck!==void 0&&(n.spellcheck=t.spellcheck),t.dir!==void 0&&(n.dir=t.dir),B(),j(),A(),M())},focus(){n.focus()},blur(){n.blur()},undo(){ce()},redo(){ue()},insertText(t){var N;if(p||n.readOnly||n.disabled)return;const a=n.selectionStart,c=n.selectionEnd;let f=O(t);if(e.maxLength!==void 0&&e.maxLength>=0){const P=e.maxLength-(r.length-(c-a));if(P<=0)return;f.length>P&&(f=f.slice(0,P))}const m=r.slice(0,a)+f+r.slice(c);r=m,u=m,n.value=m;const T=a+f.length;n.setSelectionRange(T,T),A(),W({value:m,selStart:T,selEnd:T}),(N=e.onValueChange)==null||N.call(e,m),M()},getSelection(){return{start:n.selectionStart,end:n.selectionEnd}},setSelection(t,a=t){const c=f=>Math.max(0,Math.min(r.length,Number.isFinite(f)?f:0));n.setSelectionRange(c(t),c(a))},destroy(){p||(p=!0,F.cancel(),L==null||L.disconnect(),y&&typeof cancelAnimationFrame=="function"&&cancelAnimationFrame(y),n.removeEventListener("input",ne),n.removeEventListener("compositionstart",ie),n.removeEventListener("compositionend",re),n.removeEventListener("scroll",te),n.removeEventListener("keydown",de),n.removeEventListener("focus",fe),n.removeEventListener("blur",pe),d.remove())},textarea:n,root:d,pre:h}}function k(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}const R={key:"pd-key",keyPunct:"pd-key-punct",item:"pd-item",section:"pd-section",sep:"pd-sep",ref:"pd-ref",inlineCode:"pd-inline-code",fence:"pd-fence"};function He(i){return`<span class="${R.inlineCode}">${k(i)}</span>`}const Ce=/(?:^|\s):([^\s-][^\s]*)(?=\s|$)/g;function Ie(i){let o="",s=0;Ce.lastIndex=0;let e;for(;(e=Ce.exec(i))!==null;){const l=/^\s/.test(e[0])?1:0,r=e.index+l;o+=k(i.slice(s,r)),o+=`<span class="${R.ref}">${k(i.slice(r,e.index+e[0].length))}</span>`,s=e.index+e[0].length}return o+=k(i.slice(s)),o}function K(i){let o="";for(const{code:s,seg:e}of z.splitInlineCode(i))o+=s?He(e):Ie(e);return o}function we(i,o,s,e){const l=`<span class="${R.key}">${K(s)}</span>`,r=`<span class="${R.keyPunct}">:</span>`;return`${i}${o}${l}${r}${K(e)}`}function Ve(i){const o=i.trim();if(/^\/\/!pd(?:\s+[^\s]+)?$/.test(o)){const e=/^(\s*)(\/\/!pd)(\s*.*)$/.exec(i),l=(e==null?void 0:e[1])??"",r=(e==null?void 0:e[2])??"//!pd",u=(e==null?void 0:e[3])??"";return`${k(l)}<span class="${R.section}">${k(r)}</span>${K(u)}`}if(o==="---")return`<span class="${R.sep}">${k(i)}</span>`;const s=/^(\s*)(-)(?=[ ]|$)/.exec(i);if(s){const e=k(s[1]??""),l=(s[1]??"").length+1,r=i.slice(l),u=r.trimStart(),p=r.slice(0,r.length-u.length),b=`<span class="${R.item}">-</span>`;if(!z.hasLiteralColon(u)&&z.matchKeyValue(u)){const v=z.findKeyValueSeparator(u),S=u.slice(0,v),E=u.slice(v+1);return`${e}${b}${k(p)}${we("","",S,E)}`}return`${e}${b}${k(p)}${K(u)}`}if(!z.hasLiteralColon(o)&&z.matchKeyValue(o)){const l=i.length-i.trimStart().length,r=i.slice(l),u=z.findKeyValueSeparator(r),p=r.slice(0,u).trim(),b=r.slice(u+1);return we(k(i.slice(0,l)),"",p,b)}return K(i)}function Ae(i){const o=i.split(`
|
|
13
|
+
`);let s=!1;const e=[];for(const l of o){const r=l.trimStart();if(s){r.startsWith("```")?(s=!1,e.push(`<span class="${R.fence}">${k(l)}</span>`)):e.push(k(l));continue}if(r.startsWith("```")){s=!0,e.push(`<span class="${R.fence}">${k(l)}</span>`);continue}e.push(Ve(l))}return e.join(`
|
|
14
|
+
`)}function _e(i){return o=>i==="pd"?Ae(o):Te(o)}function qe(i,o={}){return Be(i,o,_e)}Object.defineProperty(exports,"format",{enumerable:!0,get:()=>z.format});Object.defineProperty(exports,"jsonToPdText",{enumerable:!0,get:()=>z.jsonToPdText});Object.defineProperty(exports,"pdToJsonText",{enumerable:!0,get:()=>z.pdToJsonText});exports.createPdEditor=qe;exports.highlightPd=Ae;
|
package/dist/pd.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type PdEditorInstance, type PdEditorOptions } from "./core";
|
|
2
2
|
export type { EditorLang, PdEditorInstance, PdEditorOptions } from "./core";
|
|
3
3
|
export { format, jsonToPdText, pdToJsonText } from "@andares/pdfoundation";
|
|
4
4
|
export { highlightPd } from "./pd-highlight";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* 低 UI 提示词输入框——pd-only 精简入口。
|
|
7
7
|
* 仅 pd 语言高亮(自研 tokenizer);setLanguage 切到 md/xml/json/yaml 时内容
|
|
8
8
|
* 以纯文本渲染(无高亮但功能完好)。需要其余语言内置高亮时用主入口
|
|
9
9
|
* `@andares/pdeditor`(含 Prism),或通过 options.highlight 自带高亮器(BYO)。
|