import { __decorate } from "../_virtual/_@oxc-project_runtime@0.95.0/helpers/decorate.js";
import { EFTemporal } from "./EFTemporal.js";
import { LitElement, css, html } from "lit";
import { customElement, property } from "lit/decorators.js";

//#region src/elements/EFTextSegment.ts
const globalAnimationSheets = /* @__PURE__ */ new Map();
let EFTextSegment = class EFTextSegment$1 extends EFTemporal(LitElement) {
	constructor(..._args) {
		super(..._args);
		this.segmentText = "";
		this.segmentIndex = 0;
		this.segmentStartMs = 0;
		this.segmentEndMs = 0;
		this.hidden = false;
	}
	static {
		this.styles = [css`
      :host {
        display: inline;
      }
      :host([data-animated]) {
        display: inline-block;
      }
      :host([data-line-segment]) {
        display: block;
      }
      :host([hidden]) {
        opacity: 0;
        pointer-events: none;
      }
    `];
	}
	/**
	* Registers animation styles that should be shared across all text segments.
	* This is the correct way to inject animation styles for segments - not via innerHTML.
	*
	* @param id Unique identifier for this stylesheet (e.g., "my-animations")
	* @param cssText The CSS rules to inject
	*
	* @example
	* EFTextSegment.registerAnimations("bounceIn", `
	*   @keyframes bounceIn {
	*     from { transform: scale(0); }
	*     to { transform: scale(1); }
	*   }
	*   .bounce-in {
	*     animation: bounceIn 0.5s ease-out;
	*   }
	* `);
	*/
	static registerAnimations(id, cssText) {
		if (globalAnimationSheets.has(id)) return;
		const sheet = new CSSStyleSheet();
		sheet.replaceSync(cssText);
		globalAnimationSheets.set(id, sheet);
		document.querySelectorAll("ef-text-segment").forEach((segment) => {
			if (segment.shadowRoot) {
				const adoptedSheets = segment.shadowRoot.adoptedStyleSheets;
				if (!adoptedSheets.includes(sheet)) segment.shadowRoot.adoptedStyleSheets = [...adoptedSheets, sheet];
			}
		});
	}
	/**
	* Unregisters previously registered animation styles.
	*
	* @param id The identifier of the stylesheet to remove
	*/
	static unregisterAnimations(id) {
		const sheet = globalAnimationSheets.get(id);
		if (!sheet) return;
		globalAnimationSheets.delete(id);
		document.querySelectorAll("ef-text-segment").forEach((segment) => {
			if (segment.shadowRoot) segment.shadowRoot.adoptedStyleSheets = segment.shadowRoot.adoptedStyleSheets.filter((s) => s !== sheet);
		});
	}
	render() {
		this.setCSSVariables();
		return html`${this.segmentText}`;
	}
	setCSSVariables() {
		const seedValue = this.segmentIndex * 9007 % 233 / 233;
		this.style.setProperty("--ef-seed", seedValue.toString());
		const offsetMs = this.staggerOffsetMs ?? 0;
		this.style.setProperty("--ef-stagger-offset", `${offsetMs}ms`);
		this.style.setProperty("--ef-index", this.segmentIndex.toString());
	}
	firstUpdated() {
		this.setCSSVariables();
	}
	updated() {
		this.setCSSVariables();
	}
	get startTimeMs() {
		return (this.closest("ef-text")?.startTimeMs || 0) + (this.segmentStartMs || 0);
	}
	get endTimeMs() {
		const parentText = this.closest("ef-text");
		if (parentText) return parentText.startTimeMs + parentText.durationMs;
		return this.segmentEndMs || 0;
	}
	get durationMs() {
		const parentText = this.closest("ef-text");
		if (parentText) return parentText.durationMs;
		return this.segmentEndMs - this.segmentStartMs;
	}
};
__decorate([property({
	type: String,
	attribute: false
})], EFTextSegment.prototype, "segmentText", void 0);
__decorate([property({
	type: Number,
	attribute: false
})], EFTextSegment.prototype, "segmentIndex", void 0);
__decorate([property({
	type: Number,
	attribute: false
})], EFTextSegment.prototype, "staggerOffsetMs", void 0);
__decorate([property({
	type: Number,
	attribute: false
})], EFTextSegment.prototype, "segmentStartMs", void 0);
__decorate([property({
	type: Number,
	attribute: false
})], EFTextSegment.prototype, "segmentEndMs", void 0);
__decorate([property({
	type: Boolean,
	reflect: true
})], EFTextSegment.prototype, "hidden", void 0);
EFTextSegment = __decorate([customElement("ef-text-segment")], EFTextSegment);

//#endregion
export { EFTextSegment };
//# sourceMappingURL=EFTextSegment.js.map