Skip to content

Web Component Universal Kit ​

Universal mounting hardware: Native Web Component—works on any DOM wall, with or without a frontend framework.

The Web Component has zero dependency on React or Vue, making it ideal for plain websites, CMS templates, and cross-framework embeds.

For bundled projects we recommend the npm package; blog templates can also drop in the version-pinned script snippet.

bash
npm install @yunlefun-home/air-conditioner-widget

ESM, CommonJS, and TypeScript declarations are all included. Register and mount only on the client after the DOM is ready; you may import the module during SSR, but do not call mount helpers on the server.

ts
import { cdnAssets, defineAirConditionerElement } from '@yunlefun-home/air-conditioner-widget'

defineAirConditionerElement({ ...cdnAssets, enableAudio: false })
html
<air-conditioner-widget storage-key="ac:state"></air-conditioner-widget>

mount API ​

ts
import { cdnAssets, mountAirConditioner } from '@yunlefun-home/air-conditioner-widget'

mountAirConditioner('#ac', {
  storageKey: 'ac:state',
  ...cdnAssets,
  enableAudio: false,
})

The appearance matches the Vue and React components (energy label, seven-segment display, logo, louver, and round remote buttons). Shadow DOM styles are synced from Vue's style.css; after editing styles, run pnpm -C packages/widget run sync:style.

OptionDefaultDescription
logoUrl/yun-logo.svgCenter logo image URL; pass '' to hide
assetsBaseUrl/assetsBase path for fonts/digital-7-mono.ttf and audio/
audioExtm4aAudio file extension
enableAudiotrueEnable button beep and fan sound effects
showEnergyLabeltrueShow the energy efficiency sticker
title—Alt text / link title for the center logo
placementinlineinline, or top-left / top-right corner mount
localezhUI language: zh / en (remote toggle, LCD, and screen-reader text). Also settable via the locale HTML attribute; labels overrides individual strings

Because @font-face inside Shadow DOM is ignored by browsers, the component injects the digital font rule once into document.head.

When status / mode / temperature / sound / swing / fan attributes are omitted, persisted local state is used. fan accepts auto, low, medium, high (see Fan Speed); sound accepts normal, sleep, mute (see Audio and Sound Modes); swing="false" disables oscillation while any other value enables it (see Airflow and Swing).

Corner Floating Install ​

Open the interactive Floating Widget demo to try left/right wall mounting and folding the remote.

To let visitors cool off while reading blog posts without reserving iframe space (#31), mount the widget to a screen corner:

ts
import { cdnAssets, mountAirConditioner } from '@yunlefun-home/air-conditioner-widget'

// Mount to document.body on the client so ancestor transform/filter does not break fixed positioning.
const widget = mountAirConditioner(document.body, {
  placement: 'top-right',
  storageKey: 'blog:ac',
  ...cdnAssets,
  enableAudio: false,
})

// Move walls anytime, or set 'inline' to restore normal flow.
widget.setAttribute('placement', 'top-left')

// Clean up audio and listeners when leaving the page.
// widget.remove()

Once registered, plain HTML markup works too:

html
<air-conditioner-widget placement="top-right" storage-key="blog:ac"></air-conditioner-widget>

Click or press Enter / Space on the toggle button to expand the remote, and press Esc to fold it while keeping the AC running. Unknown placement values fall back to inline.

The body scales down smoothly on narrow screens, and the area between the AC unit and the remote remains clickable and scrollable. Customize z-index (default 1000) via --acw-floating-z-index. cdnAssets uses version-pinned jsDelivr URLs, or you can self-host the assets.

Events ​

ts
const widget = document.querySelector('air-conditioner-widget')

widget?.addEventListener('ac-change', (event) => {
  console.log(event.detail.state)
})

widget?.addEventListener('ac-notify', (event) => {
  console.log(event.detail.notification)
})

Released under the MIT License · The only catch is no actual wind