@patternfly/pfe-avatar
Advanced tools
Comparing version 2.0.0-next.0 to 2.0.0-next.1
{ | ||
"name": "@patternfly/pfe-avatar", | ||
"license": "MIT", | ||
"version": "2.0.0-next.0", | ||
"version": "2.0.0-next.1", | ||
"customElements": "custom-elements.json", | ||
@@ -11,10 +11,4 @@ "type": "module", | ||
"exports": { | ||
".": { | ||
"esbuild": "./pfe-avatar.ts", | ||
"default": "./pfe-avatar.js" | ||
}, | ||
"./*": { | ||
"esbuild": "./*.ts", | ||
"default": "./*.js" | ||
} | ||
".": "./pfe-avatar.js", | ||
"./*": "./*.js" | ||
}, | ||
@@ -75,5 +69,5 @@ "publishConfig": { | ||
"dependencies": { | ||
"@patternfly/pfe-core": "^2.0.0-next.0", | ||
"@patternfly/pfe-core": "^2.0.0-next.3", | ||
"lit": "^2.1.2" | ||
} | ||
} |
@@ -1,55 +0,2 @@ | ||
var V=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var u=(n,e,t,r)=>{for(var i=r>1?void 0:r?z(e,t):e,a=n.length-1,l;a>=0;a--)(l=n[a])&&(i=(r?l(e,t,i):l(i))||i);return r&&i&&V(e,t,i),i};import{LitElement as B,html as k}from"lit";import{property as _,customElement as G,query as j}from"lit/decorators.js";import{ifDefined as E}from"lit/directives/if-defined.js";import{Logger as q}from"@patternfly/pfe-core/controllers/logger.js";import{CssVariableController as I}from"@patternfly/pfe-core/controllers/css-variable-controller.js";import{pfelement as L,bound as $,observed as x}from"@patternfly/pfe-core/decorators.js";import{deprecatedCustomEvent as F}from"@patternfly/pfe-core/functions/deprecatedCustomEvent.js";function S(n){let e=5381,t=n.length;for(;t;)e=e*33^n.charCodeAt(--t);return e>>>0}function b(n,e,t){return t<0&&(t+=1),t>1&&(t-=1),6*t<1?n+(e-n)*6*t:2*t<1?e:3*t<2?n+(e-n)*(2/3-t)*6:n}function y(n,e,t){let r,i,a,l=Math.max(0,Math.min(1,n)),c=Math.max(0,Math.min(1,e)),o=Math.max(0,Math.min(1,t));if(c===0)r=o*255,i=o*255,a=o*255;else{let d,h;o<.5?h=o*(1+c):h=o+c-c*o,d=2*o-h,r=Math.floor(255*b(d,h,l+1/3)),i=Math.floor(255*b(d,h,l)),a=Math.floor(255*b(d,h,l-1/3))}return[r,i,a]}function C(n,e,t){let r,i,a,l=Math.max(0,Math.min(255,n)),c=Math.max(0,Math.min(255,e)),o=Math.max(0,Math.min(255,t)),d=l/255,h=c/255,f=o/255,g=Math.min(Math.min(d,h),f),p=Math.max(Math.max(d,h),f),m=p-g;if(a=(p+g)/2,m===0)r=0,i=0;else{a<.5?i=m/(p+g):i=m/(2-p-g);let v=((p-d)/6+m/2)/m,w=((p-h)/6+m/2)/m,M=((p-f)/6+m/2)/m;d===p?r=M-w:h===p?r=1/3+v-M:f===p&&(r=2/3+w-v),r??(r=0),r<0?r+=1:r>1&&(r-=1)}return[r,i,a]}import{css as D}from"lit";var R=D`:host { | ||
display: block; | ||
position: relative; | ||
width: var(--pfe-avatar--size, var(--pfe-avatar--width, 128px)); | ||
height: var(--pfe-avatar--size, var(--pfe-avatar--width, 128px)); | ||
} | ||
canvas { | ||
width: 100%; | ||
height: 100%; | ||
image-rendering: optimizeSpeed; | ||
/* Older versions of FF */ | ||
image-rendering: -moz-crisp-edges; | ||
/* FF 6.0+ */ | ||
image-rendering: -webkit-optimize-contrast; | ||
/* Safari */ | ||
image-rendering: -o-crisp-edges; | ||
/* OS X & Windows Opera (12.02+) */ | ||
image-rendering: pixelated; | ||
/* Awesome future-browsers */ | ||
-ms-interpolation-mode: nearest-neighbor; | ||
/* IE */ | ||
} | ||
:host([shape=rounded]) img, | ||
:host([shape=rounded]) canvas { | ||
border-radius: calc(var(--pfe-avatar--size, var(--pfe-avatar--width, 128px)) / 8 + 1px); | ||
} | ||
:host([shape=circle]) img, | ||
:host([shape=circle]) canvas { | ||
border-radius: 50%; | ||
} | ||
:host([src]) canvas { | ||
display: none; | ||
} | ||
:host([src]) img { | ||
display: block; | ||
width: 100%; | ||
height: 100%; | ||
object-fit: cover; | ||
} | ||
:host(:not([src])) img { | ||
display: none; | ||
} | ||
:host([hidden]) { | ||
display: none; | ||
}`,T=R;function O(n){n.registerColors()}var s=class extends B{constructor(){super(...arguments);this.name="";this.pattern="squares";this.shape="square";this._squareSize=0;this._triangleSize=0;this._colorIndex=-1;this.color1="";this.color2="";this.css=new I(this)}static _registerColor(e){s.colors.push({color1:`rgb(${e.join(",")})`,color2:`rgb(${this._adjustColor(e).join(",")})`})}static _adjustColor(e){let i=C(...e);return i[2]+=i[2]>.1?-.1:.1,y(...i)}static registerColors(){return s.colors=[],(this.customColors||this.defaultColors).split(/\s+/).forEach(t=>{let r;switch(t.length){case 4:if(r=/^#([A-f0-9])([A-f0-9])([A-f0-9])$/.exec(t),r){r.shift();let i=r.map(a=>parseInt(a+a,16));s._registerColor(i)}else q.log(`[pfe-avatar] invalid color ${t}`);break;case 7:if(r=/^#([A-f0-9]{2})([A-f0-9]{2})([A-f0-9]{2})$/.exec(t),r){r.shift();let i=r.map(a=>parseInt(a,16));s._registerColor(i)}else q.log(`[pfe-avatar] invalid color ${t}`)}}),this.colors}get customColors(){return this.css.getVariable("pfe-avatar--colors")}render(){return k` | ||
<canvas part="canvas"></canvas> | ||
<img src="${E(this.src)}" alt="" part="img"/> | ||
`}firstUpdated(){this._initCanvas(),this.dispatchEvent(F("pfe-avatar:connected"))}_initCanvas(){if(!this._canvas)throw new Error("canvas unavailable");let e=this.css.getVariable("pfe-avatar--width"),t=parseInt(e??s.defaultSize.toString());this._canvas.width=t,this._canvas.height=t,this._squareSize=this._canvas.width/8,this._triangleSize=this._canvas.width/4,this._ctx=this._canvas.getContext("2d"),this._update()}_update(){if(!this.src){let e=S(this.name).toString(2),t=e.split("").map(r=>Number(r));this._colorIndex=Math.floor(s.colors.length*parseInt(e,2)/Math.pow(2,32)),this.color1=s.colors[this._colorIndex].color1,this.color2=s.colors[this._colorIndex].color2,this._clear(),this._drawBackground(),this.pattern==="squares"?this._drawSquarePattern(t):this.pattern==="triangles"&&this._drawTrianglePattern(t)}}_clear(){this._ctx&&this._canvas&&this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height)}_drawBackground(){this._ctx&&this._canvas&&(this._ctx.fillStyle=this.color1,this._ctx.fillRect(0,0,this._canvas.width,this._canvas.height))}_drawSquarePattern(e){if(this._ctx){this._ctx.fillStyle=this.color2;let t=e.length;for(;t--;)e[t]&&this._drawMirroredSquare(t%4,Math.floor(t/4))}}_drawMirroredSquare(e,t){this._ctx&&(this._drawSquare(e,t),this._drawSquare(7-e,t))}_drawSquare(e,t){this._ctx&&this._ctx.fillRect(this._squareSize*e,this._squareSize*t,this._squareSize,this._squareSize)}_drawTrianglePattern(e){if(this._ctx){this._ctx.fillStyle=this.color2??"";let t=e.length;for(;t--;)if(e[t]){let r=Math.floor(t/2)%2,i=Math.floor(t/4),a=t%4,l=[r,i],c=[r,i],o=[r,i];switch(a){case 0:c[1]++,o[0]++,o[1]++;break;case 1:c[0]++,o[0]++,o[1]++;break;case 2:c[0]++,o[1]++;break;case 3:l[0]++,c[0]++,c[1]++,o[1]++;break}this._drawMirroredTriangle(l,c,o)}}}_drawMirroredTriangle(e,t,r){this._ctx&&(this._drawTriangle(e,t,r),this._drawTriangle([4-e[0],e[1]],[4-t[0],t[1]],[4-r[0],r[1]]))}_drawTriangle(e,t,r){let i=a=>a*this._triangleSize;this._ctx&&(this._ctx.beginPath(),this._ctx.moveTo(...e.map(i)),this._ctx.lineTo(...t.map(i)),this._ctx.lineTo(...r.map(i)),this._ctx.closePath(),this._ctx.fill(),this._ctx.fill())}};s.version="2.0.0-next.0",s.styles=T,s.defaultSize=128,s.defaultColors="#67accf #448087 #709c6b #a35252 #826cbb",s.colors=[],u([x("_update"),_({reflect:!0})],s.prototype,"src",2),u([x("_update"),_({reflect:!0})],s.prototype,"name",2),u([x("_update"),_({reflect:!0})],s.prototype,"pattern",2),u([_({reflect:!0})],s.prototype,"shape",2),u([j("canvas")],s.prototype,"_canvas",2),u([$],s.prototype,"_initCanvas",1),s=u([G("pfe-avatar"),L(),O],s);export{s as PfeAvatar}; | ||
var V=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var u=(n,e,t,r)=>{for(var i=r>1?void 0:r?z(e,t):e,a=n.length-1,l;a>=0;a--)(l=n[a])&&(i=(r?l(e,t,i):l(i))||i);return r&&i&&V(e,t,i),i};import{LitElement as B,html as k}from"lit";import{property as _,customElement as G,query as j}from"lit/decorators.js";import{ifDefined as L}from"lit/directives/if-defined.js";import{Logger as q}from"@patternfly/pfe-core/controllers/logger.js";import{CssVariableController as E}from"@patternfly/pfe-core/controllers/css-variable-controller.js";import{pfelement as I,bound as $,observed as x}from"@patternfly/pfe-core/decorators.js";import{deprecatedCustomEvent as N}from"@patternfly/pfe-core/functions/deprecatedCustomEvent.js";function S(n){let e=5381,t=n.length;for(;t;)e=e*33^n.charCodeAt(--t);return e>>>0}function b(n,e,t){return t<0&&(t+=1),t>1&&(t-=1),6*t<1?n+(e-n)*6*t:2*t<1?e:3*t<2?n+(e-n)*(2/3-t)*6:n}function y(n,e,t){let r,i,a,l=Math.max(0,Math.min(1,n)),c=Math.max(0,Math.min(1,e)),o=Math.max(0,Math.min(1,t));if(c===0)r=o*255,i=o*255,a=o*255;else{let d,h;o<.5?h=o*(1+c):h=o+c-c*o,d=2*o-h,r=Math.floor(255*b(d,h,l+1/3)),i=Math.floor(255*b(d,h,l)),a=Math.floor(255*b(d,h,l-1/3))}return[r,i,a]}function C(n,e,t){let r,i,a,l=Math.max(0,Math.min(255,n)),c=Math.max(0,Math.min(255,e)),o=Math.max(0,Math.min(255,t)),d=l/255,h=c/255,f=o/255,g=Math.min(Math.min(d,h),f),p=Math.max(Math.max(d,h),f),m=p-g;if(a=(p+g)/2,m===0)r=0,i=0;else{a<.5?i=m/(p+g):i=m/(2-p-g);let v=((p-d)/6+m/2)/m,w=((p-h)/6+m/2)/m,M=((p-f)/6+m/2)/m;d===p?r=M-w:h===p?r=1/3+v-M:f===p&&(r=2/3+w-v),r??(r=0),r<0?r+=1:r>1&&(r-=1)}return[r,i,a]}import{css as D}from"lit";var R=D`:host{display:block;position:relative;width:var(--pfe-avatar--size,var(--pfe-avatar--width,128px));height:var(--pfe-avatar--size,var(--pfe-avatar--width,128px))}canvas{width:100%;height:100%;image-rendering:optimizeSpeed;image-rendering:-moz-crisp-edges;image-rendering:-webkit-optimize-contrast;image-rendering:-o-crisp-edges;image-rendering:pixelated;-ms-interpolation-mode:nearest-neighbor}:host([shape=rounded]) canvas,:host([shape=rounded]) img{border-radius:calc(var(--pfe-avatar--size,var(--pfe-avatar--width,128px))/ 8 + 1px)}:host([shape=circle]) canvas,:host([shape=circle]) img{border-radius:50%}:host([src]) canvas{display:none}:host([src]) img{display:block;width:100%;height:100%;object-fit:cover}:host(:not([src])) img{display:none}:host([hidden]){display:none}`,T=R;function U(n){n.registerColors()}var s=class extends B{constructor(){super(...arguments);this.name="";this.pattern="squares";this.shape="square";this._squareSize=0;this._triangleSize=0;this._colorIndex=-1;this.color1="";this.color2="";this.css=new E(this)}static _registerColor(e){s.colors.push({color1:`rgb(${e.join(",")})`,color2:`rgb(${this._adjustColor(e).join(",")})`})}static _adjustColor(e){let i=C(...e);return i[2]+=i[2]>.1?-.1:.1,y(...i)}static registerColors(){return s.colors=[],(this.customColors||this.defaultColors).split(/\s+/).forEach(t=>{let r;switch(t.length){case 4:if(r=/^#([A-f0-9])([A-f0-9])([A-f0-9])$/.exec(t),r){r.shift();let i=r.map(a=>parseInt(a+a,16));s._registerColor(i)}else q.log(`[pfe-avatar] invalid color ${t}`);break;case 7:if(r=/^#([A-f0-9]{2})([A-f0-9]{2})([A-f0-9]{2})$/.exec(t),r){r.shift();let i=r.map(a=>parseInt(a,16));s._registerColor(i)}else q.log(`[pfe-avatar] invalid color ${t}`)}}),this.colors}get customColors(){return this.css.getVariable("pfe-avatar--colors")}render(){return k`<canvas part="canvas"></canvas><img src="${L(this.src)}" alt="" part="img">`}firstUpdated(){this._initCanvas(),this.dispatchEvent(N("pfe-avatar:connected"))}_initCanvas(){if(!this._canvas)throw new Error("canvas unavailable");let e=this.css.getVariable("pfe-avatar--width"),t=parseInt(e??s.defaultSize.toString());this._canvas.width=t,this._canvas.height=t,this._squareSize=this._canvas.width/8,this._triangleSize=this._canvas.width/4,this._ctx=this._canvas.getContext("2d"),this._update()}_update(){if(!this.src){let e=S(this.name).toString(2),t=e.split("").map(r=>Number(r));this._colorIndex=Math.floor(s.colors.length*parseInt(e,2)/Math.pow(2,32)),this.color1=s.colors[this._colorIndex].color1,this.color2=s.colors[this._colorIndex].color2,this._clear(),this._drawBackground(),this.pattern==="squares"?this._drawSquarePattern(t):this.pattern==="triangles"&&this._drawTrianglePattern(t)}}_clear(){this._ctx&&this._canvas&&this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height)}_drawBackground(){this._ctx&&this._canvas&&(this._ctx.fillStyle=this.color1,this._ctx.fillRect(0,0,this._canvas.width,this._canvas.height))}_drawSquarePattern(e){if(this._ctx){this._ctx.fillStyle=this.color2;let t=e.length;for(;t--;)e[t]&&this._drawMirroredSquare(t%4,Math.floor(t/4))}}_drawMirroredSquare(e,t){this._ctx&&(this._drawSquare(e,t),this._drawSquare(7-e,t))}_drawSquare(e,t){this._ctx&&this._ctx.fillRect(this._squareSize*e,this._squareSize*t,this._squareSize,this._squareSize)}_drawTrianglePattern(e){if(this._ctx){this._ctx.fillStyle=this.color2??"";let t=e.length;for(;t--;)if(e[t]){let r=Math.floor(t/2)%2,i=Math.floor(t/4),a=t%4,l=[r,i],c=[r,i],o=[r,i];switch(a){case 0:c[1]++,o[0]++,o[1]++;break;case 1:c[0]++,o[0]++,o[1]++;break;case 2:c[0]++,o[1]++;break;case 3:l[0]++,c[0]++,c[1]++,o[1]++;break}this._drawMirroredTriangle(l,c,o)}}}_drawMirroredTriangle(e,t,r){this._ctx&&(this._drawTriangle(e,t,r),this._drawTriangle([4-e[0],e[1]],[4-t[0],t[1]],[4-r[0],r[1]]))}_drawTriangle(e,t,r){let i=a=>a*this._triangleSize;this._ctx&&(this._ctx.beginPath(),this._ctx.moveTo(...e.map(i)),this._ctx.lineTo(...t.map(i)),this._ctx.lineTo(...r.map(i)),this._ctx.closePath(),this._ctx.fill(),this._ctx.fill())}};s.version="{{version}}",s.styles=T,s.defaultSize=128,s.defaultColors="#67accf #448087 #709c6b #a35252 #826cbb",s.colors=[],u([x("_update"),_({reflect:!0})],s.prototype,"src",2),u([x("_update"),_({reflect:!0})],s.prototype,"name",2),u([x("_update"),_({reflect:!0})],s.prototype,"pattern",2),u([_({reflect:!0})],s.prototype,"shape",2),u([j("canvas")],s.prototype,"_canvas",2),u([$],s.prototype,"_initCanvas",1),s=u([G("pfe-avatar"),I(),U],s);export{s as PfeAvatar}; | ||
//# sourceMappingURL=pfe-avatar.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
43382
597