@wordpress/shortcode 4.37.1-next.ba3aee3a2.0 → 4.37.1-next.v.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.
package/README.md CHANGED
@@ -32,7 +32,7 @@ _Parameters_
32
32
 
33
33
  _Returns_
34
34
 
35
- - `import('./types').ShortcodeAttrs`: Parsed shortcode attributes.
35
+ - `ShortcodeAttrs`: Parsed shortcode attributes.
36
36
 
37
37
  ### default
38
38
 
@@ -42,7 +42,7 @@ To access a raw representation of a shortcode, pass an `options` object, contain
42
42
 
43
43
  _Type_
44
44
 
45
- - `import('./types').shortcode`Shortcode instance.
45
+ - `Shortcode`
46
46
 
47
47
  ### fromMatch
48
48
 
@@ -52,11 +52,11 @@ Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated by
52
52
 
53
53
  _Parameters_
54
54
 
55
- - _match_ `import('./types').Match`: Match array.
55
+ - _match_ `Match`: Match array.
56
56
 
57
57
  _Returns_
58
58
 
59
- - `InstanceType<import('./types').shortcode>`: Shortcode instance.
59
+ - `ShortcodeInstance`: Shortcode instance.
60
60
 
61
61
  ### next
62
62
 
@@ -70,7 +70,7 @@ _Parameters_
70
70
 
71
71
  _Returns_
72
72
 
73
- - `import('./types').ShortcodeMatch | undefined`: Matched information.
73
+ - `ShortcodeMatch | undefined`: Matched information.
74
74
 
75
75
  ### regexp
76
76
 
@@ -104,11 +104,11 @@ _Parameters_
104
104
 
105
105
  - _tag_ `string`: Shortcode tag.
106
106
  - _text_ `string`: Text to search.
107
- - _callback_ `import('./types').ReplaceCallback`: Function to process the match and return replacement string.
107
+ - _callback_ `ReplaceCallback`: Function to process the match and return replacement string.
108
108
 
109
109
  _Returns_
110
110
 
111
- - `string`: Text with shortcodes replaced.
111
+ - Text with shortcodes replaced.
112
112
 
113
113
  ### string
114
114
 
@@ -120,7 +120,7 @@ Accepts the same `options` as the `shortcode()` constructor, containing a `tag`
120
120
 
121
121
  _Parameters_
122
122
 
123
- - _options_ `Object`:
123
+ - _options_ `ShortcodeOptions`: Shortcode options.
124
124
 
125
125
  _Returns_
126
126
 
package/build/index.cjs CHANGED
@@ -28,7 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  ));
29
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
30
 
31
- // packages/shortcode/src/index.js
31
+ // packages/shortcode/src/index.ts
32
32
  var index_exports = {};
33
33
  __export(index_exports, {
34
34
  attrs: () => attrs,
@@ -69,17 +69,21 @@ function next(tag, text, index = 0) {
69
69
  function replace(tag, text, callback) {
70
70
  return text.replace(
71
71
  regexp(tag),
72
- function(match, left, $3, attrs2, slash, content, closing, right) {
72
+ // Let us use spread syntax to capture the arguments object.
73
+ (...args) => {
74
+ const match = args[0];
75
+ const left = args[1];
76
+ const right = args[7];
73
77
  if (left === "[" && right === "]") {
74
78
  return match;
75
79
  }
76
- const result = callback(fromMatch(arguments));
80
+ const result = callback(fromMatch(args));
77
81
  return result || result === "" ? left + result + right : match;
78
82
  }
79
83
  );
80
84
  }
81
85
  function string(options) {
82
- return new shortcode(options).string();
86
+ return new Shortcode(options).string();
83
87
  }
84
88
  function regexp(tag) {
85
89
  return new RegExp(
@@ -119,17 +123,31 @@ function fromMatch(match) {
119
123
  } else {
120
124
  type = "single";
121
125
  }
122
- return new shortcode({
126
+ return new Shortcode({
123
127
  tag: match[2],
124
128
  attrs: match[3],
125
129
  type,
126
130
  content: match[5]
127
131
  });
128
132
  }
129
- var shortcode = Object.assign(
130
- function(options) {
131
- const { tag, attrs: attributes, type, content } = options || {};
132
- Object.assign(this, { tag, type, content });
133
+ var Shortcode = class {
134
+ // Instance properties
135
+ tag;
136
+ type;
137
+ content;
138
+ attrs;
139
+ // Static methods
140
+ static next = next;
141
+ static replace = replace;
142
+ static string = string;
143
+ static regexp = regexp;
144
+ static attrs = attrs;
145
+ static fromMatch = fromMatch;
146
+ constructor(options) {
147
+ const { tag, attrs: attributes, type, content } = options;
148
+ this.tag = tag;
149
+ this.type = type;
150
+ this.content = content;
133
151
  this.attrs = {
134
152
  named: {},
135
153
  numeric: []
@@ -137,59 +155,57 @@ var shortcode = Object.assign(
137
155
  if (!attributes) {
138
156
  return;
139
157
  }
140
- const attributeTypes = ["named", "numeric"];
141
158
  if (typeof attributes === "string") {
142
159
  this.attrs = attrs(attributes);
143
- } else if (attributes.length === attributeTypes.length && attributeTypes.every((t, key) => t === attributes[key])) {
160
+ } else if ("named" in attributes && "numeric" in attributes && attributes.named !== void 0 && attributes.numeric !== void 0) {
144
161
  this.attrs = attributes;
145
162
  } else {
146
163
  Object.entries(attributes).forEach(([key, value]) => {
147
- this.set(key, value);
164
+ if (typeof value === "string" || typeof value === "undefined") {
165
+ this.set(key, value);
166
+ }
148
167
  });
149
168
  }
150
- },
151
- {
152
- next,
153
- replace,
154
- string,
155
- regexp,
156
- attrs,
157
- fromMatch
158
169
  }
159
- );
160
- Object.assign(shortcode.prototype, {
161
170
  /**
162
171
  * Get a shortcode attribute.
163
172
  *
164
173
  * Automatically detects whether `attr` is named or numeric and routes it
165
174
  * accordingly.
166
175
  *
167
- * @param {(number|string)} attr Attribute key.
176
+ * @param attr Attribute key.
168
177
  *
169
- * @return {string} Attribute value.
178
+ * @return Attribute value.
170
179
  */
171
180
  get(attr) {
172
- return this.attrs[typeof attr === "number" ? "numeric" : "named"][attr];
173
- },
181
+ if (typeof attr === "number") {
182
+ return this.attrs.numeric[attr];
183
+ }
184
+ return this.attrs.named[attr];
185
+ }
174
186
  /**
175
187
  * Set a shortcode attribute.
176
188
  *
177
189
  * Automatically detects whether `attr` is named or numeric and routes it
178
190
  * accordingly.
179
191
  *
180
- * @param {(number|string)} attr Attribute key.
181
- * @param {string} value Attribute value.
192
+ * @param attr Attribute key.
193
+ * @param value Attribute value.
182
194
  *
183
- * @return {InstanceType< import('./types').shortcode >} Shortcode instance.
195
+ * @return Shortcode instance.
184
196
  */
185
197
  set(attr, value) {
186
- this.attrs[typeof attr === "number" ? "numeric" : "named"][attr] = value;
198
+ if (typeof attr === "number") {
199
+ this.attrs.numeric[attr] = value;
200
+ } else {
201
+ this.attrs.named[attr] = value;
202
+ }
187
203
  return this;
188
- },
204
+ }
189
205
  /**
190
206
  * Transform the shortcode into a string.
191
207
  *
192
- * @return {string} String representation of the shortcode.
208
+ * @return String representation of the shortcode.
193
209
  */
194
210
  string() {
195
211
  let text = "[" + this.tag;
@@ -214,8 +230,8 @@ Object.assign(shortcode.prototype, {
214
230
  }
215
231
  return text + "[/" + this.tag + "]";
216
232
  }
217
- });
218
- var index_default = shortcode;
233
+ };
234
+ var index_default = Shortcode;
219
235
  // Annotate the CommonJS export names for ESM import in node:
220
236
  0 && (module.exports = {
221
237
  attrs,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/index.js"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport memize from 'memize';\n\nexport * from './types';\n\n/**\n * Find the next matching shortcode.\n *\n * @param {string} tag Shortcode tag.\n * @param {string} text Text to search.\n * @param {number} index Index to start search from.\n *\n * @return {import('./types').ShortcodeMatch | undefined} Matched information.\n */\nexport function next( tag, text, index = 0 ) {\n\tconst re = regexp( tag );\n\n\tre.lastIndex = index;\n\n\tconst match = re.exec( text );\n\n\tif ( ! match ) {\n\t\treturn;\n\t}\n\n\t// If we matched an escaped shortcode, try again.\n\tif ( '[' === match[ 1 ] && ']' === match[ 7 ] ) {\n\t\treturn next( tag, text, re.lastIndex );\n\t}\n\n\tconst result = {\n\t\tindex: match.index,\n\t\tcontent: match[ 0 ],\n\t\tshortcode: fromMatch( match ),\n\t};\n\n\t// If we matched a leading `[`, strip it from the match and increment the\n\t// index accordingly.\n\tif ( match[ 1 ] ) {\n\t\tresult.content = result.content.slice( 1 );\n\t\tresult.index++;\n\t}\n\n\t// If we matched a trailing `]`, strip it from the match.\n\tif ( match[ 7 ] ) {\n\t\tresult.content = result.content.slice( 0, -1 );\n\t}\n\n\treturn result;\n}\n\n/**\n * Replace matching shortcodes in a block of text.\n *\n * @param {string} tag Shortcode tag.\n * @param {string} text Text to search.\n * @param {import('./types').ReplaceCallback} callback Function to process the match and return\n * replacement string.\n *\n * @return {string} Text with shortcodes replaced.\n */\nexport function replace( tag, text, callback ) {\n\treturn text.replace(\n\t\tregexp( tag ),\n\t\tfunction ( match, left, $3, attrs, slash, content, closing, right ) {\n\t\t\t// If both extra brackets exist, the shortcode has been properly\n\t\t\t// escaped.\n\t\t\tif ( left === '[' && right === ']' ) {\n\t\t\t\treturn match;\n\t\t\t}\n\n\t\t\t// Create the match object and pass it through the callback.\n\t\t\tconst result = callback( fromMatch( arguments ) );\n\n\t\t\t// Make sure to return any of the extra brackets if they weren't used to\n\t\t\t// escape the shortcode.\n\t\t\treturn result || result === '' ? left + result + right : match;\n\t\t}\n\t);\n}\n\n/**\n * Generate a string from shortcode parameters.\n *\n * Creates a shortcode instance and returns a string.\n *\n * Accepts the same `options` as the `shortcode()` constructor, containing a\n * `tag` string, a string or object of `attrs`, a boolean indicating whether to\n * format the shortcode using a `single` tag, and a `content` string.\n *\n * @param {Object} options\n *\n * @return {string} String representation of the shortcode.\n */\nexport function string( options ) {\n\treturn new shortcode( options ).string();\n}\n\n/**\n * Generate a RegExp to identify a shortcode.\n *\n * The base regex is functionally equivalent to the one found in\n * `get_shortcode_regex()` in `wp-includes/shortcodes.php`.\n *\n * Capture groups:\n *\n * 1. An extra `[` to allow for escaping shortcodes with double `[[]]`\n * 2. The shortcode name\n * 3. The shortcode argument list\n * 4. The self closing `/`\n * 5. The content of a shortcode when it wraps some content.\n * 6. The closing tag.\n * 7. An extra `]` to allow for escaping shortcodes with double `[[]]`\n *\n * @param {string} tag Shortcode tag.\n *\n * @return {RegExp} Shortcode RegExp.\n */\nexport function regexp( tag ) {\n\treturn new RegExp(\n\t\t'\\\\[(\\\\[?)(' +\n\t\t\ttag +\n\t\t\t')(?![\\\\w-])([^\\\\]\\\\/]*(?:\\\\/(?!\\\\])[^\\\\]\\\\/]*)*?)(?:(\\\\/)\\\\]|\\\\](?:([^\\\\[]*(?:\\\\[(?!\\\\/\\\\2\\\\])[^\\\\[]*)*)(\\\\[\\\\/\\\\2\\\\]))?)(\\\\]?)',\n\t\t'g'\n\t);\n}\n\n/**\n * Parse shortcode attributes.\n *\n * Shortcodes accept many types of attributes. These can chiefly be divided into\n * named and numeric attributes:\n *\n * Named attributes are assigned on a key/value basis, while numeric attributes\n * are treated as an array.\n *\n * Named attributes can be formatted as either `name=\"value\"`, `name='value'`,\n * or `name=value`. Numeric attributes can be formatted as `\"value\"` or just\n * `value`.\n *\n * @param {string} text Serialised shortcode attributes.\n *\n * @return {import('./types').ShortcodeAttrs} Parsed shortcode attributes.\n */\nexport const attrs = memize( ( text ) => {\n\tconst named = {};\n\tconst numeric = [];\n\n\t// This regular expression is reused from `shortcode_parse_atts()` in\n\t// `wp-includes/shortcodes.php`.\n\t//\n\t// Capture groups:\n\t//\n\t// 1. An attribute name, that corresponds to...\n\t// 2. a value in double quotes.\n\t// 3. An attribute name, that corresponds to...\n\t// 4. a value in single quotes.\n\t// 5. An attribute name, that corresponds to...\n\t// 6. an unquoted value.\n\t// 7. A numeric attribute in double quotes.\n\t// 8. A numeric attribute in single quotes.\n\t// 9. An unquoted numeric attribute.\n\tconst pattern =\n\t\t/([\\w-]+)\\s*=\\s*\"([^\"]*)\"(?:\\s|$)|([\\w-]+)\\s*=\\s*'([^']*)'(?:\\s|$)|([\\w-]+)\\s*=\\s*([^\\s'\"]+)(?:\\s|$)|\"([^\"]*)\"(?:\\s|$)|'([^']*)'(?:\\s|$)|(\\S+)(?:\\s|$)/g;\n\n\t// Map zero-width spaces to actual spaces.\n\ttext = text.replace( /[\\u00a0\\u200b]/g, ' ' );\n\n\tlet match;\n\n\t// Match and normalize attributes.\n\twhile ( ( match = pattern.exec( text ) ) ) {\n\t\tif ( match[ 1 ] ) {\n\t\t\tnamed[ match[ 1 ].toLowerCase() ] = match[ 2 ];\n\t\t} else if ( match[ 3 ] ) {\n\t\t\tnamed[ match[ 3 ].toLowerCase() ] = match[ 4 ];\n\t\t} else if ( match[ 5 ] ) {\n\t\t\tnamed[ match[ 5 ].toLowerCase() ] = match[ 6 ];\n\t\t} else if ( match[ 7 ] ) {\n\t\t\tnumeric.push( match[ 7 ] );\n\t\t} else if ( match[ 8 ] ) {\n\t\t\tnumeric.push( match[ 8 ] );\n\t\t} else if ( match[ 9 ] ) {\n\t\t\tnumeric.push( match[ 9 ] );\n\t\t}\n\t}\n\n\treturn { named, numeric };\n} );\n\n/**\n * Generate a Shortcode Object from a RegExp match.\n *\n * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated\n * by `regexp()`. `match` can also be set to the `arguments` from a callback\n * passed to `regexp.replace()`.\n *\n * @param {import('./types').Match} match Match array.\n *\n * @return {InstanceType<import('./types').shortcode>} Shortcode instance.\n */\nexport function fromMatch( match ) {\n\tlet type;\n\n\tif ( match[ 4 ] ) {\n\t\ttype = 'self-closing';\n\t} else if ( match[ 6 ] ) {\n\t\ttype = 'closed';\n\t} else {\n\t\ttype = 'single';\n\t}\n\n\treturn new shortcode( {\n\t\ttag: match[ 2 ],\n\t\tattrs: match[ 3 ],\n\t\ttype,\n\t\tcontent: match[ 5 ],\n\t} );\n}\n\n/**\n * Creates a shortcode instance.\n *\n * To access a raw representation of a shortcode, pass an `options` object,\n * containing a `tag` string, a string or object of `attrs`, a string indicating\n * the `type` of the shortcode ('single', 'self-closing', or 'closed'), and a\n * `content` string.\n *\n * @type {import('./types').shortcode} Shortcode instance.\n */\nconst shortcode = Object.assign(\n\tfunction ( options ) {\n\t\tconst { tag, attrs: attributes, type, content } = options || {};\n\t\tObject.assign( this, { tag, type, content } );\n\n\t\t// Ensure we have a correctly formatted `attrs` object.\n\t\tthis.attrs = {\n\t\t\tnamed: {},\n\t\t\tnumeric: [],\n\t\t};\n\n\t\tif ( ! attributes ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst attributeTypes = [ 'named', 'numeric' ];\n\n\t\t// Parse a string of attributes.\n\t\tif ( typeof attributes === 'string' ) {\n\t\t\tthis.attrs = attrs( attributes );\n\t\t\t// Identify a correctly formatted `attrs` object.\n\t\t} else if (\n\t\t\tattributes.length === attributeTypes.length &&\n\t\t\tattributeTypes.every( ( t, key ) => t === attributes[ key ] )\n\t\t) {\n\t\t\tthis.attrs = attributes;\n\t\t\t// Handle a flat object of attributes.\n\t\t} else {\n\t\t\tObject.entries( attributes ).forEach( ( [ key, value ] ) => {\n\t\t\t\tthis.set( key, value );\n\t\t\t} );\n\t\t}\n\t},\n\t{\n\t\tnext,\n\t\treplace,\n\t\tstring,\n\t\tregexp,\n\t\tattrs,\n\t\tfromMatch,\n\t}\n);\n\nObject.assign( shortcode.prototype, {\n\t/**\n\t * Get a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param {(number|string)} attr Attribute key.\n\t *\n\t * @return {string} Attribute value.\n\t */\n\tget( attr ) {\n\t\treturn this.attrs[ typeof attr === 'number' ? 'numeric' : 'named' ][\n\t\t\tattr\n\t\t];\n\t},\n\n\t/**\n\t * Set a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param {(number|string)} attr Attribute key.\n\t * @param {string} value Attribute value.\n\t *\n\t * @return {InstanceType< import('./types').shortcode >} Shortcode instance.\n\t */\n\tset( attr, value ) {\n\t\tthis.attrs[ typeof attr === 'number' ? 'numeric' : 'named' ][ attr ] =\n\t\t\tvalue;\n\t\treturn this;\n\t},\n\n\t/**\n\t * Transform the shortcode into a string.\n\t *\n\t * @return {string} String representation of the shortcode.\n\t */\n\tstring() {\n\t\tlet text = '[' + this.tag;\n\n\t\tthis.attrs.numeric.forEach( ( value ) => {\n\t\t\tif ( /\\s/.test( value ) ) {\n\t\t\t\ttext += ' \"' + value + '\"';\n\t\t\t} else {\n\t\t\t\ttext += ' ' + value;\n\t\t\t}\n\t\t} );\n\n\t\tObject.entries( this.attrs.named ).forEach( ( [ name, value ] ) => {\n\t\t\ttext += ' ' + name + '=\"' + value + '\"';\n\t\t} );\n\n\t\t// If the tag is marked as `single` or `self-closing`, close the tag and\n\t\t// ignore any additional content.\n\t\tif ( 'single' === this.type ) {\n\t\t\treturn text + ']';\n\t\t} else if ( 'self-closing' === this.type ) {\n\t\t\treturn text + ' /]';\n\t\t}\n\n\t\t// Complete the opening tag.\n\t\ttext += ']';\n\n\t\tif ( this.content ) {\n\t\t\ttext += this.content;\n\t\t}\n\n\t\t// Add the closing tag.\n\t\treturn text + '[/' + this.tag + ']';\n\t},\n} );\n\nexport default shortcode;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAmB;AAEnB,0BAAc,wBALd;AAgBO,SAAS,KAAM,KAAK,MAAM,QAAQ,GAAI;AAC5C,QAAM,KAAK,OAAQ,GAAI;AAEvB,KAAG,YAAY;AAEf,QAAM,QAAQ,GAAG,KAAM,IAAK;AAE5B,MAAK,CAAE,OAAQ;AACd;AAAA,EACD;AAGA,MAAK,QAAQ,MAAO,CAAE,KAAK,QAAQ,MAAO,CAAE,GAAI;AAC/C,WAAO,KAAM,KAAK,MAAM,GAAG,SAAU;AAAA,EACtC;AAEA,QAAM,SAAS;AAAA,IACd,OAAO,MAAM;AAAA,IACb,SAAS,MAAO,CAAE;AAAA,IAClB,WAAW,UAAW,KAAM;AAAA,EAC7B;AAIA,MAAK,MAAO,CAAE,GAAI;AACjB,WAAO,UAAU,OAAO,QAAQ,MAAO,CAAE;AACzC,WAAO;AAAA,EACR;AAGA,MAAK,MAAO,CAAE,GAAI;AACjB,WAAO,UAAU,OAAO,QAAQ,MAAO,GAAG,EAAG;AAAA,EAC9C;AAEA,SAAO;AACR;AAYO,SAAS,QAAS,KAAK,MAAM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MAAO,OAAO,SAAS,WAAW,YAAY,OAAQ,EACjE,IACD;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,IAAK,MAAM,OAAQ;AAClB,SAAK,MAAO,OAAO,SAAS,WAAW,YAAY,OAAQ,EAAG,IAAK,IAClE;AACD,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,SAAS;AACR,QAAI,OAAO,MAAM,KAAK;AAEtB,SAAK,MAAM,QAAQ,QAAS,CAAE,UAAW;AACxC,UAAK,KAAK,KAAM,KAAM,GAAI;AACzB,gBAAQ,OAAO,QAAQ;AAAA,MACxB,OAAO;AACN,gBAAQ,MAAM;AAAA,MACf;AAAA,IACD,CAAE;AAEF,WAAO,QAAS,KAAK,MAAM,KAAM,EAAE,QAAS,CAAE,CAAE,MAAM,KAAM,MAAO;AAClE,cAAQ,MAAM,OAAO,OAAO,QAAQ;AAAA,IACrC,CAAE;AAIF,QAAK,aAAa,KAAK,MAAO;AAC7B,aAAO,OAAO;AAAA,IACf,WAAY,mBAAmB,KAAK,MAAO;AAC1C,aAAO,OAAO;AAAA,IACf;AAGA,YAAQ;AAER,QAAK,KAAK,SAAU;AACnB,cAAQ,KAAK;AAAA,IACd;AAGA,WAAO,OAAO,OAAO,KAAK,MAAM;AAAA,EACjC;AACD,CAAE;AAEF,IAAO,gBAAQ;",
6
- "names": ["attrs", "memize"]
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport memize from 'memize';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tShortcodeAttrs,\n\tShortcodeMatch,\n\tShortcodeOptions,\n\tMatch,\n\tReplaceCallback,\n\tShortcodeInstance,\n} from './types';\n\nexport * from './types';\n\n/**\n * Find the next matching shortcode.\n *\n * @param tag Shortcode tag.\n * @param text Text to search.\n * @param index Index to start search from.\n *\n * @return Matched information.\n */\nexport function next(\n\ttag: string,\n\ttext: string,\n\tindex: number = 0\n): ShortcodeMatch | undefined {\n\tconst re = regexp( tag );\n\n\tre.lastIndex = index;\n\n\tconst match = re.exec( text );\n\n\tif ( ! match ) {\n\t\treturn;\n\t}\n\n\t// If we matched an escaped shortcode, try again.\n\tif ( '[' === match[ 1 ] && ']' === match[ 7 ] ) {\n\t\treturn next( tag, text, re.lastIndex );\n\t}\n\n\tconst result: ShortcodeMatch = {\n\t\tindex: match.index,\n\t\tcontent: match[ 0 ],\n\t\tshortcode: fromMatch( match ),\n\t};\n\n\t// If we matched a leading `[`, strip it from the match and increment the\n\t// index accordingly.\n\tif ( match[ 1 ] ) {\n\t\tresult.content = result.content.slice( 1 );\n\t\tresult.index++;\n\t}\n\n\t// If we matched a trailing `]`, strip it from the match.\n\tif ( match[ 7 ] ) {\n\t\tresult.content = result.content.slice( 0, -1 );\n\t}\n\n\treturn result;\n}\n\n/**\n * Replace matching shortcodes in a block of text.\n *\n * @param tag Shortcode tag.\n * @param text Text to search.\n * @param callback Function to process the match and return\n * replacement string.\n *\n * @return Text with shortcodes replaced.\n */\nexport function replace(\n\ttag: string,\n\ttext: string,\n\tcallback: ReplaceCallback\n) {\n\treturn text.replace(\n\t\tregexp( tag ),\n\t\t// Let us use spread syntax to capture the arguments object.\n\t\t( ...args: string[] ): string => {\n\t\t\tconst match = args[ 0 ];\n\t\t\tconst left = args[ 1 ];\n\t\t\tconst right = args[ 7 ];\n\n\t\t\t// If both extra brackets exist, the shortcode has been properly\n\t\t\t// escaped.\n\t\t\tif ( left === '[' && right === ']' ) {\n\t\t\t\treturn match;\n\t\t\t}\n\n\t\t\t// Create the match object and pass it through the callback.\n\t\t\tconst result = callback( fromMatch( args ) );\n\n\t\t\t// Make sure to return any of the extra brackets if they weren't used to\n\t\t\t// escape the shortcode.\n\t\t\treturn result || result === '' ? left + result + right : match;\n\t\t}\n\t);\n}\n\n/**\n * Generate a string from shortcode parameters.\n *\n * Creates a shortcode instance and returns a string.\n *\n * Accepts the same `options` as the `shortcode()` constructor, containing a\n * `tag` string, a string or object of `attrs`, a boolean indicating whether to\n * format the shortcode using a `single` tag, and a `content` string.\n *\n * @param options Shortcode options.\n *\n * @return String representation of the shortcode.\n */\nexport function string( options: ShortcodeOptions ): string {\n\treturn new Shortcode( options ).string();\n}\n\n/**\n * Generate a RegExp to identify a shortcode.\n *\n * The base regex is functionally equivalent to the one found in\n * `get_shortcode_regex()` in `wp-includes/shortcodes.php`.\n *\n * Capture groups:\n *\n * 1. An extra `[` to allow for escaping shortcodes with double `[[]]`\n * 2. The shortcode name\n * 3. The shortcode argument list\n * 4. The self closing `/`\n * 5. The content of a shortcode when it wraps some content.\n * 6. The closing tag.\n * 7. An extra `]` to allow for escaping shortcodes with double `[[]]`\n *\n * @param tag Shortcode tag.\n *\n * @return Shortcode RegExp.\n */\nexport function regexp( tag: string ): RegExp {\n\treturn new RegExp(\n\t\t'\\\\[(\\\\[?)(' +\n\t\t\ttag +\n\t\t\t')(?![\\\\w-])([^\\\\]\\\\/]*(?:\\\\/(?!\\\\])[^\\\\]\\\\/]*)*?)(?:(\\\\/)\\\\]|\\\\](?:([^\\\\[]*(?:\\\\[(?!\\\\/\\\\2\\\\])[^\\\\[]*)*)(\\\\[\\\\/\\\\2\\\\]))?)(\\\\]?)',\n\t\t'g'\n\t);\n}\n\n/**\n * Parse shortcode attributes.\n *\n * Shortcodes accept many types of attributes. These can chiefly be divided into\n * named and numeric attributes:\n *\n * Named attributes are assigned on a key/value basis, while numeric attributes\n * are treated as an array.\n *\n * Named attributes can be formatted as either `name=\"value\"`, `name='value'`,\n * or `name=value`. Numeric attributes can be formatted as `\"value\"` or just\n * `value`.\n *\n * @param {string} text Serialised shortcode attributes.\n *\n * @return {ShortcodeAttrs} Parsed shortcode attributes.\n */\nexport const attrs = memize( ( text: string ): ShortcodeAttrs => {\n\tconst named: Record< string, string | undefined > = {};\n\tconst numeric: string[] = [];\n\n\t// This regular expression is reused from `shortcode_parse_atts()` in\n\t// `wp-includes/shortcodes.php`.\n\t//\n\t// Capture groups:\n\t//\n\t// 1. An attribute name, that corresponds to...\n\t// 2. a value in double quotes.\n\t// 3. An attribute name, that corresponds to...\n\t// 4. a value in single quotes.\n\t// 5. An attribute name, that corresponds to...\n\t// 6. an unquoted value.\n\t// 7. A numeric attribute in double quotes.\n\t// 8. A numeric attribute in single quotes.\n\t// 9. An unquoted numeric attribute.\n\tconst pattern =\n\t\t/([\\w-]+)\\s*=\\s*\"([^\"]*)\"(?:\\s|$)|([\\w-]+)\\s*=\\s*'([^']*)'(?:\\s|$)|([\\w-]+)\\s*=\\s*([^\\s'\"]+)(?:\\s|$)|\"([^\"]*)\"(?:\\s|$)|'([^']*)'(?:\\s|$)|(\\S+)(?:\\s|$)/g;\n\n\t// Map zero-width spaces to actual spaces.\n\ttext = text.replace( /[\\u00a0\\u200b]/g, ' ' );\n\n\tlet match;\n\n\t// Match and normalize attributes.\n\twhile ( ( match = pattern.exec( text ) ) ) {\n\t\tif ( match[ 1 ] ) {\n\t\t\tnamed[ match[ 1 ].toLowerCase() ] = match[ 2 ];\n\t\t} else if ( match[ 3 ] ) {\n\t\t\tnamed[ match[ 3 ].toLowerCase() ] = match[ 4 ];\n\t\t} else if ( match[ 5 ] ) {\n\t\t\tnamed[ match[ 5 ].toLowerCase() ] = match[ 6 ];\n\t\t} else if ( match[ 7 ] ) {\n\t\t\tnumeric.push( match[ 7 ] );\n\t\t} else if ( match[ 8 ] ) {\n\t\t\tnumeric.push( match[ 8 ] );\n\t\t} else if ( match[ 9 ] ) {\n\t\t\tnumeric.push( match[ 9 ] );\n\t\t}\n\t}\n\n\treturn { named, numeric };\n} );\n\n/**\n * Generate a Shortcode Object from a RegExp match.\n *\n * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated\n * by `regexp()`. `match` can also be set to the `arguments` from a callback\n * passed to `regexp.replace()`.\n *\n * @param match Match array.\n *\n * @return Shortcode instance.\n */\nexport function fromMatch( match: Match ): ShortcodeInstance {\n\tlet type: 'self-closing' | 'closed' | 'single';\n\n\tif ( match[ 4 ] ) {\n\t\ttype = 'self-closing';\n\t} else if ( match[ 6 ] ) {\n\t\ttype = 'closed';\n\t} else {\n\t\ttype = 'single';\n\t}\n\n\treturn new Shortcode( {\n\t\ttag: match[ 2 ],\n\t\tattrs: match[ 3 ],\n\t\ttype,\n\t\tcontent: match[ 5 ],\n\t} );\n}\n\n/**\n * Creates a shortcode instance.\n *\n * To access a raw representation of a shortcode, pass an `options` object,\n * containing a `tag` string, a string or object of `attrs`, a string indicating\n * the `type` of the shortcode ('single', 'self-closing', or 'closed'), and a\n * `content` string.\n */\nclass Shortcode implements ShortcodeInstance {\n\t// Instance properties\n\ttag: string;\n\ttype?: 'self-closing' | 'closed' | 'single';\n\tcontent?: string;\n\tattrs: ShortcodeAttrs;\n\n\t// Static methods\n\tstatic next = next;\n\tstatic replace = replace;\n\tstatic string = string;\n\tstatic regexp = regexp;\n\tstatic attrs = attrs;\n\tstatic fromMatch = fromMatch;\n\n\tconstructor( options: ShortcodeOptions ) {\n\t\tconst { tag, attrs: attributes, type, content } = options;\n\t\tthis.tag = tag;\n\t\tthis.type = type;\n\t\tthis.content = content;\n\n\t\t// Ensure we have a correctly formatted `attrs` object.\n\t\tthis.attrs = {\n\t\t\tnamed: {},\n\t\t\tnumeric: [],\n\t\t};\n\n\t\tif ( ! attributes ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Parse a string of attributes.\n\t\tif ( typeof attributes === 'string' ) {\n\t\t\tthis.attrs = attrs( attributes );\n\t\t\t// Identify a correctly formatted `attrs` object.\n\t\t} else if (\n\t\t\t'named' in attributes &&\n\t\t\t'numeric' in attributes &&\n\t\t\tattributes.named !== undefined &&\n\t\t\tattributes.numeric !== undefined\n\t\t) {\n\t\t\tthis.attrs = attributes as ShortcodeAttrs;\n\t\t\t// Handle a flat object of attributes (e.g., { foo: 'bar', baz: 'qux' }).\n\t\t} else {\n\t\t\tObject.entries( attributes ).forEach( ( [ key, value ] ) => {\n\t\t\t\tif (\n\t\t\t\t\ttypeof value === 'string' ||\n\t\t\t\t\ttypeof value === 'undefined'\n\t\t\t\t) {\n\t\t\t\t\tthis.set( key, value );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\t}\n\n\t/**\n\t * Get a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param attr Attribute key.\n\t *\n\t * @return Attribute value.\n\t */\n\tget( attr: string | number ): string | undefined {\n\t\tif ( typeof attr === 'number' ) {\n\t\t\treturn this.attrs.numeric[ attr ];\n\t\t}\n\t\treturn this.attrs.named[ attr ];\n\t}\n\n\t/**\n\t * Set a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param attr Attribute key.\n\t * @param value Attribute value.\n\t *\n\t * @return Shortcode instance.\n\t */\n\tset( attr: string | number, value: string ): this {\n\t\tif ( typeof attr === 'number' ) {\n\t\t\tthis.attrs.numeric[ attr ] = value;\n\t\t} else {\n\t\t\tthis.attrs.named[ attr ] = value;\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Transform the shortcode into a string.\n\t *\n\t * @return String representation of the shortcode.\n\t */\n\tstring(): string {\n\t\tlet text = '[' + this.tag;\n\n\t\tthis.attrs.numeric.forEach( ( value ) => {\n\t\t\tif ( /\\s/.test( value ) ) {\n\t\t\t\ttext += ' \"' + value + '\"';\n\t\t\t} else {\n\t\t\t\ttext += ' ' + value;\n\t\t\t}\n\t\t} );\n\n\t\tObject.entries( this.attrs.named ).forEach( ( [ name, value ] ) => {\n\t\t\ttext += ' ' + name + '=\"' + value + '\"';\n\t\t} );\n\n\t\t// If the tag is marked as `single` or `self-closing`, close the tag and\n\t\t// ignore any additional content.\n\t\tif ( 'single' === this.type ) {\n\t\t\treturn text + ']';\n\t\t} else if ( 'self-closing' === this.type ) {\n\t\t\treturn text + ' /]';\n\t\t}\n\n\t\t// Complete the opening tag.\n\t\ttext += ']';\n\n\t\tif ( this.content ) {\n\t\t\ttext += this.content;\n\t\t}\n\n\t\t// Add the closing tag.\n\t\treturn text + '[/' + this.tag + ']';\n\t}\n}\n\nexport default Shortcode;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAmB;AAcnB,0BAAc,wBAjBd;AA4BO,SAAS,KACf,KACA,MACA,QAAgB,GACa;AAC7B,QAAM,KAAK,OAAQ,GAAI;AAEvB,KAAG,YAAY;AAEf,QAAM,QAAQ,GAAG,KAAM,IAAK;AAE5B,MAAK,CAAE,OAAQ;AACd;AAAA,EACD;AAGA,MAAK,QAAQ,MAAO,CAAE,KAAK,QAAQ,MAAO,CAAE,GAAI;AAC/C,WAAO,KAAM,KAAK,MAAM,GAAG,SAAU;AAAA,EACtC;AAEA,QAAM,SAAyB;AAAA,IAC9B,OAAO,MAAM;AAAA,IACb,SAAS,MAAO,CAAE;AAAA,IAClB,WAAW,UAAW,KAAM;AAAA,EAC7B;AAIA,MAAK,MAAO,CAAE,GAAI;AACjB,WAAO,UAAU,OAAO,QAAQ,MAAO,CAAE;AACzC,WAAO;AAAA,EACR;AAGA,MAAK,MAAO,CAAE,GAAI;AACjB,WAAO,UAAU,OAAO,QAAQ,MAAO,GAAG,EAAG;AAAA,EAC9C;AAEA,SAAO;AACR;AAYO,SAAS,QACf,KACA,MACA,UACC;AACD,SAAO,KAAK;AAAA,IACX,OAAQ,GAAI;AAAA;AAAA,IAEZ,IAAK,SAA4B;AAChC,YAAM,QAAQ,KAAM,CAAE;AACtB,YAAM,OAAO,KAAM,CAAE;AACrB,YAAM,QAAQ,KAAM,CAAE;AAItB,UAAK,SAAS,OAAO,UAAU,KAAM;AACpC,eAAO;AAAA,MACR;AAGA,YAAM,SAAS,SAAU,UAAW,IAAK,CAAE;AAI3C,aAAO,UAAU,WAAW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AaA,IAAK,MAAuB,OAAsB;AACjD,QAAK,OAAO,SAAS,UAAW;AAC/B,WAAK,MAAM,QAAS,IAAK,IAAI;AAAA,IAC9B,OAAO;AACN,WAAK,MAAM,MAAO,IAAK,IAAI;AAAA,IAC5B;AACA,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,SAAiB;AAChB,QAAI,OAAO,MAAM,KAAK;AAEtB,SAAK,MAAM,QAAQ,QAAS,CAAE,UAAW;AACxC,UAAK,KAAK,KAAM,KAAM,GAAI;AACzB,gBAAQ,OAAO,QAAQ;AAAA,MACxB,OAAO;AACN,gBAAQ,MAAM;AAAA,MACf;AAAA,IACD,CAAE;AAEF,WAAO,QAAS,KAAK,MAAM,KAAM,EAAE,QAAS,CAAE,CAAE,MAAM,KAAM,MAAO;AAClE,cAAQ,MAAM,OAAO,OAAO,QAAQ;AAAA,IACrC,CAAE;AAIF,QAAK,aAAa,KAAK,MAAO;AAC7B,aAAO,OAAO;AAAA,IACf,WAAY,mBAAmB,KAAK,MAAO;AAC1C,aAAO,OAAO;AAAA,IACf;AAGA,YAAQ;AAER,QAAK,KAAK,SAAU;AACnB,cAAQ,KAAK;AAAA,IACd;AAGA,WAAO,OAAO,OAAO,KAAK,MAAM;AAAA,EACjC;AACD;AAEA,IAAO,gBAAQ;",
6
+ "names": ["memize"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/types.ts"],
4
- "sourcesContent": ["/**\n * Shortcode attributes object.\n */\nexport type ShortcodeAttrs = {\n\t/**\n\t * Object with named attributes.\n\t */\n\tnamed: Record< string, string | undefined >;\n\n\t/**\n\t * Array with numeric attributes.\n\t */\n\tnumeric: string[];\n};\n\nexport type ShortcodeMatch = {\n\t/**\n\t * Index the shortcode is found at.\n\t */\n\tindex: number;\n\n\t/**\n\t * Matched content.\n\t */\n\tcontent: string;\n\n\t/**\n\t * Shortcode instance of the match.\n\t */\n\tshortcode: Shortcode;\n};\n\n/**\n * Shortcode options.\n */\nexport interface ShortcodeOptions {\n\t/**\n\t * Shortcode tag.\n\t */\n\ttag: string;\n\n\t/**\n\t * Shortcode attributes.\n\t */\n\tattrs?: Partial< ShortcodeAttrs > | string;\n\n\t/**\n\t * Shortcode content.\n\t */\n\tcontent?: string;\n\n\t/**\n\t * Shortcode type: `self-closing`, `closed`, or `single`.\n\t */\n\ttype?: 'self-closing' | 'closed' | 'single';\n}\n\n/**\n * Shortcode object.\n */\nexport interface Shortcode extends ShortcodeOptions {\n\t/**\n\t * Shortcode attributes.\n\t */\n\tattrs: ShortcodeAttrs;\n}\n\nexport type Match =\n\t| NonNullable< ReturnType< RegExp[ 'exec' ] > >\n\t| Array< string >;\n\nexport type ReplaceCallback = ( shortcode: Shortcode ) => string;\n\n/**\n * WordPress Shortcode instance.\n */\nexport interface shortcode {\n\tnew ( options: Partial< ShortcodeOptions > ): Shortcode & {\n\t\t/**\n\t\t * Transform the shortcode into a string.\n\t\t *\n\t\t * @return {string} String representation of the shortcode.\n\t\t */\n\t\tstring: () => string;\n\n\t\t/**\n\t\t * Get a shortcode attribute.\n\t\t *\n\t\t * Automatically detects whether `attr` is named or numeric and routes it\n\t\t * accordingly.\n\t\t *\n\t\t * @param {(number|string)} attr Attribute key.\n\t\t *\n\t\t * @return {string} Attribute value.\n\t\t */\n\t\tget: ( attr: string | number ) => string | undefined;\n\n\t\t/**\n\t\t * Set a shortcode attribute.\n\t\t *\n\t\t * Automatically detects whether `attr` is named or numeric and routes it\n\t\t * accordingly.\n\t\t *\n\t\t * @param {(number|string)} attr Attribute key.\n\t\t * @param {string} value Attribute value.\n\t\t *\n\t\t * @return {InstanceType< shortcode >} Shortcode instance.\n\t\t */\n\t\tset: (\n\t\t\tattr: string | number,\n\t\t\tvalue: string\n\t\t) => InstanceType< shortcode >;\n\t};\n\n\t/**\n\t * Parse shortcode attributes.\n\t *\n\t * Shortcodes accept many types of attributes. These can chiefly be divided into\n\t * named and numeric attributes:\n\t *\n\t * Named attributes are assigned on a key/value basis, while numeric attributes\n\t * are treated as an array.\n\t *\n\t * Named attributes can be formatted as either `name=\"value\"`, `name='value'`,\n\t * or `name=value`. Numeric attributes can be formatted as `\"value\"` or just\n\t * `value`.\n\t *\n\t * @param text Serialised shortcode attributes.\n\t *\n\t * @return Parsed shortcode attributes.\n\t */\n\tattrs: ( text: string ) => ShortcodeAttrs;\n\n\t/**\n\t * Generate a Shortcode Object from a RegExp match.\n\t *\n\t * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated\n\t * by `regexp()`. `match` can also be set to the `arguments` from a callback\n\t * passed to `regexp.replace()`.\n\t *\n\t * @param match Match array.\n\t *\n\t * @return Shortcode instance.\n\t */\n\tfromMatch: ( match: Match ) => InstanceType< shortcode >;\n\n\t/**\n\t * Find the next matching shortcode.\n\t *\n\t * @param tag Shortcode tag.\n\t * @param text Text to search.\n\t * @param index Index to start search from.\n\t *\n\t * @return Matched information.\n\t */\n\tnext: (\n\t\ttag: string,\n\t\ttext: string,\n\t\tindex?: number\n\t) => ShortcodeMatch | undefined;\n\n\t/**\n\t * Generate a RegExp to identify a shortcode.\n\t *\n\t * The base regex is functionally equivalent to the one found in\n\t * `get_shortcode_regex()` in `wp-includes/shortcodes.php`.\n\t *\n\t * Capture groups:\n\t *\n\t * 1. An extra `[` to allow for escaping shortcodes with double `[[]]`\n\t * 2. The shortcode name\n\t * 3. The shortcode argument list\n\t * 4. The self closing `/`\n\t * 5. The content of a shortcode when it wraps some content.\n\t * 6. The closing tag.\n\t * 7. An extra `]` to allow for escaping shortcodes with double `[[]]`\n\t *\n\t * @param tag Shortcode tag.\n\t *\n\t * @return Shortcode RegExp.\n\t */\n\tregexp: ( tag: string ) => RegExp;\n\n\t/**\n\t * Replace matching shortcodes in a block of text.\n\t *\n\t * @param tag Shortcode tag.\n\t * @param text Text to search.\n\t * @param callback Function to process the match and return\n\t * replacement string.\n\t *\n\t * @return Text with shortcodes replaced.\n\t */\n\treplace: ( tag: string, text: string, callback: ReplaceCallback ) => string;\n\n\t/**\n\t * Generate a string from shortcode parameters.\n\t *\n\t * Creates a shortcode instance and returns a string.\n\t *\n\t * Accepts the same `options` as the `shortcode()` constructor, containing a\n\t * `tag` string, a string or object of `attrs`, a boolean indicating whether to\n\t * format the shortcode using a `single` tag, and a `content` string.\n\t *\n\t * @param options\n\t *\n\t * @return String representation of the shortcode.\n\t */\n\tstring: ( options: ShortcodeOptions ) => string;\n}\n"],
4
+ "sourcesContent": ["/**\n * Shortcode attributes object.\n */\nexport type ShortcodeAttrs = {\n\t/**\n\t * Object with named attributes.\n\t */\n\tnamed: Record< string, string | undefined >;\n\n\t/**\n\t * Array with numeric attributes.\n\t */\n\tnumeric: string[];\n};\n\n/**\n * Shortcode object.\n */\nexport interface Shortcode {\n\t/**\n\t * Shortcode tag.\n\t */\n\ttag: string;\n\n\t/**\n\t * Shortcode attributes.\n\t */\n\tattrs: ShortcodeAttrs;\n\n\t/**\n\t * Shortcode content.\n\t */\n\tcontent?: string;\n\n\t/**\n\t * Shortcode type: `self-closing`, `closed`, or `single`.\n\t */\n\ttype?: 'self-closing' | 'closed' | 'single';\n}\n\n/**\n * Shortcode match result.\n */\nexport type ShortcodeMatch = {\n\t/**\n\t * Index the shortcode is found at.\n\t */\n\tindex: number;\n\n\t/**\n\t * Matched content.\n\t */\n\tcontent: string;\n\n\t/**\n\t * Shortcode instance of the match.\n\t */\n\tshortcode: Shortcode;\n};\n\n/**\n * Shortcode options for creating a new shortcode.\n */\nexport interface ShortcodeOptions {\n\t/**\n\t * Shortcode tag.\n\t */\n\ttag: string;\n\n\t/**\n\t * Shortcode attributes.\n\t */\n\tattrs?: Partial< ShortcodeAttrs > | string;\n\n\t/**\n\t * Shortcode content.\n\t */\n\tcontent?: string;\n\n\t/**\n\t * Shortcode type: `self-closing`, `closed`, or `single`.\n\t */\n\ttype?: 'self-closing' | 'closed' | 'single';\n}\n\n/**\n * Match array from regexp.exec() or arguments from replace callback.\n */\nexport type Match =\n\t| NonNullable< ReturnType< RegExp[ 'exec' ] > >\n\t| IArguments\n\t| ArrayLike< string >;\n\n/**\n * Callback function for replace operations.\n */\nexport type ReplaceCallback = ( shortcode: Shortcode ) => string;\n\n/**\n * Shortcode instance returned by the constructor.\n */\nexport interface ShortcodeInstance extends Shortcode {\n\t/**\n\t * Transform the shortcode into a string.\n\t *\n\t * @return String representation of the shortcode.\n\t */\n\tstring: () => string;\n\n\t/**\n\t * Get a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param attr Attribute key.\n\t *\n\t * @return Attribute value.\n\t */\n\tget: ( attr: string | number ) => string | undefined;\n\n\t/**\n\t * Set a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param attr Attribute key.\n\t * @param value Attribute value.\n\t *\n\t * @return Shortcode instance.\n\t */\n\tset: ( attr: string | number, value: string ) => ShortcodeInstance;\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,4 @@
1
- // packages/shortcode/src/index.js
1
+ // packages/shortcode/src/index.ts
2
2
  import memize from "memize";
3
3
  export * from "./types.mjs";
4
4
  function next(tag, text, index = 0) {
@@ -28,17 +28,21 @@ function next(tag, text, index = 0) {
28
28
  function replace(tag, text, callback) {
29
29
  return text.replace(
30
30
  regexp(tag),
31
- function(match, left, $3, attrs2, slash, content, closing, right) {
31
+ // Let us use spread syntax to capture the arguments object.
32
+ (...args) => {
33
+ const match = args[0];
34
+ const left = args[1];
35
+ const right = args[7];
32
36
  if (left === "[" && right === "]") {
33
37
  return match;
34
38
  }
35
- const result = callback(fromMatch(arguments));
39
+ const result = callback(fromMatch(args));
36
40
  return result || result === "" ? left + result + right : match;
37
41
  }
38
42
  );
39
43
  }
40
44
  function string(options) {
41
- return new shortcode(options).string();
45
+ return new Shortcode(options).string();
42
46
  }
43
47
  function regexp(tag) {
44
48
  return new RegExp(
@@ -78,17 +82,31 @@ function fromMatch(match) {
78
82
  } else {
79
83
  type = "single";
80
84
  }
81
- return new shortcode({
85
+ return new Shortcode({
82
86
  tag: match[2],
83
87
  attrs: match[3],
84
88
  type,
85
89
  content: match[5]
86
90
  });
87
91
  }
88
- var shortcode = Object.assign(
89
- function(options) {
90
- const { tag, attrs: attributes, type, content } = options || {};
91
- Object.assign(this, { tag, type, content });
92
+ var Shortcode = class {
93
+ // Instance properties
94
+ tag;
95
+ type;
96
+ content;
97
+ attrs;
98
+ // Static methods
99
+ static next = next;
100
+ static replace = replace;
101
+ static string = string;
102
+ static regexp = regexp;
103
+ static attrs = attrs;
104
+ static fromMatch = fromMatch;
105
+ constructor(options) {
106
+ const { tag, attrs: attributes, type, content } = options;
107
+ this.tag = tag;
108
+ this.type = type;
109
+ this.content = content;
92
110
  this.attrs = {
93
111
  named: {},
94
112
  numeric: []
@@ -96,59 +114,57 @@ var shortcode = Object.assign(
96
114
  if (!attributes) {
97
115
  return;
98
116
  }
99
- const attributeTypes = ["named", "numeric"];
100
117
  if (typeof attributes === "string") {
101
118
  this.attrs = attrs(attributes);
102
- } else if (attributes.length === attributeTypes.length && attributeTypes.every((t, key) => t === attributes[key])) {
119
+ } else if ("named" in attributes && "numeric" in attributes && attributes.named !== void 0 && attributes.numeric !== void 0) {
103
120
  this.attrs = attributes;
104
121
  } else {
105
122
  Object.entries(attributes).forEach(([key, value]) => {
106
- this.set(key, value);
123
+ if (typeof value === "string" || typeof value === "undefined") {
124
+ this.set(key, value);
125
+ }
107
126
  });
108
127
  }
109
- },
110
- {
111
- next,
112
- replace,
113
- string,
114
- regexp,
115
- attrs,
116
- fromMatch
117
128
  }
118
- );
119
- Object.assign(shortcode.prototype, {
120
129
  /**
121
130
  * Get a shortcode attribute.
122
131
  *
123
132
  * Automatically detects whether `attr` is named or numeric and routes it
124
133
  * accordingly.
125
134
  *
126
- * @param {(number|string)} attr Attribute key.
135
+ * @param attr Attribute key.
127
136
  *
128
- * @return {string} Attribute value.
137
+ * @return Attribute value.
129
138
  */
130
139
  get(attr) {
131
- return this.attrs[typeof attr === "number" ? "numeric" : "named"][attr];
132
- },
140
+ if (typeof attr === "number") {
141
+ return this.attrs.numeric[attr];
142
+ }
143
+ return this.attrs.named[attr];
144
+ }
133
145
  /**
134
146
  * Set a shortcode attribute.
135
147
  *
136
148
  * Automatically detects whether `attr` is named or numeric and routes it
137
149
  * accordingly.
138
150
  *
139
- * @param {(number|string)} attr Attribute key.
140
- * @param {string} value Attribute value.
151
+ * @param attr Attribute key.
152
+ * @param value Attribute value.
141
153
  *
142
- * @return {InstanceType< import('./types').shortcode >} Shortcode instance.
154
+ * @return Shortcode instance.
143
155
  */
144
156
  set(attr, value) {
145
- this.attrs[typeof attr === "number" ? "numeric" : "named"][attr] = value;
157
+ if (typeof attr === "number") {
158
+ this.attrs.numeric[attr] = value;
159
+ } else {
160
+ this.attrs.named[attr] = value;
161
+ }
146
162
  return this;
147
- },
163
+ }
148
164
  /**
149
165
  * Transform the shortcode into a string.
150
166
  *
151
- * @return {string} String representation of the shortcode.
167
+ * @return String representation of the shortcode.
152
168
  */
153
169
  string() {
154
170
  let text = "[" + this.tag;
@@ -173,8 +189,8 @@ Object.assign(shortcode.prototype, {
173
189
  }
174
190
  return text + "[/" + this.tag + "]";
175
191
  }
176
- });
177
- var index_default = shortcode;
192
+ };
193
+ var index_default = Shortcode;
178
194
  export {
179
195
  attrs,
180
196
  index_default as default,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/index.js"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport memize from 'memize';\n\nexport * from './types';\n\n/**\n * Find the next matching shortcode.\n *\n * @param {string} tag Shortcode tag.\n * @param {string} text Text to search.\n * @param {number} index Index to start search from.\n *\n * @return {import('./types').ShortcodeMatch | undefined} Matched information.\n */\nexport function next( tag, text, index = 0 ) {\n\tconst re = regexp( tag );\n\n\tre.lastIndex = index;\n\n\tconst match = re.exec( text );\n\n\tif ( ! match ) {\n\t\treturn;\n\t}\n\n\t// If we matched an escaped shortcode, try again.\n\tif ( '[' === match[ 1 ] && ']' === match[ 7 ] ) {\n\t\treturn next( tag, text, re.lastIndex );\n\t}\n\n\tconst result = {\n\t\tindex: match.index,\n\t\tcontent: match[ 0 ],\n\t\tshortcode: fromMatch( match ),\n\t};\n\n\t// If we matched a leading `[`, strip it from the match and increment the\n\t// index accordingly.\n\tif ( match[ 1 ] ) {\n\t\tresult.content = result.content.slice( 1 );\n\t\tresult.index++;\n\t}\n\n\t// If we matched a trailing `]`, strip it from the match.\n\tif ( match[ 7 ] ) {\n\t\tresult.content = result.content.slice( 0, -1 );\n\t}\n\n\treturn result;\n}\n\n/**\n * Replace matching shortcodes in a block of text.\n *\n * @param {string} tag Shortcode tag.\n * @param {string} text Text to search.\n * @param {import('./types').ReplaceCallback} callback Function to process the match and return\n * replacement string.\n *\n * @return {string} Text with shortcodes replaced.\n */\nexport function replace( tag, text, callback ) {\n\treturn text.replace(\n\t\tregexp( tag ),\n\t\tfunction ( match, left, $3, attrs, slash, content, closing, right ) {\n\t\t\t// If both extra brackets exist, the shortcode has been properly\n\t\t\t// escaped.\n\t\t\tif ( left === '[' && right === ']' ) {\n\t\t\t\treturn match;\n\t\t\t}\n\n\t\t\t// Create the match object and pass it through the callback.\n\t\t\tconst result = callback( fromMatch( arguments ) );\n\n\t\t\t// Make sure to return any of the extra brackets if they weren't used to\n\t\t\t// escape the shortcode.\n\t\t\treturn result || result === '' ? left + result + right : match;\n\t\t}\n\t);\n}\n\n/**\n * Generate a string from shortcode parameters.\n *\n * Creates a shortcode instance and returns a string.\n *\n * Accepts the same `options` as the `shortcode()` constructor, containing a\n * `tag` string, a string or object of `attrs`, a boolean indicating whether to\n * format the shortcode using a `single` tag, and a `content` string.\n *\n * @param {Object} options\n *\n * @return {string} String representation of the shortcode.\n */\nexport function string( options ) {\n\treturn new shortcode( options ).string();\n}\n\n/**\n * Generate a RegExp to identify a shortcode.\n *\n * The base regex is functionally equivalent to the one found in\n * `get_shortcode_regex()` in `wp-includes/shortcodes.php`.\n *\n * Capture groups:\n *\n * 1. An extra `[` to allow for escaping shortcodes with double `[[]]`\n * 2. The shortcode name\n * 3. The shortcode argument list\n * 4. The self closing `/`\n * 5. The content of a shortcode when it wraps some content.\n * 6. The closing tag.\n * 7. An extra `]` to allow for escaping shortcodes with double `[[]]`\n *\n * @param {string} tag Shortcode tag.\n *\n * @return {RegExp} Shortcode RegExp.\n */\nexport function regexp( tag ) {\n\treturn new RegExp(\n\t\t'\\\\[(\\\\[?)(' +\n\t\t\ttag +\n\t\t\t')(?![\\\\w-])([^\\\\]\\\\/]*(?:\\\\/(?!\\\\])[^\\\\]\\\\/]*)*?)(?:(\\\\/)\\\\]|\\\\](?:([^\\\\[]*(?:\\\\[(?!\\\\/\\\\2\\\\])[^\\\\[]*)*)(\\\\[\\\\/\\\\2\\\\]))?)(\\\\]?)',\n\t\t'g'\n\t);\n}\n\n/**\n * Parse shortcode attributes.\n *\n * Shortcodes accept many types of attributes. These can chiefly be divided into\n * named and numeric attributes:\n *\n * Named attributes are assigned on a key/value basis, while numeric attributes\n * are treated as an array.\n *\n * Named attributes can be formatted as either `name=\"value\"`, `name='value'`,\n * or `name=value`. Numeric attributes can be formatted as `\"value\"` or just\n * `value`.\n *\n * @param {string} text Serialised shortcode attributes.\n *\n * @return {import('./types').ShortcodeAttrs} Parsed shortcode attributes.\n */\nexport const attrs = memize( ( text ) => {\n\tconst named = {};\n\tconst numeric = [];\n\n\t// This regular expression is reused from `shortcode_parse_atts()` in\n\t// `wp-includes/shortcodes.php`.\n\t//\n\t// Capture groups:\n\t//\n\t// 1. An attribute name, that corresponds to...\n\t// 2. a value in double quotes.\n\t// 3. An attribute name, that corresponds to...\n\t// 4. a value in single quotes.\n\t// 5. An attribute name, that corresponds to...\n\t// 6. an unquoted value.\n\t// 7. A numeric attribute in double quotes.\n\t// 8. A numeric attribute in single quotes.\n\t// 9. An unquoted numeric attribute.\n\tconst pattern =\n\t\t/([\\w-]+)\\s*=\\s*\"([^\"]*)\"(?:\\s|$)|([\\w-]+)\\s*=\\s*'([^']*)'(?:\\s|$)|([\\w-]+)\\s*=\\s*([^\\s'\"]+)(?:\\s|$)|\"([^\"]*)\"(?:\\s|$)|'([^']*)'(?:\\s|$)|(\\S+)(?:\\s|$)/g;\n\n\t// Map zero-width spaces to actual spaces.\n\ttext = text.replace( /[\\u00a0\\u200b]/g, ' ' );\n\n\tlet match;\n\n\t// Match and normalize attributes.\n\twhile ( ( match = pattern.exec( text ) ) ) {\n\t\tif ( match[ 1 ] ) {\n\t\t\tnamed[ match[ 1 ].toLowerCase() ] = match[ 2 ];\n\t\t} else if ( match[ 3 ] ) {\n\t\t\tnamed[ match[ 3 ].toLowerCase() ] = match[ 4 ];\n\t\t} else if ( match[ 5 ] ) {\n\t\t\tnamed[ match[ 5 ].toLowerCase() ] = match[ 6 ];\n\t\t} else if ( match[ 7 ] ) {\n\t\t\tnumeric.push( match[ 7 ] );\n\t\t} else if ( match[ 8 ] ) {\n\t\t\tnumeric.push( match[ 8 ] );\n\t\t} else if ( match[ 9 ] ) {\n\t\t\tnumeric.push( match[ 9 ] );\n\t\t}\n\t}\n\n\treturn { named, numeric };\n} );\n\n/**\n * Generate a Shortcode Object from a RegExp match.\n *\n * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated\n * by `regexp()`. `match` can also be set to the `arguments` from a callback\n * passed to `regexp.replace()`.\n *\n * @param {import('./types').Match} match Match array.\n *\n * @return {InstanceType<import('./types').shortcode>} Shortcode instance.\n */\nexport function fromMatch( match ) {\n\tlet type;\n\n\tif ( match[ 4 ] ) {\n\t\ttype = 'self-closing';\n\t} else if ( match[ 6 ] ) {\n\t\ttype = 'closed';\n\t} else {\n\t\ttype = 'single';\n\t}\n\n\treturn new shortcode( {\n\t\ttag: match[ 2 ],\n\t\tattrs: match[ 3 ],\n\t\ttype,\n\t\tcontent: match[ 5 ],\n\t} );\n}\n\n/**\n * Creates a shortcode instance.\n *\n * To access a raw representation of a shortcode, pass an `options` object,\n * containing a `tag` string, a string or object of `attrs`, a string indicating\n * the `type` of the shortcode ('single', 'self-closing', or 'closed'), and a\n * `content` string.\n *\n * @type {import('./types').shortcode} Shortcode instance.\n */\nconst shortcode = Object.assign(\n\tfunction ( options ) {\n\t\tconst { tag, attrs: attributes, type, content } = options || {};\n\t\tObject.assign( this, { tag, type, content } );\n\n\t\t// Ensure we have a correctly formatted `attrs` object.\n\t\tthis.attrs = {\n\t\t\tnamed: {},\n\t\t\tnumeric: [],\n\t\t};\n\n\t\tif ( ! attributes ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst attributeTypes = [ 'named', 'numeric' ];\n\n\t\t// Parse a string of attributes.\n\t\tif ( typeof attributes === 'string' ) {\n\t\t\tthis.attrs = attrs( attributes );\n\t\t\t// Identify a correctly formatted `attrs` object.\n\t\t} else if (\n\t\t\tattributes.length === attributeTypes.length &&\n\t\t\tattributeTypes.every( ( t, key ) => t === attributes[ key ] )\n\t\t) {\n\t\t\tthis.attrs = attributes;\n\t\t\t// Handle a flat object of attributes.\n\t\t} else {\n\t\t\tObject.entries( attributes ).forEach( ( [ key, value ] ) => {\n\t\t\t\tthis.set( key, value );\n\t\t\t} );\n\t\t}\n\t},\n\t{\n\t\tnext,\n\t\treplace,\n\t\tstring,\n\t\tregexp,\n\t\tattrs,\n\t\tfromMatch,\n\t}\n);\n\nObject.assign( shortcode.prototype, {\n\t/**\n\t * Get a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param {(number|string)} attr Attribute key.\n\t *\n\t * @return {string} Attribute value.\n\t */\n\tget( attr ) {\n\t\treturn this.attrs[ typeof attr === 'number' ? 'numeric' : 'named' ][\n\t\t\tattr\n\t\t];\n\t},\n\n\t/**\n\t * Set a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param {(number|string)} attr Attribute key.\n\t * @param {string} value Attribute value.\n\t *\n\t * @return {InstanceType< import('./types').shortcode >} Shortcode instance.\n\t */\n\tset( attr, value ) {\n\t\tthis.attrs[ typeof attr === 'number' ? 'numeric' : 'named' ][ attr ] =\n\t\t\tvalue;\n\t\treturn this;\n\t},\n\n\t/**\n\t * Transform the shortcode into a string.\n\t *\n\t * @return {string} String representation of the shortcode.\n\t */\n\tstring() {\n\t\tlet text = '[' + this.tag;\n\n\t\tthis.attrs.numeric.forEach( ( value ) => {\n\t\t\tif ( /\\s/.test( value ) ) {\n\t\t\t\ttext += ' \"' + value + '\"';\n\t\t\t} else {\n\t\t\t\ttext += ' ' + value;\n\t\t\t}\n\t\t} );\n\n\t\tObject.entries( this.attrs.named ).forEach( ( [ name, value ] ) => {\n\t\t\ttext += ' ' + name + '=\"' + value + '\"';\n\t\t} );\n\n\t\t// If the tag is marked as `single` or `self-closing`, close the tag and\n\t\t// ignore any additional content.\n\t\tif ( 'single' === this.type ) {\n\t\t\treturn text + ']';\n\t\t} else if ( 'self-closing' === this.type ) {\n\t\t\treturn text + ' /]';\n\t\t}\n\n\t\t// Complete the opening tag.\n\t\ttext += ']';\n\n\t\tif ( this.content ) {\n\t\t\ttext += this.content;\n\t\t}\n\n\t\t// Add the closing tag.\n\t\treturn text + '[/' + this.tag + ']';\n\t},\n} );\n\nexport default shortcode;\n"],
5
- "mappings": ";AAGA,OAAO,YAAY;AAEnB,cAAc;AAWP,SAAS,KAAM,KAAK,MAAM,QAAQ,GAAI;AAC5C,QAAM,KAAK,OAAQ,GAAI;AAEvB,KAAG,YAAY;AAEf,QAAM,QAAQ,GAAG,KAAM,IAAK;AAE5B,MAAK,CAAE,OAAQ;AACd;AAAA,EACD;AAGA,MAAK,QAAQ,MAAO,CAAE,KAAK,QAAQ,MAAO,CAAE,GAAI;AAC/C,WAAO,KAAM,KAAK,MAAM,GAAG,SAAU;AAAA,EAC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AQ;",
6
- "names": ["attrs"]
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport memize from 'memize';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tShortcodeAttrs,\n\tShortcodeMatch,\n\tShortcodeOptions,\n\tMatch,\n\tReplaceCallback,\n\tShortcodeInstance,\n} from './types';\n\nexport * from './types';\n\n/**\n * Find the next matching shortcode.\n *\n * @param tag Shortcode tag.\n * @param text Text to search.\n * @param index Index to start search from.\n *\n * @return Matched information.\n */\nexport function next(\n\ttag: string,\n\ttext: string,\n\tindex: number = 0\n): ShortcodeMatch | undefined {\n\tconst re = regexp( tag );\n\n\tre.lastIndex = index;\n\n\tconst match = re.exec( text );\n\n\tif ( ! match ) {\n\t\treturn;\n\t}\n\n\t// If we matched an escaped shortcode, try again.\n\tif ( '[' === match[ 1 ] && ']' === match[ 7 ] ) {\n\t\treturn next( tag, text, re.lastIndex );\n\t}\n\n\tconst result: ShortcodeMatch = {\n\t\tindex: match.index,\n\t\tcontent: match[ 0 ],\n\t\tshortcode: fromMatch( match ),\n\t};\n\n\t// If we matched a leading `[`, strip it from the match and increment the\n\t// index accordingly.\n\tif ( match[ 1 ] ) {\n\t\tresult.content = result.content.slice( 1 );\n\t\tresult.index++;\n\t}\n\n\t// If we matched a trailing `]`, strip it from the match.\n\tif ( match[ 7 ] ) {\n\t\tresult.content = result.content.slice( 0, -1 );\n\t}\n\n\treturn result;\n}\n\n/**\n * Replace matching shortcodes in a block of text.\n *\n * @param tag Shortcode tag.\n * @param text Text to search.\n * @param callback Function to process the match and return\n * replacement string.\n *\n * @return Text with shortcodes replaced.\n */\nexport function replace(\n\ttag: string,\n\ttext: string,\n\tcallback: ReplaceCallback\n) {\n\treturn text.replace(\n\t\tregexp( tag ),\n\t\t// Let us use spread syntax to capture the arguments object.\n\t\t( ...args: string[] ): string => {\n\t\t\tconst match = args[ 0 ];\n\t\t\tconst left = args[ 1 ];\n\t\t\tconst right = args[ 7 ];\n\n\t\t\t// If both extra brackets exist, the shortcode has been properly\n\t\t\t// escaped.\n\t\t\tif ( left === '[' && right === ']' ) {\n\t\t\t\treturn match;\n\t\t\t}\n\n\t\t\t// Create the match object and pass it through the callback.\n\t\t\tconst result = callback( fromMatch( args ) );\n\n\t\t\t// Make sure to return any of the extra brackets if they weren't used to\n\t\t\t// escape the shortcode.\n\t\t\treturn result || result === '' ? left + result + right : match;\n\t\t}\n\t);\n}\n\n/**\n * Generate a string from shortcode parameters.\n *\n * Creates a shortcode instance and returns a string.\n *\n * Accepts the same `options` as the `shortcode()` constructor, containing a\n * `tag` string, a string or object of `attrs`, a boolean indicating whether to\n * format the shortcode using a `single` tag, and a `content` string.\n *\n * @param options Shortcode options.\n *\n * @return String representation of the shortcode.\n */\nexport function string( options: ShortcodeOptions ): string {\n\treturn new Shortcode( options ).string();\n}\n\n/**\n * Generate a RegExp to identify a shortcode.\n *\n * The base regex is functionally equivalent to the one found in\n * `get_shortcode_regex()` in `wp-includes/shortcodes.php`.\n *\n * Capture groups:\n *\n * 1. An extra `[` to allow for escaping shortcodes with double `[[]]`\n * 2. The shortcode name\n * 3. The shortcode argument list\n * 4. The self closing `/`\n * 5. The content of a shortcode when it wraps some content.\n * 6. The closing tag.\n * 7. An extra `]` to allow for escaping shortcodes with double `[[]]`\n *\n * @param tag Shortcode tag.\n *\n * @return Shortcode RegExp.\n */\nexport function regexp( tag: string ): RegExp {\n\treturn new RegExp(\n\t\t'\\\\[(\\\\[?)(' +\n\t\t\ttag +\n\t\t\t')(?![\\\\w-])([^\\\\]\\\\/]*(?:\\\\/(?!\\\\])[^\\\\]\\\\/]*)*?)(?:(\\\\/)\\\\]|\\\\](?:([^\\\\[]*(?:\\\\[(?!\\\\/\\\\2\\\\])[^\\\\[]*)*)(\\\\[\\\\/\\\\2\\\\]))?)(\\\\]?)',\n\t\t'g'\n\t);\n}\n\n/**\n * Parse shortcode attributes.\n *\n * Shortcodes accept many types of attributes. These can chiefly be divided into\n * named and numeric attributes:\n *\n * Named attributes are assigned on a key/value basis, while numeric attributes\n * are treated as an array.\n *\n * Named attributes can be formatted as either `name=\"value\"`, `name='value'`,\n * or `name=value`. Numeric attributes can be formatted as `\"value\"` or just\n * `value`.\n *\n * @param {string} text Serialised shortcode attributes.\n *\n * @return {ShortcodeAttrs} Parsed shortcode attributes.\n */\nexport const attrs = memize( ( text: string ): ShortcodeAttrs => {\n\tconst named: Record< string, string | undefined > = {};\n\tconst numeric: string[] = [];\n\n\t// This regular expression is reused from `shortcode_parse_atts()` in\n\t// `wp-includes/shortcodes.php`.\n\t//\n\t// Capture groups:\n\t//\n\t// 1. An attribute name, that corresponds to...\n\t// 2. a value in double quotes.\n\t// 3. An attribute name, that corresponds to...\n\t// 4. a value in single quotes.\n\t// 5. An attribute name, that corresponds to...\n\t// 6. an unquoted value.\n\t// 7. A numeric attribute in double quotes.\n\t// 8. A numeric attribute in single quotes.\n\t// 9. An unquoted numeric attribute.\n\tconst pattern =\n\t\t/([\\w-]+)\\s*=\\s*\"([^\"]*)\"(?:\\s|$)|([\\w-]+)\\s*=\\s*'([^']*)'(?:\\s|$)|([\\w-]+)\\s*=\\s*([^\\s'\"]+)(?:\\s|$)|\"([^\"]*)\"(?:\\s|$)|'([^']*)'(?:\\s|$)|(\\S+)(?:\\s|$)/g;\n\n\t// Map zero-width spaces to actual spaces.\n\ttext = text.replace( /[\\u00a0\\u200b]/g, ' ' );\n\n\tlet match;\n\n\t// Match and normalize attributes.\n\twhile ( ( match = pattern.exec( text ) ) ) {\n\t\tif ( match[ 1 ] ) {\n\t\t\tnamed[ match[ 1 ].toLowerCase() ] = match[ 2 ];\n\t\t} else if ( match[ 3 ] ) {\n\t\t\tnamed[ match[ 3 ].toLowerCase() ] = match[ 4 ];\n\t\t} else if ( match[ 5 ] ) {\n\t\t\tnamed[ match[ 5 ].toLowerCase() ] = match[ 6 ];\n\t\t} else if ( match[ 7 ] ) {\n\t\t\tnumeric.push( match[ 7 ] );\n\t\t} else if ( match[ 8 ] ) {\n\t\t\tnumeric.push( match[ 8 ] );\n\t\t} else if ( match[ 9 ] ) {\n\t\t\tnumeric.push( match[ 9 ] );\n\t\t}\n\t}\n\n\treturn { named, numeric };\n} );\n\n/**\n * Generate a Shortcode Object from a RegExp match.\n *\n * Accepts a `match` object from calling `regexp.exec()` on a `RegExp` generated\n * by `regexp()`. `match` can also be set to the `arguments` from a callback\n * passed to `regexp.replace()`.\n *\n * @param match Match array.\n *\n * @return Shortcode instance.\n */\nexport function fromMatch( match: Match ): ShortcodeInstance {\n\tlet type: 'self-closing' | 'closed' | 'single';\n\n\tif ( match[ 4 ] ) {\n\t\ttype = 'self-closing';\n\t} else if ( match[ 6 ] ) {\n\t\ttype = 'closed';\n\t} else {\n\t\ttype = 'single';\n\t}\n\n\treturn new Shortcode( {\n\t\ttag: match[ 2 ],\n\t\tattrs: match[ 3 ],\n\t\ttype,\n\t\tcontent: match[ 5 ],\n\t} );\n}\n\n/**\n * Creates a shortcode instance.\n *\n * To access a raw representation of a shortcode, pass an `options` object,\n * containing a `tag` string, a string or object of `attrs`, a string indicating\n * the `type` of the shortcode ('single', 'self-closing', or 'closed'), and a\n * `content` string.\n */\nclass Shortcode implements ShortcodeInstance {\n\t// Instance properties\n\ttag: string;\n\ttype?: 'self-closing' | 'closed' | 'single';\n\tcontent?: string;\n\tattrs: ShortcodeAttrs;\n\n\t// Static methods\n\tstatic next = next;\n\tstatic replace = replace;\n\tstatic string = string;\n\tstatic regexp = regexp;\n\tstatic attrs = attrs;\n\tstatic fromMatch = fromMatch;\n\n\tconstructor( options: ShortcodeOptions ) {\n\t\tconst { tag, attrs: attributes, type, content } = options;\n\t\tthis.tag = tag;\n\t\tthis.type = type;\n\t\tthis.content = content;\n\n\t\t// Ensure we have a correctly formatted `attrs` object.\n\t\tthis.attrs = {\n\t\t\tnamed: {},\n\t\t\tnumeric: [],\n\t\t};\n\n\t\tif ( ! attributes ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Parse a string of attributes.\n\t\tif ( typeof attributes === 'string' ) {\n\t\t\tthis.attrs = attrs( attributes );\n\t\t\t// Identify a correctly formatted `attrs` object.\n\t\t} else if (\n\t\t\t'named' in attributes &&\n\t\t\t'numeric' in attributes &&\n\t\t\tattributes.named !== undefined &&\n\t\t\tattributes.numeric !== undefined\n\t\t) {\n\t\t\tthis.attrs = attributes as ShortcodeAttrs;\n\t\t\t// Handle a flat object of attributes (e.g., { foo: 'bar', baz: 'qux' }).\n\t\t} else {\n\t\t\tObject.entries( attributes ).forEach( ( [ key, value ] ) => {\n\t\t\t\tif (\n\t\t\t\t\ttypeof value === 'string' ||\n\t\t\t\t\ttypeof value === 'undefined'\n\t\t\t\t) {\n\t\t\t\t\tthis.set( key, value );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\t}\n\n\t/**\n\t * Get a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param attr Attribute key.\n\t *\n\t * @return Attribute value.\n\t */\n\tget( attr: string | number ): string | undefined {\n\t\tif ( typeof attr === 'number' ) {\n\t\t\treturn this.attrs.numeric[ attr ];\n\t\t}\n\t\treturn this.attrs.named[ attr ];\n\t}\n\n\t/**\n\t * Set a shortcode attribute.\n\t *\n\t * Automatically detects whether `attr` is named or numeric and routes it\n\t * accordingly.\n\t *\n\t * @param attr Attribute key.\n\t * @param value Attribute value.\n\t *\n\t * @return Shortcode instance.\n\t */\n\tset( attr: string | number, value: string ): this {\n\t\tif ( typeof attr === 'number' ) {\n\t\t\tthis.attrs.numeric[ attr ] = value;\n\t\t} else {\n\t\t\tthis.attrs.named[ attr ] = value;\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Transform the shortcode into a string.\n\t *\n\t * @return String representation of the shortcode.\n\t */\n\tstring(): string {\n\t\tlet text = '[' + this.tag;\n\n\t\tthis.attrs.numeric.forEach( ( value ) => {\n\t\t\tif ( /\\s/.test( value ) ) {\n\t\t\t\ttext += ' \"' + value + '\"';\n\t\t\t} else {\n\t\t\t\ttext += ' ' + value;\n\t\t\t}\n\t\t} );\n\n\t\tObject.entries( this.attrs.named ).forEach( ( [ name, value ] ) => {\n\t\t\ttext += ' ' + name + '=\"' + value + '\"';\n\t\t} );\n\n\t\t// If the tag is marked as `single` or `self-closing`, close the tag and\n\t\t// ignore any additional content.\n\t\tif ( 'single' === this.type ) {\n\t\t\treturn text + ']';\n\t\t} else if ( 'self-closing' === this.type ) {\n\t\t\treturn text + ' /]';\n\t\t}\n\n\t\t// Complete the opening tag.\n\t\ttext += ']';\n\n\t\tif ( this.content ) {\n\t\t\ttext += this.content;\n\t\t}\n\n\t\t// Add the closing tag.\n\t\treturn text + '[/' + this.tag + ']';\n\t}\n}\n\nexport default Shortcode;\n"],
5
+ "mappings": ";AAGA,OAAO,YAAY;AAcnB,cAAc;AAWP,SAAS,KACf,KACA,MACA,QAAgB,GACa;AAC7B,QAAM,KAAK,OAAQ,GAAI;AAEvB,KAAG,YAAY;AAEf,QAAM,QAAQ,GAAG,KAAM,IAAK;AAE5B,MAAK,CAAE,OAAQ;AACd;AAAA,EACD;AAGA,MAAK,QAAQ,MAAO,CAAE,KAAK,QAAQ,MAAO,CAAE,GAAI;AAC/C,WAAO,KAAM,KAAK,MAAM,GAAG,SAAU;AAAA,EACtC;AAEA,QAAM,SAAyB;AAAA,IAC9B,OAAO,MAAM;AAAA,IACb,SAAS,MAAO,CAAE;AAAA,IAClB,WAAW,UAAW,KAAM;AAAA,EAC7B;AAIA,MAAK,MAAO,CAAE,GAAI;AACjB,WAAO,UAAU,OAAO,QAAQ,MAAO,CAAE;AACzC,WAAO;AAAA,EACR;AAGA,MAAK,MAAO,CAAE,GAAI;AACjB,WAAO,UAAU,OAAO,QAAQ,MAAO,GAAG,EAAG;AAAA,EAC9C;AAEA,SAAO;AACR;AAYO,SAAS,QACf,KACA,MACA,UACC;AACD,SAAO,KAAK;AAAA,IACX,OAAQ,GAAI;AAAA;AAAA,IAEZ,I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