kollapsminoriteten/wp-includes/js/dist/token-list.js

229 lines
5.9 KiB
JavaScript
Raw Normal View History

2024-04-17 11:32:24 +02:00
/******/ (() => { // webpackBootstrap
2022-06-16 14:03:35 +02:00
/******/ "use strict";
/******/ // The require scope
/******/ var __webpack_require__ = {};
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
2024-04-17 11:32:24 +02:00
/******/ (() => {
2022-06-16 14:03:35 +02:00
/******/ // define getter functions for harmony exports
2024-04-17 11:32:24 +02:00
/******/ __webpack_require__.d = (exports, definition) => {
2022-06-16 14:03:35 +02:00
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
2019-11-02 10:38:58 +01:00
/******/ };
2024-04-17 11:32:24 +02:00
/******/ })();
2022-06-16 14:03:35 +02:00
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
2024-04-17 11:32:24 +02:00
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
2022-06-16 14:03:35 +02:00
/******/
2019-11-02 10:38:58 +01:00
/************************************************************************/
2022-06-16 14:03:35 +02:00
var __webpack_exports__ = {};
2022-12-15 17:47:31 +01:00
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
2024-04-17 11:32:24 +02:00
/* harmony export */ "default": () => (/* binding */ TokenList)
2022-12-15 17:47:31 +01:00
/* harmony export */ });
2019-11-02 10:38:58 +01:00
/**
* A set of tokens.
*
2019-11-15 22:59:44 +01:00
* @see https://dom.spec.whatwg.org/#domtokenlist
2019-11-02 10:38:58 +01:00
*/
2021-07-23 11:58:50 +02:00
class TokenList {
2019-11-02 10:38:58 +01:00
/**
* Constructs a new instance of TokenList.
*
2025-02-28 08:42:11 +01:00
* @param initialValue Initial value to assign.
2019-11-02 10:38:58 +01:00
*/
2023-09-26 10:33:34 +02:00
constructor(initialValue = '') {
2025-02-28 08:42:11 +01:00
this._currentValue = '';
this._valueAsArray = [];
2023-12-07 09:44:11 +01:00
this.value = initialValue;
2021-07-23 11:58:50 +02:00
}
2023-09-26 10:33:34 +02:00
entries(...args) {
return this._valueAsArray.entries(...args);
2021-07-23 11:58:50 +02:00
}
2023-09-26 10:33:34 +02:00
forEach(...args) {
return this._valueAsArray.forEach(...args);
2021-07-23 11:58:50 +02:00
}
2023-09-26 10:33:34 +02:00
keys(...args) {
return this._valueAsArray.keys(...args);
2021-07-23 11:58:50 +02:00
}
2023-09-26 10:33:34 +02:00
values(...args) {
return this._valueAsArray.values(...args);
2021-07-23 11:58:50 +02:00
}
2023-12-07 09:44:11 +01:00
2021-07-23 11:58:50 +02:00
/**
* Returns the associated set as string.
*
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-value
*
2025-02-28 08:42:11 +01:00
* @return Token set as string.
2021-07-23 11:58:50 +02:00
*/
get value() {
return this._currentValue;
}
2023-12-07 09:44:11 +01:00
2021-07-23 11:58:50 +02:00
/**
* Replaces the associated set with a new string value.
*
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-value
*
2025-02-28 08:42:11 +01:00
* @param value New token set as string.
2021-07-23 11:58:50 +02:00
*/
set value(value) {
value = String(value);
2022-12-15 17:47:31 +01:00
this._valueAsArray = [...new Set(value.split(/\s+/g).filter(Boolean))];
2021-07-23 11:58:50 +02:00
this._currentValue = this._valueAsArray.join(' ');
}
2023-12-07 09:44:11 +01:00
2021-07-23 11:58:50 +02:00
/**
* Returns the number of tokens.
*
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-length
*
2025-02-28 08:42:11 +01:00
* @return Number of tokens.
2021-07-23 11:58:50 +02:00
*/
get length() {
return this._valueAsArray.length;
}
2023-12-07 09:44:11 +01:00
2021-07-23 11:58:50 +02:00
/**
* Returns the stringified form of the TokenList.
*
* @see https://dom.spec.whatwg.org/#DOMTokenList-stringification-behavior
* @see https://www.ecma-international.org/ecma-262/9.0/index.html#sec-tostring
*
2025-02-28 08:42:11 +01:00
* @return Token set as string.
2021-07-23 11:58:50 +02:00
*/
toString() {
return this.value;
}
2023-12-07 09:44:11 +01:00
2021-07-23 11:58:50 +02:00
/**
* Returns an iterator for the TokenList, iterating items of the set.
*
* @see https://dom.spec.whatwg.org/#domtokenlist
*
2025-02-28 08:42:11 +01:00
* @return TokenList iterator.
2021-07-23 11:58:50 +02:00
*/
*[Symbol.iterator]() {
return yield* this._valueAsArray;
}
2023-12-07 09:44:11 +01:00
2021-07-23 11:58:50 +02:00
/**
* Returns the token with index `index`.
*
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-item
*
2025-02-28 08:42:11 +01:00
* @param index Index at which to return token.
2021-07-23 11:58:50 +02:00
*
2025-02-28 08:42:11 +01:00
* @return Token at index.
2021-07-23 11:58:50 +02:00
*/
item(index) {
return this._valueAsArray[index];
}
2023-12-07 09:44:11 +01:00
2021-07-23 11:58:50 +02:00
/**
* Returns true if `token` is present, and false otherwise.
*
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-contains
*
2025-02-28 08:42:11 +01:00
* @param item Token to test.
2021-07-23 11:58:50 +02:00
*
2025-02-28 08:42:11 +01:00
* @return Whether token is present.
2021-07-23 11:58:50 +02:00
*/
contains(item) {
return this._valueAsArray.indexOf(item) !== -1;
}
2023-12-07 09:44:11 +01:00
2021-07-23 11:58:50 +02:00
/**
* Adds all arguments passed, except those already present.
*
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-add
*
2025-02-28 08:42:11 +01:00
* @param items Items to add.
2021-07-23 11:58:50 +02:00
*/
2023-09-26 10:33:34 +02:00
add(...items) {
2021-07-23 11:58:50 +02:00
this.value += ' ' + items.join(' ');
}
2023-12-07 09:44:11 +01:00
2021-07-23 11:58:50 +02:00
/**
* Removes arguments passed, if they are present.
*
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-remove
*
2025-02-28 08:42:11 +01:00
* @param items Items to remove.
2021-07-23 11:58:50 +02:00
*/
2023-09-26 10:33:34 +02:00
remove(...items) {
2022-12-15 17:47:31 +01:00
this.value = this._valueAsArray.filter(val => !items.includes(val)).join(' ');
2021-07-23 11:58:50 +02:00
}
2023-12-07 09:44:11 +01:00
2021-07-23 11:58:50 +02:00
/**
* If `force` is not given, "toggles" `token`, removing it if its present
* and adding it if its not present. If `force` is true, adds token (same
* as add()). If force is false, removes token (same as remove()). Returns
* true if `token` is now present, and false otherwise.
*
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-toggle
*
2025-02-28 08:42:11 +01:00
* @param token Token to toggle.
* @param [force] Presence to force.
2021-07-23 11:58:50 +02:00
*
2025-02-28 08:42:11 +01:00
* @return Whether token is present after toggle.
2021-07-23 11:58:50 +02:00
*/
toggle(token, force) {
if (undefined === force) {
force = !this.contains(token);
2019-11-02 10:38:58 +01:00
}
2021-07-23 11:58:50 +02:00
if (force) {
this.add(token);
} else {
2019-11-02 10:38:58 +01:00
this.remove(token);
}
2021-07-23 11:58:50 +02:00
return force;
}
2023-12-07 09:44:11 +01:00
2021-07-23 11:58:50 +02:00
/**
* Replaces `token` with `newToken`. Returns true if `token` was replaced
* with `newToken`, and false otherwise.
*
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-replace
*
2025-02-28 08:42:11 +01:00
* @param token Token to replace with `newToken`.
* @param newToken Token to use in place of `token`.
2021-07-23 11:58:50 +02:00
*
2025-02-28 08:42:11 +01:00
* @return Whether replacement occurred.
2021-07-23 11:58:50 +02:00
*/
replace(token, newToken) {
if (!this.contains(token)) {
return false;
2019-11-02 10:38:58 +01:00
}
2021-07-23 11:58:50 +02:00
this.remove(token);
this.add(newToken);
return true;
}
2023-12-07 09:44:11 +01:00
2025-02-28 08:42:11 +01:00
/* eslint-disable @typescript-eslint/no-unused-vars */
2021-07-23 11:58:50 +02:00
/**
* Returns true if `token` is in the associated attributes supported
* tokens. Returns false otherwise.
*
* Always returns `true` in this implementation.
*
2025-02-28 08:42:11 +01:00
* @param _token
2021-07-23 11:58:50 +02:00
* @see https://dom.spec.whatwg.org/#dom-domtokenlist-supports
*
2025-02-28 08:42:11 +01:00
* @return Whether token is supported.
2021-07-23 11:58:50 +02:00
*/
2025-02-28 08:42:11 +01:00
supports(_token) {
2021-07-23 11:58:50 +02:00
return true;
}
2025-02-28 08:42:11 +01:00
/* eslint-enable @typescript-eslint/no-unused-vars */
2021-07-23 11:58:50 +02:00
}
2019-11-02 10:38:58 +01:00
2022-06-16 14:03:35 +02:00
(window.wp = window.wp || {}).tokenList = __webpack_exports__["default"];
/******/ })()
;