2022-11-24 12:16:57 -05:00
|
|
|
//@ts-check
|
2022-11-25 15:51:27 -05:00
|
|
|
import * as TW from "https://esm.sh/@twind/core@1.0.1";
|
|
|
|
import TWPreTail from "https://esm.sh/@twind/preset-tailwind@1.0.1";
|
|
|
|
import TWPreAuto from "https://esm.sh/@twind/preset-autoprefix@1.0.1";
|
2022-11-24 12:16:57 -05:00
|
|
|
|
2022-12-03 19:05:26 -05:00
|
|
|
import * as UI from "./ui.js";
|
|
|
|
import { Reducer, Initial } from "./store.js";
|
|
|
|
import React from "https://esm.sh/preact@10.11.3/compat";
|
2022-12-03 22:51:22 -05:00
|
|
|
import {html} from "https://esm.sh/htm@3.1.1/preact";
|
2022-12-03 19:05:26 -05:00
|
|
|
|
2022-12-03 22:51:22 -05:00
|
|
|
/** @typedef {import("./store.js").State} State */
|
|
|
|
/** @typedef {import("https://esm.sh/preact@10.11.3/compat").JSX.Element} JSX.Element */
|
|
|
|
/** @typedef {import("./store.js").Action} Action */
|
|
|
|
/** @type {JSX.Element} */
|
2022-12-03 19:05:26 -05:00
|
|
|
|
2022-11-27 23:56:37 -05:00
|
|
|
/** @type {TW.TwindConfig} */
|
2022-11-27 16:57:06 -05:00
|
|
|
const Configure = {
|
|
|
|
theme:
|
|
|
|
{
|
|
|
|
extend:
|
|
|
|
{
|
|
|
|
keyframes:
|
|
|
|
{
|
|
|
|
flash:
|
|
|
|
{
|
|
|
|
'0%': { opacity: 1.0 },
|
|
|
|
'50%': { opacity: 0.3 },
|
|
|
|
'100%': { opacity: 0.0 }
|
|
|
|
},
|
|
|
|
pulse:
|
|
|
|
{
|
|
|
|
"0%": { opacity: 0.0 },
|
|
|
|
"10%": { opacity: 0.0 },
|
|
|
|
"12%": { opacity: 1.0 },
|
|
|
|
"22%": { opacity: 1.0 },
|
|
|
|
"42%": { opacity: 0.2 },
|
|
|
|
"100%": { opacity: 0.0 }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
animation:
|
|
|
|
{
|
|
|
|
flash: "flash 1s both"
|
|
|
|
},
|
|
|
|
strokeWidth:
|
|
|
|
{
|
|
|
|
"bold": "3px"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
rules:
|
|
|
|
[
|
|
|
|
[
|
|
|
|
"stroke-draw",
|
|
|
|
{
|
2022-11-27 23:56:37 -05:00
|
|
|
"vector-effect": "non-scaling-stroke",
|
|
|
|
"stroke-linecap": "square",
|
|
|
|
"fill": "none"
|
2022-11-27 16:57:06 -05:00
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'shadow-glow-(.*)',
|
|
|
|
(match, context)=>
|
|
|
|
{
|
|
|
|
return { "box-shadow": `0px 0px 5px 2px ${context.theme().colors[match[1]]}` };
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'shadow-sss',
|
|
|
|
{
|
|
|
|
"box-shadow": "rgb(0 0 0 / 50%) 0px -3px 2px inset, rgb(255 255 255 / 50%) 0px 10px 10px inset"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
],
|
|
|
|
presets: [TWPreTail(), TWPreAuto()]
|
|
|
|
};
|
2022-11-25 15:51:27 -05:00
|
|
|
const ShadowDOM = document.querySelector("#app").attachShadow({mode: "open"});
|
|
|
|
const ShadowDiv = document.createElement("div");
|
|
|
|
const ShadowCSS = document.createElement("style");
|
|
|
|
ShadowDOM.append(ShadowCSS);
|
|
|
|
ShadowDOM.append(ShadowDiv);
|
|
|
|
TW.observe(TW.twind(Configure, TW.cssom(ShadowCSS)), ShadowDiv);
|
2022-11-24 14:15:34 -05:00
|
|
|
|
2022-12-03 22:51:22 -05:00
|
|
|
/** @type {import("https://esm.sh/v99/preact@10.11.3/src/index.js").Context<Binding>} */
|
|
|
|
const StoreContext = React.createContext([Initial, (a)=>{}]);
|
2022-12-03 19:05:26 -05:00
|
|
|
|
|
|
|
const StoreProvider =(props)=>
|
|
|
|
{
|
|
|
|
const reducer = React.useReducer(Reducer, Initial);
|
|
|
|
return html`<${StoreContext.Provider} value=${reducer}>${props.children}<//>`;
|
|
|
|
}
|
2022-12-03 22:51:22 -05:00
|
|
|
|
|
|
|
/** @typedef {[state:State, dispatch:(inAction:Action)=>void]} Binding */
|
|
|
|
/** @type {()=>Binding} */
|
2022-12-03 19:05:26 -05:00
|
|
|
const StoreConsumer =()=> React.useContext(StoreContext);
|
|
|
|
|
|
|
|
|
|
|
|
const Deep =()=>
|
|
|
|
{
|
2022-12-03 22:51:22 -05:00
|
|
|
const [State, Dispatch] = StoreConsumer();
|
2022-12-03 19:05:26 -05:00
|
|
|
return html`
|
2022-12-03 21:40:23 -05:00
|
|
|
<${UI.Button} onClick=${()=>Dispatch({Name:"Stim", Data:1})} disabled=${State.Stim.Value == State.Stim.Max}>
|
|
|
|
${State.Stim.Value}
|
2022-12-03 19:05:26 -05:00
|
|
|
<//>`;
|
|
|
|
}
|
|
|
|
|
2022-12-03 22:51:22 -05:00
|
|
|
const Audiogram =()=>
|
|
|
|
{
|
|
|
|
const [State, Dispatch] = StoreConsumer();
|
|
|
|
return html`
|
|
|
|
<svg class="absolute top-0 w-full h-full overflow-visible stroke(blue-700 bold draw)">
|
|
|
|
${State.Draw}
|
|
|
|
<${UI.Mark} right=${false} x=${"10%"} y="20%" response=${true} />
|
|
|
|
<${UI.Mark} right=${false}/>
|
|
|
|
<line x1=${"10%"} y1=${"10%"} x2=${"50%"} y2=${"50%"} class="stroke-2 opacity-60" />
|
|
|
|
</svg>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2022-12-03 19:05:26 -05:00
|
|
|
React.render(html`
|
|
|
|
<${StoreProvider}>
|
|
|
|
<${UI.Button} icon="+">hey!<//>
|
|
|
|
<${UI.Button} light>Left<//>
|
|
|
|
<${UI.Button} inactive>Right<//>
|
|
|
|
<${UI.Button} disabled>Right<//>
|
|
|
|
<${Deep}/>
|
|
|
|
<${UI.Chart}>
|
|
|
|
<svg class="absolute top-0 w-full h-full overflow-visible stroke(blue-700 bold draw)">
|
|
|
|
<${UI.Mark} right=${true} x=${"20%"} y="20%" />
|
|
|
|
<${UI.Mark} right=${false} x=${"10%"} y="20%" response=${true} />
|
|
|
|
<${UI.Mark} right=${false}/>
|
|
|
|
<line x1=${"10%"} y1=${"10%"} x2=${"50%"} y2=${"50%"} class="stroke-2 opacity-60" />
|
|
|
|
</svg>
|
|
|
|
<//>
|
2022-11-27 16:57:06 -05:00
|
|
|
<//>
|
2022-11-25 15:51:27 -05:00
|
|
|
`, ShadowDiv);
|