track-cli 3.0.0-rc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +3 -0
  3. package/esm/_dnt.polyfills.d.ts +6 -0
  4. package/esm/_dnt.polyfills.js +1 -0
  5. package/esm/_dnt.shims.d.ts +19 -0
  6. package/esm/_dnt.shims.js +78 -0
  7. package/esm/deps/deno.land/std@0.170.0/fmt/colors.d.ts +270 -0
  8. package/esm/deps/deno.land/std@0.170.0/fmt/colors.js +473 -0
  9. package/esm/deps/deno.land/std@0.195.0/_util/os.d.ts +4 -0
  10. package/esm/deps/deno.land/std@0.195.0/_util/os.js +18 -0
  11. package/esm/deps/deno.land/std@0.195.0/assert/assert.d.ts +2 -0
  12. package/esm/deps/deno.land/std@0.195.0/assert/assert.js +8 -0
  13. package/esm/deps/deno.land/std@0.195.0/assert/assertion_error.d.ts +4 -0
  14. package/esm/deps/deno.land/std@0.195.0/assert/assertion_error.js +12 -0
  15. package/esm/deps/deno.land/std@0.195.0/datetime/_common.d.ts +50 -0
  16. package/esm/deps/deno.land/std@0.195.0/datetime/_common.js +545 -0
  17. package/esm/deps/deno.land/std@0.195.0/datetime/constants.d.ts +55 -0
  18. package/esm/deps/deno.land/std@0.195.0/datetime/constants.js +57 -0
  19. package/esm/deps/deno.land/std@0.195.0/datetime/day_of_year.d.ts +26 -0
  20. package/esm/deps/deno.land/std@0.195.0/datetime/day_of_year.js +45 -0
  21. package/esm/deps/deno.land/std@0.195.0/datetime/difference.d.ts +38 -0
  22. package/esm/deps/deno.land/std@0.195.0/datetime/difference.js +93 -0
  23. package/esm/deps/deno.land/std@0.195.0/datetime/format.d.ts +22 -0
  24. package/esm/deps/deno.land/std@0.195.0/datetime/format.js +28 -0
  25. package/esm/deps/deno.land/std@0.195.0/datetime/is_leap.d.ts +49 -0
  26. package/esm/deps/deno.land/std@0.195.0/datetime/is_leap.js +60 -0
  27. package/esm/deps/deno.land/std@0.195.0/datetime/mod.d.ts +43 -0
  28. package/esm/deps/deno.land/std@0.195.0/datetime/mod.js +45 -0
  29. package/esm/deps/deno.land/std@0.195.0/datetime/parse.d.ts +21 -0
  30. package/esm/deps/deno.land/std@0.195.0/datetime/parse.js +29 -0
  31. package/esm/deps/deno.land/std@0.195.0/datetime/to_imf.d.ts +17 -0
  32. package/esm/deps/deno.land/std@0.195.0/datetime/to_imf.js +44 -0
  33. package/esm/deps/deno.land/std@0.195.0/datetime/week_of_year.d.ts +13 -0
  34. package/esm/deps/deno.land/std@0.195.0/datetime/week_of_year.js +38 -0
  35. package/esm/deps/deno.land/std@0.195.0/fmt/colors.d.ts +270 -0
  36. package/esm/deps/deno.land/std@0.195.0/fmt/colors.js +474 -0
  37. package/esm/deps/deno.land/std@0.195.0/fmt/duration.d.ts +15 -0
  38. package/esm/deps/deno.land/std@0.195.0/fmt/duration.js +96 -0
  39. package/esm/deps/deno.land/std@0.195.0/fs/_util.d.ts +35 -0
  40. package/esm/deps/deno.land/std@0.195.0/fs/_util.js +80 -0
  41. package/esm/deps/deno.land/std@0.195.0/fs/copy.d.ts +51 -0
  42. package/esm/deps/deno.land/std@0.195.0/fs/copy.js +244 -0
  43. package/esm/deps/deno.land/std@0.195.0/fs/empty_dir.d.ts +31 -0
  44. package/esm/deps/deno.land/std@0.195.0/fs/empty_dir.js +74 -0
  45. package/esm/deps/deno.land/std@0.195.0/fs/ensure_dir.d.ts +27 -0
  46. package/esm/deps/deno.land/std@0.195.0/fs/ensure_dir.js +55 -0
  47. package/esm/deps/deno.land/std@0.195.0/fs/ensure_file.d.ts +33 -0
  48. package/esm/deps/deno.land/std@0.195.0/fs/ensure_file.js +75 -0
  49. package/esm/deps/deno.land/std@0.195.0/fs/ensure_link.d.ts +31 -0
  50. package/esm/deps/deno.land/std@0.195.0/fs/ensure_link.js +43 -0
  51. package/esm/deps/deno.land/std@0.195.0/fs/ensure_symlink.d.ts +17 -0
  52. package/esm/deps/deno.land/std@0.195.0/fs/ensure_symlink.js +68 -0
  53. package/esm/deps/deno.land/std@0.195.0/fs/eol.d.ts +40 -0
  54. package/esm/deps/deno.land/std@0.195.0/fs/eol.js +53 -0
  55. package/esm/deps/deno.land/std@0.195.0/fs/exists.d.ts +102 -0
  56. package/esm/deps/deno.land/std@0.195.0/fs/exists.js +163 -0
  57. package/esm/deps/deno.land/std@0.195.0/fs/expand_glob.d.ts +37 -0
  58. package/esm/deps/deno.land/std@0.195.0/fs/expand_glob.js +216 -0
  59. package/esm/deps/deno.land/std@0.195.0/fs/mod.d.ts +16 -0
  60. package/esm/deps/deno.land/std@0.195.0/fs/mod.js +17 -0
  61. package/esm/deps/deno.land/std@0.195.0/fs/move.d.ts +29 -0
  62. package/esm/deps/deno.land/std@0.195.0/fs/move.js +88 -0
  63. package/esm/deps/deno.land/std@0.195.0/fs/walk.d.ts +40 -0
  64. package/esm/deps/deno.land/std@0.195.0/fs/walk.js +158 -0
  65. package/esm/deps/deno.land/std@0.195.0/path/_constants.d.ts +39 -0
  66. package/esm/deps/deno.land/std@0.195.0/path/_constants.js +46 -0
  67. package/esm/deps/deno.land/std@0.195.0/path/_interface.d.ts +26 -0
  68. package/esm/deps/deno.land/std@0.195.0/path/_interface.js +3 -0
  69. package/esm/deps/deno.land/std@0.195.0/path/_util.d.ts +11 -0
  70. package/esm/deps/deno.land/std@0.195.0/path/_util.js +161 -0
  71. package/esm/deps/deno.land/std@0.195.0/path/common.d.ts +13 -0
  72. package/esm/deps/deno.land/std@0.195.0/path/common.js +36 -0
  73. package/esm/deps/deno.land/std@0.195.0/path/glob.d.ts +83 -0
  74. package/esm/deps/deno.land/std@0.195.0/path/glob.js +361 -0
  75. package/esm/deps/deno.land/std@0.195.0/path/mod.d.ts +9 -0
  76. package/esm/deps/deno.land/std@0.195.0/path/mod.js +33 -0
  77. package/esm/deps/deno.land/std@0.195.0/path/posix.d.ts +86 -0
  78. package/esm/deps/deno.land/std@0.195.0/path/posix.js +442 -0
  79. package/esm/deps/deno.land/std@0.195.0/path/separator.d.ts +2 -0
  80. package/esm/deps/deno.land/std@0.195.0/path/separator.js +5 -0
  81. package/esm/deps/deno.land/std@0.195.0/path/win32.d.ts +91 -0
  82. package/esm/deps/deno.land/std@0.195.0/path/win32.js +909 -0
  83. package/esm/deps/deno.land/x/cliffy@v0.25.7/_utils/distance.d.ts +1 -0
  84. package/esm/deps/deno.land/x/cliffy@v0.25.7/_utils/distance.js +26 -0
  85. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_errors.d.ts +76 -0
  86. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_errors.js +154 -0
  87. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_utils.d.ts +32 -0
  88. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_utils.js +105 -0
  89. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/command.d.ts +831 -0
  90. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/command.js +1701 -0
  91. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_bash_completions_generator.d.ts +17 -0
  92. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_bash_completions_generator.js +201 -0
  93. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_fish_completions_generator.d.ts +14 -0
  94. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_fish_completions_generator.js +141 -0
  95. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_zsh_completions_generator.d.ts +21 -0
  96. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_zsh_completions_generator.js +285 -0
  97. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/bash.d.ts +6 -0
  98. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/bash.js +38 -0
  99. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/complete.d.ts +8 -0
  100. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/complete.js +32 -0
  101. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/fish.d.ts +6 -0
  102. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/fish.js +38 -0
  103. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/mod.d.ts +6 -0
  104. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/mod.js +46 -0
  105. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/zsh.d.ts +6 -0
  106. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/zsh.js +38 -0
  107. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deprecated.d.ts +45 -0
  108. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deprecated.js +2 -0
  109. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deps.d.ts +1 -0
  110. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deps.js +1 -0
  111. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/_help_generator.d.ts +27 -0
  112. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/_help_generator.js +323 -0
  113. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/mod.d.ts +6 -0
  114. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/mod.js +34 -0
  115. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/mod.d.ts +18 -0
  116. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/mod.js +17 -0
  117. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/type.d.ts +41 -0
  118. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/type.js +24 -0
  119. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/action_list.d.ts +9 -0
  120. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/action_list.js +20 -0
  121. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/boolean.d.ts +9 -0
  122. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/boolean.js +13 -0
  123. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/child_command.d.ts +9 -0
  124. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/child_command.js +27 -0
  125. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/command.d.ts +7 -0
  126. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/command.js +9 -0
  127. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/enum.d.ts +10 -0
  128. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/enum.js +29 -0
  129. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/file.d.ts +5 -0
  130. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/file.js +12 -0
  131. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/integer.d.ts +7 -0
  132. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/integer.js +9 -0
  133. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/number.d.ts +7 -0
  134. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/number.js +9 -0
  135. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/string.d.ts +7 -0
  136. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/string.js +9 -0
  137. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types.d.ts +118 -0
  138. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types.js +2 -0
  139. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/mod.d.ts +5 -0
  140. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/mod.js +5 -0
  141. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/deno_land.d.ts +14 -0
  142. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/deno_land.js +46 -0
  143. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/github.d.ts +26 -0
  144. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/github.js +118 -0
  145. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/nest_land.d.ts +14 -0
  146. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/nest_land.js +55 -0
  147. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider.d.ts +27 -0
  148. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider.js +102 -0
  149. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/upgrade_command.d.ts +17 -0
  150. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/upgrade_command.js +75 -0
  151. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_errors.d.ts +60 -0
  152. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_errors.js +117 -0
  153. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_utils.d.ts +18 -0
  154. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_utils.js +106 -0
  155. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_validate_flags.d.ts +10 -0
  156. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_validate_flags.js +157 -0
  157. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/deprecated.d.ts +24 -0
  158. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/deprecated.js +9 -0
  159. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/flags.d.ts +33 -0
  160. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/flags.js +402 -0
  161. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/boolean.d.ts +3 -0
  162. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/boolean.js +11 -0
  163. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/integer.d.ts +3 -0
  164. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/integer.js +9 -0
  165. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/number.d.ts +3 -0
  166. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/number.js +9 -0
  167. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/string.d.ts +3 -0
  168. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/string.js +4 -0
  169. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types.d.ts +59 -0
  170. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types.js +1 -0
  171. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/border.d.ts +20 -0
  172. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/border.js +18 -0
  173. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/cell.d.ts +78 -0
  174. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/cell.js +128 -0
  175. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/deps.d.ts +1 -0
  176. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/deps.js +1 -0
  177. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/layout.d.ts +99 -0
  178. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/layout.js +529 -0
  179. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/row.d.ts +49 -0
  180. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/row.js +74 -0
  181. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/table.d.ts +135 -0
  182. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/table.js +237 -0
  183. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/utils.d.ts +13 -0
  184. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/utils.js +60 -0
  185. package/esm/package.json +3 -0
  186. package/esm/src/action/add.d.ts +1 -0
  187. package/esm/src/action/add.js +57 -0
  188. package/esm/src/action/clone.d.ts +6 -0
  189. package/esm/src/action/clone.js +108 -0
  190. package/esm/src/action/lang.d.ts +1 -0
  191. package/esm/src/action/lang.js +40 -0
  192. package/esm/src/action/pull.d.ts +1 -0
  193. package/esm/src/action/pull.js +22 -0
  194. package/esm/src/action/remove.d.ts +4 -0
  195. package/esm/src/action/remove.js +67 -0
  196. package/esm/src/action/reset.d.ts +1 -0
  197. package/esm/src/action/reset.js +21 -0
  198. package/esm/src/action/run.d.ts +4 -0
  199. package/esm/src/action/run.js +163 -0
  200. package/esm/src/action/status.d.ts +1 -0
  201. package/esm/src/action/status.js +5 -0
  202. package/esm/src/main.d.ts +2 -0
  203. package/esm/src/main.js +96 -0
  204. package/esm/src/meta.d.ts +3 -0
  205. package/esm/src/meta.js +51 -0
  206. package/esm/src/orca/client.d.ts +20 -0
  207. package/esm/src/orca/client.js +152 -0
  208. package/esm/src/orca/types.d.ts +54 -0
  209. package/esm/src/orca/types.js +12 -0
  210. package/esm/src/shared/config.d.ts +24 -0
  211. package/esm/src/shared/config.js +24 -0
  212. package/esm/src/shared/errors.d.ts +82 -0
  213. package/esm/src/shared/errors.js +228 -0
  214. package/esm/src/shared/file.d.ts +30 -0
  215. package/esm/src/shared/file.js +110 -0
  216. package/esm/src/shared/mod.d.ts +40 -0
  217. package/esm/src/shared/mod.js +383 -0
  218. package/esm/src/shared/types.d.ts +12 -0
  219. package/esm/src/shared/types.js +1 -0
  220. package/esm/src/track/client.d.ts +60 -0
  221. package/esm/src/track/client.js +268 -0
  222. package/esm/src/track/types.d.ts +210 -0
  223. package/esm/src/track/types.js +40 -0
  224. package/package.json +35 -0
@@ -0,0 +1,529 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var _TableLayout_instances, _TableLayout_getRows;
7
+ import { Cell } from "./cell.js";
8
+ import { Row } from "./row.js";
9
+ import { consumeWords, longest, strLength } from "./utils.js";
10
+ /** Table layout renderer. */
11
+ export class TableLayout {
12
+ /**
13
+ * Table layout constructor.
14
+ * @param table Table instance.
15
+ * @param options Render options.
16
+ */
17
+ constructor(table, options) {
18
+ _TableLayout_instances.add(this);
19
+ Object.defineProperty(this, "table", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: table
24
+ });
25
+ Object.defineProperty(this, "options", {
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true,
29
+ value: options
30
+ });
31
+ }
32
+ /** Generate table string. */
33
+ toString() {
34
+ const opts = this.createLayout();
35
+ return opts.rows.length ? this.renderRows(opts) : "";
36
+ }
37
+ /**
38
+ * Generates table layout including row and col span, converts all none
39
+ * Cell/Row values to Cells and Rows and returns the layout rendering
40
+ * settings.
41
+ */
42
+ createLayout() {
43
+ Object.keys(this.options.chars).forEach((key) => {
44
+ if (typeof this.options.chars[key] !== "string") {
45
+ this.options.chars[key] = "";
46
+ }
47
+ });
48
+ const hasBodyBorder = this.table.getBorder() ||
49
+ this.table.hasBodyBorder();
50
+ const hasHeaderBorder = this.table.hasHeaderBorder();
51
+ const hasBorder = hasHeaderBorder || hasBodyBorder;
52
+ const rows = __classPrivateFieldGet(this, _TableLayout_instances, "m", _TableLayout_getRows).call(this);
53
+ const columns = Math.max(...rows.map((row) => row.length));
54
+ for (const row of rows) {
55
+ const length = row.length;
56
+ if (length < columns) {
57
+ const diff = columns - length;
58
+ for (let i = 0; i < diff; i++) {
59
+ row.push(this.createCell(null, row));
60
+ }
61
+ }
62
+ }
63
+ const padding = [];
64
+ const width = [];
65
+ for (let colIndex = 0; colIndex < columns; colIndex++) {
66
+ const minColWidth = Array.isArray(this.options.minColWidth)
67
+ ? this.options.minColWidth[colIndex]
68
+ : this.options.minColWidth;
69
+ const maxColWidth = Array.isArray(this.options.maxColWidth)
70
+ ? this.options.maxColWidth[colIndex]
71
+ : this.options.maxColWidth;
72
+ const colWidth = longest(colIndex, rows, maxColWidth);
73
+ width[colIndex] = Math.min(maxColWidth, Math.max(minColWidth, colWidth));
74
+ padding[colIndex] = Array.isArray(this.options.padding)
75
+ ? this.options.padding[colIndex]
76
+ : this.options.padding;
77
+ }
78
+ return {
79
+ padding,
80
+ width,
81
+ rows,
82
+ columns,
83
+ hasBorder,
84
+ hasBodyBorder,
85
+ hasHeaderBorder,
86
+ };
87
+ }
88
+ /**
89
+ * Fills rows and cols by specified row/col span with a reference of the
90
+ * original cell.
91
+ */
92
+ spanRows(rows) {
93
+ const rowSpan = [];
94
+ let colSpan = 1;
95
+ let rowIndex = -1;
96
+ while (true) {
97
+ rowIndex++;
98
+ if (rowIndex === rows.length && rowSpan.every((span) => span === 1)) {
99
+ break;
100
+ }
101
+ const row = rows[rowIndex] = this.createRow(rows[rowIndex] || []);
102
+ let colIndex = -1;
103
+ while (true) {
104
+ colIndex++;
105
+ if (colIndex === row.length &&
106
+ colIndex === rowSpan.length && colSpan === 1) {
107
+ break;
108
+ }
109
+ if (colSpan > 1) {
110
+ colSpan--;
111
+ rowSpan[colIndex] = rowSpan[colIndex - 1];
112
+ row.splice(colIndex, this.getDeleteCount(rows, rowIndex, colIndex), row[colIndex - 1]);
113
+ continue;
114
+ }
115
+ if (rowSpan[colIndex] > 1) {
116
+ rowSpan[colIndex]--;
117
+ rows[rowIndex].splice(colIndex, this.getDeleteCount(rows, rowIndex, colIndex), rows[rowIndex - 1][colIndex]);
118
+ continue;
119
+ }
120
+ const cell = row[colIndex] = this.createCell(row[colIndex] || null, row);
121
+ colSpan = cell.getColSpan();
122
+ rowSpan[colIndex] = cell.getRowSpan();
123
+ }
124
+ }
125
+ return rows;
126
+ }
127
+ getDeleteCount(rows, rowIndex, colIndex) {
128
+ return colIndex <= rows[rowIndex].length - 1 &&
129
+ typeof rows[rowIndex][colIndex] === "undefined"
130
+ ? 1
131
+ : 0;
132
+ }
133
+ /**
134
+ * Create a new row from existing row or cell array.
135
+ * @param row Original row.
136
+ */
137
+ createRow(row) {
138
+ return Row.from(row)
139
+ .border(this.table.getBorder(), false)
140
+ .align(this.table.getAlign(), false);
141
+ }
142
+ /**
143
+ * Create a new cell from existing cell or cell value.
144
+ * @param cell Original cell.
145
+ * @param row Parent row.
146
+ */
147
+ createCell(cell, row) {
148
+ return Cell.from(cell ?? "")
149
+ .border(row.getBorder(), false)
150
+ .align(row.getAlign(), false);
151
+ }
152
+ /**
153
+ * Render table layout.
154
+ * @param opts Render options.
155
+ */
156
+ renderRows(opts) {
157
+ let result = "";
158
+ const rowSpan = new Array(opts.columns).fill(1);
159
+ for (let rowIndex = 0; rowIndex < opts.rows.length; rowIndex++) {
160
+ result += this.renderRow(rowSpan, rowIndex, opts);
161
+ }
162
+ return result.slice(0, -1);
163
+ }
164
+ /**
165
+ * Render row.
166
+ * @param rowSpan Current row span.
167
+ * @param rowIndex Current row index.
168
+ * @param opts Render options.
169
+ * @param isMultiline Is multiline row.
170
+ */
171
+ renderRow(rowSpan, rowIndex, opts, isMultiline) {
172
+ const row = opts.rows[rowIndex];
173
+ const prevRow = opts.rows[rowIndex - 1];
174
+ const nextRow = opts.rows[rowIndex + 1];
175
+ let result = "";
176
+ let colSpan = 1;
177
+ // border top row
178
+ if (!isMultiline && rowIndex === 0 && row.hasBorder()) {
179
+ result += this.renderBorderRow(undefined, row, rowSpan, opts);
180
+ }
181
+ let isMultilineRow = false;
182
+ result += " ".repeat(this.options.indent || 0);
183
+ for (let colIndex = 0; colIndex < opts.columns; colIndex++) {
184
+ if (colSpan > 1) {
185
+ colSpan--;
186
+ rowSpan[colIndex] = rowSpan[colIndex - 1];
187
+ continue;
188
+ }
189
+ result += this.renderCell(colIndex, row, opts);
190
+ if (rowSpan[colIndex] > 1) {
191
+ if (!isMultiline) {
192
+ rowSpan[colIndex]--;
193
+ }
194
+ }
195
+ else if (!prevRow || prevRow[colIndex] !== row[colIndex]) {
196
+ rowSpan[colIndex] = row[colIndex].getRowSpan();
197
+ }
198
+ colSpan = row[colIndex].getColSpan();
199
+ if (rowSpan[colIndex] === 1 && row[colIndex].length) {
200
+ isMultilineRow = true;
201
+ }
202
+ }
203
+ if (opts.columns > 0) {
204
+ if (row[opts.columns - 1].getBorder()) {
205
+ result += this.options.chars.right;
206
+ }
207
+ else if (opts.hasBorder) {
208
+ result += " ";
209
+ }
210
+ }
211
+ result += "\n";
212
+ if (isMultilineRow) { // skip border
213
+ return result + this.renderRow(rowSpan, rowIndex, opts, isMultilineRow);
214
+ }
215
+ // border mid row
216
+ if ((rowIndex === 0 && opts.hasHeaderBorder) ||
217
+ (rowIndex < opts.rows.length - 1 && opts.hasBodyBorder)) {
218
+ result += this.renderBorderRow(row, nextRow, rowSpan, opts);
219
+ }
220
+ // border bottom row
221
+ if (rowIndex === opts.rows.length - 1 && row.hasBorder()) {
222
+ result += this.renderBorderRow(row, undefined, rowSpan, opts);
223
+ }
224
+ return result;
225
+ }
226
+ /**
227
+ * Render cell.
228
+ * @param colIndex Current col index.
229
+ * @param row Current row.
230
+ * @param opts Render options.
231
+ * @param noBorder Disable border.
232
+ */
233
+ renderCell(colIndex, row, opts, noBorder) {
234
+ let result = "";
235
+ const prevCell = row[colIndex - 1];
236
+ const cell = row[colIndex];
237
+ if (!noBorder) {
238
+ if (colIndex === 0) {
239
+ if (cell.getBorder()) {
240
+ result += this.options.chars.left;
241
+ }
242
+ else if (opts.hasBorder) {
243
+ result += " ";
244
+ }
245
+ }
246
+ else {
247
+ if (cell.getBorder() || prevCell?.getBorder()) {
248
+ result += this.options.chars.middle;
249
+ }
250
+ else if (opts.hasBorder) {
251
+ result += " ";
252
+ }
253
+ }
254
+ }
255
+ let maxLength = opts.width[colIndex];
256
+ const colSpan = cell.getColSpan();
257
+ if (colSpan > 1) {
258
+ for (let o = 1; o < colSpan; o++) {
259
+ // add padding and with of next cell
260
+ maxLength += opts.width[colIndex + o] + opts.padding[colIndex + o];
261
+ if (opts.hasBorder) {
262
+ // add padding again and border with
263
+ maxLength += opts.padding[colIndex + o] + 1;
264
+ }
265
+ }
266
+ }
267
+ const { current, next } = this.renderCellValue(cell, maxLength);
268
+ row[colIndex].setValue(next);
269
+ if (opts.hasBorder) {
270
+ result += " ".repeat(opts.padding[colIndex]);
271
+ }
272
+ result += current;
273
+ if (opts.hasBorder || colIndex < opts.columns - 1) {
274
+ result += " ".repeat(opts.padding[colIndex]);
275
+ }
276
+ return result;
277
+ }
278
+ /**
279
+ * Render specified length of cell. Returns the rendered value and a new cell
280
+ * with the rest value.
281
+ * @param cell Cell to render.
282
+ * @param maxLength Max length of content to render.
283
+ */
284
+ renderCellValue(cell, maxLength) {
285
+ const length = Math.min(maxLength, strLength(cell.toString()));
286
+ let words = consumeWords(length, cell.toString());
287
+ // break word if word is longer than max length
288
+ const breakWord = strLength(words) > length;
289
+ if (breakWord) {
290
+ words = words.slice(0, length);
291
+ }
292
+ // get next content and remove leading space if breakWord is not true
293
+ const next = cell.toString().slice(words.length + (breakWord ? 0 : 1));
294
+ const fillLength = maxLength - strLength(words);
295
+ // Align content
296
+ const align = cell.getAlign();
297
+ let current;
298
+ if (fillLength === 0) {
299
+ current = words;
300
+ }
301
+ else if (align === "left") {
302
+ current = words + " ".repeat(fillLength);
303
+ }
304
+ else if (align === "center") {
305
+ current = " ".repeat(Math.floor(fillLength / 2)) + words +
306
+ " ".repeat(Math.ceil(fillLength / 2));
307
+ }
308
+ else if (align === "right") {
309
+ current = " ".repeat(fillLength) + words;
310
+ }
311
+ else {
312
+ throw new Error("Unknown direction: " + align);
313
+ }
314
+ return {
315
+ current,
316
+ next: cell.clone(next),
317
+ };
318
+ }
319
+ /**
320
+ * Render border row.
321
+ * @param prevRow Previous row.
322
+ * @param nextRow Next row.
323
+ * @param rowSpan Current row span.
324
+ * @param opts Render options.
325
+ */
326
+ renderBorderRow(prevRow, nextRow, rowSpan, opts) {
327
+ let result = "";
328
+ let colSpan = 1;
329
+ for (let colIndex = 0; colIndex < opts.columns; colIndex++) {
330
+ if (rowSpan[colIndex] > 1) {
331
+ if (!nextRow) {
332
+ throw new Error("invalid layout");
333
+ }
334
+ if (colSpan > 1) {
335
+ colSpan--;
336
+ continue;
337
+ }
338
+ }
339
+ result += this.renderBorderCell(colIndex, prevRow, nextRow, rowSpan, opts);
340
+ colSpan = nextRow?.[colIndex].getColSpan() ?? 1;
341
+ }
342
+ return result.length ? " ".repeat(this.options.indent) + result + "\n" : "";
343
+ }
344
+ /**
345
+ * Render border cell.
346
+ * @param colIndex Current index.
347
+ * @param prevRow Previous row.
348
+ * @param nextRow Next row.
349
+ * @param rowSpan Current row span.
350
+ * @param opts Render options.
351
+ */
352
+ renderBorderCell(colIndex, prevRow, nextRow, rowSpan, opts) {
353
+ // a1 | b1
354
+ // -------
355
+ // a2 | b2
356
+ const a1 = prevRow?.[colIndex - 1];
357
+ const a2 = nextRow?.[colIndex - 1];
358
+ const b1 = prevRow?.[colIndex];
359
+ const b2 = nextRow?.[colIndex];
360
+ const a1Border = !!a1?.getBorder();
361
+ const a2Border = !!a2?.getBorder();
362
+ const b1Border = !!b1?.getBorder();
363
+ const b2Border = !!b2?.getBorder();
364
+ const hasColSpan = (cell) => (cell?.getColSpan() ?? 1) > 1;
365
+ const hasRowSpan = (cell) => (cell?.getRowSpan() ?? 1) > 1;
366
+ let result = "";
367
+ if (colIndex === 0) {
368
+ if (rowSpan[colIndex] > 1) {
369
+ if (b1Border) {
370
+ result += this.options.chars.left;
371
+ }
372
+ else {
373
+ result += " ";
374
+ }
375
+ }
376
+ else if (b1Border && b2Border) {
377
+ result += this.options.chars.leftMid;
378
+ }
379
+ else if (b1Border) {
380
+ result += this.options.chars.bottomLeft;
381
+ }
382
+ else if (b2Border) {
383
+ result += this.options.chars.topLeft;
384
+ }
385
+ else {
386
+ result += " ";
387
+ }
388
+ }
389
+ else if (colIndex < opts.columns) {
390
+ if ((a1Border && b2Border) || (b1Border && a2Border)) {
391
+ const a1ColSpan = hasColSpan(a1);
392
+ const a2ColSpan = hasColSpan(a2);
393
+ const b1ColSpan = hasColSpan(b1);
394
+ const b2ColSpan = hasColSpan(b2);
395
+ const a1RowSpan = hasRowSpan(a1);
396
+ const a2RowSpan = hasRowSpan(a2);
397
+ const b1RowSpan = hasRowSpan(b1);
398
+ const b2RowSpan = hasRowSpan(b2);
399
+ const hasAllBorder = a1Border && b2Border && b1Border && a2Border;
400
+ const hasAllRowSpan = a1RowSpan && b1RowSpan && a2RowSpan && b2RowSpan;
401
+ const hasAllColSpan = a1ColSpan && b1ColSpan && a2ColSpan && b2ColSpan;
402
+ if (hasAllRowSpan && hasAllBorder) {
403
+ result += this.options.chars.middle;
404
+ }
405
+ else if (hasAllColSpan && hasAllBorder && a1 === b1 && a2 === b2) {
406
+ result += this.options.chars.mid;
407
+ }
408
+ else if (a1ColSpan && b1ColSpan && a1 === b1) {
409
+ result += this.options.chars.topMid;
410
+ }
411
+ else if (a2ColSpan && b2ColSpan && a2 === b2) {
412
+ result += this.options.chars.bottomMid;
413
+ }
414
+ else if (a1RowSpan && a2RowSpan && a1 === a2) {
415
+ result += this.options.chars.leftMid;
416
+ }
417
+ else if (b1RowSpan && b2RowSpan && b1 === b2) {
418
+ result += this.options.chars.rightMid;
419
+ }
420
+ else {
421
+ result += this.options.chars.midMid;
422
+ }
423
+ }
424
+ else if (a1Border && b1Border) {
425
+ if (hasColSpan(a1) && hasColSpan(b1) && a1 === b1) {
426
+ result += this.options.chars.bottom;
427
+ }
428
+ else {
429
+ result += this.options.chars.bottomMid;
430
+ }
431
+ }
432
+ else if (b1Border && b2Border) {
433
+ if (rowSpan[colIndex] > 1) {
434
+ result += this.options.chars.left;
435
+ }
436
+ else {
437
+ result += this.options.chars.leftMid;
438
+ }
439
+ }
440
+ else if (b2Border && a2Border) {
441
+ if (hasColSpan(a2) && hasColSpan(b2) && a2 === b2) {
442
+ result += this.options.chars.top;
443
+ }
444
+ else {
445
+ result += this.options.chars.topMid;
446
+ }
447
+ }
448
+ else if (a1Border && a2Border) {
449
+ if (hasRowSpan(a1) && a1 === a2) {
450
+ result += this.options.chars.right;
451
+ }
452
+ else {
453
+ result += this.options.chars.rightMid;
454
+ }
455
+ }
456
+ else if (a1Border) {
457
+ result += this.options.chars.bottomRight;
458
+ }
459
+ else if (b1Border) {
460
+ result += this.options.chars.bottomLeft;
461
+ }
462
+ else if (a2Border) {
463
+ result += this.options.chars.topRight;
464
+ }
465
+ else if (b2Border) {
466
+ result += this.options.chars.topLeft;
467
+ }
468
+ else {
469
+ result += " ";
470
+ }
471
+ }
472
+ const length = opts.padding[colIndex] + opts.width[colIndex] +
473
+ opts.padding[colIndex];
474
+ if (rowSpan[colIndex] > 1 && nextRow) {
475
+ result += this.renderCell(colIndex, nextRow, opts, true);
476
+ if (nextRow[colIndex] === nextRow[nextRow.length - 1]) {
477
+ if (b1Border) {
478
+ result += this.options.chars.right;
479
+ }
480
+ else {
481
+ result += " ";
482
+ }
483
+ return result;
484
+ }
485
+ }
486
+ else if (b1Border && b2Border) {
487
+ result += this.options.chars.mid.repeat(length);
488
+ }
489
+ else if (b1Border) {
490
+ result += this.options.chars.bottom.repeat(length);
491
+ }
492
+ else if (b2Border) {
493
+ result += this.options.chars.top.repeat(length);
494
+ }
495
+ else {
496
+ result += " ".repeat(length);
497
+ }
498
+ if (colIndex === opts.columns - 1) {
499
+ if (b1Border && b2Border) {
500
+ result += this.options.chars.rightMid;
501
+ }
502
+ else if (b1Border) {
503
+ result += this.options.chars.bottomRight;
504
+ }
505
+ else if (b2Border) {
506
+ result += this.options.chars.topRight;
507
+ }
508
+ else {
509
+ result += " ";
510
+ }
511
+ }
512
+ return result;
513
+ }
514
+ }
515
+ _TableLayout_instances = new WeakSet(), _TableLayout_getRows = function _TableLayout_getRows() {
516
+ const header = this.table.getHeader();
517
+ const rows = header ? [header, ...this.table] : this.table.slice();
518
+ const hasSpan = rows.some((row) => row.some((cell) => cell instanceof Cell && (cell.getColSpan() > 1 || cell.getRowSpan() > 1)));
519
+ if (hasSpan) {
520
+ return this.spanRows(rows);
521
+ }
522
+ return rows.map((row) => {
523
+ const newRow = this.createRow(row);
524
+ for (let i = 0; i < row.length; i++) {
525
+ newRow[i] = this.createCell(row[i], newRow);
526
+ }
527
+ return newRow;
528
+ });
529
+ };
@@ -0,0 +1,49 @@
1
+ import { Direction, ICell } from "./cell.js";
2
+ /** Row type */
3
+ export type IRow<T extends ICell | undefined = ICell | undefined> = T[] | Row<T>;
4
+ /** Json row. */
5
+ export type IDataRow = Record<string, string | number>;
6
+ /** Row options. */
7
+ export interface IRowOptions {
8
+ indent?: number;
9
+ border?: boolean;
10
+ align?: Direction;
11
+ }
12
+ /**
13
+ * Row representation.
14
+ */
15
+ export declare class Row<T extends ICell | undefined = ICell | undefined> extends Array<T> {
16
+ protected options: IRowOptions;
17
+ /**
18
+ * Create a new row. If cells is a row, all cells and options of the row will
19
+ * be copied to the new row.
20
+ * @param cells Cells or row.
21
+ */
22
+ static from<T extends ICell | undefined>(cells: IRow<T>): Row<T>;
23
+ /** Clone row recursively with all options. */
24
+ clone(): Row;
25
+ /**
26
+ * Setter:
27
+ */
28
+ /**
29
+ * Enable/disable cell border.
30
+ * @param enable Enable/disable cell border.
31
+ * @param override Override existing value.
32
+ */
33
+ border(enable: boolean, override?: boolean): this;
34
+ /**
35
+ * Align row content.
36
+ * @param direction Align direction.
37
+ * @param override Override existing value.
38
+ */
39
+ align(direction: Direction, override?: boolean): this;
40
+ /**
41
+ * Getter:
42
+ */
43
+ /** Check if row has border. */
44
+ getBorder(): boolean;
45
+ /** Check if row or any child cell has border. */
46
+ hasBorder(): boolean;
47
+ /** Get row alignment. */
48
+ getAlign(): Direction;
49
+ }
@@ -0,0 +1,74 @@
1
+ import { Cell } from "./cell.js";
2
+ /**
3
+ * Row representation.
4
+ */
5
+ export class Row extends Array {
6
+ constructor() {
7
+ super(...arguments);
8
+ Object.defineProperty(this, "options", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value: {}
13
+ });
14
+ }
15
+ /**
16
+ * Create a new row. If cells is a row, all cells and options of the row will
17
+ * be copied to the new row.
18
+ * @param cells Cells or row.
19
+ */
20
+ static from(cells) {
21
+ const row = new this(...cells);
22
+ if (cells instanceof Row) {
23
+ row.options = { ...cells.options };
24
+ }
25
+ return row;
26
+ }
27
+ /** Clone row recursively with all options. */
28
+ clone() {
29
+ const row = new Row(...this.map((cell) => cell instanceof Cell ? cell.clone() : cell));
30
+ row.options = { ...this.options };
31
+ return row;
32
+ }
33
+ /**
34
+ * Setter:
35
+ */
36
+ /**
37
+ * Enable/disable cell border.
38
+ * @param enable Enable/disable cell border.
39
+ * @param override Override existing value.
40
+ */
41
+ border(enable, override = true) {
42
+ if (override || typeof this.options.border === "undefined") {
43
+ this.options.border = enable;
44
+ }
45
+ return this;
46
+ }
47
+ /**
48
+ * Align row content.
49
+ * @param direction Align direction.
50
+ * @param override Override existing value.
51
+ */
52
+ align(direction, override = true) {
53
+ if (override || typeof this.options.align === "undefined") {
54
+ this.options.align = direction;
55
+ }
56
+ return this;
57
+ }
58
+ /**
59
+ * Getter:
60
+ */
61
+ /** Check if row has border. */
62
+ getBorder() {
63
+ return this.options.border === true;
64
+ }
65
+ /** Check if row or any child cell has border. */
66
+ hasBorder() {
67
+ return this.getBorder() ||
68
+ this.some((cell) => cell instanceof Cell && cell.getBorder());
69
+ }
70
+ /** Get row alignment. */
71
+ getAlign() {
72
+ return this.options.align ?? "left";
73
+ }
74
+ }