jc-structure 0.1.1 → 0.1.3

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.
@@ -1,2 +1,2 @@
1
- (function(o,E){typeof exports=="object"&&typeof module<"u"?E(exports):typeof define=="function"&&define.amd?define(["exports"],E):(o=typeof globalThis<"u"?globalThis:o||self,E(o["jc-structure"]={}))})(this,(function(o){"use strict";class E{items={};count=0;lowestCount=0;constructor(){}dequeue(){if(this.isEmpty())return;const t=this.items[this.lowestCount];return delete this.items[this.lowestCount],this.lowestCount++,t}enqueue(...t){t.forEach(e=>{this.items[this.count]=e,this.count++})}front(){return this.isEmpty()?void 0:this.items[this.lowestCount]}isEmpty(){return this.size()===0}size(){return this.count-this.lowestCount}clear(){this.items={},this.count=0,this.lowestCount=0}toString(){return this.isEmpty()?"":`Queue(size: ${this.size()}):[${this.items[this.lowestCount]},...rest]`}}class O{items={};count=0;constructor(){}pop(){if(this.isEmpty())return;this.count--;const t=this.items[this.count];return delete this.items[this.count],t}push(...t){t.forEach(e=>{this.items[this.count]=e,this.count++})}peek(){return this.isEmpty()?void 0:this.items[this.count-1]}isEmpty(){return this.count===0}size(){return this.count}clear(){this.items={},this.count=0}toString(){return this.isEmpty()?"":`Stack(count: ${this.count}):[${this.items[this.count-1]},...rest]`}}function S(n,t){return n===t?0:n<t?-1:1}class g{heap=[];compareFn;constructor(t=S){this.compareFn=t}static getLeftIndex(t){return 2*t+1}static getRightIndex(t){return 2*t+2}static getParentIndex(t){return t===0?void 0:Math.floor((t-1)/2)}static swap(t,e,s){[t[e],t[s]]=[t[s],t[e]]}find(){return this.isEmpty()?void 0:this.heap[0]}size(){return this.heap.length}isEmpty(){return this.size()===0}clear(){this.heap=[]}toString(){return this.heap.toString()}}class L extends g{insert(t){return t?!1:(this.heap.push(t),this.siftUp(this.heap.length-1),!0)}extract(){if(this.isEmpty())return;if(this.heap.length===1)return this.heap.shift();const t=this.heap[0];return this.heap[0]=this.heap.pop(),this.siftDown(0),t}siftUp(t){let e=t,s=g.getLeftIndex(e),i=g.getRightIndex(e),r=this.size();s<r&&this.compareFn(this.heap[e],this.heap[s])===-1&&(e=s),i<r&&this.compareFn(this.heap[e],this.heap[i])===1&&(e=i),e!==t&&(g.swap(this.heap,t,e),this.siftUp(e))}siftDown(t){let e=g.getParentIndex(t);for(;t>0&&e&&this.compareFn(this.heap[e],this.heap[t])===1;)g.swap(this.heap,e,t),t=e,e=g.getParentIndex(t)}}class k extends L{constructor(t=(e,s)=>S(s,e)){super(t)}}function z(n){return{value:n}}class j{capacity;length=0;head=null;tail=null;lookup=new Map;reverseLookup=new Map;constructor(t=10){this.capacity=t}prepend(t){this.head?(t.next=this.head,this.head.prev=t,this.head=t):this.head=this.tail=t}detach(t){t.prev&&(t.prev.next=t.next),t.next&&(t.next.prev=t.prev),this.head===t&&(this.head=this.head.next||null),this.tail===t&&(this.tail=this.tail.prev||null),t.next=void 0,t.prev=void 0}trimCache(){if(this.length<=this.capacity)return;const t=this.tail;this.detach(t);const e=this.reverseLookup.get(t);this.lookup.delete(e),this.reverseLookup.delete(t),this.length--}get(t){const e=this.lookup.get(t);if(e)return this.detach(e),this.prepend(e),e.value}update(t,e){let s=this.lookup.get(t);s?(this.detach(s),this.prepend(s),s.value=e):(s=z(e),this.length++,this.prepend(s),this.trimCache(),this.lookup.set(t,s),this.reverseLookup)}}let N=class{value;next=void 0};class R{count=0;head=void 0;constructor(){}indexOf(t){let e=this.head,s=0,i=!1;for(;e;){if(this.equals(e.value,t)){i=!0;break}s++,e=e.next}return i?s:-1}equals(t,e){return!1}getElementAt(t){if(t<0||t>=this.count)return;if(t===0)return this.head;let e=this.head;for(let s=0;s<t;s++)e=e?.next;return e}getValueAt(t){return this.getElementAt(t)?.value}insert(t,e){let s=new N;if(s.value=t,e>this.count||e<0)throw new Error("index error");this.count++;let i,r;if(e===0){s.next=this.head,this.head=s;return}i=this.getElementAt(e-1),r=i.next,i.next=s,s.next=r}push(t){let e=new N;if(e.value=t,this.count++,this.isEmpty()){this.head=e;return}let s=this.getElementAt(this.count-1);s.next=e}remove(t){const e=this.indexOf(t);return e===-1?void 0:this.removeAt(e)}removeAt(t){if(this.isEmpty()||t<0||t>=this.count)return;let e=this.getElementAt(t),s=this.getElementAt(t-1),i=e?.next;return t===0&&(this.head=i),s&&(s.next=i),this.count--,e?.value}isEmpty(){return this.count===0}size(){return this.count}clear(){this.count=0,this.head=void 0}toString(){let t="",e=this.head;for(;e;)t+=e.value,t+=",",e=e.next;return t=t.slice(0,-1),t}}class V{key;value;constructor(t,e){this.key=t,this.value=e}}function P(n,t={emptyString:!1,zeroNumber:!1}){return n==null?!(t.emptyString&&n===""||t.zeroNumber&&n===0):!1}class A{table=[];constructor(){}getItemIndex(t){for(let e=0,s=this.table.length;e<s;e++)if(this.table[e].key===t)return e;return-1}set(t,e){if(P(t))throw new Error("key is required");if(P(e))throw new Error("value is required");if(this.has(t)){let s=this.getItemIndex(t);this.table[s].value=e}else{const s=new V(t,e);this.table.push(s)}}remove(t){if(this.has(t)){let e=this.getItemIndex(t);return this.table.splice(e,1)[0]}}has(t){return this.getItemIndex(t)!==-1}get(t){if(this.has(t)){let e=this.getItemIndex(t);return this.table[e]}}keys(){return this.table.map(t=>t.key)}values(){return this.table.map(t=>t.value)}keyValues(){return this.table.map(t=>[t.key,t.value])}forEach(t){for(let e=0,s=this.size();e<s;e++){let i=this.table[e];if(!t(i.key,i.value))break}}isEmpty(){return!this.size()}size(){return this.table.length}clear(){this.table=[]}toString(){let t="";for(let e=0,s=this.table.length;e<s;e++)t+=this.table[e].toString(),t+=",";return t=t.slice(0,-1),t}}class q{isDirected;vertices;adjList;constructor(t=!1){this.isDirected=t,this.vertices=[],this.adjList=new A}addVertex(t){this.vertices.includes(t)||(this.vertices.push(t),this.adjList.set(t,[]))}addEdge(t,e){this.adjList.get(t)||this.addVertex(t),this.adjList.get(e)||this.addVertex(e),this.adjList.get(t)?.value.indexOf(e)===-1&&this.adjList.get(t)?.value.push(e),this.isDirected||this.adjList.get(e)?.value.indexOf(t)===-1&&this.adjList.get(e)?.value.push(t)}getVertices(){return this.vertices}getAdjacencyList(){return this.adjList}toString(){let t="";for(let e=0;e<this.vertices.length;e++)t+=this.vertices[e]+"-->",t+=this.adjList.get(this.vertices[e])?.toString()||"",t+=`
2
- `;return t}}class f{_data;static zero(t){return new f(...Array(t).fill(0))}constructor(...t){this._data=t}get dimension(){return this._data.length}get norm(){return Math.hypot(...this._data)}getItem(t){return this._data[t]}normalize(){const t=this.norm;if(t===0)throw new Error("Cannot normalize a zero vector");const e=this._data.map(s=>s/t);return new f(...e)}add(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to add");const e=this._data.map((s,i)=>s+t._data[i]);return new f(...e)}sub(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to subtract");const e=this._data.map((s,i)=>s-t._data[i]);return new f(...e)}mul(t){return new f(...this._data.map(e=>e*t))}dot(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to dot product");return this._data.reduce((e,s,i)=>e+s*t._data[i],0)}pos(){return this.mul(1)}neg(){return this.mul(-1)}}class w{_matrix;static zero(t,e){return new w(Array.from({length:t},()=>Array.from({length:e},()=>0)))}constructor(t){this._matrix=t}get shape(){return[this._matrix.length,this._matrix[0].length]}get row(){return this.shape[0]}get col(){return this.shape[1]}get size(){return this.row*this.col}rowVector(t){return new f(...this._matrix[t])}colVector(t){return new f(...this._matrix.map(e=>e[t]))}getItem(t){return this._matrix[t[0]][t[1]]}setItem(t,e){return this._matrix[t[0]][t[1]]=e,this}mul(t){return new w(this._matrix.map(e=>e.map(s=>s*t)))}div(t){return this.mul(1/t)}add(t){if(this.row!==t.row||this.col!==t.col)throw new Error("Matrix dimensions do not match");return new w(this._matrix.map((e,s)=>e.map((i,r)=>i+t.getItem([s,r]))))}sub(t){return this.add(t.neg())}pos(){return this.mul(1)}neg(){return this.mul(-1)}mulVector(t){if(this.col!==t.dimension)throw new Error("Matrix dimensions do not match");return new w(this._matrix.map(e=>e.map((s,i)=>s*t.getItem(i))))}mulMatrix(t){if(this.col!==t.row)throw new Error("Matrix dimensions do not match");const e=w.zero(this.row,t.col);for(let s=0;s<this.row;s++){const i=this.rowVector(s);for(let r=0;r<this.col;r++)e.setItem([s,r],i.dot(t.colVector(r)))}return e}}class h{static distance(t,e){return Math.hypot(e.x-t.x,e.y-t.y)}x;y;constructor(t,e){this.x=t,this.y=e}distanceTo(t){return h.distance(this,t)}}class u{static EPSILON=1e-10;static sloped(t){const e=t.p2.x-t.p1.x,s=t.p2.y-t.p1.y;return Math.abs(e)<u.EPSILON?Math.abs(s)<u.EPSILON?0:null:s/e}static isParallel(t,e){const s=u.sloped(t),i=u.sloped(e);return s===null&&i===null?!0:s===null||i===null?!1:Math.abs(s-i)<u.EPSILON}static getIntersection(t,e){if(u.isParallel(t,e))return null;const s=t.p1.x,i=t.p1.y,r=t.p2.x,a=t.p2.y,p=e.p1.x,l=e.p1.y,d=e.p2.x,y=e.p2.y,m=(s-r)*(l-y)-(i-a)*(p-d);if(Math.abs(m)<u.EPSILON)return null;const v=((s-p)*(l-y)-(i-l)*(p-d))/m,I=-((s-r)*(i-l)-(i-a)*(s-p))/m;if(v>=0&&v<=1&&I>=0&&I<=1){const X=s+v*(r-s),G=i+v*(a-i);return new h(X,G)}return null}static isIntersecting(t,e){return u.getIntersection(t,e)!==null}static distanceToPoint(t,e){const s=e.x-t.p1.x,i=e.y-t.p1.y,r=t.p2.x-t.p1.x,a=t.p2.y-t.p1.y,p=s*r+i*a,l=r*r+a*a;let d=-1;l>u.EPSILON&&(d=p/l);let y,m;d<0?(y=t.p1.x,m=t.p1.y):d>1?(y=t.p2.x,m=t.p2.y):(y=t.p1.x+d*r,m=t.p1.y+d*a);const v=e.x-y,I=e.y-m;return Math.hypot(v+I)}p1;p2;constructor(t,e){this.p1=t,this.p2=e}get length(){const t=this.p2.x-this.p1.x,e=this.p2.y-this.p1.y;return Math.sqrt(t*t+e*e)}get midpoint(){const t=(this.p1.x+this.p2.x)/2,e=(this.p1.y+this.p2.y)/2;return new h(t,e)}get angle(){return Math.atan2(this.p2.y-this.p1.y,this.p2.x-this.p1.x)}containsPoint(t){const e=(t.x-this.p1.x)*(this.p2.y-this.p1.y)-(t.y-this.p1.y)*(this.p2.x-this.p1.x);return Math.abs(e)>u.EPSILON?!1:(t.x-this.p1.x)*(t.x-this.p2.x)+(t.y-this.p1.y)*(t.y-this.p2.y)<=u.EPSILON}get direction(){const t=this.length;if(t<u.EPSILON)return new h(0,0);const e=(this.p2.x-this.p1.x)/t,s=(this.p2.y-this.p1.y)/t;return new h(e,s)}}class C{static EPSILON=1e-10;name;constructor(t){this.name=t}}class c extends C{static isValid(t,e,s){return t<=0||e<=0||s<=0?!1:t+e>s&&t+s>e&&e+s>t}static area(t,e,s){if(!c.isValid(t,e,s))throw new Error("Invalid triangle");const i=(t+e+s)/2;return Math.sqrt(i*(i-t)*(i-e)*(i-s))}static getType(t,e,s){if(!c.isValid(t,e,s))throw new Error("Invalid triangle sides");const i=[t,e,s].sort((l,d)=>l-d),[r,a,p]=i;return Math.abs(r-a)<c.EPSILON&&Math.abs(a-p)<c.EPSILON?"equilateral":Math.abs(r-a)<c.EPSILON||Math.abs(a-p)<c.EPSILON?"isosceles":"scalene"}static getAngles(t,e,s){if(!c.isValid(t,e,s))throw new Error("Invalid triangle sides");const i=Math.acos((e*e+s*s-t*t)/(2*e*s)),r=Math.acos((t*t+s*s-e*e)/(2*t*s)),a=Math.PI-i-r;return[i,r,a]}p1;p2;p3;constructor(t,e,s,i="triangle"){if(super(i),this.p1=t,this.p2=e,this.p3=s,this.areCollinear())throw new Error("Points are collinear, cannot form a triangle")}areCollinear(){return Math.abs((this.p2.x-this.p1.x)*(this.p3.y-this.p1.y)-(this.p3.x-this.p1.x)*(this.p2.y-this.p1.y))<C.EPSILON}get side(){return[h.distance(this.p1,this.p2),h.distance(this.p2,this.p3),h.distance(this.p3,this.p1)]}perimeter(){return c.isValid(this.side[0],this.side[1],this.side[2]),this.side.reduce((t,e)=>t+e,0)}area(){const[t,e,s]=this.side;return c.area(t,e,s)}get type(){const[t,e,s]=this.side;return c.getType(t,e,s)}get angles(){const[t,e,s]=this.side;return c.getAngles(t,e,s)}get centroid(){return new h((this.p1.x+this.p2.x+this.p3.x)/3,(this.p1.y+this.p2.y+this.p3.y)/3)}get incenter(){const[t,e,s]=this.side,i=this.perimeter()/2,r=(t*this.p1.x+e*this.p2.x+s*this.p3.x)/i,a=(t*this.p1.y+e*this.p2.y+s*this.p3.y)/i;return new h(r,a)}get circumcenter(){const t=2*(this.p1.x*(this.p2.y-this.p3.y)+this.p2.x*(this.p3.y-this.p1.y)+this.p3.x*(this.p1.y-this.p2.y));if(Math.abs(t)<c.EPSILON)throw new Error("Cannot calculate circumcenter for collinear points");const e=((this.p1.x*this.p1.x+this.p1.y*this.p1.y)*(this.p2.y-this.p3.y)+(this.p2.x*this.p2.x+this.p2.y*this.p2.y)*(this.p3.y-this.p1.y)+(this.p3.x*this.p3.x+this.p3.y*this.p3.y)*(this.p1.y-this.p2.y))/t,s=((this.p1.x*this.p1.x+this.p1.y*this.p1.y)*(this.p3.x-this.p2.x)+(this.p2.x*this.p2.x+this.p2.y*this.p2.y)*(this.p1.x-this.p3.x)+(this.p3.x*this.p3.x+this.p3.y*this.p3.y)*(this.p2.x-this.p1.x))/t;return new h(e,s)}containsPoint(t){const e=c.area(h.distance(t,this.p1),h.distance(t,this.p2),h.distance(this.p1,this.p2)),s=c.area(h.distance(t,this.p2),h.distance(t,this.p3),h.distance(this.p2,this.p3)),i=c.area(h.distance(t,this.p3),h.distance(t,this.p1),h.distance(this.p3,this.p1));return Math.abs(e+s+i-this.area())<c.EPSILON}}function D(n){return new Promise(t=>setTimeout(t,n))}function W(n){const t=[],e={"(":")","[":"]","{":"}"},s=new Set(Object.values(e));for(const i of n)if(i in e)t.push(e[i]);else if(s.has(i)&&i!==t.pop())return!1;return t.length===0}function M(n){return n!==null&&(typeof n=="object"||typeof n=="function")}class H{map=new Map;weakMap=new WeakMap;set(t,e){M(t)?this.weakMap.set(t,e):this.map.set(t,e)}get(t){return M(t)?this.weakMap.get(t):this.map.get(t)}has(t){return M(t)?this.weakMap.has(t):this.map.has(t)}}function F(n){if(!n.length)return[];const t=[[n[0]]];for(let s=1,i=n.length;s<i;s++){const r=n[s];e(r)}function e(s){for(let i=t.length-1;i>=0;i--){const r=t[i],a=r[t[i].length-1];if(a<s){t[i+1]=[...r,s];break}else a>s&&i===0&&(t[i]=[s])}}return t[t.length-1]}class ${static ROMAN_MAP=new Map([["M",1e3],["CM",900],["D",500],["CD",400],["C",100],["XC",90],["L",50],["XL",40],["X",10],["IX",9],["V",5],["IV",4],["I",1]]);static toInteger(t){if(t.length===0)throw new Error("Input cannot be empty");const e=new Set(["I","V","X","L","C","D","M"]);for(const a of t)if(!e.has(a))throw new Error(`Invalid Roman numeral character: ${a}`);let s=0,i=0;for(;i<t.length;){const a=t.slice(i,i+2);if(this.ROMAN_MAP.has(a))s+=this.ROMAN_MAP.get(a),i+=2;else{const p=t[i],l=this.ROMAN_MAP.get(p);if(!l)throw new Error(`Invalid Roman numeral sequence at position ${i}`);s+=l,i+=1}}if(this.toRoman(s)!==t)throw new Error("Invalid Roman numeral sequence");return s}static toRoman(t){if(t<=0||t>=4e3)throw new Error("Number must be between 1 and 3999");if(!Number.isInteger(t))throw new Error("Number must be an integer");let e="";for(const[s,i]of this.ROMAN_MAP)for(;t>=i;)e+=s,t-=i;return e}}function U(n){let t;const e=new Proxy(n,{construct(s,i,r){return t||(t=Reflect.construct(s,i,r)),t}});return n.prototype.constructor=e,e}const b={scriptRegex:/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,javascriptRegex:/javascript:/gi,eventHandlerRegex:/on\w+\s*=/gi,allowedTags:new Set(["div","span","p","a","img","button","input","form","label","select","option","textarea","ul","ol","li","table","tr","td","th","thead","tbody","tfoot","h1","h2","h3","h4","h5","h6","hr","br","section","article","nav","header","footer","main","aside","figure","figcaption"]),allowedAttributes:new Set(["class","id","href","src","alt","title"])};class x{static instance;constructor(){}static getInstance(){return x.instance||(x.instance=new x),x.instance}createElement(t,e={},s=""){if(!b.allowedTags.has(t.toLowerCase()))throw new Error(`Unsupported tag: ${t}`);const i=document.createElement(t);return this._processAttributes(i,e),this._processContent(i,s),i}createBatch(t,e){const s=document.createDocumentFragment();t.forEach(i=>{const r=this.createElement(i.tag,i.attributes||{},i.content||"");s.appendChild(r)}),e.appendChild(s)}setHtml(t,e){const s=this._sanitizeHtml(e);t.innerHTML=s}_processAttributes(t,e){Object.entries(e).forEach(([s,i])=>{if(!b.allowedAttributes.has(s)&&!s.startsWith("data-")){console.warn(`Potentially unsafe attribute: ${s}`);return}if(typeof i=="function")s.startsWith("on")&&t.addEventListener(s.slice(2).toLowerCase(),i);else switch(s){case"className":t.className=i;break;case"dataset":Object.assign(t.dataset,i);break;case"style":Object.assign(t.style,i);break;default:t.setAttribute(s,i)}})}_processContent(t,e){typeof e=="string"?t.textContent=e:e instanceof Node?t.appendChild(e):Array.isArray(e)&&e.forEach(s=>{typeof s=="string"?t.appendChild(document.createTextNode(s)):t.appendChild(s)})}_sanitizeHtml(t){return t.replace(b.scriptRegex,"").replace(b.javascriptRegex,"").replace(b.eventHandlerRegex,"")}}class B{features;constructor(){this.features=this.detectFeatures()}detectFeatures(){return{geolocation:"geolocation"in navigator,notification:"Notification"in window,serviceWorker:"serviceWorker"in navigator,webShare:"share"in navigator,deviceOrientation:"DeviceOrientationEvent"in window,battery:"getBattery"in navigator,online:"onLine"in navigator}}async getLocation(t={}){if(!this.features.geolocation)throw new Error("Geolocation is not supported");const e={enableHighAccuracy:!0,timeout:10*1e3,maximumAge:300*1e3};return new Promise((s,i)=>{navigator.geolocation.getCurrentPosition(r=>s({latitude:r.coords.latitude,longitude:r.coords.longitude,accuracy:r.coords.accuracy,timstamp:r.timestamp}),r=>{const a={1:"User denied the request for Geolocation.",2:"Position information is unavailable.",3:"The request to get user location timed out."};i(new Error(a[r.code]||"Unknown error"))},{...e,...t})})}async sendNotification(t,e){if(!this.features.notification)throw new Error("Notification is not supported");if(Notification.permission==="default"&&await Notification.requestPermission()!=="granted")throw new Error("Notification permission is not granted");if(Notification.permission!=="granted")throw new Error("Notification permission is not granted");return new Notification(t,{icon:e.icon,badge:e.badge,...e})}async registerServiceWorker(t){if(!this.features.serviceWorker)throw new Error("Service Worker is not supported");try{const e=await navigator.serviceWorker.register(t);return console.log("Service Worker registered with scope:",e),e}catch(e){throw console.error("Service Worker registration failed:",e),e}}async shareContent(t){if(this.features.webShare)try{return await navigator.share(t),!0}catch(e){return e instanceof Error&&e.name!="AbortError"&&console.error("Error sharing content:",e),!1}else try{return await navigator.clipboard.writeText(t.url||t.text||""),this.sendNotification("Copied to clipboard",{body:"Link copied to clipboard"}),!0}catch(e){return console.error("Error copying to clipboard:",e),!1}}}o.Dictionary=A,o.DomHelper=x,o.Graph=q,o.LIS=F,o.LRU=j,o.Line=u,o.LinkedList=R,o.Matrix=w,o.MaxHeap=k,o.MemoizeMap=H,o.MinHeap=L,o.Point=h,o.Queue=E,o.Roman=$,o.Stack=O,o.Triangle=c,o.Vector=f,o.WebAppManager=B,o.isValidBracket=W,o.singleton=U,o.sleep=D,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(a,M){typeof exports=="object"&&typeof module<"u"?M(exports):typeof define=="function"&&define.amd?define(["exports"],M):(a=typeof globalThis<"u"?globalThis:a||self,M(a["jc-structure"]={}))})(this,(function(a){"use strict";class M{items={};count=0;lowestCount=0;constructor(){}dequeue(){if(this.isEmpty())return;const t=this.items[this.lowestCount];return delete this.items[this.lowestCount],this.lowestCount++,t}enqueue(...t){t.forEach(e=>{this.items[this.count]=e,this.count++})}front(){return this.isEmpty()?void 0:this.items[this.lowestCount]}isEmpty(){return this.size()===0}size(){return this.count-this.lowestCount}clear(){this.items={},this.count=0,this.lowestCount=0}toString(){return this.isEmpty()?"":`Queue(size: ${this.size()}):[${this.items[this.lowestCount]},...rest]`}}class j{items={};count=0;constructor(){}pop(){if(this.isEmpty())return;this.count--;const t=this.items[this.count];return delete this.items[this.count],t}push(...t){t.forEach(e=>{this.items[this.count]=e,this.count++})}peek(){return this.isEmpty()?void 0:this.items[this.count-1]}isEmpty(){return this.count===0}size(){return this.count}clear(){this.items={},this.count=0}toString(){return this.isEmpty()?"":`Stack(count: ${this.count}):[${this.items[this.count-1]},...rest]`}}function C(r,t){return r===t?0:r<t?-1:1}class w{heap=[];compareFn;constructor(t=C){this.compareFn=t}static getLeftIndex(t){return 2*t+1}static getRightIndex(t){return 2*t+2}static getParentIndex(t){return t===0?void 0:Math.floor((t-1)/2)}static swap(t,e,s){[t[e],t[s]]=[t[s],t[e]]}find(){return this.isEmpty()?void 0:this.heap[0]}size(){return this.heap.length}isEmpty(){return this.size()===0}clear(){this.heap=[]}toString(){return this.heap.toString()}}class N extends w{insert(t){return t?!1:(this.heap.push(t),this.siftUp(this.heap.length-1),!0)}extract(){if(this.isEmpty())return;if(this.heap.length===1)return this.heap.shift();const t=this.heap[0];return this.heap[0]=this.heap.pop(),this.siftDown(0),t}siftUp(t){let e=t,s=w.getLeftIndex(e),i=w.getRightIndex(e),n=this.size();s<n&&this.compareFn(this.heap[e],this.heap[s])===-1&&(e=s),i<n&&this.compareFn(this.heap[e],this.heap[i])===1&&(e=i),e!==t&&(w.swap(this.heap,t,e),this.siftUp(e))}siftDown(t){let e=w.getParentIndex(t);for(;t>0&&e&&this.compareFn(this.heap[e],this.heap[t])===1;)w.swap(this.heap,e,t),t=e,e=w.getParentIndex(t)}}class z extends N{constructor(t=(e,s)=>C(s,e)){super(t)}}function U(r){return{value:r}}class V{capacity;length=0;head=null;tail=null;lookup=new Map;reverseLookup=new Map;constructor(t=10){this.capacity=t}prepend(t){this.head?(t.next=this.head,this.head.prev=t,this.head=t):this.head=this.tail=t}detach(t){t.prev&&(t.prev.next=t.next),t.next&&(t.next.prev=t.prev),this.head===t&&(this.head=this.head.next||null),this.tail===t&&(this.tail=this.tail.prev||null),t.next=void 0,t.prev=void 0}trimCache(){if(this.length<=this.capacity)return;const t=this.tail;this.detach(t);const e=this.reverseLookup.get(t);this.lookup.delete(e),this.reverseLookup.delete(t),this.length--}get(t){const e=this.lookup.get(t);if(e)return this.detach(e),this.prepend(e),e.value}update(t,e){let s=this.lookup.get(t);s?(this.detach(s),this.prepend(s),s.value=e):(s=U(e),this.length++,this.prepend(s),this.trimCache(),this.lookup.set(t,s),this.reverseLookup)}}let O=class{value;next=void 0};class D{count=0;head=void 0;constructor(){}indexOf(t){let e=this.head,s=0,i=!1;for(;e;){if(this.equals(e.value,t)){i=!0;break}s++,e=e.next}return i?s:-1}equals(t,e){return!1}getElementAt(t){if(t<0||t>=this.count)return;if(t===0)return this.head;let e=this.head;for(let s=0;s<t;s++)e=e?.next;return e}getValueAt(t){return this.getElementAt(t)?.value}insert(t,e){let s=new O;if(s.value=t,e>this.count||e<0)throw new Error("index error");this.count++;let i,n;if(e===0){s.next=this.head,this.head=s;return}i=this.getElementAt(e-1),n=i.next,i.next=s,s.next=n}push(t){let e=new O;if(e.value=t,this.count++,this.isEmpty()){this.head=e;return}let s=this.getElementAt(this.count-1);s.next=e}remove(t){const e=this.indexOf(t);return e===-1?void 0:this.removeAt(e)}removeAt(t){if(this.isEmpty()||t<0||t>=this.count)return;let e=this.getElementAt(t),s=this.getElementAt(t-1),i=e?.next;return t===0&&(this.head=i),s&&(s.next=i),this.count--,e?.value}isEmpty(){return this.count===0}size(){return this.count}clear(){this.count=0,this.head=void 0}toString(){let t="",e=this.head;for(;e;)t+=e.value,t+=",",e=e.next;return t=t.slice(0,-1),t}}class H{key;value;constructor(t,e){this.key=t,this.value=e}}function P(r,t={emptyString:!1,zeroNumber:!1}){return r==null?!(t.emptyString&&r===""||t.zeroNumber&&r===0):!1}class R{table=[];constructor(){}getItemIndex(t){for(let e=0,s=this.table.length;e<s;e++)if(this.table[e].key===t)return e;return-1}set(t,e){if(P(t))throw new Error("key is required");if(P(e))throw new Error("value is required");if(this.has(t)){let s=this.getItemIndex(t);this.table[s].value=e}else{const s=new H(t,e);this.table.push(s)}}remove(t){if(this.has(t)){let e=this.getItemIndex(t);return this.table.splice(e,1)[0]}}has(t){return this.getItemIndex(t)!==-1}get(t){if(this.has(t)){let e=this.getItemIndex(t);return this.table[e]}}keys(){return this.table.map(t=>t.key)}values(){return this.table.map(t=>t.value)}keyValues(){return this.table.map(t=>[t.key,t.value])}forEach(t){for(let e=0,s=this.size();e<s;e++){let i=this.table[e];if(!t(i.key,i.value))break}}isEmpty(){return!this.size()}size(){return this.table.length}clear(){this.table=[]}toString(){let t="";for(let e=0,s=this.table.length;e<s;e++)t+=this.table[e].toString(),t+=",";return t=t.slice(0,-1),t}}class _{isDirected;vertices;adjList;constructor(t=!1){this.isDirected=t,this.vertices=[],this.adjList=new R}addVertex(t){this.vertices.includes(t)||(this.vertices.push(t),this.adjList.set(t,[]))}addEdge(t,e){this.adjList.get(t)||this.addVertex(t),this.adjList.get(e)||this.addVertex(e),this.adjList.get(t)?.value.indexOf(e)===-1&&this.adjList.get(t)?.value.push(e),this.isDirected||this.adjList.get(e)?.value.indexOf(t)===-1&&this.adjList.get(e)?.value.push(t)}getVertices(){return this.vertices}getAdjacencyList(){return this.adjList}toString(){let t="";for(let e=0;e<this.vertices.length;e++)t+=this.vertices[e]+"-->",t+=this.adjList.get(this.vertices[e])?.toString()||"",t+=`
2
+ `;return t}}class d{_data;static zero(t){return new d(...Array(t).fill(0))}constructor(...t){this._data=t}get dimension(){return this._data.length}get norm(){return Math.hypot(...this._data)}getItem(t){return this._data[t]}normalize(){const t=this.norm;if(t===0)throw new Error("Cannot normalize a zero vector");const e=this._data.map(s=>s/t);return new d(...e)}add(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to add");const e=this._data.map((s,i)=>s+t._data[i]);return new d(...e)}sub(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to subtract");const e=this._data.map((s,i)=>s-t._data[i]);return new d(...e)}mul(t){return new d(...this._data.map(e=>e*t))}dot(t){if(this.dimension!==t.dimension)throw new Error("Vectors must have the same dimension to dot product");return this._data.reduce((e,s,i)=>e+s*t._data[i],0)}pos(){return this.mul(1)}neg(){return this.mul(-1)}}class y{_matrix;static zero(t,e){return new y(Array.from({length:t},()=>Array.from({length:e},()=>0)))}constructor(t){this._matrix=t}get shape(){return[this._matrix.length,this._matrix[0].length]}get row(){return this.shape[0]}get col(){return this.shape[1]}get size(){return this.row*this.col}rowVector(t){return new d(...this._matrix[t])}colVector(t){return new d(...this._matrix.map(e=>e[t]))}getItem(t){return this._matrix[t[0]][t[1]]}setItem(t,e){return this._matrix[t[0]][t[1]]=e,this}mul(t){return new y(this._matrix.map(e=>e.map(s=>s*t)))}div(t){return this.mul(1/t)}add(t){if(this.row!==t.row||this.col!==t.col)throw new Error("Matrix dimensions do not match");return new y(this._matrix.map((e,s)=>e.map((i,n)=>i+t.getItem([s,n]))))}sub(t){return this.add(t.neg())}pos(){return this.mul(1)}neg(){return this.mul(-1)}mulVector(t){if(this.col!==t.dimension)throw new Error("Matrix dimensions do not match");return new y(this._matrix.map(e=>e.map((s,i)=>s*t.getItem(i))))}mulMatrix(t){if(this.col!==t.row)throw new Error("Matrix dimensions do not match");const e=y.zero(this.row,t.col);for(let s=0;s<this.row;s++){const i=this.rowVector(s);for(let n=0;n<this.col;n++)e.setItem([s,n],i.dot(t.colVector(n)))}return e}}class h{static distance(t,e){return Math.hypot(e.x-t.x,e.y-t.y)}x;y;constructor(t,e){this.x=t,this.y=e}distanceTo(t){return h.distance(this,t)}}class p{static EPSILON=1e-10;static sloped(t,e=p.EPSILON){const s=t.p2.x-t.p1.x,i=t.p2.y-t.p1.y;return Math.abs(s)<e?Math.abs(i)<e?0:null:i/s}static isParallel(t,e,s=p.EPSILON){const i=p.sloped(t),n=p.sloped(e);return i===null&&n===null?!0:i===null||n===null?!1:Math.abs(i-n)<s}static getIntersection(t,e,s=p.EPSILON){if(p.isParallel(t,e))return null;const i=t.p1.x,n=t.p1.y,o=t.p2.x,u=t.p2.y,l=e.p1.x,f=e.p1.y,g=e.p2.x,E=e.p2.y,m=(i-o)*(f-E)-(n-u)*(l-g);if(Math.abs(m)<s)return null;const I=((i-l)*(f-E)-(n-f)*(l-g))/m,L=-((i-o)*(n-f)-(n-u)*(i-l))/m;if(I>=0&&I<=1&&L>=0&&L<=1){const X=i+I*(o-i),Q=n+I*(u-n);return new h(X,Q)}return null}static isIntersecting(t,e){return p.getIntersection(t,e)!==null}static distanceToPoint(t,e,s=p.EPSILON){const i=e.x-t.p1.x,n=e.y-t.p1.y,o=t.p2.x-t.p1.x,u=t.p2.y-t.p1.y,l=i*o+n*u,f=o*o+u*u;let g=-1;f>s&&(g=l/f);let E,m;g<0?(E=t.p1.x,m=t.p1.y):g>1?(E=t.p2.x,m=t.p2.y):(E=t.p1.x+g*o,m=t.p1.y+g*u);const I=e.x-E,L=e.y-m;return Math.hypot(I+L)}p1;p2;constructor(t,e){this.p1=t,this.p2=e}get length(){const t=this.p2.x-this.p1.x,e=this.p2.y-this.p1.y;return Math.sqrt(t*t+e*e)}get midpoint(){const t=(this.p1.x+this.p2.x)/2,e=(this.p1.y+this.p2.y)/2;return new h(t,e)}get angle(){return Math.atan2(this.p2.y-this.p1.y,this.p2.x-this.p1.x)}containsPoint(t,e=p.EPSILON){const s=(t.x-this.p1.x)*(this.p2.y-this.p1.y)-(t.y-this.p1.y)*(this.p2.x-this.p1.x);return Math.abs(s)>e?!1:(t.x-this.p1.x)*(t.x-this.p2.x)+(t.y-this.p1.y)*(t.y-this.p2.y)<=e}get direction(){const t=this.length;if(t<p.EPSILON)return new h(0,0);const e=(this.p2.x-this.p1.x)/t,s=(this.p2.y-this.p1.y)/t;return new h(e,s)}get start(){return this.p1}get end(){return this.p2}}class k{static EPSILON=1e-10;name;constructor(t){this.name=t}}class c extends k{static isValid(t,e,s){return t<=0||e<=0||s<=0?!1:t+e>s&&t+s>e&&e+s>t}static area(t,e,s){if(!c.isValid(t,e,s))throw new Error("Invalid triangle");const i=(t+e+s)/2;return Math.sqrt(i*(i-t)*(i-e)*(i-s))}static getType(t,e,s){if(!c.isValid(t,e,s))throw new Error("Invalid triangle sides");const i=[t,e,s].sort((l,f)=>l-f),[n,o,u]=i;return Math.abs(n-o)<c.EPSILON&&Math.abs(o-u)<c.EPSILON?"equilateral":Math.abs(n-o)<c.EPSILON||Math.abs(o-u)<c.EPSILON?"isosceles":"scalene"}static getAngles(t,e,s){if(!c.isValid(t,e,s))throw new Error("Invalid triangle sides");const i=Math.acos((e*e+s*s-t*t)/(2*e*s)),n=Math.acos((t*t+s*s-e*e)/(2*t*s)),o=Math.PI-i-n;return[i,n,o]}p1;p2;p3;constructor(t,e,s,i="triangle"){if(super(i),this.p1=t,this.p2=e,this.p3=s,this.areCollinear())throw new Error("Points are collinear, cannot form a triangle")}areCollinear(){return Math.abs((this.p2.x-this.p1.x)*(this.p3.y-this.p1.y)-(this.p3.x-this.p1.x)*(this.p2.y-this.p1.y))<k.EPSILON}get side(){return[h.distance(this.p1,this.p2),h.distance(this.p2,this.p3),h.distance(this.p3,this.p1)]}perimeter(){return c.isValid(this.side[0],this.side[1],this.side[2]),this.side.reduce((t,e)=>t+e,0)}area(){const[t,e,s]=this.side;return c.area(t,e,s)}get type(){const[t,e,s]=this.side;return c.getType(t,e,s)}get angles(){const[t,e,s]=this.side;return c.getAngles(t,e,s)}get centroid(){return new h((this.p1.x+this.p2.x+this.p3.x)/3,(this.p1.y+this.p2.y+this.p3.y)/3)}get incenter(){const[t,e,s]=this.side,i=this.perimeter()/2,n=(t*this.p1.x+e*this.p2.x+s*this.p3.x)/i,o=(t*this.p1.y+e*this.p2.y+s*this.p3.y)/i;return new h(n,o)}get circumcenter(){const t=2*(this.p1.x*(this.p2.y-this.p3.y)+this.p2.x*(this.p3.y-this.p1.y)+this.p3.x*(this.p1.y-this.p2.y));if(Math.abs(t)<c.EPSILON)throw new Error("Cannot calculate circumcenter for collinear points");const e=((this.p1.x*this.p1.x+this.p1.y*this.p1.y)*(this.p2.y-this.p3.y)+(this.p2.x*this.p2.x+this.p2.y*this.p2.y)*(this.p3.y-this.p1.y)+(this.p3.x*this.p3.x+this.p3.y*this.p3.y)*(this.p1.y-this.p2.y))/t,s=((this.p1.x*this.p1.x+this.p1.y*this.p1.y)*(this.p3.x-this.p2.x)+(this.p2.x*this.p2.x+this.p2.y*this.p2.y)*(this.p1.x-this.p3.x)+(this.p3.x*this.p3.x+this.p3.y*this.p3.y)*(this.p2.x-this.p1.x))/t;return new h(e,s)}containsPoint(t){const e=c.area(h.distance(t,this.p1),h.distance(t,this.p2),h.distance(this.p1,this.p2)),s=c.area(h.distance(t,this.p2),h.distance(t,this.p3),h.distance(this.p2,this.p3)),i=c.area(h.distance(t,this.p3),h.distance(t,this.p1),h.distance(this.p3,this.p1));return Math.abs(e+s+i-this.area())<c.EPSILON}}function $(r){return new Promise(t=>setTimeout(t,r))}function W(r){const t=[],e={"(":")","[":"]","{":"}"},s=new Set(Object.values(e));for(const i of r)if(i in e)t.push(e[i]);else if(s.has(i)&&i!==t.pop())return!1;return t.length===0}function A(r){return r!==null&&(typeof r=="object"||typeof r=="function")}class q{map=new Map;weakMap=new WeakMap;set(t,e){A(t)?this.weakMap.set(t,e):this.map.set(t,e)}get(t){return A(t)?this.weakMap.get(t):this.map.get(t)}has(t){return A(t)?this.weakMap.has(t):this.map.has(t)}}function T(r){if(!r.length)return[];const t=[[r[0]]];for(let s=1,i=r.length;s<i;s++){const n=r[s];e(n)}function e(s){for(let i=t.length-1;i>=0;i--){const n=t[i],o=n[t[i].length-1];if(o<s){t[i+1]=[...n,s];break}else o>s&&i===0&&(t[i]=[s])}}return t[t.length-1]}class G{static ROMAN_MAP=new Map([["M",1e3],["CM",900],["D",500],["CD",400],["C",100],["XC",90],["L",50],["XL",40],["X",10],["IX",9],["V",5],["IV",4],["I",1]]);static toInteger(t){if(t.length===0)throw new Error("Input cannot be empty");const e=new Set(["I","V","X","L","C","D","M"]);for(const o of t)if(!e.has(o))throw new Error(`Invalid Roman numeral character: ${o}`);let s=0,i=0;for(;i<t.length;){const o=t.slice(i,i+2);if(this.ROMAN_MAP.has(o))s+=this.ROMAN_MAP.get(o),i+=2;else{const u=t[i],l=this.ROMAN_MAP.get(u);if(!l)throw new Error(`Invalid Roman numeral sequence at position ${i}`);s+=l,i+=1}}if(this.toRoman(s)!==t)throw new Error("Invalid Roman numeral sequence");return s}static toRoman(t){if(t<=0||t>=4e3)throw new Error("Number must be between 1 and 3999");if(!Number.isInteger(t))throw new Error("Number must be an integer");let e="";for(const[s,i]of this.ROMAN_MAP)for(;t>=i;)e+=s,t-=i;return e}}function F(r){let t;const e=new Proxy(r,{construct(s,i,n){return t||(t=Reflect.construct(s,i,n)),t}});return r.prototype.constructor=e,e}const x={AUTH_UNAUTHORIZED:"未授权事件",AUTH_LOGIN_SUCCESS:"登录成功事件",AUTH_LOGOUT:"注销事件",AUTH_TOKEN_EXPIRED:"令牌过期事件",REQUEST_ERROR:"请求错误事件",REQUEST_TIMEOUT:"请求超时事件",REQUEST_NETWORK_ERROR:"网络错误事件",UI_SHOW_LOADING:"显示加载事件",UI_HIDE_LOADING:"隐藏加载事件",UI_SHOW_MESSAGE:"显示消息事件"};class b{static instance=null;listeners={};debugMode;constructor(t=!1){this.debugMode=t,Object.keys(x).forEach(e=>{this.listeners[e]=new Set})}static getInstance(t){return b.instance||(b.instance=new b(t)),b.instance}on(t,e){this.debugLog(`添加事件监听: ${x[t]}`),this.listeners[t].add(e)}emit(t,e){this.debugLog(`触发事件: ${x[t]}`,e),this.listeners[t].forEach(s=>{try{s(e)}catch(i){console.error(`事件 ${x[t]} 处理出错:`,i)}})}off(t,e){this.debugLog(`移除事件监听: ${x[t]}`),this.listeners[t].delete(e)}once(t,e){this.debugLog(`添加一次性事件监听: ${x[t]}`);const s=i=>{e(i),this.off(t,s)};this.on(t,s)}clear(){this.debugLog("清除所有事件监听器"),Object.values(this.listeners).forEach(t=>t.clear())}getListenerCount(t){return this.listeners[t].size}debugLog(t,e){this.debugMode&&console.log(`[EventEmitter] ${t}`,e||"")}}const S={scriptRegex:/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,javascriptRegex:/javascript:/gi,eventHandlerRegex:/on\w+\s*=/gi,allowedTags:new Set(["div","span","p","a","img","button","input","form","label","select","option","textarea","ul","ol","li","table","tr","td","th","thead","tbody","tfoot","h1","h2","h3","h4","h5","h6","hr","br","section","article","nav","header","footer","main","aside","figure","figcaption"]),allowedAttributes:new Set(["class","id","href","src","alt","title"])};class v{static instance;constructor(){}static getInstance(){return v.instance||(v.instance=new v),v.instance}createElement(t,e={},s=""){if(!S.allowedTags.has(t.toLowerCase()))throw new Error(`Unsupported tag: ${t}`);const i=document.createElement(t);return this._processAttributes(i,e),this._processContent(i,s),i}createBatch(t,e){const s=document.createDocumentFragment();t.forEach(i=>{const n=this.createElement(i.tag,i.attributes||{},i.content||"");s.appendChild(n)}),e.appendChild(s)}setHtml(t,e){const s=this._sanitizeHtml(e);t.innerHTML=s}_processAttributes(t,e){Object.entries(e).forEach(([s,i])=>{if(!S.allowedAttributes.has(s)&&!s.startsWith("data-")){console.warn(`Potentially unsafe attribute: ${s}`);return}if(typeof i=="function")s.startsWith("on")&&t.addEventListener(s.slice(2).toLowerCase(),i);else switch(s){case"className":t.className=i;break;case"dataset":Object.assign(t.dataset,i);break;case"style":Object.assign(t.style,i);break;default:t.setAttribute(s,i)}})}_processContent(t,e){typeof e=="string"?t.textContent=e:e instanceof Node?t.appendChild(e):Array.isArray(e)&&e.forEach(s=>{typeof s=="string"?t.appendChild(document.createTextNode(s)):t.appendChild(s)})}_sanitizeHtml(t){return t.replace(S.scriptRegex,"").replace(S.javascriptRegex,"").replace(S.eventHandlerRegex,"")}}class B{features;constructor(){this.features=this.detectFeatures()}detectFeatures(){return{geolocation:"geolocation"in navigator,notification:"Notification"in window,serviceWorker:"serviceWorker"in navigator,webShare:"share"in navigator,deviceOrientation:"DeviceOrientationEvent"in window,battery:"getBattery"in navigator,online:"onLine"in navigator}}async getLocation(t={}){if(!this.features.geolocation)throw new Error("Geolocation is not supported");const e={enableHighAccuracy:!0,timeout:10*1e3,maximumAge:300*1e3};return new Promise((s,i)=>{navigator.geolocation.getCurrentPosition(n=>s({latitude:n.coords.latitude,longitude:n.coords.longitude,accuracy:n.coords.accuracy,timstamp:n.timestamp}),n=>{const o={1:"User denied the request for Geolocation.",2:"Position information is unavailable.",3:"The request to get user location timed out."};i(new Error(o[n.code]||"Unknown error"))},{...e,...t})})}async sendNotification(t,e){if(!this.features.notification)throw new Error("Notification is not supported");if(Notification.permission==="default"&&await Notification.requestPermission()!=="granted")throw new Error("Notification permission is not granted");if(Notification.permission!=="granted")throw new Error("Notification permission is not granted");return new Notification(t,{icon:e.icon,badge:e.badge,...e})}async registerServiceWorker(t){if(!this.features.serviceWorker)throw new Error("Service Worker is not supported");try{const e=await navigator.serviceWorker.register(t);return console.log("Service Worker registered with scope:",e),e}catch(e){throw console.error("Service Worker registration failed:",e),e}}async shareContent(t){if(this.features.webShare)try{return await navigator.share(t),!0}catch(e){return e instanceof Error&&e.name!="AbortError"&&console.error("Error sharing content:",e),!1}else try{return await navigator.clipboard.writeText(t.url||t.text||""),this.sendNotification("Copied to clipboard",{body:"Link copied to clipboard"}),!0}catch(e){return console.error("Error copying to clipboard:",e),!1}}}String.prototype.pointLength=function(){let r=0;for(let t=0,e=this.length;t<e;){const s=this.codePointAt(t);t+=s>65535?2:1,r++}return r},String.prototype.pointAt=function(r){if(r>=this.pointLength())return;let t=0;for(let e=0,s=this.length;e<s;){const i=this.codePointAt(e);if(!i)return;if(t===r)return String.fromCodePoint(i);e+=i>65535?2:1,t++}},String.prototype.sliceByPoint=function(r,t=this.pointLength()){let e="";for(let s=r;s<t;s++)e+=this.pointAt(s);return e},RegExp.escape=function(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")},Element.prototype.farthest=function(r){if(typeof r!="string"||!r)return null;let t=null,e=this;for(;e;){const s=e.closest(r);if(!s)break;t=s,e=s.parentElement}return t},Object.defineProperties(Element.prototype,{firstElement:{get:function(){if(!this.children.length)return null;let r=this.firstElementChild,t=null;for(;r;)t=r,r=r.firstElementChild;return t}},lastElement:{get:function(){if(!this.children.length)return null;let r=this.lastElementChild,t=null;for(;r;)t=r,r=r.lastElementChild;return t}}}),Text.prototype.surround=function(r="strong",t=""){if(!this.nodeValue||!r||!t)return null;const s=r.split("."),i=s[0],n=s.slice(1).join(" "),o=this.textContent.indexOf(t);if(o<0)return null;const u=document.createRange();u.setStart(this,o),u.setEnd(this,o+t.length);const l=document.createElement(i);return n&&(l.className=n),u.surroundContents(l),l},a.Dictionary=R,a.DomHelper=v,a.Emitter=b,a.Graph=_,a.LIS=T,a.LRU=V,a.Line=p,a.LinkedList=D,a.Matrix=y,a.MaxHeap=z,a.MemoizeMap=q,a.MinHeap=N,a.Point=h,a.Queue=M,a.Roman=G,a.Stack=j,a.Triangle=c,a.Vector=d,a.WebAppManager=B,a.isValidBracket=W,a.singleton=F,a.sleep=$,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
package/index.d.ts CHANGED
@@ -1,125 +1,58 @@
1
- import { Vector } from "./lib/dataStructure";
2
-
3
1
  declare module "jc-structure" {
2
+ import type { IStack } from "./types/stack";
3
+ import type { IQueue } from "./types/queue";
4
+ import type { IHeap } from "./types/heap";
4
5
  /**
5
6
  * 栈类,采用object实现
6
7
  */
7
- export class Stack<T> implements IStack<T> {
8
- constructor();
9
- /**
10
- * #### 向栈顶添加元素
11
- * @param args 要添加的元素,可以是多个或一个元素。
12
- */
13
- push(...args: Array<T>): void;
14
- /**
15
- * #### 移除栈顶元素并返回该元素
16
- */
17
- pop(): T | undefined;
18
- /**
19
- * #### 返回栈顶元素,但不移除
20
- */
21
- peek(): T | undefined;
22
- /**
23
- * 判断数据结构是否为空
24
- */
25
- isEmpty(): boolean;
26
- /**
27
- * 数据结构元素长度
28
- */
29
- size(): number;
30
- /**
31
- * 重写 toString 方法
32
- */
33
- toString(): string;
34
- /**
35
- * 清除数据结构元素
36
- */
37
- clear(): void;
8
+ interface Stack<T> extends IStack<T> {}
9
+ interface StackConstructor {
10
+ new <T>(): Stack<T>;
11
+ readonly prototype: Stack<T>;
38
12
  }
13
+ declare const Stack: StackConstructor;
39
14
 
40
15
  /**
41
16
  * 队列类,采用object实现
42
17
  */
43
- export class Queue<T> implements IQueue<T> {
44
- constructor();
45
- /**
46
- * #### 向队列末尾添加元素
47
- * @param args 要添加的元素,可以是多个或一个元素。
48
- */
49
- enqueue(...args: Array<T>): void;
50
- /**
51
- * #### 移除队列头部元素并返回该元素
52
- */
53
- dequeue(): T | undefined;
54
- /**
55
- * #### 返回队列头部元素,但不移除
56
- */
57
- front(): T | undefined;
58
- /**
59
- * 判断数据结构是否为空
60
- */
61
- isEmpty(): boolean;
62
- /**
63
- * 数据结构元素长度
64
- */
65
- size(): number;
66
- /**
67
- * 重写 toString 方法
68
- */
69
- toString(): string;
70
- /**
71
- * 清除数据结构元素
72
- */
73
- clear(): void;
18
+ interface Queue<T> extends IQueue<T> {}
19
+ interface QueueConstructor {
20
+ new <T>(): Queue<T>;
21
+ readonly prototype: Queue<T>;
74
22
  }
23
+ declare const Queue: QueueConstructor;
75
24
 
76
- // export function compareFn(a: any, b: any): CompareResult;
25
+ type CompareResult = -1 | 0 | 1;
77
26
 
27
+ interface CompareFn<T> {
28
+ (a: T, b: T): CompareResult;
29
+ }
30
+
31
+ interface Obj<V = any> {
32
+ [key: string]: V;
33
+ }
78
34
  /**
79
35
  * 最小堆
80
36
  */
81
- export class MinHeap<T> {
82
- constructor(fn?: (a: T, b: T) => CompareResult);
83
- /**
84
- * 向堆中添加元素
85
- * @param args 要添加的元素,可以是多个或一个元素。
86
- */
87
- insert(...args: Array<T>): void;
88
- /**
89
- * #### 移除最小值或最大值,返回该值
90
- */
91
- extract(): T | undefined;
92
- /**
93
- * 查找一个值
94
- * @param value 要查找的值
95
- */
96
- find(): T | undefined;
97
- /**
98
- * 判断数据结构是否为空
99
- */
100
- isEmpty(): boolean;
101
- /**
102
- * 数据结构元素长度
103
- */
104
- size(): number;
105
- /**
106
- * 重写 toString 方法
107
- */
108
- toString(): string;
37
+ interface MinHeap<T> extends IHeap<T> {}
38
+ interface MinHeapConstructor {
39
+ new <T>(fn?: CompareFn<T>): MinHeap<T>;
40
+ readonly prototype: MinHeap<T>;
109
41
  }
42
+ declare const MinHeap: MinHeapConstructor;
110
43
 
111
44
  /**
112
45
  * 最大堆
113
46
  */
114
- export class MaxHeap<T> extends MinHeap<T> {
115
- constructor(fn?: (a: T, b: T) => CompareResult);
47
+ interface Constructor {
48
+ new <T>(fn?: CompareFn<T>): MinHeap<T>;
49
+ readonly prototype: MinHeap<T>;
116
50
  }
117
-
51
+ declare const MaxHeap: Constructor;
118
52
  /**
119
53
  * LRU缓存类
120
54
  */
121
- export class LRU<K, V> {
122
- constructor(capacity?: number);
55
+ interface LRU<K, V> {
123
56
  /**
124
57
  * 获取缓存的值
125
58
  * @param key 键值
@@ -132,6 +65,11 @@ declare module "jc-structure" {
132
65
  */
133
66
  update(key: K, value: V): void;
134
67
  }
68
+ interface LRUConstructor {
69
+ new <K, V>(capacity?: number): LRU<K, V>;
70
+ readonly prototype: LRU<K, V>;
71
+ }
72
+ declare const LRU: LRUConstructor;
135
73
 
136
74
  /**
137
75
  * 链表节点类
@@ -319,40 +257,47 @@ declare module "jc-structure" {
319
257
  /**
320
258
  * 罗马数字类
321
259
  */
322
- export class Roman {
260
+ interface RomanConstructor {
323
261
  /**
324
262
  * #### 转阿拉伯数字
325
263
  * @param str 罗马数字文本
326
264
  */
327
- static toInteger(str: string): number;
265
+ toInteger(str: string): number;
328
266
  /**
329
267
  * #### 转罗马数字
330
268
  * @param num 阿拉伯整数
331
269
  */
332
- static toRoman(num: number): string;
270
+ toRoman(num: number): string;
333
271
  }
272
+ declare const Roman: RomanConstructor;
334
273
 
335
- export class Point {
274
+ interface Point {
336
275
  /**
337
- * #### 点类构造函数
338
- * @param x x坐标
339
- * @param y y坐标
276
+ * #### 点x坐标
340
277
  */
341
- constructor(x: number, y: number);
278
+ readonly x: number;
342
279
  /**
343
- * #### 计算两点之间的距离
344
- * @param p1 点1
345
- * @param p2 点2
280
+ * #### 点y坐标
346
281
  */
347
- static distance(p1: Point, p2: Point): number;
282
+ readonly y: number;
348
283
  /**
349
284
  * #### 计算点与点之间的距离,实例方法
350
285
  * @param p 点p
351
286
  */
352
287
  distanceTo(p: Point): number;
353
288
  }
289
+ interface PointConstructor {
290
+ new (x: number, y: number): Point;
291
+ /**
292
+ * #### 计算两点之间的距离
293
+ * @param p1 点1
294
+ * @param p2 点2
295
+ */
296
+ distance(p1: Point, p2: Point): number;
297
+ }
298
+ declare var Point: PointConstructor;
354
299
 
355
- export class line {
300
+ interface Line {
356
301
  /**
357
302
  * #### 线段长度
358
303
  */
@@ -369,39 +314,130 @@ declare module "jc-structure" {
369
314
  * #### 获取线段的方向向量
370
315
  */
371
316
  get direction(): Point;
317
+ /**
318
+ * #### 获取线段的起点
319
+ */
320
+ get start(): Point;
321
+ /**
322
+ * #### 获取线段的终点
323
+ */
324
+ get end(): Point;
372
325
  /**
373
326
  * #### 判断点是否在线段上
374
327
  * @param point
328
+ * @param tolerance 容差,默认1e-10
375
329
  */
376
- containsPoint(point: Point): boolean;
330
+ containsPoint(point: Point, tolerance?: number): boolean;
377
331
  }
332
+ interface LineConstructor {
333
+ new (p1: Point, p2: Point): Line;
334
+ readonly prototype: Line;
378
335
 
379
- /**
380
- * ### 三角形类
381
- */
382
- export class Triangle {
383
336
  /**
384
- * #### 判断三条边是否能构成三角形
385
- * @param a 边长
386
- * @param b 边长
387
- * @param c 边长
337
+ * #### 判断线段是否平行
338
+ * @param line 线段
339
+ * @param tolerance 容差,默认1e-10
388
340
  */
389
- static isValid(a: number, b: number, c: number): boolean;
341
+ sloped(line: Line, tolerance?: number): number | null;
342
+
390
343
  /**
391
- * #### 计算三角形的面积,采用秦九昭公式或叫海伦面积公式
392
- * @param a 边长
393
- * @param b 边长
394
- * @param c 边长
344
+ * #### 判断线段是否平行
345
+ * @param line1 线段1
346
+ * @param line2 线段2
347
+ * @param tolerance 容差,默认1e-10
395
348
  */
396
- static area(a: number, b: number, c: number): number;
349
+ isParallel(line1: Line, line2: Line, tolerance?: number): boolean;
350
+
397
351
  /**
398
- * #### 获取三角形的角度
399
- * @param a 边长
400
- * @param b 边长
401
- * @param c 边长
352
+ * #### 判断线段是否相交
353
+ * @param line1 线段1
354
+ * @param line2 线段2
355
+ */
356
+ isIntersecting(line1: Line, line2: Line): boolean;
357
+
358
+ /**
359
+ * #### 获取两线段交点
360
+ * @param line1 线段1
361
+ * @param line2 线段2
362
+ * @param tolerance 容差,默认1e-10
363
+ */
364
+ getIntersection(line1: Line, line2: Line, tolerance?: number): Point | null;
365
+
366
+ /**
367
+ * #### 获取线段到点的距离
368
+ * @param line1 线段1
369
+ * @param line2 线段2
370
+ * @param tolerance 容差,默认1e-10
402
371
  */
403
- static getAngles(a: number, b: number, c: number): [number, number, number];
404
- constructor(p1: Point, p2: Point, p3: Point): Triangle;
372
+ distanceToPoint(line: Line, point: Point, tolerance?: number): number;
373
+ }
374
+ declare var Line: LineConstructor;
375
+
376
+ /**
377
+ * ### 三角形类
378
+ */
379
+ // export class Triangle {
380
+ // /**
381
+ // * #### 判断三条边是否能构成三角形
382
+ // * @param a 边长
383
+ // * @param b 边长
384
+ // * @param c 边长
385
+ // */
386
+ // static isValid(a: number, b: number, c: number): boolean;
387
+ // /**
388
+ // * #### 计算三角形的面积,采用秦九昭公式或叫海伦面积公式
389
+ // * @param a 边长
390
+ // * @param b 边长
391
+ // * @param c 边长
392
+ // */
393
+ // static area(a: number, b: number, c: number): number;
394
+ // /**
395
+ // * #### 获取三角形的角度
396
+ // * @param a 边长
397
+ // * @param b 边长
398
+ // * @param c 边长
399
+ // */
400
+ // static getAngles(a: number, b: number, c: number): [number, number, number];
401
+ // constructor(p1: Point, p2: Point, p3: Point): Triangle;
402
+ // /**
403
+ // * #### 获取三角形的边长
404
+ // */
405
+ // get side(): [number, number, number];
406
+ // /**
407
+ // * #### 获取三角形的内心点
408
+ // */
409
+ // get centroid(): Point;
410
+ // /**
411
+ // * #### 获取三角形的外切园心点
412
+ // */
413
+ // get circumcenter(): Point;
414
+ // /**
415
+ // * #### 获取三角形的内切园心点
416
+ // */
417
+ // get incenter(): Point;
418
+ // /**
419
+ // * #### 获取三角形的周长
420
+ // */
421
+ // perimeter(): number;
422
+ // /**
423
+ // * #### 获取三角形的面积
424
+ // */
425
+ // area(): number;
426
+ // /**
427
+ // * #### 判断点是否在三角形内
428
+ // * @param point
429
+ // */
430
+ // containsPoint(point: Point): boolean;
431
+ // }
432
+ enum TriangleType {
433
+ Equilateral = "equilateral", // 等边
434
+ Isosceles = "isosceles", // 等腰
435
+ Scalene = "scalene", // 不等边
436
+ }
437
+ interface Triangle {
438
+ readonly p1: Point;
439
+ readonly p2: Point;
440
+ readonly p3: Point;
405
441
  /**
406
442
  * #### 获取三角形的边长
407
443
  */
@@ -432,7 +468,35 @@ declare module "jc-structure" {
432
468
  */
433
469
  containsPoint(point: Point): boolean;
434
470
  }
471
+ interface TriangleConstructor {
472
+ new (p1: Point, p2: Point, p3: Point): Triangle;
473
+ readonly prototype: Triangle;
474
+
475
+ /**
476
+ * #### 判断三条边是否能构成三角形
477
+ * @param a
478
+ * @param b
479
+ * @param c
480
+ */
481
+ isValid(a: number, b: number, c: number): boolean;
482
+ /**
483
+ * #### 计算三角形的面积,采用秦九昭公式或叫海伦面积公式
484
+ * @param a
485
+ * @param b
486
+ * @param c
487
+ */
488
+ area(a: number, b: number, c: number): number;
489
+ /**
490
+ * #### 获取三角形的角度
491
+ * @param a
492
+ * @param b
493
+ * @param c
494
+ */
495
+ getAngles(a: number, b: number, c: number): [number, number, number];
435
496
 
497
+ getTYpe(a: number, b: number, c: number): TriangleType;
498
+ }
499
+ declare var Triangle: TriangleConstructor;
436
500
  /**
437
501
  * ### 向量类
438
502
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jc-structure",
3
3
  "private": false,
4
- "version": "0.1.1",
4
+ "version": "0.1.3",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
package/types/extend.d.ts CHANGED
@@ -20,3 +20,38 @@ interface String {
20
20
  */
21
21
  sliceByPoint(this: string, start: number, end?: number): string;
22
22
  }
23
+
24
+ interface RegExpConstructor {
25
+ /**
26
+ * #### 转义正则表达式中的特殊字符
27
+ * @param str 字符串
28
+ */
29
+ escape(str: string): string;
30
+ }
31
+
32
+ interface Element {
33
+ /**
34
+ * #### 获取最深元素集合中的第一个元素
35
+ */
36
+ readonly firstElement: Element | null;
37
+ /**
38
+ * #### 获取最深元素集合中的最后一个元素
39
+ */
40
+ readonly lastElement: Element | null;
41
+ /**
42
+ * #### 最祖先的匹配元素
43
+ * @param this element
44
+ * @param selector 选择器
45
+ */
46
+ farthest<E extends Element = Element>(this: E, selector: string): E | null;
47
+ }
48
+
49
+ interface Text {
50
+ /**
51
+ * #### 将文本节点包裹在指定标签中
52
+ * @param this Text 该文本节点
53
+ * @param selector 要包裹的元素标签,默认为:'strong'
54
+ * @param text 要包裹的文本,默认为:''
55
+ */
56
+ surround(this: Text, selector?: string, text?: string): HTMLElement | null;
57
+ }
package/types/heap.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ // import type { Structure } from "./global";
2
+
1
3
  interface IHeap<T> extends Structure {
2
4
  /**
3
5
  * #### 插入一个值,返回一个布尔值
package/types/queue.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ // import type { Structure } from "./global";
1
2
  interface IQueue<T> extends Structure {
2
3
  /**
3
4
  * #### 移除队列头部元素并返回该元素
@@ -0,0 +1,20 @@
1
+ interface Vector {
2
+ get dimension(): number;
3
+ get norm(): number;
4
+ getItem(index: number): number;
5
+ normalize(): Vector;
6
+ add(vector: Vector): Vector;
7
+ sub(vector: Vector): Vector;
8
+ mul(scalar: number): Vector;
9
+ dot(vector: Vector): number;
10
+ pos(): Vector;
11
+ neg(): Vector;
12
+ }
13
+
14
+ interface VectorConstructor {
15
+ new (...args: number[]): Vector;
16
+ readonly prototype: Vector;
17
+ zero(dimension: number): Vector;
18
+ }
19
+
20
+ declare var Vector: VectorConstructor;