UNPKG

@kajws/galaxy-js

Version:

A JavaScript port of the classic galaxy screensaver with 3D particle simulation

61 lines (60 loc) 29.1 kB
var GalaxyJS=function(p){var Mt;"use strict";/** * @license * Copyright 2019 Google LLC * SPDX-License-Identifier: BSD-3-Clause */const N=globalThis,W=N.ShadowRoot&&(N.ShadyCSS===void 0||N.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,B=Symbol(),st=new WeakMap;let it=class{constructor(t,e,s){if(this._$cssResult$=!0,s!==B)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(W&&t===void 0){const s=e!==void 0&&e.length===1;s&&(t=st.get(e)),t===void 0&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),s&&st.set(e,t))}return t}toString(){return this.cssText}};const Pt=o=>new it(typeof o=="string"?o:o+"",void 0,B),nt=(o,...t)=>{const e=o.length===1?o[0]:t.reduce((s,i,n)=>s+(a=>{if(a._$cssResult$===!0)return a.cssText;if(typeof a=="number")return a;throw Error("Value passed to 'css' function must be a 'css' function result: "+a+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+o[n+1],o[0]);return new it(e,o,B)},zt=(o,t)=>{if(W)o.adoptedStyleSheets=t.map(e=>e instanceof CSSStyleSheet?e:e.styleSheet);else for(const e of t){const s=document.createElement("style"),i=N.litNonce;i!==void 0&&s.setAttribute("nonce",i),s.textContent=e.cssText,o.appendChild(s)}},ot=W?o=>o:o=>o instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return Pt(e)})(o):o;/** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */const{is:Ot,defineProperty:Rt,getOwnPropertyDescriptor:Ut,getOwnPropertyNames:Gt,getOwnPropertySymbols:Tt,getPrototypeOf:It}=Object,g=globalThis,at=g.trustedTypes,Ht=at?at.emptyScript:"",V=g.reactiveElementPolyfillSupport,O=(o,t)=>o,F={toAttribute(o,t){switch(t){case Boolean:o=o?Ht:null;break;case Object:case Array:o=o==null?o:JSON.stringify(o)}return o},fromAttribute(o,t){let e=o;switch(t){case Boolean:e=o!==null;break;case Number:e=o===null?null:Number(o);break;case Object:case Array:try{e=JSON.parse(o)}catch{e=null}}return e}},J=(o,t)=>!Ot(o,t),rt={attribute:!0,type:String,converter:F,reflect:!1,useDefault:!1,hasChanged:J};Symbol.metadata??(Symbol.metadata=Symbol("metadata")),g.litPropertyMetadata??(g.litPropertyMetadata=new WeakMap);let E=class extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??(this.l=[])).push(t)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,e=rt){if(e.state&&(e.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(t)&&((e=Object.create(e)).wrapped=!0),this.elementProperties.set(t,e),!e.noAccessor){const s=Symbol(),i=this.getPropertyDescriptor(t,s,e);i!==void 0&&Rt(this.prototype,t,i)}}static getPropertyDescriptor(t,e,s){const{get:i,set:n}=Ut(this.prototype,t)??{get(){return this[e]},set(a){this[e]=a}};return{get:i,set(a){const h=i==null?void 0:i.call(this);n==null||n.call(this,a),this.requestUpdate(t,h,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??rt}static _$Ei(){if(this.hasOwnProperty(O("elementProperties")))return;const t=It(this);t.finalize(),t.l!==void 0&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(O("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(O("properties"))){const e=this.properties,s=[...Gt(e),...Tt(e)];for(const i of s)this.createProperty(i,e[i])}const t=this[Symbol.metadata];if(t!==null){const e=litPropertyMetadata.get(t);if(e!==void 0)for(const[s,i]of e)this.elementProperties.set(s,i)}this._$Eh=new Map;for(const[e,s]of this.elementProperties){const i=this._$Eu(e,s);i!==void 0&&this._$Eh.set(i,e)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const s=new Set(t.flat(1/0).reverse());for(const i of s)e.unshift(ot(i))}else t!==void 0&&e.push(ot(t));return e}static _$Eu(t,e){const s=e.attribute;return s===!1?void 0:typeof s=="string"?s:typeof t=="string"?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){var t;this._$ES=new Promise(e=>this.enableUpdating=e),this._$AL=new Map,this._$E_(),this.requestUpdate(),(t=this.constructor.l)==null||t.forEach(e=>e(this))}addController(t){var e;(this._$EO??(this._$EO=new Set)).add(t),this.renderRoot!==void 0&&this.isConnected&&((e=t.hostConnected)==null||e.call(t))}removeController(t){var e;(e=this._$EO)==null||e.delete(t)}_$E_(){const t=new Map,e=this.constructor.elementProperties;for(const s of e.keys())this.hasOwnProperty(s)&&(t.set(s,this[s]),delete this[s]);t.size>0&&(this._$Ep=t)}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return zt(t,this.constructor.elementStyles),t}connectedCallback(){var t;this.renderRoot??(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),(t=this._$EO)==null||t.forEach(e=>{var s;return(s=e.hostConnected)==null?void 0:s.call(e)})}enableUpdating(t){}disconnectedCallback(){var t;(t=this._$EO)==null||t.forEach(e=>{var s;return(s=e.hostDisconnected)==null?void 0:s.call(e)})}attributeChangedCallback(t,e,s){this._$AK(t,s)}_$ET(t,e){var n;const s=this.constructor.elementProperties.get(t),i=this.constructor._$Eu(t,s);if(i!==void 0&&s.reflect===!0){const a=(((n=s.converter)==null?void 0:n.toAttribute)!==void 0?s.converter:F).toAttribute(e,s.type);this._$Em=t,a==null?this.removeAttribute(i):this.setAttribute(i,a),this._$Em=null}}_$AK(t,e){var n,a;const s=this.constructor,i=s._$Eh.get(t);if(i!==void 0&&this._$Em!==i){const h=s.getPropertyOptions(i),r=typeof h.converter=="function"?{fromAttribute:h.converter}:((n=h.converter)==null?void 0:n.fromAttribute)!==void 0?h.converter:F;this._$Em=i,this[i]=r.fromAttribute(e,h.type)??((a=this._$Ej)==null?void 0:a.get(i))??null,this._$Em=null}}requestUpdate(t,e,s){var i;if(t!==void 0){const n=this.constructor,a=this[t];if(s??(s=n.getPropertyOptions(t)),!((s.hasChanged??J)(a,e)||s.useDefault&&s.reflect&&a===((i=this._$Ej)==null?void 0:i.get(t))&&!this.hasAttribute(n._$Eu(t,s))))return;this.C(t,e,s)}this.isUpdatePending===!1&&(this._$ES=this._$EP())}C(t,e,{useDefault:s,reflect:i,wrapped:n},a){s&&!(this._$Ej??(this._$Ej=new Map)).has(t)&&(this._$Ej.set(t,a??e??this[t]),n!==!0||a!==void 0)||(this._$AL.has(t)||(this.hasUpdated||s||(e=void 0),this._$AL.set(t,e)),i===!0&&this._$Em!==t&&(this._$Eq??(this._$Eq=new Set)).add(t))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(e){Promise.reject(e)}const t=this.scheduleUpdate();return t!=null&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var s;if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??(this.renderRoot=this.createRenderRoot()),this._$Ep){for(const[n,a]of this._$Ep)this[n]=a;this._$Ep=void 0}const i=this.constructor.elementProperties;if(i.size>0)for(const[n,a]of i){const{wrapped:h}=a,r=this[n];h!==!0||this._$AL.has(n)||r===void 0||this.C(n,void 0,a,r)}}let t=!1;const e=this._$AL;try{t=this.shouldUpdate(e),t?(this.willUpdate(e),(s=this._$EO)==null||s.forEach(i=>{var n;return(n=i.hostUpdate)==null?void 0:n.call(i)}),this.update(e)):this._$EM()}catch(i){throw t=!1,this._$EM(),i}t&&this._$AE(e)}willUpdate(t){}_$AE(t){var e;(e=this._$EO)==null||e.forEach(s=>{var i;return(i=s.hostUpdated)==null?void 0:i.call(s)}),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return!0}update(t){this._$Eq&&(this._$Eq=this._$Eq.forEach(e=>this._$ET(e,this[e]))),this._$EM()}updated(t){}firstUpdated(t){}};E.elementStyles=[],E.shadowRootOptions={mode:"open"},E[O("elementProperties")]=new Map,E[O("finalized")]=new Map,V==null||V({ReactiveElement:E}),(g.reactiveElementVersions??(g.reactiveElementVersions=[])).push("2.1.0");/** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */const R=globalThis,j=R.trustedTypes,ht=j?j.createPolicy("lit-html",{createHTML:o=>o}):void 0,lt="$lit$",v=`lit$${Math.random().toFixed(9).slice(2)}$`,ct="?"+v,Nt=`<${ct}>`,x=document,U=()=>x.createComment(""),G=o=>o===null||typeof o!="object"&&typeof o!="function",K=Array.isArray,Ft=o=>K(o)||typeof(o==null?void 0:o[Symbol.iterator])=="function",X=`[ \f\r]`,T=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,dt=/-->/g,ut=/>/g,S=RegExp(`>|${X}(?:([^\\s"'>=/]+)(${X}*=${X}*(?:[^ \f\r"'\`<>=]|("|')|))|$)`,"g"),pt=/'/g,mt=/"/g,_t=/^(?:script|style|textarea|title)$/i,jt=o=>(t,...e)=>({_$litType$:o,strings:t,values:e}),yt=jt(1),C=Symbol.for("lit-noChange"),_=Symbol.for("lit-nothing"),ft=new WeakMap,b=x.createTreeWalker(x,129);function $t(o,t){if(!K(o)||!o.hasOwnProperty("raw"))throw Error("invalid template strings array");return ht!==void 0?ht.createHTML(t):t}const qt=(o,t)=>{const e=o.length-1,s=[];let i,n=t===2?"<svg>":t===3?"<math>":"",a=T;for(let h=0;h<e;h++){const r=o[h];let l,u,c=-1,m=0;for(;m<r.length&&(a.lastIndex=m,u=a.exec(r),u!==null);)m=a.lastIndex,a===T?u[1]==="!--"?a=dt:u[1]!==void 0?a=ut:u[2]!==void 0?(_t.test(u[2])&&(i=RegExp("</"+u[2],"g")),a=S):u[3]!==void 0&&(a=S):a===S?u[0]===">"?(a=i??T,c=-1):u[1]===void 0?c=-2:(c=a.lastIndex-u[2].length,l=u[1],a=u[3]===void 0?S:u[3]==='"'?mt:pt):a===mt||a===pt?a=S:a===dt||a===ut?a=T:(a=S,i=void 0);const y=a===S&&o[h+1].startsWith("/>")?" ":"";n+=a===T?r+Nt:c>=0?(s.push(l),r.slice(0,c)+lt+r.slice(c)+v+y):r+v+(c===-2?h:y)}return[$t(o,n+(o[e]||"<?>")+(t===2?"</svg>":t===3?"</math>":"")),s]};class I{constructor({strings:t,_$litType$:e},s){let i;this.parts=[];let n=0,a=0;const h=t.length-1,r=this.parts,[l,u]=qt(t,e);if(this.el=I.createElement(l,s),b.currentNode=this.el.content,e===2||e===3){const c=this.el.content.firstChild;c.replaceWith(...c.childNodes)}for(;(i=b.nextNode())!==null&&r.length<h;){if(i.nodeType===1){if(i.hasAttributes())for(const c of i.getAttributeNames())if(c.endsWith(lt)){const m=u[a++],y=i.getAttribute(c).split(v),f=/([.?@])?(.*)/.exec(m);r.push({type:1,index:n,name:f[2],strings:y,ctor:f[1]==="."?kt:f[1]==="?"?Lt:f[1]==="@"?Wt:q}),i.removeAttribute(c)}else c.startsWith(v)&&(r.push({type:6,index:n}),i.removeAttribute(c));if(_t.test(i.tagName)){const c=i.textContent.split(v),m=c.length-1;if(m>0){i.textContent=j?j.emptyScript:"";for(let y=0;y<m;y++)i.append(c[y],U()),b.nextNode(),r.push({type:2,index:++n});i.append(c[m],U())}}}else if(i.nodeType===8)if(i.data===ct)r.push({type:2,index:n});else{let c=-1;for(;(c=i.data.indexOf(v,c+1))!==-1;)r.push({type:7,index:n}),c+=v.length-1}n++}}static createElement(t,e){const s=x.createElement("template");return s.innerHTML=t,s}}function M(o,t,e=o,s){var a,h;if(t===C)return t;let i=s!==void 0?(a=e._$Co)==null?void 0:a[s]:e._$Cl;const n=G(t)?void 0:t._$litDirective$;return(i==null?void 0:i.constructor)!==n&&((h=i==null?void 0:i._$AO)==null||h.call(i,!1),n===void 0?i=void 0:(i=new n(o),i._$AT(o,e,s)),s!==void 0?(e._$Co??(e._$Co=[]))[s]=i:e._$Cl=i),i!==void 0&&(t=M(o,i._$AS(o,t.values),i,s)),t}class Dt{constructor(t,e){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:e},parts:s}=this._$AD,i=((t==null?void 0:t.creationScope)??x).importNode(e,!0);b.currentNode=i;let n=b.nextNode(),a=0,h=0,r=s[0];for(;r!==void 0;){if(a===r.index){let l;r.type===2?l=new H(n,n.nextSibling,this,t):r.type===1?l=new r.ctor(n,r.name,r.strings,this,t):r.type===6&&(l=new Bt(n,this,t)),this._$AV.push(l),r=s[++h]}a!==(r==null?void 0:r.index)&&(n=b.nextNode(),a++)}return b.currentNode=x,i}p(t){let e=0;for(const s of this._$AV)s!==void 0&&(s.strings!==void 0?(s._$AI(t,s,e),e+=s.strings.length-2):s._$AI(t[e])),e++}}class H{get _$AU(){var t;return((t=this._$AM)==null?void 0:t._$AU)??this._$Cv}constructor(t,e,s,i){this.type=2,this._$AH=_,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=s,this.options=i,this._$Cv=(i==null?void 0:i.isConnected)??!0}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return e!==void 0&&(t==null?void 0:t.nodeType)===11&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=M(this,t,e),G(t)?t===_||t==null||t===""?(this._$AH!==_&&this._$AR(),this._$AH=_):t!==this._$AH&&t!==C&&this._(t):t._$litType$!==void 0?this.$(t):t.nodeType!==void 0?this.T(t):Ft(t)?this.k(t):this._(t)}O(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t))}_(t){this._$AH!==_&&G(this._$AH)?this._$AA.nextSibling.data=t:this.T(x.createTextNode(t)),this._$AH=t}$(t){var n;const{values:e,_$litType$:s}=t,i=typeof s=="number"?this._$AC(t):(s.el===void 0&&(s.el=I.createElement($t(s.h,s.h[0]),this.options)),s);if(((n=this._$AH)==null?void 0:n._$AD)===i)this._$AH.p(e);else{const a=new Dt(i,this),h=a.u(this.options);a.p(e),this.T(h),this._$AH=a}}_$AC(t){let e=ft.get(t.strings);return e===void 0&&ft.set(t.strings,e=new I(t)),e}k(t){K(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let s,i=0;for(const n of t)i===e.length?e.push(s=new H(this.O(U()),this.O(U()),this,this.options)):s=e[i],s._$AI(n),i++;i<e.length&&(this._$AR(s&&s._$AB.nextSibling,i),e.length=i)}_$AR(t=this._$AA.nextSibling,e){var s;for((s=this._$AP)==null?void 0:s.call(this,!1,!0,e);t&&t!==this._$AB;){const i=t.nextSibling;t.remove(),t=i}}setConnected(t){var e;this._$AM===void 0&&(this._$Cv=t,(e=this._$AP)==null||e.call(this,t))}}class q{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,e,s,i,n){this.type=1,this._$AH=_,this._$AN=void 0,this.element=t,this.name=e,this._$AM=i,this.options=n,s.length>2||s[0]!==""||s[1]!==""?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=_}_$AI(t,e=this,s,i){const n=this.strings;let a=!1;if(n===void 0)t=M(this,t,e,0),a=!G(t)||t!==this._$AH&&t!==C,a&&(this._$AH=t);else{const h=t;let r,l;for(t=n[0],r=0;r<n.length-1;r++)l=M(this,h[s+r],e,r),l===C&&(l=this._$AH[r]),a||(a=!G(l)||l!==this._$AH[r]),l===_?t=_:t!==_&&(t+=(l??"")+n[r+1]),this._$AH[r]=l}a&&!i&&this.j(t)}j(t){t===_?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"")}}class kt extends q{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===_?void 0:t}}class Lt extends q{constructor(){super(...arguments),this.type=4}j(t){this.element.toggleAttribute(this.name,!!t&&t!==_)}}class Wt extends q{constructor(t,e,s,i,n){super(t,e,s,i,n),this.type=5}_$AI(t,e=this){if((t=M(this,t,e,0)??_)===C)return;const s=this._$AH,i=t===_&&s!==_||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,n=t!==_&&(s===_||i);i&&this.element.removeEventListener(this.name,this,s),n&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){var e;typeof this._$AH=="function"?this._$AH.call(((e=this.options)==null?void 0:e.host)??this.element,t):this._$AH.handleEvent(t)}}class Bt{constructor(t,e,s){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=s}get _$AU(){return this._$AM._$AU}_$AI(t){M(this,t)}}const Y=R.litHtmlPolyfillSupport;Y==null||Y(I,H),(R.litHtmlVersions??(R.litHtmlVersions=[])).push("3.3.0");const Vt=(o,t,e)=>{const s=(e==null?void 0:e.renderBefore)??t;let i=s._$litPart$;if(i===void 0){const n=(e==null?void 0:e.renderBefore)??null;s._$litPart$=i=new H(t.insertBefore(U(),n),n,void 0,e??{})}return i._$AI(o),i};/** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */const w=globalThis;class P extends E{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){var e;const t=super.createRenderRoot();return(e=this.renderOptions).renderBefore??(e.renderBefore=t.firstChild),t}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=Vt(e,this.renderRoot,this.renderOptions)}connectedCallback(){var t;super.connectedCallback(),(t=this._$Do)==null||t.setConnected(!0)}disconnectedCallback(){var t;super.disconnectedCallback(),(t=this._$Do)==null||t.setConnected(!1)}render(){return C}}P._$litElement$=!0,P.finalized=!0,(Mt=w.litElementHydrateSupport)==null||Mt.call(w,{LitElement:P});const Z=w.litElementPolyfillSupport;Z==null||Z({LitElement:P}),(w.litElementVersions??(w.litElementVersions=[])).push("4.2.0");/** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */const gt=o=>(t,e)=>{e!==void 0?e.addInitializer(()=>{customElements.define(o,t)}):customElements.define(o,t)};/** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */const Jt={attribute:!0,type:String,converter:F,reflect:!1,hasChanged:J},Kt=(o=Jt,t,e)=>{const{kind:s,metadata:i}=e;let n=globalThis.litPropertyMetadata.get(i);if(n===void 0&&globalThis.litPropertyMetadata.set(i,n=new Map),s==="setter"&&((o=Object.create(o)).wrapped=!0),n.set(e.name,o),s==="accessor"){const{name:a}=e;return{set(h){const r=t.get.call(this);t.set.call(this,h),this.requestUpdate(a,r,o)},init(h){return h!==void 0&&this.C(a,void 0,o,h),h}}}if(s==="setter"){const{name:a}=e;return function(h){const r=this[a];t.call(this,h),this.requestUpdate(a,r,o)}}throw Error("Unsupported decorator location: "+s)};function z(o){return(t,e)=>typeof e=="object"?Kt(o,t,e):((s,i,n)=>{const a=i.hasOwnProperty(n);return i.constructor.createProperty(n,s),a?Object.getOwnPropertyDescriptor(i,n):void 0})(o,t,e)}/** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */const vt=(o,t,e)=>(e.configurable=!0,e.enumerable=!0,Reflect.decorate&&typeof t!="object"&&Object.defineProperty(o,t,e),e);/** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */function At(o,t){return(e,s,i)=>{const n=a=>{var h;return((h=a.renderRoot)==null?void 0:h.querySelector(o))??null};if(t){const{get:a,set:h}=typeof s=="object"?e:i??(()=>{const r=Symbol();return{get(){return this[r]},set(l){this[r]=l}}})();return vt(e,s,{get(){let r=a.call(this);return r===void 0&&(r=n(this),(r!==null||this.hasUpdated)&&h.call(this,r)),r}})}return vt(e,s,{get(){return n(this)}})}}class xt{constructor(t,e,s,i){if(this.stars=[],this.data={},!t)throw new Error("Velocity is required");if(!e)throw new Error("Position is required");if(!s)throw new Error("Rotation is required");this.vel=t,this.pos=e,this.rotation=s,this.mass=i}}class St{constructor(t,e,s=0){if(this.data={},!t)throw new Error("Position is required");if(!e)throw new Error("Velocity is required");this.pos=t,this.vel=e,this.mass=s}}const Q=(o,t)=>{for(const e of o)for(let s=0;s<e.stars.length;s++)t(e.stars[s],e,s)},bt=Math.PI*2,D=()=>Math.random()*bt,Xt=(o,t)=>Math.random()*(t-o)+o;class d{constructor(t=0,e=0,s=0){this.x=t,this.y=e,this.z=s}static zero(){return new d(0,0,0)}static random(t=1){return new d(Math.random(),Math.random(),Math.random()).mul(t)}static randomCentered(t=1){return d.random().sub(.5).mul(t)}get magnitude(){return Math.sqrt(this.x**2+this.y**2+this.z**2)}copy(){return new d(this.x,this.y,this.z)}sub(t){return typeof t=="number"?new d(this.x-t,this.y-t,this.z-t):new d(this.x-t.x,this.y-t.y,this.z-t.z)}add(t){return typeof t=="number"?new d(this.x+t,this.y+t,this.z+t):new d(this.x+t.x,this.y+t.y,this.z+t.z)}mul(t){return typeof t=="number"?new d(this.x*t,this.y*t,this.z*t):new d(this.x*t.x,this.y*t.y,this.z*t.z)}div(t){return typeof t=="number"?new d(this.x/t,this.y/t,this.z/t):new d(this.x/t.x,this.y/t.y,this.z/t.z)}normalize(){return this.div(this.magnitude)}}class ${constructor(t){if(t.length!==3)throw new Error(`Matrix must have 3 rows, got ${t.length}`);for(let e=0;e<t.length;e++)if(t[e].length!==3)throw new Error(`Row ${e} must have 3 columns, got ${t[e].length}`);this.data=t.map(e=>[...e])}static identity(){return new $([[1,0,0],[0,1,0],[0,0,1]])}static fromEuler(t,e,s){const i=Math.cos(t),n=Math.sin(t),a=Math.cos(e),h=Math.sin(e),r=Math.cos(s),l=Math.sin(s);return new $([[r*a,r*h*n-l*i,r*h*i+l*n],[l*a,l*h*n+r*i,l*h*i-r*n],[-h,a*n,a*i]])}static randomRotation(){const t=D(),e=D(),s=D();return $.fromEuler(t,e,s)}static fromAxisAngle(t,e){const s=t.x,i=t.y,n=t.z,a=Math.cos(e),h=Math.sin(e),r=1-a,l=r*s*s+a,u=r*s*i-n*h,c=r*s*n+i*h,m=r*i*s+n*h,y=r*i*i+a,f=r*i*n-s*h,et=r*n*s-i*h,L=r*n*i+s*h,se=r*n*n+a;return new $([[l,u,c],[m,y,f],[et,L,se]])}transform(t){return new d(this.data[0][0]*t.x+this.data[1][0]*t.y+this.data[2][0]*t.z,this.data[0][1]*t.x+this.data[1][1]*t.y+this.data[2][1]*t.z,this.data[0][2]*t.x+this.data[1][2]*t.y+this.data[2][2]*t.z)}mul(t){const e=[];for(let s=0;s<3;s++){e[s]=[];for(let i=0;i<3;i++){e[s][i]=0;for(let n=0;n<3;n++)e[s][i]+=this.data[s][n]*t.data[n][i]}}return new $(e)}get(t,e){return this.data[t][e]}set(t,e,s){this.data[t][e]=s}toArray(){return this.data.map(t=>[...t])}toEuler(){return new d(Math.atan2(this.data[2][1],this.data[2][2]),Math.asin(-this.data[2][0]),Math.atan2(this.data[1][0],this.data[0][0]))}}const k=.005,tt=.001,wt=o=>{Q(o,t=>{let e=d.zero();for(const i of o){const n=i.pos.sub(t.pos),a=n.magnitude**2;if(a===0)continue;const h=Math.sqrt(a),r=tt*i.mass/(h*a),l=n.mul(r);e=e.add(l)}const s=e.mul(k);t.vel=t.vel.add(s),t.pos=t.pos.add(t.vel.mul(k))});for(const t of o){let e=d.zero();for(const i of o){if(t===i)continue;const n=i.pos.sub(t.pos),a=n.magnitude**2;if(a===0)continue;const h=Math.sqrt(a),r=tt*i.mass/(h*a),l=n.mul(r);e=e.add(l)}const s=e.mul(k);t.vel=t.vel.add(s)}for(const t of o)t.pos=t.pos.add(t.vel.mul(k))},Et=o=>{const{minStarCount:t=1500,maxStarCount:e,minGalaxyRadius:s=1,maxGalaxyRadius:i,maxInitialSpeed:n=4,rewindTimeSteps:a=3,initialCollisionAvoidanceOffset:h=1.5}=o,r=d.randomCentered(n),u=r.mul(-a).add(d.randomCentered(h)),c=d.random(Math.PI),m=e?Math.random()*(e-t)+t:t,y=i?Math.random()*(i-s)+s:s,f=new xt(r,u,c,m),et=$.fromEuler(f.rotation.x,f.rotation.y,f.rotation.z);for(let L=0;L<m;L++)f.stars.push(Yt(f,et,y));return f},Yt=(o,t,e=1)=>{const s=2*Math.PI*Math.random(),i=Math.random()*e;let n=Math.random()*Math.exp(-2*(i/e))/5*e;Math.random()<.5&&(n=-n);const a=Math.sqrt(i**2+n**2),h=Math.sqrt(o.mass*tt/a),r=Math.sin(s),l=Math.cos(s),u=new d(i*l,i*r,n),c=new d(-h*r,h*l,0),m=t.transform(u).add(o.pos),y=t.transform(c).add(o.vel);return new St(m,y)};var Zt=Object.defineProperty,Qt=Object.getOwnPropertyDescriptor,A=(o,t,e,s)=>{for(var i=s>1?void 0:s?Qt(t,e):t,n=o.length-1,a;n>=0;n--)(a=o[n])&&(i=(s?a(t,e,i):a(i))||i);return s&&i&&Zt(t,e,i),i};p.GalaxySimulation=class extends P{constructor(){super(...arguments),this.galaxyCount=3,this.maxGalaxyCount=3,this.zoomFactor=1,this.rotation=.1,this._simulator=null,this._galaxyFactory=null,this._galaxies=[],this._ctx=null,this._animationFrameId=null,this._step=0,this._rotation_vector=null,this._animate=()=>{this._galaxies&&this._simulator&&this._simulator.updateGalaxies(this._galaxies),this._draw(),this._step++,this._step>1500&&(this._initialiseGalaxies(),this._updateRotation()),this._animationFrameId=requestAnimationFrame(this._animate)}}render(){return yt`<canvas id="galaxyCanvas"></canvas>`}firstUpdated(){this._ctx=this._canvas.getContext("2d"),this._resizeObserver=new ResizeObserver(()=>this._handleResize()),this._resizeObserver.observe(this),this._handleResize(),this._initialiseGalaxies(),this._updateRotation(),this._startAnimation()}updated(t){(t.has("galaxyCount")||t.has("maxGalaxyCount")||t.has("simulator")||t.has("galaxyFactory"))&&this._initialiseGalaxies()}disconnectedCallback(){super.disconnectedCallback(),this._stopAnimation(),this._resizeObserver.disconnect()}_updateRotation(){if(!this.rotation)this._rotation_vector=null;else if(typeof this.rotation=="number"||typeof this.rotation=="string"&&!this.rotation.includes(",")){const e=Number(this.rotation)*(Math.PI/180);this._rotation_vector=d.random(e)}else if(typeof this.rotation=="string"){const[t,e,s]=this.rotation.split(",").map(Number),i=t*(Math.PI/180),n=e*(Math.PI/180),a=s*(Math.PI/180);this._rotation_vector=new d(i,n,a)}}_initialiseGalaxies(){this._simulator=this.simulator||{updateGalaxies:wt},this._galaxyFactory=this.galaxyFactory||{createRandomGalaxy:()=>Et({minStarCount:700,maxStarCount:1e3,minGalaxyRadius:.5,maxGalaxyRadius:1.5})};const t=Math.floor(Math.random()*(this.maxGalaxyCount-this.galaxyCount)+this.galaxyCount),e=Math.random()*360,s=360/t;this._galaxies=[];for(let i=0;i<t;i++){const n=this._galaxyFactory.createRandomGalaxy();n.data.color=`hsl(${e+i*s}, 50%, 80%)`,this._galaxies.push(n)}this._step=0}_draw(){if(!this._ctx||!this._canvas)return;const t=this._canvas.width,e=this._canvas.height,s=(t+e)/40*this.zoomFactor;this._ctx.fillStyle="rgba(0, 0, 0, 0.4)",this._ctx.fillRect(0,0,t,e);const i=this._ctx,n=this._galaxies.reduce((h,r)=>h.add(r.pos),new d(0,0,0)).div(this._galaxies.length);let a=$.identity();if(this._rotation_vector){const h=this._rotation_vector.magnitude,r=this._rotation_vector.normalize(),l=h*this._step;a=$.fromAxisAngle(r,l)}Q(this._galaxies,(h,r)=>{if(!r.data.color){const m=`hsl(${Math.random()*360}, 100%, 50%)`;r.data.color=m}i.fillStyle=r.data.color;const l=a?a.transform(h.pos):h.pos,u=Math.floor((l.x-n.x)*s)+t/2,c=Math.floor((l.y-n.y)*s)+e/2;u>=0&&u<t&&c>=0&&c<e&&i.fillRect(u,c,1,1)})}_startAnimation(){this._animationFrameId||this._animate()}_stopAnimation(){this._animationFrameId&&(cancelAnimationFrame(this._animationFrameId),this._animationFrameId=null)}_handleResize(){const t=window.devicePixelRatio||1;this._canvas&&(this._canvas.width=this.clientWidth*t,this._canvas.height=this.clientHeight*t)}},p.GalaxySimulation.styles=nt` :host { display: block; width: 100%; height: 100%; } canvas { display: block; width: 100%; height: 100%; } `,A([z({type:Number,attribute:"galaxy-count"})],p.GalaxySimulation.prototype,"galaxyCount",2),A([z({type:Number,attribute:"max-galaxy-count"})],p.GalaxySimulation.prototype,"maxGalaxyCount",2),A([z({type:Number,attribute:"zoom"})],p.GalaxySimulation.prototype,"zoomFactor",2),A([z({type:String,attribute:"rotation"})],p.GalaxySimulation.prototype,"rotation",2),A([z({type:Object,attribute:"simulator"})],p.GalaxySimulation.prototype,"simulator",2),A([z({type:Object,attribute:"galaxy-factory"})],p.GalaxySimulation.prototype,"galaxyFactory",2),A([At("#galaxyCanvas")],p.GalaxySimulation.prototype,"_canvas",2),p.GalaxySimulation=A([gt("galaxy-simulation")],p.GalaxySimulation);var te=Object.defineProperty,ee=Object.getOwnPropertyDescriptor,Ct=(o,t,e,s)=>{for(var i=s>1?void 0:s?ee(t,e):t,n=o.length-1,a;n>=0;n--)(a=o[n])&&(i=(s?a(t,e,i):a(i))||i);return s&&i&&te(t,e,i),i};return p.SimpleGalaxySimulation=class extends P{constructor(){super(...arguments),this._ctx=null,this._galaxies=[],this._animationFrameId=null,this._step=0,this._animate=()=>{wt(this._galaxies),this._draw(),this._animationFrameId=requestAnimationFrame(this._animate),this._step++,this._step>1500&&(this._step=0,this._initialiseSimulation())}}render(){return yt`<canvas id="galaxyCanvas"></canvas>`}firstUpdated(){this._ctx=this._canvas.getContext("2d"),this._resizeObserver=new ResizeObserver(()=>this._handleResize()),this._resizeObserver.observe(this),this._initialiseSimulation(),this._startAnimation()}disconnectedCallback(){super.disconnectedCallback(),this._stopAnimation(),this._resizeObserver.disconnect()}_initialiseSimulation(){this._galaxies=[];const e=["#ffadad","#a0c4ff","#fdffb6"];for(let s=0;s<3;s++){const i=Et({minStarCount:700,maxStarCount:1e3,minGalaxyRadius:.5,maxGalaxyRadius:1.5});i.data.color=e[s%e.length],this._galaxies.push(i)}}_draw(){if(!this._ctx||!this._canvas)return;const{width:t,height:e}=this._canvas;this._ctx.fillStyle="rgba(0, 0, 0, 0.4)",this._ctx.fillRect(0,0,t,e);const s=(t+e)/40;Q(this._galaxies,(i,n)=>{this._ctx.fillStyle=n.data.color;const a=Math.floor(i.pos.x*s)+t/2,h=Math.floor(i.pos.y*s)+e/2;a>=0&&a<t&&h>=0&&h<e&&this._ctx.fillRect(a,h,1,1)})}_startAnimation(){this._animationFrameId||this._animate()}_stopAnimation(){this._animationFrameId&&(cancelAnimationFrame(this._animationFrameId),this._animationFrameId=null)}_handleResize(){if(!this._canvas)return;const t=window.devicePixelRatio||1;this._canvas.width=this.clientWidth*t,this._canvas.height=this.clientHeight*t}},p.SimpleGalaxySimulation.styles=nt` /* Styles for the host element itself (<simple-galaxy-simulation>) */ :host { display: block; /* Ensures the component takes up layout space */ width: 100%; height: 100%; overflow: hidden; /* Hides anything drawn outside the component's bounds */ } /* Styles for the canvas element inside the component */ canvas { display: block; width: 100%; height: 100%; } `,Ct([At("#galaxyCanvas")],p.SimpleGalaxySimulation.prototype,"_canvas",2),p.SimpleGalaxySimulation=Ct([gt("simple-galaxy-simulation")],p.SimpleGalaxySimulation),p.Galaxy=xt,p.Matrix3x3=$,p.Star=St,p.TWO_PI=bt,p.Vec3=d,p.randomAngle=D,p.randomAngleInRange=Xt,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"}),p}({});