[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/dist/ -> token-list.js (source)

   1  "use strict";
   2  var wp;
   3  (wp ||= {}).tokenList = (() => {
   4    var __defProp = Object.defineProperty;
   5    var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
   6    var __getOwnPropNames = Object.getOwnPropertyNames;
   7    var __hasOwnProp = Object.prototype.hasOwnProperty;
   8    var __export = (target, all) => {
   9      for (var name in all)
  10        __defProp(target, name, { get: all[name], enumerable: true });
  11    };
  12    var __copyProps = (to, from, except, desc) => {
  13      if (from && typeof from === "object" || typeof from === "function") {
  14        for (let key of __getOwnPropNames(from))
  15          if (!__hasOwnProp.call(to, key) && key !== except)
  16            __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  17      }
  18      return to;
  19    };
  20    var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  21  
  22    // packages/token-list/build-module/index.js
  23    var index_exports = {};
  24    __export(index_exports, {
  25      default: () => TokenList
  26    });
  27    var TokenList = class {
  28      _currentValue;
  29      _valueAsArray;
  30      /**
  31       * Constructs a new instance of TokenList.
  32       *
  33       * @param initialValue Initial value to assign.
  34       */
  35      constructor(initialValue = "") {
  36        this._currentValue = "";
  37        this._valueAsArray = [];
  38        this.value = initialValue;
  39      }
  40      entries(...args) {
  41        return this._valueAsArray.entries(...args);
  42      }
  43      forEach(...args) {
  44        return this._valueAsArray.forEach(...args);
  45      }
  46      keys(...args) {
  47        return this._valueAsArray.keys(...args);
  48      }
  49      values(...args) {
  50        return this._valueAsArray.values(...args);
  51      }
  52      /**
  53       * Returns the associated set as string.
  54       *
  55       * @see https://dom.spec.whatwg.org/#dom-domtokenlist-value
  56       *
  57       * @return Token set as string.
  58       */
  59      get value() {
  60        return this._currentValue;
  61      }
  62      /**
  63       * Replaces the associated set with a new string value.
  64       *
  65       * @see https://dom.spec.whatwg.org/#dom-domtokenlist-value
  66       *
  67       * @param value New token set as string.
  68       */
  69      set value(value) {
  70        value = String(value);
  71        this._valueAsArray = [
  72          ...new Set(value.split(/\s+/g).filter(Boolean))
  73        ];
  74        this._currentValue = this._valueAsArray.join(" ");
  75      }
  76      /**
  77       * Returns the number of tokens.
  78       *
  79       * @see https://dom.spec.whatwg.org/#dom-domtokenlist-length
  80       *
  81       * @return Number of tokens.
  82       */
  83      get length() {
  84        return this._valueAsArray.length;
  85      }
  86      /**
  87       * Returns the stringified form of the TokenList.
  88       *
  89       * @see https://dom.spec.whatwg.org/#DOMTokenList-stringification-behavior
  90       * @see https://www.ecma-international.org/ecma-262/9.0/index.html#sec-tostring
  91       *
  92       * @return Token set as string.
  93       */
  94      toString() {
  95        return this.value;
  96      }
  97      /**
  98       * Returns an iterator for the TokenList, iterating items of the set.
  99       *
 100       * @see https://dom.spec.whatwg.org/#domtokenlist
 101       *
 102       * @return TokenList iterator.
 103       */
 104      *[Symbol.iterator]() {
 105        return yield* this._valueAsArray;
 106      }
 107      /**
 108       * Returns the token with index `index`.
 109       *
 110       * @see https://dom.spec.whatwg.org/#dom-domtokenlist-item
 111       *
 112       * @param index Index at which to return token.
 113       *
 114       * @return Token at index.
 115       */
 116      item(index) {
 117        return this._valueAsArray[index];
 118      }
 119      /**
 120       * Returns true if `token` is present, and false otherwise.
 121       *
 122       * @see https://dom.spec.whatwg.org/#dom-domtokenlist-contains
 123       *
 124       * @param item Token to test.
 125       *
 126       * @return Whether token is present.
 127       */
 128      contains(item) {
 129        return this._valueAsArray.indexOf(item) !== -1;
 130      }
 131      /**
 132       * Adds all arguments passed, except those already present.
 133       *
 134       * @see https://dom.spec.whatwg.org/#dom-domtokenlist-add
 135       *
 136       * @param items Items to add.
 137       */
 138      add(...items) {
 139        this.value += " " + items.join(" ");
 140      }
 141      /**
 142       * Removes arguments passed, if they are present.
 143       *
 144       * @see https://dom.spec.whatwg.org/#dom-domtokenlist-remove
 145       *
 146       * @param items Items to remove.
 147       */
 148      remove(...items) {
 149        this.value = this._valueAsArray.filter((val) => !items.includes(val)).join(" ");
 150      }
 151      /**
 152       * If `force` is not given, "toggles" `token`, removing it if it’s present
 153       * and adding it if it’s not present. If `force` is true, adds token (same
 154       * as add()). If force is false, removes token (same as remove()). Returns
 155       * true if `token` is now present, and false otherwise.
 156       *
 157       * @see https://dom.spec.whatwg.org/#dom-domtokenlist-toggle
 158       *
 159       * @param token   Token to toggle.
 160       * @param [force] Presence to force.
 161       *
 162       * @return Whether token is present after toggle.
 163       */
 164      toggle(token, force) {
 165        if (void 0 === force) {
 166          force = !this.contains(token);
 167        }
 168        if (force) {
 169          this.add(token);
 170        } else {
 171          this.remove(token);
 172        }
 173        return force;
 174      }
 175      /**
 176       * Replaces `token` with `newToken`. Returns true if `token` was replaced
 177       * with `newToken`, and false otherwise.
 178       *
 179       * @see https://dom.spec.whatwg.org/#dom-domtokenlist-replace
 180       *
 181       * @param token    Token to replace with `newToken`.
 182       * @param newToken Token to use in place of `token`.
 183       *
 184       * @return Whether replacement occurred.
 185       */
 186      replace(token, newToken) {
 187        if (!this.contains(token)) {
 188          return false;
 189        }
 190        this.remove(token);
 191        this.add(newToken);
 192        return true;
 193      }
 194      /* eslint-disable @typescript-eslint/no-unused-vars */
 195      /**
 196       * Returns true if `token` is in the associated attribute’s supported
 197       * tokens. Returns false otherwise.
 198       *
 199       * Always returns `true` in this implementation.
 200       *
 201       * @param _token
 202       * @see https://dom.spec.whatwg.org/#dom-domtokenlist-supports
 203       *
 204       * @return Whether token is supported.
 205       */
 206      supports(_token) {
 207        return true;
 208      }
 209      /* eslint-enable @typescript-eslint/no-unused-vars */
 210    };
 211    return __toCommonJS(index_exports);
 212  })();
 213  if (typeof wp.tokenList === 'object' && wp.tokenList.default) { wp.tokenList = wp.tokenList.default; }


Generated : Wed Apr 15 08:20:10 2026 Cross-referenced by PHPXref