@tscircuit/schematic-viewer 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/bun-pver-release.yml +24 -0
- package/.github/workflows/bun-typecheck.yml +26 -0
- package/LICENSE +21 -0
- package/examples/resistor-and-capacitor.fixture.tsx +1 -0
- package/lib/components/SchematicViewer.tsx +3 -2
- package/lib/dev/render-to-circuit-json.ts +0 -1
- package/package.json +1 -1
- package/src/main.tsx +1 -0
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -68
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Created using @tscircuit/plop (npm install -g @tscircuit/plop)
|
|
2
|
+
name: Publish to npm
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v3
|
|
12
|
+
- name: Setup bun
|
|
13
|
+
uses: oven-sh/setup-bun@v1
|
|
14
|
+
with:
|
|
15
|
+
bun-version: latest
|
|
16
|
+
- uses: actions/setup-node@v3
|
|
17
|
+
with:
|
|
18
|
+
node-version: 20
|
|
19
|
+
registry-url: https://registry.npmjs.org/
|
|
20
|
+
- run: npm install -g pver
|
|
21
|
+
- run: bun install --frozen-lockfile
|
|
22
|
+
- run: pver release
|
|
23
|
+
env:
|
|
24
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Created using @tscircuit/plop (npm install -g @tscircuit/plop)
|
|
2
|
+
name: Type Check
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
push:
|
|
6
|
+
branches: [main]
|
|
7
|
+
pull_request:
|
|
8
|
+
branches: [main]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
type-check:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v3
|
|
16
|
+
|
|
17
|
+
- name: Setup bun
|
|
18
|
+
uses: oven-sh/setup-bun@v1
|
|
19
|
+
with:
|
|
20
|
+
bun-version: latest
|
|
21
|
+
|
|
22
|
+
- name: Install dependencies
|
|
23
|
+
run: bun i
|
|
24
|
+
|
|
25
|
+
- name: Run type check
|
|
26
|
+
run: bunx tsc --noEmit
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 tscircuit Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -5,9 +5,10 @@ import { toString as transformToString } from "transformation-matrix"
|
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
7
|
circuitJson: Array<{ type: string }>
|
|
8
|
+
containerStyle?: React.CSSProperties
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
export const SchematicViewer = ({ circuitJson }: Props) => {
|
|
11
|
+
export const SchematicViewer = ({ circuitJson, containerStyle }: Props) => {
|
|
11
12
|
const svgDivRef = useRef<HTMLDivElement>(null)
|
|
12
13
|
const { ref: containerRef } = useMouseMatrixTransform({
|
|
13
14
|
onSetTransform(transform) {
|
|
@@ -61,7 +62,7 @@ export const SchematicViewer = ({ circuitJson }: Props) => {
|
|
|
61
62
|
overflow: "hidden",
|
|
62
63
|
cursor: "grab",
|
|
63
64
|
minHeight: "300px",
|
|
64
|
-
|
|
65
|
+
...containerStyle,
|
|
65
66
|
}}
|
|
66
67
|
>
|
|
67
68
|
<div
|
package/package.json
CHANGED
package/src/main.tsx
CHANGED
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
// lib/components/SchematicViewer.tsx
|
|
2
|
-
import { useMouseMatrixTransform } from "use-mouse-matrix-transform";
|
|
3
|
-
import { convertCircuitJsonToSchematicSvg } from "circuit-to-svg";
|
|
4
|
-
import { useEffect, useMemo, useRef, useState } from "react";
|
|
5
|
-
import { toString as transformToString } from "transformation-matrix";
|
|
6
|
-
import { jsx } from "react/jsx-runtime";
|
|
7
|
-
var SchematicViewer = ({ circuitJson }) => {
|
|
8
|
-
const svgDivRef = useRef(null);
|
|
9
|
-
const { ref: containerRef } = useMouseMatrixTransform({
|
|
10
|
-
onSetTransform(transform) {
|
|
11
|
-
if (!svgDivRef.current) return;
|
|
12
|
-
svgDivRef.current.style.transform = transformToString(transform);
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
const [containerWidth, setContainerWidth] = useState(0);
|
|
16
|
-
const [containerHeight, setContainerHeight] = useState(0);
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
if (!containerRef.current) return;
|
|
19
|
-
const updateDimensions = () => {
|
|
20
|
-
const rect = containerRef.current?.getBoundingClientRect();
|
|
21
|
-
setContainerWidth(rect?.width || 0);
|
|
22
|
-
setContainerHeight(rect?.height || 0);
|
|
23
|
-
};
|
|
24
|
-
updateDimensions();
|
|
25
|
-
const resizeObserver = new ResizeObserver(updateDimensions);
|
|
26
|
-
resizeObserver.observe(containerRef.current);
|
|
27
|
-
window.addEventListener("resize", updateDimensions);
|
|
28
|
-
return () => {
|
|
29
|
-
resizeObserver.disconnect();
|
|
30
|
-
window.removeEventListener("resize", updateDimensions);
|
|
31
|
-
};
|
|
32
|
-
}, []);
|
|
33
|
-
const svg = useMemo(() => {
|
|
34
|
-
if (!containerWidth || !containerHeight) return "";
|
|
35
|
-
return convertCircuitJsonToSchematicSvg(circuitJson, {
|
|
36
|
-
width: containerWidth,
|
|
37
|
-
height: containerHeight || 720
|
|
38
|
-
});
|
|
39
|
-
}, [circuitJson, containerWidth, containerHeight]);
|
|
40
|
-
return /* @__PURE__ */ jsx(
|
|
41
|
-
"div",
|
|
42
|
-
{
|
|
43
|
-
ref: containerRef,
|
|
44
|
-
style: {
|
|
45
|
-
backgroundColor: "#F5F1ED",
|
|
46
|
-
overflow: "hidden",
|
|
47
|
-
cursor: "grab",
|
|
48
|
-
minHeight: "300px",
|
|
49
|
-
height: "100%"
|
|
50
|
-
},
|
|
51
|
-
children: /* @__PURE__ */ jsx(
|
|
52
|
-
"div",
|
|
53
|
-
{
|
|
54
|
-
ref: svgDivRef,
|
|
55
|
-
style: {
|
|
56
|
-
pointerEvents: "auto",
|
|
57
|
-
transformOrigin: "0 0"
|
|
58
|
-
},
|
|
59
|
-
dangerouslySetInnerHTML: { __html: svg }
|
|
60
|
-
}
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
|
-
);
|
|
64
|
-
};
|
|
65
|
-
export {
|
|
66
|
-
SchematicViewer
|
|
67
|
-
};
|
|
68
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../lib/components/SchematicViewer.tsx"],"sourcesContent":["import { useMouseMatrixTransform } from \"use-mouse-matrix-transform\"\nimport { convertCircuitJsonToSchematicSvg } from \"circuit-to-svg\"\nimport { useEffect, useMemo, useRef, useState } from \"react\"\nimport { toString as transformToString } from \"transformation-matrix\"\n\ninterface Props {\n circuitJson: Array<{ type: string }>\n}\n\nexport const SchematicViewer = ({ circuitJson }: Props) => {\n const svgDivRef = useRef<HTMLDivElement>(null)\n const { ref: containerRef } = useMouseMatrixTransform({\n onSetTransform(transform) {\n if (!svgDivRef.current) return\n svgDivRef.current.style.transform = transformToString(transform)\n },\n })\n const [containerWidth, setContainerWidth] = useState(0)\n const [containerHeight, setContainerHeight] = useState(0)\n\n useEffect(() => {\n if (!containerRef.current) return\n\n const updateDimensions = () => {\n const rect = containerRef.current?.getBoundingClientRect()\n\n setContainerWidth(rect?.width || 0)\n setContainerHeight(rect?.height || 0)\n }\n\n // Set initial dimensions\n updateDimensions()\n\n // Add resize listener\n const resizeObserver = new ResizeObserver(updateDimensions)\n resizeObserver.observe(containerRef.current)\n\n // Fallback to window resize\n window.addEventListener(\"resize\", updateDimensions)\n\n return () => {\n resizeObserver.disconnect()\n window.removeEventListener(\"resize\", updateDimensions)\n }\n }, [])\n\n const svg = useMemo(() => {\n if (!containerWidth || !containerHeight) return \"\"\n\n return convertCircuitJsonToSchematicSvg(circuitJson as any, {\n width: containerWidth,\n height: containerHeight || 720,\n })\n }, [circuitJson, containerWidth, containerHeight])\n\n return (\n <div\n ref={containerRef}\n style={{\n backgroundColor: \"#F5F1ED\",\n overflow: \"hidden\",\n cursor: \"grab\",\n minHeight: \"300px\",\n height: \"100%\",\n }}\n >\n <div\n ref={svgDivRef}\n style={{\n pointerEvents: \"auto\",\n transformOrigin: \"0 0\",\n }}\n // biome-ignore lint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