You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

381 lines
15 KiB

1 year ago
  1. /******/ (function() { // webpackBootstrap
  2. /******/ "use strict";
  3. /******/ // The require scope
  4. /******/ var __webpack_require__ = {};
  5. /******/
  6. /************************************************************************/
  7. /******/ /* webpack/runtime/define property getters */
  8. /******/ !function() {
  9. /******/ // define getter functions for harmony exports
  10. /******/ __webpack_require__.d = function(exports, definition) {
  11. /******/ for(var key in definition) {
  12. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  13. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  14. /******/ }
  15. /******/ }
  16. /******/ };
  17. /******/ }();
  18. /******/
  19. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  20. /******/ !function() {
  21. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  22. /******/ }();
  23. /******/
  24. /******/ /* webpack/runtime/make namespace object */
  25. /******/ !function() {
  26. /******/ // define __esModule on exports
  27. /******/ __webpack_require__.r = function(exports) {
  28. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  29. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  30. /******/ }
  31. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  32. /******/ };
  33. /******/ }();
  34. /******/
  35. /************************************************************************/
  36. var __webpack_exports__ = {};
  37. // ESM COMPAT FLAG
  38. __webpack_require__.r(__webpack_exports__);
  39. // EXPORTS
  40. __webpack_require__.d(__webpack_exports__, {
  41. count: function() { return /* binding */ count; }
  42. });
  43. ;// CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/defaultSettings.js
  44. /** @typedef {import('./index').WPWordCountStrategy} WPWordCountStrategy */
  45. /** @typedef {Partial<{type: WPWordCountStrategy, shortcodes: string[]}>} WPWordCountL10n */
  46. /**
  47. * @typedef WPWordCountSettingsFields
  48. * @property {RegExp} HTMLRegExp Regular expression that matches HTML tags
  49. * @property {RegExp} HTMLcommentRegExp Regular expression that matches HTML comments
  50. * @property {RegExp} spaceRegExp Regular expression that matches spaces in HTML
  51. * @property {RegExp} HTMLEntityRegExp Regular expression that matches HTML entities
  52. * @property {RegExp} connectorRegExp Regular expression that matches word connectors, like em-dash
  53. * @property {RegExp} removeRegExp Regular expression that matches various characters to be removed when counting
  54. * @property {RegExp} astralRegExp Regular expression that matches astral UTF-16 code points
  55. * @property {RegExp} wordsRegExp Regular expression that matches words
  56. * @property {RegExp} characters_excluding_spacesRegExp Regular expression that matches characters excluding spaces
  57. * @property {RegExp} characters_including_spacesRegExp Regular expression that matches characters including spaces
  58. * @property {RegExp} shortcodesRegExp Regular expression that matches WordPress shortcodes
  59. * @property {string[]} shortcodes List of all shortcodes
  60. * @property {WPWordCountStrategy} type Describes what and how are we counting
  61. * @property {WPWordCountL10n} l10n Object with human translations
  62. */
  63. /**
  64. * Lower-level settings for word counting that can be overridden.
  65. *
  66. * @typedef {Partial<WPWordCountSettingsFields>} WPWordCountUserSettings
  67. */
  68. // Disable reason: JSDoc linter doesn't seem to parse the union (`&`) correctly: https://github.com/jsdoc/jsdoc/issues/1285
  69. /* eslint-disable jsdoc/valid-types */
  70. /**
  71. * Word counting settings that include non-optional values we set if missing
  72. *
  73. * @typedef {WPWordCountUserSettings & typeof defaultSettings} WPWordCountDefaultSettings
  74. */
  75. /* eslint-enable jsdoc/valid-types */
  76. const defaultSettings = {
  77. HTMLRegExp: /<\/?[a-z][^>]*?>/gi,
  78. HTMLcommentRegExp: /<!--[\s\S]*?-->/g,
  79. spaceRegExp: /&nbsp;|&#160;/gi,
  80. HTMLEntityRegExp: /&\S+?;/g,
  81. // \u2014 = em-dash.
  82. connectorRegExp: /--|\u2014/g,
  83. // Characters to be removed from input text.
  84. removeRegExp: new RegExp(['[',
  85. // Basic Latin (extract)
  86. '\u0021-\u002F\u003A-\u0040\u005B-\u0060\u007B-\u007E',
  87. // Latin-1 Supplement (extract)
  88. '\u0080-\u00BF\u00D7\u00F7',
  89. /*
  90. * The following range consists of:
  91. * General Punctuation
  92. * Superscripts and Subscripts
  93. * Currency Symbols
  94. * Combining Diacritical Marks for Symbols
  95. * Letterlike Symbols
  96. * Number Forms
  97. * Arrows
  98. * Mathematical Operators
  99. * Miscellaneous Technical
  100. * Control Pictures
  101. * Optical Character Recognition
  102. * Enclosed Alphanumerics
  103. * Box Drawing
  104. * Block Elements
  105. * Geometric Shapes
  106. * Miscellaneous Symbols
  107. * Dingbats
  108. * Miscellaneous Mathematical Symbols-A
  109. * Supplemental Arrows-A
  110. * Braille Patterns
  111. * Supplemental Arrows-B
  112. * Miscellaneous Mathematical Symbols-B
  113. * Supplemental Mathematical Operators
  114. * Miscellaneous Symbols and Arrows
  115. */
  116. '\u2000-\u2BFF',
  117. // Supplemental Punctuation.
  118. '\u2E00-\u2E7F', ']'].join(''), 'g'),
  119. // Remove UTF-16 surrogate points, see https://en.wikipedia.org/wiki/UTF-16#U.2BD800_to_U.2BDFFF
  120. astralRegExp: /[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
  121. wordsRegExp: /\S\s+/g,
  122. characters_excluding_spacesRegExp: /\S/g,
  123. /*
  124. * Match anything that is not a formatting character, excluding:
  125. * \f = form feed
  126. * \n = new line
  127. * \r = carriage return
  128. * \t = tab
  129. * \v = vertical tab
  130. * \u00AD = soft hyphen
  131. * \u2028 = line separator
  132. * \u2029 = paragraph separator
  133. */
  134. characters_including_spacesRegExp: /[^\f\n\r\t\v\u00AD\u2028\u2029]/g,
  135. l10n: {
  136. type: 'words'
  137. }
  138. };
  139. ;// CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripTags.js
  140. /**
  141. * Replaces items matched in the regex with new line
  142. *
  143. * @param {import('./index').WPWordCountSettings} settings The main settings object containing regular expressions
  144. * @param {string} text The string being counted.
  145. *
  146. * @return {string} The manipulated text.
  147. */
  148. function stripTags(settings, text) {
  149. return text.replace(settings.HTMLRegExp, '\n');
  150. }
  151. ;// CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/transposeAstralsToCountableChar.js
  152. /**
  153. * Replaces items matched in the regex with character.
  154. *
  155. * @param {import('./index').WPWordCountSettings} settings The main settings object containing regular expressions
  156. * @param {string} text The string being counted.
  157. *
  158. * @return {string} The manipulated text.
  159. */
  160. function transposeAstralsToCountableChar(settings, text) {
  161. return text.replace(settings.astralRegExp, 'a');
  162. }
  163. ;// CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripHTMLEntities.js
  164. /**
  165. * Removes items matched in the regex.
  166. *
  167. * @param {import('./index').WPWordCountSettings} settings The main settings object containing regular expressions
  168. * @param {string} text The string being counted.
  169. *
  170. * @return {string} The manipulated text.
  171. */
  172. function stripHTMLEntities(settings, text) {
  173. return text.replace(settings.HTMLEntityRegExp, '');
  174. }
  175. ;// CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripConnectors.js
  176. /**
  177. * Replaces items matched in the regex with spaces.
  178. *
  179. * @param {import('./index').WPWordCountSettings} settings The main settings object containing regular expressions
  180. * @param {string} text The string being counted.
  181. *
  182. * @return {string} The manipulated text.
  183. */
  184. function stripConnectors(settings, text) {
  185. return text.replace(settings.connectorRegExp, ' ');
  186. }
  187. ;// CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripRemovables.js
  188. /**
  189. * Removes items matched in the regex.
  190. *
  191. * @param {import('./index').WPWordCountSettings} settings The main settings object containing regular expressions
  192. * @param {string} text The string being counted.
  193. *
  194. * @return {string} The manipulated text.
  195. */
  196. function stripRemovables(settings, text) {
  197. return text.replace(settings.removeRegExp, '');
  198. }
  199. ;// CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripHTMLComments.js
  200. /**
  201. * Removes items matched in the regex.
  202. *
  203. * @param {import('./index').WPWordCountSettings} settings The main settings object containing regular expressions
  204. * @param {string} text The string being counted.
  205. *
  206. * @return {string} The manipulated text.
  207. */
  208. function stripHTMLComments(settings, text) {
  209. return text.replace(settings.HTMLcommentRegExp, '');
  210. }
  211. ;// CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripShortcodes.js
  212. /**
  213. * Replaces items matched in the regex with a new line.
  214. *
  215. * @param {import('./index').WPWordCountSettings} settings The main settings object containing regular expressions
  216. * @param {string} text The string being counted.
  217. *
  218. * @return {string} The manipulated text.
  219. */
  220. function stripShortcodes(settings, text) {
  221. if (settings.shortcodesRegExp) {
  222. return text.replace(settings.shortcodesRegExp, '\n');
  223. }
  224. return text;
  225. }
  226. ;// CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/stripSpaces.js
  227. /**
  228. * Replaces items matched in the regex with spaces.
  229. *
  230. * @param {import('./index').WPWordCountSettings} settings The main settings object containing regular expressions
  231. * @param {string} text The string being counted.
  232. *
  233. * @return {string} The manipulated text.
  234. */
  235. function stripSpaces(settings, text) {
  236. return text.replace(settings.spaceRegExp, ' ');
  237. }
  238. ;// CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/transposeHTMLEntitiesToCountableChars.js
  239. /**
  240. * Replaces items matched in the regex with a single character.
  241. *
  242. * @param {import('./index').WPWordCountSettings} settings The main settings object containing regular expressions
  243. * @param {string} text The string being counted.
  244. *
  245. * @return {string} The manipulated text.
  246. */
  247. function transposeHTMLEntitiesToCountableChars(settings, text) {
  248. return text.replace(settings.HTMLEntityRegExp, 'a');
  249. }
  250. ;// CONCATENATED MODULE: ./node_modules/@wordpress/wordcount/build-module/index.js
  251. /**
  252. * Internal dependencies
  253. */
  254. /**
  255. * @typedef {import('./defaultSettings').WPWordCountDefaultSettings} WPWordCountSettings
  256. * @typedef {import('./defaultSettings').WPWordCountUserSettings} WPWordCountUserSettings
  257. */
  258. /**
  259. * Possible ways of counting.
  260. *
  261. * @typedef {'words'|'characters_excluding_spaces'|'characters_including_spaces'} WPWordCountStrategy
  262. */
  263. /**
  264. * Private function to manage the settings.
  265. *
  266. * @param {WPWordCountStrategy} type The type of count to be done.
  267. * @param {WPWordCountUserSettings} userSettings Custom settings for the count.
  268. *
  269. * @return {WPWordCountSettings} The combined settings object to be used.
  270. */
  271. function loadSettings(type, userSettings) {
  272. var _settings$l10n$shortc;
  273. const settings = Object.assign({}, defaultSettings, userSettings);
  274. settings.shortcodes = (_settings$l10n$shortc = settings.l10n?.shortcodes) !== null && _settings$l10n$shortc !== void 0 ? _settings$l10n$shortc : [];
  275. if (settings.shortcodes && settings.shortcodes.length) {
  276. settings.shortcodesRegExp = new RegExp('\\[\\/?(?:' + settings.shortcodes.join('|') + ')[^\\]]*?\\]', 'g');
  277. }
  278. settings.type = type;
  279. if (settings.type !== 'characters_excluding_spaces' && settings.type !== 'characters_including_spaces') {
  280. settings.type = 'words';
  281. }
  282. return settings;
  283. }
  284. /**
  285. * Count the words in text
  286. *
  287. * @param {string} text The text being processed
  288. * @param {RegExp} regex The regular expression pattern being matched
  289. * @param {WPWordCountSettings} settings Settings object containing regular expressions for each strip function
  290. *
  291. * @return {number} Count of words.
  292. */
  293. function countWords(text, regex, settings) {
  294. var _text$match$length;
  295. text = [stripTags.bind(null, settings), stripHTMLComments.bind(null, settings), stripShortcodes.bind(null, settings), stripSpaces.bind(null, settings), stripHTMLEntities.bind(null, settings), stripConnectors.bind(null, settings), stripRemovables.bind(null, settings)].reduce((result, fn) => fn(result), text);
  296. text = text + '\n';
  297. return (_text$match$length = text.match(regex)?.length) !== null && _text$match$length !== void 0 ? _text$match$length : 0;
  298. }
  299. /**
  300. * Count the characters in text
  301. *
  302. * @param {string} text The text being processed
  303. * @param {RegExp} regex The regular expression pattern being matched
  304. * @param {WPWordCountSettings} settings Settings object containing regular expressions for each strip function
  305. *
  306. * @return {number} Count of characters.
  307. */
  308. function countCharacters(text, regex, settings) {
  309. var _text$match$length2;
  310. text = [stripTags.bind(null, settings), stripHTMLComments.bind(null, settings), stripShortcodes.bind(null, settings), transposeAstralsToCountableChar.bind(null, settings), stripSpaces.bind(null, settings), transposeHTMLEntitiesToCountableChars.bind(null, settings)].reduce((result, fn) => fn(result), text);
  311. text = text + '\n';
  312. return (_text$match$length2 = text.match(regex)?.length) !== null && _text$match$length2 !== void 0 ? _text$match$length2 : 0;
  313. }
  314. /**
  315. * Count some words.
  316. *
  317. * @param {string} text The text being processed
  318. * @param {WPWordCountStrategy} type The type of count. Accepts 'words', 'characters_excluding_spaces', or 'characters_including_spaces'.
  319. * @param {WPWordCountUserSettings} userSettings Custom settings object.
  320. *
  321. * @example
  322. * ```js
  323. * import { count } from '@wordpress/wordcount';
  324. * const numberOfWords = count( 'Words to count', 'words', {} )
  325. * ```
  326. *
  327. * @return {number} The word or character count.
  328. */
  329. function count(text, type, userSettings) {
  330. const settings = loadSettings(type, userSettings);
  331. let matchRegExp;
  332. switch (settings.type) {
  333. case 'words':
  334. matchRegExp = settings.wordsRegExp;
  335. return countWords(text, matchRegExp, settings);
  336. case 'characters_including_spaces':
  337. matchRegExp = settings.characters_including_spacesRegExp;
  338. return countCharacters(text, matchRegExp, settings);
  339. case 'characters_excluding_spaces':
  340. matchRegExp = settings.characters_excluding_spacesRegExp;
  341. return countCharacters(text, matchRegExp, settings);
  342. default:
  343. return 0;
  344. }
  345. }
  346. (window.wp = window.wp || {}).wordcount = __webpack_exports__;
  347. /******/ })()
  348. ;