From c3ccee76e2a0536451c1c277497d59ff0de68dfe Mon Sep 17 00:00:00 2001 From: Baku Hashimoto Date: Fri, 1 Dec 2023 09:39:24 +0900 Subject: [PATCH] Update docs --- README.md | 37 +------------------------------------ docs/.vuepress/config.ts | 15 ++------------- docs/examples/primitives.js | 27 +++++++++++++++++++++++++++ docs/index.md | 10 +++++++++- package.json | 8 ++++---- typedoc.json | 8 +++++++- yarn.lock | 5 ----- 7 files changed, 50 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index c8023c4..50aac03 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@

Pathed

-DemoAPIBecome a Sponsor +DemoAPIBecome a Sponsor

@@ -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 ``` diff --git a/docs/.vuepress/config.ts b/docs/.vuepress/config.ts index d70e60f..ed2b2e8 100644 --- a/docs/.vuepress/config.ts +++ b/docs/.vuepress/config.ts @@ -33,7 +33,7 @@ module.exports = defineUserConfig({ }, { text: 'API', - link: '/api/modules', + link: '/api', }, { text: 'Github', @@ -41,18 +41,7 @@ module.exports = defineUserConfig({ }, ], }), - 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, }, diff --git a/docs/examples/primitives.js b/docs/examples/primitives.js index f0dac71..37af8b3 100644 --- a/docs/examples/primitives.js +++ b/docs/examples/primitives.js @@ -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) @@ -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]) diff --git a/docs/index.md b/docs/index.md index c11cd23..bd9ff47 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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 diff --git a/package.json b/package.json index a4a5f36..e38c156 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/typedoc.json b/typedoc.json index e2f6c7e..559a8f8 100644 --- a/typedoc.json +++ b/typedoc.json @@ -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 } diff --git a/yarn.lock b/yarn.lock index 27e0929..e12d60f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"