Files
v10/packages/html/html/src/media-container.ts
T
3cffb4d59a fix: refactor private fields to public with underscore convention
Resolves TypeScript TS4094 error "Property may not be private or protected"
in exported anonymous classes created by factory functions.

Changes:
- #mediaStore → _mediaStore (public with underscore convention)
- #mediaSlot → _mediaSlot (public with underscore convention)
- #handleMediaSlotChange → _handleMediaSlotChange (public with underscore)

The underscore prefix indicates internal/private usage by convention
while avoiding TypeScript restrictions on anonymous class exports.

Affected files:
- media-mute-button.ts: 5 field references updated
- media-play-button.ts: 5 field references updated
- media-container.ts: 10 field references updated

All HTML packages now build successfully without TS4094 errors.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-19 08:41:08 -07:00

49 lines
1.5 KiB
TypeScript

import { ConsumerMixin } from '@open-wc/context-protocol';
export function getTemplateHTML() {
return /* html */`
<slot name="media"></slot>
<slot></slot>
`;
}
// @ts-ignore - Custom element constructor compatibility
export class MediaContainer extends ConsumerMixin(HTMLElement) {
static shadowRootOptions = { mode: 'open' as ShadowRootMode };
static getTemplateHTML = getTemplateHTML;
_mediaStore: any;
_mediaSlot: HTMLSlotElement;
contexts = {
mediaStore: (mediaStore: any) => {
this._mediaStore = mediaStore;
this._handleMediaSlotChange();
},
};
constructor() {
super();
// @ts-ignore - Shadow DOM property access
if (!this.shadowRoot) {
// @ts-ignore - Shadow DOM property access
this.attachShadow((this.constructor as typeof MediaContainer).shadowRootOptions);
// @ts-ignore - Shadow DOM property access
this.shadowRoot!.innerHTML = (this.constructor as typeof MediaContainer).getTemplateHTML();
}
// @ts-ignore - Shadow DOM property access
this._mediaSlot = this.shadowRoot!.querySelector('slot[name=media]') as HTMLSlotElement;
this._mediaSlot.addEventListener('slotchange', this._handleMediaSlotChange);
}
_handleMediaSlotChange = () => {
const media = this._mediaSlot.assignedElements({ flatten: true })[0];
this._mediaStore.dispatch({ type: 'mediaelementchangerequest', detail: media });
};
}
// @ts-ignore - Custom elements type compatibility
customElements.define('media-container', MediaContainer);