@johnfmorton/some-shade 1.1.2 → 1.2.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/CHANGELOG.md +11 -0
- package/dist/index.d.ts +1 -4
- package/dist/some-shade.cjs.js +13 -15
- package/dist/some-shade.es.js +186 -196
- package/dist/some-shade.umd.js +13 -15
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [Unreleased]
|
|
4
|
+
|
|
5
|
+
## [1.2.0] - 2026-04-16
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- Render at display size instead of full natural resolution — a 4000 px image shown at 800 CSS px now renders at ≤1600 px (at 2× DPR) instead of 8000 px
|
|
10
|
+
- Replace PNG blob round-trip with direct canvas copy (`drawImage`) — eliminates PNG encoding and decoding overhead entirely
|
|
11
|
+
|
|
3
12
|
## 1.1.0 - 2026-03-01
|
|
4
13
|
|
|
5
14
|
- Add `reference-width` attribute (default 1024) — normalizes `u_gridSize` and `u_dotRadius` by source image width so the dot pattern looks visually consistent regardless of image resolution
|
|
@@ -69,3 +78,5 @@
|
|
|
69
78
|
- WebGL fallback to plain `<img>` when unavailable
|
|
70
79
|
- React playground with live controls and code export
|
|
71
80
|
- GitHub Pages deployment for playground
|
|
81
|
+
|
|
82
|
+
[1.2.0]: https://github.com/johnfmorton/some-shade-web-component/releases/tag/v1.2.0
|
package/dist/index.d.ts
CHANGED
|
@@ -45,8 +45,7 @@ export declare class SomeShadeImage extends LitElement {
|
|
|
45
45
|
blendMode: number;
|
|
46
46
|
referenceWidth: number;
|
|
47
47
|
private _webglAvailable;
|
|
48
|
-
private
|
|
49
|
-
private _snapshotLoaded;
|
|
48
|
+
private _snapshotReady;
|
|
50
49
|
private _image;
|
|
51
50
|
private _observer;
|
|
52
51
|
private _visible;
|
|
@@ -58,11 +57,9 @@ export declare class SomeShadeImage extends LitElement {
|
|
|
58
57
|
private _loadImage;
|
|
59
58
|
private _scheduleRender;
|
|
60
59
|
private _renderEffect;
|
|
61
|
-
private _onSnapshotLoad;
|
|
62
60
|
/** Hide the rendered snapshot momentarily, then fade it back in.
|
|
63
61
|
* Useful for previewing the loading-blur transition. */
|
|
64
62
|
replayTransition(delay?: number): void;
|
|
65
|
-
private _revokeSnapshot;
|
|
66
63
|
private _getUniformValues;
|
|
67
64
|
private _parseHexColor;
|
|
68
65
|
}
|
package/dist/some-shade.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("lit"),l=require("lit/decorators.js");function M(e){return e.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0})}function K(e,o,n){const i=e.createShader(o);if(!i)throw new Error("Failed to create shader");if(e.shaderSource(i,n),e.compileShader(i),!e.getShaderParameter(i,e.COMPILE_STATUS)){const t=e.getShaderInfoLog(i);throw e.deleteShader(i),new Error(`Shader compile error: ${t}`)}return i}function U(e,o,n){const i=K(e,e.VERTEX_SHADER,o),t=K(e,e.FRAGMENT_SHADER,n),r=e.createProgram();if(!r)throw new Error("Failed to create program");if(e.attachShader(r,i),e.attachShader(r,t),e.linkProgram(r),!e.getProgramParameter(r,e.LINK_STATUS)){const f=e.getProgramInfoLog(r);throw e.deleteProgram(r),new Error(`Program link error: ${f}`)}e.deleteShader(i),e.deleteShader(t);const d=new Map,h=e.getProgramParameter(r,e.ACTIVE_ATTRIBUTES);for(let f=0;f<h;f++){const c=e.getActiveAttrib(r,f);c&&d.set(c.name,e.getAttribLocation(r,c.name))}const m=new Map,s=e.getProgramParameter(r,e.ACTIVE_UNIFORMS);for(let f=0;f<s;f++){const c=e.getActiveUniform(r,f);if(c){const p=e.getUniformLocation(r,c.name);p&&m.set(c.name,p)}}return{program:r,attribLocations:d,uniformLocations:m}}function z(e,o,n){for(const[i,t]of Object.entries(n)){const r=o.uniformLocations.get(i);if(r){if(typeof t=="number")e.uniform1f(r,t);else if(Array.isArray(t))switch(t.length){case 2:e.uniform2fv(r,t);break;case 3:e.uniform3fv(r,t);break;case 4:e.uniform4fv(r,t);break}}}}function P(e,o){const n=e.createTexture();if(!n)throw new Error("Failed to create texture");return e.bindTexture(e.TEXTURE_2D,n),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,o),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),{texture:n,width:o.naturalWidth,height:o.naturalHeight}}function I(e,o){const n=new Float32Array([-1,-1,0,1,1,-1,1,1,-1,1,0,0,1,1,1,0]),i=e.createBuffer();if(!i)throw new Error("Failed to create buffer");e.bindBuffer(e.ARRAY_BUFFER,i),e.bufferData(e.ARRAY_BUFFER,n,e.STATIC_DRAW);const t=4*Float32Array.BYTES_PER_ELEMENT,r=o.attribLocations.get("a_position");r!==void 0&&r!==-1&&(e.enableVertexAttribArray(r),e.vertexAttribPointer(r,2,e.FLOAT,!1,t,0));const d=o.attribLocations.get("a_texCoord");return d!==void 0&&d!==-1&&(e.enableVertexAttribArray(d),e.vertexAttribPointer(d,2,e.FLOAT,!1,t,2*Float32Array.BYTES_PER_ELEMENT)),i}function L(e){e.drawArrays(e.TRIANGLE_STRIP,0,4)}const V=`precision mediump float;
|
|
2
2
|
|
|
3
3
|
varying vec2 v_texCoord;
|
|
4
4
|
|
|
@@ -84,7 +84,7 @@ void main() {
|
|
|
84
84
|
|
|
85
85
|
gl_FragColor = vec4(outR, outG, outB, texture2D(u_image, v_texCoord).a);
|
|
86
86
|
}
|
|
87
|
-
`,
|
|
87
|
+
`,w=`attribute vec2 a_position;
|
|
88
88
|
attribute vec2 a_texCoord;
|
|
89
89
|
varying vec2 v_texCoord;
|
|
90
90
|
|
|
@@ -92,7 +92,7 @@ void main() {
|
|
|
92
92
|
gl_Position = vec4(a_position, 0.0, 1.0);
|
|
93
93
|
v_texCoord = a_texCoord;
|
|
94
94
|
}
|
|
95
|
-
`,
|
|
95
|
+
`,N={name:"halftone-cmyk",fragmentShader:V,vertexShader:w,uniforms:[{name:"u_dotRadius",type:"float",default:4,attribute:"dot-radius"},{name:"u_gridSize",type:"float",default:8,attribute:"grid-size"},{name:"u_angleC",type:"float",default:15,attribute:"angle-c"},{name:"u_angleM",type:"float",default:75,attribute:"angle-m"},{name:"u_angleY",type:"float",default:0,attribute:"angle-y"},{name:"u_angleK",type:"float",default:45,attribute:"angle-k"},{name:"u_showC",type:"float",default:1,attribute:"show-c"},{name:"u_showM",type:"float",default:1,attribute:"show-m"},{name:"u_showY",type:"float",default:1,attribute:"show-y"},{name:"u_showK",type:"float",default:1,attribute:"show-k"},{name:"u_intensityK",type:"float",default:1,attribute:"intensity-k"}]},W=`precision mediump float;
|
|
96
96
|
|
|
97
97
|
varying vec2 v_texCoord;
|
|
98
98
|
|
|
@@ -134,7 +134,7 @@ void main() {
|
|
|
134
134
|
|
|
135
135
|
gl_FragColor = vec4(result, color.a);
|
|
136
136
|
}
|
|
137
|
-
`,
|
|
137
|
+
`,O={name:"halftone-duotone",fragmentShader:W,vertexShader:w,uniforms:[{name:"u_dotRadius",type:"float",default:4,attribute:"dot-radius"},{name:"u_gridSize",type:"float",default:8,attribute:"grid-size"},{name:"u_duotoneColor",type:"vec3",default:[0,.6,.8],attribute:"duotone-color"},{name:"u_angle",type:"float",default:0,attribute:"angle"}]},F=`precision mediump float;
|
|
138
138
|
|
|
139
139
|
varying vec2 v_texCoord;
|
|
140
140
|
|
|
@@ -190,7 +190,7 @@ void main() {
|
|
|
190
190
|
|
|
191
191
|
gl_FragColor = vec4(result, 1.0);
|
|
192
192
|
}
|
|
193
|
-
`,
|
|
193
|
+
`,Y={name:"dot-grid",fragmentShader:F,vertexShader:w,uniforms:[{name:"u_dotRadius",type:"float",default:4,attribute:"dot-radius"},{name:"u_gridSize",type:"float",default:8,attribute:"grid-size"},{name:"u_dotOffset",type:"vec2",default:[.5,.5],attribute:"dot-offset"},{name:"u_bgColor",type:"vec3",default:[1,1,1],attribute:"bg-color"},{name:"u_angle",type:"float",default:0,attribute:"angle"}]},B=`precision mediump float;
|
|
194
194
|
|
|
195
195
|
varying vec2 v_texCoord;
|
|
196
196
|
|
|
@@ -273,14 +273,12 @@ void main() {
|
|
|
273
273
|
|
|
274
274
|
gl_FragColor = vec4(clamp(result, 0.0, 1.0), color.a);
|
|
275
275
|
}
|
|
276
|
-
`,
|
|
276
|
+
`,X={name:"technicolor-2strip",fragmentShader:B,vertexShader:w,uniforms:[{name:"u_dotRadius",type:"float",default:7,attribute:"dot-radius"},{name:"u_gridSize",type:"float",default:10,attribute:"grid-size"},{name:"u_angleWarm",type:"float",default:15,attribute:"angle-warm"},{name:"u_angleCool",type:"float",default:75,attribute:"angle-cool"},{name:"u_angleK",type:"float",default:45,attribute:"angle-k"},{name:"u_showWarm",type:"float",default:1,attribute:"show-warm"},{name:"u_showCool",type:"float",default:1,attribute:"show-cool"},{name:"u_showK",type:"float",default:1,attribute:"show-k"},{name:"u_warmColor",type:"vec3",default:[.85,.25,.06],attribute:"warm-color"},{name:"u_coolColor",type:"vec3",default:[.05,.65,.6],attribute:"cool-color"},{name:"u_blendMode",type:"float",default:1,attribute:"blend-mode"},{name:"u_intensityK",type:"float",default:1,attribute:"intensity-k"}]},R=new Map;function _(e){R.set(e.name,e)}function D(e){return R.get(e)}function G(){return Array.from(R.keys())}_(N);_(O);_(Y);_(X);var H=Object.defineProperty,u=(e,o,n,i)=>{for(var t=void 0,r=e.length-1,d;r>=0;r--)(d=e[r])&&(t=d(o,n,t)||t);return t&&H(o,n,t),t};const $=2;let k=Promise.resolve();function C(e){const o=k.then(e,e);return k=o,o}const q=new Set(["effect","dotRadius","gridSize","angleC","angleM","angleY","angleK","showC","showM","showY","showK","intensityK","duotoneColor","angle","dotOffsetX","dotOffsetY","bgColor","angleWarm","angleCool","showWarm","showCool","warmColor","coolColor","blendMode","referenceWidth"]),S=class S extends y.LitElement{constructor(){super(...arguments),this.src="",this.effect="halftone-cmyk",this.dotRadius=4,this.gridSize=8,this.angleC=15,this.angleM=75,this.angleY=0,this.angleK=45,this.showC=1,this.showM=1,this.showY=1,this.showK=1,this.intensityK=1,this.duotoneColor="#0099cc",this.angle=0,this.dotOffsetX=.5,this.dotOffsetY=.5,this.bgColor="#ffffff",this.angleWarm=15,this.angleCool=75,this.showWarm=1,this.showCool=1,this.warmColor="#d94010",this.coolColor="#0da699",this.blendMode=1,this.referenceWidth=1024,this._webglAvailable=!0,this._snapshotReady=!1,this._image=null,this._observer=null,this._visible=!1,this._needsRender=!1}render(){return this._webglAvailable?y.html`
|
|
277
277
|
<img class="base" src=${this.src} alt="" />
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
alt="" />`:""}
|
|
283
|
-
`:p.html`<img src=${this.src} alt="" />`}connectedCallback(){super.connectedCallback(),this._observer=new IntersectionObserver(o=>{var t;const a=this._visible;this._visible=((t=o[0])==null?void 0:t.isIntersecting)??!1,this._visible&&!a&&(this._needsRender||this._image&&!this._snapshotUrl)&&(this._needsRender=!1,w(()=>this._renderEffect()))},{rootMargin:"200px"}),this._observer.observe(this)}updated(o){if(o.has("src")&&this.src){this._loadImage(this.src);return}if(!this._image)return;[...o.keys()].some(t=>G.has(t))&&this._scheduleRender()}disconnectedCallback(){var o;super.disconnectedCallback(),(o=this._observer)==null||o.disconnect(),this._revokeSnapshot()}_loadImage(o){const a=new Image;a.crossOrigin="anonymous",a.onload=()=>{this._image=a,this._scheduleRender()},a.onerror=()=>{console.warn(`[some-shade] Failed to load image: ${o}`)},a.src=o}_scheduleRender(){this._visible?w(()=>this._renderEffect()):(this._needsRender=!0,requestAnimationFrame(()=>{if(this._needsRender&&!this._visible){const o=this.getBoundingClientRect();o.bottom>=0&&o.top<window.innerHeight&&(this._visible=!0,this._needsRender=!1,w(()=>this._renderEffect()))}}))}async _renderEffect(){var g;if(!this._image)return;const o=T(this.effect);if(!o){console.warn(`[some-shade] Unknown effect: ${this.effect}`);return}const a=Math.min(window.devicePixelRatio||1,X),t=this._image.naturalWidth,s=this._image.naturalHeight,n=document.createElement("canvas");n.width=t*a,n.height=s*a;const r=U(n);if(!r){this._webglAvailable=!1;return}try{const c=K(r,o.vertexShader,o.fragmentShader);r.useProgram(c.program);const h=D(r,this._image),d=L(r,c);r.viewport(0,0,n.width,n.height),r.clearColor(0,0,0,0),r.clear(r.COLOR_BUFFER_BIT),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,h.texture);const f=c.uniformLocations.get("u_image");f&&r.uniform1i(f,0),k(r,c,this._getUniformValues(h,a)),r.bindBuffer(r.ARRAY_BUFFER,d);const m=4*Float32Array.BYTES_PER_ELEMENT,b=c.attribLocations.get("a_position");b!==void 0&&b!==-1&&(r.enableVertexAttribArray(b),r.vertexAttribPointer(b,2,r.FLOAT,!1,m,0));const v=c.attribLocations.get("a_texCoord");v!==void 0&&v!==-1&&(r.enableVertexAttribArray(v),r.vertexAttribPointer(v,2,r.FLOAT,!1,m,2*Float32Array.BYTES_PER_ELEMENT)),M(r);const S=await new Promise(A=>n.toBlob(A));r.deleteTexture(h.texture),r.deleteProgram(c.program),r.deleteBuffer(d),S&&(this._snapshotLoaded=!1,this._revokeSnapshot(),this._snapshotUrl=URL.createObjectURL(S))}finally{(g=r.getExtension("WEBGL_lose_context"))==null||g.loseContext()}}_onSnapshotLoad(){this._snapshotLoaded=!0}replayTransition(o=500){this._snapshotUrl&&(this._snapshotLoaded=!1,this.updateComplete.then(()=>{setTimeout(()=>{this._snapshotLoaded=!0},o)}))}_revokeSnapshot(){this._snapshotUrl&&(URL.revokeObjectURL(this._snapshotUrl),this._snapshotUrl="")}_getUniformValues(o,a){const t={};t.u_resolution=[o.width*a,o.height*a];const s=o.width/this.referenceWidth;return t.u_dotRadius=this.dotRadius*s,t.u_gridSize=this.gridSize*s,this.effect==="halftone-cmyk"?(t.u_angleC=this.angleC,t.u_angleM=this.angleM,t.u_angleY=this.angleY,t.u_angleK=this.angleK,t.u_showC=this.showC,t.u_showM=this.showM,t.u_showY=this.showY,t.u_showK=this.showK,t.u_intensityK=this.intensityK):this.effect==="halftone-duotone"?(t.u_duotoneColor=this._parseHexColor(this.duotoneColor),t.u_angle=this.angle):this.effect==="dot-grid"?(t.u_dotOffset=[this.dotOffsetX,this.dotOffsetY],t.u_bgColor=this._parseHexColor(this.bgColor),t.u_angle=this.angle):this.effect==="technicolor-2strip"&&(t.u_angleWarm=this.angleWarm,t.u_angleCool=this.angleCool,t.u_angleK=this.angleK,t.u_showWarm=this.showWarm,t.u_showCool=this.showCool,t.u_showK=this.showK,t.u_warmColor=this._parseHexColor(this.warmColor),t.u_coolColor=this._parseHexColor(this.coolColor),t.u_blendMode=this.blendMode,t.u_intensityK=this.intensityK),t}_parseHexColor(o){const a=o.replace("#",""),t=parseInt(a.substring(0,2),16)/255,s=parseInt(a.substring(2,4),16)/255,n=parseInt(a.substring(4,6),16)/255;return[t,s,n]}};R.styles=p.css`
|
|
278
|
+
<canvas
|
|
279
|
+
class="snapshot${this._snapshotReady?" ready":""}"
|
|
280
|
+
></canvas>
|
|
281
|
+
`:y.html`<img src=${this.src} alt="" />`}connectedCallback(){super.connectedCallback(),this._observer=new IntersectionObserver(o=>{var i;const n=this._visible;this._visible=((i=o[0])==null?void 0:i.isIntersecting)??!1,this._visible&&!n&&(this._needsRender||this._image&&!this._snapshotReady)&&(this._needsRender=!1,C(()=>this._renderEffect()))},{rootMargin:"200px"}),this._observer.observe(this)}updated(o){if(o.has("src")&&this.src){this._loadImage(this.src);return}if(!this._image)return;[...o.keys()].some(i=>q.has(i))&&this._scheduleRender()}disconnectedCallback(){var o;super.disconnectedCallback(),(o=this._observer)==null||o.disconnect()}_loadImage(o){const n=new Image;n.crossOrigin="anonymous",n.onload=()=>{this._image=n,this._scheduleRender()},n.onerror=()=>{console.warn(`[some-shade] Failed to load image: ${o}`)},n.src=o}_scheduleRender(){this._visible?C(()=>this._renderEffect()):(this._needsRender=!0,requestAnimationFrame(()=>{if(this._needsRender&&!this._visible){const o=this.getBoundingClientRect();o.bottom>=0&&o.top<window.innerHeight&&(this._visible=!0,this._needsRender=!1,C(()=>this._renderEffect()))}}))}async _renderEffect(){var f;if(!this._image)return;const o=D(this.effect);if(!o){console.warn(`[some-shade] Unknown effect: ${this.effect}`);return}this._snapshotReady=!1;const n=Math.min(window.devicePixelRatio||1,$),i=this._image.naturalWidth,t=this._image.naturalHeight,r=this.clientWidth||i,d=Math.min(Math.round(r*n),i),h=Math.round(d*(t/i)),m=document.createElement("canvas");m.width=d,m.height=h;const s=M(m);if(!s){this._webglAvailable=!1;return}try{const c=U(s,o.vertexShader,o.fragmentShader);s.useProgram(c.program);const p=P(s,this._image),x=I(s,c);s.viewport(0,0,m.width,m.height),s.clearColor(0,0,0,0),s.clear(s.COLOR_BUFFER_BIT),s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,p.texture);const E=c.uniformLocations.get("u_image");E&&s.uniform1i(E,0),z(s,c,this._getUniformValues(d,h,n)),s.bindBuffer(s.ARRAY_BUFFER,x);const T=4*Float32Array.BYTES_PER_ELEMENT,g=c.attribLocations.get("a_position");g!==void 0&&g!==-1&&(s.enableVertexAttribArray(g),s.vertexAttribPointer(g,2,s.FLOAT,!1,T,0));const b=c.attribLocations.get("a_texCoord");b!==void 0&&b!==-1&&(s.enableVertexAttribArray(b),s.vertexAttribPointer(b,2,s.FLOAT,!1,T,2*Float32Array.BYTES_PER_ELEMENT)),L(s);const v=this.renderRoot.querySelector(".snapshot");if(v){v.width=d,v.height=h;const A=v.getContext("2d");A&&(A.drawImage(m,0,0),this._snapshotReady=!0)}s.deleteTexture(p.texture),s.deleteProgram(c.program),s.deleteBuffer(x)}finally{(f=s.getExtension("WEBGL_lose_context"))==null||f.loseContext()}}replayTransition(o=500){this._snapshotReady&&(this._snapshotReady=!1,this.updateComplete.then(()=>{setTimeout(()=>{this._snapshotReady=!0},o)}))}_getUniformValues(o,n,i){const t={};t.u_resolution=[o,n];const r=o/(this.referenceWidth*i);return t.u_dotRadius=this.dotRadius*r,t.u_gridSize=this.gridSize*r,this.effect==="halftone-cmyk"?(t.u_angleC=this.angleC,t.u_angleM=this.angleM,t.u_angleY=this.angleY,t.u_angleK=this.angleK,t.u_showC=this.showC,t.u_showM=this.showM,t.u_showY=this.showY,t.u_showK=this.showK,t.u_intensityK=this.intensityK):this.effect==="halftone-duotone"?(t.u_duotoneColor=this._parseHexColor(this.duotoneColor),t.u_angle=this.angle):this.effect==="dot-grid"?(t.u_dotOffset=[this.dotOffsetX,this.dotOffsetY],t.u_bgColor=this._parseHexColor(this.bgColor),t.u_angle=this.angle):this.effect==="technicolor-2strip"&&(t.u_angleWarm=this.angleWarm,t.u_angleCool=this.angleCool,t.u_angleK=this.angleK,t.u_showWarm=this.showWarm,t.u_showCool=this.showCool,t.u_showK=this.showK,t.u_warmColor=this._parseHexColor(this.warmColor),t.u_coolColor=this._parseHexColor(this.coolColor),t.u_blendMode=this.blendMode,t.u_intensityK=this.intensityK),t}_parseHexColor(o){const n=o.replace("#",""),i=parseInt(n.substring(0,2),16)/255,t=parseInt(n.substring(2,4),16)/255,r=parseInt(n.substring(4,6),16)/255;return[i,t,r]}};S.styles=y.css`
|
|
284
282
|
:host {
|
|
285
283
|
display: block;
|
|
286
284
|
position: relative;
|
|
@@ -295,7 +293,7 @@ void main() {
|
|
|
295
293
|
img.base {
|
|
296
294
|
opacity: 0;
|
|
297
295
|
}
|
|
298
|
-
|
|
296
|
+
canvas.snapshot {
|
|
299
297
|
position: absolute;
|
|
300
298
|
inset: 0;
|
|
301
299
|
width: 100%;
|
|
@@ -303,7 +301,7 @@ void main() {
|
|
|
303
301
|
opacity: 0;
|
|
304
302
|
transition: opacity 0.3s ease;
|
|
305
303
|
}
|
|
306
|
-
|
|
304
|
+
canvas.snapshot.ready {
|
|
307
305
|
opacity: 1;
|
|
308
306
|
}
|
|
309
|
-
`;let
|
|
307
|
+
`;let a=S;u([l.property()],a.prototype,"src");u([l.property()],a.prototype,"effect");u([l.property({type:Number,attribute:"dot-radius"})],a.prototype,"dotRadius");u([l.property({type:Number,attribute:"grid-size"})],a.prototype,"gridSize");u([l.property({type:Number,attribute:"angle-c"})],a.prototype,"angleC");u([l.property({type:Number,attribute:"angle-m"})],a.prototype,"angleM");u([l.property({type:Number,attribute:"angle-y"})],a.prototype,"angleY");u([l.property({type:Number,attribute:"angle-k"})],a.prototype,"angleK");u([l.property({type:Number,attribute:"show-c"})],a.prototype,"showC");u([l.property({type:Number,attribute:"show-m"})],a.prototype,"showM");u([l.property({type:Number,attribute:"show-y"})],a.prototype,"showY");u([l.property({type:Number,attribute:"show-k"})],a.prototype,"showK");u([l.property({type:Number,attribute:"intensity-k"})],a.prototype,"intensityK");u([l.property({attribute:"duotone-color"})],a.prototype,"duotoneColor");u([l.property({type:Number})],a.prototype,"angle");u([l.property({type:Number,attribute:"dot-offset-x"})],a.prototype,"dotOffsetX");u([l.property({type:Number,attribute:"dot-offset-y"})],a.prototype,"dotOffsetY");u([l.property({attribute:"bg-color"})],a.prototype,"bgColor");u([l.property({type:Number,attribute:"angle-warm"})],a.prototype,"angleWarm");u([l.property({type:Number,attribute:"angle-cool"})],a.prototype,"angleCool");u([l.property({type:Number,attribute:"show-warm"})],a.prototype,"showWarm");u([l.property({type:Number,attribute:"show-cool"})],a.prototype,"showCool");u([l.property({attribute:"warm-color"})],a.prototype,"warmColor");u([l.property({attribute:"cool-color"})],a.prototype,"coolColor");u([l.property({type:Number,attribute:"blend-mode"})],a.prototype,"blendMode");u([l.property({type:Number,attribute:"reference-width"})],a.prototype,"referenceWidth");u([l.state()],a.prototype,"_webglAvailable");u([l.state()],a.prototype,"_snapshotReady");customElements.get("some-shade-image")||customElements.define("some-shade-image",a);exports.SomeShadeImage=a;exports.get=D;exports.list=G;exports.register=_;
|
package/dist/some-shade.es.js
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import { LitElement as U, css as
|
|
2
|
-
import { property as u, state as
|
|
3
|
-
function
|
|
1
|
+
import { LitElement as U, css as M, html as A } from "lit";
|
|
2
|
+
import { property as u, state as D } from "lit/decorators.js";
|
|
3
|
+
function z(e) {
|
|
4
4
|
return e.getContext("webgl", {
|
|
5
5
|
alpha: !0,
|
|
6
6
|
premultipliedAlpha: !1,
|
|
7
7
|
preserveDrawingBuffer: !0
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
const
|
|
12
|
-
if (!
|
|
13
|
-
if (e.shaderSource(
|
|
14
|
-
const
|
|
15
|
-
throw e.deleteShader(
|
|
10
|
+
function K(e, o, r) {
|
|
11
|
+
const i = e.createShader(o);
|
|
12
|
+
if (!i) throw new Error("Failed to create shader");
|
|
13
|
+
if (e.shaderSource(i, r), e.compileShader(i), !e.getShaderParameter(i, e.COMPILE_STATUS)) {
|
|
14
|
+
const t = e.getShaderInfoLog(i);
|
|
15
|
+
throw e.deleteShader(i), new Error(`Shader compile error: ${t}`);
|
|
16
16
|
}
|
|
17
|
-
return
|
|
17
|
+
return i;
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
const
|
|
21
|
-
if (!
|
|
22
|
-
if (e.attachShader(
|
|
23
|
-
const
|
|
24
|
-
throw e.deleteProgram(
|
|
19
|
+
function P(e, o, r) {
|
|
20
|
+
const i = K(e, e.VERTEX_SHADER, o), t = K(e, e.FRAGMENT_SHADER, r), n = e.createProgram();
|
|
21
|
+
if (!n) throw new Error("Failed to create program");
|
|
22
|
+
if (e.attachShader(n, i), e.attachShader(n, t), e.linkProgram(n), !e.getProgramParameter(n, e.LINK_STATUS)) {
|
|
23
|
+
const f = e.getProgramInfoLog(n);
|
|
24
|
+
throw e.deleteProgram(n), new Error(`Program link error: ${f}`);
|
|
25
25
|
}
|
|
26
|
-
e.deleteShader(
|
|
27
|
-
const
|
|
28
|
-
for (let
|
|
29
|
-
const c = e.getActiveAttrib(
|
|
30
|
-
c &&
|
|
26
|
+
e.deleteShader(i), e.deleteShader(t);
|
|
27
|
+
const d = /* @__PURE__ */ new Map(), h = e.getProgramParameter(n, e.ACTIVE_ATTRIBUTES);
|
|
28
|
+
for (let f = 0; f < h; f++) {
|
|
29
|
+
const c = e.getActiveAttrib(n, f);
|
|
30
|
+
c && d.set(c.name, e.getAttribLocation(n, c.name));
|
|
31
31
|
}
|
|
32
|
-
const
|
|
33
|
-
for (let
|
|
34
|
-
const c = e.getActiveUniform(
|
|
32
|
+
const m = /* @__PURE__ */ new Map(), s = e.getProgramParameter(n, e.ACTIVE_UNIFORMS);
|
|
33
|
+
for (let f = 0; f < s; f++) {
|
|
34
|
+
const c = e.getActiveUniform(n, f);
|
|
35
35
|
if (c) {
|
|
36
|
-
const
|
|
37
|
-
|
|
36
|
+
const _ = e.getUniformLocation(n, c.name);
|
|
37
|
+
_ && m.set(c.name, _);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
return { program:
|
|
40
|
+
return { program: n, attribLocations: d, uniformLocations: m };
|
|
41
41
|
}
|
|
42
|
-
function
|
|
43
|
-
for (const [
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
46
|
-
if (typeof
|
|
47
|
-
e.uniform1f(
|
|
48
|
-
else if (Array.isArray(
|
|
49
|
-
switch (
|
|
42
|
+
function I(e, o, r) {
|
|
43
|
+
for (const [i, t] of Object.entries(r)) {
|
|
44
|
+
const n = o.uniformLocations.get(i);
|
|
45
|
+
if (n) {
|
|
46
|
+
if (typeof t == "number")
|
|
47
|
+
e.uniform1f(n, t);
|
|
48
|
+
else if (Array.isArray(t))
|
|
49
|
+
switch (t.length) {
|
|
50
50
|
case 2:
|
|
51
|
-
e.uniform2fv(
|
|
51
|
+
e.uniform2fv(n, t);
|
|
52
52
|
break;
|
|
53
53
|
case 3:
|
|
54
|
-
e.uniform3fv(
|
|
54
|
+
e.uniform3fv(n, t);
|
|
55
55
|
break;
|
|
56
56
|
case 4:
|
|
57
|
-
e.uniform4fv(
|
|
57
|
+
e.uniform4fv(n, t);
|
|
58
58
|
break;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
function
|
|
64
|
-
const
|
|
65
|
-
if (!
|
|
66
|
-
return e.bindTexture(e.TEXTURE_2D,
|
|
63
|
+
function L(e, o) {
|
|
64
|
+
const r = e.createTexture();
|
|
65
|
+
if (!r) throw new Error("Failed to create texture");
|
|
66
|
+
return e.bindTexture(e.TEXTURE_2D, r), e.texImage2D(e.TEXTURE_2D, 0, e.RGBA, e.RGBA, e.UNSIGNED_BYTE, o), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_WRAP_S, e.CLAMP_TO_EDGE), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_WRAP_T, e.CLAMP_TO_EDGE), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_MIN_FILTER, e.LINEAR), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_MAG_FILTER, e.LINEAR), { texture: r, width: o.naturalWidth, height: o.naturalHeight };
|
|
67
67
|
}
|
|
68
|
-
function
|
|
69
|
-
const
|
|
68
|
+
function V(e, o) {
|
|
69
|
+
const r = new Float32Array([
|
|
70
70
|
// pos.x pos.y tex.s tex.t
|
|
71
71
|
-1,
|
|
72
72
|
-1,
|
|
@@ -84,18 +84,18 @@ function z(e, o) {
|
|
|
84
84
|
1,
|
|
85
85
|
1,
|
|
86
86
|
0
|
|
87
|
-
]),
|
|
88
|
-
if (!
|
|
89
|
-
e.bindBuffer(e.ARRAY_BUFFER,
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
return
|
|
87
|
+
]), i = e.createBuffer();
|
|
88
|
+
if (!i) throw new Error("Failed to create buffer");
|
|
89
|
+
e.bindBuffer(e.ARRAY_BUFFER, i), e.bufferData(e.ARRAY_BUFFER, r, e.STATIC_DRAW);
|
|
90
|
+
const t = 4 * Float32Array.BYTES_PER_ELEMENT, n = o.attribLocations.get("a_position");
|
|
91
|
+
n !== void 0 && n !== -1 && (e.enableVertexAttribArray(n), e.vertexAttribPointer(n, 2, e.FLOAT, !1, t, 0));
|
|
92
|
+
const d = o.attribLocations.get("a_texCoord");
|
|
93
|
+
return d !== void 0 && d !== -1 && (e.enableVertexAttribArray(d), e.vertexAttribPointer(d, 2, e.FLOAT, !1, t, 2 * Float32Array.BYTES_PER_ELEMENT)), i;
|
|
94
94
|
}
|
|
95
|
-
function
|
|
95
|
+
function N(e) {
|
|
96
96
|
e.drawArrays(e.TRIANGLE_STRIP, 0, 4);
|
|
97
97
|
}
|
|
98
|
-
const
|
|
98
|
+
const W = `precision mediump float;
|
|
99
99
|
|
|
100
100
|
varying vec2 v_texCoord;
|
|
101
101
|
|
|
@@ -181,7 +181,7 @@ void main() {
|
|
|
181
181
|
|
|
182
182
|
gl_FragColor = vec4(outR, outG, outB, texture2D(u_image, v_texCoord).a);
|
|
183
183
|
}
|
|
184
|
-
`,
|
|
184
|
+
`, v = `attribute vec2 a_position;
|
|
185
185
|
attribute vec2 a_texCoord;
|
|
186
186
|
varying vec2 v_texCoord;
|
|
187
187
|
|
|
@@ -189,10 +189,10 @@ void main() {
|
|
|
189
189
|
gl_Position = vec4(a_position, 0.0, 1.0);
|
|
190
190
|
v_texCoord = a_texCoord;
|
|
191
191
|
}
|
|
192
|
-
`,
|
|
192
|
+
`, F = {
|
|
193
193
|
name: "halftone-cmyk",
|
|
194
|
-
fragmentShader:
|
|
195
|
-
vertexShader:
|
|
194
|
+
fragmentShader: W,
|
|
195
|
+
vertexShader: v,
|
|
196
196
|
uniforms: [
|
|
197
197
|
{ name: "u_dotRadius", type: "float", default: 4, attribute: "dot-radius" },
|
|
198
198
|
{ name: "u_gridSize", type: "float", default: 8, attribute: "grid-size" },
|
|
@@ -206,7 +206,7 @@ void main() {
|
|
|
206
206
|
{ name: "u_showK", type: "float", default: 1, attribute: "show-k" },
|
|
207
207
|
{ name: "u_intensityK", type: "float", default: 1, attribute: "intensity-k" }
|
|
208
208
|
]
|
|
209
|
-
},
|
|
209
|
+
}, O = `precision mediump float;
|
|
210
210
|
|
|
211
211
|
varying vec2 v_texCoord;
|
|
212
212
|
|
|
@@ -248,17 +248,17 @@ void main() {
|
|
|
248
248
|
|
|
249
249
|
gl_FragColor = vec4(result, color.a);
|
|
250
250
|
}
|
|
251
|
-
`,
|
|
251
|
+
`, Y = {
|
|
252
252
|
name: "halftone-duotone",
|
|
253
|
-
fragmentShader:
|
|
254
|
-
vertexShader:
|
|
253
|
+
fragmentShader: O,
|
|
254
|
+
vertexShader: v,
|
|
255
255
|
uniforms: [
|
|
256
256
|
{ name: "u_dotRadius", type: "float", default: 4, attribute: "dot-radius" },
|
|
257
257
|
{ name: "u_gridSize", type: "float", default: 8, attribute: "grid-size" },
|
|
258
258
|
{ name: "u_duotoneColor", type: "vec3", default: [0, 0.6, 0.8], attribute: "duotone-color" },
|
|
259
259
|
{ name: "u_angle", type: "float", default: 0, attribute: "angle" }
|
|
260
260
|
]
|
|
261
|
-
},
|
|
261
|
+
}, B = `precision mediump float;
|
|
262
262
|
|
|
263
263
|
varying vec2 v_texCoord;
|
|
264
264
|
|
|
@@ -314,10 +314,10 @@ void main() {
|
|
|
314
314
|
|
|
315
315
|
gl_FragColor = vec4(result, 1.0);
|
|
316
316
|
}
|
|
317
|
-
`,
|
|
317
|
+
`, X = {
|
|
318
318
|
name: "dot-grid",
|
|
319
|
-
fragmentShader:
|
|
320
|
-
vertexShader:
|
|
319
|
+
fragmentShader: B,
|
|
320
|
+
vertexShader: v,
|
|
321
321
|
uniforms: [
|
|
322
322
|
{ name: "u_dotRadius", type: "float", default: 4, attribute: "dot-radius" },
|
|
323
323
|
{ name: "u_gridSize", type: "float", default: 8, attribute: "grid-size" },
|
|
@@ -325,7 +325,7 @@ void main() {
|
|
|
325
325
|
{ name: "u_bgColor", type: "vec3", default: [1, 1, 1], attribute: "bg-color" },
|
|
326
326
|
{ name: "u_angle", type: "float", default: 0, attribute: "angle" }
|
|
327
327
|
]
|
|
328
|
-
},
|
|
328
|
+
}, G = `precision mediump float;
|
|
329
329
|
|
|
330
330
|
varying vec2 v_texCoord;
|
|
331
331
|
|
|
@@ -408,10 +408,10 @@ void main() {
|
|
|
408
408
|
|
|
409
409
|
gl_FragColor = vec4(clamp(result, 0.0, 1.0), color.a);
|
|
410
410
|
}
|
|
411
|
-
`,
|
|
411
|
+
`, H = {
|
|
412
412
|
name: "technicolor-2strip",
|
|
413
|
-
fragmentShader:
|
|
414
|
-
vertexShader:
|
|
413
|
+
fragmentShader: G,
|
|
414
|
+
vertexShader: v,
|
|
415
415
|
uniforms: [
|
|
416
416
|
{ name: "u_dotRadius", type: "float", default: 7, attribute: "dot-radius" },
|
|
417
417
|
{ name: "u_gridSize", type: "float", default: 10, attribute: "grid-size" },
|
|
@@ -426,32 +426,32 @@ void main() {
|
|
|
426
426
|
{ name: "u_blendMode", type: "float", default: 1, attribute: "blend-mode" },
|
|
427
427
|
{ name: "u_intensityK", type: "float", default: 1, attribute: "intensity-k" }
|
|
428
428
|
]
|
|
429
|
-
},
|
|
430
|
-
function
|
|
431
|
-
|
|
429
|
+
}, C = /* @__PURE__ */ new Map();
|
|
430
|
+
function y(e) {
|
|
431
|
+
C.set(e.name, e);
|
|
432
432
|
}
|
|
433
|
-
function
|
|
434
|
-
return
|
|
433
|
+
function $(e) {
|
|
434
|
+
return C.get(e);
|
|
435
435
|
}
|
|
436
|
-
function
|
|
437
|
-
return Array.from(
|
|
436
|
+
function ee() {
|
|
437
|
+
return Array.from(C.keys());
|
|
438
438
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
var
|
|
444
|
-
for (var
|
|
445
|
-
(
|
|
446
|
-
return
|
|
439
|
+
y(F);
|
|
440
|
+
y(Y);
|
|
441
|
+
y(X);
|
|
442
|
+
y(H);
|
|
443
|
+
var q = Object.defineProperty, l = (e, o, r, i) => {
|
|
444
|
+
for (var t = void 0, n = e.length - 1, d; n >= 0; n--)
|
|
445
|
+
(d = e[n]) && (t = d(o, r, t) || t);
|
|
446
|
+
return t && q(o, r, t), t;
|
|
447
447
|
};
|
|
448
|
-
const
|
|
449
|
-
let
|
|
448
|
+
const Q = 2;
|
|
449
|
+
let k = Promise.resolve();
|
|
450
450
|
function w(e) {
|
|
451
|
-
const o =
|
|
452
|
-
return
|
|
451
|
+
const o = k.then(e, e);
|
|
452
|
+
return k = o, o;
|
|
453
453
|
}
|
|
454
|
-
const
|
|
454
|
+
const j = /* @__PURE__ */ new Set([
|
|
455
455
|
"effect",
|
|
456
456
|
"dotRadius",
|
|
457
457
|
"gridSize",
|
|
@@ -477,26 +477,24 @@ const H = /* @__PURE__ */ new Set([
|
|
|
477
477
|
"coolColor",
|
|
478
478
|
"blendMode",
|
|
479
479
|
"referenceWidth"
|
|
480
|
-
]),
|
|
480
|
+
]), R = class R extends U {
|
|
481
481
|
constructor() {
|
|
482
|
-
super(...arguments), this.src = "", this.effect = "halftone-cmyk", this.dotRadius = 4, this.gridSize = 8, this.angleC = 15, this.angleM = 75, this.angleY = 0, this.angleK = 45, this.showC = 1, this.showM = 1, this.showY = 1, this.showK = 1, this.intensityK = 1, this.duotoneColor = "#0099cc", this.angle = 0, this.dotOffsetX = 0.5, this.dotOffsetY = 0.5, this.bgColor = "#ffffff", this.angleWarm = 15, this.angleCool = 75, this.showWarm = 1, this.showCool = 1, this.warmColor = "#d94010", this.coolColor = "#0da699", this.blendMode = 1, this.referenceWidth = 1024, this._webglAvailable = !0, this.
|
|
482
|
+
super(...arguments), this.src = "", this.effect = "halftone-cmyk", this.dotRadius = 4, this.gridSize = 8, this.angleC = 15, this.angleM = 75, this.angleY = 0, this.angleK = 45, this.showC = 1, this.showM = 1, this.showY = 1, this.showK = 1, this.intensityK = 1, this.duotoneColor = "#0099cc", this.angle = 0, this.dotOffsetX = 0.5, this.dotOffsetY = 0.5, this.bgColor = "#ffffff", this.angleWarm = 15, this.angleCool = 75, this.showWarm = 1, this.showCool = 1, this.warmColor = "#d94010", this.coolColor = "#0da699", this.blendMode = 1, this.referenceWidth = 1024, this._webglAvailable = !0, this._snapshotReady = !1, this._image = null, this._observer = null, this._visible = !1, this._needsRender = !1;
|
|
483
483
|
}
|
|
484
484
|
render() {
|
|
485
|
-
return this._webglAvailable ?
|
|
485
|
+
return this._webglAvailable ? A`
|
|
486
486
|
<img class="base" src=${this.src} alt="" />
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
alt="" />` : ""}
|
|
492
|
-
` : y`<img src=${this.src} alt="" />`;
|
|
487
|
+
<canvas
|
|
488
|
+
class="snapshot${this._snapshotReady ? " ready" : ""}"
|
|
489
|
+
></canvas>
|
|
490
|
+
` : A`<img src=${this.src} alt="" />`;
|
|
493
491
|
}
|
|
494
492
|
connectedCallback() {
|
|
495
493
|
super.connectedCallback(), this._observer = new IntersectionObserver(
|
|
496
494
|
(o) => {
|
|
497
|
-
var
|
|
498
|
-
const
|
|
499
|
-
this._visible = ((
|
|
495
|
+
var i;
|
|
496
|
+
const r = this._visible;
|
|
497
|
+
this._visible = ((i = o[0]) == null ? void 0 : i.isIntersecting) ?? !1, this._visible && !r && (this._needsRender || this._image && !this._snapshotReady) && (this._needsRender = !1, w(() => this._renderEffect()));
|
|
500
498
|
},
|
|
501
499
|
// Start rendering slightly before the element scrolls into view.
|
|
502
500
|
{ rootMargin: "200px" }
|
|
@@ -509,23 +507,23 @@ const H = /* @__PURE__ */ new Set([
|
|
|
509
507
|
}
|
|
510
508
|
if (!this._image) return;
|
|
511
509
|
[...o.keys()].some(
|
|
512
|
-
(
|
|
510
|
+
(i) => j.has(i)
|
|
513
511
|
) && this._scheduleRender();
|
|
514
512
|
}
|
|
515
513
|
disconnectedCallback() {
|
|
516
514
|
var o;
|
|
517
|
-
super.disconnectedCallback(), (o = this._observer) == null || o.disconnect()
|
|
515
|
+
super.disconnectedCallback(), (o = this._observer) == null || o.disconnect();
|
|
518
516
|
}
|
|
519
517
|
// ---------------------------------------------------------------------------
|
|
520
518
|
// Image loading
|
|
521
519
|
// ---------------------------------------------------------------------------
|
|
522
520
|
_loadImage(o) {
|
|
523
|
-
const
|
|
524
|
-
|
|
525
|
-
this._image =
|
|
526
|
-
},
|
|
521
|
+
const r = new Image();
|
|
522
|
+
r.crossOrigin = "anonymous", r.onload = () => {
|
|
523
|
+
this._image = r, this._scheduleRender();
|
|
524
|
+
}, r.onerror = () => {
|
|
527
525
|
console.warn(`[some-shade] Failed to load image: ${o}`);
|
|
528
|
-
},
|
|
526
|
+
}, r.src = o;
|
|
529
527
|
}
|
|
530
528
|
// ---------------------------------------------------------------------------
|
|
531
529
|
// Render scheduling
|
|
@@ -542,87 +540,82 @@ const H = /* @__PURE__ */ new Set([
|
|
|
542
540
|
// WebGL render → snapshot → tear-down
|
|
543
541
|
// ---------------------------------------------------------------------------
|
|
544
542
|
async _renderEffect() {
|
|
545
|
-
var
|
|
543
|
+
var f;
|
|
546
544
|
if (!this._image) return;
|
|
547
|
-
const o =
|
|
545
|
+
const o = $(this.effect);
|
|
548
546
|
if (!o) {
|
|
549
547
|
console.warn(`[some-shade] Unknown effect: ${this.effect}`);
|
|
550
548
|
return;
|
|
551
549
|
}
|
|
552
|
-
|
|
553
|
-
r.
|
|
554
|
-
|
|
555
|
-
|
|
550
|
+
this._snapshotReady = !1;
|
|
551
|
+
const r = Math.min(window.devicePixelRatio || 1, Q), i = this._image.naturalWidth, t = this._image.naturalHeight, n = this.clientWidth || i, d = Math.min(Math.round(n * r), i), h = Math.round(d * (t / i)), m = document.createElement("canvas");
|
|
552
|
+
m.width = d, m.height = h;
|
|
553
|
+
const s = z(m);
|
|
554
|
+
if (!s) {
|
|
556
555
|
this._webglAvailable = !1;
|
|
557
556
|
return;
|
|
558
557
|
}
|
|
559
558
|
try {
|
|
560
|
-
const
|
|
561
|
-
|
|
559
|
+
const c = P(
|
|
560
|
+
s,
|
|
562
561
|
o.vertexShader,
|
|
563
562
|
o.fragmentShader
|
|
564
563
|
);
|
|
565
|
-
|
|
566
|
-
const
|
|
567
|
-
|
|
568
|
-
const
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
this._getUniformValues(
|
|
573
|
-
),
|
|
574
|
-
const
|
|
575
|
-
g !== void 0 && g !== -1 && (
|
|
576
|
-
const p =
|
|
577
|
-
p !== void 0 && p !== -1 && (
|
|
564
|
+
s.useProgram(c.program);
|
|
565
|
+
const _ = L(s, this._image), x = V(s, c);
|
|
566
|
+
s.viewport(0, 0, m.width, m.height), s.clearColor(0, 0, 0, 0), s.clear(s.COLOR_BUFFER_BIT), s.activeTexture(s.TEXTURE0), s.bindTexture(s.TEXTURE_2D, _.texture);
|
|
567
|
+
const S = c.uniformLocations.get("u_image");
|
|
568
|
+
S && s.uniform1i(S, 0), I(
|
|
569
|
+
s,
|
|
570
|
+
c,
|
|
571
|
+
this._getUniformValues(d, h, r)
|
|
572
|
+
), s.bindBuffer(s.ARRAY_BUFFER, x);
|
|
573
|
+
const E = 4 * Float32Array.BYTES_PER_ELEMENT, g = c.attribLocations.get("a_position");
|
|
574
|
+
g !== void 0 && g !== -1 && (s.enableVertexAttribArray(g), s.vertexAttribPointer(g, 2, s.FLOAT, !1, E, 0));
|
|
575
|
+
const p = c.attribLocations.get("a_texCoord");
|
|
576
|
+
p !== void 0 && p !== -1 && (s.enableVertexAttribArray(p), s.vertexAttribPointer(
|
|
578
577
|
p,
|
|
579
578
|
2,
|
|
580
|
-
|
|
579
|
+
s.FLOAT,
|
|
581
580
|
!1,
|
|
582
|
-
|
|
581
|
+
E,
|
|
583
582
|
2 * Float32Array.BYTES_PER_ELEMENT
|
|
584
|
-
)),
|
|
585
|
-
const
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
583
|
+
)), N(s);
|
|
584
|
+
const b = this.renderRoot.querySelector(".snapshot");
|
|
585
|
+
if (b) {
|
|
586
|
+
b.width = d, b.height = h;
|
|
587
|
+
const T = b.getContext("2d");
|
|
588
|
+
T && (T.drawImage(m, 0, 0), this._snapshotReady = !0);
|
|
589
|
+
}
|
|
590
|
+
s.deleteTexture(_.texture), s.deleteProgram(c.program), s.deleteBuffer(x);
|
|
589
591
|
} finally {
|
|
590
|
-
(
|
|
592
|
+
(f = s.getExtension("WEBGL_lose_context")) == null || f.loseContext();
|
|
591
593
|
}
|
|
592
594
|
}
|
|
593
595
|
// ---------------------------------------------------------------------------
|
|
594
596
|
// Helpers
|
|
595
597
|
// ---------------------------------------------------------------------------
|
|
596
|
-
_onSnapshotLoad() {
|
|
597
|
-
this._snapshotLoaded = !0;
|
|
598
|
-
}
|
|
599
598
|
/** Hide the rendered snapshot momentarily, then fade it back in.
|
|
600
599
|
* Useful for previewing the loading-blur transition. */
|
|
601
600
|
replayTransition(o = 500) {
|
|
602
|
-
this.
|
|
601
|
+
this._snapshotReady && (this._snapshotReady = !1, this.updateComplete.then(() => {
|
|
603
602
|
setTimeout(() => {
|
|
604
|
-
this.
|
|
603
|
+
this._snapshotReady = !0;
|
|
605
604
|
}, o);
|
|
606
605
|
}));
|
|
607
606
|
}
|
|
608
|
-
|
|
609
|
-
this._snapshotUrl && (URL.revokeObjectURL(this._snapshotUrl), this._snapshotUrl = "");
|
|
610
|
-
}
|
|
611
|
-
_getUniformValues(o, a) {
|
|
607
|
+
_getUniformValues(o, r, i) {
|
|
612
608
|
const t = {};
|
|
613
|
-
t.u_resolution = [
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
];
|
|
617
|
-
const s = o.width / this.referenceWidth;
|
|
618
|
-
return t.u_dotRadius = this.dotRadius * s, t.u_gridSize = this.gridSize * s, this.effect === "halftone-cmyk" ? (t.u_angleC = this.angleC, t.u_angleM = this.angleM, t.u_angleY = this.angleY, t.u_angleK = this.angleK, t.u_showC = this.showC, t.u_showM = this.showM, t.u_showY = this.showY, t.u_showK = this.showK, t.u_intensityK = this.intensityK) : this.effect === "halftone-duotone" ? (t.u_duotoneColor = this._parseHexColor(this.duotoneColor), t.u_angle = this.angle) : this.effect === "dot-grid" ? (t.u_dotOffset = [this.dotOffsetX, this.dotOffsetY], t.u_bgColor = this._parseHexColor(this.bgColor), t.u_angle = this.angle) : this.effect === "technicolor-2strip" && (t.u_angleWarm = this.angleWarm, t.u_angleCool = this.angleCool, t.u_angleK = this.angleK, t.u_showWarm = this.showWarm, t.u_showCool = this.showCool, t.u_showK = this.showK, t.u_warmColor = this._parseHexColor(this.warmColor), t.u_coolColor = this._parseHexColor(this.coolColor), t.u_blendMode = this.blendMode, t.u_intensityK = this.intensityK), t;
|
|
609
|
+
t.u_resolution = [o, r];
|
|
610
|
+
const n = o / (this.referenceWidth * i);
|
|
611
|
+
return t.u_dotRadius = this.dotRadius * n, t.u_gridSize = this.gridSize * n, this.effect === "halftone-cmyk" ? (t.u_angleC = this.angleC, t.u_angleM = this.angleM, t.u_angleY = this.angleY, t.u_angleK = this.angleK, t.u_showC = this.showC, t.u_showM = this.showM, t.u_showY = this.showY, t.u_showK = this.showK, t.u_intensityK = this.intensityK) : this.effect === "halftone-duotone" ? (t.u_duotoneColor = this._parseHexColor(this.duotoneColor), t.u_angle = this.angle) : this.effect === "dot-grid" ? (t.u_dotOffset = [this.dotOffsetX, this.dotOffsetY], t.u_bgColor = this._parseHexColor(this.bgColor), t.u_angle = this.angle) : this.effect === "technicolor-2strip" && (t.u_angleWarm = this.angleWarm, t.u_angleCool = this.angleCool, t.u_angleK = this.angleK, t.u_showWarm = this.showWarm, t.u_showCool = this.showCool, t.u_showK = this.showK, t.u_warmColor = this._parseHexColor(this.warmColor), t.u_coolColor = this._parseHexColor(this.coolColor), t.u_blendMode = this.blendMode, t.u_intensityK = this.intensityK), t;
|
|
619
612
|
}
|
|
620
613
|
_parseHexColor(o) {
|
|
621
|
-
const
|
|
622
|
-
return [
|
|
614
|
+
const r = o.replace("#", ""), i = parseInt(r.substring(0, 2), 16) / 255, t = parseInt(r.substring(2, 4), 16) / 255, n = parseInt(r.substring(4, 6), 16) / 255;
|
|
615
|
+
return [i, t, n];
|
|
623
616
|
}
|
|
624
617
|
};
|
|
625
|
-
|
|
618
|
+
R.styles = M`
|
|
626
619
|
:host {
|
|
627
620
|
display: block;
|
|
628
621
|
position: relative;
|
|
@@ -637,7 +630,7 @@ S.styles = K`
|
|
|
637
630
|
img.base {
|
|
638
631
|
opacity: 0;
|
|
639
632
|
}
|
|
640
|
-
|
|
633
|
+
canvas.snapshot {
|
|
641
634
|
position: absolute;
|
|
642
635
|
inset: 0;
|
|
643
636
|
width: 100%;
|
|
@@ -645,102 +638,99 @@ S.styles = K`
|
|
|
645
638
|
opacity: 0;
|
|
646
639
|
transition: opacity 0.3s ease;
|
|
647
640
|
}
|
|
648
|
-
|
|
641
|
+
canvas.snapshot.ready {
|
|
649
642
|
opacity: 1;
|
|
650
643
|
}
|
|
651
644
|
`;
|
|
652
|
-
let
|
|
645
|
+
let a = R;
|
|
653
646
|
l([
|
|
654
647
|
u()
|
|
655
|
-
],
|
|
648
|
+
], a.prototype, "src");
|
|
656
649
|
l([
|
|
657
650
|
u()
|
|
658
|
-
],
|
|
651
|
+
], a.prototype, "effect");
|
|
659
652
|
l([
|
|
660
653
|
u({ type: Number, attribute: "dot-radius" })
|
|
661
|
-
],
|
|
654
|
+
], a.prototype, "dotRadius");
|
|
662
655
|
l([
|
|
663
656
|
u({ type: Number, attribute: "grid-size" })
|
|
664
|
-
],
|
|
657
|
+
], a.prototype, "gridSize");
|
|
665
658
|
l([
|
|
666
659
|
u({ type: Number, attribute: "angle-c" })
|
|
667
|
-
],
|
|
660
|
+
], a.prototype, "angleC");
|
|
668
661
|
l([
|
|
669
662
|
u({ type: Number, attribute: "angle-m" })
|
|
670
|
-
],
|
|
663
|
+
], a.prototype, "angleM");
|
|
671
664
|
l([
|
|
672
665
|
u({ type: Number, attribute: "angle-y" })
|
|
673
|
-
],
|
|
666
|
+
], a.prototype, "angleY");
|
|
674
667
|
l([
|
|
675
668
|
u({ type: Number, attribute: "angle-k" })
|
|
676
|
-
],
|
|
669
|
+
], a.prototype, "angleK");
|
|
677
670
|
l([
|
|
678
671
|
u({ type: Number, attribute: "show-c" })
|
|
679
|
-
],
|
|
672
|
+
], a.prototype, "showC");
|
|
680
673
|
l([
|
|
681
674
|
u({ type: Number, attribute: "show-m" })
|
|
682
|
-
],
|
|
675
|
+
], a.prototype, "showM");
|
|
683
676
|
l([
|
|
684
677
|
u({ type: Number, attribute: "show-y" })
|
|
685
|
-
],
|
|
678
|
+
], a.prototype, "showY");
|
|
686
679
|
l([
|
|
687
680
|
u({ type: Number, attribute: "show-k" })
|
|
688
|
-
],
|
|
681
|
+
], a.prototype, "showK");
|
|
689
682
|
l([
|
|
690
683
|
u({ type: Number, attribute: "intensity-k" })
|
|
691
|
-
],
|
|
684
|
+
], a.prototype, "intensityK");
|
|
692
685
|
l([
|
|
693
686
|
u({ attribute: "duotone-color" })
|
|
694
|
-
],
|
|
687
|
+
], a.prototype, "duotoneColor");
|
|
695
688
|
l([
|
|
696
689
|
u({ type: Number })
|
|
697
|
-
],
|
|
690
|
+
], a.prototype, "angle");
|
|
698
691
|
l([
|
|
699
692
|
u({ type: Number, attribute: "dot-offset-x" })
|
|
700
|
-
],
|
|
693
|
+
], a.prototype, "dotOffsetX");
|
|
701
694
|
l([
|
|
702
695
|
u({ type: Number, attribute: "dot-offset-y" })
|
|
703
|
-
],
|
|
696
|
+
], a.prototype, "dotOffsetY");
|
|
704
697
|
l([
|
|
705
698
|
u({ attribute: "bg-color" })
|
|
706
|
-
],
|
|
699
|
+
], a.prototype, "bgColor");
|
|
707
700
|
l([
|
|
708
701
|
u({ type: Number, attribute: "angle-warm" })
|
|
709
|
-
],
|
|
702
|
+
], a.prototype, "angleWarm");
|
|
710
703
|
l([
|
|
711
704
|
u({ type: Number, attribute: "angle-cool" })
|
|
712
|
-
],
|
|
705
|
+
], a.prototype, "angleCool");
|
|
713
706
|
l([
|
|
714
707
|
u({ type: Number, attribute: "show-warm" })
|
|
715
|
-
],
|
|
708
|
+
], a.prototype, "showWarm");
|
|
716
709
|
l([
|
|
717
710
|
u({ type: Number, attribute: "show-cool" })
|
|
718
|
-
],
|
|
711
|
+
], a.prototype, "showCool");
|
|
719
712
|
l([
|
|
720
713
|
u({ attribute: "warm-color" })
|
|
721
|
-
],
|
|
714
|
+
], a.prototype, "warmColor");
|
|
722
715
|
l([
|
|
723
716
|
u({ attribute: "cool-color" })
|
|
724
|
-
],
|
|
717
|
+
], a.prototype, "coolColor");
|
|
725
718
|
l([
|
|
726
719
|
u({ type: Number, attribute: "blend-mode" })
|
|
727
|
-
],
|
|
720
|
+
], a.prototype, "blendMode");
|
|
728
721
|
l([
|
|
729
722
|
u({ type: Number, attribute: "reference-width" })
|
|
730
|
-
],
|
|
731
|
-
l([
|
|
732
|
-
C()
|
|
733
|
-
], i.prototype, "_webglAvailable");
|
|
723
|
+
], a.prototype, "referenceWidth");
|
|
734
724
|
l([
|
|
735
|
-
|
|
736
|
-
],
|
|
725
|
+
D()
|
|
726
|
+
], a.prototype, "_webglAvailable");
|
|
737
727
|
l([
|
|
738
|
-
|
|
739
|
-
],
|
|
740
|
-
customElements.get("some-shade-image") || customElements.define("some-shade-image",
|
|
728
|
+
D()
|
|
729
|
+
], a.prototype, "_snapshotReady");
|
|
730
|
+
customElements.get("some-shade-image") || customElements.define("some-shade-image", a);
|
|
741
731
|
export {
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
732
|
+
a as SomeShadeImage,
|
|
733
|
+
$ as get,
|
|
734
|
+
ee as list,
|
|
735
|
+
y as register
|
|
746
736
|
};
|
package/dist/some-shade.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(m,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("lit"),require("lit/decorators.js")):typeof define=="function"&&define.amd?define(["exports","lit","lit/decorators.js"],p):(m=typeof globalThis<"u"?globalThis:m||self,p(m.SomeShade={},m.Lit,m.LitDecorators))})(this,(function(m,p,l){"use strict";function U(e){return e.getContext("webgl",{alpha:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0})}function E(e,o,r){const i=e.createShader(o);if(!i)throw new Error("Failed to create shader");if(e.shaderSource(i,r),e.compileShader(i),!e.getShaderParameter(i,e.COMPILE_STATUS)){const t=e.getShaderInfoLog(i);throw e.deleteShader(i),new Error(`Shader compile error: ${t}`)}return i}function z(e,o,r){const i=E(e,e.VERTEX_SHADER,o),t=E(e,e.FRAGMENT_SHADER,r),n=e.createProgram();if(!n)throw new Error("Failed to create program");if(e.attachShader(n,i),e.attachShader(n,t),e.linkProgram(n),!e.getProgramParameter(n,e.LINK_STATUS)){const c=e.getProgramInfoLog(n);throw e.deleteProgram(n),new Error(`Program link error: ${c}`)}e.deleteShader(i),e.deleteShader(t);const f=new Map,_=e.getProgramParameter(n,e.ACTIVE_ATTRIBUTES);for(let c=0;c<_;c++){const d=e.getActiveAttrib(n,c);d&&f.set(d.name,e.getAttribLocation(n,d.name))}const h=new Map,s=e.getProgramParameter(n,e.ACTIVE_UNIFORMS);for(let c=0;c<s;c++){const d=e.getActiveUniform(n,c);if(d){const b=e.getUniformLocation(n,d.name);b&&h.set(d.name,b)}}return{program:n,attribLocations:f,uniformLocations:h}}function P(e,o,r){for(const[i,t]of Object.entries(r)){const n=o.uniformLocations.get(i);if(n){if(typeof t=="number")e.uniform1f(n,t);else if(Array.isArray(t))switch(t.length){case 2:e.uniform2fv(n,t);break;case 3:e.uniform3fv(n,t);break;case 4:e.uniform4fv(n,t);break}}}}function I(e,o){const r=e.createTexture();if(!r)throw new Error("Failed to create texture");return e.bindTexture(e.TEXTURE_2D,r),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,o),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),{texture:r,width:o.naturalWidth,height:o.naturalHeight}}function L(e,o){const r=new Float32Array([-1,-1,0,1,1,-1,1,1,-1,1,0,0,1,1,1,0]),i=e.createBuffer();if(!i)throw new Error("Failed to create buffer");e.bindBuffer(e.ARRAY_BUFFER,i),e.bufferData(e.ARRAY_BUFFER,r,e.STATIC_DRAW);const t=4*Float32Array.BYTES_PER_ELEMENT,n=o.attribLocations.get("a_position");n!==void 0&&n!==-1&&(e.enableVertexAttribArray(n),e.vertexAttribPointer(n,2,e.FLOAT,!1,t,0));const f=o.attribLocations.get("a_texCoord");return f!==void 0&&f!==-1&&(e.enableVertexAttribArray(f),e.vertexAttribPointer(f,2,e.FLOAT,!1,t,2*Float32Array.BYTES_PER_ELEMENT)),i}function V(e){e.drawArrays(e.TRIANGLE_STRIP,0,4)}const N=`precision mediump float;
|
|
2
2
|
|
|
3
3
|
varying vec2 v_texCoord;
|
|
4
4
|
|
|
@@ -84,7 +84,7 @@ void main() {
|
|
|
84
84
|
|
|
85
85
|
gl_FragColor = vec4(outR, outG, outB, texture2D(u_image, v_texCoord).a);
|
|
86
86
|
}
|
|
87
|
-
`,
|
|
87
|
+
`,v=`attribute vec2 a_position;
|
|
88
88
|
attribute vec2 a_texCoord;
|
|
89
89
|
varying vec2 v_texCoord;
|
|
90
90
|
|
|
@@ -92,7 +92,7 @@ void main() {
|
|
|
92
92
|
gl_Position = vec4(a_position, 0.0, 1.0);
|
|
93
93
|
v_texCoord = a_texCoord;
|
|
94
94
|
}
|
|
95
|
-
`,
|
|
95
|
+
`,W={name:"halftone-cmyk",fragmentShader:N,vertexShader:v,uniforms:[{name:"u_dotRadius",type:"float",default:4,attribute:"dot-radius"},{name:"u_gridSize",type:"float",default:8,attribute:"grid-size"},{name:"u_angleC",type:"float",default:15,attribute:"angle-c"},{name:"u_angleM",type:"float",default:75,attribute:"angle-m"},{name:"u_angleY",type:"float",default:0,attribute:"angle-y"},{name:"u_angleK",type:"float",default:45,attribute:"angle-k"},{name:"u_showC",type:"float",default:1,attribute:"show-c"},{name:"u_showM",type:"float",default:1,attribute:"show-m"},{name:"u_showY",type:"float",default:1,attribute:"show-y"},{name:"u_showK",type:"float",default:1,attribute:"show-k"},{name:"u_intensityK",type:"float",default:1,attribute:"intensity-k"}]},O={name:"halftone-duotone",fragmentShader:`precision mediump float;
|
|
96
96
|
|
|
97
97
|
varying vec2 v_texCoord;
|
|
98
98
|
|
|
@@ -134,7 +134,7 @@ void main() {
|
|
|
134
134
|
|
|
135
135
|
gl_FragColor = vec4(result, color.a);
|
|
136
136
|
}
|
|
137
|
-
`,vertexShader:
|
|
137
|
+
`,vertexShader:v,uniforms:[{name:"u_dotRadius",type:"float",default:4,attribute:"dot-radius"},{name:"u_gridSize",type:"float",default:8,attribute:"grid-size"},{name:"u_duotoneColor",type:"vec3",default:[0,.6,.8],attribute:"duotone-color"},{name:"u_angle",type:"float",default:0,attribute:"angle"}]},F={name:"dot-grid",fragmentShader:`precision mediump float;
|
|
138
138
|
|
|
139
139
|
varying vec2 v_texCoord;
|
|
140
140
|
|
|
@@ -190,7 +190,7 @@ void main() {
|
|
|
190
190
|
|
|
191
191
|
gl_FragColor = vec4(result, 1.0);
|
|
192
192
|
}
|
|
193
|
-
`,vertexShader:
|
|
193
|
+
`,vertexShader:v,uniforms:[{name:"u_dotRadius",type:"float",default:4,attribute:"dot-radius"},{name:"u_gridSize",type:"float",default:8,attribute:"grid-size"},{name:"u_dotOffset",type:"vec2",default:[.5,.5],attribute:"dot-offset"},{name:"u_bgColor",type:"vec3",default:[1,1,1],attribute:"bg-color"},{name:"u_angle",type:"float",default:0,attribute:"angle"}]},Y={name:"technicolor-2strip",fragmentShader:`precision mediump float;
|
|
194
194
|
|
|
195
195
|
varying vec2 v_texCoord;
|
|
196
196
|
|
|
@@ -273,14 +273,12 @@ void main() {
|
|
|
273
273
|
|
|
274
274
|
gl_FragColor = vec4(clamp(result, 0.0, 1.0), color.a);
|
|
275
275
|
}
|
|
276
|
-
`,vertexShader:
|
|
276
|
+
`,vertexShader:v,uniforms:[{name:"u_dotRadius",type:"float",default:7,attribute:"dot-radius"},{name:"u_gridSize",type:"float",default:10,attribute:"grid-size"},{name:"u_angleWarm",type:"float",default:15,attribute:"angle-warm"},{name:"u_angleCool",type:"float",default:75,attribute:"angle-cool"},{name:"u_angleK",type:"float",default:45,attribute:"angle-k"},{name:"u_showWarm",type:"float",default:1,attribute:"show-warm"},{name:"u_showCool",type:"float",default:1,attribute:"show-cool"},{name:"u_showK",type:"float",default:1,attribute:"show-k"},{name:"u_warmColor",type:"vec3",default:[.85,.25,.06],attribute:"warm-color"},{name:"u_coolColor",type:"vec3",default:[.05,.65,.6],attribute:"cool-color"},{name:"u_blendMode",type:"float",default:1,attribute:"blend-mode"},{name:"u_intensityK",type:"float",default:1,attribute:"intensity-k"}]},R=new Map;function g(e){R.set(e.name,e)}function T(e){return R.get(e)}function B(){return Array.from(R.keys())}g(W),g(O),g(F),g(Y);var X=Object.defineProperty,u=(e,o,r,i)=>{for(var t=void 0,n=e.length-1,f;n>=0;n--)(f=e[n])&&(t=f(o,r,t)||t);return t&&X(o,r,t),t};const G=2;let A=Promise.resolve();function S(e){const o=A.then(e,e);return A=o,o}const H=new Set(["effect","dotRadius","gridSize","angleC","angleM","angleY","angleK","showC","showM","showY","showK","intensityK","duotoneColor","angle","dotOffsetX","dotOffsetY","bgColor","angleWarm","angleCool","showWarm","showCool","warmColor","coolColor","blendMode","referenceWidth"]),x=class x extends p.LitElement{constructor(){super(...arguments),this.src="",this.effect="halftone-cmyk",this.dotRadius=4,this.gridSize=8,this.angleC=15,this.angleM=75,this.angleY=0,this.angleK=45,this.showC=1,this.showM=1,this.showY=1,this.showK=1,this.intensityK=1,this.duotoneColor="#0099cc",this.angle=0,this.dotOffsetX=.5,this.dotOffsetY=.5,this.bgColor="#ffffff",this.angleWarm=15,this.angleCool=75,this.showWarm=1,this.showCool=1,this.warmColor="#d94010",this.coolColor="#0da699",this.blendMode=1,this.referenceWidth=1024,this._webglAvailable=!0,this._snapshotReady=!1,this._image=null,this._observer=null,this._visible=!1,this._needsRender=!1}render(){return this._webglAvailable?p.html`
|
|
277
277
|
<img class="base" src=${this.src} alt="" />
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
alt="" />`:""}
|
|
283
|
-
`:m.html`<img src=${this.src} alt="" />`}connectedCallback(){super.connectedCallback(),this._observer=new IntersectionObserver(o=>{var t;const a=this._visible;this._visible=((t=o[0])==null?void 0:t.isIntersecting)??!1,this._visible&&!a&&(this._needsRender||this._image&&!this._snapshotUrl)&&(this._needsRender=!1,R(()=>this._renderEffect()))},{rootMargin:"200px"}),this._observer.observe(this)}updated(o){if(o.has("src")&&this.src){this._loadImage(this.src);return}if(!this._image)return;[...o.keys()].some(t=>Y.has(t))&&this._scheduleRender()}disconnectedCallback(){var o;super.disconnectedCallback(),(o=this._observer)==null||o.disconnect(),this._revokeSnapshot()}_loadImage(o){const a=new Image;a.crossOrigin="anonymous",a.onload=()=>{this._image=a,this._scheduleRender()},a.onerror=()=>{console.warn(`[some-shade] Failed to load image: ${o}`)},a.src=o}_scheduleRender(){this._visible?R(()=>this._renderEffect()):(this._needsRender=!0,requestAnimationFrame(()=>{if(this._needsRender&&!this._visible){const o=this.getBoundingClientRect();o.bottom>=0&&o.top<window.innerHeight&&(this._visible=!0,this._needsRender=!1,R(()=>this._renderEffect()))}}))}async _renderEffect(){var v;if(!this._image)return;const o=x(this.effect);if(!o){console.warn(`[some-shade] Unknown effect: ${this.effect}`);return}const a=Math.min(window.devicePixelRatio||1,W),t=this._image.naturalWidth,u=this._image.naturalHeight,r=document.createElement("canvas");r.width=t*a,r.height=u*a;const n=U(r);if(!n){this._webglAvailable=!1;return}try{const c=K(n,o.vertexShader,o.fragmentShader);n.useProgram(c.program);const _=D(n,this._image),f=L(n,c);n.viewport(0,0,r.width,r.height),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,_.texture);const h=c.uniformLocations.get("u_image");h&&n.uniform1i(h,0),k(n,c,this._getUniformValues(_,a)),n.bindBuffer(n.ARRAY_BUFFER,f);const g=4*Float32Array.BYTES_PER_ELEMENT,y=c.attribLocations.get("a_position");y!==void 0&&y!==-1&&(n.enableVertexAttribArray(y),n.vertexAttribPointer(y,2,n.FLOAT,!1,g,0));const w=c.attribLocations.get("a_texCoord");w!==void 0&&w!==-1&&(n.enableVertexAttribArray(w),n.vertexAttribPointer(w,2,n.FLOAT,!1,g,2*Float32Array.BYTES_PER_ELEMENT)),M(n);const A=await new Promise(B=>r.toBlob(B));n.deleteTexture(_.texture),n.deleteProgram(c.program),n.deleteBuffer(f),A&&(this._snapshotLoaded=!1,this._revokeSnapshot(),this._snapshotUrl=URL.createObjectURL(A))}finally{(v=n.getExtension("WEBGL_lose_context"))==null||v.loseContext()}}_onSnapshotLoad(){this._snapshotLoaded=!0}replayTransition(o=500){this._snapshotUrl&&(this._snapshotLoaded=!1,this.updateComplete.then(()=>{setTimeout(()=>{this._snapshotLoaded=!0},o)}))}_revokeSnapshot(){this._snapshotUrl&&(URL.revokeObjectURL(this._snapshotUrl),this._snapshotUrl="")}_getUniformValues(o,a){const t={};t.u_resolution=[o.width*a,o.height*a];const u=o.width/this.referenceWidth;return t.u_dotRadius=this.dotRadius*u,t.u_gridSize=this.gridSize*u,this.effect==="halftone-cmyk"?(t.u_angleC=this.angleC,t.u_angleM=this.angleM,t.u_angleY=this.angleY,t.u_angleK=this.angleK,t.u_showC=this.showC,t.u_showM=this.showM,t.u_showY=this.showY,t.u_showK=this.showK,t.u_intensityK=this.intensityK):this.effect==="halftone-duotone"?(t.u_duotoneColor=this._parseHexColor(this.duotoneColor),t.u_angle=this.angle):this.effect==="dot-grid"?(t.u_dotOffset=[this.dotOffsetX,this.dotOffsetY],t.u_bgColor=this._parseHexColor(this.bgColor),t.u_angle=this.angle):this.effect==="technicolor-2strip"&&(t.u_angleWarm=this.angleWarm,t.u_angleCool=this.angleCool,t.u_angleK=this.angleK,t.u_showWarm=this.showWarm,t.u_showCool=this.showCool,t.u_showK=this.showK,t.u_warmColor=this._parseHexColor(this.warmColor),t.u_coolColor=this._parseHexColor(this.coolColor),t.u_blendMode=this.blendMode,t.u_intensityK=this.intensityK),t}_parseHexColor(o){const a=o.replace("#",""),t=parseInt(a.substring(0,2),16)/255,u=parseInt(a.substring(2,4),16)/255,r=parseInt(a.substring(4,6),16)/255;return[t,u,r]}};S.styles=m.css`
|
|
278
|
+
<canvas
|
|
279
|
+
class="snapshot${this._snapshotReady?" ready":""}"
|
|
280
|
+
></canvas>
|
|
281
|
+
`:p.html`<img src=${this.src} alt="" />`}connectedCallback(){super.connectedCallback(),this._observer=new IntersectionObserver(o=>{var i;const r=this._visible;this._visible=((i=o[0])==null?void 0:i.isIntersecting)??!1,this._visible&&!r&&(this._needsRender||this._image&&!this._snapshotReady)&&(this._needsRender=!1,S(()=>this._renderEffect()))},{rootMargin:"200px"}),this._observer.observe(this)}updated(o){if(o.has("src")&&this.src){this._loadImage(this.src);return}if(!this._image)return;[...o.keys()].some(i=>H.has(i))&&this._scheduleRender()}disconnectedCallback(){var o;super.disconnectedCallback(),(o=this._observer)==null||o.disconnect()}_loadImage(o){const r=new Image;r.crossOrigin="anonymous",r.onload=()=>{this._image=r,this._scheduleRender()},r.onerror=()=>{console.warn(`[some-shade] Failed to load image: ${o}`)},r.src=o}_scheduleRender(){this._visible?S(()=>this._renderEffect()):(this._needsRender=!0,requestAnimationFrame(()=>{if(this._needsRender&&!this._visible){const o=this.getBoundingClientRect();o.bottom>=0&&o.top<window.innerHeight&&(this._visible=!0,this._needsRender=!1,S(()=>this._renderEffect()))}}))}async _renderEffect(){var c;if(!this._image)return;const o=T(this.effect);if(!o){console.warn(`[some-shade] Unknown effect: ${this.effect}`);return}this._snapshotReady=!1;const r=Math.min(window.devicePixelRatio||1,G),i=this._image.naturalWidth,t=this._image.naturalHeight,n=this.clientWidth||i,f=Math.min(Math.round(n*r),i),_=Math.round(f*(t/i)),h=document.createElement("canvas");h.width=f,h.height=_;const s=U(h);if(!s){this._webglAvailable=!1;return}try{const d=z(s,o.vertexShader,o.fragmentShader);s.useProgram(d.program);const b=I(s,this._image),K=L(s,d);s.viewport(0,0,h.width,h.height),s.clearColor(0,0,0,0),s.clear(s.COLOR_BUFFER_BIT),s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,b.texture);const D=d.uniformLocations.get("u_image");D&&s.uniform1i(D,0),P(s,d,this._getUniformValues(f,_,r)),s.bindBuffer(s.ARRAY_BUFFER,K);const k=4*Float32Array.BYTES_PER_ELEMENT,y=d.attribLocations.get("a_position");y!==void 0&&y!==-1&&(s.enableVertexAttribArray(y),s.vertexAttribPointer(y,2,s.FLOAT,!1,k,0));const w=d.attribLocations.get("a_texCoord");w!==void 0&&w!==-1&&(s.enableVertexAttribArray(w),s.vertexAttribPointer(w,2,s.FLOAT,!1,k,2*Float32Array.BYTES_PER_ELEMENT)),V(s);const C=this.renderRoot.querySelector(".snapshot");if(C){C.width=f,C.height=_;const M=C.getContext("2d");M&&(M.drawImage(h,0,0),this._snapshotReady=!0)}s.deleteTexture(b.texture),s.deleteProgram(d.program),s.deleteBuffer(K)}finally{(c=s.getExtension("WEBGL_lose_context"))==null||c.loseContext()}}replayTransition(o=500){this._snapshotReady&&(this._snapshotReady=!1,this.updateComplete.then(()=>{setTimeout(()=>{this._snapshotReady=!0},o)}))}_getUniformValues(o,r,i){const t={};t.u_resolution=[o,r];const n=o/(this.referenceWidth*i);return t.u_dotRadius=this.dotRadius*n,t.u_gridSize=this.gridSize*n,this.effect==="halftone-cmyk"?(t.u_angleC=this.angleC,t.u_angleM=this.angleM,t.u_angleY=this.angleY,t.u_angleK=this.angleK,t.u_showC=this.showC,t.u_showM=this.showM,t.u_showY=this.showY,t.u_showK=this.showK,t.u_intensityK=this.intensityK):this.effect==="halftone-duotone"?(t.u_duotoneColor=this._parseHexColor(this.duotoneColor),t.u_angle=this.angle):this.effect==="dot-grid"?(t.u_dotOffset=[this.dotOffsetX,this.dotOffsetY],t.u_bgColor=this._parseHexColor(this.bgColor),t.u_angle=this.angle):this.effect==="technicolor-2strip"&&(t.u_angleWarm=this.angleWarm,t.u_angleCool=this.angleCool,t.u_angleK=this.angleK,t.u_showWarm=this.showWarm,t.u_showCool=this.showCool,t.u_showK=this.showK,t.u_warmColor=this._parseHexColor(this.warmColor),t.u_coolColor=this._parseHexColor(this.coolColor),t.u_blendMode=this.blendMode,t.u_intensityK=this.intensityK),t}_parseHexColor(o){const r=o.replace("#",""),i=parseInt(r.substring(0,2),16)/255,t=parseInt(r.substring(2,4),16)/255,n=parseInt(r.substring(4,6),16)/255;return[i,t,n]}};x.styles=p.css`
|
|
284
282
|
:host {
|
|
285
283
|
display: block;
|
|
286
284
|
position: relative;
|
|
@@ -295,7 +293,7 @@ void main() {
|
|
|
295
293
|
img.base {
|
|
296
294
|
opacity: 0;
|
|
297
295
|
}
|
|
298
|
-
|
|
296
|
+
canvas.snapshot {
|
|
299
297
|
position: absolute;
|
|
300
298
|
inset: 0;
|
|
301
299
|
width: 100%;
|
|
@@ -303,7 +301,7 @@ void main() {
|
|
|
303
301
|
opacity: 0;
|
|
304
302
|
transition: opacity 0.3s ease;
|
|
305
303
|
}
|
|
306
|
-
|
|
304
|
+
canvas.snapshot.ready {
|
|
307
305
|
opacity: 1;
|
|
308
306
|
}
|
|
309
|
-
`;let
|
|
307
|
+
`;let a=x;u([l.property()],a.prototype,"src"),u([l.property()],a.prototype,"effect"),u([l.property({type:Number,attribute:"dot-radius"})],a.prototype,"dotRadius"),u([l.property({type:Number,attribute:"grid-size"})],a.prototype,"gridSize"),u([l.property({type:Number,attribute:"angle-c"})],a.prototype,"angleC"),u([l.property({type:Number,attribute:"angle-m"})],a.prototype,"angleM"),u([l.property({type:Number,attribute:"angle-y"})],a.prototype,"angleY"),u([l.property({type:Number,attribute:"angle-k"})],a.prototype,"angleK"),u([l.property({type:Number,attribute:"show-c"})],a.prototype,"showC"),u([l.property({type:Number,attribute:"show-m"})],a.prototype,"showM"),u([l.property({type:Number,attribute:"show-y"})],a.prototype,"showY"),u([l.property({type:Number,attribute:"show-k"})],a.prototype,"showK"),u([l.property({type:Number,attribute:"intensity-k"})],a.prototype,"intensityK"),u([l.property({attribute:"duotone-color"})],a.prototype,"duotoneColor"),u([l.property({type:Number})],a.prototype,"angle"),u([l.property({type:Number,attribute:"dot-offset-x"})],a.prototype,"dotOffsetX"),u([l.property({type:Number,attribute:"dot-offset-y"})],a.prototype,"dotOffsetY"),u([l.property({attribute:"bg-color"})],a.prototype,"bgColor"),u([l.property({type:Number,attribute:"angle-warm"})],a.prototype,"angleWarm"),u([l.property({type:Number,attribute:"angle-cool"})],a.prototype,"angleCool"),u([l.property({type:Number,attribute:"show-warm"})],a.prototype,"showWarm"),u([l.property({type:Number,attribute:"show-cool"})],a.prototype,"showCool"),u([l.property({attribute:"warm-color"})],a.prototype,"warmColor"),u([l.property({attribute:"cool-color"})],a.prototype,"coolColor"),u([l.property({type:Number,attribute:"blend-mode"})],a.prototype,"blendMode"),u([l.property({type:Number,attribute:"reference-width"})],a.prototype,"referenceWidth"),u([l.state()],a.prototype,"_webglAvailable"),u([l.state()],a.prototype,"_snapshotReady"),customElements.get("some-shade-image")||customElements.define("some-shade-image",a),m.SomeShadeImage=a,m.get=T,m.list=B,m.register=g,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnfmorton/some-shade",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"homepage": "https://johnfmorton.github.io/some-shade-web-component/",
|
|
6
6
|
"repository": {
|
|
@@ -27,16 +27,16 @@
|
|
|
27
27
|
"README.md",
|
|
28
28
|
"CHANGELOG.md"
|
|
29
29
|
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"dev": "vite build --watch",
|
|
32
|
+
"build": "vite build"
|
|
33
|
+
},
|
|
30
34
|
"dependencies": {
|
|
31
35
|
"lit": "^3.2.0"
|
|
32
36
|
},
|
|
33
37
|
"devDependencies": {
|
|
34
38
|
"typescript": "^5.5.0",
|
|
35
|
-
"vite": "^6.
|
|
39
|
+
"vite": "^6.4.2",
|
|
36
40
|
"vite-plugin-dts": "^4.0.0"
|
|
37
|
-
},
|
|
38
|
-
"scripts": {
|
|
39
|
-
"dev": "vite build --watch",
|
|
40
|
-
"build": "vite build"
|
|
41
41
|
}
|
|
42
|
-
}
|
|
42
|
+
}
|