Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Dec 1, 2023
1 parent 63bc98e commit c3ccee7
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 60 deletions.
37 changes: 1 addition & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div align="center">
<h1>Pathed</h1>

<a href="https://baku89.github.io/pathed/">Demo</a> ⌇ <a href="https://baku89.github.io/pathed/api/modules">API</a> ⌇ <a href="https://github.com/sponsors/baku89">Become a Sponsor</a>
<a href="https://baku89.github.io/pathed/">Demo</a> ⌇ <a href="https://baku89.github.io/pathed/api">API</a> ⌇ <a href="https://github.com/sponsors/baku89">Become a Sponsor</a>

<p>
<a href="https://www.npmjs.org/package/pathed">
Expand All @@ -20,41 +20,6 @@ Pathed is a low-level toolkit for manipulating SVG/Path2D paths, which includes
Currently, the library heavily depends on [Bazier.js](https://pomax.github.io/bezierjs) by [Pomax](https://github.com/Pomax) and [Paper.js](http://paperjs.org) by [Jürg Lehni
](https://github.com/lehni) -- or it might be said that this library is a thin wrapper for them to provide FP-oriented interfaces. Although I'm going to rewrite the whole library with zero dependencies for performance and file size, please consider sponsoring them if you think it'd be useful.

```ts
import {Path} from 'pathed'
import {mat2d} from 'linearly'

const path: Path = [
['M', [0, 0]],
['C', [0, 100], [100, 100], [100, 0]],
['L', [100, 100]],
['L', [0, 100]],
['Z'],
]

// All property functions for paths will be memoized. Thus, the path is immutable.
Path.length(path)
Path.bound(path)
Path.area(path)
Path.tangentAtT(path, 0.5)

// Creating paths by primitive functions
const circle = Path.circle([100, 100], 50)
const rect = Path.rectangle([0, 0], [100, 100])

// Manipulating and combining paths
const transformedCircle = Path.transform(circle, mat2d.fromScaling([1, 0.5]))
const offsetRect = Path.offset(rect, 100, {joinCap: 'square'})
Path.join(path, offsetRect)

// As the path data is immutable, you cannot modify the content of paths (Not using Object.freeze, but it'll be warned in TypeScript). Use the mutation functions shown below instead.
const path2 = Path.moveTo(path, [0, 200])
const path3 = Path.lineTo(path2, [100, 200])

path.setAttribute('d', Path.toSVG(path3)) // "M 0,0 C 0,100, 100,100..."
ctx.stroke(Path.toPath2D(path3))
```

## Development

```
Expand Down
15 changes: 2 additions & 13 deletions docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,15 @@ module.exports = defineUserConfig({
},
{
text: 'API',
link: '/api/modules',
link: '/api',
},
{
text: 'Github',
link: 'https://github.com/baku89/pathed',
},
],
}),
plugins: [
typedocPlugin({
entryPoints: ['./src/index.ts'],
tsconfig: '../../tsconfig.json',
cleanOutputDir: true,
hideInPageTOC: true,
sidebar: {
fullNames: true,
},
}),
palettePlugin({preset: 'sass'}),
],
plugins: [palettePlugin({preset: 'sass'})],
markdown: {
linkify: true,
},
Expand Down
27 changes: 27 additions & 0 deletions docs/examples/primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
* fill: (path: Path, color: string) => void
*/

// The path data is an array of commands and arguments.
const path = [
['M', [0, 0]],
['C', [0, 100], [100, 100], [100, 0]],
['L', [100, 100]],
['L', [0, 100]],
['Z'],
]

// You can create a path by primitive functions.
const c = Path.circle([50, 50], 40)
stroke(c, 'PaleGreen', 1)

Expand All @@ -32,3 +42,20 @@ const b = Path.cubicBezierTo(
[90, 50]
)
stroke(b, 'plum')

// All property functions for paths will be memoized.
// Thus, the path is immutable.
Path.length(path)
Path.bound(path)
Path.area(path)

// Manipulating and combining paths
const tc = Path.transform(c, mat2d.fromScaling([1, 0.5]))
const or = Path.offset(r, 100, {join: 'round'})
Path.join(tc, or)

// As the path data is immutable, you cannot modify the content of paths
// (Not using Object.freeze, but it'll be warned in TypeScript).
// Use the mutation functions shown below instead.
const path2 = Path.moveTo(path, [0, 200])
const path3 = Path.lineTo(path2, [100, 200])
10 changes: 9 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ yarn add pathed
```js:no-line-numbers
import {Path} from 'pathed'
console.log(Path.circle([0, 0], 100))
const circle = Path.circle([0, 0], 100)
// For SVG's path element
const d = Path.toSVG(circle)
svgPathElement.setAttribute('d', d)
// For Canvas API
const path2d = Path.toPath2D(circle)
context.stroke(path2d)
```

### Example
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
"types": "./lib/esm/index.d.ts",
"sideEffects": false,
"scripts": {
"dev": "vuepress dev docs",
"dev": "npm run build:api & vuepress dev docs",
"build": "tsc && tsc -p tsconfig.cjs.json",
"build:doc": "vuepress build docs",
"build:api": "typedoc src/index.ts",
"build:doc": "npm run build:api & vuepress build docs",
"lint": "eslint",
"test": "jest",
"prepare": "npm run build",
Expand Down Expand Up @@ -66,8 +67,7 @@
"typedoc-plugin-markdown": "^3.16.0",
"typescript": "^5.2.2",
"vue-eslint-parser": "^9.3.2",
"vuepress": "^2.0.0-rc.0",
"vuepress-plugin-typedoc": "^0.13.0"
"vuepress": "^2.0.0-rc.0"
},
"dependencies": {
"@types/bezier-js": "^4.1.3",
Expand Down
8 changes: 7 additions & 1 deletion typedoc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"$schema": "https://typedoc.org/schema.json",
"entryPoints": ["./src/index.ts"],
"sort": ["alphabetical"]
"out": "./docs/api",
"plugin": ["typedoc-plugin-markdown"],
"readme": "none",
"sort": ["alphabetical"],
"cleanOutputDir": true,
"includeVersion": true,
"hideInPageTOC": true
}
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5078,11 +5078,6 @@ vue@^3.2.37, vue@^3.3.8:
"@vue/server-renderer" "3.3.9"
"@vue/shared" "3.3.9"

vuepress-plugin-typedoc@^0.13.0:
version "0.13.0"
resolved "https://registry.yarnpkg.com/vuepress-plugin-typedoc/-/vuepress-plugin-typedoc-0.13.0.tgz#9e0272f5341db81dd66720c17c6a587d4c414210"
integrity sha512-3JNuR912ktT0M6kA8hWST09TzrJOm9OaA8O4xxLf5wUojeOmhczDR7VgYMriFRbfTnbpoDAw2AeD9gtW59686A==

vuepress-vite@2.0.0-rc.0:
version "2.0.0-rc.0"
resolved "https://registry.yarnpkg.com/vuepress-vite/-/vuepress-vite-2.0.0-rc.0.tgz#edcb902881368143c24199e66c2300f4bcd2b61f"
Expand Down

0 comments on commit c3ccee7

Please sign in to comment.