@maucwerk/glimmer 1.2.4 → 1.2.6

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.
package/README.md CHANGED
@@ -574,12 +574,15 @@ sun: {
574
574
  color: 0xffffff,
575
575
  intensity: 2.2,
576
576
  solar: { latitude: 52.09, longitude: 4.31, datetime: '2026-06-21T13:00:00Z' },
577
- csm: { cascades: 3, shadow_map_size: 2048, max_far: 2000 },
577
+ csm: { cascades: 3, shadow_map_size: 2048, max_far: 0 },
578
578
  }
579
579
  ```
580
580
 
581
- The cascades refresh every frame, so the shadows stay crisp while orbiting or
582
- scrubbing the time of day. Omit `csm` to keep the classic single shadow map.
581
+ `max_far` is in meters; `0` (default) auto-fits the loaded models, so the
582
+ cascades always match the architectural scale of the scene. Set an explicit
583
+ value only to override. The cascades refresh every frame, so the shadows stay
584
+ crisp while orbiting or scrubbing the time of day. Omit `csm` to keep the
585
+ classic single shadow map.
583
586
 
584
587
  ## Configuration for Common Scenarios
585
588
 
@@ -865,7 +868,7 @@ Access-Control-Allow-Methods: GET
865
868
  ## Package Structure
866
869
 
867
870
  ```
868
- @maucwerk/glimmer@1.2.4
871
+ @maucwerk/glimmer@1.2.6
869
872
  ├── dist/
870
873
  │ ├── index.d.ts # Main TypeScript declarations
871
874
  │ ├── vite/
@@ -880,7 +883,15 @@ The package supports both ESM and CommonJS with complete TypeScript declarations
880
883
 
881
884
  ## Version History
882
885
 
883
- ### v1.2.4 (Current)
886
+ ### v1.2.6 (Current)
887
+
888
+ - ✅ CSM range auto-fits the scene in meters (`max_far: 0`); explicit value still wins
889
+
890
+ ### v1.2.5
891
+
892
+ - ✅ Higher shadow bias (less acne striping); demo bird relies on the edge overlay instead of dense triangulation lines
893
+
894
+ ### v1.2.4
884
895
 
885
896
  - ✅ CSM reliability: shadow maps enabled in CSM mode, normal-bias control, tighter shadow camera depth range
886
897
 
@@ -47,6 +47,12 @@ export declare class Sun {
47
47
  * effective sun, and the rig is refreshed every frame via the viewer loop.
48
48
  * Recreated only when the cascade configuration itself changes.
49
49
  */
50
+ /**
51
+ * Resolve the cascade range in meters. An explicit max_far wins; 0 (the
52
+ * default) auto-fits the loaded models with margin, so the cascade
53
+ * resolution always matches the architectural scale of the scene.
54
+ */
55
+ private resolve_csm_range;
50
56
  private sync_csm;
51
57
  /**
52
58
  * CSM only affects materials explicitly registered via setupMaterial.
@@ -19,7 +19,7 @@ export declare const ShadowCsmSettingsSchema: z.ZodObject<{
19
19
  cascades: z.ZodDefault<z.ZodNumber>;
20
20
  /** Shadow map resolution per cascade. */
21
21
  shadow_map_size: z.ZodDefault<z.ZodNumber>;
22
- /** Farthest distance covered by the cascades, in world units. */
22
+ /** Farthest distance covered by the cascades, in world units (meters). */
23
23
  max_far: z.ZodDefault<z.ZodNumber>;
24
24
  /** Shadow bias for the cascade lights. */
25
25
  shadow_bias: z.ZodDefault<z.ZodNumber>;
@@ -76,7 +76,7 @@ export declare const SunSettingsSchema: z.ZodObject<{
76
76
  cascades: z.ZodDefault<z.ZodNumber>;
77
77
  /** Shadow map resolution per cascade. */
78
78
  shadow_map_size: z.ZodDefault<z.ZodNumber>;
79
- /** Farthest distance covered by the cascades, in world units. */
79
+ /** Farthest distance covered by the cascades, in world units (meters). */
80
80
  max_far: z.ZodDefault<z.ZodNumber>;
81
81
  /** Shadow bias for the cascade lights. */
82
82
  shadow_bias: z.ZodDefault<z.ZodNumber>;
@@ -171,7 +171,7 @@ export declare const EnvironmentSchema: z.ZodObject<{
171
171
  cascades: z.ZodDefault<z.ZodNumber>;
172
172
  /** Shadow map resolution per cascade. */
173
173
  shadow_map_size: z.ZodDefault<z.ZodNumber>;
174
- /** Farthest distance covered by the cascades, in world units. */
174
+ /** Farthest distance covered by the cascades, in world units (meters). */
175
175
  max_far: z.ZodDefault<z.ZodNumber>;
176
176
  /** Shadow bias for the cascade lights. */
177
177
  shadow_bias: z.ZodDefault<z.ZodNumber>;
@@ -403,7 +403,7 @@ export declare const SettingsSchema: z.ZodObject<{
403
403
  cascades: z.ZodDefault<z.ZodNumber>;
404
404
  /** Shadow map resolution per cascade. */
405
405
  shadow_map_size: z.ZodDefault<z.ZodNumber>;
406
- /** Farthest distance covered by the cascades, in world units. */
406
+ /** Farthest distance covered by the cascades, in world units (meters). */
407
407
  max_far: z.ZodDefault<z.ZodNumber>;
408
408
  /** Shadow bias for the cascade lights. */
409
409
  shadow_bias: z.ZodDefault<z.ZodNumber>;
@@ -2982,10 +2982,10 @@ const Nc = b.object({
2982
2982
  cascades: b.number().int().min(1).max(4).default(3),
2983
2983
  /** Shadow map resolution per cascade. */
2984
2984
  shadow_map_size: b.number().default(2048),
2985
- /** Farthest distance covered by the cascades, in world units. */
2986
- max_far: b.number().default(2e3),
2985
+ /** Farthest distance covered by the cascades, in world units (meters). */
2986
+ max_far: b.number().min(0).default(0),
2987
2987
  /** Shadow bias for the cascade lights. */
2988
- shadow_bias: b.number().default(2e-4),
2988
+ shadow_bias: b.number().default(1e-3),
2989
2989
  /**
2990
2990
  * Shadow normal bias in world units. Pushes the shadow lookup along the
2991
2991
  * surface normal; the main cure for acne/moiré on large flat surfaces.
@@ -5633,27 +5633,43 @@ class Il {
5633
5633
  * effective sun, and the rig is refreshed every frame via the viewer loop.
5634
5634
  * Recreated only when the cascade configuration itself changes.
5635
5635
  */
5636
+ /**
5637
+ * Resolve the cascade range in meters. An explicit max_far wins; 0 (the
5638
+ * default) auto-fits the loaded models with margin, so the cascade
5639
+ * resolution always matches the architectural scale of the scene.
5640
+ */
5641
+ resolve_csm_range() {
5642
+ const e = this.sun_settings.csm.max_far;
5643
+ if (e > 0) return e;
5644
+ const t = new p.Box3();
5645
+ let n = !1;
5646
+ if (this.model_manager.models.forEach((a) => {
5647
+ a.group && (t.expandByObject(a.group), n = !0);
5648
+ }), !n || t.isEmpty()) return 1e3;
5649
+ const s = t.getSize(new p.Vector3()), i = Math.max(s.x, s.y, s.z), o = Math.min(6e3, Math.max(100, i * 3));
5650
+ return j.debug(`CSM range auto-fitted to scene: ${o.toFixed(0)} m (model extent ${i.toFixed(0)} m)`), o;
5651
+ }
5636
5652
  sync_csm(e) {
5637
- const t = this.sun_settings.csm, n = JSON.stringify(t), s = new p.Vector3(-e.position[0], -e.position[1], -e.position[2]).normalize();
5638
- !this.csm || this.csm_key !== n ? (this.teardown_csm(), this.viewer.renderer.shadowMap.enabled = !0, this.csm = new dl({
5653
+ const t = this.sun_settings.csm, n = this.resolve_csm_range(), s = JSON.stringify({ ...t, max_far: n }), i = new p.Vector3(-e.position[0], -e.position[1], -e.position[2]).normalize();
5654
+ !this.csm || this.csm_key !== s ? (this.teardown_csm(), this.viewer.renderer.shadowMap.enabled = !0, this.viewer.renderer.shadowMap.type = p.PCFSoftShadowMap, this.csm = new dl({
5639
5655
  camera: this.viewer.camera,
5640
5656
  parent: this.scene,
5641
5657
  cascades: t.cascades,
5642
- maxFar: t.max_far,
5658
+ maxFar: n,
5643
5659
  mode: "practical",
5644
5660
  shadowMapSize: t.shadow_map_size,
5645
5661
  shadowBias: t.shadow_bias,
5646
- lightDirection: s.clone(),
5662
+ lightDirection: i.clone(),
5647
5663
  lightIntensity: e.intensity,
5648
5664
  lightNear: 1,
5649
- lightFar: t.max_far
5650
- }), this.csm.fade = !0, this.csm.lights.forEach((i) => {
5651
- i.color.set(e.color), i.intensity = e.intensity, i.shadow.normalBias = t.shadow_normal_bias;
5665
+ lightFar: n
5666
+ }), this.csm.fade = !0, this.csm.lights.forEach((o) => {
5667
+ o.color.set(e.color), o.intensity = e.intensity, o.shadow.normalBias = t.shadow_normal_bias;
5652
5668
  }), this.csm_callback = () => {
5653
- var i;
5654
- (i = this.csm) == null || i.update();
5655
- }, this.viewer.register_animation_callback(this.csm_callback), this.csm_key = n, this.watch_model_loads()) : (this.csm.lightDirection.copy(s), this.csm.lightIntensity = e.intensity, this.csm.lights.forEach((i) => {
5656
- i.color.set(e.color), i.intensity = e.intensity, i.shadow.normalBias = t.shadow_normal_bias;
5669
+ var o;
5670
+ (o = this.csm) == null || o.update();
5671
+ }, this.viewer.register_animation_callback(this.csm_callback), this.csm_key = s, this.watch_model_loads()) : (this.csm.lightDirection.copy(i), this.csm.lightIntensity = e.intensity, this.csm.lights.forEach((o) => {
5672
+ o.color.set(e.color), o.intensity = e.intensity, o.shadow.normalBias = t.shadow_normal_bias;
5657
5673
  })), this.setup_csm_materials();
5658
5674
  }
5659
5675
  /**
@@ -1,4 +1,4 @@
1
- (function(te,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("three")):typeof define=="function"&&define.amd?define(["exports","three"],h):(te=typeof globalThis<"u"?globalThis:te||self,h(te.Glimmer={},te.THREE))})(this,function(te,h){"use strict";var Ql=Object.defineProperty;var ed=(te,h,St)=>h in te?Ql(te,h,{enumerable:!0,configurable:!0,writable:!0,value:St}):te[h]=St;var g=(te,h,St)=>ed(te,typeof h!="symbol"?h+"":h,St);function St(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>r[t]})}}return e.default=r,Object.freeze(e)}const _=St(h);var J;(function(r){r.assertEqual=s=>s;function e(s){}r.assertIs=e;function t(s){throw new Error}r.assertNever=t,r.arrayToEnum=s=>{const i={};for(const o of s)i[o]=o;return i},r.getValidEnumValues=s=>{const i=r.objectKeys(s).filter(a=>typeof s[s[a]]!="number"),o={};for(const a of i)o[a]=s[a];return r.objectValues(o)},r.objectValues=s=>r.objectKeys(s).map(function(i){return s[i]}),r.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{const i=[];for(const o in s)Object.prototype.hasOwnProperty.call(s,o)&&i.push(o);return i},r.find=(s,i)=>{for(const o of s)if(i(o))return o},r.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&isFinite(s)&&Math.floor(s)===s;function n(s,i=" | "){return s.map(o=>typeof o=="string"?`'${o}'`:o).join(i)}r.joinValues=n,r.jsonStringifyReplacer=(s,i)=>typeof i=="bigint"?i.toString():i})(J||(J={}));var ns;(function(r){r.mergeShapes=(e,t)=>({...e,...t})})(ns||(ns={}));const I=J.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Ye=r=>{switch(typeof r){case"undefined":return I.undefined;case"string":return I.string;case"number":return isNaN(r)?I.nan:I.number;case"boolean":return I.boolean;case"function":return I.function;case"bigint":return I.bigint;case"symbol":return I.symbol;case"object":return Array.isArray(r)?I.array:r===null?I.null:r.then&&typeof r.then=="function"&&r.catch&&typeof r.catch=="function"?I.promise:typeof Map<"u"&&r instanceof Map?I.map:typeof Set<"u"&&r instanceof Set?I.set:typeof Date<"u"&&r instanceof Date?I.date:I.object;default:return I.unknown}},M=J.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),Gr=r=>JSON.stringify(r,null,2).replace(/"([^"]+)":/g,"$1:");class Ie extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=n=>{this.issues=[...this.issues,n]},this.addIssues=(n=[])=>{this.issues=[...this.issues,...n]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){const t=e||function(i){return i.message},n={_errors:[]},s=i=>{for(const o of i.issues)if(o.code==="invalid_union")o.unionErrors.map(s);else if(o.code==="invalid_return_type")s(o.returnTypeError);else if(o.code==="invalid_arguments")s(o.argumentsError);else if(o.path.length===0)n._errors.push(t(o));else{let a=n,c=0;for(;c<o.path.length;){const l=o.path[c];c===o.path.length-1?(a[l]=a[l]||{_errors:[]},a[l]._errors.push(t(o))):a[l]=a[l]||{_errors:[]},a=a[l],c++}}};return s(this),n}static assert(e){if(!(e instanceof Ie))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,J.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=t=>t.message){const t={},n=[];for(const s of this.issues)s.path.length>0?(t[s.path[0]]=t[s.path[0]]||[],t[s.path[0]].push(e(s))):n.push(e(s));return{formErrors:n,fieldErrors:t}}get formErrors(){return this.flatten()}}Ie.create=r=>new Ie(r);const At=(r,e)=>{let t;switch(r.code){case M.invalid_type:r.received===I.undefined?t="Required":t=`Expected ${r.expected}, received ${r.received}`;break;case M.invalid_literal:t=`Invalid literal value, expected ${JSON.stringify(r.expected,J.jsonStringifyReplacer)}`;break;case M.unrecognized_keys:t=`Unrecognized key(s) in object: ${J.joinValues(r.keys,", ")}`;break;case M.invalid_union:t="Invalid input";break;case M.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${J.joinValues(r.options)}`;break;case M.invalid_enum_value:t=`Invalid enum value. Expected ${J.joinValues(r.options)}, received '${r.received}'`;break;case M.invalid_arguments:t="Invalid function arguments";break;case M.invalid_return_type:t="Invalid function return type";break;case M.invalid_date:t="Invalid date";break;case M.invalid_string:typeof r.validation=="object"?"includes"in r.validation?(t=`Invalid input: must include "${r.validation.includes}"`,typeof r.validation.position=="number"&&(t=`${t} at one or more positions greater than or equal to ${r.validation.position}`)):"startsWith"in r.validation?t=`Invalid input: must start with "${r.validation.startsWith}"`:"endsWith"in r.validation?t=`Invalid input: must end with "${r.validation.endsWith}"`:J.assertNever(r.validation):r.validation!=="regex"?t=`Invalid ${r.validation}`:t="Invalid";break;case M.too_small:r.type==="array"?t=`Array must contain ${r.exact?"exactly":r.inclusive?"at least":"more than"} ${r.minimum} element(s)`:r.type==="string"?t=`String must contain ${r.exact?"exactly":r.inclusive?"at least":"over"} ${r.minimum} character(s)`:r.type==="number"?t=`Number must be ${r.exact?"exactly equal to ":r.inclusive?"greater than or equal to ":"greater than "}${r.minimum}`:r.type==="date"?t=`Date must be ${r.exact?"exactly equal to ":r.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(r.minimum))}`:t="Invalid input";break;case M.too_big:r.type==="array"?t=`Array must contain ${r.exact?"exactly":r.inclusive?"at most":"less than"} ${r.maximum} element(s)`:r.type==="string"?t=`String must contain ${r.exact?"exactly":r.inclusive?"at most":"under"} ${r.maximum} character(s)`:r.type==="number"?t=`Number must be ${r.exact?"exactly":r.inclusive?"less than or equal to":"less than"} ${r.maximum}`:r.type==="bigint"?t=`BigInt must be ${r.exact?"exactly":r.inclusive?"less than or equal to":"less than"} ${r.maximum}`:r.type==="date"?t=`Date must be ${r.exact?"exactly":r.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(r.maximum))}`:t="Invalid input";break;case M.custom:t="Invalid input";break;case M.invalid_intersection_types:t="Intersection results could not be merged";break;case M.not_multiple_of:t=`Number must be a multiple of ${r.multipleOf}`;break;case M.not_finite:t="Number must be finite";break;default:t=e.defaultError,J.assertNever(r)}return{message:t}};let ri=At;function Zr(r){ri=r}function wn(){return ri}const Sn=r=>{const{data:e,path:t,errorMaps:n,issueData:s}=r,i=[...t,...s.path||[]],o={...s,path:i};if(s.message!==void 0)return{...s,path:i,message:s.message};let a="";const c=n.filter(l=>!!l).slice().reverse();for(const l of c)a=l(o,{data:e,defaultError:a}).message;return{...s,path:i,message:a}},Wr=[];function C(r,e){const t=wn(),n=Sn({issueData:e,data:r.data,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,t,t===At?void 0:At].filter(s=>!!s)});r.common.issues.push(n)}class ye{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,t){const n=[];for(const s of t){if(s.status==="aborted")return G;s.status==="dirty"&&e.dirty(),n.push(s.value)}return{status:e.value,value:n}}static async mergeObjectAsync(e,t){const n=[];for(const s of t){const i=await s.key,o=await s.value;n.push({key:i,value:o})}return ye.mergeObjectSync(e,n)}static mergeObjectSync(e,t){const n={};for(const s of t){const{key:i,value:o}=s;if(i.status==="aborted"||o.status==="aborted")return G;i.status==="dirty"&&e.dirty(),o.status==="dirty"&&e.dirty(),i.value!=="__proto__"&&(typeof o.value<"u"||s.alwaysSet)&&(n[i.value]=o.value)}return{status:e.value,value:n}}}const G=Object.freeze({status:"aborted"}),Mt=r=>({status:"dirty",value:r}),be=r=>({status:"valid",value:r}),ss=r=>r.status==="aborted",is=r=>r.status==="dirty",ft=r=>r.status==="valid",Gt=r=>typeof Promise<"u"&&r instanceof Promise;function An(r,e,t,n){if(typeof e=="function"?r!==e||!0:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e.get(r)}function oi(r,e,t,n,s){if(typeof e=="function"?r!==e||!0:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e.set(r,t),t}typeof SuppressedError=="function"&&SuppressedError;var P;(function(r){r.errToObj=e=>typeof e=="string"?{message:e}:e||{},r.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(P||(P={}));var Zt,Wt;class Be{constructor(e,t,n,s){this._cachedPath=[],this.parent=e,this.data=t,this._path=n,this._key=s}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const ai=(r,e)=>{if(ft(e))return{success:!0,data:e.value};if(!r.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const t=new Ie(r.common.issues);return this._error=t,this._error}}};function X(r){if(!r)return{};const{errorMap:e,invalid_type_error:t,required_error:n,description:s}=r;if(e&&(t||n))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:s}:{errorMap:(o,a)=>{var c,l;const{message:d}=r;return o.code==="invalid_enum_value"?{message:d??a.defaultError}:typeof a.data>"u"?{message:(c=d??n)!==null&&c!==void 0?c:a.defaultError}:o.code!=="invalid_type"?{message:a.defaultError}:{message:(l=d??t)!==null&&l!==void 0?l:a.defaultError}},description:s}}class K{get description(){return this._def.description}_getType(e){return Ye(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:Ye(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new ye,ctx:{common:e.parent.common,data:e.data,parsedType:Ye(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(Gt(t))throw new Error("Synchronous parse encountered promise.");return t}_parseAsync(e){const t=this._parse(e);return Promise.resolve(t)}parse(e,t){const n=this.safeParse(e,t);if(n.success)return n.data;throw n.error}safeParse(e,t){var n;const s={common:{issues:[],async:(n=t==null?void 0:t.async)!==null&&n!==void 0?n:!1,contextualErrorMap:t==null?void 0:t.errorMap},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Ye(e)},i=this._parseSync({data:e,path:s.path,parent:s});return ai(s,i)}"~validate"(e){var t,n;const s={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Ye(e)};if(!this["~standard"].async)try{const i=this._parseSync({data:e,path:[],parent:s});return ft(i)?{value:i.value}:{issues:s.common.issues}}catch(i){!((n=(t=i==null?void 0:i.message)===null||t===void 0?void 0:t.toLowerCase())===null||n===void 0)&&n.includes("encountered")&&(this["~standard"].async=!0),s.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:s}).then(i=>ft(i)?{value:i.value}:{issues:s.common.issues})}async parseAsync(e,t){const n=await this.safeParseAsync(e,t);if(n.success)return n.data;throw n.error}async safeParseAsync(e,t){const n={common:{issues:[],contextualErrorMap:t==null?void 0:t.errorMap,async:!0},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Ye(e)},s=this._parse({data:e,path:n.path,parent:n}),i=await(Gt(s)?s:Promise.resolve(s));return ai(n,i)}refine(e,t){const n=s=>typeof t=="string"||typeof t>"u"?{message:t}:typeof t=="function"?t(s):t;return this._refinement((s,i)=>{const o=e(s),a=()=>i.addIssue({code:M.custom,...n(s)});return typeof Promise<"u"&&o instanceof Promise?o.then(c=>c?!0:(a(),!1)):o?!0:(a(),!1)})}refinement(e,t){return this._refinement((n,s)=>e(n)?!0:(s.addIssue(typeof t=="function"?t(n,s):t),!1))}_refinement(e){return new Ue({schema:this,typeName:V.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:t=>this["~validate"](t)}}optional(){return Ge.create(this,this._def)}nullable(){return dt.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return ze.create(this)}promise(){return Ct.create(this,this._def)}or(e){return Yt.create([this,e],this._def)}and(e){return Ht.create(this,e,this._def)}transform(e){return new Ue({...X(this._def),schema:this,typeName:V.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new tn({...X(this._def),innerType:this,defaultValue:t,typeName:V.ZodDefault})}brand(){return new as({typeName:V.ZodBranded,type:this,...X(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new nn({...X(this._def),innerType:this,catchValue:t,typeName:V.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return sn.create(this,e)}readonly(){return rn.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Xr=/^c[^\s-]{8,}$/i,$r=/^[0-9a-z]+$/,Kr=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Yr=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,Hr=/^[a-z0-9_-]{21}$/i,qr=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Jr=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,Qr=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,eo="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let rs;const to=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,no=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,so=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,io=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,ro=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,oo=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,ci="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",ao=new RegExp(`^${ci}$`);function li(r){let e="([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";return r.precision?e=`${e}\\.\\d{${r.precision}}`:r.precision==null&&(e=`${e}(\\.\\d+)?`),e}function co(r){return new RegExp(`^${li(r)}$`)}function di(r){let e=`${ci}T${li(r)}`;const t=[];return t.push(r.local?"Z?":"Z"),r.offset&&t.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${t.join("|")})`,new RegExp(`^${e}$`)}function lo(r,e){return!!((e==="v4"||!e)&&to.test(r)||(e==="v6"||!e)&&so.test(r))}function ho(r,e){if(!qr.test(r))return!1;try{const[t]=r.split("."),n=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(t.length+(4-t.length%4)%4,"="),s=JSON.parse(atob(n));return!(typeof s!="object"||s===null||!s.typ||!s.alg||e&&s.alg!==e)}catch{return!1}}function uo(r,e){return!!((e==="v4"||!e)&&no.test(r)||(e==="v6"||!e)&&io.test(r))}class Re extends K{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==I.string){const i=this._getOrReturnCtx(e);return C(i,{code:M.invalid_type,expected:I.string,received:i.parsedType}),G}const n=new ye;let s;for(const i of this._def.checks)if(i.kind==="min")e.data.length<i.value&&(s=this._getOrReturnCtx(e,s),C(s,{code:M.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),n.dirty());else if(i.kind==="max")e.data.length>i.value&&(s=this._getOrReturnCtx(e,s),C(s,{code:M.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),n.dirty());else if(i.kind==="length"){const o=e.data.length>i.value,a=e.data.length<i.value;(o||a)&&(s=this._getOrReturnCtx(e,s),o?C(s,{code:M.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}):a&&C(s,{code:M.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}),n.dirty())}else if(i.kind==="email")Qr.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"email",code:M.invalid_string,message:i.message}),n.dirty());else if(i.kind==="emoji")rs||(rs=new RegExp(eo,"u")),rs.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"emoji",code:M.invalid_string,message:i.message}),n.dirty());else if(i.kind==="uuid")Yr.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"uuid",code:M.invalid_string,message:i.message}),n.dirty());else if(i.kind==="nanoid")Hr.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"nanoid",code:M.invalid_string,message:i.message}),n.dirty());else if(i.kind==="cuid")Xr.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"cuid",code:M.invalid_string,message:i.message}),n.dirty());else if(i.kind==="cuid2")$r.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"cuid2",code:M.invalid_string,message:i.message}),n.dirty());else if(i.kind==="ulid")Kr.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"ulid",code:M.invalid_string,message:i.message}),n.dirty());else if(i.kind==="url")try{new URL(e.data)}catch{s=this._getOrReturnCtx(e,s),C(s,{validation:"url",code:M.invalid_string,message:i.message}),n.dirty()}else i.kind==="regex"?(i.regex.lastIndex=0,i.regex.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"regex",code:M.invalid_string,message:i.message}),n.dirty())):i.kind==="trim"?e.data=e.data.trim():i.kind==="includes"?e.data.includes(i.value,i.position)||(s=this._getOrReturnCtx(e,s),C(s,{code:M.invalid_string,validation:{includes:i.value,position:i.position},message:i.message}),n.dirty()):i.kind==="toLowerCase"?e.data=e.data.toLowerCase():i.kind==="toUpperCase"?e.data=e.data.toUpperCase():i.kind==="startsWith"?e.data.startsWith(i.value)||(s=this._getOrReturnCtx(e,s),C(s,{code:M.invalid_string,validation:{startsWith:i.value},message:i.message}),n.dirty()):i.kind==="endsWith"?e.data.endsWith(i.value)||(s=this._getOrReturnCtx(e,s),C(s,{code:M.invalid_string,validation:{endsWith:i.value},message:i.message}),n.dirty()):i.kind==="datetime"?di(i).test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{code:M.invalid_string,validation:"datetime",message:i.message}),n.dirty()):i.kind==="date"?ao.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{code:M.invalid_string,validation:"date",message:i.message}),n.dirty()):i.kind==="time"?co(i).test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{code:M.invalid_string,validation:"time",message:i.message}),n.dirty()):i.kind==="duration"?Jr.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"duration",code:M.invalid_string,message:i.message}),n.dirty()):i.kind==="ip"?lo(e.data,i.version)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"ip",code:M.invalid_string,message:i.message}),n.dirty()):i.kind==="jwt"?ho(e.data,i.alg)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"jwt",code:M.invalid_string,message:i.message}),n.dirty()):i.kind==="cidr"?uo(e.data,i.version)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"cidr",code:M.invalid_string,message:i.message}),n.dirty()):i.kind==="base64"?ro.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"base64",code:M.invalid_string,message:i.message}),n.dirty()):i.kind==="base64url"?oo.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"base64url",code:M.invalid_string,message:i.message}),n.dirty()):J.assertNever(i);return{status:n.value,value:e.data}}_regex(e,t,n){return this.refinement(s=>e.test(s),{validation:t,code:M.invalid_string,...P.errToObj(n)})}_addCheck(e){return new Re({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...P.errToObj(e)})}url(e){return this._addCheck({kind:"url",...P.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...P.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...P.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...P.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...P.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...P.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...P.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...P.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...P.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...P.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...P.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...P.errToObj(e)})}datetime(e){var t,n;return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,offset:(t=e==null?void 0:e.offset)!==null&&t!==void 0?t:!1,local:(n=e==null?void 0:e.local)!==null&&n!==void 0?n:!1,...P.errToObj(e==null?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,...P.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...P.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...P.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t==null?void 0:t.position,...P.errToObj(t==null?void 0:t.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...P.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...P.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...P.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...P.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...P.errToObj(t)})}nonempty(e){return this.min(1,P.errToObj(e))}trim(){return new Re({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Re({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Re({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}Re.create=r=>{var e;return new Re({checks:[],typeName:V.ZodString,coerce:(e=r==null?void 0:r.coerce)!==null&&e!==void 0?e:!1,...X(r)})};function fo(r,e){const t=(r.toString().split(".")[1]||"").length,n=(e.toString().split(".")[1]||"").length,s=t>n?t:n,i=parseInt(r.toFixed(s).replace(".","")),o=parseInt(e.toFixed(s).replace(".",""));return i%o/Math.pow(10,s)}class at extends K{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==I.number){const i=this._getOrReturnCtx(e);return C(i,{code:M.invalid_type,expected:I.number,received:i.parsedType}),G}let n;const s=new ye;for(const i of this._def.checks)i.kind==="int"?J.isInteger(e.data)||(n=this._getOrReturnCtx(e,n),C(n,{code:M.invalid_type,expected:"integer",received:"float",message:i.message}),s.dirty()):i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(n=this._getOrReturnCtx(e,n),C(n,{code:M.too_small,minimum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(n=this._getOrReturnCtx(e,n),C(n,{code:M.too_big,maximum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="multipleOf"?fo(e.data,i.value)!==0&&(n=this._getOrReturnCtx(e,n),C(n,{code:M.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):i.kind==="finite"?Number.isFinite(e.data)||(n=this._getOrReturnCtx(e,n),C(n,{code:M.not_finite,message:i.message}),s.dirty()):J.assertNever(i);return{status:s.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,P.toString(t))}gt(e,t){return this.setLimit("min",e,!1,P.toString(t))}lte(e,t){return this.setLimit("max",e,!0,P.toString(t))}lt(e,t){return this.setLimit("max",e,!1,P.toString(t))}setLimit(e,t,n,s){return new at({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:n,message:P.toString(s)}]})}_addCheck(e){return new at({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:P.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:P.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:P.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:P.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:P.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:P.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:P.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:P.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:P.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&J.isInteger(e.value))}get isFinite(){let e=null,t=null;for(const n of this._def.checks){if(n.kind==="finite"||n.kind==="int"||n.kind==="multipleOf")return!0;n.kind==="min"?(t===null||n.value>t)&&(t=n.value):n.kind==="max"&&(e===null||n.value<e)&&(e=n.value)}return Number.isFinite(t)&&Number.isFinite(e)}}at.create=r=>new at({checks:[],typeName:V.ZodNumber,coerce:(r==null?void 0:r.coerce)||!1,...X(r)});class ct extends K{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==I.bigint)return this._getInvalidInput(e);let n;const s=new ye;for(const i of this._def.checks)i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(n=this._getOrReturnCtx(e,n),C(n,{code:M.too_small,type:"bigint",minimum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(n=this._getOrReturnCtx(e,n),C(n,{code:M.too_big,type:"bigint",maximum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="multipleOf"?e.data%i.value!==BigInt(0)&&(n=this._getOrReturnCtx(e,n),C(n,{code:M.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):J.assertNever(i);return{status:s.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return C(t,{code:M.invalid_type,expected:I.bigint,received:t.parsedType}),G}gte(e,t){return this.setLimit("min",e,!0,P.toString(t))}gt(e,t){return this.setLimit("min",e,!1,P.toString(t))}lte(e,t){return this.setLimit("max",e,!0,P.toString(t))}lt(e,t){return this.setLimit("max",e,!1,P.toString(t))}setLimit(e,t,n,s){return new ct({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:n,message:P.toString(s)}]})}_addCheck(e){return new ct({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:P.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:P.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:P.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:P.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:P.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}ct.create=r=>{var e;return new ct({checks:[],typeName:V.ZodBigInt,coerce:(e=r==null?void 0:r.coerce)!==null&&e!==void 0?e:!1,...X(r)})};class Xt extends K{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==I.boolean){const n=this._getOrReturnCtx(e);return C(n,{code:M.invalid_type,expected:I.boolean,received:n.parsedType}),G}return be(e.data)}}Xt.create=r=>new Xt({typeName:V.ZodBoolean,coerce:(r==null?void 0:r.coerce)||!1,...X(r)});class mt extends K{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==I.date){const i=this._getOrReturnCtx(e);return C(i,{code:M.invalid_type,expected:I.date,received:i.parsedType}),G}if(isNaN(e.data.getTime())){const i=this._getOrReturnCtx(e);return C(i,{code:M.invalid_date}),G}const n=new ye;let s;for(const i of this._def.checks)i.kind==="min"?e.data.getTime()<i.value&&(s=this._getOrReturnCtx(e,s),C(s,{code:M.too_small,message:i.message,inclusive:!0,exact:!1,minimum:i.value,type:"date"}),n.dirty()):i.kind==="max"?e.data.getTime()>i.value&&(s=this._getOrReturnCtx(e,s),C(s,{code:M.too_big,message:i.message,inclusive:!0,exact:!1,maximum:i.value,type:"date"}),n.dirty()):J.assertNever(i);return{status:n.value,value:new Date(e.data.getTime())}}_addCheck(e){return new mt({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:P.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:P.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e!=null?new Date(e):null}}mt.create=r=>new mt({checks:[],coerce:(r==null?void 0:r.coerce)||!1,typeName:V.ZodDate,...X(r)});class Mn extends K{_parse(e){if(this._getType(e)!==I.symbol){const n=this._getOrReturnCtx(e);return C(n,{code:M.invalid_type,expected:I.symbol,received:n.parsedType}),G}return be(e.data)}}Mn.create=r=>new Mn({typeName:V.ZodSymbol,...X(r)});class $t extends K{_parse(e){if(this._getType(e)!==I.undefined){const n=this._getOrReturnCtx(e);return C(n,{code:M.invalid_type,expected:I.undefined,received:n.parsedType}),G}return be(e.data)}}$t.create=r=>new $t({typeName:V.ZodUndefined,...X(r)});class Kt extends K{_parse(e){if(this._getType(e)!==I.null){const n=this._getOrReturnCtx(e);return C(n,{code:M.invalid_type,expected:I.null,received:n.parsedType}),G}return be(e.data)}}Kt.create=r=>new Kt({typeName:V.ZodNull,...X(r)});class Lt extends K{constructor(){super(...arguments),this._any=!0}_parse(e){return be(e.data)}}Lt.create=r=>new Lt({typeName:V.ZodAny,...X(r)});class pt extends K{constructor(){super(...arguments),this._unknown=!0}_parse(e){return be(e.data)}}pt.create=r=>new pt({typeName:V.ZodUnknown,...X(r)});class He extends K{_parse(e){const t=this._getOrReturnCtx(e);return C(t,{code:M.invalid_type,expected:I.never,received:t.parsedType}),G}}He.create=r=>new He({typeName:V.ZodNever,...X(r)});class Ln extends K{_parse(e){if(this._getType(e)!==I.undefined){const n=this._getOrReturnCtx(e);return C(n,{code:M.invalid_type,expected:I.void,received:n.parsedType}),G}return be(e.data)}}Ln.create=r=>new Ln({typeName:V.ZodVoid,...X(r)});class ze extends K{_parse(e){const{ctx:t,status:n}=this._processInputParams(e),s=this._def;if(t.parsedType!==I.array)return C(t,{code:M.invalid_type,expected:I.array,received:t.parsedType}),G;if(s.exactLength!==null){const o=t.data.length>s.exactLength.value,a=t.data.length<s.exactLength.value;(o||a)&&(C(t,{code:o?M.too_big:M.too_small,minimum:a?s.exactLength.value:void 0,maximum:o?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),n.dirty())}if(s.minLength!==null&&t.data.length<s.minLength.value&&(C(t,{code:M.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),n.dirty()),s.maxLength!==null&&t.data.length>s.maxLength.value&&(C(t,{code:M.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),n.dirty()),t.common.async)return Promise.all([...t.data].map((o,a)=>s.type._parseAsync(new Be(t,o,t.path,a)))).then(o=>ye.mergeArray(n,o));const i=[...t.data].map((o,a)=>s.type._parseSync(new Be(t,o,t.path,a)));return ye.mergeArray(n,i)}get element(){return this._def.type}min(e,t){return new ze({...this._def,minLength:{value:e,message:P.toString(t)}})}max(e,t){return new ze({...this._def,maxLength:{value:e,message:P.toString(t)}})}length(e,t){return new ze({...this._def,exactLength:{value:e,message:P.toString(t)}})}nonempty(e){return this.min(1,e)}}ze.create=(r,e)=>new ze({type:r,minLength:null,maxLength:null,exactLength:null,typeName:V.ZodArray,...X(e)});function Tt(r){if(r instanceof re){const e={};for(const t in r.shape){const n=r.shape[t];e[t]=Ge.create(Tt(n))}return new re({...r._def,shape:()=>e})}else return r instanceof ze?new ze({...r._def,type:Tt(r.element)}):r instanceof Ge?Ge.create(Tt(r.unwrap())):r instanceof dt?dt.create(Tt(r.unwrap())):r instanceof Ve?Ve.create(r.items.map(e=>Tt(e))):r}class re extends K{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),t=J.objectKeys(e);return this._cached={shape:e,keys:t}}_parse(e){if(this._getType(e)!==I.object){const l=this._getOrReturnCtx(e);return C(l,{code:M.invalid_type,expected:I.object,received:l.parsedType}),G}const{status:n,ctx:s}=this._processInputParams(e),{shape:i,keys:o}=this._getCached(),a=[];if(!(this._def.catchall instanceof He&&this._def.unknownKeys==="strip"))for(const l in s.data)o.includes(l)||a.push(l);const c=[];for(const l of o){const d=i[l],u=s.data[l];c.push({key:{status:"valid",value:l},value:d._parse(new Be(s,u,s.path,l)),alwaysSet:l in s.data})}if(this._def.catchall instanceof He){const l=this._def.unknownKeys;if(l==="passthrough")for(const d of a)c.push({key:{status:"valid",value:d},value:{status:"valid",value:s.data[d]}});else if(l==="strict")a.length>0&&(C(s,{code:M.unrecognized_keys,keys:a}),n.dirty());else if(l!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const l=this._def.catchall;for(const d of a){const u=s.data[d];c.push({key:{status:"valid",value:d},value:l._parse(new Be(s,u,s.path,d)),alwaysSet:d in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const l=[];for(const d of c){const u=await d.key,f=await d.value;l.push({key:u,value:f,alwaysSet:d.alwaysSet})}return l}).then(l=>ye.mergeObjectSync(n,l)):ye.mergeObjectSync(n,c)}get shape(){return this._def.shape()}strict(e){return P.errToObj,new re({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,n)=>{var s,i,o,a;const c=(o=(i=(s=this._def).errorMap)===null||i===void 0?void 0:i.call(s,t,n).message)!==null&&o!==void 0?o:n.defaultError;return t.code==="unrecognized_keys"?{message:(a=P.errToObj(e).message)!==null&&a!==void 0?a:c}:{message:c}}}:{}})}strip(){return new re({...this._def,unknownKeys:"strip"})}passthrough(){return new re({...this._def,unknownKeys:"passthrough"})}extend(e){return new re({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new re({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:V.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new re({...this._def,catchall:e})}pick(e){const t={};return J.objectKeys(e).forEach(n=>{e[n]&&this.shape[n]&&(t[n]=this.shape[n])}),new re({...this._def,shape:()=>t})}omit(e){const t={};return J.objectKeys(this.shape).forEach(n=>{e[n]||(t[n]=this.shape[n])}),new re({...this._def,shape:()=>t})}deepPartial(){return Tt(this)}partial(e){const t={};return J.objectKeys(this.shape).forEach(n=>{const s=this.shape[n];e&&!e[n]?t[n]=s:t[n]=s.optional()}),new re({...this._def,shape:()=>t})}required(e){const t={};return J.objectKeys(this.shape).forEach(n=>{if(e&&!e[n])t[n]=this.shape[n];else{let i=this.shape[n];for(;i instanceof Ge;)i=i._def.innerType;t[n]=i}}),new re({...this._def,shape:()=>t})}keyof(){return hi(J.objectKeys(this.shape))}}re.create=(r,e)=>new re({shape:()=>r,unknownKeys:"strip",catchall:He.create(),typeName:V.ZodObject,...X(e)}),re.strictCreate=(r,e)=>new re({shape:()=>r,unknownKeys:"strict",catchall:He.create(),typeName:V.ZodObject,...X(e)}),re.lazycreate=(r,e)=>new re({shape:r,unknownKeys:"strip",catchall:He.create(),typeName:V.ZodObject,...X(e)});class Yt extends K{_parse(e){const{ctx:t}=this._processInputParams(e),n=this._def.options;function s(i){for(const a of i)if(a.result.status==="valid")return a.result;for(const a of i)if(a.result.status==="dirty")return t.common.issues.push(...a.ctx.common.issues),a.result;const o=i.map(a=>new Ie(a.ctx.common.issues));return C(t,{code:M.invalid_union,unionErrors:o}),G}if(t.common.async)return Promise.all(n.map(async i=>{const o={...t,common:{...t.common,issues:[]},parent:null};return{result:await i._parseAsync({data:t.data,path:t.path,parent:o}),ctx:o}})).then(s);{let i;const o=[];for(const c of n){const l={...t,common:{...t.common,issues:[]},parent:null},d=c._parseSync({data:t.data,path:t.path,parent:l});if(d.status==="valid")return d;d.status==="dirty"&&!i&&(i={result:d,ctx:l}),l.common.issues.length&&o.push(l.common.issues)}if(i)return t.common.issues.push(...i.ctx.common.issues),i.result;const a=o.map(c=>new Ie(c));return C(t,{code:M.invalid_union,unionErrors:a}),G}}get options(){return this._def.options}}Yt.create=(r,e)=>new Yt({options:r,typeName:V.ZodUnion,...X(e)});const qe=r=>r instanceof Jt?qe(r.schema):r instanceof Ue?qe(r.innerType()):r instanceof Qt?[r.value]:r instanceof lt?r.options:r instanceof en?J.objectValues(r.enum):r instanceof tn?qe(r._def.innerType):r instanceof $t?[void 0]:r instanceof Kt?[null]:r instanceof Ge?[void 0,...qe(r.unwrap())]:r instanceof dt?[null,...qe(r.unwrap())]:r instanceof as||r instanceof rn?qe(r.unwrap()):r instanceof nn?qe(r._def.innerType):[];class Tn extends K{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==I.object)return C(t,{code:M.invalid_type,expected:I.object,received:t.parsedType}),G;const n=this.discriminator,s=t.data[n],i=this.optionsMap.get(s);return i?t.common.async?i._parseAsync({data:t.data,path:t.path,parent:t}):i._parseSync({data:t.data,path:t.path,parent:t}):(C(t,{code:M.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[n]}),G)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,t,n){const s=new Map;for(const i of t){const o=qe(i.shape[e]);if(!o.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const a of o){if(s.has(a))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(a)}`);s.set(a,i)}}return new Tn({typeName:V.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:s,...X(n)})}}function os(r,e){const t=Ye(r),n=Ye(e);if(r===e)return{valid:!0,data:r};if(t===I.object&&n===I.object){const s=J.objectKeys(e),i=J.objectKeys(r).filter(a=>s.indexOf(a)!==-1),o={...r,...e};for(const a of i){const c=os(r[a],e[a]);if(!c.valid)return{valid:!1};o[a]=c.data}return{valid:!0,data:o}}else if(t===I.array&&n===I.array){if(r.length!==e.length)return{valid:!1};const s=[];for(let i=0;i<r.length;i++){const o=r[i],a=e[i],c=os(o,a);if(!c.valid)return{valid:!1};s.push(c.data)}return{valid:!0,data:s}}else return t===I.date&&n===I.date&&+r==+e?{valid:!0,data:r}:{valid:!1}}class Ht extends K{_parse(e){const{status:t,ctx:n}=this._processInputParams(e),s=(i,o)=>{if(ss(i)||ss(o))return G;const a=os(i.value,o.value);return a.valid?((is(i)||is(o))&&t.dirty(),{status:t.value,value:a.data}):(C(n,{code:M.invalid_intersection_types}),G)};return n.common.async?Promise.all([this._def.left._parseAsync({data:n.data,path:n.path,parent:n}),this._def.right._parseAsync({data:n.data,path:n.path,parent:n})]).then(([i,o])=>s(i,o)):s(this._def.left._parseSync({data:n.data,path:n.path,parent:n}),this._def.right._parseSync({data:n.data,path:n.path,parent:n}))}}Ht.create=(r,e,t)=>new Ht({left:r,right:e,typeName:V.ZodIntersection,...X(t)});class Ve extends K{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==I.array)return C(n,{code:M.invalid_type,expected:I.array,received:n.parsedType}),G;if(n.data.length<this._def.items.length)return C(n,{code:M.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),G;!this._def.rest&&n.data.length>this._def.items.length&&(C(n,{code:M.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const i=[...n.data].map((o,a)=>{const c=this._def.items[a]||this._def.rest;return c?c._parse(new Be(n,o,n.path,a)):null}).filter(o=>!!o);return n.common.async?Promise.all(i).then(o=>ye.mergeArray(t,o)):ye.mergeArray(t,i)}get items(){return this._def.items}rest(e){return new Ve({...this._def,rest:e})}}Ve.create=(r,e)=>{if(!Array.isArray(r))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Ve({items:r,typeName:V.ZodTuple,rest:null,...X(e)})};class qt extends K{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==I.object)return C(n,{code:M.invalid_type,expected:I.object,received:n.parsedType}),G;const s=[],i=this._def.keyType,o=this._def.valueType;for(const a in n.data)s.push({key:i._parse(new Be(n,a,n.path,a)),value:o._parse(new Be(n,n.data[a],n.path,a)),alwaysSet:a in n.data});return n.common.async?ye.mergeObjectAsync(t,s):ye.mergeObjectSync(t,s)}get element(){return this._def.valueType}static create(e,t,n){return t instanceof K?new qt({keyType:e,valueType:t,typeName:V.ZodRecord,...X(n)}):new qt({keyType:Re.create(),valueType:e,typeName:V.ZodRecord,...X(t)})}}class Dn extends K{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==I.map)return C(n,{code:M.invalid_type,expected:I.map,received:n.parsedType}),G;const s=this._def.keyType,i=this._def.valueType,o=[...n.data.entries()].map(([a,c],l)=>({key:s._parse(new Be(n,a,n.path,[l,"key"])),value:i._parse(new Be(n,c,n.path,[l,"value"]))}));if(n.common.async){const a=new Map;return Promise.resolve().then(async()=>{for(const c of o){const l=await c.key,d=await c.value;if(l.status==="aborted"||d.status==="aborted")return G;(l.status==="dirty"||d.status==="dirty")&&t.dirty(),a.set(l.value,d.value)}return{status:t.value,value:a}})}else{const a=new Map;for(const c of o){const l=c.key,d=c.value;if(l.status==="aborted"||d.status==="aborted")return G;(l.status==="dirty"||d.status==="dirty")&&t.dirty(),a.set(l.value,d.value)}return{status:t.value,value:a}}}}Dn.create=(r,e,t)=>new Dn({valueType:e,keyType:r,typeName:V.ZodMap,...X(t)});class _t extends K{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==I.set)return C(n,{code:M.invalid_type,expected:I.set,received:n.parsedType}),G;const s=this._def;s.minSize!==null&&n.data.size<s.minSize.value&&(C(n,{code:M.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),t.dirty()),s.maxSize!==null&&n.data.size>s.maxSize.value&&(C(n,{code:M.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),t.dirty());const i=this._def.valueType;function o(c){const l=new Set;for(const d of c){if(d.status==="aborted")return G;d.status==="dirty"&&t.dirty(),l.add(d.value)}return{status:t.value,value:l}}const a=[...n.data.values()].map((c,l)=>i._parse(new Be(n,c,n.path,l)));return n.common.async?Promise.all(a).then(c=>o(c)):o(a)}min(e,t){return new _t({...this._def,minSize:{value:e,message:P.toString(t)}})}max(e,t){return new _t({...this._def,maxSize:{value:e,message:P.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}_t.create=(r,e)=>new _t({valueType:r,minSize:null,maxSize:null,typeName:V.ZodSet,...X(e)});class Dt extends K{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==I.function)return C(t,{code:M.invalid_type,expected:I.function,received:t.parsedType}),G;function n(a,c){return Sn({data:a,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,wn(),At].filter(l=>!!l),issueData:{code:M.invalid_arguments,argumentsError:c}})}function s(a,c){return Sn({data:a,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,wn(),At].filter(l=>!!l),issueData:{code:M.invalid_return_type,returnTypeError:c}})}const i={errorMap:t.common.contextualErrorMap},o=t.data;if(this._def.returns instanceof Ct){const a=this;return be(async function(...c){const l=new Ie([]),d=await a._def.args.parseAsync(c,i).catch(m=>{throw l.addIssue(n(c,m)),l}),u=await Reflect.apply(o,this,d);return await a._def.returns._def.type.parseAsync(u,i).catch(m=>{throw l.addIssue(s(u,m)),l})})}else{const a=this;return be(function(...c){const l=a._def.args.safeParse(c,i);if(!l.success)throw new Ie([n(c,l.error)]);const d=Reflect.apply(o,this,l.data),u=a._def.returns.safeParse(d,i);if(!u.success)throw new Ie([s(d,u.error)]);return u.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new Dt({...this._def,args:Ve.create(e).rest(pt.create())})}returns(e){return new Dt({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,t,n){return new Dt({args:e||Ve.create([]).rest(pt.create()),returns:t||pt.create(),typeName:V.ZodFunction,...X(n)})}}class Jt extends K{get schema(){return this._def.getter()}_parse(e){const{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}Jt.create=(r,e)=>new Jt({getter:r,typeName:V.ZodLazy,...X(e)});class Qt extends K{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return C(t,{received:t.data,code:M.invalid_literal,expected:this._def.value}),G}return{status:"valid",value:e.data}}get value(){return this._def.value}}Qt.create=(r,e)=>new Qt({value:r,typeName:V.ZodLiteral,...X(e)});function hi(r,e){return new lt({values:r,typeName:V.ZodEnum,...X(e)})}class lt extends K{constructor(){super(...arguments),Zt.set(this,void 0)}_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),n=this._def.values;return C(t,{expected:J.joinValues(n),received:t.parsedType,code:M.invalid_type}),G}if(An(this,Zt)||oi(this,Zt,new Set(this._def.values)),!An(this,Zt).has(e.data)){const t=this._getOrReturnCtx(e),n=this._def.values;return C(t,{received:t.data,code:M.invalid_enum_value,options:n}),G}return be(e.data)}get options(){return this._def.values}get enum(){const e={};for(const t of this._def.values)e[t]=t;return e}get Values(){const e={};for(const t of this._def.values)e[t]=t;return e}get Enum(){const e={};for(const t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return lt.create(e,{...this._def,...t})}exclude(e,t=this._def){return lt.create(this.options.filter(n=>!e.includes(n)),{...this._def,...t})}}Zt=new WeakMap,lt.create=hi;class en extends K{constructor(){super(...arguments),Wt.set(this,void 0)}_parse(e){const t=J.getValidEnumValues(this._def.values),n=this._getOrReturnCtx(e);if(n.parsedType!==I.string&&n.parsedType!==I.number){const s=J.objectValues(t);return C(n,{expected:J.joinValues(s),received:n.parsedType,code:M.invalid_type}),G}if(An(this,Wt)||oi(this,Wt,new Set(J.getValidEnumValues(this._def.values))),!An(this,Wt).has(e.data)){const s=J.objectValues(t);return C(n,{received:n.data,code:M.invalid_enum_value,options:s}),G}return be(e.data)}get enum(){return this._def.values}}Wt=new WeakMap,en.create=(r,e)=>new en({values:r,typeName:V.ZodNativeEnum,...X(e)});class Ct extends K{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==I.promise&&t.common.async===!1)return C(t,{code:M.invalid_type,expected:I.promise,received:t.parsedType}),G;const n=t.parsedType===I.promise?t.data:Promise.resolve(t.data);return be(n.then(s=>this._def.type.parseAsync(s,{path:t.path,errorMap:t.common.contextualErrorMap})))}}Ct.create=(r,e)=>new Ct({type:r,typeName:V.ZodPromise,...X(e)});class Ue extends K{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===V.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:n}=this._processInputParams(e),s=this._def.effect||null,i={addIssue:o=>{C(n,o),o.fatal?t.abort():t.dirty()},get path(){return n.path}};if(i.addIssue=i.addIssue.bind(i),s.type==="preprocess"){const o=s.transform(n.data,i);if(n.common.async)return Promise.resolve(o).then(async a=>{if(t.value==="aborted")return G;const c=await this._def.schema._parseAsync({data:a,path:n.path,parent:n});return c.status==="aborted"?G:c.status==="dirty"||t.value==="dirty"?Mt(c.value):c});{if(t.value==="aborted")return G;const a=this._def.schema._parseSync({data:o,path:n.path,parent:n});return a.status==="aborted"?G:a.status==="dirty"||t.value==="dirty"?Mt(a.value):a}}if(s.type==="refinement"){const o=a=>{const c=s.refinement(a,i);if(n.common.async)return Promise.resolve(c);if(c instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return a};if(n.common.async===!1){const a=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});return a.status==="aborted"?G:(a.status==="dirty"&&t.dirty(),o(a.value),{status:t.value,value:a.value})}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(a=>a.status==="aborted"?G:(a.status==="dirty"&&t.dirty(),o(a.value).then(()=>({status:t.value,value:a.value}))))}if(s.type==="transform")if(n.common.async===!1){const o=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});if(!ft(o))return o;const a=s.transform(o.value,i);if(a instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:a}}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(o=>ft(o)?Promise.resolve(s.transform(o.value,i)).then(a=>({status:t.value,value:a})):o);J.assertNever(s)}}Ue.create=(r,e,t)=>new Ue({schema:r,typeName:V.ZodEffects,effect:e,...X(t)}),Ue.createWithPreprocess=(r,e,t)=>new Ue({schema:e,effect:{type:"preprocess",transform:r},typeName:V.ZodEffects,...X(t)});class Ge extends K{_parse(e){return this._getType(e)===I.undefined?be(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Ge.create=(r,e)=>new Ge({innerType:r,typeName:V.ZodOptional,...X(e)});class dt extends K{_parse(e){return this._getType(e)===I.null?be(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}dt.create=(r,e)=>new dt({innerType:r,typeName:V.ZodNullable,...X(e)});class tn extends K{_parse(e){const{ctx:t}=this._processInputParams(e);let n=t.data;return t.parsedType===I.undefined&&(n=this._def.defaultValue()),this._def.innerType._parse({data:n,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}tn.create=(r,e)=>new tn({innerType:r,typeName:V.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...X(e)});class nn extends K{_parse(e){const{ctx:t}=this._processInputParams(e),n={...t,common:{...t.common,issues:[]}},s=this._def.innerType._parse({data:n.data,path:n.path,parent:{...n}});return Gt(s)?s.then(i=>({status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new Ie(n.common.issues)},input:n.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new Ie(n.common.issues)},input:n.data})}}removeCatch(){return this._def.innerType}}nn.create=(r,e)=>new nn({innerType:r,typeName:V.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...X(e)});class Cn extends K{_parse(e){if(this._getType(e)!==I.nan){const n=this._getOrReturnCtx(e);return C(n,{code:M.invalid_type,expected:I.nan,received:n.parsedType}),G}return{status:"valid",value:e.data}}}Cn.create=r=>new Cn({typeName:V.ZodNaN,...X(r)});const mo=Symbol("zod_brand");class as extends K{_parse(e){const{ctx:t}=this._processInputParams(e),n=t.data;return this._def.type._parse({data:n,path:t.path,parent:t})}unwrap(){return this._def.type}}class sn extends K{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.common.async)return(async()=>{const i=await this._def.in._parseAsync({data:n.data,path:n.path,parent:n});return i.status==="aborted"?G:i.status==="dirty"?(t.dirty(),Mt(i.value)):this._def.out._parseAsync({data:i.value,path:n.path,parent:n})})();{const s=this._def.in._parseSync({data:n.data,path:n.path,parent:n});return s.status==="aborted"?G:s.status==="dirty"?(t.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:n.path,parent:n})}}static create(e,t){return new sn({in:e,out:t,typeName:V.ZodPipeline})}}class rn extends K{_parse(e){const t=this._def.innerType._parse(e),n=s=>(ft(s)&&(s.value=Object.freeze(s.value)),s);return Gt(t)?t.then(s=>n(s)):n(t)}unwrap(){return this._def.innerType}}rn.create=(r,e)=>new rn({innerType:r,typeName:V.ZodReadonly,...X(e)});function ui(r,e){const t=typeof r=="function"?r(e):typeof r=="string"?{message:r}:r;return typeof t=="string"?{message:t}:t}function fi(r,e={},t){return r?Lt.create().superRefine((n,s)=>{var i,o;const a=r(n);if(a instanceof Promise)return a.then(c=>{var l,d;if(!c){const u=ui(e,n),f=(d=(l=u.fatal)!==null&&l!==void 0?l:t)!==null&&d!==void 0?d:!0;s.addIssue({code:"custom",...u,fatal:f})}});if(!a){const c=ui(e,n),l=(o=(i=c.fatal)!==null&&i!==void 0?i:t)!==null&&o!==void 0?o:!0;s.addIssue({code:"custom",...c,fatal:l})}}):Lt.create()}const po={object:re.lazycreate};var V;(function(r){r.ZodString="ZodString",r.ZodNumber="ZodNumber",r.ZodNaN="ZodNaN",r.ZodBigInt="ZodBigInt",r.ZodBoolean="ZodBoolean",r.ZodDate="ZodDate",r.ZodSymbol="ZodSymbol",r.ZodUndefined="ZodUndefined",r.ZodNull="ZodNull",r.ZodAny="ZodAny",r.ZodUnknown="ZodUnknown",r.ZodNever="ZodNever",r.ZodVoid="ZodVoid",r.ZodArray="ZodArray",r.ZodObject="ZodObject",r.ZodUnion="ZodUnion",r.ZodDiscriminatedUnion="ZodDiscriminatedUnion",r.ZodIntersection="ZodIntersection",r.ZodTuple="ZodTuple",r.ZodRecord="ZodRecord",r.ZodMap="ZodMap",r.ZodSet="ZodSet",r.ZodFunction="ZodFunction",r.ZodLazy="ZodLazy",r.ZodLiteral="ZodLiteral",r.ZodEnum="ZodEnum",r.ZodEffects="ZodEffects",r.ZodNativeEnum="ZodNativeEnum",r.ZodOptional="ZodOptional",r.ZodNullable="ZodNullable",r.ZodDefault="ZodDefault",r.ZodCatch="ZodCatch",r.ZodPromise="ZodPromise",r.ZodBranded="ZodBranded",r.ZodPipeline="ZodPipeline",r.ZodReadonly="ZodReadonly"})(V||(V={}));const _o=(r,e={message:`Input not instance of ${r.name}`})=>fi(t=>t instanceof r,e),mi=Re.create,pi=at.create,go=Cn.create,yo=ct.create,_i=Xt.create,vo=mt.create,xo=Mn.create,bo=$t.create,wo=Kt.create,So=Lt.create,Ao=pt.create,Mo=He.create,Lo=Ln.create,To=ze.create,Do=re.create,Co=re.strictCreate,Oo=Yt.create,Io=Tn.create,ko=Ht.create,No=Ve.create,Eo=qt.create,Po=Dn.create,Ro=_t.create,zo=Dt.create,Uo=Jt.create,Fo=Qt.create,jo=lt.create,Bo=en.create,Vo=Ct.create,gi=Ue.create,Go=Ge.create,Zo=dt.create,Wo=Ue.createWithPreprocess,Xo=sn.create;var w=Object.freeze({__proto__:null,defaultErrorMap:At,setErrorMap:Zr,getErrorMap:wn,makeIssue:Sn,EMPTY_PATH:Wr,addIssueToContext:C,ParseStatus:ye,INVALID:G,DIRTY:Mt,OK:be,isAborted:ss,isDirty:is,isValid:ft,isAsync:Gt,get util(){return J},get objectUtil(){return ns},ZodParsedType:I,getParsedType:Ye,ZodType:K,datetimeRegex:di,ZodString:Re,ZodNumber:at,ZodBigInt:ct,ZodBoolean:Xt,ZodDate:mt,ZodSymbol:Mn,ZodUndefined:$t,ZodNull:Kt,ZodAny:Lt,ZodUnknown:pt,ZodNever:He,ZodVoid:Ln,ZodArray:ze,ZodObject:re,ZodUnion:Yt,ZodDiscriminatedUnion:Tn,ZodIntersection:Ht,ZodTuple:Ve,ZodRecord:qt,ZodMap:Dn,ZodSet:_t,ZodFunction:Dt,ZodLazy:Jt,ZodLiteral:Qt,ZodEnum:lt,ZodNativeEnum:en,ZodPromise:Ct,ZodEffects:Ue,ZodTransformer:Ue,ZodOptional:Ge,ZodNullable:dt,ZodDefault:tn,ZodCatch:nn,ZodNaN:Cn,BRAND:mo,ZodBranded:as,ZodPipeline:sn,ZodReadonly:rn,custom:fi,Schema:K,ZodSchema:K,late:po,get ZodFirstPartyTypeKind(){return V},coerce:{string:r=>Re.create({...r,coerce:!0}),number:r=>at.create({...r,coerce:!0}),boolean:r=>Xt.create({...r,coerce:!0}),bigint:r=>ct.create({...r,coerce:!0}),date:r=>mt.create({...r,coerce:!0})},any:So,array:To,bigint:yo,boolean:_i,date:vo,discriminatedUnion:Io,effect:gi,enum:jo,function:zo,instanceof:_o,intersection:ko,lazy:Uo,literal:Fo,map:Po,nan:go,nativeEnum:Bo,never:Mo,null:wo,nullable:Zo,number:pi,object:Do,oboolean:()=>_i().optional(),onumber:()=>pi().optional(),optional:Go,ostring:()=>mi().optional(),pipeline:Xo,preprocess:Wo,promise:Vo,record:Eo,set:Ro,strictObject:Co,string:mi,symbol:xo,transformer:gi,tuple:No,undefined:bo,union:Oo,unknown:Ao,void:Lo,NEVER:G,ZodIssueCode:M,quotelessJson:Gr,ZodError:Ie});const $o=w.object({latitude:w.number().min(-90).max(90),longitude:w.number().min(-180).max(180),datetime:w.string().refine(r=>!Number.isNaN(Date.parse(r)),{message:"Invalid ISO datetime"})}),Ko=w.object({cascades:w.number().int().min(1).max(4).default(3),shadow_map_size:w.number().default(2048),max_far:w.number().default(2e3),shadow_bias:w.number().default(2e-4),shadow_normal_bias:w.number().default(.1)}),Yo=w.object({color:w.number().default(16711680),intensity:w.number().default(1),position:w.tuple([w.number(),w.number(),w.number()]).default([10,10,10]),shadow:w.boolean().default(!0),solar:$o.optional(),csm:Ko.optional()}),Ho=w.object({type:w.enum(["sky","hdr","ultra","room","none"]).default("none"),url:w.string().optional(),sun:Yo.optional(),transparent:w.boolean().default(!1)}),qo=w.object({url:w.string(),color:w.number().optional(),shadow:w.boolean().default(!1),visible:w.boolean().default(!0).optional(),position:w.tuple([w.number(),w.number(),w.number()]).optional(),rotation:w.tuple([w.number(),w.number(),w.number()]).optional(),scale:w.union([w.number(),w.tuple([w.number(),w.number(),w.number()])]).default(1).optional(),conditional_edges:w.object({color:w.number().optional(),line_width:w.number().optional(),threshold_angle:w.number().optional()}).optional(),threshold_edges:w.object({color:w.number().optional(),line_width:w.number().optional(),threshold_angle:w.number().optional()}).optional(),frame_object:w.object({fit_offset:w.number().optional(),height_offset:w.number().optional()}).optional()}),On=w.object({environment:Ho.default({type:"none"}),models:w.array(qo).default([])});let yi="info";const vi={silent:0,error:1,warn:2,info:3,debug:4};function In(r){return vi[r]<=vi[yi]&&yi!=="silent"}const B={error:(...r)=>In("error")&&console.error("[glimmer]",...r),warn:(...r)=>In("warn")&&console.warn("[glimmer]",...r),info:(...r)=>In("info")&&console.log("[glimmer]",...r),debug:(...r)=>In("debug")&&console.log("[glimmer:debug]",...r)},$e=class $e extends EventTarget{constructor(t){super();g(this,"settings");try{const n=On.parse({}),s={...n,...t,environment:{...n.environment,...t.environment||{}},models:t.models||n.models};this.settings=On.parse(s),B.info("Settings initialized:",this.settings)}catch(n){throw B.error("Error initializing settings:",n),n}}static use(t={}){return $e.instance?$e.instance.update(t):$e.instance=new $e(t),$e.instance}static reset(){$e.instance&&($e.instance=void 0)}get(t){return this.settings[t]}update(t){const n=On.parse({...this.settings,...t,environment:{...this.settings.environment,...t.environment||{}},models:t.models!==void 0?t.models:this.settings.models});this.settings=n,B.info("Settings updated:",this.settings);const s=new CustomEvent("update",{detail:this.settings});this.dispatchEvent(s)}export(){return JSON.stringify(this.settings,null,2)}import(t){try{const n=JSON.parse(t);this.update(n)}catch(n){B.error("Failed to import settings:",n)}}async load_from_url(t){try{const n=await fetch(t);if(!n.ok)throw new Error(`Failed to fetch JSON from URL: ${n.statusText}`);const s=await n.json();this.update(s),B.info("Settings loaded successfully from URL:",t)}catch(n){B.error("Error loading settings from URL:",n)}}};g($e,"instance");let kn=$e;const xi={type:"change"},cs={type:"start"},bi={type:"end"},Nn=new h.Ray,wi=new h.Plane,Jo=Math.cos(70*h.MathUtils.DEG2RAD),le=new h.Vector3,Le=2*Math.PI,ne={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},ls=1e-6;class Qo extends h.Controls{constructor(e,t=null){super(e,t),this.state=ne.NONE,this.target=new h.Vector3,this.cursor=new h.Vector3,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:h.MOUSE.ROTATE,MIDDLE:h.MOUSE.DOLLY,RIGHT:h.MOUSE.PAN},this.touches={ONE:h.TOUCH.ROTATE,TWO:h.TOUCH.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this._lastPosition=new h.Vector3,this._lastQuaternion=new h.Quaternion,this._lastTargetPosition=new h.Vector3,this._quat=new h.Quaternion().setFromUnitVectors(e.up,new h.Vector3(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new h.Spherical,this._sphericalDelta=new h.Spherical,this._scale=1,this._panOffset=new h.Vector3,this._rotateStart=new h.Vector2,this._rotateEnd=new h.Vector2,this._rotateDelta=new h.Vector2,this._panStart=new h.Vector2,this._panEnd=new h.Vector2,this._panDelta=new h.Vector2,this._dollyStart=new h.Vector2,this._dollyEnd=new h.Vector2,this._dollyDelta=new h.Vector2,this._dollyDirection=new h.Vector3,this._mouse=new h.Vector2,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=ta.bind(this),this._onPointerDown=ea.bind(this),this._onPointerUp=na.bind(this),this._onContextMenu=la.bind(this),this._onMouseWheel=ra.bind(this),this._onKeyDown=oa.bind(this),this._onTouchStart=aa.bind(this),this._onTouchMove=ca.bind(this),this._onMouseDown=sa.bind(this),this._onMouseMove=ia.bind(this),this._interceptControlDown=da.bind(this),this._interceptControlUp=ha.bind(this),this.domElement!==null&&this.connect(this.domElement),this.update()}connect(e){super.connect(e),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerUp),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1}),this.domElement.getRootNode().addEventListener("keydown",this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerUp),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.stopListenToKeyEvents(),this.domElement.getRootNode().removeEventListener("keydown",this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction="auto"}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(e){e.addEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=e}stopListenToKeyEvents(){this._domElementKeyEvents!==null&&(this._domElementKeyEvents.removeEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(xi),this.update(),this.state=ne.NONE}update(e=null){const t=this.object.position;le.copy(t).sub(this.target),le.applyQuaternion(this._quat),this._spherical.setFromVector3(le),this.autoRotate&&this.state===ne.NONE&&this._rotateLeft(this._getAutoRotationAngle(e)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let n=this.minAzimuthAngle,s=this.maxAzimuthAngle;isFinite(n)&&isFinite(s)&&(n<-Math.PI?n+=Le:n>Math.PI&&(n-=Le),s<-Math.PI?s+=Le:s>Math.PI&&(s-=Le),n<=s?this._spherical.theta=Math.max(n,Math.min(s,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(n+s)/2?Math.max(n,this._spherical.theta):Math.min(s,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let i=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const o=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),i=o!=this._spherical.radius}if(le.setFromSpherical(this._spherical),le.applyQuaternion(this._quatInverse),t.copy(this.target).add(le),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let o=null;if(this.object.isPerspectiveCamera){const a=le.length();o=this._clampDistance(a*this._scale);const c=a-o;this.object.position.addScaledVector(this._dollyDirection,c),this.object.updateMatrixWorld(),i=!!c}else if(this.object.isOrthographicCamera){const a=new h.Vector3(this._mouse.x,this._mouse.y,0);a.unproject(this.object);const c=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),i=c!==this.object.zoom;const l=new h.Vector3(this._mouse.x,this._mouse.y,0);l.unproject(this.object),this.object.position.sub(l).add(a),this.object.updateMatrixWorld(),o=le.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;o!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(o).add(this.object.position):(Nn.origin.copy(this.object.position),Nn.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(Nn.direction))<Jo?this.object.lookAt(this.target):(wi.setFromNormalAndCoplanarPoint(this.object.up,this.target),Nn.intersectPlane(wi,this.target))))}else if(this.object.isOrthographicCamera){const o=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),o!==this.object.zoom&&(this.object.updateProjectionMatrix(),i=!0)}return this._scale=1,this._performCursorZoom=!1,i||this._lastPosition.distanceToSquared(this.object.position)>ls||8*(1-this._lastQuaternion.dot(this.object.quaternion))>ls||this._lastTargetPosition.distanceToSquared(this.target)>ls?(this.dispatchEvent(xi),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(e){return e!==null?Le/60*this.autoRotateSpeed*e:Le/60/60*this.autoRotateSpeed}_getZoomScale(e){const t=Math.abs(e*.01);return Math.pow(.95,this.zoomSpeed*t)}_rotateLeft(e){this._sphericalDelta.theta-=e}_rotateUp(e){this._sphericalDelta.phi-=e}_panLeft(e,t){le.setFromMatrixColumn(t,0),le.multiplyScalar(-e),this._panOffset.add(le)}_panUp(e,t){this.screenSpacePanning===!0?le.setFromMatrixColumn(t,1):(le.setFromMatrixColumn(t,0),le.crossVectors(this.object.up,le)),le.multiplyScalar(e),this._panOffset.add(le)}_pan(e,t){const n=this.domElement;if(this.object.isPerspectiveCamera){const s=this.object.position;le.copy(s).sub(this.target);let i=le.length();i*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*e*i/n.clientHeight,this.object.matrix),this._panUp(2*t*i/n.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(e*(this.object.right-this.object.left)/this.object.zoom/n.clientWidth,this.object.matrix),this._panUp(t*(this.object.top-this.object.bottom)/this.object.zoom/n.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(e,t){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const n=this.domElement.getBoundingClientRect(),s=e-n.left,i=t-n.top,o=n.width,a=n.height;this._mouse.x=s/o*2-1,this._mouse.y=-(i/a)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(e){return Math.max(this.minDistance,Math.min(this.maxDistance,e))}_handleMouseDownRotate(e){this._rotateStart.set(e.clientX,e.clientY)}_handleMouseDownDolly(e){this._updateZoomParameters(e.clientX,e.clientX),this._dollyStart.set(e.clientX,e.clientY)}_handleMouseDownPan(e){this._panStart.set(e.clientX,e.clientY)}_handleMouseMoveRotate(e){this._rotateEnd.set(e.clientX,e.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(Le*this._rotateDelta.x/t.clientHeight),this._rotateUp(Le*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(e){this._dollyEnd.set(e.clientX,e.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(e){this._panEnd.set(e.clientX,e.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(e){this._updateZoomParameters(e.clientX,e.clientY),e.deltaY<0?this._dollyIn(this._getZoomScale(e.deltaY)):e.deltaY>0&&this._dollyOut(this._getZoomScale(e.deltaY)),this.update()}_handleKeyDown(e){let t=!1;switch(e.code){case this.keys.UP:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(Le*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),t=!0;break;case this.keys.BOTTOM:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(-Le*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),t=!0;break;case this.keys.LEFT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(Le*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),t=!0;break;case this.keys.RIGHT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(-Le*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),t=!0;break}t&&(e.preventDefault(),this.update())}_handleTouchStartRotate(e){if(this._pointers.length===1)this._rotateStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),s=.5*(e.pageY+t.y);this._rotateStart.set(n,s)}}_handleTouchStartPan(e){if(this._pointers.length===1)this._panStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),s=.5*(e.pageY+t.y);this._panStart.set(n,s)}}_handleTouchStartDolly(e){const t=this._getSecondPointerPosition(e),n=e.pageX-t.x,s=e.pageY-t.y,i=Math.sqrt(n*n+s*s);this._dollyStart.set(0,i)}_handleTouchStartDollyPan(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enablePan&&this._handleTouchStartPan(e)}_handleTouchStartDollyRotate(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enableRotate&&this._handleTouchStartRotate(e)}_handleTouchMoveRotate(e){if(this._pointers.length==1)this._rotateEnd.set(e.pageX,e.pageY);else{const n=this._getSecondPointerPosition(e),s=.5*(e.pageX+n.x),i=.5*(e.pageY+n.y);this._rotateEnd.set(s,i)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(Le*this._rotateDelta.x/t.clientHeight),this._rotateUp(Le*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(e){if(this._pointers.length===1)this._panEnd.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),s=.5*(e.pageY+t.y);this._panEnd.set(n,s)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(e){const t=this._getSecondPointerPosition(e),n=e.pageX-t.x,s=e.pageY-t.y,i=Math.sqrt(n*n+s*s);this._dollyEnd.set(0,i),this._dollyDelta.set(0,Math.pow(this._dollyEnd.y/this._dollyStart.y,this.zoomSpeed)),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);const o=(e.pageX+t.x)*.5,a=(e.pageY+t.y)*.5;this._updateZoomParameters(o,a)}_handleTouchMoveDollyPan(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enablePan&&this._handleTouchMovePan(e)}_handleTouchMoveDollyRotate(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enableRotate&&this._handleTouchMoveRotate(e)}_addPointer(e){this._pointers.push(e.pointerId)}_removePointer(e){delete this._pointerPositions[e.pointerId];for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId){this._pointers.splice(t,1);return}}_isTrackingPointer(e){for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId)return!0;return!1}_trackPointer(e){let t=this._pointerPositions[e.pointerId];t===void 0&&(t=new h.Vector2,this._pointerPositions[e.pointerId]=t),t.set(e.pageX,e.pageY)}_getSecondPointerPosition(e){const t=e.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[t]}_customWheelEvent(e){const t=e.deltaMode,n={clientX:e.clientX,clientY:e.clientY,deltaY:e.deltaY};switch(t){case 1:n.deltaY*=16;break;case 2:n.deltaY*=100;break}return e.ctrlKey&&!this._controlActive&&(n.deltaY*=10),n}}function ea(r){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(r.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.domElement.addEventListener("pointerup",this._onPointerUp)),!this._isTrackingPointer(r)&&(this._addPointer(r),r.pointerType==="touch"?this._onTouchStart(r):this._onMouseDown(r)))}function ta(r){this.enabled!==!1&&(r.pointerType==="touch"?this._onTouchMove(r):this._onMouseMove(r))}function na(r){switch(this._removePointer(r),this._pointers.length){case 0:this.domElement.releasePointerCapture(r.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.dispatchEvent(bi),this.state=ne.NONE;break;case 1:const e=this._pointers[0],t=this._pointerPositions[e];this._onTouchStart({pointerId:e,pageX:t.x,pageY:t.y});break}}function sa(r){let e;switch(r.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case h.MOUSE.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(r),this.state=ne.DOLLY;break;case h.MOUSE.ROTATE:if(r.ctrlKey||r.metaKey||r.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(r),this.state=ne.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(r),this.state=ne.ROTATE}break;case h.MOUSE.PAN:if(r.ctrlKey||r.metaKey||r.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(r),this.state=ne.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(r),this.state=ne.PAN}break;default:this.state=ne.NONE}this.state!==ne.NONE&&this.dispatchEvent(cs)}function ia(r){switch(this.state){case ne.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(r);break;case ne.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(r);break;case ne.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(r);break}}function ra(r){this.enabled===!1||this.enableZoom===!1||this.state!==ne.NONE||(r.preventDefault(),this.dispatchEvent(cs),this._handleMouseWheel(this._customWheelEvent(r)),this.dispatchEvent(bi))}function oa(r){this.enabled!==!1&&this._handleKeyDown(r)}function aa(r){switch(this._trackPointer(r),this._pointers.length){case 1:switch(this.touches.ONE){case h.TOUCH.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(r),this.state=ne.TOUCH_ROTATE;break;case h.TOUCH.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(r),this.state=ne.TOUCH_PAN;break;default:this.state=ne.NONE}break;case 2:switch(this.touches.TWO){case h.TOUCH.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(r),this.state=ne.TOUCH_DOLLY_PAN;break;case h.TOUCH.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(r),this.state=ne.TOUCH_DOLLY_ROTATE;break;default:this.state=ne.NONE}break;default:this.state=ne.NONE}this.state!==ne.NONE&&this.dispatchEvent(cs)}function ca(r){switch(this._trackPointer(r),this.state){case ne.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(r),this.update();break;case ne.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(r),this.update();break;case ne.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(r),this.update();break;case ne.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(r),this.update();break;default:this.state=ne.NONE}}function la(r){this.enabled!==!1&&r.preventDefault()}function da(r){r.key==="Control"&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function ha(r){r.key==="Control"&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}class ua{constructor(e){g(this,"group");g(this,"sphere");g(this,"arrow");g(this,"scene");g(this,"is_enabled",!1);g(this,"SPHERE_RADIUS",.1);g(this,"ARROW_LENGTH",.5);g(this,"ARROW_HEAD_LENGTH",.15);g(this,"ARROW_HEAD_WIDTH",.1);this.scene=e,this.group=new _.Group,this.group.name="cursor_3d",this.group.visible=!1;const t=new _.SphereGeometry(this.SPHERE_RADIUS,16,16),n=new _.MeshBasicMaterial({color:65280,transparent:!0,opacity:.7,depthTest:!1});this.sphere=new _.Mesh(t,n),this.group.add(this.sphere),this.arrow=new _.ArrowHelper(new _.Vector3(0,1,0),new _.Vector3(0,0,0),this.ARROW_LENGTH,65280,this.ARROW_HEAD_LENGTH,this.ARROW_HEAD_WIDTH),this.group.add(this.arrow),this.scene.add(this.group)}enable(){this.is_enabled=!0,this.group.visible=!0}disable(){this.is_enabled=!1,this.group.visible=!1}get enabled(){return this.is_enabled}update(e){if(!e||!this.is_enabled){this.group.visible=!1;return}if(this.group.visible=!0,this.sphere.position.copy(e.point),this.arrow.position.copy(e.point),e.face&&e.face.normal){const t=e.face.normal.clone(),n=e.object;n.matrixWorld&&t.transformDirection(n.matrixWorld),this.arrow.setDirection(t)}}set_color(e){this.sphere.material.color.setHex(e),this.arrow.setColor(e)}dispose(){this.scene.remove(this.group),this.sphere.geometry.dispose(),this.sphere.material.dispose(),this.arrow.dispose()}}class fa extends EventTarget{constructor(t,n,s,i){super();g(this,"camera");g(this,"controls");g(this,"renderer");g(this,"scene");g(this,"_orbit_animation_id");g(this,"_orbit_restart_timeout_id");g(this,"_orbit_duration_seconds",45);g(this,"_orbit_clockwise",!0);g(this,"_auto_restart_enabled",!0);this.camera=t,this.controls=n,this.renderer=s,this.scene=i}start_animation(t,n,s=1){t||(t=30),this._orbit_duration_seconds=t,n===void 0&&(n=!0),this._orbit_clockwise=n,this.stop_animation();const i=t??this._orbit_duration_seconds,o=n??this._orbit_clockwise,a=this.camera.position.clone(),c=this.controls.target.clone(),l=c.clone();l.y=a.y;const d=a.distanceTo(l),u=Math.PI*2,f=performance.now(),m=a.x-l.x,y=a.z-l.z,v=Math.atan2(y,m),b=A=>1-Math.cos(A*Math.PI/2),S=A=>{const L=(A-f)/1e3;let x=0;L<s?x=b(L/s)*s:x=L-s+b(1)*s;const z=x%i/i,Z=v+(o?-1:1)*z*u,j=l.x+Math.cos(Z)*d,O=l.z+Math.sin(Z)*d,D=new _.Vector3(j,a.y,O);this.camera.position.copy(D),this.camera.lookAt(c),this.controls.target.copy(c),this.renderer.render(this.scene,this.camera),this._orbit_animation_id=requestAnimationFrame(S)};this._orbit_animation_id=requestAnimationFrame(S)}stop_animation(){this._orbit_animation_id&&(cancelAnimationFrame(this._orbit_animation_id),this._orbit_animation_id=void 0)}schedule_restart(t=5e3){this._auto_restart_enabled&&(this._orbit_restart_timeout_id&&clearTimeout(this._orbit_restart_timeout_id),this._orbit_restart_timeout_id=window.setTimeout(()=>{this.start_animation(this._orbit_duration_seconds,this._orbit_clockwise)},t))}set_auto_restart(t){this._auto_restart_enabled=t,!t&&this._orbit_restart_timeout_id&&(clearTimeout(this._orbit_restart_timeout_id),this._orbit_restart_timeout_id=void 0)}setup_user_override(){this.controls.addEventListener("start",()=>{this.stop_animation(),this._orbit_restart_timeout_id&&(clearTimeout(this._orbit_restart_timeout_id),this._orbit_restart_timeout_id=void 0),this.dispatchEvent(new CustomEvent("orbitstart",{detail:{}}))}),this.controls.addEventListener("end",()=>{this._auto_restart_enabled&&this.schedule_restart(),this.dispatchEvent(new CustomEvent("orbitstop",{detail:{}}))})}dispose(){this.stop_animation(),this._orbit_restart_timeout_id&&(clearTimeout(this._orbit_restart_timeout_id),this._orbit_restart_timeout_id=void 0)}}class ma{constructor(e,t,n){g(this,"raycaster");g(this,"camera");g(this,"canvas");g(this,"default_targets");this.raycaster=new _.Raycaster,this.camera=e,this.canvas=t,this.default_targets=n}raycast_from_event(e,t,n=!0){const s=this.canvas.getBoundingClientRect(),i=new _.Vector2;i.x=(e.clientX-s.left)/s.width*2-1,i.y=-((e.clientY-s.top)/s.height)*2+1,this.raycaster.setFromCamera(i,this.camera);const o=t??this.default_targets,a=this.raycaster.intersectObjects(o,!0);if(n){const c=a.filter(l=>l.object.isMesh);return c.length>0?c[0]:null}return a.length>0?a[0]:null}get_raycaster(){return this.raycaster}}class Si extends EventTarget{constructor(t,n){super();g(this,"settings");g(this,"scene");g(this,"camera");g(this,"renderer");g(this,"controls");g(this,"container");g(this,"orbit_controller");g(this,"raycast_helper");g(this,"_resize_handler",()=>this.onWindowResize());g(this,"clock",new _.Clock);g(this,"animation_callbacks",new Set);g(this,"animation_mixers",new Set);g(this,"cursor_3d");g(this,"_cursor_3d_mouse_handler");g(this,"_resolution_materials",new Set);g(this,"animate",()=>{requestAnimationFrame(this.animate);const t=this.clock.getDelta();this.update_animation_mixers(t),this.execute_animation_callbacks(t);for(const n of this._resolution_materials)try{if(n.resolution)this.renderer.getSize(n.resolution),n.resolution.multiplyScalar(window.devicePixelRatio);else if(n.uniforms&&n.uniforms.resolution&&n.uniforms.resolution.value){const s=n.uniforms.resolution.value;this.renderer.getSize(s),s.multiplyScalar(window.devicePixelRatio)}}catch{this._resolution_materials.delete(n)}this.controls.update(),this.renderer.render(this.scene,this.camera)});this.scene=new _.Scene,this.settings=n,this.container=t,this.renderer=new _.WebGLRenderer({antialias:!0}),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.toneMapping=_.ACESFilmicToneMapping,this.renderer.outputColorSpace=_.SRGBColorSpace,this.container.appendChild(this.renderer.domElement);const s=t.clientWidth/t.clientHeight;this.camera=new _.PerspectiveCamera(75,s,.1,1e3),this.camera.position.set(0,2,5),this.controls=new Qo(this.camera,this.renderer.domElement),this.controls.enableDamping=!1,this.orbit_controller=new fa(this.camera,this.controls,this.renderer,this.scene),this.raycast_helper=new ma(this.camera,this.renderer.domElement,this.scene.children),this._setup_orbit_animation_user_override(),window.addEventListener("resize",this._resize_handler),this.animate(),B.info("Viewer: Initializing...")}register_animation_mixer(t){this.animation_mixers.add(t)}unregister_animation_mixer(t){this.animation_mixers.delete(t)}update_animation_mixers(t){for(const n of this.animation_mixers)n.update(t)}register_animation_callback(t){this.animation_callbacks.add(t)}unregister_animation_callback(t){this.animation_callbacks.delete(t)}execute_animation_callbacks(t){for(const n of this.animation_callbacks)n(t)}onWindowResize(){const t=this.container.clientWidth,n=this.container.clientHeight;this.camera.aspect=t/n,this.camera.updateProjectionMatrix(),this.renderer.setSize(t,n),this.dispatchEvent(new CustomEvent("resize",{detail:{width:t,height:n}}))}register_resolution_material(t){t&&(t.resolution||t.uniforms&&t.uniforms.resolution)&&this._resolution_materials.add(t)}unregister_resolution_material(t){this._resolution_materials.delete(t)}frame_object(t,n=.2,s=1){n=n+1;const i=new _.Box3().setFromObject(t),o=i.getSize(new _.Vector3),a=i.getCenter(new _.Vector3);this.controls.target.copy(a),this.controls.update();const l=Math.max(o.x,o.y,o.z)/(2*Math.atan(Math.PI*this.camera.fov/360)),d=l/this.camera.aspect,u=n*Math.max(l,d),f=this.camera.position.clone().sub(this.controls.target).normalize();this.camera.position.copy(a).add(f.multiplyScalar(u)),this.camera.position.y=a.y+s,this.camera.near=u/100,this.camera.far=u*100,this.camera.updateProjectionMatrix(),this.renderer.render(this.scene,this.camera)}start_camera_orbit_animation(t,n,s=1){this.orbit_controller.start_animation(t,n,s)}stop_camera_orbit_animation(){this.orbit_controller.stop_animation()}set_auto_orbit(t){this.orbit_controller.set_auto_restart(t)}schedule_camera_orbit_restart(t=5e3){this.orbit_controller.schedule_restart(t)}_setup_orbit_animation_user_override(){this.orbit_controller.setup_user_override(),this.orbit_controller.addEventListener("orbitstart",()=>{this.dispatchEvent(new CustomEvent("orbitstart",{detail:{}}))}),this.orbit_controller.addEventListener("orbitstop",()=>{this.dispatchEvent(new CustomEvent("orbitstop",{detail:{}}))}),this.controls.addEventListener("change",()=>{this.dispatchEvent(new CustomEvent("camerachange",{detail:{position:this.camera.position.clone(),target:this.controls.target.clone()}}))})}raycast_from_event(t,n){return this.raycast_helper.raycast_from_event(t,n,!0)}enable_3d_cursor(t){this.cursor_3d||(this.cursor_3d=new ua(this.scene)),this.cursor_3d.enable(),this._cursor_3d_mouse_handler=n=>{var i;const s=this.raycast_from_event(n,t);(i=this.cursor_3d)==null||i.update(s)},this.renderer.domElement.addEventListener("mousemove",this._cursor_3d_mouse_handler)}disable_3d_cursor(){this.cursor_3d&&this.cursor_3d.disable(),this._cursor_3d_mouse_handler&&(this.renderer.domElement.removeEventListener("mousemove",this._cursor_3d_mouse_handler),this._cursor_3d_mouse_handler=void 0)}update_3d_cursor(t,n){var i;if(!((i=this.cursor_3d)!=null&&i.enabled))return;const s=this.raycast_from_event(t,n);this.cursor_3d.update(s)}get_3d_cursor(){return this.cursor_3d}dispose(){this.orbit_controller.dispose(),this.disable_3d_cursor(),this.cursor_3d&&(this.cursor_3d.dispose(),this.cursor_3d=void 0),window.removeEventListener("resize",this._resize_handler),this.animation_mixers.clear(),this.animation_callbacks.clear(),this.renderer.dispose(),this.renderer.domElement&&this.renderer.domElement.parentElement&&this.renderer.domElement.parentElement.removeChild(this.renderer.domElement),this._resolution_materials.clear()}}class pa extends h.DataTextureLoader{constructor(e){super(e),this.type=h.HalfFloatType}parse(e){const o=function(O,D){switch(O){case 1:throw new Error("THREE.RGBELoader: Read Error: "+(D||""));case 2:throw new Error("THREE.RGBELoader: Write Error: "+(D||""));case 3:throw new Error("THREE.RGBELoader: Bad File Format: "+(D||""));default:case 4:throw new Error("THREE.RGBELoader: Memory Error: "+(D||""))}},d=`
1
+ (function(te,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("three")):typeof define=="function"&&define.amd?define(["exports","three"],h):(te=typeof globalThis<"u"?globalThis:te||self,h(te.Glimmer={},te.THREE))})(this,function(te,h){"use strict";var Ql=Object.defineProperty;var ed=(te,h,St)=>h in te?Ql(te,h,{enumerable:!0,configurable:!0,writable:!0,value:St}):te[h]=St;var g=(te,h,St)=>ed(te,typeof h!="symbol"?h+"":h,St);function St(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>r[t]})}}return e.default=r,Object.freeze(e)}const _=St(h);var J;(function(r){r.assertEqual=s=>s;function e(s){}r.assertIs=e;function t(s){throw new Error}r.assertNever=t,r.arrayToEnum=s=>{const i={};for(const o of s)i[o]=o;return i},r.getValidEnumValues=s=>{const i=r.objectKeys(s).filter(a=>typeof s[s[a]]!="number"),o={};for(const a of i)o[a]=s[a];return r.objectValues(o)},r.objectValues=s=>r.objectKeys(s).map(function(i){return s[i]}),r.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{const i=[];for(const o in s)Object.prototype.hasOwnProperty.call(s,o)&&i.push(o);return i},r.find=(s,i)=>{for(const o of s)if(i(o))return o},r.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&isFinite(s)&&Math.floor(s)===s;function n(s,i=" | "){return s.map(o=>typeof o=="string"?`'${o}'`:o).join(i)}r.joinValues=n,r.jsonStringifyReplacer=(s,i)=>typeof i=="bigint"?i.toString():i})(J||(J={}));var ns;(function(r){r.mergeShapes=(e,t)=>({...e,...t})})(ns||(ns={}));const I=J.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Ye=r=>{switch(typeof r){case"undefined":return I.undefined;case"string":return I.string;case"number":return isNaN(r)?I.nan:I.number;case"boolean":return I.boolean;case"function":return I.function;case"bigint":return I.bigint;case"symbol":return I.symbol;case"object":return Array.isArray(r)?I.array:r===null?I.null:r.then&&typeof r.then=="function"&&r.catch&&typeof r.catch=="function"?I.promise:typeof Map<"u"&&r instanceof Map?I.map:typeof Set<"u"&&r instanceof Set?I.set:typeof Date<"u"&&r instanceof Date?I.date:I.object;default:return I.unknown}},M=J.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),Gr=r=>JSON.stringify(r,null,2).replace(/"([^"]+)":/g,"$1:");class Ie extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=n=>{this.issues=[...this.issues,n]},this.addIssues=(n=[])=>{this.issues=[...this.issues,...n]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){const t=e||function(i){return i.message},n={_errors:[]},s=i=>{for(const o of i.issues)if(o.code==="invalid_union")o.unionErrors.map(s);else if(o.code==="invalid_return_type")s(o.returnTypeError);else if(o.code==="invalid_arguments")s(o.argumentsError);else if(o.path.length===0)n._errors.push(t(o));else{let a=n,c=0;for(;c<o.path.length;){const l=o.path[c];c===o.path.length-1?(a[l]=a[l]||{_errors:[]},a[l]._errors.push(t(o))):a[l]=a[l]||{_errors:[]},a=a[l],c++}}};return s(this),n}static assert(e){if(!(e instanceof Ie))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,J.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=t=>t.message){const t={},n=[];for(const s of this.issues)s.path.length>0?(t[s.path[0]]=t[s.path[0]]||[],t[s.path[0]].push(e(s))):n.push(e(s));return{formErrors:n,fieldErrors:t}}get formErrors(){return this.flatten()}}Ie.create=r=>new Ie(r);const At=(r,e)=>{let t;switch(r.code){case M.invalid_type:r.received===I.undefined?t="Required":t=`Expected ${r.expected}, received ${r.received}`;break;case M.invalid_literal:t=`Invalid literal value, expected ${JSON.stringify(r.expected,J.jsonStringifyReplacer)}`;break;case M.unrecognized_keys:t=`Unrecognized key(s) in object: ${J.joinValues(r.keys,", ")}`;break;case M.invalid_union:t="Invalid input";break;case M.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${J.joinValues(r.options)}`;break;case M.invalid_enum_value:t=`Invalid enum value. Expected ${J.joinValues(r.options)}, received '${r.received}'`;break;case M.invalid_arguments:t="Invalid function arguments";break;case M.invalid_return_type:t="Invalid function return type";break;case M.invalid_date:t="Invalid date";break;case M.invalid_string:typeof r.validation=="object"?"includes"in r.validation?(t=`Invalid input: must include "${r.validation.includes}"`,typeof r.validation.position=="number"&&(t=`${t} at one or more positions greater than or equal to ${r.validation.position}`)):"startsWith"in r.validation?t=`Invalid input: must start with "${r.validation.startsWith}"`:"endsWith"in r.validation?t=`Invalid input: must end with "${r.validation.endsWith}"`:J.assertNever(r.validation):r.validation!=="regex"?t=`Invalid ${r.validation}`:t="Invalid";break;case M.too_small:r.type==="array"?t=`Array must contain ${r.exact?"exactly":r.inclusive?"at least":"more than"} ${r.minimum} element(s)`:r.type==="string"?t=`String must contain ${r.exact?"exactly":r.inclusive?"at least":"over"} ${r.minimum} character(s)`:r.type==="number"?t=`Number must be ${r.exact?"exactly equal to ":r.inclusive?"greater than or equal to ":"greater than "}${r.minimum}`:r.type==="date"?t=`Date must be ${r.exact?"exactly equal to ":r.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(r.minimum))}`:t="Invalid input";break;case M.too_big:r.type==="array"?t=`Array must contain ${r.exact?"exactly":r.inclusive?"at most":"less than"} ${r.maximum} element(s)`:r.type==="string"?t=`String must contain ${r.exact?"exactly":r.inclusive?"at most":"under"} ${r.maximum} character(s)`:r.type==="number"?t=`Number must be ${r.exact?"exactly":r.inclusive?"less than or equal to":"less than"} ${r.maximum}`:r.type==="bigint"?t=`BigInt must be ${r.exact?"exactly":r.inclusive?"less than or equal to":"less than"} ${r.maximum}`:r.type==="date"?t=`Date must be ${r.exact?"exactly":r.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(r.maximum))}`:t="Invalid input";break;case M.custom:t="Invalid input";break;case M.invalid_intersection_types:t="Intersection results could not be merged";break;case M.not_multiple_of:t=`Number must be a multiple of ${r.multipleOf}`;break;case M.not_finite:t="Number must be finite";break;default:t=e.defaultError,J.assertNever(r)}return{message:t}};let ri=At;function Zr(r){ri=r}function wn(){return ri}const Sn=r=>{const{data:e,path:t,errorMaps:n,issueData:s}=r,i=[...t,...s.path||[]],o={...s,path:i};if(s.message!==void 0)return{...s,path:i,message:s.message};let a="";const c=n.filter(l=>!!l).slice().reverse();for(const l of c)a=l(o,{data:e,defaultError:a}).message;return{...s,path:i,message:a}},Wr=[];function C(r,e){const t=wn(),n=Sn({issueData:e,data:r.data,path:r.path,errorMaps:[r.common.contextualErrorMap,r.schemaErrorMap,t,t===At?void 0:At].filter(s=>!!s)});r.common.issues.push(n)}class ye{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,t){const n=[];for(const s of t){if(s.status==="aborted")return G;s.status==="dirty"&&e.dirty(),n.push(s.value)}return{status:e.value,value:n}}static async mergeObjectAsync(e,t){const n=[];for(const s of t){const i=await s.key,o=await s.value;n.push({key:i,value:o})}return ye.mergeObjectSync(e,n)}static mergeObjectSync(e,t){const n={};for(const s of t){const{key:i,value:o}=s;if(i.status==="aborted"||o.status==="aborted")return G;i.status==="dirty"&&e.dirty(),o.status==="dirty"&&e.dirty(),i.value!=="__proto__"&&(typeof o.value<"u"||s.alwaysSet)&&(n[i.value]=o.value)}return{status:e.value,value:n}}}const G=Object.freeze({status:"aborted"}),Mt=r=>({status:"dirty",value:r}),be=r=>({status:"valid",value:r}),ss=r=>r.status==="aborted",is=r=>r.status==="dirty",ft=r=>r.status==="valid",Gt=r=>typeof Promise<"u"&&r instanceof Promise;function An(r,e,t,n){if(typeof e=="function"?r!==e||!0:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e.get(r)}function oi(r,e,t,n,s){if(typeof e=="function"?r!==e||!0:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e.set(r,t),t}typeof SuppressedError=="function"&&SuppressedError;var P;(function(r){r.errToObj=e=>typeof e=="string"?{message:e}:e||{},r.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(P||(P={}));var Zt,Wt;class Be{constructor(e,t,n,s){this._cachedPath=[],this.parent=e,this.data=t,this._path=n,this._key=s}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const ai=(r,e)=>{if(ft(e))return{success:!0,data:e.value};if(!r.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const t=new Ie(r.common.issues);return this._error=t,this._error}}};function X(r){if(!r)return{};const{errorMap:e,invalid_type_error:t,required_error:n,description:s}=r;if(e&&(t||n))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:s}:{errorMap:(o,a)=>{var c,l;const{message:d}=r;return o.code==="invalid_enum_value"?{message:d??a.defaultError}:typeof a.data>"u"?{message:(c=d??n)!==null&&c!==void 0?c:a.defaultError}:o.code!=="invalid_type"?{message:a.defaultError}:{message:(l=d??t)!==null&&l!==void 0?l:a.defaultError}},description:s}}class K{get description(){return this._def.description}_getType(e){return Ye(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:Ye(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new ye,ctx:{common:e.parent.common,data:e.data,parsedType:Ye(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(Gt(t))throw new Error("Synchronous parse encountered promise.");return t}_parseAsync(e){const t=this._parse(e);return Promise.resolve(t)}parse(e,t){const n=this.safeParse(e,t);if(n.success)return n.data;throw n.error}safeParse(e,t){var n;const s={common:{issues:[],async:(n=t==null?void 0:t.async)!==null&&n!==void 0?n:!1,contextualErrorMap:t==null?void 0:t.errorMap},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Ye(e)},i=this._parseSync({data:e,path:s.path,parent:s});return ai(s,i)}"~validate"(e){var t,n;const s={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Ye(e)};if(!this["~standard"].async)try{const i=this._parseSync({data:e,path:[],parent:s});return ft(i)?{value:i.value}:{issues:s.common.issues}}catch(i){!((n=(t=i==null?void 0:i.message)===null||t===void 0?void 0:t.toLowerCase())===null||n===void 0)&&n.includes("encountered")&&(this["~standard"].async=!0),s.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:s}).then(i=>ft(i)?{value:i.value}:{issues:s.common.issues})}async parseAsync(e,t){const n=await this.safeParseAsync(e,t);if(n.success)return n.data;throw n.error}async safeParseAsync(e,t){const n={common:{issues:[],contextualErrorMap:t==null?void 0:t.errorMap,async:!0},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Ye(e)},s=this._parse({data:e,path:n.path,parent:n}),i=await(Gt(s)?s:Promise.resolve(s));return ai(n,i)}refine(e,t){const n=s=>typeof t=="string"||typeof t>"u"?{message:t}:typeof t=="function"?t(s):t;return this._refinement((s,i)=>{const o=e(s),a=()=>i.addIssue({code:M.custom,...n(s)});return typeof Promise<"u"&&o instanceof Promise?o.then(c=>c?!0:(a(),!1)):o?!0:(a(),!1)})}refinement(e,t){return this._refinement((n,s)=>e(n)?!0:(s.addIssue(typeof t=="function"?t(n,s):t),!1))}_refinement(e){return new Ue({schema:this,typeName:V.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:t=>this["~validate"](t)}}optional(){return Ge.create(this,this._def)}nullable(){return dt.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return ze.create(this)}promise(){return Ct.create(this,this._def)}or(e){return Yt.create([this,e],this._def)}and(e){return Ht.create(this,e,this._def)}transform(e){return new Ue({...X(this._def),schema:this,typeName:V.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new tn({...X(this._def),innerType:this,defaultValue:t,typeName:V.ZodDefault})}brand(){return new as({typeName:V.ZodBranded,type:this,...X(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new nn({...X(this._def),innerType:this,catchValue:t,typeName:V.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return sn.create(this,e)}readonly(){return rn.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Xr=/^c[^\s-]{8,}$/i,$r=/^[0-9a-z]+$/,Kr=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Yr=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,Hr=/^[a-z0-9_-]{21}$/i,qr=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Jr=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,Qr=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,eo="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let rs;const to=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,no=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,so=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,io=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,ro=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,oo=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,ci="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",ao=new RegExp(`^${ci}$`);function li(r){let e="([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";return r.precision?e=`${e}\\.\\d{${r.precision}}`:r.precision==null&&(e=`${e}(\\.\\d+)?`),e}function co(r){return new RegExp(`^${li(r)}$`)}function di(r){let e=`${ci}T${li(r)}`;const t=[];return t.push(r.local?"Z?":"Z"),r.offset&&t.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${t.join("|")})`,new RegExp(`^${e}$`)}function lo(r,e){return!!((e==="v4"||!e)&&to.test(r)||(e==="v6"||!e)&&so.test(r))}function ho(r,e){if(!qr.test(r))return!1;try{const[t]=r.split("."),n=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(t.length+(4-t.length%4)%4,"="),s=JSON.parse(atob(n));return!(typeof s!="object"||s===null||!s.typ||!s.alg||e&&s.alg!==e)}catch{return!1}}function uo(r,e){return!!((e==="v4"||!e)&&no.test(r)||(e==="v6"||!e)&&io.test(r))}class Re extends K{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==I.string){const i=this._getOrReturnCtx(e);return C(i,{code:M.invalid_type,expected:I.string,received:i.parsedType}),G}const n=new ye;let s;for(const i of this._def.checks)if(i.kind==="min")e.data.length<i.value&&(s=this._getOrReturnCtx(e,s),C(s,{code:M.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),n.dirty());else if(i.kind==="max")e.data.length>i.value&&(s=this._getOrReturnCtx(e,s),C(s,{code:M.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),n.dirty());else if(i.kind==="length"){const o=e.data.length>i.value,a=e.data.length<i.value;(o||a)&&(s=this._getOrReturnCtx(e,s),o?C(s,{code:M.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}):a&&C(s,{code:M.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}),n.dirty())}else if(i.kind==="email")Qr.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"email",code:M.invalid_string,message:i.message}),n.dirty());else if(i.kind==="emoji")rs||(rs=new RegExp(eo,"u")),rs.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"emoji",code:M.invalid_string,message:i.message}),n.dirty());else if(i.kind==="uuid")Yr.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"uuid",code:M.invalid_string,message:i.message}),n.dirty());else if(i.kind==="nanoid")Hr.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"nanoid",code:M.invalid_string,message:i.message}),n.dirty());else if(i.kind==="cuid")Xr.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"cuid",code:M.invalid_string,message:i.message}),n.dirty());else if(i.kind==="cuid2")$r.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"cuid2",code:M.invalid_string,message:i.message}),n.dirty());else if(i.kind==="ulid")Kr.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"ulid",code:M.invalid_string,message:i.message}),n.dirty());else if(i.kind==="url")try{new URL(e.data)}catch{s=this._getOrReturnCtx(e,s),C(s,{validation:"url",code:M.invalid_string,message:i.message}),n.dirty()}else i.kind==="regex"?(i.regex.lastIndex=0,i.regex.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"regex",code:M.invalid_string,message:i.message}),n.dirty())):i.kind==="trim"?e.data=e.data.trim():i.kind==="includes"?e.data.includes(i.value,i.position)||(s=this._getOrReturnCtx(e,s),C(s,{code:M.invalid_string,validation:{includes:i.value,position:i.position},message:i.message}),n.dirty()):i.kind==="toLowerCase"?e.data=e.data.toLowerCase():i.kind==="toUpperCase"?e.data=e.data.toUpperCase():i.kind==="startsWith"?e.data.startsWith(i.value)||(s=this._getOrReturnCtx(e,s),C(s,{code:M.invalid_string,validation:{startsWith:i.value},message:i.message}),n.dirty()):i.kind==="endsWith"?e.data.endsWith(i.value)||(s=this._getOrReturnCtx(e,s),C(s,{code:M.invalid_string,validation:{endsWith:i.value},message:i.message}),n.dirty()):i.kind==="datetime"?di(i).test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{code:M.invalid_string,validation:"datetime",message:i.message}),n.dirty()):i.kind==="date"?ao.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{code:M.invalid_string,validation:"date",message:i.message}),n.dirty()):i.kind==="time"?co(i).test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{code:M.invalid_string,validation:"time",message:i.message}),n.dirty()):i.kind==="duration"?Jr.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"duration",code:M.invalid_string,message:i.message}),n.dirty()):i.kind==="ip"?lo(e.data,i.version)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"ip",code:M.invalid_string,message:i.message}),n.dirty()):i.kind==="jwt"?ho(e.data,i.alg)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"jwt",code:M.invalid_string,message:i.message}),n.dirty()):i.kind==="cidr"?uo(e.data,i.version)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"cidr",code:M.invalid_string,message:i.message}),n.dirty()):i.kind==="base64"?ro.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"base64",code:M.invalid_string,message:i.message}),n.dirty()):i.kind==="base64url"?oo.test(e.data)||(s=this._getOrReturnCtx(e,s),C(s,{validation:"base64url",code:M.invalid_string,message:i.message}),n.dirty()):J.assertNever(i);return{status:n.value,value:e.data}}_regex(e,t,n){return this.refinement(s=>e.test(s),{validation:t,code:M.invalid_string,...P.errToObj(n)})}_addCheck(e){return new Re({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...P.errToObj(e)})}url(e){return this._addCheck({kind:"url",...P.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...P.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...P.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...P.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...P.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...P.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...P.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...P.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...P.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...P.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...P.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...P.errToObj(e)})}datetime(e){var t,n;return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,offset:(t=e==null?void 0:e.offset)!==null&&t!==void 0?t:!1,local:(n=e==null?void 0:e.local)!==null&&n!==void 0?n:!1,...P.errToObj(e==null?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,...P.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...P.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...P.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t==null?void 0:t.position,...P.errToObj(t==null?void 0:t.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...P.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...P.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...P.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...P.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...P.errToObj(t)})}nonempty(e){return this.min(1,P.errToObj(e))}trim(){return new Re({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Re({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Re({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}Re.create=r=>{var e;return new Re({checks:[],typeName:V.ZodString,coerce:(e=r==null?void 0:r.coerce)!==null&&e!==void 0?e:!1,...X(r)})};function fo(r,e){const t=(r.toString().split(".")[1]||"").length,n=(e.toString().split(".")[1]||"").length,s=t>n?t:n,i=parseInt(r.toFixed(s).replace(".","")),o=parseInt(e.toFixed(s).replace(".",""));return i%o/Math.pow(10,s)}class at extends K{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==I.number){const i=this._getOrReturnCtx(e);return C(i,{code:M.invalid_type,expected:I.number,received:i.parsedType}),G}let n;const s=new ye;for(const i of this._def.checks)i.kind==="int"?J.isInteger(e.data)||(n=this._getOrReturnCtx(e,n),C(n,{code:M.invalid_type,expected:"integer",received:"float",message:i.message}),s.dirty()):i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(n=this._getOrReturnCtx(e,n),C(n,{code:M.too_small,minimum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(n=this._getOrReturnCtx(e,n),C(n,{code:M.too_big,maximum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="multipleOf"?fo(e.data,i.value)!==0&&(n=this._getOrReturnCtx(e,n),C(n,{code:M.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):i.kind==="finite"?Number.isFinite(e.data)||(n=this._getOrReturnCtx(e,n),C(n,{code:M.not_finite,message:i.message}),s.dirty()):J.assertNever(i);return{status:s.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,P.toString(t))}gt(e,t){return this.setLimit("min",e,!1,P.toString(t))}lte(e,t){return this.setLimit("max",e,!0,P.toString(t))}lt(e,t){return this.setLimit("max",e,!1,P.toString(t))}setLimit(e,t,n,s){return new at({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:n,message:P.toString(s)}]})}_addCheck(e){return new at({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:P.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:P.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:P.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:P.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:P.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:P.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:P.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:P.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:P.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&J.isInteger(e.value))}get isFinite(){let e=null,t=null;for(const n of this._def.checks){if(n.kind==="finite"||n.kind==="int"||n.kind==="multipleOf")return!0;n.kind==="min"?(t===null||n.value>t)&&(t=n.value):n.kind==="max"&&(e===null||n.value<e)&&(e=n.value)}return Number.isFinite(t)&&Number.isFinite(e)}}at.create=r=>new at({checks:[],typeName:V.ZodNumber,coerce:(r==null?void 0:r.coerce)||!1,...X(r)});class ct extends K{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==I.bigint)return this._getInvalidInput(e);let n;const s=new ye;for(const i of this._def.checks)i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(n=this._getOrReturnCtx(e,n),C(n,{code:M.too_small,type:"bigint",minimum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(n=this._getOrReturnCtx(e,n),C(n,{code:M.too_big,type:"bigint",maximum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="multipleOf"?e.data%i.value!==BigInt(0)&&(n=this._getOrReturnCtx(e,n),C(n,{code:M.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):J.assertNever(i);return{status:s.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return C(t,{code:M.invalid_type,expected:I.bigint,received:t.parsedType}),G}gte(e,t){return this.setLimit("min",e,!0,P.toString(t))}gt(e,t){return this.setLimit("min",e,!1,P.toString(t))}lte(e,t){return this.setLimit("max",e,!0,P.toString(t))}lt(e,t){return this.setLimit("max",e,!1,P.toString(t))}setLimit(e,t,n,s){return new ct({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:n,message:P.toString(s)}]})}_addCheck(e){return new ct({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:P.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:P.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:P.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:P.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:P.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}ct.create=r=>{var e;return new ct({checks:[],typeName:V.ZodBigInt,coerce:(e=r==null?void 0:r.coerce)!==null&&e!==void 0?e:!1,...X(r)})};class Xt extends K{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==I.boolean){const n=this._getOrReturnCtx(e);return C(n,{code:M.invalid_type,expected:I.boolean,received:n.parsedType}),G}return be(e.data)}}Xt.create=r=>new Xt({typeName:V.ZodBoolean,coerce:(r==null?void 0:r.coerce)||!1,...X(r)});class mt extends K{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==I.date){const i=this._getOrReturnCtx(e);return C(i,{code:M.invalid_type,expected:I.date,received:i.parsedType}),G}if(isNaN(e.data.getTime())){const i=this._getOrReturnCtx(e);return C(i,{code:M.invalid_date}),G}const n=new ye;let s;for(const i of this._def.checks)i.kind==="min"?e.data.getTime()<i.value&&(s=this._getOrReturnCtx(e,s),C(s,{code:M.too_small,message:i.message,inclusive:!0,exact:!1,minimum:i.value,type:"date"}),n.dirty()):i.kind==="max"?e.data.getTime()>i.value&&(s=this._getOrReturnCtx(e,s),C(s,{code:M.too_big,message:i.message,inclusive:!0,exact:!1,maximum:i.value,type:"date"}),n.dirty()):J.assertNever(i);return{status:n.value,value:new Date(e.data.getTime())}}_addCheck(e){return new mt({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:P.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:P.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e!=null?new Date(e):null}}mt.create=r=>new mt({checks:[],coerce:(r==null?void 0:r.coerce)||!1,typeName:V.ZodDate,...X(r)});class Mn extends K{_parse(e){if(this._getType(e)!==I.symbol){const n=this._getOrReturnCtx(e);return C(n,{code:M.invalid_type,expected:I.symbol,received:n.parsedType}),G}return be(e.data)}}Mn.create=r=>new Mn({typeName:V.ZodSymbol,...X(r)});class $t extends K{_parse(e){if(this._getType(e)!==I.undefined){const n=this._getOrReturnCtx(e);return C(n,{code:M.invalid_type,expected:I.undefined,received:n.parsedType}),G}return be(e.data)}}$t.create=r=>new $t({typeName:V.ZodUndefined,...X(r)});class Kt extends K{_parse(e){if(this._getType(e)!==I.null){const n=this._getOrReturnCtx(e);return C(n,{code:M.invalid_type,expected:I.null,received:n.parsedType}),G}return be(e.data)}}Kt.create=r=>new Kt({typeName:V.ZodNull,...X(r)});class Lt extends K{constructor(){super(...arguments),this._any=!0}_parse(e){return be(e.data)}}Lt.create=r=>new Lt({typeName:V.ZodAny,...X(r)});class pt extends K{constructor(){super(...arguments),this._unknown=!0}_parse(e){return be(e.data)}}pt.create=r=>new pt({typeName:V.ZodUnknown,...X(r)});class He extends K{_parse(e){const t=this._getOrReturnCtx(e);return C(t,{code:M.invalid_type,expected:I.never,received:t.parsedType}),G}}He.create=r=>new He({typeName:V.ZodNever,...X(r)});class Ln extends K{_parse(e){if(this._getType(e)!==I.undefined){const n=this._getOrReturnCtx(e);return C(n,{code:M.invalid_type,expected:I.void,received:n.parsedType}),G}return be(e.data)}}Ln.create=r=>new Ln({typeName:V.ZodVoid,...X(r)});class ze extends K{_parse(e){const{ctx:t,status:n}=this._processInputParams(e),s=this._def;if(t.parsedType!==I.array)return C(t,{code:M.invalid_type,expected:I.array,received:t.parsedType}),G;if(s.exactLength!==null){const o=t.data.length>s.exactLength.value,a=t.data.length<s.exactLength.value;(o||a)&&(C(t,{code:o?M.too_big:M.too_small,minimum:a?s.exactLength.value:void 0,maximum:o?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),n.dirty())}if(s.minLength!==null&&t.data.length<s.minLength.value&&(C(t,{code:M.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),n.dirty()),s.maxLength!==null&&t.data.length>s.maxLength.value&&(C(t,{code:M.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),n.dirty()),t.common.async)return Promise.all([...t.data].map((o,a)=>s.type._parseAsync(new Be(t,o,t.path,a)))).then(o=>ye.mergeArray(n,o));const i=[...t.data].map((o,a)=>s.type._parseSync(new Be(t,o,t.path,a)));return ye.mergeArray(n,i)}get element(){return this._def.type}min(e,t){return new ze({...this._def,minLength:{value:e,message:P.toString(t)}})}max(e,t){return new ze({...this._def,maxLength:{value:e,message:P.toString(t)}})}length(e,t){return new ze({...this._def,exactLength:{value:e,message:P.toString(t)}})}nonempty(e){return this.min(1,e)}}ze.create=(r,e)=>new ze({type:r,minLength:null,maxLength:null,exactLength:null,typeName:V.ZodArray,...X(e)});function Tt(r){if(r instanceof re){const e={};for(const t in r.shape){const n=r.shape[t];e[t]=Ge.create(Tt(n))}return new re({...r._def,shape:()=>e})}else return r instanceof ze?new ze({...r._def,type:Tt(r.element)}):r instanceof Ge?Ge.create(Tt(r.unwrap())):r instanceof dt?dt.create(Tt(r.unwrap())):r instanceof Ve?Ve.create(r.items.map(e=>Tt(e))):r}class re extends K{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),t=J.objectKeys(e);return this._cached={shape:e,keys:t}}_parse(e){if(this._getType(e)!==I.object){const l=this._getOrReturnCtx(e);return C(l,{code:M.invalid_type,expected:I.object,received:l.parsedType}),G}const{status:n,ctx:s}=this._processInputParams(e),{shape:i,keys:o}=this._getCached(),a=[];if(!(this._def.catchall instanceof He&&this._def.unknownKeys==="strip"))for(const l in s.data)o.includes(l)||a.push(l);const c=[];for(const l of o){const d=i[l],u=s.data[l];c.push({key:{status:"valid",value:l},value:d._parse(new Be(s,u,s.path,l)),alwaysSet:l in s.data})}if(this._def.catchall instanceof He){const l=this._def.unknownKeys;if(l==="passthrough")for(const d of a)c.push({key:{status:"valid",value:d},value:{status:"valid",value:s.data[d]}});else if(l==="strict")a.length>0&&(C(s,{code:M.unrecognized_keys,keys:a}),n.dirty());else if(l!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const l=this._def.catchall;for(const d of a){const u=s.data[d];c.push({key:{status:"valid",value:d},value:l._parse(new Be(s,u,s.path,d)),alwaysSet:d in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const l=[];for(const d of c){const u=await d.key,f=await d.value;l.push({key:u,value:f,alwaysSet:d.alwaysSet})}return l}).then(l=>ye.mergeObjectSync(n,l)):ye.mergeObjectSync(n,c)}get shape(){return this._def.shape()}strict(e){return P.errToObj,new re({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,n)=>{var s,i,o,a;const c=(o=(i=(s=this._def).errorMap)===null||i===void 0?void 0:i.call(s,t,n).message)!==null&&o!==void 0?o:n.defaultError;return t.code==="unrecognized_keys"?{message:(a=P.errToObj(e).message)!==null&&a!==void 0?a:c}:{message:c}}}:{}})}strip(){return new re({...this._def,unknownKeys:"strip"})}passthrough(){return new re({...this._def,unknownKeys:"passthrough"})}extend(e){return new re({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new re({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:V.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new re({...this._def,catchall:e})}pick(e){const t={};return J.objectKeys(e).forEach(n=>{e[n]&&this.shape[n]&&(t[n]=this.shape[n])}),new re({...this._def,shape:()=>t})}omit(e){const t={};return J.objectKeys(this.shape).forEach(n=>{e[n]||(t[n]=this.shape[n])}),new re({...this._def,shape:()=>t})}deepPartial(){return Tt(this)}partial(e){const t={};return J.objectKeys(this.shape).forEach(n=>{const s=this.shape[n];e&&!e[n]?t[n]=s:t[n]=s.optional()}),new re({...this._def,shape:()=>t})}required(e){const t={};return J.objectKeys(this.shape).forEach(n=>{if(e&&!e[n])t[n]=this.shape[n];else{let i=this.shape[n];for(;i instanceof Ge;)i=i._def.innerType;t[n]=i}}),new re({...this._def,shape:()=>t})}keyof(){return hi(J.objectKeys(this.shape))}}re.create=(r,e)=>new re({shape:()=>r,unknownKeys:"strip",catchall:He.create(),typeName:V.ZodObject,...X(e)}),re.strictCreate=(r,e)=>new re({shape:()=>r,unknownKeys:"strict",catchall:He.create(),typeName:V.ZodObject,...X(e)}),re.lazycreate=(r,e)=>new re({shape:r,unknownKeys:"strip",catchall:He.create(),typeName:V.ZodObject,...X(e)});class Yt extends K{_parse(e){const{ctx:t}=this._processInputParams(e),n=this._def.options;function s(i){for(const a of i)if(a.result.status==="valid")return a.result;for(const a of i)if(a.result.status==="dirty")return t.common.issues.push(...a.ctx.common.issues),a.result;const o=i.map(a=>new Ie(a.ctx.common.issues));return C(t,{code:M.invalid_union,unionErrors:o}),G}if(t.common.async)return Promise.all(n.map(async i=>{const o={...t,common:{...t.common,issues:[]},parent:null};return{result:await i._parseAsync({data:t.data,path:t.path,parent:o}),ctx:o}})).then(s);{let i;const o=[];for(const c of n){const l={...t,common:{...t.common,issues:[]},parent:null},d=c._parseSync({data:t.data,path:t.path,parent:l});if(d.status==="valid")return d;d.status==="dirty"&&!i&&(i={result:d,ctx:l}),l.common.issues.length&&o.push(l.common.issues)}if(i)return t.common.issues.push(...i.ctx.common.issues),i.result;const a=o.map(c=>new Ie(c));return C(t,{code:M.invalid_union,unionErrors:a}),G}}get options(){return this._def.options}}Yt.create=(r,e)=>new Yt({options:r,typeName:V.ZodUnion,...X(e)});const qe=r=>r instanceof Jt?qe(r.schema):r instanceof Ue?qe(r.innerType()):r instanceof Qt?[r.value]:r instanceof lt?r.options:r instanceof en?J.objectValues(r.enum):r instanceof tn?qe(r._def.innerType):r instanceof $t?[void 0]:r instanceof Kt?[null]:r instanceof Ge?[void 0,...qe(r.unwrap())]:r instanceof dt?[null,...qe(r.unwrap())]:r instanceof as||r instanceof rn?qe(r.unwrap()):r instanceof nn?qe(r._def.innerType):[];class Tn extends K{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==I.object)return C(t,{code:M.invalid_type,expected:I.object,received:t.parsedType}),G;const n=this.discriminator,s=t.data[n],i=this.optionsMap.get(s);return i?t.common.async?i._parseAsync({data:t.data,path:t.path,parent:t}):i._parseSync({data:t.data,path:t.path,parent:t}):(C(t,{code:M.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[n]}),G)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,t,n){const s=new Map;for(const i of t){const o=qe(i.shape[e]);if(!o.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const a of o){if(s.has(a))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(a)}`);s.set(a,i)}}return new Tn({typeName:V.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:s,...X(n)})}}function os(r,e){const t=Ye(r),n=Ye(e);if(r===e)return{valid:!0,data:r};if(t===I.object&&n===I.object){const s=J.objectKeys(e),i=J.objectKeys(r).filter(a=>s.indexOf(a)!==-1),o={...r,...e};for(const a of i){const c=os(r[a],e[a]);if(!c.valid)return{valid:!1};o[a]=c.data}return{valid:!0,data:o}}else if(t===I.array&&n===I.array){if(r.length!==e.length)return{valid:!1};const s=[];for(let i=0;i<r.length;i++){const o=r[i],a=e[i],c=os(o,a);if(!c.valid)return{valid:!1};s.push(c.data)}return{valid:!0,data:s}}else return t===I.date&&n===I.date&&+r==+e?{valid:!0,data:r}:{valid:!1}}class Ht extends K{_parse(e){const{status:t,ctx:n}=this._processInputParams(e),s=(i,o)=>{if(ss(i)||ss(o))return G;const a=os(i.value,o.value);return a.valid?((is(i)||is(o))&&t.dirty(),{status:t.value,value:a.data}):(C(n,{code:M.invalid_intersection_types}),G)};return n.common.async?Promise.all([this._def.left._parseAsync({data:n.data,path:n.path,parent:n}),this._def.right._parseAsync({data:n.data,path:n.path,parent:n})]).then(([i,o])=>s(i,o)):s(this._def.left._parseSync({data:n.data,path:n.path,parent:n}),this._def.right._parseSync({data:n.data,path:n.path,parent:n}))}}Ht.create=(r,e,t)=>new Ht({left:r,right:e,typeName:V.ZodIntersection,...X(t)});class Ve extends K{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==I.array)return C(n,{code:M.invalid_type,expected:I.array,received:n.parsedType}),G;if(n.data.length<this._def.items.length)return C(n,{code:M.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),G;!this._def.rest&&n.data.length>this._def.items.length&&(C(n,{code:M.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const i=[...n.data].map((o,a)=>{const c=this._def.items[a]||this._def.rest;return c?c._parse(new Be(n,o,n.path,a)):null}).filter(o=>!!o);return n.common.async?Promise.all(i).then(o=>ye.mergeArray(t,o)):ye.mergeArray(t,i)}get items(){return this._def.items}rest(e){return new Ve({...this._def,rest:e})}}Ve.create=(r,e)=>{if(!Array.isArray(r))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Ve({items:r,typeName:V.ZodTuple,rest:null,...X(e)})};class qt extends K{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==I.object)return C(n,{code:M.invalid_type,expected:I.object,received:n.parsedType}),G;const s=[],i=this._def.keyType,o=this._def.valueType;for(const a in n.data)s.push({key:i._parse(new Be(n,a,n.path,a)),value:o._parse(new Be(n,n.data[a],n.path,a)),alwaysSet:a in n.data});return n.common.async?ye.mergeObjectAsync(t,s):ye.mergeObjectSync(t,s)}get element(){return this._def.valueType}static create(e,t,n){return t instanceof K?new qt({keyType:e,valueType:t,typeName:V.ZodRecord,...X(n)}):new qt({keyType:Re.create(),valueType:e,typeName:V.ZodRecord,...X(t)})}}class Dn extends K{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==I.map)return C(n,{code:M.invalid_type,expected:I.map,received:n.parsedType}),G;const s=this._def.keyType,i=this._def.valueType,o=[...n.data.entries()].map(([a,c],l)=>({key:s._parse(new Be(n,a,n.path,[l,"key"])),value:i._parse(new Be(n,c,n.path,[l,"value"]))}));if(n.common.async){const a=new Map;return Promise.resolve().then(async()=>{for(const c of o){const l=await c.key,d=await c.value;if(l.status==="aborted"||d.status==="aborted")return G;(l.status==="dirty"||d.status==="dirty")&&t.dirty(),a.set(l.value,d.value)}return{status:t.value,value:a}})}else{const a=new Map;for(const c of o){const l=c.key,d=c.value;if(l.status==="aborted"||d.status==="aborted")return G;(l.status==="dirty"||d.status==="dirty")&&t.dirty(),a.set(l.value,d.value)}return{status:t.value,value:a}}}}Dn.create=(r,e,t)=>new Dn({valueType:e,keyType:r,typeName:V.ZodMap,...X(t)});class _t extends K{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==I.set)return C(n,{code:M.invalid_type,expected:I.set,received:n.parsedType}),G;const s=this._def;s.minSize!==null&&n.data.size<s.minSize.value&&(C(n,{code:M.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),t.dirty()),s.maxSize!==null&&n.data.size>s.maxSize.value&&(C(n,{code:M.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),t.dirty());const i=this._def.valueType;function o(c){const l=new Set;for(const d of c){if(d.status==="aborted")return G;d.status==="dirty"&&t.dirty(),l.add(d.value)}return{status:t.value,value:l}}const a=[...n.data.values()].map((c,l)=>i._parse(new Be(n,c,n.path,l)));return n.common.async?Promise.all(a).then(c=>o(c)):o(a)}min(e,t){return new _t({...this._def,minSize:{value:e,message:P.toString(t)}})}max(e,t){return new _t({...this._def,maxSize:{value:e,message:P.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}_t.create=(r,e)=>new _t({valueType:r,minSize:null,maxSize:null,typeName:V.ZodSet,...X(e)});class Dt extends K{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==I.function)return C(t,{code:M.invalid_type,expected:I.function,received:t.parsedType}),G;function n(a,c){return Sn({data:a,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,wn(),At].filter(l=>!!l),issueData:{code:M.invalid_arguments,argumentsError:c}})}function s(a,c){return Sn({data:a,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,wn(),At].filter(l=>!!l),issueData:{code:M.invalid_return_type,returnTypeError:c}})}const i={errorMap:t.common.contextualErrorMap},o=t.data;if(this._def.returns instanceof Ct){const a=this;return be(async function(...c){const l=new Ie([]),d=await a._def.args.parseAsync(c,i).catch(m=>{throw l.addIssue(n(c,m)),l}),u=await Reflect.apply(o,this,d);return await a._def.returns._def.type.parseAsync(u,i).catch(m=>{throw l.addIssue(s(u,m)),l})})}else{const a=this;return be(function(...c){const l=a._def.args.safeParse(c,i);if(!l.success)throw new Ie([n(c,l.error)]);const d=Reflect.apply(o,this,l.data),u=a._def.returns.safeParse(d,i);if(!u.success)throw new Ie([s(d,u.error)]);return u.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new Dt({...this._def,args:Ve.create(e).rest(pt.create())})}returns(e){return new Dt({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,t,n){return new Dt({args:e||Ve.create([]).rest(pt.create()),returns:t||pt.create(),typeName:V.ZodFunction,...X(n)})}}class Jt extends K{get schema(){return this._def.getter()}_parse(e){const{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}Jt.create=(r,e)=>new Jt({getter:r,typeName:V.ZodLazy,...X(e)});class Qt extends K{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return C(t,{received:t.data,code:M.invalid_literal,expected:this._def.value}),G}return{status:"valid",value:e.data}}get value(){return this._def.value}}Qt.create=(r,e)=>new Qt({value:r,typeName:V.ZodLiteral,...X(e)});function hi(r,e){return new lt({values:r,typeName:V.ZodEnum,...X(e)})}class lt extends K{constructor(){super(...arguments),Zt.set(this,void 0)}_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),n=this._def.values;return C(t,{expected:J.joinValues(n),received:t.parsedType,code:M.invalid_type}),G}if(An(this,Zt)||oi(this,Zt,new Set(this._def.values)),!An(this,Zt).has(e.data)){const t=this._getOrReturnCtx(e),n=this._def.values;return C(t,{received:t.data,code:M.invalid_enum_value,options:n}),G}return be(e.data)}get options(){return this._def.values}get enum(){const e={};for(const t of this._def.values)e[t]=t;return e}get Values(){const e={};for(const t of this._def.values)e[t]=t;return e}get Enum(){const e={};for(const t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return lt.create(e,{...this._def,...t})}exclude(e,t=this._def){return lt.create(this.options.filter(n=>!e.includes(n)),{...this._def,...t})}}Zt=new WeakMap,lt.create=hi;class en extends K{constructor(){super(...arguments),Wt.set(this,void 0)}_parse(e){const t=J.getValidEnumValues(this._def.values),n=this._getOrReturnCtx(e);if(n.parsedType!==I.string&&n.parsedType!==I.number){const s=J.objectValues(t);return C(n,{expected:J.joinValues(s),received:n.parsedType,code:M.invalid_type}),G}if(An(this,Wt)||oi(this,Wt,new Set(J.getValidEnumValues(this._def.values))),!An(this,Wt).has(e.data)){const s=J.objectValues(t);return C(n,{received:n.data,code:M.invalid_enum_value,options:s}),G}return be(e.data)}get enum(){return this._def.values}}Wt=new WeakMap,en.create=(r,e)=>new en({values:r,typeName:V.ZodNativeEnum,...X(e)});class Ct extends K{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==I.promise&&t.common.async===!1)return C(t,{code:M.invalid_type,expected:I.promise,received:t.parsedType}),G;const n=t.parsedType===I.promise?t.data:Promise.resolve(t.data);return be(n.then(s=>this._def.type.parseAsync(s,{path:t.path,errorMap:t.common.contextualErrorMap})))}}Ct.create=(r,e)=>new Ct({type:r,typeName:V.ZodPromise,...X(e)});class Ue extends K{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===V.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:n}=this._processInputParams(e),s=this._def.effect||null,i={addIssue:o=>{C(n,o),o.fatal?t.abort():t.dirty()},get path(){return n.path}};if(i.addIssue=i.addIssue.bind(i),s.type==="preprocess"){const o=s.transform(n.data,i);if(n.common.async)return Promise.resolve(o).then(async a=>{if(t.value==="aborted")return G;const c=await this._def.schema._parseAsync({data:a,path:n.path,parent:n});return c.status==="aborted"?G:c.status==="dirty"||t.value==="dirty"?Mt(c.value):c});{if(t.value==="aborted")return G;const a=this._def.schema._parseSync({data:o,path:n.path,parent:n});return a.status==="aborted"?G:a.status==="dirty"||t.value==="dirty"?Mt(a.value):a}}if(s.type==="refinement"){const o=a=>{const c=s.refinement(a,i);if(n.common.async)return Promise.resolve(c);if(c instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return a};if(n.common.async===!1){const a=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});return a.status==="aborted"?G:(a.status==="dirty"&&t.dirty(),o(a.value),{status:t.value,value:a.value})}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(a=>a.status==="aborted"?G:(a.status==="dirty"&&t.dirty(),o(a.value).then(()=>({status:t.value,value:a.value}))))}if(s.type==="transform")if(n.common.async===!1){const o=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});if(!ft(o))return o;const a=s.transform(o.value,i);if(a instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:a}}else return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(o=>ft(o)?Promise.resolve(s.transform(o.value,i)).then(a=>({status:t.value,value:a})):o);J.assertNever(s)}}Ue.create=(r,e,t)=>new Ue({schema:r,typeName:V.ZodEffects,effect:e,...X(t)}),Ue.createWithPreprocess=(r,e,t)=>new Ue({schema:e,effect:{type:"preprocess",transform:r},typeName:V.ZodEffects,...X(t)});class Ge extends K{_parse(e){return this._getType(e)===I.undefined?be(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Ge.create=(r,e)=>new Ge({innerType:r,typeName:V.ZodOptional,...X(e)});class dt extends K{_parse(e){return this._getType(e)===I.null?be(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}dt.create=(r,e)=>new dt({innerType:r,typeName:V.ZodNullable,...X(e)});class tn extends K{_parse(e){const{ctx:t}=this._processInputParams(e);let n=t.data;return t.parsedType===I.undefined&&(n=this._def.defaultValue()),this._def.innerType._parse({data:n,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}tn.create=(r,e)=>new tn({innerType:r,typeName:V.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...X(e)});class nn extends K{_parse(e){const{ctx:t}=this._processInputParams(e),n={...t,common:{...t.common,issues:[]}},s=this._def.innerType._parse({data:n.data,path:n.path,parent:{...n}});return Gt(s)?s.then(i=>({status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new Ie(n.common.issues)},input:n.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new Ie(n.common.issues)},input:n.data})}}removeCatch(){return this._def.innerType}}nn.create=(r,e)=>new nn({innerType:r,typeName:V.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...X(e)});class Cn extends K{_parse(e){if(this._getType(e)!==I.nan){const n=this._getOrReturnCtx(e);return C(n,{code:M.invalid_type,expected:I.nan,received:n.parsedType}),G}return{status:"valid",value:e.data}}}Cn.create=r=>new Cn({typeName:V.ZodNaN,...X(r)});const mo=Symbol("zod_brand");class as extends K{_parse(e){const{ctx:t}=this._processInputParams(e),n=t.data;return this._def.type._parse({data:n,path:t.path,parent:t})}unwrap(){return this._def.type}}class sn extends K{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.common.async)return(async()=>{const i=await this._def.in._parseAsync({data:n.data,path:n.path,parent:n});return i.status==="aborted"?G:i.status==="dirty"?(t.dirty(),Mt(i.value)):this._def.out._parseAsync({data:i.value,path:n.path,parent:n})})();{const s=this._def.in._parseSync({data:n.data,path:n.path,parent:n});return s.status==="aborted"?G:s.status==="dirty"?(t.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:n.path,parent:n})}}static create(e,t){return new sn({in:e,out:t,typeName:V.ZodPipeline})}}class rn extends K{_parse(e){const t=this._def.innerType._parse(e),n=s=>(ft(s)&&(s.value=Object.freeze(s.value)),s);return Gt(t)?t.then(s=>n(s)):n(t)}unwrap(){return this._def.innerType}}rn.create=(r,e)=>new rn({innerType:r,typeName:V.ZodReadonly,...X(e)});function ui(r,e){const t=typeof r=="function"?r(e):typeof r=="string"?{message:r}:r;return typeof t=="string"?{message:t}:t}function fi(r,e={},t){return r?Lt.create().superRefine((n,s)=>{var i,o;const a=r(n);if(a instanceof Promise)return a.then(c=>{var l,d;if(!c){const u=ui(e,n),f=(d=(l=u.fatal)!==null&&l!==void 0?l:t)!==null&&d!==void 0?d:!0;s.addIssue({code:"custom",...u,fatal:f})}});if(!a){const c=ui(e,n),l=(o=(i=c.fatal)!==null&&i!==void 0?i:t)!==null&&o!==void 0?o:!0;s.addIssue({code:"custom",...c,fatal:l})}}):Lt.create()}const po={object:re.lazycreate};var V;(function(r){r.ZodString="ZodString",r.ZodNumber="ZodNumber",r.ZodNaN="ZodNaN",r.ZodBigInt="ZodBigInt",r.ZodBoolean="ZodBoolean",r.ZodDate="ZodDate",r.ZodSymbol="ZodSymbol",r.ZodUndefined="ZodUndefined",r.ZodNull="ZodNull",r.ZodAny="ZodAny",r.ZodUnknown="ZodUnknown",r.ZodNever="ZodNever",r.ZodVoid="ZodVoid",r.ZodArray="ZodArray",r.ZodObject="ZodObject",r.ZodUnion="ZodUnion",r.ZodDiscriminatedUnion="ZodDiscriminatedUnion",r.ZodIntersection="ZodIntersection",r.ZodTuple="ZodTuple",r.ZodRecord="ZodRecord",r.ZodMap="ZodMap",r.ZodSet="ZodSet",r.ZodFunction="ZodFunction",r.ZodLazy="ZodLazy",r.ZodLiteral="ZodLiteral",r.ZodEnum="ZodEnum",r.ZodEffects="ZodEffects",r.ZodNativeEnum="ZodNativeEnum",r.ZodOptional="ZodOptional",r.ZodNullable="ZodNullable",r.ZodDefault="ZodDefault",r.ZodCatch="ZodCatch",r.ZodPromise="ZodPromise",r.ZodBranded="ZodBranded",r.ZodPipeline="ZodPipeline",r.ZodReadonly="ZodReadonly"})(V||(V={}));const _o=(r,e={message:`Input not instance of ${r.name}`})=>fi(t=>t instanceof r,e),mi=Re.create,pi=at.create,go=Cn.create,yo=ct.create,_i=Xt.create,vo=mt.create,xo=Mn.create,bo=$t.create,wo=Kt.create,So=Lt.create,Ao=pt.create,Mo=He.create,Lo=Ln.create,To=ze.create,Do=re.create,Co=re.strictCreate,Oo=Yt.create,Io=Tn.create,ko=Ht.create,No=Ve.create,Eo=qt.create,Po=Dn.create,Ro=_t.create,zo=Dt.create,Uo=Jt.create,Fo=Qt.create,jo=lt.create,Bo=en.create,Vo=Ct.create,gi=Ue.create,Go=Ge.create,Zo=dt.create,Wo=Ue.createWithPreprocess,Xo=sn.create;var w=Object.freeze({__proto__:null,defaultErrorMap:At,setErrorMap:Zr,getErrorMap:wn,makeIssue:Sn,EMPTY_PATH:Wr,addIssueToContext:C,ParseStatus:ye,INVALID:G,DIRTY:Mt,OK:be,isAborted:ss,isDirty:is,isValid:ft,isAsync:Gt,get util(){return J},get objectUtil(){return ns},ZodParsedType:I,getParsedType:Ye,ZodType:K,datetimeRegex:di,ZodString:Re,ZodNumber:at,ZodBigInt:ct,ZodBoolean:Xt,ZodDate:mt,ZodSymbol:Mn,ZodUndefined:$t,ZodNull:Kt,ZodAny:Lt,ZodUnknown:pt,ZodNever:He,ZodVoid:Ln,ZodArray:ze,ZodObject:re,ZodUnion:Yt,ZodDiscriminatedUnion:Tn,ZodIntersection:Ht,ZodTuple:Ve,ZodRecord:qt,ZodMap:Dn,ZodSet:_t,ZodFunction:Dt,ZodLazy:Jt,ZodLiteral:Qt,ZodEnum:lt,ZodNativeEnum:en,ZodPromise:Ct,ZodEffects:Ue,ZodTransformer:Ue,ZodOptional:Ge,ZodNullable:dt,ZodDefault:tn,ZodCatch:nn,ZodNaN:Cn,BRAND:mo,ZodBranded:as,ZodPipeline:sn,ZodReadonly:rn,custom:fi,Schema:K,ZodSchema:K,late:po,get ZodFirstPartyTypeKind(){return V},coerce:{string:r=>Re.create({...r,coerce:!0}),number:r=>at.create({...r,coerce:!0}),boolean:r=>Xt.create({...r,coerce:!0}),bigint:r=>ct.create({...r,coerce:!0}),date:r=>mt.create({...r,coerce:!0})},any:So,array:To,bigint:yo,boolean:_i,date:vo,discriminatedUnion:Io,effect:gi,enum:jo,function:zo,instanceof:_o,intersection:ko,lazy:Uo,literal:Fo,map:Po,nan:go,nativeEnum:Bo,never:Mo,null:wo,nullable:Zo,number:pi,object:Do,oboolean:()=>_i().optional(),onumber:()=>pi().optional(),optional:Go,ostring:()=>mi().optional(),pipeline:Xo,preprocess:Wo,promise:Vo,record:Eo,set:Ro,strictObject:Co,string:mi,symbol:xo,transformer:gi,tuple:No,undefined:bo,union:Oo,unknown:Ao,void:Lo,NEVER:G,ZodIssueCode:M,quotelessJson:Gr,ZodError:Ie});const $o=w.object({latitude:w.number().min(-90).max(90),longitude:w.number().min(-180).max(180),datetime:w.string().refine(r=>!Number.isNaN(Date.parse(r)),{message:"Invalid ISO datetime"})}),Ko=w.object({cascades:w.number().int().min(1).max(4).default(3),shadow_map_size:w.number().default(2048),max_far:w.number().min(0).default(0),shadow_bias:w.number().default(.001),shadow_normal_bias:w.number().default(.1)}),Yo=w.object({color:w.number().default(16711680),intensity:w.number().default(1),position:w.tuple([w.number(),w.number(),w.number()]).default([10,10,10]),shadow:w.boolean().default(!0),solar:$o.optional(),csm:Ko.optional()}),Ho=w.object({type:w.enum(["sky","hdr","ultra","room","none"]).default("none"),url:w.string().optional(),sun:Yo.optional(),transparent:w.boolean().default(!1)}),qo=w.object({url:w.string(),color:w.number().optional(),shadow:w.boolean().default(!1),visible:w.boolean().default(!0).optional(),position:w.tuple([w.number(),w.number(),w.number()]).optional(),rotation:w.tuple([w.number(),w.number(),w.number()]).optional(),scale:w.union([w.number(),w.tuple([w.number(),w.number(),w.number()])]).default(1).optional(),conditional_edges:w.object({color:w.number().optional(),line_width:w.number().optional(),threshold_angle:w.number().optional()}).optional(),threshold_edges:w.object({color:w.number().optional(),line_width:w.number().optional(),threshold_angle:w.number().optional()}).optional(),frame_object:w.object({fit_offset:w.number().optional(),height_offset:w.number().optional()}).optional()}),On=w.object({environment:Ho.default({type:"none"}),models:w.array(qo).default([])});let yi="info";const vi={silent:0,error:1,warn:2,info:3,debug:4};function In(r){return vi[r]<=vi[yi]&&yi!=="silent"}const B={error:(...r)=>In("error")&&console.error("[glimmer]",...r),warn:(...r)=>In("warn")&&console.warn("[glimmer]",...r),info:(...r)=>In("info")&&console.log("[glimmer]",...r),debug:(...r)=>In("debug")&&console.log("[glimmer:debug]",...r)},$e=class $e extends EventTarget{constructor(t){super();g(this,"settings");try{const n=On.parse({}),s={...n,...t,environment:{...n.environment,...t.environment||{}},models:t.models||n.models};this.settings=On.parse(s),B.info("Settings initialized:",this.settings)}catch(n){throw B.error("Error initializing settings:",n),n}}static use(t={}){return $e.instance?$e.instance.update(t):$e.instance=new $e(t),$e.instance}static reset(){$e.instance&&($e.instance=void 0)}get(t){return this.settings[t]}update(t){const n=On.parse({...this.settings,...t,environment:{...this.settings.environment,...t.environment||{}},models:t.models!==void 0?t.models:this.settings.models});this.settings=n,B.info("Settings updated:",this.settings);const s=new CustomEvent("update",{detail:this.settings});this.dispatchEvent(s)}export(){return JSON.stringify(this.settings,null,2)}import(t){try{const n=JSON.parse(t);this.update(n)}catch(n){B.error("Failed to import settings:",n)}}async load_from_url(t){try{const n=await fetch(t);if(!n.ok)throw new Error(`Failed to fetch JSON from URL: ${n.statusText}`);const s=await n.json();this.update(s),B.info("Settings loaded successfully from URL:",t)}catch(n){B.error("Error loading settings from URL:",n)}}};g($e,"instance");let kn=$e;const xi={type:"change"},cs={type:"start"},bi={type:"end"},Nn=new h.Ray,wi=new h.Plane,Jo=Math.cos(70*h.MathUtils.DEG2RAD),le=new h.Vector3,Le=2*Math.PI,ne={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},ls=1e-6;class Qo extends h.Controls{constructor(e,t=null){super(e,t),this.state=ne.NONE,this.target=new h.Vector3,this.cursor=new h.Vector3,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:h.MOUSE.ROTATE,MIDDLE:h.MOUSE.DOLLY,RIGHT:h.MOUSE.PAN},this.touches={ONE:h.TOUCH.ROTATE,TWO:h.TOUCH.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this._lastPosition=new h.Vector3,this._lastQuaternion=new h.Quaternion,this._lastTargetPosition=new h.Vector3,this._quat=new h.Quaternion().setFromUnitVectors(e.up,new h.Vector3(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new h.Spherical,this._sphericalDelta=new h.Spherical,this._scale=1,this._panOffset=new h.Vector3,this._rotateStart=new h.Vector2,this._rotateEnd=new h.Vector2,this._rotateDelta=new h.Vector2,this._panStart=new h.Vector2,this._panEnd=new h.Vector2,this._panDelta=new h.Vector2,this._dollyStart=new h.Vector2,this._dollyEnd=new h.Vector2,this._dollyDelta=new h.Vector2,this._dollyDirection=new h.Vector3,this._mouse=new h.Vector2,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=ta.bind(this),this._onPointerDown=ea.bind(this),this._onPointerUp=na.bind(this),this._onContextMenu=la.bind(this),this._onMouseWheel=ra.bind(this),this._onKeyDown=oa.bind(this),this._onTouchStart=aa.bind(this),this._onTouchMove=ca.bind(this),this._onMouseDown=sa.bind(this),this._onMouseMove=ia.bind(this),this._interceptControlDown=da.bind(this),this._interceptControlUp=ha.bind(this),this.domElement!==null&&this.connect(this.domElement),this.update()}connect(e){super.connect(e),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerUp),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1}),this.domElement.getRootNode().addEventListener("keydown",this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerUp),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.stopListenToKeyEvents(),this.domElement.getRootNode().removeEventListener("keydown",this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction="auto"}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(e){e.addEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=e}stopListenToKeyEvents(){this._domElementKeyEvents!==null&&(this._domElementKeyEvents.removeEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(xi),this.update(),this.state=ne.NONE}update(e=null){const t=this.object.position;le.copy(t).sub(this.target),le.applyQuaternion(this._quat),this._spherical.setFromVector3(le),this.autoRotate&&this.state===ne.NONE&&this._rotateLeft(this._getAutoRotationAngle(e)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let n=this.minAzimuthAngle,s=this.maxAzimuthAngle;isFinite(n)&&isFinite(s)&&(n<-Math.PI?n+=Le:n>Math.PI&&(n-=Le),s<-Math.PI?s+=Le:s>Math.PI&&(s-=Le),n<=s?this._spherical.theta=Math.max(n,Math.min(s,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(n+s)/2?Math.max(n,this._spherical.theta):Math.min(s,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let i=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const o=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),i=o!=this._spherical.radius}if(le.setFromSpherical(this._spherical),le.applyQuaternion(this._quatInverse),t.copy(this.target).add(le),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let o=null;if(this.object.isPerspectiveCamera){const a=le.length();o=this._clampDistance(a*this._scale);const c=a-o;this.object.position.addScaledVector(this._dollyDirection,c),this.object.updateMatrixWorld(),i=!!c}else if(this.object.isOrthographicCamera){const a=new h.Vector3(this._mouse.x,this._mouse.y,0);a.unproject(this.object);const c=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),i=c!==this.object.zoom;const l=new h.Vector3(this._mouse.x,this._mouse.y,0);l.unproject(this.object),this.object.position.sub(l).add(a),this.object.updateMatrixWorld(),o=le.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;o!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(o).add(this.object.position):(Nn.origin.copy(this.object.position),Nn.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(Nn.direction))<Jo?this.object.lookAt(this.target):(wi.setFromNormalAndCoplanarPoint(this.object.up,this.target),Nn.intersectPlane(wi,this.target))))}else if(this.object.isOrthographicCamera){const o=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),o!==this.object.zoom&&(this.object.updateProjectionMatrix(),i=!0)}return this._scale=1,this._performCursorZoom=!1,i||this._lastPosition.distanceToSquared(this.object.position)>ls||8*(1-this._lastQuaternion.dot(this.object.quaternion))>ls||this._lastTargetPosition.distanceToSquared(this.target)>ls?(this.dispatchEvent(xi),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(e){return e!==null?Le/60*this.autoRotateSpeed*e:Le/60/60*this.autoRotateSpeed}_getZoomScale(e){const t=Math.abs(e*.01);return Math.pow(.95,this.zoomSpeed*t)}_rotateLeft(e){this._sphericalDelta.theta-=e}_rotateUp(e){this._sphericalDelta.phi-=e}_panLeft(e,t){le.setFromMatrixColumn(t,0),le.multiplyScalar(-e),this._panOffset.add(le)}_panUp(e,t){this.screenSpacePanning===!0?le.setFromMatrixColumn(t,1):(le.setFromMatrixColumn(t,0),le.crossVectors(this.object.up,le)),le.multiplyScalar(e),this._panOffset.add(le)}_pan(e,t){const n=this.domElement;if(this.object.isPerspectiveCamera){const s=this.object.position;le.copy(s).sub(this.target);let i=le.length();i*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*e*i/n.clientHeight,this.object.matrix),this._panUp(2*t*i/n.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(e*(this.object.right-this.object.left)/this.object.zoom/n.clientWidth,this.object.matrix),this._panUp(t*(this.object.top-this.object.bottom)/this.object.zoom/n.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(e,t){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const n=this.domElement.getBoundingClientRect(),s=e-n.left,i=t-n.top,o=n.width,a=n.height;this._mouse.x=s/o*2-1,this._mouse.y=-(i/a)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(e){return Math.max(this.minDistance,Math.min(this.maxDistance,e))}_handleMouseDownRotate(e){this._rotateStart.set(e.clientX,e.clientY)}_handleMouseDownDolly(e){this._updateZoomParameters(e.clientX,e.clientX),this._dollyStart.set(e.clientX,e.clientY)}_handleMouseDownPan(e){this._panStart.set(e.clientX,e.clientY)}_handleMouseMoveRotate(e){this._rotateEnd.set(e.clientX,e.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(Le*this._rotateDelta.x/t.clientHeight),this._rotateUp(Le*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(e){this._dollyEnd.set(e.clientX,e.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(e){this._panEnd.set(e.clientX,e.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(e){this._updateZoomParameters(e.clientX,e.clientY),e.deltaY<0?this._dollyIn(this._getZoomScale(e.deltaY)):e.deltaY>0&&this._dollyOut(this._getZoomScale(e.deltaY)),this.update()}_handleKeyDown(e){let t=!1;switch(e.code){case this.keys.UP:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(Le*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),t=!0;break;case this.keys.BOTTOM:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(-Le*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),t=!0;break;case this.keys.LEFT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(Le*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),t=!0;break;case this.keys.RIGHT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(-Le*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),t=!0;break}t&&(e.preventDefault(),this.update())}_handleTouchStartRotate(e){if(this._pointers.length===1)this._rotateStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),s=.5*(e.pageY+t.y);this._rotateStart.set(n,s)}}_handleTouchStartPan(e){if(this._pointers.length===1)this._panStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),s=.5*(e.pageY+t.y);this._panStart.set(n,s)}}_handleTouchStartDolly(e){const t=this._getSecondPointerPosition(e),n=e.pageX-t.x,s=e.pageY-t.y,i=Math.sqrt(n*n+s*s);this._dollyStart.set(0,i)}_handleTouchStartDollyPan(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enablePan&&this._handleTouchStartPan(e)}_handleTouchStartDollyRotate(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enableRotate&&this._handleTouchStartRotate(e)}_handleTouchMoveRotate(e){if(this._pointers.length==1)this._rotateEnd.set(e.pageX,e.pageY);else{const n=this._getSecondPointerPosition(e),s=.5*(e.pageX+n.x),i=.5*(e.pageY+n.y);this._rotateEnd.set(s,i)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(Le*this._rotateDelta.x/t.clientHeight),this._rotateUp(Le*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(e){if(this._pointers.length===1)this._panEnd.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),s=.5*(e.pageY+t.y);this._panEnd.set(n,s)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(e){const t=this._getSecondPointerPosition(e),n=e.pageX-t.x,s=e.pageY-t.y,i=Math.sqrt(n*n+s*s);this._dollyEnd.set(0,i),this._dollyDelta.set(0,Math.pow(this._dollyEnd.y/this._dollyStart.y,this.zoomSpeed)),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);const o=(e.pageX+t.x)*.5,a=(e.pageY+t.y)*.5;this._updateZoomParameters(o,a)}_handleTouchMoveDollyPan(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enablePan&&this._handleTouchMovePan(e)}_handleTouchMoveDollyRotate(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enableRotate&&this._handleTouchMoveRotate(e)}_addPointer(e){this._pointers.push(e.pointerId)}_removePointer(e){delete this._pointerPositions[e.pointerId];for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId){this._pointers.splice(t,1);return}}_isTrackingPointer(e){for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId)return!0;return!1}_trackPointer(e){let t=this._pointerPositions[e.pointerId];t===void 0&&(t=new h.Vector2,this._pointerPositions[e.pointerId]=t),t.set(e.pageX,e.pageY)}_getSecondPointerPosition(e){const t=e.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[t]}_customWheelEvent(e){const t=e.deltaMode,n={clientX:e.clientX,clientY:e.clientY,deltaY:e.deltaY};switch(t){case 1:n.deltaY*=16;break;case 2:n.deltaY*=100;break}return e.ctrlKey&&!this._controlActive&&(n.deltaY*=10),n}}function ea(r){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(r.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.domElement.addEventListener("pointerup",this._onPointerUp)),!this._isTrackingPointer(r)&&(this._addPointer(r),r.pointerType==="touch"?this._onTouchStart(r):this._onMouseDown(r)))}function ta(r){this.enabled!==!1&&(r.pointerType==="touch"?this._onTouchMove(r):this._onMouseMove(r))}function na(r){switch(this._removePointer(r),this._pointers.length){case 0:this.domElement.releasePointerCapture(r.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.dispatchEvent(bi),this.state=ne.NONE;break;case 1:const e=this._pointers[0],t=this._pointerPositions[e];this._onTouchStart({pointerId:e,pageX:t.x,pageY:t.y});break}}function sa(r){let e;switch(r.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case h.MOUSE.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(r),this.state=ne.DOLLY;break;case h.MOUSE.ROTATE:if(r.ctrlKey||r.metaKey||r.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(r),this.state=ne.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(r),this.state=ne.ROTATE}break;case h.MOUSE.PAN:if(r.ctrlKey||r.metaKey||r.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(r),this.state=ne.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(r),this.state=ne.PAN}break;default:this.state=ne.NONE}this.state!==ne.NONE&&this.dispatchEvent(cs)}function ia(r){switch(this.state){case ne.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(r);break;case ne.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(r);break;case ne.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(r);break}}function ra(r){this.enabled===!1||this.enableZoom===!1||this.state!==ne.NONE||(r.preventDefault(),this.dispatchEvent(cs),this._handleMouseWheel(this._customWheelEvent(r)),this.dispatchEvent(bi))}function oa(r){this.enabled!==!1&&this._handleKeyDown(r)}function aa(r){switch(this._trackPointer(r),this._pointers.length){case 1:switch(this.touches.ONE){case h.TOUCH.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(r),this.state=ne.TOUCH_ROTATE;break;case h.TOUCH.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(r),this.state=ne.TOUCH_PAN;break;default:this.state=ne.NONE}break;case 2:switch(this.touches.TWO){case h.TOUCH.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(r),this.state=ne.TOUCH_DOLLY_PAN;break;case h.TOUCH.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(r),this.state=ne.TOUCH_DOLLY_ROTATE;break;default:this.state=ne.NONE}break;default:this.state=ne.NONE}this.state!==ne.NONE&&this.dispatchEvent(cs)}function ca(r){switch(this._trackPointer(r),this.state){case ne.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(r),this.update();break;case ne.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(r),this.update();break;case ne.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(r),this.update();break;case ne.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(r),this.update();break;default:this.state=ne.NONE}}function la(r){this.enabled!==!1&&r.preventDefault()}function da(r){r.key==="Control"&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function ha(r){r.key==="Control"&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}class ua{constructor(e){g(this,"group");g(this,"sphere");g(this,"arrow");g(this,"scene");g(this,"is_enabled",!1);g(this,"SPHERE_RADIUS",.1);g(this,"ARROW_LENGTH",.5);g(this,"ARROW_HEAD_LENGTH",.15);g(this,"ARROW_HEAD_WIDTH",.1);this.scene=e,this.group=new _.Group,this.group.name="cursor_3d",this.group.visible=!1;const t=new _.SphereGeometry(this.SPHERE_RADIUS,16,16),n=new _.MeshBasicMaterial({color:65280,transparent:!0,opacity:.7,depthTest:!1});this.sphere=new _.Mesh(t,n),this.group.add(this.sphere),this.arrow=new _.ArrowHelper(new _.Vector3(0,1,0),new _.Vector3(0,0,0),this.ARROW_LENGTH,65280,this.ARROW_HEAD_LENGTH,this.ARROW_HEAD_WIDTH),this.group.add(this.arrow),this.scene.add(this.group)}enable(){this.is_enabled=!0,this.group.visible=!0}disable(){this.is_enabled=!1,this.group.visible=!1}get enabled(){return this.is_enabled}update(e){if(!e||!this.is_enabled){this.group.visible=!1;return}if(this.group.visible=!0,this.sphere.position.copy(e.point),this.arrow.position.copy(e.point),e.face&&e.face.normal){const t=e.face.normal.clone(),n=e.object;n.matrixWorld&&t.transformDirection(n.matrixWorld),this.arrow.setDirection(t)}}set_color(e){this.sphere.material.color.setHex(e),this.arrow.setColor(e)}dispose(){this.scene.remove(this.group),this.sphere.geometry.dispose(),this.sphere.material.dispose(),this.arrow.dispose()}}class fa extends EventTarget{constructor(t,n,s,i){super();g(this,"camera");g(this,"controls");g(this,"renderer");g(this,"scene");g(this,"_orbit_animation_id");g(this,"_orbit_restart_timeout_id");g(this,"_orbit_duration_seconds",45);g(this,"_orbit_clockwise",!0);g(this,"_auto_restart_enabled",!0);this.camera=t,this.controls=n,this.renderer=s,this.scene=i}start_animation(t,n,s=1){t||(t=30),this._orbit_duration_seconds=t,n===void 0&&(n=!0),this._orbit_clockwise=n,this.stop_animation();const i=t??this._orbit_duration_seconds,o=n??this._orbit_clockwise,a=this.camera.position.clone(),c=this.controls.target.clone(),l=c.clone();l.y=a.y;const d=a.distanceTo(l),u=Math.PI*2,f=performance.now(),m=a.x-l.x,y=a.z-l.z,v=Math.atan2(y,m),b=A=>1-Math.cos(A*Math.PI/2),S=A=>{const L=(A-f)/1e3;let x=0;L<s?x=b(L/s)*s:x=L-s+b(1)*s;const z=x%i/i,Z=v+(o?-1:1)*z*u,j=l.x+Math.cos(Z)*d,O=l.z+Math.sin(Z)*d,D=new _.Vector3(j,a.y,O);this.camera.position.copy(D),this.camera.lookAt(c),this.controls.target.copy(c),this.renderer.render(this.scene,this.camera),this._orbit_animation_id=requestAnimationFrame(S)};this._orbit_animation_id=requestAnimationFrame(S)}stop_animation(){this._orbit_animation_id&&(cancelAnimationFrame(this._orbit_animation_id),this._orbit_animation_id=void 0)}schedule_restart(t=5e3){this._auto_restart_enabled&&(this._orbit_restart_timeout_id&&clearTimeout(this._orbit_restart_timeout_id),this._orbit_restart_timeout_id=window.setTimeout(()=>{this.start_animation(this._orbit_duration_seconds,this._orbit_clockwise)},t))}set_auto_restart(t){this._auto_restart_enabled=t,!t&&this._orbit_restart_timeout_id&&(clearTimeout(this._orbit_restart_timeout_id),this._orbit_restart_timeout_id=void 0)}setup_user_override(){this.controls.addEventListener("start",()=>{this.stop_animation(),this._orbit_restart_timeout_id&&(clearTimeout(this._orbit_restart_timeout_id),this._orbit_restart_timeout_id=void 0),this.dispatchEvent(new CustomEvent("orbitstart",{detail:{}}))}),this.controls.addEventListener("end",()=>{this._auto_restart_enabled&&this.schedule_restart(),this.dispatchEvent(new CustomEvent("orbitstop",{detail:{}}))})}dispose(){this.stop_animation(),this._orbit_restart_timeout_id&&(clearTimeout(this._orbit_restart_timeout_id),this._orbit_restart_timeout_id=void 0)}}class ma{constructor(e,t,n){g(this,"raycaster");g(this,"camera");g(this,"canvas");g(this,"default_targets");this.raycaster=new _.Raycaster,this.camera=e,this.canvas=t,this.default_targets=n}raycast_from_event(e,t,n=!0){const s=this.canvas.getBoundingClientRect(),i=new _.Vector2;i.x=(e.clientX-s.left)/s.width*2-1,i.y=-((e.clientY-s.top)/s.height)*2+1,this.raycaster.setFromCamera(i,this.camera);const o=t??this.default_targets,a=this.raycaster.intersectObjects(o,!0);if(n){const c=a.filter(l=>l.object.isMesh);return c.length>0?c[0]:null}return a.length>0?a[0]:null}get_raycaster(){return this.raycaster}}class Si extends EventTarget{constructor(t,n){super();g(this,"settings");g(this,"scene");g(this,"camera");g(this,"renderer");g(this,"controls");g(this,"container");g(this,"orbit_controller");g(this,"raycast_helper");g(this,"_resize_handler",()=>this.onWindowResize());g(this,"clock",new _.Clock);g(this,"animation_callbacks",new Set);g(this,"animation_mixers",new Set);g(this,"cursor_3d");g(this,"_cursor_3d_mouse_handler");g(this,"_resolution_materials",new Set);g(this,"animate",()=>{requestAnimationFrame(this.animate);const t=this.clock.getDelta();this.update_animation_mixers(t),this.execute_animation_callbacks(t);for(const n of this._resolution_materials)try{if(n.resolution)this.renderer.getSize(n.resolution),n.resolution.multiplyScalar(window.devicePixelRatio);else if(n.uniforms&&n.uniforms.resolution&&n.uniforms.resolution.value){const s=n.uniforms.resolution.value;this.renderer.getSize(s),s.multiplyScalar(window.devicePixelRatio)}}catch{this._resolution_materials.delete(n)}this.controls.update(),this.renderer.render(this.scene,this.camera)});this.scene=new _.Scene,this.settings=n,this.container=t,this.renderer=new _.WebGLRenderer({antialias:!0}),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.toneMapping=_.ACESFilmicToneMapping,this.renderer.outputColorSpace=_.SRGBColorSpace,this.container.appendChild(this.renderer.domElement);const s=t.clientWidth/t.clientHeight;this.camera=new _.PerspectiveCamera(75,s,.1,1e3),this.camera.position.set(0,2,5),this.controls=new Qo(this.camera,this.renderer.domElement),this.controls.enableDamping=!1,this.orbit_controller=new fa(this.camera,this.controls,this.renderer,this.scene),this.raycast_helper=new ma(this.camera,this.renderer.domElement,this.scene.children),this._setup_orbit_animation_user_override(),window.addEventListener("resize",this._resize_handler),this.animate(),B.info("Viewer: Initializing...")}register_animation_mixer(t){this.animation_mixers.add(t)}unregister_animation_mixer(t){this.animation_mixers.delete(t)}update_animation_mixers(t){for(const n of this.animation_mixers)n.update(t)}register_animation_callback(t){this.animation_callbacks.add(t)}unregister_animation_callback(t){this.animation_callbacks.delete(t)}execute_animation_callbacks(t){for(const n of this.animation_callbacks)n(t)}onWindowResize(){const t=this.container.clientWidth,n=this.container.clientHeight;this.camera.aspect=t/n,this.camera.updateProjectionMatrix(),this.renderer.setSize(t,n),this.dispatchEvent(new CustomEvent("resize",{detail:{width:t,height:n}}))}register_resolution_material(t){t&&(t.resolution||t.uniforms&&t.uniforms.resolution)&&this._resolution_materials.add(t)}unregister_resolution_material(t){this._resolution_materials.delete(t)}frame_object(t,n=.2,s=1){n=n+1;const i=new _.Box3().setFromObject(t),o=i.getSize(new _.Vector3),a=i.getCenter(new _.Vector3);this.controls.target.copy(a),this.controls.update();const l=Math.max(o.x,o.y,o.z)/(2*Math.atan(Math.PI*this.camera.fov/360)),d=l/this.camera.aspect,u=n*Math.max(l,d),f=this.camera.position.clone().sub(this.controls.target).normalize();this.camera.position.copy(a).add(f.multiplyScalar(u)),this.camera.position.y=a.y+s,this.camera.near=u/100,this.camera.far=u*100,this.camera.updateProjectionMatrix(),this.renderer.render(this.scene,this.camera)}start_camera_orbit_animation(t,n,s=1){this.orbit_controller.start_animation(t,n,s)}stop_camera_orbit_animation(){this.orbit_controller.stop_animation()}set_auto_orbit(t){this.orbit_controller.set_auto_restart(t)}schedule_camera_orbit_restart(t=5e3){this.orbit_controller.schedule_restart(t)}_setup_orbit_animation_user_override(){this.orbit_controller.setup_user_override(),this.orbit_controller.addEventListener("orbitstart",()=>{this.dispatchEvent(new CustomEvent("orbitstart",{detail:{}}))}),this.orbit_controller.addEventListener("orbitstop",()=>{this.dispatchEvent(new CustomEvent("orbitstop",{detail:{}}))}),this.controls.addEventListener("change",()=>{this.dispatchEvent(new CustomEvent("camerachange",{detail:{position:this.camera.position.clone(),target:this.controls.target.clone()}}))})}raycast_from_event(t,n){return this.raycast_helper.raycast_from_event(t,n,!0)}enable_3d_cursor(t){this.cursor_3d||(this.cursor_3d=new ua(this.scene)),this.cursor_3d.enable(),this._cursor_3d_mouse_handler=n=>{var i;const s=this.raycast_from_event(n,t);(i=this.cursor_3d)==null||i.update(s)},this.renderer.domElement.addEventListener("mousemove",this._cursor_3d_mouse_handler)}disable_3d_cursor(){this.cursor_3d&&this.cursor_3d.disable(),this._cursor_3d_mouse_handler&&(this.renderer.domElement.removeEventListener("mousemove",this._cursor_3d_mouse_handler),this._cursor_3d_mouse_handler=void 0)}update_3d_cursor(t,n){var i;if(!((i=this.cursor_3d)!=null&&i.enabled))return;const s=this.raycast_from_event(t,n);this.cursor_3d.update(s)}get_3d_cursor(){return this.cursor_3d}dispose(){this.orbit_controller.dispose(),this.disable_3d_cursor(),this.cursor_3d&&(this.cursor_3d.dispose(),this.cursor_3d=void 0),window.removeEventListener("resize",this._resize_handler),this.animation_mixers.clear(),this.animation_callbacks.clear(),this.renderer.dispose(),this.renderer.domElement&&this.renderer.domElement.parentElement&&this.renderer.domElement.parentElement.removeChild(this.renderer.domElement),this._resolution_materials.clear()}}class pa extends h.DataTextureLoader{constructor(e){super(e),this.type=h.HalfFloatType}parse(e){const o=function(O,D){switch(O){case 1:throw new Error("THREE.RGBELoader: Read Error: "+(D||""));case 2:throw new Error("THREE.RGBELoader: Write Error: "+(D||""));case 3:throw new Error("THREE.RGBELoader: Bad File Format: "+(D||""));default:case 4:throw new Error("THREE.RGBELoader: Memory Error: "+(D||""))}},d=`
2
2
  `,u=function(O,D,k){D=D||1024;let W=O.pos,$=-1,N=0,ee="",Y=String.fromCharCode.apply(null,new Uint16Array(O.subarray(W,W+128)));for(;0>($=Y.indexOf(d))&&N<D&&W<O.byteLength;)ee+=Y,N+=Y.length,W+=128,Y+=String.fromCharCode.apply(null,new Uint16Array(O.subarray(W,W+128)));return-1<$?(O.pos+=N+$+1,ee+Y.slice(0,$)):!1},f=function(O){const D=/^#\?(\S+)/,k=/^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,R=/^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,W=/^\s*FORMAT=(\S+)\s*$/,$=/^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,N={valid:0,string:"",comments:"",programtype:"RGBE",format:"",gamma:1,exposure:1,width:0,height:0};let ee,Y;for((O.pos>=O.byteLength||!(ee=u(O)))&&o(1,"no header found"),(Y=ee.match(D))||o(3,"bad initial token"),N.valid|=1,N.programtype=Y[1],N.string+=ee+`
3
3
  `;ee=u(O),ee!==!1;){if(N.string+=ee+`
4
4
  `,ee.charAt(0)==="#"){N.comments+=ee+`
@@ -443,7 +443,7 @@ uniform vec2 CSM_cascades[CSM_CASCADES];
443
443
  uniform float cameraNear;
444
444
  uniform float shadowFar;
445
445
  #endif
446
- `+h.ShaderChunk.lights_pars_begin},Li=new h.Matrix4,hs=new Pn({webGL:!0}),Je=new h.Vector3,an=new h.Box3,us=[],fs=[],ms=new h.Matrix4,Ti=new h.Matrix4,va=new h.Vector3(0,1,0);class xa{constructor(e){this.camera=e.camera,this.parent=e.parent,this.cascades=e.cascades||3,this.maxFar=e.maxFar||1e5,this.mode=e.mode||"practical",this.shadowMapSize=e.shadowMapSize||2048,this.shadowBias=e.shadowBias||1e-6,this.lightDirection=e.lightDirection||new h.Vector3(1,-1,1).normalize(),this.lightIntensity=e.lightIntensity||3,this.lightNear=e.lightNear||1,this.lightFar=e.lightFar||2e3,this.lightMargin=e.lightMargin||200,this.customSplitsCallback=e.customSplitsCallback,this.fade=!1,this.mainFrustum=new Pn({webGL:!0}),this.frustums=[],this.breaks=[],this.lights=[],this.shaders=new Map,this._createLights(),this.updateFrustums(),this._injectInclude()}_createLights(){for(let e=0;e<this.cascades;e++){const t=new h.DirectionalLight(16777215,this.lightIntensity);t.castShadow=!0,t.shadow.mapSize.width=this.shadowMapSize,t.shadow.mapSize.height=this.shadowMapSize,t.shadow.camera.near=this.lightNear,t.shadow.camera.far=this.lightFar,t.shadow.bias=this.shadowBias,this.parent.add(t),this.parent.add(t.target),this.lights.push(t)}}_initCascades(){const e=this.camera;e.updateProjectionMatrix(),this.mainFrustum.setFromProjectionMatrix(e.projectionMatrix,this.maxFar),this.mainFrustum.split(this.breaks,this.frustums)}_updateShadowBounds(){const e=this.frustums;for(let t=0;t<e.length;t++){const s=this.lights[t].shadow.camera,i=this.frustums[t],o=i.vertices.near,a=i.vertices.far,c=a[0];let l;c.distanceTo(a[2])>c.distanceTo(o[2])?l=a[2]:l=o[2];let d=c.distanceTo(l);if(this.fade){const u=this.camera,f=Math.max(u.far,this.maxFar),m=i.vertices.far[0].z/(f-u.near),y=.25*Math.pow(m,2)*(f-u.near);d+=y}s.left=-d/2,s.right=d/2,s.top=d/2,s.bottom=-d/2,s.updateProjectionMatrix()}}_getBreaks(){const e=this.camera,t=Math.min(e.far,this.maxFar);switch(this.breaks.length=0,this.mode){case"uniform":n(this.cascades,e.near,t,this.breaks);break;case"logarithmic":s(this.cascades,e.near,t,this.breaks);break;case"practical":i(this.cascades,e.near,t,.5,this.breaks);break;case"custom":this.customSplitsCallback===void 0&&console.error("CSM: Custom split scheme callback not defined."),this.customSplitsCallback(this.cascades,e.near,t,this.breaks);break}function n(o,a,c,l){for(let d=1;d<o;d++)l.push((a+(c-a)*d/o)/c);l.push(1)}function s(o,a,c,l){for(let d=1;d<o;d++)l.push(a*(c/a)**(d/o)/c);l.push(1)}function i(o,a,c,l,d){us.length=0,fs.length=0,s(o,a,c,fs),n(o,a,c,us);for(let u=1;u<o;u++)d.push(h.MathUtils.lerp(us[u-1],fs[u-1],l));d.push(1)}}update(){const e=this.camera,t=this.frustums;ms.lookAt(new h.Vector3,this.lightDirection,va),Ti.copy(ms).invert();for(let n=0;n<t.length;n++){const s=this.lights[n],i=s.shadow.camera,o=(i.right-i.left)/this.shadowMapSize,a=(i.top-i.bottom)/this.shadowMapSize;Li.multiplyMatrices(Ti,e.matrixWorld),t[n].toSpace(Li,hs);const c=hs.vertices.near,l=hs.vertices.far;an.makeEmpty();for(let d=0;d<4;d++)an.expandByPoint(c[d]),an.expandByPoint(l[d]);an.getCenter(Je),Je.z=an.max.z+this.lightMargin,Je.x=Math.floor(Je.x/o)*o,Je.y=Math.floor(Je.y/a)*a,Je.applyMatrix4(ms),s.position.copy(Je),s.target.position.copy(Je),s.target.position.x+=this.lightDirection.x,s.target.position.y+=this.lightDirection.y,s.target.position.z+=this.lightDirection.z}}_injectInclude(){h.ShaderChunk.lights_fragment_begin=Mi.lights_fragment_begin,h.ShaderChunk.lights_pars_begin=Mi.lights_pars_begin}setupMaterial(e){e.defines=e.defines||{},e.defines.USE_CSM=1,e.defines.CSM_CASCADES=this.cascades,this.fade&&(e.defines.CSM_FADE="");const t=[],n=this,s=this.shaders;e.onBeforeCompile=function(i){const o=Math.min(n.camera.far,n.maxFar);n._getExtendedBreaks(t),i.uniforms.CSM_cascades={value:t},i.uniforms.cameraNear={value:n.camera.near},i.uniforms.shadowFar={value:o},s.set(e,i)},s.set(e,null)}_updateUniforms(){const e=Math.min(this.camera.far,this.maxFar);this.shaders.forEach(function(n,s){if(n!==null){const i=n.uniforms;this._getExtendedBreaks(i.CSM_cascades.value),i.cameraNear.value=this.camera.near,i.shadowFar.value=e}!this.fade&&"CSM_FADE"in s.defines?(delete s.defines.CSM_FADE,s.needsUpdate=!0):this.fade&&!("CSM_FADE"in s.defines)&&(s.defines.CSM_FADE="",s.needsUpdate=!0)},this)}_getExtendedBreaks(e){for(;e.length<this.breaks.length;)e.push(new h.Vector2);e.length=this.breaks.length;for(let t=0;t<this.cascades;t++){const n=this.breaks[t],s=this.breaks[t-1]||0;e[t].x=s,e[t].y=n}}updateFrustums(){this._getBreaks(),this._initCascades(),this._updateShadowBounds(),this._updateUniforms()}remove(){for(let e=0;e<this.lights.length;e++)this.parent.remove(this.lights[e].target),this.parent.remove(this.lights[e])}dispose(){const e=this.shaders;e.forEach(function(t,n){delete n.onBeforeCompile,delete n.defines.USE_CSM,delete n.defines.CSM_CASCADES,delete n.defines.CSM_FADE,t!==null&&(delete t.uniforms.CSM_cascades,delete t.uniforms.cameraNear,delete t.uniforms.shadowFar),n.needsUpdate=!0}),e.clear()}}function Di(r){const t=new _.Box3().setFromObject(r).getSize(new _.Vector3);return Math.max(10,Math.max(t.x,t.y,t.z))}const ba=512,wa=100,Sa=30,Aa=-.001,Ma=3,La=16,{PI:Ta,sin:Qe,cos:et,tan:Ci,asin:Oi,atan2:Ii}=Math,Ne=Ta/180,Da=1e3*60*60*24,Ca=2440588,Oa=2451545;function Ia(r){return r.valueOf()/Da-.5+Ca-Oa}function ka(r){const e=2e3+r/365.2425;let t;return e<1920?(t=e-1900,-2.79+t*(1.494119+t*(-.0598939+t*(.0061966-t*197e-6)))):e<1941?(t=e-1920,21.2+t*(.84493+t*(-.0761+t*.0020936))):e<1961?(t=e-1950,29.07+t*(.407+t*(-1/233+t/2547))):e<1986?(t=e-1975,45.45+t*(1.067+t*(-1/260-t/718))):e<2005?(t=e-2e3,63.86+t*(.3345+t*(-.060374+t*(.0017275+t*(651814e-9+t*2373599e-11))))):e<2050?(t=e-2e3,62.92+t*(.32217+t*.005589)):(t=(e-1820)/100,-20+32*t*t-.5628*(2150-e))}function Na(r){return r+ka(r)/86400}function Ea(r,e,t){return(Ii(Qe(r),et(r)*Qe(e)-Ci(t)*et(e))/Ne+540)%360}function Pa(r,e,t){return Oi(Qe(e)*Qe(t)+et(e)*et(t)*et(r))}function Ra(r,e){return Ne*(280.46061837+360.98564736629*r)-e}function za(r){return r<0&&(r=0),2967e-7/Ci(r+.00312536/(r+.08901179))}function Ua(r){const e=r/36525,t=Ne*(280.46646+e*(36000.76983+e*3032e-7)),n=Ne*(357.52911+e*(35999.05029-e*1537e-7)),s=Qe(n),i=et(n),o=Ne*((1.914602-e*(.004817+e*14e-6))*s+(.019993-101e-6*e)*2*s*i+289e-6*s*(3-4*s*s)),a=Ne*(125.04-1934.136*e),c=t+o-Ne*(.00569+.00478*Qe(a)),l=Ne*(23.439291-e*(.0130042+e*(16e-8-e*504e-9)))+Ne*.00256*et(a);return{ra:Ii(et(l)*Qe(c),et(c)),dec:Oi(Qe(l)*Qe(c)),lon:c}}function Fa(r,e,t){const n=Ne*-t,s=Ne*e,i=Ia(r),o=Ua(Na(i)),a=Ra(i,n)-o.ra,c=Pa(a,s,o.dec);return{azimuth:Ea(a,s,o.dec),altitude:(c+za(c))/Ne}}const ps=Math.PI/180;function ja(r,e,t){const n=Fa(t,r,e),s=n.altitude,i=(n.azimuth%360+360)%360,o=s*ps,a=i*ps,c=new _.Vector3(Math.cos(o)*Math.sin(a),Math.sin(o),-Math.cos(o)*Math.cos(a));return{altitude_deg:s,azimuth_deg:i,direction:c}}const Ba=-6;function Va(r,e,t){const n=new _.Color(t);if(r<=Ba)return{intensity:0,color:new _.Color(0)};const s=Math.max(0,r),i=Math.sin(Math.min(s,90)*ps),o=e*(.12+.88*i),a=1-Math.min(s/30,1),l=new _.Color(16747586).lerp(n,1-a*.85);return{intensity:o,color:l}}class ki{constructor(e,t,n,s){g(this,"viewer");g(this,"scene");g(this,"settings");g(this,"sun_settings");g(this,"model_manager");g(this,"sun",null);g(this,"environment");g(this,"csm",null);g(this,"csm_key",null);g(this,"csm_callback",null);g(this,"models_watched",!1);this.viewer=e,this.scene=e.scene,this.settings=t,this.environment=n,this.model_manager=s,this.sun_settings=this.settings.get("environment").sun,this.settings.addEventListener("update",i=>{const o=i.detail;this.sun_settings=o.environment.sun,this.update()}),this.settings.addEventListener("environmentTextureLoaded",i=>{const o=i.detail.texture;if(this.environment.texture=o,this.sun&&this.sun_settings){const a=this._infer_sun_position_from_env_map();a&&(B.debug("Texture loaded event call; inferred Sun position from env map:",a),this.sun_settings.position=[a.x,a.y,a.z],this.update())}}),this.update()}update(){if(!this.sun_settings){this.sun&&(this.scene.remove(this.sun),this.sun=null);return}this.model_manager.ready.then(()=>{if(!this.sun_settings){this.teardown_csm();return}const e=this.apply_solar();if(!e){const n=this._infer_sun_position_from_env_map();n&&(B.debug("Inferred Sun position from env map:",n),this.sun_settings.position=[n.x,n.y,n.z])}const t=e??{position:this.sun_settings.position,intensity:this.sun_settings.intensity,color:this.sun_settings.color};this.sun_settings.csm?(this.remove_classic_sun(),this.sync_csm(t)):(this.teardown_csm(),this.sun_create(e??void 0)),this.sun_settings&&this.sync_sky(t.position)})}sync_sky(e){e&&this.environment.update_sky_environment(new _.Vector3(e[0],e[1],e[2]))}sun_fit_object(e=this.scene){const t=Di(e);let n=new _.Vector3(0,1,0).normalize();n=n.multiplyScalar(t*2),this.sun&&(n=this.sun.position.clone())}sun_fit_shadow(){const e=new _.Object3D;if(!this.model_manager){B.warn("No model manager found.");return}for(const o of this.model_manager.models.values())o.settings.shadow&&e.add(o.group.clone());e.children.length===0&&B.warn("No models with shadows found to fit shadow map."),B.debug("Models in fit_object:",e);const t=Di(e),n=ba,s=Math.ceil(t/wa),i=Math.min(Math.pow(2,Math.ceil(Math.log2(n*s))),this.viewer.renderer.capabilities.maxTextureSize);if(B.debug("Shadow map size:",i),this.sun){this.sun.shadow.mapSize.width=i,this.sun.shadow.mapSize.height=i;const o=Sa;this.sun.shadow.camera.left=-(t/2+o),this.sun.shadow.camera.right=t/2+o,this.sun.shadow.camera.top=t/2+o,this.sun.shadow.camera.bottom=-(t/2+o),this.sun.shadow.camera.near=.1,this.sun.shadow.camera.far=t*2,this.sun.shadow.bias=Aa,this.sun.shadow.radius=Ma,this.sun.shadow.blurSamples=La,B.info(`Recreated sun with shadow map size: ${i}x${i}`)}}resolve_solar(){const e=this.sun_settings.solar,t=ja(e.latitude,e.longitude,new Date(e.datetime)),n=Va(t.altitude_deg,this.sun_settings.intensity,this.sun_settings.color),s=t.direction.multiplyScalar(100);let i=0;return n.intensity>0&&(i=+`0x${n.color.getHexString()}`),B.debug(`Solar sun: lat ${e.latitude}, lon ${e.longitude}, alt ${t.altitude_deg.toFixed(1)}°, az ${t.azimuth_deg.toFixed(1)}°`),{position:[s.x,s.y,s.z],intensity:n.intensity,color:i}}apply_solar(){var e;if((e=this.sun_settings)!=null&&e.solar)try{return this.resolve_solar()}catch(t){B.warn("Failed to resolve solar sun, falling back to configured values:",t);return}}sun_create(e){if(!this.sun_settings)return;this.sun&&(this.scene.remove(this.sun),this.sun.dispose(),this.sun=null);const t=(e==null?void 0:e.color)??this.sun_settings.color,n=(e==null?void 0:e.intensity)??this.sun_settings.intensity;this.sun=new _.DirectionalLight(t,n),this.sun_settings.shadow&&(this.viewer.renderer.shadowMap.enabled=!0,this.sun.castShadow=!0,this.sun_fit_shadow()),this.sun.position.set(...(e==null?void 0:e.position)??this.sun_settings.position),this.scene.add(this.sun)}_infer_sun_position_from_env_map(){if(!this.environment)return B.warn("No environment map available."),null;const e=this.environment.texture,t=e==null?void 0:e.image;if(!t||!t.width||!t.height||!t.data)return B.warn("No environment map texture found."),null;const n=t.width,s=t.height,i=t.data;let o=0;const a=[];for(let m=0;m<i.length;m+=4){const y=i[m],v=i[m+1],b=i[m+2],S=.2126*y+.7152*v+.0722*b;if(S>o){o=S,a.length=0;const A=m/4;a.push({x:A%n,y:Math.floor(A/n)})}else if(S===o){const A=m/4;a.push({x:A%n,y:Math.floor(A/n)})}}let c=0,l=0;a.forEach(m=>{c+=m.x,l+=m.y}),c/=a.length,l/=a.length;let d=c/n*2*Math.PI;d=(d+Math.PI)%(2*Math.PI);const u=l/s*Math.PI,f=new _.Vector3(Math.sin(u)*Math.cos(d),Math.cos(u),Math.sin(u)*Math.sin(d));return f.normalize(),f.multiplyScalar(100)}remove_classic_sun(){var e,t;this.sun&&(this.scene.remove(this.sun),(t=(e=this.sun).dispose)==null||t.call(e),this.sun=null)}sync_csm(e){const t=this.sun_settings.csm,n=JSON.stringify(t),s=new _.Vector3(-e.position[0],-e.position[1],-e.position[2]).normalize();!this.csm||this.csm_key!==n?(this.teardown_csm(),this.viewer.renderer.shadowMap.enabled=!0,this.csm=new xa({camera:this.viewer.camera,parent:this.scene,cascades:t.cascades,maxFar:t.max_far,mode:"practical",shadowMapSize:t.shadow_map_size,shadowBias:t.shadow_bias,lightDirection:s.clone(),lightIntensity:e.intensity,lightNear:1,lightFar:t.max_far}),this.csm.fade=!0,this.csm.lights.forEach(i=>{i.color.set(e.color),i.intensity=e.intensity,i.shadow.normalBias=t.shadow_normal_bias}),this.csm_callback=()=>{var i;(i=this.csm)==null||i.update()},this.viewer.register_animation_callback(this.csm_callback),this.csm_key=n,this.watch_model_loads()):(this.csm.lightDirection.copy(s),this.csm.lightIntensity=e.intensity,this.csm.lights.forEach(i=>{i.color.set(e.color),i.intensity=e.intensity,i.shadow.normalBias=t.shadow_normal_bias})),this.setup_csm_materials()}setup_csm_materials(){!this.csm||!this.csm_key||this.scene.traverse(e=>{const t=e;if(!t.isMesh)return;const n=Array.isArray(t.material)?t.material:[t.material];for(const s of n){if(!s)continue;const i=s;(i.isMeshStandardMaterial||i.isMeshLambertMaterial||i.isMeshPhongMaterial)&&i.userData.csm_setup_key!==this.csm_key&&(this.csm.setupMaterial(i),i.userData.csm_setup_key=this.csm_key,i.needsUpdate=!0)}})}watch_model_loads(){this.models_watched||(this.models_watched=!0,this.model_manager.addEventListener("loaded",()=>{this.setup_csm_materials()}))}teardown_csm(){this.csm_callback&&(this.viewer.unregister_animation_callback(this.csm_callback),this.csm_callback=null),this.csm&&(this.csm.remove(),this.csm.dispose(),this.csm=null),this.csm_key=null}dispose(){this.teardown_csm(),this.remove_classic_sun()}}const ue=[];for(let r=0;r<256;++r)ue.push((r+256).toString(16).slice(1));function Ga(r,e=0){return(ue[r[e+0]]+ue[r[e+1]]+ue[r[e+2]]+ue[r[e+3]]+"-"+ue[r[e+4]]+ue[r[e+5]]+"-"+ue[r[e+6]]+ue[r[e+7]]+"-"+ue[r[e+8]]+ue[r[e+9]]+"-"+ue[r[e+10]]+ue[r[e+11]]+ue[r[e+12]]+ue[r[e+13]]+ue[r[e+14]]+ue[r[e+15]]).toLowerCase()}let _s;const Za=new Uint8Array(16);function Wa(){if(!_s){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");_s=crypto.getRandomValues.bind(crypto)}return _s(Za)}const Ni={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Xa(r,e,t){var s;if(Ni.randomUUID&&!r)return Ni.randomUUID();r=r||{};const n=r.random??((s=r.rng)==null?void 0:s.call(r))??Wa();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,Ga(n)}function $a(r,e=1e-4){e=Math.max(e,Number.EPSILON);const t={},n=r.getIndex(),s=r.getAttribute("position"),i=n?n.count:s.count;let o=0;const a=Object.keys(r.attributes),c={},l={},d=[],u=["getX","getY","getZ","getW"],f=["setX","setY","setZ","setW"];for(let A=0,L=a.length;A<L;A++){const x=a[A],z=r.attributes[x];c[x]=new z.constructor(new z.array.constructor(z.count*z.itemSize),z.itemSize,z.normalized);const Z=r.morphAttributes[x];Z&&(l[x]||(l[x]=[]),Z.forEach((j,O)=>{const D=new j.array.constructor(j.count*j.itemSize);l[x][O]=new j.constructor(D,j.itemSize,j.normalized)}))}const m=e*.5,y=Math.log10(1/e),v=Math.pow(10,y),b=m*v;for(let A=0;A<i;A++){const L=n?n.getX(A):A;let x="";for(let z=0,Z=a.length;z<Z;z++){const j=a[z],O=r.getAttribute(j),D=O.itemSize;for(let k=0;k<D;k++)x+=`${~~(O[u[k]](L)*v+b)},`}if(x in t)d.push(t[x]);else{for(let z=0,Z=a.length;z<Z;z++){const j=a[z],O=r.getAttribute(j),D=r.morphAttributes[j],k=O.itemSize,R=c[j],W=l[j];for(let $=0;$<k;$++){const N=u[$],ee=f[$];if(R[ee](o,O[N](L)),D)for(let Y=0,Me=D.length;Y<Me;Y++)W[Y][ee](o,D[Y][N](L))}}t[x]=o,d.push(o),o++}}const S=r.clone();for(const A in r.attributes){const L=c[A];if(S.setAttribute(A,new L.constructor(L.array.slice(0,o*L.itemSize),L.itemSize,L.normalized)),A in l)for(let x=0;x<l[A].length;x++){const z=l[A][x];S.morphAttributes[A][x]=new z.constructor(z.array.slice(0,o*z.itemSize),z.itemSize,z.normalized)}}return S.setIndex(d),S}function Ei(r,e){if(e===h.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),r;if(e===h.TriangleFanDrawMode||e===h.TriangleStripDrawMode){let t=r.getIndex();if(t===null){const o=[],a=r.getAttribute("position");if(a!==void 0){for(let c=0;c<a.count;c++)o.push(c);r.setIndex(o),t=r.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),r}const n=t.count-2,s=[];if(e===h.TriangleFanDrawMode)for(let o=1;o<=n;o++)s.push(t.getX(0)),s.push(t.getX(o)),s.push(t.getX(o+1));else for(let o=0;o<n;o++)o%2===0?(s.push(t.getX(o)),s.push(t.getX(o+1)),s.push(t.getX(o+2))):(s.push(t.getX(o+2)),s.push(t.getX(o+1)),s.push(t.getX(o)));s.length/3!==n&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const i=r.clone();return i.setIndex(s),i.clearGroups(),i}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",e),r}const Pi=new h.Box3,Rn=new h.Vector3;class gs extends h.InstancedBufferGeometry{constructor(){super(),this.isLineSegmentsGeometry=!0,this.type="LineSegmentsGeometry";const e=[-1,2,0,1,2,0,-1,1,0,1,1,0,-1,0,0,1,0,0,-1,-1,0,1,-1,0],t=[-1,2,1,2,-1,1,1,1,-1,-1,1,-1,-1,-2,1,-2],n=[0,2,1,2,3,1,2,4,3,4,5,3,4,6,5,6,7,5];this.setIndex(n),this.setAttribute("position",new h.Float32BufferAttribute(e,3)),this.setAttribute("uv",new h.Float32BufferAttribute(t,2))}applyMatrix4(e){const t=this.attributes.instanceStart,n=this.attributes.instanceEnd;return t!==void 0&&(t.applyMatrix4(e),n.applyMatrix4(e),t.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}setPositions(e){let t;e instanceof Float32Array?t=e:Array.isArray(e)&&(t=new Float32Array(e));const n=new h.InstancedInterleavedBuffer(t,6,1);return this.setAttribute("instanceStart",new h.InterleavedBufferAttribute(n,3,0)),this.setAttribute("instanceEnd",new h.InterleavedBufferAttribute(n,3,3)),this.instanceCount=this.attributes.instanceStart.count,this.computeBoundingBox(),this.computeBoundingSphere(),this}setColors(e){let t;e instanceof Float32Array?t=e:Array.isArray(e)&&(t=new Float32Array(e));const n=new h.InstancedInterleavedBuffer(t,6,1);return this.setAttribute("instanceColorStart",new h.InterleavedBufferAttribute(n,3,0)),this.setAttribute("instanceColorEnd",new h.InterleavedBufferAttribute(n,3,3)),this}fromWireframeGeometry(e){return this.setPositions(e.attributes.position.array),this}fromEdgesGeometry(e){return this.setPositions(e.attributes.position.array),this}fromMesh(e){return this.fromWireframeGeometry(new h.WireframeGeometry(e.geometry)),this}fromLineSegments(e){const t=e.geometry;return this.setPositions(t.attributes.position.array),this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new h.Box3);const e=this.attributes.instanceStart,t=this.attributes.instanceEnd;e!==void 0&&t!==void 0&&(this.boundingBox.setFromBufferAttribute(e),Pi.setFromBufferAttribute(t),this.boundingBox.union(Pi))}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new h.Sphere),this.boundingBox===null&&this.computeBoundingBox();const e=this.attributes.instanceStart,t=this.attributes.instanceEnd;if(e!==void 0&&t!==void 0){const n=this.boundingSphere.center;this.boundingBox.getCenter(n);let s=0;for(let i=0,o=e.count;i<o;i++)Rn.fromBufferAttribute(e,i),s=Math.max(s,n.distanceToSquared(Rn)),Rn.fromBufferAttribute(t,i),s=Math.max(s,n.distanceToSquared(Rn));this.boundingSphere.radius=Math.sqrt(s),isNaN(this.boundingSphere.radius)&&console.error("THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.",this)}}toJSON(){}}h.UniformsLib.line={worldUnits:{value:1},linewidth:{value:1},resolution:{value:new h.Vector2(1,1)},dashOffset:{value:0},dashScale:{value:1},dashSize:{value:1},gapSize:{value:1}},h.ShaderLib.line={uniforms:h.UniformsUtils.merge([h.UniformsLib.common,h.UniformsLib.fog,h.UniformsLib.line]),vertexShader:`
446
+ `+h.ShaderChunk.lights_pars_begin},Li=new h.Matrix4,hs=new Pn({webGL:!0}),Je=new h.Vector3,an=new h.Box3,us=[],fs=[],ms=new h.Matrix4,Ti=new h.Matrix4,va=new h.Vector3(0,1,0);class xa{constructor(e){this.camera=e.camera,this.parent=e.parent,this.cascades=e.cascades||3,this.maxFar=e.maxFar||1e5,this.mode=e.mode||"practical",this.shadowMapSize=e.shadowMapSize||2048,this.shadowBias=e.shadowBias||1e-6,this.lightDirection=e.lightDirection||new h.Vector3(1,-1,1).normalize(),this.lightIntensity=e.lightIntensity||3,this.lightNear=e.lightNear||1,this.lightFar=e.lightFar||2e3,this.lightMargin=e.lightMargin||200,this.customSplitsCallback=e.customSplitsCallback,this.fade=!1,this.mainFrustum=new Pn({webGL:!0}),this.frustums=[],this.breaks=[],this.lights=[],this.shaders=new Map,this._createLights(),this.updateFrustums(),this._injectInclude()}_createLights(){for(let e=0;e<this.cascades;e++){const t=new h.DirectionalLight(16777215,this.lightIntensity);t.castShadow=!0,t.shadow.mapSize.width=this.shadowMapSize,t.shadow.mapSize.height=this.shadowMapSize,t.shadow.camera.near=this.lightNear,t.shadow.camera.far=this.lightFar,t.shadow.bias=this.shadowBias,this.parent.add(t),this.parent.add(t.target),this.lights.push(t)}}_initCascades(){const e=this.camera;e.updateProjectionMatrix(),this.mainFrustum.setFromProjectionMatrix(e.projectionMatrix,this.maxFar),this.mainFrustum.split(this.breaks,this.frustums)}_updateShadowBounds(){const e=this.frustums;for(let t=0;t<e.length;t++){const s=this.lights[t].shadow.camera,i=this.frustums[t],o=i.vertices.near,a=i.vertices.far,c=a[0];let l;c.distanceTo(a[2])>c.distanceTo(o[2])?l=a[2]:l=o[2];let d=c.distanceTo(l);if(this.fade){const u=this.camera,f=Math.max(u.far,this.maxFar),m=i.vertices.far[0].z/(f-u.near),y=.25*Math.pow(m,2)*(f-u.near);d+=y}s.left=-d/2,s.right=d/2,s.top=d/2,s.bottom=-d/2,s.updateProjectionMatrix()}}_getBreaks(){const e=this.camera,t=Math.min(e.far,this.maxFar);switch(this.breaks.length=0,this.mode){case"uniform":n(this.cascades,e.near,t,this.breaks);break;case"logarithmic":s(this.cascades,e.near,t,this.breaks);break;case"practical":i(this.cascades,e.near,t,.5,this.breaks);break;case"custom":this.customSplitsCallback===void 0&&console.error("CSM: Custom split scheme callback not defined."),this.customSplitsCallback(this.cascades,e.near,t,this.breaks);break}function n(o,a,c,l){for(let d=1;d<o;d++)l.push((a+(c-a)*d/o)/c);l.push(1)}function s(o,a,c,l){for(let d=1;d<o;d++)l.push(a*(c/a)**(d/o)/c);l.push(1)}function i(o,a,c,l,d){us.length=0,fs.length=0,s(o,a,c,fs),n(o,a,c,us);for(let u=1;u<o;u++)d.push(h.MathUtils.lerp(us[u-1],fs[u-1],l));d.push(1)}}update(){const e=this.camera,t=this.frustums;ms.lookAt(new h.Vector3,this.lightDirection,va),Ti.copy(ms).invert();for(let n=0;n<t.length;n++){const s=this.lights[n],i=s.shadow.camera,o=(i.right-i.left)/this.shadowMapSize,a=(i.top-i.bottom)/this.shadowMapSize;Li.multiplyMatrices(Ti,e.matrixWorld),t[n].toSpace(Li,hs);const c=hs.vertices.near,l=hs.vertices.far;an.makeEmpty();for(let d=0;d<4;d++)an.expandByPoint(c[d]),an.expandByPoint(l[d]);an.getCenter(Je),Je.z=an.max.z+this.lightMargin,Je.x=Math.floor(Je.x/o)*o,Je.y=Math.floor(Je.y/a)*a,Je.applyMatrix4(ms),s.position.copy(Je),s.target.position.copy(Je),s.target.position.x+=this.lightDirection.x,s.target.position.y+=this.lightDirection.y,s.target.position.z+=this.lightDirection.z}}_injectInclude(){h.ShaderChunk.lights_fragment_begin=Mi.lights_fragment_begin,h.ShaderChunk.lights_pars_begin=Mi.lights_pars_begin}setupMaterial(e){e.defines=e.defines||{},e.defines.USE_CSM=1,e.defines.CSM_CASCADES=this.cascades,this.fade&&(e.defines.CSM_FADE="");const t=[],n=this,s=this.shaders;e.onBeforeCompile=function(i){const o=Math.min(n.camera.far,n.maxFar);n._getExtendedBreaks(t),i.uniforms.CSM_cascades={value:t},i.uniforms.cameraNear={value:n.camera.near},i.uniforms.shadowFar={value:o},s.set(e,i)},s.set(e,null)}_updateUniforms(){const e=Math.min(this.camera.far,this.maxFar);this.shaders.forEach(function(n,s){if(n!==null){const i=n.uniforms;this._getExtendedBreaks(i.CSM_cascades.value),i.cameraNear.value=this.camera.near,i.shadowFar.value=e}!this.fade&&"CSM_FADE"in s.defines?(delete s.defines.CSM_FADE,s.needsUpdate=!0):this.fade&&!("CSM_FADE"in s.defines)&&(s.defines.CSM_FADE="",s.needsUpdate=!0)},this)}_getExtendedBreaks(e){for(;e.length<this.breaks.length;)e.push(new h.Vector2);e.length=this.breaks.length;for(let t=0;t<this.cascades;t++){const n=this.breaks[t],s=this.breaks[t-1]||0;e[t].x=s,e[t].y=n}}updateFrustums(){this._getBreaks(),this._initCascades(),this._updateShadowBounds(),this._updateUniforms()}remove(){for(let e=0;e<this.lights.length;e++)this.parent.remove(this.lights[e].target),this.parent.remove(this.lights[e])}dispose(){const e=this.shaders;e.forEach(function(t,n){delete n.onBeforeCompile,delete n.defines.USE_CSM,delete n.defines.CSM_CASCADES,delete n.defines.CSM_FADE,t!==null&&(delete t.uniforms.CSM_cascades,delete t.uniforms.cameraNear,delete t.uniforms.shadowFar),n.needsUpdate=!0}),e.clear()}}function Di(r){const t=new _.Box3().setFromObject(r).getSize(new _.Vector3);return Math.max(10,Math.max(t.x,t.y,t.z))}const ba=512,wa=100,Sa=30,Aa=-.001,Ma=3,La=16,{PI:Ta,sin:Qe,cos:et,tan:Ci,asin:Oi,atan2:Ii}=Math,Ne=Ta/180,Da=1e3*60*60*24,Ca=2440588,Oa=2451545;function Ia(r){return r.valueOf()/Da-.5+Ca-Oa}function ka(r){const e=2e3+r/365.2425;let t;return e<1920?(t=e-1900,-2.79+t*(1.494119+t*(-.0598939+t*(.0061966-t*197e-6)))):e<1941?(t=e-1920,21.2+t*(.84493+t*(-.0761+t*.0020936))):e<1961?(t=e-1950,29.07+t*(.407+t*(-1/233+t/2547))):e<1986?(t=e-1975,45.45+t*(1.067+t*(-1/260-t/718))):e<2005?(t=e-2e3,63.86+t*(.3345+t*(-.060374+t*(.0017275+t*(651814e-9+t*2373599e-11))))):e<2050?(t=e-2e3,62.92+t*(.32217+t*.005589)):(t=(e-1820)/100,-20+32*t*t-.5628*(2150-e))}function Na(r){return r+ka(r)/86400}function Ea(r,e,t){return(Ii(Qe(r),et(r)*Qe(e)-Ci(t)*et(e))/Ne+540)%360}function Pa(r,e,t){return Oi(Qe(e)*Qe(t)+et(e)*et(t)*et(r))}function Ra(r,e){return Ne*(280.46061837+360.98564736629*r)-e}function za(r){return r<0&&(r=0),2967e-7/Ci(r+.00312536/(r+.08901179))}function Ua(r){const e=r/36525,t=Ne*(280.46646+e*(36000.76983+e*3032e-7)),n=Ne*(357.52911+e*(35999.05029-e*1537e-7)),s=Qe(n),i=et(n),o=Ne*((1.914602-e*(.004817+e*14e-6))*s+(.019993-101e-6*e)*2*s*i+289e-6*s*(3-4*s*s)),a=Ne*(125.04-1934.136*e),c=t+o-Ne*(.00569+.00478*Qe(a)),l=Ne*(23.439291-e*(.0130042+e*(16e-8-e*504e-9)))+Ne*.00256*et(a);return{ra:Ii(et(l)*Qe(c),et(c)),dec:Oi(Qe(l)*Qe(c)),lon:c}}function Fa(r,e,t){const n=Ne*-t,s=Ne*e,i=Ia(r),o=Ua(Na(i)),a=Ra(i,n)-o.ra,c=Pa(a,s,o.dec);return{azimuth:Ea(a,s,o.dec),altitude:(c+za(c))/Ne}}const ps=Math.PI/180;function ja(r,e,t){const n=Fa(t,r,e),s=n.altitude,i=(n.azimuth%360+360)%360,o=s*ps,a=i*ps,c=new _.Vector3(Math.cos(o)*Math.sin(a),Math.sin(o),-Math.cos(o)*Math.cos(a));return{altitude_deg:s,azimuth_deg:i,direction:c}}const Ba=-6;function Va(r,e,t){const n=new _.Color(t);if(r<=Ba)return{intensity:0,color:new _.Color(0)};const s=Math.max(0,r),i=Math.sin(Math.min(s,90)*ps),o=e*(.12+.88*i),a=1-Math.min(s/30,1),l=new _.Color(16747586).lerp(n,1-a*.85);return{intensity:o,color:l}}class ki{constructor(e,t,n,s){g(this,"viewer");g(this,"scene");g(this,"settings");g(this,"sun_settings");g(this,"model_manager");g(this,"sun",null);g(this,"environment");g(this,"csm",null);g(this,"csm_key",null);g(this,"csm_callback",null);g(this,"models_watched",!1);this.viewer=e,this.scene=e.scene,this.settings=t,this.environment=n,this.model_manager=s,this.sun_settings=this.settings.get("environment").sun,this.settings.addEventListener("update",i=>{const o=i.detail;this.sun_settings=o.environment.sun,this.update()}),this.settings.addEventListener("environmentTextureLoaded",i=>{const o=i.detail.texture;if(this.environment.texture=o,this.sun&&this.sun_settings){const a=this._infer_sun_position_from_env_map();a&&(B.debug("Texture loaded event call; inferred Sun position from env map:",a),this.sun_settings.position=[a.x,a.y,a.z],this.update())}}),this.update()}update(){if(!this.sun_settings){this.sun&&(this.scene.remove(this.sun),this.sun=null);return}this.model_manager.ready.then(()=>{if(!this.sun_settings){this.teardown_csm();return}const e=this.apply_solar();if(!e){const n=this._infer_sun_position_from_env_map();n&&(B.debug("Inferred Sun position from env map:",n),this.sun_settings.position=[n.x,n.y,n.z])}const t=e??{position:this.sun_settings.position,intensity:this.sun_settings.intensity,color:this.sun_settings.color};this.sun_settings.csm?(this.remove_classic_sun(),this.sync_csm(t)):(this.teardown_csm(),this.sun_create(e??void 0)),this.sun_settings&&this.sync_sky(t.position)})}sync_sky(e){e&&this.environment.update_sky_environment(new _.Vector3(e[0],e[1],e[2]))}sun_fit_object(e=this.scene){const t=Di(e);let n=new _.Vector3(0,1,0).normalize();n=n.multiplyScalar(t*2),this.sun&&(n=this.sun.position.clone())}sun_fit_shadow(){const e=new _.Object3D;if(!this.model_manager){B.warn("No model manager found.");return}for(const o of this.model_manager.models.values())o.settings.shadow&&e.add(o.group.clone());e.children.length===0&&B.warn("No models with shadows found to fit shadow map."),B.debug("Models in fit_object:",e);const t=Di(e),n=ba,s=Math.ceil(t/wa),i=Math.min(Math.pow(2,Math.ceil(Math.log2(n*s))),this.viewer.renderer.capabilities.maxTextureSize);if(B.debug("Shadow map size:",i),this.sun){this.sun.shadow.mapSize.width=i,this.sun.shadow.mapSize.height=i;const o=Sa;this.sun.shadow.camera.left=-(t/2+o),this.sun.shadow.camera.right=t/2+o,this.sun.shadow.camera.top=t/2+o,this.sun.shadow.camera.bottom=-(t/2+o),this.sun.shadow.camera.near=.1,this.sun.shadow.camera.far=t*2,this.sun.shadow.bias=Aa,this.sun.shadow.radius=Ma,this.sun.shadow.blurSamples=La,B.info(`Recreated sun with shadow map size: ${i}x${i}`)}}resolve_solar(){const e=this.sun_settings.solar,t=ja(e.latitude,e.longitude,new Date(e.datetime)),n=Va(t.altitude_deg,this.sun_settings.intensity,this.sun_settings.color),s=t.direction.multiplyScalar(100);let i=0;return n.intensity>0&&(i=+`0x${n.color.getHexString()}`),B.debug(`Solar sun: lat ${e.latitude}, lon ${e.longitude}, alt ${t.altitude_deg.toFixed(1)}°, az ${t.azimuth_deg.toFixed(1)}°`),{position:[s.x,s.y,s.z],intensity:n.intensity,color:i}}apply_solar(){var e;if((e=this.sun_settings)!=null&&e.solar)try{return this.resolve_solar()}catch(t){B.warn("Failed to resolve solar sun, falling back to configured values:",t);return}}sun_create(e){if(!this.sun_settings)return;this.sun&&(this.scene.remove(this.sun),this.sun.dispose(),this.sun=null);const t=(e==null?void 0:e.color)??this.sun_settings.color,n=(e==null?void 0:e.intensity)??this.sun_settings.intensity;this.sun=new _.DirectionalLight(t,n),this.sun_settings.shadow&&(this.viewer.renderer.shadowMap.enabled=!0,this.sun.castShadow=!0,this.sun_fit_shadow()),this.sun.position.set(...(e==null?void 0:e.position)??this.sun_settings.position),this.scene.add(this.sun)}_infer_sun_position_from_env_map(){if(!this.environment)return B.warn("No environment map available."),null;const e=this.environment.texture,t=e==null?void 0:e.image;if(!t||!t.width||!t.height||!t.data)return B.warn("No environment map texture found."),null;const n=t.width,s=t.height,i=t.data;let o=0;const a=[];for(let m=0;m<i.length;m+=4){const y=i[m],v=i[m+1],b=i[m+2],S=.2126*y+.7152*v+.0722*b;if(S>o){o=S,a.length=0;const A=m/4;a.push({x:A%n,y:Math.floor(A/n)})}else if(S===o){const A=m/4;a.push({x:A%n,y:Math.floor(A/n)})}}let c=0,l=0;a.forEach(m=>{c+=m.x,l+=m.y}),c/=a.length,l/=a.length;let d=c/n*2*Math.PI;d=(d+Math.PI)%(2*Math.PI);const u=l/s*Math.PI,f=new _.Vector3(Math.sin(u)*Math.cos(d),Math.cos(u),Math.sin(u)*Math.sin(d));return f.normalize(),f.multiplyScalar(100)}remove_classic_sun(){var e,t;this.sun&&(this.scene.remove(this.sun),(t=(e=this.sun).dispose)==null||t.call(e),this.sun=null)}resolve_csm_range(){const e=this.sun_settings.csm.max_far;if(e>0)return e;const t=new _.Box3;let n=!1;if(this.model_manager.models.forEach(a=>{a.group&&(t.expandByObject(a.group),n=!0)}),!n||t.isEmpty())return 1e3;const s=t.getSize(new _.Vector3),i=Math.max(s.x,s.y,s.z),o=Math.min(6e3,Math.max(100,i*3));return B.debug(`CSM range auto-fitted to scene: ${o.toFixed(0)} m (model extent ${i.toFixed(0)} m)`),o}sync_csm(e){const t=this.sun_settings.csm,n=this.resolve_csm_range(),s=JSON.stringify({...t,max_far:n}),i=new _.Vector3(-e.position[0],-e.position[1],-e.position[2]).normalize();!this.csm||this.csm_key!==s?(this.teardown_csm(),this.viewer.renderer.shadowMap.enabled=!0,this.viewer.renderer.shadowMap.type=_.PCFSoftShadowMap,this.csm=new xa({camera:this.viewer.camera,parent:this.scene,cascades:t.cascades,maxFar:n,mode:"practical",shadowMapSize:t.shadow_map_size,shadowBias:t.shadow_bias,lightDirection:i.clone(),lightIntensity:e.intensity,lightNear:1,lightFar:n}),this.csm.fade=!0,this.csm.lights.forEach(o=>{o.color.set(e.color),o.intensity=e.intensity,o.shadow.normalBias=t.shadow_normal_bias}),this.csm_callback=()=>{var o;(o=this.csm)==null||o.update()},this.viewer.register_animation_callback(this.csm_callback),this.csm_key=s,this.watch_model_loads()):(this.csm.lightDirection.copy(i),this.csm.lightIntensity=e.intensity,this.csm.lights.forEach(o=>{o.color.set(e.color),o.intensity=e.intensity,o.shadow.normalBias=t.shadow_normal_bias})),this.setup_csm_materials()}setup_csm_materials(){!this.csm||!this.csm_key||this.scene.traverse(e=>{const t=e;if(!t.isMesh)return;const n=Array.isArray(t.material)?t.material:[t.material];for(const s of n){if(!s)continue;const i=s;(i.isMeshStandardMaterial||i.isMeshLambertMaterial||i.isMeshPhongMaterial)&&i.userData.csm_setup_key!==this.csm_key&&(this.csm.setupMaterial(i),i.userData.csm_setup_key=this.csm_key,i.needsUpdate=!0)}})}watch_model_loads(){this.models_watched||(this.models_watched=!0,this.model_manager.addEventListener("loaded",()=>{this.setup_csm_materials()}))}teardown_csm(){this.csm_callback&&(this.viewer.unregister_animation_callback(this.csm_callback),this.csm_callback=null),this.csm&&(this.csm.remove(),this.csm.dispose(),this.csm=null),this.csm_key=null}dispose(){this.teardown_csm(),this.remove_classic_sun()}}const ue=[];for(let r=0;r<256;++r)ue.push((r+256).toString(16).slice(1));function Ga(r,e=0){return(ue[r[e+0]]+ue[r[e+1]]+ue[r[e+2]]+ue[r[e+3]]+"-"+ue[r[e+4]]+ue[r[e+5]]+"-"+ue[r[e+6]]+ue[r[e+7]]+"-"+ue[r[e+8]]+ue[r[e+9]]+"-"+ue[r[e+10]]+ue[r[e+11]]+ue[r[e+12]]+ue[r[e+13]]+ue[r[e+14]]+ue[r[e+15]]).toLowerCase()}let _s;const Za=new Uint8Array(16);function Wa(){if(!_s){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");_s=crypto.getRandomValues.bind(crypto)}return _s(Za)}const Ni={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Xa(r,e,t){var s;if(Ni.randomUUID&&!r)return Ni.randomUUID();r=r||{};const n=r.random??((s=r.rng)==null?void 0:s.call(r))??Wa();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,Ga(n)}function $a(r,e=1e-4){e=Math.max(e,Number.EPSILON);const t={},n=r.getIndex(),s=r.getAttribute("position"),i=n?n.count:s.count;let o=0;const a=Object.keys(r.attributes),c={},l={},d=[],u=["getX","getY","getZ","getW"],f=["setX","setY","setZ","setW"];for(let A=0,L=a.length;A<L;A++){const x=a[A],z=r.attributes[x];c[x]=new z.constructor(new z.array.constructor(z.count*z.itemSize),z.itemSize,z.normalized);const Z=r.morphAttributes[x];Z&&(l[x]||(l[x]=[]),Z.forEach((j,O)=>{const D=new j.array.constructor(j.count*j.itemSize);l[x][O]=new j.constructor(D,j.itemSize,j.normalized)}))}const m=e*.5,y=Math.log10(1/e),v=Math.pow(10,y),b=m*v;for(let A=0;A<i;A++){const L=n?n.getX(A):A;let x="";for(let z=0,Z=a.length;z<Z;z++){const j=a[z],O=r.getAttribute(j),D=O.itemSize;for(let k=0;k<D;k++)x+=`${~~(O[u[k]](L)*v+b)},`}if(x in t)d.push(t[x]);else{for(let z=0,Z=a.length;z<Z;z++){const j=a[z],O=r.getAttribute(j),D=r.morphAttributes[j],k=O.itemSize,R=c[j],W=l[j];for(let $=0;$<k;$++){const N=u[$],ee=f[$];if(R[ee](o,O[N](L)),D)for(let Y=0,Me=D.length;Y<Me;Y++)W[Y][ee](o,D[Y][N](L))}}t[x]=o,d.push(o),o++}}const S=r.clone();for(const A in r.attributes){const L=c[A];if(S.setAttribute(A,new L.constructor(L.array.slice(0,o*L.itemSize),L.itemSize,L.normalized)),A in l)for(let x=0;x<l[A].length;x++){const z=l[A][x];S.morphAttributes[A][x]=new z.constructor(z.array.slice(0,o*z.itemSize),z.itemSize,z.normalized)}}return S.setIndex(d),S}function Ei(r,e){if(e===h.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),r;if(e===h.TriangleFanDrawMode||e===h.TriangleStripDrawMode){let t=r.getIndex();if(t===null){const o=[],a=r.getAttribute("position");if(a!==void 0){for(let c=0;c<a.count;c++)o.push(c);r.setIndex(o),t=r.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),r}const n=t.count-2,s=[];if(e===h.TriangleFanDrawMode)for(let o=1;o<=n;o++)s.push(t.getX(0)),s.push(t.getX(o)),s.push(t.getX(o+1));else for(let o=0;o<n;o++)o%2===0?(s.push(t.getX(o)),s.push(t.getX(o+1)),s.push(t.getX(o+2))):(s.push(t.getX(o+2)),s.push(t.getX(o+1)),s.push(t.getX(o)));s.length/3!==n&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const i=r.clone();return i.setIndex(s),i.clearGroups(),i}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",e),r}const Pi=new h.Box3,Rn=new h.Vector3;class gs extends h.InstancedBufferGeometry{constructor(){super(),this.isLineSegmentsGeometry=!0,this.type="LineSegmentsGeometry";const e=[-1,2,0,1,2,0,-1,1,0,1,1,0,-1,0,0,1,0,0,-1,-1,0,1,-1,0],t=[-1,2,1,2,-1,1,1,1,-1,-1,1,-1,-1,-2,1,-2],n=[0,2,1,2,3,1,2,4,3,4,5,3,4,6,5,6,7,5];this.setIndex(n),this.setAttribute("position",new h.Float32BufferAttribute(e,3)),this.setAttribute("uv",new h.Float32BufferAttribute(t,2))}applyMatrix4(e){const t=this.attributes.instanceStart,n=this.attributes.instanceEnd;return t!==void 0&&(t.applyMatrix4(e),n.applyMatrix4(e),t.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}setPositions(e){let t;e instanceof Float32Array?t=e:Array.isArray(e)&&(t=new Float32Array(e));const n=new h.InstancedInterleavedBuffer(t,6,1);return this.setAttribute("instanceStart",new h.InterleavedBufferAttribute(n,3,0)),this.setAttribute("instanceEnd",new h.InterleavedBufferAttribute(n,3,3)),this.instanceCount=this.attributes.instanceStart.count,this.computeBoundingBox(),this.computeBoundingSphere(),this}setColors(e){let t;e instanceof Float32Array?t=e:Array.isArray(e)&&(t=new Float32Array(e));const n=new h.InstancedInterleavedBuffer(t,6,1);return this.setAttribute("instanceColorStart",new h.InterleavedBufferAttribute(n,3,0)),this.setAttribute("instanceColorEnd",new h.InterleavedBufferAttribute(n,3,3)),this}fromWireframeGeometry(e){return this.setPositions(e.attributes.position.array),this}fromEdgesGeometry(e){return this.setPositions(e.attributes.position.array),this}fromMesh(e){return this.fromWireframeGeometry(new h.WireframeGeometry(e.geometry)),this}fromLineSegments(e){const t=e.geometry;return this.setPositions(t.attributes.position.array),this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new h.Box3);const e=this.attributes.instanceStart,t=this.attributes.instanceEnd;e!==void 0&&t!==void 0&&(this.boundingBox.setFromBufferAttribute(e),Pi.setFromBufferAttribute(t),this.boundingBox.union(Pi))}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new h.Sphere),this.boundingBox===null&&this.computeBoundingBox();const e=this.attributes.instanceStart,t=this.attributes.instanceEnd;if(e!==void 0&&t!==void 0){const n=this.boundingSphere.center;this.boundingBox.getCenter(n);let s=0;for(let i=0,o=e.count;i<o;i++)Rn.fromBufferAttribute(e,i),s=Math.max(s,n.distanceToSquared(Rn)),Rn.fromBufferAttribute(t,i),s=Math.max(s,n.distanceToSquared(Rn));this.boundingSphere.radius=Math.sqrt(s),isNaN(this.boundingSphere.radius)&&console.error("THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.",this)}}toJSON(){}}h.UniformsLib.line={worldUnits:{value:1},linewidth:{value:1},resolution:{value:new h.Vector2(1,1)},dashOffset:{value:0},dashScale:{value:1},dashSize:{value:1},gapSize:{value:1}},h.ShaderLib.line={uniforms:h.UniformsUtils.merge([h.UniformsLib.common,h.UniformsLib.fog,h.UniformsLib.line]),vertexShader:`
447
447
  #include <common>
448
448
  #include <color_pars_vertex>
449
449
  #include <fog_pars_vertex>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maucwerk/glimmer",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "description": "A lightweight, interactive 3D model viewer for web applications built with Three.js",
5
5
  "main": "dist/vite/glimmer.umd.js",
6
6
  "module": "dist/vite/glimmer.mjs",