wp/wp-includes/js/dist/token-list.js
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    80 /******/ 	// __webpack_public_path__
    80 /******/ 	// __webpack_public_path__
    81 /******/ 	__webpack_require__.p = "";
    81 /******/ 	__webpack_require__.p = "";
    82 /******/
    82 /******/
    83 /******/
    83 /******/
    84 /******/ 	// Load entry module and return exports
    84 /******/ 	// Load entry module and return exports
    85 /******/ 	return __webpack_require__(__webpack_require__.s = 432);
    85 /******/ 	return __webpack_require__(__webpack_require__.s = "hwXU");
    86 /******/ })
    86 /******/ })
    87 /************************************************************************/
    87 /************************************************************************/
    88 /******/ ({
    88 /******/ ({
    89 
    89 
    90 /***/ 19:
    90 /***/ "YLtl":
    91 /***/ (function(module, __webpack_exports__, __webpack_require__) {
    91 /***/ (function(module, exports) {
    92 
    92 
    93 "use strict";
    93 (function() { module.exports = window["lodash"]; }());
    94 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _createClass; });
       
    95 function _defineProperties(target, props) {
       
    96   for (var i = 0; i < props.length; i++) {
       
    97     var descriptor = props[i];
       
    98     descriptor.enumerable = descriptor.enumerable || false;
       
    99     descriptor.configurable = true;
       
   100     if ("value" in descriptor) descriptor.writable = true;
       
   101     Object.defineProperty(target, descriptor.key, descriptor);
       
   102   }
       
   103 }
       
   104 
       
   105 function _createClass(Constructor, protoProps, staticProps) {
       
   106   if (protoProps) _defineProperties(Constructor.prototype, protoProps);
       
   107   if (staticProps) _defineProperties(Constructor, staticProps);
       
   108   return Constructor;
       
   109 }
       
   110 
    94 
   111 /***/ }),
    95 /***/ }),
   112 
    96 
   113 /***/ 2:
    97 /***/ "hwXU":
   114 /***/ (function(module, exports) {
       
   115 
       
   116 (function() { module.exports = this["lodash"]; }());
       
   117 
       
   118 /***/ }),
       
   119 
       
   120 /***/ 20:
       
   121 /***/ (function(module, __webpack_exports__, __webpack_require__) {
       
   122 
       
   123 "use strict";
       
   124 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _classCallCheck; });
       
   125 function _classCallCheck(instance, Constructor) {
       
   126   if (!(instance instanceof Constructor)) {
       
   127     throw new TypeError("Cannot call a class as a function");
       
   128   }
       
   129 }
       
   130 
       
   131 /***/ }),
       
   132 
       
   133 /***/ 24:
       
   134 /***/ (function(module, exports) {
       
   135 
       
   136 (function() { module.exports = this["regeneratorRuntime"]; }());
       
   137 
       
   138 /***/ }),
       
   139 
       
   140 /***/ 432:
       
   141 /***/ (function(module, __webpack_exports__, __webpack_require__) {
    98 /***/ (function(module, __webpack_exports__, __webpack_require__) {
   142 
    99 
   143 "use strict";
   100 "use strict";
   144 __webpack_require__.r(__webpack_exports__);
   101 __webpack_require__.r(__webpack_exports__);
   145 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return TokenList; });
   102 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return TokenList; });
   146 /* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(24);
   103 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("YLtl");
   147 /* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0__);
   104 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__);
   148 /* harmony import */ var _babel_runtime_helpers_esm_classCallCheck__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(20);
       
   149 /* harmony import */ var _babel_runtime_helpers_esm_createClass__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(19);
       
   150 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2);
       
   151 /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_3__);
       
   152 
       
   153 
       
   154 
       
   155 
       
   156 /**
   105 /**
   157  * External dependencies
   106  * External dependencies
   158  */
   107  */
   159 
   108 
   160 /**
   109 /**
   161  * A set of tokens.
   110  * A set of tokens.
   162  *
   111  *
   163  * @see https://dom.spec.whatwg.org/#domtokenlist
   112  * @see https://dom.spec.whatwg.org/#domtokenlist
   164  */
   113  */
   165 
   114 
   166 var TokenList = /*#__PURE__*/function () {
   115 class TokenList {
   167   /**
   116   /**
   168    * Constructs a new instance of TokenList.
   117    * Constructs a new instance of TokenList.
   169    *
   118    *
   170    * @param {string} initialValue Initial value to assign.
   119    * @param {string} initialValue Initial value to assign.
   171    */
   120    */
   172   function TokenList() {
   121   constructor(initialValue = '') {
   173     var initialValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
       
   174 
       
   175     Object(_babel_runtime_helpers_esm_classCallCheck__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"])(this, TokenList);
       
   176 
       
   177     this.value = initialValue; // Disable reason: These are type hints on the class.
   122     this.value = initialValue; // Disable reason: These are type hints on the class.
   178 
   123 
   179     /* eslint-disable no-unused-expressions */
   124     /* eslint-disable no-unused-expressions */
   180 
   125 
   181     /** @type {string} */
   126     /** @type {string} */
   183     this._currentValue;
   128     this._currentValue;
   184     /** @type {string[]} */
   129     /** @type {string[]} */
   185 
   130 
   186     this._valueAsArray;
   131     this._valueAsArray;
   187     /* eslint-enable no-unused-expressions */
   132     /* eslint-enable no-unused-expressions */
   188   } // Disable reason: JSDoc lint doesn't understand TypeScript types
   133   }
   189 
       
   190   /* eslint-disable jsdoc/valid-types */
       
   191 
       
   192   /**
   134   /**
   193    * @param {Parameters<Array<string>['entries']>} args
   135    * @param {Parameters<Array<string>['entries']>} args
   194    */
   136    */
   195 
   137 
   196 
   138 
   197   Object(_babel_runtime_helpers_esm_createClass__WEBPACK_IMPORTED_MODULE_2__[/* default */ "a"])(TokenList, [{
   139   entries(...args) {
   198     key: "entries",
   140     return this._valueAsArray.entries(...args);
   199     value: function entries() {
   141   }
   200       var _this$_valueAsArray;
   142   /**
   201 
   143    * @param {Parameters<Array<string>['forEach']>} args
   202       return (_this$_valueAsArray = this._valueAsArray).entries.apply(_this$_valueAsArray, arguments);
   144    */
       
   145 
       
   146 
       
   147   forEach(...args) {
       
   148     return this._valueAsArray.forEach(...args);
       
   149   }
       
   150   /**
       
   151    * @param {Parameters<Array<string>['keys']>} args
       
   152    */
       
   153 
       
   154 
       
   155   keys(...args) {
       
   156     return this._valueAsArray.keys(...args);
       
   157   }
       
   158   /**
       
   159    * @param {Parameters<Array<string>['values']>} args
       
   160    */
       
   161 
       
   162 
       
   163   values(...args) {
       
   164     return this._valueAsArray.values(...args);
       
   165   }
       
   166   /**
       
   167    * Returns the associated set as string.
       
   168    *
       
   169    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-value
       
   170    *
       
   171    * @return {string} Token set as string.
       
   172    */
       
   173 
       
   174 
       
   175   get value() {
       
   176     return this._currentValue;
       
   177   }
       
   178   /**
       
   179    * Replaces the associated set with a new string value.
       
   180    *
       
   181    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-value
       
   182    *
       
   183    * @param {string} value New token set as string.
       
   184    */
       
   185 
       
   186 
       
   187   set value(value) {
       
   188     value = String(value);
       
   189     this._valueAsArray = Object(lodash__WEBPACK_IMPORTED_MODULE_0__["uniq"])(Object(lodash__WEBPACK_IMPORTED_MODULE_0__["compact"])(value.split(/\s+/g)));
       
   190     this._currentValue = this._valueAsArray.join(' ');
       
   191   }
       
   192   /**
       
   193    * Returns the number of tokens.
       
   194    *
       
   195    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-length
       
   196    *
       
   197    * @return {number} Number of tokens.
       
   198    */
       
   199 
       
   200 
       
   201   get length() {
       
   202     return this._valueAsArray.length;
       
   203   }
       
   204   /**
       
   205    * Returns the stringified form of the TokenList.
       
   206    *
       
   207    * @see https://dom.spec.whatwg.org/#DOMTokenList-stringification-behavior
       
   208    * @see https://www.ecma-international.org/ecma-262/9.0/index.html#sec-tostring
       
   209    *
       
   210    * @return {string} Token set as string.
       
   211    */
       
   212 
       
   213 
       
   214   toString() {
       
   215     return this.value;
       
   216   }
       
   217   /**
       
   218    * Returns an iterator for the TokenList, iterating items of the set.
       
   219    *
       
   220    * @see https://dom.spec.whatwg.org/#domtokenlist
       
   221    *
       
   222    * @return {IterableIterator<string>} TokenList iterator.
       
   223    */
       
   224 
       
   225 
       
   226   *[Symbol.iterator]() {
       
   227     return yield* this._valueAsArray;
       
   228   }
       
   229   /**
       
   230    * Returns the token with index `index`.
       
   231    *
       
   232    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-item
       
   233    *
       
   234    * @param {number} index Index at which to return token.
       
   235    *
       
   236    * @return {string|undefined} Token at index.
       
   237    */
       
   238 
       
   239 
       
   240   item(index) {
       
   241     return this._valueAsArray[index];
       
   242   }
       
   243   /**
       
   244    * Returns true if `token` is present, and false otherwise.
       
   245    *
       
   246    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-contains
       
   247    *
       
   248    * @param {string} item Token to test.
       
   249    *
       
   250    * @return {boolean} Whether token is present.
       
   251    */
       
   252 
       
   253 
       
   254   contains(item) {
       
   255     return this._valueAsArray.indexOf(item) !== -1;
       
   256   }
       
   257   /**
       
   258    * Adds all arguments passed, except those already present.
       
   259    *
       
   260    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-add
       
   261    *
       
   262    * @param {...string} items Items to add.
       
   263    */
       
   264 
       
   265 
       
   266   add(...items) {
       
   267     this.value += ' ' + items.join(' ');
       
   268   }
       
   269   /**
       
   270    * Removes arguments passed, if they are present.
       
   271    *
       
   272    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-remove
       
   273    *
       
   274    * @param {...string} items Items to remove.
       
   275    */
       
   276 
       
   277 
       
   278   remove(...items) {
       
   279     this.value = Object(lodash__WEBPACK_IMPORTED_MODULE_0__["without"])(this._valueAsArray, ...items).join(' ');
       
   280   }
       
   281   /**
       
   282    * If `force` is not given, "toggles" `token`, removing it if it’s present
       
   283    * and adding it if it’s not present. If `force` is true, adds token (same
       
   284    * as add()). If force is false, removes token (same as remove()). Returns
       
   285    * true if `token` is now present, and false otherwise.
       
   286    *
       
   287    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-toggle
       
   288    *
       
   289    * @param {string}  token   Token to toggle.
       
   290    * @param {boolean} [force] Presence to force.
       
   291    *
       
   292    * @return {boolean} Whether token is present after toggle.
       
   293    */
       
   294 
       
   295 
       
   296   toggle(token, force) {
       
   297     if (undefined === force) {
       
   298       force = !this.contains(token);
   203     }
   299     }
   204     /**
   300 
   205      * @param {Parameters<Array<string>['forEach']>} args
   301     if (force) {
   206      */
   302       this.add(token);
   207 
   303     } else {
   208   }, {
   304       this.remove(token);
   209     key: "forEach",
       
   210     value: function forEach() {
       
   211       var _this$_valueAsArray2;
       
   212 
       
   213       return (_this$_valueAsArray2 = this._valueAsArray).forEach.apply(_this$_valueAsArray2, arguments);
       
   214     }
   305     }
   215     /**
   306 
   216      * @param {Parameters<Array<string>['keys']>} args
   307     return force;
   217      */
   308   }
   218 
   309   /**
   219   }, {
   310    * Replaces `token` with `newToken`. Returns true if `token` was replaced
   220     key: "keys",
   311    * with `newToken`, and false otherwise.
   221     value: function keys() {
   312    *
   222       var _this$_valueAsArray3;
   313    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-replace
   223 
   314    *
   224       return (_this$_valueAsArray3 = this._valueAsArray).keys.apply(_this$_valueAsArray3, arguments);
   315    * @param {string} token    Token to replace with `newToken`.
       
   316    * @param {string} newToken Token to use in place of `token`.
       
   317    *
       
   318    * @return {boolean} Whether replacement occurred.
       
   319    */
       
   320 
       
   321 
       
   322   replace(token, newToken) {
       
   323     if (!this.contains(token)) {
       
   324       return false;
   225     }
   325     }
   226     /**
   326 
   227      * @param {Parameters<Array<string>['values']>} args
   327     this.remove(token);
   228      */
   328     this.add(newToken);
   229 
   329     return true;
   230   }, {
   330   }
   231     key: "values",
   331   /**
   232     value: function values() {
   332    * Returns true if `token` is in the associated attribute’s supported
   233       var _this$_valueAsArray4;
   333    * tokens. Returns false otherwise.
   234 
   334    *
   235       return (_this$_valueAsArray4 = this._valueAsArray).values.apply(_this$_valueAsArray4, arguments);
   335    * Always returns `true` in this implementation.
   236     }
   336    *
   237     /* eslint-enable jsdoc/valid-types */
   337    * @see https://dom.spec.whatwg.org/#dom-domtokenlist-supports
   238 
   338    *
   239     /**
   339    * @return {boolean} Whether token is supported.
   240      * Returns the associated set as string.
   340    */
   241      *
   341 
   242      * @see https://dom.spec.whatwg.org/#dom-domtokenlist-value
   342 
   243      *
   343   supports() {
   244      * @return {string} Token set as string.
   344     return true;
   245      */
   345   }
   246 
   346 
   247   }, {
   347 }
   248     key: "toString",
       
   249 
       
   250     /**
       
   251      * Returns the stringified form of the TokenList.
       
   252      *
       
   253      * @see https://dom.spec.whatwg.org/#DOMTokenList-stringification-behavior
       
   254      * @see https://www.ecma-international.org/ecma-262/9.0/index.html#sec-tostring
       
   255      *
       
   256      * @return {string} Token set as string.
       
   257      */
       
   258     value: function toString() {
       
   259       return this.value;
       
   260     }
       
   261     /**
       
   262      * Returns an iterator for the TokenList, iterating items of the set.
       
   263      *
       
   264      * @see https://dom.spec.whatwg.org/#domtokenlist
       
   265      *
       
   266      * @return {IterableIterator<string>} TokenList iterator.
       
   267      */
       
   268 
       
   269   }, {
       
   270     key: Symbol.iterator,
       
   271     value: /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.mark(function value() {
       
   272       return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.wrap(function value$(_context) {
       
   273         while (1) {
       
   274           switch (_context.prev = _context.next) {
       
   275             case 0:
       
   276               return _context.delegateYield(this._valueAsArray, "t0", 1);
       
   277 
       
   278             case 1:
       
   279               return _context.abrupt("return", _context.t0);
       
   280 
       
   281             case 2:
       
   282             case "end":
       
   283               return _context.stop();
       
   284           }
       
   285         }
       
   286       }, value, this);
       
   287     })
       
   288     /**
       
   289      * Returns the token with index `index`.
       
   290      *
       
   291      * @see https://dom.spec.whatwg.org/#dom-domtokenlist-item
       
   292      *
       
   293      * @param {number} index Index at which to return token.
       
   294      *
       
   295      * @return {string|undefined} Token at index.
       
   296      */
       
   297 
       
   298   }, {
       
   299     key: "item",
       
   300     value: function item(index) {
       
   301       return this._valueAsArray[index];
       
   302     }
       
   303     /**
       
   304      * Returns true if `token` is present, and false otherwise.
       
   305      *
       
   306      * @see https://dom.spec.whatwg.org/#dom-domtokenlist-contains
       
   307      *
       
   308      * @param {string} item Token to test.
       
   309      *
       
   310      * @return {boolean} Whether token is present.
       
   311      */
       
   312 
       
   313   }, {
       
   314     key: "contains",
       
   315     value: function contains(item) {
       
   316       return this._valueAsArray.indexOf(item) !== -1;
       
   317     }
       
   318     /**
       
   319      * Adds all arguments passed, except those already present.
       
   320      *
       
   321      * @see https://dom.spec.whatwg.org/#dom-domtokenlist-add
       
   322      *
       
   323      * @param {...string} items Items to add.
       
   324      */
       
   325 
       
   326   }, {
       
   327     key: "add",
       
   328     value: function add() {
       
   329       for (var _len = arguments.length, items = new Array(_len), _key = 0; _key < _len; _key++) {
       
   330         items[_key] = arguments[_key];
       
   331       }
       
   332 
       
   333       this.value += ' ' + items.join(' ');
       
   334     }
       
   335     /**
       
   336      * Removes arguments passed, if they are present.
       
   337      *
       
   338      * @see https://dom.spec.whatwg.org/#dom-domtokenlist-remove
       
   339      *
       
   340      * @param {...string} items Items to remove.
       
   341      */
       
   342 
       
   343   }, {
       
   344     key: "remove",
       
   345     value: function remove() {
       
   346       for (var _len2 = arguments.length, items = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
       
   347         items[_key2] = arguments[_key2];
       
   348       }
       
   349 
       
   350       this.value = lodash__WEBPACK_IMPORTED_MODULE_3__["without"].apply(void 0, [this._valueAsArray].concat(items)).join(' ');
       
   351     }
       
   352     /**
       
   353      * If `force` is not given, "toggles" `token`, removing it if it’s present
       
   354      * and adding it if it’s not present. If `force` is true, adds token (same
       
   355      * as add()). If force is false, removes token (same as remove()). Returns
       
   356      * true if `token` is now present, and false otherwise.
       
   357      *
       
   358      * @see https://dom.spec.whatwg.org/#dom-domtokenlist-toggle
       
   359      *
       
   360      * @param {string}  token   Token to toggle.
       
   361      * @param {boolean} [force] Presence to force.
       
   362      *
       
   363      * @return {boolean} Whether token is present after toggle.
       
   364      */
       
   365 
       
   366   }, {
       
   367     key: "toggle",
       
   368     value: function toggle(token, force) {
       
   369       if (undefined === force) {
       
   370         force = !this.contains(token);
       
   371       }
       
   372 
       
   373       if (force) {
       
   374         this.add(token);
       
   375       } else {
       
   376         this.remove(token);
       
   377       }
       
   378 
       
   379       return force;
       
   380     }
       
   381     /**
       
   382      * Replaces `token` with `newToken`. Returns true if `token` was replaced
       
   383      * with `newToken`, and false otherwise.
       
   384      *
       
   385      * @see https://dom.spec.whatwg.org/#dom-domtokenlist-replace
       
   386      *
       
   387      * @param {string} token    Token to replace with `newToken`.
       
   388      * @param {string} newToken Token to use in place of `token`.
       
   389      *
       
   390      * @return {boolean} Whether replacement occurred.
       
   391      */
       
   392 
       
   393   }, {
       
   394     key: "replace",
       
   395     value: function replace(token, newToken) {
       
   396       if (!this.contains(token)) {
       
   397         return false;
       
   398       }
       
   399 
       
   400       this.remove(token);
       
   401       this.add(newToken);
       
   402       return true;
       
   403     }
       
   404     /**
       
   405      * Returns true if `token` is in the associated attribute’s supported
       
   406      * tokens. Returns false otherwise.
       
   407      *
       
   408      * Always returns `true` in this implementation.
       
   409      *
       
   410      * @see https://dom.spec.whatwg.org/#dom-domtokenlist-supports
       
   411      *
       
   412      * @return {boolean} Whether token is supported.
       
   413      */
       
   414 
       
   415   }, {
       
   416     key: "supports",
       
   417     value: function supports() {
       
   418       return true;
       
   419     }
       
   420   }, {
       
   421     key: "value",
       
   422     get: function get() {
       
   423       return this._currentValue;
       
   424     }
       
   425     /**
       
   426      * Replaces the associated set with a new string value.
       
   427      *
       
   428      * @see https://dom.spec.whatwg.org/#dom-domtokenlist-value
       
   429      *
       
   430      * @param {string} value New token set as string.
       
   431      */
       
   432     ,
       
   433     set: function set(value) {
       
   434       value = String(value);
       
   435       this._valueAsArray = Object(lodash__WEBPACK_IMPORTED_MODULE_3__["uniq"])(Object(lodash__WEBPACK_IMPORTED_MODULE_3__["compact"])(value.split(/\s+/g)));
       
   436       this._currentValue = this._valueAsArray.join(' ');
       
   437     }
       
   438     /**
       
   439      * Returns the number of tokens.
       
   440      *
       
   441      * @see https://dom.spec.whatwg.org/#dom-domtokenlist-length
       
   442      *
       
   443      * @return {number} Number of tokens.
       
   444      */
       
   445 
       
   446   }, {
       
   447     key: "length",
       
   448     get: function get() {
       
   449       return this._valueAsArray.length;
       
   450     }
       
   451   }]);
       
   452 
       
   453   return TokenList;
       
   454 }();
       
   455 
       
   456 
       
   457 
   348 
   458 
   349 
   459 /***/ })
   350 /***/ })
   460 
   351 
   461 /******/ })["default"];
   352 /******/ })["default"];