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