shortcode.js (19384B)
1 this["wp"] = this["wp"] || {}; this["wp"]["shortcode"] = 2 /******/ (function(modules) { // webpackBootstrap 3 /******/ // The module cache 4 /******/ var installedModules = {}; 5 /******/ 6 /******/ // The require function 7 /******/ function __webpack_require__(moduleId) { 8 /******/ 9 /******/ // Check if module is in cache 10 /******/ if(installedModules[moduleId]) { 11 /******/ return installedModules[moduleId].exports; 12 /******/ } 13 /******/ // Create a new module (and put it into the cache) 14 /******/ var module = installedModules[moduleId] = { 15 /******/ i: moduleId, 16 /******/ l: false, 17 /******/ exports: {} 18 /******/ }; 19 /******/ 20 /******/ // Execute the module function 21 /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 22 /******/ 23 /******/ // Flag the module as loaded 24 /******/ module.l = true; 25 /******/ 26 /******/ // Return the exports of the module 27 /******/ return module.exports; 28 /******/ } 29 /******/ 30 /******/ 31 /******/ // expose the modules object (__webpack_modules__) 32 /******/ __webpack_require__.m = modules; 33 /******/ 34 /******/ // expose the module cache 35 /******/ __webpack_require__.c = installedModules; 36 /******/ 37 /******/ // define getter function for harmony exports 38 /******/ __webpack_require__.d = function(exports, name, getter) { 39 /******/ if(!__webpack_require__.o(exports, name)) { 40 /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); 41 /******/ } 42 /******/ }; 43 /******/ 44 /******/ // define __esModule on exports 45 /******/ __webpack_require__.r = function(exports) { 46 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 47 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 48 /******/ } 49 /******/ Object.defineProperty(exports, '__esModule', { value: true }); 50 /******/ }; 51 /******/ 52 /******/ // create a fake namespace object 53 /******/ // mode & 1: value is a module id, require it 54 /******/ // mode & 2: merge all properties of value into the ns 55 /******/ // mode & 4: return value when already ns object 56 /******/ // mode & 8|1: behave like require 57 /******/ __webpack_require__.t = function(value, mode) { 58 /******/ if(mode & 1) value = __webpack_require__(value); 59 /******/ if(mode & 8) return value; 60 /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; 61 /******/ var ns = Object.create(null); 62 /******/ __webpack_require__.r(ns); 63 /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); 64 /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); 65 /******/ return ns; 66 /******/ }; 67 /******/ 68 /******/ // getDefaultExport function for compatibility with non-harmony modules 69 /******/ __webpack_require__.n = function(module) { 70 /******/ var getter = module && module.__esModule ? 71 /******/ function getDefault() { return module['default']; } : 72 /******/ function getModuleExports() { return module; }; 73 /******/ __webpack_require__.d(getter, 'a', getter); 74 /******/ return getter; 75 /******/ }; 76 /******/ 77 /******/ // Object.prototype.hasOwnProperty.call 78 /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; 79 /******/ 80 /******/ // __webpack_public_path__ 81 /******/ __webpack_require__.p = ""; 82 /******/ 83 /******/ 84 /******/ // Load entry module and return exports 85 /******/ return __webpack_require__(__webpack_require__.s = "/2FX"); 86 /******/ }) 87 /************************************************************************/ 88 /******/ ({ 89 90 /***/ "/2FX": 91 /***/ (function(module, __webpack_exports__, __webpack_require__) { 92 93 "use strict"; 94 __webpack_require__.r(__webpack_exports__); 95 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "next", function() { return next; }); 96 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "replace", function() { return replace; }); 97 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "string", function() { return string; }); 98 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "regexp", function() { return regexp; }); 99 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "attrs", function() { return attrs; }); 100 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "fromMatch", function() { return fromMatch; }); 101 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("YLtl"); 102 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__); 103 /* harmony import */ var memize__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("4eJC"); 104 /* harmony import */ var memize__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(memize__WEBPACK_IMPORTED_MODULE_1__); 105 /** 106 * External dependencies 107 */ 108 109 110 /** 111 * Shortcode attributes object. 112 * 113 * @typedef {Object} WPShortcodeAttrs 114 * 115 * @property {Object} named Object with named attributes. 116 * @property {Array} numeric Array with numeric attributes. 117 */ 118 119 /** 120 * Shortcode object. 121 * 122 * @typedef {Object} WPShortcode 123 * 124 * @property {string} tag Shortcode tag. 125 * @property {WPShortcodeAttrs} attrs Shortcode attributes. 126 * @property {string} content Shortcode content. 127 * @property {string} type Shortcode type: `self-closing`, 128 * `closed`, or `single`. 129 */ 130 131 /** 132 * @typedef {Object} WPShortcodeMatch 133 * 134 * @property {number} index Index the shortcode is found at. 135 * @property {string} content Matched content. 136 * @property {WPShortcode} shortcode Shortcode instance of the match. 137 */ 138 139 /** 140 * Find the next matching shortcode. 141 * 142 * @param {string} tag Shortcode tag. 143 * @param {string} text Text to search. 144 * @param {number} index Index to start search from. 145 * 146 * @return {?WPShortcodeMatch} Matched information. 147 */ 148 149 function next(tag, text, index = 0) { 150 const re = regexp(tag); 151 re.lastIndex = index; 152 const match = re.exec(text); 153 154 if (!match) { 155 return; 156 } // If we matched an escaped shortcode, try again. 157 158 159 if ('[' === match[1] && ']' === match[7]) { 160 return next(tag, text, re.lastIndex); 161 } 162 163 const result = { 164 index: match.index, 165 content: match[0], 166 shortcode: fromMatch(match) 167 }; // If we matched a leading `[`, strip it from the match and increment the 168 // index accordingly. 169 170 if (match[1]) { 171 result.content = result.content.slice(1); 172 result.index++; 173 } // If we matched a trailing `]`, strip it from the match. 174 175 176 if (match[7]) { 177 result.content = result.content.slice(0, -1); 178 } 179 180 return result; 181 } 182 /** 183 * Replace matching shortcodes in a block of text. 184 * 185 * @param {string} tag Shortcode tag. 186 * @param {string} text Text to search. 187 * @param {Function} callback Function to process the match and return 188 * replacement string. 189 * 190 * @return {string} Text with shortcodes replaced. 191 */ 192 193 function replace(tag, text, callback) { 194 return text.replace(regexp(tag), function (match, left, $3, attrs, slash, content, closing, right) { 195 // If both extra brackets exist, the shortcode has been properly 196 // escaped. 197 if (left === '[' && right === ']') { 198 return match; 199 } // Create the match object and pass it through the callback. 200 201 202 const result = callback(fromMatch(arguments)); // Make sure to return any of the extra brackets if they weren't used to 203 // escape the shortcode. 204 205 return result || result === '' ? left + result + right : match; 206 }); 207 } 208 /** 209 * Generate a string from shortcode parameters. 210 * 211 * Creates a shortcode instance and returns a string. 212 * 213 * Accepts the same `options` as the `shortcode()` constructor, containing a 214 * `tag` string, a string or object of `attrs`, a boolean indicating whether to 215 * format the shortcode using a `single` tag, and a `content` string. 216 * 217 * @param {Object} options 218 * 219 * @return {string} String representation of the shortcode. 220 */ 221 222 function string(options) { 223 return new shortcode(options).string(); 224 } 225 /** 226 * Generate a RegExp to identify a shortcode. 227 * 228 * The base regex is functionally equivalent to the one found in 229 * `get_shortcode_regex()` in `wp-includes/shortcodes.php`. 230 * 231 * Capture groups: 232 * 233 * 1. An extra `[` to allow for escaping shortcodes with double `[[]]` 234 * 2. The shortcode name 235 * 3. The shortcode argument list 236 * 4. The self closing `/` 237 * 5. The content of a shortcode when it wraps some content. 238 * 6. The closing tag. 239 * 7. An extra `]` to allow for escaping shortcodes with double `[[]]` 240 * 241 * @param {string} tag Shortcode tag. 242 * 243 * @return {RegExp} Shortcode RegExp. 244 */ 245 246 function regexp(tag) { 247 return new RegExp('\\[(\\[?)(' + tag + ')(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*(?:\\[(?!\\/\\2\\])[^\\[]*)*)(\\[\\/\\2\\]))?)(\\]?)', 'g'); 248 } 249 /** 250 * Parse shortcode attributes. 251 * 252 * Shortcodes accept many types of attributes. These can chiefly be divided into 253 * named and numeric attributes: 254 * 255 * Named attributes are assigned on a key/value basis, while numeric attributes 256 * are treated as an array. 257 * 258 * Named attributes can be formatted as either `name="value"`, `name='value'`, 259 * or `name=value`. Numeric attributes can be formatted as `"value"` or just 260 * `value`. 261 * 262 * @param {string} text Serialised shortcode attributes. 263 * 264 * @return {WPShortcodeAttrs} Parsed shortcode attributes. 265 */ 266 267 const attrs = memize__WEBPACK_IMPORTED_MODULE_1___default()(text => { 268 const named = {}; 269 const numeric = []; // This regular expression is reused from `shortcode_parse_atts()` in 270 // `wp-includes/shortcodes.php`. 271 // 272 // Capture groups: 273 // 274 // 1. An attribute name, that corresponds to... 275 // 2. a value in double quotes. 276 // 3. An attribute name, that corresponds to... 277 // 4. a value in single quotes. 278 // 5. An attribute name, that corresponds to... 279 // 6. an unquoted value. 280 // 7. A numeric attribute in double quotes. 281 // 8. A numeric attribute in single quotes. 282 // 9. An unquoted numeric attribute. 283 284 const pattern = /([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*'([^']*)'(?:\s|$)|([\w-]+)\s*=\s*([^\s'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|'([^']*)'(?:\s|$)|(\S+)(?:\s|$)/g; // Map zero-width spaces to actual spaces. 285 286 text = text.replace(/[\u00a0\u200b]/g, ' '); 287 let match; // Match and normalize attributes. 288 289 while (match = pattern.exec(text)) { 290 if (match[1]) { 291 named[match[1].toLowerCase()] = match[2]; 292 } else if (match[3]) { 293 named[match[3].toLowerCase()] = match[4]; 294 } else if (match[5]) { 295 named[match[5].toLowerCase()] = match[6]; 296 } else if (match[7]) { 297 numeric.push(match[7]); 298 } else if (match[8]) { 299 numeric.push(match[8]); 300 } else if (match[9]) { 301 numeric.push(match[9]); 302 } 303 } 304 305 return { 306 named, 307 numeric 308 }; 309 }); 310 /** 311 * Generate a Shortcode Object from a RegExp match. 312 * 313 * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated 314 * by `regexp()`. `match` can also be set to the `arguments` from a callback 315 * passed to `regexp.replace()`. 316 * 317 * @param {Array} match Match array. 318 * 319 * @return {WPShortcode} Shortcode instance. 320 */ 321 322 function fromMatch(match) { 323 let type; 324 325 if (match[4]) { 326 type = 'self-closing'; 327 } else if (match[6]) { 328 type = 'closed'; 329 } else { 330 type = 'single'; 331 } 332 333 return new shortcode({ 334 tag: match[2], 335 attrs: match[3], 336 type, 337 content: match[5] 338 }); 339 } 340 /** 341 * Creates a shortcode instance. 342 * 343 * To access a raw representation of a shortcode, pass an `options` object, 344 * containing a `tag` string, a string or object of `attrs`, a string indicating 345 * the `type` of the shortcode ('single', 'self-closing', or 'closed'), and a 346 * `content` string. 347 * 348 * @param {Object} options Options as described. 349 * 350 * @return {WPShortcode} Shortcode instance. 351 */ 352 353 const shortcode = Object(lodash__WEBPACK_IMPORTED_MODULE_0__["extend"])(function (options) { 354 Object(lodash__WEBPACK_IMPORTED_MODULE_0__["extend"])(this, Object(lodash__WEBPACK_IMPORTED_MODULE_0__["pick"])(options || {}, 'tag', 'attrs', 'type', 'content')); 355 const attributes = this.attrs; // Ensure we have a correctly formatted `attrs` object. 356 357 this.attrs = { 358 named: {}, 359 numeric: [] 360 }; 361 362 if (!attributes) { 363 return; 364 } // Parse a string of attributes. 365 366 367 if (Object(lodash__WEBPACK_IMPORTED_MODULE_0__["isString"])(attributes)) { 368 this.attrs = attrs(attributes); // Identify a correctly formatted `attrs` object. 369 } else if (Object(lodash__WEBPACK_IMPORTED_MODULE_0__["isEqual"])(Object.keys(attributes), ['named', 'numeric'])) { 370 this.attrs = attributes; // Handle a flat object of attributes. 371 } else { 372 Object(lodash__WEBPACK_IMPORTED_MODULE_0__["forEach"])(attributes, (value, key) => { 373 this.set(key, value); 374 }); 375 } 376 }, { 377 next, 378 replace, 379 string, 380 regexp, 381 attrs, 382 fromMatch 383 }); 384 Object(lodash__WEBPACK_IMPORTED_MODULE_0__["extend"])(shortcode.prototype, { 385 /** 386 * Get a shortcode attribute. 387 * 388 * Automatically detects whether `attr` is named or numeric and routes it 389 * accordingly. 390 * 391 * @param {(number|string)} attr Attribute key. 392 * 393 * @return {string} Attribute value. 394 */ 395 get(attr) { 396 return this.attrs[Object(lodash__WEBPACK_IMPORTED_MODULE_0__["isNumber"])(attr) ? 'numeric' : 'named'][attr]; 397 }, 398 399 /** 400 * Set a shortcode attribute. 401 * 402 * Automatically detects whether `attr` is named or numeric and routes it 403 * accordingly. 404 * 405 * @param {(number|string)} attr Attribute key. 406 * @param {string} value Attribute value. 407 * 408 * @return {WPShortcode} Shortcode instance. 409 */ 410 set(attr, value) { 411 this.attrs[Object(lodash__WEBPACK_IMPORTED_MODULE_0__["isNumber"])(attr) ? 'numeric' : 'named'][attr] = value; 412 return this; 413 }, 414 415 /** 416 * Transform the shortcode into a string. 417 * 418 * @return {string} String representation of the shortcode. 419 */ 420 string() { 421 let text = '[' + this.tag; 422 Object(lodash__WEBPACK_IMPORTED_MODULE_0__["forEach"])(this.attrs.numeric, value => { 423 if (/\s/.test(value)) { 424 text += ' "' + value + '"'; 425 } else { 426 text += ' ' + value; 427 } 428 }); 429 Object(lodash__WEBPACK_IMPORTED_MODULE_0__["forEach"])(this.attrs.named, (value, name) => { 430 text += ' ' + name + '="' + value + '"'; 431 }); // If the tag is marked as `single` or `self-closing`, close the tag and 432 // ignore any additional content. 433 434 if ('single' === this.type) { 435 return text + ']'; 436 } else if ('self-closing' === this.type) { 437 return text + ' /]'; 438 } // Complete the opening tag. 439 440 441 text += ']'; 442 443 if (this.content) { 444 text += this.content; 445 } // Add the closing tag. 446 447 448 return text + '[/' + this.tag + ']'; 449 } 450 451 }); 452 /* harmony default export */ __webpack_exports__["default"] = (shortcode); 453 454 455 /***/ }), 456 457 /***/ "4eJC": 458 /***/ (function(module, exports, __webpack_require__) { 459 460 /** 461 * Memize options object. 462 * 463 * @typedef MemizeOptions 464 * 465 * @property {number} [maxSize] Maximum size of the cache. 466 */ 467 468 /** 469 * Internal cache entry. 470 * 471 * @typedef MemizeCacheNode 472 * 473 * @property {?MemizeCacheNode|undefined} [prev] Previous node. 474 * @property {?MemizeCacheNode|undefined} [next] Next node. 475 * @property {Array<*>} args Function arguments for cache 476 * entry. 477 * @property {*} val Function result. 478 */ 479 480 /** 481 * Properties of the enhanced function for controlling cache. 482 * 483 * @typedef MemizeMemoizedFunction 484 * 485 * @property {()=>void} clear Clear the cache. 486 */ 487 488 /** 489 * Accepts a function to be memoized, and returns a new memoized function, with 490 * optional options. 491 * 492 * @template {Function} F 493 * 494 * @param {F} fn Function to memoize. 495 * @param {MemizeOptions} [options] Options object. 496 * 497 * @return {F & MemizeMemoizedFunction} Memoized function. 498 */ 499 function memize( fn, options ) { 500 var size = 0; 501 502 /** @type {?MemizeCacheNode|undefined} */ 503 var head; 504 505 /** @type {?MemizeCacheNode|undefined} */ 506 var tail; 507 508 options = options || {}; 509 510 function memoized( /* ...args */ ) { 511 var node = head, 512 len = arguments.length, 513 args, i; 514 515 searchCache: while ( node ) { 516 // Perform a shallow equality test to confirm that whether the node 517 // under test is a candidate for the arguments passed. Two arrays 518 // are shallowly equal if their length matches and each entry is 519 // strictly equal between the two sets. Avoid abstracting to a 520 // function which could incur an arguments leaking deoptimization. 521 522 // Check whether node arguments match arguments length 523 if ( node.args.length !== arguments.length ) { 524 node = node.next; 525 continue; 526 } 527 528 // Check whether node arguments match arguments values 529 for ( i = 0; i < len; i++ ) { 530 if ( node.args[ i ] !== arguments[ i ] ) { 531 node = node.next; 532 continue searchCache; 533 } 534 } 535 536 // At this point we can assume we've found a match 537 538 // Surface matched node to head if not already 539 if ( node !== head ) { 540 // As tail, shift to previous. Must only shift if not also 541 // head, since if both head and tail, there is no previous. 542 if ( node === tail ) { 543 tail = node.prev; 544 } 545 546 // Adjust siblings to point to each other. If node was tail, 547 // this also handles new tail's empty `next` assignment. 548 /** @type {MemizeCacheNode} */ ( node.prev ).next = node.next; 549 if ( node.next ) { 550 node.next.prev = node.prev; 551 } 552 553 node.next = head; 554 node.prev = null; 555 /** @type {MemizeCacheNode} */ ( head ).prev = node; 556 head = node; 557 } 558 559 // Return immediately 560 return node.val; 561 } 562 563 // No cached value found. Continue to insertion phase: 564 565 // Create a copy of arguments (avoid leaking deoptimization) 566 args = new Array( len ); 567 for ( i = 0; i < len; i++ ) { 568 args[ i ] = arguments[ i ]; 569 } 570 571 node = { 572 args: args, 573 574 // Generate the result from original function 575 val: fn.apply( null, args ), 576 }; 577 578 // Don't need to check whether node is already head, since it would 579 // have been returned above already if it was 580 581 // Shift existing head down list 582 if ( head ) { 583 head.prev = node; 584 node.next = head; 585 } else { 586 // If no head, follows that there's no tail (at initial or reset) 587 tail = node; 588 } 589 590 // Trim tail if we're reached max size and are pending cache insertion 591 if ( size === /** @type {MemizeOptions} */ ( options ).maxSize ) { 592 tail = /** @type {MemizeCacheNode} */ ( tail ).prev; 593 /** @type {MemizeCacheNode} */ ( tail ).next = null; 594 } else { 595 size++; 596 } 597 598 head = node; 599 600 return node.val; 601 } 602 603 memoized.clear = function() { 604 head = null; 605 tail = null; 606 size = 0; 607 }; 608 609 if ( false ) {} 610 611 // Ignore reason: There's not a clear solution to create an intersection of 612 // the function with additional properties, where the goal is to retain the 613 // function signature of the incoming argument and add control properties 614 // on the return value. 615 616 // @ts-ignore 617 return memoized; 618 } 619 620 module.exports = memize; 621 622 623 /***/ }), 624 625 /***/ "YLtl": 626 /***/ (function(module, exports) { 627 628 (function() { module.exports = window["lodash"]; }()); 629 630 /***/ }) 631 632 /******/ })["default"];