1
0
Fork 0

chore: Port FreeSewing.dev to docusaurus

The replaces the NextJS site powering FreeSewing.dev with a Docusaurus
setup. It's part of my efforts to simplify FreeSewing's setup so we can
focus on our core value proposition.
This commit is contained in:
Joost De Cock 2024-09-28 13:13:48 +02:00
parent 497633d1d3
commit ab3204f9f1
692 changed files with 11037 additions and 20674 deletions

View file

@ -0,0 +1,43 @@
---
title: Point.addCircle()
---
The `Point.addCircle()` method adds a circle to a Point. Under the hood, this
will call `Point.attr()` as circles are added by setting attributes. Refer to
[Drawing circles](/howtos/code/drawing-circles) for more details.
## Signature
```js
Point point.addCircle(
number radius,
string className
)
```
:::tipThis method is chainable as it returns the `Point` object:::
## Example
<Example caption="Examples of Point.addCircle(), compare this to [Point.setCircle](/reference/api/point/setcircle)">
```js
({ Point, points, part }) => {
points.a = new Point(30, 10)
.addCircle(3, 'lining dashed')
.addCircle(7, 'mark dashed')
points.b = new Point(50, 10)
.addCircle(1, 'interfacing')
.addCircle(3, 'fabric')
.addCircle(5, 'lining')
.addCircle(7, 'mark')
.addCircle(9, 'note')
points.c = new Point(70, 10)
.addCircle(3, 'interfacing')
.addCircle(7, 'mark lashed')
return part
}
```
</Example>

View file

@ -0,0 +1,43 @@
---
title: Point.addText()
---
The `Point.addText()` method adds text on a Point. Under the hood, this will
call `Point.attr()` as text is added by setting attributes. Refer to [Adding
text](/howtos/code/adding-text) for more details.
## Signature
```js
Point point.addText(
string text,
string className
)
```
:::tipThis method is chainable as it returns the `Point` object:::
## Example
<Example caption="Examples of Point.addText(), compare this to [Point.setText](/reference/api/point/settext)">
```js
({ Point, points, Path, paths, part }) => {
points.anchor = new Point(100, 25)
.addText('FreeSewing')
.addText('rocks')
// Avoid the text getting cropped
paths.hidden = new Path()
.move(points.anchor)
.line(points.anchor.shift(0, 80))
.addClass('hidden')
return part
}
```
</Example>
## Notes
Remember to [use translation keys, not text](/guides/best-practices#use-translation-keys)

View file

@ -0,0 +1,38 @@
---
title: Point.angle()
---
The `Point.angle()` method returns the angle (in degrees) between this point
and the point passed into the method. An angle of 0° points to the right, and
the angle increases counterclockwise.
## Signature
```js
float point.angle(Point pointB)
```
## Example
<Example caption="An example of the Point.angle() method">
```js
({ Point, points, Path, paths, part }) => {
points.sun = new Point(10, 5)
points.moon = points.sun.shift(-15, 70)
points.text = points.sun
.shiftFractionTowards(points.moon, 0.8)
.setText(
points.sun.angle(points.moon)+"°",
"text-sm fill-note center"
)
paths.line = new Path()
.move(points.sun)
.line(points.moon)
.setClass("dashed")
return part
}
```
</Example>

View file

@ -0,0 +1,24 @@
---
title: Point.asRenderProps()
---
The `Point.asRenderProps()` method will return the data stored in the
point as a serializable JavaScript object. This method is typically
not invoked directly but rather called under the hood as a result of
calling [`Pattern.getRenderProps()`](/reference/api/pattern/getrenderprops).
## Signature
```js
Object point.asRenderProps()
```
## Returned object properties
This returns JavaScript object has the following properties:
| Name | Description |
| ----:| ----------- |
| `attributes` | The result of [Path.attributes.asRenderProps()](/reference/api/attributes/asrenderprops) |
| `x` | A number indicating the X-Coordinate of the point |
| `y` | A number indicating the Y-Coordinate of the point |

View file

@ -0,0 +1,48 @@
---
title: Point.attr()
---
The `Point.attr()` method adds an attribute to the point, and returns the
original point. Setting the third parameter to `true` will replace the value of
the attribute instead of adding it.
## Signature
```js
Point point.attr(
string name,
mixed value,
bool overwrite = false
)
```
If the third parameter is set to `true` it will call [`this.attributes.set()`](/reference/api/attributes/set/) instead, thereby overwriting the value of the attribute.
:::tipThis method is chainable as it returns the `Point` object:::
## Example
<Example caption="An example of the Point.attr() method">
```js
({ Point, points, Path, paths, part }) => {
points.anchor = new Point(100, 25)
.attr('data-text', 'FreeSewing')
.attr('data-text', 'rocks')
// Avoid the text getting cropped
paths.hidden = new Path()
.move(points.anchor)
.line(points.anchor.shift(0, 80))
.addClass('hidden')
return part
}
```
</Example>
## Notes
See [Using Attributes](/howtos/code/attributes)
for information about custom Attributes that can be used with Points.

View file

@ -0,0 +1,45 @@
---
title: Point.clone()
---
The `Point.clone()` method returns a new `Point` with the same coordinates and
attributes as the original point.
## Signature
```js
Point point.clone()
```
:::tipThis method is chainable as it returns the `Point` object:::
## Example
<Example caption="An example of the Point.clone() method">
```js
({ Point, points, Path, paths, Snippet, snippets, part }) => {
points.A = new Point(25, 25)
.setText("Point A", "text-xl")
.attr("data-text-fill-opacity", "0.5")
points.B = points.A.clone().setText("Point B")
snippets.x = new Snippet("notch", points.A)
// Avoid the text getting cropped
paths.hidden = new Path()
.move(new Point(20,10))
.move(new Point(75,30))
.addClass('hidden')
return part
}
```
</Example>
## Notes
The [`Point.copy()`](/reference/api/point/copy/) method will only copy the
point's coordinates, whereas this `Point.clone()` method will also copy its
attributes.

View file

@ -0,0 +1,44 @@
---
title: Point.copy()
---
The `Point.copy()` method returns a new point with the same coordinates as the
original point. This method does _not_ copy any attributes the original point
may have.
## Signature
```js
Point point.copy()
```
## Point.copy() example
<Example caption="An example of the Point.copy() method">
```js
({ Point, points, Path, paths, Snippet, snippets, part }) => {
points.A = new Point(25, 25)
.setText("Point A", "text-xl")
.attr("data-text-fill-opacity", "0.5")
points.B = points.A.clone().setText("Point B")
snippets.x = new Snippet("notch", points.A)
// Avoid the text getting cropped
paths.hidden = new Path()
.move(new Point(20,10))
.move(new Point(75,30))
.addClass('hidden')
return part
}
```
</Example>
## Notes
The `Point.copy()` method will only copy the point's coordinates.
To also copy the attributes, use [`Point.clone()`](/reference/api/point/clone/) instead.

View file

@ -0,0 +1,32 @@
---
title: Point.dx()
---
The `Point.dx()` method returns the delta (in mm) along the X-axis between this
point and the point you pass it.
## Signature
```js
float point.dx(Point point)
```
## Example
<Example caption="An example of the Point.dx() method">
```js
({ Point, points, Path, paths, units, part }) => {
points.from = new Point(10, 10)
points.to = new Point(76.6, 10)
paths.line = new Path()
.move(points.from)
.line(points.to)
.setClass("dotted")
.setText(units(points.from.dx(points.to)), 'center')
return part
}
```
</Example>

View file

@ -0,0 +1,37 @@
---
title: Point.dy()
---
The `Point.dy()` method returns the delta (in mm) along the Y-axis between this
point and the point you pass it.
## Signature
```js
float point.dy(Point point)
```
## Example
<Example caption="An example of the Point.dy() method">
```js
({ Point, points, Path, paths, units, part }) => {
points.from = new Point(10, 40)
points.to = new Point(10, 10)
paths.line = new Path()
.move(points.from)
.line(points.to)
.setClass("dotted")
.setText(units(points.from.dy(points.to)), 'center')
// Prevents clipping
paths.diag = new Path()
.move(new Point(-10,40))
.move(new Point(60,10))
return part
}
```
</Example>

View file

@ -0,0 +1,67 @@
---
title: Point.flipX()
---
The `Point.flipX()` method returns a new `Point` that mirrors the original
point around the X-value of the point you pass it. If you do not pass in a
point, it will default to mirroring around an X-value of zero.
## Signature
```js
Point point.flipX(Point mirror = false)
```
## Example
<Example caption="An example of the Point.flipX() method">
```js
({ Point, points, Path, paths, part }) => {
points.top = new Point(50, 10)
points.out1 = new Point(70, 30)
points.in1 = new Point(55, 35)
points.out2 = new Point(75, 50)
points.in2 = new Point(60, 55)
points.out3 = new Point(80, 70)
points.in3 = new Point(55, 70)
points.trunkOut = new Point(55, 80)
points.trunkIn = new Point(50, 80)
points._out1 = points.out1.flipX(points.top)
points._in1 = points.in1.flipX(points.top)
points._out2 = points.out2.flipX(points.top)
points._in2 = points.in2.flipX(points.top)
points._out3 = points.out3.flipX(points.top)
points._in3 = points.in3.flipX(points.top)
points._trunkOut = points.trunkOut.flipX(points.top)
points.bottom = new Point(50, 80)
paths.tree = new Path()
.move(points.top)
.line(points.out1)
.line(points.in1)
.line(points.out2)
.line(points.in2)
.line(points.out3)
.line(points.in3)
.line(points.trunkOut)
.line(points._trunkOut)
.line(points._in3)
.line(points._out3)
.line(points._in2)
.line(points._out2)
.line(points._in1)
.line(points._out1)
.close()
paths.mirror = new Path()
.move(points.top)
.line(points.bottom)
.setClass("note dashed")
return part
}
```
</Example>

View file

@ -0,0 +1,72 @@
---
title: Point.flipY()
---
The `Point.flipY()` method returns a new `Point` that mirrors the original
point around the Y-value of the point you pass it. If you do not pass in a
point, it will default to mirroring around an Y-value of zero.
## Signature
```js
Point point.flipY(Point mirror = false)
```
## Example
<Example caption="An example of the Point.flipY() method">
```js
({ Point, points, Path, paths, part }) => {
points.start = new Point(0, 50)
points.churchTowerWallLeft = new Point(10, 50)
points.churchTowerRoofLeft = new Point(10, 30)
points.churchTowerTop = new Point(15, 10)
points.churchTowerRoofRight = new Point(20, 30)
points.churchRoofRight = new Point(50, 30)
points.churchWallRight = new Point(50, 50)
points.houseWallLeft = new Point(65, 50)
points.houseRoofLeft = new Point(65, 35)
points.houseRoofTop = new Point(75, 25)
points.houseRoofRight = new Point(85, 35)
points.houseWallRight = new Point(85, 50)
points.end = new Point(95, 50)
points.mirror = new Point(0, 60)
points.mirrorLineEnd = new Point(95, 60)
points._start = points.start.flipY(points.mirror)
points._churchTowerWallLeft = points.churchTowerWallLeft.flipY(points.mirror)
points._churchTowerRoofLeft = points.churchTowerRoofLeft.flipY(points.mirror)
points._churchTowerTop = points.churchTowerTop.flipY(points.mirror)
points._churchTowerRoofRight = points.churchTowerRoofRight.flipY(
points.mirror
)
points._churchRoofRight = points.churchRoofRight.flipY(points.mirror)
points._churchWallRight = points.churchWallRight.flipY(points.mirror)
points._houseWallLeft = points.houseWallLeft.flipY(points.mirror)
points._houseRoofLeft = points.houseRoofLeft.flipY(points.mirror)
points._houseRoofTop = points.houseRoofTop.flipY(points.mirror)
points._houseRoofRight = points.houseRoofRight.flipY(points.mirror)
points._houseWallRight = points.houseWallRight.flipY(points.mirror)
points._end = points.end.flipY(points.mirror)
paths.skylineTop = new Path()
.move(points.start)
.line(points.churchTowerWallLeft)
.line(points.churchTowerRoofLeft)
.line(points.churchTowerTop)
.line(points.churchTowerRoofRight)
.line(points.churchRoofRight)
.line(points.churchWallRight)
.line(points.houseWallLeft)
.line(points.houseRoofLeft)
.line(points.houseRoofTop)
.line(points.houseRoofRight)
.line(points.houseWallRight)
.line(points.end)
return part
}
```
</Example>

View file

@ -0,0 +1,48 @@
---
title: Point
---
A Point object represents a point on a 2D plane with an X and Y axis.
## Signature
```js
Point new Point(Number x, Number y)
```
The point constructor takes two arguments:
- `x` : The X-coordinate of the point
- `y` : The Y-coordinate of the point
## Properties
Point objects come with the following properties:
- `x` : The X-coordinate of the point
- `y` : The Y-coordinate of the point
- `attributes` : An [Attributes](/reference/api/attributes) instance holding the point's attributes
:::note RELATED
See [Using Attributes](/howtos/code/attributes)
for information about custom Attributes that can be used with Points.
:::
## Example
<Example caption="Example of the Point constructor">
```js
({ Point, points, part }) => {
points.example = new Point(0,0)
.addCircle(10)
return part
}
```
</Example>
## Methods
A Point object exposes the following methods:
<ReadMore />

View file

@ -0,0 +1,35 @@
---
title: Point.rotate()
---
The `Point.rotate()` method returns a new `Point` that has been rotated by
`angle` degrees around the point (`center`) that you pass it.
Just like the result of the [`Point.angle()`](/reference/api/point/angle/)
method, an angle of 0° points right, and the angle increases counterclockwise.
## Signature
```js
Point point.rotate(float angle, Point center)
```
## Example
<Example caption="An example of the Point.rotate() method">
```js
({ Point, points, Path, paths, Snippet, snippets, part }) => {
points.sun = new Point(40, 40)
points.moon = new Point(70, 40)
let step = 360 / 36
for (let i = 1; i < 37; i++) {
let angle = step * i
points[`moon${i}`] = points.moon.rotate(angle, points.sun)
paths[`moon${i}`] = new Path().move(points.sun).line(points[`moon${i}`])
}
return part
}
```
</Example>

View file

@ -0,0 +1,50 @@
---
title: Point.setCircle()
---
The `Point.setCircle()` method adds a circle to a Point. It yields similar
results as the [`Point.addCircle()`](/reference/api/point/addcircle) method,
the different is that `Point.setCircle()` will overwrite any previous circle
set.
Essentially, it mimics the difference between adding vs setting an attribute.
Refer to [Drawing circles](/howtos/code/drawing-circles) for more details on
how circles are handled.
## Signature
```js
Point point.setCircle(
number radius,
string className
)
```
:::tipThis method is chainable as it returns the `Point` object:::
## Example
<Example caption="Examples of Point.setCircle(), compare this to [Point.addCircle()](/reference/api/point/addcircle)">
```js
({ Point, points, part }) => {
points.a = new Point(30, 10)
.setCircle(3, 'lining dashed')
.setCircle(7, 'mark dashed')
points.b = new Point(50, 10)
.setCircle(1, 'interfacing')
.setCircle(3, 'fabric')
.setCircle(5, 'lining')
.setCircle(7, 'mark')
.setCircle(9, 'note')
points.c = new Point(70, 10)
.setCircle(3, 'interfacing')
.setCircle(7, 'mark lashed')
return part
}
```
</Example>

View file

@ -0,0 +1,43 @@
---
title: Point.setText()
---
The `Point.setText()` method sets text on a Point. Under the hood, this will
call `Point.attr()` as text is set via attributes. Refer to [Adding
text](/howtos/code/adding-text) for more details.
## Signature
```js
Point point.setText(
string text,
string className
)
```
:::tipThis method is chainable as it returns the `Point` object:::
## Example
<Example caption="Examples of Point.setText(), compare this to [Point.setText()](/reference/api/point/settext)">
```js
({ Point, points, Path, paths, part }) => {
points.anchor = new Point(100, 25)
.setText('FreeSewing')
.setText('rocks')
// Avoid the text getting cropped
paths.hidden = new Path()
.move(points.anchor)
.line(points.anchor.shift(0, 80))
.addClass('hidden')
return part
}
```
</Example>
## Notes
Remember to [use translation keys, not text](/guides/best-practices#use-translation-keys)

View file

@ -0,0 +1,36 @@
---
title: Point.shift()
---
The `Point.shift()` method returns a new `Point` that is `distance` (mm) away
in the direction of `angle` (degrees). An angle of 0° points to the right, and
the angle increases counterclockwise.
## Signature
```js
Point point.shift(float angle, float distance)
```
## Example
<Example caption="An example of the Point.shift() method">
```js
({ Point, points, macro, part }) => {
points.A = new Point(90, 40)
.setText("Point A", "right text-sm")
points.B = points.A.shift(155, 70)
.setText("Point B is point A shifted 7 cm\nat a 155 degree angle", "text-sm")
.attr("data-text-lineheight", 6)
macro("ld", {
from: points.B,
to: points.A,
d: -10
})
return part
}
```
</Example>

View file

@ -0,0 +1,60 @@
---
title: Point.shiftFractionTowards()
---
The `Point.shiftFractionTowards()` method returns a new `Point` that is shifted
towards the `target` by a `fraction` of the distance between this point and the
target.
This method accepts values larger than 1 to go beyond the target point, or
negative values to shift the point in the opposite direction.
## Signature
```js
Point point.shiftFractionTowards(Point target, float fraction)
```
## Point.shiftFractionTowards() example
<Example caption="An example of the Point.shiftFractionTowards() method">
```js
({ Point, points, Path, paths, macro, part }) => {
points.A = new Point(90, 70).setText("Point A", "text-sm")
points.B = new Point(10, 10).setText("Point B", "text-sm")
points.C = points.A.shiftFractionTowards(points.B, 0.5)
.setText(
"Point C is point A shifted 50%\nin the direction of point B",
"center text-sm"
)
.attr("data-text-lineheight", 6)
paths.direction = new Path()
.move(points.A)
.line(points.B)
.setClass("note dashed")
macro("ld", {
from: points.C,
to: points.A,
d: -10
})
macro("ld", {
from: points.B,
to: points.A,
d: 20
})
return part
}
```
</Example>
## Notes
If you need to move a point by a specific distance instead of a percentage, use
[`Point.shiftTowards()`](/reference/api/point/shifttowards/) or
[`Point.shiftOutwards()`](/reference/api/point/shiftoutwards/) instead.

View file

@ -0,0 +1,40 @@
---
title: Point.shiftOutwards()
---
The `Point.shiftOutwards()` method returns a new `Point` that is shifted
`distance` (mm) beyond the `target` in the direction of the target point.
## Signature
```js
Point point.shiftOutwards(Point target, float distance)
```
## Example
<Example caption="An example of the Point.shiftOutwards() method">
```js
({ Point, points, Path, paths, macro, part }) => {
points.A = new Point(90, 70).setText("Point A", "text-sm right")
points.B = new Point(10, 10).setText("Point B", "text-sm")
points.C = points.A.shiftOutwards(points.B, 30)
.setText("Point C is point A shifted 3 cm\nbeyond point B", "text-sm")
.attr("data-text-lineheight", 6)
paths.direction = new Path()
.move(points.A)
.line(points.C)
.addClass("note dashed")
macro("ld", {
from: points.C,
to: points.B,
d: -10
})
return part
}
```
</Example>

View file

@ -0,0 +1,47 @@
---
title: Point.shiftTowards()
---
The `Point.shiftTowards()` method returns a new `Point` that is shifted
`distance` (mm) in the direction of the `target`.
## Signature
```js
Point point.shiftTowards(Point target, float distance)
```
## Example
<Example caption="An example of the Point.shiftTowards() method">
```js
({ Point, points, Path, paths, macro, part }) => {
points.A = new Point(90, 70).setText("Point A", "right text-sm")
points.B = new Point(10, 10).setText("Point B", "text-sm")
points.C = points.A.shiftTowards(points.B, 35)
.setText("Point C is point A shifted 3.5 cm\nin the direction of point B", "center, text-sm")
.attr("data-text-lineheight", 6)
paths.direction = new Path()
.move(points.A)
.line(points.B)
.addClass("note dashed")
macro("ld", {
from: points.C,
to: points.A,
d: -10
})
return part
}
```
</Example>
## Notes
If you need to move a point a percentage instead of a specific distance, use
[`Point.shiftFractionTowards()`](/reference/api/point/shiftfractiontowards/)
instead.

View file

@ -0,0 +1,47 @@
---
title: Point.sitsOn()
---
The `Point.sitsOn()` method returns `true` if this point has the _exact_ same
coordinates as the point you pass to it.
## Signature
```js
bool point.sitsOn(Point check)
```
## Example
<Example caption="An example of the Point.sitsOn() method">
```js
({ Point, points, Path, paths, Snippet, snippets, part }) => {
let s
for (let i = 0; i < 10; i++) {
points[`a${i}`] = new Point(i * 10, 40)
points[`b${i}`] = new Point(i * 10, i * 8)
if (points[`a${i}`].sitsOn(points[`b${i}`])) s = "notch"
else s = "bnotch"
snippets[`b${i}`] = new Snippet(s, points[`b${i}`])
snippets[`a${i}`] = new Snippet(s, points[`a${i}`])
}
// Prevent clipping
paths.diag = new Path()
.move(new Point(0,0))
.move(new Point(90,70))
return part
}
```
</Example>
## Notes
This method uses strict comparison. So points with an X-coordinate of `10` and
`10.0001` are considered to be different.
To check if two points have the same coordinates rounded to the nearest
millimeter, use [`Point.sitsRoughlyOn()`](/reference/api/point/sitsroughlyon/)
instead.

View file

@ -0,0 +1,46 @@
---
title: Point.sitsRoughlyOn()
---
The `Point.sitsRoughlyOn()` method returns `true` if this point has roughly
(rounded to the nearest millimeter) the same coordinates as the one you pass to
it.
## Signature
```js
bool point.sitsRoughlyOn(Point check)
```
## Example
<Example caption="An example of the Point.sitsRoughlyOn() method">
```js
({ Point, points, Path, paths, Snippet, snippets, part }) => {
let s
for (let i = 0; i < 10; i++) {
points[`a${i}`] = new Point(i * 10, 40)
points[`b${i}`] = new Point(i * 10, i * 8)
if (points[`a${i}`].sitsRoughlyOn(points[`b${i}`])) s = "notch"
else s = "bnotch"
snippets[`b${i}`] = new Snippet(s, points[`b${i}`])
snippets[`a${i}`] = new Snippet(s, points[`a${i}`])
}
// Prevent clipping
paths.diag = new Path()
.move(new Point(0,0))
.move(new Point(90,70))
return part
}
```
</Example>
## Notes
The difference between this method and
[`Point.sitsOn()`](/reference/api/point/sitson/) is that this one rounds things
down to the nearest integer (thus mm) before checking.

View file

@ -0,0 +1,49 @@
---
title: Point.slope()
---
The `Point.slope()` method returns the slope (dy/dx) of a line between two Points.
## Signature
```js
point.slope(otherPoint)
```
## Example
<Example caption="An example of the Point.slope() method">
```js
({ Point, points, Path, paths, Snippet, snippets, part, macro }) => {
points.A = new Point(0,0)
points.B = new Point(200,150)
const slope = points.A.slope(points.B)
macro('hd', {
from: points.A,
to: points.B,
y: points.B.y,
})
macro('vd', {
to: points.B,
from: points.A,
x: 0,
})
paths.line = new Path()
.move(points.A)
.line(points.B)
.attr("class", "canvas")
.setText("Slope: " + slope, "center text-lg")
return part
}
```
</Example>

View file

@ -0,0 +1,51 @@
---
title: Point.translate()
---
The `Point.translate()` method returns a new `Point` with a [translate
transform](https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/translate)
applied.
## Signature
```js
Point point.translate(float deltaX, float deltaY)
```
In other words, this will:
- Add `deltaX` to the point's X-coordinate
- Add `deltaY` to the point's Y-coordinate
Positive values for `deltaX` will move the point to the right.
Positive values for `deltaY` will move the point downwards.
## Example
<Example caption="An example of the Point.translate() method">
```js
({ Point, points, Snippet, snippets, macro, part }) => {
points.A = new Point(10, 10).setText("Point A", "text-sm")
points.B = points.A.translate(120, 60)
.setText(
"Point B is point A with a\ntranslate(120, 60)\ntransform applied",
"right text-sm"
)
.attr("data-text-dy", -6)
.attr("data-text-lineheight", 6)
snippets.A = new Snippet("x", points.A)
snippets.B = new Snippet("x", points.B)
macro("ld", {
from: points.A,
to: points.B,
text: "translate(120,60)",
noStartMarker: true
})
return part
}
```
</Example>