wp/wp-includes/js/dist/token-list.js
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     1 /******/ (function() { // webpackBootstrap
     1 /******/ (() => { // webpackBootstrap
     2 /******/ 	"use strict";
     2 /******/ 	"use strict";
     3 /******/ 	// The require scope
     3 /******/ 	// The require scope
     4 /******/ 	var __webpack_require__ = {};
     4 /******/ 	var __webpack_require__ = {};
     5 /******/ 	
     5 /******/ 	
     6 /************************************************************************/
     6 /************************************************************************/
     7 /******/ 	/* webpack/runtime/define property getters */
     7 /******/ 	/* webpack/runtime/define property getters */
     8 /******/ 	!function() {
     8 /******/ 	(() => {
     9 /******/ 		// define getter functions for harmony exports
     9 /******/ 		// define getter functions for harmony exports
    10 /******/ 		__webpack_require__.d = function(exports, definition) {
    10 /******/ 		__webpack_require__.d = (exports, definition) => {
    11 /******/ 			for(var key in definition) {
    11 /******/ 			for(var key in definition) {
    12 /******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
    12 /******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
    13 /******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
    13 /******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
    14 /******/ 				}
    14 /******/ 				}
    15 /******/ 			}
    15 /******/ 			}
    16 /******/ 		};
    16 /******/ 		};
    17 /******/ 	}();
    17 /******/ 	})();
    18 /******/ 	
    18 /******/ 	
    19 /******/ 	/* webpack/runtime/hasOwnProperty shorthand */
    19 /******/ 	/* webpack/runtime/hasOwnProperty shorthand */
    20 /******/ 	!function() {
    20 /******/ 	(() => {
    21 /******/ 		__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
    21 /******/ 		__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
    22 /******/ 	}();
    22 /******/ 	})();
    23 /******/ 	
    23 /******/ 	
    24 /************************************************************************/
    24 /************************************************************************/
    25 var __webpack_exports__ = {};
    25 var __webpack_exports__ = {};
    26 
    26 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
    27 // EXPORTS
    27 /* harmony export */   "default": () => (/* binding */ TokenList)
    28 __webpack_require__.d(__webpack_exports__, {
    28 /* harmony export */ });
    29   "default": function() { return /* binding */ TokenList; }
       
    30 });
       
    31 
       
    32 ;// CONCATENATED MODULE: external "lodash"
       
    33 var external_lodash_namespaceObject = window["lodash"];
       
    34 ;// CONCATENATED MODULE: ./node_modules/@wordpress/token-list/build-module/index.js
       
    35 /**
       
    36  * External dependencies
       
    37  */
       
    38 
       
    39 /**
    29 /**
    40  * A set of tokens.
    30  * A set of tokens.
    41  *
    31  *
    42  * @see https://dom.spec.whatwg.org/#domtokenlist
    32  * @see https://dom.spec.whatwg.org/#domtokenlist
    43  */
    33  */
    44 
       
    45 class TokenList {
    34 class TokenList {
    46   /**
    35   /**
    47    * Constructs a new instance of TokenList.
    36    * Constructs a new instance of TokenList.
    48    *
    37    *
    49    * @param {string} initialValue Initial value to assign.
    38    * @param {string} initialValue Initial value to assign.
    50    */
    39    */
    51   constructor() {
    40   constructor(initialValue = '') {
    52     let initialValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
    41     this.value = initialValue;
    53     this.value = initialValue; // Disable reason: These are type hints on the class.
    42 
    54 
    43     // Disable reason: These are type hints on the class.
    55     /* eslint-disable no-unused-expressions */
    44     /* eslint-disable no-unused-expressions */
    56 
       
    57     /** @type {string} */
    45     /** @type {string} */
    58 
       
    59     this._currentValue;
    46     this._currentValue;
       
    47 
    60     /** @type {string[]} */
    48     /** @type {string[]} */
    61 
       
    62     this._valueAsArray;
    49     this._valueAsArray;
    63     /* eslint-enable no-unused-expressions */
    50     /* eslint-enable no-unused-expressions */
    64   }
    51   }
       
    52 
    65   /**
    53   /**
    66    * @param {Parameters<Array<string>['entries']>} args
    54    * @param {Parameters<Array<string>['entries']>} args
    67    */
    55    */
    68 
    56   entries(...args) {
    69 
    57     return this._valueAsArray.entries(...args);
    70   entries() {
    58   }
    71     return this._valueAsArray.entries(...arguments);
    59 
    72   }
       
    73   /**
    60   /**
    74    * @param {Parameters<Array<string>['forEach']>} args
    61    * @param {Parameters<Array<string>['forEach']>} args
    75    */
    62    */
    76 
    63   forEach(...args) {
    77 
    64     return this._valueAsArray.forEach(...args);
    78   forEach() {
    65   }
    79     return this._valueAsArray.forEach(...arguments);
    66 
    80   }
       
    81   /**
    67   /**
    82    * @param {Parameters<Array<string>['keys']>} args
    68    * @param {Parameters<Array<string>['keys']>} args
    83    */
    69    */
    84 
    70   keys(...args) {
    85 
    71     return this._valueAsArray.keys(...args);
    86   keys() {
    72   }
    87     return this._valueAsArray.keys(...arguments);
    73 
    88   }
       
    89   /**
    74   /**
    90    * @param {Parameters<Array<string>['values']>} args
    75    * @param {Parameters<Array<string>['values']>} args
    91    */
    76    */
    92 
    77   values(...args) {
    93 
    78     return this._valueAsArray.values(...args);
    94   values() {
    79   }
    95     return this._valueAsArray.values(...arguments);
    80 
    96   }
       
    97   /**
    81   /**
    98    * Returns the associated set as string.
    82    * Returns the associated set as string.
    99    *
    83    *
   100    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-value
    84    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-value
   101    *
    85    *
   102    * @return {string} Token set as string.
    86    * @return {string} Token set as string.
   103    */
    87    */
   104 
       
   105 
       
   106   get value() {
    88   get value() {
   107     return this._currentValue;
    89     return this._currentValue;
   108   }
    90   }
       
    91 
   109   /**
    92   /**
   110    * Replaces the associated set with a new string value.
    93    * Replaces the associated set with a new string value.
   111    *
    94    *
   112    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-value
    95    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-value
   113    *
    96    *
   114    * @param {string} value New token set as string.
    97    * @param {string} value New token set as string.
   115    */
    98    */
   116 
       
   117 
       
   118   set value(value) {
    99   set value(value) {
   119     value = String(value);
   100     value = String(value);
   120     this._valueAsArray = (0,external_lodash_namespaceObject.uniq)((0,external_lodash_namespaceObject.compact)(value.split(/\s+/g)));
   101     this._valueAsArray = [...new Set(value.split(/\s+/g).filter(Boolean))];
   121     this._currentValue = this._valueAsArray.join(' ');
   102     this._currentValue = this._valueAsArray.join(' ');
   122   }
   103   }
       
   104 
   123   /**
   105   /**
   124    * Returns the number of tokens.
   106    * Returns the number of tokens.
   125    *
   107    *
   126    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-length
   108    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-length
   127    *
   109    *
   128    * @return {number} Number of tokens.
   110    * @return {number} Number of tokens.
   129    */
   111    */
   130 
       
   131 
       
   132   get length() {
   112   get length() {
   133     return this._valueAsArray.length;
   113     return this._valueAsArray.length;
   134   }
   114   }
       
   115 
   135   /**
   116   /**
   136    * Returns the stringified form of the TokenList.
   117    * Returns the stringified form of the TokenList.
   137    *
   118    *
   138    * @see https://dom.spec.whatwg.org/#DOMTokenList-stringification-behavior
   119    * @see https://dom.spec.whatwg.org/#DOMTokenList-stringification-behavior
   139    * @see https://www.ecma-international.org/ecma-262/9.0/index.html#sec-tostring
   120    * @see https://www.ecma-international.org/ecma-262/9.0/index.html#sec-tostring
   140    *
   121    *
   141    * @return {string} Token set as string.
   122    * @return {string} Token set as string.
   142    */
   123    */
   143 
       
   144 
       
   145   toString() {
   124   toString() {
   146     return this.value;
   125     return this.value;
   147   }
   126   }
       
   127 
   148   /**
   128   /**
   149    * Returns an iterator for the TokenList, iterating items of the set.
   129    * Returns an iterator for the TokenList, iterating items of the set.
   150    *
   130    *
   151    * @see https://dom.spec.whatwg.org/#domtokenlist
   131    * @see https://dom.spec.whatwg.org/#domtokenlist
   152    *
   132    *
   153    * @return {IterableIterator<string>} TokenList iterator.
   133    * @return {IterableIterator<string>} TokenList iterator.
   154    */
   134    */
   155 
       
   156 
       
   157   *[Symbol.iterator]() {
   135   *[Symbol.iterator]() {
   158     return yield* this._valueAsArray;
   136     return yield* this._valueAsArray;
   159   }
   137   }
       
   138 
   160   /**
   139   /**
   161    * Returns the token with index `index`.
   140    * Returns the token with index `index`.
   162    *
   141    *
   163    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-item
   142    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-item
   164    *
   143    *
   165    * @param {number} index Index at which to return token.
   144    * @param {number} index Index at which to return token.
   166    *
   145    *
   167    * @return {string|undefined} Token at index.
   146    * @return {string|undefined} Token at index.
   168    */
   147    */
   169 
       
   170 
       
   171   item(index) {
   148   item(index) {
   172     return this._valueAsArray[index];
   149     return this._valueAsArray[index];
   173   }
   150   }
       
   151 
   174   /**
   152   /**
   175    * Returns true if `token` is present, and false otherwise.
   153    * Returns true if `token` is present, and false otherwise.
   176    *
   154    *
   177    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-contains
   155    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-contains
   178    *
   156    *
   179    * @param {string} item Token to test.
   157    * @param {string} item Token to test.
   180    *
   158    *
   181    * @return {boolean} Whether token is present.
   159    * @return {boolean} Whether token is present.
   182    */
   160    */
   183 
       
   184 
       
   185   contains(item) {
   161   contains(item) {
   186     return this._valueAsArray.indexOf(item) !== -1;
   162     return this._valueAsArray.indexOf(item) !== -1;
   187   }
   163   }
       
   164 
   188   /**
   165   /**
   189    * Adds all arguments passed, except those already present.
   166    * Adds all arguments passed, except those already present.
   190    *
   167    *
   191    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-add
   168    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-add
   192    *
   169    *
   193    * @param {...string} items Items to add.
   170    * @param {...string} items Items to add.
   194    */
   171    */
   195 
   172   add(...items) {
   196 
       
   197   add() {
       
   198     for (var _len = arguments.length, items = new Array(_len), _key = 0; _key < _len; _key++) {
       
   199       items[_key] = arguments[_key];
       
   200     }
       
   201 
       
   202     this.value += ' ' + items.join(' ');
   173     this.value += ' ' + items.join(' ');
   203   }
   174   }
       
   175 
   204   /**
   176   /**
   205    * Removes arguments passed, if they are present.
   177    * Removes arguments passed, if they are present.
   206    *
   178    *
   207    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-remove
   179    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-remove
   208    *
   180    *
   209    * @param {...string} items Items to remove.
   181    * @param {...string} items Items to remove.
   210    */
   182    */
   211 
   183   remove(...items) {
   212 
   184     this.value = this._valueAsArray.filter(val => !items.includes(val)).join(' ');
   213   remove() {
   185   }
   214     for (var _len2 = arguments.length, items = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
   186 
   215       items[_key2] = arguments[_key2];
       
   216     }
       
   217 
       
   218     this.value = (0,external_lodash_namespaceObject.without)(this._valueAsArray, ...items).join(' ');
       
   219   }
       
   220   /**
   187   /**
   221    * If `force` is not given, "toggles" `token`, removing it if it’s present
   188    * If `force` is not given, "toggles" `token`, removing it if it’s present
   222    * and adding it if it’s not present. If `force` is true, adds token (same
   189    * and adding it if it’s not present. If `force` is true, adds token (same
   223    * as add()). If force is false, removes token (same as remove()). Returns
   190    * as add()). If force is false, removes token (same as remove()). Returns
   224    * true if `token` is now present, and false otherwise.
   191    * true if `token` is now present, and false otherwise.
   228    * @param {string}  token   Token to toggle.
   195    * @param {string}  token   Token to toggle.
   229    * @param {boolean} [force] Presence to force.
   196    * @param {boolean} [force] Presence to force.
   230    *
   197    *
   231    * @return {boolean} Whether token is present after toggle.
   198    * @return {boolean} Whether token is present after toggle.
   232    */
   199    */
   233 
       
   234 
       
   235   toggle(token, force) {
   200   toggle(token, force) {
   236     if (undefined === force) {
   201     if (undefined === force) {
   237       force = !this.contains(token);
   202       force = !this.contains(token);
   238     }
   203     }
   239 
       
   240     if (force) {
   204     if (force) {
   241       this.add(token);
   205       this.add(token);
   242     } else {
   206     } else {
   243       this.remove(token);
   207       this.remove(token);
   244     }
   208     }
   245 
       
   246     return force;
   209     return force;
   247   }
   210   }
       
   211 
   248   /**
   212   /**
   249    * Replaces `token` with `newToken`. Returns true if `token` was replaced
   213    * Replaces `token` with `newToken`. Returns true if `token` was replaced
   250    * with `newToken`, and false otherwise.
   214    * with `newToken`, and false otherwise.
   251    *
   215    *
   252    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-replace
   216    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-replace
   254    * @param {string} token    Token to replace with `newToken`.
   218    * @param {string} token    Token to replace with `newToken`.
   255    * @param {string} newToken Token to use in place of `token`.
   219    * @param {string} newToken Token to use in place of `token`.
   256    *
   220    *
   257    * @return {boolean} Whether replacement occurred.
   221    * @return {boolean} Whether replacement occurred.
   258    */
   222    */
   259 
       
   260 
       
   261   replace(token, newToken) {
   223   replace(token, newToken) {
   262     if (!this.contains(token)) {
   224     if (!this.contains(token)) {
   263       return false;
   225       return false;
   264     }
   226     }
   265 
       
   266     this.remove(token);
   227     this.remove(token);
   267     this.add(newToken);
   228     this.add(newToken);
   268     return true;
   229     return true;
   269   }
   230   }
       
   231 
   270   /**
   232   /**
   271    * Returns true if `token` is in the associated attribute’s supported
   233    * Returns true if `token` is in the associated attribute’s supported
   272    * tokens. Returns false otherwise.
   234    * tokens. Returns false otherwise.
   273    *
   235    *
   274    * Always returns `true` in this implementation.
   236    * Always returns `true` in this implementation.
   275    *
   237    *
   276    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-supports
   238    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-supports
   277    *
   239    *
   278    * @return {boolean} Whether token is supported.
   240    * @return {boolean} Whether token is supported.
   279    */
   241    */
   280 
       
   281 
       
   282   supports() {
   242   supports() {
   283     return true;
   243     return true;
   284   }
   244   }
   285 
       
   286 }
   245 }
   287 
   246 
   288 (window.wp = window.wp || {}).tokenList = __webpack_exports__["default"];
   247 (window.wp = window.wp || {}).tokenList = __webpack_exports__["default"];
   289 /******/ })()
   248 /******/ })()
   290 ;
   249 ;