var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { ZERO_WIDTH_SPACE } from '@blockeditor/inline';
import { ShadowlessElement } from '@blockeditor/lit';
import { css, html } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';
export function affineTextStyles(props, override) {
    let textDecorations = '';
    if (props.underline) {
        textDecorations += 'underline';
    }
    if (props.strike) {
        textDecorations += ' line-through';
    }
    let inlineCodeStyle = {};
    if (props.code) {
        inlineCodeStyle = {
            'font-family': 'var(--affine-font-code-family)',
            background: 'var(--affine-background-code-block)',
            color: 'var(--affine-text-primary-color)',
            'border-radius': '2px',
            padding: '3px 6px 4px',
            'font-variant-ligatures': 'none',
            'line-height': 'var(--affine-font-base)',
        };
    }
    return styleMap({
        'font-weight': props.bold ? 'bolder' : 'inherit',
        'font-style': props.italic ? 'italic' : 'normal',
        'background-color': props.background ? props.background : undefined,
        color: props.color ? props.color : undefined,
        'text-decoration': textDecorations.length > 0 ? textDecorations : 'none',
        ...inlineCodeStyle,
        ...override,
    });
}
let AffineText = class AffineText extends ShadowlessElement {
    constructor() {
        super(...arguments);
        this.delta = {
            insert: ZERO_WIDTH_SPACE,
        };
    }
    render() {
        const style = this.delta.attributes
            ? affineTextStyles(this.delta.attributes)
            : styleMap({});
        // we need to avoid \n appearing before and after the span element, which will
        // cause the unexpected space
        if (this.delta.attributes?.code) {
            return html `<code style=${style}
        ><v-text .str=${this.delta.insert}></v-text
      ></code>`;
        }
        // we need to avoid \n appearing before and after the span element, which will
        // cause the unexpected space
        return html `<span style=${style}
      ><v-text .str=${this.delta.insert}></v-text
    ></span>`;
    }
};
AffineText.styles = css `
    affine-text {
      white-space: break-spaces;
      word-break: break-word;
    }
  `;
__decorate([
    property({ type: Object })
], AffineText.prototype, "delta", void 0);
AffineText = __decorate([
    customElement('affine-text')
], AffineText);
export { AffineText };
//# sourceMappingURL=affine-text.js.map