@tscircuit/schematic-viewer 1.2.12 → 1.2.14
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/.storybook/main.ts +3 -2
- package/dist/index.d.ts +7 -3
- package/dist/index.js +80 -26
- package/dist/index.js.map +1 -1
- package/package.json +15 -10
- package/renovate.json +6 -0
- package/src/Schematic.tsx +9 -2
- package/src/lib/utils/get-rotation-from-anchor-side.ts +11 -0
- package/src/lib/utils/get-vec-from-anchor-side.ts +11 -0
- package/src/schematic-components/DebugPoint.tsx +25 -0
- package/src/schematic-components/SchematicBug.tsx +12 -6
- package/src/schematic-components/SchematicNetLabel.tsx +21 -8
- package/src/stories/basics/schematic-net-labels-2.stories.tsx +33 -0
- package/src/stories/bug-one-sided.stories.tsx +6 -5
- package/src/stories/bug-pin-spacing.stories.tsx +49 -0
- package/src/stories/bugs/bug8-autolayout.stories.tsx +52 -0
- package/src/stories/circuit-components/netalias.stories.tsx +14 -0
- package/vite.config.js +7 -0
package/.storybook/main.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { StorybookConfig } from "@storybook/
|
|
1
|
+
import type { StorybookConfig } from "@storybook/react-vite"
|
|
2
|
+
|
|
2
3
|
const config: StorybookConfig = {
|
|
3
4
|
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
|
|
4
5
|
addons: [],
|
|
5
6
|
framework: {
|
|
6
|
-
name: "@storybook/
|
|
7
|
+
name: "@storybook/react-vite",
|
|
7
8
|
options: {},
|
|
8
9
|
},
|
|
9
10
|
docs: {},
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { AnySoupElement } from '@tscircuit/soup';
|
|
3
|
+
|
|
1
4
|
interface SchematicProps {
|
|
2
5
|
children?: any;
|
|
3
6
|
/** @deprecated use soup */
|
|
4
7
|
elements?: any;
|
|
5
|
-
soup?:
|
|
8
|
+
soup?: AnySoupElement[];
|
|
6
9
|
style?: any;
|
|
7
10
|
showTable?: boolean;
|
|
11
|
+
_soupPostProcessor?: (soup: AnySoupElement[]) => AnySoupElement[];
|
|
8
12
|
}
|
|
9
|
-
declare const Schematic: (props: SchematicProps) => JSX.Element;
|
|
10
|
-
declare const SchematicWithoutContext: ({ children, elements: initialElements, soup: initialSoup, style, showTable, }: SchematicProps) => JSX.Element;
|
|
13
|
+
declare const Schematic: (props: SchematicProps) => react_jsx_runtime.JSX.Element;
|
|
14
|
+
declare const SchematicWithoutContext: ({ children, elements: initialElements, soup: initialSoup, style, showTable, _soupPostProcessor, }: SchematicProps) => react_jsx_runtime.JSX.Element;
|
|
11
15
|
|
|
12
16
|
export { Schematic, SchematicProps, SchematicWithoutContext };
|
package/dist/index.js
CHANGED
|
@@ -941,47 +941,62 @@ module.exports = __toCommonJS(src_exports);
|
|
|
941
941
|
// src/Schematic.tsx
|
|
942
942
|
var import_react9 = require("react");
|
|
943
943
|
|
|
944
|
-
// node_modules/zustand/esm/vanilla.
|
|
944
|
+
// node_modules/zustand/esm/vanilla.mjs
|
|
945
|
+
var import_meta = {};
|
|
945
946
|
var createStoreImpl = (createState) => {
|
|
946
947
|
let state;
|
|
947
948
|
const listeners = /* @__PURE__ */ new Set();
|
|
948
949
|
const setState = (partial, replace) => {
|
|
949
950
|
const nextState = typeof partial === "function" ? partial(state) : partial;
|
|
950
|
-
if (nextState
|
|
951
|
+
if (!Object.is(nextState, state)) {
|
|
951
952
|
const previousState = state;
|
|
952
|
-
state = replace ? nextState : Object.assign({}, state, nextState);
|
|
953
|
+
state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
|
|
953
954
|
listeners.forEach((listener) => listener(state, previousState));
|
|
954
955
|
}
|
|
955
956
|
};
|
|
956
957
|
const getState = () => state;
|
|
958
|
+
const getInitialState = () => initialState;
|
|
957
959
|
const subscribe = (listener) => {
|
|
958
960
|
listeners.add(listener);
|
|
959
961
|
return () => listeners.delete(listener);
|
|
960
962
|
};
|
|
961
|
-
const destroy = () =>
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
963
|
+
const destroy = () => {
|
|
964
|
+
if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production") {
|
|
965
|
+
console.warn(
|
|
966
|
+
"[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."
|
|
967
|
+
);
|
|
968
|
+
}
|
|
969
|
+
listeners.clear();
|
|
970
|
+
};
|
|
971
|
+
const api = { setState, getState, getInitialState, subscribe, destroy };
|
|
972
|
+
const initialState = state = createState(setState, getState, api);
|
|
968
973
|
return api;
|
|
969
974
|
};
|
|
970
975
|
var createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
|
|
971
976
|
|
|
972
|
-
// node_modules/zustand/esm/index.
|
|
973
|
-
var import_react = require("react");
|
|
974
|
-
var import_with_selector = __toESM(require_with_selector());
|
|
977
|
+
// node_modules/zustand/esm/index.mjs
|
|
978
|
+
var import_react = __toESM(require("react"), 1);
|
|
979
|
+
var import_with_selector = __toESM(require_with_selector(), 1);
|
|
980
|
+
var import_meta2 = {};
|
|
981
|
+
var { useDebugValue } = import_react.default;
|
|
975
982
|
var { useSyncExternalStoreWithSelector } = import_with_selector.default;
|
|
976
|
-
|
|
983
|
+
var didWarnAboutEqualityFn = false;
|
|
984
|
+
var identity = (arg) => arg;
|
|
985
|
+
function useStore(api, selector = identity, equalityFn) {
|
|
986
|
+
if ((import_meta2.env ? import_meta2.env.MODE : void 0) !== "production" && equalityFn && !didWarnAboutEqualityFn) {
|
|
987
|
+
console.warn(
|
|
988
|
+
"[DEPRECATED] Use `createWithEqualityFn` instead of `create` or use `useStoreWithEqualityFn` instead of `useStore`. They can be imported from 'zustand/traditional'. https://github.com/pmndrs/zustand/discussions/1937"
|
|
989
|
+
);
|
|
990
|
+
didWarnAboutEqualityFn = true;
|
|
991
|
+
}
|
|
977
992
|
const slice = useSyncExternalStoreWithSelector(
|
|
978
993
|
api.subscribe,
|
|
979
994
|
api.getState,
|
|
980
|
-
api.getServerState || api.
|
|
995
|
+
api.getServerState || api.getInitialState,
|
|
981
996
|
selector,
|
|
982
997
|
equalityFn
|
|
983
998
|
);
|
|
984
|
-
|
|
999
|
+
useDebugValue(slice);
|
|
985
1000
|
return slice;
|
|
986
1001
|
}
|
|
987
1002
|
|
|
@@ -1814,7 +1829,10 @@ var SchematicBug = ({ component: { source, schematic } }) => {
|
|
|
1814
1829
|
d: `M ${-bugw / 2} ${-bugh / 2} L ${bugw / 2} ${-bugh / 2} L ${bugw / 2} ${bugh / 2} L ${-bugw / 2} ${bugh / 2}Z`
|
|
1815
1830
|
},
|
|
1816
1831
|
...port_indices.map((portNum) => {
|
|
1817
|
-
const pos = (0, import_builder2.getPortPosition)(
|
|
1832
|
+
const pos = (0, import_builder2.getPortPosition)(
|
|
1833
|
+
{ ...port_arrangement, pin_spacing: schematic.pin_spacing },
|
|
1834
|
+
portNum
|
|
1835
|
+
);
|
|
1818
1836
|
const x2 = pos.side === "left" ? -bugw / 2 : pos.side === "right" ? bugw / 2 : pos.x;
|
|
1819
1837
|
const y2 = pos.side === "top" ? bugh / 2 : pos.side === "bottom" ? -bugh / 2 : pos.y;
|
|
1820
1838
|
return {
|
|
@@ -2095,29 +2113,61 @@ var SchematicPath = (props) => {
|
|
|
2095
2113
|
};
|
|
2096
2114
|
var SchematicPath_default = SchematicPath;
|
|
2097
2115
|
|
|
2116
|
+
// src/lib/utils/get-rotation-from-anchor-side.ts
|
|
2117
|
+
var getRotationFromAnchorSide = (anchor_side) => {
|
|
2118
|
+
if (anchor_side === "left")
|
|
2119
|
+
return 0;
|
|
2120
|
+
if (anchor_side === "top")
|
|
2121
|
+
return Math.PI * 3 / 2;
|
|
2122
|
+
if (anchor_side === "right")
|
|
2123
|
+
return Math.PI;
|
|
2124
|
+
if (anchor_side === "bottom")
|
|
2125
|
+
return Math.PI / 2;
|
|
2126
|
+
return 0;
|
|
2127
|
+
};
|
|
2128
|
+
|
|
2129
|
+
// src/lib/utils/get-vec-from-anchor-side.ts
|
|
2130
|
+
var getVecFromAnchorSide = (anchor_side) => {
|
|
2131
|
+
if (anchor_side === "left")
|
|
2132
|
+
return { x: -1, y: 0 };
|
|
2133
|
+
if (anchor_side === "top")
|
|
2134
|
+
return { x: 0, y: -1 };
|
|
2135
|
+
if (anchor_side === "right")
|
|
2136
|
+
return { x: 1, y: 0 };
|
|
2137
|
+
if (anchor_side === "bottom")
|
|
2138
|
+
return { x: 0, y: 1 };
|
|
2139
|
+
throw new Error(`invalid anchor side "${anchor_side}"`);
|
|
2140
|
+
};
|
|
2141
|
+
|
|
2098
2142
|
// src/schematic-components/SchematicNetLabel.tsx
|
|
2099
2143
|
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
2100
2144
|
var SchematicNetLabel = ({
|
|
2101
2145
|
net_label
|
|
2102
2146
|
}) => {
|
|
2103
|
-
|
|
2104
|
-
const
|
|
2147
|
+
const anchor_side = net_label.anchor_side;
|
|
2148
|
+
const is_vertical = anchor_side === "top" || anchor_side === "bottom";
|
|
2149
|
+
const text_width = is_vertical ? 0.3 : net_label.text.length * 0.15;
|
|
2105
2150
|
const path_width = 31 + net_label.text.length * 5;
|
|
2151
|
+
const anchor_vec = getVecFromAnchorSide(anchor_side);
|
|
2152
|
+
const anchor_dist = is_vertical ? 0.04 : text_width / 4;
|
|
2153
|
+
anchor_vec.x *= anchor_dist;
|
|
2154
|
+
anchor_vec.y *= anchor_dist;
|
|
2106
2155
|
return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_jsx_runtime20.Fragment, { children: [
|
|
2107
2156
|
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
2108
2157
|
SVGPathComponent_default,
|
|
2109
2158
|
{
|
|
2110
|
-
rotation:
|
|
2159
|
+
rotation: getRotationFromAnchorSide(anchor_side),
|
|
2111
2160
|
center: net_label.center,
|
|
2112
2161
|
size: {
|
|
2113
2162
|
width: 0.05 + text_width,
|
|
2114
|
-
height: 0.
|
|
2163
|
+
height: 0.2 + (is_vertical ? 0.1 * Math.max(1, net_label.text.length - 2) : 0)
|
|
2115
2164
|
},
|
|
2116
2165
|
paths: [
|
|
2117
2166
|
{
|
|
2118
2167
|
stroke: "gray",
|
|
2119
2168
|
strokeWidth: 0.75,
|
|
2120
|
-
d: `M 0 15 L 5 15 L 11 9 L ${path_width} 9 L ${path_width} 21 L 11 21 L 5 15
|
|
2169
|
+
// d: `M 0 15 L 5 15 L 11 9 L ${path_width} 9 L ${path_width} 21 L 11 21 L 5 15`,
|
|
2170
|
+
d: `M 0 15 L 5 15 L 11 5 L ${path_width} 5 L ${path_width} 26 L 11 26 L 5 15`
|
|
2121
2171
|
}
|
|
2122
2172
|
]
|
|
2123
2173
|
}
|
|
@@ -2126,10 +2176,10 @@ var SchematicNetLabel = ({
|
|
|
2126
2176
|
SchematicText_default,
|
|
2127
2177
|
{
|
|
2128
2178
|
schematic_text: {
|
|
2129
|
-
anchor: "
|
|
2179
|
+
anchor: is_vertical ? "center" : anchor_side,
|
|
2130
2180
|
position: {
|
|
2131
|
-
x: net_label.center.x
|
|
2132
|
-
y: net_label.center.y
|
|
2181
|
+
x: net_label.center.x + anchor_vec.x,
|
|
2182
|
+
y: net_label.center.y + anchor_vec.y
|
|
2133
2183
|
},
|
|
2134
2184
|
schematic_component_id: "SYNTHETIC",
|
|
2135
2185
|
schematic_text_id: "SYNTHETIC",
|
|
@@ -2216,7 +2266,8 @@ var SchematicWithoutContext = ({
|
|
|
2216
2266
|
elements: initialElements,
|
|
2217
2267
|
soup: initialSoup,
|
|
2218
2268
|
style,
|
|
2219
|
-
showTable = false
|
|
2269
|
+
showTable = false,
|
|
2270
|
+
_soupPostProcessor
|
|
2220
2271
|
}) => {
|
|
2221
2272
|
initialSoup = initialSoup ?? initialElements ?? [];
|
|
2222
2273
|
const [elements, setElements] = (0, import_react9.useState)(initialSoup ?? []);
|
|
@@ -2261,6 +2312,9 @@ var SchematicWithoutContext = ({
|
|
|
2261
2312
|
}
|
|
2262
2313
|
const projectBuilder = (0, import_builder3.createProjectBuilder)();
|
|
2263
2314
|
(import_react_fiber.createRoot ?? import_react_fiber.default.createRoot)().render(children, projectBuilder).then(async (elements2) => {
|
|
2315
|
+
if (_soupPostProcessor) {
|
|
2316
|
+
elements2 = _soupPostProcessor(elements2);
|
|
2317
|
+
}
|
|
2264
2318
|
setElementsAndCamera(elements2);
|
|
2265
2319
|
}).catch((e) => {
|
|
2266
2320
|
console.error("ERROR RENDERING CIRCUIT");
|