2021-02-14 17:32:55 +00:00
|
|
|
import React, { useState } from "react";
|
|
|
|
import { dilateBoundingBox, getBoundingBoxSize } from "../bounding-box";
|
2021-02-15 14:56:02 +00:00
|
|
|
import {
|
|
|
|
createSvgSymbolContext,
|
|
|
|
SvgSymbolContent,
|
|
|
|
SvgSymbolData,
|
|
|
|
} from "../svg-symbol";
|
2021-02-15 13:33:33 +00:00
|
|
|
import { SvgVocabulary } from "../svg-vocabulary";
|
2021-02-15 14:56:02 +00:00
|
|
|
import { SvgSymbolContext } from "../svg-symbol";
|
2021-02-17 13:07:04 +00:00
|
|
|
import { SymbolContextWidget } from "../symbol-context-widget";
|
2021-02-27 18:28:44 +00:00
|
|
|
import { HoverDebugHelper } from "../hover-debug-helper";
|
2021-02-14 17:32:55 +00:00
|
|
|
|
|
|
|
type SvgSymbolProps = {
|
|
|
|
data: SvgSymbolData;
|
|
|
|
scale?: number;
|
|
|
|
} & SvgSymbolContext;
|
|
|
|
|
|
|
|
const px = (value: number) => `${value}px`;
|
|
|
|
|
2021-02-15 13:33:33 +00:00
|
|
|
const BBOX_DILATION = 100;
|
2021-02-14 17:32:55 +00:00
|
|
|
|
|
|
|
const SvgSymbol: React.FC<SvgSymbolProps> = (props) => {
|
|
|
|
const d = props.data;
|
|
|
|
const bbox = dilateBoundingBox(d.bbox, BBOX_DILATION);
|
|
|
|
const scale = props.scale || 1;
|
|
|
|
const [width, height] = getBoundingBoxSize(bbox);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<svg
|
|
|
|
viewBox={`${bbox.x.min} ${bbox.y.min} ${width} ${height}`}
|
|
|
|
width={px(width * scale)}
|
|
|
|
height={px(height * scale)}
|
|
|
|
>
|
2021-02-15 14:56:02 +00:00
|
|
|
<SvgSymbolContent {...props} />
|
2021-02-14 17:32:55 +00:00
|
|
|
</svg>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const VocabularyPage: React.FC<{}> = () => {
|
2021-02-17 13:07:04 +00:00
|
|
|
const [ctx, setCtx] = useState(createSvgSymbolContext());
|
2021-02-14 17:32:55 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<h1>Mystic Symbolic Vocabulary</h1>
|
2021-02-17 13:07:04 +00:00
|
|
|
<SymbolContextWidget ctx={ctx} onChange={setCtx} />
|
2021-02-27 18:28:44 +00:00
|
|
|
<HoverDebugHelper>
|
|
|
|
{SvgVocabulary.map((symbolData) => (
|
2021-02-14 17:32:55 +00:00
|
|
|
<div
|
2021-02-27 18:28:44 +00:00
|
|
|
key={symbolData.name}
|
2021-02-14 17:32:55 +00:00
|
|
|
style={{
|
2021-02-27 18:28:44 +00:00
|
|
|
display: "inline-block",
|
|
|
|
border: "1px solid black",
|
|
|
|
margin: "4px",
|
2021-02-14 17:32:55 +00:00
|
|
|
}}
|
|
|
|
>
|
2021-02-27 18:28:44 +00:00
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
backgroundColor: "black",
|
|
|
|
color: "white",
|
|
|
|
padding: "4px",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{symbolData.name}
|
|
|
|
</div>
|
|
|
|
<div className="checkerboard-bg" style={{ lineHeight: 0 }}>
|
|
|
|
<SvgSymbol data={symbolData} scale={0.25} {...ctx} />
|
|
|
|
</div>
|
2021-02-14 17:32:55 +00:00
|
|
|
</div>
|
2021-02-27 18:28:44 +00:00
|
|
|
))}
|
|
|
|
</HoverDebugHelper>
|
2021-02-14 17:32:55 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|