New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@flourish/pocket-knife

Package Overview
Dependencies
Maintainers
0
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@flourish/pocket-knife - npm Package Compare versions

Comparing version 2.1.1 to 2.2.0

src/base-64-encode.js

2

package.json
{
"name": "@flourish/pocket-knife",
"type": "module",
"version": "2.1.1",
"version": "2.2.0",
"private": false,

@@ -6,0 +6,0 @@ "description": "Flourish module with handy tools",

@@ -751,2 +751,12 @@ (function (global, factory) {

function encodeBase64(str) {
return btoa(String.fromCharCode(...new TextEncoder().encode(str)));
}
function decodeBase64(str) {
return new TextDecoder().decode(
Uint8Array.from(atob(str), (c) => c.charCodeAt(0)),
);
}
const canvas = document.createElement("canvas");

@@ -984,2 +994,4 @@ const ctx = canvas.getContext("2d");

exports.createScreenshotSVG = createScreenshotSVG;
exports.decodeBase64 = decodeBase64;
exports.encodeBase64 = encodeBase64;
exports.getTextDimensions = getTextDimensions;

@@ -986,0 +998,0 @@ exports.getTextDirection = getTextDirection;

@@ -1,1 +0,1 @@

(function(t,e){typeof exports==="object"&&typeof module!=="undefined"?e(exports):typeof define==="function"&&define.amd?define(["exports"],e):(t=typeof globalThis!=="undefined"?globalThis:t||self,e(t.pocketKnife={}))})(this,function(t){"use strict";function e(t,e,n){t.prototype=e.prototype=n;n.constructor=t}function n(t,e){var n=Object.create(t.prototype);for(var r in e)n[r]=e[r];return n}function u(){}var r=.7;var i=1/r;var s="\\s*([+-]?\\d+)\\s*",o="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",a="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",j=/^#([0-9a-f]{3,8})$/,z=new RegExp(`^rgb\\(${s},${s},${s}\\)$`),F=new RegExp(`^rgb\\(${a},${a},${a}\\)$`),O=new RegExp(`^rgba\\(${s},${s},${s},${o}\\)$`),P=new RegExp(`^rgba\\(${a},${a},${a},${o}\\)$`),I=new RegExp(`^hsl\\(${o},${a},${a}\\)$`),L=new RegExp(`^hsla\\(${o},${a},${a},${o}\\)$`);var l={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};e(u,d,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:c,formatHex:c,formatHex8:D,formatHsl:G,formatRgb:h,toString:h});function c(){return this.rgb().formatHex()}function D(){return this.rgb().formatHex8()}function G(){return $(this).formatHsl()}function h(){return this.rgb().formatRgb()}function d(t){var e,n;t=(t+"").trim().toLowerCase();return(e=j.exec(t))?(n=e[1].length,e=parseInt(e[1],16),n===6?f(e):n===3?new p(e>>8&15|e>>4&240,e>>4&15|e&240,(e&15)<<4|e&15,1):n===8?g(e>>24&255,e>>16&255,e>>8&255,(e&255)/255):n===4?g(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|e&240,((e&15)<<4|e&15)/255):null):(e=z.exec(t))?new p(e[1],e[2],e[3],1):(e=F.exec(t))?new p(e[1]*255/100,e[2]*255/100,e[3]*255/100,1):(e=O.exec(t))?g(e[1],e[2],e[3],e[4]):(e=P.exec(t))?g(e[1]*255/100,e[2]*255/100,e[3]*255/100,e[4]):(e=I.exec(t))?v(e[1],e[2]/100,e[3]/100,1):(e=L.exec(t))?v(e[1],e[2]/100,e[3]/100,e[4]):l.hasOwnProperty(t)?f(l[t]):t==="transparent"?new p(NaN,NaN,NaN,0):null}function f(t){return new p(t>>16&255,t>>8&255,t&255,1)}function g(t,e,n,r){if(r<=0)t=e=n=NaN;return new p(t,e,n,r)}function V(t){if(!(t instanceof u))t=d(t);if(!t)return new p;t=t.rgb();return new p(t.r,t.g,t.b,t.opacity)}function W(t,e,n,r){return arguments.length===1?V(t):new p(t,e,n,r==null?1:r)}function p(t,e,n,r){this.r=+t;this.g=+e;this.b=+n;this.opacity=+r}e(p,W,n(u,{brighter(t){t=t==null?i:Math.pow(i,t);return new p(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){t=t==null?r:Math.pow(r,t);return new p(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new p(b(this.r),b(this.g),b(this.b),m(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&(-.5<=this.g&&this.g<255.5)&&(-.5<=this.b&&this.b<255.5)&&(0<=this.opacity&&this.opacity<=1)},hex:w,formatHex:w,formatHex8:U,formatRgb:y,toString:y}));function w(){return`#${x(this.r)}${x(this.g)}${x(this.b)}`}function U(){return`#${x(this.r)}${x(this.g)}${x(this.b)}${x((isNaN(this.opacity)?1:this.opacity)*255)}`}function y(){const t=m(this.opacity);return`${t===1?"rgb(":"rgba("}${b(this.r)}, ${b(this.g)}, ${b(this.b)}${t===1?")":`, ${t})`}`}function m(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function b(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function x(t){t=b(t);return(t<16?"0":"")+t.toString(16)}function v(t,e,n,r){if(r<=0)t=e=n=NaN;else if(n<=0||n>=1)t=e=NaN;else if(e<=0)t=NaN;return new k(t,e,n,r)}function $(t){if(t instanceof k)return new k(t.h,t.s,t.l,t.opacity);if(!(t instanceof u))t=d(t);if(!t)return new k;if(t instanceof k)return t;t=t.rgb();var e=t.r/255,n=t.g/255,r=t.b/255,i=Math.min(e,n,r),s=Math.max(e,n,r),o=NaN,a=s-i,l=(s+i)/2;if(a){if(e===s)o=(n-r)/a+(n<r)*6;else if(n===s)o=(r-e)/a+2;else o=(e-n)/a+4;a/=l<.5?s+i:2-s-i;o*=60}else{a=l>0&&l<1?0:o}return new k(o,a,l,t.opacity)}function K(t,e,n,r){return arguments.length===1?$(t):new k(t,e,n,r==null?1:r)}function k(t,e,n,r){this.h=+t;this.s=+e;this.l=+n;this.opacity=+r}e(k,K,n(u,{brighter(t){t=t==null?i:Math.pow(i,t);return new k(this.h,this.s,this.l*t,this.opacity)},darker(t){t=t==null?r:Math.pow(r,t);return new k(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+(this.h<0)*360,e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*e,i=2*n-r;return new p(S(t>=240?t-240:t+120,i,r),S(t,i,r),S(t<120?t+240:t-120,i,r),this.opacity)},clamp(){return new k(N(this.h),A(this.s),A(this.l),m(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&(0<=this.l&&this.l<=1)&&(0<=this.opacity&&this.opacity<=1)},formatHsl(){const t=m(this.opacity);return`${t===1?"hsl(":"hsla("}${N(this.h)}, ${A(this.s)*100}%, ${A(this.l)*100}%${t===1?")":`, ${t})`}`}}));function N(t){t=(t||0)%360;return t<0?t+360:t}function A(t){return Math.max(0,Math.min(1,t||0))}function S(t,e,n){return(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)*255}var C="$";function E(){}E.prototype=T.prototype={constructor:E,has:function(t){return C+t in this},get:function(t){return this[C+t]},set:function(t,e){this[C+t]=e;return this},remove:function(t){var e=C+t;return e in this&&delete this[e]},clear:function(){for(var t in this)if(t[0]===C)delete this[t]},keys:function(){var t=[];for(var e in this)if(e[0]===C)t.push(e.slice(1));return t},values:function(){var t=[];for(var e in this)if(e[0]===C)t.push(this[e]);return t},entries:function(){var t=[];for(var e in this)if(e[0]===C)t.push({key:e.slice(1),value:this[e]});return t},size:function(){var t=0;for(var e in this)if(e[0]===C)++t;return t},empty:function(){for(var t in this)if(t[0]===C)return false;return true},each:function(t){for(var e in this)if(e[0]===C)t(this[e],e.slice(1),this)}};function T(t,e){var n=new E;if(t instanceof E)t.each(function(t,e){n.set(e,t)});else if(Array.isArray(t)){var r=-1,i=t.length,s;if(e==null)while(++r<i)n.set(r,t[r]);else while(++r<i)n.set(e(s=t[r],r,t),s)}else if(t)for(var o in t)n.set(o,t[o]);return n}function M(){}var q=T.prototype;M.prototype=J.prototype={constructor:M,has:q.has,add:function(t){t+="";this[C+t]=t;return this},remove:q.remove,clear:q.clear,values:q.keys,size:q.size,empty:q.empty,each:q.each};function J(t,e){var n=new M;if(t instanceof M)t.each(function(t){n.add(t)});else if(t){var r=-1,i=t.length;if(e==null)while(++r<i)n.add(t[r]);else while(++r<i)n.add(e(t[r],r,t))}return n}function Q(b,t){if(typeof b=="string")b=document.querySelector(b);if(!b){console.error("No valid target in createScreenshotSVG");return null}const{width:e,height:n,x:r,y:i}=b.getBoundingClientRect();const x=document.createElementNS("http://www.w3.org/2000/svg","svg");x.id=t;x.classList.add("flourish-screenshot-svg-container");x.style.left=r+"px";x.style.top=i+"px";x.style.width=e+"px";x.style.height=n+"px";x.style.position="absolute";b.appendChild(x);function s(t){if(typeof t=="string")t=b.querySelectorAll(t);if(!t){console.error("No valid els inside addTextElements");return null}for(const n of t){const{x:r,y:t,width:e}=n.getBoundingClientRect();const i=document.createElementNS("http://www.w3.org/2000/svg","text");const{color:s,"font-family":o,"font-size":a,"font-weight":l,"line-height":u,"padding-left":c,"padding-top":h}=window.getComputedStyle(n);const d=`${l} ${a} ${o}`;const f=ot(n.innerText,d,null,Math.ceil(e));const g=isNaN(parseFloat(u))?parseFloat(a)*1.2+"px":u;const p=window.getComputedStyle(n.closest("[style*='opacity']")||n).opacity;f.forEach((t,e)=>{const n=document.createElementNS("http://www.w3.org/2000/svg","tspan");n.innerHTML=t;n.setAttribute("dy",e===0?parseFloat(h):g);n.setAttribute("dx",parseFloat(c));n.setAttribute("x",r);n.setAttribute("opacity",p);i.appendChild(n)});i.style.dominantBaseline="text-before-edge";i.setAttribute("x",r+"px");i.setAttribute("y",t+"px");i.setAttribute("font-family",o);i.setAttribute("font-size",a);i.setAttribute("font-weight",l);i.setAttribute("fill",s);x.appendChild(i)}return this}function o(t){if(typeof t=="string")t=b.querySelectorAll(t);if(!t){console.error("No valid els inside addCircleElements");return null}for(const r of t){const i=document.createElementNS("http://www.w3.org/2000/svg","circle");const{x:t,y:e,width:n}=r.getBoundingClientRect();const s=window.getComputedStyle(r)["background-color"];const o=window.getComputedStyle(r.closest("[style*='opacity']")||r).opacity;const a=n/2;i.setAttribute("cx",t+a+"px");i.setAttribute("cy",e+a+"px");i.setAttribute("r",a+"px");i.setAttribute("opacity",o);i.setAttribute("fill",s);if(s==="rgba(0, 0, 0, 0)")i.setAttribute("stroke","#CCC");x.appendChild(i)}return this}function a(t,s){if(typeof t=="string")t=b.querySelectorAll(t);if(!t){console.error("No valid els inside addSwatchElements");return null}if(typeof s=="string")s=b.querySelectorAll(s);for(const[o,a]of t.entries()){const l=document.createElementNS("http://www.w3.org/2000/svg","rect");const{x:t,y:e,width:n,height:r}=a.getBoundingClientRect();const u=s[o]?.getBoundingClientRect()?.y;const c=window.getComputedStyle(a)["background-color"];const h=window.getComputedStyle(a).border;const[,d,f,g,p]=h.replace(/\s/g,"").match(/rgba?\((\d+(?:\.\d+)?),(\d+(?:\.\d+)?),(\d+(?:\.\d+)?)(?:,(\d+(?:\.\d+)?))?\)/i);const w=p?`rgba(${d},${f},${g},${p})`:`rgb(${d},${f},${g})`||"#000";const y=h.split(" ")[0]||0;let i=window.getComputedStyle(a)["border-radius"]||0;i=parseFloat(i);const m=window.getComputedStyle(a.closest("[style*='opacity']")||a).opacity;l.setAttribute("x",t);l.setAttribute("y",u||e);l.setAttribute("width",`${n}px`);l.setAttribute("height",`${r}px`);l.setAttribute("rx",i);l.setAttribute("ry",i);l.setAttribute("opacity",m);l.setAttribute("fill",c);l.setAttribute("stroke",w);l.setAttribute("stroke-width",y);if(c==="rgba(0, 0, 0, 0)")l.setAttribute("stroke","#CCC");x.appendChild(l)}return this}function l(t,e,n){if(typeof t=="string")t=b.querySelector(t);if(!t){console.error("No valid els inside addCircleElements");return null}const r=document.createElementNS("http://www.w3.org/2000/svg","g");const{x:i,y:s,width:o,height:a}=t.getBoundingClientRect();const{max:l,min:u}=n;const c=l-u;for(let t=0;t<=o;t++){const h=document.createElementNS("http://www.w3.org/2000/svg","line");h.setAttribute("stroke",e(u+t*c/o));h.setAttribute("x1",t+i);h.setAttribute("y1",s);h.setAttribute("x2",t+i);h.setAttribute("y2",a+s);r.appendChild(h)}x.appendChild(r);return this}function u(){x.remove()}return{addTextElements:s,addCircleElements:o,addSwatchElements:a,addGradient:l,remove:u}}function X(t){if(typeof t!="string")return false;return t.match(/^(https?:\/\/.+\.(jpg|jpeg|svg|png|gif|webp)$|data:image\/)/i)!=null}function Y(t){if(typeof t!="string")return false;return t.match(/^(https?:\/\/|data:)/i)!=null}const Z=document.createElement("canvas");const R=Z.getContext("2d");function tt(t){var e,n;if(window.innerWidth!==e){e=window.innerWidth;n=parseFloat(getComputedStyle(document.documentElement).fontSize)}return t*n}function B(t,e){R.font=e||"10px sans-serif";var n=R.measureText(t);return{width:n.width,height:n.actualBoundingBoxAscent+n.actualBoundingBoxDescent}}function et(t,e){return B(t,e).width}function nt(t,e){return B(t,e).height}function rt(){return window.getComputedStyle(document.body).direction||"ltr"}function H(t,e){if(typeof t!="string")return false;var n=d(t);n.opacity=e!==undefined?e:1;return n}function it(t,e){var n=H(t,e);return n?n.toString():false}function _(t){return t<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4)}function st(t){if(!t){console.warn("No valid color",t);return}const e=H(t);const n=_(e.r/255)*.2126+_(e.g/255)*.7152+_(e.b/255)*.0722;const r=1>n?(n+.05)/1.05:1.05/(n+.05);const i=0>n?(n+.05)/.05:.05/(n+.05);return r>i?true:false}function ot(t,e,n,r,i=true){if(typeof t!=="string")t=String(t);const s=t=>R.measureText(t).width>r;const o=(t,e)=>{let n=R.measureText(t).width;if(n<=e){return t}let r=1;let i=t;do{i=t.substring(0,t.length-r)+"…";n=R.measureText(i).width}while(n>e&&++r<t.length);if(i.length<1)i=t.substring(0,1)+"…";return i};R.font=e;let a=[];Object.defineProperty(a,"widest_line",{value:0,enumerable:true,writable:true});Object.defineProperty(a,"has_truncated",{value:false,enumerable:true,writable:true});if(typeof t==="undefined"||Number.isInteger(n)&&n<=0)return a;if(t.length===0){a.push("");return a}if(r<=0){if(t.length>0){a.push(t.slice(0,1)+"…");a.widest_line=R.measureText(a[0]).width}return a}if(!t||t.length===0||n===0||r<=0)return a;const l=t.split(/\s+/g);if(!s(t)){a.push(t);a.widest_line=R.measureText(t).width;a.has_truncated=false;return a}let u=new String(l[0]);if(u&&s(u)){if(i){u=o(u,r)}else if(l.length>1){u+="…"}a.push(u);a.widest_line=R.measureText(u).width;a.has_truncated=true;return a}let c="";let h=false;l.forEach(t=>{if(h)return;if(s(c+(c?" ":"")+t)){if(c){const e=R.measureText(c).width;if(e>r){c=o(c,r);h=true}a.push(c);c=""}c=t}else{c+=(c?" ":"")+t}});if(c&&!h){a.push(o(c,r))}if(a.length>n){const d=a.length>n;if(d&&Number.isInteger(n)){a.splice(n,a.length-n);let t=a[a.length-1];if(s(t+"…")){t=o(t,r-R.measureText("…").width)}if(t.slice(-1)!=="…"){t+="…"}a[a.length-1]=t;h=true}}a.widest_line=Math.max(...a.map(t=>R.measureText(t).width));a.has_truncated=h;return a}function at(t,e,n){if(t.column_names[e]===undefined)return[];var r=Array.isArray(t.column_names[e]);var i=J(t,function(t){return r?t[e][n||0]:t[e]});var s=[];i.each(function(t){s.push(t)});return s}t.createScreenshotSVG=Q;t.getTextDimensions=B;t.getTextDirection=rt;t.getTextHeight=nt;t.getTextWidth=et;t.getUniqueValuesFromBinding=at;t.hexToColor=H;t.hexToRgba=it;t.isImage=X;t.isPale=st;t.isUrl=Y;t.remToPx=tt;t.wrapStringToLines=ot});
(function(t,e){typeof exports==="object"&&typeof module!=="undefined"?e(exports):typeof define==="function"&&define.amd?define(["exports"],e):(t=typeof globalThis!=="undefined"?globalThis:t||self,e(t.pocketKnife={}))})(this,function(t){"use strict";function e(t,e,n){t.prototype=e.prototype=n;n.constructor=t}function n(t,e){var n=Object.create(t.prototype);for(var r in e)n[r]=e[r];return n}function u(){}var r=.7;var i=1/r;var o="\\s*([+-]?\\d+)\\s*",s="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",a="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",j=/^#([0-9a-f]{3,8})$/,z=new RegExp(`^rgb\\(${o},${o},${o}\\)$`),F=new RegExp(`^rgb\\(${a},${a},${a}\\)$`),O=new RegExp(`^rgba\\(${o},${o},${o},${s}\\)$`),P=new RegExp(`^rgba\\(${a},${a},${a},${s}\\)$`),D=new RegExp(`^hsl\\(${s},${a},${a}\\)$`),I=new RegExp(`^hsla\\(${s},${a},${a},${s}\\)$`);var l={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};e(u,d,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:c,formatHex:c,formatHex8:L,formatHsl:G,formatRgb:h,toString:h});function c(){return this.rgb().formatHex()}function L(){return this.rgb().formatHex8()}function G(){return $(this).formatHsl()}function h(){return this.rgb().formatRgb()}function d(t){var e,n;t=(t+"").trim().toLowerCase();return(e=j.exec(t))?(n=e[1].length,e=parseInt(e[1],16),n===6?f(e):n===3?new p(e>>8&15|e>>4&240,e>>4&15|e&240,(e&15)<<4|e&15,1):n===8?g(e>>24&255,e>>16&255,e>>8&255,(e&255)/255):n===4?g(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|e&240,((e&15)<<4|e&15)/255):null):(e=z.exec(t))?new p(e[1],e[2],e[3],1):(e=F.exec(t))?new p(e[1]*255/100,e[2]*255/100,e[3]*255/100,1):(e=O.exec(t))?g(e[1],e[2],e[3],e[4]):(e=P.exec(t))?g(e[1]*255/100,e[2]*255/100,e[3]*255/100,e[4]):(e=D.exec(t))?v(e[1],e[2]/100,e[3]/100,1):(e=I.exec(t))?v(e[1],e[2]/100,e[3]/100,e[4]):l.hasOwnProperty(t)?f(l[t]):t==="transparent"?new p(NaN,NaN,NaN,0):null}function f(t){return new p(t>>16&255,t>>8&255,t&255,1)}function g(t,e,n,r){if(r<=0)t=e=n=NaN;return new p(t,e,n,r)}function U(t){if(!(t instanceof u))t=d(t);if(!t)return new p;t=t.rgb();return new p(t.r,t.g,t.b,t.opacity)}function V(t,e,n,r){return arguments.length===1?U(t):new p(t,e,n,r==null?1:r)}function p(t,e,n,r){this.r=+t;this.g=+e;this.b=+n;this.opacity=+r}e(p,V,n(u,{brighter(t){t=t==null?i:Math.pow(i,t);return new p(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){t=t==null?r:Math.pow(r,t);return new p(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new p(b(this.r),b(this.g),b(this.b),y(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&(-.5<=this.g&&this.g<255.5)&&(-.5<=this.b&&this.b<255.5)&&(0<=this.opacity&&this.opacity<=1)},hex:w,formatHex:w,formatHex8:W,formatRgb:m,toString:m}));function w(){return`#${x(this.r)}${x(this.g)}${x(this.b)}`}function W(){return`#${x(this.r)}${x(this.g)}${x(this.b)}${x((isNaN(this.opacity)?1:this.opacity)*255)}`}function m(){const t=y(this.opacity);return`${t===1?"rgb(":"rgba("}${b(this.r)}, ${b(this.g)}, ${b(this.b)}${t===1?")":`, ${t})`}`}function y(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function b(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function x(t){t=b(t);return(t<16?"0":"")+t.toString(16)}function v(t,e,n,r){if(r<=0)t=e=n=NaN;else if(n<=0||n>=1)t=e=NaN;else if(e<=0)t=NaN;return new k(t,e,n,r)}function $(t){if(t instanceof k)return new k(t.h,t.s,t.l,t.opacity);if(!(t instanceof u))t=d(t);if(!t)return new k;if(t instanceof k)return t;t=t.rgb();var e=t.r/255,n=t.g/255,r=t.b/255,i=Math.min(e,n,r),o=Math.max(e,n,r),s=NaN,a=o-i,l=(o+i)/2;if(a){if(e===o)s=(n-r)/a+(n<r)*6;else if(n===o)s=(r-e)/a+2;else s=(e-n)/a+4;a/=l<.5?o+i:2-o-i;s*=60}else{a=l>0&&l<1?0:s}return new k(s,a,l,t.opacity)}function K(t,e,n,r){return arguments.length===1?$(t):new k(t,e,n,r==null?1:r)}function k(t,e,n,r){this.h=+t;this.s=+e;this.l=+n;this.opacity=+r}e(k,K,n(u,{brighter(t){t=t==null?i:Math.pow(i,t);return new k(this.h,this.s,this.l*t,this.opacity)},darker(t){t=t==null?r:Math.pow(r,t);return new k(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+(this.h<0)*360,e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*e,i=2*n-r;return new p(C(t>=240?t-240:t+120,i,r),C(t,i,r),C(t<120?t+240:t-120,i,r),this.opacity)},clamp(){return new k(A(this.h),N(this.s),N(this.l),y(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&(0<=this.l&&this.l<=1)&&(0<=this.opacity&&this.opacity<=1)},formatHsl(){const t=y(this.opacity);return`${t===1?"hsl(":"hsla("}${A(this.h)}, ${N(this.s)*100}%, ${N(this.l)*100}%${t===1?")":`, ${t})`}`}}));function A(t){t=(t||0)%360;return t<0?t+360:t}function N(t){return Math.max(0,Math.min(1,t||0))}function C(t,e,n){return(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)*255}var S="$";function E(){}E.prototype=T.prototype={constructor:E,has:function(t){return S+t in this},get:function(t){return this[S+t]},set:function(t,e){this[S+t]=e;return this},remove:function(t){var e=S+t;return e in this&&delete this[e]},clear:function(){for(var t in this)if(t[0]===S)delete this[t]},keys:function(){var t=[];for(var e in this)if(e[0]===S)t.push(e.slice(1));return t},values:function(){var t=[];for(var e in this)if(e[0]===S)t.push(this[e]);return t},entries:function(){var t=[];for(var e in this)if(e[0]===S)t.push({key:e.slice(1),value:this[e]});return t},size:function(){var t=0;for(var e in this)if(e[0]===S)++t;return t},empty:function(){for(var t in this)if(t[0]===S)return false;return true},each:function(t){for(var e in this)if(e[0]===S)t(this[e],e.slice(1),this)}};function T(t,e){var n=new E;if(t instanceof E)t.each(function(t,e){n.set(e,t)});else if(Array.isArray(t)){var r=-1,i=t.length,o;if(e==null)while(++r<i)n.set(r,t[r]);else while(++r<i)n.set(e(o=t[r],r,t),o)}else if(t)for(var s in t)n.set(s,t[s]);return n}function M(){}var q=T.prototype;M.prototype=J.prototype={constructor:M,has:q.has,add:function(t){t+="";this[S+t]=t;return this},remove:q.remove,clear:q.clear,values:q.keys,size:q.size,empty:q.empty,each:q.each};function J(t,e){var n=new M;if(t instanceof M)t.each(function(t){n.add(t)});else if(t){var r=-1,i=t.length;if(e==null)while(++r<i)n.add(t[r]);else while(++r<i)n.add(e(t[r],r,t))}return n}function Q(b,t){if(typeof b=="string")b=document.querySelector(b);if(!b){console.error("No valid target in createScreenshotSVG");return null}const{width:e,height:n,x:r,y:i}=b.getBoundingClientRect();const x=document.createElementNS("http://www.w3.org/2000/svg","svg");x.id=t;x.classList.add("flourish-screenshot-svg-container");x.style.left=r+"px";x.style.top=i+"px";x.style.width=e+"px";x.style.height=n+"px";x.style.position="absolute";b.appendChild(x);function o(t){if(typeof t=="string")t=b.querySelectorAll(t);if(!t){console.error("No valid els inside addTextElements");return null}for(const n of t){const{x:r,y:t,width:e}=n.getBoundingClientRect();const i=document.createElementNS("http://www.w3.org/2000/svg","text");const{color:o,"font-family":s,"font-size":a,"font-weight":l,"line-height":u,"padding-left":c,"padding-top":h}=window.getComputedStyle(n);const d=`${l} ${a} ${s}`;const f=lt(n.innerText,d,null,Math.ceil(e));const g=isNaN(parseFloat(u))?parseFloat(a)*1.2+"px":u;const p=window.getComputedStyle(n.closest("[style*='opacity']")||n).opacity;f.forEach((t,e)=>{const n=document.createElementNS("http://www.w3.org/2000/svg","tspan");n.innerHTML=t;n.setAttribute("dy",e===0?parseFloat(h):g);n.setAttribute("dx",parseFloat(c));n.setAttribute("x",r);n.setAttribute("opacity",p);i.appendChild(n)});i.style.dominantBaseline="text-before-edge";i.setAttribute("x",r+"px");i.setAttribute("y",t+"px");i.setAttribute("font-family",s);i.setAttribute("font-size",a);i.setAttribute("font-weight",l);i.setAttribute("fill",o);x.appendChild(i)}return this}function s(t){if(typeof t=="string")t=b.querySelectorAll(t);if(!t){console.error("No valid els inside addCircleElements");return null}for(const r of t){const i=document.createElementNS("http://www.w3.org/2000/svg","circle");const{x:t,y:e,width:n}=r.getBoundingClientRect();const o=window.getComputedStyle(r)["background-color"];const s=window.getComputedStyle(r.closest("[style*='opacity']")||r).opacity;const a=n/2;i.setAttribute("cx",t+a+"px");i.setAttribute("cy",e+a+"px");i.setAttribute("r",a+"px");i.setAttribute("opacity",s);i.setAttribute("fill",o);if(o==="rgba(0, 0, 0, 0)")i.setAttribute("stroke","#CCC");x.appendChild(i)}return this}function a(t,o){if(typeof t=="string")t=b.querySelectorAll(t);if(!t){console.error("No valid els inside addSwatchElements");return null}if(typeof o=="string")o=b.querySelectorAll(o);for(const[s,a]of t.entries()){const l=document.createElementNS("http://www.w3.org/2000/svg","rect");const{x:t,y:e,width:n,height:r}=a.getBoundingClientRect();const u=o[s]?.getBoundingClientRect()?.y;const c=window.getComputedStyle(a)["background-color"];const h=window.getComputedStyle(a).border;const[,d,f,g,p]=h.replace(/\s/g,"").match(/rgba?\((\d+(?:\.\d+)?),(\d+(?:\.\d+)?),(\d+(?:\.\d+)?)(?:,(\d+(?:\.\d+)?))?\)/i);const w=p?`rgba(${d},${f},${g},${p})`:`rgb(${d},${f},${g})`||"#000";const m=h.split(" ")[0]||0;let i=window.getComputedStyle(a)["border-radius"]||0;i=parseFloat(i);const y=window.getComputedStyle(a.closest("[style*='opacity']")||a).opacity;l.setAttribute("x",t);l.setAttribute("y",u||e);l.setAttribute("width",`${n}px`);l.setAttribute("height",`${r}px`);l.setAttribute("rx",i);l.setAttribute("ry",i);l.setAttribute("opacity",y);l.setAttribute("fill",c);l.setAttribute("stroke",w);l.setAttribute("stroke-width",m);if(c==="rgba(0, 0, 0, 0)")l.setAttribute("stroke","#CCC");x.appendChild(l)}return this}function l(t,e,n){if(typeof t=="string")t=b.querySelector(t);if(!t){console.error("No valid els inside addCircleElements");return null}const r=document.createElementNS("http://www.w3.org/2000/svg","g");const{x:i,y:o,width:s,height:a}=t.getBoundingClientRect();const{max:l,min:u}=n;const c=l-u;for(let t=0;t<=s;t++){const h=document.createElementNS("http://www.w3.org/2000/svg","line");h.setAttribute("stroke",e(u+t*c/s));h.setAttribute("x1",t+i);h.setAttribute("y1",o);h.setAttribute("x2",t+i);h.setAttribute("y2",a+o);r.appendChild(h)}x.appendChild(r);return this}function u(){x.remove()}return{addTextElements:o,addCircleElements:s,addSwatchElements:a,addGradient:l,remove:u}}function X(t){if(typeof t!="string")return false;return t.match(/^(https?:\/\/.+\.(jpg|jpeg|svg|png|gif|webp)$|data:image\/)/i)!=null}function Y(t){if(typeof t!="string")return false;return t.match(/^(https?:\/\/|data:)/i)!=null}function Z(t){return btoa(String.fromCharCode(...(new TextEncoder).encode(t)))}function tt(t){return(new TextDecoder).decode(Uint8Array.from(atob(t),t=>t.charCodeAt(0)))}const et=document.createElement("canvas");const R=et.getContext("2d");function nt(t){var e,n;if(window.innerWidth!==e){e=window.innerWidth;n=parseFloat(getComputedStyle(document.documentElement).fontSize)}return t*n}function B(t,e){R.font=e||"10px sans-serif";var n=R.measureText(t);return{width:n.width,height:n.actualBoundingBoxAscent+n.actualBoundingBoxDescent}}function rt(t,e){return B(t,e).width}function it(t,e){return B(t,e).height}function ot(){return window.getComputedStyle(document.body).direction||"ltr"}function H(t,e){if(typeof t!="string")return false;var n=d(t);n.opacity=e!==undefined?e:1;return n}function st(t,e){var n=H(t,e);return n?n.toString():false}function _(t){return t<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4)}function at(t){if(!t){console.warn("No valid color",t);return}const e=H(t);const n=_(e.r/255)*.2126+_(e.g/255)*.7152+_(e.b/255)*.0722;const r=1>n?(n+.05)/1.05:1.05/(n+.05);const i=0>n?(n+.05)/.05:.05/(n+.05);return r>i?true:false}function lt(t,e,n,r,i=true){if(typeof t!=="string")t=String(t);const o=t=>R.measureText(t).width>r;const s=(t,e)=>{let n=R.measureText(t).width;if(n<=e){return t}let r=1;let i=t;do{i=t.substring(0,t.length-r)+"…";n=R.measureText(i).width}while(n>e&&++r<t.length);if(i.length<1)i=t.substring(0,1)+"…";return i};R.font=e;let a=[];Object.defineProperty(a,"widest_line",{value:0,enumerable:true,writable:true});Object.defineProperty(a,"has_truncated",{value:false,enumerable:true,writable:true});if(typeof t==="undefined"||Number.isInteger(n)&&n<=0)return a;if(t.length===0){a.push("");return a}if(r<=0){if(t.length>0){a.push(t.slice(0,1)+"…");a.widest_line=R.measureText(a[0]).width}return a}if(!t||t.length===0||n===0||r<=0)return a;const l=t.split(/\s+/g);if(!o(t)){a.push(t);a.widest_line=R.measureText(t).width;a.has_truncated=false;return a}let u=new String(l[0]);if(u&&o(u)){if(i){u=s(u,r)}else if(l.length>1){u+="…"}a.push(u);a.widest_line=R.measureText(u).width;a.has_truncated=true;return a}let c="";let h=false;l.forEach(t=>{if(h)return;if(o(c+(c?" ":"")+t)){if(c){const e=R.measureText(c).width;if(e>r){c=s(c,r);h=true}a.push(c);c=""}c=t}else{c+=(c?" ":"")+t}});if(c&&!h){a.push(s(c,r))}if(a.length>n){const d=a.length>n;if(d&&Number.isInteger(n)){a.splice(n,a.length-n);let t=a[a.length-1];if(o(t+"…")){t=s(t,r-R.measureText("…").width)}if(t.slice(-1)!=="…"){t+="…"}a[a.length-1]=t;h=true}}a.widest_line=Math.max(...a.map(t=>R.measureText(t).width));a.has_truncated=h;return a}function ut(t,e,n){if(t.column_names[e]===undefined)return[];var r=Array.isArray(t.column_names[e]);var i=J(t,function(t){return r?t[e][n||0]:t[e]});var o=[];i.each(function(t){o.push(t)});return o}t.createScreenshotSVG=Q;t.decodeBase64=tt;t.encodeBase64=Z;t.getTextDimensions=B;t.getTextDirection=ot;t.getTextHeight=it;t.getTextWidth=rt;t.getUniqueValuesFromBinding=ut;t.hexToColor=H;t.hexToRgba=st;t.isImage=X;t.isPale=at;t.isUrl=Y;t.remToPx=nt;t.wrapStringToLines=lt});

@@ -0,1 +1,4 @@

# 2.2.0
* Added utility functions for safely encoding and decoding strings to base-64
# 2.1.1

@@ -2,0 +5,0 @@ * Remove repo from package.json

@@ -6,2 +6,3 @@ import { color } from "d3-color";

import { isUrl } from "./is-url.js";
import { encodeBase64, decodeBase64 } from "./base-64-encode.js";

@@ -253,2 +254,4 @@ const canvas = document.createElement("canvas");

createScreenshotSVG,
encodeBase64,
decodeBase64,
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc