import '../_common/components/embed-card/embed-card-caption.js'; import { assertExists } from '@blockeditor/global/utils'; import { ShadowlessElement, WithDisposable } from '@blockeditor/lit'; import { html, nothing } from 'lit'; import { customElement, property } from 'lit/decorators.js'; import { styleMap } from 'lit/directives/style-map.js'; import { EMBED_CARD_HEIGHT, EMBED_CARD_WIDTH } from '../_common/consts.js'; import { getEdgelessPageByElement } from '../_common/utils/query.js'; import { Bound } from '../surface-block/utils/bound.js'; import type { BookmarkBlockComponent } from './bookmark-block.js'; import type { BookmarkBlockModel } from './bookmark-model.js'; @customElement('affine-edgeless-bookmark') export class EdgelessBookmarkBlockComponent extends WithDisposable( ShadowlessElement ) { @property({ attribute: false }) block!: BookmarkBlockComponent; get model() { return this.block.model; } get edgeless() { const edgeless = getEdgelessPageByElement(this); assertExists(edgeless); return edgeless; } override connectedCallback() { super.connectedCallback(); this.disposables.add( this.model.page.slots.blockUpdated.on(({ id }) => { if (id === this.model.id) { this.requestUpdate(); } }) ); } override render() { const style = this.model.style; const width = EMBED_CARD_WIDTH[style]; const height = EMBED_CARD_HEIGHT[style]; const bound = Bound.deserialize( ( (this.edgeless.service.getElementById( this.model.id ) as BookmarkBlockModel) ?? this.model ).xywh ); const scaleX = bound.w / width; const scaleY = bound.h / height; return html`