1define(["exports", "../utils/boot.js", "../utils/wrap.js", "../utils/settings.js", "../utils/flattened-nodes-observer.js", "../utils/flush.js", "../utils/debounce.js"], function (_exports, _boot, _wrap, _settings, _flattenedNodesObserver, _flush, _debounce) { 2 "use strict"; 3 4 Object.defineProperty(_exports, "__esModule", { 5 value: true 6 }); 7 Object.defineProperty(_exports, "flush", { 8 enumerable: true, 9 get: function () { 10 return _flush.flush; 11 } 12 }); 13 Object.defineProperty(_exports, "addDebouncer", { 14 enumerable: true, 15 get: function () { 16 return _flush.enqueueDebouncer; 17 } 18 }); 19 _exports.dom = _exports.DomApi = _exports.EventApi = _exports.matchesSelector = void 0; 20 21 /** 22 @license 23 Copyright (c) 2017 The Polymer Project Authors. All rights reserved. 24 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt 25 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt 26 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt 27 Code distributed by Google as part of the polymer project is also 28 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt 29 */ 30 31 /* eslint-disable no-unused-vars */ 32 // used in type annotations 33 34 /* eslint-enable no-unused-vars */ 35 const p = Element.prototype; 36 /** 37 * @const {function(this:Node, string): boolean} 38 */ 39 40 const normalizedMatchesSelector = p.matches || p.matchesSelector || p.mozMatchesSelector || p.msMatchesSelector || p.oMatchesSelector || p.webkitMatchesSelector; 41 /** 42 * Cross-platform `element.matches` shim. 43 * 44 * @function matchesSelector 45 * @param {!Node}
45 node Node to check selector against 46 * @param {string} selector Selector to match 47 * @return {boolean} True if node matched selector 48 */ 49 50 const matchesSelector = function (node, selector) { 51 return normalizedMatchesSelector.call(node, selector); 52 }; 53 /** 54 * Node API wrapper class returned from `Polymer.dom.(target)` when 55 * `target` is a `Node`. 56 * @implements {PolymerDomApi} 57 * @unrestricted 58 */ 59 60 61 _exports.matchesSelector = matchesSelector; 62 63 class DomApiNative { 64 /** 65 * @param {Node} node Node for which to create a Polymer.dom helper object. 66 */ 67 constructor(node) { 68 if (window['ShadyDOM'] && window['ShadyDOM']['inUse']) { 69 window['ShadyDOM']['patch'](node); 70 } 71 72 this.node = node; 73 } 74 /** 75 * Returns an instance of `FlattenedNodesObserver` that 76 * listens for node changes on this element. 77 * 78 * @param {function(this:HTMLElement, { target: !HTMLElement, addedNodes: !Array<!Element>, removedNodes: !Array<!Element> }):void} callback Called when direct or distributed children 79 * of this element changes 80 * @return {!PolymerDomApi.ObserveHandle} Observer instance 81 * @override 82 */ 83 84 85 observeNodes(callback) { 86 return new _flattenedNodesObserver.FlattenedNodesObserver( 87 /** @type {!HTMLElement} */ 88 this.node, callback); 89 } 90 /** 91 * Disconnects an observer previously created via `observeNodes` 92 * 93 * @param {!PolymerDomApi.ObserveHandle} observerHandle Observer instance 94 * to disconnect. 95 * @return {void} 96 * @override 97 */ 98 99 100 unobserveNodes(observerHandle) { 101 observerHandle.disconnect(); 102 } 103 /** 104 * Provided as a backwards-compatible API only. This method does nothing. 105 * @return {void} 106 */ 107 108 109 notifyObserver() {} 110 /** 111 * Returns true if the provided node is contained with this element's 112 * light-DOM children or shadow root, including any nested shadow roots 113 * of children therein. 114 * 115 * @param {Node} node Node to test 116 * @return {boolean} Returns true if the given `node` is contained within 117 * this element's light or shadow DOM. 118 * @override 119 */ 120 121 122 deepContains(node) { 123 if ((0, _wrap.wrap)(this.node).contains(node)) { 124 return true; 125 } 126 127 let n = node; 128 let doc = node.ownerDocument; // walk from node to `this` or `document` 129 130 while (n && n !== doc && n !== this.node) { 131 // use logical parentnode, or native ShadowRoot host 132 n = (0, _wrap.wrap)(n).parentNode || (0, _wrap.wrap)(n).host; 133 } 134 135 return n === this.node; 136 } 137 /** 138 * Returns the root node of this node. Equivalent to `getRootNode()`. 139 * 140 * @return {Node} Top most element in the dom tree in which the node 141 * exists. If the node is connected to a document this is either a 142 * shadowRoot or the document; otherwise, it may be the node 143 * itself or a node or document fragment containing it. 144 * @override 145 */ 146 147 148 getOwnerRoot() { 149 return (0, _wrap.wrap)(this.node).getRootNode(); 150 } 151 /** 152 * For slot elements, returns the nodes assigned to the slot; otherwise 153 * an empty array. It is equivalent to `<slot>.addignedNodes({flatten:true})`. 154 * 155 * @return {!Array<!Node>} Array of assigned nodes 156 * @override 157 */ 158 159 160 getDistributedNodes() { 161 return this.node.localName === 'slot' ? (0, _wrap.wrap)(this.node).assignedNodes({ 162 flatten: true 163 }) : []; 164 } 165 /** 166 * Returns an array of all slots this element was distributed to. 167 * 168 * @return {!Array<!HTMLSlotElement>} Description 169 * @override 170 */ 171 172 173 getDestinationInsertionPoints() { 174 let ip$ = []; 175 let n = (0, _wrap.wrap)(this.node).assignedSlot; 176 177 while (n) { 178 ip$.push(n); 179 n = (0, _wrap.wrap)(n).assignedSlot; 180 } 181 182 return ip$; 183 } 184 /** 185 * Calls `importNode` on the `ownerDocument` for this node. 186 * 187 * @param {!Node} node Node to import 188 * @param {boolean} deep True if the node should be cloned deeply during 189 * import 190 * @return {Node} Clone of given node imported to this owner document 191 */ 192 193 194 importNode(node, deep) { 195 let doc = this.node instanceof Document ? this.node : this.node.ownerDocument; 196 return (0, _wrap.wrap)(doc).importNode(node, deep); 197 } 198 /** 199 * @return {!Array<!Node>} Returns a flattened list of all child nodes and 200 * nodes assigned to child slots. 201 * @override 202 */ 203 204 205 getEffectiveChildNodes() { 206 return _flattenedNodesObserver.FlattenedNodesObserver.getFlattenedNodes(
207 /** @type {!HTMLElement} */ 208 this.node); 209 } 210 /** 211 * Returns a filtered list of flattened child elements for this element based 212 * on the given selector. 213 * 214 * @param {string} selector Selector to filter nodes against 215 * @return {!Array<!HTMLElement>} List of flattened child elements 216 * @override 217 */ 218 219 220 queryDistributedElements(selector) { 221 let c$ = this.getEffectiveChildNodes(); 222 let list = []; 223 224 for (let i = 0, l = c$.length, c; i < l && (c = c$[i]); i++) { 225 if (c.nodeType === Node.ELEMENT_NODE && matchesSelector(c, selector)) { 226 list.push(c); 227 } 228 } 229 230 return list; 231 } 232 /** 233 * For shadow roots, returns the currently focused element within this 234 * shadow root. 235 * 236 * return {Node|undefined} Currently focused element 237 * @override 238 */ 239 240 241 get activeElement() { 242 let node = this.node; 243 return node._activeElement !== undefined ? node._activeElement : node.activeElement; 244 } 245 246 } 247 248 function forwardMethods(proto, methods) { 249 for (let i = 0; i < methods.length; i++) { 250 let method = methods[i]; 251 /* eslint-disable valid-jsdoc */ 252 253 proto[method] = 254 /** @this {DomApiNative} */ 255 function () { 256 return this.node[method].apply(this.node, arguments); 257 }; 258 /* eslint-enable */ 259 260 } 261 } 262 263 function forwardReadOnlyProperties(proto, properties) { 264 for (let i = 0; i < properties.length; i++) { 265 let name = properties[i]; 266 Object.defineProperty(proto, name, { 267 get: function () { 268 const domApi = 269 /** @type {DomApiNative} */ 270 this; 271 return domApi.node[name]; 272 }, 273 configurable: true 274 }); 275 } 276 } 277 278 function forwardProperties(proto, properties) { 279 for (let i = 0; i < properties.length; i++) { 280 let name = properties[i]; 281 Object.defineProperty(proto, name, { 282 /** 283 * @this {DomApiNative} 284 * @return {*} . 285 */ 286 get: function () { 287 return this.node[name]; 288 }, 289 290 /** 291 * @this {DomApiNative} 292 * @param {*} value . 293 */ 294 set: function (value) { 295 this.node[name] = value; 296 }, 297 configurable: true 298 }); 299 } 300 } 301 /** 302 * Event API wrapper class returned from `dom.(target)` when 303 * `target` is an `Event`. 304 */ 305 306 307 class EventApi { 308 constructor(event) { 309 this.event = event; 310 } 311 /** 312 * Returns the first node on the `composedPath` of this event. 313 * 314 * @return {!EventTarget} The node this event was dispatched to 315 */ 316 317 318 get rootTarget() { 319 return this.path[0]; 320 } 321 /** 322 * Returns the local (re-targeted) target for this event. 323 * 324 * @return {!EventTarget} The local (re-targeted) target for this event. 325 */ 326 327 328 get localTarget() { 329 return this.event.target; 330 } 331 /** 332 * Returns the `composedPath` for this event. 333 * @return {!Array<!EventTarget>} The nodes this event propagated through 334 */ 335 336 337 get path() { 338 return this.event.composedPath(); 339 } 340 341 } 342 /** 343 * @function 344 * @param {boolean=} deep 345 * @return {!Node} 346 */ 347 348 349 _exports.EventApi = EventApi; 350 DomApiNative.prototype.cloneNode; 351 /** 352 * @function 353 * @param {!Node} node 354 * @return {!Node} 355 */ 356 357 DomApiNative.prototype.appendChild; 358 /** 359 * @function 360 * @param {!Node} newChild 361 * @param {Node} refChild 362 * @return {!Node} 363 */ 364 365 DomApiNative.prototype.insertBefore; 366 /** 367 * @function 368 * @param {!Node} node 369 * @return {!Node} 370 */ 371 372 DomApiNative.prototype.removeChild; 373 /** 374 * @function 375 * @param {!Node} oldChild 376 * @param {!Node} newChild 377 * @return {!Node} 378 */ 379 380 DomApiNative.prototype.replaceChild; 381 /** 382 * @function 383 * @param {string} name 384 * @param {string} value 385 * @return {void} 386 */ 387 388 DomApiNative.prototype.setAttribute; 389 /** 390 * @function 391 * @param {string} name 392 * @return {void} 393 */ 394 395 DomApiNative.prototype.removeAttribute; 396 /** 397 * @function 398 * @param {string} selector 399 * @return {?Element} 400 */ 401 402 DomApiNative.prototype.querySelector; 403 /** 404 * @function 405 * @param {string} selector 406 * @return {!NodeList<!Element>} 407 */ 408 409 DomApiNative.prototype.querySelectorAll; 410 /** @type {?Node} */ 411 412 DomApiNative.prototype.parentNode; 413 /** @type {?Node} */ 414 415 DomApiNative.prototype.firstChild; 416 /** @type {?Node} */ 417 418 DomApiNative.prototype.lastChild; 419 /** @type {?Node} */ 420 421 DomApiNative.prototype.nextSibling; 422 /** @type {?Node} */ 423 424 DomApiNative.prototype.previousSibling; 425 /** @type {?HTMLElement} */ 426 427 DomApiNative.prototype.firstElementChild; 428 /** @type {?HTMLElement} */ 429 430 DomApiNative.prototype.lastElementChild; 431 /** @type {?HTMLElement} */ 432 433 DomApiNative.prototype.nextElementSibling; 434 /** @type {?HTMLElement} */ 435 436 DomApiNative.prototype.previousElementSibling;
437 /** @type {!Array<!Node>} */ 438 439 DomApiNative.prototype.childNodes; 440 /** @type {!Array<!HTMLElement>} */ 441 442 DomApiNative.prototype.children; 443 /** @type {?DOMTokenList} */ 444 445 DomApiNative.prototype.classList; 446 /** @type {string} */ 447 448 DomApiNative.prototype.textContent; 449 /** @type {string} */ 450 451 DomApiNative.prototype.innerHTML; 452 let DomApiImpl = DomApiNative; 453 454 if (window['ShadyDOM'] && window['ShadyDOM']['inUse'] && window['ShadyDOM']['noPatch'] && window['ShadyDOM']['Wrapper']) { 455 /** 456 * @private 457 * @extends {HTMLElement} 458 */ 459 class Wrapper extends window['ShadyDOM']['Wrapper'] {} // copy bespoke API onto wrapper 460 461 462 Object.getOwnPropertyNames(DomApiNative.prototype).forEach(prop => { 463 if (prop != 'activeElement') { 464 Wrapper.prototype[prop] = DomApiNative.prototype[prop]; 465 } 466 }); // Note, `classList` is here only for legacy compatibility since it does not 467 // trigger distribution in v1 Shadow DOM. 468 469 forwardReadOnlyProperties(Wrapper.prototype, ['classList']); 470 DomApiImpl = Wrapper; 471 Object.defineProperties(EventApi.prototype, { 472 // Returns the "lowest" node in the same root as the event's currentTarget. 473 // When in `noPatch` mode, this must be calculated by walking the event's 474 // path. 475 localTarget: { 476 get() { 477 const current = this.event.currentTarget; 478 const currentRoot = current && dom(current).getOwnerRoot(); 479 const p$ = this.path; 480 481 for (let i = 0; i < p$.length; i++) { 482 const e = p$[i]; 483 484 if (dom(e).getOwnerRoot() === currentRoot) { 485 return e; 486 } 487 } 488 }, 489 490 configurable: true 491 }, 492 path: { 493 get() { 494 return window['ShadyDOM']['composedPath'](this.event); 495 }, 496 497 configurable: true 498 } 499 }); 500 } else { 501 // Methods that can provoke distribution or must return the logical, not 502 // composed tree. 503 forwardMethods(DomApiNative.prototype, ['cloneNode', 'appendChild', 'insertBefore', 'removeChild', 'replaceChild', 'setAttribute', 'removeAttribute', 'querySelector', 'querySelectorAll']); // Properties that should return the logical, not composed tree. Note, `classList` 504 // is here only for legacy compatibility since it does not trigger distribution 505 // in v1 Shadow DOM. 506 507 forwardReadOnlyProperties(DomApiNative.prototype, ['parentNode', 'firstChild', 'lastChild', 'nextSibling', 'previousSibling', 'firstElementChild', 'lastElementChild', 'nextElementSibling', 'previousElementSibling', 'childNodes', 'children', 'classList']); 508 forwardProperties(DomApiNative.prototype, ['textContent', 'innerHTML', 'className']); 509 } 510 511 const DomApi = DomApiImpl; 512 /** 513 * Legacy DOM and Event manipulation API wrapper factory used to abstract 514 * differences between native Shadow DOM and "Shady DOM" when polyfilling on 515 * older browsers. 516 * 517 * Note that in Polymer 2.x use of `Polymer.dom` is no longer required and 518 * in the majority of cases simply facades directly to the standard native 519 * API. 520 * 521 * @summary Legacy DOM and Event manipulation API wrapper factory used to 522 * abstract differences between native Shadow DOM and "Shady DOM." 523 * @param {(Node|Event|DomApiNative|EventApi)=} obj Node or event to operate on 524 * @return {!DomApiNative|!EventApi} Wrapper providing either node API or event API 525 */ 526 527 _exports.DomApi = DomApi; 528 529 const dom = function (obj) { 530 obj = obj || document; 531 532 if (obj instanceof DomApiImpl) { 533 return ( 534 /** @type {!DomApi} */ 535 obj 536 ); 537 } 538 539 if (obj instanceof EventApi) { 540 return ( 541 /** @type {!EventApi} */ 542 obj 543 ); 544 } 545 546 let helper = obj['__domApi']; 547 548 if (!helper) { 549 if (obj instanceof Event) { 550 helper = new EventApi(obj); 551 } else { 552 helper = new DomApiImpl( 553 /** @type {Node} */ 554 obj); 555 } 556 557 obj['__domApi'] = helper; 558 } 559 560 return helper; 561 }; 562 563 _exports.dom = dom; 564});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.