euv-cli 0.51.0

Cross-platform CLI tool for the euv native UI framework supporting run, build, check, fmt, doctor, new, and Hyperlane SSE dynamic updates across all supported platforms.
Documentation
import euvNative from 'libeuv_harmony_host.so';

@Entry
@Component
struct Index {
  @StorageLink('euvNativeHandle') nativeHandle: number = 0;
  @StorageLink('euvDensity') density: number = 2.0;
  @StorageLink('euvDeviceType') deviceType: string = 'phone';
  @StorageLink('euvImeActive') imeActive: boolean = false;
  @State imeBuffer: string = '';

  onBackPress(): boolean {
    if (this.nativeHandle !== 0) {
      return euvNative.euvHarmonyBackPress(this.nativeHandle);
    }
    return false;
  }

  build() {
    Stack() {
      XComponent({
        id: 'euv_xcomponent',
        type: XComponentType.SURFACE,
        libraryname: 'euv_harmony_host'
      })
        .width('100%')
        .height('100%')
        .focusable(true)
        .defaultFocus(true)
        .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
        .backgroundColor('#09090B')
        .onMouse((event: MouseEvent) => {
          if (this.nativeHandle === 0) return;
          let action: number = 3;
          if (event.action === MouseAction.Press) action = 1;
          else if (event.action === MouseAction.Release) action = 2;
          else if (event.action === MouseAction.Move) action = 3;
          let button: number = 0;
          if (event.button === MouseButton.Left) button = 1;
          else if (event.button === MouseButton.Right) button = 2;
          else if (event.button === MouseButton.Middle) button = 4;
          euvNative.euvHarmonyOnMouse(
            this.nativeHandle,
            action,
            button,
            event.x * this.density,
            event.y * this.density
          );
        })
        .onAxisEvent((event: AxisEvent) => {
          if (this.nativeHandle === 0) return;
          const dx: number = event.getHorizontalAxisValue ? event.getHorizontalAxisValue() : 0;
          const dy: number = event.getVerticalAxisValue ? event.getVerticalAxisValue() : 0;
          if (Math.abs(dx) > 0.001 || Math.abs(dy) > 0.001) {
            euvNative.euvHarmonyOnScroll(this.nativeHandle, dx, dy);
          }
        })
        .onKeyEvent((event: KeyEvent) => {
          if (this.nativeHandle === 0) return;
          const isDown: boolean = event.type === KeyType.Down;
          const shift: boolean = event.getModifierKeyState ? event.getModifierKeyState(['Shift']) : false;
          const ctrl: boolean = event.getModifierKeyState ? event.getModifierKeyState(['Ctrl']) : false;
          const alt: boolean = event.getModifierKeyState ? event.getModifierKeyState(['Alt']) : false;
          const meta: boolean = event.getModifierKeyState ? event.getModifierKeyState(['Fn']) : false;
          euvNative.euvHarmonyOnKey(
            this.nativeHandle,
            event.keyCode,
            isDown,
            shift,
            ctrl,
            alt,
            meta,
            false
          );
          if (isDown && !ctrl && !alt && !meta && event.keyText && event.keyText.length === 1) {
            euvNative.euvHarmonyTextInput(this.nativeHandle, event.keyText);
          }
        })
        .onDigitalCrown((event: CrownEvent) => {
          if (this.nativeHandle === 0) return;
          const detents: number = (event.degree || 0) / 15.0;
          if (Math.abs(detents) > 0.001) {
            euvNative.euvHarmonyOnCrown(this.nativeHandle, detents);
          }
        })

      if (this.imeActive) {
        TextInput({ text: this.imeBuffer })
          .width(1)
          .height(1)
          .opacity(0.01)
          .onChange((val: string) => {
            if (val.length > 0 && this.nativeHandle !== 0) {
              euvNative.euvHarmonyTextInput(this.nativeHandle, val);
              this.imeBuffer = '';
            }
          })
      }
    }
    .width('100%')
    .height('100%')
    .backgroundColor('#09090B')
  }
}