@tscircuit/core 0.0.1
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/README.md +35 -0
- package/dist/index.cjs +5353 -0
- package/index.ts +1 -0
- package/lib/Project.ts +84 -0
- package/lib/components/base-components/NormalComponent.ts +330 -0
- package/lib/components/base-components/PrimitiveComponent.ts +299 -0
- package/lib/components/base-components/Renderable.ts +113 -0
- package/lib/components/index.ts +14 -0
- package/lib/components/normal-components/Board.ts +38 -0
- package/lib/components/normal-components/Capacitor.ts +23 -0
- package/lib/components/normal-components/Diode.ts +27 -0
- package/lib/components/normal-components/Led.ts +27 -0
- package/lib/components/normal-components/Resistor.ts +19 -0
- package/lib/components/primitive-components/Footprint.ts +4 -0
- package/lib/components/primitive-components/Group.ts +10 -0
- package/lib/components/primitive-components/Net.ts +12 -0
- package/lib/components/primitive-components/Port.ts +187 -0
- package/lib/components/primitive-components/SmtPad.ts +80 -0
- package/lib/components/primitive-components/Trace.ts +219 -0
- package/lib/components/primitive-components/TraceHint.ts +4 -0
- package/lib/fiber/catalogue.ts +22 -0
- package/lib/fiber/create-instance-from-react-element.ts +168 -0
- package/lib/fiber/intrinsic-jsx.ts +43 -0
- package/lib/index.ts +5 -0
- package/lib/register-catalogue.ts +3 -0
- package/lib/utils/autorouting/SimpleRouteJson.ts +37 -0
- package/lib/utils/autorouting/computeObstacleBounds.ts +10 -0
- package/lib/utils/constants.ts +35 -0
- package/lib/utils/createComponentsFromSoup.ts +86 -0
- package/lib/utils/get-relative-direction.ts +14 -0
- package/lib/utils/getPortFromHints.ts +10 -0
- package/lib/utils/projectPointInDirection.ts +18 -0
- package/lib/utils/selector-matching/index.ts +62 -0
- package/package.json +40 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { PrimitiveComponent } from "lib/components"
|
|
2
|
+
import type { Primitive } from "schematic-symbols/drawing/types"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Determines if a component matches a given selector.
|
|
6
|
+
*
|
|
7
|
+
* This function supports the following selector types:
|
|
8
|
+
* - ID selectors (#id)
|
|
9
|
+
* - Class selectors (.className)
|
|
10
|
+
* - Type selectors (resistor)
|
|
11
|
+
* - Attribute selectors ([key='value'])
|
|
12
|
+
*
|
|
13
|
+
* It also supports combinations of these selectors.
|
|
14
|
+
*
|
|
15
|
+
* @param component - The component to check.
|
|
16
|
+
* @param selector - The selector string to match against.
|
|
17
|
+
* @returns True if the component matches the selector, false otherwise.
|
|
18
|
+
*/
|
|
19
|
+
export function isMatchingSelector(
|
|
20
|
+
component: PrimitiveComponent,
|
|
21
|
+
selector: string,
|
|
22
|
+
): boolean {
|
|
23
|
+
// Check for ID selector
|
|
24
|
+
const idMatch = selector.match(/^#(\w+)/)
|
|
25
|
+
if (idMatch) {
|
|
26
|
+
return component.props.id === idMatch[1]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Check for class selector
|
|
30
|
+
const classMatch = selector.match(/^\.(\w+)/)
|
|
31
|
+
if (classMatch) {
|
|
32
|
+
return component.isMatchingNameOrAlias(classMatch[1])
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Split the selector into type and conditions
|
|
36
|
+
const [type, ...conditions] = selector.split(/(?=[#.[])/)
|
|
37
|
+
|
|
38
|
+
// Check if the component type matches
|
|
39
|
+
if (
|
|
40
|
+
type &&
|
|
41
|
+
type !== "*" &&
|
|
42
|
+
component.lowercaseComponentName !== type.toLowerCase()
|
|
43
|
+
) {
|
|
44
|
+
return false
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Check all conditions
|
|
48
|
+
return conditions.every((condition) => {
|
|
49
|
+
if (condition.startsWith("#")) {
|
|
50
|
+
return component.props.id === condition.slice(1)
|
|
51
|
+
}
|
|
52
|
+
if (condition.startsWith(".")) {
|
|
53
|
+
return component.isMatchingNameOrAlias(condition.slice(1))
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Check for attribute selector
|
|
57
|
+
const match = condition.match(/\[(\w+)=['"]?(.+?)['"]?\]/)
|
|
58
|
+
if (!match) return true
|
|
59
|
+
const [, prop, value] = match
|
|
60
|
+
return component.props[prop] === value
|
|
61
|
+
})
|
|
62
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tscircuit/core",
|
|
3
|
+
"module": "index.ts",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"types": "index.ts",
|
|
6
|
+
"version": "0.0.1",
|
|
7
|
+
"main": "dist/index.cjs",
|
|
8
|
+
"files": [
|
|
9
|
+
"index.ts",
|
|
10
|
+
"lib",
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsup index.ts"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@biomejs/biome": "^1.8.3",
|
|
18
|
+
"@tscircuit/log-soup": "^1.0.2",
|
|
19
|
+
"@types/bun": "latest",
|
|
20
|
+
"@types/react": "^18.3.3",
|
|
21
|
+
"@types/react-reconciler": "^0.28.8",
|
|
22
|
+
"circuit-to-svg": "^0.0.3",
|
|
23
|
+
"looks-same": "^9.0.1",
|
|
24
|
+
"tsup": "^8.2.4"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"typescript": "^5.0.0"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@tscircuit/infgrid-ijump-astar": "0.0.2",
|
|
31
|
+
"@tscircuit/props": "^0.0.36",
|
|
32
|
+
"@tscircuit/soup": "^0.0.52",
|
|
33
|
+
"@tscircuit/soup-util": "0.0.18",
|
|
34
|
+
"footprinter": "^0.0.44",
|
|
35
|
+
"react": "^18.3.1",
|
|
36
|
+
"react-reconciler": "^0.29.2",
|
|
37
|
+
"schematic-symbols": "0.0.10",
|
|
38
|
+
"transformation-matrix": "^2.16.1"
|
|
39
|
+
}
|
|
40
|
+
}
|