Home /Modules/gui/gui-html-codecs-demo.sleela

gui-html-codecs-demo.sleela

lib/gui/version-dual/gui-html-codecs-demo.sleela · 93 line(s) · sleela

<< lib/gui/version-dual/gui-html-codecs-demo.sleela
   A runnable walkthrough of the dual (4.0) HTML renderer and codec awareness:
   a quick-responsive HTML/CSS/JS render pipeline, and GUI components that can
   SEE the codecs the system supports (/codecs) before offering media. >>
#sleela 2.5
material;
class GuiHtmlCodecsDemo {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
     or catalog can read and (where appropriate) override this record.
     Values are faithful to the subject's real origin where publicly known. >>
  String metaVersion = "1.0.0";
  int metaId = 11124;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-10-16";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-10-16";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 9;
  < metaNationalSchedule: a real, citable instrument or "none" >
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }

  void main() {
    < ---- Codec awareness: the GUI can see what /codecs supports ---- >
    SLGuiCodecs codecs = new SLGuiCodecs(); codecs.configure();
    print("codecs known=" + codecs.codecCount() + ", playable=" + codecs.playableCount());
    print("  PCM_WAV: " + codecs.stateName(codecs.stateAt(codecs.idOf("PCM_WAV"))) +
          " playable=" + codecs.playable("PCM_WAV"));
    print("  OPUS:    " + codecs.stateName(codecs.stateAt(codecs.idOf("OPUS"))) +
          " playable=" + codecs.playable("OPUS"));
    print("  MIDI:    " + codecs.stateName(codecs.stateAt(codecs.idOf("MIDI"))) +
          " playable=" + codecs.playable("MIDI") + " (event format)");
    print("  .mp3 extension -> " + codecs.nameAt(codecs.byExtension(".mp3")) +
          " playable=" + codecs.playableExtension(".mp3"));

    < A video canvas / recorder can gate on real capability. >
    SLGuiVideoCanvas vid = new SLGuiVideoCanvas(); vid.configure("movies/clip.webm");
    print("video 'clip.webm' extension playable=" + codecs.playableExtension(".webm"));
    SLGuiAudioRecorder rec = new SLGuiAudioRecorder(); rec.configure("default", "take.flac");
    print("recorder can encode FLAC=" + codecs.recordable("FLAC") +
          ", MP3=" + codecs.recordable("MP3") + " (MP3 decode-only)");

    < ---- HTML renderer: quick-responsive, CSS + JavaScript ---- >
    SLGuiHtmlRenderer r = new SLGuiHtmlRenderer(); r.configure();
    r.setQuickResponse(true); r.setQuickPaintMs(100);
    r.setCssEnabled(true); r.setJsEnabled(true); r.setJsTimeoutMs(4000);
    print("renderer: css=" + r.cssOn() + " js=" + r.jsOn() +
          " quick<=" + r.getQuickPaintMs() + "ms honored=" + r.honored());

    < Drive the pipeline the way the host reports progress for an HTML 200. >
    r.render();                 print("  phase: " + r.phaseName());
    r.onParsed(214);            print("  parsed " + r.nodes() + " nodes -> " + r.phaseName());
    r.onStyled(96);             print("  styled " + r.rules() + " CSS rules -> " + r.phaseName());
    r.onFirstPaint(72);         print("  first paint @" + r.firstPaint() + "ms (quick) -> " + r.phaseName());
    r.runScript(); r.runScript();print("  ran " + r.scripts() + " scripts -> " + r.phaseName());
    r.onPainted();              print("  " + r.phaseName() + " · responsive=" + r.responsive());

    < The renderer is codec-aware for <video>/<audio>/<source>. >
    print("  page <video> opus accepted=" + r.acceptMediaCodec("OPUS"));
    print("  page <audio> amr-wb mime canPlayType=" + r.canPlayType("audio/amr-wb"));
    print("  page <video> theora (unknown) accepted=" + r.acceptMediaCodec("THEORA") +
          " -> blockedMedia=" + r.blockedMedia());
    print("  renderer supportedCodecCount=" + r.supportedCodecCount());
  }
}