@pairbo/ui-kit 0.3.19 → 0.3.20

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.
Files changed (2) hide show
  1. package/dist/ui-kit.js +1 -1
  2. package/package.json +1 -1
package/dist/ui-kit.js CHANGED
@@ -2599,7 +2599,7 @@
2599
2599
  .type-canvas-container.image-loading pbo-image {
2600
2600
  display: block;
2601
2601
  }
2602
- `;var Up=Object.defineProperty,Wp=Object.getOwnPropertyDescriptor,Lt=(n,t,e,i)=>{for(var s=i>1?void 0:i?Wp(t,e):t,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(t,e,s):o(s))||s);return i&&s&&Up(t,e,s),s};let _t=class extends pt{constructor(){super(...arguments),this.backgroundImageUrl=void 0,this.message="",this.font="Arial",this.color="#000",this.alignment="left",this.scale=1,this.areaPosition={left:0,top:0},this.areaSize={width:0,height:0},this.imgLoading=!1,this.backgroundImage=void 0,this.resizeObserver=void 0}async handleBackgroundImageUrlChange(){this.imgLoading=!0,await this.appendBackgroundImageToCanvas(this.backgroundImageUrl??"",()=>{this.imgLoading=!1}),this.updateTextAreaPosition()}handleBackgroundImageChange(){if(!this.backgroundImage)return;const t=this.canvas.getContext("2d");if(!t)throw new Error("Could not get canvas context");t.drawImage(this.backgroundImage,0,0,this.canvas.width,this.canvas.height)}handleTextUpdate(){if(!this.backgroundImage)return;const t=this.canvas.getContext("2d");t&&(t.clearRect(0,0,this.canvas.width,this.canvas.height),t.drawImage(this.backgroundImage,0,0,this.canvas.width,this.canvas.height),this.wrapText(t,this.message,this.areaPosition,this.areaSize,12,this.alignment))}handleAreaUpdate(){this.backgroundImage&&this.handleTextUpdate()}firstUpdated(){this.resizeObserver=new ResizeObserver(()=>{this.updateTextAreaPosition()}),this.resizeObserver.observe(this.canvasContainer)}getMaxStringLength(t,e,i){let s=0;for(let r=1;r<=e.length;r++){const o=e.substring(0,r);if(t.measureText(o).width>i)break;s=r}return s}wrapText(t,e,i,s,r,o){const a=s.height/r,l=a/1.2,c=e.split(`
2602
+ `;var Up=Object.defineProperty,Wp=Object.getOwnPropertyDescriptor,Lt=(n,t,e,i)=>{for(var s=i>1?void 0:i?Wp(t,e):t,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(t,e,s):o(s))||s);return i&&s&&Up(t,e,s),s};let _t=class extends pt{constructor(){super(...arguments),this.backgroundImageUrl=void 0,this.message="",this.font="Arial",this.color="#000",this.alignment="left",this.scale=1,this.areaPosition={left:0,top:0},this.areaSize={width:0,height:0},this.imgLoading=!1,this.backgroundImage=void 0,this.resizeObserver=void 0}async handleBackgroundImageUrlChange(){this.imgLoading=!0,await this.appendBackgroundImageToCanvas(this.backgroundImageUrl??"",()=>{this.imgLoading=!1}),this.updateTextAreaPosition()}handleBackgroundImageChange(){if(!this.backgroundImage)return;const t=this.canvas.getContext("2d");if(!t)throw new Error("Could not get canvas context");t.drawImage(this.backgroundImage,0,0,this.canvas.width,this.canvas.height)}handleTextUpdate(){if(!this.backgroundImage)return;const t=this.canvas.getContext("2d");t&&(t.clearRect(0,0,this.canvas.width,this.canvas.height),t.drawImage(this.backgroundImage,0,0,this.canvas.width,this.canvas.height),this.wrapText(t,this.message,this.areaPosition,this.areaSize,12,this.alignment))}handleAreaUpdate(){this.backgroundImage&&this.handleTextUpdate()}firstUpdated(){this.resizeObserver=new ResizeObserver(()=>{this.updateTextAreaPosition()}),this.resizeObserver.observe(this.canvasContainer)}getMaxStringLength(t,e,i){let s=0;for(let r=1;r<=e.length;r++){const o=e.substring(0,r);if(t.measureText(o).width>i)break;s=r}return s}wrapText(t,e,i,s,r,o){if(!t||!e||!i||!s)return;const a=s.height/r,l=a/1.2,c=e.split(`
2603
2603
  `);let h=[];t.font=`${l}px ${this.font}`,c.forEach(u=>{const p=u.split(" ");let g="";for(let f=0;f<p.length;f++)if(t.measureText(p[f]).width>s.width){const y=this.getMaxStringLength(t,p[f],s.width),w=p[f];f+1<p.length?(p[f]=w.substring(0,y),p[f+1]=w.substring(y,w.length)+p[f+1]):(p[f]=w.substring(0,y),p.push(w.substring(y,w.length)))}for(let f=0;f<p.length;f++){let b=g+p[f]+" ";t.measureText(b).width>s.width&&f>0?(h.push(g),g=p[f]+" "):g=b}h.push(g)});let d=i.left;o==="center"&&(d+=s.width/2),o==="right"&&(d+=s.width);for(let u=0;u<r&&u<h.length;u++){const p=h[u];t.fillStyle=this.color,t.textAlign=o,t.fillText(p,d,i.top+(u+1)*a)}}updateTextAreaPosition(){if(!this.canvas||!this.backgroundImage)return;const t=this.canvasContainer.clientWidth;this.scale=t/this.backgroundImage.width,this.canvas.width=this.backgroundImage.width*this.scale,this.canvas.height=this.backgroundImage.height*this.scale;const e=this.canvas.getContext("2d");e&&e.drawImage(this.backgroundImage,0,0,this.canvas.width,this.canvas.height),this.areaPosition={left:.084*this.canvas.width,top:.4874*this.canvas.height},this.areaSize={width:.832*this.canvas.width,height:this.canvas.height-this.areaPosition.top-this.areaPosition.left}}async appendBackgroundImageToCanvas(t,e){return new Promise((i,s)=>{const r=new Image;r.onerror=()=>{s(new Error("Failed to load image"))},r.onload=()=>{this.backgroundImage=r,e&&e(),i()},r.src=t})}render(){return L`
2604
2604
  <div
2605
2605
  class="${pe({"type-canvas-container":!0,"image-loading":this.imgLoading})}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pairbo/ui-kit",
3
- "version": "0.3.19",
3
+ "version": "0.3.20",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "readme": "./README-NPM.md",