diff --git a/shared/static/scripts/sx-browser.js b/shared/static/scripts/sx-browser.js index d24b459..8198d2f 100644 --- a/shared/static/scripts/sx-browser.js +++ b/shared/static/scripts/sx-browser.js @@ -59,15 +59,6 @@ function RawHTML(html) { this.html = html; } RawHTML.prototype._raw = true; - function StyleValue(className, declarations, mediaRules, pseudoRules, keyframes) { - this.className = className; - this.declarations = declarations || ""; - this.mediaRules = mediaRules || []; - this.pseudoRules = pseudoRules || []; - this.keyframes = keyframes || []; - } - StyleValue.prototype._styleValue = true; - function isSym(x) { return x != null && x._sym === true; } function isKw(x) { return x != null && x._kw === true; } @@ -103,7 +94,6 @@ if (x._component) return "component"; if (x._macro) return "macro"; if (x._raw) return "raw-html"; - if (x._styleValue) return "style-value"; if (typeof Node !== "undefined" && x instanceof Node) return "dom-node"; if (Array.isArray(x)) return "list"; if (typeof x === "object") return "dict"; @@ -150,27 +140,6 @@ function isComponent(x) { return x != null && x._component === true; } function isMacro(x) { return x != null && x._macro === true; } - function isStyleValue(x) { return x != null && x._styleValue === true; } - function styleValueClass(x) { return x.className; } - function styleValue_p(x) { return x != null && x._styleValue === true; } - - function buildKeyframes(kfName, steps, env) { - // Platform implementation of defkeyframes - var parts = []; - for (var i = 0; i < steps.length; i++) { - var step = steps[i]; - var selector = isSym(step[0]) ? step[0].name : String(step[0]); - var body = trampoline(evalExpr(step[1], env)); - var decls = isStyleValue(body) ? body.declarations : String(body); - parts.push(selector + "{" + decls + "}"); - } - var kfRule = "@keyframes " + kfName + "{" + parts.join("") + "}"; - var cn = "sx-ref-kf-" + kfName; - var sv = new StyleValue(cn, "animation-name:" + kfName, [], [], [[kfName, kfRule]]); - env[kfName] = sv; - return sv; - } - function envHas(env, name) { return name in env; } function envGet(env, name) { return env[name]; } function envSet(env, name, val) { env[name] = val; } @@ -384,29 +353,6 @@ PRIMITIVES["strip-tags"] = function(s) { return String(s).replace(/<[^>]+>/g, ""); }; - // stdlib.style - PRIMITIVES["css"] = function() { - var atoms = []; - for (var i = 0; i < arguments.length; i++) { - var a = arguments[i]; - if (isNil(a) || a === false) continue; - atoms.push(isKw(a) ? a.name : String(a)); - } - if (!atoms.length) return NIL; - return new StyleValue("sx-" + atoms.join("-"), atoms.join(";"), [], [], []); - }; - PRIMITIVES["merge-styles"] = function() { - var valid = []; - for (var i = 0; i < arguments.length; i++) { - if (isStyleValue(arguments[i])) valid.push(arguments[i]); - } - if (!valid.length) return NIL; - if (valid.length === 1) return valid[0]; - var allDecls = valid.map(function(v) { return v.declarations; }).join(";"); - return new StyleValue("sx-merged", allDecls, [], [], []); - }; - - // stdlib.debug PRIMITIVES["assert"] = function(cond, msg) { if (!isSxTruthy(cond)) throw new Error("Assertion error: " + (msg || "Assertion failed")); @@ -493,7 +439,7 @@ function isSpecialForm(n) { return n in { "if":1,"when":1,"cond":1,"case":1,"and":1,"or":1,"let":1,"let*":1, "lambda":1,"fn":1,"define":1,"defcomp":1,"defmacro":1,"defstyle":1, - "defkeyframes":1,"defhandler":1,"begin":1,"do":1, + "defhandler":1,"begin":1,"do":1, "quote":1,"quasiquote":1,"->":1,"set!":1 }; } function isHoForm(n) { return n in { @@ -504,7 +450,7 @@ function isDefinitionForm(name) { return name === "define" || name === "defcomp" || name === "defmacro" || - name === "defstyle" || name === "defkeyframes" || name === "defhandler"; + name === "defstyle" || name === "defhandler"; } function indexOf_(s, ch) { @@ -604,10 +550,10 @@ var args = rest(expr); return (isSxTruthy(!isSxTruthy(sxOr((typeOf(head) == "symbol"), (typeOf(head) == "lambda"), (typeOf(head) == "list")))) ? map(function(x) { return trampoline(evalExpr(x, env)); }, expr) : (isSxTruthy((typeOf(head) == "symbol")) ? (function() { var name = symbolName(head); - return (isSxTruthy((name == "if")) ? sfIf(args, env) : (isSxTruthy((name == "when")) ? sfWhen(args, env) : (isSxTruthy((name == "cond")) ? sfCond(args, env) : (isSxTruthy((name == "case")) ? sfCase(args, env) : (isSxTruthy((name == "and")) ? sfAnd(args, env) : (isSxTruthy((name == "or")) ? sfOr(args, env) : (isSxTruthy((name == "let")) ? sfLet(args, env) : (isSxTruthy((name == "let*")) ? sfLet(args, env) : (isSxTruthy((name == "letrec")) ? sfLetrec(args, env) : (isSxTruthy((name == "lambda")) ? sfLambda(args, env) : (isSxTruthy((name == "fn")) ? sfLambda(args, env) : (isSxTruthy((name == "define")) ? sfDefine(args, env) : (isSxTruthy((name == "defcomp")) ? sfDefcomp(args, env) : (isSxTruthy((name == "defmacro")) ? sfDefmacro(args, env) : (isSxTruthy((name == "defstyle")) ? sfDefstyle(args, env) : (isSxTruthy((name == "defkeyframes")) ? sfDefkeyframes(args, env) : (isSxTruthy((name == "defhandler")) ? sfDefhandler(args, env) : (isSxTruthy((name == "defpage")) ? sfDefpage(args, env) : (isSxTruthy((name == "defquery")) ? sfDefquery(args, env) : (isSxTruthy((name == "defaction")) ? sfDefaction(args, env) : (isSxTruthy((name == "begin")) ? sfBegin(args, env) : (isSxTruthy((name == "do")) ? sfBegin(args, env) : (isSxTruthy((name == "quote")) ? sfQuote(args, env) : (isSxTruthy((name == "quasiquote")) ? sfQuasiquote(args, env) : (isSxTruthy((name == "->")) ? sfThreadFirst(args, env) : (isSxTruthy((name == "set!")) ? sfSetBang(args, env) : (isSxTruthy((name == "reset")) ? sfReset(args, env) : (isSxTruthy((name == "shift")) ? sfShift(args, env) : (isSxTruthy((name == "dynamic-wind")) ? sfDynamicWind(args, env) : (isSxTruthy((name == "map")) ? hoMap(args, env) : (isSxTruthy((name == "map-indexed")) ? hoMapIndexed(args, env) : (isSxTruthy((name == "filter")) ? hoFilter(args, env) : (isSxTruthy((name == "reduce")) ? hoReduce(args, env) : (isSxTruthy((name == "some")) ? hoSome(args, env) : (isSxTruthy((name == "every?")) ? hoEvery(args, env) : (isSxTruthy((name == "for-each")) ? hoForEach(args, env) : (isSxTruthy((isSxTruthy(envHas(env, name)) && isMacro(envGet(env, name)))) ? (function() { + return (isSxTruthy((name == "if")) ? sfIf(args, env) : (isSxTruthy((name == "when")) ? sfWhen(args, env) : (isSxTruthy((name == "cond")) ? sfCond(args, env) : (isSxTruthy((name == "case")) ? sfCase(args, env) : (isSxTruthy((name == "and")) ? sfAnd(args, env) : (isSxTruthy((name == "or")) ? sfOr(args, env) : (isSxTruthy((name == "let")) ? sfLet(args, env) : (isSxTruthy((name == "let*")) ? sfLet(args, env) : (isSxTruthy((name == "letrec")) ? sfLetrec(args, env) : (isSxTruthy((name == "lambda")) ? sfLambda(args, env) : (isSxTruthy((name == "fn")) ? sfLambda(args, env) : (isSxTruthy((name == "define")) ? sfDefine(args, env) : (isSxTruthy((name == "defcomp")) ? sfDefcomp(args, env) : (isSxTruthy((name == "defmacro")) ? sfDefmacro(args, env) : (isSxTruthy((name == "defstyle")) ? sfDefstyle(args, env) : (isSxTruthy((name == "defhandler")) ? sfDefhandler(args, env) : (isSxTruthy((name == "defpage")) ? sfDefpage(args, env) : (isSxTruthy((name == "defquery")) ? sfDefquery(args, env) : (isSxTruthy((name == "defaction")) ? sfDefaction(args, env) : (isSxTruthy((name == "begin")) ? sfBegin(args, env) : (isSxTruthy((name == "do")) ? sfBegin(args, env) : (isSxTruthy((name == "quote")) ? sfQuote(args, env) : (isSxTruthy((name == "quasiquote")) ? sfQuasiquote(args, env) : (isSxTruthy((name == "->")) ? sfThreadFirst(args, env) : (isSxTruthy((name == "set!")) ? sfSetBang(args, env) : (isSxTruthy((name == "reset")) ? sfReset(args, env) : (isSxTruthy((name == "shift")) ? sfShift(args, env) : (isSxTruthy((name == "dynamic-wind")) ? sfDynamicWind(args, env) : (isSxTruthy((name == "map")) ? hoMap(args, env) : (isSxTruthy((name == "map-indexed")) ? hoMapIndexed(args, env) : (isSxTruthy((name == "filter")) ? hoFilter(args, env) : (isSxTruthy((name == "reduce")) ? hoReduce(args, env) : (isSxTruthy((name == "some")) ? hoSome(args, env) : (isSxTruthy((name == "every?")) ? hoEvery(args, env) : (isSxTruthy((name == "for-each")) ? hoForEach(args, env) : (isSxTruthy((isSxTruthy(envHas(env, name)) && isMacro(envGet(env, name)))) ? (function() { var mac = envGet(env, name); return makeThunk(expandMacro(mac, args, env), env); -})() : (isSxTruthy(isRenderExpr(expr)) ? renderExpr(expr, env) : evalCall(head, args, env))))))))))))))))))))))))))))))))))))))); +})() : (isSxTruthy(isRenderExpr(expr)) ? renderExpr(expr, env) : evalCall(head, args, env)))))))))))))))))))))))))))))))))))))); })() : evalCall(head, args, env))); })(); }; @@ -828,13 +774,6 @@ return append_b(inits, nth(binding, 1)); }, bindings) : reduce(function(acc, pai return value; })(); }; - // sf-defkeyframes - var sfDefkeyframes = function(args, env) { return (function() { - var kfName = symbolName(first(args)); - var steps = rest(args); - return buildKeyframes(kfName, steps, env); -})(); }; - // sf-begin var sfBegin = function(args, env) { return (isSxTruthy(isEmpty(args)) ? NIL : (forEach(function(e) { return trampoline(evalExpr(e, env)); }, slice(args, 0, (len(args) - 1))), makeThunk(last(args), env))); }; @@ -994,7 +933,7 @@ return append_b(inits, nth(binding, 1)); }, bindings) : reduce(function(acc, pai var BOOLEAN_ATTRS = ["async", "autofocus", "autoplay", "checked", "controls", "default", "defer", "disabled", "formnovalidate", "hidden", "inert", "ismap", "loop", "multiple", "muted", "nomodule", "novalidate", "open", "playsinline", "readonly", "required", "reversed", "selected"]; // definition-form? - var isDefinitionForm = function(name) { return sxOr((name == "define"), (name == "defcomp"), (name == "defmacro"), (name == "defstyle"), (name == "defkeyframes"), (name == "defhandler")); }; + var isDefinitionForm = function(name) { return sxOr((name == "define"), (name == "defcomp"), (name == "defmacro"), (name == "defstyle"), (name == "defhandler")); }; // parse-element-args var parseElementArgs = function(args, env) { return (function() { @@ -1014,7 +953,7 @@ return append_b(inits, nth(binding, 1)); }, bindings) : reduce(function(acc, pai // render-attrs var renderAttrs = function(attrs) { return join("", map(function(key) { return (function() { var val = dictGet(attrs, key); - return (isSxTruthy((isSxTruthy(contains(BOOLEAN_ATTRS, key)) && val)) ? (String(" ") + String(key)) : (isSxTruthy((isSxTruthy(contains(BOOLEAN_ATTRS, key)) && !isSxTruthy(val))) ? "" : (isSxTruthy(isNil(val)) ? "" : (isSxTruthy((isSxTruthy((key == "style")) && isStyleValue(val))) ? (String(" class=\"") + String(styleValueClass(val)) + String("\"")) : (String(" ") + String(key) + String("=\"") + String(escapeAttr((String(val)))) + String("\"")))))); + return (isSxTruthy((isSxTruthy(contains(BOOLEAN_ATTRS, key)) && val)) ? (String(" ") + String(key)) : (isSxTruthy((isSxTruthy(contains(BOOLEAN_ATTRS, key)) && !isSxTruthy(val))) ? "" : (isSxTruthy(isNil(val)) ? "" : (String(" ") + String(key) + String("=\"") + String(escapeAttr((String(val)))) + String("\""))))); })(); }, keys(attrs))); }; // eval-cond @@ -1165,10 +1104,10 @@ continue; } else { return NIL; } } }; var renderToHtml = function(expr, env) { return (function() { var _m = typeOf(expr); if (_m == "nil") return ""; if (_m == "string") return escapeHtml(expr); if (_m == "number") return (String(expr)); if (_m == "boolean") return (isSxTruthy(expr) ? "true" : "false"); if (_m == "list") return (isSxTruthy(isEmpty(expr)) ? "" : renderListToHtml(expr, env)); if (_m == "symbol") return renderValueToHtml(trampoline(evalExpr(expr, env)), env); if (_m == "keyword") return escapeHtml(keywordName(expr)); if (_m == "raw-html") return rawHtmlContent(expr); return renderValueToHtml(trampoline(evalExpr(expr, env)), env); })(); }; // render-value-to-html - var renderValueToHtml = function(val, env) { return (function() { var _m = typeOf(val); if (_m == "nil") return ""; if (_m == "string") return escapeHtml(val); if (_m == "number") return (String(val)); if (_m == "boolean") return (isSxTruthy(val) ? "true" : "false"); if (_m == "list") return renderListToHtml(val, env); if (_m == "raw-html") return rawHtmlContent(val); if (_m == "style-value") return styleValueClass(val); return escapeHtml((String(val))); })(); }; + var renderValueToHtml = function(val, env) { return (function() { var _m = typeOf(val); if (_m == "nil") return ""; if (_m == "string") return escapeHtml(val); if (_m == "number") return (String(val)); if (_m == "boolean") return (isSxTruthy(val) ? "true" : "false"); if (_m == "list") return renderListToHtml(val, env); if (_m == "raw-html") return rawHtmlContent(val); return escapeHtml((String(val))); })(); }; // RENDER_HTML_FORMS - var RENDER_HTML_FORMS = ["if", "when", "cond", "case", "let", "let*", "begin", "do", "define", "defcomp", "defmacro", "defstyle", "defkeyframes", "defhandler", "map", "map-indexed", "filter", "for-each"]; + var RENDER_HTML_FORMS = ["if", "when", "cond", "case", "let", "let*", "begin", "do", "define", "defcomp", "defmacro", "defstyle", "defhandler", "map", "map-indexed", "filter", "for-each"]; // render-html-form? var isRenderHtmlForm = function(name) { return contains(RENDER_HTML_FORMS, name); }; @@ -1316,7 +1255,7 @@ continue; } else { return NIL; } } }; var MATH_NS = "http://www.w3.org/1998/Math/MathML"; // render-to-dom - var renderToDom = function(expr, env, ns) { return (function() { var _m = typeOf(expr); if (_m == "nil") return createFragment(); if (_m == "boolean") return createFragment(); if (_m == "raw-html") return domParseHtml(rawHtmlContent(expr)); if (_m == "string") return createTextNode(expr); if (_m == "number") return createTextNode((String(expr))); if (_m == "symbol") return renderToDom(trampoline(evalExpr(expr, env)), env, ns); if (_m == "keyword") return createTextNode(keywordName(expr)); if (_m == "dom-node") return expr; if (_m == "dict") return createFragment(); if (_m == "list") return (isSxTruthy(isEmpty(expr)) ? createFragment() : renderDomList(expr, env, ns)); if (_m == "style-value") return createTextNode(styleValueClass(expr)); return createTextNode((String(expr))); })(); }; + var renderToDom = function(expr, env, ns) { return (function() { var _m = typeOf(expr); if (_m == "nil") return createFragment(); if (_m == "boolean") return createFragment(); if (_m == "raw-html") return domParseHtml(rawHtmlContent(expr)); if (_m == "string") return createTextNode(expr); if (_m == "number") return createTextNode((String(expr))); if (_m == "symbol") return renderToDom(trampoline(evalExpr(expr, env)), env, ns); if (_m == "keyword") return createTextNode(keywordName(expr)); if (_m == "dom-node") return expr; if (_m == "dict") return createFragment(); if (_m == "list") return (isSxTruthy(isEmpty(expr)) ? createFragment() : renderDomList(expr, env, ns)); return createTextNode((String(expr))); })(); }; // render-dom-list var renderDomList = function(expr, env, ns) { return (function() { @@ -1339,22 +1278,15 @@ continue; } else { return NIL; } } }; var renderDomElement = function(tag, args, env, ns) { return (function() { var newNs = (isSxTruthy((tag == "svg")) ? SVG_NS : (isSxTruthy((tag == "math")) ? MATH_NS : ns)); var el = domCreateElement(tag, newNs); - var extraClass = NIL; reduce(function(state, arg) { return (function() { var skip = get(state, "skip"); return (isSxTruthy(skip) ? assoc(state, "skip", false, "i", (get(state, "i") + 1)) : (isSxTruthy((isSxTruthy((typeOf(arg) == "keyword")) && ((get(state, "i") + 1) < len(args)))) ? (function() { var attrName = keywordName(arg); var attrVal = trampoline(evalExpr(nth(args, (get(state, "i") + 1)), env)); - (isSxTruthy(sxOr(isNil(attrVal), (attrVal == false))) ? NIL : (isSxTruthy((isSxTruthy((attrName == "style")) && isStyleValue(attrVal))) ? (extraClass = styleValueClass(attrVal)) : (isSxTruthy(contains(BOOLEAN_ATTRS, attrName)) ? (isSxTruthy(attrVal) ? domSetAttr(el, attrName, "") : NIL) : (isSxTruthy((attrVal == true)) ? domSetAttr(el, attrName, "") : domSetAttr(el, attrName, (String(attrVal))))))); + (isSxTruthy(sxOr(isNil(attrVal), (attrVal == false))) ? NIL : (isSxTruthy(contains(BOOLEAN_ATTRS, attrName)) ? (isSxTruthy(attrVal) ? domSetAttr(el, attrName, "") : NIL) : (isSxTruthy((attrVal == true)) ? domSetAttr(el, attrName, "") : domSetAttr(el, attrName, (String(attrVal)))))); return assoc(state, "skip", true, "i", (get(state, "i") + 1)); })() : ((isSxTruthy(!isSxTruthy(contains(VOID_ELEMENTS, tag))) ? domAppend(el, renderToDom(arg, env, newNs)) : NIL), assoc(state, "i", (get(state, "i") + 1))))); })(); }, {["i"]: 0, ["skip"]: false}, args); - if (isSxTruthy(extraClass)) { - (function() { - var existing = domGetAttr(el, "class"); - return domSetAttr(el, "class", (isSxTruthy(existing) ? (String(existing) + String(" ") + String(extraClass)) : extraClass)); -})(); -} return el; })(); }; @@ -1405,7 +1337,7 @@ continue; } else { return NIL; } } }; var renderDomUnknownComponent = function(name) { return error((String("Unknown component: ") + String(name))); }; // RENDER_DOM_FORMS - var RENDER_DOM_FORMS = ["if", "when", "cond", "case", "let", "let*", "begin", "do", "define", "defcomp", "defmacro", "defstyle", "defkeyframes", "defhandler", "map", "map-indexed", "filter", "for-each"]; + var RENDER_DOM_FORMS = ["if", "when", "cond", "case", "let", "let*", "begin", "do", "define", "defcomp", "defmacro", "defstyle", "defhandler", "map", "map-indexed", "filter", "for-each"]; // render-dom-form? var isRenderDomForm = function(name) { return contains(RENDER_DOM_FORMS, name); }; @@ -2172,180 +2104,6 @@ return bindInlineHandlers(root); }; var engineInit = function() { return (initCssTracking(), sxProcessScripts(NIL), sxHydrate(NIL), processElements(NIL)); }; - // === Transpiled from cssx === - - // _style-atoms - var _styleAtoms = {}; - - // _pseudo-variants - var _pseudoVariants = {}; - - // _responsive-breakpoints - var _responsiveBreakpoints = {}; - - // _style-keyframes - var _styleKeyframes = {}; - - // _arbitrary-patterns - var _arbitraryPatterns = []; - - // _child-selector-prefixes - var _childSelectorPrefixes = []; - - // _style-cache - var _styleCache = {}; - - // _injected-styles - var _injectedStyles = {}; - - // load-style-dict - var loadStyleDict = function(data) { _styleAtoms = sxOr(get(data, "a"), {}); -_pseudoVariants = sxOr(get(data, "v"), {}); -_responsiveBreakpoints = sxOr(get(data, "b"), {}); -_styleKeyframes = sxOr(get(data, "k"), {}); -_childSelectorPrefixes = sxOr(get(data, "c"), []); -_arbitraryPatterns = map(function(pair) { return {["re"]: compileRegex((String("^") + String(first(pair)) + String("$"))), ["tmpl"]: nth(pair, 1)}; }, sxOr(get(data, "p"), [])); -return (_styleCache = {}); }; - - // split-variant - var splitVariant = function(atom) { return (function() { - var result = NIL; - { var _c = keys(_responsiveBreakpoints); for (var _i = 0; _i < _c.length; _i++) { var bp = _c[_i]; if (isSxTruthy(isNil(result))) { - (function() { - var prefix = (String(bp) + String(":")); - return (isSxTruthy(startsWith(atom, prefix)) ? (function() { - var restAtom = slice(atom, len(prefix)); - return (function() { - var innerMatch = NIL; - { var _c = keys(_pseudoVariants); for (var _i = 0; _i < _c.length; _i++) { var pv = _c[_i]; if (isSxTruthy(isNil(innerMatch))) { - (function() { - var innerPrefix = (String(pv) + String(":")); - return (isSxTruthy(startsWith(restAtom, innerPrefix)) ? (innerMatch = [(String(bp) + String(":") + String(pv)), slice(restAtom, len(innerPrefix))]) : NIL); -})(); -} } } - return (result = sxOr(innerMatch, [bp, restAtom])); -})(); -})() : NIL); -})(); -} } } - if (isSxTruthy(isNil(result))) { - { var _c = keys(_pseudoVariants); for (var _i = 0; _i < _c.length; _i++) { var pv = _c[_i]; if (isSxTruthy(isNil(result))) { - (function() { - var prefix = (String(pv) + String(":")); - return (isSxTruthy(startsWith(atom, prefix)) ? (result = [pv, slice(atom, len(prefix))]) : NIL); -})(); -} } } -} - return sxOr(result, [NIL, atom]); -})(); }; - - // resolve-atom - var resolveAtom = function(atom) { return (function() { - var decls = dictGet(_styleAtoms, atom); - return (isSxTruthy(!isSxTruthy(isNil(decls))) ? decls : (isSxTruthy(startsWith(atom, "animate-")) ? (function() { - var kfName = slice(atom, 8); - return (isSxTruthy(dictHas(_styleKeyframes, kfName)) ? (String("animation-name:") + String(kfName)) : NIL); -})() : (function() { - var matchResult = NIL; - { var _c = _arbitraryPatterns; for (var _i = 0; _i < _c.length; _i++) { var pat = _c[_i]; if (isSxTruthy(isNil(matchResult))) { - (function() { - var m = regexMatch(get(pat, "re"), atom); - return (isSxTruthy(m) ? (matchResult = regexReplaceGroups(get(pat, "tmpl"), m)) : NIL); -})(); -} } } - return matchResult; -})())); -})(); }; - - // is-child-selector-atom? - var isChildSelectorAtom = function(atom) { return some(function(prefix) { return startsWith(atom, prefix); }, _childSelectorPrefixes); }; - - // hash-style - var hashStyle = function(input) { return fnv1aHash(input); }; - - // resolve-style - var resolveStyle = function(atoms) { return (function() { - var key = join("\\0", atoms); - return (function() { - var cached = dictGet(_styleCache, key); - return (isSxTruthy(!isSxTruthy(isNil(cached))) ? cached : (function() { - var baseDecls = []; - var mediaRules = []; - var pseudoRules = []; - var kfNeeded = []; - { var _c = atoms; for (var _i = 0; _i < _c.length; _i++) { var a = _c[_i]; if (isSxTruthy(a)) { - (function() { - var clean = (isSxTruthy(startsWith(a, ":")) ? slice(a, 1) : a); - return (function() { - var parts = splitVariant(clean); - return (function() { - var variant = first(parts); - var base = nth(parts, 1); - var decls = resolveAtom(base); - return (isSxTruthy(decls) ? ((isSxTruthy(startsWith(base, "animate-")) ? (function() { - var kfName = slice(base, 8); - return (isSxTruthy(dictHas(_styleKeyframes, kfName)) ? append_b(kfNeeded, [kfName, dictGet(_styleKeyframes, kfName)]) : NIL); -})() : NIL), (isSxTruthy(isNil(variant)) ? (isSxTruthy(isChildSelectorAtom(base)) ? append_b(pseudoRules, [">:not(:first-child)", decls]) : append_b(baseDecls, decls)) : (isSxTruthy(dictHas(_responsiveBreakpoints, variant)) ? append_b(mediaRules, [dictGet(_responsiveBreakpoints, variant), decls]) : (isSxTruthy(dictHas(_pseudoVariants, variant)) ? append_b(pseudoRules, [dictGet(_pseudoVariants, variant), decls]) : (function() { - var vparts = split(variant, ":"); - var mediaPart = NIL; - var pseudoPart = NIL; - { var _c = vparts; for (var _i = 0; _i < _c.length; _i++) { var vp = _c[_i]; (isSxTruthy(dictHas(_responsiveBreakpoints, vp)) ? (mediaPart = dictGet(_responsiveBreakpoints, vp)) : (isSxTruthy(dictHas(_pseudoVariants, vp)) ? (pseudoPart = dictGet(_pseudoVariants, vp)) : NIL)); } } - if (isSxTruthy(mediaPart)) { - mediaRules.push([mediaPart, decls]); -} - if (isSxTruthy(pseudoPart)) { - pseudoRules.push([pseudoPart, decls]); -} - return (isSxTruthy((isSxTruthy(isNil(mediaPart)) && isNil(pseudoPart))) ? append_b(baseDecls, decls) : NIL); -})())))) : NIL); -})(); -})(); -})(); -} } } - return (function() { - var hashInput = join(";", baseDecls); - { var _c = mediaRules; for (var _i = 0; _i < _c.length; _i++) { var mr = _c[_i]; hashInput = (String(hashInput) + String("@") + String(first(mr)) + String("{") + String(nth(mr, 1)) + String("}")); } } - { var _c = pseudoRules; for (var _i = 0; _i < _c.length; _i++) { var pr = _c[_i]; hashInput = (String(hashInput) + String(first(pr)) + String("{") + String(nth(pr, 1)) + String("}")); } } - { var _c = kfNeeded; for (var _i = 0; _i < _c.length; _i++) { var kf = _c[_i]; hashInput = (String(hashInput) + String(nth(kf, 1))); } } - return (function() { - var cn = (String("sx-") + String(hashStyle(hashInput))); - var sv = makeStyleValue_(cn, join(";", baseDecls), mediaRules, pseudoRules, kfNeeded); - _styleCache[key] = sv; - injectStyleValue(sv, atoms); - return sv; -})(); -})(); -})()); -})(); -})(); }; - - // merge-style-values - var mergeStyleValues = function(styles) { return (isSxTruthy((len(styles) == 1)) ? first(styles) : (function() { - var allDecls = []; - var allMedia = []; - var allPseudo = []; - var allKf = []; - { var _c = styles; for (var _i = 0; _i < _c.length; _i++) { var sv = _c[_i]; if (isSxTruthy(styleValueDeclarations(sv))) { - allDecls.push(styleValueDeclarations(sv)); -} -allMedia = concat(allMedia, styleValueMediaRules(sv)); -allPseudo = concat(allPseudo, styleValuePseudoRules(sv)); -allKf = concat(allKf, styleValueKeyframes_(sv)); } } - return (function() { - var hashInput = join(";", allDecls); - { var _c = allMedia; for (var _i = 0; _i < _c.length; _i++) { var mr = _c[_i]; hashInput = (String(hashInput) + String("@") + String(first(mr)) + String("{") + String(nth(mr, 1)) + String("}")); } } - { var _c = allPseudo; for (var _i = 0; _i < _c.length; _i++) { var pr = _c[_i]; hashInput = (String(hashInput) + String(first(pr)) + String("{") + String(nth(pr, 1)) + String("}")); } } - { var _c = allKf; for (var _i = 0; _i < _c.length; _i++) { var kf = _c[_i]; hashInput = (String(hashInput) + String(nth(kf, 1))); } } - return (function() { - var cn = (String("sx-") + String(hashStyle(hashInput))); - var merged = makeStyleValue_(cn, join(";", allDecls), allMedia, allPseudo, allKf); - injectStyleValue(merged, []); - return merged; -})(); -})(); -})()); }; - - // === Transpiled from boot === // HEAD_HOIST_SELECTOR @@ -2461,26 +2219,6 @@ callExpr.push(dictGet(kwargs, k)); } } })(); return setSxCompCookie(hash); })()); -})(); }; - - // init-style-dict - var initStyleDict = function() { return (function() { - var scripts = queryStyleScripts(); - return forEach(function(s) { return (isSxTruthy(!isSxTruthy(isProcessed(s, "styles"))) ? (markProcessed(s, "styles"), (function() { - var text = domTextContent(s); - var hash = domGetAttr(s, "data-hash"); - return (isSxTruthy(isNil(hash)) ? (isSxTruthy((isSxTruthy(text) && !isSxTruthy(isEmpty(trim(text))))) ? parseAndLoadStyleDict(text) : NIL) : (function() { - var hasInline = (isSxTruthy(text) && !isSxTruthy(isEmpty(trim(text)))); - (function() { - var cachedHash = localStorageGet("sx-styles-hash"); - return (isSxTruthy((cachedHash == hash)) ? (isSxTruthy(hasInline) ? (localStorageSet("sx-styles-src", text), parseAndLoadStyleDict(text), logInfo("styles: downloaded (cookie stale)")) : (function() { - var cached = localStorageGet("sx-styles-src"); - return (isSxTruthy(cached) ? (parseAndLoadStyleDict(cached), logInfo((String("styles: cached (") + String(hash) + String(")")))) : (clearSxStylesCookie(), browserReload())); -})()) : (isSxTruthy(hasInline) ? (localStorageSet("sx-styles-hash", hash), localStorageSet("sx-styles-src", text), parseAndLoadStyleDict(text), logInfo((String("styles: downloaded (") + String(hash) + String(")")))) : (localStorageRemove("sx-styles-hash"), localStorageRemove("sx-styles-src"), clearSxStylesCookie(), browserReload()))); -})(); - return setSxStylesCookie(hash); -})()); -})()) : NIL); }, scripts); })(); }; // _page-routes @@ -2506,7 +2244,7 @@ callExpr.push(dictGet(kwargs, k)); } } })(); }; // boot-init - var bootInit = function() { return (logInfo((String("sx-browser ") + String(SX_VERSION))), initCssTracking(), initStyleDict(), processPageScripts(), processSxScripts(NIL), sxHydrateElements(NIL), processElements(NIL)); }; + var bootInit = function() { return (logInfo((String("sx-browser ") + String(SX_VERSION))), initCssTracking(), processPageScripts(), processSxScripts(NIL), sxHydrateElements(NIL), processElements(NIL)); }; // === Transpiled from router (client-side route matching) === @@ -2779,7 +2517,6 @@ callExpr.push(dictGet(kwargs, k)); } } renderDomElement = function(tag, args, env, ns) { var newNs = tag === "svg" ? SVG_NS : tag === "math" ? MATH_NS : ns; var el = domCreateElement(tag, newNs); - var extraClasses = []; var isVoid = contains(VOID_ELEMENTS, tag); for (var i = 0; i < args.length; i++) { var arg = args[i]; @@ -2788,11 +2525,7 @@ callExpr.push(dictGet(kwargs, k)); } } var attrVal = trampoline(evalExpr(args[i + 1], env)); i++; // skip value if (isNil(attrVal) || attrVal === false) continue; - if (attrName === "class" && attrVal && attrVal._styleValue) { - extraClasses.push(attrVal.className); - } else if (attrName === "style" && attrVal && attrVal._styleValue) { - extraClasses.push(attrVal.className); - } else if (contains(BOOLEAN_ATTRS, attrName)) { + if (contains(BOOLEAN_ATTRS, attrName)) { if (isSxTruthy(attrVal)) el.setAttribute(attrName, ""); } else if (attrVal === true) { el.setAttribute(attrName, ""); @@ -2806,10 +2539,6 @@ callExpr.push(dictGet(kwargs, k)); } } } } } - if (extraClasses.length) { - var existing = el.getAttribute("class") || ""; - el.setAttribute("class", (existing ? existing + " " : "") + extraClasses.join(" ")); - } return el; }; @@ -3703,70 +3432,6 @@ callExpr.push(dictGet(kwargs, k)); } } return result; } - function makeStyleValue_(cn, decls, media, pseudo, kf) { - return new StyleValue(cn, decls || "", media || [], pseudo || [], kf || []); - } - - function styleValueDeclarations(sv) { return sv.declarations; } - function styleValueMediaRules(sv) { return sv.mediaRules; } - function styleValuePseudoRules(sv) { return sv.pseudoRules; } - function styleValueKeyframes_(sv) { return sv.keyframes; } - - function injectStyleValue(sv, atoms) { - if (_injectedStyles[sv.className]) return; - _injectedStyles[sv.className] = true; - - if (!_hasDom) return; - var cssTarget = document.getElementById("sx-css"); - if (!cssTarget) return; - - var rules = []; - // Child-selector atoms are now routed to pseudoRules by the resolver - // with selector ">:not(:first-child)", so base declarations are always - // applied directly to the class. - if (sv.declarations) { - rules.push("." + sv.className + "{" + sv.declarations + "}"); - } - for (var pi = 0; pi < sv.pseudoRules.length; pi++) { - var sel = sv.pseudoRules[pi][0], decls = sv.pseudoRules[pi][1]; - if (sel.indexOf("&") >= 0) { - rules.push(sel.replace(/&/g, "." + sv.className) + "{" + decls + "}"); - } else { - rules.push("." + sv.className + sel + "{" + decls + "}"); - } - } - for (var mi = 0; mi < sv.mediaRules.length; mi++) { - rules.push("@media " + sv.mediaRules[mi][0] + "{." + sv.className + "{" + sv.mediaRules[mi][1] + "}}"); - } - for (var ki = 0; ki < sv.keyframes.length; ki++) { - rules.push(sv.keyframes[ki][1]); - } - cssTarget.textContent += rules.join(""); - } - - // Replace stub css primitive with real CSSX implementation - PRIMITIVES["css"] = function() { - var atoms = []; - for (var i = 0; i < arguments.length; i++) { - var a = arguments[i]; - if (isNil(a) || a === false) continue; - atoms.push(isKw(a) ? a.name : String(a)); - } - if (!atoms.length) return NIL; - return resolveStyle(atoms); - }; - - PRIMITIVES["merge-styles"] = function() { - var valid = []; - for (var i = 0; i < arguments.length; i++) { - if (isStyleValue(arguments[i])) valid.push(arguments[i]); - } - if (!valid.length) return NIL; - if (valid.length === 1) return valid[0]; - return mergeStyleValues(valid); - }; - - // ========================================================================= // Platform interface — Boot (mount, hydrate, scripts, cookies) // ========================================================================= @@ -3823,12 +3488,6 @@ callExpr.push(dictGet(kwargs, k)); } } r.querySelectorAll('script[type="text/sx"]')); } - function queryStyleScripts() { - if (!_hasDom) return []; - return Array.prototype.slice.call( - document.querySelectorAll('script[type="text/sx-styles"]')); - } - function queryPageScripts() { if (!_hasDom) return []; return Array.prototype.slice.call( @@ -3860,14 +3519,6 @@ callExpr.push(dictGet(kwargs, k)); } } if (_hasDom) document.cookie = "sx-comp-hash=;path=/;max-age=0;SameSite=Lax"; } - function setSxStylesCookie(hash) { - if (_hasDom) document.cookie = "sx-styles-hash=" + hash + ";path=/;max-age=31536000;SameSite=Lax"; - } - - function clearSxStylesCookie() { - if (_hasDom) document.cookie = "sx-styles-hash=;path=/;max-age=0;SameSite=Lax"; - } - // --- Env helpers --- function parseEnvAttr(el) { @@ -3916,12 +3567,6 @@ callExpr.push(dictGet(kwargs, k)); } } } } - function parseAndLoadStyleDict(text) { - try { loadStyleDict(JSON.parse(text)); } - catch (e) { if (typeof console !== "undefined") console.warn("[sx-ref] style dict parse error", e); } - } - - // ========================================================================= // Post-transpilation fixups // ========================================================================= @@ -4082,7 +3727,7 @@ callExpr.push(dictGet(kwargs, k)); } } // define/defcomp/defmacro — eval for side effects if (hname === "define" || hname === "defcomp" || hname === "defmacro" || - hname === "defstyle" || hname === "defkeyframes" || hname === "defhandler") { + hname === "defstyle" || hname === "defhandler") { trampoline(evalExpr(expr, env)); return null; } @@ -4204,11 +3849,7 @@ callExpr.push(dictGet(kwargs, k)); } } })(attrName, attrVal); } else { if (!isNil(attrVal) && attrVal !== false) { - if (attrName === "class" && attrVal && attrVal._styleValue) { - el.setAttribute("class", (el.getAttribute("class") || "") + " " + attrVal.className); - } else if (attrName === "style" && attrVal && attrVal._styleValue) { - el.setAttribute("class", (el.getAttribute("class") || "") + " " + attrVal.className); - } else if (contains(BOOLEAN_ATTRS, attrName)) { + if (contains(BOOLEAN_ATTRS, attrName)) { if (isSxTruthy(attrVal)) el.setAttribute(attrName, ""); } else if (attrVal === true) { el.setAttribute(attrName, ""); @@ -4670,7 +4311,7 @@ callExpr.push(dictGet(kwargs, k)); } } registerIoDeps: typeof registerIoDeps === "function" ? registerIoDeps : null, asyncRender: typeof asyncSxRenderWithEnv === "function" ? asyncSxRenderWithEnv : null, asyncRenderToDom: typeof asyncRenderToDom === "function" ? asyncRenderToDom : null, - _version: "ref-2.0 (boot+cssx+dom+engine+html+orchestration+parser+sx, bootstrap-compiled)" + _version: "ref-2.0 (boot+dom+engine+html+orchestration+parser+sx, bootstrap-compiled)" }; diff --git a/shared/static/scripts/sx-ref.js b/shared/static/scripts/sx-ref.js index 4db4434..2654502 100644 --- a/shared/static/scripts/sx-ref.js +++ b/shared/static/scripts/sx-ref.js @@ -58,15 +58,6 @@ function RawHTML(html) { this.html = html; } RawHTML.prototype._raw = true; - function StyleValue(className, declarations, mediaRules, pseudoRules, keyframes) { - this.className = className; - this.declarations = declarations || ""; - this.mediaRules = mediaRules || []; - this.pseudoRules = pseudoRules || []; - this.keyframes = keyframes || []; - } - StyleValue.prototype._styleValue = true; - function isSym(x) { return x != null && x._sym === true; } function isKw(x) { return x != null && x._kw === true; } @@ -102,7 +93,6 @@ if (x._component) return "component"; if (x._macro) return "macro"; if (x._raw) return "raw-html"; - if (x._styleValue) return "style-value"; if (typeof Node !== "undefined" && x instanceof Node) return "dom-node"; if (Array.isArray(x)) return "list"; if (typeof x === "object") return "dict"; @@ -149,27 +139,6 @@ function isComponent(x) { return x != null && x._component === true; } function isMacro(x) { return x != null && x._macro === true; } - function isStyleValue(x) { return x != null && x._styleValue === true; } - function styleValueClass(x) { return x.className; } - function styleValue_p(x) { return x != null && x._styleValue === true; } - - function buildKeyframes(kfName, steps, env) { - // Platform implementation of defkeyframes - var parts = []; - for (var i = 0; i < steps.length; i++) { - var step = steps[i]; - var selector = isSym(step[0]) ? step[0].name : String(step[0]); - var body = trampoline(evalExpr(step[1], env)); - var decls = isStyleValue(body) ? body.declarations : String(body); - parts.push(selector + "{" + decls + "}"); - } - var kfRule = "@keyframes " + kfName + "{" + parts.join("") + "}"; - var cn = "sx-ref-kf-" + kfName; - var sv = new StyleValue(cn, "animation-name:" + kfName, [], [], [[kfName, kfRule]]); - env[kfName] = sv; - return sv; - } - function envHas(env, name) { return name in env; } function envGet(env, name) { return env[name]; } function envSet(env, name, val) { env[name] = val; } @@ -377,29 +346,6 @@ PRIMITIVES["strip-tags"] = function(s) { return String(s).replace(/<[^>]+>/g, ""); }; - // stdlib.style - PRIMITIVES["css"] = function() { - var atoms = []; - for (var i = 0; i < arguments.length; i++) { - var a = arguments[i]; - if (isNil(a) || a === false) continue; - atoms.push(isKw(a) ? a.name : String(a)); - } - if (!atoms.length) return NIL; - return new StyleValue("sx-" + atoms.join("-"), atoms.join(";"), [], [], []); - }; - PRIMITIVES["merge-styles"] = function() { - var valid = []; - for (var i = 0; i < arguments.length; i++) { - if (isStyleValue(arguments[i])) valid.push(arguments[i]); - } - if (!valid.length) return NIL; - if (valid.length === 1) return valid[0]; - var allDecls = valid.map(function(v) { return v.declarations; }).join(";"); - return new StyleValue("sx-merged", allDecls, [], [], []); - }; - - // stdlib.debug PRIMITIVES["assert"] = function(cond, msg) { if (!isSxTruthy(cond)) throw new Error("Assertion error: " + (msg || "Assertion failed")); @@ -486,7 +432,7 @@ function isSpecialForm(n) { return n in { "if":1,"when":1,"cond":1,"case":1,"and":1,"or":1,"let":1,"let*":1, "lambda":1,"fn":1,"define":1,"defcomp":1,"defmacro":1,"defstyle":1, - "defkeyframes":1,"defhandler":1,"begin":1,"do":1, + "defhandler":1,"begin":1,"do":1, "quote":1,"quasiquote":1,"->":1,"set!":1 }; } function isHoForm(n) { return n in { @@ -517,7 +463,7 @@ function isDefinitionForm(name) { return name === "define" || name === "defcomp" || name === "defmacro" || - name === "defstyle" || name === "defkeyframes" || name === "defhandler"; + name === "defstyle" || name === "defhandler"; } function indexOf_(s, ch) { @@ -657,10 +603,10 @@ var args = rest(expr); return (isSxTruthy(!sxOr((typeOf(head) == "symbol"), (typeOf(head) == "lambda"), (typeOf(head) == "list"))) ? map(function(x) { return trampoline(evalExpr(x, env)); }, expr) : (isSxTruthy((typeOf(head) == "symbol")) ? (function() { var name = symbolName(head); - return (isSxTruthy((name == "if")) ? sfIf(args, env) : (isSxTruthy((name == "when")) ? sfWhen(args, env) : (isSxTruthy((name == "cond")) ? sfCond(args, env) : (isSxTruthy((name == "case")) ? sfCase(args, env) : (isSxTruthy((name == "and")) ? sfAnd(args, env) : (isSxTruthy((name == "or")) ? sfOr(args, env) : (isSxTruthy((name == "let")) ? sfLet(args, env) : (isSxTruthy((name == "let*")) ? sfLet(args, env) : (isSxTruthy((name == "letrec")) ? sfLetrec(args, env) : (isSxTruthy((name == "lambda")) ? sfLambda(args, env) : (isSxTruthy((name == "fn")) ? sfLambda(args, env) : (isSxTruthy((name == "define")) ? sfDefine(args, env) : (isSxTruthy((name == "defcomp")) ? sfDefcomp(args, env) : (isSxTruthy((name == "defmacro")) ? sfDefmacro(args, env) : (isSxTruthy((name == "defstyle")) ? sfDefstyle(args, env) : (isSxTruthy((name == "defkeyframes")) ? sfDefkeyframes(args, env) : (isSxTruthy((name == "defhandler")) ? sfDefhandler(args, env) : (isSxTruthy((name == "defpage")) ? sfDefpage(args, env) : (isSxTruthy((name == "defquery")) ? sfDefquery(args, env) : (isSxTruthy((name == "defaction")) ? sfDefaction(args, env) : (isSxTruthy((name == "begin")) ? sfBegin(args, env) : (isSxTruthy((name == "do")) ? sfBegin(args, env) : (isSxTruthy((name == "quote")) ? sfQuote(args, env) : (isSxTruthy((name == "quasiquote")) ? sfQuasiquote(args, env) : (isSxTruthy((name == "->")) ? sfThreadFirst(args, env) : (isSxTruthy((name == "set!")) ? sfSetBang(args, env) : (isSxTruthy((name == "reset")) ? sfReset(args, env) : (isSxTruthy((name == "shift")) ? sfShift(args, env) : (isSxTruthy((name == "dynamic-wind")) ? sfDynamicWind(args, env) : (isSxTruthy((name == "map")) ? hoMap(args, env) : (isSxTruthy((name == "map-indexed")) ? hoMapIndexed(args, env) : (isSxTruthy((name == "filter")) ? hoFilter(args, env) : (isSxTruthy((name == "reduce")) ? hoReduce(args, env) : (isSxTruthy((name == "some")) ? hoSome(args, env) : (isSxTruthy((name == "every?")) ? hoEvery(args, env) : (isSxTruthy((name == "for-each")) ? hoForEach(args, env) : (isSxTruthy((isSxTruthy(envHas(env, name)) && isMacro(envGet(env, name)))) ? (function() { + return (isSxTruthy((name == "if")) ? sfIf(args, env) : (isSxTruthy((name == "when")) ? sfWhen(args, env) : (isSxTruthy((name == "cond")) ? sfCond(args, env) : (isSxTruthy((name == "case")) ? sfCase(args, env) : (isSxTruthy((name == "and")) ? sfAnd(args, env) : (isSxTruthy((name == "or")) ? sfOr(args, env) : (isSxTruthy((name == "let")) ? sfLet(args, env) : (isSxTruthy((name == "let*")) ? sfLet(args, env) : (isSxTruthy((name == "letrec")) ? sfLetrec(args, env) : (isSxTruthy((name == "lambda")) ? sfLambda(args, env) : (isSxTruthy((name == "fn")) ? sfLambda(args, env) : (isSxTruthy((name == "define")) ? sfDefine(args, env) : (isSxTruthy((name == "defcomp")) ? sfDefcomp(args, env) : (isSxTruthy((name == "defmacro")) ? sfDefmacro(args, env) : (isSxTruthy((name == "defstyle")) ? sfDefstyle(args, env) : (isSxTruthy((name == "defhandler")) ? sfDefhandler(args, env) : (isSxTruthy((name == "defpage")) ? sfDefpage(args, env) : (isSxTruthy((name == "defquery")) ? sfDefquery(args, env) : (isSxTruthy((name == "defaction")) ? sfDefaction(args, env) : (isSxTruthy((name == "begin")) ? sfBegin(args, env) : (isSxTruthy((name == "do")) ? sfBegin(args, env) : (isSxTruthy((name == "quote")) ? sfQuote(args, env) : (isSxTruthy((name == "quasiquote")) ? sfQuasiquote(args, env) : (isSxTruthy((name == "->")) ? sfThreadFirst(args, env) : (isSxTruthy((name == "set!")) ? sfSetBang(args, env) : (isSxTruthy((name == "reset")) ? sfReset(args, env) : (isSxTruthy((name == "shift")) ? sfShift(args, env) : (isSxTruthy((name == "dynamic-wind")) ? sfDynamicWind(args, env) : (isSxTruthy((name == "map")) ? hoMap(args, env) : (isSxTruthy((name == "map-indexed")) ? hoMapIndexed(args, env) : (isSxTruthy((name == "filter")) ? hoFilter(args, env) : (isSxTruthy((name == "reduce")) ? hoReduce(args, env) : (isSxTruthy((name == "some")) ? hoSome(args, env) : (isSxTruthy((name == "every?")) ? hoEvery(args, env) : (isSxTruthy((name == "for-each")) ? hoForEach(args, env) : (isSxTruthy((isSxTruthy(envHas(env, name)) && isMacro(envGet(env, name)))) ? (function() { var mac = envGet(env, name); return makeThunk(expandMacro(mac, args, env), env); -})() : (isSxTruthy(isRenderExpr(expr)) ? renderExpr(expr, env) : evalCall(head, args, env))))))))))))))))))))))))))))))))))))))); +})() : (isSxTruthy(isRenderExpr(expr)) ? renderExpr(expr, env) : evalCall(head, args, env)))))))))))))))))))))))))))))))))))))); })() : evalCall(head, args, env))); })(); }; @@ -881,13 +827,6 @@ return append_b(inits, nth(binding, 1)); }, bindings) : reduce(function(acc, pai return value; })(); }; - // sf-defkeyframes - var sfDefkeyframes = function(args, env) { return (function() { - var kfName = symbolName(first(args)); - var steps = rest(args); - return buildKeyframes(kfName, steps, env); -})(); }; - // sf-begin var sfBegin = function(args, env) { return (isSxTruthy(isEmpty(args)) ? NIL : (forEach(function(e) { return trampoline(evalExpr(e, env)); }, slice(args, 0, (len(args) - 1))), makeThunk(last(args), env))); }; @@ -1047,7 +986,7 @@ return append_b(inits, nth(binding, 1)); }, bindings) : reduce(function(acc, pai var BOOLEAN_ATTRS = ["async", "autofocus", "autoplay", "checked", "controls", "default", "defer", "disabled", "formnovalidate", "hidden", "inert", "ismap", "loop", "multiple", "muted", "nomodule", "novalidate", "open", "playsinline", "readonly", "required", "reversed", "selected"]; // definition-form? - var isDefinitionForm = function(name) { return sxOr((name == "define"), (name == "defcomp"), (name == "defmacro"), (name == "defstyle"), (name == "defkeyframes"), (name == "defhandler")); }; + var isDefinitionForm = function(name) { return sxOr((name == "define"), (name == "defcomp"), (name == "defmacro"), (name == "defstyle"), (name == "defhandler")); }; // parse-element-args var parseElementArgs = function(args, env) { return (function() { @@ -1067,7 +1006,7 @@ return append_b(inits, nth(binding, 1)); }, bindings) : reduce(function(acc, pai // render-attrs var renderAttrs = function(attrs) { return join("", map(function(key) { return (function() { var val = dictGet(attrs, key); - return (isSxTruthy((isSxTruthy(contains(BOOLEAN_ATTRS, key)) && val)) ? (String(" ") + String(key)) : (isSxTruthy((isSxTruthy(contains(BOOLEAN_ATTRS, key)) && !val)) ? "" : (isSxTruthy(isNil(val)) ? "" : (isSxTruthy((isSxTruthy((key == "style")) && isStyleValue(val))) ? (String(" class=\"") + String(styleValueClass(val)) + String("\"")) : (String(" ") + String(key) + String("=\"") + String(escapeAttr((String(val)))) + String("\"")))))); + return (isSxTruthy((isSxTruthy(contains(BOOLEAN_ATTRS, key)) && val)) ? (String(" ") + String(key)) : (isSxTruthy((isSxTruthy(contains(BOOLEAN_ATTRS, key)) && !val)) ? "" : (isSxTruthy(isNil(val)) ? "" : (String(" ") + String(key) + String("=\"") + String(escapeAttr((String(val)))) + String("\""))))); })(); }, keys(attrs))); }; @@ -1188,10 +1127,10 @@ continue; } else { return NIL; } } }; var renderToHtml = function(expr, env) { return (function() { var _m = typeOf(expr); if (_m == "nil") return ""; if (_m == "string") return escapeHtml(expr); if (_m == "number") return (String(expr)); if (_m == "boolean") return (isSxTruthy(expr) ? "true" : "false"); if (_m == "list") return (isSxTruthy(isEmpty(expr)) ? "" : renderListToHtml(expr, env)); if (_m == "symbol") return renderValueToHtml(trampoline(evalExpr(expr, env)), env); if (_m == "keyword") return escapeHtml(keywordName(expr)); if (_m == "raw-html") return rawHtmlContent(expr); return renderValueToHtml(trampoline(evalExpr(expr, env)), env); })(); }; // render-value-to-html - var renderValueToHtml = function(val, env) { return (function() { var _m = typeOf(val); if (_m == "nil") return ""; if (_m == "string") return escapeHtml(val); if (_m == "number") return (String(val)); if (_m == "boolean") return (isSxTruthy(val) ? "true" : "false"); if (_m == "list") return renderListToHtml(val, env); if (_m == "raw-html") return rawHtmlContent(val); if (_m == "style-value") return styleValueClass(val); return escapeHtml((String(val))); })(); }; + var renderValueToHtml = function(val, env) { return (function() { var _m = typeOf(val); if (_m == "nil") return ""; if (_m == "string") return escapeHtml(val); if (_m == "number") return (String(val)); if (_m == "boolean") return (isSxTruthy(val) ? "true" : "false"); if (_m == "list") return renderListToHtml(val, env); if (_m == "raw-html") return rawHtmlContent(val); return escapeHtml((String(val))); })(); }; // RENDER_HTML_FORMS - var RENDER_HTML_FORMS = ["if", "when", "cond", "case", "let", "let*", "begin", "do", "define", "defcomp", "defmacro", "defstyle", "defkeyframes", "defhandler", "map", "map-indexed", "filter", "for-each"]; + var RENDER_HTML_FORMS = ["if", "when", "cond", "case", "let", "let*", "begin", "do", "define", "defcomp", "defmacro", "defstyle", "defhandler", "map", "map-indexed", "filter", "for-each"]; // render-html-form? var isRenderHtmlForm = function(name) { return contains(RENDER_HTML_FORMS, name); }; @@ -1339,7 +1278,7 @@ continue; } else { return NIL; } } }; var MATH_NS = "http://www.w3.org/1998/Math/MathML"; // render-to-dom - var renderToDom = function(expr, env, ns) { return (function() { var _m = typeOf(expr); if (_m == "nil") return createFragment(); if (_m == "boolean") return createFragment(); if (_m == "raw-html") return domParseHtml(rawHtmlContent(expr)); if (_m == "string") return createTextNode(expr); if (_m == "number") return createTextNode((String(expr))); if (_m == "symbol") return renderToDom(trampoline(evalExpr(expr, env)), env, ns); if (_m == "keyword") return createTextNode(keywordName(expr)); if (_m == "dom-node") return expr; if (_m == "dict") return createFragment(); if (_m == "list") return (isSxTruthy(isEmpty(expr)) ? createFragment() : renderDomList(expr, env, ns)); if (_m == "style-value") return createTextNode(styleValueClass(expr)); return createTextNode((String(expr))); })(); }; + var renderToDom = function(expr, env, ns) { return (function() { var _m = typeOf(expr); if (_m == "nil") return createFragment(); if (_m == "boolean") return createFragment(); if (_m == "raw-html") return domParseHtml(rawHtmlContent(expr)); if (_m == "string") return createTextNode(expr); if (_m == "number") return createTextNode((String(expr))); if (_m == "symbol") return renderToDom(trampoline(evalExpr(expr, env)), env, ns); if (_m == "keyword") return createTextNode(keywordName(expr)); if (_m == "dom-node") return expr; if (_m == "dict") return createFragment(); if (_m == "list") return (isSxTruthy(isEmpty(expr)) ? createFragment() : renderDomList(expr, env, ns)); return createTextNode((String(expr))); })(); }; // render-dom-list var renderDomList = function(expr, env, ns) { return (function() { @@ -1362,22 +1301,15 @@ continue; } else { return NIL; } } }; var renderDomElement = function(tag, args, env, ns) { return (function() { var newNs = (isSxTruthy((tag == "svg")) ? SVG_NS : (isSxTruthy((tag == "math")) ? MATH_NS : ns)); var el = domCreateElement(tag, newNs); - var extraClass = NIL; reduce(function(state, arg) { return (function() { var skip = get(state, "skip"); return (isSxTruthy(skip) ? assoc(state, "skip", false, "i", (get(state, "i") + 1)) : (isSxTruthy((isSxTruthy((typeOf(arg) == "keyword")) && ((get(state, "i") + 1) < len(args)))) ? (function() { var attrName = keywordName(arg); var attrVal = trampoline(evalExpr(nth(args, (get(state, "i") + 1)), env)); - (isSxTruthy(sxOr(isNil(attrVal), (attrVal == false))) ? NIL : (isSxTruthy((isSxTruthy((attrName == "style")) && isStyleValue(attrVal))) ? (extraClass = styleValueClass(attrVal)) : (isSxTruthy(contains(BOOLEAN_ATTRS, attrName)) ? (isSxTruthy(attrVal) ? domSetAttr(el, attrName, "") : NIL) : (isSxTruthy((attrVal == true)) ? domSetAttr(el, attrName, "") : domSetAttr(el, attrName, (String(attrVal))))))); + (isSxTruthy(sxOr(isNil(attrVal), (attrVal == false))) ? NIL : (isSxTruthy(contains(BOOLEAN_ATTRS, attrName)) ? (isSxTruthy(attrVal) ? domSetAttr(el, attrName, "") : NIL) : (isSxTruthy((attrVal == true)) ? domSetAttr(el, attrName, "") : domSetAttr(el, attrName, (String(attrVal)))))); return assoc(state, "skip", true, "i", (get(state, "i") + 1)); })() : ((isSxTruthy(!contains(VOID_ELEMENTS, tag)) ? domAppend(el, renderToDom(arg, env, newNs)) : NIL), assoc(state, "i", (get(state, "i") + 1))))); })(); }, {["i"]: 0, ["skip"]: false}, args); - if (isSxTruthy(extraClass)) { - (function() { - var existing = domGetAttr(el, "class"); - return domSetAttr(el, "class", (isSxTruthy(existing) ? (String(existing) + String(" ") + String(extraClass)) : extraClass)); -})(); -} return el; })(); }; @@ -1433,7 +1365,7 @@ continue; } else { return NIL; } } }; })(); }; // RENDER_DOM_FORMS - var RENDER_DOM_FORMS = ["if", "when", "cond", "case", "let", "let*", "begin", "do", "define", "defcomp", "defmacro", "defstyle", "defkeyframes", "defhandler", "map", "map-indexed", "filter", "for-each"]; + var RENDER_DOM_FORMS = ["if", "when", "cond", "case", "let", "let*", "begin", "do", "define", "defcomp", "defmacro", "defstyle", "defhandler", "map", "map-indexed", "filter", "for-each"]; // render-dom-form? var isRenderDomForm = function(name) { return contains(RENDER_DOM_FORMS, name); }; @@ -2089,180 +2021,6 @@ return bindInlineHandlers(root); }; var engineInit = function() { return (initCssTracking(), sxProcessScripts(NIL), sxHydrate(NIL), processElements(NIL)); }; - // === Transpiled from cssx === - - // _style-atoms - var _styleAtoms = {}; - - // _pseudo-variants - var _pseudoVariants = {}; - - // _responsive-breakpoints - var _responsiveBreakpoints = {}; - - // _style-keyframes - var _styleKeyframes = {}; - - // _arbitrary-patterns - var _arbitraryPatterns = []; - - // _child-selector-prefixes - var _childSelectorPrefixes = []; - - // _style-cache - var _styleCache = {}; - - // _injected-styles - var _injectedStyles = {}; - - // load-style-dict - var loadStyleDict = function(data) { _styleAtoms = sxOr(get(data, "a"), {}); -_pseudoVariants = sxOr(get(data, "v"), {}); -_responsiveBreakpoints = sxOr(get(data, "b"), {}); -_styleKeyframes = sxOr(get(data, "k"), {}); -_childSelectorPrefixes = sxOr(get(data, "c"), []); -_arbitraryPatterns = map(function(pair) { return {["re"]: compileRegex((String("^") + String(first(pair)) + String("$"))), ["tmpl"]: nth(pair, 1)}; }, sxOr(get(data, "p"), [])); -return (_styleCache = {}); }; - - // split-variant - var splitVariant = function(atom) { return (function() { - var result = NIL; - { var _c = keys(_responsiveBreakpoints); for (var _i = 0; _i < _c.length; _i++) { var bp = _c[_i]; if (isSxTruthy(isNil(result))) { - (function() { - var prefix = (String(bp) + String(":")); - return (isSxTruthy(startsWith(atom, prefix)) ? (function() { - var restAtom = slice(atom, len(prefix)); - return (function() { - var innerMatch = NIL; - { var _c = keys(_pseudoVariants); for (var _i = 0; _i < _c.length; _i++) { var pv = _c[_i]; if (isSxTruthy(isNil(innerMatch))) { - (function() { - var innerPrefix = (String(pv) + String(":")); - return (isSxTruthy(startsWith(restAtom, innerPrefix)) ? (innerMatch = [(String(bp) + String(":") + String(pv)), slice(restAtom, len(innerPrefix))]) : NIL); -})(); -} } } - return (result = sxOr(innerMatch, [bp, restAtom])); -})(); -})() : NIL); -})(); -} } } - if (isSxTruthy(isNil(result))) { - { var _c = keys(_pseudoVariants); for (var _i = 0; _i < _c.length; _i++) { var pv = _c[_i]; if (isSxTruthy(isNil(result))) { - (function() { - var prefix = (String(pv) + String(":")); - return (isSxTruthy(startsWith(atom, prefix)) ? (result = [pv, slice(atom, len(prefix))]) : NIL); -})(); -} } } -} - return sxOr(result, [NIL, atom]); -})(); }; - - // resolve-atom - var resolveAtom = function(atom) { return (function() { - var decls = dictGet(_styleAtoms, atom); - return (isSxTruthy(!isNil(decls)) ? decls : (isSxTruthy(startsWith(atom, "animate-")) ? (function() { - var kfName = slice(atom, 8); - return (isSxTruthy(dictHas(_styleKeyframes, kfName)) ? (String("animation-name:") + String(kfName)) : NIL); -})() : (function() { - var matchResult = NIL; - { var _c = _arbitraryPatterns; for (var _i = 0; _i < _c.length; _i++) { var pat = _c[_i]; if (isSxTruthy(isNil(matchResult))) { - (function() { - var m = regexMatch(get(pat, "re"), atom); - return (isSxTruthy(m) ? (matchResult = regexReplaceGroups(get(pat, "tmpl"), m)) : NIL); -})(); -} } } - return matchResult; -})())); -})(); }; - - // is-child-selector-atom? - var isChildSelectorAtom = function(atom) { return some(function(prefix) { return startsWith(atom, prefix); }, _childSelectorPrefixes); }; - - // hash-style - var hashStyle = function(input) { return fnv1aHash(input); }; - - // resolve-style - var resolveStyle = function(atoms) { return (function() { - var key = join("\\0", atoms); - return (function() { - var cached = dictGet(_styleCache, key); - return (isSxTruthy(!isNil(cached)) ? cached : (function() { - var baseDecls = []; - var mediaRules = []; - var pseudoRules = []; - var kfNeeded = []; - { var _c = atoms; for (var _i = 0; _i < _c.length; _i++) { var a = _c[_i]; if (isSxTruthy(a)) { - (function() { - var clean = (isSxTruthy(startsWith(a, ":")) ? slice(a, 1) : a); - return (function() { - var parts = splitVariant(clean); - return (function() { - var variant = first(parts); - var base = nth(parts, 1); - var decls = resolveAtom(base); - return (isSxTruthy(decls) ? ((isSxTruthy(startsWith(base, "animate-")) ? (function() { - var kfName = slice(base, 8); - return (isSxTruthy(dictHas(_styleKeyframes, kfName)) ? append_b(kfNeeded, [kfName, dictGet(_styleKeyframes, kfName)]) : NIL); -})() : NIL), (isSxTruthy(isNil(variant)) ? (isSxTruthy(isChildSelectorAtom(base)) ? append_b(pseudoRules, [">:not(:first-child)", decls]) : append_b(baseDecls, decls)) : (isSxTruthy(dictHas(_responsiveBreakpoints, variant)) ? append_b(mediaRules, [dictGet(_responsiveBreakpoints, variant), decls]) : (isSxTruthy(dictHas(_pseudoVariants, variant)) ? append_b(pseudoRules, [dictGet(_pseudoVariants, variant), decls]) : (function() { - var vparts = split(variant, ":"); - var mediaPart = NIL; - var pseudoPart = NIL; - { var _c = vparts; for (var _i = 0; _i < _c.length; _i++) { var vp = _c[_i]; (isSxTruthy(dictHas(_responsiveBreakpoints, vp)) ? (mediaPart = dictGet(_responsiveBreakpoints, vp)) : (isSxTruthy(dictHas(_pseudoVariants, vp)) ? (pseudoPart = dictGet(_pseudoVariants, vp)) : NIL)); } } - if (isSxTruthy(mediaPart)) { - mediaRules.push([mediaPart, decls]); -} - if (isSxTruthy(pseudoPart)) { - pseudoRules.push([pseudoPart, decls]); -} - return (isSxTruthy((isSxTruthy(isNil(mediaPart)) && isNil(pseudoPart))) ? append_b(baseDecls, decls) : NIL); -})())))) : NIL); -})(); -})(); -})(); -} } } - return (function() { - var hashInput = join(";", baseDecls); - { var _c = mediaRules; for (var _i = 0; _i < _c.length; _i++) { var mr = _c[_i]; hashInput = (String(hashInput) + String("@") + String(first(mr)) + String("{") + String(nth(mr, 1)) + String("}")); } } - { var _c = pseudoRules; for (var _i = 0; _i < _c.length; _i++) { var pr = _c[_i]; hashInput = (String(hashInput) + String(first(pr)) + String("{") + String(nth(pr, 1)) + String("}")); } } - { var _c = kfNeeded; for (var _i = 0; _i < _c.length; _i++) { var kf = _c[_i]; hashInput = (String(hashInput) + String(nth(kf, 1))); } } - return (function() { - var cn = (String("sx-") + String(hashStyle(hashInput))); - var sv = makeStyleValue_(cn, join(";", baseDecls), mediaRules, pseudoRules, kfNeeded); - _styleCache[key] = sv; - injectStyleValue(sv, atoms); - return sv; -})(); -})(); -})()); -})(); -})(); }; - - // merge-style-values - var mergeStyleValues = function(styles) { return (isSxTruthy((len(styles) == 1)) ? first(styles) : (function() { - var allDecls = []; - var allMedia = []; - var allPseudo = []; - var allKf = []; - { var _c = styles; for (var _i = 0; _i < _c.length; _i++) { var sv = _c[_i]; if (isSxTruthy(styleValueDeclarations(sv))) { - allDecls.push(styleValueDeclarations(sv)); -} -allMedia = concat(allMedia, styleValueMediaRules(sv)); -allPseudo = concat(allPseudo, styleValuePseudoRules(sv)); -allKf = concat(allKf, styleValueKeyframes_(sv)); } } - return (function() { - var hashInput = join(";", allDecls); - { var _c = allMedia; for (var _i = 0; _i < _c.length; _i++) { var mr = _c[_i]; hashInput = (String(hashInput) + String("@") + String(first(mr)) + String("{") + String(nth(mr, 1)) + String("}")); } } - { var _c = allPseudo; for (var _i = 0; _i < _c.length; _i++) { var pr = _c[_i]; hashInput = (String(hashInput) + String(first(pr)) + String("{") + String(nth(pr, 1)) + String("}")); } } - { var _c = allKf; for (var _i = 0; _i < _c.length; _i++) { var kf = _c[_i]; hashInput = (String(hashInput) + String(nth(kf, 1))); } } - return (function() { - var cn = (String("sx-") + String(hashStyle(hashInput))); - var merged = makeStyleValue_(cn, join(";", allDecls), allMedia, allPseudo, allKf); - injectStyleValue(merged, []); - return merged; -})(); -})(); -})()); }; - - // === Transpiled from boot === // HEAD_HOIST_SELECTOR @@ -2363,30 +2121,10 @@ callExpr.push(dictGet(kwargs, k)); } } })(); return setSxCompCookie(hash); })()); -})(); }; - - // init-style-dict - var initStyleDict = function() { return (function() { - var scripts = queryStyleScripts(); - return forEach(function(s) { return (isSxTruthy(!isProcessed(s, "styles")) ? (markProcessed(s, "styles"), (function() { - var text = domTextContent(s); - var hash = domGetAttr(s, "data-hash"); - return (isSxTruthy(isNil(hash)) ? (isSxTruthy((isSxTruthy(text) && !isEmpty(trim(text)))) ? parseAndLoadStyleDict(text) : NIL) : (function() { - var hasInline = (isSxTruthy(text) && !isEmpty(trim(text))); - (function() { - var cachedHash = localStorageGet("sx-styles-hash"); - return (isSxTruthy((cachedHash == hash)) ? (isSxTruthy(hasInline) ? (localStorageSet("sx-styles-src", text), parseAndLoadStyleDict(text), logInfo("styles: downloaded (cookie stale)")) : (function() { - var cached = localStorageGet("sx-styles-src"); - return (isSxTruthy(cached) ? (parseAndLoadStyleDict(cached), logInfo((String("styles: cached (") + String(hash) + String(")")))) : (clearSxStylesCookie(), browserReload())); -})()) : (isSxTruthy(hasInline) ? (localStorageSet("sx-styles-hash", hash), localStorageSet("sx-styles-src", text), parseAndLoadStyleDict(text), logInfo((String("styles: downloaded (") + String(hash) + String(")")))) : (localStorageRemove("sx-styles-hash"), localStorageRemove("sx-styles-src"), clearSxStylesCookie(), browserReload()))); -})(); - return setSxStylesCookie(hash); -})()); -})()) : NIL); }, scripts); })(); }; // boot-init - var bootInit = function() { return (initCssTracking(), initStyleDict(), processSxScripts(NIL), sxHydrateElements(NIL), processElements(NIL)); }; + var bootInit = function() { return (initCssTracking(), processSxScripts(NIL), sxHydrateElements(NIL), processElements(NIL)); }; // === Transpiled from deps (component dependency analysis) === @@ -3290,70 +3028,6 @@ callExpr.push(dictGet(kwargs, k)); } } return result; } - function makeStyleValue_(cn, decls, media, pseudo, kf) { - return new StyleValue(cn, decls || "", media || [], pseudo || [], kf || []); - } - - function styleValueDeclarations(sv) { return sv.declarations; } - function styleValueMediaRules(sv) { return sv.mediaRules; } - function styleValuePseudoRules(sv) { return sv.pseudoRules; } - function styleValueKeyframes_(sv) { return sv.keyframes; } - - function injectStyleValue(sv, atoms) { - if (_injectedStyles[sv.className]) return; - _injectedStyles[sv.className] = true; - - if (!_hasDom) return; - var cssTarget = document.getElementById("sx-css"); - if (!cssTarget) return; - - var rules = []; - // Child-selector atoms are now routed to pseudoRules by the resolver - // with selector ">:not(:first-child)", so base declarations are always - // applied directly to the class. - if (sv.declarations) { - rules.push("." + sv.className + "{" + sv.declarations + "}"); - } - for (var pi = 0; pi < sv.pseudoRules.length; pi++) { - var sel = sv.pseudoRules[pi][0], decls = sv.pseudoRules[pi][1]; - if (sel.indexOf("&") >= 0) { - rules.push(sel.replace(/&/g, "." + sv.className) + "{" + decls + "}"); - } else { - rules.push("." + sv.className + sel + "{" + decls + "}"); - } - } - for (var mi = 0; mi < sv.mediaRules.length; mi++) { - rules.push("@media " + sv.mediaRules[mi][0] + "{." + sv.className + "{" + sv.mediaRules[mi][1] + "}}"); - } - for (var ki = 0; ki < sv.keyframes.length; ki++) { - rules.push(sv.keyframes[ki][1]); - } - cssTarget.textContent += rules.join(""); - } - - // Replace stub css primitive with real CSSX implementation - PRIMITIVES["css"] = function() { - var atoms = []; - for (var i = 0; i < arguments.length; i++) { - var a = arguments[i]; - if (isNil(a) || a === false) continue; - atoms.push(isKw(a) ? a.name : String(a)); - } - if (!atoms.length) return NIL; - return resolveStyle(atoms); - }; - - PRIMITIVES["merge-styles"] = function() { - var valid = []; - for (var i = 0; i < arguments.length; i++) { - if (isStyleValue(arguments[i])) valid.push(arguments[i]); - } - if (!valid.length) return NIL; - if (valid.length === 1) return valid[0]; - return mergeStyleValues(valid); - }; - - // ========================================================================= // Platform interface — Boot (mount, hydrate, scripts, cookies) // ========================================================================= @@ -3410,12 +3084,6 @@ callExpr.push(dictGet(kwargs, k)); } } r.querySelectorAll('script[type="text/sx"]')); } - function queryStyleScripts() { - if (!_hasDom) return []; - return Array.prototype.slice.call( - document.querySelectorAll('script[type="text/sx-styles"]')); - } - // --- localStorage --- function localStorageGet(key) { @@ -3441,14 +3109,6 @@ callExpr.push(dictGet(kwargs, k)); } } if (_hasDom) document.cookie = "sx-comp-hash=;path=/;max-age=0;SameSite=Lax"; } - function setSxStylesCookie(hash) { - if (_hasDom) document.cookie = "sx-styles-hash=" + hash + ";path=/;max-age=31536000;SameSite=Lax"; - } - - function clearSxStylesCookie() { - if (_hasDom) document.cookie = "sx-styles-hash=;path=/;max-age=0;SameSite=Lax"; - } - // --- Env helpers --- function parseEnvAttr(el) { @@ -3493,12 +3153,6 @@ callExpr.push(dictGet(kwargs, k)); } } } } - function parseAndLoadStyleDict(text) { - try { loadStyleDict(JSON.parse(text)); } - catch (e) { if (typeof console !== "undefined") console.warn("[sx-ref] style dict parse error", e); } - } - - // ========================================================================= // Post-transpilation fixups // ========================================================================= @@ -3675,7 +3329,7 @@ callExpr.push(dictGet(kwargs, k)); } } transitiveIoRefs: transitiveIoRefs, computeAllIoRefs: computeAllIoRefs, componentPure_p: componentPure_p, - _version: "ref-2.0 (boot+cssx+dom+engine+html+orchestration+parser+sx, bootstrap-compiled)" + _version: "ref-2.0 (boot+dom+engine+html+orchestration+parser+sx, bootstrap-compiled)" }; diff --git a/shared/static/scripts/sx.js b/shared/static/scripts/sx.js index 49f32b3..a1ae93b 100644 --- a/shared/static/scripts/sx.js +++ b/shared/static/scripts/sx.js @@ -63,23 +63,12 @@ function RawHTML(html) { this.html = html; } RawHTML.prototype._raw = true; - /** CSSX StyleValue — generated CSS class with rules. */ - function StyleValue(className, declarations, mediaRules, pseudoRules, keyframes) { - this.className = className; - this.declarations = declarations || ""; - this.mediaRules = mediaRules || []; - this.pseudoRules = pseudoRules || []; - this.keyframes = keyframes || []; - } - StyleValue.prototype._styleValue = true; - function isSym(x) { return x && x._sym === true; } function isKw(x) { return x && x._kw === true; } function isLambda(x) { return x && x._lambda === true; } function isComponent(x) { return x && x._component === true; } function isMacro(x) { return x && x._macro === true; } function isRaw(x) { return x && x._raw === true; } - function isStyleValue(x) { return x && x._styleValue === true; } // --- Parser --- @@ -416,227 +405,6 @@ return String(s).split(",").map(function(x) { return x.trim(); }).filter(function(x) { return x; }); }; - // --- CSSX Style Dictionary + Resolver --- - - var _styleAtoms = {}; // atom → CSS declarations - var _pseudoVariants = {}; // variant → CSS pseudo-selector - var _responsiveBreakpoints = {}; // variant → media query - var _styleKeyframes = {}; // name → @keyframes rule - var _arbitraryPatterns = []; // [{re: RegExp, tmpl: string}, ...] - var _childSelectorPrefixes = []; // ["space-x-", "space-y-", ...] - var _styleCache = {}; // atoms-key → StyleValue - var _injectedStyles = {}; // className → true (already in - @@ -820,14 +819,6 @@ def sx_page(ctx: dict, page_sx: str, *, import logging logging.getLogger("sx").warning("Pretty-print page_sx failed: %s", e) - # Style dictionary for client-side css primitive - styles_hash = _get_style_dict_hash() - client_styles_hash = _get_sx_styles_cookie() - if not _is_dev_mode() and client_styles_hash and client_styles_hash == styles_hash: - styles_json = "" # Client has cached version - else: - styles_json = _build_style_dict_json() - # Page registry for client-side routing import logging _plog = logging.getLogger("sx.pages") @@ -844,8 +835,6 @@ def sx_page(ctx: dict, page_sx: str, *, csrf=_html_escape(csrf), component_hash=component_hash, component_defs=component_defs, - styles_hash=styles_hash, - styles_json=styles_json, pages_sx=pages_sx, page_sx=page_sx, sx_css=sx_css, @@ -907,10 +896,6 @@ def sx_page_streaming_parts(ctx: dict, page_html: str, *, title = ctx.get("base_title", "Rose Ash") csrf = _get_csrf_token() - styles_hash = _get_style_dict_hash() - client_styles_hash = _get_sx_styles_cookie() - styles_json = "" if (not _is_dev_mode() and client_styles_hash == styles_hash) else _build_style_dict_json() - import logging from quart import current_app pages_sx = _build_pages_sx(current_app.name) @@ -953,7 +938,6 @@ def sx_page_streaming_parts(ctx: dict, page_html: str, *, '\n' '\n' '\n' - f'\n' f'\n' f'\n' # Server-rendered HTML — suspense placeholders are real DOM elements @@ -989,58 +973,6 @@ def sx_streaming_resolve_script(suspension_id: str, sx_source: str, _SCRIPT_HASH_CACHE: dict[str, str] = {} -_STYLE_DICT_JSON: str = "" -_STYLE_DICT_HASH: str = "" - - -def _build_style_dict_json() -> str: - """Build compact JSON style dictionary for client-side css primitive.""" - global _STYLE_DICT_JSON, _STYLE_DICT_HASH - if _STYLE_DICT_JSON: - return _STYLE_DICT_JSON - - import json - from .style_dict import ( - STYLE_ATOMS, PSEUDO_VARIANTS, RESPONSIVE_BREAKPOINTS, - KEYFRAMES, ARBITRARY_PATTERNS, CHILD_SELECTOR_ATOMS, - ) - - # Derive child selector prefixes from CHILD_SELECTOR_ATOMS - prefixes = set() - for atom in CHILD_SELECTOR_ATOMS: - # "space-y-4" → "space-y-", "divide-y" → "divide-" - for sep in ("space-x-", "space-y-", "divide-x", "divide-y"): - if atom.startswith(sep): - prefixes.add(sep) - break - - data = { - "a": STYLE_ATOMS, - "v": PSEUDO_VARIANTS, - "b": RESPONSIVE_BREAKPOINTS, - "k": KEYFRAMES, - "p": ARBITRARY_PATTERNS, - "c": sorted(prefixes), - } - _STYLE_DICT_JSON = json.dumps(data, separators=(",", ":")) - _STYLE_DICT_HASH = hashlib.md5(_STYLE_DICT_JSON.encode()).hexdigest()[:8] - return _STYLE_DICT_JSON - - -def _get_style_dict_hash() -> str: - """Get the hash of the style dictionary JSON.""" - if not _STYLE_DICT_HASH: - _build_style_dict_json() - return _STYLE_DICT_HASH - - -def _get_sx_styles_cookie() -> str: - """Read the sx-styles-hash cookie from the current request.""" - try: - from quart import request - return request.cookies.get("sx-styles-hash", "") - except RuntimeError: - return "" def _script_hash(filename: str) -> str: diff --git a/shared/sx/html.py b/shared/sx/html.py index 8123ada..820f341 100644 --- a/shared/sx/html.py +++ b/shared/sx/html.py @@ -27,7 +27,7 @@ from __future__ import annotations import contextvars from typing import Any -from .types import Component, Keyword, Lambda, Macro, NIL, StyleValue, Symbol +from .types import Component, Keyword, Lambda, Macro, NIL, Symbol from .evaluator import _eval as _raw_eval, _call_component as _raw_call_component, _expand_macro, _trampoline def _eval(expr, env): @@ -510,19 +510,6 @@ def _render_element(tag: str, args: list, env: dict[str, Any]) -> str: children.append(arg) i += 1 - # Handle :style StyleValue — convert to class and register CSS rule - style_val = attrs.get("style") - if isinstance(style_val, StyleValue): - from .css_registry import register_generated_rule - register_generated_rule(style_val) - # Merge into :class - existing_class = attrs.get("class") - if existing_class and existing_class is not NIL and existing_class is not False: - attrs["class"] = f"{existing_class} {style_val.class_name}" - else: - attrs["class"] = style_val.class_name - del attrs["style"] - # Collect CSS classes if collector is active class_val = attrs.get("class") if class_val is not None and class_val is not NIL and class_val is not False: diff --git a/shared/sx/parser.py b/shared/sx/parser.py index 4017ec4..f38af53 100644 --- a/shared/sx/parser.py +++ b/shared/sx/parser.py @@ -380,11 +380,6 @@ def serialize(expr: Any, indent: int = 0, pretty: bool = False) -> str: items.append(serialize(v, indent, pretty)) return "{" + " ".join(items) + "}" - # StyleValue — serialize as class name string - from .types import StyleValue - if isinstance(expr, StyleValue): - return f'"{expr.class_name}"' - # _RawHTML — pre-rendered HTML; wrap as (raw! "...") for SX wire format from .html import _RawHTML if isinstance(expr, _RawHTML): diff --git a/shared/sx/primitives_stdlib.py b/shared/sx/primitives_stdlib.py index d019339..650aa12 100644 --- a/shared/sx/primitives_stdlib.py +++ b/shared/sx/primitives_stdlib.py @@ -89,37 +89,6 @@ def prim_strip_tags(s: str) -> str: return re.sub(r"<[^>]+>", "", s) -# --------------------------------------------------------------------------- -# stdlib.style -# --------------------------------------------------------------------------- - -@register_primitive("css") -def prim_css(*args: Any) -> Any: - """``(css :flex :gap-4 :hover:bg-sky-200)`` → StyleValue.""" - from .types import Keyword - from .style_resolver import resolve_style - atoms = tuple( - (a.name if isinstance(a, Keyword) else str(a)) - for a in args if a is not None and a is not NIL and a is not False - ) - if not atoms: - return NIL - return resolve_style(atoms) - - -@register_primitive("merge-styles") -def prim_merge_styles(*styles: Any) -> Any: - """``(merge-styles style1 style2)`` → merged StyleValue.""" - from .types import StyleValue - from .style_resolver import merge_styles - valid = [s for s in styles if isinstance(s, StyleValue)] - if not valid: - return NIL - if len(valid) == 1: - return valid[0] - return merge_styles(valid) - - # --------------------------------------------------------------------------- # stdlib.debug # --------------------------------------------------------------------------- diff --git a/shared/sx/ref/BOUNDARY.md b/shared/sx/ref/BOUNDARY.md index 40b4279..8b151c9 100644 --- a/shared/sx/ref/BOUNDARY.md +++ b/shared/sx/ref/BOUNDARY.md @@ -38,7 +38,6 @@ Only these types may cross the host-SX boundary: | list | `list` | `Array` | `Vec` | | dict | `dict` | `Object` / `Map` | `HashMap` | | sx-source | `SxExpr` wrapper | `string` | `String` | -| style-value | `StyleValue` | `StyleValue` | `StyleValue` | **NOT allowed:** ORM models, datetime objects, request objects, raw callables, framework types. Convert at the edge before crossing. diff --git a/shared/sx/ref/adapter-dom.sx b/shared/sx/ref/adapter-dom.sx index fda72ee..f338a49 100644 --- a/shared/sx/ref/adapter-dom.sx +++ b/shared/sx/ref/adapter-dom.sx @@ -52,9 +52,6 @@ (create-fragment) (render-dom-list expr env ns)) - ;; Style value → text of class name - "style-value" (create-text-node (style-value-class expr)) - ;; Fallback :else (create-text-node (str expr))))) @@ -147,8 +144,7 @@ (let ((new-ns (cond (= tag "svg") SVG_NS (= tag "math") MATH_NS :else ns)) - (el (dom-create-element tag new-ns)) - (extra-class nil)) + (el (dom-create-element tag new-ns))) ;; Process args: keywords → attrs, others → children (reduce @@ -168,9 +164,6 @@ ;; nil or false → skip (or (nil? attr-val) (= attr-val false)) nil - ;; :style StyleValue → convert to class - (and (= attr-name "style") (style-value? attr-val)) - (set! extra-class (style-value-class attr-val)) ;; Boolean attr (contains? BOOLEAN_ATTRS attr-name) (when attr-val (dom-set-attr el attr-name "")) @@ -190,12 +183,6 @@ (dict "i" 0 "skip" false) args) - ;; Merge StyleValue class - (when extra-class - (let ((existing (dom-get-attr el "class"))) - (dom-set-attr el "class" - (if existing (str existing " " extra-class) extra-class)))) - el))) @@ -297,7 +284,7 @@ (define RENDER_DOM_FORMS (list "if" "when" "cond" "case" "let" "let*" "begin" "do" - "define" "defcomp" "defmacro" "defstyle" "defkeyframes" "defhandler" + "define" "defcomp" "defmacro" "defstyle" "defhandler" "map" "map-indexed" "filter" "for-each")) (define render-dom-form? @@ -450,7 +437,6 @@ ;; ;; From render.sx: ;; HTML_TAGS, VOID_ELEMENTS, BOOLEAN_ATTRS, definition-form? -;; style-value?, style-value-class ;; ;; From eval.sx: ;; eval-expr, trampoline, expand-macro, process-bindings, eval-cond diff --git a/shared/sx/ref/adapter-html.sx b/shared/sx/ref/adapter-html.sx index cf9e702..a910035 100644 --- a/shared/sx/ref/adapter-html.sx +++ b/shared/sx/ref/adapter-html.sx @@ -41,7 +41,6 @@ "boolean" (if val "true" "false") "list" (render-list-to-html val env) "raw-html" (raw-html-content val) - "style-value" (style-value-class val) :else (escape-html (str val))))) @@ -51,7 +50,7 @@ (define RENDER_HTML_FORMS (list "if" "when" "cond" "case" "let" "let*" "begin" "do" - "define" "defcomp" "defmacro" "defstyle" "defkeyframes" "defhandler" + "define" "defcomp" "defmacro" "defstyle" "defhandler" "map" "map-indexed" "filter" "for-each")) (define render-html-form? @@ -293,7 +292,7 @@ ;; -------------------------------------------------------------------------- ;; ;; Inherited from render.sx: -;; escape-html, escape-attr, raw-html-content, style-value?, style-value-class +;; escape-html, escape-attr, raw-html-content ;; ;; From eval.sx: ;; eval-expr, trampoline, expand-macro, process-bindings, eval-cond diff --git a/shared/sx/ref/async_eval_ref.py b/shared/sx/ref/async_eval_ref.py index e037e02..af9c903 100644 --- a/shared/sx/ref/async_eval_ref.py +++ b/shared/sx/ref/async_eval_ref.py @@ -26,7 +26,7 @@ import contextvars import inspect from typing import Any -from ..types import Component, Keyword, Lambda, Macro, NIL, StyleValue, Symbol +from ..types import Component, Keyword, Lambda, Macro, NIL, Symbol from ..parser import SxExpr, serialize from ..primitives_io import IO_PRIMITIVES, RequestContext, execute_io from ..html import ( @@ -250,18 +250,6 @@ async def _arender_element(tag, args, env, ctx): children.append(arg) i += 1 - # StyleValue → class - style_val = attrs.get("style") - if isinstance(style_val, StyleValue): - from ..css_registry import register_generated_rule - register_generated_rule(style_val) - existing = attrs.get("class") - if existing and existing is not NIL and existing is not False: - attrs["class"] = f"{existing} {style_val.class_name}" - else: - attrs["class"] = style_val.class_name - del attrs["style"] - class_val = attrs.get("class") if class_val is not None and class_val is not NIL and class_val is not False: collector = css_class_collector.get(None) @@ -464,7 +452,6 @@ _ASYNC_RENDER_FORMS = { "do": _arsf_begin, "define": _arsf_define, "defstyle": _arsf_define, - "defkeyframes": _arsf_define, "defcomp": _arsf_define, "defmacro": _arsf_define, "defhandler": _arsf_define, @@ -716,23 +703,18 @@ async def _aser_call(name, args, env, ctx): if isinstance(arg, Keyword) and i + 1 < len(args): val = await _aser(args[i + 1], env, ctx) if val is not NIL and val is not None: - if arg.name == "style" and isinstance(val, StyleValue): - from ..css_registry import register_generated_rule - register_generated_rule(val) - extra_class = val.class_name - else: - parts.append(f":{arg.name}") - if isinstance(val, list): - live = [v for v in val if v is not NIL and v is not None] - items = [serialize(v) for v in live] - if not items: - parts.append("nil") - elif any(isinstance(v, SxExpr) for v in live): - parts.append("(<> " + " ".join(items) + ")") - else: - parts.append("(list " + " ".join(items) + ")") + parts.append(f":{arg.name}") + if isinstance(val, list): + live = [v for v in val if v is not NIL and v is not None] + items = [serialize(v) for v in live] + if not items: + parts.append("nil") + elif any(isinstance(v, SxExpr) for v in live): + parts.append("(<> " + " ".join(items) + ")") else: - parts.append(serialize(val)) + parts.append("(list " + " ".join(items) + ")") + else: + parts.append(serialize(val)) i += 2 else: result = await _aser(arg, env, ctx) @@ -996,7 +978,6 @@ _ASER_FORMS = { "fn": _assf_lambda, "define": _assf_define, "defstyle": _assf_define, - "defkeyframes": _assf_define, "defcomp": _assf_define, "defmacro": _assf_define, "defhandler": _assf_define, diff --git a/shared/sx/ref/boot.sx b/shared/sx/ref/boot.sx index f3a9cd6..8f85e85 100644 --- a/shared/sx/ref/boot.sx +++ b/shared/sx/ref/boot.sx @@ -3,16 +3,14 @@ ;; ;; Handles the browser startup lifecycle: ;; 1. CSS tracking init -;; 2. Style dictionary loading (from