Home /Modules/website/website.sleela

website.sleela

lib/website/website.sleela · 175 line(s) · sleela

#sleela 2.5
material;
< website.sleela -- the self-contained, runnable build of the SLeeLa Website >
< Generator. The SLeeLa compiler's `run` compiles one file as a single unit, >
< so this aggregate inlines every class the generator needs (design, sign, >
< emitter) plus a `main` that composes a demo site and prints the finished >
< HTML. The split per-class files in this package (SLWebsiteDesign.sleela, >
< SLWebsiteSign.sleela, SLWebsiteEmitter.sleela, SLWebsiteGenerator.sleela) are >
< the package's discovery surface; this file is the executable counterpart, >
< mirroring the data-structures/data_structures.sleela convention. >
<  >
< Build custom, exciting websites from a design (theme, palette, an "energy" >
< dial, layout grammar) and an ordered list of semantic signs. No new VM >
< opcode is required: everything here is arithmetic and the existing String >
< concatenation on OP_ADD. >

< --- Design: the global look -------------------------------------------- >
struct WebDesign {
  < ---- 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 = 10060;
  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-03";
  < 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; }
    String theme; String brand; String base; String accent; String font;
    int radius; int energy; int grammar;
}

< --- Sign: a semantic content block ------------------------------------- >
struct WebSign { int kind; String a; String b; String c; }

class WebsiteGenerator {

    int clamp(int v, int lo, int hi) {
        if (v < lo) { return lo; }
        if (v > hi) { return hi; }
        return v;
    }

    WebDesign preset(String name) {
        WebDesign d = new WebDesign();
        if (name == "neon") {
            d.theme = "neon"; d.brand = "#7c3aed"; d.base = "#0b0714"; d.accent = "#22d3ee";
            d.font = "'Space Grotesk', system-ui, sans-serif"; d.radius = 18; d.energy = 95; d.grammar = 3;
            return d;
        }
        if (name == "brutalist") {
            d.theme = "brutalist"; d.brand = "#111111"; d.base = "#f5f5f5"; d.accent = "#ff3b30";
            d.font = "'Arial Black', system-ui, sans-serif"; d.radius = 0; d.energy = 70; d.grammar = 0;
            return d;
        }
        if (name == "editorial") {
            d.theme = "editorial"; d.brand = "#1f2937"; d.base = "#fbfbf8"; d.accent = "#b45309";
            d.font = "Georgia, 'Times New Roman', serif"; d.radius = 4; d.energy = 15; d.grammar = 1;
            return d;
        }
        d.theme = "aurora"; d.brand = "#2563eb"; d.base = "#0f172a"; d.accent = "#38bdf8";
        d.font = "'Inter', system-ui, sans-serif"; d.radius = 14; d.energy = 60; d.grammar = 2;
        return d;
    }

    int motionLevel(WebDesign d) {
        if (d.energy >= 75) { return 2; }
        if (d.energy >= 35) { return 1; }
        return 0;
    }

    String intToStr(int v) { return "" + v; }

    String styleFor(WebDesign d) {
        int motion = motionLevel(d);
        String heroBg = "var(--brand)";
        if (motion == 1) { heroBg = "linear-gradient(135deg, var(--brand), var(--accent))"; }
        if (motion == 2) { heroBg = "linear-gradient(120deg, var(--brand), var(--accent), var(--brand))"; }

        String css = "<style>\n";
        css = css + ":root{--brand:" + d.brand + ";--base:" + d.base + ";--accent:" + d.accent
                  + ";--radius:" + intToStr(d.radius) + "px;--font:" + d.font + ";}\n";
        css = css + "*{box-sizing:border-box;margin:0;padding:0}";
        css = css + "body{font-family:var(--font);background:var(--base);color:#e5e7eb;line-height:1.55}";
        css = css + "section{padding:72px 24px}.wrap{max-width:1080px;margin:0 auto}";
        css = css + "nav{position:sticky;top:0;display:flex;justify-content:space-between;align-items:center;padding:16px 24px;background:rgba(0,0,0,.35)}";
        css = css + "nav .brand{font-weight:800;color:#fff}";
        css = css + ".hero{background:" + heroBg + ";border-radius:var(--radius);padding:120px 32px;text-align:center;color:#fff}";
        css = css + ".hero h1{font-size:clamp(2.2rem,6vw,4rem);letter-spacing:-.02em}";
        css = css + ".hero p{opacity:.9;margin:16px auto 28px;max-width:46ch}";
        css = css + ".btn{display:inline-block;background:var(--accent);color:#001;font-weight:700;padding:14px 26px;border-radius:var(--radius);text-decoration:none}";
        css = css + ".grid{display:grid;gap:20px;grid-template-columns:repeat(auto-fit,minmax(220px,1fr))}";
        css = css + ".card{background:rgba(255,255,255,.05);border:1px solid rgba(255,255,255,.08);border-radius:var(--radius);padding:24px}";
        css = css + ".cta{background:var(--accent);color:#001;text-align:center;border-radius:var(--radius)}";
        css = css + "blockquote{font-size:1.5rem;max-width:40ch;margin:0 auto;text-align:center;color:#fff}";
        css = css + "footer{padding:48px 24px;background:rgba(0,0,0,.4)}";
        if (motion == 2) {
            css = css + ".hero{background-size:200% 200%;animation:flow 12s ease infinite}";
            css = css + "@keyframes flow{0%{background-position:0% 50%}50%{background-position:100% 50%}100%{background-position:0% 50%}}";
        }
        css = css + "\n</style>";
        return css;
    }

    String renderSign(WebSign s) {
        if (s.kind == 0) { return "<nav><span class=\"brand\">" + s.a + "</span><span>" + s.b + "</span></nav>"; }
        if (s.kind == 1) { return "<section class=\"hero\"><div class=\"wrap\"><h1>" + s.a + "</h1><p>" + s.b + "</p><a class=\"btn\" href=\"#\">" + s.c + "</a></div></section>"; }
        if (s.kind == 2) { return "<section><div class=\"wrap\"><h2>" + s.a + "</h2><div class=\"grid\">" + s.b + "</div></div></section>"; }
        if (s.kind == 5) { return "<section><blockquote>" + s.a + "<br><small>- " + s.b + "</small></blockquote></section>"; }
        if (s.kind == 6) { return "<section class=\"cta\"><div class=\"wrap\"><h2>" + s.a + "</h2><a class=\"btn\" href=\"" + s.c + "\">" + s.b + "</a></div></section>"; }
        return "<footer><div class=\"wrap\"><strong>" + s.a + "</strong><div>" + s.b + "</div></footer>";
    }

    WebSign sign(int kind, String a, String b, String c) {
        WebSign s = new WebSign(); s.kind = kind; s.a = a; s.b = b; s.c = c; return s;
    }

    String build(String presetName) {
        WebDesign d = preset(presetName);
        String body = "";
        body = body + renderSign(sign(0, "Lumen", "Features &nbsp; Pricing &nbsp; Contact", ""));
        body = body + renderSign(sign(1, "Launch something unforgettable",
                "A website generated from pure design intent and semantic signs.", "Start building"));
        String cards = "";
        cards = cards + "<div class=\"card\"><h3>Design-driven</h3><p>Describe the look once; every page obeys it.</p></div>";
        cards = cards + "<div class=\"card\"><h3>Sign-based</h3><p>Pages are semantic blocks, not markup soup.</p></div>";
        cards = cards + "<div class=\"card\"><h3>Zero dependencies</h3><p>Output is a single self-contained document.</p></div>";
        body = body + renderSign(sign(2, "Why it works", cards, ""));
        body = body + renderSign(sign(5, "We shipped a launch page in an afternoon.", "A. Builder", ""));
        body = body + renderSign(sign(6, "Ready to generate your site?", "Open the Studio", "#studio"));
        body = body + renderSign(sign(8, "Lumen", "Made with the SLeeLa Website Generator", ""));

        String style = styleFor(d);
        String html = "<!doctype html>\n<html lang=\"en\">\n<head>\n";
        html = html + "<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n";
        html = html + "<title>Lumen - generated by SLeeLa</title>\n" + style + "\n</head>\n<body>\n" + body + "\n</body>\n</html>\n";
        return html;
    }

    void main() {
        print(build("neon"));
    }
}