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