Compare commits
No commits in common. "b905f92c069e13a1e0672293f4ad408f5e3ff185" and "a4ab8a79dfd8288662bd16a2d1911964e23d57af" have entirely different histories.
b905f92c06
...
a4ab8a79df
7
.vscode/settings.json
vendored
7
.vscode/settings.json
vendored
@ -1,4 +1,9 @@
|
||||
{
|
||||
"deno.enable": true,
|
||||
"deno.unstable": true
|
||||
"deno.unstable": true,
|
||||
"deno.codeLens.testArgs": [
|
||||
"--allow-all",
|
||||
"--no-check",
|
||||
"--no-lock"
|
||||
]
|
||||
}
|
@ -1,9 +1,8 @@
|
||||
{
|
||||
"compilerOptions": {"types":["store.d.ts"]},
|
||||
"tasks":
|
||||
{
|
||||
"fs": "deno run -A --no-lock https://deno.land/std@0.166.0/http/file_server.ts",
|
||||
"test": "deno test --no-lock --watch store.test.js",
|
||||
"test-debug": "deno test --no-lock --inspect-brk store.test.js"
|
||||
"test": "deno test --no-lock --watch test/store_test.js",
|
||||
"test-debug": "deno test --no-lock --inspect-brk test/store_test.js"
|
||||
}
|
||||
}
|
122
src/app.js
122
src/app.js
@ -1,53 +1,99 @@
|
||||
import * as TW from "./twind.js";
|
||||
//@ts-check
|
||||
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";
|
||||
|
||||
import * as UI from "./ui.js";
|
||||
import { Reducer, Initial } from "./store.js";
|
||||
import React from "https://esm.sh/preact@10.11.3/compat";
|
||||
import {html} from "https://esm.sh/htm@3.1.1/preact";
|
||||
|
||||
/** @type {preact.Context<Binding>} */
|
||||
const StoreContext = React.createContext([Initial, (_a)=>{}]);
|
||||
|
||||
|
||||
/** @type {(props:{children:preact.ComponentChildren})=>preact.VNode} */
|
||||
const StoreProvider =(props)=>
|
||||
{
|
||||
const reducer = React.useReducer(Reducer, Initial);
|
||||
return html`<${StoreContext.Provider} value=${reducer}>${props.children}<//>`;
|
||||
}
|
||||
|
||||
/** @typedef {[state:Store.State, dispatch:(inAction:Store.Action)=>void]} Binding */
|
||||
/** @type {()=>Binding} */
|
||||
const StoreConsumer =()=> React.useContext(StoreContext);
|
||||
|
||||
const Deep =()=>
|
||||
{
|
||||
const [State, Dispatch] = StoreConsumer();
|
||||
return html`
|
||||
<${UI.Button} onClick=${()=>Dispatch({Name:"Stim", Data:1})} disabled=${State.Stim.Value == State.Stim.Max}>
|
||||
${State.Stim.Value}
|
||||
<//>`;
|
||||
}
|
||||
|
||||
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>
|
||||
`;
|
||||
}
|
||||
|
||||
/** @type {TW.TwindConfig} */
|
||||
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",
|
||||
{
|
||||
"vector-effect": "non-scaling-stroke",
|
||||
"stroke-linecap": "square",
|
||||
"fill": "none"
|
||||
},
|
||||
],
|
||||
[
|
||||
'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()]
|
||||
};
|
||||
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);
|
||||
|
||||
TW.Init(ShadowCSS, ShadowDiv);
|
||||
|
||||
const StoreContext = React.createContext(null);
|
||||
const StoreProvider =(props)=>
|
||||
{
|
||||
const reducer = React.useReducer(Reducer, Initial);
|
||||
return html`<${StoreContext.Provider} value=${reducer}>${props.children}<//>`;
|
||||
}
|
||||
const StoreConsumer =()=> React.useContext(StoreContext);
|
||||
|
||||
|
||||
const Deep =()=>
|
||||
{
|
||||
const [State, Dispatch] = React.useContext(StoreContext);
|
||||
return html`
|
||||
<${UI.Button} onClick=${()=>Dispatch({Name:"Stim", Data:1})} disabled=${State.Stim.Value == State.Stim.Max}>
|
||||
${State.Stim.Value}
|
||||
<//>`;
|
||||
}
|
||||
|
||||
React.render(html`
|
||||
<${StoreProvider}>
|
||||
|
74
src/store.js
74
src/store.js
@ -1,5 +1,8 @@
|
||||
//@ts-check
|
||||
|
||||
const size = 1/6;
|
||||
/** @type {Array<Store.ColumnMapping>} */
|
||||
/** @typedef {[frequency:number, position:number, normal:boolean]} ColumnMapping */
|
||||
/** @type {Array<ColumnMapping>} */
|
||||
export const ColumnMapping = [
|
||||
[ 125, size*0.0, true ],
|
||||
[ 250, size*1.0, true ],
|
||||
@ -11,7 +14,7 @@ export const ColumnMapping = [
|
||||
[6000, size*5.5, false],
|
||||
[8000, size*6.0, true ]
|
||||
];
|
||||
/** @type {(inFrequency:number)=>Store.ColumnMapping|false} */
|
||||
/** @type {(inFrequency:number)=>ColumnMapping|false} */
|
||||
export const ColumnLookup =(inFrequency)=>
|
||||
{
|
||||
for(let i=0; i<ColumnMapping.length; i++)
|
||||
@ -23,13 +26,19 @@ export const ColumnLookup =(inFrequency)=>
|
||||
};
|
||||
|
||||
|
||||
/** @type {(freq:Store.TestFrequency, chan:number, user:boolean)=>Store.TestFrequencySample|undefined} */
|
||||
export const MarkGet =(freq, chan, user)=> freq[/** @type {Store.PlotKey} */ (`${user ? "User" : "Test"}${chan ? "R" : "L"}`)];
|
||||
/** @type {(freq:TestFrequency, chan:number, user:boolean)=>TestFrequencySample|undefined} */
|
||||
export const MarkGet =(freq, chan, user)=> freq[/** @type {"UserL"|"UserR"|"TestL"|"TestR"} */ (`${user ? "User" : "Test"}${chan ? "R" : "L"}`)];
|
||||
|
||||
/** @type {(freq:Store.TestFrequency, chan:number, mark:TestFrequencySample|undefined)=>Store.TestFrequencySample|undefined} */
|
||||
/** @type {(freq:TestFrequency, chan:number, mark:TestFrequencySample|undefined)=>TestFrequencySample|undefined} */
|
||||
export const MarkSet =(freq, chan, mark)=> freq[ chan ? "UserR" : "UserL" ] = mark;
|
||||
|
||||
/** @type {Store.State} */
|
||||
/** @typedef {{Min:number, Max:number, Value:number, Step:number}} Range */
|
||||
/** @typedef {{Stim:number, Resp:boolean}} TestFrequencySample */
|
||||
/** @typedef {{Hz:number, TestL:TestFrequencySample, TestR:TestFrequencySample, UserL?:TestFrequencySample, UserR?:TestFrequencySample}} TestFrequency */
|
||||
/** @typedef {{Name:string, Plot:Array<TestFrequency>}} Test */
|
||||
/** @typedef {{Test?:Test, Freq?:TestFrequency, Mark?:TestFrequencySample}} Context */
|
||||
/** @typedef {{Chan:Range, Freq:Range, Stim:Range, Live:Context, Draw:{UserL:DrawGroup, UserR:DrawGroup, TestL:DrawGroup, TestR:DrawGroup}, Tests:Array<Test>}} State */
|
||||
/** @type {State} */
|
||||
export const Initial =
|
||||
{
|
||||
Chan: { Min:0, Max:1, Value:0, Step:1 },
|
||||
@ -60,7 +69,15 @@ export const Initial =
|
||||
]
|
||||
};
|
||||
|
||||
/** @type {Record<string, Store.ContextUpdater>} */
|
||||
/** @typedef {{Name:"Mark", Data:boolean|null}} ActionMark */
|
||||
/** @typedef {{Name:"Test", Data:number}} ActionTest */
|
||||
/** @typedef {{Name:"Chan", Data:number}} ActionChan */
|
||||
/** @typedef {{Name:"Freq", Data:number}} ActionFreq */
|
||||
/** @typedef {{Name:"Stim", Data:number}} ActionStim */
|
||||
/** @typedef {ActionMark|ActionTest|ActionChan|ActionFreq|ActionStim} Action */
|
||||
/** @typedef {(inState:State, inAction:Action)=>State} Reducer */
|
||||
/** @typedef {(inState:State)=>boolean} SelectionUpdater */
|
||||
/** @type {Record<string, SelectionUpdater>} */
|
||||
const Update =
|
||||
{
|
||||
Freq(inState)
|
||||
@ -94,16 +111,19 @@ const Update =
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** @type {(inTest:Store.Test, inChan:number, inStim:Range, inIsUser:boolean)=>Store.DrawGroup} */
|
||||
/** @typedef {{X:number, Y:number, Mark:TestFrequencySample}} DrawPoint */
|
||||
/** @typedef {{Points:Array<DrawPoint>, Paths:Array<Array<DrawPoint>>}} DrawGroup */
|
||||
/** @typedef {{Left:DrawGroup, Right:DrawGroup}} DrawChart */
|
||||
/** @typedef {{User?:DrawChart, Test?:DrawChart}} DrawTest */
|
||||
/** @type {(inTest:Test, inChan:number, inStim:Range, inIsUser:boolean)=>DrawGroup} */
|
||||
export function Congtiguous(inTest, inChan, inStim, inIsUser)
|
||||
{
|
||||
/** @type {Store.DrawGroup} */
|
||||
/** @type {DrawGroup} */
|
||||
const output = {Points:[], Paths:[]};
|
||||
|
||||
let plot;
|
||||
let valid = false;
|
||||
/** @type {Array<Store.DrawPoint>} */
|
||||
/** @type {Array<DrawPoint>} */
|
||||
let segment = [];
|
||||
for(let i=0; i<inTest.Plot.length; i++)
|
||||
{
|
||||
@ -114,7 +134,7 @@ export function Congtiguous(inTest, inChan, inStim, inIsUser)
|
||||
const lookup = ColumnLookup(plot.Hz);
|
||||
if(lookup)
|
||||
{
|
||||
/** @type {Store.DrawPoint} */
|
||||
/** @type {DrawPoint} */
|
||||
const point = {
|
||||
X: lookup[1]*100,
|
||||
Y: (mark.Stim - inStim.Min)/(inStim.Max - inStim.Min) * 100,
|
||||
@ -143,7 +163,7 @@ export function Congtiguous(inTest, inChan, inStim, inIsUser)
|
||||
}
|
||||
|
||||
|
||||
/** @type {Store.Reducer} */
|
||||
/** @type {Reducer} */
|
||||
export function Reducer(inState, inAction)
|
||||
{
|
||||
const clone = {...inState};
|
||||
@ -187,3 +207,31 @@ export function Reducer(inState, inAction)
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
/*
|
||||
const minified =
|
||||
[
|
||||
1,
|
||||
[
|
||||
[20, 30, 50, 40, 60, 80],[20, 30, 50, 40, 60, 80]
|
||||
]
|
||||
];
|
||||
const Expand =(inMin)=>
|
||||
{
|
||||
const outTests = [];
|
||||
const inFreq = inMin[0];
|
||||
for(let i=1; i<inMin.length; i++)
|
||||
{
|
||||
let inTest = inMin[i];
|
||||
let inTestName = inTest[0];
|
||||
|
||||
const outTest = {
|
||||
Name:inTest[0],
|
||||
Plot:[]
|
||||
};
|
||||
outTests.push(outTest);
|
||||
const outFreq = {Hz:0, TestL:{Stim:0, Resp:true}, TestR:{Stim:0, Resp:true}, UserL:undefined, UserR:undefined};
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
70
src/twind.js
70
src/twind.js
@ -1,70 +0,0 @@
|
||||
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";
|
||||
|
||||
/** @type {TW.TwindConfig} */
|
||||
export 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",
|
||||
{
|
||||
"vector-effect": "non-scaling-stroke",
|
||||
"stroke-linecap": "square",
|
||||
"fill": "none"
|
||||
},
|
||||
],
|
||||
[
|
||||
'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()]
|
||||
};
|
||||
|
||||
/** @type {(elStyle:HTMLStyleElement, elDiv:HTMLDivElement)=>void} */
|
||||
export const Init =(elStyle, elDiv)=>
|
||||
{
|
||||
TW.observe(TW.twind(Configure, TW.cssom(elStyle)), elDiv);
|
||||
};
|
54
store.d.ts
vendored
54
store.d.ts
vendored
@ -1,54 +0,0 @@
|
||||
declare namespace Store {
|
||||
type ColumnMapping = [frequency: number, position: number, normal: boolean];
|
||||
|
||||
type Range = { Min: number; Max: number; Value: number; Step: number };
|
||||
type TestFrequencySample = { Stim: number; Resp: boolean };
|
||||
|
||||
type TestFrequency = {
|
||||
Hz: number;
|
||||
TestL: TestFrequencySample;
|
||||
TestR: TestFrequencySample;
|
||||
UserL?: TestFrequencySample;
|
||||
UserR?: TestFrequencySample;
|
||||
};
|
||||
|
||||
type Test = { Name: string; Plot: Array<TestFrequency> };
|
||||
|
||||
type Context = {
|
||||
Test?: Test;
|
||||
Freq?: TestFrequency;
|
||||
Mark?: TestFrequencySample;
|
||||
};
|
||||
|
||||
type State = {
|
||||
Chan: Range;
|
||||
Freq: Range;
|
||||
Stim: Range;
|
||||
Live: Context;
|
||||
Draw: {
|
||||
UserL: DrawGroup;
|
||||
UserR: DrawGroup;
|
||||
TestL: DrawGroup;
|
||||
TestR: DrawGroup;
|
||||
};
|
||||
Tests: Array<Test>;
|
||||
};
|
||||
|
||||
type ActionMark = { Name: "Mark"; Data: boolean | null };
|
||||
type ActionTest = { Name: "Test"; Data: number };
|
||||
type ActionChan = { Name: "Chan"; Data: number };
|
||||
type ActionFreq = { Name: "Freq"; Data: number };
|
||||
type ActionStim = { Name: "Stim"; Data: number };
|
||||
type Action = ActionMark | ActionTest | ActionChan | ActionFreq | ActionStim;
|
||||
type Reducer = (inState: State, inAction: Action) => State;
|
||||
type ContextUpdater = (inState: State) => boolean;
|
||||
|
||||
type PlotKeyUser = "UserL" | "UserR";
|
||||
type PlotKeyTest = "TestL" | "TestR";
|
||||
type PlotKey = PlotKeyUser | PlotKeyTest;
|
||||
|
||||
type DrawPoint = { X: number; Y: number; Mark: TestFrequencySample };
|
||||
type DrawGroup = { Points: Array<DrawPoint>; Paths: Array<Array<DrawPoint>> };
|
||||
type DrawChart = { Left: DrawGroup; Right: DrawGroup };
|
||||
type DrawTest = { User?: DrawChart; Test?: DrawChart };
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import { assertEquals } from "https://deno.land/std@0.166.0/testing/asserts.ts";
|
||||
import { Reducer, ColumnMapping, Congtiguous, Initial } from "./src/store.js";
|
||||
import { Reducer, ColumnMapping, Congtiguous, Initial } from "../src/store.js";
|
||||
|
||||
let state = {...Initial};
|
||||
|
||||
@ -103,7 +103,7 @@ Deno.test("Make Marks", async(t)=>
|
||||
|
||||
Deno.test("Contiguous Lines", ()=>
|
||||
{
|
||||
/** @type {Store.Test} */
|
||||
/** @type {import("../src/store.js").Test} */
|
||||
const model = {
|
||||
Name:"",
|
||||
Plot:[
|
Loading…
Reference in New Issue
Block a user