@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.
@@ -0,0 +1,46 @@
1
+ "use strict";var Pe=Object.defineProperty;var Me=(r,i,s)=>i in r?Pe(r,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[i]=s;var A=(r,i,s)=>Me(r,typeof i!="symbol"?i+"":i,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("@andares/pdfoundation");function ze(r,i,{signal:s,edges:t}={}){let a,e=null;const l=t!=null&&t.includes("leading"),u=t==null||t.includes("trailing"),d=()=>{e!==null&&(r.apply(a,e),a=void 0,e=null)},S=()=>{u&&d(),$()};let v=null;const _=()=>{v!=null&&clearTimeout(v),v=setTimeout(()=>{v=null,S()},i)},L=()=>{v!==null&&(clearTimeout(v),v=null)},$=()=>{L(),a=void 0,e=null},y=()=>{d()},x=function(...p){if(s!=null&&s.aborted)return;a=this,e=p;const g=v==null;_(),l&&g&&d()};return x.schedule=_,x.cancel=$,x.flush=y,s==null||s.addEventListener("abort",$,{once:!0}),x}function Q(r,i){const s=r,t=s.key.toLowerCase(),a=i.split("+"),e=a.slice(0,-1),l=a[a.length-1];return!(t!==l||e.includes("shift")!==s.shiftKey||e.includes("ctrl")!==s.ctrlKey||e.includes("alt")!==s.altKey||e.includes("meta")!==s.metaKey)}function ve(r,i){var a;const t=r.slice(0,i).split(`
2
+ `);return{line:t.length-1,col:((a=t[t.length-1])==null?void 0:a.length)??0}}function K(r,i,s){var a;let t=0;for(let e=0;e<i;e++)t+=(((a=r[e])==null?void 0:a.length)??0)+1;return t+s}function ye(){return(r,i)=>{var S;if(i.type!=="keydown"||!Q(i,"enter"))return;const{value:s,selectionStart:t,selectionEnd:a}=r,e=s.slice(0,t).split(`
3
+ `).pop()??"",l=((S=/^\s*/.exec(e))==null?void 0:S[0])??"";i.preventDefault();const u=/^(\s*)-(?=[ ]|$)/.test(e),d=`
4
+ ${l}${u?"- ":""}`;return{value:s.slice(0,t)+d+s.slice(a),selectionStart:t+d.length,selectionEnd:t+d.length}}}function He(r){return/^(\s*)-(?=[ ]|$)/.test(r)}function xe(r,i){return r.startsWith(i)?i.length:r.startsWith(" ")?1:0}function ke(r){return(i,s)=>{if(s.type!=="keydown")return;const{value:t,selectionStart:a,selectionEnd:e}=i,l=t.split(`
5
+ `),u=t.slice(0,a).split(`
6
+ `).length-1,d=t.slice(0,e).split(`
7
+ `).length-1,S=ve(t,a),v=ve(t,e);if(Q(s,"shift+tab")){s.preventDefault();const _=l.map((p,g)=>g>=u&&g<=d?p.slice(xe(p,r)):p),L=_.join(`
8
+ `);if(L===t)return;const $=p=>{const g=xe(l[p.line]??"",r);return{line:p.line,col:Math.max(0,p.col-g)}},y=$(S),x=$(v);return{value:L,selectionStart:K(_,y.line,y.col),selectionEnd:K(_,x.line,x.col)}}if(Q(s,"tab")){s.preventDefault();const _=l.map((y,x)=>({l:y,i:x})).filter(({i:y})=>y>=u&&y<=d);if(_.length>0&&_.every(({l:y})=>He(y))||a!==e){const y=l.map((k,b)=>b>=u&&b<=d&&k!==""?r+k:k),x=y.join(`
9
+ `),p=k=>{const b=l[k.line]??"",ee=k.line>=u&&k.line<=d;return{line:k.line,col:ee&&b!==""?k.col+r.length:k.col}},g=p(S),o=p(v);return{value:x,selectionStart:K(y,g.line,g.col),selectionEnd:K(y,o.line,o.col)}}const $=a+r.length;return{value:t.slice(0,a)+r+t.slice(e),selectionStart:$,selectionEnd:$}}}}function Ve(r){return r.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function R(r){return r.replace(/\r\n?/g,`
10
+ `)}function Ie(r,i){const s=document.createRange();s.selectNodeContents(r),r.replaceChildren(s.createContextualFragment(i))}function Ke(r,i){const s=Math.min(r.length,i.length);let t=0;for(;t<s&&r.charCodeAt(t)===i.charCodeAt(t);)t++;return t}const je=new Set(["padding","paddingTop","paddingRight","paddingBottom","paddingLeft"]);function _e(r){var t;const i={top:"0px",right:"0px",bottom:"0px",left:"0px"},s=(t=r.padding)==null?void 0:t.trim();if(s){const a=s.split(/\s+/);if(a.length===1){const e=a[0]??"0px";i.top=i.right=i.bottom=i.left=e}else a.length===2?(i.top=i.bottom=a[0]??"0px",i.right=i.left=a[1]??"0px"):a.length===3?(i.top=a[0]??"0px",i.right=i.left=a[1]??"0px",i.bottom=a[2]??"0px"):(i.top=a[0]??"0px",i.right=a[1]??"0px",i.bottom=a[2]??"0px",i.left=a[3]??"0px")}return r.paddingTop&&(i.top=r.paddingTop),r.paddingRight&&(i.right=r.paddingRight),r.paddingBottom&&(i.bottom=r.paddingBottom),r.paddingLeft&&(i.left=r.paddingLeft),i}function qe(r){return r.startsWith("--")?r:r.replace(/[A-Z]/g,i=>`-${i.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;",Le="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;",We="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;",Ce="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 j(r,i,s,t,a={}){const e=document.createElement(r);e.className=i,e.setAttribute("part",s),e.style.cssText=t;for(const[l,u]of Object.entries(a))e.setAttribute(l,u);return e}function Ue(r,i,s){let t={...i},a=t.language??"pd",e=R(t.value??""),l=e,u=!1,d=!1,S=!1,v=t.lineNumbers??!1,_=G(),L="",$=!1,y=0,x=null;const p=j("div","pd-root","root",Se),g=j("pre","pd-highlight","highlight",$e,{"aria-hidden":"true"}),o=j("textarea","pd-input","input",Le),k=j("div","pd-placeholder","placeholder",Ce,{"aria-hidden":"true"});let b=null;o.spellcheck=t.spellcheck??!1,o.setAttribute("autocapitalize","off"),o.setAttribute("autocorrect","off"),o.setAttribute("autocomplete","off"),o.setAttribute("wrap","soft"),o.value=e,o.readOnly=t.readOnly??!1,o.disabled=t.disabled??!1,(n=>{n!==void 0&&n>=0?o.maxLength=n:o.removeAttribute("maxlength")})(t.maxLength),t.dir&&(o.dir=t.dir),H(),p.appendChild(g),p.appendChild(k),p.appendChild(o),r.appendChild(p),z(),J(),T(),W();function B(){u||(g.scrollTop=o.scrollTop,g.scrollLeft=o.scrollLeft,b&&(b.scrollTop=o.scrollTop,b.scrollLeft=o.scrollLeft))}function De(){if(typeof getComputedStyle!="function")return 0;const n=getComputedStyle(r),c=Number.parseFloat(n.paddingTop)||0,h=Number.parseFloat(n.paddingBottom)||0;return Math.max(0,r.clientHeight-c-h)}function q(){$?(g.style.position="absolute",g.style.left="0",g.style.top="0",g.style.height="100%"):(g.style.position="relative",g.style.left="auto",g.style.top="auto",g.style.height="auto")}function W(){if(u)return;const n=De(),c=g.scrollHeight;if(!$){n>0&&c>n+1&&($=!0,q(),p.style.height=`${n}px`,B());return}if(n<=0||c<=n+1){$=!1,q(),p.style.height="",o.scrollTop=0;return}const h=Number.parseFloat(p.style.height)||0;Math.abs(h-n)>.5&&(p.style.height=`${n}px`),B()}function te(){if(!y){if(typeof requestAnimationFrame!="function"){W();return}y=requestAnimationFrame(()=>{y=0,W()})}}typeof ResizeObserver<"u"&&(x=new ResizeObserver(()=>te()),x.observe(r),x.observe(p));const ne=()=>B(),Ne=(n,c,h)=>{var f;e=n,l=n,U({value:n,selStart:c,selEnd:h}),(f=t.onValueChange)==null||f.call(t,n)},ie=n=>{if(u)return;const c=R(o.value);if(d||n!=null&&n.isComposing){e=c,T();return}c!==e&&(e=c,T()),c!==l&&Ne(c,o.selectionStart,o.selectionEnd)},re=()=>{d=!0},oe=()=>{d=!1;const n=R(o.value);n!==e&&(e=n,T())},Re=Math.max(0,t.historyLimit??5),le=Math.max(0,t.historyDebounce??1e3),E=[{value:e,selStart:-1,selEnd:-1}],N=[],se=()=>{E.length>Re+1&&E.splice(1,1)},ae=n=>{const c=E[0];if(c!==void 0&&c.selStart<0&&c.value!==n.value){const f=Ke(c.value,n.value);c.selStart=f,c.selEnd=f}const h=E.at(-1);h!==void 0&&h.value===n.value||(N.length=0,E.push(n),se())},P=ze(ae,le),U=n=>{le===0?ae(n):P(n)},ce=n=>{var f;const c=n.selStart>=0?n.selStart:Math.min(n.value.length,o.selectionStart),h=n.selEnd>=0?n.selEnd:c;e=n.value,l=n.value,o.value=n.value,o.setSelectionRange(Math.max(0,Math.min(c,n.value.length)),Math.max(0,Math.min(h,n.value.length))),T(),B(),(f=t.onValueChange)==null||f.call(t,n.value)},ue=()=>{if(P.flush(),E.length<=1)return!1;const n=E.pop();n!==void 0&&N.push(n);const c=E.at(-1);return c!==void 0&&ce(c),!0},de=()=>{if(P.flush(),N.length===0)return!1;const n=N.pop();return n===void 0?!1:(E.push(n),se(),ce(n),!0)},he=n=>{var w;if(u||n.isComposing||d||o.readOnly||o.disabled)return;const c=n.ctrlKey||n.metaKey,h=n.key.toLowerCase();if(c&&(h==="z"||h==="y")){n.preventDefault(),h==="y"||h==="z"&&n.shiftKey?de():ue();return}if(h==="escape"){(t.tabBehavior??"indent")==="indent"&&(S=!0);return}if(h==="tab"&&(t.tabBehavior??"indent")==="focus")return;if(h==="tab"&&S){S=!1;return}const f={value:e,selectionStart:o.selectionStart,selectionEnd:o.selectionEnd};let m=f;for(const D of Y){const O=D(m,n);O&&(m={...m,...O})}(m.value!==f.value||m.selectionStart!==f.selectionStart||m.selectionEnd!==f.selectionEnd)&&(n.preventDefault(),e=m.value,o.value=m.value,o.setSelectionRange(m.selectionStart,m.selectionEnd),l=m.value,T(),U({value:m.value,selStart:m.selectionStart,selEnd:m.selectionEnd}),(w=t.onValueChange)==null||w.call(t,m.value),B())},pe=()=>p.classList.add("pd-focused"),fe=()=>p.classList.remove("pd-focused");o.addEventListener("input",ie),o.addEventListener("compositionstart",re),o.addEventListener("compositionend",oe),o.addEventListener("scroll",ne,{passive:!0}),o.addEventListener("keydown",he),o.addEventListener("focus",pe),o.addEventListener("blur",fe);function G(){return t.highlight?n=>{var c;return((c=t.highlight)==null?void 0:c.call(t,n,a))??""}:s(a)}function T(){if(u)return;const n=t.highlightThreshold??1e5,c=e.length>n?Ve(e):_(e);Ie(g,`${c}<br/>`),v&&ge(),J(),x||te()}function ge(){if(!v)return;b||(b=document.createElement("pre"),b.className="pd-lines",b.setAttribute("part","gutter"),b.setAttribute("aria-hidden","true"),p.insertBefore(b,k));const n=e.split(`
11
+ `),h=`${String(n.length).length+1}ch`,f=_e(t.styles??{}),m=`position:absolute;inset-inline-start:${f.left};width:${h};text-align:end;opacity:var(--pd-gutter-opacity,0.35);color:var(--pd-gutter-color,inherit)`,w=document.createDocumentFragment();n.forEach((D,O)=>{const I=document.createElement("span");I.className="pd-ln",I.style.cssText=m,I.textContent=String(O+1);const Z=document.createElement("span");Z.style.color="transparent",Z.textContent=D,w.append(I,Z),O<n.length-1&&w.append(document.createTextNode(`
12
+ `))}),w.append(document.createElement("br")),b.replaceChildren(w),h!==L&&(L=h,z(),b.style.cssText=me(f))}function J(){const n=t.placeholder??"";k.textContent=n,k.style.display=n&&e.length===0?"block":"none",n?o.setAttribute("aria-placeholder",n):o.removeAttribute("aria-placeholder")}function be(n){const c=L?`calc(${n.left} + ${L})`:n.left;return`padding:${n.top} ${n.right} ${n.bottom} ${c};`}function X(n,c){return c+be(n)}function me(n){return We+be(n)}function z(){const n=t.styles??{},c=_e(n),h=Object.entries(n).filter(([f])=>!je.has(f)).map(([f,m])=>`${qe(f)}:${m};`).join("");p.style.cssText=Se+h,g.style.cssText=X(c,$e),o.style.cssText=X(c,Le),k.style.cssText=X(c,Ce),b&&(b.style.cssText=me(c)),q(),t.dir&&(p.dir=t.dir,o.dir=t.dir,g.dir=t.dir,k.dir=t.dir,b&&(b.dir=t.dir))}function H(){t.ariaLabel?o.setAttribute("aria-label",t.ariaLabel):o.removeAttribute("aria-label"),t.ariaLabelledby?o.setAttribute("aria-labelledby",t.ariaLabelledby):o.removeAttribute("aria-labelledby"),t.ariaDescribedby?o.setAttribute("aria-describedby",t.ariaDescribedby):o.removeAttribute("aria-describedby"),t.readOnly?o.setAttribute("aria-readonly","true"):o.removeAttribute("aria-readonly"),t.disabled?o.setAttribute("aria-disabled","true"):o.removeAttribute("aria-disabled")}v&&ge();const Y=[ye(),ke(t.indentUnit??" ")];return{setValue(n,c){if(u||d)return;let h=R(n);t.maxLength!==void 0&&t.maxLength>=0&&(h=h.slice(0,t.maxLength)),P.cancel(),e=h,l=h,o.value=h,o.setSelectionRange(h.length,h.length),((c==null?void 0:c.resetHistory)??!0)&&(E.length=0,E.push({value:h,selStart:-1,selEnd:-1}),N.length=0),T(),B()},getValue(){return e},setLanguage(n){a=n,t={...t,language:n},_=G(),T()},setPlaceholder(n){t={...t,placeholder:n},J()},setReadOnly(n){t={...t,readOnly:n},o.readOnly=n,H()},setDisabled(n){t={...t,disabled:n},o.disabled=n,H()},setLineNumbers(n){v!==n&&(v=n,!n&&b&&(b.remove(),b=null,L=""),z(),T())},update(n){u||(t={...t,...n},n.indentUnit!==void 0&&Y.splice(0,Y.length,ye(),ke(n.indentUnit)),n.language!==void 0&&(a=n.language),("highlight"in n||n.language!==void 0)&&(_=G()),n.lineNumbers!==void 0&&(v=n.lineNumbers,!v&&b&&(b.remove(),b=null,L="")),n.value!==void 0&&(e=R(n.value),l=e,o.value=e,E.length=0,E.push({value:e,selStart:-1,selEnd:-1}),N.length=0),n.readOnly!==void 0&&(o.readOnly=n.readOnly),n.disabled!==void 0&&(o.disabled=n.disabled),n.maxLength!==void 0&&(n.maxLength>=0?o.maxLength=n.maxLength:o.removeAttribute("maxlength")),n.spellcheck!==void 0&&(o.spellcheck=n.spellcheck),n.dir!==void 0&&(o.dir=n.dir),H(),z(),T(),B())},focus(){o.focus()},blur(){o.blur()},undo(){ue()},redo(){de()},insertText(n){var D;if(u||o.readOnly||o.disabled)return;const c=o.selectionStart,h=o.selectionEnd;let f=R(n);if(t.maxLength!==void 0&&t.maxLength>=0){const O=t.maxLength-(e.length-(h-c));if(O<=0)return;f.length>O&&(f=f.slice(0,O))}const m=e.slice(0,c)+f+e.slice(h);e=m,l=m,o.value=m;const w=c+f.length;o.setSelectionRange(w,w),T(),U({value:m,selStart:w,selEnd:w}),(D=t.onValueChange)==null||D.call(t,m),B()},getSelection(){return{start:o.selectionStart,end:o.selectionEnd}},setSelection(n,c=n){const h=f=>Math.max(0,Math.min(e.length,Number.isFinite(f)?f:0));o.setSelectionRange(h(n),h(c))},destroy(){u||(u=!0,P.cancel(),x==null||x.disconnect(),y&&typeof cancelAnimationFrame=="function"&&cancelAnimationFrame(y),o.removeEventListener("input",ie),o.removeEventListener("compositionstart",re),o.removeEventListener("compositionend",oe),o.removeEventListener("scroll",ne),o.removeEventListener("keydown",he),o.removeEventListener("focus",pe),o.removeEventListener("blur",fe),p.remove())},textarea:o,root:p,pre:g}}function C(r){return r.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}const F={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 Ge(r){return`<span class="${F.inlineCode}">${C(r)}</span>`}const Ee=/(?:^|\s):([^\s-][^\s]*)(?=\s|$)/g;function Je(r){let i="",s=0;Ee.lastIndex=0;let t;for(;(t=Ee.exec(r))!==null;){const a=/^\s/.test(t[0])?1:0,e=t.index+a;i+=C(r.slice(s,e)),i+=`<span class="${F.ref}">${C(r.slice(e,t.index+t[0].length))}</span>`,s=t.index+t[0].length}return i+=C(r.slice(s)),i}function M(r){let i="";for(const{code:s,seg:t}of V.splitInlineCode(r))i+=s?Ge(t):Je(t);return i}function Ae(r,i,s,t){const a=`<span class="${F.key}">${M(s)}</span>`,e=`<span class="${F.keyPunct}">:</span>`;return`${r}${i}${a}${e}${M(t)}`}function Xe(r){const i=r.trim();if(/^\/\/!pd(?:\s+[^\s]+)?$/.test(i)){const t=/^(\s*)(\/\/!pd)(\s*.*)$/.exec(r),a=(t==null?void 0:t[1])??"",e=(t==null?void 0:t[2])??"//!pd",l=(t==null?void 0:t[3])??"";return`${C(a)}<span class="${F.section}">${C(e)}</span>${M(l)}`}if(i==="---")return`<span class="${F.sep}">${C(r)}</span>`;const s=/^(\s*)(-)(?=[ ]|$)/.exec(r);if(s){const t=C(s[1]??""),a=(s[1]??"").length+1,e=r.slice(a),l=e.trimStart(),u=e.slice(0,e.length-l.length),d=`<span class="${F.item}">-</span>`;if(!V.hasLiteralColon(l)&&V.matchKeyValue(l)){const v=V.findKeyValueSeparator(l),_=l.slice(0,v),L=l.slice(v+1);return`${t}${d}${C(u)}${Ae("","",_,L)}`}return`${t}${d}${C(u)}${M(l)}`}if(!V.hasLiteralColon(i)&&V.matchKeyValue(i)){const a=r.length-r.trimStart().length,e=r.slice(a),l=V.findKeyValueSeparator(e),u=e.slice(0,l).trim(),d=e.slice(l+1);return Ae(C(r.slice(0,a)),"",u,d)}return M(r)}function Oe(r){const i=r.split(`
13
+ `);let s=!1;const t=[];for(const a of i){const e=a.trimStart();if(s){e.startsWith("```")?(s=!1,t.push(`<span class="${F.fence}">${C(a)}</span>`)):t.push(C(a));continue}if(e.startsWith("```")){s=!0,t.push(`<span class="${F.fence}">${C(a)}</span>`);continue}t.push(Xe(a))}return t.join(`
14
+ `)}function Ye(r){return i=>r==="pd"?Oe(i):Ve(i)}function Fe(r){const i=r;return`
15
+ ${i}.pd-key{color:var(--pd-token-key,color-mix(in oklab,currentColor 66%,transparent))}
16
+ ${i}.pd-key-punct{color:var(--pd-token-punct,color-mix(in oklab,currentColor 45%,transparent))}
17
+ ${i}.pd-item{color:var(--pd-token-item,color-mix(in oklab,currentColor 78%,transparent))}
18
+ ${i}.pd-section{color:var(--pd-token-section,color-mix(in oklab,currentColor 62%,transparent))}
19
+ ${i}.pd-sep{color:var(--pd-token-sep,color-mix(in oklab,currentColor 45%,transparent))}
20
+ ${i}.pd-ref{color:var(--pd-token-ref,color-mix(in oklab,currentColor 74%,transparent))}
21
+ ${i}.pd-inline-code{color:var(--pd-token-code,color-mix(in oklab,currentColor 84%,transparent))}
22
+ ${i}.pd-fence{color:var(--pd-token-fence,color-mix(in oklab,currentColor 55%,transparent))}
23
+ ${i}.token.comment,${i}.token.prolog,${i}.token.doctype,${i}.token.cdata{color:var(--pd-token-comment,color-mix(in oklab,currentColor 52%,transparent))}
24
+ ${i}.token.string,${i}.token.attr-value{color:var(--pd-token-string,color-mix(in oklab,currentColor 78%,transparent))}
25
+ ${i}.token.keyword,${i}.token.tag,${i}.token.operator{color:var(--pd-token-keyword,color-mix(in oklab,currentColor 64%,transparent))}
26
+ ${i}.token.number,${i}.token.boolean{color:var(--pd-token-number,color-mix(in oklab,currentColor 72%,transparent))}
27
+ ${i}.token.property,${i}.token.function{color:var(--pd-token-property,color-mix(in oklab,currentColor 68%,transparent))}
28
+ ${i}.token.punctuation{color:var(--pd-token-punctuation,color-mix(in oklab,currentColor 50%,transparent))}
29
+ `}function Be(r){const i=r;return`
30
+ @supports not (color: color-mix(in oklab, red, blue)){
31
+ ${i}.pd-key{opacity:.72}${i}.pd-key-punct{opacity:.5}${i}.pd-item{opacity:.8}
32
+ ${i}.pd-section{opacity:.65}${i}.pd-sep{opacity:.5}${i}.pd-ref{opacity:.78}
33
+ ${i}.pd-inline-code{opacity:.88}${i}.pd-fence{opacity:.6}
34
+ }`}const we=`
35
+ :host{display:block;min-width:0;max-width:100%;height:auto;max-height:inherit;font:inherit;color:inherit;background:transparent}
36
+ :host([disabled]){opacity:var(--pd-disabled-opacity,.6)}
37
+ :host(:focus-within){outline:var(--pd-focus-ring,2px solid color-mix(in oklab,currentColor 32%,transparent));outline-offset:var(--pd-focus-ring-offset,2px);border-radius:var(--pd-focus-radius,2px)}
38
+ ${Fe("")}
39
+ ${Be("")}
40
+ `;function Ze(){const r="pd-editor ";return`
41
+ pd-editor{display:block;min-width:0;max-width:100%;height:auto;max-height:inherit;font:inherit;color:inherit;background:transparent}
42
+ pd-editor[disabled]{opacity:var(--pd-disabled-opacity,.6)}
43
+ pd-editor:focus-within{outline:var(--pd-focus-ring,2px solid color-mix(in oklab,currentColor 32%,transparent));outline-offset:var(--pd-focus-ring-offset,2px);border-radius:var(--pd-focus-radius,2px)}
44
+ ${Fe(r)}
45
+ ${Be(r)}
46
+ `}const Te=new WeakSet;function Qe(r){if(Te.has(r))return;Te.add(r);const i=r.createElement("style");i.setAttribute("data-pd-editor",""),i.textContent=Ze(),(r.head??r.documentElement).appendChild(i)}function et(r){if(r.querySelector("style[data-pd-editor]"))return;try{if(typeof CSSStyleSheet<"u"&&"replaceSync"in CSSStyleSheet.prototype){const s=new CSSStyleSheet;s.replaceSync(we),r.adoptedStyleSheets=[...r.adoptedStyleSheets,s];return}}catch{}const i=document.createElement("style");i.setAttribute("data-pd-editor",""),i.textContent=we,r.appendChild(i)}const tt=["value","language","placeholder","indent-unit","line-numbers","tab-behavior","readonly","disabled","maxlength","name","spellcheck","inputmode","enterkeyhint","dir","aria-label","aria-labelledby","aria-describedby","shadow"];function nt(r="pd-editor"){if(typeof HTMLElement>"u"||typeof customElements>"u")return null;const i=customElements.get(r);if(i)return i;class s extends HTMLElement{constructor(){super();A(this,"_editor",null);A(this,"_internals",null);A(this,"_container",null);A(this,"_shadow",null);A(this,"_value","");A(this,"_defaultValue",null);A(this,"_highlight",null);A(this,"_formDisabled",!1);A(this,"_focusValue","");A(this,"_onFocus",()=>{this._focusValue=this._value,this._emit("pd-focus",{value:this._value})});A(this,"_onBlur",()=>{this._value!==this._focusValue&&this._emit("pd-change",{value:this._value}),this._emit("pd-blur",{value:this._value})});try{this._internals=typeof this.attachInternals=="function"?this.attachInternals():null}catch{this._internals=null}}static get observedAttributes(){return tt}get value(){return this._editor?this._editor.getValue():this._value}set value(e){var u;const l=e==null?"":String(e);this._value=l,(u=this._editor)==null||u.setValue(l),this._syncFormValue()}get language(){return this.getAttribute("language")??"pd"}set language(e){this.setAttribute("language",String(e))}get placeholder(){return this.getAttribute("placeholder")??""}set placeholder(e){this.setAttribute("placeholder",String(e))}get readOnly(){return this.hasAttribute("readonly")}set readOnly(e){this.toggleAttribute("readonly",!!e)}get disabled(){return this.hasAttribute("disabled")}set disabled(e){this.toggleAttribute("disabled",!!e)}get lineNumbers(){return this.hasAttribute("line-numbers")}set lineNumbers(e){this.toggleAttribute("line-numbers",!!e)}get indentUnit(){return this.getAttribute("indent-unit")??" "}set indentUnit(e){this.setAttribute("indent-unit",String(e))}get tabBehavior(){return this.getAttribute("tab-behavior")==="focus"?"focus":"indent"}set tabBehavior(e){this.setAttribute("tab-behavior",e==="focus"?"focus":"indent")}get maxLength(){const e=this.getAttribute("maxlength");if(e===null||e==="")return-1;const l=Number.parseInt(e,10);return Number.isFinite(l)?l:-1}set maxLength(e){!Number.isFinite(e)||e<0?this.removeAttribute("maxlength"):this.setAttribute("maxlength",String(Math.floor(e)))}get name(){return this.getAttribute("name")??""}set name(e){this.setAttribute("name",String(e))}get highlight(){return this._highlight}set highlight(e){this._highlight=typeof e=="function"?e:null,this._syncOptions()}get editor(){return this._editor}get textarea(){var e;return((e=this._editor)==null?void 0:e.textarea)??null}connectedCallback(){this._upgradeProperties();const e=this.getAttribute("value");if(e!==null&&this._value===""&&(this._value=e),this._defaultValue===null&&(this._defaultValue=this._value),this._editor)return;const l=this.getAttribute("shadow")==="false";l?Qe(this.ownerDocument):(this._shadow??(this._shadow=this.attachShadow({mode:"open",delegatesFocus:!0})),et(this._shadow));const u=l?this:this._shadow,d=document.createElement("div");d.className="pd-container",d.setAttribute("part","container"),d.style.cssText="display:block;height:100%;max-height:inherit;min-width:0",u.appendChild(d),this._container=d;const S={value:this._value,language:this.language,placeholder:this.placeholder,readOnly:this.readOnly,disabled:this.disabled||this._formDisabled,lineNumbers:this.lineNumbers,indentUnit:this.indentUnit,tabBehavior:this.tabBehavior,maxLength:this.maxLength,spellcheck:this.getAttribute("spellcheck")==="true",dir:this.getAttribute("dir")??"",ariaLabel:this.getAttribute("aria-label")??void 0,ariaLabelledby:this.getAttribute("aria-labelledby")??void 0,ariaDescribedby:this.getAttribute("aria-describedby")??void 0,highlight:this._highlight??void 0,onValueChange:v=>this._handleValueChange(v)};this._editor=Ue(d,S,Ye),this._editor.textarea.addEventListener("focus",this._onFocus),this._editor.textarea.addEventListener("blur",this._onBlur),this._focusValue=this._value,this._applyInputHints(),this._syncFormValue(),queueMicrotask(()=>{this._editor&&this._emit("pd-ready",{editor:this._editor})})}disconnectedCallback(){var e,l,u,d;this._editor&&(this._value=this._editor.getValue()),(e=this._editor)==null||e.textarea.removeEventListener("focus",this._onFocus),(l=this._editor)==null||l.textarea.removeEventListener("blur",this._onBlur),(u=this._editor)==null||u.destroy(),this._editor=null,(d=this._container)==null||d.remove(),this._container=null}attributeChangedCallback(e,l,u){var d;if(l!==u){if(e==="value"){this._value=u??"",(d=this._editor)==null||d.setValue(this._value),this._syncFormValue();return}e!=="shadow"&&this._editor&&(this._syncOptions(),e==="language"&&this._emit("pd-language-change",{value:this.language}))}}formResetCallback(){this.value=this._defaultValue??""}formDisabledCallback(e){var l;this._formDisabled=e,(l=this._editor)==null||l.setDisabled(e||this.disabled)}formStateRestoreCallback(e){typeof e=="string"&&(this.value=e)}setValue(e){this.value=e}getValue(){return this.value}setLanguage(e){this.language=e}insertText(e){var l;(l=this._editor)==null||l.insertText(e)}getSelection(){var e;return((e=this._editor)==null?void 0:e.getSelection())??null}setSelection(e,l){var u;(u=this._editor)==null||u.setSelection(e,l)}undo(){var e;(e=this._editor)==null||e.undo()}redo(){var e;(e=this._editor)==null||e.redo()}focus(){var e;(e=this._editor)==null||e.focus()}blur(){var e;(e=this._editor)==null||e.blur()}_upgradeProperties(){const e=["value","language","placeholder","readOnly","disabled","lineNumbers","indentUnit","tabBehavior","maxLength","name","highlight"];for(const l of e)if(Object.prototype.hasOwnProperty.call(this,l)){const u=this,d=u[l];delete u[l],u[l]=d}}_syncOptions(){var e;(e=this._editor)==null||e.update({language:this.language,placeholder:this.placeholder,readOnly:this.readOnly,disabled:this.disabled||this._formDisabled,lineNumbers:this.lineNumbers,indentUnit:this.indentUnit,tabBehavior:this.tabBehavior,maxLength:this.maxLength,spellcheck:this.getAttribute("spellcheck")==="true",dir:this.getAttribute("dir")??"",ariaLabel:this.getAttribute("aria-label")??void 0,ariaLabelledby:this.getAttribute("aria-labelledby")??void 0,ariaDescribedby:this.getAttribute("aria-describedby")??void 0,highlight:this._highlight??void 0}),this._applyInputHints()}_applyInputHints(){var l;const e=(l=this._editor)==null?void 0:l.textarea;if(e)for(const u of["inputmode","enterkeyhint"]){const d=this.getAttribute(u);d?e.setAttribute(u,d):e.removeAttribute(u)}}_handleValueChange(e){this._value=e,this._syncFormValue(),this._emit("pd-input",{value:e})}_syncFormValue(){var e;typeof((e=this._internals)==null?void 0:e.setFormValue)=="function"&&this._internals.setFormValue(this._value)}_emit(e,l){this.dispatchEvent(new CustomEvent(e,{detail:l,bubbles:!0,composed:!0}))}}return A(s,"formAssociated",!0),customElements.define(r,s),s}Object.defineProperty(exports,"format",{enumerable:!0,get:()=>V.format});Object.defineProperty(exports,"jsonToPdText",{enumerable:!0,get:()=>V.jsonToPdText});Object.defineProperty(exports,"pdToJsonText",{enumerable:!0,get:()=>V.pdToJsonText});exports.definePdEditor=nt;exports.highlightPd=Oe;
@@ -0,0 +1,43 @@
1
+ import { type EditorLang, type PdEditorInstance, type TabBehavior } from "./core";
2
+ export { format, jsonToPdText, pdToJsonText } from "@andares/pdfoundation";
3
+ export { highlightPd } from "./pd-highlight";
4
+ /** 元素侧高亮器签名(与 core 的 options.highlight 一致) */
5
+ export type PdHighlighter = (source: string, lang: EditorLang) => string;
6
+ export interface PdEditorElement extends HTMLElement {
7
+ value: string;
8
+ language: string;
9
+ placeholder: string;
10
+ readOnly: boolean;
11
+ disabled: boolean;
12
+ lineNumbers: boolean;
13
+ indentUnit: string;
14
+ tabBehavior: TabBehavior;
15
+ maxLength: number;
16
+ name: string;
17
+ /** BYO 高亮器;null = 回到内置 pd-only 管线 */
18
+ highlight: PdHighlighter | null;
19
+ readonly editor: PdEditorInstance | null;
20
+ readonly textarea: HTMLTextAreaElement | null;
21
+ setValue(value: string): void;
22
+ getValue(): string;
23
+ setLanguage(lang: string): void;
24
+ insertText(text: string): void;
25
+ getSelection(): {
26
+ start: number;
27
+ end: number;
28
+ } | null;
29
+ setSelection(start: number, end?: number): void;
30
+ undo(): void;
31
+ redo(): void;
32
+ }
33
+ export type PdEditorElementConstructor = new () => PdEditorElement;
34
+ /**
35
+ * 定义 `<pd-editor>`(幂等)。Node/SSR 下安全返回 null;浏览器里返回构造器。
36
+ *
37
+ * 用法:
38
+ * ```ts
39
+ * import { definePdEditor } from "@andares/pdeditor/element";
40
+ * definePdEditor(); // 或 import "@andares/pdeditor/element/auto" 自动注册
41
+ * ```
42
+ */
43
+ export declare function definePdEditor(tagName?: string): PdEditorElementConstructor | null;