decocms 2.286.0 → 2.286.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/dist/client/assets/{AlertCircle-DTmaHldD.js → AlertCircle-Bgzr6uRA.js} +1 -1
- package/dist/client/assets/{ArrowNarrowLeft-DlPeFc4v.js → ArrowNarrowLeft-ByrdB8Dd.js} +1 -1
- package/dist/client/assets/{CheckCircle-DJ3lme5R.js → CheckCircle-88bls7UK.js} +1 -1
- package/dist/client/assets/{ChevronDown-DGnjAtqs.js → ChevronDown-Jd-cYHC-.js} +1 -1
- package/dist/client/assets/{ChevronRight-DV9No7GF.js → ChevronRight-71i8ke8L.js} +1 -1
- package/dist/client/assets/{ChevronUp-BkSgkwhO.js → ChevronUp-D_szSdLd.js} +1 -1
- package/dist/client/assets/{Container-B1nHZdmn.js → Container-DWaKXfYv.js} +1 -1
- package/dist/client/assets/{DotsVertical-Bp2tW8JI.js → DotsVertical-CjXyjLNU.js} +1 -1
- package/dist/client/assets/{LinkExternal01-BBbCPDtX.js → LinkExternal01-DB08YntP.js} +1 -1
- package/dist/client/assets/{Lock01-DpPIS3K7.js → Lock01-dBhVogWg.js} +1 -1
- package/dist/client/assets/{Palette-CI8n49a8.js → Palette-DuWQiO51.js} +1 -1
- package/dist/client/assets/{Play-DKFUTU3G.js → Play-D7pqvkYq.js} +1 -1
- package/dist/client/assets/{Plus-oXFwCrYz.js → Plus-BzxOIhxj.js} +1 -1
- package/dist/client/assets/{RefreshCcw01-B10mKiE2.js → RefreshCcw01-BxULs6ec.js} +1 -1
- package/dist/client/assets/{SearchMd-BRJBvWf4.js → SearchMd-D6tCV38D.js} +1 -1
- package/dist/client/assets/{Settings02-Dm9dFDqk.js → Settings02-MyfUtBA4.js} +1 -1
- package/dist/client/assets/{Shield01-BZJVBd5S.js → Shield01-CMw4M4Ml.js} +1 -1
- package/dist/client/assets/{Star01-_IJK5Yjt.js → Star01-DZHrISf9.js} +1 -1
- package/dist/client/assets/{Sun-QqE1VnS_.js → Sun-C8X8gjZW.js} +1 -1
- package/dist/client/assets/{Tool01-CKowkGsd.js → Tool01-BscqkhhO.js} +1 -1
- package/dist/client/assets/{Trash01-C6bAXG6g.js → Trash01-DZpzvWVW.js} +1 -1
- package/dist/client/assets/{User01-C2-anwoO.js → User01-VHn0SqBP.js} +1 -1
- package/dist/client/assets/{Users03-DqYvPeZM.js → Users03-DwNyb_q2.js} +1 -1
- package/dist/client/assets/{X-i9zBn6Hn.js → X-BuUY-erD.js} +1 -1
- package/dist/client/assets/{XCircle-C1sJYG9R.js → XCircle-BFZeumzD.js} +1 -1
- package/dist/client/assets/{XClose-BbIo6xHe.js → XClose-ANREDbeo.js} +1 -1
- package/dist/client/assets/{Zap-KmbRMccM.js → Zap-BxJkZzJb.js} +1 -1
- package/dist/client/assets/{ZapSquare-DT93lGV4.js → ZapSquare-Bz3HDhTc.js} +1 -1
- package/dist/client/assets/{accordion-BV3tm7bj.js → accordion-DK_chPAh.js} +1 -1
- package/dist/client/assets/{agent-icon-CyE6nkC1.js → agent-icon-DKQKq---.js} +1 -1
- package/dist/client/assets/{agents-list-7o6gZt-q.js → agents-list-DBdCJGrz.js} +1 -1
- package/dist/client/assets/ai-providers-BhNFwI7O.js +1 -0
- package/dist/client/assets/{alert-dialog-CicrCOay.js → alert-dialog-CtGXaT-Y.js} +1 -1
- package/dist/client/assets/{auth-catchall-Cyd7fWQv.js → auth-catchall-B4ADnlpm.js} +1 -1
- package/dist/client/assets/{automation-list-row-B4Vfg4UC.js → automation-list-row-B_yW9vLo.js} +1 -1
- package/dist/client/assets/{automations-DRM_lJom.js → automations-B3iEjSty.js} +1 -1
- package/dist/client/assets/{avatar-CF1bgUpD.js → avatar-DcLXZkYK.js} +1 -1
- package/dist/client/assets/{badge-s_TAXGUN.js → badge-BJBM0LXp.js} +1 -1
- package/dist/client/assets/brand-context-BahSISOs.js +1 -0
- package/dist/client/assets/{card-CaekC2K0.js → card-DqrPrhd5.js} +1 -1
- package/dist/client/assets/{chat-context-DP5UfIrn.js → chat-context-DfEaB6Uj.js} +1 -1
- package/dist/client/assets/{checkbox-DznLgPgR.js → checkbox-Dplb_VaM.js} +1 -1
- package/dist/client/assets/{collection-detail-CTQuhG7N.js → collection-detail-KgUZfuij.js} +1 -1
- package/dist/client/assets/{collection-display-button-BgYKhoGQ.js → collection-display-button-DecHBxzk.js} +1 -1
- package/dist/client/assets/{collection-search-Bo2bOvRn.js → collection-search-B_zW9IS4.js} +1 -1
- package/dist/client/assets/{collection-search-DMqppne6.js → collection-search-DF-hPm66.js} +1 -1
- package/dist/client/assets/{collection-table-wrapper-KnWZIddd.js → collection-table-wrapper-DG-B8ykv.js} +1 -1
- package/dist/client/assets/{collection-tabs-CU6MCzSn.js → collection-tabs-tHg8euhu.js} +1 -1
- package/dist/client/assets/{collections-DHmXATua.js → collections-KKlyNHih.js} +1 -1
- package/dist/client/assets/{command-D4w2xkZT.js → command-Cpu7RbMv.js} +1 -1
- package/dist/client/assets/{connection-card-DBz-rrLk.js → connection-card-CD0fnfut.js} +1 -1
- package/dist/client/assets/{connection-detail-zHqb5ZSw.js → connection-detail-CFY9ol5g.js} +1 -1
- package/dist/client/assets/{connection-form-helpers-CBEV0IXi.js → connection-form-helpers-DVewXDLo.js} +1 -1
- package/dist/client/assets/{connections-CHiGbl1F.js → connections-B-Liq5Ll.js} +1 -1
- package/dist/client/assets/{constants-v4RUVkEN.js → constants-D7DNenhk.js} +1 -1
- package/dist/client/assets/{constants-DDHDU3PV.js → constants-aD7HJ6sY.js} +1 -1
- package/dist/client/assets/{dialog-C4lREl-t.js → dialog-nGTWjCEa.js} +1 -1
- package/dist/client/assets/{drawer-BTCEaGGQ.js → drawer-DyPUsgdj.js} +1 -1
- package/dist/client/assets/{dropdown-menu-v2GifVOh.js → dropdown-menu-Cc_jn9Z7.js} +1 -1
- package/dist/client/assets/{dynamic-plugin-layout-CVBBnlEt.js → dynamic-plugin-layout-Bun8S8Gm.js} +1 -1
- package/dist/client/assets/{empty-state-DdKZ_is7.js → empty-state-CqQa90x5.js} +1 -1
- package/dist/client/assets/{empty-state-BdQTFnZA.js → empty-state-DgThOXBB.js} +1 -1
- package/dist/client/assets/{extract-connection-data-CfXvFcGA.js → extract-connection-data-Bx0uarS8.js} +1 -1
- package/dist/client/assets/{features-fsR9zLkr.js → features-ekquKatz.js} +1 -1
- package/dist/client/assets/{form-D7DN8UcB.js → form-DB-TdsHz.js} +1 -1
- package/dist/client/assets/{general-WQbdllPl.js → general-BrK_oI6y.js} +1 -1
- package/dist/client/assets/{github-repo-picker-DZqLC6FL.js → github-repo-picker-CwCtQ7G3.js} +1 -1
- package/dist/client/assets/{index-DBclwIf_.js → index-Amg25tew.js} +1 -1
- package/dist/client/assets/{index-D-RCnwJQ.js → index-BZopUfMN.js} +1 -1
- package/dist/client/assets/{index-qXZ0t4XR.js → index-BfYZ2YG_.js} +4 -4
- package/dist/client/assets/{index-FnxI6OGR.js → index-CT9V-xpg.js} +1 -1
- package/dist/client/assets/{index-C5AR7k1c.js → index-CwstDhH7.js} +1 -1
- package/dist/client/assets/{index-D34n6J5J.js → index-DhJrYN5i.js} +2 -2
- package/dist/client/assets/{index-CHKi_s_a.js → index-DtMbbDUN.js} +1 -1
- package/dist/client/assets/{index-e3AFJ_dX.js → index-DtdOoKdU.js} +1 -1
- package/dist/client/assets/{index-zDq2Zqio.js → index-DvgxnJsz.js} +1 -1
- package/dist/client/assets/{index-DnJZfbsP.js → index-pD6VF9-w.js} +1 -1
- package/dist/client/assets/{infiniteQueryObserver-1_M-sq16.js → infiniteQueryObserver-B_9sKQsI.js} +1 -1
- package/dist/client/assets/{input-urtyHxks.js → input-COFLoOjb.js} +1 -1
- package/dist/client/assets/{integration-icon-Cdkk9YPE.js → integration-icon-DKrcAAs9.js} +1 -1
- package/dist/client/assets/{label-Bt4h_QUk.js → label-BZVcstmy.js} +1 -1
- package/dist/client/assets/{layout-B5SDe6IW.js → layout-Dp5y9gtR.js} +1 -1
- package/dist/client/assets/{login-7zFMf3C1.js → login-ComGApTe.js} +1 -1
- package/dist/client/assets/{members-Dy7hWkQ8.js → members-CHnKVrrd.js} +1 -1
- package/dist/client/assets/{monaco-editor-lveN-AoO.js → monaco-editor-EL8K9shU.js} +1 -1
- package/dist/client/assets/{monitoring-stats-row-D3x0_phM.js → monitoring-stats-row-D9crys0K.js} +1 -1
- package/dist/client/assets/{oauth-callback-BJALVgfT.js → oauth-callback-B0mEhNIK.js} +1 -1
- package/dist/client/assets/{oauth-callback-ai-provider-o8Hfz-wL.js → oauth-callback-ai-provider-Dj0EctfO.js} +1 -1
- package/dist/client/assets/{onboarding-DlI3PsIA.js → onboarding-czNV0UuI.js} +1 -1
- package/dist/client/assets/{org-layout-DPzm8vzJ.js → org-layout-CGtnLM_Q.js} +1 -1
- package/dist/client/assets/{org-plugin-layout-DB72TzxO.js → org-plugin-layout-Ba2ZEzcE.js} +1 -1
- package/dist/client/assets/{plugin-empty-state-BzyxU1IF.js → plugin-empty-state-fmAUJ6xt.js} +1 -1
- package/dist/client/assets/{plugin-header-hJH6-4Nr.js → plugin-header-3c9kItnR.js} +1 -1
- package/dist/client/assets/{plugin-layout-l_MDXBYc.js → plugin-layout-CUFHRJeM.js} +1 -1
- package/dist/client/assets/{popover-j_PzMtdY.js → popover-Bo1-wNsY.js} +1 -1
- package/dist/client/assets/{profile-lf_QL3Ye.js → profile-C4ZfFzUo.js} +1 -1
- package/dist/client/assets/{project-app-view-DuFzKNXE.js → project-app-view-DbITEuQv.js} +1 -1
- package/dist/client/assets/registry-CrUw5Sj_.js +2 -0
- package/dist/client/assets/{registry-layout-DRb_iR_v.js → registry-layout-q6bMBk9s.js} +1 -1
- package/dist/client/assets/{required-auth-layout-C2o7AZ4K.js → required-auth-layout-CP-yDaO3.js} +1 -1
- package/dist/client/assets/{reset-password-DTEY3I_i.js → reset-password-CpFcPkI4.js} +1 -1
- package/dist/client/assets/{roles-DW1_Kn6r.js → roles-CSJcHSQ8.js} +1 -1
- package/dist/client/assets/{scroll-area-BebfgLv6.js → scroll-area-CXUp8wR9.js} +1 -1
- package/dist/client/assets/{search-input-dmuYGYsk.js → search-input-ClG6niuo.js} +1 -1
- package/dist/client/assets/{select-CePxsPeP.js → select-Cn3ZnqjJ.js} +1 -1
- package/dist/client/assets/{select-model-QQ7yjZl9.js → select-model-BwE-9vfJ.js} +1 -1
- package/dist/client/assets/{settings-layout-Cd1tdTnr.js → settings-layout-dHGH4vpw.js} +1 -1
- package/dist/client/assets/{shell-layout-BE22YA40.js → shell-layout-BsqL_vND.js} +1 -1
- package/dist/client/assets/{skeleton-C9NsUzIb.js → skeleton-DOcx8lZU.js} +1 -1
- package/dist/client/assets/{sso-QSGlyP2n.js → sso-37Vu3qt9.js} +1 -1
- package/dist/client/assets/{store-BB9yi6PD.js → store-D1kidhJ8.js} +1 -1
- package/dist/client/assets/store-registry-qx_8ffch.js +2 -0
- package/dist/client/assets/{switch-VBeL01bM.js → switch-ihM2hYRH.js} +1 -1
- package/dist/client/assets/{table-CQMW-Toa.js → table-CAUXYO7-.js} +1 -1
- package/dist/client/assets/{tabs-DOoLL5wa.js → tabs-DcOxSeRf.js} +1 -1
- package/dist/client/assets/{task-status-vvRP86lz.js → task-status-CHfFeACA.js} +1 -1
- package/dist/client/assets/{textarea-Ie4QUdo5.js → textarea-CsnX9Ktr.js} +1 -1
- package/dist/client/assets/{toggle-group-C077Smww.js → toggle-group-_HWF3GFc.js} +1 -1
- package/dist/client/assets/{tools-list-UnPsMGhr.js → tools-list-A0gJUqTb.js} +1 -1
- package/dist/client/assets/{types-D4PfKOFF.js → types-BGXCye_w.js} +1 -1
- package/dist/client/assets/{use-ai-providers-DHuVj1kn.js → use-ai-providers-DSLKay0D.js} +1 -1
- package/dist/client/assets/{use-collections-DRlHpXQL.js → use-collections-DvPoAlor.js} +1 -1
- package/dist/client/assets/{use-connection-Cif-LY0f.js → use-connection-MU3rXx28.js} +1 -1
- package/dist/client/assets/{use-copy-uiSuMvtc.js → use-copy-tC0v6ypy.js} +1 -1
- package/dist/client/assets/{use-create-virtual-mcp-CBpw3zXA.js → use-create-virtual-mcp-C-LLRhrB.js} +1 -1
- package/dist/client/assets/{use-decopilot-events-Dpt6CcIN.js → use-decopilot-events-fHBaJaln.js} +1 -1
- package/dist/client/assets/{use-delete-connection-BZmW9ZAz.js → use-delete-connection-CowwQ4CA.js} +1 -1
- package/dist/client/assets/{use-infinite-scroll-CWlV3gJA.js → use-infinite-scroll-BUM8dH47.js} +1 -1
- package/dist/client/assets/{use-list-state-BJZWeXjY.js → use-list-state-Ba4O0IuX.js} +1 -1
- package/dist/client/assets/{use-mcp-tools-BYVtg7WH.js → use-mcp-tools-B5zpuics.js} +1 -1
- package/dist/client/assets/{use-members-M_p47epa.js → use-members-Bhu2ZnQb.js} +1 -1
- package/dist/client/assets/{use-mobile-CxvYCzu9.js → use-mobile-C4Yo3nsX.js} +1 -1
- package/dist/client/assets/{use-navigate-to-agent-CFIKBq0L.js → use-navigate-to-agent-Bx0DB5DW.js} +1 -1
- package/dist/client/assets/{use-org-sso-CACnH9GQ.js → use-org-sso-BK-ft_ER.js} +1 -1
- package/dist/client/assets/{use-organization-roles-o4lVU0iD.js → use-organization-roles-uEcrMWhG.js} +1 -1
- package/dist/client/assets/{use-organization-settings-BD9CIHH5.js → use-organization-settings-CMC2yyUM.js} +1 -1
- package/dist/client/assets/{use-registry-connections-DR_etJ2H.js → use-registry-connections-Biq_9qgb.js} +1 -1
- package/dist/client/assets/{use-status-sounds-Ce7WandB.js → use-status-sounds-DfhTS64d.js} +1 -1
- package/dist/client/assets/{use-tasks-Dpp1DK1f.js → use-tasks-DofxyZR4.js} +1 -1
- package/dist/client/assets/{use-view-mode-CZPzVaxj.js → use-view-mode-DSeYcON6.js} +1 -1
- package/dist/client/assets/{use-virtual-mcp-0vHwLInn.js → use-virtual-mcp-WT1ZdgMM.js} +1 -1
- package/dist/client/assets/useInfiniteQuery-Gkc0b2zi.js +1 -0
- package/dist/client/assets/useSuspenseInfiniteQuery-YePUpUV3.js +1 -0
- package/dist/client/assets/{user-xj80BAo3.js → user-5oBDTi_W.js} +1 -1
- package/dist/client/assets/{view-mode-toggle-D5CGwPOj.js → view-mode-toggle-BvyYLass.js} +1 -1
- package/dist/client/assets/{workflow-CD_DiE5j.js → workflow-DoVF6xyx.js} +1 -1
- package/dist/client/assets/workflow-detail-XUi-wHY3.js +1 -0
- package/dist/client/index.html +1 -1
- package/dist/server/cli.js +1 -1
- package/dist/server/node_modules/get-east-asian-width/index.d.ts +60 -0
- package/dist/server/node_modules/get-east-asian-width/index.js +30 -0
- package/dist/server/node_modules/get-east-asian-width/lookup-data.js +18 -0
- package/dist/server/node_modules/get-east-asian-width/lookup.js +135 -0
- package/dist/server/node_modules/get-east-asian-width/package.json +71 -0
- package/dist/server/node_modules/get-east-asian-width/readme.md +65 -0
- package/dist/server/node_modules/get-east-asian-width/utilities.js +24 -0
- package/dist/server/node_modules/slice-ansi/index.d.ts +19 -0
- package/dist/server/node_modules/slice-ansi/index.js +260 -0
- package/dist/server/node_modules/{is-fullwidth-code-point → slice-ansi}/license +1 -0
- package/dist/server/node_modules/slice-ansi/package.json +59 -0
- package/dist/server/node_modules/slice-ansi/readme.md +54 -0
- package/dist/server/node_modules/slice-ansi/tokenize-ansi.js +752 -0
- package/package.json +1 -1
- package/dist/client/assets/ai-providers-DI3UF9nU.js +0 -1
- package/dist/client/assets/brand-context-iopLFZ2k.js +0 -1
- package/dist/client/assets/registry-D3m_WKwq.js +0 -2
- package/dist/client/assets/store-registry-BSp-W72J.js +0 -2
- package/dist/client/assets/useInfiniteQuery-B4w-6TrV.js +0 -1
- package/dist/client/assets/useSuspenseInfiniteQuery-WURyRq6p.js +0 -1
- package/dist/client/assets/workflow-detail-CxWEb-ID.js +0 -1
- package/dist/server/node_modules/ansi-regex/index.d.ts +0 -33
- package/dist/server/node_modules/ansi-regex/index.js +0 -14
- package/dist/server/node_modules/ansi-regex/package.json +0 -61
- package/dist/server/node_modules/ansi-regex/readme.md +0 -66
- package/dist/server/node_modules/emoji-regex/LICENSE-MIT.txt +0 -20
- package/dist/server/node_modules/emoji-regex/README.md +0 -107
- package/dist/server/node_modules/emoji-regex/index.d.ts +0 -3
- package/dist/server/node_modules/emoji-regex/index.js +0 -4
- package/dist/server/node_modules/emoji-regex/index.mjs +0 -4
- package/dist/server/node_modules/emoji-regex/package.json +0 -45
- package/dist/server/node_modules/environment/index.d.ts +0 -74
- package/dist/server/node_modules/environment/index.js +0 -47
- package/dist/server/node_modules/environment/license +0 -9
- package/dist/server/node_modules/environment/package.json +0 -74
- package/dist/server/node_modules/environment/readme.md +0 -94
- package/dist/server/node_modules/escape-string-regexp/index.d.ts +0 -18
- package/dist/server/node_modules/escape-string-regexp/index.js +0 -11
- package/dist/server/node_modules/escape-string-regexp/license +0 -9
- package/dist/server/node_modules/escape-string-regexp/package.json +0 -43
- package/dist/server/node_modules/escape-string-regexp/readme.md +0 -29
- package/dist/server/node_modules/is-fullwidth-code-point/index.d.ts +0 -17
- package/dist/server/node_modules/is-fullwidth-code-point/index.js +0 -12
- package/dist/server/node_modules/is-fullwidth-code-point/package.json +0 -53
- package/dist/server/node_modules/is-fullwidth-code-point/readme.md +0 -31
- package/dist/server/node_modules/is-unicode-supported/index.d.ts +0 -12
- package/dist/server/node_modules/is-unicode-supported/index.js +0 -21
- package/dist/server/node_modules/is-unicode-supported/license +0 -9
- package/dist/server/node_modules/is-unicode-supported/package.json +0 -47
- package/dist/server/node_modules/is-unicode-supported/readme.md +0 -35
- package/dist/server/node_modules/onetime/index.d.ts +0 -64
- package/dist/server/node_modules/onetime/index.js +0 -44
- package/dist/server/node_modules/onetime/license +0 -9
- package/dist/server/node_modules/onetime/package.json +0 -43
- package/dist/server/node_modules/onetime/readme.md +0 -94
- package/dist/server/node_modules/restore-cursor/index.d.ts +0 -11
- package/dist/server/node_modules/restore-cursor/index.js +0 -11
- package/dist/server/node_modules/restore-cursor/license +0 -9
- package/dist/server/node_modules/restore-cursor/package.json +0 -55
- package/dist/server/node_modules/restore-cursor/readme.md +0 -31
- package/dist/server/node_modules/string-width/index.d.ts +0 -39
- package/dist/server/node_modules/string-width/index.js +0 -82
- package/dist/server/node_modules/string-width/license +0 -9
- package/dist/server/node_modules/string-width/package.json +0 -64
- package/dist/server/node_modules/string-width/readme.md +0 -66
- /package/dist/server/node_modules/{ansi-regex → get-east-asian-width}/license +0 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export type WidthType = 'fullwidth' | 'halfwidth' | 'wide' | 'narrow' | 'neutral' | 'ambiguous';
|
|
2
|
+
|
|
3
|
+
export type Options = {
|
|
4
|
+
/**
|
|
5
|
+
Whether to treat an `'ambiguous'` character as wide.
|
|
6
|
+
|
|
7
|
+
@default true
|
|
8
|
+
|
|
9
|
+
@example
|
|
10
|
+
```
|
|
11
|
+
import {eastAsianWidth} from 'get-east-asian-width';
|
|
12
|
+
|
|
13
|
+
const codePoint = '⛣'.codePointAt(0);
|
|
14
|
+
|
|
15
|
+
console.log(eastAsianWidth(codePoint));
|
|
16
|
+
//=> 1
|
|
17
|
+
|
|
18
|
+
console.log(eastAsianWidth(codePoint, {ambiguousAsWide: true}));
|
|
19
|
+
//=> 2
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
> Ambiguous characters behave like wide or narrow characters depending on the context (language tag, script identification, associated font, source of data, or explicit markup; all can provide the context). __If the context cannot be established reliably, they should be treated as narrow characters by default.__
|
|
23
|
+
> - http://www.unicode.org/reports/tr11/
|
|
24
|
+
*/
|
|
25
|
+
readonly ambiguousAsWide?: boolean;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
Returns the width as a number for the given code point.
|
|
30
|
+
|
|
31
|
+
@param codePoint - A Unicode code point.
|
|
32
|
+
|
|
33
|
+
@example
|
|
34
|
+
```
|
|
35
|
+
import {eastAsianWidth} from 'get-east-asian-width';
|
|
36
|
+
|
|
37
|
+
const codePoint = '字'.codePointAt(0);
|
|
38
|
+
|
|
39
|
+
console.log(eastAsianWidth(codePoint));
|
|
40
|
+
//=> 2
|
|
41
|
+
```
|
|
42
|
+
*/
|
|
43
|
+
export function eastAsianWidth(codePoint: number, options?: Options): 1 | 2;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
Returns the type of “East Asian Width” for the given code point.
|
|
47
|
+
|
|
48
|
+
@param codePoint - A Unicode code point.
|
|
49
|
+
|
|
50
|
+
@example
|
|
51
|
+
```
|
|
52
|
+
import {eastAsianWidthType} from 'get-east-asian-width';
|
|
53
|
+
|
|
54
|
+
const codePoint = '字'.codePointAt(0);
|
|
55
|
+
|
|
56
|
+
console.log(eastAsianWidthType(codePoint));
|
|
57
|
+
//=> 'wide'
|
|
58
|
+
```
|
|
59
|
+
*/
|
|
60
|
+
export function eastAsianWidthType(codePoint: number): WidthType;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {getCategory, isAmbiguous, isFullWidth, isWide} from './lookup.js';
|
|
2
|
+
|
|
3
|
+
function validate(codePoint) {
|
|
4
|
+
if (!Number.isSafeInteger(codePoint)) {
|
|
5
|
+
throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function eastAsianWidthType(codePoint) {
|
|
10
|
+
validate(codePoint);
|
|
11
|
+
|
|
12
|
+
return getCategory(codePoint);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function eastAsianWidth(codePoint, {ambiguousAsWide = false} = {}) {
|
|
16
|
+
validate(codePoint);
|
|
17
|
+
|
|
18
|
+
if (
|
|
19
|
+
isFullWidth(codePoint)
|
|
20
|
+
|| isWide(codePoint)
|
|
21
|
+
|| (ambiguousAsWide && isAmbiguous(codePoint))
|
|
22
|
+
) {
|
|
23
|
+
return 2;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return 1;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Private exports for https://github.com/sindresorhus/is-fullwidth-code-point
|
|
30
|
+
export {isFullWidth as _isFullWidth, isWide as _isWide} from './lookup.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Generated by scripts/build.js
|
|
2
|
+
|
|
3
|
+
// prettier-ignore
|
|
4
|
+
const ambiguousRanges = [161, 161, 164, 164, 167, 168, 170, 170, 173, 174, 176, 180, 182, 186, 188, 191, 198, 198, 208, 208, 215, 216, 222, 225, 230, 230, 232, 234, 236, 237, 240, 240, 242, 243, 247, 250, 252, 252, 254, 254, 257, 257, 273, 273, 275, 275, 283, 283, 294, 295, 299, 299, 305, 307, 312, 312, 319, 322, 324, 324, 328, 331, 333, 333, 338, 339, 358, 359, 363, 363, 462, 462, 464, 464, 466, 466, 468, 468, 470, 470, 472, 472, 474, 474, 476, 476, 593, 593, 609, 609, 708, 708, 711, 711, 713, 715, 717, 717, 720, 720, 728, 731, 733, 733, 735, 735, 768, 879, 913, 929, 931, 937, 945, 961, 963, 969, 1025, 1025, 1040, 1103, 1105, 1105, 8208, 8208, 8211, 8214, 8216, 8217, 8220, 8221, 8224, 8226, 8228, 8231, 8240, 8240, 8242, 8243, 8245, 8245, 8251, 8251, 8254, 8254, 8308, 8308, 8319, 8319, 8321, 8324, 8364, 8364, 8451, 8451, 8453, 8453, 8457, 8457, 8467, 8467, 8470, 8470, 8481, 8482, 8486, 8486, 8491, 8491, 8531, 8532, 8539, 8542, 8544, 8555, 8560, 8569, 8585, 8585, 8592, 8601, 8632, 8633, 8658, 8658, 8660, 8660, 8679, 8679, 8704, 8704, 8706, 8707, 8711, 8712, 8715, 8715, 8719, 8719, 8721, 8721, 8725, 8725, 8730, 8730, 8733, 8736, 8739, 8739, 8741, 8741, 8743, 8748, 8750, 8750, 8756, 8759, 8764, 8765, 8776, 8776, 8780, 8780, 8786, 8786, 8800, 8801, 8804, 8807, 8810, 8811, 8814, 8815, 8834, 8835, 8838, 8839, 8853, 8853, 8857, 8857, 8869, 8869, 8895, 8895, 8978, 8978, 9312, 9449, 9451, 9547, 9552, 9587, 9600, 9615, 9618, 9621, 9632, 9633, 9635, 9641, 9650, 9651, 9654, 9655, 9660, 9661, 9664, 9665, 9670, 9672, 9675, 9675, 9678, 9681, 9698, 9701, 9711, 9711, 9733, 9734, 9737, 9737, 9742, 9743, 9756, 9756, 9758, 9758, 9792, 9792, 9794, 9794, 9824, 9825, 9827, 9829, 9831, 9834, 9836, 9837, 9839, 9839, 9886, 9887, 9919, 9919, 9926, 9933, 9935, 9939, 9941, 9953, 9955, 9955, 9960, 9961, 9963, 9969, 9972, 9972, 9974, 9977, 9979, 9980, 9982, 9983, 10045, 10045, 10102, 10111, 11094, 11097, 12872, 12879, 57344, 63743, 65024, 65039, 65533, 65533, 127232, 127242, 127248, 127277, 127280, 127337, 127344, 127373, 127375, 127376, 127387, 127404, 917760, 917999, 983040, 1048573, 1048576, 1114109];
|
|
5
|
+
|
|
6
|
+
// prettier-ignore
|
|
7
|
+
const fullwidthRanges = [12288, 12288, 65281, 65376, 65504, 65510];
|
|
8
|
+
|
|
9
|
+
// prettier-ignore
|
|
10
|
+
const halfwidthRanges = [8361, 8361, 65377, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, 65512, 65518];
|
|
11
|
+
|
|
12
|
+
// prettier-ignore
|
|
13
|
+
const narrowRanges = [32, 126, 162, 163, 165, 166, 172, 172, 175, 175, 10214, 10221, 10629, 10630];
|
|
14
|
+
|
|
15
|
+
// prettier-ignore
|
|
16
|
+
const wideRanges = [4352, 4447, 8986, 8987, 9001, 9002, 9193, 9196, 9200, 9200, 9203, 9203, 9725, 9726, 9748, 9749, 9776, 9783, 9800, 9811, 9855, 9855, 9866, 9871, 9875, 9875, 9889, 9889, 9898, 9899, 9917, 9918, 9924, 9925, 9934, 9934, 9940, 9940, 9962, 9962, 9970, 9971, 9973, 9973, 9978, 9978, 9981, 9981, 9989, 9989, 9994, 9995, 10024, 10024, 10060, 10060, 10062, 10062, 10067, 10069, 10071, 10071, 10133, 10135, 10160, 10160, 10175, 10175, 11035, 11036, 11088, 11088, 11093, 11093, 11904, 11929, 11931, 12019, 12032, 12245, 12272, 12287, 12289, 12350, 12353, 12438, 12441, 12543, 12549, 12591, 12593, 12686, 12688, 12773, 12783, 12830, 12832, 12871, 12880, 42124, 42128, 42182, 43360, 43388, 44032, 55203, 63744, 64255, 65040, 65049, 65072, 65106, 65108, 65126, 65128, 65131, 94176, 94180, 94192, 94198, 94208, 101589, 101631, 101662, 101760, 101874, 110576, 110579, 110581, 110587, 110589, 110590, 110592, 110882, 110898, 110898, 110928, 110930, 110933, 110933, 110948, 110951, 110960, 111355, 119552, 119638, 119648, 119670, 126980, 126980, 127183, 127183, 127374, 127374, 127377, 127386, 127488, 127490, 127504, 127547, 127552, 127560, 127568, 127569, 127584, 127589, 127744, 127776, 127789, 127797, 127799, 127868, 127870, 127891, 127904, 127946, 127951, 127955, 127968, 127984, 127988, 127988, 127992, 128062, 128064, 128064, 128066, 128252, 128255, 128317, 128331, 128334, 128336, 128359, 128378, 128378, 128405, 128406, 128420, 128420, 128507, 128591, 128640, 128709, 128716, 128716, 128720, 128722, 128725, 128728, 128732, 128735, 128747, 128748, 128756, 128764, 128992, 129003, 129008, 129008, 129292, 129338, 129340, 129349, 129351, 129535, 129648, 129660, 129664, 129674, 129678, 129734, 129736, 129736, 129741, 129756, 129759, 129770, 129775, 129784, 131072, 196605, 196608, 262141];
|
|
17
|
+
|
|
18
|
+
export {ambiguousRanges, fullwidthRanges, halfwidthRanges, narrowRanges, wideRanges};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ambiguousRanges,
|
|
3
|
+
fullwidthRanges,
|
|
4
|
+
halfwidthRanges,
|
|
5
|
+
narrowRanges,
|
|
6
|
+
wideRanges,
|
|
7
|
+
} from './lookup-data.js';
|
|
8
|
+
import {isInRange} from './utilities.js';
|
|
9
|
+
|
|
10
|
+
const minimumAmbiguousCodePoint = ambiguousRanges[0];
|
|
11
|
+
const maximumAmbiguousCodePoint = ambiguousRanges.at(-1);
|
|
12
|
+
const minimumFullWidthCodePoint = fullwidthRanges[0];
|
|
13
|
+
const maximumFullWidthCodePoint = fullwidthRanges.at(-1);
|
|
14
|
+
const minimumHalfWidthCodePoint = halfwidthRanges[0];
|
|
15
|
+
const maximumHalfWidthCodePoint = halfwidthRanges.at(-1);
|
|
16
|
+
const minimumNarrowCodePoint = narrowRanges[0];
|
|
17
|
+
const maximumNarrowCodePoint = narrowRanges.at(-1);
|
|
18
|
+
const minimumWideCodePoint = wideRanges[0];
|
|
19
|
+
const maximumWideCodePoint = wideRanges.at(-1);
|
|
20
|
+
|
|
21
|
+
const commonCjkCodePoint = 0x4E_00;
|
|
22
|
+
const [wideFastPathStart, wideFastPathEnd] = findWideFastPathRange(wideRanges);
|
|
23
|
+
|
|
24
|
+
// Use a hot-path range so common `isWide` calls can skip binary search.
|
|
25
|
+
// The range containing U+4E00 covers common CJK ideographs;
|
|
26
|
+
// fallback to the largest range for resilience to Unicode table changes.
|
|
27
|
+
function findWideFastPathRange(ranges) {
|
|
28
|
+
let fastPathStart = ranges[0];
|
|
29
|
+
let fastPathEnd = ranges[1];
|
|
30
|
+
|
|
31
|
+
for (let index = 0; index < ranges.length; index += 2) {
|
|
32
|
+
const start = ranges[index];
|
|
33
|
+
const end = ranges[index + 1];
|
|
34
|
+
|
|
35
|
+
if (
|
|
36
|
+
commonCjkCodePoint >= start
|
|
37
|
+
&& commonCjkCodePoint <= end
|
|
38
|
+
) {
|
|
39
|
+
return [start, end];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if ((end - start) > (fastPathEnd - fastPathStart)) {
|
|
43
|
+
fastPathStart = start;
|
|
44
|
+
fastPathEnd = end;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return [fastPathStart, fastPathEnd];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const isAmbiguous = codePoint => {
|
|
52
|
+
if (
|
|
53
|
+
codePoint < minimumAmbiguousCodePoint
|
|
54
|
+
|| codePoint > maximumAmbiguousCodePoint
|
|
55
|
+
) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return isInRange(ambiguousRanges, codePoint);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const isFullWidth = codePoint => {
|
|
63
|
+
if (
|
|
64
|
+
codePoint < minimumFullWidthCodePoint
|
|
65
|
+
|| codePoint > maximumFullWidthCodePoint
|
|
66
|
+
) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return isInRange(fullwidthRanges, codePoint);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const isHalfWidth = codePoint => {
|
|
74
|
+
if (
|
|
75
|
+
codePoint < minimumHalfWidthCodePoint
|
|
76
|
+
|| codePoint > maximumHalfWidthCodePoint
|
|
77
|
+
) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return isInRange(halfwidthRanges, codePoint);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const isNarrow = codePoint => {
|
|
85
|
+
if (
|
|
86
|
+
codePoint < minimumNarrowCodePoint
|
|
87
|
+
|| codePoint > maximumNarrowCodePoint
|
|
88
|
+
) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return isInRange(narrowRanges, codePoint);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export const isWide = codePoint => {
|
|
96
|
+
if (
|
|
97
|
+
codePoint >= wideFastPathStart
|
|
98
|
+
&& codePoint <= wideFastPathEnd
|
|
99
|
+
) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (
|
|
104
|
+
codePoint < minimumWideCodePoint
|
|
105
|
+
|| codePoint > maximumWideCodePoint
|
|
106
|
+
) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return isInRange(wideRanges, codePoint);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export function getCategory(codePoint) {
|
|
114
|
+
if (isAmbiguous(codePoint)) {
|
|
115
|
+
return 'ambiguous';
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (isFullWidth(codePoint)) {
|
|
119
|
+
return 'fullwidth';
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (isHalfWidth(codePoint)) {
|
|
123
|
+
return 'halfwidth';
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (isNarrow(codePoint)) {
|
|
127
|
+
return 'narrow';
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (isWide(codePoint)) {
|
|
131
|
+
return 'wide';
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return 'neutral';
|
|
135
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "get-east-asian-width",
|
|
3
|
+
"version": "1.5.0",
|
|
4
|
+
"description": "Determine the East Asian Width of a Unicode character",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": "sindresorhus/get-east-asian-width",
|
|
7
|
+
"funding": "https://github.com/sponsors/sindresorhus",
|
|
8
|
+
"author": {
|
|
9
|
+
"name": "Sindre Sorhus",
|
|
10
|
+
"email": "sindresorhus@gmail.com",
|
|
11
|
+
"url": "https://sindresorhus.com"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
"types": "./index.d.ts",
|
|
16
|
+
"default": "./index.js"
|
|
17
|
+
},
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=18"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "xo && ava && tsc index.d.ts",
|
|
24
|
+
"build": "node scripts/build.js",
|
|
25
|
+
"prepublish": "npm run build"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"index.js",
|
|
29
|
+
"index.d.ts",
|
|
30
|
+
"lookup.js",
|
|
31
|
+
"lookup-data.js",
|
|
32
|
+
"utilities.js"
|
|
33
|
+
],
|
|
34
|
+
"keywords": [
|
|
35
|
+
"unicode",
|
|
36
|
+
"east-asian-width",
|
|
37
|
+
"eastasianwidth",
|
|
38
|
+
"character",
|
|
39
|
+
"string",
|
|
40
|
+
"width",
|
|
41
|
+
"text",
|
|
42
|
+
"layout",
|
|
43
|
+
"alignment",
|
|
44
|
+
"fullwidth",
|
|
45
|
+
"halfwidth",
|
|
46
|
+
"ambiguous",
|
|
47
|
+
"narrow",
|
|
48
|
+
"wide",
|
|
49
|
+
"neutral",
|
|
50
|
+
"typography",
|
|
51
|
+
"japanese",
|
|
52
|
+
"chinese",
|
|
53
|
+
"korean",
|
|
54
|
+
"codepoint",
|
|
55
|
+
"text-processing",
|
|
56
|
+
"i18n",
|
|
57
|
+
"l10n"
|
|
58
|
+
],
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"ava": "^5.3.1",
|
|
61
|
+
"outdent": "^0.8.0",
|
|
62
|
+
"simplify-ranges": "^0.1.0",
|
|
63
|
+
"typescript": "^5.2.2",
|
|
64
|
+
"xo": "^0.56.0"
|
|
65
|
+
},
|
|
66
|
+
"xo": {
|
|
67
|
+
"ignores": [
|
|
68
|
+
"lookup-data.js"
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# get-east-asian-width
|
|
2
|
+
|
|
3
|
+
> Determine the [East Asian Width](https://unicode.org/reports/tr11/) of a Unicode character
|
|
4
|
+
|
|
5
|
+
> East Asian Width categorizes Unicode characters based on their occupied space in East Asian typography, which helps in text layout and alignment, particularly in languages like Japanese, Chinese, and Korean.
|
|
6
|
+
|
|
7
|
+
Unlike other similar packages, this package uses the latest Unicode data (which changes each year).
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install get-east-asian-width
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import {eastAsianWidth, eastAsianWidthType} from 'get-east-asian-width';
|
|
19
|
+
|
|
20
|
+
const codePoint = '字'.codePointAt(0);
|
|
21
|
+
|
|
22
|
+
console.log(eastAsianWidth(codePoint));
|
|
23
|
+
//=> 2
|
|
24
|
+
|
|
25
|
+
console.log(eastAsianWidthType(codePoint));
|
|
26
|
+
//=> 'wide'
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## `eastAsianWidth(codePoint: number, options?: object): 1 | 2`
|
|
30
|
+
|
|
31
|
+
Returns the width as a number for the given code point.
|
|
32
|
+
|
|
33
|
+
### options
|
|
34
|
+
|
|
35
|
+
Type: `object`
|
|
36
|
+
|
|
37
|
+
#### ambiguousAsWide
|
|
38
|
+
|
|
39
|
+
Type: `boolean`\
|
|
40
|
+
Default: `false`
|
|
41
|
+
|
|
42
|
+
Whether to treat an `'ambiguous'` character as wide.
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
import {eastAsianWidth} from 'get-east-asian-width';
|
|
46
|
+
|
|
47
|
+
const codePoint = '⛣'.codePointAt(0);
|
|
48
|
+
|
|
49
|
+
console.log(eastAsianWidth(codePoint));
|
|
50
|
+
//=> 1
|
|
51
|
+
|
|
52
|
+
console.log(eastAsianWidth(codePoint, {ambiguousAsWide: true}));
|
|
53
|
+
//=> 2
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
> Ambiguous characters behave like wide or narrow characters depending on the context (language tag, script identification, associated font, source of data, or explicit markup; all can provide the context). **If the context cannot be established reliably, they should be treated as narrow characters by default.**
|
|
57
|
+
> - http://www.unicode.org/reports/tr11/
|
|
58
|
+
|
|
59
|
+
## `eastAsianWidthType(codePoint: number): 'fullwidth' | 'halfwidth' | 'wide' | 'narrow' | 'neutral' | 'ambiguous'`
|
|
60
|
+
|
|
61
|
+
Returns the type of “East Asian Width” for the given code point.
|
|
62
|
+
|
|
63
|
+
## Related
|
|
64
|
+
|
|
65
|
+
- [string-width](https://github.com/sindresorhus/string-width) - Get the visual width of a string
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Binary search on a sorted flat array of [start, end] pairs.
|
|
3
|
+
|
|
4
|
+
@param {number[]} ranges - Flat array of inclusive [start, end] range pairs, e.g. [0, 5, 10, 20].
|
|
5
|
+
@param {number} codePoint - The value to search for.
|
|
6
|
+
@returns {boolean} Whether the value falls within any of the ranges.
|
|
7
|
+
*/
|
|
8
|
+
export const isInRange = (ranges, codePoint) => {
|
|
9
|
+
let low = 0;
|
|
10
|
+
let high = Math.floor(ranges.length / 2) - 1;
|
|
11
|
+
while (low <= high) {
|
|
12
|
+
const mid = Math.floor((low + high) / 2);
|
|
13
|
+
const i = mid * 2;
|
|
14
|
+
if (codePoint < ranges[i]) {
|
|
15
|
+
high = mid - 1;
|
|
16
|
+
} else if (codePoint > ranges[i + 1]) {
|
|
17
|
+
low = mid + 1;
|
|
18
|
+
} else {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return false;
|
|
24
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Slice a string with [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles)
|
|
3
|
+
|
|
4
|
+
@param string - A string with ANSI escape codes. Like one styled by [`chalk`](https://github.com/chalk/chalk).
|
|
5
|
+
@param startSlice - Zero-based visible-column index at which to start the slice. Grapheme clusters are kept intact.
|
|
6
|
+
@param endSlice - Zero-based visible-column index at which to end the slice.
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import chalk from 'chalk';
|
|
11
|
+
import sliceAnsi from 'slice-ansi';
|
|
12
|
+
|
|
13
|
+
const string = 'The quick brown ' + chalk.red('fox jumped over ') +
|
|
14
|
+
'the lazy ' + chalk.green('dog and then ran away with the unicorn.');
|
|
15
|
+
|
|
16
|
+
console.log(sliceAnsi(string, 20, 30));
|
|
17
|
+
```
|
|
18
|
+
*/
|
|
19
|
+
export default function sliceAnsi(string: string, startSlice: number, endSlice?: number): string;
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import tokenizeAnsi from './tokenize-ansi.js';
|
|
2
|
+
|
|
3
|
+
function applySgrFragments(activeStyles, fragments) {
|
|
4
|
+
for (const fragment of fragments) {
|
|
5
|
+
switch (fragment.type) {
|
|
6
|
+
case 'reset': {
|
|
7
|
+
activeStyles.clear();
|
|
8
|
+
break;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
case 'end': {
|
|
12
|
+
activeStyles.delete(fragment.endCode);
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
case 'start': {
|
|
17
|
+
activeStyles.delete(fragment.endCode);
|
|
18
|
+
activeStyles.set(fragment.endCode, fragment.code);
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
default: {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return activeStyles;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function undoAnsiCodes(activeStyles) {
|
|
32
|
+
return [...activeStyles.keys()].reverse().join('');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function closeHyperlink(hyperlinkToken) {
|
|
36
|
+
return `${hyperlinkToken.closePrefix}${hyperlinkToken.terminator}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function shouldIncludeSgrAfterEnd(token, activeStyles) {
|
|
40
|
+
let hasStartFragment = false;
|
|
41
|
+
let hasClosingEffect = false;
|
|
42
|
+
|
|
43
|
+
for (const fragment of token.fragments) {
|
|
44
|
+
if (fragment.type === 'start') {
|
|
45
|
+
hasStartFragment = true;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (fragment.type === 'reset' && activeStyles.size > 0) {
|
|
50
|
+
hasClosingEffect = true;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (fragment.type === 'end' && activeStyles.has(fragment.endCode)) {
|
|
55
|
+
hasClosingEffect = true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return hasClosingEffect && !hasStartFragment;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function applySgrToken({token, isPastEnd, activeStyles, returnValue, include, activeHyperlink, position}) {
|
|
63
|
+
if (isPastEnd && !shouldIncludeSgrAfterEnd(token, activeStyles)) {
|
|
64
|
+
return {
|
|
65
|
+
activeStyles,
|
|
66
|
+
activeHyperlink,
|
|
67
|
+
position,
|
|
68
|
+
returnValue,
|
|
69
|
+
include,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
activeStyles = applySgrFragments(activeStyles, token.fragments);
|
|
74
|
+
if (include) {
|
|
75
|
+
returnValue += token.code;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
activeStyles,
|
|
80
|
+
activeHyperlink,
|
|
81
|
+
position,
|
|
82
|
+
returnValue,
|
|
83
|
+
include,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function applyHyperlinkToken({token, isPastEnd, activeStyles, activeHyperlink, position, returnValue, include}) {
|
|
88
|
+
if (
|
|
89
|
+
isPastEnd
|
|
90
|
+
&& (
|
|
91
|
+
token.action !== 'close'
|
|
92
|
+
|| !activeHyperlink
|
|
93
|
+
)
|
|
94
|
+
) {
|
|
95
|
+
return {
|
|
96
|
+
activeStyles,
|
|
97
|
+
activeHyperlink,
|
|
98
|
+
position,
|
|
99
|
+
returnValue,
|
|
100
|
+
include,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (token.action === 'open') {
|
|
105
|
+
activeHyperlink = token;
|
|
106
|
+
} else if (token.action === 'close') {
|
|
107
|
+
activeHyperlink = undefined;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (include) {
|
|
111
|
+
returnValue += token.code;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
activeStyles,
|
|
116
|
+
activeHyperlink,
|
|
117
|
+
position,
|
|
118
|
+
returnValue,
|
|
119
|
+
include,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function applyControlToken({token, isPastEnd, activeStyles, activeHyperlink, position, returnValue, include}) {
|
|
124
|
+
if (!isPastEnd && include) {
|
|
125
|
+
returnValue += token.code;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
activeStyles,
|
|
130
|
+
activeHyperlink,
|
|
131
|
+
position,
|
|
132
|
+
returnValue,
|
|
133
|
+
include,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function applyCharacterToken({token, start, activeStyles, activeHyperlink, position, returnValue, include}) {
|
|
138
|
+
if (
|
|
139
|
+
!include
|
|
140
|
+
&& position >= start
|
|
141
|
+
&& !token.isGraphemeContinuation
|
|
142
|
+
) {
|
|
143
|
+
include = true;
|
|
144
|
+
returnValue = [...activeStyles.values()].join('');
|
|
145
|
+
if (activeHyperlink) {
|
|
146
|
+
returnValue += activeHyperlink.code;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (include) {
|
|
151
|
+
returnValue += token.value;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
position += token.visibleWidth;
|
|
155
|
+
return {
|
|
156
|
+
activeStyles,
|
|
157
|
+
activeHyperlink,
|
|
158
|
+
position,
|
|
159
|
+
returnValue,
|
|
160
|
+
include,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const tokenHandlers = {
|
|
165
|
+
sgr: applySgrToken,
|
|
166
|
+
hyperlink: applyHyperlinkToken,
|
|
167
|
+
control: applyControlToken,
|
|
168
|
+
character: applyCharacterToken,
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
function applyToken(parameters) {
|
|
172
|
+
const tokenHandler = tokenHandlers[parameters.token.type];
|
|
173
|
+
if (!tokenHandler) {
|
|
174
|
+
const {
|
|
175
|
+
activeStyles,
|
|
176
|
+
activeHyperlink,
|
|
177
|
+
position,
|
|
178
|
+
returnValue,
|
|
179
|
+
include,
|
|
180
|
+
} = parameters;
|
|
181
|
+
|
|
182
|
+
return {
|
|
183
|
+
activeStyles,
|
|
184
|
+
activeHyperlink,
|
|
185
|
+
position,
|
|
186
|
+
returnValue,
|
|
187
|
+
include,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return tokenHandler(parameters);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function createHasContinuationAheadMap(tokens) {
|
|
195
|
+
const hasContinuationAhead = Array.from({length: tokens.length}, () => false);
|
|
196
|
+
let nextCharacterIsContinuation = false;
|
|
197
|
+
|
|
198
|
+
for (let tokenIndex = tokens.length - 1; tokenIndex >= 0; tokenIndex--) {
|
|
199
|
+
const token = tokens[tokenIndex];
|
|
200
|
+
hasContinuationAhead[tokenIndex] = nextCharacterIsContinuation;
|
|
201
|
+
if (token.type === 'character') {
|
|
202
|
+
nextCharacterIsContinuation = Boolean(token.isGraphemeContinuation);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return hasContinuationAhead;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export default function sliceAnsi(string, start, end) {
|
|
210
|
+
const tokens = tokenizeAnsi(string, {endCharacter: end});
|
|
211
|
+
const hasContinuationAhead = createHasContinuationAheadMap(tokens);
|
|
212
|
+
let activeStyles = new Map();
|
|
213
|
+
let activeHyperlink;
|
|
214
|
+
let position = 0;
|
|
215
|
+
let returnValue = '';
|
|
216
|
+
let include = false;
|
|
217
|
+
|
|
218
|
+
for (const [tokenIndex, token] of tokens.entries()) {
|
|
219
|
+
let isPastEnd = end !== undefined && position >= end;
|
|
220
|
+
if (
|
|
221
|
+
isPastEnd
|
|
222
|
+
&& token.type !== 'character'
|
|
223
|
+
&& hasContinuationAhead[tokenIndex]
|
|
224
|
+
) {
|
|
225
|
+
isPastEnd = false;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (
|
|
229
|
+
isPastEnd
|
|
230
|
+
&& token.type === 'character'
|
|
231
|
+
&& !token.isGraphemeContinuation
|
|
232
|
+
) {
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
({activeStyles, activeHyperlink, position, returnValue, include} = applyToken({
|
|
237
|
+
token,
|
|
238
|
+
isPastEnd,
|
|
239
|
+
start,
|
|
240
|
+
activeStyles,
|
|
241
|
+
activeHyperlink,
|
|
242
|
+
position,
|
|
243
|
+
returnValue,
|
|
244
|
+
include,
|
|
245
|
+
}));
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (!include) {
|
|
249
|
+
return '';
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (activeHyperlink) {
|
|
253
|
+
returnValue += closeHyperlink(activeHyperlink);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Disable active codes at the end
|
|
257
|
+
returnValue += undoAnsiCodes(activeStyles);
|
|
258
|
+
|
|
259
|
+
return returnValue;
|
|
260
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
+
Copyright (c) DC <threedeecee@gmail.com>
|
|
3
4
|
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
4
5
|
|
|
5
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|