UNPKG

@tarojs/components

Version:
75 lines (74 loc) 2.25 kB
import { Host, h } from '@stencil/core'; function isEqualTag(a, b) { return typeof a.tagName === 'undefined' ? a.nodeType === b.nodeType : a.tagName === b.tagName; } function parseChildNodes(items, targets, needClean = false) { const list = Array.from(targets.values()); for (let i = 0, j = 0; i < list.length; i++) { const target = list[i]; if (!target) return; let item = items.item(j); while (item) { if (!isEqualTag(item, target) || needClean) { item.remove(); j++; item = items.item(j); continue; } if (target.childNodes.length > 0) { const cleanAll = ['taro-image-core'].includes(target.tagName.toLocaleLowerCase()); parseChildNodes(item.childNodes, target.childNodes, cleanAll); } break; } while (i === list.length - 1 && j < items.length) { j++; item = items.item(j); item === null || item === void 0 ? void 0 : item.remove(); } } } export class SwiperItem { constructor() { this.itemId = undefined; } componentDidRender() { var _a, _b, _c; const el = this.el; if (el.classList.contains('swiper-slide-duplicate')) { const list = Array .from(((_b = (_a = el.parentElement) === null || _a === void 0 ? void 0 : _a.childNodes) === null || _b === void 0 ? void 0 : _b.values()) || []) .filter((e) => e.tagName === 'TARO-SWIPER-ITEM-CORE'); if (list.length > 0) { parseChildNodes(el.childNodes, (_c = list[list.indexOf(el) === 0 ? list.length - 2 : 1]) === null || _c === void 0 ? void 0 : _c.childNodes); } } } render() { return (h(Host, { class: 'swiper-slide', "item-id": this.itemId })); } static get is() { return "taro-swiper-item-core"; } static get properties() { return { "itemId": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "attribute": "item-id", "reflect": false } }; } static get elementRef() { return "el"; } }