UNPKG

damon-utils

Version:
231 lines (211 loc) 7.24 kB
<!DOCTYPE html> <html lang="en" data-state="js-off"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="./vendor/normalize.css-main/normalize.css"> <script> // Javascript-on document.documentElement.dataset.state = ''; </script> <style></style> <style> body { --fonts-core: Segoe UI, Roboto, sans-serif, Arial, Liberation Sans; --fonts-code: Consolas, Menlo, JuliaMono, Liberation Mono, monospace; --fonts-variable: Segoe UI Variable, Roboto Flex, SF Pro Text, sans-serif, Inter; --color: #FEFEFE; --colors-white: rgb(255, 255, 255); --colors-red: rgb(255, 0, 0); --colors-cyan: rgb(0, 255, 255); --colors-orange: rgb(255, 128, 0); --colors-yellow: rgb(255, 255, 0); --colors-purple: rgb(128, 0, 128); --colors-green: rgb(0, 255, 0); --colors-magenta: rgb(255, 0, 255); --lights-0: #171717; --tempo: 8px; --tab-size: 4; line-height: 1.5; margin: 0; tab-size: var(--tab-size); -moz-tab-size: var(--tab-size); background-color: #2B2B2B; font-size: 14px; color: var(--color); color-scheme: dark; /* scrollbar-width: thin; */ scrollbar-color: #AAAAAA #2B2B2B; scroll-behavior: smooth; accent-color: var(--colors-cyan); font-family: Consolas, Menlo, JuliaMono, Liberation Mono, monospace; } body { margin: 10px; } /* Fix: https://bugs.chromium.org/p/chromium/issues/detail?id=1150352 */ object { color-scheme: normal; } ::-webkit-scrollbar { background: #2B2B2B; /* height: 10px; */ /* width: 10px; */ } ::-webkit-scrollbar-track { background: #2B2B2B; } ::-webkit-scrollbar-thumb { border: 2px solid #2B2B2B; background: #AAAAAA; border-radius: 10px; } #contents::-webkit-scrollbar-corner { background: #2B2B2B; } .inlineSVG { width: inherit; height: inherit; } #contents a { color: var(--colors-azure); text-decoration: none; text-underline-offset: 0.2rem; } #contents a:hover, #contents a:focus { text-decoration: underline; } #contents a:active { color: var(--colors-orange); } table { border-collapse: collapse; } th, td { padding: 10px; padding-bottom: 5px; } th { white-space: nowrap; border-right: 2px solid #555555; text-align: left; background: linear-gradient( to right, #2B2B2B 5px, transparent 5px, transparent calc(100% - 5px), #2B2B2B calc(100% - 5px) ), linear-gradient( to bottom, #2B2B2B 5px, transparent 5px ), #555555; } thead th { text-align: center; } td { /* Keeps width superior to height. */ min-width: calc(14px + 10px); white-space: break-spaces; text-align: center; border-right: 2px solid #555555; background: linear-gradient( to right, #2B2B2B 5px, transparent 5px, transparent calc(100% - 5px), #2B2B2B calc(100% - 5px) ), linear-gradient( to bottom, #2B2B2B 5px, transparent 5px ), #555555; } th:last-child, td:last-child { border-right: none; } .true { background-color: royalblue; } .false { background-color: crimson; } </style> </head> <body> <script> window.addEventListener('load', function (e) { ( function () { } )(); }); </script> <script src="./app.js"></script> <script src="./out.js"></script> <script src="./node_modules/damon2/dist/damon.min.js"></script> <!-- Or inline app.js below here during build --> <script> let damon = new Damon(); let damonUtils = new DamonUtils(damon); let damonDecision = ` - befores: {} - Input - booleans: {} - Printer prints - Red light flashing - Computer recognizes printer - afters: {} - Check power cable - Replace ink - Paper jam - rows: {} - 0 - 0 - 1 - 1 - 1 - 1 - 0 - 1 - 1 - 1 - rules: {} - Paper jam: {} - 1: {} - and: {} - ==: {} - var: "Printer prints" - 1 - ==: {} - var: "Red light flashing" - 0`.replaceAll('\n' + ' '.repeat(4), '\n'); let damonDecisionMap = damon.damonToMap(damonDecision, 0, true), decisionTableArray = damonUtils.damonDecisionMapToArrayTable(damonDecisionMap), decisionTableRecords = damonUtils.arrayTableToPandasRecords(decisionTableArray); let keysMap = Array.from(damonDecisionMap.keys()) .map((x) => [x.slice(x.match(/^[0-9]+-/)[0].length), x]); if (keysMap.find((x) => x[0] == 'booleans') === undefined) { throw new Error('Missing "booleans" key.'); } let booleans = Array.from(damonDecisionMap.get(keysMap.find((x) => x[0] == 'booleans')[1]).keys()), htmlTable = damonUtils.arrayDecisionTableToHtml(decisionTableArray, booleans); document.body.appendChild(htmlTable); </script> </body> </html>