playground · interpretador Kof real · KofJS no browser
Playground Kof
Interpretador Kof real no navegador — mesma linguagem e mesma semântica do backend JS oficial (kof-runtime.mjs): Int com wrap |0, Long como BigInt, Double no formato JDK, Char imprimindo o caráter, records com == de conteúdo, enums, classes com herança e this, switch com patterns e switch-expr, null-safety, coleções com map/filter/reduce, lambdas, try/catch/finally, spawn/await com poll/done, arrays multidim e stdlib portada para o browser (9 namespaces) — a base da linguagem; sintaxe nova da 0.6.0 (sealed, variância out/in, interop.schema) ainda não roda no interpretador do browser. Abaixo, os 14 módulos de kof-ui-widgets com código ao lado do preview.
Única limitação é a arquitetura do GitHub Pages: 100% estático, sem servidor/host para kof.db/kof.io/kof.web — esses gaps reportam o mesmo código que kof check (DB001/WEB001) e nunca silenciam (R6). Execução é manual; revise código compartilhado antes de executar.
Dois quadrados: código → saída
Edite os exemplos da fachada do interpretador e execute manualmente para ver a saída.
Kof real no browser — Int/Long/Double/Float/Char, records/enums/classes, if-expr/switch com patterns, for-in/while, try/catch/finally (throw String), spawn/await e 9 namespaces da stdlib. Única limitação: Pages é estático. Executar ou Ctrl+Enter; links compartilhados só carregam o código.
Clique em Executar ou pressione Ctrl+Enter.$ kof run app.kf --target js # local: GraalJS embarcado$ kof build app.kf --target js # gera Default.mjs + kof-runtime.mjsÉ o mesmo Kof: Int com wrap |0, Long como BigInt, Double.toString do JDK, Char imprimindo o caráter, kofEq/kofStr de conteúdo. A única diferença é a arquitetura do Pages (100% estático): kof.db/kof.io/kof.web precisam de host e reportam DB001/WEB001 — igual ao kof check local.
Cada intenção com nome, código ao lado do que renderiza
Quatorze famílias, ~65 intenções — trechos oficiais de kof-ui-widgets com demonstrações React. Código exibido é o oficial do repo; preview é ilustrativo.
import kof.ui.Windowimport kof.ui.Labelimport kof.ui.Viewimport kof.ui.Buttonimport kof.ui.Inputimport kof.ui.Colorimport kof.ui.Fontimport kof.ui.Themeimport kof.ui.Hrimport kof.ui.Columnimport kof.ui.Rowimport kof.ui.Tableimport kof.ui.Textareaimport kof.ui.Selectimport kof.ui.Canvasimport kof.ui.Componentimport kof.ui.Storeimport kof.ui.Eventimport kof.ui.Imageimport kof.ui.Iconimport kof.ui.Linkimport kof.ui.Formimport kof.ui.Ulimport kof.ui.Olimport kof.ui.Gridimport kof.ui.Boximport kof.ui.Stackimport kof.ui.Spacerimport kof.ui.Wrapimport kof.ui.Centerimport kof.ui.Alignimport kof.ui.Fieldsetimport kof.ui.Iframeimport kof.ui.Videoimport kof.ui.Audio// 00-core.kf — fundação: App, tema, e helpers puros de texto/número.//// Tudo aqui é composição dos primitivos do kof.ui ou funções puras.// As funções puras são o coração testável da biblioteca: cada componente// interativo delega a transição de estado para uma delas.// ---- App --------------------------------------------------------------------// "abra o app" — janela pronta: tema escuro do Kof, tamanho civilizado.App(String title): Window { var w = Window(title) w.size(960, 640) w.theme = CurrentTheme() var wh = w return wh}// ---- Cores semânticas (atalhos do tema escuro) ------------------------------SurfaceColor(): Color { var c = CurrentTheme().surface() return c}ErrorColor(): Color { var c = CurrentTheme().error() return c}PrimaryColor(): Color { var c = CurrentTheme().primary() return c}TextColor(): Color { var c = CurrentTheme().text() return c}// ---- Texto puro -------------------------------------------------------------// repete `piece` n vezes — base de barras, skeletons e grids.// A plataforma já tem strings.repeat (n<=0 => "").repeat(String piece, Int n): String { return strings.repeat(piece, n)}// completa com espaços à direita até `width` (tabelas, colunas).padEnd(String s, Int width): String { return strings.padRight(s, width, " ")}// completa com espaços à esquerda até `width` (números alinhados).padStart(String s, Int width): String { return strings.padLeft(s, width, " ")}// trunca com reticências quando passa de `width`.ellipsis(String s, Int width): String { if (s.length <= width) { return s } if (width < 2) { return substringN(s, 0, width) } return substringN(s, 0, width - 1) + "…"}// substring segura: corta nos limites, nunca estoura.substringN(String s, Int start, Int end): String { if (s.length == 0) { return "" } var a = clamp(start, 0, s.length) var b = clamp(end, 0, s.length) if (b <= a) { return "" } return s.substring(a, b)}// conta ocorrências de um caractere (um char = string de 1).countChar(String s, String ch): Int { if (ch.length == 0) { return 0 } return strings.count(s, ch)}// junta uma lista com separador (breadcrumbs, menus).join(List<String> parts, String sep): String { if (parts.size == 0) { return "" } var out = parts.get(0) var i = 1 while (i < parts.size) { out = out + sep + parts.get(i) i = i + 1 } return out}// ---- Números puros ------------------------------------------------------------clamp(Int v, Int min, Int max): Int { return math.clamp(v, min, max)}// wrap-around: avança voltando ao início (carrosséis, relógios).wrapNext(Int i, Int n): Int { if (n <= 0) { return 0 } return (i + 1) % n}wrapPrev(Int i, Int n): Int { if (n <= 0) { return 0 } return (i - 1 + n) % n}Fundação: App (Window+Theme), cores semânticas e helpers puros repeat/pad/ellipsis.
De hello a dashboard — o mesmo app, vários mundos
Exemplos de kof-ui-widgets com previews ilustrativos em React. A galeria não executa esses programas Kof; consulte o repositório para execução local.
// hello.kf — o menor app com kof-ui-widgets//// scripts/run-example.sh hello//// ou, na mão:// cat src/kof-ui-widgets.kf examples/hello.kf > .build/hello.kf// kof run .build/hello.kf --target=jsmain() { var w = App("Olá") w.bind(Column(listOf( Heading("Olá, Kof"), Text("Este app é feito de intenções, não de mecanismos."), Badge("alpha") ))) w.show()}App + Heading + Text + Badge
Ver no GitHub →como rodar local com o oficial
git clone https://github.com/KofLang/kof-ui-widgets && cd kof-ui-widgetskof run "$(scripts/build.sh examples/dashboard.kf)" --target=js # webview nativokof run "$(scripts/build.sh examples/hello.kf)" --target=jvm # JVMKof real — limitação só do Pages
Roda com paridade
- Mesma semântica do KofJS oficial (records, enums, switch patterns, coleções)
- Stdlib da base (9 namespaces): math/strings/encoding/time/uuid/validation/net/random
- Erros com código + linha iguais ao `kof check` (R6, nunca silencia)
Só não roda no Pages
- 100% estático — sem host para `kof.db`/`kof.io`/`kof.web` → `DB001`/`WEB001`
- Previews da galeria são React ilustrativo (código exibido é o oficial)
- `fetch` do interpretador roda na thread do browser (pode congelar)
Local = completo
No seu host, kof check app.kf e kof run --target jvm|js|native liberam DB/io/web/server com a mesma linguagem — o Pages só não tem servidor.
