@cjean-fr/jittergrid 0.0.0-stage → 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Christophe Jean
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 CHANGED
@@ -1,3 +1,19 @@
1
- # Temporary Holding Version
1
+ # @cjean-fr/jittergrid
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Seeded triangulation of a jittered grid. The same options always give the
4
+ same pattern.
5
+
6
+ ```ts
7
+ import { generateTiles, generateTriangulation } from "@cjean-fr/jittergrid";
8
+
9
+ const options = { width: 900, height: 300, cellSize: 60, variance: 0.8, seed: 188 };
10
+
11
+ generateTriangulation(options); // "data:image/svg+xml,..." for a CSS background
12
+ generateTiles(options); // { points, shades }, to redraw the pattern yourself
13
+ ```
14
+
15
+ `generateTriangulation` groups the triangles by fill into one path each, in
16
+ relative coordinates. `generateTiles` returns the grid points and one shade per
17
+ triangle, in the order described in its doc comment.
18
+
19
+ Thanks to [Trianglify](https://trianglify.io/) for the inspiration.
@@ -0,0 +1,31 @@
1
+ interface Point {
2
+ x: number;
3
+ y: number;
4
+ }
5
+ interface TrianglifyOptions {
6
+ width?: number;
7
+ height?: number;
8
+ cellSize?: number;
9
+ variance?: number;
10
+ seed?: number;
11
+ }
12
+ /**
13
+ * Generates a jittered grid triangulation as an SVG Data URI
14
+ * @param options
15
+ * @returns
16
+ */
17
+ declare function generateTriangulation(options?: TrianglifyOptions): string;
18
+ /**
19
+ * The data behind `generateTriangulation`, in the SVG's own coordinates,
20
+ * for redrawing it client side: the jittered grid, where each cell (j, i)
21
+ * holds the triangles (j,i)(j,i+1)(j+1,i) and (j,i+1)(j+1,i+1)(j+1,i), and
22
+ * one shade per triangle in that order: white alpha when positive, black
23
+ * alpha when negative, out of 255.
24
+ */
25
+ declare function generateTiles(options?: TrianglifyOptions): {
26
+ points: Point[][];
27
+ shades: number[];
28
+ };
29
+
30
+ export { generateTiles, generateTriangulation };
31
+ export type { Point, TrianglifyOptions };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ var p=Object.defineProperty;var g=(n,e)=>p(n,"name",{value:e,configurable:!0});class f{static{g(this,"PRNG")}seed;constructor(e){this.seed=(Math.trunc(e)%2147483647+2147483647)%2147483647||1}next(){return this.seed=this.seed*16807%2147483647,(this.seed-1)/2147483646}}function y(n={}){const{width:e=900,height:t=300,cellSize:o=50,variance:a=.75,seed:l=1}=n,s=new f(l),r=x(e,t,o,a,s),d=m(r,s),i=M(e,t,d);return`data:image/svg+xml,${encodeURIComponent(i).replace(/%20/g," ").replace(/%3D/g,"=").replace(/%3A/g,":").replace(/%2F/g,"/").replace(/%22/g,"'")}`}g(y,"generateTriangulation");function $(n={}){const{width:e=900,height:t=300,cellSize:o=50,variance:a=.75,seed:l=1}=n,s=new f(l),r=x(e,t,o,a,s),d=2*(r.length-1)*((r[0]?.length??1)-1),i=Array.from({length:d},()=>{const c=s.next(),h=Math.round(c*5)*5;return c>.5?-h:h});return{points:r,shades:i}}g($,"generateTiles");function x(n,e,t,o,a){const l=[],s=Math.ceil(n/t)+2,r=Math.ceil(e/t)+2;for(let d=0;d<r;d++){const i=[];for(let c=0;c<s;c++){const h=Math.round((c-.5)*t+(a.next()-.5)*t*o),u=Math.round((d-.5)*t+(a.next()-.5)*t*o);i.push({x:h,y:u})}l.push(i)}return l}g(x,"generatePoints");function v(n){const e=n.next(),t=e>.5?"#000000":"#ffffff",o=(Math.round(e*5)*5).toString(16).padStart(2,"0");return t+o}g(v,"getRandomFillColor");function w(n,e){const[t,o,a]=n,l=t.x-e.x,s=t.y-e.y,r=o.x-t.x,d=o.y-t.y,i=a.x-o.x,c=a.y-o.y;return`m${l} ${s} ${r} ${d} ${i} ${c}`.replace(/ -/g,"-")}g(w,"formatRelativeTrianglePath");function m(n,e){const t={},o={},a=n.length,l=n[0]?.length??0;for(let s=0;s<a-1;s++)for(let r=0;r<l-1;r++)[[n[s][r],n[s][r+1],n[s+1][r]],[n[s][r+1],n[s+1][r+1],n[s+1][r]]].forEach(i=>{const c=v(e);t[c]||(t[c]="",o[c]={x:0,y:0});const h=o[c],u=w(i,h);t[c]+=u,o[c]=i[2]});return t}g(m,"generateTriangleGroups");function M(n,e,t){let o="";for(const[a,l]of Object.entries(t))o+=`<path fill="${a}" d="${l}"/>`;return`<svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${e}" viewBox="0 0 ${n} ${e}" preserveAspectRatio="xMidYMid slice">${o}</svg>`}g(M,"buildSvgData");export{$ as generateTiles,y as generateTriangulation};
package/package.json CHANGED
@@ -1,6 +1,44 @@
1
1
  {
2
2
  "name": "@cjean-fr/jittergrid",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Seeded jittered-grid triangulation, as a compact SVG data URI or as raw tile data.",
5
+ "author": "Christophe Jean",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/cjean-fr/atelier.git",
10
+ "directory": "packages/jittergrid"
11
+ },
12
+ "sideEffects": false,
13
+ "type": "module",
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "engines": {
17
+ "node": ">=22.0.0"
18
+ },
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js"
23
+ }
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "scripts": {
29
+ "build": "pkgroll --minify",
30
+ "check": "tsc --noEmit",
31
+ "format": "prettier --write \"**/*.{ts,tsx,json,md}\"",
32
+ "test": "bun test"
33
+ },
34
+ "devDependencies": {
35
+ "@types/bun": "^1.4.4",
36
+ "pkgroll": "^2.29.0",
37
+ "typescript": "^6.0.3"
38
+ },
39
+ "files": [
40
+ "dist",
41
+ "README.md",
42
+ "LICENSE"
43
+ ]
44
+ }