typograf 6.15.0 → 7.0.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 (308) hide show
  1. package/CHANGELOG.md +447 -0
  2. package/LICENSE.md +1 -1
  3. package/README.md +1 -1
  4. package/dist/consts.d.ts +2 -0
  5. package/dist/data/be.d.ts +8 -0
  6. package/dist/data/bg.d.ts +8 -0
  7. package/dist/data/ca.d.ts +8 -0
  8. package/dist/data/common.d.ts +6 -0
  9. package/dist/data/cs.d.ts +8 -0
  10. package/dist/data/da.d.ts +8 -0
  11. package/dist/data/de.d.ts +8 -0
  12. package/dist/data/el.d.ts +8 -0
  13. package/dist/data/en-GB.d.ts +8 -0
  14. package/dist/data/en-US.d.ts +8 -0
  15. package/dist/data/eo.d.ts +8 -0
  16. package/dist/data/es.d.ts +8 -0
  17. package/dist/data/et.d.ts +8 -0
  18. package/dist/data/fi.d.ts +8 -0
  19. package/dist/data/fr.d.ts +9 -0
  20. package/dist/data/ga.d.ts +8 -0
  21. package/dist/data/hu.d.ts +8 -0
  22. package/dist/data/index.d.ts +1 -0
  23. package/dist/data/it.d.ts +8 -0
  24. package/dist/data/lv.d.ts +8 -0
  25. package/dist/data/nl.d.ts +8 -0
  26. package/dist/data/no.d.ts +8 -0
  27. package/dist/data/pl.d.ts +8 -0
  28. package/dist/data/ro.d.ts +8 -0
  29. package/dist/data/ru.d.ts +19 -0
  30. package/dist/data/sk.d.ts +8 -0
  31. package/dist/data/sl.d.ts +8 -0
  32. package/dist/data/sr.d.ts +8 -0
  33. package/dist/data/sv.d.ts +8 -0
  34. package/dist/data/tr.d.ts +8 -0
  35. package/dist/data/uk.d.ts +8 -0
  36. package/dist/data.d.ts +16 -0
  37. package/dist/groupIndexes.d.ts +1 -0
  38. package/dist/helpers/object.d.ts +4 -0
  39. package/dist/helpers/regExp.d.ts +4 -0
  40. package/dist/helpers/string.d.ts +6 -0
  41. package/dist/htmlEntities/index.d.ts +41 -0
  42. package/dist/htmlEntities/invisible.d.ts +2 -0
  43. package/dist/htmlEntities/visible.d.ts +2 -0
  44. package/dist/htmlTags/block.d.ts +1 -0
  45. package/dist/htmlTags/inline.d.ts +1 -0
  46. package/dist/locale.d.ts +5 -0
  47. package/dist/main.d.ts +130 -0
  48. package/dist/prefs.d.ts +6 -0
  49. package/dist/rule.d.ts +9 -0
  50. package/dist/rules/common/html/e-mail.d.ts +2 -0
  51. package/dist/rules/common/html/e-mail.test.d.ts +1 -0
  52. package/dist/rules/common/html/escape.d.ts +2 -0
  53. package/dist/rules/common/html/escape.test.d.ts +1 -0
  54. package/dist/rules/common/html/index.d.ts +1 -0
  55. package/dist/rules/common/html/nbr.d.ts +2 -0
  56. package/dist/rules/common/html/nbr.test.d.ts +1 -0
  57. package/dist/rules/common/html/p.d.ts +2 -0
  58. package/dist/rules/common/html/p.test.d.ts +1 -0
  59. package/dist/rules/common/html/processingAttrs.d.ts +4 -0
  60. package/dist/rules/common/html/quot.d.ts +2 -0
  61. package/dist/rules/common/html/quot.test.d.ts +1 -0
  62. package/dist/rules/common/html/stripTags.d.ts +2 -0
  63. package/dist/rules/common/html/stripTags.test.d.ts +1 -0
  64. package/dist/rules/common/html/url.d.ts +2 -0
  65. package/dist/rules/common/html/url.test.d.ts +1 -0
  66. package/dist/rules/common/index.d.ts +7 -0
  67. package/dist/rules/common/nbsp/afterNumber.d.ts +2 -0
  68. package/dist/rules/common/nbsp/afterNumber.test.d.ts +1 -0
  69. package/dist/rules/common/nbsp/afterParagraphMark.d.ts +2 -0
  70. package/dist/rules/common/nbsp/afterParagraphMark.test.d.ts +1 -0
  71. package/dist/rules/common/nbsp/afterSectionMark.d.ts +2 -0
  72. package/dist/rules/common/nbsp/afterSectionMark.test.d.ts +1 -0
  73. package/dist/rules/common/nbsp/afterShortWord.d.ts +4 -0
  74. package/dist/rules/common/nbsp/afterShortWord.test.d.ts +1 -0
  75. package/dist/rules/common/nbsp/beforeShortLastNumber.d.ts +4 -0
  76. package/dist/rules/common/nbsp/beforeShortLastNumber.test.d.ts +1 -0
  77. package/dist/rules/common/nbsp/beforeShortLastWord.d.ts +4 -0
  78. package/dist/rules/common/nbsp/beforeShortLastWord.test.d.ts +1 -0
  79. package/dist/rules/common/nbsp/dpi.d.ts +2 -0
  80. package/dist/rules/common/nbsp/dpi.test.d.ts +1 -0
  81. package/dist/rules/common/nbsp/index.d.ts +1 -0
  82. package/dist/rules/common/nbsp/nowrap.d.ts +2 -0
  83. package/dist/rules/common/nbsp/nowrap.test.d.ts +1 -0
  84. package/dist/rules/common/nbsp/replaceNbsp.d.ts +2 -0
  85. package/dist/rules/common/nbsp/replaceNbsp.test.d.ts +1 -0
  86. package/dist/rules/common/number/digitGrouping.d.ts +4 -0
  87. package/dist/rules/common/number/digitGrouping.test.d.ts +1 -0
  88. package/dist/rules/common/number/fraction.d.ts +2 -0
  89. package/dist/rules/common/number/fraction.test.d.ts +1 -0
  90. package/dist/rules/common/number/index.d.ts +1 -0
  91. package/dist/rules/common/number/mathSigns.d.ts +2 -0
  92. package/dist/rules/common/number/mathSigns.test.d.ts +1 -0
  93. package/dist/rules/common/number/times.d.ts +2 -0
  94. package/dist/rules/common/number/times.test.d.ts +1 -0
  95. package/dist/rules/common/other/delBOM.d.ts +2 -0
  96. package/dist/rules/common/other/delBOM.test.d.ts +1 -0
  97. package/dist/rules/common/other/index.d.ts +1 -0
  98. package/dist/rules/common/other/repeatWord.d.ts +4 -0
  99. package/dist/rules/common/other/repeatWord.test.d.ts +1 -0
  100. package/dist/rules/common/punctuation/apostrophe.d.ts +2 -0
  101. package/dist/rules/common/punctuation/apostrophe.test.d.ts +1 -0
  102. package/dist/rules/common/punctuation/delDoublePunctuation.d.ts +2 -0
  103. package/dist/rules/common/punctuation/delDoublePunctuation.test.d.ts +1 -0
  104. package/dist/rules/common/punctuation/hellip.d.ts +2 -0
  105. package/dist/rules/common/punctuation/hellip.en-US.test.d.ts +1 -0
  106. package/dist/rules/common/punctuation/hellip.ru.test.d.ts +1 -0
  107. package/dist/rules/common/punctuation/index.d.ts +1 -0
  108. package/dist/rules/common/punctuation/quote.d.ts +5 -0
  109. package/dist/rules/common/punctuation/quote.de.test.d.ts +1 -0
  110. package/dist/rules/common/punctuation/quote.en-GB.test.d.ts +1 -0
  111. package/dist/rules/common/punctuation/quote.en-US.test.d.ts +1 -0
  112. package/dist/rules/common/punctuation/quote.fi.test.d.ts +1 -0
  113. package/dist/rules/common/punctuation/quote.fr.test.d.ts +1 -0
  114. package/dist/rules/common/punctuation/quote.pl.test.d.ts +1 -0
  115. package/dist/rules/common/punctuation/quote.ru.test.d.ts +1 -0
  116. package/dist/rules/common/punctuation/quoteLink.d.ts +2 -0
  117. package/dist/rules/common/punctuation/quoteLink.test.d.ts +1 -0
  118. package/dist/rules/common/space/afterColon.d.ts +2 -0
  119. package/dist/rules/common/space/afterColon.test.d.ts +1 -0
  120. package/dist/rules/common/space/afterComma.d.ts +2 -0
  121. package/dist/rules/common/space/afterComma.test.d.ts +1 -0
  122. package/dist/rules/common/space/afterExclamationMark.d.ts +2 -0
  123. package/dist/rules/common/space/afterExclamationMark.test.d.ts +1 -0
  124. package/dist/rules/common/space/afterQuestionMark.d.ts +2 -0
  125. package/dist/rules/common/space/afterQuestionMark.test.d.ts +1 -0
  126. package/dist/rules/common/space/afterSemicolon.d.ts +2 -0
  127. package/dist/rules/common/space/afterSemicolon.test.d.ts +1 -0
  128. package/dist/rules/common/space/beforeBracket.d.ts +2 -0
  129. package/dist/rules/common/space/beforeBracket.test.d.ts +1 -0
  130. package/dist/rules/common/space/bracket.d.ts +2 -0
  131. package/dist/rules/common/space/bracket.test.d.ts +1 -0
  132. package/dist/rules/common/space/delBeforeDot.d.ts +2 -0
  133. package/dist/rules/common/space/delBeforeDot.test.d.ts +1 -0
  134. package/dist/rules/common/space/delBeforePercent.d.ts +2 -0
  135. package/dist/rules/common/space/delBeforePercent.test.d.ts +1 -0
  136. package/dist/rules/common/space/delBeforePunctuation.d.ts +2 -0
  137. package/dist/rules/common/space/delBeforePunctuation.test.d.ts +1 -0
  138. package/dist/rules/common/space/delBetweenExclamationMarks.d.ts +2 -0
  139. package/dist/rules/common/space/delBetweenExclamationMarks.test.d.ts +1 -0
  140. package/dist/rules/common/space/delLeadingBlanks.d.ts +2 -0
  141. package/dist/rules/common/space/delLeadingBlanks.test.d.ts +1 -0
  142. package/dist/rules/common/space/delRepeatN.d.ts +4 -0
  143. package/dist/rules/common/space/delRepeatN.test.d.ts +1 -0
  144. package/dist/rules/common/space/delRepeatSpace.d.ts +2 -0
  145. package/dist/rules/common/space/delRepeatSpace.test.d.ts +1 -0
  146. package/dist/rules/common/space/delTrailingBlanks.d.ts +2 -0
  147. package/dist/rules/common/space/delTrailingBlanks.test.d.ts +1 -0
  148. package/dist/rules/common/space/index.d.ts +1 -0
  149. package/dist/rules/common/space/insertFinalNewline.d.ts +2 -0
  150. package/dist/rules/common/space/insertFinalNewline.test.d.ts +1 -0
  151. package/dist/rules/common/space/replaceTab.d.ts +2 -0
  152. package/dist/rules/common/space/replaceTab.test.d.ts +1 -0
  153. package/dist/rules/common/space/squareBracket.d.ts +2 -0
  154. package/dist/rules/common/space/squareBracket.test.d.ts +1 -0
  155. package/dist/rules/common/space/trimLeft.d.ts +2 -0
  156. package/dist/rules/common/space/trimLeft.test.d.ts +1 -0
  157. package/dist/rules/common/space/trimRight.d.ts +2 -0
  158. package/dist/rules/common/space/trimRight.test.d.ts +1 -0
  159. package/dist/rules/common/symbols/arrow.d.ts +2 -0
  160. package/dist/rules/common/symbols/arrow.test.d.ts +1 -0
  161. package/dist/rules/common/symbols/cf.d.ts +2 -0
  162. package/dist/rules/common/symbols/cf.test.d.ts +1 -0
  163. package/dist/rules/common/symbols/copy.d.ts +2 -0
  164. package/dist/rules/common/symbols/copy.test.d.ts +1 -0
  165. package/dist/rules/common/symbols/index.d.ts +1 -0
  166. package/dist/rules/en-US/dash/index.d.ts +1 -0
  167. package/dist/rules/en-US/dash/main.d.ts +2 -0
  168. package/dist/rules/en-US/dash/main.test.d.ts +1 -0
  169. package/dist/rules/en-US/index.d.ts +1 -0
  170. package/dist/rules/index.d.ts +3 -0
  171. package/dist/rules/ru/dash/centuries.d.ts +4 -0
  172. package/dist/rules/ru/dash/centuries.test.d.ts +1 -0
  173. package/dist/rules/ru/dash/daysMonth.d.ts +4 -0
  174. package/dist/rules/ru/dash/daysMonth.test.d.ts +1 -0
  175. package/dist/rules/ru/dash/de.d.ts +2 -0
  176. package/dist/rules/ru/dash/de.test.d.ts +1 -0
  177. package/dist/rules/ru/dash/decade.d.ts +4 -0
  178. package/dist/rules/ru/dash/decade.test.d.ts +1 -0
  179. package/dist/rules/ru/dash/directSpeech.d.ts +2 -0
  180. package/dist/rules/ru/dash/directSpeech.test.d.ts +1 -0
  181. package/dist/rules/ru/dash/index.d.ts +1 -0
  182. package/dist/rules/ru/dash/izpod.d.ts +2 -0
  183. package/dist/rules/ru/dash/izpod.test.d.ts +1 -0
  184. package/dist/rules/ru/dash/izza.d.ts +2 -0
  185. package/dist/rules/ru/dash/izza.test.d.ts +1 -0
  186. package/dist/rules/ru/dash/ka.d.ts +2 -0
  187. package/dist/rules/ru/dash/ka.test.d.ts +1 -0
  188. package/dist/rules/ru/dash/kakto.d.ts +2 -0
  189. package/dist/rules/ru/dash/kakto.test.d.ts +1 -0
  190. package/dist/rules/ru/dash/koe.d.ts +2 -0
  191. package/dist/rules/ru/dash/koe.test.d.ts +1 -0
  192. package/dist/rules/ru/dash/main.d.ts +2 -0
  193. package/dist/rules/ru/dash/main.test.d.ts +1 -0
  194. package/dist/rules/ru/dash/month.d.ts +4 -0
  195. package/dist/rules/ru/dash/month.test.d.ts +1 -0
  196. package/dist/rules/ru/dash/surname.d.ts +2 -0
  197. package/dist/rules/ru/dash/surname.test.d.ts +1 -0
  198. package/dist/rules/ru/dash/taki.d.ts +2 -0
  199. package/dist/rules/ru/dash/taki.test.d.ts +1 -0
  200. package/dist/rules/ru/dash/time.d.ts +4 -0
  201. package/dist/rules/ru/dash/time.test.d.ts +1 -0
  202. package/dist/rules/ru/dash/to.d.ts +2 -0
  203. package/dist/rules/ru/dash/to.test.d.ts +1 -0
  204. package/dist/rules/ru/dash/weekday.d.ts +4 -0
  205. package/dist/rules/ru/dash/weekday.test.d.ts +1 -0
  206. package/dist/rules/ru/dash/years.d.ts +4 -0
  207. package/dist/rules/ru/dash/years.test.d.ts +1 -0
  208. package/dist/rules/ru/date/fromISO.d.ts +2 -0
  209. package/dist/rules/ru/date/fromISO.test.d.ts +1 -0
  210. package/dist/rules/ru/date/index.d.ts +1 -0
  211. package/dist/rules/ru/date/weekday.d.ts +2 -0
  212. package/dist/rules/ru/date/weekday.test.d.ts +1 -0
  213. package/dist/rules/ru/index.d.ts +11 -0
  214. package/dist/rules/ru/money/currency.d.ts +2 -0
  215. package/dist/rules/ru/money/currency.test.d.ts +1 -0
  216. package/dist/rules/ru/money/index.d.ts +1 -0
  217. package/dist/rules/ru/money/ruble.d.ts +2 -0
  218. package/dist/rules/ru/money/ruble.test.d.ts +1 -0
  219. package/dist/rules/ru/nbsp/abbr.d.ts +2 -0
  220. package/dist/rules/ru/nbsp/abbr.test.d.ts +1 -0
  221. package/dist/rules/ru/nbsp/addr.d.ts +2 -0
  222. package/dist/rules/ru/nbsp/addr.test.d.ts +1 -0
  223. package/dist/rules/ru/nbsp/afterNumberSign.d.ts +2 -0
  224. package/dist/rules/ru/nbsp/afterNumberSign.test.d.ts +1 -0
  225. package/dist/rules/ru/nbsp/beforeParticle.d.ts +2 -0
  226. package/dist/rules/ru/nbsp/beforeParticle.test.d.ts +1 -0
  227. package/dist/rules/ru/nbsp/centuries.d.ts +2 -0
  228. package/dist/rules/ru/nbsp/centuries.test.d.ts +1 -0
  229. package/dist/rules/ru/nbsp/dayMonth.d.ts +2 -0
  230. package/dist/rules/ru/nbsp/dayMonth.test.d.ts +1 -0
  231. package/dist/rules/ru/nbsp/index.d.ts +1 -0
  232. package/dist/rules/ru/nbsp/initials.d.ts +2 -0
  233. package/dist/rules/ru/nbsp/initials.test.d.ts +1 -0
  234. package/dist/rules/ru/nbsp/m.d.ts +2 -0
  235. package/dist/rules/ru/nbsp/m.test.d.ts +1 -0
  236. package/dist/rules/ru/nbsp/mln.d.ts +2 -0
  237. package/dist/rules/ru/nbsp/mln.test.d.ts +1 -0
  238. package/dist/rules/ru/nbsp/ooo.d.ts +2 -0
  239. package/dist/rules/ru/nbsp/ooo.test.d.ts +1 -0
  240. package/dist/rules/ru/nbsp/page.d.ts +2 -0
  241. package/dist/rules/ru/nbsp/page.test.d.ts +1 -0
  242. package/dist/rules/ru/nbsp/ps.d.ts +2 -0
  243. package/dist/rules/ru/nbsp/ps.test.d.ts +1 -0
  244. package/dist/rules/ru/nbsp/rubleKopek.d.ts +2 -0
  245. package/dist/rules/ru/nbsp/rubleKopek.test.d.ts +1 -0
  246. package/dist/rules/ru/nbsp/see.d.ts +2 -0
  247. package/dist/rules/ru/nbsp/see.test.d.ts +1 -0
  248. package/dist/rules/ru/nbsp/year.d.ts +2 -0
  249. package/dist/rules/ru/nbsp/year.test.d.ts +1 -0
  250. package/dist/rules/ru/nbsp/years.d.ts +2 -0
  251. package/dist/rules/ru/nbsp/years.test.d.ts +1 -0
  252. package/dist/rules/ru/number/comma.d.ts +2 -0
  253. package/dist/rules/ru/number/comma.test.d.ts +1 -0
  254. package/dist/rules/ru/number/index.d.ts +1 -0
  255. package/dist/rules/ru/number/ordinals.d.ts +2 -0
  256. package/dist/rules/ru/number/ordinals.test.d.ts +1 -0
  257. package/dist/rules/ru/optalign/bracket.d.ts +4 -0
  258. package/dist/rules/ru/optalign/bracket.test.d.ts +1 -0
  259. package/dist/rules/ru/optalign/comma.d.ts +4 -0
  260. package/dist/rules/ru/optalign/comma.test.d.ts +1 -0
  261. package/dist/rules/ru/optalign/helpers.d.ts +2 -0
  262. package/dist/rules/ru/optalign/index.d.ts +1 -0
  263. package/dist/rules/ru/optalign/quote.d.ts +4 -0
  264. package/dist/rules/ru/optalign/quote.test.d.ts +1 -0
  265. package/dist/rules/ru/other/accent.d.ts +2 -0
  266. package/dist/rules/ru/other/accent.test.d.ts +1 -0
  267. package/dist/rules/ru/other/index.d.ts +1 -0
  268. package/dist/rules/ru/other/phone-number.d.ts +2 -0
  269. package/dist/rules/ru/other/phone-number.test.d.ts +1 -0
  270. package/dist/rules/ru/punctuation/ano.d.ts +2 -0
  271. package/dist/rules/ru/punctuation/ano.test.d.ts +1 -0
  272. package/dist/rules/ru/punctuation/exclamation.d.ts +2 -0
  273. package/dist/rules/ru/punctuation/exclamation.test.d.ts +1 -0
  274. package/dist/rules/ru/punctuation/exclamationQuestion.d.ts +2 -0
  275. package/dist/rules/ru/punctuation/exclamationQuestion.test.d.ts +1 -0
  276. package/dist/rules/ru/punctuation/hellipQuestion.d.ts +2 -0
  277. package/dist/rules/ru/punctuation/hellipQuestion.test.d.ts +1 -0
  278. package/dist/rules/ru/punctuation/index.d.ts +1 -0
  279. package/dist/rules/ru/space/afterHellip.d.ts +2 -0
  280. package/dist/rules/ru/space/afterHellip.test.d.ts +1 -0
  281. package/dist/rules/ru/space/index.d.ts +1 -0
  282. package/dist/rules/ru/space/year.d.ts +2 -0
  283. package/dist/rules/ru/space/year.test.d.ts +1 -0
  284. package/dist/rules/ru/symbols/NN.d.ts +2 -0
  285. package/dist/rules/ru/symbols/NN.test.d.ts +1 -0
  286. package/dist/rules/ru/symbols/index.d.ts +1 -0
  287. package/dist/rules/ru/typo/index.d.ts +1 -0
  288. package/dist/rules/ru/typo/switchingKeyboardLayout.d.ts +2 -0
  289. package/dist/rules/ru/typo/switchingKeyboardLayout.test.d.ts +1 -0
  290. package/dist/safeTags.d.ts +42 -0
  291. package/dist/typograf.all.d.ts +2 -0
  292. package/dist/typograf.all.js +3274 -3543
  293. package/dist/typograf.all.min.js +2 -2
  294. package/dist/typograf.css +5 -5
  295. package/dist/typograf.d.ts +3 -0
  296. package/dist/typograf.es.mjs +3268 -0
  297. package/dist/typograf.js +3175 -3050
  298. package/dist/typograf.min.js +2 -2
  299. package/dist/typograf.titles.js +1 -409
  300. package/dist/typograf.titles.json +1 -409
  301. package/dist/version.d.ts +1 -0
  302. package/docs/RULES.en-US.md +105 -105
  303. package/docs/RULES.ru.md +105 -105
  304. package/docs/RULES_SORTED.en-US.md +105 -105
  305. package/docs/RULES_SORTED.ru.md +105 -105
  306. package/package.json +47 -31
  307. package/dist/typograf.es.js +0 -3143
  308. package/typograf.d.ts +0 -51
@@ -0,0 +1,3268 @@
1
+ /*! typograf | © 2023 Denis Seleznev | MIT License | https://github.com/typograf/typograf */
2
+ /******************************************************************************
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
+ PERFORMANCE OF THIS SOFTWARE.
15
+ ***************************************************************************** */
16
+
17
+ var __assign = function() {
18
+ __assign = Object.assign || function __assign(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
22
+ }
23
+ return t;
24
+ };
25
+ return __assign.apply(this, arguments);
26
+ };
27
+
28
+ function __spreadArray(to, from, pack) {
29
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
30
+ if (ar || !(i in from)) {
31
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
32
+ ar[i] = from[i];
33
+ }
34
+ }
35
+ return to.concat(ar || Array.prototype.slice.call(from));
36
+ }
37
+
38
+ // http://www.w3.org/TR/html4/sgml/entities
39
+ var visibleEntities = [
40
+ ['iexcl', 161],
41
+ ['cent', 162],
42
+ ['pound', 163],
43
+ ['curren', 164],
44
+ ['yen', 165],
45
+ ['brvbar', 166],
46
+ ['sect', 167],
47
+ ['uml', 168],
48
+ ['copy', 169],
49
+ ['ordf', 170],
50
+ ['laquo', 171],
51
+ ['not', 172],
52
+ ['reg', 174],
53
+ ['macr', 175],
54
+ ['deg', 176],
55
+ ['plusmn', 177],
56
+ ['sup2', 178],
57
+ ['sup3', 179],
58
+ ['acute', 180],
59
+ ['micro', 181],
60
+ ['para', 182],
61
+ ['middot', 183],
62
+ ['cedil', 184],
63
+ ['sup1', 185],
64
+ ['ordm', 186],
65
+ ['raquo', 187],
66
+ ['frac14', 188],
67
+ ['frac12', 189],
68
+ ['frac34', 190],
69
+ ['iquest', 191],
70
+ ['Agrave', 192],
71
+ ['Aacute', 193],
72
+ ['Acirc', 194],
73
+ ['Atilde', 195],
74
+ ['Auml', 196],
75
+ ['Aring', 197],
76
+ ['AElig', 198],
77
+ ['Ccedil', 199],
78
+ ['Egrave', 200],
79
+ ['Eacute', 201],
80
+ ['Ecirc', 202],
81
+ ['Euml', 203],
82
+ ['Igrave', 204],
83
+ ['Iacute', 205],
84
+ ['Icirc', 206],
85
+ ['Iuml', 207],
86
+ ['ETH', 208],
87
+ ['Ntilde', 209],
88
+ ['Ograve', 210],
89
+ ['Oacute', 211],
90
+ ['Ocirc', 212],
91
+ ['Otilde', 213],
92
+ ['Ouml', 214],
93
+ ['times', 215],
94
+ ['Oslash', 216],
95
+ ['Ugrave', 217],
96
+ ['Uacute', 218],
97
+ ['Ucirc', 219],
98
+ ['Uuml', 220],
99
+ ['Yacute', 221],
100
+ ['THORN', 222],
101
+ ['szlig', 223],
102
+ ['agrave', 224],
103
+ ['aacute', 225],
104
+ ['acirc', 226],
105
+ ['atilde', 227],
106
+ ['auml', 228],
107
+ ['aring', 229],
108
+ ['aelig', 230],
109
+ ['ccedil', 231],
110
+ ['egrave', 232],
111
+ ['eacute', 233],
112
+ ['ecirc', 234],
113
+ ['euml', 235],
114
+ ['igrave', 236],
115
+ ['iacute', 237],
116
+ ['icirc', 238],
117
+ ['iuml', 239],
118
+ ['eth', 240],
119
+ ['ntilde', 241],
120
+ ['ograve', 242],
121
+ ['oacute', 243],
122
+ ['ocirc', 244],
123
+ ['otilde', 245],
124
+ ['ouml', 246],
125
+ ['divide', 247],
126
+ ['oslash', 248],
127
+ ['ugrave', 249],
128
+ ['uacute', 250],
129
+ ['ucirc', 251],
130
+ ['uuml', 252],
131
+ ['yacute', 253],
132
+ ['thorn', 254],
133
+ ['yuml', 255],
134
+ ['fnof', 402],
135
+ ['Alpha', 913],
136
+ ['Beta', 914],
137
+ ['Gamma', 915],
138
+ ['Delta', 916],
139
+ ['Epsilon', 917],
140
+ ['Zeta', 918],
141
+ ['Eta', 919],
142
+ ['Theta', 920],
143
+ ['Iota', 921],
144
+ ['Kappa', 922],
145
+ ['Lambda', 923],
146
+ ['Mu', 924],
147
+ ['Nu', 925],
148
+ ['Xi', 926],
149
+ ['Omicron', 927],
150
+ ['Pi', 928],
151
+ ['Rho', 929],
152
+ ['Sigma', 931],
153
+ ['Tau', 932],
154
+ ['Upsilon', 933],
155
+ ['Phi', 934],
156
+ ['Chi', 935],
157
+ ['Psi', 936],
158
+ ['Omega', 937],
159
+ ['alpha', 945],
160
+ ['beta', 946],
161
+ ['gamma', 947],
162
+ ['delta', 948],
163
+ ['epsilon', 949],
164
+ ['zeta', 950],
165
+ ['eta', 951],
166
+ ['theta', 952],
167
+ ['iota', 953],
168
+ ['kappa', 954],
169
+ ['lambda', 955],
170
+ ['mu', 956],
171
+ ['nu', 957],
172
+ ['xi', 958],
173
+ ['omicron', 959],
174
+ ['pi', 960],
175
+ ['rho', 961],
176
+ ['sigmaf', 962],
177
+ ['sigma', 963],
178
+ ['tau', 964],
179
+ ['upsilon', 965],
180
+ ['phi', 966],
181
+ ['chi', 967],
182
+ ['psi', 968],
183
+ ['omega', 969],
184
+ ['thetasym', 977],
185
+ ['upsih', 978],
186
+ ['piv', 982],
187
+ ['bull', 8226],
188
+ ['hellip', 8230],
189
+ ['prime', 8242],
190
+ ['Prime', 8243],
191
+ ['oline', 8254],
192
+ ['frasl', 8260],
193
+ ['weierp', 8472],
194
+ ['image', 8465],
195
+ ['real', 8476],
196
+ ['trade', 8482],
197
+ ['alefsym', 8501],
198
+ ['larr', 8592],
199
+ ['uarr', 8593],
200
+ ['rarr', 8594],
201
+ ['darr', 8595],
202
+ ['harr', 8596],
203
+ ['crarr', 8629],
204
+ ['lArr', 8656],
205
+ ['uArr', 8657],
206
+ ['rArr', 8658],
207
+ ['dArr', 8659],
208
+ ['hArr', 8660],
209
+ ['forall', 8704],
210
+ ['part', 8706],
211
+ ['exist', 8707],
212
+ ['empty', 8709],
213
+ ['nabla', 8711],
214
+ ['isin', 8712],
215
+ ['notin', 8713],
216
+ ['ni', 8715],
217
+ ['prod', 8719],
218
+ ['sum', 8721],
219
+ ['minus', 8722],
220
+ ['lowast', 8727],
221
+ ['radic', 8730],
222
+ ['prop', 8733],
223
+ ['infin', 8734],
224
+ ['ang', 8736],
225
+ ['and', 8743],
226
+ ['or', 8744],
227
+ ['cap', 8745],
228
+ ['cup', 8746],
229
+ ['int', 8747],
230
+ ['there4', 8756],
231
+ ['sim', 8764],
232
+ ['cong', 8773],
233
+ ['asymp', 8776],
234
+ ['ne', 8800],
235
+ ['equiv', 8801],
236
+ ['le', 8804],
237
+ ['ge', 8805],
238
+ ['sub', 8834],
239
+ ['sup', 8835],
240
+ ['nsub', 8836],
241
+ ['sube', 8838],
242
+ ['supe', 8839],
243
+ ['oplus', 8853],
244
+ ['otimes', 8855],
245
+ ['perp', 8869],
246
+ ['sdot', 8901],
247
+ ['lceil', 8968],
248
+ ['rceil', 8969],
249
+ ['lfloor', 8970],
250
+ ['rfloor', 8971],
251
+ ['lang', 9001],
252
+ ['rang', 9002],
253
+ ['spades', 9824],
254
+ ['clubs', 9827],
255
+ ['hearts', 9829],
256
+ ['diams', 9830],
257
+ ['loz', 9674],
258
+ ['OElig', 338],
259
+ ['oelig', 339],
260
+ ['Scaron', 352],
261
+ ['scaron', 353],
262
+ ['Yuml', 376],
263
+ ['circ', 710],
264
+ ['tilde', 732],
265
+ ['ndash', 8211],
266
+ ['mdash', 8212],
267
+ ['lsquo', 8216],
268
+ ['rsquo', 8217],
269
+ ['sbquo', 8218],
270
+ ['ldquo', 8220],
271
+ ['rdquo', 8221],
272
+ ['bdquo', 8222],
273
+ ['dagger', 8224],
274
+ ['Dagger', 8225],
275
+ ['permil', 8240],
276
+ ['lsaquo', 8249],
277
+ ['rsaquo', 8250],
278
+ ['euro', 8364],
279
+ ['NestedGreaterGreater', 8811],
280
+ ['NestedLessLess', 8810]
281
+ ];
282
+
283
+ var invisibleEntities = [
284
+ ['nbsp', 160],
285
+ ['thinsp', 8201],
286
+ ['ensp', 8194],
287
+ ['emsp', 8195],
288
+ ['shy', 173],
289
+ ['zwnj', 8204],
290
+ ['zwj', 8205],
291
+ ['lrm', 8206],
292
+ ['rlm', 8207]
293
+ ];
294
+
295
+ var HtmlEntities = /** @class */ (function () {
296
+ function HtmlEntities() {
297
+ var _this = this;
298
+ this.entities = this.prepareEntities(__spreadArray(__spreadArray([], visibleEntities, true), invisibleEntities, true));
299
+ this.entitiesByName = {};
300
+ this.entitiesByNameEntity = {};
301
+ this.entitiesByDigitEntity = {};
302
+ this.entitiesByUtf = {};
303
+ this.entities.forEach(function (entity) {
304
+ _this.entitiesByName[entity.name] = entity;
305
+ _this.entitiesByNameEntity[entity.nameEntity] = entity;
306
+ _this.entitiesByDigitEntity[entity.digitEntity] = entity;
307
+ _this.entitiesByUtf[entity.utf] = entity;
308
+ });
309
+ this.invisibleEntities = this.prepareEntities(invisibleEntities);
310
+ }
311
+ /**
312
+ * Entities as name or digit to UTF-8.
313
+ */
314
+ HtmlEntities.prototype.toUtf = function (context) {
315
+ var _this = this;
316
+ if (context.text.search(/&#/) !== -1) {
317
+ context.text = this.decHexToUtf(context.text);
318
+ }
319
+ if (context.text.search(/&[a-z]/i) !== -1) {
320
+ // 2 - min length of entity without & and ;. Example: &DD;
321
+ // 31 - max length of entity without & and ;. Example: &CounterClockwiseContourIntegral;
322
+ context.text = context.text.replace(/&[a-z\d]{2,31};/gi, function (key) {
323
+ var entity = _this.entitiesByNameEntity[key];
324
+ return entity ? entity.utf : key;
325
+ });
326
+ }
327
+ };
328
+ /**
329
+ * Entities in decimal or hexadecimal form to UTF-8.
330
+ */
331
+ HtmlEntities.prototype.decHexToUtf = function (text) {
332
+ return text
333
+ .replace(/&#(\d{1,6});/gi, function ($0, $1) {
334
+ return String.fromCharCode(parseInt($1, 10));
335
+ })
336
+ .replace(/&#x([\da-f]{1,6});/gi, function ($0, $1) {
337
+ return String.fromCharCode(parseInt($1, 16));
338
+ });
339
+ };
340
+ /**
341
+ * Restore HTML entities in text.
342
+ */
343
+ HtmlEntities.prototype.restore = function (context) {
344
+ var params = context.prefs.htmlEntity;
345
+ var type = params.type;
346
+ var entities = this.entities;
347
+ if (type === 'name' || type === 'digit') {
348
+ if (params.onlyInvisible || params.list) {
349
+ entities = [];
350
+ if (params.onlyInvisible) {
351
+ entities = entities.concat(this.invisibleEntities);
352
+ }
353
+ if (params.list) {
354
+ entities = entities.concat(this.prepareListParam(params.list));
355
+ }
356
+ }
357
+ var entityType = type === 'name' ? 'nameEntity' : 'digitEntity';
358
+ context.text = this.restoreEntitiesByIndex(context.text, entityType, entities);
359
+ }
360
+ };
361
+ /**
362
+ * Get a entity by utf using the type.
363
+ */
364
+ HtmlEntities.prototype.getByUtf = function (symbol, type) {
365
+ var result;
366
+ switch (type) {
367
+ case 'digit':
368
+ result = this.entitiesByDigitEntity[symbol];
369
+ break;
370
+ case 'name':
371
+ result = this.entitiesByNameEntity[symbol];
372
+ break;
373
+ default:
374
+ result = symbol;
375
+ break;
376
+ }
377
+ return result;
378
+ };
379
+ HtmlEntities.prototype.prepareEntities = function (entities) {
380
+ var result = [];
381
+ entities.forEach(function (entity) {
382
+ var name = entity[0], digit = entity[1];
383
+ var utf = String.fromCharCode(digit);
384
+ result.push({
385
+ name: name,
386
+ nameEntity: '&' + name + ';',
387
+ digitEntity: '&#' + digit + ';',
388
+ utf: utf,
389
+ reName: new RegExp('&' + name + ';', 'g'),
390
+ reUtf: new RegExp(utf, 'g')
391
+ });
392
+ });
393
+ return result;
394
+ };
395
+ HtmlEntities.prototype.prepareListParam = function (list) {
396
+ var _this = this;
397
+ var result = [];
398
+ list.forEach(function (name) {
399
+ var entity = _this.entitiesByName[name];
400
+ if (entity) {
401
+ result.push(entity);
402
+ }
403
+ });
404
+ return result;
405
+ };
406
+ HtmlEntities.prototype.restoreEntitiesByIndex = function (text, type, entities) {
407
+ entities.forEach(function (entity) {
408
+ text = text.replace(entity.reUtf, entity[type]);
409
+ });
410
+ return text;
411
+ };
412
+ return HtmlEntities;
413
+ }());
414
+ var htmlEntities = new HtmlEntities();
415
+
416
+ var locales = [];
417
+ function addLocale(locale) {
418
+ var code = (locale || '').split('/')[0];
419
+ if (code && code !== 'common' && !hasLocale(code)) {
420
+ locales.push(code);
421
+ locales.sort();
422
+ }
423
+ }
424
+ function getLocales() {
425
+ return locales;
426
+ }
427
+ function hasLocale(locale) {
428
+ return locale === 'common' || locales.indexOf(locale) !== -1;
429
+ }
430
+ function prepareLocale(locale1, locale2) {
431
+ var locale = locale1 || locale2;
432
+ if (!locale) {
433
+ return [];
434
+ }
435
+ return Array.isArray(locale) ? locale : [locale];
436
+ }
437
+ function checkLocales(locales) {
438
+ if (!locales.length) {
439
+ throw Error('Not defined the property "locale".');
440
+ }
441
+ locales.forEach(function (locale) {
442
+ if (!hasLocale(locale)) {
443
+ throw Error("\"".concat(locale, "\" is not supported locale."));
444
+ }
445
+ });
446
+ }
447
+
448
+ var data$1 = {};
449
+ /**
450
+ * Get data for use in rules.
451
+ */
452
+ function getData(key) {
453
+ return data$1[key];
454
+ }
455
+ /**
456
+ * Set data for use in rules.
457
+ */
458
+ function setData(newData) {
459
+ Object.keys(newData).forEach(function (key) {
460
+ addLocale(key);
461
+ data$1[key] = newData[key];
462
+ });
463
+ }
464
+
465
+ var inlineElements = [
466
+ 'a',
467
+ 'abbr',
468
+ 'acronym',
469
+ 'b',
470
+ 'bdo',
471
+ 'big',
472
+ 'br',
473
+ 'button',
474
+ 'cite',
475
+ 'code',
476
+ 'dfn',
477
+ 'em',
478
+ 'i',
479
+ 'img',
480
+ 'input',
481
+ 'kbd',
482
+ 'label',
483
+ 'map',
484
+ 'object',
485
+ 'q',
486
+ 'samp',
487
+ 'script',
488
+ 'select',
489
+ 'small',
490
+ 'span',
491
+ 'strong',
492
+ 'sub',
493
+ 'sup',
494
+ 'textarea',
495
+ 'time',
496
+ 'tt',
497
+ 'var'
498
+ ];
499
+
500
+ var regExpUrl = new RegExp('(https?|file|ftp)://([a-zA-Z0-9/+-=%&:_.~?]+[a-zA-Z0-9#+]*)', 'g');
501
+ var regExpNumber = '\\d+([.,]\\d+)?';
502
+ var regExpDigit = /\d/;
503
+ function isDigit(symbol) {
504
+ return symbol.search(regExpDigit) > -1;
505
+ }
506
+
507
+ var privateLabel = '\uF000';
508
+ var privateSeparateLabel = '\uF001';
509
+
510
+ var SafeTags = /** @class */ (function () {
511
+ function SafeTags() {
512
+ this.groups = ['own', 'html', 'url'];
513
+ this.hidden = {};
514
+ this.counter = 0;
515
+ var html = [
516
+ ['<!--', '-->'],
517
+ ['<!ENTITY', '>'],
518
+ ['<!DOCTYPE', '>'],
519
+ ['<\\?xml', '\\?>'],
520
+ ['<!\\[CDATA\\[', '\\]\\]>']
521
+ ];
522
+ [
523
+ 'code',
524
+ 'kbd',
525
+ 'object',
526
+ 'pre',
527
+ 'samp',
528
+ 'script',
529
+ 'style',
530
+ 'var'
531
+ ].forEach(function (tag) {
532
+ html.push([
533
+ "<".concat(tag, "(\\s[^>]*?)?>"),
534
+ "</".concat(tag, ">")
535
+ ]);
536
+ });
537
+ this.tags = {
538
+ own: [],
539
+ html: html.map(this.prepareRegExp),
540
+ url: [regExpUrl]
541
+ };
542
+ }
543
+ /**
544
+ * Add own safe tag.
545
+ */
546
+ SafeTags.prototype.add = function (tag) {
547
+ this.tags.own.push(this.prepareRegExp(tag));
548
+ };
549
+ /**
550
+ * Show safe tags.
551
+ */
552
+ SafeTags.prototype.show = function (context, group) {
553
+ var reReplace = new RegExp(privateLabel + 'tf\\d+' + privateLabel, 'g');
554
+ var reSearch = new RegExp(privateLabel + 'tf\\d');
555
+ var replaceLabel = function (match) {
556
+ return context.safeTags.hidden[group][match] || match;
557
+ };
558
+ for (var i = 0, len = this.tags[group].length; i < len; i++) {
559
+ context.text = context.text.replace(reReplace, replaceLabel);
560
+ if (context.text.search(reSearch) === -1) {
561
+ break;
562
+ }
563
+ }
564
+ };
565
+ /**
566
+ * Hide safe tags.
567
+ */
568
+ SafeTags.prototype.hide = function (context, group) {
569
+ var _this = this;
570
+ context.safeTags.hidden[group] = {};
571
+ var pasteLabel = this.pasteLabel.bind(this, context, group);
572
+ this.tags[group].forEach(function (tag) {
573
+ context.text = context.text.replace(_this.prepareRegExp(tag), pasteLabel);
574
+ });
575
+ };
576
+ /**
577
+ * Hide HTML tags.
578
+ */
579
+ SafeTags.prototype.hideHTMLTags = function (context) {
580
+ if (context.isHTML) {
581
+ var pasteLabel = this.pasteLabel.bind(this, context, 'html');
582
+ context.text = context.text
583
+ .replace(/<\/?[a-z][^]*?>/gi, pasteLabel) // Tags
584
+ .replace(/&lt;\/?[a-z][^]*?&gt;/gi, pasteLabel) // Escaping tags
585
+ .replace(/&[gl]t;/gi, pasteLabel);
586
+ }
587
+ };
588
+ /**
589
+ * Get previous label.
590
+ */
591
+ SafeTags.prototype.getPrevLabel = function (text, position) {
592
+ for (var i = position - 1; i >= 0; i--) {
593
+ if (text[i] === privateLabel) {
594
+ return text.slice(i, position + 1);
595
+ }
596
+ }
597
+ return '';
598
+ };
599
+ SafeTags.prototype.getNextLabel = function (text, position) {
600
+ for (var i = position + 1; i < text.length; i++) {
601
+ if (text[i] === privateLabel) {
602
+ return text.slice(position, i + 1);
603
+ }
604
+ }
605
+ return '';
606
+ };
607
+ SafeTags.prototype.getTagByLabel = function (context, label) {
608
+ var result = null;
609
+ this.groups.some(function (group) {
610
+ var value = context.safeTags.hidden[group][label];
611
+ if (typeof value !== 'undefined') {
612
+ result = {
613
+ group: group,
614
+ value: value
615
+ };
616
+ }
617
+ return result;
618
+ });
619
+ return result;
620
+ };
621
+ SafeTags.prototype.getTagInfo = function (tag) {
622
+ if (!tag) {
623
+ return null;
624
+ }
625
+ var result = { group: tag.group };
626
+ switch (tag.group) {
627
+ case 'html':
628
+ result.name = tag.value.split(/[<\s>]/)[1];
629
+ result.isInline = inlineElements.indexOf(result.name) > -1;
630
+ result.isClosing = tag.value.search(/^<\//) > -1;
631
+ break;
632
+ case 'url':
633
+ result.isInline = true;
634
+ break;
635
+ case 'own':
636
+ result.isInline = false;
637
+ break;
638
+ }
639
+ return result;
640
+ };
641
+ SafeTags.prototype.pasteLabel = function (context, group, match) {
642
+ var safeTags = context.safeTags;
643
+ var key = privateLabel + 'tf' + safeTags.counter + privateLabel;
644
+ safeTags.hidden[group][key] = match;
645
+ safeTags.counter++;
646
+ return key;
647
+ };
648
+ SafeTags.prototype.prepareRegExp = function (tag) {
649
+ if (tag instanceof RegExp) {
650
+ return tag;
651
+ }
652
+ var startTag = tag[0], endTag = tag[1], middle = tag[2];
653
+ return new RegExp(startTag +
654
+ (typeof middle === 'undefined' ? '[^]*?' : middle) +
655
+ endTag, 'gi');
656
+ };
657
+ SafeTags.prototype.getPrevTagInfo = function (context, text, pos) {
658
+ var prevLabel = this.getPrevLabel(text, pos - 1);
659
+ if (prevLabel) {
660
+ var prevTag = this.getTagByLabel(context, prevLabel);
661
+ if (prevTag) {
662
+ return this.getTagInfo(prevTag);
663
+ }
664
+ }
665
+ return null;
666
+ };
667
+ SafeTags.prototype.getNextTagInfo = function (context, text, pos) {
668
+ var nextLabel = this.getNextLabel(text, pos + 1);
669
+ if (nextLabel) {
670
+ var nextTag = this.getTagByLabel(context, nextLabel);
671
+ if (nextTag) {
672
+ return this.getTagInfo(nextTag);
673
+ }
674
+ }
675
+ return null;
676
+ };
677
+ return SafeTags;
678
+ }());
679
+
680
+ function repeat(symbol, count) {
681
+ var result = '';
682
+ for (;;) {
683
+ if ((count & 1) === 1) {
684
+ result += symbol;
685
+ }
686
+ count >>>= 1;
687
+ if (count === 0) {
688
+ break;
689
+ }
690
+ symbol += symbol;
691
+ }
692
+ return result;
693
+ }
694
+ function replaceNbsp$1(text) {
695
+ return text.replace(/\u00A0/g, ' ');
696
+ }
697
+ function replace(text, re) {
698
+ for (var i = 0; i < re.length; i++) {
699
+ text = text.replace(re[i][0], re[i][1]);
700
+ }
701
+ return text;
702
+ }
703
+ function isHTML(text) {
704
+ return text.search(/(<\/?[a-z]|<!|&[lg]t;)/i) !== -1;
705
+ }
706
+ function removeCR(text) {
707
+ return text.replace(/\r\n?/g, '\n');
708
+ }
709
+ function fixLineEnding(text, type) {
710
+ if (type === 'CRLF') { // Windows
711
+ return text.replace(/\n/g, '\r\n');
712
+ }
713
+ else if (type === 'CR') { // Mac
714
+ return text.replace(/\n/g, '\r');
715
+ }
716
+ return text;
717
+ }
718
+
719
+ /**
720
+ * Get a deep copy of a object.
721
+ */
722
+ function deepCopy(obj) {
723
+ return typeof obj === 'object' ? JSON.parse(JSON.stringify(obj)) : obj;
724
+ }
725
+
726
+ var groupIndexes = {
727
+ symbols: 110,
728
+ 'number': 150,
729
+ space: 210,
730
+ dash: 310,
731
+ punctuation: 410,
732
+ nbsp: 510,
733
+ money: 710,
734
+ date: 810,
735
+ other: 910,
736
+ optalign: 1010,
737
+ typo: 1110,
738
+ html: 1210
739
+ };
740
+
741
+ var DEFAULT_RULE_INDEX = 0;
742
+ var DEFAULT_QUEUE_NAME = 'default';
743
+ var rules = [];
744
+ var innerRules = [];
745
+ function addInnerRule(rule) {
746
+ innerRules.push(prepareRule(rule));
747
+ }
748
+ function addRule(rule) {
749
+ var preparedRule = prepareRule(rule);
750
+ addLocale(preparedRule.locale);
751
+ rules.push(preparedRule);
752
+ }
753
+ function sortRules(rules) {
754
+ rules.sort(function (a, b) { return a.index > b.index ? 1 : -1; });
755
+ }
756
+ function getRules() {
757
+ var result = __spreadArray([], rules, true);
758
+ sortRules(result);
759
+ return result;
760
+ }
761
+ function getInnerRules() {
762
+ return __spreadArray([], innerRules, true);
763
+ }
764
+ function getRuleIndex(rule) {
765
+ if (typeof rule.index === 'number') {
766
+ return rule.index;
767
+ }
768
+ var _a = rule.name.split('/'), group = _a[1];
769
+ var groupIndex = groupIndexes[group];
770
+ if (typeof groupIndex === 'undefined') {
771
+ groupIndex = DEFAULT_RULE_INDEX;
772
+ }
773
+ if (typeof rule.index === 'string') {
774
+ return groupIndex + parseInt(rule.index, 10);
775
+ }
776
+ return groupIndex;
777
+ }
778
+ function prepareRule(rule) {
779
+ var _a = rule.name.split('/'), locale = _a[0], group = _a[1], shortName = _a[2];
780
+ var preparedRule = {
781
+ name: rule.name,
782
+ shortName: shortName,
783
+ handler: rule.handler,
784
+ queue: rule.queue || DEFAULT_QUEUE_NAME,
785
+ enabled: rule.disabled === true ? false : true,
786
+ locale: locale,
787
+ group: group,
788
+ index: getRuleIndex(rule),
789
+ settings: rule.settings,
790
+ live: rule.live,
791
+ htmlAttrs: rule.htmlAttrs,
792
+ };
793
+ return preparedRule;
794
+ }
795
+
796
+ var PACKAGE_VERSION = '7.0.0';
797
+
798
+ function prepareHtmlEntity(htmlEntity) {
799
+ var result = {
800
+ type: (htmlEntity === null || htmlEntity === void 0 ? void 0 : htmlEntity.type) || 'default',
801
+ list: htmlEntity === null || htmlEntity === void 0 ? void 0 : htmlEntity.list,
802
+ onlyInvisible: Boolean(htmlEntity === null || htmlEntity === void 0 ? void 0 : htmlEntity.onlyInvisible),
803
+ };
804
+ return result;
805
+ }
806
+ function prepareLineEnding(lineEnding) {
807
+ return lineEnding || 'LF';
808
+ }
809
+ function preparePrefs(prefs) {
810
+ var result = {
811
+ locale: prepareLocale(prefs.locale),
812
+ lineEnding: prepareLineEnding(prefs.lineEnding),
813
+ live: Boolean(prefs.live),
814
+ ruleFilter: prefs.ruleFilter,
815
+ enableRule: prefs.enableRule,
816
+ disableRule: prefs.disableRule,
817
+ processingSeparateParts: prefs.processingSeparateParts,
818
+ htmlEntity: prepareHtmlEntity(prefs.htmlEntity),
819
+ };
820
+ return result;
821
+ }
822
+ function prepareContextPrefs(prefs, executePrefs) {
823
+ var result = __assign({}, prefs);
824
+ if (!executePrefs) {
825
+ return result;
826
+ }
827
+ if ('locale' in executePrefs) {
828
+ result.locale = prepareLocale(executePrefs.locale);
829
+ }
830
+ if ('htmlEntity' in executePrefs) {
831
+ result.htmlEntity = prepareHtmlEntity(executePrefs.htmlEntity);
832
+ }
833
+ if ('lineEnding' in executePrefs) {
834
+ result.lineEnding = prepareLineEnding(executePrefs.lineEnding);
835
+ }
836
+ if ('processingSeparateParts' in executePrefs) {
837
+ result.processingSeparateParts = executePrefs.processingSeparateParts;
838
+ }
839
+ if ('ruleFilter' in executePrefs) {
840
+ result.ruleFilter = executePrefs.ruleFilter;
841
+ }
842
+ return result;
843
+ }
844
+
845
+ var Typograf = /** @class */ (function () {
846
+ function Typograf(prefs) {
847
+ var _this = this;
848
+ this.rules = [];
849
+ this.innerRules = [];
850
+ this.rulesByQueues = {};
851
+ this.innerRulesByQueues = {};
852
+ this.separatePartsTags = [
853
+ 'title',
854
+ 'p',
855
+ 'h[1-6]',
856
+ 'select',
857
+ 'legend',
858
+ ];
859
+ this.prefs = preparePrefs(prefs);
860
+ checkLocales(this.prefs.locale);
861
+ this.safeTags = new SafeTags();
862
+ this.settings = {};
863
+ this.enabledRules = {};
864
+ this.innerRulesByQueues = {};
865
+ this.innerRules = getInnerRules();
866
+ this.innerRules.forEach(function (rule) {
867
+ _this.innerRulesByQueues[rule.queue] = _this.innerRulesByQueues[rule.queue] || [];
868
+ _this.innerRulesByQueues[rule.queue].push(rule);
869
+ });
870
+ this.rulesByQueues = {};
871
+ this.rules = getRules();
872
+ this.rules.forEach(function (rule) {
873
+ _this.prepareRuleSettings(rule);
874
+ _this.rulesByQueues[rule.queue] = _this.rulesByQueues[rule.queue] || [];
875
+ _this.rulesByQueues[rule.queue].push(rule);
876
+ });
877
+ this.prefs.disableRule && this.disableRule(this.prefs.disableRule);
878
+ this.prefs.enableRule && this.enableRule(this.prefs.enableRule);
879
+ }
880
+ Typograf.addRule = function (rule) {
881
+ addRule(rule);
882
+ };
883
+ Typograf.addRules = function (rules) {
884
+ var _this = this;
885
+ rules.forEach(function (item) {
886
+ _this.addRule(item);
887
+ });
888
+ };
889
+ /**
890
+ * Add internal rule.
891
+ * Internal rules are executed before main rules.
892
+ */
893
+ Typograf.addInnerRule = function (rule) {
894
+ addInnerRule(rule);
895
+ };
896
+ Typograf.addInnerRules = function (rules) {
897
+ var _this = this;
898
+ rules.forEach(function (item) {
899
+ _this.addInnerRule(item);
900
+ });
901
+ };
902
+ Typograf.getRule = function (ruleName) {
903
+ var rule = null;
904
+ var rules = getRules();
905
+ rules.some(function (item) {
906
+ if (item.name === ruleName) {
907
+ rule = item;
908
+ return true;
909
+ }
910
+ return false;
911
+ });
912
+ return rule;
913
+ };
914
+ Typograf.getRules = function () {
915
+ return getRules();
916
+ };
917
+ Typograf.getInnerRules = function () {
918
+ return getInnerRules();
919
+ };
920
+ Typograf.getLocales = function () {
921
+ return getLocales();
922
+ };
923
+ Typograf.addLocale = function (locale) {
924
+ addLocale(locale);
925
+ };
926
+ Typograf.hasLocale = function (locale) {
927
+ return hasLocale(locale);
928
+ };
929
+ Typograf.setData = function (data) {
930
+ setData(data);
931
+ };
932
+ Typograf.getData = function (key) {
933
+ return getData(key);
934
+ };
935
+ /**
936
+ * Execute typographical rules for text.
937
+ */
938
+ Typograf.prototype.execute = function (text, prefs) {
939
+ text = '' + text;
940
+ if (!text) {
941
+ return '';
942
+ }
943
+ var contextPrefs = prepareContextPrefs(this.prefs, prefs);
944
+ checkLocales(contextPrefs.locale);
945
+ var context = this.prepareContext(text, contextPrefs);
946
+ return this.process(context);
947
+ };
948
+ Typograf.prototype.getSetting = function (ruleName, setting) {
949
+ return this.settings[ruleName] && this.settings[ruleName][setting];
950
+ };
951
+ Typograf.prototype.setSetting = function (ruleName, setting, value) {
952
+ this.settings[ruleName] = this.settings[ruleName] || {};
953
+ this.settings[ruleName][setting] = value;
954
+ };
955
+ Typograf.prototype.isEnabledRule = function (ruleName) {
956
+ return this.enabledRules[ruleName] !== false;
957
+ };
958
+ Typograf.prototype.isDisabledRule = function (ruleName) {
959
+ return !this.enabledRules[ruleName];
960
+ };
961
+ Typograf.prototype.enableRule = function (ruleName) {
962
+ return this.enable(ruleName, true);
963
+ };
964
+ Typograf.prototype.disableRule = function (ruleName) {
965
+ return this.enable(ruleName, false);
966
+ };
967
+ /**
968
+ * Add safe tag.
969
+ *
970
+ * @example
971
+ * // const typograf = new Typograf({ locale: 'ru' });
972
+ * // typograf.addSafeTag('<mytag>', '</mytag>');
973
+ * // typograf.addSafeTag('<mytag>', '</mytag>', '.*?');
974
+ * // typograf.addSafeTag(/<mytag>.*?</mytag>/gi);
975
+ */
976
+ Typograf.prototype.addSafeTag = function (startTag, endTag, middle) {
977
+ var tag = startTag instanceof RegExp ? startTag : [startTag, endTag, middle];
978
+ this.safeTags.add(tag);
979
+ };
980
+ Typograf.prototype.prepareContext = function (text, prefs) {
981
+ var context = {
982
+ text: text,
983
+ isHTML: isHTML(text),
984
+ prefs: prefs,
985
+ getData: function (key) {
986
+ if (key === 'char') {
987
+ return prefs.locale.map(function (item) {
988
+ return getData(item + '/' + key);
989
+ }).join('');
990
+ }
991
+ else {
992
+ return getData(prefs.locale[0] + '/' + key);
993
+ }
994
+ },
995
+ safeTags: this.safeTags,
996
+ };
997
+ return context;
998
+ };
999
+ Typograf.prototype.splitBySeparateParts = function (context) {
1000
+ if (!context.isHTML || context.prefs.processingSeparateParts === false) {
1001
+ return [context.text];
1002
+ }
1003
+ var text = [];
1004
+ var reTags = new RegExp('<(' + this.separatePartsTags.join('|') + ')(\\s[^>]*?)?>[^]*?</\\1>', 'gi');
1005
+ var position = 0;
1006
+ context.text.replace(reTags, function ($0, $1, $2, itemPosition) {
1007
+ if (position !== itemPosition) {
1008
+ text.push((position ? privateSeparateLabel : '') +
1009
+ context.text.slice(position, itemPosition) +
1010
+ privateSeparateLabel);
1011
+ }
1012
+ text.push($0);
1013
+ position = itemPosition + $0.length;
1014
+ return $0;
1015
+ });
1016
+ text.push(position ?
1017
+ (privateSeparateLabel + context.text.slice(position, context.text.length)) :
1018
+ context.text);
1019
+ return text;
1020
+ };
1021
+ Typograf.prototype.process = function (context) {
1022
+ var _this = this;
1023
+ context.text = removeCR(context.text);
1024
+ this.executeRules(context, 'start');
1025
+ this.safeTags.hide(context, 'own');
1026
+ this.executeRules(context, 'hide-safe-tags-own');
1027
+ this.safeTags.hide(context, 'html');
1028
+ this.executeRules(context, 'hide-safe-tags-html');
1029
+ var isRootHTML = context.isHTML;
1030
+ var re = new RegExp(privateSeparateLabel, 'g');
1031
+ context.text = this.splitBySeparateParts(context).map(function (item) {
1032
+ context.text = item;
1033
+ context.isHTML = isHTML(item);
1034
+ _this.safeTags.hideHTMLTags(context);
1035
+ _this.safeTags.hide(context, 'url');
1036
+ _this.executeRules(context, 'hide-safe-tags-url');
1037
+ _this.executeRules(context, 'hide-safe-tags');
1038
+ htmlEntities.toUtf(context);
1039
+ if (context.prefs.live) {
1040
+ context.text = replaceNbsp$1(context.text);
1041
+ }
1042
+ _this.executeRules(context, 'utf');
1043
+ _this.executeRules(context);
1044
+ htmlEntities.restore(context);
1045
+ _this.executeRules(context, 'html-entities');
1046
+ _this.safeTags.show(context, 'url');
1047
+ _this.executeRules(context, 'show-safe-tags-url');
1048
+ return context.text.replace(re, '');
1049
+ }).join('');
1050
+ context.isHTML = isRootHTML;
1051
+ this.safeTags.show(context, 'html');
1052
+ this.executeRules(context, 'show-safe-tags-html');
1053
+ this.safeTags.show(context, 'own');
1054
+ this.executeRules(context, 'show-safe-tags-own');
1055
+ this.executeRules(context, 'end');
1056
+ return fixLineEnding(context.text, context.prefs.lineEnding);
1057
+ };
1058
+ Typograf.prototype.executeRules = function (context, queue) {
1059
+ var _this = this;
1060
+ if (queue === void 0) { queue = DEFAULT_QUEUE_NAME; }
1061
+ var rules = this.rulesByQueues[queue];
1062
+ var innerRules = this.innerRulesByQueues[queue];
1063
+ innerRules && innerRules.forEach(function (rule) {
1064
+ _this.ruleIterator(context, rule);
1065
+ });
1066
+ rules && rules.forEach(function (rule) {
1067
+ _this.ruleIterator(context, rule);
1068
+ });
1069
+ };
1070
+ Typograf.prototype.ruleIterator = function (context, rule) {
1071
+ if ((context.prefs.live === true && rule.live === false) || (context.prefs.live === false && rule.live === true)) {
1072
+ return;
1073
+ }
1074
+ if ((rule.locale === 'common' || rule.locale === context.prefs.locale[0]) && this.isEnabledRule(rule.name)) {
1075
+ if (context.prefs.ruleFilter && !context.prefs.ruleFilter(rule)) {
1076
+ return;
1077
+ }
1078
+ this.onBeforeRule && this.onBeforeRule(rule.name, context);
1079
+ context.text = rule.handler.call(this, context.text, this.settings[rule.name], context);
1080
+ this.onAfterRule && this.onAfterRule(rule.name, context);
1081
+ }
1082
+ };
1083
+ Typograf.prototype.prepareRuleSettings = function (rule) {
1084
+ this.settings[rule.name] = deepCopy(rule.settings);
1085
+ this.enabledRules[rule.name] = rule.enabled;
1086
+ };
1087
+ Typograf.prototype.enable = function (ruleName, enabled) {
1088
+ var _this = this;
1089
+ if (Array.isArray(ruleName)) {
1090
+ ruleName.forEach(function (item) {
1091
+ _this.enableByMask(item, enabled);
1092
+ });
1093
+ }
1094
+ else {
1095
+ this.enableByMask(ruleName, enabled);
1096
+ }
1097
+ };
1098
+ Typograf.prototype.enableByMask = function (ruleName, enabled) {
1099
+ var _this = this;
1100
+ if (!ruleName) {
1101
+ return;
1102
+ }
1103
+ if (ruleName.search(/\*/) !== -1) {
1104
+ var re_1 = new RegExp(ruleName
1105
+ .replace(/\//g, '\\/')
1106
+ .replace(/\*/g, '.*'));
1107
+ this.rules.forEach(function (el) {
1108
+ var name = el.name;
1109
+ if (re_1.test(name)) {
1110
+ _this.enabledRules[name] = enabled;
1111
+ }
1112
+ });
1113
+ }
1114
+ else {
1115
+ this.enabledRules[ruleName] = enabled;
1116
+ }
1117
+ };
1118
+ Typograf.groups = [];
1119
+ Typograf.titles = {};
1120
+ Typograf.version = PACKAGE_VERSION;
1121
+ return Typograf;
1122
+ }());
1123
+
1124
+ var common = {
1125
+ 'common/char': 'a-z',
1126
+ 'common/dash': '--?|‒|–|—',
1127
+ 'common/quote': '«‹»›„“‟”"',
1128
+ };
1129
+
1130
+ var be = {
1131
+ 'be/char': 'абвгдежзйклмнопрстуфхцчшыьэюяёіўґ',
1132
+ 'be/quote': {
1133
+ left: '«“',
1134
+ right: '»”',
1135
+ }
1136
+ };
1137
+
1138
+ var bg = {
1139
+ 'bg/char': 'абвгдежзийклмнопрстуфхцчшщъьюя',
1140
+ 'bg/quote': {
1141
+ left: '„’',
1142
+ right: '“’',
1143
+ }
1144
+ };
1145
+
1146
+ var ca = {
1147
+ 'ca/char': 'abcdefghijlmnopqrstuvxyzàçèéíïòóúü',
1148
+ 'ca/quote': {
1149
+ left: '«“',
1150
+ right: '»”',
1151
+ }
1152
+ };
1153
+
1154
+ var cs = {
1155
+ 'cs/char': 'a-záéíóúýčďěňřšťůž',
1156
+ 'cs/quote': {
1157
+ left: '„‚',
1158
+ right: '“‘',
1159
+ }
1160
+ };
1161
+
1162
+ var da = {
1163
+ 'da/char': 'a-zåæø',
1164
+ 'da/quote': {
1165
+ left: '»›',
1166
+ right: '«‹',
1167
+ }
1168
+ };
1169
+
1170
+ var de = {
1171
+ 'de/char': 'a-zßäöü',
1172
+ 'de/quote': {
1173
+ left: '„‚',
1174
+ right: '“‘',
1175
+ }
1176
+ };
1177
+
1178
+ var el = {
1179
+ 'el/char': 'ΐάέήίΰαβγδεζηθικλμνξοπρςστυφχψωϊϋόύώϲάέήίόύώ',
1180
+ 'el/quote': {
1181
+ left: '«“',
1182
+ right: '»”',
1183
+ }
1184
+ };
1185
+
1186
+ var enGB = {
1187
+ 'en-GB/char': 'a-z',
1188
+ 'en-GB/quote': {
1189
+ left: '‘“',
1190
+ right: '’”',
1191
+ }
1192
+ };
1193
+
1194
+ var enUS = {
1195
+ 'en-US/char': 'a-z',
1196
+ 'en-US/quote': {
1197
+ left: '“‘',
1198
+ right: '”’',
1199
+ }
1200
+ };
1201
+
1202
+ var eo = {
1203
+ 'eo/char': 'abcdefghijklmnoprstuvzĉĝĥĵŝŭ',
1204
+ 'eo/quote': {
1205
+ left: '“‘',
1206
+ right: '”’',
1207
+ }
1208
+ };
1209
+
1210
+ var es = {
1211
+ 'es/char': 'a-záéíñóúü',
1212
+ 'es/quote': {
1213
+ left: '«“',
1214
+ right: '»”',
1215
+ }
1216
+ };
1217
+
1218
+ var et = {
1219
+ 'et/char': 'abdefghijklmnoprstuvzäõöüšž',
1220
+ 'et/quote': {
1221
+ left: '„«',
1222
+ right: '“»',
1223
+ }
1224
+ };
1225
+
1226
+ var fi = {
1227
+ 'fi/char': 'abcdefghijklmnopqrstuvyöäå',
1228
+ 'fi/quote': {
1229
+ left: '”’',
1230
+ right: '”’',
1231
+ }
1232
+ };
1233
+
1234
+ var fr = {
1235
+ 'fr/char': 'a-zàâçèéêëîïôûüœæ',
1236
+ 'fr/quote': {
1237
+ left: '«‹',
1238
+ right: '»›',
1239
+ spacing: true,
1240
+ }
1241
+ };
1242
+
1243
+ var ga = {
1244
+ 'ga/char': 'abcdefghilmnoprstuvwxyzáéíóú',
1245
+ 'ga/quote': {
1246
+ left: '“‘',
1247
+ right: '”’',
1248
+ }
1249
+ };
1250
+
1251
+ var hu = {
1252
+ 'hu/char': 'a-záäéíóöúüőű',
1253
+ 'hu/quote': {
1254
+ left: '„»',
1255
+ right: '”«',
1256
+ }
1257
+ };
1258
+
1259
+ var it = {
1260
+ 'it/char': 'a-zàéèìòù',
1261
+ 'it/quote': {
1262
+ left: '«“',
1263
+ right: '»”',
1264
+ }
1265
+ };
1266
+
1267
+ var lv = {
1268
+ 'lv/char': 'abcdefghijklmnopqrstuvxzæœ',
1269
+ 'lv/quote': {
1270
+ left: '«„',
1271
+ right: '»“',
1272
+ }
1273
+ };
1274
+
1275
+ var nl = {
1276
+ 'nl/char': 'a-zäçèéêëîïñöûü',
1277
+ 'nl/quote': {
1278
+ left: '‘“',
1279
+ right: '’”',
1280
+ }
1281
+ };
1282
+
1283
+ var no = {
1284
+ 'no/char': 'a-zåæèéêòóôø',
1285
+ 'no/quote': {
1286
+ left: '«’',
1287
+ right: '»’',
1288
+ }
1289
+ };
1290
+
1291
+ var pl = {
1292
+ 'pl/char': 'abcdefghijklmnoprstuvwxyzóąćęłńśźż',
1293
+ 'pl/quote': {
1294
+ left: '„«',
1295
+ right: '”»',
1296
+ }
1297
+ };
1298
+
1299
+ var ro = {
1300
+ 'ro/char': 'abcdefghijklmnoprstuvxzîășț',
1301
+ 'ro/quote': {
1302
+ left: '„«',
1303
+ right: '”»',
1304
+ }
1305
+ };
1306
+
1307
+ var ru = {
1308
+ 'ru/char': 'а-яё',
1309
+ 'ru/dashBefore': '(^| |\\n)',
1310
+ 'ru/dashAfter': '(?=[\u00A0 ,.?:!]|$)',
1311
+ 'ru/dashAfterDe': '(?=[,.?:!]|[\u00A0 ][^А-ЯЁ]|$)',
1312
+ 'ru/l': 'а-яёa-z',
1313
+ 'ru/L': 'А-ЯЁA-Z',
1314
+ 'ru/month': 'январь|февраль|март|апрель|май|июнь|июль|август|сентябрь|октябрь|ноябрь|декабрь',
1315
+ 'ru/monthGenCase': 'января|февраля|марта|апреля|мая|июня|июля|августа|сентября|октября|ноября|декабря',
1316
+ 'ru/monthPreCase': 'январе|феврале|марте|апреле|мае|июне|июле|августе|сентябре|октябре|ноябре|декабре',
1317
+ 'ru/quote': {
1318
+ left: '«„‚',
1319
+ right: '»“‘',
1320
+ removeDuplicateQuotes: true,
1321
+ },
1322
+ 'ru/shortMonth': 'янв|фев|мар|апр|ма[ейя]|июн|июл|авг|сен|окт|ноя|дек',
1323
+ 'ru/weekday': 'понедельник|вторник|среда|четверг|пятница|суббота|воскресенье',
1324
+ };
1325
+
1326
+ var sk = {
1327
+ 'sk/char': 'abcdefghijklmnoprstuvwxyzáäéíóôúýčďľňŕšťž',
1328
+ 'sk/quote': {
1329
+ left: '„‚',
1330
+ right: '“‘',
1331
+ }
1332
+ };
1333
+
1334
+ var sl = {
1335
+ 'sl/char': 'a-zčšž',
1336
+ 'sl/quote': {
1337
+ left: '„‚',
1338
+ right: '“‘',
1339
+ }
1340
+ };
1341
+
1342
+ var sr = {
1343
+ 'sr/char': 'abcdefghijklmnoprstuvzćčđšž',
1344
+ 'sr/quote': {
1345
+ left: '„’',
1346
+ right: '”’',
1347
+ }
1348
+ };
1349
+
1350
+ var sv = {
1351
+ 'sv/char': 'a-zäåéö',
1352
+ 'sv/quote': {
1353
+ left: '”’',
1354
+ right: '”’',
1355
+ }
1356
+ };
1357
+
1358
+ var tr = {
1359
+ 'tr/char': 'abcdefghijklmnoprstuvyzâçîöûüğış',
1360
+ 'tr/quote': {
1361
+ left: '“‘',
1362
+ right: '”’',
1363
+ }
1364
+ };
1365
+
1366
+ var uk = {
1367
+ 'uk/char': 'абвгдежзийклмнопрстуфхцчшщьюяєіїґ',
1368
+ 'uk/quote': {
1369
+ left: '«„',
1370
+ right: '»“',
1371
+ }
1372
+ };
1373
+
1374
+ var data = [
1375
+ common,
1376
+ be,
1377
+ bg,
1378
+ ca,
1379
+ cs,
1380
+ da,
1381
+ de,
1382
+ el,
1383
+ enGB,
1384
+ enUS,
1385
+ eo,
1386
+ es,
1387
+ et,
1388
+ fi,
1389
+ fr,
1390
+ ga,
1391
+ hu,
1392
+ it,
1393
+ lv,
1394
+ nl,
1395
+ no,
1396
+ pl,
1397
+ ro,
1398
+ ru,
1399
+ sk,
1400
+ sl,
1401
+ sr,
1402
+ sv,
1403
+ tr,
1404
+ uk
1405
+ ];
1406
+ data.forEach(function (item) { return setData(item); });
1407
+
1408
+ var eMailRule = {
1409
+ name: 'common/html/e-mail',
1410
+ queue: 'end',
1411
+ handler: function (text, _settings, context) {
1412
+ return context.isHTML ? text : text.replace(/(^|[\s;(])([\w\-.]{2,64})@([\w\-.]{2,64})\.([a-z]{2,64})([)\s.,!?]|$)/gi, '$1<a href="mailto:$2@$3.$4">$2@$3.$4</a>$5');
1413
+ },
1414
+ disabled: true,
1415
+ htmlAttrs: false,
1416
+ };
1417
+
1418
+ var entityMap = {
1419
+ '&': '&amp;',
1420
+ '<': '&lt;',
1421
+ '>': '&gt;',
1422
+ '"': '&quot;',
1423
+ '\'': '&#39;',
1424
+ '/': '&#x2F;'
1425
+ };
1426
+ var escapeRule = {
1427
+ name: 'common/html/escape',
1428
+ index: '+100',
1429
+ queue: 'end',
1430
+ handler: function (text) {
1431
+ return text.replace(/[&<>"'/]/g, function (key) { return entityMap[key]; });
1432
+ },
1433
+ disabled: true,
1434
+ };
1435
+
1436
+ var nbrRule = {
1437
+ name: 'common/html/nbr',
1438
+ index: '+10',
1439
+ queue: 'end',
1440
+ handler: function (text) {
1441
+ return text.replace(/([^\n>])\n(?=[^\n])/g, '$1<br/>\n');
1442
+ },
1443
+ disabled: true,
1444
+ htmlAttrs: false,
1445
+ };
1446
+
1447
+ var blockElements = [
1448
+ 'address',
1449
+ 'article',
1450
+ 'aside',
1451
+ 'blockquote',
1452
+ 'canvas',
1453
+ 'dd',
1454
+ 'div',
1455
+ 'dl',
1456
+ 'fieldset',
1457
+ 'figcaption',
1458
+ 'figure',
1459
+ 'footer',
1460
+ 'form',
1461
+ 'h1',
1462
+ 'h2',
1463
+ 'h3',
1464
+ 'h4',
1465
+ 'h5',
1466
+ 'h6',
1467
+ 'header',
1468
+ 'hgroup',
1469
+ 'hr',
1470
+ 'li',
1471
+ 'main',
1472
+ 'nav',
1473
+ 'noscript',
1474
+ 'ol',
1475
+ 'output',
1476
+ 'p',
1477
+ 'pre',
1478
+ 'section',
1479
+ 'table',
1480
+ 'tfoot',
1481
+ 'ul',
1482
+ 'video'
1483
+ ];
1484
+
1485
+ var blockRe = new RegExp('<(' + blockElements.join('|') + ')[>\\s]');
1486
+ var separator = '\n\n';
1487
+ var pRule = {
1488
+ name: 'common/html/p',
1489
+ index: '+5',
1490
+ queue: 'end',
1491
+ handler: function (text) {
1492
+ var buffer = text.split(separator);
1493
+ buffer.forEach(function (text, i, data) {
1494
+ if (!text.trim()) {
1495
+ return;
1496
+ }
1497
+ if (!blockRe.test(text)) {
1498
+ data[i] = text.replace(/^(\s*)/, '$1<p>').replace(/(\s*)$/, '</p>$1');
1499
+ }
1500
+ });
1501
+ return buffer.join(separator);
1502
+ },
1503
+ disabled: true,
1504
+ htmlAttrs: false,
1505
+ };
1506
+
1507
+ var processingAttrsRule = {
1508
+ name: 'common/html/processingAttrs',
1509
+ queue: 'hide-safe-tags-own',
1510
+ handler: function (text, settings, context) {
1511
+ var _this = this;
1512
+ var reAttrs = new RegExp('(^|\\s)(' + settings.attrs.join('|') + ')=("[^"]*?"|\'[^\']*?\')', 'gi');
1513
+ var prefs = deepCopy(context.prefs);
1514
+ prefs.ruleFilter = function (rule) { return rule.htmlAttrs !== false; };
1515
+ return text.replace(/(<[-\w]+\s)([^>]+?)(?=>)/g, function (_match, tagName, attrs) {
1516
+ var resultAttrs = attrs.replace(reAttrs, function (_submatch, space, attrName, attrValue) {
1517
+ var lquote = attrValue[0];
1518
+ var rquote = attrValue[attrValue.length - 1];
1519
+ var value = attrValue.slice(1, -1);
1520
+ return space + attrName + '=' + lquote + _this.execute(value, prefs) + rquote;
1521
+ });
1522
+ return tagName + resultAttrs;
1523
+ });
1524
+ },
1525
+ settings: {
1526
+ attrs: ['title', 'placeholder']
1527
+ },
1528
+ disabled: true,
1529
+ htmlAttrs: false,
1530
+ };
1531
+
1532
+ var quotRule = {
1533
+ name: 'common/html/quot',
1534
+ queue: 'hide-safe-tags',
1535
+ handler: function (text) {
1536
+ return text.replace(/&quot;/g, '"');
1537
+ },
1538
+ };
1539
+
1540
+ var stripTagsRule = {
1541
+ name: 'common/html/stripTags',
1542
+ index: '+99',
1543
+ queue: 'end',
1544
+ handler: function (text) {
1545
+ return text.replace(/<[^>]+>/g, '');
1546
+ },
1547
+ disabled: true,
1548
+ };
1549
+
1550
+ var urlRule = {
1551
+ name: 'common/html/url',
1552
+ queue: 'end',
1553
+ handler: function (text, _settings, context) {
1554
+ return context.isHTML ? text : text.replace(regExpUrl, function ($0, protocol, path) {
1555
+ path = path
1556
+ .replace(/([^/]+\/?)(\?|#)$/, '$1') // Remove ending ? and #
1557
+ .replace(/^([^/]+)\/$/, '$1'); // Remove ending /
1558
+ if (protocol === 'http') {
1559
+ path = path.replace(/^([^/]+)(:80)([^\d]|\/|$)/, '$1$3'); // Remove 80 port
1560
+ }
1561
+ else if (protocol === 'https') {
1562
+ path = path.replace(/^([^/]+)(:443)([^\d]|\/|$)/, '$1$3'); // Remove 443 port
1563
+ }
1564
+ var url = path;
1565
+ var fullUrl = protocol + '://' + path;
1566
+ var firstPart = '<a href="' + fullUrl + '">';
1567
+ if (protocol === 'http' || protocol === 'https') {
1568
+ url = url.replace(/^www\./, '');
1569
+ return firstPart + (protocol === 'http' ? url : protocol + '://' + url) + '</a>';
1570
+ }
1571
+ return firstPart + fullUrl + '</a>';
1572
+ });
1573
+ },
1574
+ disabled: true,
1575
+ htmlAttrs: false,
1576
+ };
1577
+
1578
+ Typograf.addRules([
1579
+ eMailRule,
1580
+ escapeRule,
1581
+ nbrRule,
1582
+ pRule,
1583
+ processingAttrsRule,
1584
+ quotRule,
1585
+ stripTagsRule,
1586
+ urlRule,
1587
+ ]);
1588
+
1589
+ var afterNumberRule = {
1590
+ name: 'common/nbsp/afterNumber',
1591
+ handler: function (text, _settings, context) {
1592
+ var char = context.getData('char');
1593
+ var re = '(^|\\s)(\\d{1,5}) ([' + char + ']+)';
1594
+ return text.replace(new RegExp(re, 'gi'), '$1$2\u00A0$3');
1595
+ },
1596
+ disabled: true,
1597
+ };
1598
+
1599
+ var afterParagraphMarkRule = {
1600
+ name: 'common/nbsp/afterParagraphMark',
1601
+ handler: function (text) {
1602
+ return text.replace(/¶ ?(?=\d)/g, '¶\u00A0');
1603
+ },
1604
+ };
1605
+
1606
+ var afterSectionMarkRule = {
1607
+ name: 'common/nbsp/afterSectionMark',
1608
+ handler: function (text, _settings, context) {
1609
+ // \u2009 - THIN SPACE
1610
+ // \u202F - NARROW NO-BREAK SPACE
1611
+ var locale = context.prefs.locale[0];
1612
+ return text.replace(/§[ \u00A0\u2009]?(?=\d|I|V|X)/g, locale === 'ru' ? '§\u202F' : '§\u00A0');
1613
+ },
1614
+ };
1615
+
1616
+ var afterShortWordRule = {
1617
+ name: 'common/nbsp/afterShortWord',
1618
+ handler: function (text, settings, context) {
1619
+ var len = settings.lengthShortWord;
1620
+ var quote = getData('common/quote');
1621
+ var char = context.getData('char');
1622
+ var before = ' \u00A0(' + privateLabel + quote;
1623
+ var subStr = '(^|[' + before + '])([' + char + ']{1,' + len + '}) ';
1624
+ var newSubStr = '$1$2\u00A0';
1625
+ var re = new RegExp(subStr, 'gim');
1626
+ return text
1627
+ .replace(re, newSubStr)
1628
+ .replace(re, newSubStr);
1629
+ },
1630
+ settings: {
1631
+ lengthShortWord: 2,
1632
+ },
1633
+ };
1634
+
1635
+ var beforeShortLastNumberRule = {
1636
+ name: 'common/nbsp/beforeShortLastNumber',
1637
+ handler: function (text, settings, context) {
1638
+ var quote = context.getData('quote');
1639
+ var ch = context.getData('char');
1640
+ var CH = ch.toUpperCase();
1641
+ var re = new RegExp('([' + ch + CH +
1642
+ ']) (?=\\d{1,' + settings.lengthLastNumber +
1643
+ '}[-+−%\'"' + quote.right + ')]?([.!?…]( [' +
1644
+ CH + ']|$)|$))', 'gm');
1645
+ return text.replace(re, '$1\u00A0');
1646
+ },
1647
+ live: false,
1648
+ settings: {
1649
+ lengthLastNumber: 2,
1650
+ },
1651
+ };
1652
+
1653
+ var beforeShortLastWordRule = {
1654
+ name: 'common/nbsp/beforeShortLastWord',
1655
+ handler: function (text, settings, context) {
1656
+ var ch = context.getData('char');
1657
+ var CH = ch.toUpperCase();
1658
+ var re = new RegExp('([' + ch + '\\d]) ([' +
1659
+ ch + CH + ']{1,' + settings.lengthLastWord +
1660
+ '}[.!?…])( [' + CH + ']|$)', 'g');
1661
+ return text.replace(re, '$1\u00A0$2$3');
1662
+ },
1663
+ settings: {
1664
+ lengthLastWord: 3,
1665
+ },
1666
+ };
1667
+
1668
+ var dpiRule = {
1669
+ name: 'common/nbsp/dpi',
1670
+ handler: function (text) {
1671
+ return text.replace(/(\d) ?(lpi|dpi)(?!\w)/, '$1\u00A0$2');
1672
+ },
1673
+ };
1674
+
1675
+ function replaceNbsp($0, $1, $2, $3) {
1676
+ return $1 + $2.replace(/([^\u00A0])\u00A0([^\u00A0])/g, '$1 $2') + $3;
1677
+ }
1678
+ var nowrapRule = {
1679
+ name: 'common/nbsp/nowrap',
1680
+ queue: 'end',
1681
+ handler: function (text) {
1682
+ return text
1683
+ .replace(/(<nowrap>)(.*?)(<\/nowrap>)/g, replaceNbsp)
1684
+ .replace(/(<nobr>)(.*?)(<\/nobr>)/g, replaceNbsp);
1685
+ },
1686
+ };
1687
+
1688
+ var replaceNbspRule = {
1689
+ name: 'common/nbsp/replaceNbsp',
1690
+ queue: 'utf',
1691
+ live: false,
1692
+ handler: replaceNbsp$1,
1693
+ disabled: true,
1694
+ };
1695
+
1696
+ Typograf.addRules([
1697
+ afterNumberRule,
1698
+ afterParagraphMarkRule,
1699
+ afterSectionMarkRule,
1700
+ afterShortWordRule,
1701
+ beforeShortLastNumberRule,
1702
+ beforeShortLastWordRule,
1703
+ dpiRule,
1704
+ nowrapRule,
1705
+ replaceNbspRule,
1706
+ ]);
1707
+
1708
+ var digitGroupingRule = {
1709
+ name: 'common/number/digitGrouping',
1710
+ index: '310',
1711
+ disabled: true,
1712
+ handler: function (text, settings) {
1713
+ return text
1714
+ .replace(new RegExp("(^ ?|\\D |".concat(privateLabel, ")(\\d{1,3}([ \u00A0\u202F\u2009]\\d{3})+)(?! ?[\\d-])"), 'gm'), function ($0, $1, $2) { return $1 + $2.replace(/\s/g, settings.space); })
1715
+ // https://www.bipm.org/utils/common/pdf/si-brochure/SI-Brochure-9-EN.pdf #5.4.4
1716
+ .replace(/(\d{5,}([.,]\d+)?)/g, function ($0, $1) {
1717
+ var decimalMarker = $1.match(/[.,]/);
1718
+ var parts = decimalMarker ? $1.split(decimalMarker) : [$1];
1719
+ var integerPart = parts[0];
1720
+ var fractionalPart = parts[1];
1721
+ integerPart = integerPart.replace(/(\d)(?=(\d{3})+([^\d]|$))/g, '$1' + settings.space);
1722
+ return decimalMarker ?
1723
+ integerPart + decimalMarker + fractionalPart :
1724
+ integerPart;
1725
+ });
1726
+ },
1727
+ settings: {
1728
+ space: '\u202F',
1729
+ },
1730
+ };
1731
+
1732
+ var fractionRule = {
1733
+ name: 'common/number/fraction',
1734
+ handler: function (text) {
1735
+ return text
1736
+ .replace(/(^|\D)1\/2(\D|$)/g, '$1½$2')
1737
+ .replace(/(^|\D)1\/4(\D|$)/g, '$1¼$2')
1738
+ .replace(/(^|\D)3\/4(\D|$)/g, '$1¾$2');
1739
+ },
1740
+ };
1741
+
1742
+ var mathSignsRule = {
1743
+ name: 'common/number/mathSigns',
1744
+ handler: function (text) {
1745
+ return replace(text, [
1746
+ [/!=/g, '≠'],
1747
+ [/<=/g, '≤'],
1748
+ [/(^|[^=])>=/g, '$1≥'],
1749
+ [/<=>/g, '⇔'],
1750
+ [/<</g, '≪'],
1751
+ [/>>/g, '≫'],
1752
+ [/~=/g, '≅'],
1753
+ [/(^|[^+])\+-/g, '$1±']
1754
+ ]);
1755
+ }
1756
+ };
1757
+
1758
+ var timesRule = {
1759
+ name: 'common/number/times',
1760
+ handler: function (text) {
1761
+ return text.replace(/(\d)[ \u00A0]?[xх][ \u00A0]?(\d)/g, '$1×$2');
1762
+ },
1763
+ };
1764
+
1765
+ Typograf.addRules([
1766
+ digitGroupingRule,
1767
+ fractionRule,
1768
+ mathSignsRule,
1769
+ timesRule,
1770
+ ]);
1771
+
1772
+ var delBOMRule = {
1773
+ name: 'common/other/delBOM',
1774
+ queue: 'start',
1775
+ index: -1,
1776
+ handler: function (text) {
1777
+ if (text.charCodeAt(0) === 0xFEFF) {
1778
+ return text.slice(1);
1779
+ }
1780
+ return text;
1781
+ },
1782
+ };
1783
+
1784
+ var repeatWordRule = {
1785
+ name: 'common/other/repeatWord',
1786
+ handler: function (text, settings, context) {
1787
+ var quote = getData('common/quote');
1788
+ var char = context.getData('char');
1789
+ var punc = '[;:,.?! \n' + quote + ']';
1790
+ var re = new RegExp('(' + punc + '|^)' +
1791
+ '([' + char + ']{' + settings.min + ',}) ' +
1792
+ '\\2(' + punc + '|$)', 'gi');
1793
+ return text.replace(re, '$1$2$3');
1794
+ },
1795
+ settings: { min: 2 },
1796
+ disabled: true,
1797
+ };
1798
+
1799
+ Typograf.addRules([
1800
+ delBOMRule,
1801
+ repeatWordRule,
1802
+ ]);
1803
+
1804
+ var apostropheRule = {
1805
+ name: 'common/punctuation/apostrophe',
1806
+ handler: function (text, _settings, context) {
1807
+ var char = context.getData('char');
1808
+ var letters = '([' + char + '])';
1809
+ var re = new RegExp(letters + '\'' + letters, 'gi');
1810
+ return text.replace(re, '$1’$2');
1811
+ },
1812
+ };
1813
+
1814
+ var delDoublePunctuationRule = {
1815
+ name: 'common/punctuation/delDoublePunctuation',
1816
+ handler: function (text) {
1817
+ return text
1818
+ .replace(/(^|[^,]),,(?!,)/g, '$1,')
1819
+ .replace(/(^|[^:])::(?!:)/g, '$1:')
1820
+ .replace(/(^|[^!?.])\.\.(?!\.)/g, '$1.')
1821
+ .replace(/(^|[^;]);;(?!;)/g, '$1;')
1822
+ .replace(/(^|[^?])\?\?(?!\?)/g, '$1?');
1823
+ },
1824
+ };
1825
+
1826
+ var hellipRule = {
1827
+ name: 'common/punctuation/hellip',
1828
+ handler: function (text, _settings, context) {
1829
+ return context.prefs.locale[0] === 'ru' ?
1830
+ text.replace(/(^|[^.])\.{3,4}(?=[^.]|$)/g, '$1…') :
1831
+ text.replace(/(^|[^.])\.{3}(\.?)(?=[^.]|$)/g, '$1…$2');
1832
+ },
1833
+ };
1834
+
1835
+ var MAX_LEVEL_WITH_ERRORS = 2;
1836
+ var Quote = /** @class */ (function () {
1837
+ function Quote() {
1838
+ this.bufferQuotes = {
1839
+ left: '\uF005\uF006\uF007',
1840
+ right: '\uF008\uF009\uF0A0',
1841
+ };
1842
+ this.beforeLeft = ' \n\t\u00a0[(';
1843
+ this.afterRight = ' \n\t\u00a0!?.:;#*,…)\\]';
1844
+ }
1845
+ Quote.prototype.process = function (params) {
1846
+ var text = params.context.text;
1847
+ var count = this.count(text);
1848
+ if (!count.total) {
1849
+ return text;
1850
+ }
1851
+ var originalSettings = params.settings;
1852
+ var isEqualQuotes = params.settings.left[0] === params.settings.right[0];
1853
+ // For SW, FI
1854
+ if (isEqualQuotes) {
1855
+ params.settings = deepCopy(params.settings);
1856
+ params.settings.left = this.bufferQuotes.left.slice(0, params.settings.left.length);
1857
+ params.settings.right = this.bufferQuotes.right.slice(0, params.settings.right.length);
1858
+ }
1859
+ // For FR
1860
+ if (params.settings.spacing) {
1861
+ text = this.removeSpacing(text, params.settings);
1862
+ }
1863
+ text = this.set(text, params);
1864
+ // For FR
1865
+ if (params.settings.spacing) {
1866
+ text = this.setSpacing(text, params.settings);
1867
+ }
1868
+ // For RU
1869
+ if (params.settings.removeDuplicateQuotes) {
1870
+ text = this.removeDuplicates(text, params.settings);
1871
+ }
1872
+ // For SW, FI
1873
+ if (isEqualQuotes) {
1874
+ text = this.returnOriginalQuotes(text, originalSettings, params.settings);
1875
+ params.settings = originalSettings;
1876
+ }
1877
+ return text;
1878
+ };
1879
+ Quote.prototype.returnOriginalQuotes = function (text, originalSettings, bufferSettings) {
1880
+ var buffer = {};
1881
+ for (var i = 0; i < bufferSettings.left.length; i++) {
1882
+ buffer[bufferSettings.left[i]] = originalSettings.left[i];
1883
+ buffer[bufferSettings.right[i]] = originalSettings.right[i];
1884
+ }
1885
+ return text.replace(new RegExp('[' + bufferSettings.left + bufferSettings.right + ']', 'g'), function (quote) {
1886
+ return buffer[quote];
1887
+ });
1888
+ };
1889
+ Quote.prototype.count = function (text) {
1890
+ var count = { total: 0 };
1891
+ text.replace(new RegExp('[' + getData('common/quote') + ']', 'g'), function (quote) {
1892
+ if (!count[quote]) {
1893
+ count[quote] = 0;
1894
+ }
1895
+ count[quote]++;
1896
+ count.total++;
1897
+ return quote;
1898
+ });
1899
+ return count;
1900
+ };
1901
+ Quote.prototype.removeDuplicates = function (text, settings) {
1902
+ var lquote = settings.left[0];
1903
+ var lquote2 = settings.left[1] || lquote;
1904
+ var rquote = settings.right[0];
1905
+ if (lquote !== lquote2) {
1906
+ return text;
1907
+ }
1908
+ return text
1909
+ // ««word» word» -> «word» word»
1910
+ .replace(new RegExp(lquote + lquote, 'g'), lquote)
1911
+ // «word «word»» -> «word «word»
1912
+ .replace(new RegExp(rquote + rquote, 'g'), rquote);
1913
+ };
1914
+ Quote.prototype.removeSpacing = function (text, settings) {
1915
+ for (var i = 0, len = settings.left.length; i < len; i++) {
1916
+ var lquote = settings.left[i];
1917
+ var rquote = settings.right[i];
1918
+ text = text
1919
+ .replace(new RegExp(lquote + '([ \u202F\u00A0])', 'g'), lquote)
1920
+ .replace(new RegExp('([ \u202F\u00A0])' + rquote, 'g'), rquote);
1921
+ }
1922
+ return text;
1923
+ };
1924
+ Quote.prototype.setSpacing = function (text, settings) {
1925
+ for (var i = 0, len = settings.left.length; i < len; i++) {
1926
+ var lquote = settings.left[i];
1927
+ var rquote = settings.right[i];
1928
+ text = text
1929
+ .replace(new RegExp(lquote + '([^\u202F])', 'g'), lquote + '\u202F$1')
1930
+ .replace(new RegExp('([^\u202F])' + rquote, 'g'), '$1\u202F' + rquote);
1931
+ }
1932
+ return text;
1933
+ };
1934
+ Quote.prototype.set = function (text, params) {
1935
+ var quotes = getData('common/quote');
1936
+ var lquote = params.settings.left[0];
1937
+ var lquote2 = params.settings.left[1] || lquote;
1938
+ var rquote = params.settings.right[0];
1939
+ var reL = new RegExp('(^|[' + this.beforeLeft + '])([' + quotes + ']+)(?=[^\\s' + privateLabel + '])', 'gim');
1940
+ var reR = new RegExp('([^\\s' + privateLabel + '])([' + quotes + ']+)(?=[' + this.afterRight + ']|$)', 'gim');
1941
+ text = text
1942
+ .replace(reL, function ($0, $1, $2) { return $1 + repeat(lquote, $2.length); })
1943
+ .replace(reR, function ($0, $1, $2) { return $1 + repeat(rquote, $2.length); });
1944
+ text = this.setAboveTags(text, params);
1945
+ if (lquote !== lquote2) {
1946
+ text = this.setInner(text, params.settings);
1947
+ }
1948
+ return text;
1949
+ };
1950
+ Quote.prototype.setAboveTags = function (text, params) {
1951
+ var _this = this;
1952
+ var quotes = getData('common/quote');
1953
+ var lquote = params.settings.left[0];
1954
+ var rquote = params.settings.right[0];
1955
+ return text.replace(new RegExp('(^|.)([' + quotes + '])(.|$)', 'gm'), function (original, prev, quote, next, pos) {
1956
+ if (prev !== privateLabel && next !== privateLabel) {
1957
+ return original;
1958
+ }
1959
+ if (prev === privateLabel && next === privateLabel) {
1960
+ if (quote === '"') {
1961
+ return prev + _this.getAboveTwoTags(text, pos + 1, params) + next;
1962
+ }
1963
+ return original;
1964
+ }
1965
+ if (prev === privateLabel) {
1966
+ var hasRight = _this.afterRight.indexOf(next) > -1;
1967
+ var prevInfo = params.safeTags.getPrevTagInfo(params.context, text, pos - 1);
1968
+ if (hasRight && prevInfo && prevInfo.group === 'html') {
1969
+ return prev + (prevInfo.isClosing ? rquote : lquote) + next;
1970
+ }
1971
+ return prev + (!next || hasRight ? rquote : lquote) + next;
1972
+ }
1973
+ else {
1974
+ var hasLeft = _this.beforeLeft.indexOf(prev) > -1;
1975
+ var nextInfo = params.safeTags.getNextTagInfo(params.context, text, pos + 1);
1976
+ if (hasLeft && nextInfo && nextInfo.group === 'html') {
1977
+ return prev + (nextInfo.isClosing ? rquote : lquote) + next;
1978
+ }
1979
+ return prev + (!prev || hasLeft ? lquote : rquote) + next;
1980
+ }
1981
+ });
1982
+ };
1983
+ Quote.prototype.getAboveTwoTags = function (text, pos, params) {
1984
+ var prevInfo = params.safeTags.getPrevTagInfo(params.context, text, pos);
1985
+ var nextInfo = params.safeTags.getNextTagInfo(params.context, text, pos);
1986
+ if (prevInfo) {
1987
+ if (prevInfo.group === 'html') {
1988
+ if (!prevInfo.isClosing) {
1989
+ return params.settings.left[0];
1990
+ }
1991
+ if (nextInfo && nextInfo.isClosing && prevInfo.isClosing) {
1992
+ return params.settings.right[0];
1993
+ }
1994
+ }
1995
+ }
1996
+ return text[pos];
1997
+ };
1998
+ Quote.prototype.setInner = function (text, settings) {
1999
+ var lquote = settings.left[0];
2000
+ var rquote = settings.right[0];
2001
+ var minLevel = 0;
2002
+ var maxLevel = this.getMaxLevel(text, lquote, rquote, settings.left.length);
2003
+ var level = minLevel;
2004
+ var result = '';
2005
+ for (var i = 0, len = text.length; i < len; i++) {
2006
+ var letter = text[i];
2007
+ if (letter === lquote) {
2008
+ result += settings.left[level > maxLevel - 1 ? maxLevel - 1 : level];
2009
+ level++;
2010
+ if (level > maxLevel) {
2011
+ level = maxLevel;
2012
+ }
2013
+ }
2014
+ else if (letter === rquote) {
2015
+ level--;
2016
+ if (level < minLevel) {
2017
+ level = minLevel;
2018
+ }
2019
+ result += settings.right[level];
2020
+ }
2021
+ else {
2022
+ if (letter === '"') {
2023
+ level = minLevel;
2024
+ }
2025
+ result += letter;
2026
+ }
2027
+ }
2028
+ return result;
2029
+ };
2030
+ Quote.prototype.getMaxLevel = function (text, leftQuote, rightQuote, length) {
2031
+ var count = this.count(text);
2032
+ return count[leftQuote] === count[rightQuote] ?
2033
+ length :
2034
+ Math.min(length, MAX_LEVEL_WITH_ERRORS);
2035
+ };
2036
+ return Quote;
2037
+ }());
2038
+ var quote = new Quote();
2039
+ var settings = {};
2040
+ getLocales().forEach(function (locale) {
2041
+ settings[locale] = deepCopy(getData(locale + '/quote'));
2042
+ });
2043
+ var quoteRule$1 = {
2044
+ name: 'common/punctuation/quote',
2045
+ handler: function (text, commonSettings, context) {
2046
+ var locale = context.prefs.locale[0];
2047
+ var settings = commonSettings[locale];
2048
+ if (!settings) {
2049
+ return text;
2050
+ }
2051
+ return quote.process({
2052
+ context: context,
2053
+ settings: settings,
2054
+ safeTags: this.safeTags,
2055
+ });
2056
+ },
2057
+ settings: settings,
2058
+ };
2059
+
2060
+ var quoteLinkRule = {
2061
+ name: 'common/punctuation/quoteLink',
2062
+ queue: 'show-safe-tags-html',
2063
+ index: '+5',
2064
+ handler: function (text, _settings, context) {
2065
+ var quotes = this.getSetting('common/punctuation/quote', context.prefs.locale[0]);
2066
+ var lquote1 = htmlEntities.getByUtf(quotes.left[0]);
2067
+ var rquote1 = htmlEntities.getByUtf(quotes.right[0]);
2068
+ var lquote2 = htmlEntities.getByUtf(quotes.left[1]);
2069
+ var rquote2 = htmlEntities.getByUtf(quotes.right[1]);
2070
+ lquote2 = lquote2 ? ('|' + lquote2) : '';
2071
+ rquote2 = rquote2 ? ('|' + rquote2) : '';
2072
+ var re = new RegExp('(<[aA]\\s[^>]*?>)(' + lquote1 + lquote2 + ')([^]*?)(' + rquote1 + rquote2 + ')(</[aA]>)', 'g');
2073
+ return text.replace(re, '$2$1$3$5$4');
2074
+ },
2075
+ };
2076
+
2077
+ Typograf.addRules([
2078
+ apostropheRule,
2079
+ delDoublePunctuationRule,
2080
+ hellipRule,
2081
+ quoteRule$1,
2082
+ quoteLinkRule,
2083
+ ]);
2084
+
2085
+ var beforeBracketRule = {
2086
+ name: 'common/space/beforeBracket',
2087
+ handler: function (text, _settings, context) {
2088
+ var char = context.getData('char');
2089
+ var re = new RegExp('([' + char + '.!?,;…)])\\(', 'gi');
2090
+ return text.replace(re, '$1 (');
2091
+ },
2092
+ };
2093
+
2094
+ var bracketRule$1 = {
2095
+ name: 'common/space/bracket',
2096
+ handler: function (text) {
2097
+ return text
2098
+ .replace(/(\() +/g, '(')
2099
+ .replace(/ +\)/g, ')');
2100
+ },
2101
+ };
2102
+
2103
+ var delBeforePercentRule = {
2104
+ name: 'common/space/delBeforePercent',
2105
+ handler: function (text) {
2106
+ return text.replace(/(\d)( |\u00A0)(%|‰|‱)/g, '$1$3');
2107
+ },
2108
+ };
2109
+
2110
+ var delBeforePunctuationRule = {
2111
+ name: 'common/space/delBeforePunctuation',
2112
+ handler: function (text) {
2113
+ return text.replace(/(^|[^!?:;,.…]) ([!?:;,])(?!\))/g, '$1$2');
2114
+ },
2115
+ };
2116
+
2117
+ var delBetweenExclamationMarksRule = {
2118
+ name: 'common/space/delBetweenExclamationMarks',
2119
+ handler: function (text) {
2120
+ return text.replace(/([!?]) (?=[!?])/g, '$1');
2121
+ },
2122
+ };
2123
+
2124
+ var delBeforeDotRule = {
2125
+ name: 'common/space/delBeforeDot',
2126
+ handler: function (text) {
2127
+ return text.replace(/(^|[^!?:;,.…]) (\.|\.\.\.)(\s|$)/g, '$1$2$3');
2128
+ },
2129
+ };
2130
+
2131
+ var delLeadingBlanksRule = {
2132
+ name: 'common/space/delLeadingBlanks',
2133
+ handler: function (text) {
2134
+ return text.replace(/^[ \t]+/mg, '');
2135
+ },
2136
+ disabled: true,
2137
+ };
2138
+
2139
+ var delRepeatNRule = {
2140
+ name: 'common/space/delRepeatN',
2141
+ index: '-1',
2142
+ handler: function (text, settings) {
2143
+ var maxConsecutiveLineBreaks = settings.maxConsecutiveLineBreaks;
2144
+ var consecutiveLineBreaksRegex = new RegExp("\n{".concat(maxConsecutiveLineBreaks + 1, ",}"), 'g');
2145
+ var replaceValue = repeat('\n', maxConsecutiveLineBreaks);
2146
+ return text.replace(consecutiveLineBreaksRegex, replaceValue);
2147
+ },
2148
+ settings: {
2149
+ maxConsecutiveLineBreaks: 2,
2150
+ },
2151
+ };
2152
+
2153
+ var delRepeatSpaceRule = {
2154
+ name: 'common/space/delRepeatSpace',
2155
+ index: '-1',
2156
+ handler: function (text) {
2157
+ return text.replace(/([^\n \t])[ \t]{2,}(?![\n \t])/g, '$1 ');
2158
+ },
2159
+ };
2160
+
2161
+ var delTrailingBlanksRule = {
2162
+ name: 'common/space/delTrailingBlanks',
2163
+ index: '-3',
2164
+ handler: function (text) {
2165
+ return text.replace(/[ \t]+\n/g, '\n');
2166
+ },
2167
+ };
2168
+
2169
+ var insertFinalNewlineRule = {
2170
+ name: 'common/space/insertFinalNewline',
2171
+ queue: 'end',
2172
+ handler: function (text) {
2173
+ return text[text.length - 1] === '\n' ? text : text + '\n';
2174
+ },
2175
+ live: false,
2176
+ disabled: true,
2177
+ };
2178
+
2179
+ var replaceTabRule = {
2180
+ name: 'common/space/replaceTab',
2181
+ index: '-5',
2182
+ handler: function (text) {
2183
+ return text.replace(/\t/g, ' ');
2184
+ },
2185
+ };
2186
+
2187
+ var squareBracketRule = {
2188
+ name: 'common/space/squareBracket',
2189
+ handler: function (text) {
2190
+ return text
2191
+ .replace(/(\[) +/g, '[')
2192
+ .replace(/ +\]/g, ']');
2193
+ },
2194
+ };
2195
+
2196
+ var trimLeftRule = {
2197
+ name: 'common/space/trimLeft',
2198
+ index: '-4',
2199
+ handler: String.prototype.trimLeft ?
2200
+ function (text) { return text.trimLeft(); } :
2201
+ /* istanbul ignore next */
2202
+ function (text) { return text.replace(/^[\s\uFEFF\xA0]+/g, ''); },
2203
+ };
2204
+
2205
+ var trimRightRule = {
2206
+ name: 'common/space/trimRight',
2207
+ index: '-3',
2208
+ live: false,
2209
+ handler: String.prototype.trimRight ?
2210
+ function (text) { return text.trimRight(); } :
2211
+ /* istanbul ignore next */
2212
+ function (text) { return text.replace(/[\s\uFEFF\xA0]+$/g, ''); }
2213
+ };
2214
+
2215
+ var reColon = new RegExp('(\\D):([^)",:.?\\s\\/\\\\' + privateLabel + '])', 'g');
2216
+ var afterColonRule = {
2217
+ name: 'common/space/afterColon',
2218
+ handler: function (text) {
2219
+ return text.replace(reColon, '$1: $2');
2220
+ },
2221
+ };
2222
+
2223
+ var afterCommaRule = {
2224
+ name: 'common/space/afterComma',
2225
+ handler: function (text, settings, context) {
2226
+ var quote = context.getData('quote');
2227
+ var quotes = typeof quote === 'string' ? quote : quote.right;
2228
+ return text.replace(new RegExp('(.),([^)",:.?\\s\\/\\\\' + privateLabel + quotes + '])', 'g'), function ($0, $1, $2) { return isDigit($1) && isDigit($2) ? $0 : $1 + ', ' + $2; });
2229
+ }
2230
+ };
2231
+
2232
+ var reQuestionMark = new RegExp('\\?([^).…!;?\\s[\\])' + privateLabel + getData('common/quote') + '])', 'g');
2233
+ var afterQuestionMarkRule = {
2234
+ name: 'common/space/afterQuestionMark',
2235
+ handler: function (text) {
2236
+ return text.replace(reQuestionMark, '? $1');
2237
+ },
2238
+ };
2239
+
2240
+ var reExclamationMark = new RegExp('!([^).…!;?\\s[\\])' + privateLabel + getData('common/quote') + '])', 'g');
2241
+ var afterExclamationMarkRule = {
2242
+ name: 'common/space/afterExclamationMark',
2243
+ handler: function (text) {
2244
+ return text.replace(reExclamationMark, '! $1');
2245
+ },
2246
+ };
2247
+
2248
+ var reSemicolon = new RegExp(';([^).…!;?\\s[\\])' + privateLabel + getData('common/quote') + '])', 'g');
2249
+ var afterSemicolonRule = {
2250
+ name: 'common/space/afterSemicolon',
2251
+ handler: function (text) {
2252
+ return text.replace(reSemicolon, '; $1');
2253
+ },
2254
+ };
2255
+
2256
+ Typograf.addRules([
2257
+ afterColonRule,
2258
+ afterCommaRule,
2259
+ afterQuestionMarkRule,
2260
+ afterExclamationMarkRule,
2261
+ afterSemicolonRule,
2262
+ beforeBracketRule,
2263
+ bracketRule$1,
2264
+ delBeforeDotRule,
2265
+ delBeforePercentRule,
2266
+ delBeforePunctuationRule,
2267
+ delBetweenExclamationMarksRule,
2268
+ delLeadingBlanksRule,
2269
+ delRepeatNRule,
2270
+ delRepeatSpaceRule,
2271
+ delTrailingBlanksRule,
2272
+ insertFinalNewlineRule,
2273
+ replaceTabRule,
2274
+ squareBracketRule,
2275
+ trimLeftRule,
2276
+ trimRightRule,
2277
+ ]);
2278
+
2279
+ var arrowRule = {
2280
+ name: 'common/symbols/arrow',
2281
+ handler: function (text) {
2282
+ return replace(text, [
2283
+ [/(^|[^-])->(?!>)/g, '$1→'],
2284
+ [/(^|[^<])<-(?!-)/g, '$1←']
2285
+ ]);
2286
+ },
2287
+ };
2288
+
2289
+ var cfRule = {
2290
+ name: 'common/symbols/cf',
2291
+ handler: function (text) {
2292
+ var re = new RegExp('(^|[\\s(\\[+≈±−—–\\-])(\\d+(?:[.,]\\d+)?)[ \u00A0\u2009]?(C|F)([\\W\\s.,:!?")\\]]|$)', 'mg');
2293
+ return text.replace(re, '$1$2\u2009°$3$4');
2294
+ },
2295
+ };
2296
+
2297
+ var copyRule = {
2298
+ name: 'common/symbols/copy',
2299
+ handler: function (text) {
2300
+ return replace(text, [
2301
+ [/\(r\)/gi, '®'],
2302
+ [/(copyright )?\((c|с)\)/gi, '©'],
2303
+ [/\(tm\)/gi, '™']
2304
+ ]);
2305
+ },
2306
+ };
2307
+
2308
+ Typograf.addRules([
2309
+ arrowRule,
2310
+ cfRule,
2311
+ copyRule,
2312
+ ]);
2313
+
2314
+ var mainRule$1 = {
2315
+ name: 'en-US/dash/main',
2316
+ index: '-5',
2317
+ handler: function (text) {
2318
+ var dashes = getData('common/dash');
2319
+ var nonBreakingSpace = '\u00A0';
2320
+ var emDash = '\u2014';
2321
+ var spaceBefore = "[ ".concat(nonBreakingSpace, "]"); // white space or a non-breaking space
2322
+ var spaceAfter = "[ ".concat(nonBreakingSpace, "\n]"); // same as spaceBefore, but includes line break
2323
+ var re = new RegExp("".concat(spaceBefore, "(").concat(dashes, ")(").concat(spaceAfter, ")"), 'g');
2324
+ return text.replace(re, "".concat(nonBreakingSpace).concat(emDash, "$2"));
2325
+ },
2326
+ };
2327
+
2328
+ Typograf.addRules([
2329
+ mainRule$1,
2330
+ ]);
2331
+
2332
+ var centuriesRule$1 = {
2333
+ name: 'ru/dash/centuries',
2334
+ handler: function (text, settings) {
2335
+ var dashes = '(' + getData('common/dash') + ')';
2336
+ var re = new RegExp('(X|I|V)[ |\u00A0]?' + dashes + '[ |\u00A0]?(X|I|V)', 'g');
2337
+ return text.replace(re, '$1' + settings.dash + '$3');
2338
+ },
2339
+ settings: {
2340
+ dash: '\u2013', // &ndash;
2341
+ },
2342
+ };
2343
+
2344
+ var daysMonthRule = {
2345
+ name: 'ru/dash/daysMonth',
2346
+ handler: function (text, settings) {
2347
+ var re = new RegExp('(^|\\s)([123]?\\d)' +
2348
+ '(' + getData('common/dash') + ')' +
2349
+ '([123]?\\d)[ \u00A0]' +
2350
+ '(' + getData('ru/monthGenCase') + ')', 'g');
2351
+ return text.replace(re, '$1$2' + settings.dash + '$4\u00A0$5');
2352
+ },
2353
+ settings: {
2354
+ dash: '\u2013', // &ndash;
2355
+ },
2356
+ };
2357
+
2358
+ var deRule = {
2359
+ name: 'ru/dash/de',
2360
+ handler: function (text) {
2361
+ var re = new RegExp('([a-яё]+) де' + getData('ru/dashAfterDe'), 'g');
2362
+ return text.replace(re, '$1-де');
2363
+ },
2364
+ disabled: true,
2365
+ };
2366
+
2367
+ var decadeRule = {
2368
+ name: 'ru/dash/decade',
2369
+ handler: function (text, settings) {
2370
+ var re = new RegExp('(^|\\s)(\\d{3}|\\d)0' +
2371
+ '(' + getData('common/dash') + ')' +
2372
+ '(\\d{3}|\\d)0(-е[ \u00A0])' +
2373
+ '(?=г\\.?[ \u00A0]?г|год)', 'g');
2374
+ return text.replace(re, '$1$20' + settings.dash + '$40$5');
2375
+ },
2376
+ settings: {
2377
+ dash: '\u2013', // &ndash;
2378
+ },
2379
+ };
2380
+
2381
+ var directSpeechRule = {
2382
+ name: 'ru/dash/directSpeech',
2383
+ handler: function (text) {
2384
+ var dashes = getData('common/dash');
2385
+ var re1 = new RegExp("([\"\u00BB\u2018\u201C,])[ |\u00A0]?(".concat(dashes, ")[ |\u00A0]"), 'g');
2386
+ var re2 = new RegExp("(^|".concat(privateLabel, ")(").concat(dashes, ")( |\u00A0)"), 'gm');
2387
+ var re3 = new RegExp("([.\u2026?!])[ \u00A0](".concat(dashes, ")[ \u00A0]"), 'g');
2388
+ return text
2389
+ .replace(re1, '$1\u00A0\u2014 ')
2390
+ .replace(re2, '$1\u2014\u00A0')
2391
+ .replace(re3, '$1 \u2014\u00A0');
2392
+ },
2393
+ };
2394
+
2395
+ var izpodRule = {
2396
+ name: 'ru/dash/izpod',
2397
+ handler: function (text) {
2398
+ var re = new RegExp(getData('ru/dashBefore') + '(И|и)з под' + getData('ru/dashAfter'), 'g');
2399
+ return text.replace(re, '$1$2з-под');
2400
+ },
2401
+ };
2402
+
2403
+ var izzaRule = {
2404
+ name: 'ru/dash/izza',
2405
+ handler: function (text) {
2406
+ var re = new RegExp(getData('ru/dashBefore') + '(И|и)з за' + getData('ru/dashAfter'), 'g');
2407
+ return text.replace(re, '$1$2з-за');
2408
+ },
2409
+ };
2410
+
2411
+ var kaRule = {
2412
+ name: 'ru/dash/ka',
2413
+ handler: function (text) {
2414
+ var re = new RegExp('([a-яё]+) ка(сь)?' + getData('ru/dashAfter'), 'g');
2415
+ return text.replace(re, '$1-ка$2');
2416
+ },
2417
+ };
2418
+
2419
+ var koeRule = {
2420
+ name: 'ru/dash/koe',
2421
+ handler: function (text) {
2422
+ var re = new RegExp(getData('ru/dashBefore') +
2423
+ '([Кк]о[ей])\\s([а-яё]{3,})' +
2424
+ getData('ru/dashAfter'), 'g');
2425
+ return text.replace(re, '$1$2-$3');
2426
+ },
2427
+ };
2428
+
2429
+ var mainRule = {
2430
+ name: 'ru/dash/main',
2431
+ index: '-5',
2432
+ handler: function (text) {
2433
+ var dashes = getData('common/dash');
2434
+ var re = new RegExp('([ \u00A0])(' + dashes + ')([ \u00A0\\n])', 'g');
2435
+ return text.replace(re, '\u00A0\u2014$3');
2436
+ },
2437
+ };
2438
+
2439
+ var monthRule = {
2440
+ name: 'ru/dash/month',
2441
+ handler: function (text, settings) {
2442
+ var months = '(' + getData('ru/month') + ')';
2443
+ var monthsPre = '(' + getData('ru/monthPreCase') + ')';
2444
+ var dashes = getData('common/dash');
2445
+ var re = new RegExp(months + ' ?(' + dashes + ') ?' + months, 'gi');
2446
+ var rePre = new RegExp(monthsPre + ' ?(' + dashes + ') ?' + monthsPre, 'gi');
2447
+ var newSubStr = '$1' + settings.dash + '$3';
2448
+ return text
2449
+ .replace(re, newSubStr)
2450
+ .replace(rePre, newSubStr);
2451
+ },
2452
+ settings: {
2453
+ dash: '\u2013', // &ndash;
2454
+ },
2455
+ };
2456
+
2457
+ var surnameRule = {
2458
+ name: 'ru/dash/surname',
2459
+ handler: function (text) {
2460
+ var re = new RegExp('([А-ЯЁ][а-яё]+)\\s-([а-яё]{1,3})(?![^а-яё]|$)', 'g');
2461
+ return text.replace(re, '$1\u00A0\u2014$2');
2462
+ },
2463
+ };
2464
+
2465
+ var takiRule = {
2466
+ name: 'ru/dash/taki',
2467
+ handler: function (text) {
2468
+ var re = new RegExp('(верно|довольно|опять|прямо|так|вс[её]|действительно|неужели)\\s(таки)' +
2469
+ getData('ru/dashAfter'), 'g');
2470
+ return text.replace(re, '$1-$2');
2471
+ },
2472
+ };
2473
+
2474
+ var timeRule = {
2475
+ name: 'ru/dash/time',
2476
+ handler: function (text, settings) {
2477
+ var re = new RegExp(getData('ru/dashBefore') +
2478
+ '(\\d?\\d:[0-5]\\d)' +
2479
+ getData('common/dash') +
2480
+ '(\\d?\\d:[0-5]\\d)' +
2481
+ getData('ru/dashAfter'), 'g');
2482
+ return text.replace(re, '$1$2' + settings.dash + '$3');
2483
+ },
2484
+ settings: {
2485
+ dash: '\u2013', // &ndash;
2486
+ },
2487
+ };
2488
+
2489
+ var toRule = {
2490
+ name: 'ru/dash/to',
2491
+ handler: function (text) {
2492
+ var words = '[Оо]ткуда|[Кк]уда|[Гг]де|[Кк]огда|[Зз]ачем|[Пп]очему|[Кк]ак|[Кк]ако[ейм]|[Кк]акая|[Кк]аки[емх]|[Кк]акими|[Кк]акую|[Чч]то|[Чч]его|[Чч]е[йм]|[Чч]ьим?|[Кк]то|[Кк]ого|[Кк]ому|[Кк]ем';
2493
+ var re = new RegExp('(^|[^А-ЯЁа-яё\\w])(' + words + ')( | -|- )(то|либо|нибудь)' +
2494
+ getData('ru/dashAfter'), 'g');
2495
+ return text.replace(re, function ($0, $1, $2, $3, $4) {
2496
+ var kakto = $2 + $3 + $4;
2497
+ // Отдельно обрабатываем в ru/dash/kakto
2498
+ if (kakto === 'как то' || kakto === 'Как то') {
2499
+ return $0;
2500
+ }
2501
+ return $1 + $2 + '-' + $4;
2502
+ });
2503
+ },
2504
+ };
2505
+
2506
+ var kaktoRule = {
2507
+ name: 'ru/dash/kakto',
2508
+ handler: function (text) {
2509
+ var re = new RegExp('(^|[^А-ЯЁа-яё\\w])([Кк]ак) то' + getData('ru/dashAfter'), 'g');
2510
+ return text.replace(re, '$1$2-то');
2511
+ },
2512
+ };
2513
+
2514
+ var weekdayRule$1 = {
2515
+ name: 'ru/dash/weekday',
2516
+ handler: function (text, settings) {
2517
+ var part = '(' + getData('ru/weekday') + ')';
2518
+ var re = new RegExp(part + ' ?(' + getData('common/dash') + ') ?' + part, 'gi');
2519
+ return text.replace(re, '$1' + settings.dash + '$3');
2520
+ },
2521
+ settings: {
2522
+ dash: '\u2013', // &ndash;
2523
+ },
2524
+ };
2525
+
2526
+ var yearsRule$1 = {
2527
+ name: 'ru/dash/years',
2528
+ handler: function (text, settings) {
2529
+ var dashes = getData('common/dash');
2530
+ var re = new RegExp('(\\D|^)(\\d{4})[ \u00A0]?(' +
2531
+ dashes + ')[ \u00A0]?(\\d{4})(?=[ \u00A0]?г)', 'g');
2532
+ return text.replace(re, function ($0, $1, $2, $3, $4) {
2533
+ if (parseInt($2, 10) < parseInt($4, 10)) {
2534
+ return $1 + $2 + settings.dash + $4;
2535
+ }
2536
+ return $0;
2537
+ });
2538
+ },
2539
+ settings: {
2540
+ dash: '\u2013', // &ndash;
2541
+ },
2542
+ };
2543
+
2544
+ Typograf.addRules([
2545
+ centuriesRule$1,
2546
+ daysMonthRule,
2547
+ deRule,
2548
+ decadeRule,
2549
+ directSpeechRule,
2550
+ izpodRule,
2551
+ izzaRule,
2552
+ kaRule,
2553
+ koeRule,
2554
+ mainRule,
2555
+ monthRule,
2556
+ surnameRule,
2557
+ takiRule,
2558
+ timeRule,
2559
+ toRule,
2560
+ kaktoRule,
2561
+ weekdayRule$1,
2562
+ yearsRule$1,
2563
+ ]);
2564
+
2565
+ var sp1 = '(-|\\.|\\/)';
2566
+ var sp2 = '(-|\\/)';
2567
+ var re1 = new RegExp('(^|\\D)(\\d{4})' + sp1 + '(\\d{2})' + sp1 + '(\\d{2})(\\D|$)', 'gi');
2568
+ var re2 = new RegExp('(^|\\D)(\\d{2})' + sp2 + '(\\d{2})' + sp2 + '(\\d{4})(\\D|$)', 'gi');
2569
+ var fromISORule = {
2570
+ name: 'ru/date/fromISO',
2571
+ handler: function (text) {
2572
+ return text
2573
+ .replace(re1, '$1$6.$4.$2$7')
2574
+ .replace(re2, '$1$4.$2.$6$7');
2575
+ },
2576
+ };
2577
+
2578
+ var weekdayRule = {
2579
+ name: 'ru/date/weekday',
2580
+ handler: function (text) {
2581
+ var space = '( |\u00A0)';
2582
+ var monthCase = getData('ru/monthGenCase');
2583
+ var weekday = getData('ru/weekday');
2584
+ var re = new RegExp('(\\d)' + space + '(' + monthCase + '),' + space + '(' + weekday + ')', 'gi');
2585
+ return text.replace(re, function (_, $1, $2, $3, $4, $5) {
2586
+ return $1 + $2 + $3.toLowerCase() + ',' + $4 + $5.toLowerCase();
2587
+ });
2588
+ },
2589
+ };
2590
+
2591
+ Typograf.addRules([
2592
+ fromISORule,
2593
+ weekdayRule,
2594
+ ]);
2595
+
2596
+ var currencyRule = {
2597
+ name: 'ru/money/currency',
2598
+ handler: function (text) {
2599
+ var currency = '([$€¥Ұ£₤₽])';
2600
+ var space = '[ \u00A0\u2009\u202F]';
2601
+ var re1 = new RegExp('(^|[\\D]{2})' + currency + ' ?(' + regExpNumber + '(' + space + '\\d{3})*)(' + space + '?(тыс\\.|млн|млрд|трлн))?', 'gm');
2602
+ var re2 = new RegExp('(^|[\\D])(' + regExpNumber + ') ?' + currency, 'gm');
2603
+ return text
2604
+ .replace(re1, function ($0, $1, $2, $3, $4, $5, $6, $7) {
2605
+ return $1 + $3 + ($7 ? '\u00A0' + $7 : '') + '\u00A0' + $2;
2606
+ })
2607
+ .replace(re2, '$1$2\u00A0$4');
2608
+ },
2609
+ disabled: true,
2610
+ };
2611
+
2612
+ var rubleRule = {
2613
+ name: 'ru/money/ruble',
2614
+ handler: function (text) {
2615
+ var newSubstr = '$1\u00A0₽';
2616
+ var commonPart = '(\\d+)( |\u00A0)?(р|руб)\\.';
2617
+ var re1 = new RegExp('^' + commonPart + '$', 'g');
2618
+ var re2 = new RegExp(commonPart + '(?=[!?,:;])', 'g');
2619
+ var re3 = new RegExp(commonPart + '(?=\\s+[A-ЯЁ])', 'g');
2620
+ return text
2621
+ .replace(re1, newSubstr)
2622
+ .replace(re2, newSubstr)
2623
+ .replace(re3, newSubstr + '.');
2624
+ },
2625
+ disabled: true,
2626
+ };
2627
+
2628
+ Typograf.addRules([
2629
+ currencyRule,
2630
+ rubleRule,
2631
+ ]);
2632
+
2633
+ function abbr($0, $1, $2, $3) {
2634
+ // дд.мм.гггг
2635
+ if ($2 === 'дд' && $3 === 'мм') {
2636
+ return $0;
2637
+ }
2638
+ // Являются ли сокращения ссылкой
2639
+ if (['рф', 'ру', 'рус', 'орг', 'укр', 'бг', 'срб'].indexOf($3) > -1) {
2640
+ return $0;
2641
+ }
2642
+ return $1 + $2 + '.' + '\u00A0' + $3 + '.';
2643
+ }
2644
+ var abbrRule = {
2645
+ name: 'ru/nbsp/abbr',
2646
+ handler: function (text) {
2647
+ var re = new RegExp("(^|\\s|".concat(privateLabel, ")([\u0430-\u044F\u0451]{1,3})\\. ?([\u0430-\u044F\u0451]{1,3})\\."), 'g');
2648
+ return text
2649
+ .replace(re, abbr)
2650
+ // Для тройных сокращений - а.е.м.
2651
+ .replace(re, abbr);
2652
+ },
2653
+ };
2654
+
2655
+ var addrRule = {
2656
+ name: 'ru/nbsp/addr',
2657
+ handler: function (text) {
2658
+ return text
2659
+ .replace(/(\s|^)(дом|д\.|кв\.|под\.|п-д) *(\d+)/gi, '$1$2\u00A0$3')
2660
+ .replace(/(\s|^)(мкр-н|мк-н|мкр\.|мкрн)\s/gi, '$1$2\u00A0') // микрорайон
2661
+ .replace(/(\s|^)(эт\.) *(-?\d+)/gi, '$1$2\u00A0$3')
2662
+ .replace(/(\s|^)(\d+) +этаж([^а-яё]|$)/gi, '$1$2\u00A0этаж$3')
2663
+ .replace(/(\s|^)литер\s([А-Я]|$)/gi, '$1литер\u00A0$2')
2664
+ /*
2665
+ область, край, станция, поселок, село,
2666
+ деревня, улица, переулок, проезд, проспект,
2667
+ бульвар, площадь, набережная, шоссе,
2668
+ тупик, офис, комната, участок, владение, строение, корпус
2669
+ */
2670
+ .replace(/(\s|^)(обл|кр|ст|пос|с|д|ул|пер|пр|пр-т|просп|пл|бул|б-р|наб|ш|туп|оф|комн?|уч|вл|влад|стр|кор)\. *([а-яёa-z\d]+)/gi, '$1$2.\u00A0$3')
2671
+ // город
2672
+ .replace(/(\D[ \u00A0]|^)г\. ?([А-ЯЁ])/gm, '$1г.\u00A0$2');
2673
+ },
2674
+ };
2675
+
2676
+ var afterNumberSignRule = {
2677
+ name: 'ru/nbsp/afterNumberSign',
2678
+ handler: function (text) {
2679
+ // \u2009 - THIN SPACE
2680
+ // \u202F - NARROW NO-BREAK SPACE
2681
+ return text.replace(/№[ \u00A0\u2009]?(\d|п\/п)/g, '№\u202F$1');
2682
+ },
2683
+ };
2684
+
2685
+ var beforeParticleRule = {
2686
+ name: 'ru/nbsp/beforeParticle',
2687
+ index: '+5',
2688
+ handler: function (text) {
2689
+ var particles = '(ли|ль|же|ж|бы|б)';
2690
+ var re1 = new RegExp('([А-ЯЁа-яё]) ' + particles + '(?=[,;:?!"‘“»])', 'g');
2691
+ var re2 = new RegExp('([А-ЯЁа-яё])[ \u00A0]' + particles + '[ \u00A0]', 'g');
2692
+ return text
2693
+ .replace(re1, '$1\u00A0$2')
2694
+ .replace(re2, '$1\u00A0$2 ');
2695
+ },
2696
+ };
2697
+
2698
+ var centuriesRule = {
2699
+ name: 'ru/nbsp/centuries',
2700
+ handler: function (text) {
2701
+ var dashes = getData('common/dash');
2702
+ var before = '(^|\\s)([VIX]+)';
2703
+ var after = '(?=[,;:?!"‘“»]|$)';
2704
+ var re1 = new RegExp(before + '[ \u00A0]?в\\.?' + after, 'gm');
2705
+ var re2 = new RegExp(before + '(' + dashes + ')' + '([VIX]+)[ \u00A0]?в\\.?([ \u00A0]?в\\.?)?' + after, 'gm');
2706
+ return text
2707
+ .replace(re1, '$1$2\u00A0в.')
2708
+ .replace(re2, '$1$2$3$4\u00A0вв.');
2709
+ },
2710
+ };
2711
+
2712
+ var dayMonthRule = {
2713
+ name: 'ru/nbsp/dayMonth',
2714
+ handler: function (text) {
2715
+ var re = new RegExp('(\\d{1,2}) (' + getData('ru/shortMonth') + ')', 'gi');
2716
+ return text.replace(re, '$1\u00A0$2');
2717
+ },
2718
+ };
2719
+
2720
+ var initialsRule = {
2721
+ name: 'ru/nbsp/initials',
2722
+ handler: function (text) {
2723
+ var spaces = '\u00A0\u202F '; // nbsp, thinsp
2724
+ var quote = getData('ru/quote');
2725
+ var re = new RegExp('(^|[' + spaces +
2726
+ quote.left +
2727
+ privateLabel +
2728
+ '"])([А-ЯЁ])\\.[' + spaces + ']?([А-ЯЁ])\\.[' + spaces +
2729
+ ']?([А-ЯЁ][а-яё]+)', 'gm');
2730
+ return text.replace(re, '$1$2.\u00A0$3.\u00A0$4');
2731
+ },
2732
+ };
2733
+
2734
+ var pow = {
2735
+ '2': '²',
2736
+ '²': '²',
2737
+ '3': '³',
2738
+ '³': '³',
2739
+ '': ''
2740
+ };
2741
+ var mRule = {
2742
+ name: 'ru/nbsp/m',
2743
+ index: '+5',
2744
+ handler: function (text) {
2745
+ var re = new RegExp('(^|[\\s,.\\(' + privateLabel + '])' +
2746
+ '(\\d+)[ \u00A0]?(мм?|см|км|дм|гм|mm?|km|cm|dm)([23²³])?([\\s\\).!?,;' +
2747
+ privateLabel + ']|$)', 'gm');
2748
+ return text.replace(re, function (_$0, $1, $2, $3, $4, $5) {
2749
+ return $1 + $2 + '\u00A0' + $3 + pow[$4 || ''] + ($5 === '\u00A0' ? ' ' : $5);
2750
+ });
2751
+ },
2752
+ };
2753
+
2754
+ var mlnRule = {
2755
+ name: 'ru/nbsp/mln',
2756
+ handler: function (text) {
2757
+ return text.replace(/(\d) ?(тыс|млн|млрд|трлн)(\.|\s|$)/gi, '$1\u00a0$2$3');
2758
+ },
2759
+ };
2760
+
2761
+ var oooRule = {
2762
+ name: 'ru/nbsp/ooo',
2763
+ handler: function (text) {
2764
+ return text.replace(/(^|[^a-яёA-ЯЁ])(ООО|ОАО|ЗАО|НИИ|ПБОЮЛ) /g, '$1$2\u00A0');
2765
+ },
2766
+ };
2767
+
2768
+ var pageRule = {
2769
+ name: 'ru/nbsp/page',
2770
+ handler: function (text) {
2771
+ var re = new RegExp('(^|[)\\s' + privateLabel + '])' +
2772
+ '(стр|гл|рис|илл?|ст|п|c)\\. *(\\d+)([\\s.,?!;:]|$)', 'gim');
2773
+ return text.replace(re, '$1$2.\u00A0$3$4');
2774
+ },
2775
+ };
2776
+
2777
+ var psRule = {
2778
+ name: 'ru/nbsp/ps',
2779
+ handler: function (text) {
2780
+ var re = new RegExp("(^|\\s|".concat(privateLabel, ")[p\u0437]\\.[ \u00A0]?([p\u0437]\\.[ \u00A0]?)?[s\u044B]\\.:? "), 'gim');
2781
+ return text.replace(re, function ($0, $1, $2) {
2782
+ return $1 + ($2 ? 'P.\u00A0P.\u00A0S. ' : 'P.\u00A0S. ');
2783
+ });
2784
+ },
2785
+ };
2786
+
2787
+ var rubleKopekRule = {
2788
+ name: 'ru/nbsp/rubleKopek',
2789
+ handler: function (text) {
2790
+ return text.replace(/(\d) ?(?=(руб|коп)\.)/g, '$1\u00A0');
2791
+ },
2792
+ };
2793
+
2794
+ var seeRule = {
2795
+ name: 'ru/nbsp/see',
2796
+ handler: function (text) {
2797
+ var re = new RegExp("(^|\\s|".concat(privateLabel, "|\\()(\u0441\u043C|\u0438\u043C)\\.[ \u00A0]?([\u0430-\u044F\u04510-9a-z]+)([\\s.,?!]|$)"), 'gi');
2798
+ return text.replace(re, function ($0, $1, $2, $3, $4) {
2799
+ return ($1 === '\u00A0' ? ' ' : $1) + $2 + '.\u00A0' + $3 + $4;
2800
+ });
2801
+ },
2802
+ };
2803
+
2804
+ var yearRule$1 = {
2805
+ name: 'ru/nbsp/year',
2806
+ handler: function (text) {
2807
+ return text.replace(/(^|\D)(\d{4}) ?г([ ,;.\n]|$)/g, '$1$2\u00A0г$3');
2808
+ },
2809
+ };
2810
+
2811
+ var yearsRule = {
2812
+ name: 'ru/nbsp/years',
2813
+ index: '+5',
2814
+ handler: function (text) {
2815
+ var dashes = getData('common/dash');
2816
+ var re = new RegExp('(^|\\D)(\\d{4})(' +
2817
+ dashes + ')(\\d{4})[ \u00A0]?г\\.?([ \u00A0]?г\\.)?(?=[,;:?!"‘“»\\s]|$)', 'gm');
2818
+ return text.replace(re, '$1$2$3$4\u00A0гг.');
2819
+ },
2820
+ };
2821
+
2822
+ Typograf.addRules([
2823
+ abbrRule,
2824
+ addrRule,
2825
+ afterNumberSignRule,
2826
+ beforeParticleRule,
2827
+ centuriesRule,
2828
+ dayMonthRule,
2829
+ initialsRule,
2830
+ mRule,
2831
+ mlnRule,
2832
+ oooRule,
2833
+ pageRule,
2834
+ psRule,
2835
+ rubleKopekRule,
2836
+ seeRule,
2837
+ yearRule$1,
2838
+ yearsRule,
2839
+ ]);
2840
+
2841
+ var commaRule$1 = {
2842
+ name: 'ru/number/comma',
2843
+ handler: function (text) {
2844
+ // \u00A0 - NO-BREAK SPACE
2845
+ // \u2009 - THIN SPACE
2846
+ // \u202F - NARROW NO-BREAK SPACE
2847
+ return text.replace(/(^|\s)(\d+)\.(\d+[\u00A0\u2009\u202F ]*?[%‰°×x])/gim, '$1$2,$3');
2848
+ },
2849
+ };
2850
+
2851
+ var ordinalsRule = {
2852
+ name: 'ru/number/ordinals',
2853
+ handler: function (text, _settings, context) {
2854
+ var char = context.getData('char');
2855
+ var re = new RegExp('(\\d[%‰]?)-(ый|ой|ая|ое|ые|ым|ом|ых|ого|ому|ыми)(?![' + char + '])', 'g');
2856
+ return text.replace(re, function ($0, $1, $2) {
2857
+ var parts = {
2858
+ 'ой': 'й',
2859
+ 'ый': 'й',
2860
+ 'ая': 'я',
2861
+ 'ое': 'е',
2862
+ 'ые': 'е',
2863
+ 'ым': 'м',
2864
+ 'ом': 'м',
2865
+ 'ых': 'х',
2866
+ 'ого': 'го',
2867
+ 'ому': 'му',
2868
+ 'ыми': 'ми',
2869
+ };
2870
+ return $1 + '-' + parts[$2];
2871
+ });
2872
+ },
2873
+ };
2874
+
2875
+ Typograf.addRules([
2876
+ commaRule$1,
2877
+ ordinalsRule,
2878
+ ]);
2879
+
2880
+ function removeOptAlignTags(text, classNames) {
2881
+ var re = new RegExp('<span class="(' + classNames.join('|') + ')">([^]*?)</span>', 'g');
2882
+ return text.replace(re, '$2');
2883
+ }
2884
+ function removeOptAlignTagsFromTitle(text, classNames) {
2885
+ return text.replace(/<title>[^]*?<\/title>/i, function (text) {
2886
+ return removeOptAlignTags(text, classNames);
2887
+ });
2888
+ }
2889
+
2890
+ var classNames$2 = [
2891
+ 'typograf-oa-lbracket',
2892
+ 'typograf-oa-n-lbracket',
2893
+ 'typograf-oa-sp-lbracket'
2894
+ ];
2895
+ var name$2 = 'ru/optalign/bracket';
2896
+ var bracketRule = {
2897
+ name: name$2,
2898
+ handler: function (text) {
2899
+ return text
2900
+ .replace(/( |\u00A0)\(/g, '<span class="typograf-oa-sp-lbracket">$1</span><span class="typograf-oa-lbracket">(</span>')
2901
+ .replace(/^\(/gm, '<span class="typograf-oa-n-lbracket">(</span>');
2902
+ },
2903
+ disabled: true,
2904
+ htmlAttrs: false,
2905
+ };
2906
+ var innerStartBracketRule = {
2907
+ name: name$2,
2908
+ queue: 'start',
2909
+ handler: function (text) {
2910
+ return removeOptAlignTags(text, classNames$2);
2911
+ },
2912
+ htmlAttrs: false,
2913
+ };
2914
+ var innerEndBracketRule = {
2915
+ name: name$2,
2916
+ queue: 'end',
2917
+ handler: function (text) {
2918
+ return removeOptAlignTagsFromTitle(text, classNames$2);
2919
+ },
2920
+ htmlAttrs: false,
2921
+ };
2922
+
2923
+ var classNames$1 = [
2924
+ 'typograf-oa-comma',
2925
+ 'typograf-oa-comma-sp',
2926
+ ];
2927
+ var name$1 = 'ru/optalign/comma';
2928
+ var commaRule = {
2929
+ name: name$1,
2930
+ handler: function (text, _settings, context) {
2931
+ var char = context.getData('char');
2932
+ var re = new RegExp('([' + char + '\\d\u0301]+), ', 'gi');
2933
+ return text.replace(re, '$1<span class="typograf-oa-comma">,</span><span class="typograf-oa-comma-sp"> </span>');
2934
+ },
2935
+ disabled: true,
2936
+ htmlAttrs: false,
2937
+ };
2938
+ var innerStartCommaRule = {
2939
+ name: name$1,
2940
+ queue: 'start',
2941
+ handler: function (text) {
2942
+ return removeOptAlignTags(text, classNames$1);
2943
+ },
2944
+ htmlAttrs: false,
2945
+ };
2946
+ var innerEndCommaRule = {
2947
+ name: name$1,
2948
+ queue: 'end',
2949
+ handler: function (text) {
2950
+ return removeOptAlignTagsFromTitle(text, classNames$1);
2951
+ },
2952
+ htmlAttrs: false,
2953
+ };
2954
+
2955
+ var classNames = [
2956
+ 'typograf-oa-lquote',
2957
+ 'typograf-oa-n-lquote',
2958
+ 'typograf-oa-sp-lquote'
2959
+ ];
2960
+ var name = 'ru/optalign/quote';
2961
+ var quoteRule = {
2962
+ name: name,
2963
+ handler: function (text) {
2964
+ var quote = this.getSetting('common/punctuation/quote', 'ru');
2965
+ var lquotes = '([' + quote.left[0] + (quote.left[1] || '') + '])';
2966
+ var reNewLine = new RegExp('(^|\n\n|' + privateLabel + ')(' + lquotes + ')', 'g');
2967
+ var reInside = new RegExp('([^\n' + privateLabel + '])([ \u00A0\n])(' + lquotes + ')', 'gi');
2968
+ return text
2969
+ .replace(reNewLine, '$1<span class="typograf-oa-n-lquote">$2</span>')
2970
+ .replace(reInside, '$1<span class="typograf-oa-sp-lquote">$2</span><span class="typograf-oa-lquote">$3</span>');
2971
+ },
2972
+ disabled: true,
2973
+ htmlAttrs: false,
2974
+ };
2975
+ var innerStartQuoteRule = {
2976
+ name: name,
2977
+ queue: 'start',
2978
+ handler: function (text) {
2979
+ return removeOptAlignTags(text, classNames);
2980
+ },
2981
+ htmlAttrs: false,
2982
+ };
2983
+ var innerEndQuoteRule = {
2984
+ name: name,
2985
+ queue: 'end',
2986
+ handler: function (text) {
2987
+ return removeOptAlignTagsFromTitle(text, classNames);
2988
+ },
2989
+ htmlAttrs: false,
2990
+ };
2991
+
2992
+ Typograf.addRules([
2993
+ bracketRule,
2994
+ commaRule,
2995
+ quoteRule,
2996
+ ]);
2997
+ Typograf.addInnerRules([
2998
+ innerStartBracketRule,
2999
+ innerEndBracketRule,
3000
+ innerStartCommaRule,
3001
+ innerEndCommaRule,
3002
+ innerStartQuoteRule,
3003
+ innerEndQuoteRule,
3004
+ ]);
3005
+
3006
+ var accentRule = {
3007
+ name: 'ru/other/accent',
3008
+ handler: function (text) {
3009
+ return text.replace(/([а-яё])([АЕЁИОУЫЭЮЯ])([^А-ЯЁ\w]|$)/g, function ($0, $1, $2, $3) {
3010
+ return $1 + $2.toLowerCase() + '\u0301' + $3;
3011
+ });
3012
+ },
3013
+ disabled: true,
3014
+ };
3015
+
3016
+ var defaultCityCodeLength = 5;
3017
+ var countryCode = '7';
3018
+ var exceptions = [];
3019
+ var exceptionsMax = 8;
3020
+ var exceptionsMin = 2;
3021
+ [
3022
+ 4162, 416332, 8512, 851111, 4722, 4725, 391379, 8442, 4732,
3023
+ 4152, 4154451, 4154459, 4154455, 41544513, 8142, 8332, 8612,
3024
+ 8622, 3525, 812, 8342, 8152, 3812, 4862, 3422, 342633, 8112,
3025
+ 9142, 8452, 3432, 3434, 3435, 4812, 8432, 8439, 3822,
3026
+ 4872, 3412, 3511, 3512, 3022, 4112, 4852, 4855, 3852, 3854,
3027
+ 8182, 818, 90, 3472, 4741, 4764, 4832, 4922, 8172, 8202, 8722,
3028
+ 4932, 493, 3952, 3951, 3953, 411533, 4842, 3842, 3843, 8212,
3029
+ 4942, '39131-39179', '39190-39199', 391, 4712, 4742, 8362, 495, 499, 4966, 4964, 4967, 498,
3030
+ 8312, 8313, 3832, 383612, 3532, 8412, 4232, 423370, 423630, 8632,
3031
+ 8642, 8482, 4242, 8672, 8652, 4752, 4822, 482502, 4826300, 3452,
3032
+ 8422, 4212, 3466, 3462, 8712, 8352,
3033
+ '901-934', '936-939', '950-953', 958, '960-969',
3034
+ '977-989', '991-997', 999
3035
+ ].forEach(function (num) {
3036
+ if (typeof num === 'string') {
3037
+ var buf = num.split('-');
3038
+ for (var i = +buf[0]; i <= +buf[1]; i++) {
3039
+ exceptions.push(i);
3040
+ }
3041
+ }
3042
+ else {
3043
+ exceptions.push(num);
3044
+ }
3045
+ });
3046
+ function phone(num) {
3047
+ var firstSym = num[0];
3048
+ var cityCode = '';
3049
+ var hasPlusWithCode;
3050
+ var hasEight;
3051
+ if (num.length < 8) {
3052
+ return phoneBlocks(num);
3053
+ }
3054
+ // 8 495 123-45-67, +7 495 123-45-67
3055
+ if (num.length > 10) {
3056
+ if (firstSym === '+') {
3057
+ if (num[1] === countryCode) {
3058
+ hasPlusWithCode = true;
3059
+ num = num.substr(2);
3060
+ }
3061
+ else {
3062
+ return num;
3063
+ }
3064
+ }
3065
+ else if (firstSym === '8') {
3066
+ hasEight = true;
3067
+ num = num.substr(1);
3068
+ }
3069
+ }
3070
+ for (var cityCodeLen = exceptionsMax; cityCodeLen >= exceptionsMin; cityCodeLen--) {
3071
+ var code = +num.substr(0, cityCodeLen);
3072
+ if (exceptions.indexOf(code) > -1) {
3073
+ cityCode = num.substr(0, cityCodeLen);
3074
+ num = num.substr(cityCodeLen);
3075
+ break;
3076
+ }
3077
+ }
3078
+ if (!cityCode) {
3079
+ cityCode = num.substr(0, defaultCityCodeLength);
3080
+ num = num.substr(defaultCityCodeLength);
3081
+ }
3082
+ return (hasPlusWithCode ? '+' + countryCode + '\u00A0' : '') +
3083
+ (hasEight ? '8\u00A0' : '') +
3084
+ prepareCode(cityCode) + '\u00A0' +
3085
+ phoneBlocks(num);
3086
+ }
3087
+ function prepareCode(code) {
3088
+ var numCode = +code;
3089
+ var len = code.length;
3090
+ var result = [code];
3091
+ var withoutBrackets = false;
3092
+ if (len > 3) {
3093
+ switch (len) {
3094
+ case 4:
3095
+ result = [code.substr(0, 2), code.substr(2, 2)];
3096
+ break;
3097
+ case 5:
3098
+ result = [code.substr(0, 3), code.substr(3, 3)];
3099
+ break;
3100
+ case 6:
3101
+ result = [code.substr(0, 2), code.substr(2, 2), code.substr(4, 2)];
3102
+ break;
3103
+ }
3104
+ }
3105
+ else {
3106
+ // Мобильные и московские номера без скобок
3107
+ withoutBrackets = (numCode > 900 && numCode <= 999) || numCode === 495 || numCode === 499;
3108
+ }
3109
+ var str = result.join('-');
3110
+ return withoutBrackets ? str : '(' + str + ')';
3111
+ }
3112
+ function phoneBlocks(num) {
3113
+ var add = '';
3114
+ if (num.length % 2) {
3115
+ add = num[0];
3116
+ add += num.length <= 5 ? '-' : '';
3117
+ num = num.substr(1, num.length - 1);
3118
+ }
3119
+ return add + num.split(/(?=(?:\d\d)+$)/).join('-');
3120
+ }
3121
+ function clearPhone(text) {
3122
+ return text.replace(/[^\d+]/g, '');
3123
+ }
3124
+ var phoneNumberRule = {
3125
+ name: 'ru/other/phone-number',
3126
+ live: false,
3127
+ handler: function (text) {
3128
+ var re = new RegExp('(^|,| |' + privateLabel + ')(\\+7[\\d\\(\\) \u00A0-]{10,18})(?=,|;|' + privateLabel + '|$)', 'gm');
3129
+ return text
3130
+ .replace(re, function ($0, $1, $2) {
3131
+ var buf = clearPhone($2);
3132
+ return buf.length === 12 ? $1 + phone(buf) : $0;
3133
+ })
3134
+ .replace(
3135
+ // eslint-disable-next-line no-misleading-character-class
3136
+ /(^|[^а-яё])([☎☏✆📠📞📱]|т\.|тел\.|ф\.|моб\.|факс|сотовый|мобильный|телефон)(:?\s*?)([+\d(][\d \u00A0\-()]{3,}\d)/gi, function ($0, $1, $2, $3, $4) {
3137
+ var buf = clearPhone($4);
3138
+ if (buf.length >= 5) {
3139
+ return $1 + $2 + $3 + phone(buf);
3140
+ }
3141
+ return $0;
3142
+ });
3143
+ },
3144
+ };
3145
+
3146
+ Typograf.addRules([
3147
+ accentRule,
3148
+ phoneNumberRule,
3149
+ ]);
3150
+
3151
+ var anoRule = {
3152
+ name: 'ru/punctuation/ano',
3153
+ handler: function (text) {
3154
+ var re = new RegExp('([^«„[(!?,:;\\-‒–—\\s' + privateLabel + '])(\\s+)(а|но)(?= |\u00A0|\\n)', 'g');
3155
+ return text.replace(re, '$1,$2$3');
3156
+ },
3157
+ };
3158
+
3159
+ var exclamationRule = {
3160
+ name: 'ru/punctuation/exclamation',
3161
+ handler: function (text) {
3162
+ return text
3163
+ .replace(/(^|[^!])!{2}($|[^!])/gm, '$1!$2')
3164
+ .replace(/(^|[^!])!{4}($|[^!])/gm, '$1!!!$2');
3165
+ },
3166
+ live: false,
3167
+ };
3168
+
3169
+ var exclamationQuestionRule = {
3170
+ name: 'ru/punctuation/exclamationQuestion',
3171
+ index: '+5',
3172
+ handler: function (text) {
3173
+ var re = new RegExp('(^|[^!])!\\?([^?]|$)', 'g');
3174
+ return text.replace(re, '$1?!$2');
3175
+ },
3176
+ };
3177
+
3178
+ var hellipQuestionRule = {
3179
+ name: 'ru/punctuation/hellipQuestion',
3180
+ handler: function (text) {
3181
+ return text
3182
+ .replace(/(^|[^.])(\.\.\.|…),/g, '$1…')
3183
+ .replace(/(!|\?)(\.\.\.|…)(?=[^.]|$)/g, '$1..');
3184
+ },
3185
+ };
3186
+
3187
+ Typograf.addRules([
3188
+ anoRule,
3189
+ exclamationRule,
3190
+ exclamationQuestionRule,
3191
+ hellipQuestionRule,
3192
+ ]);
3193
+
3194
+ var afterHellipRule = {
3195
+ name: 'ru/space/afterHellip',
3196
+ handler: function (text) {
3197
+ return text
3198
+ .replace(/([а-яё])(\.\.\.|…)([А-ЯЁ])/g, '$1$2 $3')
3199
+ .replace(/([?!]\.\.)([а-яёa-z])/gi, '$1 $2');
3200
+ },
3201
+ };
3202
+
3203
+ var yearRule = {
3204
+ name: 'ru/space/year',
3205
+ handler: function (text, _settings, context) {
3206
+ var char = context.getData('char');
3207
+ var re = new RegExp('(^| |\u00A0)(\\d{3,4})(год([ауе]|ом)?)([^' +
3208
+ char + ']|$)', 'g');
3209
+ return text.replace(re, '$1$2 $3$5');
3210
+ }
3211
+ };
3212
+
3213
+ Typograf.addRules([
3214
+ afterHellipRule,
3215
+ yearRule,
3216
+ ]);
3217
+
3218
+ var nnRule = {
3219
+ name: 'ru/symbols/NN',
3220
+ handler: function (text) {
3221
+ return text.replace(/№№/g, '№');
3222
+ },
3223
+ };
3224
+
3225
+ Typograf.addRules([
3226
+ nnRule,
3227
+ ]);
3228
+
3229
+ var replacements = {
3230
+ A: 'А',
3231
+ a: 'а',
3232
+ B: 'В',
3233
+ E: 'Е',
3234
+ e: 'е',
3235
+ K: 'К',
3236
+ M: 'М',
3237
+ H: 'Н',
3238
+ O: 'О',
3239
+ o: 'о',
3240
+ P: 'Р',
3241
+ p: 'р',
3242
+ C: 'С',
3243
+ c: 'с',
3244
+ T: 'Т',
3245
+ y: 'у',
3246
+ X: 'Х',
3247
+ x: 'х'
3248
+ };
3249
+ var keys = Object.keys(replacements).join('');
3250
+ var switchingKeyboardLayoutRule = {
3251
+ name: 'ru/typo/switchingKeyboardLayout',
3252
+ handler: function (text) {
3253
+ var re = new RegExp('([' + keys + ']{1,3})(?=[А-ЯЁа-яё]+?)', 'g');
3254
+ return text.replace(re, function (str, $1) {
3255
+ var result = '';
3256
+ for (var i = 0; i < $1.length; i++) {
3257
+ result += replacements[$1[i]];
3258
+ }
3259
+ return result;
3260
+ });
3261
+ }
3262
+ };
3263
+
3264
+ Typograf.addRules([
3265
+ switchingKeyboardLayoutRule,
3266
+ ]);
3267
+
3268
+ export { Typograf as default };