@kitschpatrol/tldraw-cli 1.0.0 → 1.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.
- package/bin/cli.js +1 -1
- package/package.json +2 -2
package/bin/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var Ot=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var an="
|
|
2
|
+
var Ot=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var an="1.0.0";import hn from"express";import bi from"node:net";import wi from"node:os";var he=class extends Error{constructor(t){super(`${t} is locked`)}},Jt={old:new Set,young:new Set},yi=1e3*15;var ie,Oi=()=>{let s=wi.networkInterfaces(),t=new Set([void 0,"0.0.0.0"]);for(let e of Object.values(s))for(let n of e)t.add(n.address);return t},ln=s=>new Promise((t,e)=>{let n=bi.createServer();n.unref(),n.on("error",e),n.listen(s,()=>{let{port:i}=n.address();n.close(()=>{t(i)})})}),cn=async(s,t)=>{if(s.host||s.port===0)return ln(s);for(let e of t)try{await ln({port:s.port,host:e})}catch(n){if(!["EADDRNOTAVAIL","EINVAL"].includes(n.code))throw n}return s.port},_i=function*(s){s&&(yield*s),yield 0};async function $e(s){let t,e=new Set;if(s&&(s.port&&(t=typeof s.port=="number"?[s.port]:s.port),s.exclude)){let i=s.exclude;if(typeof i[Symbol.iterator]!="function")throw new TypeError("The `exclude` option must be an iterable.");for(let r of i){if(typeof r!="number")throw new TypeError("Each item in the `exclude` option must be a number corresponding to the port you want excluded.");if(!Number.isSafeInteger(r))throw new TypeError(`Number ${r} in the exclude option is not a safe integer and can't be used`)}e=new Set(i)}ie===void 0&&(ie=setTimeout(()=>{ie=void 0,Jt.old=Jt.young,Jt.young=new Set},yi),ie.unref&&ie.unref());let n=Oi();for(let i of _i(t))try{if(e.has(i))continue;let r=await cn({...s,port:i},n);for(;Jt.old.has(r)||Jt.young.has(r);){if(i!==0)throw new he(i);r=await cn({...s,port:i},n)}return Jt.young.add(r),r}catch(r){if(!["EADDRINUSE","EACCES"].includes(r.code)&&!(r instanceof he))throw r}throw new Error("No available ports found")}import un from"node:fs/promises";import dn from"node:os";import Zt from"node:path";import{dirname as xi}from"node:path";import{fileURLToPath as Ei}from"node:url";import ji from"puppeteer";import Ci from"node:os";var fn=Ci.homedir();function ue(s){if(typeof s!="string")throw new TypeError(`Expected a string, got ${typeof s}`);return fn?s.replace(/^~(?=$|\/|\\)/,fn):s}async function Ai(s){let t=hn(),e=await $e();return t.use(hn.static(s)),new Promise((n,i)=>{let r=t.listen(e,()=>{n(r)});r.on("error",a=>{i(a)})})}async function Pi(s){return new Promise((t,e)=>{s.on("Browser.downloadProgress",n=>{n.state==="completed"?t(n.guid):n.state==="canceled"&&e(new Error("Download was canceled"))})})}async function pn(s,t="svg",e="./",n=!1){let i=xi(Ei(import.meta.url)),r=Zt.resolve(ue(s));n&&console.log(`Loading tldr file "${r}"`);let a=await un.readFile(r,"utf8");n&&console.log("Starting tldraw server...");let c=Zt.join(i,i.endsWith("/src/cli")?"../../dist":"../dist"),g=await Ai(c),{port:w}=g.address();n&&console.log(`tldraw hosted from "http://localhost:${w}"`),n&&console.log("Starting Puppeteer...");let p=await ji.launch({headless:"new"}),u=await p.newPage();await u.setRequestInterception(!0),u.on("request",F=>{F.url().endsWith("favicon.ico")?F.respond({status:200}):F.continue()}),u.on("console",F=>{let z=F.type(),T=F.text();z==="error"?(console.log(F.args()),console.log(F.location()),console.error(`[Browser] ${T}`)):z==="warning"?console.warn(`[Browser] ${T}`):n&&console.log(`[Browser] ${T}`)});let m=await u.target().createCDPSession();await m.send("Browser.setDownloadBehavior",{behavior:"allowAndName",downloadPath:dn.tmpdir(),eventsEnabled:!0}),await u.goto(`http://localhost:${w}`),await u.waitForFunction(()=>window.tldrawExportFile!==void 0),n&&console.log("Requesting download"),await u.evaluate((F,z)=>{window.tldrawExportFile(F,z)},a,t);let y=await Pi(m);n&&console.log("Download complete"),await p.close(),n&&console.log("Stopped Puppeteer");let E=Zt.basename(s,Zt.extname(s)),_=Zt.join(dn.tmpdir(),y),d=ue(Zt.join(e,`${E}.${t}`));await un.rename(_,d),n&&console.log(`Saved to "${d}"`),g.close(),n&&console.log("Stopped tldraw server")}import{notStrictEqual as Xi,strictEqual as ki}from"assert";var Si={right:Fi,center:Ni},Mi=0,de=1,Ii=2,pe=3,ve=class{constructor(t){var e;this.width=t.width,this.wrap=(e=t.wrap)!==null&&e!==void 0?e:!0,this.rows=[]}span(...t){let e=this.div(...t);e.span=!0}resetOutput(){this.rows=[]}div(...t){if(t.length===0&&this.div(""),this.wrap&&this.shouldApplyLayoutDSL(...t)&&typeof t[0]=="string")return this.applyLayoutDSL(t[0]);let e=t.map(n=>typeof n=="string"?this.colFromString(n):n);return this.rows.push(e),e}shouldApplyLayoutDSL(...t){return t.length===1&&typeof t[0]=="string"&&/[\t\n]/.test(t[0])}applyLayoutDSL(t){let e=t.split(`
|
|
3
3
|
`).map(i=>i.split(" ")),n=0;return e.forEach(i=>{i.length>1&&at.stringWidth(i[0])>n&&(n=Math.min(Math.floor(this.width*.5),at.stringWidth(i[0])))}),e.forEach(i=>{this.div(...i.map((r,a)=>({text:r.trim(),padding:this.measurePadding(r),width:a===0&&i.length>1?n:void 0})))}),this.rows[this.rows.length-1]}colFromString(t){return{text:t,padding:this.measurePadding(t)}}measurePadding(t){let e=at.stripAnsi(t);return[0,e.match(/\s*$/)[0].length,0,e.match(/^\s*/)[0].length]}toString(){let t=[];return this.rows.forEach(e=>{this.rowToString(e,t)}),t.filter(e=>!e.hidden).map(e=>e.text).join(`
|
|
4
4
|
`)}rowToString(t,e){return this.rasterize(t).forEach((n,i)=>{let r="";n.forEach((a,c)=>{let{width:g}=t[c],w=this.negatePadding(t[c]),p=a;if(w>at.stringWidth(a)&&(p+=" ".repeat(w-at.stringWidth(a))),t[c].align&&t[c].align!=="left"&&this.wrap){let m=Si[t[c].align];p=m(p,w),at.stringWidth(p)<w&&(p+=" ".repeat((g||0)-at.stringWidth(p)-1))}let u=t[c].padding||[0,0,0,0];u[pe]&&(r+=" ".repeat(u[pe])),r+=mn(t[c],p,"| "),r+=p,r+=mn(t[c],p," |"),u[de]&&(r+=" ".repeat(u[de])),i===0&&e.length>0&&(r=this.renderInline(r,e[e.length-1]))}),e.push({text:r.replace(/ +$/,""),span:t.span})}),e}renderInline(t,e){let n=t.match(/^ */),i=n?n[0].length:0,r=e.text,a=at.stringWidth(r.trimRight());return e.span?this.wrap?i<a?t:(e.hidden=!0,r.trimRight()+" ".repeat(i-a)+t.trimLeft()):(e.hidden=!0,r+t):t}rasterize(t){let e=[],n=this.columnWidths(t),i;return t.forEach((r,a)=>{r.width=n[a],this.wrap?i=at.wrap(r.text,this.negatePadding(r),{hard:!0}).split(`
|
|
5
5
|
`):i=r.text.split(`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitschpatrol/tldraw-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A tiny little CLI tool for converting tldraw .tldr files into svg or png images.",
|
|
6
6
|
"repository": {
|
|
@@ -78,6 +78,6 @@
|
|
|
78
78
|
"lint": "shared-config --lint",
|
|
79
79
|
"preview": "vite preview",
|
|
80
80
|
"release": "pnpm build && pnpm bumpp --commit 'Release: %s' && pnpm publish --otp $(op read 'op://Personal/Npmjs/one-time password?attribute=otp')",
|
|
81
|
-
"tldraw-copy-assets": "
|
|
81
|
+
"tldraw-copy-assets": "rsync -av --include='/*/' --exclude='/*' ./node_modules/@tldraw/assets/ ./src/tldraw/public/"
|
|
82
82
|
}
|
|
83
83
|
}
|