You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

248 lines
6.5 KiB

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