import { r as e } from "./three.webgpu-vPugBGTK.js";
import { createContext as t, useCallback as n, useContext as r, useEffect as i, useMemo as a, useRef as o } from "react";
import { BufferAttribute as s, Color as c, DataTexture as l, NearestFilter as u, RGBAFormat as d, UnsignedByteType as f } from "three";
import { useStore as p } from "zustand";
import { createStore as m } from "zustand/vanilla";
//#region src/viewer/store/ViewerStoreContext.ts
var h = t(null);
//#endregion
//#region src/viewer/store/useViewerStore.ts
function g(e) {
	return p(_(), e);
}
function _() {
	let e = r(h);
	if (!e) throw Error("useViewerStore must be used inside ViewerStoreProvider");
	return e;
}
//#endregion
//#region src/viewer/store/ViewerStore.ts
var v = "rgb(17, 148, 189)", y = "rgb(104, 198, 227)", b = {
	bottom: !0,
	left: !0,
	right: !0,
	top: !0,
	visible: !0
};
function x() {
	return m((e) => ({
		api: null,
		defaultHotkeysEnabled: !0,
		gridAxesVisibility: b,
		modelNames: {},
		modelProps: {},
		modelStructure: {},
		preselectionColor: y,
		selected: {},
		selectionColor: v,
		selectionInteractionDisabled: !1,
		showNavCube: !0,
		showStats: !1,
		userDevice: "pc",
		setApi: (t) => e({ api: t }),
		setDefaultHotkeysEnabled: (t) => e({ defaultHotkeysEnabled: t }),
		setGridAxesVisibility: (t) => {
			e((e) => ({ gridAxesVisibility: {
				...e.gridAxesVisibility,
				...t
			} }));
		},
		setGridAxisVisibility: (t, n) => {
			e((e) => ({ gridAxesVisibility: {
				...e.gridAxesVisibility,
				[t]: n
			} }));
		},
		setShowGridAxes: (t) => {
			e((e) => ({ gridAxesVisibility: {
				...e.gridAxesVisibility,
				visible: t
			} }));
		},
		setModelNames: (t) => e({ modelNames: t }),
		setModelProps: (t) => e({ modelProps: t }),
		setModelStructure: (t) => e({ modelStructure: t }),
		setPreselectionColor: (t) => e({ preselectionColor: t }),
		setSelectionColor: (t) => e({ selectionColor: t }),
		setSelectionInteractionDisabled: (t) => e({ selectionInteractionDisabled: t }),
		setShowNavCube: (t) => e({ showNavCube: t }),
		setShowStats: (t) => e({ showStats: t }),
		setUserDevice: (t) => e({ userDevice: t }),
		setSelection: (t) => e({ selected: t }),
		setSelected: (t, n, r = !1) => {
			e((e) => {
				if (r) {
					let r = {};
					return Object.keys(e.selected).forEach((e) => {
						r[Number(e)] = Number(e) === t ? new Set(n) : /* @__PURE__ */ new Set();
					}), r[t] || (r[t] = new Set(n)), { selected: r };
				}
				return { selected: {
					...e.selected,
					[t]: new Set(n)
				} };
			});
		},
		addSelected: (t, n) => {
			e((e) => {
				let r = new Set(e.selected[t] ?? []);
				return n.forEach((e) => r.add(e)), { selected: {
					...e.selected,
					[t]: r
				} };
			});
		},
		removeSelected: (t, n) => {
			e((e) => {
				let r = new Set(e.selected[t] ?? []);
				return n.forEach((e) => r.delete(e)), { selected: {
					...e.selected,
					[t]: r
				} };
			});
		},
		resetSelected: (t) => {
			e((e) => {
				if (t !== void 0) return { selected: {
					...e.selected,
					[t]: /* @__PURE__ */ new Set()
				} };
				let n = {};
				return Object.keys(e.selected).forEach((e) => {
					n[Number(e)] = /* @__PURE__ */ new Set();
				}), { selected: n };
			});
		}
	}));
}
var S = 2;
function C() {
	let e = new l(new Uint8Array(256 * 4), 256, 1, d, f);
	return e.magFilter = u, e.minFilter = u, e.generateMipmaps = !1, e.needsUpdate = !0, T(e, 1, new c(v)), e;
}
function w(e) {
	return `${e.r.toFixed(6)}:${e.g.toFixed(6)}:${e.b.toFixed(6)}`;
}
function T(e, t, n) {
	let r = e.image.data, i = t * 4;
	r[i] = Math.round(n.r * 255), r[i + 1] = Math.round(n.g * 255), r[i + 2] = Math.round(n.b * 255), r[i + 3] = 255, e.needsUpdate = !0;
}
function E(e) {
	return e.mesh.geometry.attributes.colorIndex;
}
function D(e) {
	let t = e.mesh.geometry.attributes.ids;
	if (!t) return null;
	let n = new s(e.mesh.userData.useUint32ColorIndex === !0 ? new Uint32Array(t.count) : new Uint8Array(t.count), 1);
	return e.mesh.geometry.setAttribute("colorIndex", n), n;
}
function O(e, t) {
	let n = E(e);
	return n || t === 0 ? n : D(e);
}
function k(e) {
	e.mesh.userData.keepColorIndexAttribute !== !0 && E(e) && e.mesh.geometry.deleteAttribute("colorIndex");
}
function A(e, t, n) {
	let r = e.get(t);
	return !r && n && (r = /* @__PURE__ */ new Set(), e.set(t, r)), r;
}
function j(e, t) {
	let n = O(e.record, t);
	if (!n) return !1;
	let r = n.array;
	return e.vertexRanges.forEach(({ count: e, start: n }) => {
		r.fill(t, n, n + e);
	}), n.needsUpdate = !0, !0;
}
function M(e, t, n, r, i) {
	e && e.forEach((e) => {
		if (e.record.modelID !== t) return;
		let a = j(e, r), o = A(i, e.record, r !== 0 && a);
		r === 0 ? (o?.delete(n), o?.size || (i.delete(e.record), k(e.record))) : a && o?.add(n);
	});
}
function N(e, t, n) {
	let r = /* @__PURE__ */ new Set();
	return e.elementIndex.forEach((e, i) => {
		n.has(i) || e.some((e) => e.record.modelID === t) && r.add(i);
	}), r;
}
function P(e) {
	let t = /* @__PURE__ */ new Set();
	return Object.entries(e).forEach(([e, n]) => {
		n.forEach((n) => t.add(`${e}:${n}`));
	}), t;
}
function F(e, t) {
	let n = /* @__PURE__ */ new Map(), r = (e) => {
		let [t, r] = e.split(":").map(Number), i = n.get(t);
		i || (i = /* @__PURE__ */ new Set(), n.set(t, i)), i.add(r);
	};
	return t.forEach((t) => {
		e.has(t) || r(t);
	}), e.forEach((e) => {
		t.has(e) || r(e);
	}), n;
}
function I(e) {
	let t = g((e) => e.selected), r = g((e) => e.selectionColor), s = a(() => C(), []), l = o(/* @__PURE__ */ new Map()), u = o(S), d = o(/* @__PURE__ */ new Map()), f = o(t), p = o(/* @__PURE__ */ new Set()), m = o(/* @__PURE__ */ new WeakMap());
	i(() => {
		f.current = t;
	}, [t]), i(() => () => s.dispose(), [s]), i(() => {
		T(s, 1, new c(r));
	}, [s, r]);
	let h = n((e, t) => f.current[e]?.has(t) ? 1 : d.current.get(e)?.get(t) ?? 0, []), _ = n((t, n) => {
		let r = e.buildIndex();
		n.forEach((e) => {
			M(r.elementIndex.get(e), t, e, h(t, e), m.current);
		});
	}, [e, h]), v = n((e) => {
		let t = new c(e), n = w(t), r = l.current.get(n);
		if (r !== void 0) return r;
		let i = u.current;
		if (i >= 256) throw Error("Element color palette is full. Maximum colors: 255.");
		return l.current.set(n, i), u.current += 1, T(s, i, t), i;
	}, [s]);
	i(() => {
		let e = P(t);
		F(p.current, e).forEach((e, t) => {
			_(t, Array.from(e));
		}), p.current = e;
	}, [_, t]);
	let y = n((e, t, n) => {
		let r = v(n), i = d.current.get(e);
		i || (i = /* @__PURE__ */ new Map(), d.current.set(e, i)), t.forEach((e) => i.set(e, r)), _(e, t);
	}, [_, v]), b = n((t, n, r) => {
		let i = e.buildIndex(), a = /* @__PURE__ */ new Set(), o = Object.entries(n);
		o.forEach(([, e]) => {
			e.forEach((e) => a.add(e));
		}), r !== void 0 && y(t, Array.from(N(i, t, a)), r), o.forEach(([e, n]) => {
			y(t, n, e);
		});
	}, [e, y]), x = n((e, t) => {
		Object.entries(e).forEach(([e, n]) => {
			b(Number(e), n, t);
		});
	}, [b]), E = n((e, t) => {
		let n = d.current.get(e);
		t.forEach((e) => n?.delete(e)), n?.size === 0 && d.current.delete(e), _(e, t);
	}, [_]), D = n((e) => {
		let t = d.current.get(e);
		if (!t?.size) return;
		let n = Array.from(t.keys());
		t.clear(), d.current.delete(e), _(e, n);
	}, [_]), O = n(() => {
		let t = e.buildIndex(), n = /* @__PURE__ */ new Map(), r = (e, t) => {
			let r = n.get(e);
			r || (r = /* @__PURE__ */ new Set(), n.set(e, r)), r.add(t);
		};
		d.current.forEach((e, t) => {
			e.forEach((e, n) => {
				r(t, n);
			});
		}), Object.entries(f.current).forEach(([e, t]) => {
			t.forEach((t) => r(Number(e), t));
		}), n.forEach((e, n) => {
			e.forEach((e) => {
				M(t.elementIndex.get(e), n, e, h(n, e), m.current);
			});
		});
	}, [e, h]), A = n(() => {
		e.buildIndex().records.forEach((e) => {
			m.current.delete(e), k(e);
		}), m.current = /* @__PURE__ */ new WeakMap(), d.current.clear(), O();
	}, [O, e]);
	return {
		colorPaletteTexture: s,
		colorUtils: a(() => ({
			applyStoredColors: O,
			clearAllColors: A,
			clearColor: E,
			clearModelColors: D,
			rebuildByColors: x,
			rebuildModelByColors: b,
			setColor: y
		}), [
			O,
			A,
			E,
			D,
			x,
			b,
			y
		])
	};
}
e.BRDF_GGX, e.BRDF_Lambert, e.BasicPointShadowFilter, e.BasicShadowFilter, e.Break, e.Const, e.Continue, e.DFGLUT, e.D_GGX, e.Discard, e.EPSILON, e.F_Schlick, e.Fn, e.INFINITY, e.If, e.Loop, e.NodeAccess, e.NodeShaderStage, e.NodeType, e.NodeUpdateType, e.PCFShadowFilter, e.PCFSoftShadowFilter, e.PI, e.PI2, e.TWO_PI, e.HALF_PI, e.PointShadowFilter, e.Return, e.Schlick_to_F0, e.ShaderNode, e.Stack, e.Switch, e.TBNViewMatrix, e.VSMShadowFilter, e.V_GGX_SmithCorrelated, e.Var, e.VarIntent;
var L = e.abs;
e.acesFilmicToneMapping, e.acos, e.acosh, e.add, e.addMethodChaining, e.addNodeElement, e.agxToneMapping, e.all, e.alphaT, e.and, e.anisotropy, e.anisotropyB, e.anisotropyT, e.any, e.append, e.array, e.arrayBuffer, e.asin, e.asinh, e.assign, e.atan, e.atanh, e.atomicAdd, e.atomicAnd, e.atomicFunc, e.atomicLoad, e.atomicMax, e.atomicMin, e.atomicOr, e.atomicStore, e.atomicSub, e.atomicXor, e.attenuationColor, e.attenuationDistance;
var R = e.attribute;
e.attributeArray, e.backgroundBlurriness, e.backgroundIntensity, e.backgroundRotation, e.batch, e.bentNormalView, e.billboarding, e.bitAnd, e.bitNot, e.bitOr, e.bitXor, e.bitangentGeometry, e.bitangentLocal, e.bitangentView, e.bitangentWorld, e.bitcast, e.blendBurn, e.blendColor, e.blendDodge, e.blendOverlay, e.blendScreen, e.blur, e.bool, e.buffer, e.bufferAttribute, e.bumpMap, e.builtin, e.builtinAOContext, e.builtinShadowContext, e.bvec2, e.bvec3, e.bvec4, e.bypass, e.cache, e.call, e.cameraFar, e.cameraIndex, e.cameraNear, e.cameraNormalMatrix, e.cameraPosition, e.cameraProjectionMatrix, e.cameraProjectionMatrixInverse, e.cameraViewMatrix, e.cameraViewport, e.cameraWorldMatrix, e.cbrt, e.cdl, e.ceil, e.checker, e.cineonToneMapping, e.clamp, e.clearcoat, e.clearcoatNormalView, e.clearcoatRoughness, e.clipSpace, e.code, e.color, e.colorSpaceToWorking, e.colorToDirection, e.compute, e.computeKernel, e.computeSkinning, e.context, e.convert, e.convertColorSpace, e.convertToTexture, e.countLeadingZeros, e.countOneBits, e.countTrailingZeros, e.cos, e.cosh, e.cross, e.cubeTexture, e.cubeTextureBase, e.dFdx, e.dFdy, e.dashSize, e.debug, e.decrement, e.decrementBefore, e.defaultBuildStages, e.defaultShaderStages, e.defined, e.degrees, e.deltaTime, e.densityFog, e.densityFogFactor, e.depth, e.depthPass, e.determinant, e.difference, e.diffuseColor, e.directPointLight, e.directionToColor, e.directionToFaceDirection, e.dispersion, e.distance, e.div, e.dot, e.drawIndex, e.dynamicBufferAttribute, e.element, e.emissive, e.equal, e.equirectUV, e.exp, e.exp2, e.exponentialHeightFogFactor, e.expression, e.faceDirection, e.faceForward, e.faceforward;
var z = e.float;
e.floatBitsToInt, e.floatBitsToUint, e.floor, e.fog, e.fract, e.frameGroup, e.frameId, e.frontFacing, e.fwidth, e.gain, e.gapSize, e.getConstNodeType, e.getCurrentStack, e.getDirection, e.getDistanceAttenuation, e.getGeometryRoughness, e.getNormalFromDepth, e.interleavedGradientNoise, e.vogelDiskSample, e.getParallaxCorrectNormal, e.getRoughness, e.getScreenPosition, e.getShIrradianceAt, e.getShadowMaterial, e.getShadowRenderObjectFunction, e.getTextureIndex, e.getViewPosition, e.globalId, e.glsl, e.glslFn, e.grayscale, e.greaterThan, e.greaterThanEqual, e.hash, e.highpModelNormalViewMatrix, e.highpModelViewMatrix, e.hue, e.increment, e.incrementBefore, e.instance, e.instanceIndex, e.instancedArray, e.instancedBufferAttribute, e.instancedDynamicBufferAttribute, e.instancedMesh, e.int, e.intBitsToFloat, e.inverse, e.inverseSqrt, e.inversesqrt, e.invocationLocalIndex, e.invocationSubgroupIndex, e.ior, e.iridescence, e.iridescenceIOR, e.iridescenceThickness, e.ivec2, e.ivec3, e.ivec4, e.js, e.label, e.length, e.lengthSq, e.lessThan, e.lessThanEqual, e.lightPosition, e.lightProjectionUV, e.lightShadowMatrix, e.lightTargetDirection, e.lightTargetPosition, e.lightViewPosition, e.lightingContext, e.lights, e.linearDepth, e.linearToneMapping, e.localId, e.log, e.log2, e.logarithmicDepthToViewZ, e.luminance, e.mat2, e.mat3, e.mat4, e.matcapUV, e.materialAO, e.materialAlphaTest, e.materialAnisotropy, e.materialAnisotropyVector, e.materialAttenuationColor, e.materialAttenuationDistance, e.materialClearcoat, e.materialClearcoatNormal, e.materialClearcoatRoughness, e.materialColor, e.materialDispersion, e.materialEmissive, e.materialEnvIntensity, e.materialEnvRotation, e.materialIOR, e.materialIridescence, e.materialIridescenceIOR, e.materialIridescenceThickness, e.materialLightMap, e.materialLineDashOffset, e.materialLineDashSize, e.materialLineGapSize, e.materialLineScale, e.materialLineWidth, e.materialMetalness, e.materialNormal, e.materialOpacity, e.materialPointSize, e.materialReference, e.materialReflectivity, e.materialRefractionRatio, e.materialRotation, e.materialRoughness, e.materialSheen, e.materialSheenRoughness, e.materialShininess, e.materialSpecular, e.materialSpecularColor, e.materialSpecularIntensity, e.materialSpecularStrength, e.materialThickness, e.materialTransmission, e.max, e.maxMipLevel, e.mediumpModelViewMatrix, e.metalness, e.min, e.mix, e.mixElement, e.mod, e.modInt, e.modelDirection, e.modelNormalMatrix, e.modelPosition, e.modelRadius, e.modelScale, e.modelViewMatrix, e.modelViewPosition, e.modelViewProjection, e.modelWorldMatrix, e.modelWorldMatrixInverse, e.morphReference, e.mrt, e.mul, e.mx_aastep, e.mx_add, e.mx_atan2, e.mx_cell_noise_float, e.mx_contrast, e.mx_divide, e.mx_fractal_noise_float, e.mx_fractal_noise_vec2, e.mx_fractal_noise_vec3, e.mx_fractal_noise_vec4, e.mx_frame, e.mx_heighttonormal, e.mx_hsvtorgb, e.mx_ifequal, e.mx_ifgreater, e.mx_ifgreatereq, e.mx_invert, e.mx_modulo, e.mx_multiply, e.mx_noise_float, e.mx_noise_vec3, e.mx_noise_vec4, e.mx_place2d, e.mx_power, e.mx_ramp4, e.mx_ramplr, e.mx_ramptb, e.mx_rgbtohsv, e.mx_rotate2d, e.mx_rotate3d, e.mx_safepower, e.mx_separate, e.mx_splitlr, e.mx_splittb, e.mx_srgb_texture_to_lin_rec709, e.mx_subtract, e.mx_timer, e.mx_transform_uv, e.mx_unifiednoise2d, e.mx_unifiednoise3d, e.mx_worley_noise_float, e.mx_worley_noise_vec2, e.mx_worley_noise_vec3, e.negate, e.neutralToneMapping, e.nodeArray, e.nodeImmutable, e.nodeObject, e.nodeObjectIntent, e.nodeObjects, e.nodeProxy, e.nodeProxyIntent, e.normalFlat, e.normalGeometry, e.normalLocal, e.normalMap, e.normalView, e.normalViewGeometry, e.normalWorld, e.normalWorldGeometry, e.normalize, e.not, e.notEqual, e.numWorkgroups, e.objectDirection, e.objectGroup, e.objectPosition, e.objectRadius, e.objectScale, e.objectViewPosition, e.objectWorldMatrix, e.OnBeforeObjectUpdate, e.OnBeforeMaterialUpdate, e.OnObjectUpdate, e.OnMaterialUpdate, e.oneMinus, e.or, e.orthographicDepthToViewZ, e.oscSawtooth, e.oscSine, e.oscSquare, e.oscTriangle, e.output, e.outputStruct, e.overloadingFn, e.packHalf2x16, e.packSnorm2x16, e.packUnorm2x16, e.parabola, e.parallaxDirection, e.parallaxUV, e.parameter, e.pass, e.passTexture, e.pcurve, e.perspectiveDepthToViewZ, e.pmremTexture, e.pointShadow, e.pointUV, e.pointWidth, e.positionGeometry, e.positionLocal, e.positionPrevious, e.positionView, e.positionViewDirection, e.positionWorld, e.positionWorldDirection, e.posterize, e.pow, e.pow2, e.pow3, e.pow4, e.premultiplyAlpha, e.property, e.radians, e.rand, e.range, e.rangeFog, e.rangeFogFactor, e.reciprocal, e.reference, e.referenceBuffer, e.reflect, e.reflectVector, e.reflectView, e.reflector, e.refract, e.refractVector, e.refractView, e.reinhardToneMapping, e.remap, e.remapClamp, e.renderGroup, e.renderOutput, e.rendererReference, e.replaceDefaultUV, e.rotate, e.rotateUV, e.roughness, e.round, e.rtt, e.sRGBTransferEOTF, e.sRGBTransferOETF, e.sample, e.sampler, e.samplerComparison, e.saturate, e.saturation, e.screen, e.screenCoordinate, e.screenDPR, e.screenSize, e.screenUV, e.select, e.setCurrentStack, e.setName, e.shaderStages, e.shadow, e.shadowPositionWorld, e.shapeCircle, e.sharedUniformGroup, e.sheen, e.sheenRoughness, e.shiftLeft, e.shiftRight, e.shininess, e.sign, e.sin, e.sinh, e.sinc, e.skinning, e.smoothstep, e.smoothstepElement, e.specularColor, e.specularF90, e.spherizeUV, e.split, e.spritesheetUV, e.sqrt, e.stack, e.step, e.stepElement, e.storage, e.storageBarrier, e.storageTexture, e.string, e.struct, e.sub, e.subgroupAdd, e.subgroupAll, e.subgroupAnd, e.subgroupAny, e.subgroupBallot, e.subgroupBroadcast, e.subgroupBroadcastFirst, e.subBuild, e.subgroupElect, e.subgroupExclusiveAdd, e.subgroupExclusiveMul, e.subgroupInclusiveAdd, e.subgroupInclusiveMul, e.subgroupIndex, e.subgroupMax, e.subgroupMin, e.subgroupMul, e.subgroupOr, e.subgroupShuffle, e.subgroupShuffleDown, e.subgroupShuffleUp, e.subgroupShuffleXor, e.subgroupSize, e.subgroupXor, e.tan, e.tanh, e.tangentGeometry, e.tangentLocal, e.tangentView, e.tangentWorld;
var B = e.texture;
e.texture3D, e.textureBarrier, e.textureBicubic, e.textureBicubicLevel, e.textureCubeUV, e.textureLoad, e.textureSize, e.textureLevel, e.textureStore, e.thickness, e.time, e.toneMapping, e.toneMappingExposure, e.toonOutlinePass, e.transformDirection, e.transformNormal, e.transformNormalToView, e.transformedClearcoatNormalView, e.transformedNormalView, e.transformedNormalWorld, e.transmission, e.transpose, e.triNoise3D, e.triplanarTexture, e.triplanarTextures, e.trunc, e.uint, e.uintBitsToFloat;
var V = e.uniform;
e.uniformArray, e.uniformCubeTexture, e.uniformGroup, e.uniformFlow, e.uniformTexture, e.unpackHalf2x16, e.unpackSnorm2x16, e.unpackUnorm2x16, e.unpremultiplyAlpha, e.userData;
var H = e.uv;
e.uvec2, e.uvec3, e.uvec4, e.varying, e.varyingProperty;
var U = e.vec2;
e.vec3, e.vec4, e.vectorComponents, e.velocity, e.vertexColor, e.vertexIndex, e.vertexStage, e.vibrance, e.viewZToLogarithmicDepth, e.viewZToOrthographicDepth, e.viewZToPerspectiveDepth, e.viewZToReversedOrthographicDepth, e.viewZToReversedPerspectiveDepth, e.viewport, e.viewportCoordinate, e.viewportDepthTexture, e.viewportLinearDepth, e.viewportMipTexture, e.viewportOpaqueMipTexture, e.viewportResolution, e.viewportSafeUV, e.viewportSharedTexture, e.viewportSize, e.viewportTexture, e.viewportUV, e.wgsl, e.wgslFn, e.workgroupArray, e.workgroupBarrier, e.workgroupId, e.workingToColorSpace, e.xor;
//#endregion
export { V as a, I as c, _ as d, h as f, B as i, x as l, R as n, H as o, z as r, U as s, L as t, g as u };
