@ohos-ports/pm2 0.0.0-stage → 7.1.2-beta.0

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 (267) hide show
  1. package/CHANGELOG.md +2607 -0
  2. package/CONTRIBUTING.md +124 -0
  3. package/GNU-AGPL-3.0.txt +665 -0
  4. package/LICENSE +1 -0
  5. package/README.md +255 -2
  6. package/SECURITY.md +41 -0
  7. package/bin/pm2 +3 -0
  8. package/bin/pm2-dev +3 -0
  9. package/bin/pm2-docker +3 -0
  10. package/bin/pm2-runtime +3 -0
  11. package/bin/pm2.ps1 +3 -0
  12. package/constants.js +113 -0
  13. package/index.js +12 -0
  14. package/lib/API/Configuration.js +212 -0
  15. package/lib/API/Containerizer.js +335 -0
  16. package/lib/API/Dashboard.js +726 -0
  17. package/lib/API/Deploy.js +117 -0
  18. package/lib/API/Extra.js +798 -0
  19. package/lib/API/ExtraMgmt/Docker.js +30 -0
  20. package/lib/API/Log.js +388 -0
  21. package/lib/API/LogManagement.js +351 -0
  22. package/lib/API/Modules/LOCAL.js +122 -0
  23. package/lib/API/Modules/Modularizer.js +148 -0
  24. package/lib/API/Modules/NPM.js +443 -0
  25. package/lib/API/Modules/TAR.js +368 -0
  26. package/lib/API/Modules/flagExt.js +46 -0
  27. package/lib/API/Modules/index.js +120 -0
  28. package/lib/API/Monit.js +247 -0
  29. package/lib/API/Serve.js +497 -0
  30. package/lib/API/Startup.js +630 -0
  31. package/lib/API/UX/helpers.js +213 -0
  32. package/lib/API/UX/index.js +9 -0
  33. package/lib/API/UX/pm2-describe.js +197 -0
  34. package/lib/API/UX/pm2-ls-minimal.js +31 -0
  35. package/lib/API/UX/pm2-ls.js +581 -0
  36. package/lib/API/Version.js +383 -0
  37. package/lib/API/interpreter.json +12 -0
  38. package/lib/API/pm2-plus/PM2IO.js +381 -0
  39. package/lib/API/pm2-plus/auth-strategies/CliAuth.js +306 -0
  40. package/lib/API/pm2-plus/auth-strategies/WebAuth.js +195 -0
  41. package/lib/API/pm2-plus/helpers.js +97 -0
  42. package/lib/API/pm2-plus/link.js +126 -0
  43. package/lib/API/pm2-plus/pres/motd +16 -0
  44. package/lib/API/pm2-plus/pres/motd.update +26 -0
  45. package/lib/API/pm2-plus/pres/welcome +28 -0
  46. package/lib/API/pm2-plus/process-selector.js +52 -0
  47. package/lib/API/schema.json +375 -0
  48. package/lib/API.js +1980 -0
  49. package/lib/Client.js +793 -0
  50. package/lib/Common.js +949 -0
  51. package/lib/Configuration.js +309 -0
  52. package/lib/Daemon.js +468 -0
  53. package/lib/Event.js +37 -0
  54. package/lib/God/ActionMethods.js +955 -0
  55. package/lib/God/ClusterMode.js +192 -0
  56. package/lib/God/ForkMode.js +205 -0
  57. package/lib/God/Methods.js +292 -0
  58. package/lib/God/Reload.js +300 -0
  59. package/lib/God/StdioLogger.js +239 -0
  60. package/lib/God.js +653 -0
  61. package/lib/HttpInterface.js +75 -0
  62. package/lib/OtelManager.js +74 -0
  63. package/lib/ProcessContainer.js +321 -0
  64. package/lib/ProcessContainerBun.js +355 -0
  65. package/lib/ProcessContainerFork.js +42 -0
  66. package/lib/ProcessContainerForkBun.js +31 -0
  67. package/lib/ProcessUtils.js +74 -0
  68. package/lib/TreeKill.js +111 -0
  69. package/lib/Utility.js +304 -0
  70. package/lib/VersionCheck.js +46 -0
  71. package/lib/Watcher.js +117 -0
  72. package/lib/Worker.js +200 -0
  73. package/lib/binaries/CLI.js +1092 -0
  74. package/lib/binaries/DevCLI.js +183 -0
  75. package/lib/binaries/Runtime.js +101 -0
  76. package/lib/binaries/Runtime4Docker.js +192 -0
  77. package/lib/completion.js +229 -0
  78. package/lib/completion.sh +40 -0
  79. package/lib/motd +36 -0
  80. package/lib/templates/Dockerfiles/Dockerfile-nodejs.tpl +8 -0
  81. package/lib/templates/ecosystem-es.tpl +24 -0
  82. package/lib/templates/ecosystem-simple-es.tpl +8 -0
  83. package/lib/templates/ecosystem-simple.tpl +6 -0
  84. package/lib/templates/ecosystem.tpl +22 -0
  85. package/lib/templates/init-scripts/launchd.tpl +35 -0
  86. package/lib/templates/init-scripts/openrc.tpl +52 -0
  87. package/lib/templates/init-scripts/pm2-init-amazon.sh +86 -0
  88. package/lib/templates/init-scripts/rcd-openbsd.tpl +41 -0
  89. package/lib/templates/init-scripts/rcd.tpl +44 -0
  90. package/lib/templates/init-scripts/smf.tpl +43 -0
  91. package/lib/templates/init-scripts/systemd-online.tpl +22 -0
  92. package/lib/templates/init-scripts/systemd.tpl +22 -0
  93. package/lib/templates/init-scripts/upstart.tpl +103 -0
  94. package/lib/templates/logrotate.d/pm2 +10 -0
  95. package/lib/templates/sample-apps/http-server/README.md +14 -0
  96. package/lib/templates/sample-apps/http-server/api.js +9 -0
  97. package/lib/templates/sample-apps/http-server/ecosystem.config.js +14 -0
  98. package/lib/templates/sample-apps/http-server/package.json +11 -0
  99. package/lib/templates/sample-apps/pm2-plus-metrics-actions/README.md +45 -0
  100. package/lib/templates/sample-apps/pm2-plus-metrics-actions/custom-metrics.js +66 -0
  101. package/lib/templates/sample-apps/pm2-plus-metrics-actions/ecosystem.config.js +12 -0
  102. package/lib/templates/sample-apps/pm2-plus-metrics-actions/package.json +11 -0
  103. package/lib/templates/sample-apps/python-app/README.md +4 -0
  104. package/lib/templates/sample-apps/python-app/echo.py +7 -0
  105. package/lib/templates/sample-apps/python-app/ecosystem.config.js +12 -0
  106. package/lib/templates/sample-apps/python-app/package.json +11 -0
  107. package/lib/tools/Config.js +251 -0
  108. package/lib/tools/SysMetrics.js +375 -0
  109. package/lib/tools/copydirSync.js +101 -0
  110. package/lib/tools/deleteFolderRecursive.js +19 -0
  111. package/lib/tools/find-package-json.js +74 -0
  112. package/lib/tools/fmt.js +72 -0
  113. package/lib/tools/interpreter.js +88 -0
  114. package/lib/tools/isbinaryfile.js +94 -0
  115. package/lib/tools/json5.js +752 -0
  116. package/lib/tools/multimeter/bar.js +111 -0
  117. package/lib/tools/multimeter/charm/encode.js +18 -0
  118. package/lib/tools/multimeter/charm/index.js +305 -0
  119. package/lib/tools/multimeter/index.js +76 -0
  120. package/lib/tools/open.js +56 -0
  121. package/lib/tools/passwd.js +58 -0
  122. package/lib/tools/pm2-config-keys.js +165 -0
  123. package/lib/tools/prompt.js +76 -0
  124. package/lib/tools/serviceStop.js +149 -0
  125. package/lib/tools/sexec.js +55 -0
  126. package/lib/tools/treeify.js +113 -0
  127. package/lib/tools/typestrip.js +55 -0
  128. package/lib/tools/which.js +120 -0
  129. package/lib/tools/xdg-open +861 -0
  130. package/modules/blessed/LICENSE +20 -0
  131. package/modules/blessed/README.md +34 -0
  132. package/modules/blessed/index.js +1 -0
  133. package/modules/blessed/lib/alias.js +526 -0
  134. package/modules/blessed/lib/blessed.js +32 -0
  135. package/modules/blessed/lib/colors.js +530 -0
  136. package/modules/blessed/lib/events.js +189 -0
  137. package/modules/blessed/lib/gpmclient.js +221 -0
  138. package/modules/blessed/lib/helpers.js +165 -0
  139. package/modules/blessed/lib/keys.js +339 -0
  140. package/modules/blessed/lib/program.js +4297 -0
  141. package/modules/blessed/lib/tput.js +3022 -0
  142. package/modules/blessed/lib/unicode.js +885 -0
  143. package/modules/blessed/lib/widget.js +32 -0
  144. package/modules/blessed/lib/widgets/box.js +34 -0
  145. package/modules/blessed/lib/widgets/element.js +2570 -0
  146. package/modules/blessed/lib/widgets/list.js +599 -0
  147. package/modules/blessed/lib/widgets/log.js +83 -0
  148. package/modules/blessed/lib/widgets/node.js +282 -0
  149. package/modules/blessed/lib/widgets/screen.js +2298 -0
  150. package/modules/blessed/lib/widgets/scrollablebox.js +389 -0
  151. package/modules/blessed/lib/widgets/scrollabletext.js +35 -0
  152. package/modules/blessed/lib/widgets/text.js +35 -0
  153. package/modules/blessed/usr/linux +0 -0
  154. package/modules/blessed/usr/windows-ansi +0 -0
  155. package/modules/blessed/usr/xterm +0 -0
  156. package/modules/blessed/usr/xterm-256color +0 -0
  157. package/modules/blessed/usr/xterm.termcap +243 -0
  158. package/modules/chokidar/LICENSE +21 -0
  159. package/modules/chokidar/VENDORED.md +76 -0
  160. package/modules/chokidar/index.js +979 -0
  161. package/modules/chokidar/lib/brace-expand.js +180 -0
  162. package/modules/chokidar/lib/constants.js +66 -0
  163. package/modules/chokidar/lib/fsevents-handler.js +526 -0
  164. package/modules/chokidar/lib/nodefs-handler.js +654 -0
  165. package/modules/fclone.js +49 -0
  166. package/modules/pm2-axon/index.js +2 -0
  167. package/modules/pm2-axon/lib/configurable/History.md +5 -0
  168. package/modules/pm2-axon/lib/configurable/Makefile +7 -0
  169. package/modules/pm2-axon/lib/configurable/Readme.md +57 -0
  170. package/modules/pm2-axon/lib/configurable/index.js +2 -0
  171. package/modules/pm2-axon/lib/configurable/lib/configurable.js +47 -0
  172. package/modules/pm2-axon/lib/configurable/package.json +68 -0
  173. package/modules/pm2-axon/lib/index.js +44 -0
  174. package/modules/pm2-axon/lib/plugins/queue.js +71 -0
  175. package/modules/pm2-axon/lib/plugins/round-robin.js +55 -0
  176. package/modules/pm2-axon/lib/sockets/pub-emitter.js +26 -0
  177. package/modules/pm2-axon/lib/sockets/pub.js +77 -0
  178. package/modules/pm2-axon/lib/sockets/pull.js +37 -0
  179. package/modules/pm2-axon/lib/sockets/push.js +32 -0
  180. package/modules/pm2-axon/lib/sockets/rep.js +73 -0
  181. package/modules/pm2-axon/lib/sockets/req.js +101 -0
  182. package/modules/pm2-axon/lib/sockets/sock.js +430 -0
  183. package/modules/pm2-axon/lib/sockets/sub-emitter.js +92 -0
  184. package/modules/pm2-axon/lib/sockets/sub.js +147 -0
  185. package/modules/pm2-axon/lib/utils.js +19 -0
  186. package/modules/pm2-axon-rpc/index.js +3 -0
  187. package/modules/pm2-axon-rpc/lib/client.js +63 -0
  188. package/modules/pm2-axon-rpc/lib/server.js +139 -0
  189. package/modules/pm2-io-agent/LICENSE +661 -0
  190. package/modules/pm2-io-agent/README.md +62 -0
  191. package/modules/pm2-io-agent/config.js +30 -0
  192. package/modules/pm2-io-agent/constants.js +118 -0
  193. package/modules/pm2-io-agent/index.js +2 -0
  194. package/modules/pm2-io-agent/src/InteractorClient.js +513 -0
  195. package/modules/pm2-io-agent/src/InteractorDaemon.js +455 -0
  196. package/modules/pm2-io-agent/src/PM2Client.js +112 -0
  197. package/modules/pm2-io-agent/src/PM2Interface.js +180 -0
  198. package/modules/pm2-io-agent/src/TransporterInterface.js +173 -0
  199. package/modules/pm2-io-agent/src/Utility.js +392 -0
  200. package/modules/pm2-io-agent/src/WatchDog.js +70 -0
  201. package/modules/pm2-io-agent/src/push/DataRetriever.js +77 -0
  202. package/modules/pm2-io-agent/src/push/PushInteractor.js +206 -0
  203. package/modules/pm2-io-agent/src/push/TransactionAggregator.js +670 -0
  204. package/modules/pm2-io-agent/src/reverse/ReverseInteractor.js +128 -0
  205. package/modules/pm2-io-agent/src/transporters/Transporter.js +129 -0
  206. package/modules/pm2-io-agent/src/transporters/WebsocketTransport.js +202 -0
  207. package/modules/pm2-io-agent/src/utils/BinaryHeap.js +135 -0
  208. package/modules/pm2-io-agent/src/utils/EDS.js +111 -0
  209. package/modules/pm2-io-agent/src/utils/probes/Histogram.js +204 -0
  210. package/modules/pm2-io-agent/src/utils/units.js +10 -0
  211. package/modules/pm2-io-bpm/configuration.js +141 -0
  212. package/modules/pm2-io-bpm/constants.js +10 -0
  213. package/modules/pm2-io-bpm/featureManager.js +110 -0
  214. package/modules/pm2-io-bpm/features/dependencies.js +48 -0
  215. package/modules/pm2-io-bpm/features/events.js +50 -0
  216. package/modules/pm2-io-bpm/features/metrics.js +102 -0
  217. package/modules/pm2-io-bpm/features/notify.js +238 -0
  218. package/modules/pm2-io-bpm/features/profiling.js +70 -0
  219. package/modules/pm2-io-bpm/features/tracing.js +174 -0
  220. package/modules/pm2-io-bpm/index.js +11 -0
  221. package/modules/pm2-io-bpm/metrics/eventLoopMetrics.js +136 -0
  222. package/modules/pm2-io-bpm/metrics/httpMetrics.js +175 -0
  223. package/modules/pm2-io-bpm/metrics/network.js +132 -0
  224. package/modules/pm2-io-bpm/metrics/runtime.js +161 -0
  225. package/modules/pm2-io-bpm/metrics/v8.js +104 -0
  226. package/modules/pm2-io-bpm/otel/constants.js +7 -0
  227. package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/index.js +17 -0
  228. package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/node/index.js +17 -0
  229. package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/node/util.js +51 -0
  230. package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/transform.js +137 -0
  231. package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/types.js +24 -0
  232. package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/utils.js +23 -0
  233. package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/zipkin.js +149 -0
  234. package/modules/pm2-io-bpm/pmx.js +380 -0
  235. package/modules/pm2-io-bpm/profilers/addonProfiler.js +193 -0
  236. package/modules/pm2-io-bpm/profilers/inspectorProfiler.js +302 -0
  237. package/modules/pm2-io-bpm/serviceManager.js +21 -0
  238. package/modules/pm2-io-bpm/services/actions.js +159 -0
  239. package/modules/pm2-io-bpm/services/inspector.js +43 -0
  240. package/modules/pm2-io-bpm/services/metrics.js +186 -0
  241. package/modules/pm2-io-bpm/services/runtimeStats.js +54 -0
  242. package/modules/pm2-io-bpm/services/transport.js +11 -0
  243. package/modules/pm2-io-bpm/transports/IPCTransport.js +115 -0
  244. package/modules/pm2-io-bpm/utils/BinaryHeap.js +134 -0
  245. package/modules/pm2-io-bpm/utils/EDS.js +113 -0
  246. package/modules/pm2-io-bpm/utils/EWMA.js +32 -0
  247. package/modules/pm2-io-bpm/utils/autocast.js +61 -0
  248. package/modules/pm2-io-bpm/utils/metrics/counter.js +33 -0
  249. package/modules/pm2-io-bpm/utils/metrics/gauge.js +23 -0
  250. package/modules/pm2-io-bpm/utils/metrics/histogram.js +192 -0
  251. package/modules/pm2-io-bpm/utils/metrics/meter.js +46 -0
  252. package/modules/pm2-io-bpm/utils/miscellaneous.js +19 -0
  253. package/modules/pm2-io-bpm/utils/module.js +67 -0
  254. package/modules/pm2-io-bpm/utils/shimmer.js +19 -0
  255. package/modules/pm2-io-bpm/utils/stackParser.js +160 -0
  256. package/modules/pm2-io-bpm/utils/transactionAggregator.js +429 -0
  257. package/modules/pm2-io-bpm/utils/units.js +16 -0
  258. package/modules/vizion/LICENSE +13 -0
  259. package/modules/vizion/README.md +133 -0
  260. package/modules/vizion/index.js +1 -0
  261. package/modules/vizion/lib/git/git.js +247 -0
  262. package/modules/vizion/lib/vizion.js +52 -0
  263. package/package.json +170 -4
  264. package/paths.js +121 -0
  265. package/pm2 +11 -0
  266. package/types/index.d.ts +732 -0
  267. package/types/tsconfig.json +14 -0
@@ -0,0 +1,885 @@
1
+ /**
2
+ * unicode.js - east asian width and surrogate pairs
3
+ * Copyright (c) 2013-2015, Christopher Jeffrey and contributors (MIT License).
4
+ * https://github.com/chjj/blessed
5
+ * Borrowed from vangie/east-asian-width, komagata/eastasianwidth,
6
+ * and mathiasbynens/String.prototype.codePointAt. Licenses below.
7
+ */
8
+
9
+ // east-asian-width
10
+ //
11
+ // Copyright (c) 2015 Vangie Du
12
+ // https://github.com/vangie/east-asian-width
13
+ //
14
+ // Permission is hereby granted, free of charge, to any person
15
+ // obtaining a copy of this software and associated documentation
16
+ // files (the "Software"), to deal in the Software without
17
+ // restriction, including without limitation the rights to use,
18
+ // copy, modify, merge, publish, distribute, sublicense, and/or sell
19
+ // copies of the Software, and to permit persons to whom the
20
+ // Software is furnished to do so, subject to the following
21
+ // conditions:
22
+ //
23
+ // The above copyright notice and this permission notice shall be
24
+ // included in all copies or substantial portions of the Software.
25
+ //
26
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
28
+ // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
30
+ // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
31
+ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
32
+ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
33
+ // OTHER DEALINGS IN THE SOFTWARE.
34
+
35
+ // eastasianwidth
36
+ //
37
+ // Copyright (c) 2013, Masaki Komagata
38
+ // https://github.com/komagata/eastasianwidth
39
+ //
40
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
41
+ // of this software and associated documentation files (the "Software"), to deal
42
+ // in the Software without restriction, including without limitation the rights
43
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
44
+ // copies of the Software, and to permit persons to whom the Software is
45
+ // furnished to do so, subject to the following conditions:
46
+ //
47
+ // The above copyright notice and this permission notice shall be included in
48
+ // all copies or substantial portions of the Software.
49
+ //
50
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
51
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
52
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
53
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
54
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
55
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
56
+ // THE SOFTWARE.
57
+
58
+ // String.prototype.codePointAt
59
+ //
60
+ // Copyright Mathias Bynens <https://mathiasbynens.be/>
61
+ // https://github.com/mathiasbynens/String.prototype.codePointAt
62
+ //
63
+ // Permission is hereby granted, free of charge, to any person obtaining
64
+ // a copy of this software and associated documentation files (the
65
+ // "Software"), to deal in the Software without restriction, including
66
+ // without limitation the rights to use, copy, modify, merge, publish,
67
+ // distribute, sublicense, and/or sell copies of the Software, and to
68
+ // permit persons to whom the Software is furnished to do so, subject to
69
+ // the following conditions:
70
+ //
71
+ // The above copyright notice and this permission notice shall be
72
+ // included in all copies or substantial portions of the Software.
73
+ //
74
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
75
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
76
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
77
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
78
+ // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
79
+ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
80
+ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
81
+
82
+ // String.fromCodePoint
83
+ //
84
+ // Copyright Mathias Bynens <https://mathiasbynens.be/>
85
+ // https://github.com/mathiasbynens/String.fromCodePoint
86
+ //
87
+ // Permission is hereby granted, free of charge, to any person obtaining
88
+ // a copy of this software and associated documentation files (the
89
+ // "Software"), to deal in the Software without restriction, including
90
+ // without limitation the rights to use, copy, modify, merge, publish,
91
+ // distribute, sublicense, and/or sell copies of the Software, and to
92
+ // permit persons to whom the Software is furnished to do so, subject to
93
+ // the following conditions:
94
+ //
95
+ // The above copyright notice and this permission notice shall be
96
+ // included in all copies or substantial portions of the Software.
97
+ //
98
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
99
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
100
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
101
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
102
+ // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
103
+ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
104
+ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
105
+
106
+ var stringFromCharCode = String.fromCharCode;
107
+ var floor = Math.floor;
108
+
109
+ /**
110
+ * Wide, Surrogates, and Combining
111
+ */
112
+
113
+ exports.charWidth = function(str, i) {
114
+ var point = typeof str !== 'number'
115
+ ? exports.codePointAt(str, i || 0)
116
+ : str;
117
+
118
+ // nul
119
+ if (point === 0) return 0;
120
+
121
+ // tab
122
+ if (point === 0x09) {
123
+ if (!exports.blessed) {
124
+ exports.blessed = require('../');
125
+ }
126
+ return exports.blessed.screen.global
127
+ ? exports.blessed.screen.global.tabc.length
128
+ : 8;
129
+ }
130
+
131
+ // 8-bit control characters (2-width according to unicode??)
132
+ if (point < 32 || (point >= 0x7f && point < 0xa0)) {
133
+ return 0;
134
+ }
135
+
136
+ // search table of non-spacing characters
137
+ // is ucs combining or C0/C1 control character
138
+ if (exports.combining[point]) {
139
+ return 0;
140
+ }
141
+
142
+ // check for double-wide
143
+ // if (point >= 0x1100
144
+ // && (point <= 0x115f // Hangul Jamo init. consonants
145
+ // || point === 0x2329 || point === 0x232a
146
+ // || (point >= 0x2e80 && point <= 0xa4cf
147
+ // && point !== 0x303f) // CJK ... Yi
148
+ // || (point >= 0xac00 && point <= 0xd7a3) // Hangul Syllables
149
+ // || (point >= 0xf900 && point <= 0xfaff) // CJK Compatibility Ideographs
150
+ // || (point >= 0xfe10 && point <= 0xfe19) // Vertical forms
151
+ // || (point >= 0xfe30 && point <= 0xfe6f) // CJK Compatibility Forms
152
+ // || (point >= 0xff00 && point <= 0xff60) // Fullwidth Forms
153
+ // || (point >= 0xffe0 && point <= 0xffe6)
154
+ // || (point >= 0x20000 && point <= 0x2fffd)
155
+ // || (point >= 0x30000 && point <= 0x3fffd))) {
156
+ // return 2;
157
+ // }
158
+
159
+ // check for double-wide
160
+ if ((0x3000 === point)
161
+ || (0xFF01 <= point && point <= 0xFF60)
162
+ || (0xFFE0 <= point && point <= 0xFFE6)) {
163
+ return 2;
164
+ }
165
+
166
+ if ((0x1100 <= point && point <= 0x115F)
167
+ || (0x11A3 <= point && point <= 0x11A7)
168
+ || (0x11FA <= point && point <= 0x11FF)
169
+ || (0x2329 <= point && point <= 0x232A)
170
+ || (0x2E80 <= point && point <= 0x2E99)
171
+ || (0x2E9B <= point && point <= 0x2EF3)
172
+ || (0x2F00 <= point && point <= 0x2FD5)
173
+ || (0x2FF0 <= point && point <= 0x2FFB)
174
+ || (0x3001 <= point && point <= 0x303E)
175
+ || (0x3041 <= point && point <= 0x3096)
176
+ || (0x3099 <= point && point <= 0x30FF)
177
+ || (0x3105 <= point && point <= 0x312D)
178
+ || (0x3131 <= point && point <= 0x318E)
179
+ || (0x3190 <= point && point <= 0x31BA)
180
+ || (0x31C0 <= point && point <= 0x31E3)
181
+ || (0x31F0 <= point && point <= 0x321E)
182
+ || (0x3220 <= point && point <= 0x3247)
183
+ || (0x3250 <= point && point <= 0x32FE)
184
+ || (0x3300 <= point && point <= 0x4DBF)
185
+ || (0x4E00 <= point && point <= 0xA48C)
186
+ || (0xA490 <= point && point <= 0xA4C6)
187
+ || (0xA960 <= point && point <= 0xA97C)
188
+ || (0xAC00 <= point && point <= 0xD7A3)
189
+ || (0xD7B0 <= point && point <= 0xD7C6)
190
+ || (0xD7CB <= point && point <= 0xD7FB)
191
+ || (0xF900 <= point && point <= 0xFAFF)
192
+ || (0xFE10 <= point && point <= 0xFE19)
193
+ || (0xFE30 <= point && point <= 0xFE52)
194
+ || (0xFE54 <= point && point <= 0xFE66)
195
+ || (0xFE68 <= point && point <= 0xFE6B)
196
+ || (0x1B000 <= point && point <= 0x1B001)
197
+ || (0x1F200 <= point && point <= 0x1F202)
198
+ || (0x1F210 <= point && point <= 0x1F23A)
199
+ || (0x1F240 <= point && point <= 0x1F248)
200
+ || (0x1F250 <= point && point <= 0x1F251)
201
+ || (0x20000 <= point && point <= 0x2F73F)
202
+ || (0x2B740 <= point && point <= 0x2FFFD)
203
+ || (0x30000 <= point && point <= 0x3FFFD)) {
204
+ return 2;
205
+ }
206
+
207
+ // Emoji rendered on two columns by modern terminals (Unicode >= 9,
208
+ // East_Asian_Width=W). The original table predates them: an emoji
209
+ // counted as 1 cell shifts every following cell of the line by one on
210
+ // the real terminal, and the shifted cells are never redrawn (pm2 #5397).
211
+ if (exports.isWideEmoji(point)) {
212
+ return 2;
213
+ }
214
+
215
+ // CJK Ambiguous
216
+ // http://www.unicode.org/reports/tr11/
217
+ // http://www.unicode.org/reports/tr11/#Ambiguous
218
+ if (process.env.NCURSES_CJK_WIDTH) {
219
+ if ((0x00A1 === point)
220
+ || (0x00A4 === point)
221
+ || (0x00A7 <= point && point <= 0x00A8)
222
+ || (0x00AA === point)
223
+ || (0x00AD <= point && point <= 0x00AE)
224
+ || (0x00B0 <= point && point <= 0x00B4)
225
+ || (0x00B6 <= point && point <= 0x00BA)
226
+ || (0x00BC <= point && point <= 0x00BF)
227
+ || (0x00C6 === point)
228
+ || (0x00D0 === point)
229
+ || (0x00D7 <= point && point <= 0x00D8)
230
+ || (0x00DE <= point && point <= 0x00E1)
231
+ || (0x00E6 === point)
232
+ || (0x00E8 <= point && point <= 0x00EA)
233
+ || (0x00EC <= point && point <= 0x00ED)
234
+ || (0x00F0 === point)
235
+ || (0x00F2 <= point && point <= 0x00F3)
236
+ || (0x00F7 <= point && point <= 0x00FA)
237
+ || (0x00FC === point)
238
+ || (0x00FE === point)
239
+ || (0x0101 === point)
240
+ || (0x0111 === point)
241
+ || (0x0113 === point)
242
+ || (0x011B === point)
243
+ || (0x0126 <= point && point <= 0x0127)
244
+ || (0x012B === point)
245
+ || (0x0131 <= point && point <= 0x0133)
246
+ || (0x0138 === point)
247
+ || (0x013F <= point && point <= 0x0142)
248
+ || (0x0144 === point)
249
+ || (0x0148 <= point && point <= 0x014B)
250
+ || (0x014D === point)
251
+ || (0x0152 <= point && point <= 0x0153)
252
+ || (0x0166 <= point && point <= 0x0167)
253
+ || (0x016B === point)
254
+ || (0x01CE === point)
255
+ || (0x01D0 === point)
256
+ || (0x01D2 === point)
257
+ || (0x01D4 === point)
258
+ || (0x01D6 === point)
259
+ || (0x01D8 === point)
260
+ || (0x01DA === point)
261
+ || (0x01DC === point)
262
+ || (0x0251 === point)
263
+ || (0x0261 === point)
264
+ || (0x02C4 === point)
265
+ || (0x02C7 === point)
266
+ || (0x02C9 <= point && point <= 0x02CB)
267
+ || (0x02CD === point)
268
+ || (0x02D0 === point)
269
+ || (0x02D8 <= point && point <= 0x02DB)
270
+ || (0x02DD === point)
271
+ || (0x02DF === point)
272
+ || (0x0300 <= point && point <= 0x036F)
273
+ || (0x0391 <= point && point <= 0x03A1)
274
+ || (0x03A3 <= point && point <= 0x03A9)
275
+ || (0x03B1 <= point && point <= 0x03C1)
276
+ || (0x03C3 <= point && point <= 0x03C9)
277
+ || (0x0401 === point)
278
+ || (0x0410 <= point && point <= 0x044F)
279
+ || (0x0451 === point)
280
+ || (0x2010 === point)
281
+ || (0x2013 <= point && point <= 0x2016)
282
+ || (0x2018 <= point && point <= 0x2019)
283
+ || (0x201C <= point && point <= 0x201D)
284
+ || (0x2020 <= point && point <= 0x2022)
285
+ || (0x2024 <= point && point <= 0x2027)
286
+ || (0x2030 === point)
287
+ || (0x2032 <= point && point <= 0x2033)
288
+ || (0x2035 === point)
289
+ || (0x203B === point)
290
+ || (0x203E === point)
291
+ || (0x2074 === point)
292
+ || (0x207F === point)
293
+ || (0x2081 <= point && point <= 0x2084)
294
+ || (0x20AC === point)
295
+ || (0x2103 === point)
296
+ || (0x2105 === point)
297
+ || (0x2109 === point)
298
+ || (0x2113 === point)
299
+ || (0x2116 === point)
300
+ || (0x2121 <= point && point <= 0x2122)
301
+ || (0x2126 === point)
302
+ || (0x212B === point)
303
+ || (0x2153 <= point && point <= 0x2154)
304
+ || (0x215B <= point && point <= 0x215E)
305
+ || (0x2160 <= point && point <= 0x216B)
306
+ || (0x2170 <= point && point <= 0x2179)
307
+ || (0x2189 === point)
308
+ || (0x2190 <= point && point <= 0x2199)
309
+ || (0x21B8 <= point && point <= 0x21B9)
310
+ || (0x21D2 === point)
311
+ || (0x21D4 === point)
312
+ || (0x21E7 === point)
313
+ || (0x2200 === point)
314
+ || (0x2202 <= point && point <= 0x2203)
315
+ || (0x2207 <= point && point <= 0x2208)
316
+ || (0x220B === point)
317
+ || (0x220F === point)
318
+ || (0x2211 === point)
319
+ || (0x2215 === point)
320
+ || (0x221A === point)
321
+ || (0x221D <= point && point <= 0x2220)
322
+ || (0x2223 === point)
323
+ || (0x2225 === point)
324
+ || (0x2227 <= point && point <= 0x222C)
325
+ || (0x222E === point)
326
+ || (0x2234 <= point && point <= 0x2237)
327
+ || (0x223C <= point && point <= 0x223D)
328
+ || (0x2248 === point)
329
+ || (0x224C === point)
330
+ || (0x2252 === point)
331
+ || (0x2260 <= point && point <= 0x2261)
332
+ || (0x2264 <= point && point <= 0x2267)
333
+ || (0x226A <= point && point <= 0x226B)
334
+ || (0x226E <= point && point <= 0x226F)
335
+ || (0x2282 <= point && point <= 0x2283)
336
+ || (0x2286 <= point && point <= 0x2287)
337
+ || (0x2295 === point)
338
+ || (0x2299 === point)
339
+ || (0x22A5 === point)
340
+ || (0x22BF === point)
341
+ || (0x2312 === point)
342
+ || (0x2460 <= point && point <= 0x24E9)
343
+ || (0x24EB <= point && point <= 0x254B)
344
+ || (0x2550 <= point && point <= 0x2573)
345
+ || (0x2580 <= point && point <= 0x258F)
346
+ || (0x2592 <= point && point <= 0x2595)
347
+ || (0x25A0 <= point && point <= 0x25A1)
348
+ || (0x25A3 <= point && point <= 0x25A9)
349
+ || (0x25B2 <= point && point <= 0x25B3)
350
+ || (0x25B6 <= point && point <= 0x25B7)
351
+ || (0x25BC <= point && point <= 0x25BD)
352
+ || (0x25C0 <= point && point <= 0x25C1)
353
+ || (0x25C6 <= point && point <= 0x25C8)
354
+ || (0x25CB === point)
355
+ || (0x25CE <= point && point <= 0x25D1)
356
+ || (0x25E2 <= point && point <= 0x25E5)
357
+ || (0x25EF === point)
358
+ || (0x2605 <= point && point <= 0x2606)
359
+ || (0x2609 === point)
360
+ || (0x260E <= point && point <= 0x260F)
361
+ || (0x2614 <= point && point <= 0x2615)
362
+ || (0x261C === point)
363
+ || (0x261E === point)
364
+ || (0x2640 === point)
365
+ || (0x2642 === point)
366
+ || (0x2660 <= point && point <= 0x2661)
367
+ || (0x2663 <= point && point <= 0x2665)
368
+ || (0x2667 <= point && point <= 0x266A)
369
+ || (0x266C <= point && point <= 0x266D)
370
+ || (0x266F === point)
371
+ || (0x269E <= point && point <= 0x269F)
372
+ || (0x26BE <= point && point <= 0x26BF)
373
+ || (0x26C4 <= point && point <= 0x26CD)
374
+ || (0x26CF <= point && point <= 0x26E1)
375
+ || (0x26E3 === point)
376
+ || (0x26E8 <= point && point <= 0x26FF)
377
+ || (0x273D === point)
378
+ || (0x2757 === point)
379
+ || (0x2776 <= point && point <= 0x277F)
380
+ || (0x2B55 <= point && point <= 0x2B59)
381
+ || (0x3248 <= point && point <= 0x324F)
382
+ || (0xE000 <= point && point <= 0xF8FF)
383
+ || (0xFE00 <= point && point <= 0xFE0F)
384
+ || (0xFFFD === point)
385
+ || (0x1F100 <= point && point <= 0x1F10A)
386
+ || (0x1F110 <= point && point <= 0x1F12D)
387
+ || (0x1F130 <= point && point <= 0x1F169)
388
+ || (0x1F170 <= point && point <= 0x1F19A)
389
+ || (0xE0100 <= point && point <= 0xE01EF)
390
+ || (0xF0000 <= point && point <= 0xFFFFD)
391
+ || (0x100000 <= point && point <= 0x10FFFD)) {
392
+ return +process.env.NCURSES_CJK_WIDTH || 1;
393
+ }
394
+ }
395
+
396
+ return 1;
397
+ };
398
+
399
+ // Emoji code points with a default emoji (wide) presentation, plus the
400
+ // BMP symbols terminals render wide (✅ ❌ ⚡ ⭐ …). Ranges follow
401
+ // emoji-data.txt Extended_Pictographic ∩ East_Asian_Width=W. Regional
402
+ // indicators (flags) are left at 1 so a pair takes 2 cells, like wcwidth.
403
+ // Known limits: ZWJ sequences (👨‍👩‍👧) and U+FE0F presentation selectors
404
+ // (❤️) are still measured per code point.
405
+ exports.wideEmojiTable = [
406
+ [0x231A, 0x231B], [0x23E9, 0x23EC], [0x23F0, 0x23F0],
407
+ [0x23F3, 0x23F3], [0x25FD, 0x25FE], [0x2614, 0x2615],
408
+ [0x2648, 0x2653], [0x267F, 0x267F], [0x2693, 0x2693],
409
+ [0x26A1, 0x26A1], [0x26AA, 0x26AB], [0x26BD, 0x26BE],
410
+ [0x26C4, 0x26C5], [0x26CE, 0x26CE], [0x26D4, 0x26D4],
411
+ [0x26EA, 0x26EA], [0x26F2, 0x26F3], [0x26F5, 0x26F5],
412
+ [0x26FA, 0x26FA], [0x26FD, 0x26FD], [0x2705, 0x2705],
413
+ [0x270A, 0x270B], [0x2728, 0x2728], [0x274C, 0x274C],
414
+ [0x274E, 0x274E], [0x2753, 0x2755], [0x2757, 0x2757],
415
+ [0x2795, 0x2797], [0x27B0, 0x27B0], [0x27BF, 0x27BF],
416
+ [0x2B1B, 0x2B1C], [0x2B50, 0x2B50], [0x2B55, 0x2B55],
417
+ [0x1F004, 0x1F004], [0x1F0CF, 0x1F0CF], [0x1F18E, 0x1F18E],
418
+ [0x1F191, 0x1F19A], [0x1F201, 0x1F201],
419
+ [0x1F21A, 0x1F21A], [0x1F22F, 0x1F22F], [0x1F232, 0x1F236],
420
+ [0x1F238, 0x1F23A], [0x1F250, 0x1F251], [0x1F300, 0x1F320],
421
+ [0x1F32D, 0x1F335], [0x1F337, 0x1F37C], [0x1F37E, 0x1F393],
422
+ [0x1F3A0, 0x1F3CA], [0x1F3CF, 0x1F3D3], [0x1F3E0, 0x1F3F0],
423
+ [0x1F3F4, 0x1F3F4], [0x1F3F8, 0x1F43E], [0x1F440, 0x1F440],
424
+ [0x1F442, 0x1F4FC], [0x1F4FF, 0x1F53D], [0x1F54B, 0x1F54E],
425
+ [0x1F550, 0x1F567], [0x1F57A, 0x1F57A], [0x1F595, 0x1F596],
426
+ [0x1F5A4, 0x1F5A4], [0x1F5FB, 0x1F64F], [0x1F680, 0x1F6C5],
427
+ [0x1F6CC, 0x1F6CC], [0x1F6D0, 0x1F6D2], [0x1F6D5, 0x1F6D7],
428
+ [0x1F6DC, 0x1F6DF], [0x1F6EB, 0x1F6EC], [0x1F6F4, 0x1F6FC],
429
+ [0x1F7E0, 0x1F7EB], [0x1F7F0, 0x1F7F0], [0x1F90C, 0x1F93A],
430
+ [0x1F93C, 0x1F945], [0x1F947, 0x1F9FF], [0x1FA70, 0x1FA7C],
431
+ [0x1FA80, 0x1FA89], [0x1FA8F, 0x1FAC6], [0x1FACE, 0x1FADC],
432
+ [0x1FADF, 0x1FAE9], [0x1FAF0, 0x1FAF8]
433
+ ];
434
+
435
+ exports.isWideEmoji = function(point) {
436
+ var table = exports.wideEmojiTable;
437
+ var lo = 0, hi = table.length - 1;
438
+ if (point < table[0][0] || point > table[hi][1]) return false;
439
+ while (lo <= hi) {
440
+ var mid = (lo + hi) >> 1;
441
+ if (point < table[mid][0]) hi = mid - 1;
442
+ else if (point > table[mid][1]) lo = mid + 1;
443
+ else return true;
444
+ }
445
+ return false;
446
+ };
447
+
448
+ exports.strWidth = function(str) {
449
+ var width = 0;
450
+ for (var i = 0; i < str.length; i++) {
451
+ width += exports.charWidth(str, i);
452
+ if (exports.isSurrogate(str, i)) i++;
453
+ }
454
+ return width;
455
+ };
456
+
457
+ exports.isSurrogate = function(str, i) {
458
+ var point = typeof str !== 'number'
459
+ ? exports.codePointAt(str, i || 0)
460
+ : str;
461
+ return point > 0x00ffff;
462
+ };
463
+
464
+ exports.combiningTable = [
465
+ [0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489],
466
+ [0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2],
467
+ [0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603],
468
+ [0x0610, 0x0615], [0x064B, 0x065E], [0x0670, 0x0670],
469
+ [0x06D6, 0x06E4], [0x06E7, 0x06E8], [0x06EA, 0x06ED],
470
+ [0x070F, 0x070F], [0x0711, 0x0711], [0x0730, 0x074A],
471
+ [0x07A6, 0x07B0], [0x07EB, 0x07F3], [0x0901, 0x0902],
472
+ [0x093C, 0x093C], [0x0941, 0x0948], [0x094D, 0x094D],
473
+ [0x0951, 0x0954], [0x0962, 0x0963], [0x0981, 0x0981],
474
+ [0x09BC, 0x09BC], [0x09C1, 0x09C4], [0x09CD, 0x09CD],
475
+ [0x09E2, 0x09E3], [0x0A01, 0x0A02], [0x0A3C, 0x0A3C],
476
+ [0x0A41, 0x0A42], [0x0A47, 0x0A48], [0x0A4B, 0x0A4D],
477
+ [0x0A70, 0x0A71], [0x0A81, 0x0A82], [0x0ABC, 0x0ABC],
478
+ [0x0AC1, 0x0AC5], [0x0AC7, 0x0AC8], [0x0ACD, 0x0ACD],
479
+ [0x0AE2, 0x0AE3], [0x0B01, 0x0B01], [0x0B3C, 0x0B3C],
480
+ [0x0B3F, 0x0B3F], [0x0B41, 0x0B43], [0x0B4D, 0x0B4D],
481
+ [0x0B56, 0x0B56], [0x0B82, 0x0B82], [0x0BC0, 0x0BC0],
482
+ [0x0BCD, 0x0BCD], [0x0C3E, 0x0C40], [0x0C46, 0x0C48],
483
+ [0x0C4A, 0x0C4D], [0x0C55, 0x0C56], [0x0CBC, 0x0CBC],
484
+ [0x0CBF, 0x0CBF], [0x0CC6, 0x0CC6], [0x0CCC, 0x0CCD],
485
+ [0x0CE2, 0x0CE3], [0x0D41, 0x0D43], [0x0D4D, 0x0D4D],
486
+ [0x0DCA, 0x0DCA], [0x0DD2, 0x0DD4], [0x0DD6, 0x0DD6],
487
+ [0x0E31, 0x0E31], [0x0E34, 0x0E3A], [0x0E47, 0x0E4E],
488
+ [0x0EB1, 0x0EB1], [0x0EB4, 0x0EB9], [0x0EBB, 0x0EBC],
489
+ [0x0EC8, 0x0ECD], [0x0F18, 0x0F19], [0x0F35, 0x0F35],
490
+ [0x0F37, 0x0F37], [0x0F39, 0x0F39], [0x0F71, 0x0F7E],
491
+ [0x0F80, 0x0F84], [0x0F86, 0x0F87], [0x0F90, 0x0F97],
492
+ [0x0F99, 0x0FBC], [0x0FC6, 0x0FC6], [0x102D, 0x1030],
493
+ [0x1032, 0x1032], [0x1036, 0x1037], [0x1039, 0x1039],
494
+ [0x1058, 0x1059], [0x1160, 0x11FF], [0x135F, 0x135F],
495
+ [0x1712, 0x1714], [0x1732, 0x1734], [0x1752, 0x1753],
496
+ [0x1772, 0x1773], [0x17B4, 0x17B5], [0x17B7, 0x17BD],
497
+ [0x17C6, 0x17C6], [0x17C9, 0x17D3], [0x17DD, 0x17DD],
498
+ [0x180B, 0x180D], [0x18A9, 0x18A9], [0x1920, 0x1922],
499
+ [0x1927, 0x1928], [0x1932, 0x1932], [0x1939, 0x193B],
500
+ [0x1A17, 0x1A18], [0x1B00, 0x1B03], [0x1B34, 0x1B34],
501
+ [0x1B36, 0x1B3A], [0x1B3C, 0x1B3C], [0x1B42, 0x1B42],
502
+ [0x1B6B, 0x1B73], [0x1DC0, 0x1DCA], [0x1DFE, 0x1DFF],
503
+ [0x200B, 0x200F], [0x202A, 0x202E], [0x2060, 0x2063],
504
+ [0x206A, 0x206F], [0x20D0, 0x20EF], [0x302A, 0x302F],
505
+ [0x3099, 0x309A], [0xA806, 0xA806], [0xA80B, 0xA80B],
506
+ [0xA825, 0xA826], [0xFB1E, 0xFB1E], [0xFE00, 0xFE0F],
507
+ [0xFE20, 0xFE23], [0xFEFF, 0xFEFF], [0xFFF9, 0xFFFB],
508
+ [0x10A01, 0x10A03], [0x10A05, 0x10A06], [0x10A0C, 0x10A0F],
509
+ [0x10A38, 0x10A3A], [0x10A3F, 0x10A3F], [0x1D167, 0x1D169],
510
+ [0x1D173, 0x1D182], [0x1D185, 0x1D18B], [0x1D1AA, 0x1D1AD],
511
+ [0x1D242, 0x1D244], [0xE0001, 0xE0001], [0xE0020, 0xE007F],
512
+ [0xE0100, 0xE01EF]
513
+ ];
514
+
515
+ exports.combining = exports.combiningTable.reduce(function(out, row) {
516
+ for (var i = row[0]; i <= row[1]; i++) {
517
+ out[i] = true;
518
+ }
519
+ return out;
520
+ }, {});
521
+
522
+ exports.isCombining = function(str, i) {
523
+ var point = typeof str !== 'number'
524
+ ? exports.codePointAt(str, i || 0)
525
+ : str;
526
+ return exports.combining[point] === true;
527
+ };
528
+
529
+ /**
530
+ * Code Point Helpers
531
+ */
532
+
533
+ exports.codePointAt = function(str, position) {
534
+ if (str == null) {
535
+ throw TypeError();
536
+ }
537
+ var string = String(str);
538
+ if (string.codePointAt) {
539
+ return string.codePointAt(position);
540
+ }
541
+ var size = string.length;
542
+ // `ToInteger`
543
+ var index = position ? Number(position) : 0;
544
+ if (index !== index) { // better `isNaN`
545
+ index = 0;
546
+ }
547
+ // Account for out-of-bounds indices:
548
+ if (index < 0 || index >= size) {
549
+ return undefined;
550
+ }
551
+ // Get the first code unit
552
+ var first = string.charCodeAt(index);
553
+ var second;
554
+ if ( // check if it’s the start of a surrogate pair
555
+ first >= 0xD800 && first <= 0xDBFF && // high surrogate
556
+ size > index + 1 // there is a next code unit
557
+ ) {
558
+ second = string.charCodeAt(index + 1);
559
+ if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate
560
+ // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
561
+ return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
562
+ }
563
+ }
564
+ return first;
565
+ };
566
+
567
+ // exports.codePointAt = function(str, position) {
568
+ // position = +position || 0;
569
+ // var x = str.charCodeAt(position);
570
+ // var y = str.length > 1 ? str.charCodeAt(position + 1) : 0;
571
+ // var point = x;
572
+ // if ((0xD800 <= x && x <= 0xDBFF) && (0xDC00 <= y && y <= 0xDFFF)) {
573
+ // x &= 0x3FF;
574
+ // y &= 0x3FF;
575
+ // point = (x << 10) | y;
576
+ // point += 0x10000;
577
+ // }
578
+ // return point;
579
+ // };
580
+
581
+ exports.fromCodePoint = function() {
582
+ if (String.fromCodePoint) {
583
+ return String.fromCodePoint.apply(String, arguments);
584
+ }
585
+ var MAX_SIZE = 0x4000;
586
+ var codeUnits = [];
587
+ var highSurrogate;
588
+ var lowSurrogate;
589
+ var index = -1;
590
+ var length = arguments.length;
591
+ if (!length) {
592
+ return '';
593
+ }
594
+ var result = '';
595
+ while (++index < length) {
596
+ var codePoint = Number(arguments[index]);
597
+ if (
598
+ !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
599
+ codePoint < 0 || // not a valid Unicode code point
600
+ codePoint > 0x10FFFF || // not a valid Unicode code point
601
+ floor(codePoint) !== codePoint // not an integer
602
+ ) {
603
+ throw RangeError('Invalid code point: ' + codePoint);
604
+ }
605
+ if (codePoint <= 0xFFFF) { // BMP code point
606
+ codeUnits.push(codePoint);
607
+ } else { // Astral code point; split in surrogate halves
608
+ // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
609
+ codePoint -= 0x10000;
610
+ highSurrogate = (codePoint >> 10) + 0xD800;
611
+ lowSurrogate = (codePoint % 0x400) + 0xDC00;
612
+ codeUnits.push(highSurrogate, lowSurrogate);
613
+ }
614
+ if (index + 1 === length || codeUnits.length > MAX_SIZE) {
615
+ result += stringFromCharCode.apply(null, codeUnits);
616
+ codeUnits.length = 0;
617
+ }
618
+ }
619
+ return result;
620
+ };
621
+
622
+ /**
623
+ * Regexes
624
+ */
625
+
626
+ exports.chars = {};
627
+
628
+ // Double width characters that are _not_ surrogate pairs.
629
+ // NOTE: 0x20000 - 0x2fffd and 0x30000 - 0x3fffd are not necessary for this
630
+ // regex anyway. This regex is used to put a blank char after wide chars to
631
+ // be eaten, however, if this is a surrogate pair, parseContent already adds
632
+ // the extra one char because its length equals 2 instead of 1.
633
+ exports.chars.wide = new RegExp('(['
634
+ + '\\u1100-\\u115f' // Hangul Jamo init. consonants
635
+ + '\\u2329\\u232a'
636
+ + '\\u2e80-\\u303e\\u3040-\\ua4cf' // CJK ... Yi
637
+ + '\\uac00-\\ud7a3' // Hangul Syllables
638
+ + '\\uf900-\\ufaff' // CJK Compatibility Ideographs
639
+ + '\\ufe10-\\ufe19' // Vertical forms
640
+ + '\\ufe30-\\ufe6f' // CJK Compatibility Forms
641
+ + '\\uff00-\\uff60' // Fullwidth Forms
642
+ + '\\uffe0-\\uffe6'
643
+ + '])', 'g');
644
+
645
+ // Regex sources for the wide emoji table (see charWidth): a BMP character
646
+ // class and surrogate pair alternatives for the astral ranges.
647
+ function hex4(n) {
648
+ return '\\u' + ('0000' + n.toString(16)).slice(-4);
649
+ }
650
+
651
+ function emojiSources() {
652
+ var bmp = '';
653
+ var astral = [];
654
+ exports.wideEmojiTable.forEach(function(row) {
655
+ var lo = row[0], hi = row[1];
656
+ if (hi <= 0xFFFF) {
657
+ bmp += lo === hi ? hex4(lo) : hex4(lo) + '-' + hex4(hi);
658
+ return;
659
+ }
660
+ // split the range on high surrogate boundaries
661
+ while (lo <= hi) {
662
+ var high = 0xD800 + ((lo - 0x10000) >> 10);
663
+ var last = Math.min(hi, ((high - 0xD800 + 1) << 10) + 0x10000 - 1);
664
+ var l = 0xDC00 + ((lo - 0x10000) & 0x3FF);
665
+ var h = 0xDC00 + ((last - 0x10000) & 0x3FF);
666
+ astral.push(hex4(high) + (l === h ? hex4(l) : '[' + hex4(l) + '-' + hex4(h) + ']'));
667
+ lo = last + 1;
668
+ }
669
+ });
670
+ return { bmp: bmp, astral: astral.join('|') };
671
+ }
672
+
673
+ var emoji = emojiSources();
674
+
675
+ exports.chars.wide = new RegExp('(['
676
+ + exports.chars.wide.source.slice(2, -2)
677
+ + emoji.bmp
678
+ + '])', 'g');
679
+
680
+ // All surrogate pair wide chars.
681
+ exports.chars.swide = new RegExp('('
682
+ // 0x20000 - 0x2fffd:
683
+ + '[\\ud840-\\ud87f][\\udc00-\\udffd]'
684
+ + '|'
685
+ // 0x30000 - 0x3fffd:
686
+ + '[\\ud880-\\ud8bf][\\udc00-\\udffd]'
687
+ + '|'
688
+ // emoji
689
+ + emoji.astral
690
+ + ')', 'g');
691
+
692
+ // All wide chars including surrogate pairs.
693
+ exports.chars.all = new RegExp('('
694
+ + exports.chars.swide.source.slice(1, -1)
695
+ + '|'
696
+ + exports.chars.wide.source.slice(1, -1)
697
+ + ')', 'g');
698
+
699
+ // Regex to detect a surrogate pair.
700
+ exports.chars.surrogate = /[\ud800-\udbff][\udc00-\udfff]/g;
701
+
702
+ // Regex to find combining characters.
703
+ exports.chars.combining = exports.combiningTable.reduce(function(out, row) {
704
+ var low, high, range;
705
+ if (row[0] > 0x00ffff) {
706
+ low = exports.fromCodePoint(row[0]);
707
+ low = [
708
+ hexify(low.charCodeAt(0)),
709
+ hexify(low.charCodeAt(1))
710
+ ];
711
+ high = exports.fromCodePoint(row[1]);
712
+ high = [
713
+ hexify(high.charCodeAt(0)),
714
+ hexify(high.charCodeAt(1))
715
+ ];
716
+ range = '[\\u' + low[0] + '-' + '\\u' + high[0] + ']'
717
+ + '[\\u' + low[1] + '-' + '\\u' + high[1] + ']';
718
+ if (!~out.indexOf('|')) out += ']';
719
+ out += '|' + range;
720
+ } else {
721
+ low = hexify(row[0]);
722
+ high = hexify(row[1]);
723
+ low = '\\u' + low;
724
+ high = '\\u' + high;
725
+ out += low + '-' + high;
726
+ }
727
+ return out;
728
+ }, '[');
729
+
730
+ exports.chars.combining = new RegExp(exports.chars.combining, 'g');
731
+
732
+ function hexify(n) {
733
+ n = n.toString(16);
734
+ while (n.length < 4) n = '0' + n;
735
+ return n;
736
+ }
737
+
738
+ /*
739
+ exports.chars.combining = new RegExp(
740
+ '['
741
+ + '\\u0300-\\u036f'
742
+ + '\\u0483-\\u0486'
743
+ + '\\u0488-\\u0489'
744
+ + '\\u0591-\\u05bd'
745
+ + '\\u05bf-\\u05bf'
746
+ + '\\u05c1-\\u05c2'
747
+ + '\\u05c4-\\u05c5'
748
+ + '\\u05c7-\\u05c7'
749
+ + '\\u0600-\\u0603'
750
+ + '\\u0610-\\u0615'
751
+ + '\\u064b-\\u065e'
752
+ + '\\u0670-\\u0670'
753
+ + '\\u06d6-\\u06e4'
754
+ + '\\u06e7-\\u06e8'
755
+ + '\\u06ea-\\u06ed'
756
+ + '\\u070f-\\u070f'
757
+ + '\\u0711-\\u0711'
758
+ + '\\u0730-\\u074a'
759
+ + '\\u07a6-\\u07b0'
760
+ + '\\u07eb-\\u07f3'
761
+ + '\\u0901-\\u0902'
762
+ + '\\u093c-\\u093c'
763
+ + '\\u0941-\\u0948'
764
+ + '\\u094d-\\u094d'
765
+ + '\\u0951-\\u0954'
766
+ + '\\u0962-\\u0963'
767
+ + '\\u0981-\\u0981'
768
+ + '\\u09bc-\\u09bc'
769
+ + '\\u09c1-\\u09c4'
770
+ + '\\u09cd-\\u09cd'
771
+ + '\\u09e2-\\u09e3'
772
+ + '\\u0a01-\\u0a02'
773
+ + '\\u0a3c-\\u0a3c'
774
+ + '\\u0a41-\\u0a42'
775
+ + '\\u0a47-\\u0a48'
776
+ + '\\u0a4b-\\u0a4d'
777
+ + '\\u0a70-\\u0a71'
778
+ + '\\u0a81-\\u0a82'
779
+ + '\\u0abc-\\u0abc'
780
+ + '\\u0ac1-\\u0ac5'
781
+ + '\\u0ac7-\\u0ac8'
782
+ + '\\u0acd-\\u0acd'
783
+ + '\\u0ae2-\\u0ae3'
784
+ + '\\u0b01-\\u0b01'
785
+ + '\\u0b3c-\\u0b3c'
786
+ + '\\u0b3f-\\u0b3f'
787
+ + '\\u0b41-\\u0b43'
788
+ + '\\u0b4d-\\u0b4d'
789
+ + '\\u0b56-\\u0b56'
790
+ + '\\u0b82-\\u0b82'
791
+ + '\\u0bc0-\\u0bc0'
792
+ + '\\u0bcd-\\u0bcd'
793
+ + '\\u0c3e-\\u0c40'
794
+ + '\\u0c46-\\u0c48'
795
+ + '\\u0c4a-\\u0c4d'
796
+ + '\\u0c55-\\u0c56'
797
+ + '\\u0cbc-\\u0cbc'
798
+ + '\\u0cbf-\\u0cbf'
799
+ + '\\u0cc6-\\u0cc6'
800
+ + '\\u0ccc-\\u0ccd'
801
+ + '\\u0ce2-\\u0ce3'
802
+ + '\\u0d41-\\u0d43'
803
+ + '\\u0d4d-\\u0d4d'
804
+ + '\\u0dca-\\u0dca'
805
+ + '\\u0dd2-\\u0dd4'
806
+ + '\\u0dd6-\\u0dd6'
807
+ + '\\u0e31-\\u0e31'
808
+ + '\\u0e34-\\u0e3a'
809
+ + '\\u0e47-\\u0e4e'
810
+ + '\\u0eb1-\\u0eb1'
811
+ + '\\u0eb4-\\u0eb9'
812
+ + '\\u0ebb-\\u0ebc'
813
+ + '\\u0ec8-\\u0ecd'
814
+ + '\\u0f18-\\u0f19'
815
+ + '\\u0f35-\\u0f35'
816
+ + '\\u0f37-\\u0f37'
817
+ + '\\u0f39-\\u0f39'
818
+ + '\\u0f71-\\u0f7e'
819
+ + '\\u0f80-\\u0f84'
820
+ + '\\u0f86-\\u0f87'
821
+ + '\\u0f90-\\u0f97'
822
+ + '\\u0f99-\\u0fbc'
823
+ + '\\u0fc6-\\u0fc6'
824
+ + '\\u102d-\\u1030'
825
+ + '\\u1032-\\u1032'
826
+ + '\\u1036-\\u1037'
827
+ + '\\u1039-\\u1039'
828
+ + '\\u1058-\\u1059'
829
+ + '\\u1160-\\u11ff'
830
+ + '\\u135f-\\u135f'
831
+ + '\\u1712-\\u1714'
832
+ + '\\u1732-\\u1734'
833
+ + '\\u1752-\\u1753'
834
+ + '\\u1772-\\u1773'
835
+ + '\\u17b4-\\u17b5'
836
+ + '\\u17b7-\\u17bd'
837
+ + '\\u17c6-\\u17c6'
838
+ + '\\u17c9-\\u17d3'
839
+ + '\\u17dd-\\u17dd'
840
+ + '\\u180b-\\u180d'
841
+ + '\\u18a9-\\u18a9'
842
+ + '\\u1920-\\u1922'
843
+ + '\\u1927-\\u1928'
844
+ + '\\u1932-\\u1932'
845
+ + '\\u1939-\\u193b'
846
+ + '\\u1a17-\\u1a18'
847
+ + '\\u1b00-\\u1b03'
848
+ + '\\u1b34-\\u1b34'
849
+ + '\\u1b36-\\u1b3a'
850
+ + '\\u1b3c-\\u1b3c'
851
+ + '\\u1b42-\\u1b42'
852
+ + '\\u1b6b-\\u1b73'
853
+ + '\\u1dc0-\\u1dca'
854
+ + '\\u1dfe-\\u1dff'
855
+ + '\\u200b-\\u200f'
856
+ + '\\u202a-\\u202e'
857
+ + '\\u2060-\\u2063'
858
+ + '\\u206a-\\u206f'
859
+ + '\\u20d0-\\u20ef'
860
+ + '\\u302a-\\u302f'
861
+ + '\\u3099-\\u309a'
862
+ + '\\ua806-\\ua806'
863
+ + '\\ua80b-\\ua80b'
864
+ + '\\ua825-\\ua826'
865
+ + '\\ufb1e-\\ufb1e'
866
+ + '\\ufe00-\\ufe0f'
867
+ + '\\ufe20-\\ufe23'
868
+ + '\\ufeff-\\ufeff'
869
+ + '\\ufff9-\\ufffb'
870
+ + ']'
871
+ + '|[\\ud802-\\ud802][\\ude01-\\ude03]'
872
+ + '|[\\ud802-\\ud802][\\ude05-\\ude06]'
873
+ + '|[\\ud802-\\ud802][\\ude0c-\\ude0f]'
874
+ + '|[\\ud802-\\ud802][\\ude38-\\ude3a]'
875
+ + '|[\\ud802-\\ud802][\\ude3f-\\ude3f]'
876
+ + '|[\\ud834-\\ud834][\\udd67-\\udd69]'
877
+ + '|[\\ud834-\\ud834][\\udd73-\\udd82]'
878
+ + '|[\\ud834-\\ud834][\\udd85-\\udd8b]'
879
+ + '|[\\ud834-\\ud834][\\uddaa-\\uddad]'
880
+ + '|[\\ud834-\\ud834][\\ude42-\\ude44]'
881
+ + '|[\\udb40-\\udb40][\\udc01-\\udc01]'
882
+ + '|[\\udb40-\\udb40][\\udc20-\\udc7f]'
883
+ + '|[\\udb40-\\udb40][\\udd00-\\uddef]'
884
+ , 'g');
885
+ */