├── .gitignore ├── CNAME ├── dune-project ├── styles ├── _intro.scss ├── _canvas.scss ├── _aside.scss ├── _status.scss ├── _list.scss ├── _footer.scss ├── _semantics.scss ├── _resources.scss ├── _om.scss ├── _code.scss ├── _header.scss ├── _index.scss ├── mathjax.js ├── _stack.scss ├── _exe.scss ├── _types.scss └── main.scss ├── dune ├── TODO ├── src ├── dune ├── error.ml ├── parser.mly ├── expr.ml ├── lexer.mll ├── alonzo.ml └── stlc.ml ├── .gitattributes ├── CHANGELOG ├── lib ├── bool.alonzo └── nat.alonzo ├── footer.pug ├── alonzo.opam ├── README.md ├── package.json ├── highlight.js ├── LICENSE ├── framework.js ├── header.pug ├── index.pug ├── main.css └── bundle.js /.gitignore: -------------------------------------------------------------------------------- 1 | _build/ 2 | -------------------------------------------------------------------------------- /CNAME: -------------------------------------------------------------------------------- 1 | alonzo.groupoid.space 2 | -------------------------------------------------------------------------------- /dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 2.9) 2 | (using menhir 2.1) 3 | -------------------------------------------------------------------------------- /styles/_intro.scss: -------------------------------------------------------------------------------- 1 | .intro { 2 | width: 650px; 3 | max-width: 100%; 4 | margin: auto; 5 | } -------------------------------------------------------------------------------- /styles/_canvas.scss: -------------------------------------------------------------------------------- 1 | canvas { 2 | max-width: 100%; 3 | position: absolute; 4 | z-index: -10; 5 | } -------------------------------------------------------------------------------- /dune: -------------------------------------------------------------------------------- 1 | (env (dev (flags (:standard -warn-error -A)))) 2 | (install (files lib/bool.alonzo lib/nat.alonzo) (section share) (package alonzo)) 3 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | # TODO 2 | 3 | * Better Errors 4 | * Function Equality 5 | * Empty, Unit, Product 6 | * Bool, Nat 7 | * Semantics (CCC) 8 | * PDF paper 9 | -------------------------------------------------------------------------------- /src/dune: -------------------------------------------------------------------------------- 1 | (ocamllex lexer) 2 | (menhir (modules parser)) 3 | (executable (name alonzo) (libraries dynlink zarith unix) (package alonzo) (public_name alonzo)) 4 | -------------------------------------------------------------------------------- /styles/_aside.scss: -------------------------------------------------------------------------------- 1 | aside { 2 | max-width: 650px; 3 | margin: auto; 4 | padding: 8px; 5 | font-size: 20px; 6 | text-align: right; 7 | time, div { 8 | margin-bottom: 20px; 9 | display: block; 10 | } 11 | } -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.js linguist-detectable=false 2 | *.pug linguist-detectable=false 3 | *.css linguist-detectable=false 4 | *.scss linguist-detectable=false 5 | *.tex linguist-detectable=false 6 | *.sh linguist-detectable=false 7 | *.html linguist-detectable=false 8 | *.htm linguist-detectable=false 9 | -------------------------------------------------------------------------------- /styles/_status.scss: -------------------------------------------------------------------------------- 1 | .status { 2 | text-align: left; 3 | display: inline-block; 4 | padding-left: 32px; 5 | 6 | ol { 7 | line-height: 1.5; 8 | font-size: 18px; 9 | @media(min-width: 768px) { 10 | font-size: 22px; 11 | } 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | Changelog 2 | ========= 3 | 4 | 5 APR 2022 Version 0.4.0 Church Encoding: 5 | 6 | * Bool and Nat terms 7 | * Pure Core of Simply Typed Lambda Calculus in 100 LOC 8 | * Parser in 15 LOC 9 | * Lexer in 35 LOC 10 | 11 | 2 JUN 2025 Version 3.6.0 STLC Implementation 12 | 13 | * Added stlc.ml as alternative implementation 14 | -------------------------------------------------------------------------------- /styles/_list.scss: -------------------------------------------------------------------------------- 1 | .list { 2 | h1 { 3 | color: #7D8A96; 4 | font-size: 32px; 5 | text-transform: uppercase; 6 | border-bottom: 1px solid rgba(0, 0 , 0,0.3); 7 | display: inline-block; 8 | margin: 42px 8px 10px; 9 | @media(min-width: 768px) { 10 | font-size: 40px; 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /lib/bool.alonzo: -------------------------------------------------------------------------------- 1 | -- STLC 2 | 3 | #eval λ (x: T), x : T → T 4 | #eval (λ (x: T → T),x) (λ (y: T), y) : T → T 5 | 6 | abbrev bool := T → T → T 7 | abbrev bool_to_bool := bool → bool 8 | def true : bool := λ (x: T), λ (y:T), x 9 | def false : bool := λ (x: T) (y: T), y 10 | 11 | #eval λ (t: T) (f: T), true t f : bool 12 | #eval λ (t: T) (f: T), false t f : bool 13 | #eval (λ (x: bool_to_bool), x) (λ (y: bool), y) : bool_to_bool 14 | -------------------------------------------------------------------------------- /footer.pug: -------------------------------------------------------------------------------- 1 | link(rel='stylesheet' href='https://groupoid.space/main.css') 2 | 3 | footer.footer 4 | a(href='https://5HT.co/license/') 5 | img.footer__logo(src='https://longchenpa.guru/seal.png',width=50) 6 | span.footer__copy 2015—2025 © Олег Мараховський 7 | script(src='https://groupoid.space/highlight.js?v=1') 8 | script(src='https://groupoid.space/bundle.js') 9 | -------------------------------------------------------------------------------- /styles/_footer.scss: -------------------------------------------------------------------------------- 1 | .footer { 2 | width: 100%; 3 | padding: 15px; 4 | background: #7F8C8D; 5 | color: white; 6 | text-align: center; 7 | 8 | &__logo { 9 | width: 50px; 10 | margin: 20px; 11 | } 12 | 13 | &__copy { 14 | font-size: 16px; 15 | white-space: pre; 16 | } 17 | @media(min-width: 768px) { 18 | &__copy { 19 | font-size: 24px; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /lib/nat.alonzo: -------------------------------------------------------------------------------- 1 | -- STLC 2 | 3 | def zero : (T → T) → T → T := λ (s: T → T) (z: T),z 4 | def one : (T → T) → T → T := λ (s: T → T) (z: T), s z 5 | def two : (T → T) → T → T := λ (s: T → T) (z: T), s (s z) 6 | def three : (T → T) → T → T := λ (s: T → T) (z: T), s (s (s z)) 7 | 8 | def succ : ((T → T) → T → T) → ((T → T) → T → T) 9 | := λ (w: (T → T) → T → T) (y: T → T) (x: T), y (w y x) 10 | 11 | #eval succ zero : (T → T) → T → T 12 | #eval succ one : (T → T) → T → T 13 | #eval succ two : (T → T) → T → T 14 | -------------------------------------------------------------------------------- /alonzo.opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | name: "alonzo" 3 | version: "0.4.0" 4 | maintainer: "Namdak Tönpa " 5 | authors: [ "Oleh Marakhovskyi @jealrock" ] 6 | homepage: "https://github.com/groupoid/alonzo" 7 | bug-reports: "https://github.com/groupoid/alonzo/issues" 8 | dev-repo: "git+https://github.com/groupoid/alonzo" 9 | synopsis: "STLC type system" 10 | license: "ISC" 11 | depends: [ 12 | "dune" {>= "2.9"} 13 | "zarith" {>= "1.12"} 14 | "ocaml" {>= "4.14.0"} 15 | "menhir" {>= "20220210"} 16 | ] 17 | build: [ ["dune" "build" "-p" name "-j" jobs] ] 18 | -------------------------------------------------------------------------------- /styles/_semantics.scss: -------------------------------------------------------------------------------- 1 | .semantics { 2 | text-align: center; 3 | 4 | figure { 5 | display: inline-block; 6 | max-width: min-content; 7 | font-size: 13px; 8 | @media(min-width:800px) { 9 | font-size: 16px; 10 | } 11 | } 12 | 13 | h1 { 14 | color: #7D8A96; 15 | font-size: 32px; 16 | text-transform: uppercase; 17 | border-bottom: 1px solid rgba(0, 0 , 0,0.3); 18 | display: inline-block; 19 | margin-bottom: 8px; 20 | } 21 | 22 | section { 23 | margin-top: 40px; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /styles/_resources.scss: -------------------------------------------------------------------------------- 1 | .resources { 2 | 3 | max-width: 650px; 4 | margin: 32px auto 0; 5 | text-align: left; 6 | padding: 8px; 7 | 8 | &__title { 9 | display: inline-block; 10 | margin-bottom: 10px; 11 | color: #7D8A96; 12 | font-size: 32px; 13 | text-transform: uppercase; 14 | border-bottom: 1px solid rgba(0, 0 , 0,0.3); 15 | @media(min-width: 768px) { 16 | font-size: 40px; 17 | } 18 | } 19 | &__list { 20 | padding-left: 32px; 21 | line-height: 1.5; 22 | font-size: 18px; 23 | @media(min-width: 768px) { 24 | font-size: 22px; 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Alonzo 2 | 3 | 4 | 5 | Alonzo is a STLC type system written in OCaml. 6 | 7 | ## Build 8 | 9 | ```shell 10 | $ dune build 11 | $ dune exec alonzo lib/nat.alonzo 12 | ``` 13 | 14 | ## STLC 15 | 16 | * A Formulation of the Simple Theory of Types [Church] 17 | * An Overview of Type Theories [Guallart] 18 | * Category Theory and Lambda Calculus [García] 19 | 20 | ## Credits 21 | 22 | * Oleh Marakhovskyi 23 | -------------------------------------------------------------------------------- /styles/_om.scss: -------------------------------------------------------------------------------- 1 | .om { 2 | 3 | figure { 4 | max-width: inherit; 5 | } 6 | 7 | section { 8 | h1 { 9 | margin-top: 50px; 10 | } 11 | } 12 | 13 | h1 { 14 | color: #7D8A96; 15 | font-size: 32px; 16 | text-transform: uppercase; 17 | border-bottom: 1px solid rgba(0, 0 , 0,0.3); 18 | display: inline-block; 19 | margin-bottom: 32px; 20 | @media(min-width: 768px) { 21 | font-size: 40px; 22 | } 23 | } 24 | 25 | h1 + h2 { 26 | margin-top: 20px; 27 | } 28 | 29 | h3 { 30 | max-width: 100%; 31 | margin: auto; 32 | width: 600px; 33 | padding: 16px 8px 0; 34 | } 35 | } -------------------------------------------------------------------------------- /src/error.ml: -------------------------------------------------------------------------------- 1 | open Expr 2 | 3 | exception Parser of int * int * string 4 | exception UnboundVariable of name 5 | exception Type of typexp * typexp 6 | exception Application of exp * typexp * exp * typexp 7 | 8 | let print_error : exn -> unit = function 9 | | UnboundVariable var -> Printf.printf "Unbound variable: %s\n" var 10 | | Type (expected, actual) -> Printf.printf "Types don't match.\n Expected: %s\nActual: %s\n" (t_to_s expected) (t_to_s actual) 11 | | Application (e1, te1, e2, te2) -> Printf.printf "Can't apply %s:%s\nto %s:%s.\n" (e_to_s e1) (t_to_s te1) (e_to_s e2) (t_to_s te2) 12 | | ex -> Printf.printf "Uncaught exception: %s\n" (Printexc.to_string ex) 13 | 14 | let handle_errors (f : 'a -> 'b) (arg : 'a) : unit = 15 | try f arg with ex -> print_error ex; () 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "alonzo", 3 | "version": "1.0.1", 4 | "description": "Groupoid Infinity Institute", 5 | "main": "", 6 | "scripts": { 7 | "start": "node-sass ./styles -o ./ && pug -O ./framework.js index.pug ", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/groupoid/alonzo" 13 | }, 14 | "author": "Namdak Tonpa", 15 | "license": "DHARMA", 16 | "preinstall": "npm i -g node-sass && npm i -g pug-cli", 17 | "dependencies": { 18 | "mathjax-full": "^3.2.0", 19 | "npm": "^8.12.1", 20 | "pug": "^3.0.2", 21 | "pug-cli": "^1.0.0-alpha6", 22 | "sass": "^1.52.2" 23 | }, 24 | "devDependencies": { 25 | "node-sass": "^7.0.3" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/parser.mly: -------------------------------------------------------------------------------- 1 | %{ open Expr %} 2 | 3 | %token IDENT 4 | %token LPARENS RPARENS 5 | %token COLON COMMA LAM ARROW DEF DEFEQ EVAL ABBREV 6 | %token EOF 7 | 8 | %right ARROW 9 | %start main 10 | 11 | %% 12 | 13 | typexp: IDENT { TVar $1 } | typexp ARROW typexp { TFun ($1, $3) } | LPARENS typexp RPARENS { $2 } 14 | param: LPARENS IDENT COLON typexp RPARENS { PVar ($2, $4) } 15 | params: param params { $1 :: $2 } | param { [$1] } 16 | exp: IDENT { EVar $1 } | LAM params COMMA exp { lam $2 $4 } | exp2 exp2+ { app $1 $2 } | LPARENS exp RPARENS { $2 } 17 | exp2: IDENT { EVar $1 } | LPARENS exp RPARENS { $2 } 18 | command: DEF IDENT COLON typexp DEFEQ exp { Decl ($2, $4, $6) } | ABBREV IDENT DEFEQ typexp { Abbr ($2, $4) } | EVAL exp COLON typexp { Eval ($2, $4) } 19 | main: command main { $1 :: $2 } | EOF { [] } 20 | -------------------------------------------------------------------------------- /styles/_code.scss: -------------------------------------------------------------------------------- 1 | code { 2 | display: inline-block; 3 | overflow-x: auto; 4 | max-width: 100%; 5 | padding: 12px; 6 | margin: 8px 0; 7 | white-space: pre; 8 | text-align: left; 9 | border-radius: 4px; 10 | font-size: 14px; 11 | color: #00259c; 12 | background: white; 13 | box-shadow: 0 1px 4px #f1f0f0, inset 0 0 0 1px #e7e6e5; 14 | @media (min-width: 768px) { 15 | font-size: 17px; 16 | } 17 | } 18 | 19 | pre { 20 | white-space: normal; 21 | max-width: 100%; 22 | width: 650px; 23 | padding: 12px; 24 | margin: 8px auto; 25 | text-align: left; 26 | border-radius: 4px; 27 | font-size: 14px; 28 | color: #00259c; 29 | background: white; 30 | box-shadow: 0 1px 4px #f1f0f0, inset 0 0 0 1px #e7e6e5; 31 | @media (min-width: 768px) { 32 | font-size: 17px; 33 | } 34 | } 35 | 36 | .h__name { 37 | color: #00259c; 38 | font-weight: bold; 39 | } 40 | 41 | .h__keyword { 42 | color: #ca30d4; 43 | } 44 | 45 | .h__symbol { 46 | color: #9f9fa3; 47 | } -------------------------------------------------------------------------------- /highlight.js: -------------------------------------------------------------------------------- 1 | function highlight() { 2 | var code = document.getElementsByTagName('code'); 3 | for (var i = 0; i < code.length; i++) { 4 | code[i].innerHTML = code[i].innerHTML 5 | .replace(/([(){}→=]+|:|:=)/g, 6 | '$1') 7 | .replace(/\b(data|transp|∀|Π|Σ|λ|glue|unglue|Glue|hcomp|where|def|mutual|begin|end|module|import|option|false|true|indᵂ|sup|.1|.2|Σ|Π|Pi|Sigma|W|𝟎|𝟏|𝟐|ind₂|ind₁|ind₀|★|0₂|1₂|Path|PathP|Type|Prop|inductive|record|forall|fun|match|let|axiom|type|theorem|lemma|in|U|S|V)\b(?!:)/g, 8 | '$1'); 9 | } 10 | } 11 | 12 | highlight(); 13 | 14 | var lastScrollPosition = 0; 15 | var ticking = false; 16 | 17 | var titles = document.querySelector('.header__titles'); 18 | var logo = document.querySelector('.header__logo'); 19 | function doSomething(scrollPos) { 20 | titles.style.transform = 'translate3d(0px, ' + (scrollPos/2) + 'px, 0px)'; 21 | logo.style.transform = 'translate3d(0px, ' + (scrollPos/2) + 'px, 0px)'; 22 | } 23 | -------------------------------------------------------------------------------- /src/expr.ml: -------------------------------------------------------------------------------- 1 | type name = string 2 | 3 | type typexp = 4 | | TVar of name 5 | | TFun of typexp * typexp 6 | 7 | type param = 8 | | PVar of name * typexp 9 | 10 | type exp = 11 | | ELam of param * exp 12 | | EApp of exp * exp 13 | | EVar of name 14 | 15 | type command = 16 | | Decl of name * typexp * exp 17 | | Abbr of name * typexp 18 | | Eval of exp * typexp 19 | 20 | let rec lam params exp = 21 | match params with 22 | | [] -> exp 23 | | x :: xs -> ELam (x, lam xs exp) 24 | 25 | let rec app f = function 26 | | [] -> f 27 | | x :: xs -> app (EApp (f, x)) xs 28 | 29 | let rec t_to_s (t : typexp): name :> string = 30 | match t with 31 | | TVar n -> n 32 | | TFun (t1, t2) -> Printf.sprintf "(%s→%s)" (t_to_s t1) (t_to_s t2) 33 | 34 | let p_to_s (p : param): name :> string = 35 | match p with 36 | | PVar (n, t) -> Printf.sprintf "(%s: %s)" n (t_to_s t) 37 | 38 | let rec e_to_s (exp: exp): name :> string = 39 | match exp with 40 | | ELam (p, e) -> Printf.sprintf "(λ%s,%s)" (p_to_s p) (e_to_s e) 41 | | EApp (e1, e2) -> Printf.sprintf "(%s %s)" (e_to_s e1) (e_to_s e2) 42 | | EVar v -> v 43 | -------------------------------------------------------------------------------- /styles/_header.scss: -------------------------------------------------------------------------------- 1 | .header { 2 | background: black; 3 | color: white; 4 | position: relative; 5 | min-height: 450px; 6 | padding: 16px 8px; 7 | display: flex; 8 | text-align: center; 9 | flex-direction: column; 10 | justify-content: center; 11 | align-items: center; 12 | width: 100%; 13 | z-index: 5; 14 | 15 | &__logo { 16 | width: 130px; 17 | position: relative; 18 | } 19 | 20 | &__titles { 21 | position: relative; 22 | max-width: 800px; 23 | margin: 20px; 24 | text-shadow: 1px 1px 7px #56CCF2; 25 | } 26 | 27 | &__title { 28 | font-size: 48px; 29 | line-height: 1.1; 30 | } 31 | 32 | &__subtitle { 33 | font-size: 22px; 34 | } 35 | 36 | @media(min-width: 768px) { 37 | flex-direction: row; 38 | 39 | &__logo { 40 | width: 160px; 41 | margin-right: 10px; 42 | } 43 | 44 | &__title { 45 | font-size: 60px; 46 | } 47 | 48 | &__subtitle { 49 | font-size: 30px; 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /styles/_index.scss: -------------------------------------------------------------------------------- 1 | .index { 2 | max-width: 900px; 3 | margin: auto; 4 | padding: 20px 0; 5 | display: flex; 6 | flex-wrap: wrap; 7 | justify-content: center; 8 | 9 | &__col { 10 | white-space: nowrap; 11 | padding: 15px 25px; 12 | margin: 15px; 13 | background: #fefefe; 14 | box-shadow: 0 1px 4px rgba(0, 0, 100, 0.1), inset 0 0 0 1px rgba(0, 0, 0, 0.1); 15 | transition: box-shadow 0.5s cubic-bezier(0.23, 1, 0.32, 1); 16 | 17 | &:hover { 18 | box-shadow: 0 8px 40px rgba(0, 0, 100, 0.15), inset 0 0 0 1px rgba(0, 0, 0, 0.1); 19 | } 20 | } 21 | 22 | a { 23 | line-height: 1.5; 24 | color: #888; 25 | font-size: 24px; 26 | } 27 | 28 | a[href^="#"] { 29 | color: #BBBBBB; 30 | } 31 | 32 | a:hover { 33 | color: #3A98C8; 34 | } 35 | 36 | a[href^="#"]:hover { 37 | color: #BBBBBB; 38 | } 39 | 40 | h2 { 41 | font-size: 24px; 42 | text-align: left; 43 | color: #707070; 44 | margin: 0 0 10px; 45 | text-transform: uppercase; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/lexer.mll: -------------------------------------------------------------------------------- 1 | { 2 | open Parser 3 | open Lexing 4 | 5 | let nextLine lexbuf = 6 | let pos = lexbuf.lex_curr_p in 7 | lexbuf.lex_curr_p <- { pos with pos_bol = pos.pos_cnum; pos_lnum = pos.pos_lnum + 1 } 8 | 9 | } 10 | 11 | let nl = "\r\n"|"\r"|"\n" 12 | let inlineComment = "--" [^ '\n' '\r']* (nl|eof) 13 | 14 | let ws = ['\t' ' '] 15 | let latin1 = [^ '\t' ' ' '\r' '\n' '(' ')' ':' ','] # '-' 16 | let bytes2 = ['\192'-'\223']['\128'-'\191'] 17 | let bytes3 = ['\224'-'\239']['\128'-'\191']['\128'-'\191'] 18 | let bytes4 = ['\240'-'\247']['\128'-'\191']['\128'-'\191']['\128'-'\191'] 19 | let utf8 = latin1|bytes2|bytes3|bytes4 20 | let ident = utf8* 21 | 22 | let defeq = ":=" | "\xE2\x89\x94" 23 | let arrow = "->" | "\xE2\x86\x92" 24 | let lam = "\\" | "\xCE\xBB" 25 | 26 | rule read = parse 27 | | nl { nextLine lexbuf; read lexbuf } 28 | | inlineComment { nextLine lexbuf; read lexbuf } 29 | | ws+ { read lexbuf } 30 | | '(' { LPARENS } 31 | | ')' { RPARENS } 32 | | lam { LAM } 33 | | arrow { ARROW } 34 | | ':' { COLON } 35 | | ',' { COMMA } 36 | | "def" { DEF } 37 | | "abbrev" { ABBREV } 38 | | defeq { DEFEQ } 39 | | "#eval" { EVAL } 40 | | ident as s { IDENT s } 41 | | eof { EOF } 42 | -------------------------------------------------------------------------------- /styles/mathjax.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | var newMathJax = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js'; 3 | var oldMathJax = 'cdn.mathjax.org/mathjax/latest/MathJax.js'; 4 | var replaceScript = function (script, src) { 5 | var newScript = document.createElement('script'); 6 | newScript.src = newMathJax + src.replace(/.*?(\?|$)/, '$1'); 7 | newScript.onload = script.onload; 8 | newScript.onerror = script.onerror; 9 | script.onload = script.onerror = null; 10 | while (script.firstChild) newScript.appendChild(script.firstChild); 11 | if (script.id != null) newScript.id = script.id; 12 | script.parentNode.replaceChild(newScript, script); 13 | console.info('MathJax: 2.7.1.'); 14 | } 15 | 16 | if (document.currentScript) { 17 | var script = document.currentScript; 18 | replaceScript(script, script.src); 19 | } else { 20 | var n = oldMathJax.length; 21 | var scripts = document.getElementsByTagName('script'); 22 | for (var i = 0; i < scripts.length; i++) { 23 | var script = scripts[i]; 24 | var src = (script.src || '').replace(/.*?:\/\//,''); 25 | if (src.substr(0, n) === oldMathJax) { 26 | replaceScript(script, src); 27 | break; 28 | } 29 | } 30 | } 31 | })(); 32 | -------------------------------------------------------------------------------- /styles/_stack.scss: -------------------------------------------------------------------------------- 1 | .stack { 2 | margin: auto; 3 | max-width: 100%; 4 | border-spacing: 10px; 5 | color: #282828; 6 | font-size: 20px; 7 | 8 | td { 9 | background-color:#fff9a6; 10 | // width: 80px; 11 | padding: 4px; 12 | outline: 1px solid rgba(0, 0, 0, .3); 13 | } 14 | 15 | th { 16 | padding: 4px; 17 | text-align: left; 18 | font-weight: normal; 19 | } 20 | 21 | .empty { 22 | background-color: inherit; 23 | outline: inherit; 24 | 25 | } 26 | 27 | } 28 | 29 | 30 | 31 | 32 | @media(max-width: 600px) { 33 | .stack { 34 | font-size: 16px; 35 | display: inline-block; 36 | border-spacing: 0; 37 | tbody { 38 | display: block; 39 | } 40 | 41 | tr { 42 | display: block; 43 | text-align: left; 44 | vertical-align: top; 45 | position: relative; 46 | } 47 | 48 | td { 49 | margin: 30px 0 10px; 50 | text-align: center; 51 | padding: 4px; 52 | display: inline-block; 53 | width: 90px; 54 | } 55 | 56 | td[colspan="4"] { 57 | width: 360px; 58 | } 59 | 60 | td[colspan="2"] { 61 | width: 180px; 62 | } 63 | 64 | th { 65 | position: absolute; 66 | top: 0; 67 | width: 100%; 68 | } 69 | } 70 | } 71 | 72 | 73 | 74 | @media(max-width: 320px) { 75 | .stack { 76 | font-size: 12px; 77 | td { 78 | margin: 20px 0 5px; 79 | width: 80px; 80 | } 81 | 82 | td[colspan="4"] { 83 | width: 320px; 84 | } 85 | 86 | td[colspan="2"] { 87 | width: 160px; 88 | } 89 | } 90 | } 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /styles/_exe.scss: -------------------------------------------------------------------------------- 1 | .exe { 2 | 3 | figure { 4 | max-width: inherit; 5 | } 6 | 7 | h1 { 8 | color: #7D8A96; 9 | font-size: 32px; 10 | text-transform: uppercase; 11 | border-bottom: 1px solid rgba(0, 0 , 0,0.3); 12 | display: inline-block; 13 | margin: 42px 0 10px; 14 | @media(min-width: 768px) { 15 | font-size: 40px; 16 | } 17 | } 18 | 19 | h1 + h2 { 20 | margin-top: 0px; 21 | } 22 | } 23 | 24 | .macro { 25 | margin: 0 auto; 26 | display: flex; 27 | justify-content: space-around; 28 | max-width: 600px; 29 | flex-wrap: wrap; 30 | width: 100%; 31 | &__col { 32 | h3 { 33 | padding: 0; 34 | width: initial; 35 | } 36 | padding-left: 24px; 37 | line-height: 1.5; 38 | font-size: 14px; 39 | @media(min-width: 768px) { 40 | font-size: 22px; 41 | } 42 | } 43 | } 44 | 45 | .langf { 46 | @media(min-width: 920px) { 47 | display: flex; 48 | flex-direction: row; 49 | justify-content: center; 50 | } 51 | 52 | ol { 53 | display: inline-block; 54 | max-width: 650px; 55 | margin: auto; 56 | font-size: 20px; 57 | padding-left: 36px; 58 | } 59 | 60 | &__col { 61 | @media(min-width: 920px) { 62 | .langf-col:last-child { 63 | white-space: pre; 64 | margin-left: 20px; 65 | } 66 | 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /styles/_types.scss: -------------------------------------------------------------------------------- 1 | .types { 2 | display: inline-block; 3 | text-align: left; 4 | max-width: 100%; 5 | padding: 0 8px; 6 | h1 { 7 | color: #7D8A96; 8 | font-size: 32px; 9 | text-transform: uppercase; 10 | border-bottom: 1px solid rgba(0, 0 , 0,0.3); 11 | display: inline-block; 12 | margin: 42px 0 10px; 13 | @media(min-width: 768px) { 14 | font-size: 40px; 15 | } 16 | } 17 | 18 | section { 19 | max-width: 100%; 20 | } 21 | 22 | p { 23 | margin: 0; 24 | padding-left: 0; 25 | } 26 | 27 | 28 | 29 | h1 + h2 { 30 | margin-top: 0px; 31 | } 32 | 33 | 34 | .type { 35 | max-width: 660px; 36 | display: flex; 37 | flex-flow: row wrap; 38 | &__col { 39 | padding-left: 22px; 40 | flex: 1 0 15%; 41 | h3 { 42 | width: initial; 43 | padding: 0; 44 | margin: 0; 45 | } 46 | @media(min-width: 600px) { 47 | padding-right: 22px; 48 | flex: 1 0 15%; 49 | font-size: 20px; 50 | } 51 | } 52 | } 53 | 54 | .legend { 55 | margin: 20px auto 0; 56 | display: inline-block; 57 | padding: 10px 20px; 58 | font-size: 24px; 59 | background: #FDF6E3; 60 | border-radius: 4px; 61 | box-shadow: 0 4px 6px rgba(50,50,93,.11), 62 | 0 1px 3px rgba(0, 0, 0,.08); 63 | } 64 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | DHARMA License 2 | 3 | Copyright (c) 2016—2022 Groupoid Infinity 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | YOU CANNOT USE THIS SOFTWARE IN ANY (PROVABLE BY MONEY TRACE) 10 | PROCESS CHAIN OF EXTERMINATING UKRAINIANS BY ANY MEANS OF FASCIST 11 | ACTIONS AGAINST OUR TERRITORIAL INTEGRITY, CULTURAL DIVERSITY BY 12 | APPLYING MILITARY INVASIONS, ECONOMICAL WARS, HUMANITARIAN DISASTERS, 13 | ARTFICIAL HOLODOMORS, GENOCIDE, RAPING, LOOTING, ROBBERIES, SPREADING 14 | FAKE INFORMATION, AND OTHER CONTEMPORARY WEAPONS OF WAR AT SCALE 15 | OR IN INVIDIVUAL MANNER. 16 | 17 | YOU CANNOT USE THIS SOFTWARE BY ANY MEANS IN INTEREST OF LEGAL 18 | ENTITIES OR INDIVIDUALS WHO IS SUPPORTING NOW OR WAS SUPPORTING 19 | BACK THEN FASCISM, RUSCISM, COMMUNISM, CHAUVINISM, HUMILIATION, 20 | AND OTHER SUPPRESSIVE IDEOLOGIES IN DIFFERENT EXPRESSIONS. 21 | 22 | STOP KILLING UKRAINIANS, 23 | THE COUNTER RENDERS TENS OF MILLIONS. 24 | 25 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 26 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 27 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 28 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 29 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 30 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 31 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 32 | -------------------------------------------------------------------------------- /src/alonzo.ml: -------------------------------------------------------------------------------- 1 | open Error 2 | 3 | module ENV = Map.Make (String) 4 | let decls : (Expr.exp ENV.t) ref = ref ENV.empty 5 | let abbrs : (Expr.typexp ENV.t) ref = ref ENV.empty 6 | 7 | let rec unabbr (texp: Expr.typexp) : Expr.typexp = 8 | match texp with 9 | | TVar n -> Option.value (ENV.find_opt n !abbrs) ~default:texp 10 | | TFun (t1, t2) -> TFun (unabbr t1, unabbr t2) 11 | 12 | let rec teval (params: Expr.param list): Expr.exp -> Expr.typexp = function 13 | | EVar n -> begin 14 | let param = List.find_opt (function Expr.PVar(pn, _) -> pn = n) params in 15 | match param with 16 | | None -> begin match ENV.find_opt n !decls with 17 | | Some v -> teval [] v 18 | | None -> raise (UnboundVariable n) 19 | end 20 | | Some PVar (_, t) -> unabbr t 21 | end 22 | | ELam (PVar (n, t), e) -> TFun (unabbr t, teval (List.append params [PVar (n,t)]) e) 23 | | EApp (e1, e2) -> 24 | let te1 = teval params e1 in 25 | let te2 = teval params e2 in 26 | begin match te1 with 27 | | TFun (t1, t2) when t1 = te2 -> unabbr t2 28 | | _ -> raise (Application (e1, te1, e2, te2)) 29 | end 30 | 31 | let rec subst (x: Expr.name) (sub: Expr.exp): Expr.exp -> Expr.exp = function 32 | | EVar n -> if n = x then sub else EVar n 33 | | ELam (p, e) -> ELam(p, subst x sub e) 34 | | EApp (e1, e2) -> EApp (subst x sub e1, subst x sub e2) 35 | 36 | let rec reduce (exp : Expr.exp): Expr.exp = 37 | match exp with 38 | | EVar n -> begin match ENV.find_opt n !decls with 39 | | Some v -> v 40 | | None -> EVar n 41 | end 42 | | ELam (p, e) -> ELam (p, reduce e) 43 | | EApp (e1, e2) -> 44 | let re1 = reduce e1 in 45 | let re2 = reduce e2 in 46 | begin match re1 with 47 | | ELam (PVar (n, _), e) -> reduce (subst n re2 e) 48 | | _ -> EApp (re1, re2) 49 | end 50 | 51 | let run (commands : Expr.command list): unit = 52 | let checker (expected: Expr.typexp) (e: Expr.exp) (f: unit -> unit) = 53 | let actual = teval [] e in 54 | if actual = unabbr expected then f () else raise (Type (expected, actual)) in 55 | 56 | let runner = function 57 | | Expr.Decl (n, t, e) -> checker t e (fun () -> decls := ENV.add n (reduce e) !decls); 58 | | Expr.Abbr (n, t) -> abbrs := ENV.add n (unabbr t) !abbrs; 59 | | Expr.Eval (e, t) -> checker t e (fun () -> print_endline (reduce e |> Expr.e_to_s)); in 60 | 61 | List.iter runner commands 62 | 63 | let evalFile path : unit = 64 | let chan = open_in path in 65 | let lexbuf = Lexing.from_channel chan in 66 | try 67 | let commands = Parser.main Lexer.read lexbuf in 68 | handle_errors run commands; 69 | close_in chan; 70 | flush_all () 71 | with Parser.Error -> 72 | Parser (Lexing.lexeme_start lexbuf, Lexing.lexeme_end lexbuf, Lexing.lexeme lexbuf) 73 | |> raise 74 | 75 | let main () = 76 | Array.sub Sys.argv 1 (Array.length Sys.argv - 1) |> Array.iter evalFile; 77 | () 78 | 79 | let () = main () 80 | -------------------------------------------------------------------------------- /framework.js: -------------------------------------------------------------------------------- 1 | // Mixin usages in PUG: 2 | 3 | // +tex(false, false). 4 | // $\mathbf{Definition}$ (Space of Sections). Let $\mathbf{H}$ be 5 | // a $(\infty,1)$-topos, and let $E \rightarrow B : \mathbf{H}_{/B}$ a bundle in 6 | // $\mathbf{H}$, object in the slice topos. Then the space of sections $\Gamma_\Sigma(E)$ 7 | // of this bundle is the Dependent Product. 8 | 9 | // +tex(true, false). 10 | // $$ 11 | // \Gamma_\Sigma(E) = \Pi_\Sigma (E) \in \mathbf{H}. 12 | // $$ 13 | 14 | // +code. 15 | // def Pi (A : U) (B : A → U) : U := Π (x : A), B x 16 | 17 | const {mathjax} = require('mathjax-full/js/mathjax.js'); 18 | const {TeX} = require('mathjax-full/js/input/tex.js'); 19 | const {SVG} = require('mathjax-full/js/output/svg.js'); 20 | const {liteAdaptor} = require('mathjax-full/js/adaptors/liteAdaptor.js'); 21 | const {RegisterHTMLHandler} = require('mathjax-full/js/handlers/html.js'); 22 | const {AssistiveMmlHandler} = require('mathjax-full/js/a11y/assistive-mml.js'); 23 | const {AllPackages} = require('mathjax-full/js/input/tex/AllPackages.js'); 24 | 25 | const adaptor = liteAdaptor(); 26 | const handler = RegisterHTMLHandler(adaptor); 27 | 28 | const tex = new TeX({ 29 | packages: ['base', 'autoload', 'require', 'ams', 'amscd', 'newcommand', 'configmacros'], 30 | inlineMath: [ ["$", "$"] ], 31 | macros: { // Plug your Glyphs here 32 | llparenthesis: '\\mathopen{\u2987}', 33 | rrparenthesis: '\\mathclose{\u2988}', 34 | llbracket: '\\mathopen{\u27E6}', 35 | rrbracket: '\\mathclose{\u27E7}', 36 | incmap: '\\mathclose{\u21AA}', 37 | meet: '\\mathopen{\u2227}', 38 | map: '\\mathopen{\u21A6}', 39 | join: '\\mathopen{\u2228}', 40 | trans: '\\, \\mathbin{\\vcenter{\\rule{.3ex}{.3ex}}} \\,', 41 | mapright: ['\\xrightarrow{{#1}}', 1], 42 | mapdown: ['\\Big\\downarrow\\rlap{\\raise2pt{\\scriptstyle{#1}}}', 1], 43 | mapdiagl: ['\\vcenter{\\searrow}\\rlap{\\raise2pt{\\scriptstyle{#1}}}', 1], 44 | mapdiagr: ['\\vcenter{\\swarrow}\\rlap{\\raise2pt{\\scriptstyle{#1}}}', 1], 45 | } 46 | }); 47 | 48 | tex.postFilters.add(({math, data}) => { 49 | if (!data.error) return; 50 | data.root.walkTree((node) => { 51 | if (node.isKind('merror')) { 52 | console.log('TeX error:\n ' + node.attributes.get('data-mjx-error')); 53 | } 54 | }); 55 | }); 56 | 57 | const svg = new SVG({fontCache: 'local'}); 58 | 59 | function renderPug(block) { 60 | var recv; with({pug_html: ""}){ 61 | eval(`(${block})();`); recv = pug_html; 62 | }; return recv 63 | } 64 | 65 | function renderTeX(formulae) { 66 | return adaptor.innerHTML(mathjax.document(formulae, { 67 | InputJax: tex, OutputJax: svg 68 | }).render().document.body); 69 | } 70 | 71 | exports.tex = function (block) { 72 | return renderTeX(renderPug(block)); 73 | } 74 | 75 | exports.highlight = function (block) { 76 | return renderPug(block) 77 | .replace(/([(){}→=]+|:|:=)/g, 78 | '$1') 79 | .replace(/\b(∀|Π|Σ|W|λ|glue|unglue|Glue|transp|hcomp|where|def|begin|end|module|import|option|false|true|indᵂ|sup|.1|.2|𝟎|𝟏|𝟐|ind₂|ind₁|ind₀|★|0₂|1₂|PathP|PartialP|inc|ouc|axiom|theorem|lemdata|ma|U|V)\b(?!:)/g, 80 | '$1'); 81 | } 82 | -------------------------------------------------------------------------------- /styles/main.scss: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'local'; 3 | src: url('https://groupoid.space/Geometria-Light.otf'); 4 | font-weight: normal; 5 | font-style: normal; 6 | } 7 | 8 | .MathJax_Display { 9 | overflow-x: auto; 10 | overflow-y: hidden; 11 | } 12 | 13 | nav a { 14 | font-size: 18px; 15 | border: 2px solid #dedede; 16 | background-color: white; 17 | color: lightblue; 18 | text-decoration: none; 19 | margin: 5px 5px; 20 | padding: 7px 12px; 21 | min-width: 150px; 22 | text-align: center; 23 | } 24 | 25 | nav a:visited { 26 | color: lightblue; 27 | } 28 | 29 | nav a:hover { 30 | border-bottom: 2px solid #00b8cf; 31 | } 32 | 33 | 34 | nav { 35 | display: flex; 36 | background-color: #FBFBFB; 37 | flex-direction: row; 38 | justify-content: center; 39 | } 40 | 41 | nav a { 42 | font-size: 18px; 43 | min-width: initial; 44 | } 45 | 46 | 47 | * { 48 | margin: 0; 49 | padding: 0; 50 | box-sizing: border-box; 51 | } 52 | 53 | sub, 54 | sup { 55 | font-size: 80%; 56 | line-height: 0; 57 | position: relative; 58 | vertical-align: baseline; 59 | } 60 | 61 | sub { 62 | bottom: -0.25em; 63 | } 64 | 65 | sup { 66 | top: -0.5em; 67 | } 68 | 69 | html { 70 | height: 100%; 71 | } 72 | 73 | body { 74 | min-height: 100%; 75 | text-rendering: optimizeLegibility; 76 | -webkit-font-smoothing: antialiased; 77 | } 78 | 79 | h1, h2, h3, h4 { 80 | font-weight: normal; 81 | } 82 | 83 | ul { 84 | list-style-type: none; 85 | } 86 | 87 | ol, 88 | ul { 89 | text-align: left; 90 | line-height: 1.5; 91 | } 92 | 93 | img, figure { 94 | vertical-align: middle; 95 | } 96 | 97 | img { margin-left:20px; } 98 | 99 | .content { 100 | min-height: 100%; 101 | font-family: local; 102 | display: flex; // sticky footer 103 | flex-direction: column; 104 | position: relative; 105 | } 106 | 107 | .main { 108 | color: #586E75; 109 | background: #FBFBFB; 110 | padding: 50px 0px; 111 | text-align: center; 112 | box-shadow: 0 3px 10px rgba(0,0,0,0); 113 | // 0 -3px 10px rgba(0,0,0,0.3); 114 | z-index: 5; 115 | flex: 1 1 auto; // sticky footer 116 | 117 | } 118 | 119 | figure { 120 | min-width: 300px; 121 | overflow-x: auto; 122 | padding: 10px 2px; 123 | font-size: 18px; 124 | display: block; 125 | } 126 | 127 | figure::after { 128 | content: "\A"; 129 | white-space: pre; 130 | } 131 | 132 | h2 { 133 | font-size: 24px; 134 | color: #268BD2; 135 | @media(min-width: 768px) { 136 | font-size: 32px; 137 | } 138 | margin: 34px 0 8px; 139 | } 140 | 141 | h3 { 142 | max-width: 100%; 143 | margin: 16px auto 0; 144 | // width: 650px; 145 | padding: 0 0 0 8px; 146 | text-transform: uppercase; 147 | text-align: left; 148 | font-size: 22px; 149 | } 150 | 151 | p { 152 | max-width: 100%; 153 | width: 650px; 154 | margin: auto; 155 | padding: 8px; 156 | text-align: left; 157 | font-size: 18px; 158 | line-height: 1.4; 159 | @media(min-width: 768px) { 160 | font-size: 22px; 161 | } 162 | } 163 | 164 | p:hover { 165 | background: white; 166 | } 167 | 168 | mark { 169 | background: #FDF6E3; 170 | padding: 0px 2px; 171 | border-radius: 2px; 172 | color: #586E75; 173 | } 174 | 175 | a { 176 | color: #3A98C8; 177 | text-decoration: none; 178 | &:visited { 179 | color: #3A98C8; 180 | } 181 | 182 | &:hover { 183 | color: #D33682; 184 | } 185 | 186 | &:active { 187 | color: #D33682; 188 | } 189 | } 190 | 191 | 192 | @import '_aside'; 193 | @import '_header'; 194 | @import '_footer'; 195 | @import '_semantics'; 196 | @import '_intro'; 197 | @import '_status'; 198 | @import '_resources'; 199 | @import '_index'; 200 | @import '_om'; 201 | @import '_exe'; 202 | @import '_types'; 203 | @import '_list'; 204 | @import '_code'; 205 | @import '_canvas'; 206 | @import '_stack'; 207 | 208 | -------------------------------------------------------------------------------- /header.pug: -------------------------------------------------------------------------------- 1 | mixin tex(center=false, paragraph=true) 2 | if paragraph 3 | p(style=center ? {'text-align': 'center' } : null)!= tex(`${block}`) 4 | else 5 | span(style=center ? { 6 | 'text-align': 'center', 7 | 'display': 'block', 8 | 'padding-top': '8px', 9 | 'padding-bottom': '8px', 10 | } : null)!= tex(`${block}`) 11 | 12 | mixin tex2(center=false, paragraph=true) 13 | p(style=center ? { 14 | 'text-align': 'center', 15 | 'display': 'block', 16 | 'padding-top': '8px', 17 | 'padding-bottom': '8px', 18 | } : null)!= tex(`${block}`) 19 | 20 | mixin code 21 | code!= highlight(`${block}`) 22 | 23 | mixin header(logo, title, subtitle) 24 | header.header 25 | .header__titles 26 | h1.header__title!= title 27 | h4.header__subtitle!= subtitle 28 | 29 | doctype html 30 | html 31 | head 32 | meta(charset='utf-8') 33 | meta(http-equiv='x-ua-compatible' content='ie=edge') 34 | meta(property='fb:app_id' content='118554188236439') 35 | meta(name='viewport' content='width=device-width, initial-scale=1') 36 | meta(name='author' content='Maxim Sokhatsky') 37 | meta(name='twitter:site' content='@5HT') 38 | meta(name='twitter:creator' content='@5HT') 39 | meta(property='og:type' content='website') 40 | meta(property='og:image' content='https://avatars.githubusercontent.com/u/17128096?s=400&u=66a63d4cdd9625b2b4b37d724cc00fe6401e5bd8&v=4') 41 | meta(name='msapplication-TileColor' content='#ffffff') 42 | meta(name='msapplication-TileImage' content='https://anders.groupoid.space/images/ms-icon-144x144.png') 43 | meta(name='theme-color' content='#ffffff') 44 | 45 | link(rel='stylesheet' href='https://anders.groupoid.space/main.css?v=1') 46 | link(rel='apple-touch-icon' sizes='57x57' href='https://anders.groupoid.space/images/apple-icon-57x57.png') 47 | link(rel='apple-touch-icon' sizes='60x60' href='https://anders.groupoid.space/images/apple-icon-60x60.png') 48 | link(rel='apple-touch-icon' sizes='72x72' href='https://anders.groupoid.space/images/apple-icon-72x72.png') 49 | link(rel='apple-touch-icon' sizes='76x76' href='https://anders.groupoid.space/images/apple-icon-76x76.png') 50 | link(rel='apple-touch-icon' sizes='114x114' href='https://anders.groupoid.space/images/apple-icon-114x114.png') 51 | link(rel='apple-touch-icon' sizes='120x120' href='https://anders.groupoid.space/images/apple-icon-120x120.png') 52 | link(rel='apple-touch-icon' sizes='144x144' href='https://anders.groupoid.space/images/apple-icon-144x144.png') 53 | link(rel='apple-touch-icon' sizes='152x152' href='https://anders.groupoid.space/images/apple-icon-152x152.png') 54 | link(rel='apple-touch-icon' sizes='180x180' href='https://anders.groupoid.space/images//apple-icon-180x180.png') 55 | link(rel='icon' type='image/png' sizes='192x192' href='https://anders.groupoid.space/images/android-icon-192x192.png') 56 | link(rel='icon' type='image/png' sizes='32x32' href='https://anders.groupoid.space/images/favicon-32x32.png') 57 | link(rel='icon' type='image/png' sizes='96x96' href='https://anders.groupoid.space/images/favicon-96x96.png') 58 | link(rel='icon' type='image/png' sizes='16x16' href='https://anders.groupoid.space/images/favicon-16x16.png') 59 | link(rel='manifest' href='https://anders.groupoid.space/images/manifest.json') 60 | 61 | style. 62 | svg a{fill:blue;stroke:blue} 63 | [data-mml-node="merror"]>g{fill:red;stroke:red} 64 | [data-mml-node="merror"]>rect[data-background]{fill:yellow;stroke:none} 65 | [data-frame],[data-line]{stroke-width:70px;fill:none} 66 | .mjx-dashed{stroke-dasharray:140} 67 | .mjx-dotted{stroke-linecap:round;stroke-dasharray:0,140} 68 | use[data-c]{stroke-width:3px} 69 | 70 | body.content 71 | block vars 72 | block content 73 | -------------------------------------------------------------------------------- /src/stlc.ml: -------------------------------------------------------------------------------- 1 | (* Alonzo (c) 2025 5HT $ ocamlc -o alonzo stlc.ml *) 2 | 3 | type term = 4 | | Var of string 5 | | Star 6 | | Arrow of term * term 7 | | Lam of string * term * term 8 | | App of term * term 9 | | Unit 10 | | Prod of term * term 11 | | Pair of term * term 12 | | Pr1 of term 13 | | Pr2 of term 14 | 15 | let rec string_of_term = function 16 | | Var x -> x 17 | | Star -> "*" 18 | | Arrow (a, b) -> "(" ^ string_of_term a ^ " -> " ^ string_of_term b ^ ")" 19 | | Lam (x, a, t) -> "λ (" ^ x ^ " : " ^ string_of_term a ^ "), " ^ string_of_term t 20 | | App (t1, t2) -> "(" ^ string_of_term t1 ^ " " ^ string_of_term t2 ^ ")" 21 | | Unit -> "unit" 22 | | Prod (a, b) -> "(" ^ string_of_term a ^ " * " ^ string_of_term b ^ ")" 23 | | Pair (t1, t2) -> "<" ^ string_of_term t1 ^ ", " ^ string_of_term t2 ^ ">" 24 | | Pr1 t -> "π1(" ^ string_of_term t ^ ")" 25 | | Pr2 t -> "π2(" ^ string_of_term t ^ ")" 26 | 27 | type context = (string * term) list 28 | 29 | let rec subst x s = function 30 | | Var y -> if x = y then s else Var y 31 | | Arrow (a, b) -> Arrow (subst x s a, subst x s b) 32 | | Lam (y, a, b) when x <> y -> Lam (y, subst x s a, subst x s b) 33 | | App (f, a) -> App (subst x s f, subst x s a) 34 | | Prod (a, b) -> Prod (subst x s a, subst x s b) 35 | | Pair (t1, t2) -> Pair (subst x s t1, subst x s t2) 36 | | Pr1 t -> Pr1 (subst x s t) 37 | | Pr2 t -> Pr2 (subst x s t) 38 | | t -> t 39 | 40 | let rec lookup x = function 41 | | [] -> raise (Failure ("Unbound variable: " ^ x)) 42 | | (y, typ) :: rest -> if x = y then typ else lookup x rest 43 | 44 | let rec equal ctx t1 t2 = match t1, t2 with 45 | | Var x, Var y -> x = y 46 | | Star, Star -> true 47 | | Arrow (a, b), Arrow (a', b') -> equal ctx a a' && equal ctx b b' 48 | | Lam (x, a, b), Lam (y, a', b') -> equal ctx a a' && equal ((x, a) :: ctx) b (subst y (Var x) b') 49 | | App (f, a), App (f', a') -> equal ctx f f' && equal ctx a a' 50 | | Unit, Unit -> true 51 | | Prod (a, b), Prod (a', b') -> equal ctx a a' && equal ctx b b' 52 | | Pair (t1, t2), Pair (t1', t2') -> equal ctx t1 t1' && equal ctx t2 t2' 53 | | Pr1 t, Pr1 t' -> equal ctx t t' 54 | | Pr2 t, Pr2 t' -> equal ctx t t' 55 | | Lam (x, _, b), t -> equal ctx b (App (t, Var x)) 56 | | t, Lam (x, _, b) -> equal ctx (App (t, Var x)) b 57 | | _ -> false 58 | 59 | and reduce ctx t = match t with 60 | | App (Lam (x, _, b), a) -> subst x a b 61 | | App (f, a) -> App (reduce ctx f, reduce ctx a) 62 | | Pr1 (Pair (t1, _)) -> t1 63 | | Pr2 (Pair (_, t2)) -> t2 64 | | Pr1 t -> Pr1 (reduce ctx t) 65 | | Pr2 t -> Pr2 (reduce ctx t) 66 | | _ -> t 67 | 68 | and normalize ctx t = 69 | let t' = reduce ctx t in 70 | if equal ctx t t' then t else normalize ctx t' 71 | 72 | and infer ctx t = let res = match t with 73 | | Var x -> lookup x ctx 74 | | Star -> Star 75 | | Arrow (a, b) -> 76 | let _ = infer ctx a in 77 | let _ = infer ctx b in 78 | if equal ctx (infer ctx a) Star && equal ctx (infer ctx b) Star then Star 79 | else raise (Failure "Arrow type components must be of type *") 80 | | Lam (x, a, b) -> 81 | let _ = infer ctx a in 82 | if not (equal ctx (infer ctx a) Star) then raise (Failure "Lambda annotation must be a type"); 83 | Arrow (a, infer ((x, a) :: ctx) b) 84 | | App (f, a) -> 85 | let f_type = infer ctx f in 86 | (match f_type with 87 | | Arrow (a', b) -> 88 | let a_type = infer ctx a in 89 | if equal ctx a_type a' then b 90 | else raise (Failure "Argument type mismatch") 91 | | _ -> raise (Failure "Application requires an arrow type")) 92 | | Unit -> Star 93 | | Prod (a, b) -> 94 | let _ = infer ctx a in 95 | let _ = infer ctx b in 96 | if equal ctx (infer ctx a) Star && equal ctx (infer ctx b) Star then Star 97 | else raise (Failure "Product type components must be of type *") 98 | | Pair (t1, t2) -> 99 | let t1_type = infer ctx t1 in 100 | let t2_type = infer ctx t2 in 101 | Prod (t1_type, t2_type) 102 | | Pr1 t -> 103 | let t_type = infer ctx t in 104 | (match t_type with 105 | | Prod (a, _) -> a 106 | | _ -> raise (Failure "First projection requires a product type")) 107 | | Pr2 t -> 108 | let t_type = infer ctx t in 109 | (match t_type with 110 | | Prod (_, b) -> b 111 | | _ -> raise (Failure "Second projection requires a product type")) 112 | in normalize ctx res 113 | 114 | (* Test Suite *) 115 | 116 | let id_type = Arrow (Star, Star) 117 | let id = Lam ("x", Star, Var "x") 118 | let unit_type = Star 119 | let pair_type = Prod (Star, Star) 120 | let pair_test = Pair (Unit, Unit) 121 | let pr1_test = Pr1 pair_test 122 | let pr2_test = Pr2 pair_test 123 | 124 | let beta = (App (Lam ("x", Star, Var "x"), Unit), Unit) 125 | let eta = (Lam ("x", Star, App (Var "f", Var "x")), Var "f") 126 | let pair_beta = (Pr1 (Pair (Unit, Unit)), Unit) 127 | 128 | let rec test_equal ctx t1 t2 = 129 | let t1' = normalize ctx t1 in 130 | let t2' = normalize ctx t2 in 131 | equal ctx t1' t2' 132 | 133 | let run_type_test name term expected_type = 134 | let ctx = [] in 135 | try 136 | let inferred = infer ctx term in 137 | let norm_inferred = normalize ctx inferred in 138 | let norm_expected = normalize ctx expected_type in 139 | Printf.printf "Test %s:\n- Term: %s\n- Inferred: %s\n- Expected: %s\n- Result: %s\n\n" 140 | name 141 | (string_of_term term) 142 | (string_of_term norm_inferred) 143 | (string_of_term norm_expected) 144 | (if test_equal [] norm_inferred norm_expected then "PASS" else "FAIL") 145 | with 146 | | Failure msg -> Printf.printf "Test %s: Failed with error: %s\n\n" name msg 147 | 148 | let run_equality_test ctx name (t1, t2) = 149 | let result = test_equal ctx t1 t2 in 150 | Printf.printf "Equality Test %s:\n- Term1: %s\n- Term2: %s\n- Result: %s\n\n" 151 | name 152 | (string_of_term t1) 153 | (string_of_term t2) 154 | (if result then "PASS" else "FAIL") 155 | 156 | let () = 157 | let ctx = [("f", Arrow (Star, Star)); ("u", Star)] in 158 | run_type_test "Identity" id id_type; 159 | run_type_test "Unit" Unit unit_type; 160 | run_type_test "Pair" pair_test pair_type; 161 | run_type_test "First Projection" pr1_test Star; 162 | run_type_test "Second Projection" pr2_test Star; 163 | run_equality_test ctx "Beta Reduction" beta; 164 | run_equality_test ctx "Eta Equivalence" eta; 165 | run_equality_test [] "Pair Beta" pair_beta; 166 | -------------------------------------------------------------------------------- /index.pug: -------------------------------------------------------------------------------- 1 | include header 2 | 3 | html 4 | head 5 | meta(property='og:title' content='ALONZO') 6 | meta(property='og:description' content='Внутрішня мова декартово замкнених категорій') 7 | meta(property='og:url' content='https://alonzo.groupoid.space/') 8 | 9 | block title 10 | title ALONZO 11 | 12 | block content 13 | +header('', 'Alonzo', 'Мінімальна мова для функціональних обчислень у декартово-замкнених категоріях') 14 | article.main 15 | .exe 16 | section 17 | h1 Анотація 18 | aside Намдак Тонпа 19 | time ДАТА: 2 ЧЕРВНЯ 2025 20 | section 21 | +tex. 22 | Мова програмування $\mathbf{Alonzo}$ — це внутрішня мова декартово-замкнених категорій, 23 | що реалізує функціональні обчислення через лямбда-абстракцію, аплікацію, стрілкові типи, 24 | одиничний тип та добутки. Вона забезпечує строгу типізацію та відповідає структурі CCC. 25 | 26 | .semantics 27 | section 28 | h2#ast Синтаксис 29 | +tex. 30 | Терми $\mathbf{Alonzo}$ складаються зі змінних, зірки (тип типів), стрілкових типів, 31 | лямбда-абстракцій, аплікацій, одиничного типу, добутків, пар та їх проекцій. 32 | Мова підтримує строгі типи, забезпечуючи типобезпеку. 33 | code. 34 | I = #identifier 35 | STLC = I | Star | Arrow (STLC, STLC) | Lam (I, STLC, STLC) 36 | | App (STLC, STLC) | Unit | Prod (STLC, STLC) 37 | | Pair (STLC, STLC) | Pr1 STLC | Pr2 STLC 38 | br. 39 | code('OCaml'). 40 | type term = 41 | | Var of string 42 | | Star 43 | | Arrow of term * term 44 | | Lam of string * term * term 45 | | App of term * term 46 | | Unit 47 | | Prod of term * term 48 | | Pair of term * term 49 | | Pr1 of term 50 | | Pr2 of term 51 | br. 52 | 53 | h2#rules Правила обчислень 54 | +tex. 55 | Обчислення в $\mathbf{Alonzo}$ базуються на бета-редукції для аплікацій 56 | та редукції для проекцій пар, з підтримкою eta-рівності. 57 | code. 58 | App (Lam (x, A, t), u) → subst x u t (* β-редукція *) 59 | Pr1 (Pair (t,unofficial, u)) → t (* π1-редукція *) 60 | Pr2 (Pair (t, u)) → u (* π2-редукція *) 61 | Lam (x, A, App (t, Var x)) → t (* η-рівність *) 62 | br. 63 | +tex(true). 64 | $$ 65 | \begin{equation} 66 | \tag{β-reduction} 67 | \dfrac 68 | {(\lambda x : A . t) \, u} 69 | {t[x \mapsto u]} 70 | \end{equation} 71 | $$ 72 | +tex(true). 73 | $$ 74 | \begin{equation} 75 | \tag{π1-reduction} 76 | \dfrac 77 | {\pi_1 \langle t, u \rangle} 78 | {t} 79 | \end{equation} 80 | $$ 81 | +tex(true). 82 | $$ 83 | \begin{equation} 84 | \tag{π2-reduction} 85 | \dfrac 86 | {\pi_2 \langle t, u \rangle} 87 | {u} 88 | \end{equation} 89 | $$ 90 | 91 | h2#typing Правила типізації 92 | +tex. 93 | Типізація в $\mathbf{Alonzo}$ забезпечує, що кожен терм має коректний тип. 94 | Основні правила включають: 95 | code. 96 | (* Контекст: Γ = список пар (x : A) *) 97 | Var x : A (* якщо (x : A) ∈ Γ *) 98 | Star : Star (* тип типів *) 99 | Arrow (A, B) : Star (* якщо A : Star, B : Star *) 100 | Lam (x, A, t) : Arrow (A, B) (* якщо Γ ⊢ A : Star, Γ, x : A ⊢ t : B *) 101 | App (t, u) : B (* якщо t : Arrow (A, B), u : A *) 102 | Unit : Star (* одиничний тип *) 103 | Prod (A, B) : Star (* якщо A : Star, B : Star *) 104 | Pair (t, u) : Prod (A, B) (* якщо t : A, u : B *) 105 | Pr1 t : A (* якщо t : Prod (A, B) *) 106 | Pr2 t : B (* якщо t : Prod (A, B) *) 107 | br. 108 | 109 | h2 Підстановка 110 | +tex. 111 | Підстановка в $\mathbf{Alonzo}$ замінює змінну на терм, зберігаючи типобезпеку. 112 | code('OCaml'). 113 | let rec subst x s = function 114 | | Var y -> if x = y then s else Var y 115 | | Arrow (a, b) -> Arrow (subst x s a, subst x s b) 116 | | Lam (y, a, b) when x <> y -> Lam (y, subst x s a, subst x s b) 117 | | App (f, a) -> App (subst x s f, subst x s a) 118 | | Prod (a, b) -> Prod (subst x s a, subst x s b) 119 | | Pair (t1, t2) -> Pair (subst x s t1, subst x s t2) 120 | | Pr1 t -> Pr1 (subst x s t) 121 | | Pr2 t -> Pr2 (subst x s t) 122 | | t -> t 123 | br. 124 | 125 | h2 Редукція 126 | +tex. 127 | Редукція виконує бета-редукцію та редукцію проекцій для активних пар. 128 | code('OCaml'). 129 | let rec reduce ctx t = match t with 130 | | App (Lam (x, _, b), a) -> subst x a b 131 | | App (f, a) -> App (reduce ctx f, reduce ctx a) 132 | | Pr1 (Pair (t1, _)) -> t1 133 | | Pr2 (Pair (_, t2)) -> t2 134 | | Pr1 t -> Pr1 (reduce ctx t) 135 | | Pr2 t -> Pr2 (reduce ctx t) 136 | | _ -> t 137 | br. 138 | 139 | h2 Нормалізація 140 | +tex. 141 | Нормалізація повторює редукцію до досягнення нормальної форми. 142 | code('OCaml'). 143 | let rec normalize ctx t = 144 | let t' = reduce ctx t in 145 | if equal ctx t t' then t else normalize ctx t' 146 | br. 147 | 148 | h2 Внутрішня мова CCC 149 | +tex. 150 | Доведення, що $\mathbf{Alonzo}$ є внутрішньою мовою декартово-замкнених категорій: 151 | +tex(true). 152 | $$ 153 | \begin{cases} 154 | \mathrm{Var} : A, \\ 155 | \mathrm{Star} : \mathrm{Type}, \\ 156 | \mathrm{Arrow} : A \to B \to \mathrm{Type}, \\ 157 | \mathrm{Lam} : (A \to B) \to (A \implies B), \\ 158 | \mathrm{App} : (A \implies B) \to A \to B, \\ 159 | \mathrm{Unit} : \mathbf{1}, \\ 160 | \mathrm{Prod} : A \to B \to \mathrm{Type}, \\ 161 | \mathrm{Pair} : A \to B \to A \times B, \\ 162 | \mathrm{Pr1} : A \times B \to A, \\ 163 | \mathrm{Pr2} : A \times B \to B. 164 | \end{cases} 165 | $$ 166 | +tex. 167 | Ці конструктори відповідають аксіомам CCC: 168 | +tex. 169 | $\mathrm{Star}$ позначає об'єкти категорії (типи), 170 | $\mathrm{Arrow}$ моделює експоненціальний об'єкт $B^A$, 171 | $\mathrm{Lam}$ відповідає морфізму $\lambda: (A \to B) \to (A \implies B)$, 172 | $\mathrm{App}$ реалізує оцінку $ev: (A \implies B) \times A \to B$, 173 | $\mathrm{Unit}$ є термінальним об'єктом $\mathbf{1}$, для якого $A \to \mathbf{1}$ є унікальним, 174 | $\mathrm{Prod}$ моделює декартовий добуток $A \times B$, 175 | $\mathrm{Pair}$ створює пару $\langle t, u \rangle: A \to B \to A \times B$, 176 | $\mathrm{Pr1}$ і $\mathrm{Pr2}$ є проекціями $\pi_1: A \times B \to A$ та $\pi_2: A \times B \to B$, 177 | $\mathrm{Var}$ позначає об'єкти категорії. 178 | +tex. 179 | Лямбда-абстракція та аплікація відповідають структурі CCC: 180 | +tex(true). 181 | $$ 182 | \begin{cases} 183 | \lambda x.t \vdash \mathrm{Lam}(x, A, t): A \implies B, \\ 184 | t \, u \mapsto \mathrm{App}(t, u): B. 185 | \end{cases} 186 | $$ 187 | 188 | section 189 | h1 Бібліографія 190 | p(style="font-size:16px;"). 191 | [1]. Church, A. A Formulation of the Simple Theory of Types. 1940
192 | [2]. Guallart, N. An Overview of Type Theories. 2014
193 | [3]. García, M. Category Theory and Lambda Calculus. 2020
194 | 195 | include footer -------------------------------------------------------------------------------- /main.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'local'; 3 | src: url("https://groupoid.space/Geometria-Light.otf"); 4 | font-weight: normal; 5 | font-style: normal; } 6 | 7 | .MathJax_Display { 8 | overflow-x: auto; 9 | overflow-y: hidden; } 10 | 11 | nav a { 12 | font-size: 18px; 13 | border: 2px solid #dedede; 14 | background-color: white; 15 | color: lightblue; 16 | text-decoration: none; 17 | margin: 5px 5px; 18 | padding: 7px 12px; 19 | min-width: 150px; 20 | text-align: center; } 21 | 22 | nav a:visited { 23 | color: lightblue; } 24 | 25 | nav a:hover { 26 | border-bottom: 2px solid #00b8cf; } 27 | 28 | nav { 29 | display: flex; 30 | background-color: #FBFBFB; 31 | flex-direction: row; 32 | justify-content: center; } 33 | 34 | nav a { 35 | font-size: 18px; 36 | min-width: initial; } 37 | 38 | * { 39 | margin: 0; 40 | padding: 0; 41 | box-sizing: border-box; } 42 | 43 | sub, 44 | sup { 45 | font-size: 80%; 46 | line-height: 0; 47 | position: relative; 48 | vertical-align: baseline; } 49 | 50 | sub { 51 | bottom: -0.25em; } 52 | 53 | sup { 54 | top: -0.5em; } 55 | 56 | html { 57 | height: 100%; } 58 | 59 | body { 60 | min-height: 100%; 61 | text-rendering: optimizeLegibility; 62 | -webkit-font-smoothing: antialiased; } 63 | 64 | h1, h2, h3, h4 { 65 | font-weight: normal; } 66 | 67 | ul { 68 | list-style-type: none; } 69 | 70 | ol, 71 | ul { 72 | text-align: left; 73 | line-height: 1.5; } 74 | 75 | img, figure { 76 | vertical-align: middle; } 77 | 78 | img { 79 | margin-left: 20px; } 80 | 81 | .content { 82 | min-height: 100%; 83 | font-family: local; 84 | display: flex; 85 | flex-direction: column; 86 | position: relative; } 87 | 88 | .main { 89 | color: #586E75; 90 | background: #FBFBFB; 91 | padding: 50px 0px; 92 | text-align: center; 93 | box-shadow: 0 3px 10px rgba(0, 0, 0, 0); 94 | z-index: 5; 95 | flex: 1 1 auto; } 96 | 97 | figure { 98 | min-width: 300px; 99 | overflow-x: auto; 100 | padding: 10px 2px; 101 | font-size: 18px; 102 | display: block; } 103 | 104 | figure::after { 105 | content: "\A"; 106 | white-space: pre; } 107 | 108 | h2 { 109 | font-size: 24px; 110 | color: #268BD2; 111 | margin: 34px 0 8px; } 112 | @media (min-width: 768px) { 113 | h2 { 114 | font-size: 32px; } } 115 | 116 | h3 { 117 | max-width: 100%; 118 | margin: 16px auto 0; 119 | padding: 0 0 0 8px; 120 | text-transform: uppercase; 121 | text-align: left; 122 | font-size: 22px; } 123 | 124 | p { 125 | max-width: 100%; 126 | width: 650px; 127 | margin: auto; 128 | padding: 8px; 129 | text-align: left; 130 | font-size: 18px; 131 | line-height: 1.4; } 132 | @media (min-width: 768px) { 133 | p { 134 | font-size: 22px; } } 135 | 136 | p:hover { 137 | background: white; } 138 | 139 | mark { 140 | background: #FDF6E3; 141 | padding: 0px 2px; 142 | border-radius: 2px; 143 | color: #586E75; } 144 | 145 | a { 146 | color: #3A98C8; 147 | text-decoration: none; } 148 | a:visited { 149 | color: #3A98C8; } 150 | a:hover { 151 | color: #D33682; } 152 | a:active { 153 | color: #D33682; } 154 | 155 | aside { 156 | max-width: 650px; 157 | margin: auto; 158 | padding: 8px; 159 | font-size: 20px; 160 | text-align: right; } 161 | aside time, aside div { 162 | margin-bottom: 20px; 163 | display: block; } 164 | 165 | .header { 166 | background: black; 167 | color: white; 168 | position: relative; 169 | min-height: 450px; 170 | padding: 16px 8px; 171 | display: flex; 172 | text-align: center; 173 | flex-direction: column; 174 | justify-content: center; 175 | align-items: center; 176 | width: 100%; 177 | z-index: 5; } 178 | .header__logo { 179 | width: 130px; 180 | position: relative; } 181 | .header__titles { 182 | position: relative; 183 | max-width: 800px; 184 | margin: 20px; 185 | text-shadow: 1px 1px 7px #56CCF2; } 186 | .header__title { 187 | font-size: 48px; 188 | line-height: 1.1; } 189 | .header__subtitle { 190 | font-size: 22px; } 191 | @media (min-width: 768px) { 192 | .header { 193 | flex-direction: row; } 194 | .header__logo { 195 | width: 160px; 196 | margin-right: 10px; } 197 | .header__title { 198 | font-size: 60px; } 199 | .header__subtitle { 200 | font-size: 30px; } } 201 | 202 | .footer { 203 | width: 100%; 204 | padding: 15px; 205 | background: #7F8C8D; 206 | color: white; 207 | text-align: center; } 208 | .footer__logo { 209 | width: 50px; 210 | margin: 20px; } 211 | .footer__copy { 212 | font-size: 16px; 213 | white-space: pre; } 214 | @media (min-width: 768px) { 215 | .footer__copy { 216 | font-size: 24px; } } 217 | 218 | .semantics { 219 | text-align: center; } 220 | .semantics figure { 221 | display: inline-block; 222 | max-width: min-content; 223 | font-size: 13px; } 224 | @media (min-width: 800px) { 225 | .semantics figure { 226 | font-size: 16px; } } 227 | .semantics h1 { 228 | color: #7D8A96; 229 | font-size: 32px; 230 | text-transform: uppercase; 231 | border-bottom: 1px solid rgba(0, 0, 0, 0.3); 232 | display: inline-block; 233 | margin-bottom: 8px; } 234 | .semantics section { 235 | margin-top: 40px; } 236 | 237 | .intro { 238 | width: 650px; 239 | max-width: 100%; 240 | margin: auto; } 241 | 242 | .status { 243 | text-align: left; 244 | display: inline-block; 245 | padding-left: 32px; } 246 | .status ol { 247 | line-height: 1.5; 248 | font-size: 18px; } 249 | @media (min-width: 768px) { 250 | .status ol { 251 | font-size: 22px; } } 252 | 253 | .resources { 254 | max-width: 650px; 255 | margin: 32px auto 0; 256 | text-align: left; 257 | padding: 8px; } 258 | .resources__title { 259 | display: inline-block; 260 | margin-bottom: 10px; 261 | color: #7D8A96; 262 | font-size: 32px; 263 | text-transform: uppercase; 264 | border-bottom: 1px solid rgba(0, 0, 0, 0.3); } 265 | @media (min-width: 768px) { 266 | .resources__title { 267 | font-size: 40px; } } 268 | .resources__list { 269 | padding-left: 32px; 270 | line-height: 1.5; 271 | font-size: 18px; } 272 | @media (min-width: 768px) { 273 | .resources__list { 274 | font-size: 22px; } } 275 | 276 | .index { 277 | max-width: 900px; 278 | margin: auto; 279 | padding: 20px 0; 280 | display: flex; 281 | flex-wrap: wrap; 282 | justify-content: center; } 283 | .index__col { 284 | white-space: nowrap; 285 | padding: 15px 25px; 286 | margin: 15px; 287 | background: #fefefe; 288 | box-shadow: 0 1px 4px rgba(0, 0, 100, 0.1), inset 0 0 0 1px rgba(0, 0, 0, 0.1); 289 | transition: box-shadow 0.5s cubic-bezier(0.23, 1, 0.32, 1); } 290 | .index__col:hover { 291 | box-shadow: 0 8px 40px rgba(0, 0, 100, 0.15), inset 0 0 0 1px rgba(0, 0, 0, 0.1); } 292 | .index a { 293 | line-height: 1.5; 294 | color: #888; 295 | font-size: 24px; } 296 | .index a[href^="#"] { 297 | color: #BBBBBB; } 298 | .index a:hover { 299 | color: #3A98C8; } 300 | .index a[href^="#"]:hover { 301 | color: #BBBBBB; } 302 | .index h2 { 303 | font-size: 24px; 304 | text-align: left; 305 | color: #707070; 306 | margin: 0 0 10px; 307 | text-transform: uppercase; } 308 | 309 | .om figure { 310 | max-width: inherit; } 311 | 312 | .om section h1 { 313 | margin-top: 50px; } 314 | 315 | .om h1 { 316 | color: #7D8A96; 317 | font-size: 32px; 318 | text-transform: uppercase; 319 | border-bottom: 1px solid rgba(0, 0, 0, 0.3); 320 | display: inline-block; 321 | margin-bottom: 32px; } 322 | @media (min-width: 768px) { 323 | .om h1 { 324 | font-size: 40px; } } 325 | 326 | .om h1 + h2 { 327 | margin-top: 20px; } 328 | 329 | .om h3 { 330 | max-width: 100%; 331 | margin: auto; 332 | width: 600px; 333 | padding: 16px 8px 0; } 334 | 335 | .exe figure { 336 | max-width: inherit; } 337 | 338 | .exe h1 { 339 | color: #7D8A96; 340 | font-size: 32px; 341 | text-transform: uppercase; 342 | border-bottom: 1px solid rgba(0, 0, 0, 0.3); 343 | display: inline-block; 344 | margin: 42px 0 10px; } 345 | @media (min-width: 768px) { 346 | .exe h1 { 347 | font-size: 40px; } } 348 | 349 | .exe h1 + h2 { 350 | margin-top: 0px; } 351 | 352 | .macro { 353 | margin: 0 auto; 354 | display: flex; 355 | justify-content: space-around; 356 | max-width: 600px; 357 | flex-wrap: wrap; 358 | width: 100%; } 359 | .macro__col { 360 | padding-left: 24px; 361 | line-height: 1.5; 362 | font-size: 14px; } 363 | .macro__col h3 { 364 | padding: 0; 365 | width: initial; } 366 | @media (min-width: 768px) { 367 | .macro__col { 368 | font-size: 22px; } } 369 | 370 | @media (min-width: 920px) { 371 | .langf { 372 | display: flex; 373 | flex-direction: row; 374 | justify-content: center; } } 375 | 376 | .langf ol { 377 | display: inline-block; 378 | max-width: 650px; 379 | margin: auto; 380 | font-size: 20px; 381 | padding-left: 36px; } 382 | 383 | @media (min-width: 920px) { 384 | .langf__col .langf-col:last-child { 385 | white-space: pre; 386 | margin-left: 20px; } } 387 | 388 | .types { 389 | display: inline-block; 390 | text-align: left; 391 | max-width: 100%; 392 | padding: 0 8px; } 393 | .types h1 { 394 | color: #7D8A96; 395 | font-size: 32px; 396 | text-transform: uppercase; 397 | border-bottom: 1px solid rgba(0, 0, 0, 0.3); 398 | display: inline-block; 399 | margin: 42px 0 10px; } 400 | @media (min-width: 768px) { 401 | .types h1 { 402 | font-size: 40px; } } 403 | .types section { 404 | max-width: 100%; } 405 | .types p { 406 | margin: 0; 407 | padding-left: 0; } 408 | .types h1 + h2 { 409 | margin-top: 0px; } 410 | .types .type { 411 | max-width: 660px; 412 | display: flex; 413 | flex-flow: row wrap; } 414 | .types .type__col { 415 | padding-left: 22px; 416 | flex: 1 0 15%; } 417 | .types .type__col h3 { 418 | width: initial; 419 | padding: 0; 420 | margin: 0; } 421 | @media (min-width: 600px) { 422 | .types .type__col { 423 | padding-right: 22px; 424 | flex: 1 0 15%; 425 | font-size: 20px; } } 426 | .types .legend { 427 | margin: 20px auto 0; 428 | display: inline-block; 429 | padding: 10px 20px; 430 | font-size: 24px; 431 | background: #FDF6E3; 432 | border-radius: 4px; 433 | box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08); } 434 | 435 | .list h1 { 436 | color: #7D8A96; 437 | font-size: 32px; 438 | text-transform: uppercase; 439 | border-bottom: 1px solid rgba(0, 0, 0, 0.3); 440 | display: inline-block; 441 | margin: 42px 8px 10px; } 442 | @media (min-width: 768px) { 443 | .list h1 { 444 | font-size: 40px; } } 445 | 446 | code { 447 | display: inline-block; 448 | overflow-x: auto; 449 | max-width: 100%; 450 | padding: 12px; 451 | margin: 8px 0; 452 | white-space: pre; 453 | text-align: left; 454 | border-radius: 4px; 455 | font-size: 14px; 456 | color: #00259c; 457 | background: white; 458 | box-shadow: 0 1px 4px #f1f0f0, inset 0 0 0 1px #e7e6e5; } 459 | @media (min-width: 768px) { 460 | code { 461 | font-size: 17px; } } 462 | 463 | pre { 464 | white-space: normal; 465 | max-width: 100%; 466 | width: 650px; 467 | padding: 12px; 468 | margin: 8px auto; 469 | text-align: left; 470 | border-radius: 4px; 471 | font-size: 14px; 472 | color: #00259c; 473 | background: white; 474 | box-shadow: 0 1px 4px #f1f0f0, inset 0 0 0 1px #e7e6e5; } 475 | @media (min-width: 768px) { 476 | pre { 477 | font-size: 17px; } } 478 | 479 | .h__name { 480 | color: #00259c; 481 | font-weight: bold; } 482 | 483 | .h__keyword { 484 | color: #ca30d4; } 485 | 486 | .h__symbol { 487 | color: #9f9fa3; } 488 | 489 | canvas { 490 | max-width: 100%; 491 | position: absolute; 492 | z-index: -10; } 493 | 494 | .stack { 495 | margin: auto; 496 | max-width: 100%; 497 | border-spacing: 10px; 498 | color: #282828; 499 | font-size: 20px; } 500 | .stack td { 501 | background-color: #fff9a6; 502 | padding: 4px; 503 | outline: 1px solid rgba(0, 0, 0, 0.3); } 504 | .stack th { 505 | padding: 4px; 506 | text-align: left; 507 | font-weight: normal; } 508 | .stack .empty { 509 | background-color: inherit; 510 | outline: inherit; } 511 | 512 | @media (max-width: 600px) { 513 | .stack { 514 | font-size: 16px; 515 | display: inline-block; 516 | border-spacing: 0; } 517 | .stack tbody { 518 | display: block; } 519 | .stack tr { 520 | display: block; 521 | text-align: left; 522 | vertical-align: top; 523 | position: relative; } 524 | .stack td { 525 | margin: 30px 0 10px; 526 | text-align: center; 527 | padding: 4px; 528 | display: inline-block; 529 | width: 90px; } 530 | .stack td[colspan="4"] { 531 | width: 360px; } 532 | .stack td[colspan="2"] { 533 | width: 180px; } 534 | .stack th { 535 | position: absolute; 536 | top: 0; 537 | width: 100%; } } 538 | 539 | @media (max-width: 320px) { 540 | .stack { 541 | font-size: 12px; } 542 | .stack td { 543 | margin: 20px 0 5px; 544 | width: 80px; } 545 | .stack td[colspan="4"] { 546 | width: 320px; } 547 | .stack td[colspan="2"] { 548 | width: 160px; } } 549 | -------------------------------------------------------------------------------- /bundle.js: -------------------------------------------------------------------------------- 1 | !function e(t,n,r){function a(o,f){if(!n[o]){if(!t[o]){var u="function"==typeof require&&require;if(!f&&u)return u(o,!0);if(i)return i(o,!0);var s=new Error("Cannot find module '"+o+"'");throw s.code="MODULE_NOT_FOUND",s}var c=n[o]={exports:{}};t[o][0].call(c.exports,function(e){var n=t[o][1][e];return a(n?n:e)},c,c.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o0&&void 0!==arguments[0]?arguments[0]:{},a=Object.assign({onDone:function(r){if("function"==typeof n.onDone&&n.onDone.apply(e,t),r){var a=document.createElement("div");document.body.appendChild(a),a.className="error";var i=document.createElement("div");i.innerText=r,a.appendChild(i)}}},n);return"function"==typeof headlessRegl?a=headlessRegl(a):window.frameDone=function(){},r(a)}},{31:31}],5:[function(e,t,n){function r(e,t){var n=t[0],r=t[1],a=t[2],i=t[3],o=t[4],f=t[5],u=t[6],s=t[7],c=t[8],l=t[9],m=t[10],d=t[11],p=t[12],h=t[13],v=t[14],b=t[15];return e[0]=f*(m*b-d*v)-l*(u*b-s*v)+h*(u*d-s*m),e[1]=-(r*(m*b-d*v)-l*(a*b-i*v)+h*(a*d-i*m)),e[2]=r*(u*b-s*v)-f*(a*b-i*v)+h*(a*s-i*u),e[3]=-(r*(u*d-s*m)-f*(a*d-i*m)+l*(a*s-i*u)),e[4]=-(o*(m*b-d*v)-c*(u*b-s*v)+p*(u*d-s*m)),e[5]=n*(m*b-d*v)-c*(a*b-i*v)+p*(a*d-i*m),e[6]=-(n*(u*b-s*v)-o*(a*b-i*v)+p*(a*s-i*u)),e[7]=n*(u*d-s*m)-o*(a*d-i*m)+c*(a*s-i*u),e[8]=o*(l*b-d*h)-c*(f*b-s*h)+p*(f*d-s*l),e[9]=-(n*(l*b-d*h)-c*(r*b-i*h)+p*(r*d-i*l)),e[10]=n*(f*b-s*h)-o*(r*b-i*h)+p*(r*s-i*f),e[11]=-(n*(f*d-s*l)-o*(r*d-i*l)+c*(r*s-i*f)),e[12]=-(o*(l*v-m*h)-c*(f*v-u*h)+p*(f*m-u*l)),e[13]=n*(l*v-m*h)-c*(r*v-a*h)+p*(r*m-a*l),e[14]=-(n*(f*v-u*h)-o*(r*v-a*h)+p*(r*u-a*f)),e[15]=n*(f*m-u*l)-o*(r*m-a*l)+c*(r*u-a*f),e}t.exports=r},{}],6:[function(e,t,n){function r(e){var t=new Float32Array(16);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}t.exports=r},{}],7:[function(e,t,n){function r(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}t.exports=r},{}],8:[function(e,t,n){function r(){var e=new Float32Array(16);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}t.exports=r},{}],9:[function(e,t,n){function r(e){var t=e[0],n=e[1],r=e[2],a=e[3],i=e[4],o=e[5],f=e[6],u=e[7],s=e[8],c=e[9],l=e[10],m=e[11],d=e[12],p=e[13],h=e[14],v=e[15],b=t*o-n*i,g=t*f-r*i,y=t*u-a*i,x=n*f-r*o,w=n*u-a*o,k=r*u-a*f,S=s*p-c*d,_=s*h-l*d,A=s*v-m*d,E=c*h-l*p,D=c*v-m*p,T=l*v-m*h;return b*T-g*D+y*E+x*A-w*_+k*S}t.exports=r},{}],10:[function(e,t,n){function r(e,t){var n=t[0],r=t[1],a=t[2],i=t[3],o=n+n,f=r+r,u=a+a,s=n*o,c=r*o,l=r*f,m=a*o,d=a*f,p=a*u,h=i*o,v=i*f,b=i*u;return e[0]=1-l-p,e[1]=c+b,e[2]=m-v,e[3]=0,e[4]=c-b,e[5]=1-s-p,e[6]=d+h,e[7]=0,e[8]=m+v,e[9]=d-h,e[10]=1-s-l,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}t.exports=r},{}],11:[function(e,t,n){function r(e,t,n){var r=t[0],a=t[1],i=t[2],o=t[3],f=r+r,u=a+a,s=i+i,c=r*f,l=r*u,m=r*s,d=a*u,p=a*s,h=i*s,v=o*f,b=o*u,g=o*s;return e[0]=1-(d+h),e[1]=l+g,e[2]=m-b,e[3]=0,e[4]=l-g,e[5]=1-(c+h),e[6]=p+v,e[7]=0,e[8]=m+b,e[9]=p-v,e[10]=1-(c+d),e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}t.exports=r},{}],12:[function(e,t,n){function r(e,t,n,r,a,i,o){var f=1/(n-t),u=1/(a-r),s=1/(i-o);return e[0]=2*i*f,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=2*i*u,e[6]=0,e[7]=0,e[8]=(n+t)*f,e[9]=(a+r)*u,e[10]=(o+i)*s,e[11]=-1,e[12]=0,e[13]=0,e[14]=o*i*2*s,e[15]=0,e}t.exports=r},{}],13:[function(e,t,n){function r(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}t.exports=r},{}],14:[function(e,t,n){t.exports={create:e(8),clone:e(6),copy:e(7),identity:e(13),transpose:e(28),invert:e(15),adjoint:e(5),determinant:e(9),multiply:e(17),translate:e(27),scale:e(25),rotate:e(21),rotateX:e(22),rotateY:e(23),rotateZ:e(24),fromRotationTranslation:e(11),fromQuat:e(10),frustum:e(12),perspective:e(19),perspectiveFromFieldOfView:e(20),ortho:e(18),lookAt:e(16),str:e(26)}},{10:10,11:11,12:12,13:13,15:15,16:16,17:17,18:18,19:19,20:20,21:21,22:22,23:23,24:24,25:25,26:26,27:27,28:28,5:5,6:6,7:7,8:8,9:9}],15:[function(e,t,n){function r(e,t){var n=t[0],r=t[1],a=t[2],i=t[3],o=t[4],f=t[5],u=t[6],s=t[7],c=t[8],l=t[9],m=t[10],d=t[11],p=t[12],h=t[13],v=t[14],b=t[15],g=n*f-r*o,y=n*u-a*o,x=n*s-i*o,w=r*u-a*f,k=r*s-i*f,S=a*s-i*u,_=c*h-l*p,A=c*v-m*p,E=c*b-d*p,D=l*v-m*h,T=l*b-d*h,j=m*b-d*v,C=g*j-y*T+x*D+w*E-k*A+S*_;return C?(C=1/C,e[0]=(f*j-u*T+s*D)*C,e[1]=(a*T-r*j-i*D)*C,e[2]=(h*S-v*k+b*w)*C,e[3]=(m*k-l*S-d*w)*C,e[4]=(u*E-o*j-s*A)*C,e[5]=(n*j-a*E+i*A)*C,e[6]=(v*x-p*S-b*y)*C,e[7]=(c*S-m*x+d*y)*C,e[8]=(o*T-f*E+s*_)*C,e[9]=(r*E-n*T-i*_)*C,e[10]=(p*k-h*x+b*g)*C,e[11]=(l*x-c*k-d*g)*C,e[12]=(f*A-o*D-u*_)*C,e[13]=(n*D-r*A+a*_)*C,e[14]=(h*y-p*w-v*g)*C,e[15]=(c*w-l*y+m*g)*C,e):null}t.exports=r},{}],16:[function(e,t,n){function r(e,t,n,r){var i,o,f,u,s,c,l,m,d,p,h=t[0],v=t[1],b=t[2],g=r[0],y=r[1],x=r[2],w=n[0],k=n[1],S=n[2];return Math.abs(h-w)<1e-6&&Math.abs(v-k)<1e-6&&Math.abs(b-S)<1e-6?a(e):(l=h-w,m=v-k,d=b-S,p=1/Math.sqrt(l*l+m*m+d*d),l*=p,m*=p,d*=p,i=y*d-x*m,o=x*l-g*d,f=g*m-y*l,p=Math.sqrt(i*i+o*o+f*f),p?(p=1/p,i*=p,o*=p,f*=p):(i=0,o=0,f=0),u=m*f-d*o,s=d*i-l*f,c=l*o-m*i,p=Math.sqrt(u*u+s*s+c*c),p?(p=1/p,u*=p,s*=p,c*=p):(u=0,s=0,c=0),e[0]=i,e[1]=u,e[2]=l,e[3]=0,e[4]=o,e[5]=s,e[6]=m,e[7]=0,e[8]=f,e[9]=c,e[10]=d,e[11]=0,e[12]=-(i*h+o*v+f*b),e[13]=-(u*h+s*v+c*b),e[14]=-(l*h+m*v+d*b),e[15]=1,e)}var a=e(13);t.exports=r},{13:13}],17:[function(e,t,n){function r(e,t,n){var r=t[0],a=t[1],i=t[2],o=t[3],f=t[4],u=t[5],s=t[6],c=t[7],l=t[8],m=t[9],d=t[10],p=t[11],h=t[12],v=t[13],b=t[14],g=t[15],y=n[0],x=n[1],w=n[2],k=n[3];return e[0]=y*r+x*f+w*l+k*h,e[1]=y*a+x*u+w*m+k*v,e[2]=y*i+x*s+w*d+k*b,e[3]=y*o+x*c+w*p+k*g,y=n[4],x=n[5],w=n[6],k=n[7],e[4]=y*r+x*f+w*l+k*h,e[5]=y*a+x*u+w*m+k*v,e[6]=y*i+x*s+w*d+k*b,e[7]=y*o+x*c+w*p+k*g,y=n[8],x=n[9],w=n[10],k=n[11],e[8]=y*r+x*f+w*l+k*h,e[9]=y*a+x*u+w*m+k*v,e[10]=y*i+x*s+w*d+k*b,e[11]=y*o+x*c+w*p+k*g,y=n[12],x=n[13],w=n[14],k=n[15],e[12]=y*r+x*f+w*l+k*h,e[13]=y*a+x*u+w*m+k*v,e[14]=y*i+x*s+w*d+k*b,e[15]=y*o+x*c+w*p+k*g,e}t.exports=r},{}],18:[function(e,t,n){function r(e,t,n,r,a,i,o){var f=1/(t-n),u=1/(r-a),s=1/(i-o);return e[0]=-2*f,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*u,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*s,e[11]=0,e[12]=(t+n)*f,e[13]=(a+r)*u,e[14]=(o+i)*s,e[15]=1,e}t.exports=r},{}],19:[function(e,t,n){function r(e,t,n,r,a){var i=1/Math.tan(t/2),o=1/(r-a);return e[0]=i/n,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=(a+r)*o,e[11]=-1,e[12]=0,e[13]=0,e[14]=2*a*r*o,e[15]=0,e}t.exports=r},{}],20:[function(e,t,n){function r(e,t,n,r){var a=Math.tan(t.upDegrees*Math.PI/180),i=Math.tan(t.downDegrees*Math.PI/180),o=Math.tan(t.leftDegrees*Math.PI/180),f=Math.tan(t.rightDegrees*Math.PI/180),u=2/(o+f),s=2/(a+i);return e[0]=u,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=s,e[6]=0,e[7]=0,e[8]=-((o-f)*u*.5),e[9]=(a-i)*s*.5,e[10]=r/(n-r),e[11]=-1,e[12]=0,e[13]=0,e[14]=r*n/(n-r),e[15]=0,e}t.exports=r},{}],21:[function(e,t,n){function r(e,t,n,r){var a,i,o,f,u,s,c,l,m,d,p,h,v,b,g,y,x,w,k,S,_,A,E,D,T=r[0],j=r[1],C=r[2],O=Math.sqrt(T*T+j*j+C*C);return Math.abs(O)<1e-6?null:(O=1/O,T*=O,j*=O,C*=O,a=Math.sin(n),i=Math.cos(n),o=1-i,f=t[0],u=t[1],s=t[2],c=t[3],l=t[4],m=t[5],d=t[6],p=t[7],h=t[8],v=t[9],b=t[10],g=t[11],y=T*T*o+i,x=j*T*o+C*a,w=C*T*o-j*a,k=T*j*o-C*a,S=j*j*o+i,_=C*j*o+T*a,A=T*C*o+j*a,E=j*C*o-T*a,D=C*C*o+i,e[0]=f*y+l*x+h*w,e[1]=u*y+m*x+v*w,e[2]=s*y+d*x+b*w,e[3]=c*y+p*x+g*w,e[4]=f*k+l*S+h*_,e[5]=u*k+m*S+v*_,e[6]=s*k+d*S+b*_,e[7]=c*k+p*S+g*_,e[8]=f*A+l*E+h*D,e[9]=u*A+m*E+v*D,e[10]=s*A+d*E+b*D,e[11]=c*A+p*E+g*D,t!==e&&(e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e)}t.exports=r},{}],22:[function(e,t,n){function r(e,t,n){var r=Math.sin(n),a=Math.cos(n),i=t[4],o=t[5],f=t[6],u=t[7],s=t[8],c=t[9],l=t[10],m=t[11];return t!==e&&(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[4]=i*a+s*r,e[5]=o*a+c*r,e[6]=f*a+l*r,e[7]=u*a+m*r,e[8]=s*a-i*r,e[9]=c*a-o*r,e[10]=l*a-f*r,e[11]=m*a-u*r,e}t.exports=r},{}],23:[function(e,t,n){function r(e,t,n){var r=Math.sin(n),a=Math.cos(n),i=t[0],o=t[1],f=t[2],u=t[3],s=t[8],c=t[9],l=t[10],m=t[11];return t!==e&&(e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=i*a-s*r,e[1]=o*a-c*r,e[2]=f*a-l*r,e[3]=u*a-m*r,e[8]=i*r+s*a,e[9]=o*r+c*a,e[10]=f*r+l*a,e[11]=u*r+m*a,e}t.exports=r},{}],24:[function(e,t,n){function r(e,t,n){var r=Math.sin(n),a=Math.cos(n),i=t[0],o=t[1],f=t[2],u=t[3],s=t[4],c=t[5],l=t[6],m=t[7];return t!==e&&(e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=i*a+s*r,e[1]=o*a+c*r,e[2]=f*a+l*r,e[3]=u*a+m*r,e[4]=s*a-i*r,e[5]=c*a-o*r,e[6]=l*a-f*r,e[7]=m*a-u*r,e}t.exports=r},{}],25:[function(e,t,n){function r(e,t,n){var r=n[0],a=n[1],i=n[2];return e[0]=t[0]*r,e[1]=t[1]*r,e[2]=t[2]*r,e[3]=t[3]*r,e[4]=t[4]*a,e[5]=t[5]*a,e[6]=t[6]*a,e[7]=t[7]*a,e[8]=t[8]*i,e[9]=t[9]*i,e[10]=t[10]*i,e[11]=t[11]*i,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}t.exports=r},{}],26:[function(e,t,n){function r(e){return"mat4("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+", "+e[4]+", "+e[5]+", "+e[6]+", "+e[7]+", "+e[8]+", "+e[9]+", "+e[10]+", "+e[11]+", "+e[12]+", "+e[13]+", "+e[14]+", "+e[15]+")"}t.exports=r},{}],27:[function(e,t,n){function r(e,t,n){var r,a,i,o,f,u,s,c,l,m,d,p,h=n[0],v=n[1],b=n[2];return t===e?(e[12]=t[0]*h+t[4]*v+t[8]*b+t[12],e[13]=t[1]*h+t[5]*v+t[9]*b+t[13],e[14]=t[2]*h+t[6]*v+t[10]*b+t[14],e[15]=t[3]*h+t[7]*v+t[11]*b+t[15]):(r=t[0],a=t[1],i=t[2],o=t[3],f=t[4],u=t[5],s=t[6],c=t[7],l=t[8],m=t[9],d=t[10],p=t[11],e[0]=r,e[1]=a,e[2]=i,e[3]=o,e[4]=f,e[5]=u,e[6]=s,e[7]=c,e[8]=l,e[9]=m,e[10]=d,e[11]=p,e[12]=r*h+f*v+l*b+t[12],e[13]=a*h+u*v+m*b+t[13],e[14]=i*h+s*v+d*b+t[14],e[15]=o*h+c*v+p*b+t[15]),e}t.exports=r},{}],28:[function(e,t,n){function r(e,t){if(e===t){var n=t[1],r=t[2],a=t[3],i=t[6],o=t[7],f=t[11];e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=n,e[6]=t[9],e[7]=t[13],e[8]=r,e[9]=i,e[11]=t[14],e[12]=a,e[13]=o,e[14]=f}else e[0]=t[0],e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=t[1],e[5]=t[5],e[6]=t[9],e[7]=t[13],e[8]=t[2],e[9]=t[6],e[10]=t[10],e[11]=t[14],e[12]=t[3],e[13]=t[7],e[14]=t[11],e[15]=t[15];return e}t.exports=r},{}],29:[function(e,t,n){t.exports=function(e){"string"==typeof e&&(e=[e]);for(var t=[].slice.call(arguments,1),n=[],r=0;r=0&&(0|e)===e||t("invalid parameter type, ("+e+")"+r(n)+". must be a nonnegative integer")}function u(e,n,a){n.indexOf(e)<0&&t("invalid value"+r(a)+". must be one of: "+n)}function s(e){Object.keys(e).forEach(function(e){et.indexOf(e)<0&&t('invalid regl constructor argument "'+e+'". must be one of '+et)})}function c(e,t){for(e+="";e.length0&&t.push(new d("unknown",0,e))}}),t}function g(e,t){t.forEach(function(t){var n=e[t.file];if(n){var r=n.index[t.line];if(r)return r.errors.push(t),void(n.hasErrors=!0)}e.unknown.hasErrors=!0,e.unknown.lines[0].errors.push(t)})}function y(e,t,r,a,i){if(!e.getShaderParameter(t,e.COMPILE_STATUS)){var o=e.getShaderInfoLog(t),f=a===e.FRAGMENT_SHADER?"fragment":"vertex";E(r,"string",f+" shader source must be a string",i);var u=v(r,i),s=b(o);g(u,s),Object.keys(u).forEach(function(e){function t(e,t){r.push(e),a.push(t||"")}var n=u[e];if(n.hasErrors){var r=[""],a=[""];t("file number "+e+": "+n.name+"\n","color:red;text-decoration:underline;font-weight:bold"),n.lines.forEach(function(e){if(e.errors.length>0){t(c(e.number,4)+"| ","background-color:yellow; font-weight:bold"),t(e.line+"\n","color:red; background-color:yellow; font-weight:bold");var n=0;e.errors.forEach(function(r){var a=r.message,i=/^\s*\'(.*)\'\s*\:\s*(.*)$/.exec(a);if(i){var o=i[1];switch(a=i[2],o){case"assign":o="="}n=Math.max(e.line.indexOf(o,n),0)}else n=0;t(c("| ",6)),t(c("^^^",n+3)+"\n","font-weight:bold"),t(c("| ",6)),t(a+"\n","font-weight:bold")}),t(c("| ",6)+"\n")}else t(c(e.number,4)+"| "),t(e.line+"\n","color:red")}),"undefined"!=typeof document?(a[0]=r.join("%c"),console.log.apply(console,a)):console.log(r.join(""))}}),n.raise("Error compiling "+f+" shader, "+u[0].name)}}function x(e,t,r,a,i){if(!e.getProgramParameter(t,e.LINK_STATUS)){var o=e.getProgramInfoLog(t),f=v(r,i),u=v(a,i),s='Error linking program with vertex shader, "'+u[0].name+'", and fragment shader "'+f[0].name+'"';"undefined"!=typeof document?console.log("%c"+s+"\n%c"+o,"color:red;text-decoration:underline;font-weight:bold","color:red"):console.log(s+"\n"+o),n.raise(s)}}function w(e){e._commandRef=p()}function k(e,t,n,r){function a(e){return e?r.id(e):0}function i(e,t){Object.keys(t).forEach(function(t){e[r.id(t)]=!0})}w(e),e._fragId=a(e.static.frag),e._vertId=a(e.static.vert);var o=e._uniformSet={};i(o,t.static),i(o,t.dynamic);var f=e._attributeSet={};i(f,n.static),i(f,n.dynamic),e._hasCount="count"in e.static||"count"in e.dynamic||"elements"in e.static||"elements"in e.dynamic}function S(e,n){var r=h();t(e+" in command "+(n||p())+("unknown"===r?"":" called from "+r))}function _(e,t,n){e||S(t,n||p())}function A(e,t,n,a){e in t||S("unknown parameter ("+e+")"+r(n)+". possible values: "+Object.keys(t).join(),a||p())}function E(e,t,n,a){typeof e!==t&&S("invalid parameter type"+r(n)+". expected "+t+", got "+typeof e,a||p())}function D(e){e()}function T(e,t,n){e.texture?u(e.texture._texture.internalformat,t,"unsupported texture format for attachment"):u(e.renderbuffer._renderbuffer.format,n,"unsupported renderbuffer format for attachment")}function j(e,t){return e===ht||e===pt||e===vt?2:e===bt?4:yt[e]*t}function C(e){return!(e&e-1||!e)}function O(e,t,r){var a,i=t.width,o=t.height,f=t.channels;n(i>0&&i<=r.maxTextureSize&&o>0&&o<=r.maxTextureSize,"invalid texture shape"),e.wrapS===tt&&e.wrapT===tt||n(C(i)&&C(o),"incompatible wrap mode for texture, both width and height must be power of 2"),1===t.mipmask?1!==i&&1!==o&&n(e.minFilter!==rt&&e.minFilter!==it&&e.minFilter!==at&&e.minFilter!==ot,"min filter requires mipmap"):(n(C(i)&&C(o),"texture must be a square power of 2 to support mipmapping"),n(t.mipmask===(i<<1)-1,"missing or incomplete mipmap data")),t.type===dt&&(r.extensions.indexOf("oes_texture_float_linear")<0&&n(e.minFilter===nt&&e.magFilter===nt,"filter not supported, must enable oes_texture_float_linear"),n(!e.genMipmaps,"mipmap generation not supported with float textures"));var u=t.images;for(a=0;a<16;++a)if(u[a]){var s=i>>a,c=o>>a;n(t.mipmask&1<0&&i<=a.maxTextureSize&&o>0&&o<=a.maxTextureSize,"invalid texture shape"),n(i===o,"cube map must be square"),n(t.wrapS===tt&&t.wrapT===tt,"wrap mode not supported by cube map");for(var u=0;u>l,p=o>>l;n(s.mipmask&1<1&&t===n&&('"'===t||"'"===t))return['"'+M(e.substr(1,e.length-2))+'"'];var r=/\[(false|true|null|\d+|'[^']*'|"[^"]*")\]/.exec(e);if(r)return P(e.substr(0,r.index)).concat(P(r[1])).concat(P(e.substr(r.index+r[0].length)));var a=e.split(".");if(1===a.length)return['"'+M(e)+'"'];for(var i=[],o=0;o0,"invalid pixel ratio"))):xt.raise("invalid arguments to regl"),t&&("canvas"===t.nodeName.toLowerCase()?r=t:n=t),!a){if(!r){xt("undefined"!=typeof document,"must manually specify webgl context outside of DOM environments");var d=U(n||document.body,l,s);if(!d)return null;r=d.canvas,m=d.onDestroy}a=q(r,o)}return a?{gl:a,canvas:r,container:n,extensions:f,optionalExtensions:u,pixelRatio:s,profile:c,onDone:l,onDestroy:m}:(m(),l("webgl not supported, try upgrading your browser or graphics drivers http://get.webgl.org"),null)}function Y(e,t){function n(t){xt.type(t,"string","extension name must be string");var n,a=t.toLowerCase();try{n=r[a]=e.getExtension(a)}catch(e){}return!!n}for(var r={},a=0;a65535)<<4,e>>>=t,n=(e>255)<<3,e>>>=n,t|=n,n=(e>15)<<2,e>>>=n,t|=n,n=(e>3)<<1,e>>>=n,t|=n,t|e>>1}function Z(e){var t=K(e),n=sn[J(t)>>2];return n.length>0?n.pop():new ArrayBuffer(t)}function ee(e){sn[J(e.byteLength)>>2].push(e)}function te(e,t){var n=null;switch(e){case tn:n=new Int8Array(Z(t),0,t);break;case nn:n=new Uint8Array(Z(t),0,t);break;case rn:n=new Int16Array(Z(2*t),0,t);break;case an:n=new Uint16Array(Z(2*t),0,t);break;case on:n=new Int32Array(Z(4*t),0,t);break;case fn:n=new Uint32Array(Z(4*t),0,t);break;case un:n=new Float32Array(Z(4*t),0,t);break;default:return null}return n.length!==t?n.subarray(0,t):n}function ne(e){ee(e.buffer)}function re(e,t,n){for(var r=0;r0){var u;if(Array.isArray(t[0])){f=An(t);for(var s=1,c=1;c0)if("number"==typeof e[0]){var a=cn.allocType(p.dtype,e.length);ce(a,e),l(a,r),cn.freeType(a)}else if(Array.isArray(e[0])||Je(e[0])){n=An(e);var i=_n(e,n,p.dtype);l(i,r),cn.freeType(i)}else xt.raise("invalid buffer data")}else if(Je(e))l(e,r);else if(X(e)){n=e.shape;var o=e.stride,f=0,u=0,s=0,m=0;1===n.length?(f=n[0],u=1,s=o[0],m=0):2===n.length?(f=n[0],u=n[1],s=o[0],m=o[1]):xt.raise("invalid shape");var d=Array.isArray(e.data)?p.dtype:se(e.data),h=cn.allocType(d,f*u);le(h,e.data,f,u,s,m,e.offset),l(h,r),cn.freeType(h)}else xt.raise("invalid data for buffer subdata");return c}t.bufferCount++;var p=new r(i);return m[p.id]=p,o||c(a),c._reglType="buffer",c._buffer=p,c.subdata=d,n.profile&&(c.stats=p.stats),c.destroy=function(){u(p)},c}function c(){en(m).forEach(function(t){t.buffer=e.createBuffer(),e.bindBuffer(t.type,t.buffer),e.bufferData(t.type,t.persistentData||t.byteLength,t.usage)})}var l=0,m={};r.prototype.bind=function(){e.bindBuffer(this.type,this.buffer)},r.prototype.destroy=function(){u(this)};var d=[];return n.profile&&(t.getTotalBufferSize=function(){var e=0;return Object.keys(m).forEach(function(t){e+=m[t].stats.size}),e}),{create:s,createStream:a,destroyStream:i,clear:function(){en(m).forEach(u),d.forEach(u)},getBuffer:function(e){return e&&e._buffer instanceof r?e._buffer:null},restore:c,_initBuffer:f}}function de(e,t,n,r){function a(e){this.id=l++,c[this.id]=this,this.buffer=e,this.primType=Nn,this.vertCount=0,this.type=0}function i(e){var t=d.pop();return t||(t=new a(n.create(null,Vn,!0,!1)._buffer)),f(t,e,Yn,-1,-1,0,0),t}function o(e){d.push(e)}function f(r,a,i,o,f,u,s){if(r.buffer.bind(),a){var c=s;s||Je(a)&&(!X(a)||Je(a.data))||(c=t.oes_element_index_uint?Qn:Gn),n._initBuffer(r.buffer,a,i,c,3)}else e.bufferData(Vn,u,i),r.buffer.dtype=l||qn,r.buffer.usage=i,r.buffer.dimension=3,r.buffer.byteLength=u;var l=s;if(!s){switch(r.buffer.dtype){case qn:case Un:l=qn;break;case Gn:case Wn:l=Gn;break;case Qn:case Hn:l=Qn;break;default:xt.raise("unsupported type for element array")}r.buffer.dtype=l}r.type=l,xt(l!==Qn||!!t.oes_element_index_uint,"32 bit element buffers not supported, enable oes_element_index_uint first");var m=f;m<0&&(m=r.buffer.byteLength,l===Gn?m>>=1:l===Qn&&(m>>=2)),r.vertCount=m;var d=o;if(o<0){d=Nn;var p=r.buffer.dimension;1===p&&(d=Bn),2===p&&(d=Rn),3===p&&(d=Nn)}r.primType=d}function u(e){r.elementsCount--,xt(null!==e.buffer,"must not double destroy elements"),delete c[e.id],e.buffer.destroy(),e.buffer=null}function s(e,t){function i(e){if(e)if("number"==typeof e)o(e),s.primType=Nn,s.vertCount=0|e,s.type=qn;else{var t=null,n=Xn,r=-1,a=-1,u=0,c=0;Array.isArray(e)||Je(e)||X(e)?t=e:(xt.type(e,"object","invalid arguments for elements"),"data"in e&&(t=e.data,xt(Array.isArray(t)||Je(t)||X(t),"invalid data for element buffer")),"usage"in e&&(xt.parameter(e.usage,Sn,"invalid element buffer usage"),n=Sn[e.usage]),"primitive"in e&&(xt.parameter(e.primitive,Ln,"invalid element buffer primitive"),r=Ln[e.primitive]),"count"in e&&(xt("number"==typeof e.count&&e.count>=0,"invalid vertex count for elements"),a=0|e.count),"type"in e&&(xt.parameter(e.type,m,"invalid buffer type"),c=m[e.type]),"length"in e?u=0|e.length:(u=a,c===Gn||c===Wn?u*=2:c!==Qn&&c!==Hn||(u*=4))),f(s,t,n,r,a,u,c)}else o(),s.primType=Nn,s.vertCount=0,s.type=qn;return i}var o=n.create(null,Vn,!0),s=new a(o._buffer);return r.elementsCount++,i(e),i._reglType="elements",i._elements=s,i.subdata=function(e,t){return o.subdata(e,t),i},i.destroy=function(){u(s)},i}var c={},l=0,m={uint8:qn,uint16:Gn};t.oes_element_index_uint&&(m.uint32=Qn),a.prototype.bind=function(){this.buffer.bind()};var d=[];return{create:s,createStream:i,destroyStream:o,getElements:function(e){return"function"==typeof e&&e._elements instanceof a?e._elements:null},clear:function(){en(c).forEach(u)}}}function pe(e){for(var t=cn.allocType(Jn,e.length),n=0;n>>31<<15,i=(r<<1>>>24)-127,o=r>>13&1023;if(i<-24)t[n]=a;else if(i<-14){var f=-14-i;t[n]=a+(o+1024>>f)}else i>15?t[n]=a+31744:t[n]=a+(i+15<<10)+o}return t}function he(e){return Array.isArray(e)||Je(e)}function ve(e){return"[object "+e+"]"}function be(e){return Array.isArray(e)&&(0===e.length||"number"==typeof e[0])}function ge(e){if(!Array.isArray(e))return!1;var t=e.length;return!(0===t||!he(e[0]))}function ye(e){return Object.prototype.toString.call(e)}function xe(e){return ye(e)===sa}function we(e){return ye(e)===ca}function ke(e){return ye(e)===la}function Se(e){return ye(e)===ma}function _e(e){if(!e)return!1;var t=ye(e);return da.indexOf(t)>=0||(be(e)||ge(e)||X(e))}function Ae(e){return 0|Ke[Object.prototype.toString.call(e)]}function Ee(e,t){var n=t.length;switch(e.type){case zr:case Fr:case Mr:case Pr:var r=cn.allocType(e.type,n);r.set(t),e.data=r;break;case yr:e.data=pe(t);break;default:xt.raise("unsupported texture type, must specify a typed array")}}function De(e,t){return cn.allocType(e.type===yr?Pr:e.type,t)}function Te(e,t){e.type===yr?(e.data=pe(t),cn.freeType(t)):e.data=t}function je(e,t,n,r,a,i){for(var o=e.width,f=e.height,u=e.channels,s=o*f*u,c=De(e,s),l=0,m=0;m=1;)f+=o*u*u,u/=2;return f}return o*n*r}function Oe(e,t,n,r,a,i,o){function f(){this.internalformat=rr,this.format=rr,this.type=zr,this.compressed=!1,this.premultiplyAlpha=!1,this.flipY=!1,this.unpackAlignment=1,this.colorSpace=0,this.width=0,this.height=0,this.channels=0}function u(e,t){e.internalformat=t.internalformat,e.format=t.format,e.type=t.type,e.compressed=t.compressed,e.premultiplyAlpha=t.premultiplyAlpha,e.flipY=t.flipY,e.unpackAlignment=t.unpackAlignment,e.colorSpace=t.colorSpace,e.width=t.width,e.height=t.height,e.channels=t.channels}function s(e,r){if("object"==typeof r&&r){if("premultiplyAlpha"in r&&(xt.type(r.premultiplyAlpha,"boolean","invalid premultiplyAlpha"),e.premultiplyAlpha=r.premultiplyAlpha),"flipY"in r&&(xt.type(r.flipY,"boolean","invalid texture flip"),e.flipY=r.flipY),"alignment"in r&&(xt.oneOf(r.alignment,[1,2,4,8],"invalid texture unpack alignment"),e.unpackAlignment=r.alignment),"colorSpace"in r&&(xt.parameter(r.colorSpace,B,"invalid colorSpace"),e.colorSpace=B[r.colorSpace]),"type"in r){var a=r.type;xt(t.oes_texture_float||!("float"===a||"float32"===a),"you must enable the OES_texture_float extension in order to use floating point textures."),xt(t.oes_texture_half_float||!("half float"===a||"float16"===a),"you must enable the OES_texture_half_float extension in order to use 16-bit floating point textures."),xt(t.webgl_depth_texture||!("uint16"===a||"uint32"===a||"depth stencil"===a),"you must enable the WEBGL_depth_texture extension in order to use depth/stencil textures."),xt.parameter(a,R,"invalid texture type"),e.type=R[a]}var i=e.width,o=e.height,f=e.channels,u=!1;"shape"in r?(xt(Array.isArray(r.shape)&&r.shape.length>=2,"shape must be an array"),i=r.shape[0],o=r.shape[1],3===r.shape.length&&(f=r.shape[2],xt(f>0&&f<=4,"invalid number of channels"),u=!0),xt(i>=0&&i<=n.maxTextureSize,"invalid width"),xt(o>=0&&o<=n.maxTextureSize,"invalid height")):("radius"in r&&(i=o=r.radius,xt(i>=0&&i<=n.maxTextureSize,"invalid radius")),"width"in r&&(i=r.width,xt(i>=0&&i<=n.maxTextureSize,"invalid width")),"height"in r&&(o=r.height,xt(o>=0&&o<=n.maxTextureSize,"invalid height")),"channels"in r&&(f=r.channels,xt(f>0&&f<=4,"invalid number of channels"),u=!0)),e.width=0|i,e.height=0|o,e.channels=0|f;var s=!1;if("format"in r){var c=r.format;xt(t.webgl_depth_texture||!("depth"===c||"depth stencil"===c),"you must enable the WEBGL_depth_texture extension in order to use depth/stencil textures."),xt.parameter(c,N,"invalid texture format");var l=e.internalformat=N[c];e.format=$[l],c in R&&("type"in r||(e.type=R[c])),c in U&&(e.compressed=!0),s=!0}!u&&s?e.channels=ua[e.format]:u&&!s?e.channels!==fa[e.format]&&(e.format=e.internalformat=fa[e.channels]):s&&u&&xt(e.channels===ua[e.format],"number of channels inconsistent with specified format")}}function c(t){e.pixelStorei(ta,t.flipY),e.pixelStorei(na,t.premultiplyAlpha),e.pixelStorei(ra,t.colorSpace),e.pixelStorei(ea,t.unpackAlignment)}function l(){f.call(this),this.xOffset=0,this.yOffset=0,this.data=null,this.needsFree=!1,this.element=null,this.needsCopy=!1}function m(e,t){var r=null;if(_e(t)?r=t:t&&(xt.type(t,"object","invalid pixel data type"),s(e,t),"x"in t&&(e.xOffset=0|t.x),"y"in t&&(e.yOffset=0|t.y),_e(t.data)&&(r=t.data)),xt(!e.compressed||r instanceof Uint8Array,"compressed texture data must be stored in a uint8array"),t.copy){xt(!r,"can not specify copy and data field for the same texture");var i=a.viewportWidth,o=a.viewportHeight;e.width=e.width||i-e.xOffset,e.height=e.height||o-e.yOffset,e.needsCopy=!0,xt(e.xOffset>=0&&e.xOffset=0&&e.yOffset0&&e.width<=i&&e.height>0&&e.height<=o,"copy texture read out of bounds")}else if(r){if(Je(r))e.channels=e.channels||4,e.data=r,"type"in t||e.type!==zr||(e.type=Ae(r));else if(be(r))e.channels=e.channels||4,Ee(e,r),e.alignment=1,e.needsFree=!0;else if(X(r)){var f=r.data;Array.isArray(f)||e.type!==zr||(e.type=Ae(f));var u,c,l,m,d,p,h=r.shape,v=r.stride;3===h.length?(l=h[2],p=v[2]):(xt(2===h.length,"invalid ndarray pixel data, must be 2 or 3D"),l=1,p=1),u=h[0],c=h[1],m=v[0],d=v[1],e.alignment=1,e.width=u,e.height=c,e.channels=l,e.format=e.internalformat=fa[l],e.needsFree=!0,je(e,f,m,d,p,r.offset)}else if(xe(r)||we(r))xe(r)?e.element=r:e.element=r.canvas,e.width=e.element.width,e.height=e.element.height,e.channels=4;else if(ke(r))e.element=r,e.width=r.naturalWidth,e.height=r.naturalHeight,e.channels=4;else if(Se(r))e.element=r,e.width=r.videoWidth,e.height=r.videoHeight,e.channels=4;else if(ge(r)){var b=e.width||r[0].length,g=e.height||r.length,y=e.channels;y=he(r[0][0])?y||r[0][0].length:y||1;for(var x=ln.shape(r),w=1,k=0;k=0,"oes_texture_float extension not enabled"):e.type===yr&&xt(n.extensions.indexOf("oes_texture_half_float")>=0,"oes_texture_half_float extension not enabled")}function d(t,n,a){var i=t.element,o=t.data,f=t.internalformat,u=t.format,s=t.type,l=t.width,m=t.height;c(t),i?e.texImage2D(n,a,u,u,s,i):t.compressed?e.compressedTexImage2D(n,a,f,l,m,0,o):t.needsCopy?(r(),e.copyTexImage2D(n,a,u,t.xOffset,t.yOffset,l,m,0)):e.texImage2D(n,a,u,l,m,0,u,s,o)}function p(t,n,a,i,o){var f=t.element,u=t.data,s=t.internalformat,l=t.format,m=t.type,d=t.width,p=t.height;c(t),f?e.texSubImage2D(n,o,a,i,l,m,f):t.compressed?e.compressedTexSubImage2D(n,o,a,i,s,d,p,u):t.needsCopy?(r(),e.copyTexSubImage2D(n,o,a,i,t.xOffset,t.yOffset,d,p)):e.texSubImage2D(n,o,a,i,d,p,l,m,u)}function h(){return K.pop()||new l}function v(e){e.needsFree&&cn.freeType(e.data),l.call(e),K.push(e)}function b(){f.call(this),this.genMipmaps=!1,this.mipmapHint=$r,this.mipmask=0,this.images=Array(16)}function g(e,t,n){var r=e.images[0]=h();e.mipmask=1,r.width=e.width=t,r.height=e.height=n,r.channels=e.channels=4}function y(e,t){var n=null;if(_e(t))n=e.images[0]=h(),u(n,e),m(n,t),e.mipmask=1;else if(s(e,t),Array.isArray(t.mipmap))for(var r=t.mipmap,a=0;a>=a,n.height>>=a,m(n,r[a]),e.mipmask|=1<=0&&(e.genMipmaps=!0)}if("mag"in t){var a=t.mag;xt.parameter(a,I),e.magFilter=I[a]}var i=e.wrapS,o=e.wrapT;if("wrap"in t){var f=t.wrap;"string"==typeof f?(xt.parameter(f,P),i=o=P[f]):Array.isArray(f)&&(xt.parameter(f[0],P),xt.parameter(f[1],P),i=P[f[0]],o=P[f[1]])}else{if("wrapS"in t){var u=t.wrapS;xt.parameter(u,P),i=P[u]}if("wrapT"in t){var s=t.wrapT;xt.parameter(s,P),o=P[s]}}if(e.wrapS=i,e.wrapT=o,"anisotropic"in t){var c=t.anisotropic;xt("number"==typeof c&&c>=1&&c<=n.maxAnisotropic,"aniso samples must be between 1 and "),e.anisotropic=t.anisotropic}if("mipmap"in t){var l=!1;switch(typeof t.mipmap){case"string":xt.parameter(t.mipmap,M,"invalid mipmap hint"),e.mipmapHint=M[t.mipmap],e.genMipmaps=!0,l=!0;break;case"boolean":l=e.genMipmaps=t.mipmap;break;case"object":xt(Array.isArray(t.mipmap),"invalid mipmap type"),e.genMipmaps=!1,l=!0;break;default:xt.raise("invalid mipmap type")}!l||"min"in t||(e.minFilter=Hr)}}function A(n,r){e.texParameteri(r,qr,n.minFilter),e.texParameteri(r,Ur,n.magFilter),e.texParameteri(r,Ir,n.wrapS),e.texParameteri(r,Lr,n.wrapT),t.ext_texture_filter_anisotropic&&e.texParameteri(r,Zr,n.anisotropic),n.genMipmaps&&(e.hint(Xr,n.mipmapHint),e.generateMipmap(r))}function E(t){f.call(this),this.mipmask=0,this.internalformat=rr,this.id=Z++,this.refCount=1,this.target=t,this.texture=e.createTexture(),this.unit=-1,this.bindCount=0,this.texInfo=new S,o.profile&&(this.stats={size:0})}function D(t){e.activeTexture(ia),e.bindTexture(t.target,t.texture)}function T(){var t=ne[0];t?e.bindTexture(t.target,t.texture):e.bindTexture(er,null)}function j(t){var n=t.texture;xt(n,"must not double destroy texture");var r=t.unit,a=t.target;r>=0&&(e.activeTexture(ia+r),e.bindTexture(a,null),ne[r]=null),e.deleteTexture(n),t.texture=null,t.params=null,t.pixels=null,t.refCount=0,delete ee[t.id],i.textureCount--}function C(t,r){function a(e,t){var r=c.texInfo;S.call(r);var i=w();return"number"==typeof e?"number"==typeof t?g(i,0|e,0|t):g(i,0|e,0|e):e?(xt.type(e,"object","invalid arguments to regl.texture"),_(r,e),y(i,e)):g(i,1,1),r.genMipmaps&&(i.mipmask=(i.width<<1)-1),c.mipmask=i.mipmask,u(c,i),xt.texture2D(r,i,n),c.internalformat=i.internalformat,a.width=i.width,a.height=i.height,D(c),x(i,er),A(r,er),T(),k(i),o.profile&&(c.stats.size=Ce(c.internalformat,c.type,i.width,i.height,r.genMipmaps,!1)),a.format=G[c.internalformat],a.type=H[c.type],a.mag=Q[r.magFilter],a.min=V[r.minFilter],a.wrapS=Y[r.wrapS],a.wrapT=Y[r.wrapT],a}function f(e,t,n,r){xt(!!e,"must specify image data");var i=0|t,o=0|n,f=0|r,s=h();return u(s,c),s.width=0,s.height=0,m(s,e),s.width=s.width||(c.width>>f)-i,s.height=s.height||(c.height>>f)-o,xt(c.type===s.type&&c.format===s.format&&c.internalformat===s.internalformat,"incompatible format for texture.subimage"),xt(i>=0&&o>=0&&i+s.width<=c.width&&o+s.height<=c.height,"texture.subimage write out of bounds"),xt(c.mipmask&1<>f;++f)e.texImage2D(er,f,c.format,r>>f,i>>f,0,c.format,c.type,null);return T(),o.profile&&(c.stats.size=Ce(c.internalformat,c.type,r,i,!1,!1)),a}var c=new E(er);return ee[c.id]=c,i.textureCount++,a(t,r),a.subimage=f,a.resize=s,a._reglType="texture2d",a._texture=c,o.profile&&(a.stats=c.stats),a.destroy=function(){c.decRef()},a}function O(t,r,a,f,c,l){function d(e,t,r,a,i,f){var c,l=C.texInfo;for(S.call(l),c=0;c<6;++c)O[c]=w();if("number"!=typeof e&&e)if("object"==typeof e)if(t)y(O[0],e),y(O[1],t),y(O[2],r),y(O[3],a),y(O[4],i),y(O[5],f);else if(_(l,e),s(C,e),"faces"in e){var m=e.faces;for(xt(Array.isArray(m)&&6===m.length,"cube faces must be a length 6 array"),c=0;c<6;++c)xt("object"==typeof m[c]&&!!m[c],"invalid input for cube map face"),u(O[c],C),y(O[c],m[c])}else for(c=0;c<6;++c)y(O[c],e);else xt.raise("invalid arguments to cube map");else{var p=0|e||1;for(c=0;c<6;++c)g(O[c],p,p)}for(u(C,O[0]),l.genMipmaps?C.mipmask=(O[0].width<<1)-1:C.mipmask=O[0].mipmask,xt.textureCube(C,l,O,n),C.internalformat=O[0].internalformat,d.width=O[0].width,d.height=O[0].height,D(C),c=0;c<6;++c)x(O[c],nr+c);for(A(l,tr),T(),o.profile&&(C.stats.size=Ce(C.internalformat,C.type,d.width,d.height,l.genMipmaps,!0)),d.format=G[C.internalformat],d.type=H[C.type],d.mag=Q[l.magFilter],d.min=V[l.minFilter],d.wrapS=Y[l.wrapS],d.wrapT=Y[l.wrapT],c=0;c<6;++c)k(O[c]);return d}function b(e,t,n,r,a){xt(!!t,"must specify image data"),xt("number"==typeof e&&e===(0|e)&&e>=0&&e<6,"invalid face");var i=0|n,o=0|r,f=0|a,s=h();return u(s,C),s.width=0,s.height=0,m(s,t),s.width=s.width||(C.width>>f)-i,s.height=s.height||(C.height>>f)-o,xt(C.type===s.type&&C.format===s.format&&C.internalformat===s.internalformat,"incompatible format for texture.subimage"),xt(i>=0&&o>=0&&i+s.width<=C.width&&o+s.height<=C.height,"texture.subimage write out of bounds"),xt(C.mipmask&1<>a;++a)e.texImage2D(nr+r,a,C.format,n>>a,n>>a,0,C.format,C.type,null);return T(),o.profile&&(C.stats.size=Ce(C.internalformat,C.type,d.width,d.height,!1,!0)),d}}var C=new E(tr);ee[C.id]=C,i.cubeCount++;var O=new Array(6);return d(t,r,a,f,c,l),d.subimage=b,d.resize=j,d._reglType="textureCube",d._texture=C,o.profile&&(d.stats=C.stats),d.destroy=function(){C.decRef()},d}function z(){for(var t=0;t>n,t.height>>n,0,t.internalformat,t.type,null);else for(var r=0;r<6;++r)e.texImage2D(nr+r,n,t.internalformat,t.width>>n,t.height>>n,0,t.internalformat,t.type,null);A(t.texInfo,t.target)})}var M={"don't care":$r,"dont care":$r,nice:Jr,fast:Kr},P={repeat:Br,clamp:Rr,mirror:Nr},I={nearest:Wr,linear:Gr},L=Ze({mipmap:Yr,"nearest mipmap nearest":Hr,"linear mipmap nearest":Qr,"nearest mipmap linear":Vr,"linear mipmap linear":Yr},I),B={none:0,browser:aa},R={uint8:zr,rgba4:lr,rgb565:dr,"rgb5 a1":mr},N={alpha:ar,luminance:or,"luminance alpha":fr,rgb:ir,rgba:rr,rgba4:ur,"rgb5 a1":sr,rgb565:cr},U={};t.ext_srgb&&(N.srgb=br,N.srgba=gr),t.oes_texture_float&&(R.float32=R.float=Pr),t.oes_texture_half_float&&(R.float16=R["half float"]=yr),t.webgl_depth_texture&&(Ze(N,{depth:hr,"depth stencil":vr}),Ze(R,{uint16:Fr,uint32:Mr,"depth stencil":pr})),t.webgl_compressed_texture_s3tc&&Ze(U,{"rgb s3tc dxt1":xr,"rgba s3tc dxt1":wr,"rgba s3tc dxt3":kr,"rgba s3tc dxt5":Sr}),t.webgl_compressed_texture_atc&&Ze(U,{"rgb atc":_r,"rgba atc explicit alpha":Ar,"rgba atc interpolated alpha":Er}),t.webgl_compressed_texture_pvrtc&&Ze(U,{"rgb pvrtc 4bppv1":Dr,"rgb pvrtc 2bppv1":Tr,"rgba pvrtc 4bppv1":jr,"rgba pvrtc 2bppv1":Cr}),t.webgl_compressed_texture_etc1&&(U["rgb etc1"]=Or);var q=Array.prototype.slice.call(e.getParameter(Zn));Object.keys(U).forEach(function(e){var t=U[e];q.indexOf(t)>=0&&(N[e]=t)});var W=Object.keys(N);n.textureFormats=W;var G=[];Object.keys(N).forEach(function(e){var t=N[e];G[t]=e});var H=[];Object.keys(R).forEach(function(e){var t=R[e];H[t]=e});var Q=[];Object.keys(I).forEach(function(e){var t=I[e];Q[t]=e});var V=[];Object.keys(L).forEach(function(e){var t=L[e];V[t]=e});var Y=[];Object.keys(P).forEach(function(e){var t=P[e];Y[t]=e});var $=W.reduce(function(e,t){var n=N[t];return n===or||n===ar||n===or||n===fr||n===hr||n===vr?e[n]=n:n===sr||t.indexOf("rgba")>=0?e[n]=rr:e[n]=ir,e},{}),K=[],J=[],Z=0,ee={},te=n.maxTextureUnits,ne=Array(te).map(function(){return null});return Ze(E.prototype,{bind:function(){var t=this;t.bindCount+=1;var n=t.unit;if(n<0){for(var r=0;r0)continue;a.unit=-1}ne[r]=t,n=r;break}n>=te&&xt.raise("insufficient number of texture units"),o.profile&&i.maxTextureUnits=za&&t=2,"invalid shape for framebuffer"),s=z[0],d=z[1]}else"radius"in O&&(s=d=O.radius),"width"in O&&(s=O.width),"height"in O&&(d=O.height);("color"in O||"colors"in O)&&(g=O.color||O.colors,Array.isArray(g)&&xt(1===g.length||o,"multiple render targets not supported")),g||("colorCount"in O&&(E=0|O.colorCount,xt(E>0,"invalid color buffer count")),"colorTexture"in O&&(y=!!O.colorTexture,x="rgba4"),"colorType"in O&&(A=O.colorType,y?(xt(t.oes_texture_float||!("float"===A||"float32"===A),"you must enable OES_texture_float in order to use floating point framebuffer objects"),xt(t.oes_texture_half_float||!("half float"===A||"float16"===A),"you must enable OES_texture_half_float in order to use 16-bit floating point framebuffer objects")):"half float"===A||"float16"===A?(xt(t.ext_color_buffer_half_float,"you must enable EXT_color_buffer_half_float to use 16-bit render buffers"),x="rgba16f"):"float"!==A&&"float32"!==A||(xt(t.webgl_color_buffer_float,"you must enable WEBGL_color_buffer_float in order to use 32-bit floating point renderbuffers"),x="rgba32f"),xt.oneOf(A,_,"invalid color type")),"colorFormat"in O&&(x=O.colorFormat,k.indexOf(x)>=0?y=!0:S.indexOf(x)>=0?y=!1:y?xt.oneOf(O.colorFormat,k,"invalid color format for texture"):xt.oneOf(O.colorFormat,S,"invalid color format for renderbuffer"))),("depthTexture"in O||"depthStencilTexture"in O)&&(C=!(!O.depthTexture&&!O.depthStencilTexture),xt(!C||t.webgl_depth_texture,"webgl_depth_texture extension not supported")),"depth"in O&&("boolean"==typeof O.depth?p=O.depth:(D=O.depth,v=!1)),"stencil"in O&&("boolean"==typeof O.stencil?v=O.stencil:(T=O.stencil,p=!1)),"depthStencil"in O&&("boolean"==typeof O.depthStencil?p=v=O.depthStencil:(j=O.depthStencil,p=!1,v=!1))}else s=d=1;var F=null,M=null,P=null,I=null;if(Array.isArray(g))F=g.map(c);else if(g)F=[c(g)];else for(F=new Array(E),i=0;i=0||F[i].renderbuffer&&oi.indexOf(F[i].renderbuffer._renderbuffer.format)>=0,"framebuffer color attachment "+i+" is invalid"),F[i]&&F[i].texture){var B=Ya[F[i].texture._texture.format]*Xa[F[i].texture._texture.type];null===L?L=B:xt(L===B,"all color attachments much have the same number of bits per pixel.")}return u(M,s,d),xt(!M||M.texture&&M.texture._texture.format===Qa||M.renderbuffer&&M.renderbuffer._renderbuffer.format===Za,"invalid depth attachment for framebuffer object"),u(P,s,d),xt(!P||P.renderbuffer&&P.renderbuffer._renderbuffer.format===ei,"invalid stencil attachment for framebuffer object"),u(I,s,d),xt(!I||I.texture&&I.texture._texture.format===ti||I.renderbuffer&&I.renderbuffer._renderbuffer.format===ti,"invalid depth-stencil attachment for framebuffer object"),h(f),f.width=s,f.height=d,f.colorAttachments=F,f.depthAttachment=M,f.stencilAttachment=P,f.depthStencilAttachment=I,a.color=F.map(m),a.depth=m(M),a.stencil=m(P),a.depthStencil=m(I),a.width=f.width,a.height=f.height,b(f),a}function o(e,t){xt(w.next!==f,"can not resize a framebuffer which is currently in use"); 3 | var n=0|e,r=0|t||n;if(n===f.width&&r===f.height)return a;for(var i=f.colorAttachments,o=0;o=2,"invalid shape for framebuffer"),xt(p[0]===p[1],"cube framebuffer must be square"),u=p[0]}else"radius"in d&&(u=0|d.radius),"width"in d?(u=0|d.width,"height"in d&&xt(d.height===u,"must be square")):"height"in d&&(u=0|d.height);("color"in d||"colors"in d)&&(s=d.color||d.colors,Array.isArray(s)&&xt(1===s.length||i,"multiple render targets not supported")),s||("colorCount"in d&&(m=0|d.colorCount,xt(m>0,"invalid color buffer count")),"colorType"in d&&(xt.oneOf(d.colorType,_,"invalid color type"),l=d.colorType),"colorFormat"in d&&(c=d.colorFormat,xt.oneOf(d.colorFormat,k,"invalid color format for texture"))),"depth"in d&&(f.depth=d.depth),"stencil"in d&&(f.stencil=d.stencil),"depthStencil"in d&&(f.depthStencil=d.depthStencil)}else u=1;var h;if(s)if(Array.isArray(s))for(h=[],n=0;n0&&(f.depth=o[0].depth,f.stencil=o[0].stencil,f.depthStencil=o[0].depthStencil),o[n]?o[n](f):o[n]=g(f)}return Ze(a,{width:u,height:u,color:h})}function i(e){var t,r=0|e;if(xt(r>0&&r<=n.maxCubeMapSize,"invalid radius for cube fbo"),r===a.width)return a;var i=a.color;for(t=0;t1)for(var h=0;he&&(e=t.stats.uniformsCount)}),e},n.getMaxAttributesCount=function(){var e=0;return d.forEach(function(t){t.stats.attributesCount>e&&(e=t.stats.attributesCount)}),e}),{clear:function(){var t=e.deleteShader.bind(e);en(c).forEach(t),c={},en(l).forEach(t),l={},d.forEach(function(t){e.deleteProgram(t.program)}),d.length=0,m={},n.shaderCount=0},program:function(e,t,r){xt.command(e>=0,"missing vertex shader",r),xt.command(t>=0,"missing fragment shader",r);var a=m[t];a||(a=m[t]={});var i=a[e];return i||(i=new f(t,e),n.shaderCount++,u(i,r),a[e]=i,d.push(i)),i},restore:s,shader:o,frag:-1,vert:-1}}function Le(e,t,n,r,a,i){function o(o){var f;null===t.next?(xt(a.preserveDrawingBuffer,'you must create a webgl context with "preserveDrawingBuffer":true in order to read pixels from the drawing buffer'),f=pi):(xt(null!==t.next.colorAttachments[0].texture,"You cannot read from a renderbuffer"),f=t.next.colorAttachments[0].texture._texture.type,i.oes_texture_float?xt(f===pi||f===vi,"Reading from a framebuffer is only allowed for the types 'uint8' and 'float'"):xt(f===pi,"Reading from a framebuffer is only allowed for the type 'uint8'"));var u=0,s=0,c=r.framebufferWidth,l=r.framebufferHeight,m=null;Je(o)?m=o:o&&(xt.type(o,"object","invalid arguments to regl.read()"),u=0|o.x,s=0|o.y,xt(u>=0&&u=0&&s0&&c+u<=r.framebufferWidth,"invalid width for read pixels"),xt(l>0&&l+s<=r.framebufferHeight,"invalid height for read pixels"),n();var d=c*l*4;return m||(f===pi?m=new Uint8Array(d):f===vi&&(m=m||new Float32Array(d))),xt.isTypedArray(m,"data buffer for regl.read() must be a typedarray"),xt(m.byteLength>=d,"data buffer for regl.read() too small"),e.pixelStorei(hi,4),e.readPixels(u,s,c,l,di,f,m),m}function f(e){var n;return t.setFBO({framebuffer:e.framebuffer},function(){n=o(e)}),n}function u(e){return e&&"framebuffer"in e?f(e):o(e)}return u}function Be(e){return Array.prototype.slice.call(e)}function Re(e){return Be(e).join("")}function Ne(){function e(e){for(var t=0;t0&&(n.push(e,"="),n.push.apply(n,Be(arguments)),n.push(";")),e}var n=[],r=[];return Ze(e,{def:t,toString:function(){return Re([r.length>0?"var "+r+";":"",Re(n)])}})}function n(){function e(e,t){r(e,t,"=",n.def(e,t),";")}var n=t(),r=t(),a=n.toString,i=r.toString;return Ze(function(){n.apply(n,Be(arguments))},{def:n.def,entry:n,exit:r,save:e,set:function(t,r,a){e(t,r),n(t,r,"=",a,";")},toString:function(){return a()+i()}})}function r(){var e=Re(arguments),t=n(),r=n(),a=t.toString,i=r.toString;return Ze(t,{then:function(){return t.apply(t,Be(arguments)),this},else:function(){return r.apply(r,Be(arguments)),this},toString:function(){var t=i();return t&&(t="else{"+t+"}"),Re(["if(",e,"){",a(),"}",t])}})}function a(e,t){function r(){var e="a"+a.length;return a.push(e),e}var a=[];t=t||0;for(var i=0;i=1,r>=2,t)}if(n===Ai){var a=e.data;return new We(a.thisDep,a.contextDep,a.propDep,t)}return new We(n===_i,n===Si,n===ki,t)}function Ve(e,t,n,r,a,i,o,f,u,s,c,l,m,d,p){function h(e){return e.replace(".","_")}function v(e,t,n){var r=h(e);te.push(e),ee[r]=Z[r]=!!n,ne[r]=t}function b(e,t,n){var r=h(e);te.push(e),Array.isArray(n)?(Z[r]=n.slice(),ee[r]=n.slice()):Z[r]=ee[r]=n,re[r]=t}function g(){var e=Ne(),n=e.link,r=e.global;e.id=oe++,e.batchId="0";var a=n(ae),i=e.shared={props:"a0"};Object.keys(ae).forEach(function(e){i[e]=r.def(a,".",e)}),xt.optional(function(){e.CHECK=n(xt),e.commandStr=xt.guessCommand(),e.command=n(e.commandStr),e.assert=function(e,t,r){e("if(!(",t,"))",this.CHECK,".commandRaise(",n(r),",",this.command,");")},ie.invalidBlendCombinations=pf});var o=e.next={},f=e.current={};Object.keys(re).forEach(function(e){Array.isArray(Z[e])&&(o[e]=r.def(i.next,".",e),f[e]=r.def(i.current,".",e))});var u=e.constants={};Object.keys(ie).forEach(function(e){u[e]=r.def(JSON.stringify(ie[e]))}),e.invoke=function(t,r){switch(r.type){case wi:var a=["this",i.context,i.props,e.batchId];return t.def(n(r.data),".call(",a.slice(0,Math.max(r.data.length+1,4)),")");case ki:return t.def(i.props,r.data);case Si:return t.def(i.context,r.data);case _i:return t.def("this",r.data);case Ai:return r.data.append(e,t),r.data.ref}},e.attribCache={};var c={};return e.scopeAttrib=function(e){var r=t.id(e);if(r in c)return c[r];var a=s.scope[r];a||(a=s.scope[r]=new Y);var i=c[r]=n(a);return i},e}function y(e){var t,n=e.static,r=e.dynamic;if(Zi in n){var a=!!n[Zi];t=He(function(e,t){return a}),t.enable=a}else if(Zi in r){var i=r[Zi];t=Qe(i,function(e,t){return e.invoke(t,i)})}return t}function x(e,t){var n=e.static,r=e.dynamic;if(eo in n){var a=n[eo];return a?(a=f.getFramebuffer(a),xt.command(a,"invalid framebuffer object"),He(function(e,t){var n=e.link(a),r=e.shared;t.set(r.framebuffer,".next",n);var i=r.context;return t.set(i,"."+co,n+".width"),t.set(i,"."+lo,n+".height"),n})):He(function(e,t){var n=e.shared;t.set(n.framebuffer,".next","null");var r=n.context;return t.set(r,"."+co,r+"."+vo),t.set(r,"."+lo,r+"."+bo),"null"})}if(eo in r){var i=r[eo];return Qe(i,function(e,t){var n=e.invoke(t,i),r=e.shared,a=r.framebuffer,o=t.def(a,".getFramebuffer(",n,")");xt.optional(function(){e.assert(t,"!"+n+"||"+o,"invalid framebuffer object")}),t.set(a,".next",o);var f=r.context;return t.set(f,"."+co,o+"?"+o+".width:"+f+"."+vo),t.set(f,"."+lo,o+"?"+o+".height:"+f+"."+bo),o})}return null}function w(e,t,n){function r(e){if(e in a){var r=a[e];xt.commandType(r,"object","invalid "+e,n.commandStr);var o,f,u=!0,s=0|r.x,c=0|r.y;return"width"in r?(o=0|r.width,xt.command(o>=0,"invalid "+e,n.commandStr)):u=!1,"height"in r?(f=0|r.height,xt.command(f>=0,"invalid "+e,n.commandStr)):u=!1,new We(!u&&t&&t.thisDep,!u&&t&&t.contextDep,!u&&t&&t.propDep,function(e,t){var n=e.shared.context,a=o;"width"in r||(a=t.def(n,".",co,"-",s));var i=f;return"height"in r||(i=t.def(n,".",lo,"-",c)),[s,c,a,i]})}if(e in i){var l=i[e],m=Qe(l,function(t,n){var r=t.invoke(n,l);xt.optional(function(){t.assert(n,r+"&&typeof "+r+'==="object"',"invalid "+e)});var a=t.shared.context,i=n.def(r,".x|0"),o=n.def(r,".y|0"),f=n.def('"width" in ',r,"?",r,".width|0:","(",a,".",co,"-",i,")"),u=n.def('"height" in ',r,"?",r,".height|0:","(",a,".",lo,"-",o,")");return xt.optional(function(){t.assert(n,f+">=0&&"+u+">=0","invalid "+e)}),[i,o,f,u]});return t&&(m.thisDep=m.thisDep||t.thisDep,m.contextDep=m.contextDep||t.contextDep,m.propDep=m.propDep||t.propDep),m}return t?new We(t.thisDep,t.contextDep,t.propDep,function(e,t){var n=e.shared.context;return[0,0,t.def(n,".",co),t.def(n,".",lo)]}):null}var a=e.static,i=e.dynamic,o=r(Ji);if(o){var f=o;o=new We(o.thisDep,o.contextDep,o.propDep,function(e,t){var n=f.append(e,t),r=e.shared.context;return t.set(r,"."+mo,n[2]),t.set(r,"."+po,n[3]),n})}return{viewport:o,scissor_box:r(Ki)}}function k(e){function n(e){if(e in a){var n=t.id(a[e]);xt.optional(function(){c.shader(bf[e],n,xt.guessCommand())});var r=He(function(){return n});return r.id=n,r}if(e in i){var o=i[e];return Qe(o,function(t,n){var r=t.invoke(n,o),a=n.def(t.shared.strings,".id(",r,")");return xt.optional(function(){n(t.shared.shader,".shader(",bf[e],",",a,",",t.command,");")}),a})}return null}var r,a=e.static,i=e.dynamic,o=n(no),f=n(to),u=null;return Ge(o)&&Ge(f)?(u=c.program(f.id,o.id),r=He(function(e,t){return e.link(u)})):r=new We(o&&o.thisDep||f&&f.thisDep,o&&o.contextDep||f&&f.contextDep,o&&o.propDep||f&&f.propDep,function(e,t){var n,r=e.shared.shader;n=o?o.append(e,t):t.def(r,".",no);var a;a=f?f.append(e,t):t.def(r,".",to);var i=r+".program("+a+","+n;return xt.optional(function(){i+=","+e.command}),t.def(i+")")}),{frag:o,vert:f,progVar:r,program:u}}function S(e,t){function n(){if(ro in f){var e=f[ro];Ue(e)?e=i.getElements(i.create(e,!0)):e&&(e=i.getElements(e),xt.command(e,"invalid elements",t.commandStr));var n=He(function(t,n){if(e){var r=t.link(e);return t.ELEMENTS=r,r}return t.ELEMENTS=null,null});return n.value=e,n}if(ro in u){var r=u[ro];return Qe(r,function(e,t){var n=e.shared,a=n.isBufferArgs,i=n.elements,o=e.invoke(t,r),f=t.def("null"),u=t.def(a,"(",o,")"),s=e.cond(u).then(f,"=",i,".createStream(",o,");").else(f,"=",i,".getElements(",o,");");return xt.optional(function(){e.assert(s.else,"!"+o+"||"+f,"invalid elements")}),t.entry(s),t.exit(e.cond(u).then(i,".destroyStream(",f,");")),e.ELEMENTS=f,f})}return null}function r(){if(ao in f){var e=f[ao];return xt.commandParameter(e,Ln,"invalid primitve",t.commandStr),He(function(t,n){return Ln[e]})}if(ao in u){var n=u[ao];return Qe(n,function(e,t){var r=e.constants.primTypes,a=e.invoke(t,n);return xt.optional(function(){e.assert(t,a+" in "+r,"invalid primitive, must be one of "+Object.keys(Ln))}),t.def(r,"[",a,"]")})}return s?Ge(s)?He(s.value?function(e,t){return t.def(e.ELEMENTS,".primType")}:function(){return Ko}):new We(s.thisDep,s.contextDep,s.propDep,function(e,t){var n=e.ELEMENTS;return t.def(n,"?",n,".primType:",Ko)}):null}function a(e,n){if(e in f){var r=0|f[e];return xt.command(!n||r>=0,"invalid "+e,t.commandStr),He(function(e,t){return n&&(e.OFFSET=r),r})}if(e in u){var a=u[e];return Qe(a,function(t,r){var i=t.invoke(r,a);return n&&(t.OFFSET=i,xt.optional(function(){t.assert(r,i+">=0","invalid "+e)})),i})}return n&&s?He(function(e,t){return e.OFFSET="0",0}):null}function o(){if(io in f){var e=0|f[io];return xt.command("number"==typeof e&&e>=0,"invalid vertex count",t.commandStr),He(function(){return e})}if(io in u){var n=u[io];return Qe(n,function(e,t){var r=e.invoke(t,n);return xt.optional(function(){e.assert(t,"typeof "+r+'==="number"&&'+r+">=0&&"+r+"===("+r+"|0)","invalid vertex count")}),r})}if(s){if(Ge(s)){if(s)return c?new We(c.thisDep,c.contextDep,c.propDep,function(e,t){var n=t.def(e.ELEMENTS,".vertCount-",e.OFFSET);return xt.optional(function(){e.assert(t,n+">=0","invalid vertex offset/element buffer too small")}),n}):He(function(e,t){return t.def(e.ELEMENTS,".vertCount")});var r=He(function(){return-1});return xt.optional(function(){r.MISSING=!0}),r}var a=new We(s.thisDep||c.thisDep,s.contextDep||c.contextDep,s.propDep||c.propDep,function(e,t){var n=e.ELEMENTS;return e.OFFSET?t.def(n,"?",n,".vertCount-",e.OFFSET,":-1"):t.def(n,"?",n,".vertCount:-1")});return xt.optional(function(){a.DYNAMIC=!0}),a}return null}var f=e.static,u=e.dynamic,s=n(),c=a(oo,!0);return{elements:s,primitive:r(),count:o(),instances:a(fo,!1),offset:c}}function _(e,t){var n=e.static,a=e.dynamic,i={};return te.forEach(function(e){function o(t,r){if(e in n){var o=t(n[e]);i[f]=He(function(){return o})}else if(e in a){var u=a[e];i[f]=Qe(u,function(e,t){return r(e,t,e.invoke(t,u))})}}var f=h(e);switch(e){case Ii:case Di:case Ei:case Hi:case Oi:case $i:case Ni:case qi:case Wi:case Mi:return o(function(n){return xt.commandType(n,"boolean",e,t.commandStr),n},function(t,n,r){return xt.optional(function(){t.assert(n,"typeof "+r+'==="boolean"',"invalid flag "+e,t.commandStr)}),r});case zi:return o(function(n){return xt.commandParameter(n,hf,"invalid "+e,t.commandStr),hf[n]},function(t,n,r){var a=t.constants.compareFuncs;return xt.optional(function(){t.assert(n,r+" in "+a,"invalid "+e+", must be one of "+Object.keys(hf))}),n.def(a,"[",r,"]")});case Fi:return o(function(e){return xt.command(he(e)&&2===e.length&&"number"==typeof e[0]&&"number"==typeof e[1]&&e[0]<=e[1],"depth range is 2d array",t.commandStr),e},function(e,t,n){xt.optional(function(){e.assert(t,e.shared.isArrayLike+"("+n+")&&"+n+".length===2&&typeof "+n+'[0]==="number"&&typeof '+n+'[1]==="number"&&'+n+"[0]<="+n+"[1]","depth range must be a 2d array")});var r=t.def("+",n,"[0]"),a=t.def("+",n,"[1]");return[r,a]});case Ci:return o(function(e){xt.commandType(e,"object","blend.func",t.commandStr);var n="srcRGB"in e?e.srcRGB:e.src,r="srcAlpha"in e?e.srcAlpha:e.src,a="dstRGB"in e?e.dstRGB:e.dst,i="dstAlpha"in e?e.dstAlpha:e.dst;return xt.commandParameter(n,df,f+".srcRGB",t.commandStr),xt.commandParameter(r,df,f+".srcAlpha",t.commandStr),xt.commandParameter(a,df,f+".dstRGB",t.commandStr),xt.commandParameter(i,df,f+".dstAlpha",t.commandStr),xt.command(pf.indexOf(n+", "+a)===-1,"unallowed blending combination (srcRGB, dstRGB) = ("+n+", "+a+")",t.commandStr),[df[n],df[a],df[r],df[i]]},function(t,n,r){function a(a,o){var f=n.def('"',a,o,'" in ',r,"?",r,".",a,o,":",r,".",a);return xt.optional(function(){t.assert(n,f+" in "+i,"invalid "+e+"."+a+o+", must be one of "+Object.keys(df))}),f}var i=t.constants.blendFuncs;xt.optional(function(){t.assert(n,r+"&&typeof "+r+'==="object"',"invalid blend func, must be an object")});var o=a("src","RGB"),f=a("dst","RGB");xt.optional(function(){var e=t.constants.invalidBlendCombinations;t.assert(n,e+".indexOf("+o+'+", "+'+f+") === -1 ","unallowed blending combination for (srcRGB, dstRGB)")});var u=n.def(i,"[",o,"]"),s=n.def(i,"[",a("src","Alpha"),"]"),c=n.def(i,"[",f,"]"),l=n.def(i,"[",a("dst","Alpha"),"]");return[u,c,s,l]});case ji:return o(function(n){return"string"==typeof n?(xt.commandParameter(n,X,"invalid "+e,t.commandStr),[X[n],X[n]]):"object"==typeof n?(xt.commandParameter(n.rgb,X,e+".rgb",t.commandStr),xt.commandParameter(n.alpha,X,e+".alpha",t.commandStr),[X[n.rgb],X[n.alpha]]):void xt.commandRaise("invalid blend.equation",t.commandStr)},function(t,n,r){var a=t.constants.blendEquations,i=n.def(),o=n.def(),f=t.cond("typeof ",r,'==="string"');return xt.optional(function(){function n(e,n,r){t.assert(e,r+" in "+a,"invalid "+n+", must be one of "+Object.keys(X))}n(f.then,e,r),t.assert(f.else,r+"&&typeof "+r+'==="object"',"invalid "+e),n(f.else,e+".rgb",r+".rgb"),n(f.else,e+".alpha",r+".alpha")}),f.then(i,"=",o,"=",a,"[",r,"];"),f.else(i,"=",a,"[",r,".rgb];",o,"=",a,"[",r,".alpha];"),n(f),[i,o]});case Ti:return o(function(e){return xt.command(he(e)&&4===e.length,"blend.color must be a 4d array",t.commandStr),$(4,function(t){return+e[t]})},function(e,t,n){return xt.optional(function(){e.assert(t,e.shared.isArrayLike+"("+n+")&&"+n+".length===4","blend.color must be a 4d array")}),$(4,function(e){return t.def("+",n,"[",e,"]")})});case Qi:return o(function(e){return xt.commandType(e,"number",f,t.commandStr),0|e},function(e,t,n){return xt.optional(function(){e.assert(t,"typeof "+n+'==="number"',"invalid stencil.mask")}),t.def(n,"|0")});case Vi:return o(function(n){xt.commandType(n,"object",f,t.commandStr);var r=n.cmp||"keep",a=n.ref||0,i="mask"in n?n.mask:-1;return xt.commandParameter(r,hf,e+".cmp",t.commandStr),xt.commandType(a,"number",e+".ref",t.commandStr),xt.commandType(i,"number",e+".mask",t.commandStr),[hf[r],a,i]},function(e,t,n){var r=e.constants.compareFuncs;xt.optional(function(){function a(){e.assert(t,Array.prototype.join.call(arguments,""),"invalid stencil.func")}a(n+"&&typeof ",n,'==="object"'),a('!("cmp" in ',n,")||(",n,".cmp in ",r,")")});var a=t.def('"cmp" in ',n,"?",r,"[",n,".cmp]",":",of),i=t.def(n,".ref|0"),o=t.def('"mask" in ',n,"?",n,".mask|0:-1");return[a,i,o]});case Yi:case Xi:return o(function(n){xt.commandType(n,"object",f,t.commandStr);var r=n.fail||"keep",a=n.zfail||"keep",i=n.zpass||"keep";return xt.commandParameter(r,vf,e+".fail",t.commandStr),xt.commandParameter(a,vf,e+".zfail",t.commandStr),xt.commandParameter(i,vf,e+".zpass",t.commandStr),[e===Xi?Zo:Jo,vf[r],vf[a],vf[i]]},function(t,n,r){function a(a){return xt.optional(function(){t.assert(n,'!("'+a+'" in '+r+")||("+r+"."+a+" in "+i+")","invalid "+e+"."+a+", must be one of "+Object.keys(vf))}),n.def('"',a,'" in ',r,"?",i,"[",r,".",a,"]:",of)}var i=t.constants.stencilOps;return xt.optional(function(){t.assert(n,r+"&&typeof "+r+'==="object"',"invalid "+e)}),[e===Xi?Zo:Jo,a("fail"),a("zfail"),a("zpass")]});case Ui:return o(function(e){xt.commandType(e,"object",f,t.commandStr);var n=0|e.factor,r=0|e.units;return xt.commandType(n,"number",f+".factor",t.commandStr),xt.commandType(r,"number",f+".units",t.commandStr),[n,r]},function(t,n,r){xt.optional(function(){t.assert(n,r+"&&typeof "+r+'==="object"',"invalid "+e)});var a=n.def(r,".factor|0"),i=n.def(r,".units|0");return[a,i]});case Li:return o(function(e){var n=0;return"front"===e?n=Jo:"back"===e&&(n=Zo),xt.command(!!n,f,t.commandStr),n},function(e,t,n){return xt.optional(function(){e.assert(t,n+'==="front"||'+n+'==="back"',"invalid cull.face")}),t.def(n,'==="front"?',Jo,":",Zo)});case Ri:return o(function(e){return xt.command("number"==typeof e&&e>=r.lineWidthDims[0]&&e<=r.lineWidthDims[1],"invalid line width, must positive number between "+r.lineWidthDims[0]+" and "+r.lineWidthDims[1],t.commandStr),e},function(e,t,n){return xt.optional(function(){e.assert(t,"typeof "+n+'==="number"&&'+n+">="+r.lineWidthDims[0]+"&&"+n+"<="+r.lineWidthDims[1],"invalid line width")}),n});case Bi:return o(function(e){return xt.commandParameter(e,gf,f,t.commandStr),gf[e]},function(e,t,n){return xt.optional(function(){e.assert(t,n+'==="cw"||'+n+'==="ccw"',"invalid frontFace, must be one of cw,ccw")}),t.def(n+'==="cw"?'+ef+":"+tf)});case Pi:return o(function(e){return xt.command(he(e)&&4===e.length,"color.mask must be length 4 array",t.commandStr),e.map(function(e){return!!e})},function(e,t,n){return xt.optional(function(){e.assert(t,e.shared.isArrayLike+"("+n+")&&"+n+".length===4","invalid color.mask")}),$(4,function(e){return"!!"+n+"["+e+"]"})});case Gi:return o(function(e){xt.command("object"==typeof e&&e,f,t.commandStr);var n="value"in e?e.value:1,r=!!e.invert;return xt.command("number"==typeof n&&n>=0&&n<=1,"sample.coverage.value must be a number between 0 and 1",t.commandStr),[n,r]},function(e,t,n){xt.optional(function(){e.assert(t,n+"&&typeof "+n+'==="object"',"invalid sample.coverage")});var r=t.def('"value" in ',n,"?+",n,".value:1"),a=t.def("!!",n,".invert");return[r,a]})}}),i}function A(e,t){var n=e.static,r=e.dynamic,a={};return Object.keys(n).forEach(function(e){var r,i=n[e];if("number"==typeof i||"boolean"==typeof i)r=He(function(){return i});else if("function"==typeof i){var o=i._reglType;"texture2d"===o||"textureCube"===o?r=He(function(e){return e.link(i)}):"framebuffer"===o||"framebufferCube"===o?(xt.command(i.color.length>0,'missing color attachment for framebuffer sent to uniform "'+e+'"',t.commandStr),r=He(function(e){return e.link(i.color[0])})):xt.commandRaise('invalid data for uniform "'+e+'"',t.commandStr)}else he(i)?r=He(function(t){var n=t.global.def("[",$(i.length,function(n){return xt.command("number"==typeof i[n]||"boolean"==typeof i[n],"invalid uniform "+e,t.commandStr),i[n]}),"]");return n}):xt.commandRaise('invalid or missing data for uniform "'+e+'"',t.commandStr);r.value=i,a[e]=r}),Object.keys(r).forEach(function(e){var t=r[e];a[e]=Qe(t,function(e,n){return e.invoke(n,t)})}),a}function E(e,n){var r=e.static,i=e.dynamic,o={};return Object.keys(r).forEach(function(e){var i=r[e],f=t.id(e),u=new Y;if(Ue(i))u.state=yi,u.buffer=a.getBuffer(a.create(i,yo,!1,!0)),u.type=0;else{var s=a.getBuffer(i);if(s)u.state=yi,u.buffer=s,u.type=0;else if(xt.command("object"==typeof i&&i,"invalid data for attribute "+e,n.commandStr),i.constant){var c=i.constant;u.buffer="null",u.state=xi,"number"==typeof c?u.x=c:(xt.command(he(c)&&c.length>0&&c.length<=4,"invalid constant for attribute "+e,n.commandStr),bi.forEach(function(e,t){t=0,'invalid offset for attribute "'+e+'"',n.commandStr);var m=0|i.stride;xt.command(m>=0&&m<256,'invalid stride for attribute "'+e+'", must be integer betweeen [0, 255]',n.commandStr);var d=0|i.size;xt.command(!("size"in i)||d>0&&d<=4,'invalid size for attribute "'+e+'", must be 1,2,3,4',n.commandStr);var p=!!i.normalized,h=0;"type"in i&&(xt.commandParameter(i.type,xn,"invalid type for attribute "+e,n.commandStr),h=xn[i.type]);var v=0|i.divisor;"divisor"in i&&(xt.command(0===v||K,'cannot specify divisor for attribute "'+e+'", instancing not supported',n.commandStr),xt.command(v>=0,'invalid divisor for attribute "'+e+'"',n.commandStr)),xt.optional(function(){var t=n.commandStr,r=["buffer","offset","divisor","normalized","type","size","stride"];Object.keys(i).forEach(function(n){xt.command(r.indexOf(n)>=0,'unknown parameter "'+n+'" for attribute pointer "'+e+'" (valid parameters are '+r+")",t)})}),u.buffer=s,u.state=yi,u.size=d,u.normalized=p,u.type=h||s.dtype,u.offset=l,u.stride=m,u.divisor=v}}o[e]=He(function(e,t){var n=e.attribCache;if(f in n)return n[f];var r={isStream:!1};return Object.keys(u).forEach(function(e){r[e]=u[e]}),u.buffer&&(r.buffer=e.link(u.buffer),r.type=r.type||r.buffer+".dtype"),n[f]=r,r})}),Object.keys(i).forEach(function(e){function t(t,r){function a(e){r(s[e],"=",i,".",e,"|0;")}var i=t.invoke(r,n),o=t.shared,f=o.isBufferArgs,u=o.buffer;xt.optional(function(){t.assert(r,i+"&&(typeof "+i+'==="object"||typeof '+i+'==="function")&&('+f+"("+i+")||"+u+".getBuffer("+i+")||"+u+".getBuffer("+i+".buffer)||"+f+"("+i+'.buffer)||("constant" in '+i+"&&(typeof "+i+'.constant==="number"||'+o.isArrayLike+"("+i+".constant))))",'invalid dynamic attribute "'+e+'"')});var s={isStream:r.def(!1)},c=new Y;c.state=yi,Object.keys(c).forEach(function(e){s[e]=r.def(""+c[e])});var l=s.buffer,m=s.type;return r("if(",f,"(",i,")){",s.isStream,"=true;",l,"=",u,".createStream(",yo,",",i,");",m,"=",l,".dtype;","}else{",l,"=",u,".getBuffer(",i,");","if(",l,"){",m,"=",l,".dtype;",'}else if("constant" in ',i,"){",s.state,"=",xi,";","if(typeof "+i+'.constant === "number"){',s[bi[0]],"=",i,".constant;",bi.slice(1).map(function(e){return s[e]}).join("="),"=0;","}else{",bi.map(function(e,t){return s[e]+"="+i+".constant.length>="+t+"?"+i+".constant["+t+"]:0;"}).join(""),"}}else{","if(",f,"(",i,".buffer)){",l,"=",u,".createStream(",yo,",",i,".buffer);","}else{",l,"=",u,".getBuffer(",i,".buffer);","}",m,'="type" in ',i,"?",o.glTypes,"[",i,".type]:",l,".dtype;",s.normalized,"=!!",i,".normalized;"),a("size"),a("offset"),a("stride"),a("divisor"),r("}}"),r.exit("if(",s.isStream,"){",u,".destroyStream(",l,");","}"),s}var n=i[e];o[e]=Qe(n,t)}),o}function D(e){var t=e.static,n=e.dynamic,r={};return Object.keys(t).forEach(function(e){var n=t[e];r[e]=He(function(e,t){return"number"==typeof n||"boolean"==typeof n?""+n:e.link(n)})}),Object.keys(n).forEach(function(e){var t=n[e];r[e]=Qe(t,function(e,n){return e.invoke(n,t)})}),r}function T(e,t,n,r,a){function i(e){var t=s[e];t&&(l[e]=t)}var o=e.static,f=e.dynamic;xt.optional(function(){function e(e){Object.keys(e).forEach(function(e){xt.command(t.indexOf(e)>=0,'unknown parameter "'+e+'"',a.commandStr)})}var t=[eo,to,no,ro,ao,oo,io,fo,Zi].concat(te);e(o),e(f)});var u=x(e,a),s=w(e,u,a),c=S(e,a),l=_(e,a),m=k(e,a);i(Ji),i(h(Ki));var d=Object.keys(l).length>0,p={framebuffer:u,draw:c,shader:m,state:l,dirty:d};return p.profile=y(e,a),p.uniforms=A(n,a),p.attributes=E(t,a),p.context=D(r,a),p}function j(e,t,n){var r=e.shared,a=r.context,i=e.scope();Object.keys(n).forEach(function(r){t.save(a,"."+r);var o=n[r];i(a,".",r,"=",o.append(e,t),";")}),t(i)}function C(e,t,n,r){var a,i=e.shared,o=i.gl,f=i.framebuffer;J&&(a=t.def(i.extensions,".webgl_draw_buffers"));var u,s=e.constants,c=s.drawBuffer,l=s.backBuffer;u=n?n.append(e,t):t.def(f,".next"),r||t("if(",u,"!==",f,".cur){"),t("if(",u,"){",o,".bindFramebuffer(",lf,",",u,".framebuffer);"),J&&t(a,".drawBuffersWEBGL(",c,"[",u,".colorAttachments.length]);"),t("}else{",o,".bindFramebuffer(",lf,",null);"),J&&t(a,".drawBuffersWEBGL(",l,");"),t("}",f,".cur=",u,";"),r||t("}")}function O(e,t,n){var r=e.shared,a=r.gl,i=e.current,o=e.next,f=r.current,u=r.next,s=e.cond(f,".dirty");te.forEach(function(t){var r=h(t);if(!(r in n.state)){var c,l;if(r in o){c=o[r],l=i[r];var m=$(Z[r].length,function(e){return s.def(c,"[",e,"]")});s(e.cond(m.map(function(e,t){return e+"!=="+l+"["+t+"]"}).join("||")).then(a,".",re[r],"(",m,");",m.map(function(e,t){return l+"["+t+"]="+e}).join(";"),";"))}else{c=s.def(u,".",r);var d=e.cond(c,"!==",f,".",r);s(d),r in ne?d(e.cond(c).then(a,".enable(",ne[r],");").else(a,".disable(",ne[r],");"),f,".",r,"=",c,";"):d(a,".",re[r],"(",c,");",f,".",r,"=",c,";")}}}),0===Object.keys(n.state).length&&s(f,".dirty=false;"),t(s)}function z(e,t,n,r){var a=e.shared,i=e.current,o=a.current,f=a.gl;qe(Object.keys(n)).forEach(function(a){var u=n[a];if(!r||r(u)){var s=u.append(e,t);if(ne[a]){var c=ne[a];Ge(u)?s?t(f,".enable(",c,");"):t(f,".disable(",c,");"):t(e.cond(s).then(f,".enable(",c,");").else(f,".disable(",c,");")),t(o,".",a,"=",s,";")}else if(he(s)){var l=i[a];t(f,".",re[a],"(",s,");",s.map(function(e,t){return l+"["+t+"]="+e}).join(";"),";")}else t(f,".",re[a],"(",s,");",o,".",a,"=",s,";")}})}function F(e,t){K&&(e.instancing=t.def(e.shared.extensions,".angle_instanced_arrays"))}function M(e,t,n,r,a){function i(){return"undefined"==typeof performance?"Date.now()":"performance.now()"}function o(e){s=t.def(),e(s,"=",i(),";"),"string"==typeof a?e(p,".count+=",a,";"):e(p,".count++;"),d&&(r?(c=t.def(),e(c,"=",v,".getNumPendingQueries();")):e(v,".beginQuery(",p,");"))}function f(e){e(p,".cpuTime+=",i(),"-",s,";"),d&&(r?e(v,".pushScopeStats(",c,",",v,".getNumPendingQueries(),",p,");"):e(v,".endQuery();"))}function u(e){var n=t.def(h,".profile");t(h,".profile=",e,";"),t.exit(h,".profile=",n,";")}var s,c,l,m=e.shared,p=e.stats,h=m.current,v=m.timer,b=n.profile;if(b){if(Ge(b))return void(b.enable?(o(t),f(t.exit),u("true")):u("false"));l=b.append(e,t),u(l)}else l=t.def(h,".profile");var g=e.block();o(g),t("if(",l,"){",g,"}");var y=e.block();f(y),t.exit("if(",l,"){",y,"}")}function P(e,t,n,r,a){function i(e){switch(e){case Po:case Ro:case Wo:return 2;case Io:case No:case Go:return 3;case Lo:case Uo:case Ho:return 4;default:return 1}}function o(n,r,a){function i(){t("if(!",c,".buffer){",u,".enableVertexAttribArray(",s,");}");var n,i=a.type; 4 | if(n=a.size?t.def(a.size,"||",r):r,t("if(",c,".type!==",i,"||",c,".size!==",n,"||",p.map(function(e){return c+"."+e+"!=="+a[e]}).join("||"),"){",u,".bindBuffer(",yo,",",m,".buffer);",u,".vertexAttribPointer(",[s,n,i,a.normalized,a.stride,a.offset],");",c,".type=",i,";",c,".size=",n,";",p.map(function(e){return c+"."+e+"="+a[e]+";"}).join(""),"}"),K){var o=a.divisor;t("if(",c,".divisor!==",o,"){",e.instancing,".vertexAttribDivisorANGLE(",[s,o],");",c,".divisor=",o,";}")}}function o(){t("if(",c,".buffer){",u,".disableVertexAttribArray(",s,");","}if(",bi.map(function(e,t){return c+"."+e+"!=="+d[t]}).join("||"),"){",u,".vertexAttrib4f(",s,",",d,");",bi.map(function(e,t){return c+"."+e+"="+d[t]+";"}).join(""),"}")}var u=f.gl,s=t.def(n,".location"),c=t.def(f.attributes,"[",s,"]"),l=a.state,m=a.buffer,d=[a.x,a.y,a.z,a.w],p=["buffer","normalized","offset","stride"];l===yi?i():l===xi?o():(t("if(",l,"===",yi,"){"),i(),t("}else{"),o(),t("}"))}var f=e.shared;r.forEach(function(r){var f,u=r.name,s=n.attributes[u];if(s){if(!a(s))return;f=s.append(e,t)}else{if(!a(yf))return;var c=e.scopeAttrib(u);xt.optional(function(){e.assert(t,c+".state","missing attribute "+u)}),f={},Object.keys(new Y).forEach(function(e){f[e]=t.def(c,".",e)})}o(e.link(r),i(r.info.type),f)})}function I(e,n,r,a,i){for(var o,f=e.shared,u=f.gl,s=0;s1?$(w,function(e){return c+"["+e+"]"}):c);n(");")}}function L(e,t,n,r){function a(){var a,i=m.elements,o=t;return i?((i.contextDep&&r.contextDynamic||i.propDep)&&(o=n),a=i.append(e,o)):a=o.def(l,".",ro),a&&o("if("+a+")"+c+".bindBuffer("+xo+","+a+".buffer.buffer);"),a}function i(){var a,i=m.count,o=t;return i?((i.contextDep&&r.contextDynamic||i.propDep)&&(o=n),a=i.append(e,o),xt.optional(function(){i.MISSING&&e.assert(t,"false","missing vertex count"),i.DYNAMIC&&e.assert(o,a+">=0","missing vertex count")})):(a=o.def(l,".",io),xt.optional(function(){e.assert(o,a+">=0","missing vertex count")})),a}function o(a){var i=m[a];return i?i.contextDep&&r.contextDynamic||i.propDep?i.append(e,n):i.append(e,t):t.def(l,".",a)}function f(){function e(){n(g,".drawElementsInstancedANGLE(",[p,v,y,h+"<<(("+y+"-"+gi+")>>1)",b],");")}function t(){n(g,".drawArraysInstancedANGLE(",[p,h,v,b],");")}d?x?e():(n("if(",d,"){"),e(),n("}else{"),t(),n("}")):t()}function u(){function e(){n(c+".drawElements("+[p,v,y,h+"<<(("+y+"-"+gi+")>>1)"]+");")}function t(){n(c+".drawArrays("+[p,h,v]+");")}d?x?e():(n("if(",d,"){"),e(),n("}else{"),t(),n("}")):t()}var s=e.shared,c=s.gl,l=s.draw,m=r.draw,d=a(),p=o(ao),h=o(oo),v=i();if("number"==typeof v){if(0===v)return}else n("if(",v,"){"),n.exit("}");var b,g;K&&(b=o(fo),g=e.instancing);var y=d+".type",x=m.elements&&Ge(m.elements);K&&("number"!=typeof b||b>=0)?"string"==typeof b?(n("if(",b,">0){"),f(),n("}else if(",b,"<0){"),u(),n("}")):f():u()}function B(e,t,n,r,a){var i=g(),o=i.proc("body",a);return xt.optional(function(){i.commandStr=t.commandStr,i.command=i.link(t.commandStr)}),K&&(i.instancing=o.def(i.shared.extensions,".angle_instanced_arrays")),e(i,o,n,r),i.compile().body}function R(e,t,n,r){F(e,t),P(e,t,n,r.attributes,function(){return!0}),I(e,t,n,r.uniforms,function(){return!0}),L(e,t,t,n)}function N(e,t){var n=e.proc("draw",1);F(e,n),j(e,n,t.context),C(e,n,t.framebuffer),O(e,n,t),z(e,n,t.state),M(e,n,t,!1,!0);var r=t.shader.progVar.append(e,n);if(n(e.shared.gl,".useProgram(",r,".program);"),t.shader.program)R(e,n,t,t.shader.program);else{var a=e.global.def("{}"),i=n.def(r,".id"),o=n.def(a,"[",i,"]");n(e.cond(o).then(o,".call(this,a0);").else(o,"=",a,"[",i,"]=",e.link(function(n){return B(R,e,t,n,1)}),"(",r,");",o,".call(this,a0);"))}Object.keys(t.state).length>0&&n(e.shared.current,".dirty=true;")}function U(e,t,n,r){function a(){return!0}e.batchId="a1",F(e,t),P(e,t,n,r.attributes,a),I(e,t,n,r.uniforms,a),L(e,t,t,n)}function q(e,t,n,r){function a(e){return e.contextDep&&o||e.propDep}function i(e){return!a(e)}F(e,t);var o=n.contextDep,f=t.def(),u="a0",s="a1",c=t.def();e.shared.props=c,e.batchId=f;var l=e.scope(),m=e.scope();if(t(l.entry,"for(",f,"=0;",f,"<",s,";++",f,"){",c,"=",u,"[",f,"];",m,"}",l.exit),n.needsContext&&j(e,m,n.context),n.needsFramebuffer&&C(e,m,n.framebuffer),z(e,m,n.state,a),n.profile&&a(n.profile)&&M(e,m,n,!1,!0),r)P(e,l,n,r.attributes,i),P(e,m,n,r.attributes,a),I(e,l,n,r.uniforms,i),I(e,m,n,r.uniforms,a),L(e,l,m,n);else{var d=e.global.def("{}"),p=n.shader.progVar.append(e,m),h=m.def(p,".id"),v=m.def(d,"[",h,"]");m(e.shared.gl,".useProgram(",p,".program);","if(!",v,"){",v,"=",d,"[",h,"]=",e.link(function(t){return B(U,e,n,t,2)}),"(",p,");}",v,".call(this,a0[",f,"],",f,");")}}function W(e,t){function n(e){return e.contextDep&&a||e.propDep}var r=e.proc("batch",2);e.batchId="0",F(e,r);var a=!1,i=!0;Object.keys(t.context).forEach(function(e){a=a||t.context[e].propDep}),a||(j(e,r,t.context),i=!1);var o=t.framebuffer,f=!1;o?(o.propDep?a=f=!0:o.contextDep&&a&&(f=!0),f||C(e,r,o)):C(e,r,null),t.state.viewport&&t.state.viewport.propDep&&(a=!0),O(e,r,t),z(e,r,t.state,function(e){return!n(e)}),t.profile&&n(t.profile)||M(e,r,t,!1,"a1"),t.contextDep=a,t.needsContext=i,t.needsFramebuffer=f;var u=t.shader.progVar;if(u.contextDep&&a||u.propDep)q(e,r,t,null);else{var s=u.append(e,r);if(r(e.shared.gl,".useProgram(",s,".program);"),t.shader.program)q(e,r,t,t.shader.program);else{var c=e.global.def("{}"),l=r.def(s,".id"),m=r.def(c,"[",l,"]");r(e.cond(m).then(m,".call(this,a0,a1);").else(m,"=",c,"[",l,"]=",e.link(function(n){return B(q,e,t,n,2)}),"(",s,");",m,".call(this,a0,a1);"))}}Object.keys(t.state).length>0&&r(e.shared.current,".dirty=true;")}function G(e,n){function r(t){var r=n.shader[t];r&&a.set(i.shader,"."+t,r.append(e,a))}var a=e.proc("scope",3);e.batchId="a2";var i=e.shared,o=i.current;j(e,a,n.context),n.framebuffer&&n.framebuffer.append(e,a),qe(Object.keys(n.state)).forEach(function(t){var r=n.state[t],o=r.append(e,a);he(o)?o.forEach(function(n,r){a.set(e.next[t],"["+r+"]",n)}):a.set(i.next,"."+t,o)}),M(e,a,n,!0,!0),[ro,oo,io,fo,ao].forEach(function(t){var r=n.draw[t];r&&a.set(i.draw,"."+t,""+r.append(e,a))}),Object.keys(n.uniforms).forEach(function(r){a.set(i.uniforms,"["+t.id(r)+"]",n.uniforms[r].append(e,a))}),Object.keys(n.attributes).forEach(function(t){var r=n.attributes[t].append(e,a),i=e.scopeAttrib(t);Object.keys(new Y).forEach(function(e){a.set(i,"."+e,r[e])})}),r(to),r(no),Object.keys(n.state).length>0&&(a(o,".dirty=true;"),a.exit(o,".dirty=true;")),a("a1(",e.shared.context,",a0,",e.batchId,");")}function H(e){if("object"==typeof e&&!he(e)){for(var t=Object.keys(e),n=0;n=0;--e){var n=G[e];n&&n(T,null,0)}b.flush(),_&&_.update()}function n(){!$&&G.length>0&&($=_t.next(t))}function r(){$&&(_t.cancel(t),$=null)}function a(e){e.preventDefault(),y=!0,r(),H.forEach(function(e){e()})}function i(e){b.getError(),y=!1,x.restore(),P.restore(),z.restore(),I.restore(),L.restore(),B.restore(),_&&_.restore(),R.procs.refresh(),n(),Q.forEach(function(e){e()})}function o(){G.length=0,r(),W&&(W.removeEventListener(Tf,a),W.removeEventListener(jf,i)),P.clear(),B.clear(),L.clear(),I.clear(),F.clear(),z.clear(),_&&_.clear(),X.forEach(function(e){e()})}function f(e){function t(e){function t(e){if(e in n){var t=n[e];delete n[e],Object.keys(t).forEach(function(r){n[e+"."+r]=t[r]})}}var n=Ze({},e);return delete n.uniforms,delete n.attributes,delete n.context,"stencil"in n&&n.stencil.op&&(n.stencil.opBack=n.stencil.opFront=n.stencil.op,delete n.stencil.op),t("blend"),t("depth"),t("cull"),t("stencil"),t("polygonOffset"),t("scissor"),t("sample"),n}function n(e){var t={},n={};return Object.keys(e).forEach(function(r){var a=e[r];St.isDynamic(a)?n[r]=St.unbox(a,r):t[r]=a}),{dynamic:n,static:t}}function r(e){for(;p.length0)return m.call(this,r(0|e),0|e)}else{if(!Array.isArray(e))return l.call(this,e);if(e.length)return m.call(this,e,e.length)}}xt(!!e,"invalid args to regl({...})"),xt.type(e,"object","invalid args to regl({...})");var i=n(e.context||{}),o=n(e.uniforms||{}),f=n(e.attributes||{}),u=n(t(e)),s={gpuTime:0,cpuTime:0,count:0},c=R.compile(u,f,o,i,s),l=c.draw,m=c.batch,d=c.scope,p=[];return Ze(a,{stats:s})}function u(e,t){var n=0;R.procs.poll();var r=t.color;r&&(b.clearColor(+r[0]||0,+r[1]||0,+r[2]||0,+r[3]||0),n|=_f),"depth"in t&&(b.clearDepth(+t.depth),n|=Af),"stencil"in t&&(b.clearStencil(0|t.stencil),n|=Ef),xt(!!n,"called regl.clear with no buffer specified"),b.clear(n)}function s(e){if(xt("object"==typeof e&&e,"regl.clear() takes an object as input"),"framebuffer"in e)if(e.framebuffer&&"framebufferCube"===e.framebuffer_reglType)for(var t=0;t<6;++t)K(Ze({framebuffer:e.framebuffer.faces[t]},e),u);else K(e,u);else u(null,e)}function c(e){function t(){function t(){var e=Xe(G,t);G[e]=G[G.length-1],G.length-=1,G.length<=0&&r()}var n=Xe(G,e);xt(n>=0,"cannot cancel a frame twice"),G[n]=t}return xt.type(e,"function","regl.frame() callback must be a function"),G.push(e),n(),{cancel:t}}function l(){var e=q.viewport,t=q.scissor_box;e[0]=e[1]=t[0]=t[1]=0,T.viewportWidth=T.framebufferWidth=T.drawingBufferWidth=e[2]=t[2]=b.drawingBufferWidth,T.viewportHeight=T.framebufferHeight=T.drawingBufferHeight=e[3]=t[3]=b.drawingBufferHeight}function m(){T.tick+=1,T.time=p(),l(),R.procs.poll()}function d(){l(),R.procs.refresh(),_&&_.update()}function p(){return(At()-A)/1e3}function h(e,t){xt.type(t,"function","listener callback must be a function");var n;switch(e){case"frame":return c(t);case"lost":n=H;break;case"restore":n=Q;break;case"destroy":n=X;break;default:xt.raise("invalid event, must be one of frame,lost,restore,destroy")}return n.push(t),{cancel:function(){for(var e=0;e=0},read:U,destroy:o,_gl:b,_refresh:d,poll:function(){m(),_&&_.update()},now:p,stats:k});return v.onDone(null,J),J}var Ke={"[object Int8Array]":5120,"[object Int16Array]":5122,"[object Int32Array]":5124,"[object Uint8Array]":5121,"[object Uint8ClampedArray]":5121,"[object Uint16Array]":5123,"[object Uint32Array]":5125,"[object Float32Array]":5126,"[object Float64Array]":5121,"[object ArrayBuffer]":5121},Je=function(e){return Object.prototype.toString.call(e)in Ke},Ze=function(e,t){for(var n=Object.keys(t),r=0;r=2,"invalid renderbuffer shape"),i=0|d[0],o=0|d[1]}else"radius"in m&&(i=o=0|m.radius),"width"in m&&(i=0|m.width),"height"in m&&(o=0|m.height);"format"in m&&(xt.parameter(m.format,s,"invalid renderbuffer format"),u=s[m.format])}else"number"==typeof t?(i=0|t,o="number"==typeof r?0|r:i):t?xt.raise("invalid arguments to renderbuffer constructor"):i=o=1;if(xt(i>0&&o>0&&i<=n.maxRenderbufferSize&&o<=n.maxRenderbufferSize,"invalid renderbuffer size"),i!==l.width||o!==l.height||u!==l.format)return f.width=l.width=i,f.height=l.height=o,l.format=u,e.bindRenderbuffer(va,l.renderbuffer),e.renderbufferStorage(va,u,i,o),a.profile&&(l.stats.size=ze(l.format,l.width,l.height)),f.format=c[l.format],f}function u(t,r){var i=0|t,o=0|r||i;return i===l.width&&o===l.height?f:(xt(i>0&&o>0&&i<=n.maxRenderbufferSize&&o<=n.maxRenderbufferSize,"invalid renderbuffer size"),f.width=l.width=i,f.height=l.height=o,e.bindRenderbuffer(va,l.renderbuffer),e.renderbufferStorage(va,l.format,i,o),a.profile&&(l.stats.size=ze(l.format,l.width,l.height)),f)}var l=new i(e.createRenderbuffer());return m[l.id]=l,r.renderbufferCount++,f(t,o),f.resize=u,f._reglType="renderbuffer",f._renderbuffer=l,a.profile&&(f.stats=l.stats),f.destroy=function(){l.decRef()},f}function u(){en(m).forEach(function(t){t.renderbuffer=e.createRenderbuffer(),e.bindRenderbuffer(va,t.renderbuffer),e.renderbufferStorage(va,t.format,t.width,t.height)}),e.bindRenderbuffer(va,null)}var s={rgba4:ba,rgb565:ya,"rgb5 a1":ga,depth:xa,stencil:wa,"depth stencil":ka};t.ext_srgb&&(s.srgba=Sa),t.ext_color_buffer_half_float&&(s.rgba16f=Aa,s.rgb16f=Ea),t.webgl_color_buffer_float&&(s.rgba32f=_a);var c=[];Object.keys(s).forEach(function(e){var t=s[e];c[t]=e});var l=0,m={};return i.prototype.decRef=function(){--this.refCount<=0&&o(this)},a.profile&&(r.getTotalRenderbufferSize=function(){var e=0;return Object.keys(m).forEach(function(t){e+=m[t].stats.size}),e}),{create:f,clear:function(){en(m).forEach(o)},restore:u}},ja=36160,Ca=36161,Oa=3553,za=34069,Fa=36064,Ma=36096,Pa=36128,Ia=33306,La=36053,Ba=36054,Ra=36055,Na=36057,Ua=36061,qa=36193,Wa=5121,Ga=5126,Ha=6408,Qa=6402,Va=[Ha],Ya=[];Ya[Ha]=4;var Xa=[];Xa[Wa]=1,Xa[Ga]=4,Xa[qa]=2;var $a=32854,Ka=32855,Ja=36194,Za=33189,ei=36168,ti=34041,ni=35907,ri=34836,ai=34842,ii=34843,oi=[$a,Ka,Ja,ni,ai,ii,ri],fi={};fi[La]="complete",fi[Ba]="incomplete attachment",fi[Na]="incomplete dimensions",fi[Ra]="incomplete, missing attachment",fi[Ua]="unsupported";var ui=5126,si=35632,ci=35633,li=35718,mi=35721,di=6408,pi=5121,hi=3333,vi=5126,bi="xyzw".split(""),gi=5121,yi=1,xi=2,wi=0,ki=1,Si=2,_i=3,Ai=4,Ei="dither",Di="blend.enable",Ti="blend.color",ji="blend.equation",Ci="blend.func",Oi="depth.enable",zi="depth.func",Fi="depth.range",Mi="depth.mask",Pi="colorMask",Ii="cull.enable",Li="cull.face",Bi="frontFace",Ri="lineWidth",Ni="polygonOffset.enable",Ui="polygonOffset.offset",qi="sample.alpha",Wi="sample.enable",Gi="sample.coverage",Hi="stencil.enable",Qi="stencil.mask",Vi="stencil.func",Yi="stencil.opFront",Xi="stencil.opBack",$i="scissor.enable",Ki="scissor.box",Ji="viewport",Zi="profile",eo="framebuffer",to="vert",no="frag",ro="elements",ao="primitive",io="count",oo="offset",fo="instances",uo="Width",so="Height",co=eo+uo,lo=eo+so,mo=Ji+uo,po=Ji+so,ho="drawingBuffer",vo=ho+uo,bo=ho+so,go=[Ci,ji,Vi,Yi,Xi,Gi,Ji,Ki,Ui],yo=34962,xo=34963,wo=35632,ko=35633,So=3553,_o=34067,Ao=2884,Eo=3042,Do=3024,To=2960,jo=2929,Co=3089,Oo=32823,zo=32926,Fo=32928,Mo=5126,Po=35664,Io=35665,Lo=35666,Bo=5124,Ro=35667,No=35668,Uo=35669,qo=35670,Wo=35671,Go=35672,Ho=35673,Qo=35674,Vo=35675,Yo=35676,Xo=35678,$o=35680,Ko=4,Jo=1028,Zo=1029,ef=2304,tf=2305,nf=32775,rf=32776,af=519,of=7680,ff=0,uf=1,sf=32774,cf=513,lf=36160,mf=36064,df={0:0,1:1,zero:0,one:1,"src color":768,"one minus src color":769,"src alpha":770,"one minus src alpha":771,"dst color":774,"one minus dst color":775,"dst alpha":772,"one minus dst alpha":773,"constant color":32769,"one minus constant color":32770,"constant alpha":32771,"one minus constant alpha":32772,"src alpha saturate":776},pf=["constant color, constant alpha","one minus constant color, constant alpha","constant color, one minus constant alpha","one minus constant color, one minus constant alpha","constant alpha, constant color","constant alpha, one minus constant color","one minus constant alpha, constant color","one minus constant alpha, one minus constant color"],hf={never:512,less:513,"<":513,equal:514,"=":514,"==":514,"===":514,lequal:515,"<=":515,greater:516,">":516,notequal:517,"!=":517,"!==":517,gequal:518,">=":518,always:519},vf={0:0,zero:0,keep:7680,replace:7681,increment:7682,decrement:7683,"increment wrap":34055,"decrement wrap":34056,invert:5386},bf={frag:wo,vert:ko},gf={cw:ef,ccw:tf},yf=new We(!1,!1,!1,function(){}),xf=34918,wf=34919,kf=35007,Sf=function(e,t){function n(){return m.pop()||l.createQueryEXT()}function r(e){m.push(e)}function a(e){var t=n();l.beginQueryEXT(kf,t),d.push(t),s(d.length-1,d.length,e)}function i(){l.endQueryEXT(kf)}function o(){this.startQueryIndex=-1,this.endQueryIndex=-1,this.sum=0,this.stats=null}function f(){return p.pop()||new o}function u(e){p.push(e)}function s(e,t,n){var r=f();r.startQueryIndex=e,r.endQueryIndex=t,r.sum=0,r.stats=n,h.push(r)}function c(){var e,t,n=d.length;if(0!==n){b.length=Math.max(b.length,n+1),v.length=Math.max(v.length,n+1),v[0]=0,b[0]=0;var a=0;for(e=0,t=0;t