[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/dist/ -> wordcount.js (source)

   1  /******/ (() => { // webpackBootstrap
   2  /******/     var __webpack_modules__ = ({
   3  
   4  /***/ 677:
   5  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
   6  
   7  "use strict";
   8  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
   9  /* harmony export */   A: () => (/* binding */ stripTags)
  10  /* harmony export */ });
  11  function stripTags(settings, text) {
  12    return text.replace(settings.HTMLRegExp, "\n");
  13  }
  14  
  15  
  16  
  17  /***/ }),
  18  
  19  /***/ 2125:
  20  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  21  
  22  "use strict";
  23  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  24  /* harmony export */   A: () => (/* binding */ transposeAstralsToCountableChar)
  25  /* harmony export */ });
  26  function transposeAstralsToCountableChar(settings, text) {
  27    return text.replace(settings.astralRegExp, "a");
  28  }
  29  
  30  
  31  
  32  /***/ }),
  33  
  34  /***/ 3608:
  35  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  36  
  37  "use strict";
  38  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  39  /* harmony export */   A: () => (/* binding */ stripConnectors)
  40  /* harmony export */ });
  41  function stripConnectors(settings, text) {
  42    return text.replace(settings.connectorRegExp, " ");
  43  }
  44  
  45  
  46  
  47  /***/ }),
  48  
  49  /***/ 4516:
  50  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  51  
  52  "use strict";
  53  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  54  /* harmony export */   A: () => (/* binding */ stripShortcodes)
  55  /* harmony export */ });
  56  function stripShortcodes(settings, text) {
  57    if (settings.shortcodesRegExp) {
  58      return text.replace(settings.shortcodesRegExp, "\n");
  59    }
  60    return text;
  61  }
  62  
  63  
  64  
  65  /***/ }),
  66  
  67  /***/ 4579:
  68  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  69  
  70  "use strict";
  71  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  72  /* harmony export */   A: () => (/* binding */ stripHTMLComments)
  73  /* harmony export */ });
  74  function stripHTMLComments(settings, text) {
  75    return text.replace(settings.HTMLcommentRegExp, "");
  76  }
  77  
  78  
  79  
  80  /***/ }),
  81  
  82  /***/ 4846:
  83  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  84  
  85  "use strict";
  86  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  87  /* harmony export */   A: () => (/* binding */ stripHTMLEntities)
  88  /* harmony export */ });
  89  function stripHTMLEntities(settings, text) {
  90    return text.replace(settings.HTMLEntityRegExp, "");
  91  }
  92  
  93  
  94  
  95  /***/ }),
  96  
  97  /***/ 6019:
  98  /***/ (() => {
  99  
 100  
 101  
 102  /***/ }),
 103  
 104  /***/ 6542:
 105  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
 106  
 107  "use strict";
 108  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
 109  /* harmony export */   A: () => (/* binding */ stripRemovables)
 110  /* harmony export */ });
 111  function stripRemovables(settings, text) {
 112    return text.replace(settings.removeRegExp, "");
 113  }
 114  
 115  
 116  
 117  /***/ }),
 118  
 119  /***/ 7742:
 120  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
 121  
 122  "use strict";
 123  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
 124  /* harmony export */   L: () => (/* binding */ defaultSettings)
 125  /* harmony export */ });
 126  const defaultSettings = {
 127    HTMLRegExp: /<\/?[a-z][^>]*?>/gi,
 128    HTMLcommentRegExp: /<!--[\s\S]*?-->/g,
 129    spaceRegExp: /&nbsp;|&#160;/gi,
 130    HTMLEntityRegExp: /&\S+?;/g,
 131    // \u2014 = em-dash.
 132    connectorRegExp: /--|\u2014/g,
 133    // Characters to be removed from input text.
 134    removeRegExp: new RegExp(
 135      [
 136        "[",
 137        // Basic Latin (extract)
 138        "!-/:-@[-`{-~",
 139        // Latin-1 Supplement (extract)
 140        "\x80-\xBF\xD7\xF7",
 141        /*
 142         * The following range consists of:
 143         * General Punctuation
 144         * Superscripts and Subscripts
 145         * Currency Symbols
 146         * Combining Diacritical Marks for Symbols
 147         * Letterlike Symbols
 148         * Number Forms
 149         * Arrows
 150         * Mathematical Operators
 151         * Miscellaneous Technical
 152         * Control Pictures
 153         * Optical Character Recognition
 154         * Enclosed Alphanumerics
 155         * Box Drawing
 156         * Block Elements
 157         * Geometric Shapes
 158         * Miscellaneous Symbols
 159         * Dingbats
 160         * Miscellaneous Mathematical Symbols-A
 161         * Supplemental Arrows-A
 162         * Braille Patterns
 163         * Supplemental Arrows-B
 164         * Miscellaneous Mathematical Symbols-B
 165         * Supplemental Mathematical Operators
 166         * Miscellaneous Symbols and Arrows
 167         */
 168        "\u2000-\u2BFF",
 169        // Supplemental Punctuation.
 170        "\u2E00-\u2E7F",
 171        "]"
 172      ].join(""),
 173      "g"
 174    ),
 175    // Remove UTF-16 surrogate points, see https://en.wikipedia.org/wiki/UTF-16#U.2BD800_to_U.2BDFFF
 176    astralRegExp: /[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
 177    wordsRegExp: /\S\s+/g,
 178    characters_excluding_spacesRegExp: /\S/g,
 179    /*
 180     * Match anything that is not a formatting character, excluding:
 181     * \f = form feed
 182     * \n = new line
 183     * \r = carriage return
 184     * \t = tab
 185     * \v = vertical tab
 186     * \u00AD = soft hyphen
 187     * \u2028 = line separator
 188     * \u2029 = paragraph separator
 189     */
 190    characters_including_spacesRegExp: /[^\f\n\r\t\v\u00AD\u2028\u2029]/g,
 191    l10n: {
 192      type: "words"
 193    }
 194  };
 195  
 196  
 197  
 198  /***/ }),
 199  
 200  /***/ 8026:
 201  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
 202  
 203  "use strict";
 204  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
 205  /* harmony export */   A: () => (/* binding */ transposeHTMLEntitiesToCountableChars)
 206  /* harmony export */ });
 207  function transposeHTMLEntitiesToCountableChars(settings, text) {
 208    return text.replace(settings.HTMLEntityRegExp, "a");
 209  }
 210  
 211  
 212  
 213  /***/ }),
 214  
 215  /***/ 8511:
 216  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
 217  
 218  "use strict";
 219  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
 220  /* harmony export */   A: () => (/* binding */ stripSpaces)
 221  /* harmony export */ });
 222  function stripSpaces(settings, text) {
 223    return text.replace(settings.spaceRegExp, " ");
 224  }
 225  
 226  
 227  
 228  /***/ })
 229  
 230  /******/     });
 231  /************************************************************************/
 232  /******/     // The module cache
 233  /******/     var __webpack_module_cache__ = {};
 234  /******/     
 235  /******/     // The require function
 236  /******/ 	function __webpack_require__(moduleId) {
 237  /******/         // Check if module is in cache
 238  /******/         var cachedModule = __webpack_module_cache__[moduleId];
 239  /******/         if (cachedModule !== undefined) {
 240  /******/             return cachedModule.exports;
 241  /******/         }
 242  /******/         // Create a new module (and put it into the cache)
 243  /******/         var module = __webpack_module_cache__[moduleId] = {
 244  /******/             // no module.id needed
 245  /******/             // no module.loaded needed
 246  /******/             exports: {}
 247  /******/         };
 248  /******/     
 249  /******/         // Execute the module function
 250  /******/         __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
 251  /******/     
 252  /******/         // Return the exports of the module
 253  /******/         return module.exports;
 254  /******/     }
 255  /******/     
 256  /************************************************************************/
 257  /******/     /* webpack/runtime/compat get default export */
 258  /******/     (() => {
 259  /******/         // getDefaultExport function for compatibility with non-harmony modules
 260  /******/         __webpack_require__.n = (module) => {
 261  /******/             var getter = module && module.__esModule ?
 262  /******/                 () => (module['default']) :
 263  /******/                 () => (module);
 264  /******/             __webpack_require__.d(getter, { a: getter });
 265  /******/             return getter;
 266  /******/         };
 267  /******/     })();
 268  /******/     
 269  /******/     /* webpack/runtime/define property getters */
 270  /******/     (() => {
 271  /******/         // define getter functions for harmony exports
 272  /******/         __webpack_require__.d = (exports, definition) => {
 273  /******/             for(var key in definition) {
 274  /******/                 if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
 275  /******/                     Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
 276  /******/                 }
 277  /******/             }
 278  /******/         };
 279  /******/     })();
 280  /******/     
 281  /******/     /* webpack/runtime/hasOwnProperty shorthand */
 282  /******/     (() => {
 283  /******/         __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
 284  /******/     })();
 285  /******/     
 286  /******/     /* webpack/runtime/make namespace object */
 287  /******/     (() => {
 288  /******/         // define __esModule on exports
 289  /******/         __webpack_require__.r = (exports) => {
 290  /******/             if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
 291  /******/                 Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
 292  /******/             }
 293  /******/             Object.defineProperty(exports, '__esModule', { value: true });
 294  /******/         };
 295  /******/     })();
 296  /******/     
 297  /************************************************************************/
 298  var __webpack_exports__ = {};
 299  // This entry needs to be wrapped in an IIFE because it needs to be in strict mode.
 300  (() => {
 301  "use strict";
 302  __webpack_require__.r(__webpack_exports__);
 303  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
 304  /* harmony export */   count: () => (/* binding */ count)
 305  /* harmony export */ });
 306  /* harmony import */ var _defaultSettings__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7742);
 307  /* harmony import */ var _stripTags__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(677);
 308  /* harmony import */ var _transposeAstralsToCountableChar__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(2125);
 309  /* harmony import */ var _stripHTMLEntities__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(4846);
 310  /* harmony import */ var _stripConnectors__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(3608);
 311  /* harmony import */ var _stripRemovables__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(6542);
 312  /* harmony import */ var _stripHTMLComments__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(4579);
 313  /* harmony import */ var _stripShortcodes__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(4516);
 314  /* harmony import */ var _stripSpaces__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(8511);
 315  /* harmony import */ var _transposeHTMLEntitiesToCountableChars__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(8026);
 316  /* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(6019);
 317  /* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_10___default = /*#__PURE__*/__webpack_require__.n(_types__WEBPACK_IMPORTED_MODULE_10__);
 318  /* harmony reexport (unknown) */ var __WEBPACK_REEXPORT_OBJECT__ = {};
 319  /* harmony reexport (unknown) */ for(const __WEBPACK_IMPORT_KEY__ in _types__WEBPACK_IMPORTED_MODULE_10__) if(["default","count"].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = () => _types__WEBPACK_IMPORTED_MODULE_10__[__WEBPACK_IMPORT_KEY__]
 320  /* harmony reexport (unknown) */ __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
 321  
 322  
 323  
 324  
 325  
 326  
 327  
 328  
 329  
 330  
 331  function loadSettings(type = "words", userSettings = {}) {
 332    const mergedSettings = { ..._defaultSettings__WEBPACK_IMPORTED_MODULE_0__/* .defaultSettings */ .L, ...userSettings };
 333    const settings = {
 334      ...mergedSettings,
 335      type,
 336      shortcodes: []
 337    };
 338    settings.shortcodes = settings.l10n?.shortcodes ?? [];
 339    if (settings.shortcodes && settings.shortcodes.length) {
 340      settings.shortcodesRegExp = new RegExp(
 341        "\\[\\/?(?:" + settings.shortcodes.join("|") + ")[^\\]]*?\\]",
 342        "g"
 343      );
 344    }
 345    if (settings.type !== "characters_excluding_spaces" && settings.type !== "characters_including_spaces") {
 346      settings.type = "words";
 347    }
 348    return settings;
 349  }
 350  function countWords(text, regex, settings) {
 351    text = [
 352      _stripTags__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .A.bind(null, settings),
 353      _stripHTMLComments__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .A.bind(null, settings),
 354      _stripShortcodes__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .A.bind(null, settings),
 355      _stripSpaces__WEBPACK_IMPORTED_MODULE_4__/* ["default"] */ .A.bind(null, settings),
 356      _stripHTMLEntities__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .A.bind(null, settings),
 357      _stripConnectors__WEBPACK_IMPORTED_MODULE_6__/* ["default"] */ .A.bind(null, settings),
 358      _stripRemovables__WEBPACK_IMPORTED_MODULE_7__/* ["default"] */ .A.bind(null, settings)
 359    ].reduce((result, fn) => fn(result), text);
 360    text = text + "\n";
 361    return text.match(regex)?.length ?? 0;
 362  }
 363  function countCharacters(text, regex, settings) {
 364    text = [
 365      _stripTags__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .A.bind(null, settings),
 366      _stripHTMLComments__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .A.bind(null, settings),
 367      _stripShortcodes__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .A.bind(null, settings),
 368      _transposeAstralsToCountableChar__WEBPACK_IMPORTED_MODULE_8__/* ["default"] */ .A.bind(null, settings),
 369      _stripSpaces__WEBPACK_IMPORTED_MODULE_4__/* ["default"] */ .A.bind(null, settings),
 370      _transposeHTMLEntitiesToCountableChars__WEBPACK_IMPORTED_MODULE_9__/* ["default"] */ .A.bind(null, settings)
 371    ].reduce((result, fn) => fn(result), text);
 372    text = text + "\n";
 373    return text.match(regex)?.length ?? 0;
 374  }
 375  function count(text, type, userSettings) {
 376    const settings = loadSettings(type, userSettings);
 377    let matchRegExp;
 378    switch (settings.type) {
 379      case "words":
 380        matchRegExp = settings.wordsRegExp;
 381        return countWords(text, matchRegExp, settings);
 382      case "characters_including_spaces":
 383        matchRegExp = settings.characters_including_spacesRegExp;
 384        return countCharacters(text, matchRegExp, settings);
 385      case "characters_excluding_spaces":
 386        matchRegExp = settings.characters_excluding_spacesRegExp;
 387        return countCharacters(text, matchRegExp, settings);
 388      default:
 389        return 0;
 390    }
 391  }
 392  
 393  
 394  
 395  })();
 396  
 397  (window.wp = window.wp || {}).wordcount = __webpack_exports__;
 398  /******/ })()
 399  ;


Generated : Wed Oct 29 08:20:06 2025 Cross-referenced by PHPXref