@p5-wrapper/common 0.1.0
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/LICENSE +21 -0
- package/README.md +49 -0
- package/dist/main.cjs +7 -0
- package/dist/main.d.ts +48 -0
- package/dist/main.mjs +46 -0
- package/package.json +85 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 P5 wrapper
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# @p5-wrapper/common
|
|
2
|
+
|
|
3
|
+
Common types and utilities for use across p5 wrapper libraries.
|
|
4
|
+
|
|
5
|
+
This package is the **source of truth** for the shared contracts and p5 instance
|
|
6
|
+
lifecycle utilities used by every wrapper library in the
|
|
7
|
+
[P5-wrapper](https://github.com/P5-wrapper) organisation.
|
|
8
|
+
|
|
9
|
+
The library is deliberately **framework agnostic**: it imports no framework, and
|
|
10
|
+
the only renderer-bound concept is the `OutputNode` type parameter on the props
|
|
11
|
+
contract. Each ecosystem binds `OutputNode` to its own render output
|
|
12
|
+
(`ReactNode` for React, `VNode` for Vue, embedded view nodes for Angular, and so
|
|
13
|
+
on), which keeps the input props identical across all implementations.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @p5-wrapper/common p5
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`p5` is a peer dependency so that the consumer owns the `p5` version.
|
|
22
|
+
|
|
23
|
+
## Build contract
|
|
24
|
+
|
|
25
|
+
Published artefacts live in `dist/`:
|
|
26
|
+
|
|
27
|
+
- `types` → `main.d.ts` (bundled via `vite-plugin-dts`)
|
|
28
|
+
- `import` → `main.mjs` (ESM)
|
|
29
|
+
- `require` → `main.cjs` (CJS)
|
|
30
|
+
|
|
31
|
+
The `.mjs`/`.cjs` extensions are pinned (never derived from a Vite `[format]`
|
|
32
|
+
placeholder) so the module format self-describes under `"type": "module"`. If
|
|
33
|
+
you change the filenames, change the `exports` map in the `package.json` and the
|
|
34
|
+
Vite config in the same commit.
|
|
35
|
+
|
|
36
|
+
## Development
|
|
37
|
+
|
|
38
|
+
| Command | Action |
|
|
39
|
+
| :------------------- | :---------------------------------------------- |
|
|
40
|
+
| `pnpm install` | Install dependencies (updates the lock file). |
|
|
41
|
+
| `pnpm format` | Format all files with Prettier. |
|
|
42
|
+
| `pnpm format:check` | Check formatting without writing. |
|
|
43
|
+
| `pnpm lint` | Run ESLint (type-aware). |
|
|
44
|
+
| `pnpm lint:fix` | Run ESLint with autofix. |
|
|
45
|
+
| `pnpm test` | Run the Vitest suite. |
|
|
46
|
+
| `pnpm test:coverage` | Run tests with coverage (what CI runs). |
|
|
47
|
+
| `pnpm test:watch` | Watch mode. |
|
|
48
|
+
| `pnpm build` | Clean, type check, and build the npm library. |
|
|
49
|
+
| `pnpm integrate` | format:check → lint → test → build (CI mirror). |
|
package/dist/main.cjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));let c=require("p5");c=s(c,1);let l=require("microdiff");l=s(l,1);var u=`canvas-container`;function d(e,t){return new c.default(e,t)}var f=`[P5Canvas] The error boundary was triggered. The error message was:`;function p(e){return e.trim().split(`
|
|
2
|
+
`).map(e=>e.trim()).join(`
|
|
3
|
+
`)}function m(e){return p(`
|
|
4
|
+
${f}
|
|
5
|
+
|
|
6
|
+
${e}
|
|
7
|
+
`)}function h(e){return e instanceof Error?`${e.name}("${e.message}")`:typeof e==`symbol`?e.toString():typeof e==`string`?`String("${e}")`:typeof e==`number`?`Number(${e})`:typeof e==`bigint`?`BigInt(${e})`:e instanceof Array?`Array(${JSON.stringify([...e])})`:e instanceof Set?`Set(${JSON.stringify([...e])})`:Object.getPrototypeOf(e)===Object.prototype?`Object(${JSON.stringify(e)})`:`Unknown(${typeof e})`}function g(e){let t=m(h(e));console.error(t)}function _(e,t){return(0,l.default)(e,t).length===0}function v(e){e.current?.remove(),e.current=null}function y(e,t,n){return t.current===null?null:(v(e),d(n,t.current))}exports.CanvasContainerClassName=u,exports.createP5CanvasInstance=d,exports.logErrorBoundaryError=g,exports.p5=c.default,exports.propsAreEqual=_,exports.removeP5CanvasInstance=v,exports.updateP5CanvasInstance=y;
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { default as p5_2 } from 'p5';
|
|
2
|
+
|
|
3
|
+
export declare type CanvasContainer = HTMLDivElement;
|
|
4
|
+
|
|
5
|
+
export declare const CanvasContainerClassName = "canvas-container";
|
|
6
|
+
|
|
7
|
+
export declare interface CanvasContainerRef {
|
|
8
|
+
current: CanvasContainer | null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export declare function createP5CanvasInstance<Props extends SketchProps>(sketch: Sketch<Props>, canvasContainer: CanvasContainer): P5CanvasInstance<Props>;
|
|
12
|
+
|
|
13
|
+
export declare function logErrorBoundaryError(error: unknown): void;
|
|
14
|
+
|
|
15
|
+
export { p5_2 as p5 }
|
|
16
|
+
|
|
17
|
+
export declare type P5CanvasInstance<Props extends SketchProps = SketchProps> = p5_2 & {
|
|
18
|
+
updateWithProps?: (props: Props) => void;
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** Ref to the active p5.js sketch instance controlling the canvas */
|
|
23
|
+
export declare interface P5CanvasInstanceRef<Props extends SketchProps> {
|
|
24
|
+
current: P5CanvasInstance<Props> | null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export declare type P5CanvasProps<Props extends SketchProps = SketchProps, OutputNode = unknown> = {
|
|
28
|
+
sketch?: Sketch<Props>;
|
|
29
|
+
updater?: Updater<Props>;
|
|
30
|
+
fallback?: () => OutputNode;
|
|
31
|
+
loading?: () => OutputNode;
|
|
32
|
+
error?: (error: unknown) => OutputNode;
|
|
33
|
+
children?: OutputNode;
|
|
34
|
+
} & Props;
|
|
35
|
+
|
|
36
|
+
export declare function propsAreEqual<Props extends SketchProps>(previous: Props, next: Props): boolean;
|
|
37
|
+
|
|
38
|
+
export declare function removeP5CanvasInstance<Props extends SketchProps>(p5CanvasInstanceRef: P5CanvasInstanceRef<Props>): void;
|
|
39
|
+
|
|
40
|
+
export declare type Sketch<Props extends SketchProps = SketchProps> = (instance: P5CanvasInstance<Props>) => void;
|
|
41
|
+
|
|
42
|
+
export declare type SketchProps = Record<string, unknown>;
|
|
43
|
+
|
|
44
|
+
export declare function updateP5CanvasInstance<Props extends SketchProps>(p5CanvasInstanceRef: P5CanvasInstanceRef<Props>, canvasContainerRef: CanvasContainerRef, sketch: Sketch<Props>): P5CanvasInstance<Props> | null;
|
|
45
|
+
|
|
46
|
+
export declare type Updater<Props extends SketchProps = SketchProps> = (instance: P5CanvasInstance<Props>, props: Props) => void;
|
|
47
|
+
|
|
48
|
+
export { }
|
package/dist/main.mjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import e from "p5";
|
|
2
|
+
import t from "microdiff";
|
|
3
|
+
//#region src/constants/CanvasContainerClassName.ts
|
|
4
|
+
var n = "canvas-container";
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/utils/createP5CanvasInstance.ts
|
|
7
|
+
function r(t, n) {
|
|
8
|
+
return new e(t, n);
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/utils/logErrorBoundaryError.ts
|
|
12
|
+
var i = "[P5Canvas] The error boundary was triggered. The error message was:";
|
|
13
|
+
function a(e) {
|
|
14
|
+
return e.trim().split("\n").map((e) => e.trim()).join("\n");
|
|
15
|
+
}
|
|
16
|
+
function o(e) {
|
|
17
|
+
return a(`
|
|
18
|
+
${i}
|
|
19
|
+
|
|
20
|
+
${e}
|
|
21
|
+
`);
|
|
22
|
+
}
|
|
23
|
+
function s(e) {
|
|
24
|
+
return e instanceof Error ? `${e.name}("${e.message}")` : typeof e == "symbol" ? e.toString() : typeof e == "string" ? `String("${e}")` : typeof e == "number" ? `Number(${e})` : typeof e == "bigint" ? `BigInt(${e})` : e instanceof Array ? `Array(${JSON.stringify([...e])})` : e instanceof Set ? `Set(${JSON.stringify([...e])})` : Object.getPrototypeOf(e) === Object.prototype ? `Object(${JSON.stringify(e)})` : `Unknown(${typeof e})`;
|
|
25
|
+
}
|
|
26
|
+
function c(e) {
|
|
27
|
+
let t = o(s(e));
|
|
28
|
+
console.error(t);
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/utils/propsAreEqual.ts
|
|
32
|
+
function l(e, n) {
|
|
33
|
+
return t(e, n).length === 0;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/utils/removeP5CanvasInstance.ts
|
|
37
|
+
function u(e) {
|
|
38
|
+
e.current?.remove(), e.current = null;
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/utils/updateP5CanvasInstance.ts
|
|
42
|
+
function d(e, t, n) {
|
|
43
|
+
return t.current === null ? null : (u(e), r(n, t.current));
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { n as CanvasContainerClassName, r as createP5CanvasInstance, c as logErrorBoundaryError, e as p5, l as propsAreEqual, u as removeP5CanvasInstance, d as updateP5CanvasInstance };
|
package/package.json
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@p5-wrapper/common",
|
|
3
|
+
"description": "Common types and utilities for use across p5 wrapper libraries.",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"packageManager": "pnpm@12.3.4",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=24.20.0"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/P5-wrapper/common",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"files": [
|
|
13
|
+
"README.md",
|
|
14
|
+
"dist/*"
|
|
15
|
+
],
|
|
16
|
+
"types": "./dist/main.d.ts",
|
|
17
|
+
"main": "./dist/main.cjs",
|
|
18
|
+
"module": "./dist/main.mjs",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/main.d.ts",
|
|
22
|
+
"import": "./dist/main.mjs",
|
|
23
|
+
"require": "./dist/main.cjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "rimraf dist && pnpm build:library",
|
|
28
|
+
"build:library": "tsc --noEmit && vite build --config config/vite/vite.config.ts --mode lib",
|
|
29
|
+
"format": "pnpm prettier --write .",
|
|
30
|
+
"format:check": "pnpm prettier --check .",
|
|
31
|
+
"integrate": "pnpm format:check && pnpm lint && pnpm test && pnpm build",
|
|
32
|
+
"lint": "eslint --config config/eslint/eslint.config.ts",
|
|
33
|
+
"lint:fix": "pnpm lint --fix",
|
|
34
|
+
"prettier": "prettier --config config/prettier/prettier.json --ignore-path .gitignore --ignore-path config/prettier/.prettierignore",
|
|
35
|
+
"test": "vitest run --silent --config config/vite/vite.config.ts",
|
|
36
|
+
"test:coverage": "vitest run --silent --coverage --config config/vite/vite.config.ts",
|
|
37
|
+
"test:watch": "vitest watch --config config/vite/vite.config.ts"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"p5",
|
|
41
|
+
"processing",
|
|
42
|
+
"typescript",
|
|
43
|
+
"shared",
|
|
44
|
+
"contracts"
|
|
45
|
+
],
|
|
46
|
+
"author": {
|
|
47
|
+
"name": "James Robb",
|
|
48
|
+
"url": "https://github.com/jamesrweb",
|
|
49
|
+
"email": "47126579+jamesrweb@users.noreply.github.com"
|
|
50
|
+
},
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "git+https://github.com/P5-wrapper/common.git"
|
|
54
|
+
},
|
|
55
|
+
"bugs": {
|
|
56
|
+
"url": "https://github.com/P5-wrapper/common/issues"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"microdiff": "^1.6.0"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"p5": ">= 2.0.0"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@eslint/compat": "^2.1.1",
|
|
66
|
+
"@eslint/config-helpers": "^0.7.0",
|
|
67
|
+
"@eslint/js": "^10.0.1",
|
|
68
|
+
"@microsoft/api-extractor": "^7.59.0",
|
|
69
|
+
"@trivago/prettier-plugin-sort-imports": "^6.0.2",
|
|
70
|
+
"@types/node": "^26.4.1",
|
|
71
|
+
"@vitest/coverage-v8": "^5.0.0",
|
|
72
|
+
"eslint": "^10.10.0",
|
|
73
|
+
"happy-dom": "^20.14.0",
|
|
74
|
+
"jiti": "^2.7.0",
|
|
75
|
+
"p5": "^2.3.2",
|
|
76
|
+
"prettier": "^3.9.6",
|
|
77
|
+
"rimraf": "^6.1.3",
|
|
78
|
+
"typescript": "6.0.3",
|
|
79
|
+
"typescript-eslint": "^8.69.0",
|
|
80
|
+
"vite": "^8.2.2",
|
|
81
|
+
"vite-plugin-dts": "^5.1.0",
|
|
82
|
+
"vitest": "^5.0.0",
|
|
83
|
+
"vitest-canvas-mock": "^1.1.5"
|
|
84
|
+
}
|
|
85
|
+
}
|