@eloqnt/cli 0.6.32 → 0.6.33
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/CHANGELOG.md +13 -0
- package/dist/bin/eloqnt.mjs +1 -1
- package/dist/context-CD9Scwzs.mjs +1 -0
- package/dist/{crowdin-DdfREp0-.mjs → crowdin-yPxHlC19.mjs} +1 -1
- package/dist/download-D4Pu2ld1.mjs +3 -0
- package/dist/extract-DAKfzwXH.mjs +3 -0
- package/dist/lint-tRRSSz2-.mjs +7 -0
- package/dist/resolvePaths-CKsEPHfH.mjs +1 -0
- package/dist/{review-hRnF51uJ.mjs → review-CasB0UBu.mjs} +1 -1
- package/dist/source-CsUPsHDM.mjs +11 -0
- package/dist/stringWidth-D0Z3LOKi.mjs +1 -0
- package/dist/{translate-D4A7TVLU.mjs → translate-DcvHKUEY.mjs} +4 -4
- package/dist/upload-CDI-U4mI.mjs +3 -0
- package/package.json +2 -2
- package/dist/lint-Wu02Ge85.mjs +0 -7
- package/dist/source-CNaJNsTq.mjs +0 -11
- package/dist/stringWidth-DvyI3S_b.mjs +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @eloqnt/cli
|
|
2
2
|
|
|
3
|
+
## 0.6.33
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a925589: Add `eloqnt crowdin context extract`, `upload`, and `download` to add a source outline of where your code uses each string to its context on Crowdin. Context you write in place of an outline is kept until the string’s text changes.
|
|
8
|
+
- a925589: Fail with an error when a `srcPath` folder doesn’t exist or holds no next-intl calls, instead of running `lint`, `translate`, and `review source` without source analysis.
|
|
9
|
+
- Updated dependencies [a925589]
|
|
10
|
+
- Updated dependencies [5a2a313]
|
|
11
|
+
- Updated dependencies [ad5c626]
|
|
12
|
+
- Updated dependencies [dec6700]
|
|
13
|
+
- Updated dependencies [a925589]
|
|
14
|
+
- @eloqnt/sdk@0.6.31
|
|
15
|
+
|
|
3
16
|
## 0.6.32
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/bin/eloqnt.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import e from"node:process";import{defineCommand as t,renderUsage as n,runMain as r}from"citty";import i from"picocolors";var a=`0.6.
|
|
2
|
+
import e from"node:process";import{defineCommand as t,renderUsage as n,runMain as r}from"citty";import i from"picocolors";var a=`0.6.33`;try{e.loadEnvFile()}catch{}const o=t({meta:{name:`eloqnt`,version:a,description:`AI-powered translations for developers`},subCommands:{lint:d(()=>import(`../lint-tRRSSz2-.mjs`)),review:d(()=>import(`../review-CasB0UBu.mjs`)),translate:d(()=>import(`../translate-DcvHKUEY.mjs`)),crowdin:d(()=>import(`../crowdin-yPxHlC19.mjs`)),login:d(()=>import(`../login-cvA1zw4B.mjs`)),logout:d(()=>import(`../logout-BAr7ojyZ.mjs`)),whoami:d(()=>import(`../whoami-CUFPZPY4.mjs`))}}),s=e.argv.slice(2);r(o,{rawArgs:s.length===1&&s[0]===`-v`?[`--version`]:s,async showUsage(e,t){console.log(await n(e,t)),console.log(i.dim(`Docs: ${await c(e,t)}`))}});async function c(e,t){let n=(await u(e.meta))?.name,r=(await u(t?.meta))?.name,i=r===void 0||r===`eloqnt`?n:r;return i===void 0||i===`eloqnt`?`https://cli.eloqnt.dev/docs`:`https://cli.eloqnt.dev/docs/cli/${await l(i)}`}async function l(e){let t=o.subCommands??{};if(e in t)return e;for(let[n,r]of Object.entries(t)){let t=(await u(r))?.subCommands;if(t&&e in t)return n}return e}function u(e){return typeof e==`function`?e():e}function d(e){return()=>e().then(e=>e.default)}export{a as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{defineCommand as e}from"citty";var t=e({meta:{name:`context`,description:`Extract, upload, and download context for your Crowdin strings.`},subCommands:{extract:()=>import(`./extract-DAKfzwXH.mjs`).then(e=>e.default),upload:()=>import(`./upload-CDI-U4mI.mjs`).then(e=>e.default),download:()=>import(`./download-D4Pu2ld1.mjs`).then(e=>e.default)}});export{t as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineCommand as e}from"citty";var t=e({meta:{name:`crowdin`,description:`Sync messages with a Crowdin project (uses crowdin.yml).`},subCommands:{upload:()=>import(`./upload-Dsy5tcAd.mjs`).then(e=>e.default),download:()=>import(`./download-DfXkJo_Z.mjs`).then(e=>e.default)}});export{t as default};
|
|
1
|
+
import{defineCommand as e}from"citty";var t=e({meta:{name:`crowdin`,description:`Sync messages with a Crowdin project (uses crowdin.yml).`},subCommands:{upload:()=>import(`./upload-Dsy5tcAd.mjs`).then(e=>e.default),download:()=>import(`./download-DfXkJo_Z.mjs`).then(e=>e.default),context:()=>import(`./context-CD9Scwzs.mjs`).then(e=>e.default)}});export{t as default};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{n as t,r as n,t as r}from"./withSpinner-CeQSfolX.mjs";import i from"node:process";import a from"picocolors";import{basename as o,relative as s}from"node:path";import{downloadCrowdinContext as c}from"@eloqnt/sdk/_internal";var l=e({meta:{name:`download`,description:`Download the strings of your Crowdin project with their current context.`},requiresConfig:!1,args:{branch:{type:`string`,description:`Sync with this branch of the Crowdin project`}},async execute({rootDir:e,args:t}){let n=await r({label:`Downloading context from Crowdin`,json:!!t.json,task:()=>c({rootDir:e,branch:t.branch})}),a=i.cwd();return{result:{...n,contextFile:s(a,n.contextFile),files:n.files.map(e=>({...e,file:s(a,e.file)}))}}},render({result:e}){let r=e.files.map(e=>({file:e.file,detail:a.green(`${e.strings} ${e.strings===1?`string`:`strings`}`)+(e.withAiContext>0?a.dim(`, ${e.withAiContext} with AI context`):``)})),i=e.files.reduce((e,t)=>e+t.strings,0),s=a.green(`✔ Downloaded ${i} ${i===1?`string`:`strings`} from ${e.project.name} to ${o(e.contextFile)}`)+(e.branch?` ${a.dim(`(${e.branch})`)}`:``);return`\n${[t(r),...n(e.warnings),s].join(`
|
|
2
|
+
|
|
3
|
+
`)}`},json:({result:e})=>e});export{l as default};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{n as t,r as n,t as r}from"./withSpinner-CeQSfolX.mjs";import{t as i}from"./resolvePaths-CKsEPHfH.mjs";import a from"node:process";import o from"picocolors";import{basename as s,relative as c}from"node:path";import{extractCrowdinContext as l}from"@eloqnt/sdk/_internal-source";var u=e({meta:{name:`extract`,description:`Extract context for your Crowdin strings from how your code uses them.`},async execute({config:e,rootDir:t,args:n}){let{messages:o,srcPath:s}=e,u=await r({label:`Extracting context from source code`,json:!!n.json,task:()=>l({messagesPath:i(o.path,t),sourceLocale:o.sourceLocale,format:o.format,locales:o.locales,codes:o.codes,srcPath:s?i(s,t):void 0,rootDir:t})}),d=a.cwd();return{result:{...u,contextFile:c(d,u.contextFile),files:u.files.map(e=>({...e,file:c(d,e.file)}))}}},render({result:e}){let r=e.files.map(e=>({file:e.file,detail:o.green(`${e.extracted} extracted`)+(e.reset>0?o.dim(`, ${e.reset} ${e.reset===1?`edit`:`edits`} reset to an outline`):``)+(e.unused>0?o.dim(`, ${e.unused} not found in source`):``)})),i=e.files.reduce((e,t)=>e+t.extracted,0),a=i===0?o.dim(`No strings found in source code`):o.green(`✔ Extracted context for ${i} ${i===1?`string`:`strings`} to ${s(e.contextFile)}`),c=[t(r),...n(e.warnings),a],l=i>0?o.dim("→ Run `eloqnt crowdin context upload` to upload it"):void 0;return`\n${c.join(`
|
|
2
|
+
|
|
3
|
+
`)}${l?`\n\n${l}`:``}`},json:({result:e})=>e});export{u as default};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{t}from"./resolvePaths-CKsEPHfH.mjs";import{n,t as r}from"./report-CEfrIjER.mjs";import{a as i,i as a,r as o,t as s}from"./stringWidth-D0Z3LOKi.mjs";import{lint as c}from"@eloqnt/sdk";import l from"node:process";import u from"picocolors";import{relative as d,resolve as f}from"node:path";var p=e({meta:{name:`lint`,description:`Statically analyze your source code and messages for common problems.`},args:{strict:{type:`boolean`,description:`Exit with a non-zero code when warnings are found`,default:!1}},async execute({config:e,rootDir:n,args:r}){let{messages:i,srcPath:a}=e,o=await c({messagesPath:t(i.path,n),sourceLocale:i.sourceLocale,format:i.format,locales:i.locales,codes:i.codes,srcPath:a?t(a,n):void 0,rules:e.lint?.rules,overrides:e.lint?.overrides,rootDir:n}),s=l.cwd();return{issues:o.map(e=>{let t=e;if(t.location&&(t={...t,location:{...t.location,file:d(s,t.location.file)}}),t.rule===`undefined-key`&&t.sourceReferences?.length){let e=t.sourceReferences.map(e=>({...e,path:d(s,e.path)})),n=e[0].line?`${e[0].path}:${e[0].line}`:e[0].path,r=e.length>1?` (+${e.length-1} more)`:``;t={...t,sourceReferences:e,message:`Used in ${n}${r} but not defined for ${i.sourceLocale}`}}return t}),sourceLocale:i.sourceLocale,noSrcPath:!a,strict:!!r.strict}},render:({issues:e,sourceLocale:t,noSrcPath:n})=>{let r=h(e,t),i=n?`\n${u.dim("– Skipped source code analysis due to absent `srcPath`")}\n${r}`:r;return l.env.GITHUB_ACTIONS&&e.length>0?`${i}\n${_(e)}`:i},ok:({issues:e,strict:t})=>t?e.length===0:!e.some(e=>e.severity===`error`),json:({issues:e})=>e.map(e=>({...e,docsUrl:m(e.rule)}))});function m(e){return`https://cli.eloqnt.dev/docs/lint-rules/${e}`}function h(e,t){if(e.length===0)return`\n${u.green(`No issues found`)}\n`;let n=Object.groupBy(e,e=>e.location?.file??e.locale),r=x(Object.entries(n),t).map(([e,n])=>S(e,n,n[0].locale===t)),i=e.filter(e=>e.severity===`error`).length,a=e.length-i,o=[i>0&&u.bold(u.red(`✗ ${g(i,`error`)}`)),a>0&&u.bold(u.yellow(`! ${g(a,`warning`)}`))].filter(Boolean).join(`
|
|
2
|
+
`),s=e.filter(e=>e.rule===`missing-translation`).length,c=[e.some(e=>e.rule!==`missing-translation`)&&u.dim(`→ Rule details: ${m(`<rule>`)}`),s>0&&u.dim(`→ Run \`eloqnt translate\` to fill in ${s} missing ${s===1?`translation`:`translations`}`)].filter(Boolean).join(`
|
|
3
|
+
`);return`\n${[...r,o,c].filter(Boolean).join(`
|
|
4
|
+
|
|
5
|
+
`)}\n`}function g(e,t){return`${e} ${e===1?t:`${t}s`}`}function _(e){return e.map(e=>{let t=e.rule===`undefined-key`&&e.sourceReferences?.length?e.sourceReferences[0]:void 0,n=t?.path??e.location?.file,r=[n&&`file=${b(v(n))}`,t?.line&&`line=${t.line}`,`title=${b(e.rule)}`].filter(Boolean).join(`,`),i=y(`"${e.key}": ${e.message}\n${m(e.rule)}`);return`::${e.severity} ${r}::${i}`}).join(`
|
|
6
|
+
`)}function v(e){let t=l.env.GITHUB_WORKSPACE;return t?d(t,f(e)):e}function y(e){return e.replace(/%/g,`%25`).replace(/\r/g,`%0D`).replace(/\n/g,`%0A`)}function b(e){return y(e).replace(/:/g,`%3A`).replace(/,/g,`%2C`)}function x(e,t){let n=e.findIndex(([,e])=>e[0].locale===t);if(n<=0)return e;let r=[...e],[i]=r.splice(n,1);return[i,...r]}function S(e,t,n){let i=[n?`${u.cyan(e)} ${u.dim(`(source locale)`)}`:u.cyan(e)];for(let e of t){i.push(u.dim(`│`));let{content:t,span:n}=C(e);i.push(r(t)),i.push(...T(n,e))}return i.join(`
|
|
7
|
+
`)}function C(e){let t=`"${e.key}"`,r=e.targetMessage??e.sourceMessage,a=w(t),s=e.highlight?.type===`value`||e.highlight?.type===`argument`,c=s?u.dim(t):t,l=u.dim(`: `),d=o(t);if(r!==void 0&&e.highlight?.type===`argument`){let t=n(r),i=e.highlight.token,s=t.indexOf(i);if(s>=0){let{inner:e,offset:n}=E(t,s,i.length,a);return{content:`${c}${l}"${e}"`,span:{column:d+3+n,length:o(i)}}}}let f=r===void 0?`"…"`:`"${i(n(r),a)}"`,p=`${c}${l}${s?f:u.dim(f)}`;return r!==void 0&&e.highlight?.type===`value`?{content:p,span:{column:d+2,length:o(f)}}:{content:p,span:{column:0,length:d}}}function w(e){let t=3+o(e)+2+2;return Math.max(24,Math.min(48,a()-t))}function T(e,t){let n=t.severity===`error`?u.red:u.yellow,i=Math.min(1,e.length-1),a=`─`.repeat(i)+`┬`+`─`.repeat(e.length-1-i),o=`${t.message} ${u.dim(`(${t.rule})`)}`;return[r(` `.repeat(e.column)+n(a)),r(`${` `.repeat(e.column+i)}${n(`╰─`)} ${o}`)]}function E(e,t,n,r){let i=s(e),a=i.reduce((e,t)=>e+t.width,0),o=D(i,t),c=D(i,t+n);if(a<=r)return{inner:e,offset:O(i,0,o)};let l=Math.max(O(i,o,c),r-2),u=o,d=0;for(;u>0&&d+i[u-1].width<=16;)u--,d+=i[u].width;let f=o;for(;f<i.length&&d+i[f].width<=l;)d+=i[f].width,f++;for(;u>0&&d+i[u-1].width<=l;)u--,d+=i[u].width;let p=u>0?`…`:``,m=f<i.length?`…`:``;return{inner:p+i.slice(u,f).map(e=>e.text).join(``)+m,offset:O(i,u,o)+p.length}}function D(e,t){let n=0;for(let r=0;r<e.length;r++){if(n>=t)return r;n+=e[r].text.length}return e.length}function O(e,t,n){let r=0;for(let i=t;i<n;i++)r+=e[i].width;return r}export{p as default,_ as formatGithubAnnotations,h as formatLint};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{resolve as e}from"node:path";function t(t,n){return(Array.isArray(t)?t:[t]).map(t=>typeof t==`string`?e(n,t):{source:e(n,t.source),targets:e(n,t.targets)})}export{t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineCommand as e}from"citty";var t=e({meta:{name:`review`,description:`Review source strings and fix issues in place.`},setup({rawArgs:e}){e.find(e=>!e.startsWith(`-`))!==`source`&&e.unshift(`source`)},subCommands:{source:()=>import(`./source-
|
|
1
|
+
import{defineCommand as e}from"citty";var t=e({meta:{name:`review`,description:`Review source strings and fix issues in place.`},setup({rawArgs:e}){e.find(e=>!e.startsWith(`-`))!==`source`&&e.unshift(`source`)},subCommands:{source:()=>import(`./source-CsUPsHDM.mjs`).then(e=>e.default)}});export{t as default};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{t}from"./createSpinner-BBkrpcrh.mjs";import{t as n}from"./resolvePaths-CKsEPHfH.mjs";import{t as r}from"./parseListArg-p5H1s5JC.mjs";import{n as i,t as a}from"./report-CEfrIjER.mjs";import{a as o,i as s,n as c,r as l}from"./stringWidth-D0Z3LOKi.mjs";import{a as u,r as d}from"./urls-qvEAJDcV.mjs";import{n as f,r as p,t as m}from"./writeStep-CerCYWGN.mjs";import{reviewSource as h}from"@eloqnt/sdk";import g from"node:process";import _ from"picocolors";import{basename as v,dirname as y,relative as b}from"node:path";import{loadStyleguide as x}from"@eloqnt/sdk/_internal";var S=e({meta:{name:`source`,description:`Review source strings for errors and fix them in place.`,requiresLogin:!0},args:{id:{type:`string`,description:`(Re-)review these message ids (comma-separated)`}},async execute({config:e,rootDir:i,args:a}){let{messages:o,srcPath:s}=e,c=n(o.path,i),l=s?n(s,i):void 0,f=await x({rootDir:i,path:e.styleguides}),v=p(f,[o.sourceLocale]),y=e.model?`eloqnt/engine (${typeof e.model==`string`?e.model:e.model.modelId})`:`eloqnt/engine (hosted)`,S=g.stderr.isTTY&&!a.json,C;function w(e){if(!a.json){if(e.phase===`context-enrichment`){e.state===`started`?(g.stderr.write(`
|
|
2
|
+
`),S?(C=t({withGuide:!1}),C.start(`Context enrichment running`)):g.stderr.write(_.dim(`Context enrichment running …
|
|
3
|
+
`))):e.state===`completed`?(C?.clear(),C=void 0,m(_.green(`✔`),`Context enrichment complete`)):(g.stderr.write(`
|
|
4
|
+
`),m(_.dim(`–`),"Skipped source code analysis due to absent `srcPath`"));return}if(e.phase===`post-checks`){e.state===`started`?S?(C=t({withGuide:!1}),C.start(`Post-review checks running`)):g.stderr.write(_.dim(`Post-review checks running …
|
|
5
|
+
`)):(C?.clear(),C=void 0,m(_.green(`✔`),`Post-review checks done`));return}e.state===`started`?(v?m(_.green(`✔`),v):m(_.dim(`–`),`No styleguides found`),S?(C=t({withGuide:!1}),C.start(`Reviewing source strings via ${y}`)):g.stderr.write(_.dim(`Reviewing source strings via ${y} …\n`))):(C?.clear(),C=void 0,m(_.green(`✔`),`Reviewed source strings via ${y}`))}}let T;try{T=await h({messagesPath:c,sourceLocale:o.sourceLocale,format:o.format,locales:o.locales,codes:o.codes,rootDir:i,engineUrl:d(),languageModel:e.model,authToken:await u(),styleguide:f,ids:r(a.id),srcPath:l,onProgress:w})}catch(e){throw C?.clear(),e}let E=g.cwd();return{result:{...T,files:T.files.map(e=>({...e,file:b(E,e.file)})),findings:T.findings.map(e=>({...e,file:e.file?b(E,e.file):void 0,sourceFiles:e.sourceFiles.map(e=>b(E,e))}))}}},render:({result:e})=>C(e),ok:({result:e})=>e.findings.every(e=>e.status===`fixed`),json:({result:e})=>e});function C(e,t=s()){let{findings:n,reviewed:r,missingTranslations:i,quota:a}=e,o=[],c=new Map;for(let t of n){let n=t.file??e.sourceLocale,r=c.get(n)??[];r.push(t),c.set(n,r)}for(let[e,n]of c){let r=[`${_.cyan(e)} ${_.dim(`(source locale)`)}`];for(let e of n)r.push(_.dim(`│`)),r.push(...w(e,t));o.push(r.join(`
|
|
6
|
+
`))}let l=O(n,e.sourceLocale),u=Object.groupBy(e.files,e=>y(e.file)),d=Object.entries(u).map(([e,t=[]])=>{let n=Math.max(0,...t.map(e=>v(e.file).length)),r=t.map(e=>{let t=v(e.file).padEnd(n),r=l.get(e.file);return` ${t} ${k(e.reviewed,r?.fixed??0,r?.reported??0,a!==void 0)}`});return[_.dim(`${e}/`),...r].join(`
|
|
7
|
+
`)}).join(`
|
|
8
|
+
|
|
9
|
+
`);o.push(d),a&&o.push(_.yellow(`! Monthly included usage exhausted, reviewed as much as possible. Resets ${f(a.resetsAt)}`));let p=r===0?_.dim(`→ Add new strings for the source locale to review them before translation`):i>0?_.dim("→ Run `eloqnt translate` to translate"):void 0;return`\n${o.join(`
|
|
10
|
+
|
|
11
|
+
`)}${p?`\n\n${p}`:``}\n`}function w(e,t){let n=t-3-2,r=e.newId??e.id,o=T(e.id,e.before,n),s=[a(`${_.red(`-`)} ${_.dim(o)}`)],u;if(e.status===`fixed`){let t=T(r,e.after,n),i=E(e.via,e.sourceFiles,n-l(t));u=i?T(r,e.after,n-l(i)):t,s.push(a(`${_.green(`+`)} ${u}${i?_.dim(i):``}`))}else{let t=e.sourceFiles[0],i;if(t){let e=[t,D(t),v(t)].map(e=>` (apply manually in ${e})`);i=c(n,e)||e.at(-1)}else i=` (apply manually)`;u=T(r,e.after,n-l(i)),s.push(a(`${_.yellow(`!`)} ${u}${_.dim(i)}`))}let d=Math.min(l(u)+2,t-3);return s.push(a(_.yellow(`─┬${`─`.repeat(Math.max(0,d-2))}`))),s.push(a(` ${_.yellow(`╰─`)} ${i(e.note)}`)),s}function T(e,t,n){let r=l(`"${e}": ""`);return`"${e}": "${o(i(t),Math.max(0,n-r))}"`}function E(e,t,n){if(e!==`code`||t.length===0)return``;let r=t.length>1?[`(${t.length} call sites)`]:[`(${t[0]})`,`(${D(t[0])})`,`(${v(t[0])})`],i=c(n-1,r);return i?` ${i}`:``}function D(e){let t=e.split(`/`);return t.length<=2?e:`${t[0]}/…/${t.at(-1)}`}function O(e,t){let n=new Map;for(let r of e){let e=r.file??t,i=n.get(e)??{fixed:0,reported:0};i[r.status===`fixed`?`fixed`:`reported`]++,n.set(e,i)}return n}function k(e,t,n,r){if(e===0)return _.dim(`Nothing to review`);let i=[`${e} reviewed`];t===0&&n===0&&!r&&i.push(`no fixes needed`),t>0&&i.push(`${t} fixed`),n>0&&i.push(`${n} ${n===1?`needs`:`need`} a manual edit`);let a=i.join(`, `);return n>0?_.yellow(a):r?_.dim(a):_.green(a)}export{S as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"node:process";const t=new Intl.Segmenter,n=[[4352,4447],[9001,9002],[11904,12350],[12353,13311],[13312,19903],[19968,40959],[40960,42191],[44032,55203],[63744,64255],[65040,65049],[65072,65135],[65280,65376],[65504,65510],[126976,127743],[127744,129791],[131072,262141]];function r(e){let n=[];for(let{segment:r}of t.segment(e))n.push({text:r,width:c(r)});return n}function i(e){let n=0;for(let{segment:r}of t.segment(e))n+=c(r);return n}function a(t=80){let{columns:n,isTTY:r}=e.stdout;return!r||!n?t:Math.max(40,n)}function o(e,t){if(i(e)<=t)return e;let n=``,a=0;for(let i of r(e)){if(a+i.width>t-1)break;n+=i.text,a+=i.width}return`${n}…`}function s(e,t){return t.find(t=>i(t)<=e)??``}function c(e){let t=e.codePointAt(0)??0;return l(t)?0:n.some(([e,n])=>t>=e&&t<=n)?2:1}function l(e){return e<=31||e>=127&&e<=159||e>=768&&e<=879||e>=8203&&e<=8207||e>=8232&&e<=8238||e>=8288&&e<=8292||e===65279}export{o as a,a as i,s as n,i as r,r as t};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{t}from"./
|
|
2
|
-
`),O?(k=
|
|
1
|
+
import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{t}from"./createSpinner-BBkrpcrh.mjs";import{t as n}from"./resolvePaths-CKsEPHfH.mjs";import{t as r}from"./parseListArg-p5H1s5JC.mjs";import{a as i,i as a,n as o}from"./stringWidth-D0Z3LOKi.mjs";import{a as s,r as c,t as l}from"./urls-qvEAJDcV.mjs";import{n as u,r as d,t as f}from"./writeStep-CerCYWGN.mjs";import{translate as p}from"@eloqnt/sdk";import m from"node:process";import h from"picocolors";import{basename as g,dirname as _,relative as v}from"node:path";import{loadStyleguide as y}from"@eloqnt/sdk/_internal";var b=e({meta:{name:`translate`,description:`Translate strings to target locales (defaults to missing ones).`,requiresLogin:!0},args:{id:{type:`string`,description:`(Re-)translate these message ids (comma-separated)`},locale:{type:`string`,description:`Restrict to these target locales (comma-separated)`}},async execute({config:e,rootDir:l,args:u}){let{messages:g,srcPath:_}=e,b=n(g.path,l),x=_?n(_,l):void 0,S=await y({rootDir:l,path:e.styleguides}),C=e.model?`eloqnt/engine (${typeof e.model==`string`?e.model:e.model.modelId})`:`eloqnt/engine (hosted)`,w=r(u.locale),T=w??(Array.isArray(g.locales)?g.locales.filter(e=>e!==g.sourceLocale):void 0),E=`${T?.length?`${T.join(`, `)} `:``}via ${C}`,D=d(S,T??Object.keys(S.byLocale)),O=m.stderr.isTTY&&!u.json,k;function A(e,t,n){let r=`(${t}/${n})`,s=a()-4,c=`Translating ${e}% done`;return o(s,[`Translating ${E} · ${e}% done ${r}`,`Translating ${E} · ${e}% done`,`Translating ${e}% done ${r}`,c])||i(c,s)}let j=0;function M(e){if(!u.json){if(e.phase===`context-enrichment`){e.state===`started`?(m.stderr.write(`
|
|
2
|
+
`),O?(k=t({withGuide:!1}),k.start(`Context enrichment running`)):m.stderr.write(h.dim(`Context enrichment running …
|
|
3
3
|
`))):e.state===`completed`?(k?.clear(),k=void 0,f(h.green(`✔`),`Context enrichment complete`)):(m.stderr.write(`
|
|
4
|
-
`),f(h.dim(`–`),"Skipped context enrichment (no `srcPath` set)"));return}if(e.phase===`translate`){if(e.state===`started`)D?f(h.green(`✔`),D):f(h.dim(`–`),`No styleguides found`),O?(k=
|
|
5
|
-
`)):(k?.clear(),k=void 0,f(h.green(`✔`),`Post-translation checks done`))}}let N;try{N=await p({messagesPath:b,sourceLocale:g.sourceLocale,format:g.format,locales:g.locales,codes:g.codes,rootDir:l,engineUrl:c(),languageModel:e.model,authToken:await s(),styleguide:S,ids:
|
|
4
|
+
`),f(h.dim(`–`),"Skipped context enrichment (no `srcPath` set)"));return}if(e.phase===`translate`){if(e.state===`started`)D?f(h.green(`✔`),D):f(h.dim(`–`),`No styleguides found`),O?(k=t({withGuide:!1}),k.start(`Translating ${E}`)):m.stderr.write(h.dim(`Translating ${E} …\n`));else if(e.state===`progress`){let t=Math.floor(e.completedStrings/e.totalStrings*100);if(O)k?.message(A(t,e.completedStrings,e.totalStrings));else{let n=Math.floor(t/25);n>j&&n<4&&(j=n,m.stderr.write(h.dim(`Translating ${t}% done (${e.completedStrings}/${e.totalStrings}) …\n`)))}}else e.state===`stopped`?(k?.clear(),k=void 0):(k?.clear(),k=void 0,f(h.green(`✔`),`Translated ${E}`));return}e.state===`started`?O?(k=t({withGuide:!1}),k.start(`Post-translation checks running`)):m.stderr.write(h.dim(`Post-translation checks running …
|
|
5
|
+
`)):(k?.clear(),k=void 0,f(h.green(`✔`),`Post-translation checks done`))}}let N;try{N=await p({messagesPath:b,sourceLocale:g.sourceLocale,format:g.format,locales:g.locales,codes:g.codes,rootDir:l,engineUrl:c(),languageModel:e.model,authToken:await s(),styleguide:S,ids:r(u.id),onlyLocales:w,srcPath:x,onProgress:M})}catch(e){throw k?.clear(),e}let P=m.cwd(),F=N.targets.flatMap(e=>e.files.map(t=>({file:v(P,t.file),locale:e.locale,count:t.translated.length})));return{result:N,rows:F,complete:N.complete,noStyleguides:!D}},render({result:e,rows:t,complete:n,noStyleguides:r}){let i=Object.groupBy(t,e=>_(e.file));return`\n${Object.entries(i).map(([e,t=[]])=>{let n=Math.max(0,...t.map(e=>g(e.file).length)),r=t.map(e=>g(e.file)),i=r.length!==new Set(r).size,a=Math.max(0,...t.map(e=>e.locale.length)),o=t.map(e=>` ${g(e.file).padEnd(n)} ${i?`${h.dim(e.locale.padEnd(a))} `:``}${e.count===0?h.dim(`Nothing to translate`):h.green(`${e.count} translated`)}`);return[h.dim(`${e}/`),...o].join(`
|
|
6
6
|
`)}).join(`
|
|
7
7
|
|
|
8
8
|
`)}\n\n${n?h.green(`✔ Project fully translated`):e.quota?h.yellow(`! Monthly included usage exhausted, translated as much as possible. Resets ${u(e.quota.resetsAt)}`):h.dim(`✗ Partially translated, run eloqnt lint to see what's left`)}${r?`\n\n${h.dim(`→ Add a styleguide to improve your translation quality`)}\n${h.dim(` ${l}/docs/styleguides`)}`:``}`},json:({result:e})=>e});export{b as default};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{n as t,r as n,t as r}from"./withSpinner-CeQSfolX.mjs";import i from"node:process";import a from"picocolors";import{relative as o}from"node:path";import{uploadCrowdinContext as s}from"@eloqnt/sdk/_internal";var c=e({meta:{name:`upload`,description:`Upload the context in crowdin-context.jsonl to the strings in your Crowdin project.`},requiresConfig:!1,args:{branch:{type:`string`,description:`Sync with this branch of the Crowdin project`}},async execute({rootDir:e,args:t}){let n=await r({label:`Uploading context to Crowdin`,json:!!t.json,task:()=>s({rootDir:e,branch:t.branch})}),a=i.cwd();return{result:{...n,files:n.files.map(e=>({...e,file:o(a,e.file)}))}}},render({result:e}){let r=e.files.map(e=>{let t=[e.updated>0?a.green(`${e.updated} updated`):void 0,e.unchanged>0?a.dim(`${e.unchanged} unchanged`):void 0,e.skipped>0?a.dim(`${e.skipped} edited on Crowdin`):void 0,e.missing>0?a.yellow(`${e.missing} not on Crowdin`):void 0].filter(Boolean);return{file:e.file,detail:t.length>0?t.join(a.dim(`, `)):a.dim(`Nothing to upload`)}}),i=e.files.reduce((e,t)=>e+t.updated,0),o=i===0?a.dim(`Context on Crowdin is up to date`):a.green(`✔ Uploaded context for ${i} ${i===1?`string`:`strings`} to ${e.project.name}`)+(e.branch?` ${a.dim(`(${e.branch})`)}`:``);return`\n${[t(r),...n(e.warnings),o].join(`
|
|
2
|
+
|
|
3
|
+
`)}`},json:({result:e})=>e});export{c as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eloqnt/cli",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.33",
|
|
4
4
|
"description": "A linter for your translation files, with AI translation built in.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"citty": "^0.1.6",
|
|
38
38
|
"open": "^11.0.0",
|
|
39
39
|
"picocolors": "^1.1.1",
|
|
40
|
-
"@eloqnt/sdk": "0.6.
|
|
40
|
+
"@eloqnt/sdk": "0.6.31"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "^25.9.5"
|
package/dist/lint-Wu02Ge85.mjs
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{n as t,t as n}from"./report-CEfrIjER.mjs";import{a as r,i,o as a,r as o,t as s}from"./stringWidth-DvyI3S_b.mjs";import{lint as c}from"@eloqnt/sdk";import l from"node:process";import u from"picocolors";import{relative as d,resolve as f}from"node:path";var p=e({meta:{name:`lint`,description:`Statically analyze your source code and messages for common problems.`},args:{strict:{type:`boolean`,description:`Exit with a non-zero code when warnings are found`,default:!1}},async execute({config:e,rootDir:t,args:n}){let{messages:r,srcPath:i}=e,o=await c({messagesPath:a(r.path,t),sourceLocale:r.sourceLocale,format:r.format,locales:r.locales,codes:r.codes,srcPath:i?a(i,t):void 0,rules:e.lint?.rules,overrides:e.lint?.overrides,rootDir:t}),s=l.cwd();return{issues:o.map(e=>{let t=e;if(t.location&&(t={...t,location:{...t.location,file:d(s,t.location.file)}}),t.rule===`undefined-key`&&t.sourceReferences?.length){let e=t.sourceReferences.map(e=>({...e,path:d(s,e.path)})),n=e[0].line?`${e[0].path}:${e[0].line}`:e[0].path,i=e.length>1?` (+${e.length-1} more)`:``;t={...t,sourceReferences:e,message:`Used in ${n}${i} but not defined for ${r.sourceLocale}`}}return t}),sourceLocale:r.sourceLocale,noSrcPath:!i,strict:!!n.strict}},render:({issues:e,sourceLocale:t,noSrcPath:n})=>{let r=h(e,t),i=n?`\n${u.dim("– Skipped source code analysis due to absent `srcPath`")}\n${r}`:r;return l.env.GITHUB_ACTIONS&&e.length>0?`${i}\n${_(e)}`:i},ok:({issues:e,strict:t})=>t?e.length===0:!e.some(e=>e.severity===`error`),json:({issues:e})=>e.map(e=>({...e,docsUrl:m(e.rule)}))});function m(e){return`https://cli.eloqnt.dev/docs/lint-rules/${e}`}function h(e,t){if(e.length===0)return`\n${u.green(`No issues found`)}\n`;let n=Object.groupBy(e,e=>e.location?.file??e.locale),r=x(Object.entries(n),t).map(([e,n])=>S(e,n,n[0].locale===t)),i=e.filter(e=>e.severity===`error`).length,a=e.length-i,o=[i>0&&u.bold(u.red(`✗ ${g(i,`error`)}`)),a>0&&u.bold(u.yellow(`! ${g(a,`warning`)}`))].filter(Boolean).join(`
|
|
2
|
-
`),s=e.filter(e=>e.rule===`missing-translation`).length,c=[e.some(e=>e.rule!==`missing-translation`)&&u.dim(`→ Rule details: ${m(`<rule>`)}`),s>0&&u.dim(`→ Run \`eloqnt translate\` to fill in ${s} missing ${s===1?`translation`:`translations`}`)].filter(Boolean).join(`
|
|
3
|
-
`);return`\n${[...r,o,c].filter(Boolean).join(`
|
|
4
|
-
|
|
5
|
-
`)}\n`}function g(e,t){return`${e} ${e===1?t:`${t}s`}`}function _(e){return e.map(e=>{let t=e.rule===`undefined-key`&&e.sourceReferences?.length?e.sourceReferences[0]:void 0,n=t?.path??e.location?.file,r=[n&&`file=${b(v(n))}`,t?.line&&`line=${t.line}`,`title=${b(e.rule)}`].filter(Boolean).join(`,`),i=y(`"${e.key}": ${e.message}\n${m(e.rule)}`);return`::${e.severity} ${r}::${i}`}).join(`
|
|
6
|
-
`)}function v(e){let t=l.env.GITHUB_WORKSPACE;return t?d(t,f(e)):e}function y(e){return e.replace(/%/g,`%25`).replace(/\r/g,`%0D`).replace(/\n/g,`%0A`)}function b(e){return y(e).replace(/:/g,`%3A`).replace(/,/g,`%2C`)}function x(e,t){let n=e.findIndex(([,e])=>e[0].locale===t);if(n<=0)return e;let r=[...e],[i]=r.splice(n,1);return[i,...r]}function S(e,t,r){let i=[r?`${u.cyan(e)} ${u.dim(`(source locale)`)}`:u.cyan(e)];for(let e of t){i.push(u.dim(`│`));let{content:t,span:r}=C(e);i.push(n(t)),i.push(...T(r,e))}return i.join(`
|
|
7
|
-
`)}function C(e){let n=`"${e.key}"`,i=e.targetMessage??e.sourceMessage,a=w(n),s=e.highlight?.type===`value`||e.highlight?.type===`argument`,c=s?u.dim(n):n,l=u.dim(`: `),d=o(n);if(i!==void 0&&e.highlight?.type===`argument`){let n=t(i),r=e.highlight.token,s=n.indexOf(r);if(s>=0){let{inner:e,offset:t}=E(n,s,r.length,a);return{content:`${c}${l}"${e}"`,span:{column:d+3+t,length:o(r)}}}}let f=i===void 0?`"…"`:`"${r(t(i),a)}"`,p=`${c}${l}${s?f:u.dim(f)}`;return i!==void 0&&e.highlight?.type===`value`?{content:p,span:{column:d+2,length:o(f)}}:{content:p,span:{column:0,length:d}}}function w(e){let t=3+o(e)+2+2;return Math.max(24,Math.min(48,i()-t))}function T(e,t){let r=t.severity===`error`?u.red:u.yellow,i=Math.min(1,e.length-1),a=`─`.repeat(i)+`┬`+`─`.repeat(e.length-1-i),o=`${t.message} ${u.dim(`(${t.rule})`)}`;return[n(` `.repeat(e.column)+r(a)),n(`${` `.repeat(e.column+i)}${r(`╰─`)} ${o}`)]}function E(e,t,n,r){let i=s(e),a=i.reduce((e,t)=>e+t.width,0),o=D(i,t),c=D(i,t+n);if(a<=r)return{inner:e,offset:O(i,0,o)};let l=Math.max(O(i,o,c),r-2),u=o,d=0;for(;u>0&&d+i[u-1].width<=16;)u--,d+=i[u].width;let f=o;for(;f<i.length&&d+i[f].width<=l;)d+=i[f].width,f++;for(;u>0&&d+i[u-1].width<=l;)u--,d+=i[u].width;let p=u>0?`…`:``,m=f<i.length?`…`:``;return{inner:p+i.slice(u,f).map(e=>e.text).join(``)+m,offset:O(i,u,o)+p.length}}function D(e,t){let n=0;for(let r=0;r<e.length;r++){if(n>=t)return r;n+=e[r].text.length}return e.length}function O(e,t,n){let r=0;for(let i=t;i<n;i++)r+=e[i].width;return r}export{p as default,_ as formatGithubAnnotations,h as formatLint};
|
package/dist/source-CNaJNsTq.mjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{t}from"./parseListArg-p5H1s5JC.mjs";import{t as n}from"./createSpinner-BBkrpcrh.mjs";import{n as r,t as i}from"./report-CEfrIjER.mjs";import{a,i as o,n as s,o as c,r as l}from"./stringWidth-DvyI3S_b.mjs";import{a as u,r as d}from"./urls-qvEAJDcV.mjs";import{n as f,r as p,t as m}from"./writeStep-CerCYWGN.mjs";import{reviewSource as h}from"@eloqnt/sdk";import g from"node:process";import _ from"picocolors";import{basename as v,dirname as y,relative as b}from"node:path";import{loadStyleguide as x}from"@eloqnt/sdk/_internal";var S=e({meta:{name:`source`,description:`Review source strings for errors and fix them in place.`,requiresLogin:!0},args:{id:{type:`string`,description:`(Re-)review these message ids (comma-separated)`}},async execute({config:e,rootDir:r,args:i}){let{messages:a,srcPath:o}=e,s=c(a.path,r),l=o?c(o,r):void 0,f=await x({rootDir:r,path:e.styleguides}),v=p(f,[a.sourceLocale]),y=e.model?`eloqnt/engine (${typeof e.model==`string`?e.model:e.model.modelId})`:`eloqnt/engine (hosted)`,S=g.stderr.isTTY&&!i.json,C;function w(e){if(!i.json){if(e.phase===`context-enrichment`){e.state===`started`?(g.stderr.write(`
|
|
2
|
-
`),S?(C=n({withGuide:!1}),C.start(`Context enrichment running`)):g.stderr.write(_.dim(`Context enrichment running …
|
|
3
|
-
`))):e.state===`completed`?(C?.clear(),C=void 0,m(_.green(`✔`),`Context enrichment complete`)):(g.stderr.write(`
|
|
4
|
-
`),m(_.dim(`–`),"Skipped source code analysis due to absent `srcPath`"));return}if(e.phase===`post-checks`){e.state===`started`?S?(C=n({withGuide:!1}),C.start(`Post-review checks running`)):g.stderr.write(_.dim(`Post-review checks running …
|
|
5
|
-
`)):(C?.clear(),C=void 0,m(_.green(`✔`),`Post-review checks done`));return}e.state===`started`?(v?m(_.green(`✔`),v):m(_.dim(`–`),`No styleguides found`),S?(C=n({withGuide:!1}),C.start(`Reviewing source strings via ${y}`)):g.stderr.write(_.dim(`Reviewing source strings via ${y} …\n`))):(C?.clear(),C=void 0,m(_.green(`✔`),`Reviewed source strings via ${y}`))}}let T;try{T=await h({messagesPath:s,sourceLocale:a.sourceLocale,format:a.format,locales:a.locales,codes:a.codes,rootDir:r,engineUrl:d(),languageModel:e.model,authToken:await u(),styleguide:f,ids:t(i.id),srcPath:l,onProgress:w})}catch(e){throw C?.clear(),e}let E=g.cwd();return{result:{...T,files:T.files.map(e=>({...e,file:b(E,e.file)})),findings:T.findings.map(e=>({...e,file:e.file?b(E,e.file):void 0,sourceFiles:e.sourceFiles.map(e=>b(E,e))}))}}},render:({result:e})=>C(e),ok:({result:e})=>e.findings.every(e=>e.status===`fixed`),json:({result:e})=>e});function C(e,t=o()){let{findings:n,reviewed:r,missingTranslations:i,quota:a}=e,s=[],c=new Map;for(let t of n){let n=t.file??e.sourceLocale,r=c.get(n)??[];r.push(t),c.set(n,r)}for(let[e,n]of c){let r=[`${_.cyan(e)} ${_.dim(`(source locale)`)}`];for(let e of n)r.push(_.dim(`│`)),r.push(...w(e,t));s.push(r.join(`
|
|
6
|
-
`))}let l=O(n,e.sourceLocale),u=Object.groupBy(e.files,e=>y(e.file)),d=Object.entries(u).map(([e,t=[]])=>{let n=Math.max(0,...t.map(e=>v(e.file).length)),r=t.map(e=>{let t=v(e.file).padEnd(n),r=l.get(e.file);return` ${t} ${k(e.reviewed,r?.fixed??0,r?.reported??0,a!==void 0)}`});return[_.dim(`${e}/`),...r].join(`
|
|
7
|
-
`)}).join(`
|
|
8
|
-
|
|
9
|
-
`);s.push(d),a&&s.push(_.yellow(`! Monthly included usage exhausted, reviewed as much as possible. Resets ${f(a.resetsAt)}`));let p=r===0?_.dim(`→ Add new strings for the source locale to review them before translation`):i>0?_.dim("→ Run `eloqnt translate` to translate"):void 0;return`\n${s.join(`
|
|
10
|
-
|
|
11
|
-
`)}${p?`\n\n${p}`:``}\n`}function w(e,t){let n=t-3-2,a=e.newId??e.id,o=T(e.id,e.before,n),c=[i(`${_.red(`-`)} ${_.dim(o)}`)],u;if(e.status===`fixed`){let t=T(a,e.after,n),r=E(e.via,e.sourceFiles,n-l(t));u=r?T(a,e.after,n-l(r)):t,c.push(i(`${_.green(`+`)} ${u}${r?_.dim(r):``}`))}else{let t=e.sourceFiles[0],r;if(t){let e=[t,D(t),v(t)].map(e=>` (apply manually in ${e})`);r=s(n,e)||e.at(-1)}else r=` (apply manually)`;u=T(a,e.after,n-l(r)),c.push(i(`${_.yellow(`!`)} ${u}${_.dim(r)}`))}let d=Math.min(l(u)+2,t-3);return c.push(i(_.yellow(`─┬${`─`.repeat(Math.max(0,d-2))}`))),c.push(i(` ${_.yellow(`╰─`)} ${r(e.note)}`)),c}function T(e,t,n){let i=l(`"${e}": ""`);return`"${e}": "${a(r(t),Math.max(0,n-i))}"`}function E(e,t,n){if(e!==`code`||t.length===0)return``;let r=t.length>1?[`(${t.length} call sites)`]:[`(${t[0]})`,`(${D(t[0])})`,`(${v(t[0])})`],i=s(n-1,r);return i?` ${i}`:``}function D(e){let t=e.split(`/`);return t.length<=2?e:`${t[0]}/…/${t.at(-1)}`}function O(e,t){let n=new Map;for(let r of e){let e=r.file??t,i=n.get(e)??{fixed:0,reported:0};i[r.status===`fixed`?`fixed`:`reported`]++,n.set(e,i)}return n}function k(e,t,n,r){if(e===0)return _.dim(`Nothing to review`);let i=[`${e} reviewed`];t===0&&n===0&&!r&&i.push(`no fixes needed`),t>0&&i.push(`${t} fixed`),n>0&&i.push(`${n} ${n===1?`needs`:`need`} a manual edit`);let a=i.join(`, `);return n>0?_.yellow(a):r?_.dim(a):_.green(a)}export{S as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"node:process";import{resolve as t}from"node:path";function n(e,n){return(Array.isArray(e)?e:[e]).map(e=>typeof e==`string`?t(n,e):{source:t(n,e.source),targets:t(n,e.targets)})}const r=new Intl.Segmenter,i=[[4352,4447],[9001,9002],[11904,12350],[12353,13311],[13312,19903],[19968,40959],[40960,42191],[44032,55203],[63744,64255],[65040,65049],[65072,65135],[65280,65376],[65504,65510],[126976,127743],[127744,129791],[131072,262141]];function a(e){let t=[];for(let{segment:n}of r.segment(e))t.push({text:n,width:u(n)});return t}function o(e){let t=0;for(let{segment:n}of r.segment(e))t+=u(n);return t}function s(t=80){let{columns:n,isTTY:r}=e.stdout;return!r||!n?t:Math.max(40,n)}function c(e,t){if(o(e)<=t)return e;let n=``,r=0;for(let i of a(e)){if(r+i.width>t-1)break;n+=i.text,r+=i.width}return`${n}…`}function l(e,t){return t.find(t=>o(t)<=e)??``}function u(e){let t=e.codePointAt(0)??0;return d(t)?0:i.some(([e,n])=>t>=e&&t<=n)?2:1}function d(e){return e<=31||e>=127&&e<=159||e>=768&&e<=879||e>=8203&&e<=8207||e>=8232&&e<=8238||e>=8288&&e<=8292||e===65279}export{c as a,s as i,l as n,n as o,o as r,a as t};
|