@margoengine/pixel 0.1.0 → 1.0.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.
@@ -1,4 +1,4 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
3
 
4
4
  import { n as e, r as t, t as n } from "./errors-CDgOgzCd.js";
@@ -29,7 +29,7 @@ var s = {
29
29
  srcFactor: "one",
30
30
  dstFactor: "one-minus-src-alpha"
31
31
  }
32
- }, c = class {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
32
+ }, c = class {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
33
33
  #e;
34
34
  #t;
35
35
  #n;
package/dist/crt.js CHANGED
@@ -1,6 +1,6 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
- const i=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
3
+ const i=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
4
  import { n as e } from "./errors-CDgOgzCd.js";
5
5
  import { n as t, r as n, t as r } from "./blit-DyxX_nQq.js";
6
6
  import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
@@ -75,7 +75,7 @@ return vec4f(min(rgb,vec3f(a)),a);
75
75
  constructor(e) {
76
76
  super(e, "CRT", a, 80, `crt-${++o}`), this.curvature = e.curvature ?? .08, this.scanlines = e.scanlines ?? .5, this.mask = e.mask ?? .2, this.glow = e.glow ?? .25, this.brightness = e.brightness ?? 1.2, this.colorBleed = e.colorBleed ?? 0, this.chromaticOffset = e.chromaticOffset ?? 0, this.redOffset = e.redOffset ?? 0, this.greenOffset = e.greenOffset ?? 0, this.blueOffset = e.blueOffset ?? 0, this.#e();
77
77
  }
78
- static attach(e, n) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
78
+ static attach(e, n) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
79
79
  let r = new t(n);
80
80
  return i(e).use(r), r;
81
81
  }
package/dist/follow.js CHANGED
@@ -1,6 +1,6 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
- const i=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
3
+ const i=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
4
  import { n as e, t } from "./errors-CDgOgzCd.js";
5
5
  import { n, t as r } from "./blit-DyxX_nQq.js";
6
6
  import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
@@ -14,7 +14,7 @@ ${n}
14
14
  `, o = (t, n, r = -Infinity, i = Infinity) => {
15
15
  if (!Number.isFinite(t) || t < r || t > i) throw e(`PixelFollow ${n} must be finite in [${r}, ${i}], got ${t}`, "pixel-options");
16
16
  return t;
17
- }, s = (e) => e.map((e) => o(e, "color", 0, 1)), c = (e, t, n) => Math.max(t, Math.min(n, e)), l = 0, u = class n extends r {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
17
+ }, s = (e) => e.map((e) => o(e, "color", 0, 1)), c = (e, t, n) => Math.max(t, Math.min(n, e)), l = 0, u = class n extends r {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
18
18
  #e;
19
19
  #t;
20
20
  #n;
@@ -41,7 +41,7 @@ ${n}
41
41
  }, "PixelFollow", a, 32, `pixel-follow-${++l}`), !t.camera) throw e("PixelFollow needs a camera", "pixel-options");
42
42
  this.camera = t.camera, this.target = t.target, this.lerp = t.lerp ?? 1, this.deadZone = t.deadZone ?? [0, 0], this.offset = t.offset ?? [0, 0], this.bounds = t.bounds, this.#e = [this.camera.x, this.camera.y], this.#t = [...this.#e], this.#s = n, this.update(0);
43
43
  }
44
- static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
44
+ static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
45
45
  let r = new n(t);
46
46
  return i(e).use(r), r;
47
47
  }
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
- const a=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
3
+ const a=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
4
  import { n as e, r as t, t as n } from "./errors-CDgOgzCd.js";
5
5
  import { n as r, t as i } from "./view-rect-sVPGRhlO.js";
6
6
  import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
@@ -163,7 +163,7 @@ var o = 1e-6, s = (t, n) => {
163
163
  release(e) {
164
164
  e && this.made?.destroy(), this.made = this.group = void 0;
165
165
  }
166
- }, g = class o {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
166
+ }, g = class o {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
167
167
  constructor(n) {
168
168
  if (this.list = [], this.added = 0, this.disposed = !1, this.pipelines = /* @__PURE__ */ new Map(), this.offsets = /* @__PURE__ */ new Uint32Array(1), this.next = new Float32Array(p / 4), this.scroll = {
169
169
  x: 0,
@@ -179,7 +179,7 @@ var o = 1e-6, s = (t, n) => {
179
179
  if (!Number.isFinite(a)) throw e("Invalid pixel order", "pixel-options");
180
180
  this.camera = n.camera instanceof l ? n.camera : new l(n.camera), this.order = a, this.layerMask = r(n.layers ?? 1, "LayerCompositor layers"), this.name = n.name ?? `pixel-${++m}`;
181
181
  }
182
- static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
182
+ static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
183
183
  let n = new o(t);
184
184
  return a(e).use(n), n;
185
185
  }
package/dist/palette.js CHANGED
@@ -1,6 +1,6 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
- const i=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
3
+ const i=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
4
  import { n as e, r as t, t as n } from "./errors-CDgOgzCd.js";
5
5
  import { t as r } from "./texture-option-3VFmNske.js";
6
6
  import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
@@ -163,7 +163,7 @@ function b(e, t, n, r, i = "oklab", a, o = .125) {
163
163
  r < p && (p = r, f = t);
164
164
  }), f;
165
165
  }
166
- var x = "\nstruct Settings {\n count: u32,\n side: u32,\n oklab: u32,\n straight: u32,\n spread: f32\n}\n@group(0) @binding(0) var<uniform> settings: Settings;\n@group(0) @binding(1) var image: texture_2d<f32>;\n@group(0) @binding(2) var candidates: texture_2d<f32>;\n@group(0) @binding(3) var shown: texture_2d<f32>;\n@group(0) @binding(4) var pattern: texture_2d<f32>;\n\n@vertex fn vertexMain(@builtin(vertex_index) i: u32) -> @builtin(position) vec4f {\n return vec4f(f32(i & 1u) * 4 - 1, f32(i >> 1u) * 4 - 1, 0, 1);\n}\n\nfn linear(v: f32) -> f32 {\n if (v <= 0.04045) { return v / 12.92; }\n return pow((v + 0.055) / 1.055, 2.4);\n}\n\nfn oklab(c: vec3f) -> vec3f {\n let r = linear(c.r);\n let g = linear(c.g);\n let b = linear(c.b);\n let l = pow(0.4122214708*r + 0.5363325363*g + 0.0514459929*b, 1.0/3.0);\n let m = pow(0.2119034982*r + 0.6806995451*g + 0.1073969566*b, 1.0/3.0);\n let k = pow(0.0883024619*r + 0.2817188376*g + 0.6299787005*b, 1.0/3.0);\n return vec3f(\n 0.2104542553*l + 0.793617785*m - 0.0040720468*k,\n 1.9779984951*l - 2.428592205*m + 0.4505937099*k,\n 0.0259040371*l + 0.7827717662*m - 0.808675766*k\n );\n}\n\n@fragment fn fragmentMain(@builtin(position) p: vec4f) -> @location(0) vec4f {\n let t = vec2i(p.xy);\n if (any(t >= vec2i(textureDimensions(image)))) { return vec4f(0); }\n let source = textureLoad(image, t, 0);\n if (source.a == 0) { return vec4f(0); }\n var c = source.rgb;\n if (settings.straight == 0u) { c /= source.a; }\n if (settings.side > 0u) {\n c += settings.spread * (textureLoad(pattern, vec2u(t) % settings.side, 0).r - 0.5);\n }\n c = clamp(c, vec3f(0), vec3f(1));\n if (settings.oklab == 1u) { c = oklab(c); }\n\n var best = 0u;\n var least = 1e30;\n for (var i = 0u; i < settings.count; i++) {\n let d = c - textureLoad(candidates, vec2u(i, 0u), 0).rgb;\n let e = dot(d, d);\n if (e < least) { least = e; best = i; }\n }\n let color = textureLoad(shown, vec2u(best, 0u), 0).rgb;\n if (settings.straight == 1u) { return vec4f(color, source.a); }\n return vec4f(color * source.a, source.a);\n}", S = 32, C = 0, w = class a {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
166
+ var x = "\nstruct Settings {\n count: u32,\n side: u32,\n oklab: u32,\n straight: u32,\n spread: f32\n}\n@group(0) @binding(0) var<uniform> settings: Settings;\n@group(0) @binding(1) var image: texture_2d<f32>;\n@group(0) @binding(2) var candidates: texture_2d<f32>;\n@group(0) @binding(3) var shown: texture_2d<f32>;\n@group(0) @binding(4) var pattern: texture_2d<f32>;\n\n@vertex fn vertexMain(@builtin(vertex_index) i: u32) -> @builtin(position) vec4f {\n return vec4f(f32(i & 1u) * 4 - 1, f32(i >> 1u) * 4 - 1, 0, 1);\n}\n\nfn linear(v: f32) -> f32 {\n if (v <= 0.04045) { return v / 12.92; }\n return pow((v + 0.055) / 1.055, 2.4);\n}\n\nfn oklab(c: vec3f) -> vec3f {\n let r = linear(c.r);\n let g = linear(c.g);\n let b = linear(c.b);\n let l = pow(0.4122214708*r + 0.5363325363*g + 0.0514459929*b, 1.0/3.0);\n let m = pow(0.2119034982*r + 0.6806995451*g + 0.1073969566*b, 1.0/3.0);\n let k = pow(0.0883024619*r + 0.2817188376*g + 0.6299787005*b, 1.0/3.0);\n return vec3f(\n 0.2104542553*l + 0.793617785*m - 0.0040720468*k,\n 1.9779984951*l - 2.428592205*m + 0.4505937099*k,\n 0.0259040371*l + 0.7827717662*m - 0.808675766*k\n );\n}\n\n@fragment fn fragmentMain(@builtin(position) p: vec4f) -> @location(0) vec4f {\n let t = vec2i(p.xy);\n if (any(t >= vec2i(textureDimensions(image)))) { return vec4f(0); }\n let source = textureLoad(image, t, 0);\n if (source.a == 0) { return vec4f(0); }\n var c = source.rgb;\n if (settings.straight == 0u) { c /= source.a; }\n if (settings.side > 0u) {\n c += settings.spread * (textureLoad(pattern, vec2u(t) % settings.side, 0).r - 0.5);\n }\n c = clamp(c, vec3f(0), vec3f(1));\n if (settings.oklab == 1u) { c = oklab(c); }\n\n var best = 0u;\n var least = 1e30;\n for (var i = 0u; i < settings.count; i++) {\n let d = c - textureLoad(candidates, vec2u(i, 0u), 0).rgb;\n let e = dot(d, d);\n if (e < least) { least = e; best = i; }\n }\n let color = textureLoad(shown, vec2u(best, 0u), 0).rgb;\n if (settings.straight == 1u) { return vec4f(color, source.a); }\n return vec4f(color * source.a, source.a);\n}", S = 32, C = 0, w = class a {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
167
167
  #e;
168
168
  #t;
169
169
  #n;
@@ -192,7 +192,7 @@ var x = "\nstruct Settings {\n count: u32,\n side: u32,\n oklab: u32,\n stra
192
192
  if (this.#e = new r(n.source, "PaletteQuantize source", "setSource"), this.#t = new r(n.target, "PaletteQuantize target", "setTarget"), this.#n = i, this.#r = n.distance ?? "oklab", this.#r !== "oklab" && this.#r !== "srgb") throw e("Invalid distance: use oklab or srgb", "pixel-palette");
193
193
  this.dither = n.dither ?? "none", this.spread = n.spread ?? .125, this.#i = n.premultiplied === !1, this.name = n.name ?? `palette-${++C}`, this.setPalette(n.palette, n.swap);
194
194
  }
195
- static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
195
+ static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
196
196
  let n = new a(t);
197
197
  return i(e).use(n), n;
198
198
  }
package/dist/render3d.js CHANGED
@@ -1,6 +1,6 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
- const i=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
3
+ const i=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
4
  import { n as e, r as t, t as n } from "./errors-CDgOgzCd.js";
5
5
  import { t as r } from "./texture-option-3VFmNske.js";
6
6
  import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
@@ -118,7 +118,7 @@ fn turned(t:vec2i,n:vec4f)->bool{
118
118
  }
119
119
  if(edge){return settings.color;}
120
120
  return source;
121
- }`, d = 128, f = 0, p = class o {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
121
+ }`, d = 128, f = 0, p = class o {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
122
122
  #e;
123
123
  #t;
124
124
  #n;
@@ -146,7 +146,7 @@ fn turned(t:vec2i,n:vec4f)->bool{
146
146
  if (!Number.isFinite(o) || !Number.isInteger(s) || s < 1) throw e("Invalid Render3D value", "pixel-low-res");
147
147
  this.#e = n.camera, this.width = i, this.height = a, this.#t = new r(n.target, "Render3D target", "setTarget"), this.outline = n.outline ?? {}, this.#n = n.background, this.#r = n.scene, this.#i = n.layers, this.#a = s, this.#o = o, this.name = n.name ?? `render3d-${++f}`;
148
148
  }
149
- static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
149
+ static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
150
150
  let n = new o(t);
151
151
  return (t.scene ?? i(e)).use(n), n;
152
152
  }
package/dist/scale.js CHANGED
@@ -1,6 +1,6 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
- const i=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
3
+ const i=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
4
  import { n as e } from "./errors-CDgOgzCd.js";
5
5
  import { n as t, r as n, t as r } from "./blit-DyxX_nQq.js";
6
6
  import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
@@ -82,7 +82,7 @@ return mix(top,bottom,k.y);
82
82
  constructor(e) {
83
83
  super(e, "PixelScale", a, 32, `pixel-scale-${++o}`), this.filter = e.filter ?? "sharp-bilinear", c(this.filter);
84
84
  }
85
- static attach(t, n) {__margoAssertCore(t,__margoCoreRequirement("0.1.0",import.meta.url));
85
+ static attach(t, n) {__margoAssertCore(t,__margoCoreRequirement("1.0.0",import.meta.url));
86
86
  let r = new e(n);
87
87
  return i(t).use(r), r;
88
88
  }
package/package.json CHANGED
@@ -1,74 +1,71 @@
1
- {
2
- "name": "@margoengine/pixel",
3
- "version": "0.1.0",
4
- "description": "Pixel art rendering: a pixel camera with integer zoom and parallax, and a layer compositor that scales low-res layers by whole numbers and turns them with every output pixel one source pixel.",
5
- "keywords": [
6
- "margoengine",
7
- "webgpu",
8
- "2d",
9
- "pixel-art",
10
- "parallax"
11
- ],
12
- "homepage": "https://margoengine.com",
13
- "bugs": {
14
- "url": "https://github.com/scottcampbelldata/margoengine/issues"
15
- },
16
- "repository": {
17
- "type": "git",
18
- "url": "git+https://github.com/scottcampbelldata/margoengine.git",
19
- "directory": "packages/pixel"
20
- },
21
- "license": "Apache-2.0",
22
- "author": "Scott Campbell",
23
- "type": "module",
24
- "sideEffects": false,
25
- "exports": {
26
- ".": {
27
- "types": "./dist/index.d.ts",
28
- "import": "./dist/index.js"
29
- },
30
- "./palette": {
31
- "types": "./dist/palette.d.ts",
32
- "import": "./dist/palette.js"
33
- },
34
- "./render3d": {
35
- "types": "./dist/render3d.d.ts",
36
- "import": "./dist/render3d.js"
37
- },
38
- "./scale": {
39
- "types": "./dist/scale.d.ts",
40
- "import": "./dist/scale.js"
41
- },
42
- "./follow": {
43
- "types": "./dist/follow.d.ts",
44
- "import": "./dist/follow.js"
45
- },
46
- "./crt": {
47
- "types": "./dist/crt.d.ts",
48
- "import": "./dist/crt.js"
49
- }
50
- },
51
- "files": [
52
- "dist",
53
- "LICENSE",
54
- "NOTICE"
55
- ],
56
- "publishConfig": {
57
- "access": "public"
58
- },
59
- "peerDependencies": {
60
- "@margoengine/core": "^0.1.0"
61
- },
62
- "dependencies": {
63
- "@margoengine/math": "^0.1.0"
64
- },
65
- "devDependencies": {
66
- "@margoengine/cameras": "^0.1.0"
67
- },
68
- "scripts": {
69
- "build": "node ../../scripts/build-optional.js pixel",
70
- "test": "npm run build && node --test tests/*.test.js",
71
- "test:gpu": "cd ../.. && node packages/pixel/tests/browser-check.mjs && node packages/pixel/tests/palette-check.mjs && node packages/pixel/tests/render3d-check.mjs && node packages/pixel/tests/scale-check.mjs && node packages/pixel/tests/crt-check.mjs && node packages/pixel/tests/follow-check.mjs && node packages/pixel/tests/pixel-restore-check.mjs",
72
- "prepack": "npm run build"
73
- }
74
- }
1
+ {
2
+ "name": "@margoengine/pixel",
3
+ "version": "1.0.0",
4
+ "description": "Pixel art rendering: a pixel camera with integer zoom and parallax, and a layer compositor that scales low-res layers by whole numbers and turns them with every output pixel one source pixel.",
5
+ "keywords": [
6
+ "margoengine",
7
+ "webgpu",
8
+ "2d",
9
+ "pixel-art",
10
+ "parallax"
11
+ ],
12
+ "homepage": "https://margoengine.com",
13
+ "bugs": {
14
+ "url": "https://github.com/scottcampbelldata/margoengine/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/scottcampbelldata/margoengine.git",
19
+ "directory": "packages/pixel"
20
+ },
21
+ "license": "Apache-2.0",
22
+ "author": "Scott Campbell",
23
+ "type": "module",
24
+ "sideEffects": false,
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js"
29
+ },
30
+ "./palette": {
31
+ "types": "./dist/palette.d.ts",
32
+ "import": "./dist/palette.js"
33
+ },
34
+ "./render3d": {
35
+ "types": "./dist/render3d.d.ts",
36
+ "import": "./dist/render3d.js"
37
+ },
38
+ "./scale": {
39
+ "types": "./dist/scale.d.ts",
40
+ "import": "./dist/scale.js"
41
+ },
42
+ "./follow": {"types": "./dist/follow.d.ts", "import": "./dist/follow.js"},
43
+ "./crt": {
44
+ "types": "./dist/crt.d.ts",
45
+ "import": "./dist/crt.js"
46
+ }
47
+ },
48
+ "files": [
49
+ "dist",
50
+ "LICENSE",
51
+ "NOTICE"
52
+ ],
53
+ "publishConfig": {
54
+ "access": "public"
55
+ },
56
+ "peerDependencies": {
57
+ "@margoengine/core": "^1.0.0"
58
+ },
59
+ "dependencies": {
60
+ "@margoengine/math": "^1.0.0"
61
+ },
62
+ "devDependencies": {
63
+ "@margoengine/cameras": "^1.0.0"
64
+ },
65
+ "scripts": {
66
+ "build": "node ../../scripts/build-optional.js pixel",
67
+ "test": "npm run build && node --test tests/*.test.js",
68
+ "test:gpu": "cd ../.. && node packages/pixel/tests/browser-check.mjs && node packages/pixel/tests/palette-check.mjs && node packages/pixel/tests/render3d-check.mjs && node packages/pixel/tests/scale-check.mjs && node packages/pixel/tests/crt-check.mjs && node packages/pixel/tests/follow-check.mjs && node packages/pixel/tests/pixel-restore-check.mjs",
69
+ "prepack": "npm run build"
70
+ }
71
+ }