import { LitElement, HTMLTemplateResult, html } from 'lit'; import { customElement, property, state } from 'lit/decorators.js'; import { Constant } from './constant.js'; import { getCaptureEyeStyles } from './capture-eye-styles.js'; import { ModalManager } from './modal/modal-manager.js'; import { CaptureEyeModal, EngagementZone } from './modal/modal.js'; import { MediaViewer } from './media-viewer/media-viewer.js'; import interactionTracker, { TrackerEvent, } from './modal/interaction-tracker.js'; import { isMobile } from './utils.js'; @customElement('capture-eye') export class CaptureEye extends LitElement { static override styles = getCaptureEyeStyles(); /** * Nid of the asset. */ @property({ type: String }) nid = ''; /** * layout name of the asset. Options: original, curated */ @property({ type: String }) layout = Constant.layout.original; /** * Set visibility behavior. Default is mouse hover to show. Options: hover, always */ @property({ type: String }) visibility = Constant.visibility.hover; /** * Set position. Default is top left. Options: top left, top right, bottom left, bottom right */ @property({ type: String }) position = ''; /** * Set color: default is #377dde, and for mobile, the default is #333333. */ @property({ type: String }) color = ''; /** * Set heading source. Default is headline. Options: headline, abstract */ @property({ type: String , attribute: 'heading-source' }) headingSource = ''; /** * Customizable copyright zone title. */ @property({ type: String, attribute: 'cz-title' }) copyrightZoneTitle = ''; /** * Urls of the engagement images. Use comma to separate multiple images. */ @property({ type: String, attribute: 'eng-img' }) engagementImage = ''; /** * Urls of the engagement links. Use comma to separate multiple links. */ @property({ type: String, attribute: 'eng-link' }) engagementLink = ''; /** * Text of the action button. */ @property({ type: String, attribute: 'action-button-text' }) actionButtonText = ''; /** * Url of the action button link. */ @property({ type: String, attribute: 'action-button-link' }) actionButtonLink = ''; /** * Control the CR Pin behavior. Default is on. Options: on, off */ @property({ type: String, attribute: 'cr-pin' }) crPin = Constant.crPin.on; @state({}) protected _isFullVisibility = false; private _resizeObserver: ResizeObserver | null = null; get assetUrl() { return `${Constant.url.ipfsGateway}/${this.nid}`; } get assetProfileUrl() { return `${Constant.url.profile}/${this.nid}`; } constructor() { super(); this.loadFontFace(); console.debug(MediaViewer.name); // The line ensures MediaViewer is included in compilation. console.debug(CaptureEyeModal.name); // The line ensures CaptureEyeModal is included in compilation. } override connectedCallback() { super.connectedCallback(); if (!this._resizeObserver && (this.visibility === Constant.visibility.always || isMobile())) { this._resizeObserver = new ResizeObserver((entries) => { for (const entry of entries) { this.handleResize(entry); } }); // Handle edge cases where the size remains unchanged and no errors occur setTimeout(() => { this.setButtonFullVisibility(); }, 3000); } } override disconnectedCallback() { super.disconnectedCallback(); ModalManager.getInstance().removeModal(); if (this._resizeObserver) { this._resizeObserver.disconnect(); this._resizeObserver = null; } } get isOpened() { return !ModalManager.getInstance().modalHidden; } open() { this.setButtonActive(true); this.openEye(); } close() { ModalManager.getInstance().removeModal(); } private buttonTemplate() { if (!this.nid) { return html``; } const mobile = isMobile(); const color = this.color ? this.color : mobile ? Constant.color.mobileEye : Constant.color.defaultEye; const size = mobile ? 24 : 32; const positions = this.position.split(' '); return html`
`; } override render() { return html`