@kajws/galaxy-js
Version:
A JavaScript port of the classic galaxy screensaver with 3D particle simulation
61 lines (60 loc) • 28.6 kB
JavaScript
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/const j=globalThis,Z=j.ShadowRoot&&(j.ShadyCSS===void 0||j.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,Q=Symbol(),it=new WeakMap;let _t=class{constructor(t,e,s){if(this._$cssResult$=!0,s!==Q)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(Z&&t===void 0){const s=e!==void 0&&e.length===1;s&&(t=it.get(e)),t===void 0&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),s&&it.set(e,t))}return t}toString(){return this.cssText}};const Pt=n=>new _t(typeof n=="string"?n:n+"",void 0,Q),ft=(n,...t)=>{const e=n.length===1?n[0]:t.reduce((s,i,o)=>s+(r=>{if(r._$cssResult$===!0)return r.cssText;if(typeof r=="number")return r;throw Error("Value passed to 'css' function must be a 'css' function result: "+r+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+n[o+1],n[0]);return new _t(e,n,Q)},Mt=(n,t)=>{if(Z)n.adoptedStyleSheets=t.map(e=>e instanceof CSSStyleSheet?e:e.styleSheet);else for(const e of t){const s=document.createElement("style"),i=j.litNonce;i!==void 0&&s.setAttribute("nonce",i),s.textContent=e.cssText,n.appendChild(s)}},nt=Z?n=>n:n=>n instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return Pt(e)})(n):n;/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/const{is:zt,defineProperty:Ot,getOwnPropertyDescriptor:Rt,getOwnPropertyNames:Ut,getOwnPropertySymbols:Tt,getPrototypeOf:Ht}=Object,v=globalThis,ot=v.trustedTypes,It=ot?ot.emptyScript:"",W=v.reactiveElementPolyfillSupport,R=(n,t)=>n,q={toAttribute(n,t){switch(t){case Boolean:n=n?It:null;break;case Object:case Array:n=n==null?n:JSON.stringify(n)}return n},fromAttribute(n,t){let e=n;switch(t){case Boolean:e=n!==null;break;case Number:e=n===null?null:Number(n);break;case Object:case Array:try{e=JSON.parse(n)}catch{e=null}}return e}},tt=(n,t)=>!zt(n,t),rt={attribute:!0,type:String,converter:q,reflect:!1,useDefault:!1,hasChanged:tt};Symbol.metadata??(Symbol.metadata=Symbol("metadata")),v.litPropertyMetadata??(v.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&&Ot(this.prototype,t,i)}}static getPropertyDescriptor(t,e,s){const{get:i,set:o}=Rt(this.prototype,t)??{get(){return this[e]},set(r){this[e]=r}};return{get:i,set(r){const h=i==null?void 0:i.call(this);o==null||o.call(this,r),this.requestUpdate(t,h,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??rt}static _$Ei(){if(this.hasOwnProperty(R("elementProperties")))return;const t=Ht(this);t.finalize(),t.l!==void 0&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(R("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(R("properties"))){const e=this.properties,s=[...Ut(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(nt(i))}else t!==void 0&&e.push(nt(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 Mt(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 o;const s=this.constructor.elementProperties.get(t),i=this.constructor._$Eu(t,s);if(i!==void 0&&s.reflect===!0){const r=(((o=s.converter)==null?void 0:o.toAttribute)!==void 0?s.converter:q).toAttribute(e,s.type);this._$Em=t,r==null?this.removeAttribute(i):this.setAttribute(i,r),this._$Em=null}}_$AK(t,e){var o,r;const s=this.constructor,i=s._$Eh.get(t);if(i!==void 0&&this._$Em!==i){const h=s.getPropertyOptions(i),a=typeof h.converter=="function"?{fromAttribute:h.converter}:((o=h.converter)==null?void 0:o.fromAttribute)!==void 0?h.converter:q;this._$Em=i,this[i]=a.fromAttribute(e,h.type)??((r=this._$Ej)==null?void 0:r.get(i))??null,this._$Em=null}}requestUpdate(t,e,s){var i;if(t!==void 0){const o=this.constructor,r=this[t];if(s??(s=o.getPropertyOptions(t)),!((s.hasChanged??tt)(r,e)||s.useDefault&&s.reflect&&r===((i=this._$Ej)==null?void 0:i.get(t))&&!this.hasAttribute(o._$Eu(t,s))))return;this.C(t,e,s)}this.isUpdatePending===!1&&(this._$ES=this._$EP())}C(t,e,{useDefault:s,reflect:i,wrapped:o},r){s&&!(this._$Ej??(this._$Ej=new Map)).has(t)&&(this._$Ej.set(t,r??e??this[t]),o!==!0||r!==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[o,r]of this._$Ep)this[o]=r;this._$Ep=void 0}const i=this.constructor.elementProperties;if(i.size>0)for(const[o,r]of i){const{wrapped:h}=r,a=this[o];h!==!0||this._$AL.has(o)||a===void 0||this.C(o,void 0,r,a)}}let t=!1;const e=this._$AL;try{t=this.shouldUpdate(e),t?(this.willUpdate(e),(s=this._$EO)==null||s.forEach(i=>{var o;return(o=i.hostUpdate)==null?void 0:o.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[R("elementProperties")]=new Map,E[R("finalized")]=new Map,W==null||W({ReactiveElement:E}),(v.reactiveElementVersions??(v.reactiveElementVersions=[])).push("2.1.0");/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/const U=globalThis,D=U.trustedTypes,at=D?D.createPolicy("lit-html",{createHTML:n=>n}):void 0,yt="$lit$",g=`lit$${Math.random().toFixed(9).slice(2)}$`,$t="?"+g,Nt=`<${$t}>`,S=document,T=()=>S.createComment(""),H=n=>n===null||typeof n!="object"&&typeof n!="function",et=Array.isArray,Ft=n=>et(n)||typeof(n==null?void 0:n[Symbol.iterator])=="function",V=`[
\f\r]`,O=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,ht=/-->/g,lt=/>/g,A=RegExp(`>|${V}(?:([^\\s"'>=/]+)(${V}*=${V}*(?:[^
\f\r"'\`<>=]|("|')|))|$)`,"g"),ct=/'/g,dt=/"/g,gt=/^(?:script|style|textarea|title)$/i,Gt=n=>(t,...e)=>({_$litType$:n,strings:t,values:e}),vt=Gt(1),P=Symbol.for("lit-noChange"),p=Symbol.for("lit-nothing"),ut=new WeakMap,b=S.createTreeWalker(S,129);function xt(n,t){if(!et(n)||!n.hasOwnProperty("raw"))throw Error("invalid template strings array");return at!==void 0?at.createHTML(t):t}const jt=(n,t)=>{const e=n.length-1,s=[];let i,o=t===2?"<svg>":t===3?"<math>":"",r=O;for(let h=0;h<e;h++){const a=n[h];let l,d,c=-1,m=0;for(;m<a.length&&(r.lastIndex=m,d=r.exec(a),d!==null);)m=r.lastIndex,r===O?d[1]==="!--"?r=ht:d[1]!==void 0?r=lt:d[2]!==void 0?(gt.test(d[2])&&(i=RegExp("</"+d[2],"g")),r=A):d[3]!==void 0&&(r=A):r===A?d[0]===">"?(r=i??O,c=-1):d[1]===void 0?c=-2:(c=r.lastIndex-d[2].length,l=d[1],r=d[3]===void 0?A:d[3]==='"'?dt:ct):r===dt||r===ct?r=A:r===ht||r===lt?r=O:(r=A,i=void 0);const _=r===A&&n[h+1].startsWith("/>")?" ":"";o+=r===O?a+Nt:c>=0?(s.push(l),a.slice(0,c)+yt+a.slice(c)+g+_):a+g+(c===-2?h:_)}return[xt(n,o+(n[e]||"<?>")+(t===2?"</svg>":t===3?"</math>":"")),s]};class I{constructor({strings:t,_$litType$:e},s){let i;this.parts=[];let o=0,r=0;const h=t.length-1,a=this.parts,[l,d]=jt(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&&a.length<h;){if(i.nodeType===1){if(i.hasAttributes())for(const c of i.getAttributeNames())if(c.endsWith(yt)){const m=d[r++],_=i.getAttribute(c).split(g),f=/([.?@])?(.*)/.exec(m);a.push({type:1,index:o,name:f[2],strings:_,ctor:f[1]==="."?Dt:f[1]==="?"?kt:f[1]==="@"?Lt:L}),i.removeAttribute(c)}else c.startsWith(g)&&(a.push({type:6,index:o}),i.removeAttribute(c));if(gt.test(i.tagName)){const c=i.textContent.split(g),m=c.length-1;if(m>0){i.textContent=D?D.emptyScript:"";for(let _=0;_<m;_++)i.append(c[_],T()),b.nextNode(),a.push({type:2,index:++o});i.append(c[m],T())}}}else if(i.nodeType===8)if(i.data===$t)a.push({type:2,index:o});else{let c=-1;for(;(c=i.data.indexOf(g,c+1))!==-1;)a.push({type:7,index:o}),c+=g.length-1}o++}}static createElement(t,e){const s=S.createElement("template");return s.innerHTML=t,s}}function M(n,t,e=n,s){var r,h;if(t===P)return t;let i=s!==void 0?(r=e._$Co)==null?void 0:r[s]:e._$Cl;const o=H(t)?void 0:t._$litDirective$;return(i==null?void 0:i.constructor)!==o&&((h=i==null?void 0:i._$AO)==null||h.call(i,!1),o===void 0?i=void 0:(i=new o(n),i._$AT(n,e,s)),s!==void 0?(e._$Co??(e._$Co=[]))[s]=i:e._$Cl=i),i!==void 0&&(t=M(n,i._$AS(n,t.values),i,s)),t}class qt{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)??S).importNode(e,!0);b.currentNode=i;let o=b.nextNode(),r=0,h=0,a=s[0];for(;a!==void 0;){if(r===a.index){let l;a.type===2?l=new N(o,o.nextSibling,this,t):a.type===1?l=new a.ctor(o,a.name,a.strings,this,t):a.type===6&&(l=new Bt(o,this,t)),this._$AV.push(l),a=s[++h]}r!==(a==null?void 0:a.index)&&(o=b.nextNode(),r++)}return b.currentNode=S,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 N{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=p,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),H(t)?t===p||t==null||t===""?(this._$AH!==p&&this._$AR(),this._$AH=p):t!==this._$AH&&t!==P&&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!==p&&H(this._$AH)?this._$AA.nextSibling.data=t:this.T(S.createTextNode(t)),this._$AH=t}$(t){var o;const{values:e,_$litType$:s}=t,i=typeof s=="number"?this._$AC(t):(s.el===void 0&&(s.el=I.createElement(xt(s.h,s.h[0]),this.options)),s);if(((o=this._$AH)==null?void 0:o._$AD)===i)this._$AH.p(e);else{const r=new qt(i,this),h=r.u(this.options);r.p(e),this.T(h),this._$AH=r}}_$AC(t){let e=ut.get(t.strings);return e===void 0&&ut.set(t.strings,e=new I(t)),e}k(t){et(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let s,i=0;for(const o of t)i===e.length?e.push(s=new N(this.O(T()),this.O(T()),this,this.options)):s=e[i],s._$AI(o),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 L{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,e,s,i,o){this.type=1,this._$AH=p,this._$AN=void 0,this.element=t,this.name=e,this._$AM=i,this.options=o,s.length>2||s[0]!==""||s[1]!==""?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=p}_$AI(t,e=this,s,i){const o=this.strings;let r=!1;if(o===void 0)t=M(this,t,e,0),r=!H(t)||t!==this._$AH&&t!==P,r&&(this._$AH=t);else{const h=t;let a,l;for(t=o[0],a=0;a<o.length-1;a++)l=M(this,h[s+a],e,a),l===P&&(l=this._$AH[a]),r||(r=!H(l)||l!==this._$AH[a]),l===p?t=p:t!==p&&(t+=(l??"")+o[a+1]),this._$AH[a]=l}r&&!i&&this.j(t)}j(t){t===p?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"")}}class Dt extends L{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===p?void 0:t}}class kt extends L{constructor(){super(...arguments),this.type=4}j(t){this.element.toggleAttribute(this.name,!!t&&t!==p)}}class Lt extends L{constructor(t,e,s,i,o){super(t,e,s,i,o),this.type=5}_$AI(t,e=this){if((t=M(this,t,e,0)??p)===P)return;const s=this._$AH,i=t===p&&s!==p||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,o=t!==p&&(s===p||i);i&&this.element.removeEventListener(this.name,this,s),o&&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 J=U.litHtmlPolyfillSupport;J==null||J(I,N),(U.litHtmlVersions??(U.litHtmlVersions=[])).push("3.3.0");const Wt=(n,t,e)=>{const s=(e==null?void 0:e.renderBefore)??t;let i=s._$litPart$;if(i===void 0){const o=(e==null?void 0:e.renderBefore)??null;s._$litPart$=i=new N(t.insertBefore(T(),o),o,void 0,e??{})}return i._$AI(n),i};/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/const w=globalThis;class C 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=Wt(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 P}}var mt;C._$litElement$=!0,C.finalized=!0,(mt=w.litElementHydrateSupport)==null||mt.call(w,{LitElement:C});const K=w.litElementPolyfillSupport;K==null||K({LitElement:C});(w.litElementVersions??(w.litElementVersions=[])).push("4.2.0");/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/const At=n=>(t,e)=>{e!==void 0?e.addInitializer(()=>{customElements.define(n,t)}):customElements.define(n,t)};/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/const Vt={attribute:!0,type:String,converter:q,reflect:!1,hasChanged:tt},Jt=(n=Vt,t,e)=>{const{kind:s,metadata:i}=e;let o=globalThis.litPropertyMetadata.get(i);if(o===void 0&&globalThis.litPropertyMetadata.set(i,o=new Map),s==="setter"&&((n=Object.create(n)).wrapped=!0),o.set(e.name,n),s==="accessor"){const{name:r}=e;return{set(h){const a=t.get.call(this);t.set.call(this,h),this.requestUpdate(r,a,n)},init(h){return h!==void 0&&this.C(r,void 0,n,h),h}}}if(s==="setter"){const{name:r}=e;return function(h){const a=this[r];t.call(this,h),this.requestUpdate(r,a,n)}}throw Error("Unsupported decorator location: "+s)};function z(n){return(t,e)=>typeof e=="object"?Jt(n,t,e):((s,i,o)=>{const r=i.hasOwnProperty(o);return i.constructor.createProperty(o,s),r?Object.getOwnPropertyDescriptor(i,o):void 0})(n,t,e)}/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/const pt=(n,t,e)=>(e.configurable=!0,e.enumerable=!0,Reflect.decorate&&typeof t!="object"&&Object.defineProperty(n,t,e),e);/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/function bt(n,t){return(e,s,i)=>{const o=r=>{var h;return((h=r.renderRoot)==null?void 0:h.querySelector(n))??null};if(t){const{get:r,set:h}=typeof s=="object"?e:i??(()=>{const a=Symbol();return{get(){return this[a]},set(l){this[a]=l}}})();return pt(e,s,{get(){let a=r.call(this);return a===void 0&&(a=o(this),(a!==null||this.hasUpdated)&&h.call(this,a)),a}})}return pt(e,s,{get(){return o(this)}})}}class Kt{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 Xt{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 st=(n,t)=>{for(const e of n)for(let s=0;s<e.stars.length;s++)t(e.stars[s],e,s)},Yt=Math.PI*2,X=()=>Math.random()*Yt;class u{constructor(t=0,e=0,s=0){this.x=t,this.y=e,this.z=s}static zero(){return new u(0,0,0)}static random(t=1){return new u(Math.random(),Math.random(),Math.random()).mul(t)}static randomCentered(t=1){return u.random().sub(.5).mul(t)}get magnitude(){return Math.sqrt(this.x**2+this.y**2+this.z**2)}copy(){return new u(this.x,this.y,this.z)}sub(t){return typeof t=="number"?new u(this.x-t,this.y-t,this.z-t):new u(this.x-t.x,this.y-t.y,this.z-t.z)}add(t){return typeof t=="number"?new u(this.x+t,this.y+t,this.z+t):new u(this.x+t.x,this.y+t.y,this.z+t.z)}mul(t){return typeof t=="number"?new u(this.x*t,this.y*t,this.z*t):new u(this.x*t.x,this.y*t.y,this.z*t.z)}div(t){return typeof t=="number"?new u(this.x/t,this.y/t,this.z/t):new u(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),o=Math.sin(t),r=Math.cos(e),h=Math.sin(e),a=Math.cos(s),l=Math.sin(s);return new $([[a*r,a*h*o-l*i,a*h*i+l*o],[l*r,l*h*o+a*i,l*h*i-a*o],[-h,r*o,r*i]])}static randomRotation(){const t=X(),e=X(),s=X();return $.fromEuler(t,e,s)}static fromAxisAngle(t,e){const s=t.x,i=t.y,o=t.z,r=Math.cos(e),h=Math.sin(e),a=1-r,l=a*s*s+r,d=a*s*i-o*h,c=a*s*o+i*h,m=a*i*s+o*h,_=a*i*i+r,f=a*i*o-s*h,B=a*o*s-i*h,F=a*o*i+s*h,Ct=a*o*o+r;return new $([[l,d,c],[m,_,f],[B,F,Ct]])}transform(t){return new u(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 o=0;o<3;o++)e[s][i]+=this.data[s][o]*t.data[o][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 u(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 G=.005,Y=.001,wt=n=>{st(n,t=>{let e=u.zero();for(const i of n){const o=i.pos.sub(t.pos),r=o.magnitude**2;if(r===0)continue;const h=Math.sqrt(r),a=Y*i.mass/(h*r),l=o.mul(a);e=e.add(l)}const s=e.mul(G);t.vel=t.vel.add(s),t.pos=t.pos.add(t.vel.mul(G))});for(const t of n){let e=u.zero();for(const i of n){if(t===i)continue;const o=i.pos.sub(t.pos),r=o.magnitude**2;if(r===0)continue;const h=Math.sqrt(r),a=Y*i.mass/(h*r),l=o.mul(a);e=e.add(l)}const s=e.mul(G);t.vel=t.vel.add(s)}for(const t of n)t.pos=t.pos.add(t.vel.mul(G))},St=n=>{const{minStarCount:t=1500,maxStarCount:e,minGalaxyRadius:s=1,maxGalaxyRadius:i,maxInitialSpeed:o=4,rewindTimeSteps:r=3,initialCollisionAvoidanceOffset:h=1.5}=n,a=u.randomCentered(o),d=a.mul(-r).add(u.randomCentered(h)),c=u.random(Math.PI),m=e?Math.random()*(e-t)+t:t,_=i?Math.random()*(i-s)+s:s,f=new Kt(a,d,c,m),B=$.fromEuler(f.rotation.x,f.rotation.y,f.rotation.z);for(let F=0;F<m;F++)f.stars.push(Zt(f,B,_));return f},Zt=(n,t,e=1)=>{const s=2*Math.PI*Math.random(),i=Math.random()*e;let o=Math.random()*Math.exp(-2*(i/e))/5*e;Math.random()<.5&&(o=-o);const r=Math.sqrt(i**2+o**2),h=Math.sqrt(n.mass*Y/r),a=Math.sin(s),l=Math.cos(s),d=new u(i*l,i*a,o),c=new u(-h*a,h*l,0),m=t.transform(d).add(n.pos),_=t.transform(c).add(n.vel);return new Xt(m,_)};var Qt=Object.defineProperty,te=Object.getOwnPropertyDescriptor,x=(n,t,e,s)=>{for(var i=s>1?void 0:s?te(t,e):t,o=n.length-1,r;o>=0;o--)(r=n[o])&&(i=(s?r(t,e,i):r(i))||i);return s&&i&&Qt(t,e,i),i};let y=class extends C{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 vt`<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(n){(n.has("galaxyCount")||n.has("maxGalaxyCount")||n.has("simulator")||n.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 t=Number(this.rotation)*(Math.PI/180);this._rotation_vector=u.random(t)}else if(typeof this.rotation=="string"){const[n,t,e]=this.rotation.split(",").map(Number),s=n*(Math.PI/180),i=t*(Math.PI/180),o=e*(Math.PI/180);this._rotation_vector=new u(s,i,o)}}_initialiseGalaxies(){this._simulator=this.simulator||{updateGalaxies:wt},this._galaxyFactory=this.galaxyFactory||{createRandomGalaxy:()=>St({minStarCount:700,maxStarCount:1e3,minGalaxyRadius:.5,maxGalaxyRadius:1.5})};const n=Math.floor(Math.random()*(this.maxGalaxyCount-this.galaxyCount)+this.galaxyCount),t=Math.random()*360,e=360/n;this._galaxies=[];for(let s=0;s<n;s++){const i=this._galaxyFactory.createRandomGalaxy();i.data.color=`hsl(${t+s*e}, 50%, 80%)`,this._galaxies.push(i)}this._step=0}_draw(){if(!this._ctx||!this._canvas)return;const n=this._canvas.width,t=this._canvas.height,e=(n+t)/40*this.zoomFactor;this._ctx.fillStyle="rgba(0, 0, 0, 0.4)",this._ctx.fillRect(0,0,n,t);const s=this._ctx,i=this._galaxies.reduce((r,h)=>r.add(h.pos),new u(0,0,0)).div(this._galaxies.length);let o=$.identity();if(this._rotation_vector){const r=this._rotation_vector.magnitude,h=this._rotation_vector.normalize(),a=r*this._step;o=$.fromAxisAngle(h,a)}st(this._galaxies,(r,h)=>{if(!h.data.color){const c=`hsl(${Math.random()*360}, 100%, 50%)`;h.data.color=c}s.fillStyle=h.data.color;const a=o?o.transform(r.pos):r.pos,l=Math.floor((a.x-i.x)*e)+n/2,d=Math.floor((a.y-i.y)*e)+t/2;l>=0&&l<n&&d>=0&&d<t&&s.fillRect(l,d,1,1)})}_startAnimation(){this._animationFrameId||this._animate()}_stopAnimation(){this._animationFrameId&&(cancelAnimationFrame(this._animationFrameId),this._animationFrameId=null)}_handleResize(){const n=window.devicePixelRatio||1;this._canvas&&(this._canvas.width=this.clientWidth*n,this._canvas.height=this.clientHeight*n)}};y.styles=ft`
:host {
display: block;
width: 100%;
height: 100%;
}
canvas {
display: block;
width: 100%;
height: 100%;
}
`;x([z({type:Number,attribute:"galaxy-count"})],y.prototype,"galaxyCount",2);x([z({type:Number,attribute:"max-galaxy-count"})],y.prototype,"maxGalaxyCount",2);x([z({type:Number,attribute:"zoom"})],y.prototype,"zoomFactor",2);x([z({type:String,attribute:"rotation"})],y.prototype,"rotation",2);x([z({type:Object,attribute:"simulator"})],y.prototype,"simulator",2);x([z({type:Object,attribute:"galaxy-factory"})],y.prototype,"galaxyFactory",2);x([bt("#galaxyCanvas")],y.prototype,"_canvas",2);y=x([At("galaxy-simulation")],y);var ee=Object.defineProperty,se=Object.getOwnPropertyDescriptor,Et=(n,t,e,s)=>{for(var i=s>1?void 0:s?se(t,e):t,o=n.length-1,r;o>=0;o--)(r=n[o])&&(i=(s?r(t,e,i):r(i))||i);return s&&i&&ee(t,e,i),i};let k=class extends C{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 vt`<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 t=["#ffadad","#a0c4ff","#fdffb6"];for(let e=0;e<3;e++){const s=St({minStarCount:700,maxStarCount:1e3,minGalaxyRadius:.5,maxGalaxyRadius:1.5});s.data.color=t[e%t.length],this._galaxies.push(s)}}_draw(){if(!this._ctx||!this._canvas)return;const{width:n,height:t}=this._canvas;this._ctx.fillStyle="rgba(0, 0, 0, 0.4)",this._ctx.fillRect(0,0,n,t);const e=(n+t)/40;st(this._galaxies,(s,i)=>{this._ctx.fillStyle=i.data.color;const o=Math.floor(s.pos.x*e)+n/2,r=Math.floor(s.pos.y*e)+t/2;o>=0&&o<n&&r>=0&&r<t&&this._ctx.fillRect(o,r,1,1)})}_startAnimation(){this._animationFrameId||this._animate()}_stopAnimation(){this._animationFrameId&&(cancelAnimationFrame(this._animationFrameId),this._animationFrameId=null)}_handleResize(){if(!this._canvas)return;const n=window.devicePixelRatio||1;this._canvas.width=this.clientWidth*n,this._canvas.height=this.clientHeight*n}};k.styles=ft`
/* 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%;
}
`;Et([bt("#galaxyCanvas")],k.prototype,"_canvas",2);k=Et([At("simple-galaxy-simulation")],k);