@benz-ai-x/dsh-md-preview 0.2.2 → 0.2.3

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.
Files changed (2) hide show
  1. package/lib/client.js +9 -1
  2. package/package.json +1 -1
package/lib/client.js CHANGED
@@ -61,7 +61,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
61
61
  `+e.scrub();for(let n of e.markers)t.marks.push(n)}return this.finishLeaf(t),null}stopAt(e){if(this.stoppedAt!=null&&this.stoppedAt<e)throw RangeError(`Can't move stoppedAt forward`);this.stoppedAt=e}reuseFragment(e){if(!this.fragments.moveTo(this.absoluteLineStart+e,this.absoluteLineStart)||!this.fragments.matches(this.block.hash))return!1;let t=this.fragments.takeNodes(this);return t?(this.absoluteLineStart+=t,this.lineStart=Ib(this.absoluteLineStart,this.ranges),this.moveRangeI(),this.absoluteLineStart<this.to?(this.lineStart++,this.absoluteLineStart++,this.readLine()):(this.atEnd=!0,this.readLine()),!0):!1}get depth(){return this.stack.length}parentType(e=this.depth-1){return this.parser.nodeSet.types[this.stack[e].type]}nextLine(){return this.lineStart+=this.line.text.length,this.absoluteLineEnd>=this.to?(this.absoluteLineStart=this.absoluteLineEnd,this.atEnd=!0,this.readLine(),!1):(this.lineStart++,this.absoluteLineStart=this.absoluteLineEnd+1,this.moveRangeI(),this.readLine(),!0)}peekLine(){return this.scanLine(this.absoluteLineEnd+1).text}moveRangeI(){for(;this.rangeI<this.ranges.length-1&&this.absoluteLineStart>=this.ranges[this.rangeI].to;)this.rangeI++,this.absoluteLineStart=Math.max(this.absoluteLineStart,this.ranges[this.rangeI].from)}scanLine(e){let t=lb;if(t.end=e,e>=this.to)t.text=``;else if(t.text=this.lineChunkAt(e),t.end+=t.text.length,this.ranges.length>1){let e=this.absoluteLineStart,n=this.rangeI;for(;this.ranges[n].to<t.end;){n++;let r=this.ranges[n].from,i=this.lineChunkAt(r);t.end=r+i.length,t.text=t.text.slice(0,this.ranges[n-1].to-e)+i,e=t.end-t.text.length}}return t}readLine(){let{line:e}=this,{text:t,end:n}=this.scanLine(this.absoluteLineStart);for(this.absoluteLineEnd=n,e.reset(t);e.depth<this.stack.length;e.depth++){let t=this.stack[e.depth],n=this.parser.skipContextMarkup[t.type];if(!n)throw Error(`Unhandled block context `+Q[t.type]);let r=this.line.markers.length;if(!n(t,this,e)){this.line.markers.length>r&&(t.end=this.line.markers[this.line.markers.length-1].to),e.forward();break}e.forward()}}lineChunkAt(e){let t=this.input.chunk(e),n;if(this.input.lineChunks)n=t==`
62
62
  `?``:t;else{let e=t.indexOf(`
63
63
  `);n=e<0?t:t.slice(0,e)}return e+n.length>this.to?n.slice(0,this.to-e):n}prevLineEnd(){return this.atEnd?this.lineStart:this.lineStart-1}startContext(e,t,n=0){this.block=Py.create(e,n,this.lineStart+t,this.block.hash,this.lineStart+this.line.text.length),this.stack.push(this.block)}startComposite(e,t,n=0){this.startContext(this.parser.getNodeType(e),t,n)}addNode(e,t,n){typeof e==`number`&&(e=new J(this.parser.nodeSet.types[e],_b,_b,(n??this.prevLineEnd())-t)),this.block.addChild(e,t-this.block.from)}addElement(e){this.block.addChild(e.toTree(this.parser.nodeSet),e.from-this.block.from)}addLeafElement(e,t){this.addNode(this.buffer.writeElements(Nb(t.children,e.marks),-t.from).finish(t.type,t.to-t.from),t.from)}finishContext(){let e=this.stack.pop(),t=this.stack[this.stack.length-1];t.addChild(e.toTree(this.parser.nodeSet),e.from-t.from),this.block=t}finish(){for(;this.stack.length>1;)this.finishContext();return this.addGaps(this.block.toTree(this.parser.nodeSet,this.lineStart))}addGaps(e){return this.ranges.length>1?db(this.ranges,0,e.topNode,this.ranges[0].from,this.reusePlaceholders):e}finishLeaf(e){for(let t of e.parsers)if(t.finish(this,e))return;let t=Nb(this.parser.parseInline(e.content,e.start),e.marks);this.addNode(this.buffer.writeElements(t,-e.start).finish(Q.Paragraph,e.content.length),e.start)}elt(e,t,n,r){return typeof e==`string`?$(this.parser.getNodeType(e),t,n,r):new bb(e,t)}get buffer(){return new vb(this.parser.nodeSet)}};function db(e,t,n,r,i){let a=e[t].to,o=[],s=[],c=n.from+r;function l(n,i){for(;i?n>=a:n>a;){let i=e[t+1].from-a;r+=i,n+=i,t++,a=e[t].to}}for(let u=n.firstChild;u;u=u.nextSibling){l(u.from+r,!0);let n=u.from+r,d,f=i.get(u.tree);f?d=f:u.to+r>a?(d=db(e,t,u,r,i),l(u.to+r,!1)):d=u.toTree(),o.push(d),s.push(n-c)}return l(n.to+r,!1),new J(n.type,o,s,n.to+r-c,n.tree?n.tree.propValues:void 0)}var fb=class e extends Rh{constructor(e,t,n,r,i,a,o,s,c){super(),this.nodeSet=e,this.blockParsers=t,this.leafBlockParsers=n,this.blockNames=r,this.endLeafBlock=i,this.skipContextMarkup=a,this.inlineParsers=o,this.inlineNames=s,this.wrappers=c,this.nodeTypes=Object.create(null);for(let t of e.types)this.nodeTypes[t.name]=t.id}createParse(e,t,n){let r=new ub(this,e,t,n);for(let i of this.wrappers)r=i(r,e,t,n);return r}configure(t){let n=mb(t);if(!n)return this;let{nodeSet:r,skipContextMarkup:i}=this,a=this.blockParsers.slice(),o=this.leafBlockParsers.slice(),s=this.blockNames.slice(),c=this.inlineParsers.slice(),l=this.inlineNames.slice(),u=this.endLeafBlock.slice(),d=this.wrappers;if(pb(n.defineNodes)){i=Object.assign({},i);let e=r.types.slice(),t;for(let r of n.defineNodes){let{name:n,block:a,composite:o,style:s}=typeof r==`string`?{name:r}:r;if(e.some(e=>e.name==n))continue;o&&(i[e.length]=(e,t,n)=>o(t,n,e.value));let c=e.length,l=o?[`Block`,`BlockContext`]:a?c>=Q.ATXHeading1&&c<=Q.SetextHeading2?[`Block`,`LeafBlock`,`Heading`]:[`Block`,`LeafBlock`]:void 0;e.push(mh.define({id:c,name:n,props:l&&[[K.group,l]]})),s&&(t||={},Array.isArray(s)||s instanceof Vh?t[n]=s:Object.assign(t,s))}r=new hh(e),t&&(r=r.extend(Kh(t)))}if(pb(n.props)&&(r=r.extend(...n.props)),pb(n.remove))for(let e of n.remove){let t=this.blockNames.indexOf(e),n=this.inlineNames.indexOf(e);t>-1&&(a[t]=o[t]=void 0),n>-1&&(c[n]=void 0)}if(pb(n.parseBlock))for(let e of n.parseBlock){let t=s.indexOf(e.name);if(t>-1)a[t]=e.parse,o[t]=e.leaf;else{let t=e.before?hb(s,e.before):e.after?hb(s,e.after)+1:s.length-1;a.splice(t,0,e.parse),o.splice(t,0,e.leaf),s.splice(t,0,e.name)}e.endLeaf&&u.push(e.endLeaf)}if(pb(n.parseInline))for(let e of n.parseInline){let t=l.indexOf(e.name);if(t>-1)c[t]=e.parse;else{let t=e.before?hb(l,e.before):e.after?hb(l,e.after)+1:l.length-1;c.splice(t,0,e.parse),l.splice(t,0,e.name)}}return n.wrap&&(d=d.concat(n.wrap)),new e(r,a,o,s,u,i,c,l,d)}getNodeType(e){let t=this.nodeTypes[e];if(t==null)throw RangeError(`Unknown node type '${e}'`);return t}parseInline(e,t){let n=new Mb(this,e,t);outer:for(let e=t;e<n.end;){let t=n.char(e);for(let r of this.inlineParsers)if(r){let i=r(n,t,e);if(i>=0){e=i;continue outer}}e++}return n.resolveMarkers(0)}};function pb(e){return e!=null&&e.length>0}function mb(e){if(!Array.isArray(e))return e;if(e.length==0)return null;let t=mb(e[0]);if(e.length==1)return t;let n=mb(e.slice(1));if(!n||!t)return t||n;let r=(e,t)=>(e||_b).concat(t||_b),i=t.wrap,a=n.wrap;return{props:r(t.props,n.props),defineNodes:r(t.defineNodes,n.defineNodes),parseBlock:r(t.parseBlock,n.parseBlock),parseInline:r(t.parseInline,n.parseInline),remove:r(t.remove,n.remove),wrap:i?a?(e,t,n,r)=>i(a(e,t,n,r),t,n,r):i:a}}function hb(e,t){let n=e.indexOf(t);if(n<0)throw RangeError(`Position specified relative to unknown parser ${t}`);return n}let gb=[mh.none];for(let e=1,t;t=Q[e];e++)gb[e]=mh.define({id:e,name:t,props:e>=Q.Escape?[]:[[K.group,e in Ry?[`Block`,`BlockContext`]:[`Block`,`LeafBlock`]]],top:t==`Document`});let _b=[];var vb=class{constructor(e){this.nodeSet=e,this.content=[],this.nodes=[]}write(e,t,n,r=0){return this.content.push(e,t,n,4+r*4),this}writeElements(e,t=0){for(let n of e)n.writeTo(this,t);return this}finish(e,t){return J.build({buffer:this.content,nodeSet:this.nodeSet,reused:this.nodes,topID:e,length:t})}},yb=class{constructor(e,t,n,r=_b){this.type=e,this.from=t,this.to=n,this.children=r}writeTo(e,t){let n=e.content.length;e.writeElements(this.children,t),e.content.push(this.type,this.from+t,this.to+t,e.content.length+4-n)}toTree(e){return new vb(e).writeElements(this.children,-this.from).finish(this.type,this.to-this.from)}},bb=class{constructor(e,t){this.tree=e,this.from=t}get to(){return this.from+this.tree.length}get type(){return this.tree.type.id}get children(){return _b}writeTo(e,t){e.nodes.push(this.tree),e.content.push(e.nodes.length-1,this.from+t,this.to+t,-1)}toTree(){return this.tree}};function $(e,t,n,r){return new yb(e,t,n,r)}let xb={resolve:`Emphasis`,mark:`EmphasisMark`},Sb={resolve:`Emphasis`,mark:`EmphasisMark`},Cb={},wb={};var Tb=class{constructor(e,t,n,r){this.type=e,this.from=t,this.to=n,this.side=r}};let Eb=/[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~\xA1\u2010-\u2027]/;try{Eb=RegExp(`[\\p{S}|\\p{P}]`,`u`)}catch{}let Db={Escape(e,t,n){if(t!=92||n==e.end-1)return-1;let r=e.char(n+1);for(let t=0;t<32;t++)if(`!"#$%&'()*+,-./:;<=>?@[\\]^_\`{|}~`.charCodeAt(t)==r)return e.append($(Q.Escape,n,n+2));return-1},Entity(e,t,n){if(t!=38)return-1;let r=/^(?:#\d+|#x[a-f\d]+|\w+);/i.exec(e.slice(n+1,n+31));return r?e.append($(Q.Entity,n,n+1+r[0].length)):-1},InlineCode(e,t,n){if(t!=96||n&&e.char(n-1)==96)return-1;let r=n+1;for(;r<e.end&&e.char(r)==96;)r++;let i=r-n,a=0;for(;r<e.end;r++)if(e.char(r)==96){if(a++,a==i&&e.char(r+1)!=96)return e.append($(Q.InlineCode,n,r+1,[$(Q.CodeMark,n,n+i),$(Q.CodeMark,r+1-i,r+1)]))}else a=0;return-1},HTMLTag(e,t,n){if(t!=60||n==e.end-1)return-1;let r=e.slice(n+1,e.end),i=/^(?:[a-z][-\w+.]+:[^\s>]+|[a-z\d.!#$%&'*+/=?^_`{|}~-]+@[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?(?:\.[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?)*)>/i.exec(r);if(i)return e.append($(Q.Autolink,n,n+1+i[0].length,[$(Q.LinkMark,n,n+1),$(Q.URL,n+1,n+i[0].length),$(Q.LinkMark,n+i[0].length,n+1+i[0].length)]));let a=/^!--[^>](?:-[^-]|[^-])*?-->/i.exec(r);if(a)return e.append($(Q.Comment,n,n+1+a[0].length));let o=/^\?[^]*?\?>/.exec(r);if(o)return e.append($(Q.ProcessingInstruction,n,n+1+o[0].length));let s=/^(?:![A-Z][^]*?>|!\[CDATA\[[^]*?\]\]>|\/\s*[a-zA-Z][\w-]*\s*>|\s*[a-zA-Z][\w-]*(\s+[a-zA-Z:_][\w-.:]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*(\/\s*)?>)/.exec(r);return s?e.append($(Q.HTMLTag,n,n+1+s[0].length)):-1},Emphasis(e,t,n){if(t!=95&&t!=42)return-1;let r=n+1;for(;e.char(r)==t;)r++;let i=e.slice(n-1,n),a=e.slice(r,r+1),o=Eb.test(i),s=Eb.test(a),c=/\s|^$/.test(i),l=/\s|^$/.test(a),u=!l&&(!s||c||o),d=!c&&(!o||l||s),f=u&&(t==42||!d||o),p=d&&(t==42||!u||s);return e.append(new Tb(t==95?xb:Sb,n,r,!!f|(p?2:0)))},HardBreak(e,t,n){if(t==92&&e.char(n+1)==10)return e.append($(Q.HardBreak,n,n+2));if(t==32){let t=n+1;for(;e.char(t)==32;)t++;if(e.char(t)==10&&t>=n+2)return e.append($(Q.HardBreak,n,t+1))}return-1},Link(e,t,n){return t==91?e.append(new Tb(Cb,n,n+1,1)):-1},Image(e,t,n){return t==33&&e.char(n+1)==91?e.append(new Tb(wb,n,n+2,1)):-1},LinkEnd(e,t,n){if(t!=93)return-1;for(let t=e.parts.length-1;t>=0;t--){let r=e.parts[t];if(r instanceof Tb&&(r.type==Cb||r.type==wb)){if(!r.side||e.skipSpace(r.to)==n&&!/[(\[]/.test(e.slice(n+1,n+2)))return e.parts[t]=null,-1;let i=e.takeContent(t),a=e.parts[t]=Ob(e,i,r.type==Cb?Q.Link:Q.Image,r.from,n+1);if(r.type==Cb)for(let n=0;n<t;n++){let t=e.parts[n];t instanceof Tb&&t.type==Cb&&(t.side=0)}return a.to}}return-1}};function Ob(e,t,n,r,i){let{text:a}=e,o=e.char(i),s=i;if(t.unshift($(Q.LinkMark,r,r+(n==Q.Image?2:1))),t.push($(Q.LinkMark,i-1,i)),o==40){let n=e.skipSpace(i+1),r=kb(a,n-e.offset,e.offset),o;r&&(n=e.skipSpace(r.to),n!=r.to&&(o=Ab(a,n-e.offset,e.offset),o&&(n=e.skipSpace(o.to)))),e.char(n)==41&&(t.push($(Q.LinkMark,i,i+1)),s=n+1,r&&t.push(r),o&&t.push(o),t.push($(Q.LinkMark,n,s)))}else if(o==91){let n=jb(a,i-e.offset,e.offset,!1);n&&(t.push(n),s=n.to)}return $(n,r,s,t)}function kb(e,t,n){if(e.charCodeAt(t)==60){for(let r=t+1;r<e.length;r++){let i=e.charCodeAt(r);if(i==62)return $(Q.URL,t+n,r+1+n);if(i==60||i==10)return!1}return null}{let r=0,i=t;for(let t=!1;i<e.length;i++){let n=e.charCodeAt(i);if(zy(n))break;if(t)t=!1;else if(n==40)r++;else if(n==41){if(!r)break;r--}else n==92&&(t=!0)}return i>t?$(Q.URL,t+n,i+n):i==e.length&&null}}function Ab(e,t,n){let r=e.charCodeAt(t);if(r!=39&&r!=34&&r!=40)return!1;let i=r==40?41:r;for(let r=t+1,a=!1;r<e.length;r++){let o=e.charCodeAt(r);if(a)a=!1;else if(o==i)return $(Q.LinkTitle,t+n,r+1+n);else o==92&&(a=!0)}return null}function jb(e,t,n,r){for(let i=!1,a=t+1,o=Math.min(e.length,a+999);a<o;a++){let o=e.charCodeAt(a);if(i)i=!1;else if(o==93)return!r&&$(Q.LinkLabel,t+n,a+1+n);else{if(r&&!zy(o)&&(r=!1),o==91)return!1;o==92&&(i=!0)}}return null}var Mb=class{constructor(e,t,n){this.parser=e,this.text=t,this.offset=n,this.parts=[]}char(e){return e>=this.end?-1:this.text.charCodeAt(e-this.offset)}get end(){return this.offset+this.text.length}slice(e,t){return this.text.slice(e-this.offset,t-this.offset)}append(e){return this.parts.push(e),e.to}addDelimiter(e,t,n,r,i){return this.append(new Tb(e,t,n,!!r|(i?2:0)))}get hasOpenLink(){for(let e=this.parts.length-1;e>=0;e--){let t=this.parts[e];if(t instanceof Tb&&(t.type==Cb||t.type==wb))return!0}return!1}addElement(e){return this.append(e)}resolveMarkers(e){for(let t=e;t<this.parts.length;t++){let n=this.parts[t];if(!(n instanceof Tb&&n.type.resolve&&n.side&2))continue;let r=n.type==xb||n.type==Sb,i=n.to-n.from,a,o=t-1;for(;o>=e;o--){let e=this.parts[o];if(e instanceof Tb&&e.side&1&&e.type==n.type&&!(r&&(n.side&1||e.side&2)&&(e.to-e.from+i)%3==0&&((e.to-e.from)%3||i%3))){a=e;break}}if(!a)continue;let s=n.type.resolve,c=[],l=a.from,u=n.to;if(r){let e=Math.min(2,a.to-a.from,i);l=a.to-e,u=n.from+e,s=e==1?`Emphasis`:`StrongEmphasis`}a.type.mark&&c.push(this.elt(a.type.mark,l,a.to));for(let e=o+1;e<t;e++)this.parts[e]instanceof yb&&c.push(this.parts[e]),this.parts[e]=null;n.type.mark&&c.push(this.elt(n.type.mark,n.from,u));let d=this.elt(s,l,u,c);this.parts[o]=r&&a.from!=l?new Tb(a.type,a.from,l,a.side):null,(this.parts[t]=r&&n.to!=u?new Tb(n.type,u,n.to,n.side):null)?this.parts.splice(t,0,d):this.parts[t]=d}let t=[];for(let n=e;n<this.parts.length;n++){let e=this.parts[n];e instanceof yb&&t.push(e)}return t}findOpeningDelimiter(e){for(let t=this.parts.length-1;t>=0;t--){let n=this.parts[t];if(n instanceof Tb&&n.type==e&&n.side&1)return t}return null}takeContent(e){let t=this.resolveMarkers(e);return this.parts.length=e,t}getDelimiterAt(e){let t=this.parts[e];return t instanceof Tb?t:null}skipSpace(e){return By(this.text,e-this.offset)+this.offset}elt(e,t,n,r){return typeof e==`string`?$(this.parser.getNodeType(e),t,n,r):new bb(e,t)}};Mb.linkStart=Cb,Mb.imageStart=wb;function Nb(e,t){if(!t.length)return e;if(!e.length)return t;let n=e.slice(),r=0;for(let e of t){for(;r<n.length&&n[r].to<e.to;)r++;if(r<n.length&&n[r].from<e.from){let t=n[r];t instanceof yb&&(n[r]=new yb(t.type,t.from,t.to,Nb(t.children,[e])))}else n.splice(r++,0,e)}return n}let Pb=[Q.CodeBlock,Q.ListItem,Q.OrderedList,Q.BulletList];var Fb=class{constructor(e,t){this.fragments=e,this.input=t,this.i=0,this.fragment=null,this.fragmentEnd=-1,this.cursor=null,e.length&&(this.fragment=e[this.i++])}nextFragment(){this.fragment=this.i<this.fragments.length?this.fragments[this.i++]:null,this.cursor=null,this.fragmentEnd=-1}moveTo(e,t){for(;this.fragment&&this.fragment.to<=e;)this.nextFragment();if(!this.fragment||this.fragment.from>(e?e-1:0))return!1;if(this.fragmentEnd<0){let e=this.fragment.to;for(;e>0&&this.input.read(e-1,e)!=`
64
- `;)e--;this.fragmentEnd=e?e-1:0}let n=this.cursor;n||(n=this.cursor=this.fragment.tree.cursor(),n.firstChild());let r=e+this.fragment.offset;for(;n.to<=r;)if(!n.parent())return!1;for(;;){if(n.from>=r)return this.fragment.from<=t;if(!n.childAfter(r))return!1}}matches(e){let t=this.cursor.tree;return t&&t.prop(K.contextHash)==e}takeNodes(e){let t=this.cursor,n=this.fragment.offset,r=this.fragmentEnd-+!!this.fragment.openEnd,i=e.absoluteLineStart,a=i,o=e.block.children.length,s=a,c=o;for(;;){if(t.to-n>r){if(t.type.isAnonymous&&t.firstChild())continue;break}let i=Ib(t.from-n,e.ranges);if(t.to-n<=e.ranges[e.rangeI].to)e.addNode(t.tree,i);else{let n=new J(e.parser.nodeSet.types[Q.Paragraph],[],[],0,e.block.hashProp);e.reusePlaceholders.set(n,t.tree),e.addNode(n,i)}if(t.type.is(`Block`)&&(Pb.indexOf(t.type.id)<0?(a=t.to-n,o=e.block.children.length):(a=s,o=c),s=t.to-n,c=e.block.children.length),!t.nextSibling())break}for(;e.block.children.length>o;)e.block.children.pop(),e.block.positions.pop();return a-i}};function Ib(e,t){let n=e;for(let r=1;r<t.length;r++){let i=t[r-1].to,a=t[r].from;i<e&&(n-=a-i)}return n}let Lb=Kh({"Blockquote/...":X.quote,HorizontalRule:X.contentSeparator,"ATXHeading1/... SetextHeading1/...":X.heading1,"ATXHeading2/... SetextHeading2/...":X.heading2,"ATXHeading3/...":X.heading3,"ATXHeading4/...":X.heading4,"ATXHeading5/...":X.heading5,"ATXHeading6/...":X.heading6,"Comment CommentBlock":X.comment,Escape:X.escape,Entity:X.character,"Emphasis/...":X.emphasis,"StrongEmphasis/...":X.strong,"Link/... Image/...":X.link,"OrderedList/... BulletList/...":X.list,"BlockQuote/...":X.quote,"InlineCode CodeText":X.monospace,"URL Autolink":X.url,"HeaderMark HardBreak QuoteMark ListMark LinkMark EmphasisMark CodeMark":X.processingInstruction,"CodeInfo LinkLabel":X.labelName,LinkTitle:X.string,Paragraph:X.content}),Rb=new fb(new hh(gb).extend(Lb),Object.keys(rb).map(e=>rb[e]),Object.keys(rb).map(e=>sb[e]),Object.keys(rb),cb,Ry,Object.keys(Db).map(e=>Db[e]),Object.keys(Db),[]),zb={resolve:`Strikethrough`,mark:`StrikethroughMark`},Bb={defineNodes:[{name:`Strikethrough`,style:{"Strikethrough/...":X.strikethrough}},{name:`StrikethroughMark`,style:X.processingInstruction}],parseInline:[{name:`Strikethrough`,parse(e,t,n){if(t!=126||e.char(n+1)!=126||e.char(n+2)==126)return-1;let r=e.slice(n-1,n),i=e.slice(n+2,n+3),a=/\s|^$/.test(r),o=/\s|^$/.test(i),s=Eb.test(r),c=Eb.test(i);return e.addDelimiter(zb,n,n+2,!o&&(!c||a||s),!a&&(!s||o||c))},after:`Emphasis`}]};function Vb(e,t,n=0,r,i=0){let a=0,o=!0,s=-1,c=-1,l=!1,u=()=>{r.push(e.elt(`TableCell`,i+s,i+c,e.parser.parseInline(t.slice(s,c),i+s)))};for(let d=n;d<t.length;d++){let n=t.charCodeAt(d);n==124&&!l?((!o||s>-1)&&a++,o=!1,r&&(s>-1&&u(),r.push(e.elt(`TableDelimiter`,d+i,d+i+1))),s=c=-1):(l||n!=32&&n!=9)&&(s<0&&(s=d),c=d+1),l=!l&&n==92}return s>-1&&(a++,r&&u()),a}function Hb(e,t){for(let n=t;n<e.length;n++){let t=e.charCodeAt(n);if(t==124)return!0;t==92&&n++}return!1}let Ub=/^[>\s]*\|?(\s*:?-+:?\s*\|)+(\s*:?-+:?\s*)?$/;var Wb=class{constructor(){this.rows=null}nextLine(e,t,n){if(this.rows==null){this.rows=!1;let r;if((t.next==45||t.next==58||t.next==124)&&Ub.test(r=t.text.slice(t.pos))){let i=[];Vb(e,n.content,0,i,n.start)==Vb(e,r,0)&&(this.rows=[e.elt(`TableHeader`,n.start,n.start+n.content.length,i),e.elt(`TableDelimiter`,e.lineStart+t.pos,e.lineStart+t.text.length)])}}else if(this.rows){let n=[];Vb(e,t.text,t.pos,n,e.lineStart),this.rows.push(e.elt(`TableRow`,e.lineStart+t.pos,e.lineStart+t.text.length,n))}return!1}finish(e,t){return this.rows?(e.addLeafElement(t,e.elt(`Table`,t.start,t.start+t.content.length,this.rows)),!0):!1}};let Gb={defineNodes:[{name:`Table`,block:!0},{name:`TableHeader`,style:{"TableHeader/...":X.heading}},`TableRow`,{name:`TableCell`,style:X.content},{name:`TableDelimiter`,style:X.processingInstruction}],parseBlock:[{name:`Table`,leaf(e,t){return Hb(t.content,0)?new Wb:null},endLeaf(e,t,n){if(n.parsers.some(e=>e instanceof Wb)||!Hb(t.text,t.basePos))return!1;let r=e.peekLine();return Ub.test(r)&&Vb(e,t.text,t.basePos)==Vb(e,r,t.basePos)},before:`SetextHeading`}]};var Kb=class{nextLine(){return!1}finish(e,t){return e.addLeafElement(t,e.elt(`Task`,t.start,t.start+t.content.length,[e.elt(`TaskMarker`,t.start,t.start+3),...e.parser.parseInline(t.content.slice(3),t.start+3)])),!0}};let qb={defineNodes:[{name:`Task`,block:!0,style:X.list},{name:`TaskMarker`,style:X.atom}],parseBlock:[{name:`TaskList`,leaf(e,t){return/^\[[ xX]\][ \t]/.test(t.content)&&e.parentType().name==`ListItem`?new Kb:null},after:`SetextHeading`}]},Jb=/(www\.)|(https?:\/\/)|([\w.+-]{1,100}@)|(mailto:|xmpp:)/gy,Yb=/[\w-]+(\.[\w-]+)+(:\d+)?(\/[^\s<]*)?/gy,Xb=/[\w-]+\.[\w-]+($|[/:])/,Zb=/[\w.+-]+@[\w-]+(\.[\w.-]+)+/gy,Qb=/\/[a-zA-Z\d@.]+/gy;function $b(e,t,n,r){let i=0;for(let a=t;a<n;a++)e[a]==r&&i++;return i}function ex(e,t){Yb.lastIndex=t;let n=Yb.exec(e);if(!n||Xb.exec(n[0])[0].indexOf(`_`)>-1)return-1;let r=t+n[0].length;for(;;){let n=e[r-1],i;if(/[?!.,:*_~]/.test(n)||n==`)`&&$b(e,t,r,`)`)>$b(e,t,r,`(`))r--;else if(n==`;`&&(i=/&(?:#\d+|#x[a-f\d]+|\w+);$/.exec(e.slice(t,r))))r=t+i.index;else break}return r}function tx(e,t){Zb.lastIndex=t;let n=Zb.exec(e);if(!n)return-1;let r=n[0][n[0].length-1];return r==`_`||r==`-`?-1:t+n[0].length-+(r==`.`)}let nx=[Gb,qb,Bb,{parseInline:[{name:`Autolink`,parse(e,t,n){let r=n-e.offset;if(r&&/\w/.test(e.text[r-1]))return-1;Jb.lastIndex=r;let i=Jb.exec(e.text),a=-1;return!i||(i[1]||i[2]?(a=ex(e.text,r+i[0].length),a>-1&&e.hasOpenLink&&(a=r+/([^\[\]]|\[[^\]]*\])*/.exec(e.text.slice(r,a))[0].length)):i[3]?a=tx(e.text,r):(a=tx(e.text,r+i[0].length),a>-1&&i[0]==`xmpp:`&&(Qb.lastIndex=a,i=Qb.exec(e.text),i&&(a=i.index+i[0].length))),a<0)?-1:(e.addElement(e.elt(`URL`,n,a+e.offset)),a+e.offset)}}]}];function rx(e,t,n){return(r,i,a)=>{if(i!=e||r.char(a+1)==e)return-1;let o=[r.elt(n,a,a+1)];for(let i=a+1;i<r.end;i++){let s=r.char(i);if(s==e)return r.addElement(r.elt(t,a,i+1,o.concat(r.elt(n,i,i+1))));if(s==92&&o.push(r.elt(`Escape`,i,i+++2)),zy(s))break}return-1}}let ix={defineNodes:[{name:`Superscript`,style:X.special(X.content)},{name:`SuperscriptMark`,style:X.processingInstruction}],parseInline:[{name:`Superscript`,parse:rx(94,`Superscript`,`SuperscriptMark`)}]},ax={defineNodes:[{name:`Subscript`,style:X.special(X.content)},{name:`SubscriptMark`,style:X.processingInstruction}],parseInline:[{name:`Subscript`,parse:rx(126,`Subscript`,`SubscriptMark`)}]},ox={defineNodes:[{name:`Emoji`,style:X.character}],parseInline:[{name:`Emoji`,parse(e,t,n){let r;return t!=58||!(r=/^[a-zA-Z_0-9]+:/.exec(e.slice(n+1,e.end)))?-1:e.addElement(e.elt(`Emoji`,n,n+1+r[0].length))}}]},sx=yg.define({parser:Rb.configure([nx,ax,ix,ox])});function cx({initialValue:e,onChange:t,onSave:n}){let r=(0,a.useRef)(null),o=(0,a.useRef)(t);o.current=t;let s=(0,a.useRef)(n);return s.current=n,(0,a.useEffect)(()=>{let t=r.current,n=new G({state:F.create({doc:e,extensions:[ch(),O_(),Nm(),Bm(),Xg($g,{fallback:!0}),G.lineWrapping,sx,_m.of([{key:`Mod-s`,run:()=>(s.current(),!0)},...Ny,...K_]),G.updateListener.of(e=>{e.docChanged&&o.current(e.state.doc.toString())}),G.theme({"&":{height:`100%`},".cm-scroller":{fontFamily:`inherit`}})]}),...t===null?{}:{parent:t}});return()=>{n.destroy()}},[e]),(0,i.jsx)(`div`,{className:`dsh-md-preview-editor`,ref:r})}function lx(e){return{code:{copyLabel:e(`copy`),copiedLabel:e(`copied`)},footnotes:e(`footnotes`)}}function ux({usePreviewTarget:e,close:t,read:n,write:r,t:s}){let c=e(e=>e),[l,u]=(0,a.useState)({state:`loading`}),[d,f]=(0,a.useState)(440),[p,m]=(0,a.useState)(0),h=(0,a.useMemo)(()=>lx(s),[s]),[g,_]=(0,a.useState)(`view`),[v,ee]=(0,a.useState)(``),[te,ne]=(0,a.useState)(!1),[re,y]=(0,a.useState)(!1),[b,x]=(0,a.useState)(!1),[ie,ae]=(0,a.useState)(!1),[oe,se]=(0,a.useState)(null),ce=(0,a.useRef)(null),le=(0,a.useRef)(null);(0,a.useEffect)(()=>()=>{le.current!==null&&window.clearTimeout(le.current)},[]),(0,a.useEffect)(()=>{if(c===null)return;u({state:`loading`}),_(`view`),ne(!1),y(!1);let e=new AbortController;return n(c.sessionId,c.path,e.signal).then(t=>{e.signal.aborted||u(t.ok?{state:`ready`,file:t.value}:{state:`failed`,code:t.error.code,message:t.error.message})}),()=>{e.abort()}},[n,c,p]),(0,a.useEffect)(()=>{ce.current?.abort(),ce.current=null},[c]);let ue=(0,a.useRef)(!1);(0,a.useEffect)(()=>{c===null?ue.current=!1:ue.current||=!0},[c]);let de=(0,a.useCallback)(e=>{f(t=>Math.min(960,Math.max(320,t-e)))},[]),fe=g===`edit`&&l.state===`ready`&&v!==l.file.content,pe=(0,a.useCallback)(()=>{ae(!0),le.current!==null&&window.clearTimeout(le.current),le.current=window.setTimeout(()=>{ae(!1)},2e3)},[]),me=(0,a.useCallback)(e=>{if(c===null||l.state!==`ready`||b)return;let t=l.file,n=new AbortController;ce.current=n,x(!0),se(null),r(c.sessionId,c.path,v,e?void 0:t.fingerprint,e,n.signal).then(e=>{n.signal.aborted||(e.ok?(_(`view`),ne(!1),y(!1),pe(),m(e=>e+1)):e.error.code===`md-preview/conflict`?ne(!0):se({code:e.error.code,message:e.error.message}))}).finally(()=>{n.signal.aborted||x(!1)})},[l,v,pe,b,c,r]),he=(0,a.useCallback)(()=>{fe?y(!0):t()},[t,fe]);return c===null?null:(0,i.jsx)(`div`,{className:`dsh-md-preview-dock`,children:(0,i.jsxs)(`div`,{className:`dsh-md-preview-panel`,style:{width:`${d}px`},children:[(0,i.jsxs)(`div`,{className:`dsh-md-preview-header`,children:[(0,i.jsx)(`span`,{className:`dsh-md-preview-icon`,"aria-hidden":!0,children:`📄`}),(0,i.jsx)(`div`,{className:`dsh-md-preview-title`,title:c.path,children:ss(c.path)}),g===`view`&&l.state===`ready`&&(0,i.jsx)(`button`,{type:`button`,className:`dsh-md-preview-icon`,"aria-label":s(`panel.edit`),title:s(`panel.edit`),onClick:()=>{ee(l.file.content),ne(!1),se(null),y(!1),_(`edit`)},children:(0,i.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`14`,height:`14`,"aria-hidden":!0,children:(0,i.jsx)(`path`,{d:`M11.5 2.5l2 2L6 12l-3 1 1-3zM10 4l2 2`,stroke:`currentColor`,strokeWidth:`1.3`,fill:`none`,strokeLinecap:`round`,strokeLinejoin:`round`})})}),g===`edit`&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`button`,{type:`button`,className:`dsh-md-preview-icon`,"aria-label":s(`panel.save`),title:s(`panel.save`),disabled:b||!fe&&!te,onClick:()=>{me(!1)},children:(0,i.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`14`,height:`14`,"aria-hidden":!0,children:(0,i.jsx)(`path`,{d:`M2 2h9l3 3v9H2zM5 2v4h6V2M4 14V9h8v5`,stroke:`currentColor`,strokeWidth:`1.3`,fill:`none`,strokeLinejoin:`round`})})}),(0,i.jsx)(`button`,{type:`button`,className:`dsh-md-preview-icon`,"aria-label":s(`panel.cancel`),title:s(`panel.cancel`),onClick:()=>{_(`view`),ne(!1),se(null),y(!1)},children:(0,i.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`14`,height:`14`,"aria-hidden":!0,children:(0,i.jsx)(`path`,{d:`M3 3l10 10M13 3L3 13`,stroke:`currentColor`,strokeWidth:`1.3`,strokeLinecap:`round`})})})]}),(0,i.jsx)(`button`,{type:`button`,className:`dsh-md-preview-icon`,"aria-label":s(`panel.close`),onClick:he,children:(0,i.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`14`,height:`14`,"aria-hidden":!0,children:(0,i.jsx)(`path`,{d:`M4 4l8 8M12 4l-8 8`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`})})})]}),(0,i.jsxs)(`div`,{className:`dsh-md-preview-body`,children:[ie&&g===`view`&&(0,i.jsxs)(`div`,{className:`dsh-md-preview-toast`,role:`status`,children:[`✓ `,s(`panel.saved`)]}),re&&(0,i.jsxs)(`div`,{className:`dsh-md-preview-bar`,role:`alert`,children:[(0,i.jsx)(`span`,{children:s(`panel.unsaved.title`)}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>{t()},children:s(`panel.unsaved.discard`)}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>{y(!1)},children:s(`panel.unsaved.keep`)})]}),oe!==null&&g===`edit`&&(0,i.jsxs)(`div`,{className:`dsh-md-preview-bar`,role:`alert`,children:[(0,i.jsxs)(`span`,{children:[s(`panel.saveError`),` · `,oe.code,oe.message.length>0?` — ${oe.message}`:``]}),(0,i.jsx)(`button`,{type:`button`,disabled:b,onClick:()=>{me(!1)},children:s(`panel.save.retry`)})]}),te&&g===`edit`&&(0,i.jsxs)(`div`,{className:`dsh-md-preview-bar`,role:`alert`,children:[(0,i.jsx)(`span`,{children:s(`panel.conflict.title`)}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>{_(`view`),ne(!1),m(e=>e+1)},children:s(`panel.conflict.reload`)}),(0,i.jsx)(`button`,{type:`button`,disabled:b,onClick:()=>{me(!0)},children:s(`panel.conflict.force`)})]}),g===`edit`?(0,i.jsx)(cx,{initialValue:l.state===`ready`?l.file.content:``,onChange:ee,onSave:()=>{me(!1)}}):(0,i.jsxs)(i.Fragment,{children:[l.state===`loading`&&(0,i.jsx)(`div`,{className:`dsh-md-preview-state`,children:s(`panel.loading`)}),l.state===`failed`&&(0,i.jsxs)(`div`,{className:`dsh-md-preview-state`,children:[(0,i.jsxs)(`div`,{className:`dsh-md-preview-error`,children:[s(`panel.error`),` · `,l.code]}),(0,i.jsx)(`div`,{children:l.message}),(0,i.jsx)(`button`,{type:`button`,className:`dsh-md-preview-retry`,onClick:()=>{m(e=>e+1)},children:s(`panel.retry`)})]}),l.state===`ready`&&(0,i.jsx)(o.MarkdownText,{text:l.file.content,labels:h})]})]}),(0,i.jsx)(dx,{onResize:de})]})})}function dx(e){let[t,n]=(0,a.useState)(!1),r=(0,a.useRef)(!1),o=(0,a.useRef)(0),s=(0,a.useRef)(0),c=(0,a.useRef)(null),l=(0,a.useRef)(e.onResize);l.current=e.onResize;let u=(0,a.useCallback)(e=>{e.preventDefault();try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}r.current=!0,o.current=e.clientX,s.current=e.clientX,n(!0)},[]),d=(0,a.useCallback)(e=>{r.current&&(s.current=e.clientX,c.current??=requestAnimationFrame(()=>{c.current=null,l.current(s.current-o.current),o.current=s.current}))},[]),f=(0,a.useCallback)(e=>{r.current&&(e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId),c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),r.current=!1,n(!1))},[]);return(0,i.jsx)(`div`,{"aria-hidden":!0,className:`dsh-md-preview-handle`,"data-dragging":t||void 0,onPointerDown:u,onPointerMove:d,onPointerUp:f})}let fx=`md-preview`,px={"panel.title":`Markdown 预览`,"panel.close":`关闭预览`,"panel.loading":`正在加载…`,"panel.empty":`没有可预览的文档`,"panel.error":`加载失败`,"panel.retry":`重试`,"panel.edit":`编辑`,"panel.save":`保存`,"panel.cancel":`取消编辑`,"panel.saved":`已保存`,"panel.saveError":`保存失败`,"panel.save.retry":`重试`,"panel.conflict.title":`文件已在别处被修改`,"panel.conflict.reload":`重新加载`,"panel.conflict.force":`强制覆盖`,"panel.unsaved.title":`有未保存的修改`,"panel.unsaved.discard":`放弃修改`,"panel.unsaved.keep":`继续编辑`,"chip.preview":`预览 {name}`,"chip.open":`打开 {name}`,"action.label":`预览文档`,"action.open":`预览 {name}`,copy:`复制`,copied:`已复制`,footnotes:`脚注`},mx={"panel.title":`Markdown preview`,"panel.close":`Close preview`,"panel.loading":`Loading…`,"panel.empty":`No document to preview`,"panel.error":`Failed to load`,"panel.retry":`Retry`,"panel.edit":`Edit`,"panel.save":`Save`,"panel.cancel":`Cancel editing`,"panel.saved":`Saved`,"panel.saveError":`Save failed`,"panel.save.retry":`Retry`,"panel.conflict.title":`The file changed elsewhere`,"panel.conflict.reload":`Reload`,"panel.conflict.force":`Overwrite`,"panel.unsaved.title":`You have unsaved changes`,"panel.unsaved.discard":`Discard changes`,"panel.unsaved.keep":`Keep editing`,"chip.preview":`Preview {name}`,"chip.open":`Open {name}`,"action.label":`Preview documents`,"action.open":`Preview {name}`,copy:`Copy`,copied:`Copied`,footnotes:`Footnotes`};function hx(e,t){let n=e.data.get(`deliverables`);if(n===void 0)return[];let r=[],i=new Set;for(let e of n.produced)e.seq>t||i.has(e.path)||(i.add(e.path),r.push(e.path));return r}function gx(e){let t=hx(e.turn,e.seq);return t.some(us)?ds(t):null}let _x=!1;function vx(){if(_x||typeof document>`u`)return;let e=document.createElement(`style`);e.setAttribute(`data-plugin-css`,`md-preview`),e.textContent=`
64
+ `;)e--;this.fragmentEnd=e?e-1:0}let n=this.cursor;n||(n=this.cursor=this.fragment.tree.cursor(),n.firstChild());let r=e+this.fragment.offset;for(;n.to<=r;)if(!n.parent())return!1;for(;;){if(n.from>=r)return this.fragment.from<=t;if(!n.childAfter(r))return!1}}matches(e){let t=this.cursor.tree;return t&&t.prop(K.contextHash)==e}takeNodes(e){let t=this.cursor,n=this.fragment.offset,r=this.fragmentEnd-+!!this.fragment.openEnd,i=e.absoluteLineStart,a=i,o=e.block.children.length,s=a,c=o;for(;;){if(t.to-n>r){if(t.type.isAnonymous&&t.firstChild())continue;break}let i=Ib(t.from-n,e.ranges);if(t.to-n<=e.ranges[e.rangeI].to)e.addNode(t.tree,i);else{let n=new J(e.parser.nodeSet.types[Q.Paragraph],[],[],0,e.block.hashProp);e.reusePlaceholders.set(n,t.tree),e.addNode(n,i)}if(t.type.is(`Block`)&&(Pb.indexOf(t.type.id)<0?(a=t.to-n,o=e.block.children.length):(a=s,o=c),s=t.to-n,c=e.block.children.length),!t.nextSibling())break}for(;e.block.children.length>o;)e.block.children.pop(),e.block.positions.pop();return a-i}};function Ib(e,t){let n=e;for(let r=1;r<t.length;r++){let i=t[r-1].to,a=t[r].from;i<e&&(n-=a-i)}return n}let Lb=Kh({"Blockquote/...":X.quote,HorizontalRule:X.contentSeparator,"ATXHeading1/... SetextHeading1/...":X.heading1,"ATXHeading2/... SetextHeading2/...":X.heading2,"ATXHeading3/...":X.heading3,"ATXHeading4/...":X.heading4,"ATXHeading5/...":X.heading5,"ATXHeading6/...":X.heading6,"Comment CommentBlock":X.comment,Escape:X.escape,Entity:X.character,"Emphasis/...":X.emphasis,"StrongEmphasis/...":X.strong,"Link/... Image/...":X.link,"OrderedList/... BulletList/...":X.list,"BlockQuote/...":X.quote,"InlineCode CodeText":X.monospace,"URL Autolink":X.url,"HeaderMark HardBreak QuoteMark ListMark LinkMark EmphasisMark CodeMark":X.processingInstruction,"CodeInfo LinkLabel":X.labelName,LinkTitle:X.string,Paragraph:X.content}),Rb=new fb(new hh(gb).extend(Lb),Object.keys(rb).map(e=>rb[e]),Object.keys(rb).map(e=>sb[e]),Object.keys(rb),cb,Ry,Object.keys(Db).map(e=>Db[e]),Object.keys(Db),[]),zb={resolve:`Strikethrough`,mark:`StrikethroughMark`},Bb={defineNodes:[{name:`Strikethrough`,style:{"Strikethrough/...":X.strikethrough}},{name:`StrikethroughMark`,style:X.processingInstruction}],parseInline:[{name:`Strikethrough`,parse(e,t,n){if(t!=126||e.char(n+1)!=126||e.char(n+2)==126)return-1;let r=e.slice(n-1,n),i=e.slice(n+2,n+3),a=/\s|^$/.test(r),o=/\s|^$/.test(i),s=Eb.test(r),c=Eb.test(i);return e.addDelimiter(zb,n,n+2,!o&&(!c||a||s),!a&&(!s||o||c))},after:`Emphasis`}]};function Vb(e,t,n=0,r,i=0){let a=0,o=!0,s=-1,c=-1,l=!1,u=()=>{r.push(e.elt(`TableCell`,i+s,i+c,e.parser.parseInline(t.slice(s,c),i+s)))};for(let d=n;d<t.length;d++){let n=t.charCodeAt(d);n==124&&!l?((!o||s>-1)&&a++,o=!1,r&&(s>-1&&u(),r.push(e.elt(`TableDelimiter`,d+i,d+i+1))),s=c=-1):(l||n!=32&&n!=9)&&(s<0&&(s=d),c=d+1),l=!l&&n==92}return s>-1&&(a++,r&&u()),a}function Hb(e,t){for(let n=t;n<e.length;n++){let t=e.charCodeAt(n);if(t==124)return!0;t==92&&n++}return!1}let Ub=/^[>\s]*\|?(\s*:?-+:?\s*\|)+(\s*:?-+:?\s*)?$/;var Wb=class{constructor(){this.rows=null}nextLine(e,t,n){if(this.rows==null){this.rows=!1;let r;if((t.next==45||t.next==58||t.next==124)&&Ub.test(r=t.text.slice(t.pos))){let i=[];Vb(e,n.content,0,i,n.start)==Vb(e,r,0)&&(this.rows=[e.elt(`TableHeader`,n.start,n.start+n.content.length,i),e.elt(`TableDelimiter`,e.lineStart+t.pos,e.lineStart+t.text.length)])}}else if(this.rows){let n=[];Vb(e,t.text,t.pos,n,e.lineStart),this.rows.push(e.elt(`TableRow`,e.lineStart+t.pos,e.lineStart+t.text.length,n))}return!1}finish(e,t){return this.rows?(e.addLeafElement(t,e.elt(`Table`,t.start,t.start+t.content.length,this.rows)),!0):!1}};let Gb={defineNodes:[{name:`Table`,block:!0},{name:`TableHeader`,style:{"TableHeader/...":X.heading}},`TableRow`,{name:`TableCell`,style:X.content},{name:`TableDelimiter`,style:X.processingInstruction}],parseBlock:[{name:`Table`,leaf(e,t){return Hb(t.content,0)?new Wb:null},endLeaf(e,t,n){if(n.parsers.some(e=>e instanceof Wb)||!Hb(t.text,t.basePos))return!1;let r=e.peekLine();return Ub.test(r)&&Vb(e,t.text,t.basePos)==Vb(e,r,t.basePos)},before:`SetextHeading`}]};var Kb=class{nextLine(){return!1}finish(e,t){return e.addLeafElement(t,e.elt(`Task`,t.start,t.start+t.content.length,[e.elt(`TaskMarker`,t.start,t.start+3),...e.parser.parseInline(t.content.slice(3),t.start+3)])),!0}};let qb={defineNodes:[{name:`Task`,block:!0,style:X.list},{name:`TaskMarker`,style:X.atom}],parseBlock:[{name:`TaskList`,leaf(e,t){return/^\[[ xX]\][ \t]/.test(t.content)&&e.parentType().name==`ListItem`?new Kb:null},after:`SetextHeading`}]},Jb=/(www\.)|(https?:\/\/)|([\w.+-]{1,100}@)|(mailto:|xmpp:)/gy,Yb=/[\w-]+(\.[\w-]+)+(:\d+)?(\/[^\s<]*)?/gy,Xb=/[\w-]+\.[\w-]+($|[/:])/,Zb=/[\w.+-]+@[\w-]+(\.[\w.-]+)+/gy,Qb=/\/[a-zA-Z\d@.]+/gy;function $b(e,t,n,r){let i=0;for(let a=t;a<n;a++)e[a]==r&&i++;return i}function ex(e,t){Yb.lastIndex=t;let n=Yb.exec(e);if(!n||Xb.exec(n[0])[0].indexOf(`_`)>-1)return-1;let r=t+n[0].length;for(;;){let n=e[r-1],i;if(/[?!.,:*_~]/.test(n)||n==`)`&&$b(e,t,r,`)`)>$b(e,t,r,`(`))r--;else if(n==`;`&&(i=/&(?:#\d+|#x[a-f\d]+|\w+);$/.exec(e.slice(t,r))))r=t+i.index;else break}return r}function tx(e,t){Zb.lastIndex=t;let n=Zb.exec(e);if(!n)return-1;let r=n[0][n[0].length-1];return r==`_`||r==`-`?-1:t+n[0].length-+(r==`.`)}let nx=[Gb,qb,Bb,{parseInline:[{name:`Autolink`,parse(e,t,n){let r=n-e.offset;if(r&&/\w/.test(e.text[r-1]))return-1;Jb.lastIndex=r;let i=Jb.exec(e.text),a=-1;return!i||(i[1]||i[2]?(a=ex(e.text,r+i[0].length),a>-1&&e.hasOpenLink&&(a=r+/([^\[\]]|\[[^\]]*\])*/.exec(e.text.slice(r,a))[0].length)):i[3]?a=tx(e.text,r):(a=tx(e.text,r+i[0].length),a>-1&&i[0]==`xmpp:`&&(Qb.lastIndex=a,i=Qb.exec(e.text),i&&(a=i.index+i[0].length))),a<0)?-1:(e.addElement(e.elt(`URL`,n,a+e.offset)),a+e.offset)}}]}];function rx(e,t,n){return(r,i,a)=>{if(i!=e||r.char(a+1)==e)return-1;let o=[r.elt(n,a,a+1)];for(let i=a+1;i<r.end;i++){let s=r.char(i);if(s==e)return r.addElement(r.elt(t,a,i+1,o.concat(r.elt(n,i,i+1))));if(s==92&&o.push(r.elt(`Escape`,i,i+++2)),zy(s))break}return-1}}let ix={defineNodes:[{name:`Superscript`,style:X.special(X.content)},{name:`SuperscriptMark`,style:X.processingInstruction}],parseInline:[{name:`Superscript`,parse:rx(94,`Superscript`,`SuperscriptMark`)}]},ax={defineNodes:[{name:`Subscript`,style:X.special(X.content)},{name:`SubscriptMark`,style:X.processingInstruction}],parseInline:[{name:`Subscript`,parse:rx(126,`Subscript`,`SubscriptMark`)}]},ox={defineNodes:[{name:`Emoji`,style:X.character}],parseInline:[{name:`Emoji`,parse(e,t,n){let r;return t!=58||!(r=/^[a-zA-Z_0-9]+:/.exec(e.slice(n+1,e.end)))?-1:e.addElement(e.elt(`Emoji`,n,n+1+r[0].length))}}]},sx=yg.define({parser:Rb.configure([nx,ax,ix,ox])});function cx({initialValue:e,onChange:t,onSave:n}){let r=(0,a.useRef)(null),o=(0,a.useRef)(t);o.current=t;let s=(0,a.useRef)(n);return s.current=n,(0,a.useEffect)(()=>{let t=r.current,n=new G({state:F.create({doc:e,extensions:[ch(),O_(),Nm(),Bm(),Xg($g,{fallback:!0}),G.lineWrapping,sx,_m.of([{key:`Mod-s`,run:()=>(s.current(),!0)},...Ny,...K_]),G.updateListener.of(e=>{e.docChanged&&o.current(e.state.doc.toString())}),G.theme({"&":{height:`100%`},".cm-scroller":{fontFamily:`inherit`}})]}),...t===null?{}:{parent:t}});return()=>{n.destroy()}},[e]),(0,i.jsx)(`div`,{className:`dsh-md-preview-editor`,ref:r})}function lx(e){return{code:{copyLabel:e(`copy`),copiedLabel:e(`copied`)},footnotes:e(`footnotes`)}}function ux({usePreviewTarget:e,close:t,read:n,write:r,t:s}){let c=e(e=>e),[l,u]=(0,a.useState)({state:`loading`}),[d,f]=(0,a.useState)(440),[p,m]=(0,a.useState)(0),h=(0,a.useMemo)(()=>lx(s),[s]),[g,_]=(0,a.useState)(`view`),[v,ee]=(0,a.useState)(``),[te,ne]=(0,a.useState)(!1),[re,y]=(0,a.useState)(!1),[b,x]=(0,a.useState)(!1),[ie,ae]=(0,a.useState)(!1),[oe,se]=(0,a.useState)(null),ce=(0,a.useRef)(null),le=(0,a.useRef)(null);(0,a.useEffect)(()=>()=>{le.current!==null&&window.clearTimeout(le.current)},[]),(0,a.useEffect)(()=>{if(c===null)return;u({state:`loading`}),_(`view`),ne(!1),y(!1);let e=new AbortController;return n(c.sessionId,c.path,e.signal).then(t=>{e.signal.aborted||u(t.ok?{state:`ready`,file:t.value}:{state:`failed`,code:t.error.code,message:t.error.message})}),()=>{e.abort()}},[n,c,p]),(0,a.useEffect)(()=>{ce.current?.abort(),ce.current=null},[c]);let ue=(0,a.useRef)(!1);(0,a.useEffect)(()=>{c===null?ue.current=!1:ue.current||=!0},[c]);let de=(0,a.useCallback)(e=>{f(t=>Math.min(960,Math.max(320,t-e)))},[]),fe=g===`edit`&&l.state===`ready`&&v!==l.file.content,pe=(0,a.useCallback)(()=>{ae(!0),le.current!==null&&window.clearTimeout(le.current),le.current=window.setTimeout(()=>{ae(!1)},2e3)},[]),me=(0,a.useCallback)(e=>{if(c===null||l.state!==`ready`||b)return;let t=l.file,n=new AbortController;ce.current=n,x(!0),se(null),r(c.sessionId,c.path,v,e?void 0:t.fingerprint,e,n.signal).then(e=>{n.signal.aborted||(e.ok?(_(`view`),ne(!1),y(!1),pe(),m(e=>e+1)):e.error.code===`md-preview/conflict`?ne(!0):se({code:e.error.code,message:e.error.message}))}).finally(()=>{n.signal.aborted||x(!1)})},[l,v,pe,b,c,r]),he=(0,a.useCallback)(()=>{fe?y(!0):t()},[t,fe]);return c===null?null:(0,i.jsx)(`div`,{className:`dsh-md-preview-dock`,children:(0,i.jsxs)(`div`,{className:`dsh-md-preview-panel`,style:{width:`${d}px`},children:[(0,i.jsxs)(`div`,{className:`dsh-md-preview-header`,children:[(0,i.jsx)(`span`,{className:`dsh-md-preview-icon`,"aria-hidden":!0,children:`📄`}),(0,i.jsx)(`div`,{className:`dsh-md-preview-title`,title:c.path,children:ss(c.path)}),(0,i.jsx)(`span`,{className:`dsh-md-preview-version`,"aria-hidden":!0,children:`v0.2.3`}),g===`view`&&l.state===`ready`&&(0,i.jsx)(`button`,{type:`button`,className:`dsh-md-preview-icon`,"aria-label":s(`panel.edit`),title:s(`panel.edit`),onClick:()=>{ee(l.file.content),ne(!1),se(null),y(!1),_(`edit`)},children:(0,i.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`14`,height:`14`,"aria-hidden":!0,children:(0,i.jsx)(`path`,{d:`M11.5 2.5l2 2L6 12l-3 1 1-3zM10 4l2 2`,stroke:`currentColor`,strokeWidth:`1.3`,fill:`none`,strokeLinecap:`round`,strokeLinejoin:`round`})})}),g===`edit`&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`button`,{type:`button`,className:`dsh-md-preview-icon`,"aria-label":s(`panel.save`),title:s(`panel.save`),disabled:b||!fe&&!te,onClick:()=>{me(!1)},children:(0,i.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`14`,height:`14`,"aria-hidden":!0,children:(0,i.jsx)(`path`,{d:`M2 2h9l3 3v9H2zM5 2v4h6V2M4 14V9h8v5`,stroke:`currentColor`,strokeWidth:`1.3`,fill:`none`,strokeLinejoin:`round`})})}),(0,i.jsx)(`button`,{type:`button`,className:`dsh-md-preview-icon`,"aria-label":s(`panel.cancel`),title:s(`panel.cancel`),onClick:()=>{_(`view`),ne(!1),se(null),y(!1)},children:(0,i.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`14`,height:`14`,"aria-hidden":!0,children:(0,i.jsx)(`path`,{d:`M3 3l10 10M13 3L3 13`,stroke:`currentColor`,strokeWidth:`1.3`,strokeLinecap:`round`})})})]}),(0,i.jsx)(`button`,{type:`button`,className:`dsh-md-preview-icon`,"aria-label":s(`panel.close`),onClick:he,children:(0,i.jsx)(`svg`,{viewBox:`0 0 16 16`,width:`14`,height:`14`,"aria-hidden":!0,children:(0,i.jsx)(`path`,{d:`M4 4l8 8M12 4l-8 8`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`})})})]}),(0,i.jsxs)(`div`,{className:`dsh-md-preview-body`,children:[ie&&g===`view`&&(0,i.jsxs)(`div`,{className:`dsh-md-preview-toast`,role:`status`,children:[`✓ `,s(`panel.saved`)]}),re&&(0,i.jsxs)(`div`,{className:`dsh-md-preview-bar`,role:`alert`,children:[(0,i.jsx)(`span`,{children:s(`panel.unsaved.title`)}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>{t()},children:s(`panel.unsaved.discard`)}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>{y(!1)},children:s(`panel.unsaved.keep`)})]}),oe!==null&&g===`edit`&&(0,i.jsxs)(`div`,{className:`dsh-md-preview-bar`,role:`alert`,children:[(0,i.jsxs)(`span`,{children:[s(`panel.saveError`),` · `,oe.code,oe.message.length>0?` — ${oe.message}`:``]}),(0,i.jsx)(`button`,{type:`button`,disabled:b,onClick:()=>{me(!1)},children:s(`panel.save.retry`)})]}),te&&g===`edit`&&(0,i.jsxs)(`div`,{className:`dsh-md-preview-bar`,role:`alert`,children:[(0,i.jsx)(`span`,{children:s(`panel.conflict.title`)}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>{_(`view`),ne(!1),m(e=>e+1)},children:s(`panel.conflict.reload`)}),(0,i.jsx)(`button`,{type:`button`,disabled:b,onClick:()=>{me(!0)},children:s(`panel.conflict.force`)})]}),g===`edit`?(0,i.jsx)(cx,{initialValue:l.state===`ready`?l.file.content:``,onChange:ee,onSave:()=>{me(!1)}}):(0,i.jsxs)(i.Fragment,{children:[l.state===`loading`&&(0,i.jsx)(`div`,{className:`dsh-md-preview-state`,children:s(`panel.loading`)}),l.state===`failed`&&(0,i.jsxs)(`div`,{className:`dsh-md-preview-state`,children:[(0,i.jsxs)(`div`,{className:`dsh-md-preview-error`,children:[s(`panel.error`),` · `,l.code]}),(0,i.jsx)(`div`,{children:l.message}),(0,i.jsx)(`button`,{type:`button`,className:`dsh-md-preview-retry`,onClick:()=>{m(e=>e+1)},children:s(`panel.retry`)})]}),l.state===`ready`&&(0,i.jsx)(o.MarkdownText,{text:l.file.content,labels:h})]})]}),(0,i.jsx)(dx,{onResize:de})]})})}function dx(e){let[t,n]=(0,a.useState)(!1),r=(0,a.useRef)(!1),o=(0,a.useRef)(0),s=(0,a.useRef)(0),c=(0,a.useRef)(null),l=(0,a.useRef)(e.onResize);l.current=e.onResize;let u=(0,a.useCallback)(e=>{e.preventDefault();try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}r.current=!0,o.current=e.clientX,s.current=e.clientX,n(!0)},[]),d=(0,a.useCallback)(e=>{r.current&&(s.current=e.clientX,c.current??=requestAnimationFrame(()=>{c.current=null,l.current(s.current-o.current),o.current=s.current}))},[]),f=(0,a.useCallback)(e=>{r.current&&(e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId),c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),r.current=!1,n(!1))},[]);return(0,i.jsx)(`div`,{"aria-hidden":!0,className:`dsh-md-preview-handle`,"data-dragging":t||void 0,onPointerDown:u,onPointerMove:d,onPointerUp:f})}let fx=`md-preview`,px={"panel.title":`Markdown 预览`,"panel.close":`关闭预览`,"panel.loading":`正在加载…`,"panel.empty":`没有可预览的文档`,"panel.error":`加载失败`,"panel.retry":`重试`,"panel.edit":`编辑`,"panel.save":`保存`,"panel.cancel":`取消编辑`,"panel.saved":`已保存`,"panel.saveError":`保存失败`,"panel.save.retry":`重试`,"panel.conflict.title":`文件已在别处被修改`,"panel.conflict.reload":`重新加载`,"panel.conflict.force":`强制覆盖`,"panel.unsaved.title":`有未保存的修改`,"panel.unsaved.discard":`放弃修改`,"panel.unsaved.keep":`继续编辑`,"chip.preview":`预览 {name}`,"chip.open":`打开 {name}`,"action.label":`预览文档`,"action.open":`预览 {name}`,copy:`复制`,copied:`已复制`,footnotes:`脚注`},mx={"panel.title":`Markdown preview`,"panel.close":`Close preview`,"panel.loading":`Loading…`,"panel.empty":`No document to preview`,"panel.error":`Failed to load`,"panel.retry":`Retry`,"panel.edit":`Edit`,"panel.save":`Save`,"panel.cancel":`Cancel editing`,"panel.saved":`Saved`,"panel.saveError":`Save failed`,"panel.save.retry":`Retry`,"panel.conflict.title":`The file changed elsewhere`,"panel.conflict.reload":`Reload`,"panel.conflict.force":`Overwrite`,"panel.unsaved.title":`You have unsaved changes`,"panel.unsaved.discard":`Discard changes`,"panel.unsaved.keep":`Keep editing`,"chip.preview":`Preview {name}`,"chip.open":`Open {name}`,"action.label":`Preview documents`,"action.open":`Preview {name}`,copy:`Copy`,copied:`Copied`,footnotes:`Footnotes`};function hx(e,t){let n=e.data.get(`deliverables`);if(n===void 0)return[];let r=[],i=new Set;for(let e of n.produced)e.seq>t||i.has(e.path)||(i.add(e.path),r.push(e.path));return r}function gx(e){let t=hx(e.turn,e.seq);return t.some(us)?ds(t):null}let _x=!1;function vx(){if(_x||typeof document>`u`)return;let e=document.createElement(`style`);e.setAttribute(`data-plugin-css`,`md-preview`),e.textContent=`
65
65
  .dsh-md-preview-dock {
66
66
  position: absolute;
67
67
  inset: 0;
@@ -109,6 +109,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
109
109
  padding: 14px 12px 12px;
110
110
  border-bottom: 1px solid var(--dsw-alias-border-l2);
111
111
  }
112
+ .dsh-md-preview-version {
113
+ flex: none;
114
+ margin-left: 4px;
115
+ font-size: 11px;
116
+ font-variant-numeric: tabular-nums;
117
+ color: var(--dsw-alias-label-tertiary, var(--dsw-alias-label-secondary));
118
+ user-select: none;
119
+ }
112
120
  .dsh-md-preview-title {
113
121
  flex: 1;
114
122
  overflow: hidden;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@benz-ai-x/dsh-md-preview",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "DSH markdown preview: clicking a markdown document in the conversation opens a rendered preview panel docked to the right of the chat.",
5
5
  "license": "MIT",
6
6
  "repository": {