rays-javascript-extension/build/ryzjsext.min.js

31 lines
14 KiB
JavaScript

/**
* Ray's JavaScript Extension
* @version v0.1.0.112 (2024/02/03 2030)
*/
Array.isEmpty=function(a){return"array"!=Object.getDataType(a)?!0:0>=a.length};Array.toFlatten=function(a,b,c){for(let d=0;d<a.length;d++)c.push(a[d]),0<a[d][b].length&&Array.toFlatten(a[d][b],b,c)};Array.prototype.addRange=function(a){if(null==a)return this;for(let b=0;b<a.length;b++)this.push(a[b]);return this};Array.prototype.any=function(a,b){return 0<this.count(a,b)};Array.prototype.copy=function(){return JSON.parse(JSON.stringify(this))};
Array.prototype.count=function(a,b){let c=0;for(let d=0;d<this.length;d++)"undefined"!=typeof this[d][a]&&this[d][a]==b&&c++;return c};Array.prototype.countMany=function(...a){let b=0;a.forEach(c=>{b+=this.count(c.propName,c.value)});return b};Array.prototype.flatten=function(a){let b=[];Array.toFlatten(this,a,b);return b};Array.prototype.index=function(a,b){for(let c=0;c<this.length;c++)if("undefined"!=typeof this[c][a]&&this[c][a]==b)return c;return-1};
Array.prototype.insert=function(a,b){0>a?this.splice(0,0,b):a>=this.length?this.push(b):this.splice(a,0,b);return this};Array.prototype.joinIfNotNullOrWhitespace=function(a){let b="";for(let c=0;c<this.length;c++)String.isNullOrWhitespace(this[c])||(String.isNullOrWhitespace(b)||(b+=a),b+=this[c]);return b};Array.prototype.first=function(a,b){for(let c=0;c<this.length;c++)if("undefined"!=typeof this[c][a]&&this[c][a]==b)return this[c];return null};
Array.prototype.forEachTree=function(a,b){for(let c=0;c<this.length&&!1!==b(this[c])&&(0>=this[c][a].length||!1!==this[c][a].forEachTree(a,b));c++);};Array.prototype.indexes=function(a,b){let c=[];for(let d=0;d<this.length;d++)"undefined"!=typeof this[d][a]&&this[d][a]==b&&c.push(d);return c};Array.prototype.orderBy=function(a){this.sort(function(b,c){return b[a]<c[a]?-1:b[a]>c[a]?1:0});return this};
Array.prototype.orderByDesc=function(a){this.sort(function(b,c){return b[a]<c[a]?1:b[a]>c[a]?-1:0});return this};Array.prototype.remove=function(a){let b=[];for(let c=0;c<this.length;c++)this[c]==a&&b.push(c);for(a=b.length-1;0<=a;a--)this.removeAt(b[a]);return this};Array.prototype.removeAt=function(a){if(0>a||a>=this.length)return this;this.splice(a,1);return this};Array.prototype.removeRange=function(a){for(let b=0;b<a.length;b++)this.remove(a[b]);return this};
Array.prototype.select=function(a,b){let c=[];for(let d=0;d<this.length;d++)"undefined"!=typeof this[d][a]&&this[d][a]==b&&c.push(this[d]);return c};Array.prototype.selectMany=function(...a){let b=this;a.forEach(c=>{b=b.select(c.propName,c.value)});return b};Array.prototype.toList=function(a){let b=[];this.forEach(c=>{b.push(c[a])});return b};Array.prototype.sortTree=function(a,b){this.orderBy(b);for(let c=0;c<this.length;c++)0>=this[c][a].length||this[c][a].orderBy(b)};Boolean.isFalse=function(a){return String.isNullOrUndefined(a)?!0:a.toString().containsCI("false","f","y","0","x")};Boolean.isTrue=function(a){return String.isNullOrUndefined(a)?!1:a.toString().containsCI("true","t","n","1","o")};Boolean.ifTrue=function(a,b,c){return Boolean.isTrue(a)?b:c};class Canvas{constructor(a){this.container=a;this.canvasContainer=this.flowContainer=this.ctx=null;this.autoSize=!0;this.padding={Top:0,Right:0,Bottom:0,Left:0};this.initialiseComponents()}initialiseComponents(){null!=this.container&&(this.container.innerHTML="<div class='border'><canvas></canvas></div>",null!=this.container&&(this.container.style.width="100%",this.container.style.height="100%",this.flowContainer=this.container.getElementsByTagName("div")[0],this.canvasContainer=this.flowContainer.getElementsByTagName("canvas")[0],
this.ctx=this.canvasContainer.getContext("2d")),this.AutoSize=this.AutoSize,this.Width=this.Width,this.Height=this.Height,this.Clear())}get AutoSize(){return this.autoSize}set AutoSize(a){this.autoSize=a;null!=this.flowContainer&&(1==a?this.flowContainer.style.overflow="hidden":(this.flowContainer.style.overflowX=this.Width>=this.ClientWidth?"hidden":"auto",this.flowContainer.style.overflowY=this.Height>=this.ClientHeight?"hidden":"auto"))}get ClientHeight(){return null==this.canvasContainer?0:this.getHeight(this.canvasContainer)}set ClientHeight(a){null!=
this.canvasContainer&&(this.canvasContainer.style.height=a+"px");null!=this.ctx&&(this.ctx.canvas.height=a)}get ClientWidth(){return null==this.canvasContainer?0:this.getWidth(this.canvasContainer)}set ClientWidth(a){null!=this.canvasContainer&&(this.canvasContainer.style.width=a+"px");null!=this.ctx&&(this.ctx.canvas.width=a)}get Height(){return null==this.container?0:this.getHeight(this.container)}set Height(a){null!=this.container&&(this.container.style.height=a+"px");null!=this.flowContainer&&
(this.flowContainer.style.height=a+"px");1==this.AutoSize&&(this.ClientHeight=a)}get Width(){return null==this.container?0:this.getWidth(this.container)}set Width(a){null!=this.container&&(this.container.style.width=a+"px");null!=this.flowContainer&&(this.flowContainer.style.width=a+"px");1==this.AutoSize&&(this.ClientWidth=a)}get Size(){return{W:this.Width,H:this.Height}}get ClientRectangle(){return{X:this.padding.Left,Y:this.padding.Top,W:this.Width-(this.padding.Left+this.padding.Right),H:this.Height-
(this.padding.Top+this.padding.Bottom)}}get Rectangle(){return{X:0,Y:0,W:this.Width,H:this.Height}}Clear(){null!=this.ctx&&this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}DrawArrowS(a,b,c){null!=this.ctx&&(c=Object.assign({LineWidth:1,LineDash:[],FillColour:null},c),a.X+=.5,a.Y+=.5,a.W-=c.LineWidth,a.H-=c.LineWidth,this.ctx.beginPath(),this.ctx.strokeStyle=b,this.ctx.lineWidth=c.LineWidth,this.ctx.setLineDash(c.LineDash),this.ctx.moveTo(a.X,a.Y),this.ctx.lineTo(a.X+a.W,a.Y),this.ctx.lineTo(a.X+
Math.half(a.W),a.Y+a.H),this.ctx.closePath(),null!=c.FillColour&&(this.ctx.fillStyle=c.FillColour,this.ctx.fill()),this.ctx.stroke())}DrawCircle(a,b,c,d,e){if(null!=this.ctx){e=Object.assign({LineWidth:1,LineDash:[],FillColour:null},e);a+=Math.half(c);b+=Math.half(c);var f=Math.half(c);Math.half(c);a+=.5;b+=.5;f-=Math.half(e.LineWidth);Math.half(e.LineWidth);this.ctx.beginPath();this.ctx.strokeStyle=d;this.ctx.lineWidth=e.LineWidth;this.ctx.setLineDash(e.LineDash);this.ctx.arc(a,b,f,0,2*Math.PI,!1);
this.ctx.closePath();null!=e.FillColour&&(this.ctx.fillStyle=e.FillColour,this.ctx.fill());this.ctx.stroke()}}DrawDiamond(a,b,c){null!=this.ctx&&(c=Object.assign({LineWidth:1,LineDash:[],FillColour:null},c),a.X+=.5,a.Y+=.5,a.W-=c.LineWidth,a.H-=c.LineWidth,this.ctx.beginPath(),this.ctx.strokeStyle=b,this.ctx.lineWidth=c.LineWidth,this.ctx.setLineDash(c.LineDash),this.ctx.moveTo(a.X+Math.half(a.W),a.Y),this.ctx.lineTo(a.X+a.W,a.Y+Math.half(a.H)),this.ctx.lineTo(a.X+Math.half(a.W),a.Y+a.H),this.ctx.lineTo(a.X,
a.Y+Math.half(a.H)),this.ctx.closePath(),null!=c.FillColour&&(this.ctx.fillStyle=c.FillColour,this.ctx.fill()),this.ctx.stroke())}DrawRectangle(a,b,c){null!=this.ctx&&(c=Object.assign({LineWidth:1,LineDash:[],FillColour:null},c),a.X+=.5,a.Y+=.5,a.W-=c.LineWidth,a.H-=c.LineWidth,this.ctx.beginPath(),this.ctx.strokeStyle=b,this.ctx.lineWidth=c.LineWidth,this.ctx.setLineDash(c.LineDash),this.ctx.rect(a.X,a.Y,a.W,a.H),null!=c.FillColour&&(this.ctx.fillStyle=c.FillColour,this.ctx.fill()),this.ctx.closePath(),
this.ctx.stroke())}DrawLine(a,b,c,d,e,f){null!=this.ctx&&(f=Object.assign({LineWidth:1,LineDash:[]},f),b-=.5,this.ctx.beginPath(),this.ctx.strokeStyle=e,this.ctx.lineWidth=f.LineWidth,this.ctx.setLineDash(f.LineDash),this.ctx.moveTo(a,b),this.ctx.lineTo(c,d),this.ctx.stroke())}DrawLines(a,b,c){if(null!=this.ctx&&null!=a&&!(0>=a.length)){c=Object.assign({LineWidth:1,LineDash:[]},c);this.ctx.beginPath();this.ctx.strokeStyle=b;this.ctx.lineWidth=c.LineWidth;this.ctx.setLineDash(c.LineDash);this.ctx.moveTo(a[0].X,
a[0].Y);for(b=1;b<a.length;b++)this.ctx.lineTo(a[b].X,a[b].Y);this.ctx.stroke()}}DrawHorizontalLine(a,b,c,d,e){null!=this.ctx&&(e=Object.assign({LineWidth:1,LineDash:[]},e),b-=.5,this.ctx.beginPath(),this.ctx.strokeStyle=d,this.ctx.lineWidth=e.LineWidth,this.ctx.setLineDash(e.LineDash),this.ctx.moveTo(a,b),this.ctx.lineTo(a+c,b),this.ctx.stroke())}DrawText(a,b,c,d,e,f){null!=this.ctx&&(f=Object.assign({Align:"left"},f),this.ctx.font=d,this.ctx.fillStyle=e,this.ctx.textAlign=f.Align,this.ctx.textBaseline=
"top",this.ctx.fillText(c,a,b))}DrawVerticalLine(a,b,c,d,e){null!=this.ctx&&(e=Object.assign({LineWidth:1,LineDash:[]},e),a-=.5,b-=e.LineWidth,this.ctx.beginPath(),this.ctx.strokeStyle=d,this.ctx.lineWidth=e.LineWidth,this.ctx.setLineDash(e.LineDash),this.ctx.moveTo(a,b),this.ctx.lineTo(a,b+c),this.ctx.stroke())}FillText(a,b,c,d,e){if(null!=this.ctx){e=Object.assign({Align:"center",VAlign:"middle"},e);this.ctx.font=c;this.ctx.fillStyle=d;this.ctx.textAlign=e.Align;this.ctx.textBaseline="top";c=this.ctx.measureText(b);
d=a.X+Math.half(a.W);var f=a.Y;switch(e.VAlign){case "center":case "middle":f+=Math.half(a.H-c.fontBoundingBoxDescent)+c.fontBoundingBoxAscent;break;case "bottom":f+=a.H-c.fontBoundingBoxDescent}this.ctx.fillText(b,d,f)}}Invalidate(){this.AutoSize=this.AutoSize;this.Width=this.Width;this.Height=this.Height}MeasureText(a,b){if(null==this.ctx)return null;this.ctx.font=a;a=this.ctx.measureText(b);return{W:a.width,H:Math.round(a.fontBoundingBoxDescent+a.fontBoundingBoxAscent)}}getWidth(a){return a.offsetWidth||
a.innerWidth||a.clientWidth}getHeight(a){return a.offsetHeight||a.innerHeight||a.clientHeight}};Date.addDays=function(a,b){a=new Date(a);a.addDays(b);return a};Date.addMonths=function(a,b){a=new Date(a);a.addMonths(b);return a};Date.addYears=function(a,b){a=new Date(a);a.addYears(b);return a};Date.max=function(a,b){return null==a?b:null==b?a:new Date(a)<=new Date(b)?new Date(b):new Date(a)};Date.min=function(a,b){return null==a?b:null==b?a:new Date(a)<=new Date(b)?new Date(a):new Date(b)};Date.diffDays=function(a,b){return Math.ceil(((new Date(b)).getTime()-(new Date(a)).getTime())/864E5)};
Date.today=function(){let a=new Date;a.setHours(0);a.setMinutes(0);a.setSeconds(0);a.setMilliseconds(0);return a};Date.prototype.addDays=function(a){this.setDate(this.getDate()+parseInt(a))};Date.prototype.addMonths=function(a){this.setMonth(this.getMonth()+parseInt(a))};Date.prototype.addYears=function(a){this.setFullYear(this.getFullYear()+parseInt(a))};
Date.prototype.toCString=function(a){a=a.replace("fffffff",this.getMilliseconds().toString().padStart(7,"0"));a=a.replace("ffffff",this.getMilliseconds().toString().padStart(6,"0"));a=a.replace("fffff",this.getMilliseconds().toString().padStart(5,"0"));a=a.replace("yyyy",this.getFullYear().toString().padStart(4,"0"));a=a.replace("MMMM","{1}");a=a.replace("dddd","{2}");a=a.replace("ffff",this.getMilliseconds().toString().padStart(4,"0"));a=a.replace("yyy",this.getFullYear().toString().padStart(3,"0"));
a=a.replace("MMM","{3}");a=a.replace("ddd","{4}");a=a.replace("fff",this.getMilliseconds().toString().padStart(3,"0"));a=a.replace("zzz","");a=a.replace("yy",this.getFullYear().toString().slice(-2));a=a.replace("MM",(this.getMonth()+1).toString().padStart(2,"0"));a=a.replace("dd",this.getDate().toString().padStart(2,"0"));a=a.replace("HH",this.getHours().toString().padStart(2,"0"));a=a.replace("hh",(12<this.getHours()?this.getHours()-12:this.getHours()).toString().padStart(2,"0"));a=a.replace("mm",
this.getMinutes().toString().padStart(2,"0"));a=a.replace("ss",this.getSeconds().toString().padStart(2,"0"));a=a.replace("ff",this.getMilliseconds().toString().padStart(2,"0"));a=a.replace("tt","{5}");a=a.replace("zz","");a=a.replace("y",this.getFullYear().toString());a=a.replace("M",(this.getMonth()+1).toString());a=a.replace("d",this.getDate().toString());a=a.replace("H",this.getHours().toString());a=a.replace("h",(12<this.getHours()?this.getHours()-12:this.getHours()).toString());a=a.replace("m",
this.getMinutes().toString());a=a.replace("s",this.getSeconds().toString());a=a.replace("z","");a=a.replace("t","{6}");a=a.replace("Z","");a=a.replace("{1}",this.toLocaleString("default",{month:"long"}));a=a.replace("{2}",this.toLocaleString("default",{weekday:"long"}));a=a.replace("{3}",this.toLocaleString("default",{month:"short"}));a=a.replace("{4}",this.toLocaleString("default",{weekday:"short"}));a=a.replace("{5}",12<=this.getHours()?"PM":"AM");return a=a.replace("{6}",12<=this.getHours()?"P":
"A")};Document.ready=async function(a){(async function(){"loading"!==document.readyState?a():document.addEventListener("DOMContentLoaded",function(){a()})})()};Math.randomN=function(a,b){a=Math.ceil(a);b=Math.floor(b);return Math.floor(Math.random()*(b-a)+a)};Math.average=function(a){let b=0;a.forEach(c=>{b+=parseFloat(c)});return b/a.length};Math.avg=function(...a){let b=0;a.forEach(c=>{b+=parseFloat(c)});return b/a.length};Math.half=function(a){return a/2};Object.isNullOrUndefined=function(a){return"undefined"==typeof a||null==a?!0:!1};Object.getDataType=function(a){return String.isNullOrUndefined(a)?"null":"object"==typeof a?Array.isArray(a)?"array":"object":typeof a};class Rectangle{constructor(a,b,c,d){this.X=a;this.Y=b;this.W=c;this.H=d}static containsPoint(a,b){const c=a.X+a.W,d=a.Y+a.H;return b.X>=a.X&&b.X<=c&&b.Y>=a.Y&&b.Y<=d}static combine(a,b){const c=Math.max(a.Y+a.H,b.Y+b.H),d={X:Math.min(a.X,b.X),Y:Math.min(a.Y,b.Y),W:0,H:0};d.W=Math.max(a.X+a.W,b.X+b.W)-d.X;d.H=c-d.Y;return d}};String.isNullOrUndefined=function(a){return"undefined"==typeof a||null==a?!0:!1};String.isNullOrWhitespace=function(a){return String.isNullOrUndefined(a)?!0:"string"==typeof a?0>=a.trim().length:0>=a.toString().trim().length};String.joinIfNotNullOrWhitespace=function(a,...b){let c="";for(let d=0;d<b.length;d++)String.isNullOrWhitespace(b[d])||(String.isNullOrWhitespace(c)||(c+=a),c+=b[d]);return c};String.prototype.contains=function(...a){for(let b of a)if(this==b)return!0;return!1};
String.prototype.containsCI=function(...a){for(let b of a)if(this.toLowerCase()==b.toLowerCase())return!0;return!1};String.prototype.encodeHtmlLinks=function(){return value.replace(/(http[s]{0,1}:\/\/[^\s]+)/g,"<a href='$1'>$1</a>")};String.prototype.toTitleCase=function(){let a;a=this.replace(/([A-Z]{1})/g," $1");a=a.trim();return a=a.charAt(0).toUpperCase()+a.substr(1)};String.prototype.getFilename=function(){return this.substring(this.lastIndexOf("/")+1)};Window.goToTop=function(){Window.scrollTo(0,0)};
Window.fragment={get:function(){if(!window.location.hash)return null;const a=window.location.hash.indexOf("?");return 0>a?window.location.hash.substring(1):window.location.hash.substring(1,a)},getQuery:function(){if(!window.location.hash)return null;var a=window.location.hash;a=a.indexOf("?");if(0>a)return null;a=hasQueryString.substring(a+1);a=new URLSearchParams(a);const b={};for(const [c,d]of a.entries())b[c]=d;return b},clear:function(){location.hash="";history.replaceState("","",location.pathname)}};