i-plane 1.2.0 → 2.0.1

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.
@@ -1,2 +0,0 @@
1
- import{L as re,N as T,O as B,P as O,V as ne,W as be,X as z,Z as ke,_ as V,a as Ce,b as ve,ba as pe,l as g,m as U,n as Y,r as me,u as d,x as H,y as b,z as A}from"./cli-gyrf14cz.js";var te=ve(function(He,ee){var I=!0,Q=!1,Z=!1;ee.exports=function(e,t){if(t)I=!t.enabled,Q=!!t.label,Z=!!t.labelAfter;e.core.ruler.after("inline","github-task-lists",function(r){var n=r.tokens;for(var i=2;i<n.length;i++)if($e(n,i))Pe(n[i],r.Token),G(n[i-2],"class","task-list-item"+(!I?" enabled":"")),G(n[xe(n,i-2)],"class","contains-task-list")})};function G(e,t,r){var n=e.attrIndex(t),i=[t,r];if(n<0)e.attrPush(i);else e.attrs[n]=i}function xe(e,t){var r=e[t].level-1;for(var n=t-1;n>=0;n--)if(e[n].level===r)return n;return-1}function $e(e,t){return Ye(e[t])&&Xe(e[t-1])&&Me(e[t-2])&&Te(e[t])}function Pe(e,t){if(e.children.unshift(Ae(e,t)),e.children[1].content=e.children[1].content.slice(3),e.content=e.content.slice(3),Q)if(Z){e.children.pop();var r="task-item-"+Math.ceil(Math.random()*1e7-1000);e.children[0].content=e.children[0].content.slice(0,-1)+' id="'+r+'">',e.children.push(Le(e.content,r,t))}else e.children.unshift(Ee(t)),e.children.push(Se(t))}function Ae(e,t){var r=new t("html_inline","",0),n=I?' disabled="" ':"";if(e.content.indexOf("[ ] ")===0)r.content='<input class="task-list-item-checkbox"'+n+'type="checkbox">';else if(e.content.indexOf("[x] ")===0||e.content.indexOf("[X] ")===0)r.content='<input class="task-list-item-checkbox" checked=""'+n+'type="checkbox">';return r}function Ee(e){var t=new e("html_inline","",0);return t.content="<label>",t}function Se(e){var t=new e("html_inline","",0);return t.content="</label>",t}function Le(e,t,r){var n=new r("html_inline","",0);return n.content='<label class="task-list-item-label" for="'+t+'">'+e+"</label>",n.attrs=[{for:t}],n}function Ye(e){return e.type==="inline"}function Xe(e){return e.type==="paragraph_open"}function Me(e){return e.type==="list_item_open"}function Te(e){return e.content.indexOf("[ ] ")===0||e.content.indexOf("[x] ")===0||e.content.indexOf("[X] ")===0}});import{readFile as Re}from"node:fs/promises";import{createHash as je,randomUUID as De}from"node:crypto";var ie=Ce(te(),1);import*as h from"yjs";var S=(e)=>String(e??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),x=(e,t)=>t==null||t===""?"":` ${e}="${S(t)}"`,M=(e)=>{if(Array.isArray(e))return e.map(M);if(e&&typeof e==="object")return Object.fromEntries(Object.entries(e).sort(([t],[r])=>t.localeCompare(r)).map(([t,r])=>[t,M(r)]));return e},Be=new Set(["doc","paragraph","heading","bulletlist","orderedlist","listitem","tasklist","taskitem","blockquote","codeblock","horizontalrule","hardbreak","table","tablerow","tableheader","tablecell","imagecomponent","image"]),oe=(e,t=!0)=>e instanceof h.XmlText?{text:M(e.toDelta())}:{kind:e.nodeName,attributes:M(Object.fromEntries(Object.entries(e.getAttributes()).filter(([r])=>r!=="id"||!(t||Be.has(e.nodeName.toLowerCase()))))),children:e.toArray().map((r)=>oe(r,!1))},R=(e)=>je("sha256").update(JSON.stringify(oe(e))).digest("hex"),L=(e)=>e instanceof h.XmlText?e.toDelta().map((t)=>typeof t.insert==="string"?t.insert:JSON.stringify(t.insert)).join(""):e.toArray().map((t)=>L(t)).join(" "),se=(e)=>e.toArray().map((t,r)=>{let n=t instanceof h.XmlElement?String(t.getAttribute("id")??"")||null:null;return{index:r,anchor:n,shortAnchor:n?b(n).slice(0,8):null,kind:t instanceof h.XmlElement?t.nodeName:"text",preview:b(L(t)).replace(/\s+/g," ").trim().slice(0,40)}}),C=(e,t)=>{let r=e.toArray().flatMap((i,s)=>{if(!(i instanceof h.XmlElement))return[];let a=String(i.getAttribute("id")??"");return a.length>0&&a.toLowerCase().startsWith(t.toLowerCase())?[{node:i,index:s,anchor:a}]:[]});if(r.length===0)throw new d(`No top-level block matches "${t}". Run page outline to see current anchors.`,404);if(r.length!==1)throw new g(`Ambiguous block anchor "${t}": ${r.map((i)=>`${i.anchor} [${i.index}]`).join(", ")}`);let n=r[0];if(!n)throw new d("Block disappeared.");return n},_=(e)=>{let t=0;for(let r of e.toArray())if(r instanceof h.XmlElement&&!r.getAttribute("id"))r.setAttribute("id",De()),t++;return t},j=(e,t,r=!1)=>{if(e instanceof h.XmlText){let o=L(e),c=r?b(o):o;if(c!==o)return t.add("Sensitive text was redacted; the printed block is not a lossless copy"),S(c);return e.toDelta().map((m)=>{let l=S(typeof m.insert==="string"?m.insert:JSON.stringify(m.insert));for(let[u,w]of Object.entries(m.attributes??{})){let v=Object.fromEntries(Object.entries(w&&typeof w==="object"?w:{}).map(([P,y])=>[P,r&&typeof y==="string"?b(y):y]));if(u==="bold")l=`<strong>${l}</strong>`;else if(u==="italic")l=`<em>${l}</em>`;else if(u==="strike")l=`<s>${l}</s>`;else if(u==="code")l=`<code>${l}</code>`;else if(u==="link")l=`<a${x("href",v.href)}${x("title",v.title)}>${l}</a>`;else if(t.add(`Mark ${u} is not representable by this Markdown reader`),u==="underline")l=`&lt;u&gt;${l}&lt;/u&gt;`}return l}).join("")}let n=e.nodeName.toLowerCase(),i=Object.fromEntries(Object.entries(e.getAttributes()).map(([o,c])=>[o,r&&typeof c==="string"?b(c):c])),s=()=>e.toArray().map((o)=>j(o,t,r)).join("");if(i.textAlign&&i.textAlign!=="left")t.add("Text alignment is not representable in Markdown");if(n==="doc")return s();if(n==="paragraph")return`<p>${s()}</p>`;if(n==="heading"){let o=Math.min(6,Math.max(1,Number(i.level)||1));return`<h${o}>${s()}</h${o}>`}if(n==="bulletlist")return`<ul>${s()}</ul>`;if(n==="orderedlist")return`<ol${x("start",i.start)}>${s()}</ol>`;if(n==="listitem")return`<li>${s()}</li>`;if(n==="tasklist")return`<ul>${s()}</ul>`;if(n==="taskitem"){let o=`<input type="checkbox"${i.checked===!0||i.checked==="true"?" checked":""}>`,c=s().replace(/^<p>([\s\S]*?)<\/p>/,"$1");return`<li>${o}${c}</li>`}if(n==="blockquote")return`<blockquote>${s()}</blockquote>`;if(n==="codeblock")return`<pre><code${i.language?x("class",`language-${i.language}`):""}>${S(r?b(L(e)):L(e))}</code></pre>`;if(n==="horizontalrule")return"<hr>";if(n==="hardbreak")return"<br>";if(n==="table")return`<table>${s()}</table>`;if(n==="tablerow")return`<tr>${s()}</tr>`;if(n==="tablecell"||n==="tableheader"){let o=e.toArray().filter((l)=>l instanceof h.XmlElement),c=(l)=>l.nodeName.toLowerCase()==="hardbreak"||l.toArray().some((u)=>u instanceof h.XmlElement&&c(u));if(o.length>1||o.some((l)=>l.nodeName.toLowerCase()!=="paragraph"||c(l)))t.add("Multiple paragraphs, line breaks or block structure inside table cells are flattened in Markdown");if(Number(i.colspan??1)!==1||Number(i.rowspan??1)!==1)t.add("Merged table cells are not representable in Markdown");if(i.background||i.colwidth)t.add("Table styling is not representable in Markdown");let m=n==="tablecell"?"td":"th";return`<${m}>${s()}</${m}>`}if(n==="imagecomponent"||n==="image"){if(i.width||i.height||i.alignment)t.add("Image dimensions or alignment are not representable in Markdown");return`<img${x("src",i.src)}${x("alt",i.alt)}${x("title",i.title)}>`}t.add(`Unsupported node ${e.nodeName}; preserved as XML text`);let a=e.toString();return`<pre><code class="language-xml">${S(r?ne(a):a)}</code></pre>`},Oe=(e)=>{let t=new Set,r=e.toArray().map((n)=>j(n,t)).join("");return{markdown:T(r),losses:[...t]}},ae=(e,t)=>{let{node:r,anchor:n}=C(e,t),i=new Set;return{anchor:n,fingerprint:R(r),markdown:T(j(r,i,!0)),losses:[...i]}},ce=(e)=>{let t=new Set;for(let r of e)j(r,t);return[...t]},N=new re({html:!1}).use(ie.default);N.core.ruler.before("github-task-lists","empty-task-items",(e)=>{for(let t=2;t<e.tokens.length;t++){let r=e.tokens[t],n=r?.children?.[0];if(r&&n&&/^\[[ xX]\]$/.test(r.content)&&e.tokens[t-1]?.tag==="p"&&e.tokens[t-2]?.tag==="li")r.content+=" ",n.content+=" "}});var le=(e)=>e.toArray().flatMap((t)=>t instanceof h.XmlElement?[...t.nodeName.toLowerCase()==="codeblock"?[t]:[],...le(t)]:[]),de=async(e,t)=>{let r=N.render(t).trim().replace(/(<li class="task-list-item">)\s*<p>([\s\S]*?)<\/p>/g,"$1$2").replace(/(<input class="task-list-item-checkbox"[^>]*>) /g,"$1");if(!r){let a=new h.Doc;return{doc:a,fragment:a.getXmlFragment("default"),losses:[]}}let n=r.replace(/<img([^>]*?)\s*\/?>/g,"<image-component$1></image-component>").replace(/<ul class="contains-task-list">/g,'<ul data-type="taskList">').replace(/<li class="task-list-item">(\s*<p>)?<input\b([^>]*)>/g,(a,o,c)=>`<li data-type="taskItem" data-checked="${/\bchecked=/.test(c)}">${o??""}`),i=await e.raw("/live/convert-document",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({description_html:n,variant:"rich"})});if(i.status!==200)throw new d(`Document converter answered ${i.status}.`,i.status);let s=new h.Doc;try{let a=JSON.parse(i.text);if(typeof a.description_binary!=="string"||!a.description_binary)throw Error("Missing document binary");h.applyUpdate(s,Buffer.from(a.description_binary,"base64"));let o=s.getXmlFragment("default"),c=N.parse(t,{}).filter((w)=>w.block&&w.tag==="code").map((w)=>w.info.trim().split(/\s+/)[0]||null),m=le(o),l=[];if(c.length!==m.length)l.push("The converter changed the number of code blocks");else s.transact(()=>m.forEach((w,E)=>{let v=c[E];if(v)w.setAttribute("language",v);else w.removeAttribute("language")}));if(Oe(o).markdown!==T(r))l.push("The converter changed Markdown content or formatting");return s.transact(()=>_(o)),{doc:s,fragment:o,losses:l}}catch(a){if(s.destroy(),a instanceof d)throw a;throw new d(`Cannot decode the converted document: ${a instanceof Error?a.message:String(a)}`)}};import*as D from"yjs";var q=(e,t=!1)=>{if(e.length&&!t)throw new g(`This edit can lose content or formatting: ${e.join("; ")}. Inspect the document, then pass --allow-loss to accept these losses.`)},fe=(e,t,r)=>{let n=t.block?C(e,t.block):void 0;if(n&&t.ifMatch&&!t.force&&R(n.node)!==t.ifMatch)throw new d("Block content changed since page read. Read it again and use its new --if-match fingerprint, or pass --force to overwrite the concurrent edit.",409);let i=r?.fragment.length??0;if(t.kind!=="rm"&&!r)throw new g("Expected Markdown content.");if((t.kind==="insert"||n&&t.kind==="set")&&i===0)throw new g("Empty block content. Use page rm --block to remove a block.");let s=t.kind==="insert"?[]:n?[n.node]:e.toArray(),a=[...new Set([...r?.losses??[],...ce(s)])];if(t.kind!=="rm")q(a,t.allowLoss);let o=n?.index??0;if(t.kind==="insert")o=t.after?C(e,t.after).index+1:e.length;let c=r?.fragment.toArray().map((m)=>{if(!(m instanceof D.XmlElement)&&!(m instanceof D.XmlText))throw new d("Unsupported document block; no changes were made.");return m.clone()})??[];if(t.kind!=="insert")e.delete(o,n?1:e.length);if(t.kind!=="rm"&&c.length){if(e.insert(o,c),n&&c[0]&&"setAttribute"in c[0])c[0].setAttribute("id",n.anchor)}return t.kind==="rm"?[]:a};import{HocuspocusProvider as Ue,HocuspocusProviderWebsocket as Fe}from"@hocuspocus/provider";import{HttpsProxyAgent as Ie}from"https-proxy-agent";import Ne from"ws";import*as he from"yjs";class W extends d{}class ue{doc=new he.Doc;fragment=this.doc.getXmlFragment("default");socket;provider;agent;pending;failure;writing=!1;acknowledged=!1;disposed=!1;deadline;constructor(e,t,r,n=20000){this.deadline=n,H(r);let i=me(e);if(i)H(i),this.agent=new Ie(i);let s=this.agent;class a extends Ne{constructor(o){super(o,{agent:s,handshakeTimeout:n})}}this.socket=new Fe({url:e,WebSocketPolyfill:a,autoConnect:!1,maxAttempts:1,onClose:()=>this.fail(new d("Live connection closed."))}),this.socket.on("maxAttemptsFailed",()=>this.fail(new d("Cannot connect to the live server."))),this.provider=new Ue({websocketProvider:this.socket,name:t,document:this.doc,awareness:null,token:r,forceSyncInterval:!1,flushDelay:!1,onClose:()=>this.fail(new d("Live document connection closed.")),onSynced:()=>this.progress(),onUnsyncedChanges:()=>this.progress(),onAuthenticationFailed:()=>this.fail(new W("Live authentication was refused."))}),this.provider.attach()}progress(){if(this.disposed||this.failure||!this.provider?.isSynced||this.provider.hasUnsyncedChanges)return;if(this.writing)this.acknowledged=!0;this.pending?.resolve()}fail(e){if(this.disposed||this.failure)return;if(this.writing&&!this.acknowledged)e=new d("Live connection failed after sending changes; delivery is uncertain. Inspect the live document before retrying. The command was not replayed.");this.failure=e,this.socket.shouldConnect=!1,this.pending?.reject(e)}async wait(e){if(this.failure)throw this.failure;let t;try{await new Promise((r,n)=>{this.pending={resolve:r,reject:n},t=setTimeout(()=>this.fail(new d("Live synchronization timed out.")),this.deadline),e(),this.progress()})}finally{clearTimeout(t),this.pending=void 0}}async ready(){await this.wait(()=>{this.socket.connect().catch(()=>this.fail(new d("Cannot connect to the live server.")))})}async write(e){if(this.failure)throw this.failure;if(!this.provider.isSynced)throw new d("Live document is not synchronized.");if(this.provider.authorizedScope!=="read-write")throw new d("The live session does not allow writing this page.");let t=!1,r=(n,i)=>{if(i===this)t=!0};this.doc.on("update",r);try{return await this.wait(()=>{this.writing=!0,this.doc.transact(()=>e(this.fragment),this)}),{delivery:t?"acknowledged":"unchanged",persistence:"asynchronous"}}finally{this.doc.off("update",r)}}destroy(){if(this.disposed)return;this.disposed=!0,this.provider.destroy(),this.socket.destroy(),this.agent?.destroy(),this.doc.destroy()}}var ge=async(e,t,r)=>{let n=new URL(`${e.config.url.value}/live/collaboration`);n.protocol=n.protocol==="https:"?"wss:":"ws:",n.searchParams.set("documentType","project_page"),n.searchParams.set("projectId",t),n.searchParams.set("workspaceSlug",e.config.workspace.value);for(let i=0;i<2;i++){let s=await e.session(i===1),a=new ue(n.href,r,JSON.stringify({id:s.userId,cookie:pe(s)}));try{return await a.ready(),a}catch(o){if(a.destroy(),i===0&&o instanceof W)continue;throw new d(b(o instanceof Error?o.message:String(o)))}}throw new d("Live authentication failed.")};var _e=async(e,t=!1)=>{let r=U(e,"file"),n=U(e,"text");if(r!==void 0&&n!==void 0)throw new g("--file and --text are mutually exclusive.");if(r!==void 0)try{return await Re(r,"utf8")}catch{throw new g(`Cannot read Markdown file "${r}".`)}if(n!==void 0||t)return n;throw new g("Expected --file <path> or --text <markdown>.")},we=(e)=>{if(e.length)console.error(b(`Warning: ${e.join("; ")}`))},J=(e)=>`${e.id} ${e.deleted?"deleted":e.delivery??"created"}${e.stamped!==void 0?`; stamped ${e.stamped} blocks`:""}${e.delivery?"; database persistence is asynchronous":""}`,vt=async(e,t,r,n)=>{let i=B(r.positionals[0],"a project"),s=e==="page create",a=e==="page rm",o=s?O(r,"name"):B(r.positionals[1],"a page UUID or name"),c=r.flags.has("block")?O(r,"block"):void 0,m=r.flags.has("after")?O(r,"after"):void 0,l=Y(r,"at-end"),u=U(r,"if-match"),w=Y(r,"force"),E=Y(r,"allow-loss");if(a&&!Y(r,"yes"))throw new g("Deletion requires --yes.");if((u!==void 0||w)&&!c)throw new g("--if-match and --force require --block.");if(u!==void 0&&!/^[a-f0-9]{64}$/i.test(u))throw new g("--if-match expects the SHA-256 fingerprint from page read --json.");if(e==="page read"&&!c)throw new g("Expected --block <anchor>.");if(e==="page insert"&&Boolean(m)===l)throw new g("Choose exactly one of --after <anchor> or --at-end.");let v=s||e==="page set"||e==="page insert"?await _e(r,s):void 0,P=await be(t,i),y,F;try{if(v!==void 0)y=await de(t,v),q(y.losses,E);let p=s?await t.request(z(P.id),{method:"POST",body:{name:o,access:0}}):await ke(t,P.id,o);if(s)F=p;if(s&&!y){A({id:p.id,name:p.name},n,J);return}if(a&&!c){V(p,!0);let k=`${z(P.id)}${p.id}/`;if(!p.archived_at)try{await t.request(`${k}archive/`,{method:"POST"})}catch(f){throw new d(`Archiving page ${p.id} was not confirmed: ${f instanceof Error?f.message:String(f)}. Inspect this UUID before retrying; deletion was not attempted.`)}try{await t.request(k,{method:"DELETE"})}catch(f){throw new d(`Page ${p.id} was archived, but deletion was not confirmed: ${f instanceof Error?f.message:String(f)}. Inspect it by UUID before retrying.`)}A({id:p.id,deleted:!0},n,J);return}if(!(e==="page outline"||e==="page read"))V(p);let X=await ge(t,P.id,p.id);try{if(e==="page outline")A(se(X.fragment),n,(k)=>k.map((f)=>`${f.index} ${f.shortAnchor??"(no anchor)"} ${f.kind} ${f.preview}`).join(`
2
- `));else if(e==="page read"){let k=ae(X.fragment,B(c,"--block <anchor>"));we(k.losses),A(k,n,(f)=>f.markdown)}else{let k,f=[],ye=await X.write((K)=>{if(e==="page stamp")k=_(K);else f=fe(K,{kind:a?"rm":e==="page insert"?"insert":"set",block:c,after:m,atEnd:l,ifMatch:u?.toLowerCase(),force:w,allowLoss:E},y)});we(f),A({id:p.id,...ye,stamped:k,losses:f},n,J)}}finally{X.destroy()}}catch(p){if(F)throw new d(`Page ${F.id} was created, but its content operation did not complete: ${p instanceof Error?p.message:String(p)}. Inspect this page before retrying; do not create a duplicate.`);throw p}finally{y?.doc.destroy()}};export{vt as runPageContent};