{ "version": 3, "sources": ["../../../../../../../src/js/lib/baby-lisp.js", "../../../../../../../src/js/lib/baby-lisp-apply.js", "../../../../../../../src/js/lib/booleanbucket.js", "../../../../../../../src/js/lib/mode.js", "../../../../../../../src/js/lib/a11y-user-detect.js"], "sourcesContent": ["// https://gist.github.com/jameslaneconkling/24acb8ea326a1c8fdf64225aa7d0f44e\nconst rules = [\n { type: \"space\", regex: /^\\s/ },\n { type: \"lParen\", regex: /^\\(/ },\n { type: \"rParen\", regex: /^\\)/ },\n { type: \"number\", regex: /^[0-9.]+/ },\n { type: \"string\", regex: /^\".*?\"/ },\n { type: \"variable\", regex: /^[^\\s()]+/ } // take from the beginning 1+ characters until you hit a ' ', '(', or ')' // TODO - support escaped double quote\n];\n\nconst tokenizer = rules => input => {\n for (let i = 0; i < rules.length; i += 1) {\n let tokenized = rules[i].regex.exec(input);\n if (tokenized) {\n return {\n token: tokenized[0],\n type: rules[i].type,\n rest: input.slice(tokenized[0].length)\n };\n }\n }\n\n throw new Error(`no matching tokenize rule for ${JSON.stringify(input)}`);\n};\n\nconst parser = tokenize =>\n function parse(input, ast, parents = []) {\n if (input === \"\") {\n return ast;\n }\n\n const { token, type, rest } = tokenize(input);\n\n if (type === \"space\") {\n // do nothing\n return parse(rest, ast, parents);\n } else if (type === \"variable\") {\n ast.push(token);\n return parse(rest, ast, parents);\n } else if (type === \"number\") {\n ast.push(Number(token));\n return parse(rest, ast, parents);\n } else if (type === \"string\") {\n ast.push(token.replace(/(^\"|\"$)/g, \"'\"));\n return parse(rest, ast, parents);\n } else if (type === \"lParen\") {\n parents.push(ast);\n return parse(rest, [], parents);\n } else if (type === \"rParen\") {\n const parentAst = parents.pop();\n if (parentAst) {\n parentAst.push(ast);\n return parse(rest, parentAst, parents);\n }\n\n return parse(rest, ast, parents);\n }\n\n throw new Error(`Missing parse logic for rule ${JSON.stringify(type)}`);\n };\n\nexport default parser(tokenizer(rules));\n", "import parse from \"./baby-lisp.js\";\nimport * as L from \"./functional.js\";\n\n/**\n * @typedef {Object} Bucket\n * @property {method} get Method to get key\n */\n\n/**\n * Test string against a bucket's contents\n * @function\n * @param {Bucket} bucket with a get(key) method returning a Boolean\n * or undefined.\n * @param {String} string Lispy string to test against the bucket\n */\nexport const stringSaysDo = (bucket, string) => {\n const ast = parse(`(${string})`);\n return astSaysDo(bucket)(ast);\n};\n\n/**\n * Test ast against bucket's contents\n * @function\n * @param {Bucket} bucket with a get(key) method returning a Boolean\n * or undefined.\n * @param {Object} AST Lispy AST (nested array of strings) to test against the bucket\n */\nconst astSaysDo = bucket => ast => {\n if (ast instanceof Array) {\n if (ast[0] === \"and\") {\n return L.compose(L.all(astSaysDo(bucket)), L.tail)(ast);\n }\n if (ast[0] === \"or\") {\n return L.compose(L.any(astSaysDo(bucket)), L.tail)(ast);\n }\n if (ast[0] === \"not\") {\n return L.compose(L.not, L.any(astSaysDo(bucket)), L.tail)(ast);\n }\n return L.compose(L.any(astSaysDo(bucket)))(ast);\n } else {\n return bucket.get(ast);\n }\n};\n", "export class BooleanBucket {\n constructor() {\n this.booleans = [];\n }\n /**\n * @param {String} key Key to get\n */\n get(key) {\n return this.booleans[key];\n }\n /**\n * @param {String} key Key to set\n */\n set(key) {\n return this.toggle(key, true);\n }\n /**\n * @param {String} key Key to unset\n */\n unset(key) {\n return this.toggle(key, false);\n }\n /**\n * @param {String} key Key to toggle\n * @param {Boolean} [bool] New value\n */\n toggle(key, bool) {\n bool = typeof bool === \"boolean\" ? bool : !this.get(key);\n if (bool !== this.get(key)) {\n this.booleans[key] = bool;\n return [true, bool];\n } else {\n return [false, bool];\n }\n }\n}\n", "/* global $ */\nimport { stringSaysDo } from \"./baby-lisp-apply.js\";\nimport { BooleanBucket } from \"./booleanbucket.js\";\n\nclass BucketWithConsequences extends BooleanBucket {\n /**\n * @param {String} key Key to toggle\n * @param {Boolean} [bool] New value\n * @param {Boolean} [reflect] Reflect the key as a class in the \n\n * Will hide or show any element which has somewhere inside data-when or data-hide-when attribute.\n * Whether or not to show or hide is based on the parsing of those attributes.\n *\n * See baby-lisp.test.js for examples.\n */\n toggle(mode, bool, reflect = true) {\n if (mode.includes('\"')) {\n console.warn(\n \"Mode contains a double quote, that is not allowed - used in querySelectorAll\"\n );\n return this;\n }\n const [changedOrAdded, bool2] = super.toggle(mode, bool);\n // Refrain from unnecessary redraw (by checking previous value):\n if (changedOrAdded) {\n $(document).trigger(\"bb:mode:\" + mode, bool2);\n if (reflect) $(\"body\").toggleClass(mode, bool2);\n {\n [\n ...document.querySelectorAll(\n '[data-when*=\"' + mode + '\"], [data-hide-when*=\"' + mode + '\"]'\n )\n ].forEach(elt => {\n let hidden = false;\n const hideWhen = elt.dataset[\"hideWhen\"];\n if (hideWhen) {\n hidden = stringSaysDo(this, hideWhen);\n }\n // hideWhen is absent or yields false, so still shown, and\n // when becomes the judge:\n if (!hidden) {\n const when = elt.dataset[\"when\"];\n // If there is no when, still show.\n if (when) {\n hidden = !stringSaysDo(this, when);\n }\n }\n elt.hidden = hidden;\n });\n }\n }\n return this;\n }\n}\n\nconst Mode = new BucketWithConsequences();\n\nexport { Mode };\n", "/* a11y-user-detect:\n *\n * \"User Detect\" will dynamically toggle between\n * a-keyboard-user & a-mouse-user (described in a11y.less)\n * depending on user interaction on document.\n *\n * The idea is to give keyboard users more visual queues,\n * without effecting the aesthetics for non-keyboard users.\n *\n * Author: Tim Bauwens\n * Copyright 2017 Berkeley Bridge\n *\n */\n\nimport { Mode } from \"$json/lib/mode\";\n\nexport const isKeyboardUser = () => Mode.get(\"a-keyboard-user\");\n\nexport const isMouseUser = () => Mode.get(\"a-mouse-user\");\n\nexport const setKeyboardUser = () => {\n Mode.set(\"a-keyboard-user\");\n Mode.unset(\"a-mouse-user\");\n};\n\nexport const setMouseUser = () => {\n Mode.unset(\"a-keyboard-user\");\n Mode.set(\"a-mouse-user\");\n};\n\n$(function () {\n let openingMatch, mouse;\n try {\n // Could have no opener, or opener could be X-Origin\n if (window.opener.document.body) {\n openingMatch = window.opener.document.body.className.match(\n /\\ba-(keyboard|mouse)-user\\b/\n );\n if (openingMatch) mouse = openingMatch[1] === \"mouse\";\n }\n } catch (e) {\n mouse = false;\n }\n if (mouse) {\n setMouseUser();\n } else {\n setKeyboardUser();\n }\n $(document.body).on(\"mousedown touchstart\", function () {\n setMouseUser();\n });\n $(document.body).on(\"keydown\", function (e) {\n if (\n e.key === \"Tab\" ||\n e.target.matches(`input[type=\"radio\"], input[type=\"checkbox\"]`)\n ) {\n setKeyboardUser();\n }\n });\n});\n"], "mappings": "oEACA,GAAM,GAAQ,CACZ,CAAE,KAAM,QAAS,MAAO,OACxB,CAAE,KAAM,SAAU,MAAO,OACzB,CAAE,KAAM,SAAU,MAAO,OACzB,CAAE,KAAM,SAAU,MAAO,YACzB,CAAE,KAAM,SAAU,MAAO,UACzB,CAAE,KAAM,WAAY,MAAO,cAGvB,EAAY,GAAS,GAAS,CAClC,OAAS,GAAI,EAAG,EAAI,EAAM,OAAQ,GAAK,EAAG,CACxC,GAAI,GAAY,EAAM,GAAG,MAAM,KAAK,GACpC,GAAI,EACF,MAAO,CACL,MAAO,EAAU,GACjB,KAAM,EAAM,GAAG,KACf,KAAM,EAAM,MAAM,EAAU,GAAG,SAKrC,KAAM,IAAI,OAAM,iCAAiC,KAAK,UAAU,OAG5D,EAAS,GACb,WAAe,EAAO,EAAK,EAAU,GAAI,CACvC,GAAI,IAAU,GACZ,MAAO,GAGT,GAAM,CAAE,QAAO,OAAM,QAAS,EAAS,GAEvC,GAAI,IAAS,QAEX,MAAO,GAAM,EAAM,EAAK,GACnB,GAAI,IAAS,WAClB,SAAI,KAAK,GACF,EAAM,EAAM,EAAK,GACnB,GAAI,IAAS,SAClB,SAAI,KAAK,OAAO,IACT,EAAM,EAAM,EAAK,GACnB,GAAI,IAAS,SAClB,SAAI,KAAK,EAAM,QAAQ,WAAY,MAC5B,EAAM,EAAM,EAAK,GACnB,GAAI,IAAS,SAClB,SAAQ,KAAK,GACN,EAAM,EAAM,GAAI,GA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