aptechka 0.17.0 → 0.18.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aptechka",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/denisavitski/aptechka.git"
@@ -78,11 +78,6 @@
78
78
  "default": "./lib/element-resizer/index.js",
79
79
  "types": "./lib/element-resizer/index.d.ts"
80
80
  },
81
- "./en3": {
82
- "require": "./lib/en3/index.cjs",
83
- "default": "./lib/en3/index.js",
84
- "types": "./lib/en3/index.d.ts"
85
- },
86
81
  "./image": {
87
82
  "require": "./lib/image/index.cjs",
88
83
  "default": "./lib/image/index.js",
@@ -230,24 +225,6 @@
230
225
  "element-resizer": [
231
226
  "lib/element-resizer/index.d.ts"
232
227
  ],
233
- "en3": [
234
- "lib/en3/index.d.ts"
235
- ],
236
- "en3/helpers": [
237
- "lib/en3/helpers/index.d.ts"
238
- ],
239
- "en3/libs": [
240
- "lib/en3/libs/index.d.ts"
241
- ],
242
- "en3/loaders": [
243
- "lib/en3/loaders/index.d.ts"
244
- ],
245
- "en3/misc": [
246
- "lib/en3/misc/index.d.ts"
247
- ],
248
- "en3/utils": [
249
- "lib/en3/utils/index.d.ts"
250
- ],
251
228
  "image": [
252
229
  "lib/image/index.d.ts"
253
230
  ],
@@ -321,18 +298,15 @@
321
298
  },
322
299
  "devDependencies": {
323
300
  "@types/node": "^22.2.0",
324
- "@types/three": "^0.167.1",
325
301
  "tsx": "^4.17.0",
326
302
  "vite": "5.4.0",
327
303
  "vite-plugin-dts": "^4.0.2",
328
304
  "vite-plugin-htmc": "^0.1.14"
329
305
  },
330
306
  "dependencies": {
331
- "detect-gpu": "^5.0.42",
332
- "three": "^0.167.1"
307
+ "detect-gpu": "^5.0.42"
333
308
  },
334
309
  "peerDependencies": {
335
- "detect-gpu": "^5.0.42",
336
- "three": "^0.167.1"
310
+ "detect-gpu": "^5.0.42"
337
311
  }
338
312
  }
@@ -1,20 +0,0 @@
1
- import { Intersection, Object3D } from 'three';
2
- export type En3RaycasterEventType = 'pointerDown' | 'pointerUp' | 'pointerMove' | 'pointerLeave' | 'pointerEnter' | 'pointerMove';
3
- export type En3RaycasterEvent = {
4
- type: En3RaycasterEventType;
5
- originalEvent: PointerEvent;
6
- target: Object3D;
7
- } & Intersection<Object3D>;
8
- export interface En3RaycasterOptions {
9
- targetName?: string;
10
- eventDispatcher?: Object3D;
11
- propagation?: boolean;
12
- }
13
- export type En3RaycasterCallback = (event: En3RaycasterEvent) => void;
14
- export declare class En3Raycaster {
15
- #private;
16
- constructor();
17
- destroy(): void;
18
- add(object3D: Object3D, options?: En3RaycasterOptions): void;
19
- remove(object3D: Object3D): void;
20
- }
@@ -1,39 +0,0 @@
1
- import { LayoutBox, LayoutBoxOptions } from '../layout-box';
2
- import { ElementOrSelector } from '../utils';
3
- import { Object3D, OrthographicCamera, PerspectiveCamera, Scene } from 'three';
4
- export interface En3ViewOptions {
5
- cameraType?: 'perspective' | 'orthographic';
6
- cameraDistance?: number;
7
- cameraNear?: number;
8
- cameraFar?: number;
9
- cameraFov?: 'auto' | number;
10
- sizeElement?: ElementOrSelector<HTMLElement>;
11
- beforeRender?: () => void;
12
- }
13
- export type En3AttachedObject3D<T extends Object3D> = T & {
14
- userData: {
15
- box: LayoutBox;
16
- };
17
- };
18
- export type En3AttachOptions = Omit<LayoutBoxOptions, 'containerElement' | 'cartesian' | 'scrollStep'>;
19
- export type En3ViewBeforeRenderCallback = () => void;
20
- export declare class En3View {
21
- #private;
22
- beforeRenderCallback: En3ViewBeforeRenderCallback | undefined;
23
- constructor(name: string, options?: En3ViewOptions);
24
- get name(): string;
25
- get camera(): PerspectiveCamera | OrthographicCamera;
26
- get scene(): Scene;
27
- get box(): LayoutBox;
28
- get cameraDistance(): number;
29
- set cameraDistance(value: number);
30
- get sizeElement(): HTMLElement;
31
- get isClipped(): boolean;
32
- resize(): void;
33
- destroy(): void;
34
- attachToHTMLElement<T extends Object3D>(element: ElementOrSelector<HTMLElement>, object: T, options?: En3AttachOptions): En3AttachedObject3D<T>;
35
- detachFromHTMLElement(object: Object3D): void;
36
- add<T extends Object3D<any>>(object: T): T;
37
- add<T extends Object3D<any>>(object: T, element: ElementOrSelector<HTMLElement>, options?: En3AttachOptions): En3AttachedObject3D<T>;
38
- remove(object: Object3D, detach?: boolean): void;
39
- }
package/lib/en3/en3.d.ts DELETED
@@ -1,36 +0,0 @@
1
- import { ElementOrSelector } from '../utils';
2
- import { WebGLRenderer, WebGLRendererParameters } from 'three';
3
- import { En3View, En3ViewOptions } from './En3View';
4
- import { En3Raycaster } from './En3Raycaster';
5
- import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
6
- export interface En3Options {
7
- webGLRendererParameters?: WebGLRendererParameters;
8
- maxPixelRatio?: number;
9
- containerElement?: ElementOrSelector<HTMLElement>;
10
- view?: En3ViewOptions;
11
- zIndex?: number;
12
- composer?: typeof EffectComposer;
13
- }
14
- declare class En3 {
15
- #private;
16
- get CDNVersion(): string;
17
- get containerElement(): HTMLElement;
18
- get webglRenderer(): WebGLRenderer;
19
- get raycaster(): En3Raycaster;
20
- get views(): Map<string, En3View>;
21
- get view(): En3View;
22
- get camera(): import('three').PerspectiveCamera | import('three').OrthographicCamera;
23
- get scene(): import('three').Scene;
24
- get width(): number;
25
- get height(): number;
26
- get pixelRatio(): number;
27
- get composer(): EffectComposer;
28
- setup(options?: En3Options): void;
29
- destroy(): void;
30
- createView(viewName: string, viewOptions?: En3ViewOptions): En3View;
31
- getView(viewName: string): En3View;
32
- destroyView(viewName: string): void;
33
- render(view: En3View): void;
34
- }
35
- export declare const en3: En3;
36
- export {};
package/lib/en3/index.cjs DELETED
@@ -1,8 +0,0 @@
1
- "use strict";var ue=Object.defineProperty,me=Object.defineProperties;var fe=Object.getOwnPropertyDescriptors;var J=Object.getOwnPropertySymbols;var ge=Object.prototype.hasOwnProperty,Ee=Object.prototype.propertyIsEnumerable;var ee=s=>{throw TypeError(s)};var Q=(s,e,i)=>e in s?ue(s,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):s[e]=i,A=(s,e)=>{for(var i in e||(e={}))ge.call(e,i)&&Q(s,i,e[i]);if(J)for(var i of J(e))Ee.call(e,i)&&Q(s,i,e[i]);return s},te=(s,e)=>me(s,fe(e));var ie=(s,e,i)=>e.has(s)||ee("Cannot "+i);var t=(s,e,i)=>(ie(s,e,"read from private field"),i?i.call(s):e.get(s)),r=(s,e,i)=>e.has(s)?ee("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,i),n=(s,e,i,a)=>(ie(s,e,"write to private field"),a?a.call(s,i):e.set(s,i),i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const se=require("../order/index.cjs"),re=require("../window-resizer/index.cjs"),ne=require("../ticker/index.cjs"),he=require("../dom-JBOkFLTh.cjs"),u=require("three"),ae=require("../layout-box/index.cjs");function ce(s){const e=i=>{i.dispose();for(const a of Object.keys(i)){const h=i[a];h&&typeof h=="object"&&"minFilter"in h&&h.dispose()}};s.traverse(i=>{if(i instanceof u.Mesh){if(i.geometry.dispose(),!Array.isArray(i.material)&&i.material.isMaterial)e(i.material);else if(Array.isArray(i.material))for(const a of i.material)e(a)}})}var P,o,V,v,w,O,D,R;class X{constructor(e,i){r(this,P);r(this,o);r(this,V);r(this,v);r(this,w);r(this,O);r(this,D);r(this,R);n(this,P,e),n(this,o,(i==null?void 0:i.cameraType)==="orthographic"?new u.OrthographicCamera:new u.PerspectiveCamera),n(this,V,new u.Scene),n(this,v,[]),n(this,w,(i==null?void 0:i.cameraDistance)||1e3),t(this,o).near=(i==null?void 0:i.cameraNear)||1,t(this,o).far=(i==null?void 0:i.cameraFar)||11e3,n(this,O,(i==null?void 0:i.cameraFov)||"auto"),t(this,o).position.z=t(this,w),t(this,o).name=`Cameras.${t(this,P)}`,n(this,D,he.getElement(i==null?void 0:i.sizeElement)||document.documentElement),this.beforeRenderCallback=i==null?void 0:i.beforeRender,n(this,R,new ae.LayoutBox(t(this,D))),t(this,R).onResize(()=>{this.resize()})}get name(){return t(this,P)}get camera(){return t(this,o)}get scene(){return t(this,V)}get box(){return t(this,R)}get cameraDistance(){return t(this,w)}set cameraDistance(e){n(this,w,e),this.resize()}get sizeElement(){return t(this,D)}get isClipped(){return t(this,D)!==d.containerElement}resize(){const{width:e,height:i}=t(this,R);t(this,o).userData.controlled||(t(this,o).position.z=t(this,w)),t(this,o)instanceof u.PerspectiveCamera?(t(this,o).aspect=e/i,t(this,o).fov=t(this,O)==="auto"?2*Math.atan(i/2/t(this,w))*(180/Math.PI):t(this,o).userData.controlled?t(this,o).fov:t(this,O)):t(this,o)instanceof u.OrthographicCamera&&(t(this,o).left=e/-2,t(this,o).right=e/2,t(this,o).top=i/2,t(this,o).bottom=i/-2),t(this,o).updateProjectionMatrix()}destroy(){t(this,v).forEach(e=>{e.userData.box.destroy()}),t(this,V).clear(),ce(t(this,V)),d.destroyView(this.name),t(this,R).destroy()}attachToHTMLElement(e,i,a){const h=new ae.LayoutBox(e,te(A({},a),{containerElement:t(this,D),cartesian:!0,scrollStep:!this.isClipped}));return h.bindObject(i),i.userData.box=h,t(this,v).push(i),i}detachFromHTMLElement(e){n(this,v,t(this,v).filter(i=>i===e?(e.userData.box.destroy(),!1):!0))}add(...e){const i=e[0],a=e[1],h=e[2];return a&&this.attachToHTMLElement(a,i,h),this.scene.add(i),i}remove(e,i){this.scene.remove(e),i&&this.detachFromHTMLElement(e)}}P=new WeakMap,o=new WeakMap,V=new WeakMap,v=new WeakMap,w=new WeakMap,O=new WeakMap,D=new WeakMap,R=new WeakMap;var H,F,I,z,N;class xe{constructor(e){r(this,H);r(this,F);r(this,I);r(this,z);r(this,N);n(this,H,e.targetName||void 0),n(this,F,e.eventDispatcher||e.object3D),n(this,I,e.propagation||!1),n(this,z,e.object3D),n(this,N,t(this,H)?()=>t(this,z).getObjectByName(t(this,H))||t(this,z):()=>t(this,z))}get object3D(){return t(this,z)}get eventDispatcher(){return t(this,F)}get propagation(){return t(this,I)}get target(){return t(this,N).call(this)}dispatch(e,i){this.eventDispatcher.dispatchEvent(A({originalEvent:i,type:e},this.intersection))}}H=new WeakMap,F=new WeakMap,I=new WeakMap,z=new WeakMap,N=new WeakMap;var y,m,j,_,q,B,W;class ye{constructor(){r(this,y,[]);r(this,m,[]);r(this,j,new u.Vector2);r(this,_,new u.Raycaster);r(this,q,e=>{for(let i=0;i<t(this,m).length;i++)t(this,m)[i].dispatch("pointerDown",e)});r(this,B,e=>{for(let i=0;i<t(this,m).length;i++)t(this,m)[i].dispatch("pointerUp",e)});r(this,W,e=>{if(!t(this,y).length)return;t(this,j).x=e.clientX/d.width*2-1,t(this,j).y=-(e.clientY/d.height)*2+1,d.camera&&t(this,_).setFromCamera(t(this,j),d.camera);const i=[];for(const c of t(this,y)){const f=t(this,_).intersectObject(c.target);f.length&&(c.intersection=f[0],i.push(c))}let a=!1;const h=t(this,m).filter(c=>!i.find(f=>f.object3D.uuid===c.object3D.uuid)),x=i.sort((c,f)=>f.object3D.position.z-c.object3D.position.z).filter((c,f)=>a?(h.push(c),!1):(a=!c.propagation,!0)),p=x.filter(c=>!t(this,m).find(f=>f.object3D.uuid===c.object3D.uuid));for(let c=0;c<h.length;c++)h[c].dispatch("pointerLeave",e);for(let c=0;c<p.length;c++)p[c].dispatch("pointerEnter",e);n(this,m,x);for(let c=0;c<t(this,m).length;c++)t(this,m)[c].dispatch("pointerMove",e)});d.containerElement.addEventListener("pointerdown",t(this,q)),d.containerElement.addEventListener("pointerup",t(this,B)),d.containerElement.addEventListener("pointermove",t(this,W))}destroy(){d.containerElement.removeEventListener("pointerdown",t(this,q)),d.containerElement.removeEventListener("pointerup",t(this,B)),d.containerElement.removeEventListener("pointermove",t(this,W)),n(this,y,[]),n(this,m,[])}add(e,i){if(t(this,y).find(h=>h.object3D.uuid===e.uuid))return;const a=new xe(A({object3D:e},i));t(this,y).push(a)}remove(e){n(this,y,t(this,y).filter(i=>i.object3D.uuid!==e.uuid)),n(this,m,t(this,m).filter(i=>i.object3D.uuid!==e.uuid))}}y=new WeakMap,m=new WeakMap,j=new WeakMap,_=new WeakMap,q=new WeakMap,B=new WeakMap,W=new WeakMap;var U,b,l,k,g,T,C,L,Y,S,Z,E,$,G;class be{constructor(){r(this,U,`https://unpkg.com/three@0.${u.REVISION}.x`);r(this,b,null);r(this,l,null);r(this,k,null);r(this,g,new Map);r(this,T,0);r(this,C,0);r(this,L,0);r(this,Y,2);r(this,S,!1);r(this,Z,!1);r(this,E,null);r(this,$,()=>{n(this,T,t(this,b).clientWidth),n(this,C,t(this,b).clientHeight),n(this,L,Math.min(t(this,Y),devicePixelRatio||1)),t(this,l).setPixelRatio(t(this,L)),t(this,l).setSize(t(this,T),t(this,C)),t(this,E)&&(t(this,E).setPixelRatio(t(this,L)),t(this,E).setSize(t(this,T),t(this,C)))});r(this,G,()=>{t(this,l).setRenderTarget(null),t(this,g).forEach(e=>{this.render(e)})})}get CDNVersion(){return t(this,U)}get containerElement(){return t(this,b)}get webglRenderer(){return t(this,l)}get raycaster(){return t(this,k)}get views(){return t(this,g)}get view(){return this.getView("default")}get camera(){return this.getView("default").camera}get scene(){return this.getView("default").scene}get width(){return t(this,T)}get height(){return t(this,C)}get pixelRatio(){return t(this,L)}get composer(){return t(this,E)}setup(e){if(t(this,S)){console.warn("[en3.setup]: You are trying to setup en3 again.");return}n(this,b,he.getElement(e==null?void 0:e.containerElement)||document.body),n(this,Y,(e==null?void 0:e.maxPixelRatio)||2),n(this,l,new u.WebGLRenderer(e==null?void 0:e.webGLRendererParameters)),t(this,l).domElement.style.cssText=`
2
- position: fixed;
3
- left: 0;
4
- top: 0;
5
- width: 100%;
6
- height: 100%;
7
- z-index: ${(e==null?void 0:e.zIndex)||0};
8
- `,(t(this,b).shadowRoot||t(this,b)).append(t(this,l).domElement),t(this,g).set("default",new X("default",A({sizeElement:t(this,b)},e==null?void 0:e.view))),n(this,k,new ye),e!=null&&e.composer&&(n(this,E,new e.composer(t(this,l))),this.render=()=>{t(this,E).render()}),n(this,S,!0),re.windowResizer.subscribe(t(this,$),se.RESIZE_ORDER.EN3),ne.ticker.subscribe(t(this,G),{order:se.TICK_ORDER.EN3})}destroy(){if(!t(this,S)){console.warn("[en3.setup]: You are trying to destory en3 but it has not been initialized.");return}re.windowResizer.unsubscribe(t(this,$)),ne.ticker.unsubscribe(t(this,G)),t(this,k).destroy(),t(this,g).forEach(e=>{e.destroy()}),t(this,l).dispose(),t(this,l).domElement.remove(),n(this,l,null),t(this,E).dispose(),n(this,E,null),n(this,S,!1)}createView(e,i){const a=t(this,g).size,h=new X(e,i);return t(this,g).set(e,h),a===1&&t(this,l).setScissorTest(!0),h}getView(e){return t(this,g).get(e)}destroyView(e){const i=t(this,g).get(e);i&&(t(this,g).delete(e),i.destroy(),t(this,g).size<=1&&t(this,l).setScissorTest(!1))}render(e){var i;if(t(this,g).size>1||this.view.isClipped){const a=e.box.left+e.box.CSSTranslation.x+e.box.scrollValue.x,h=d.height-e.box.height-e.box.top+e.box.CSSTranslation.y+e.box.scrollValue.y*-1;t(this,l).setScissor(a,h,e.box.width,e.box.height),t(this,l).setViewport(a,h,e.box.width,e.box.height)}(i=e.beforeRenderCallback)==null||i.call(e),t(this,l).render(e.scene,e.camera)}}U=new WeakMap,b=new WeakMap,l=new WeakMap,k=new WeakMap,g=new WeakMap,T=new WeakMap,C=new WeakMap,L=new WeakMap,Y=new WeakMap,S=new WeakMap,Z=new WeakMap,E=new WeakMap,$=new WeakMap,G=new WeakMap;const d=new be;function we(s,e,i){const a=e.x,h=e.y,M=i||s.image.width/s.image.height;let x=0,p=0,c=s.offset.x,f=s.offset.y,oe=s.rotation,le=s.center.x,de=s.center.y;a/h>M?(x=1,p=h/a*M):(p=1,x=a/h/M),s.matrix.setUvTransform(c,f,x,p,oe,le,de)}const K=new u.Vector3,pe=new u.Vector3;function ve(s,e="default"){const i=d.getView(e),{width:a,height:h}=d,M=a/h;s instanceof u.Vector3?K.copy(s):K.set(...s);const x=i.camera.getWorldPosition(pe).distanceTo(K);if(i.camera instanceof u.OrthographicCamera)return{width:a/i.camera.zoom,height:h/i.camera.zoom,factor:1,distance:x,aspect:M};{const p=i.camera.fov*Math.PI/180,c=2*Math.tan(p/2)*x,f=c*(a/h);return{width:f,height:c,factor:a/f,distance:x,aspect:M}}}function De(s,e){s.traverse(i=>{i instanceof u.Mesh&&i.material&&(Array.isArray(i.material)?i.material:[i.material]).forEach(e)})}function Re(s,e){s.traverse(i=>{i instanceof u.Mesh&&e(i)})}exports.En3View=X;exports.coverTexture=we;exports.dispose=ce;exports.en3=d;exports.getCurrentViewport=ve;exports.traverseMaterials=De;exports.traverseMeshes=Re;
@@ -1,7 +0,0 @@
1
- export { en3 } from './en3';
2
- export { En3View, type En3ViewOptions, type En3AttachedObject3D, type En3AttachOptions, type En3ViewBeforeRenderCallback, } from './En3View';
3
- export { coverTexture } from './utils/coverTexture';
4
- export { dispose } from './utils/dispose';
5
- export { getCurrentViewport } from './utils/getCurrentViewport';
6
- export { traverseMaterials } from './utils/traverseMaterials';
7
- export { traverseMeshes } from './utils/traverseMeshes';
package/lib/en3/index.js DELETED
@@ -1,374 +0,0 @@
1
- var me = Object.defineProperty, fe = Object.defineProperties;
2
- var ge = Object.getOwnPropertyDescriptors;
3
- var Q = Object.getOwnPropertySymbols;
4
- var Ee = Object.prototype.hasOwnProperty, be = Object.prototype.propertyIsEnumerable;
5
- var te = (s) => {
6
- throw TypeError(s);
7
- };
8
- var ee = (s, e, i) => e in s ? me(s, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : s[e] = i, k = (s, e) => {
9
- for (var i in e || (e = {}))
10
- Ee.call(e, i) && ee(s, i, e[i]);
11
- if (Q)
12
- for (var i of Q(e))
13
- be.call(e, i) && ee(s, i, e[i]);
14
- return s;
15
- }, ie = (s, e) => fe(s, ge(e));
16
- var se = (s, e, i) => e.has(s) || te("Cannot " + i);
17
- var t = (s, e, i) => (se(s, e, "read from private field"), i ? i.call(s) : e.get(s)), r = (s, e, i) => e.has(s) ? te("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(s) : e.set(s, i), a = (s, e, i, h) => (se(s, e, "write to private field"), h ? h.call(s, i) : e.set(s, i), i);
18
- import { RESIZE_ORDER as ye, TICK_ORDER as xe } from "../order/index.js";
19
- import { windowResizer as re } from "../window-resizer/index.js";
20
- import { ticker as ae } from "../ticker/index.js";
21
- import { g as oe } from "../dom-0S_WDL4g.js";
22
- import { Mesh as q, OrthographicCamera as X, PerspectiveCamera as he, Scene as we, Vector2 as pe, Raycaster as De, REVISION as Re, WebGLRenderer as ve, Vector3 as J } from "three";
23
- import { LayoutBox as ne } from "../layout-box/index.js";
24
- function ze(s) {
25
- const e = (i) => {
26
- i.dispose();
27
- for (const h of Object.keys(i)) {
28
- const n = i[h];
29
- n && typeof n == "object" && "minFilter" in n && n.dispose();
30
- }
31
- };
32
- s.traverse((i) => {
33
- if (i instanceof q) {
34
- if (i.geometry.dispose(), !Array.isArray(i.material) && i.material.isMaterial)
35
- e(i.material);
36
- else if (Array.isArray(i.material))
37
- for (const h of i.material) e(h);
38
- }
39
- });
40
- }
41
- var S, o, L, p, x, P, D, R;
42
- class ce {
43
- constructor(e, i) {
44
- r(this, S);
45
- r(this, o);
46
- r(this, L);
47
- r(this, p);
48
- r(this, x);
49
- r(this, P);
50
- r(this, D);
51
- r(this, R);
52
- a(this, S, e), a(this, o, (i == null ? void 0 : i.cameraType) === "orthographic" ? new X() : new he()), a(this, L, new we()), a(this, p, []), a(this, x, (i == null ? void 0 : i.cameraDistance) || 1e3), t(this, o).near = (i == null ? void 0 : i.cameraNear) || 1, t(this, o).far = (i == null ? void 0 : i.cameraFar) || 11e3, a(this, P, (i == null ? void 0 : i.cameraFov) || "auto"), t(this, o).position.z = t(this, x), t(this, o).name = `Cameras.${t(this, S)}`, a(this, D, oe(i == null ? void 0 : i.sizeElement) || document.documentElement), this.beforeRenderCallback = i == null ? void 0 : i.beforeRender, a(this, R, new ne(t(this, D))), t(this, R).onResize(() => {
53
- this.resize();
54
- });
55
- }
56
- get name() {
57
- return t(this, S);
58
- }
59
- get camera() {
60
- return t(this, o);
61
- }
62
- get scene() {
63
- return t(this, L);
64
- }
65
- get box() {
66
- return t(this, R);
67
- }
68
- get cameraDistance() {
69
- return t(this, x);
70
- }
71
- set cameraDistance(e) {
72
- a(this, x, e), this.resize();
73
- }
74
- get sizeElement() {
75
- return t(this, D);
76
- }
77
- get isClipped() {
78
- return t(this, D) !== u.containerElement;
79
- }
80
- resize() {
81
- const { width: e, height: i } = t(this, R);
82
- t(this, o).userData.controlled || (t(this, o).position.z = t(this, x)), t(this, o) instanceof he ? (t(this, o).aspect = e / i, t(this, o).fov = t(this, P) === "auto" ? 2 * Math.atan(i / 2 / t(this, x)) * (180 / Math.PI) : t(this, o).userData.controlled ? t(this, o).fov : t(this, P)) : t(this, o) instanceof X && (t(this, o).left = e / -2, t(this, o).right = e / 2, t(this, o).top = i / 2, t(this, o).bottom = i / -2), t(this, o).updateProjectionMatrix();
83
- }
84
- destroy() {
85
- t(this, p).forEach((e) => {
86
- e.userData.box.destroy();
87
- }), t(this, L).clear(), ze(t(this, L)), u.destroyView(this.name), t(this, R).destroy();
88
- }
89
- attachToHTMLElement(e, i, h) {
90
- const n = new ne(e, ie(k({}, h), {
91
- containerElement: t(this, D),
92
- cartesian: !0,
93
- scrollStep: !this.isClipped
94
- }));
95
- return n.bindObject(i), i.userData.box = n, t(this, p).push(i), i;
96
- }
97
- detachFromHTMLElement(e) {
98
- a(this, p, t(this, p).filter((i) => i === e ? (e.userData.box.destroy(), !1) : !0));
99
- }
100
- add(...e) {
101
- const i = e[0], h = e[1], n = e[2];
102
- return h && this.attachToHTMLElement(h, i, n), this.scene.add(i), i;
103
- }
104
- remove(e, i) {
105
- this.scene.remove(e), i && this.detachFromHTMLElement(e);
106
- }
107
- }
108
- S = new WeakMap(), o = new WeakMap(), L = new WeakMap(), p = new WeakMap(), x = new WeakMap(), P = new WeakMap(), D = new WeakMap(), R = new WeakMap();
109
- var H, A, F, v, I;
110
- class Le {
111
- constructor(e) {
112
- r(this, H);
113
- r(this, A);
114
- r(this, F);
115
- r(this, v);
116
- r(this, I);
117
- a(this, H, e.targetName || void 0), a(this, A, e.eventDispatcher || e.object3D), a(this, F, e.propagation || !1), a(this, v, e.object3D), a(this, I, t(this, H) ? () => t(this, v).getObjectByName(t(this, H)) || t(this, v) : () => t(this, v));
118
- }
119
- get object3D() {
120
- return t(this, v);
121
- }
122
- get eventDispatcher() {
123
- return t(this, A);
124
- }
125
- get propagation() {
126
- return t(this, F);
127
- }
128
- get target() {
129
- return t(this, I).call(this);
130
- }
131
- dispatch(e, i) {
132
- this.eventDispatcher.dispatchEvent(k({
133
- originalEvent: i,
134
- type: e
135
- }, this.intersection));
136
- }
137
- }
138
- H = new WeakMap(), A = new WeakMap(), F = new WeakMap(), v = new WeakMap(), I = new WeakMap();
139
- var b, d, O, N, W, Y, _;
140
- class Te {
141
- constructor() {
142
- r(this, b, []);
143
- r(this, d, []);
144
- r(this, O, new pe());
145
- r(this, N, new De());
146
- r(this, W, (e) => {
147
- for (let i = 0; i < t(this, d).length; i++)
148
- t(this, d)[i].dispatch("pointerDown", e);
149
- });
150
- r(this, Y, (e) => {
151
- for (let i = 0; i < t(this, d).length; i++)
152
- t(this, d)[i].dispatch("pointerUp", e);
153
- });
154
- r(this, _, (e) => {
155
- if (!t(this, b).length)
156
- return;
157
- t(this, O).x = e.clientX / u.width * 2 - 1, t(this, O).y = -(e.clientY / u.height) * 2 + 1, u.camera && t(this, N).setFromCamera(t(this, O), u.camera);
158
- const i = [];
159
- for (const c of t(this, b)) {
160
- const m = t(this, N).intersectObject(c.target);
161
- m.length && (c.intersection = m[0], i.push(c));
162
- }
163
- let h = !1;
164
- const n = t(this, d).filter(
165
- (c) => !i.find((m) => m.object3D.uuid === c.object3D.uuid)
166
- ), E = i.sort(
167
- (c, m) => m.object3D.position.z - c.object3D.position.z
168
- ).filter((c, m) => h ? (n.push(c), !1) : (h = !c.propagation, !0)), w = E.filter(
169
- (c) => !t(this, d).find((m) => m.object3D.uuid === c.object3D.uuid)
170
- );
171
- for (let c = 0; c < n.length; c++)
172
- n[c].dispatch("pointerLeave", e);
173
- for (let c = 0; c < w.length; c++)
174
- w[c].dispatch("pointerEnter", e);
175
- a(this, d, E);
176
- for (let c = 0; c < t(this, d).length; c++)
177
- t(this, d)[c].dispatch("pointerMove", e);
178
- });
179
- u.containerElement.addEventListener(
180
- "pointerdown",
181
- t(this, W)
182
- ), u.containerElement.addEventListener("pointerup", t(this, Y)), u.containerElement.addEventListener(
183
- "pointermove",
184
- t(this, _)
185
- );
186
- }
187
- destroy() {
188
- u.containerElement.removeEventListener(
189
- "pointerdown",
190
- t(this, W)
191
- ), u.containerElement.removeEventListener(
192
- "pointerup",
193
- t(this, Y)
194
- ), u.containerElement.removeEventListener(
195
- "pointermove",
196
- t(this, _)
197
- ), a(this, b, []), a(this, d, []);
198
- }
199
- add(e, i) {
200
- if (t(this, b).find((n) => n.object3D.uuid === e.uuid))
201
- return;
202
- const h = new Le(k({
203
- object3D: e
204
- }, i));
205
- t(this, b).push(h);
206
- }
207
- remove(e) {
208
- a(this, b, t(this, b).filter(
209
- (i) => i.object3D.uuid !== e.uuid
210
- )), a(this, d, t(this, d).filter((i) => i.object3D.uuid !== e.uuid));
211
- }
212
- }
213
- b = new WeakMap(), d = new WeakMap(), O = new WeakMap(), N = new WeakMap(), W = new WeakMap(), Y = new WeakMap(), _ = new WeakMap();
214
- var U, y, l, j, f, T, V, M, $, C, Z, g, B, G;
215
- class Ve {
216
- constructor() {
217
- r(this, U, `https://unpkg.com/three@0.${Re}.x`);
218
- r(this, y, null);
219
- r(this, l, null);
220
- r(this, j, null);
221
- r(this, f, /* @__PURE__ */ new Map());
222
- r(this, T, 0);
223
- r(this, V, 0);
224
- r(this, M, 0);
225
- r(this, $, 2);
226
- r(this, C, !1);
227
- r(this, Z, !1);
228
- r(this, g, null);
229
- r(this, B, () => {
230
- a(this, T, t(this, y).clientWidth), a(this, V, t(this, y).clientHeight), a(this, M, Math.min(t(this, $), devicePixelRatio || 1)), t(this, l).setPixelRatio(t(this, M)), t(this, l).setSize(t(this, T), t(this, V)), t(this, g) && (t(this, g).setPixelRatio(t(this, M)), t(this, g).setSize(t(this, T), t(this, V)));
231
- });
232
- r(this, G, () => {
233
- t(this, l).setRenderTarget(null), t(this, f).forEach((e) => {
234
- this.render(e);
235
- });
236
- });
237
- }
238
- get CDNVersion() {
239
- return t(this, U);
240
- }
241
- get containerElement() {
242
- return t(this, y);
243
- }
244
- get webglRenderer() {
245
- return t(this, l);
246
- }
247
- get raycaster() {
248
- return t(this, j);
249
- }
250
- get views() {
251
- return t(this, f);
252
- }
253
- get view() {
254
- return this.getView("default");
255
- }
256
- get camera() {
257
- return this.getView("default").camera;
258
- }
259
- get scene() {
260
- return this.getView("default").scene;
261
- }
262
- get width() {
263
- return t(this, T);
264
- }
265
- get height() {
266
- return t(this, V);
267
- }
268
- get pixelRatio() {
269
- return t(this, M);
270
- }
271
- get composer() {
272
- return t(this, g);
273
- }
274
- setup(e) {
275
- if (t(this, C)) {
276
- console.warn("[en3.setup]: You are trying to setup en3 again.");
277
- return;
278
- }
279
- a(this, y, oe(e == null ? void 0 : e.containerElement) || document.body), a(this, $, (e == null ? void 0 : e.maxPixelRatio) || 2), a(this, l, new ve(e == null ? void 0 : e.webGLRendererParameters)), t(this, l).domElement.style.cssText = `
280
- position: fixed;
281
- left: 0;
282
- top: 0;
283
- width: 100%;
284
- height: 100%;
285
- z-index: ${(e == null ? void 0 : e.zIndex) || 0};
286
- `, (t(this, y).shadowRoot || t(this, y)).append(t(this, l).domElement), t(this, f).set(
287
- "default",
288
- new ce("default", k({
289
- sizeElement: t(this, y)
290
- }, e == null ? void 0 : e.view))
291
- ), a(this, j, new Te()), e != null && e.composer && (a(this, g, new e.composer(t(this, l))), this.render = () => {
292
- t(this, g).render();
293
- }), a(this, C, !0), re.subscribe(t(this, B), ye.EN3), ae.subscribe(t(this, G), { order: xe.EN3 });
294
- }
295
- destroy() {
296
- if (!t(this, C)) {
297
- console.warn(
298
- "[en3.setup]: You are trying to destory en3 but it has not been initialized."
299
- );
300
- return;
301
- }
302
- re.unsubscribe(t(this, B)), ae.unsubscribe(t(this, G)), t(this, j).destroy(), t(this, f).forEach((e) => {
303
- e.destroy();
304
- }), t(this, l).dispose(), t(this, l).domElement.remove(), a(this, l, null), t(this, g).dispose(), a(this, g, null), a(this, C, !1);
305
- }
306
- createView(e, i) {
307
- const h = t(this, f).size, n = new ce(e, i);
308
- return t(this, f).set(e, n), h === 1 && t(this, l).setScissorTest(!0), n;
309
- }
310
- getView(e) {
311
- return t(this, f).get(e);
312
- }
313
- destroyView(e) {
314
- const i = t(this, f).get(e);
315
- i && (t(this, f).delete(e), i.destroy(), t(this, f).size <= 1 && t(this, l).setScissorTest(!1));
316
- }
317
- render(e) {
318
- var i;
319
- if (t(this, f).size > 1 || this.view.isClipped) {
320
- const h = e.box.left + e.box.CSSTranslation.x + e.box.scrollValue.x, n = u.height - e.box.height - e.box.top + e.box.CSSTranslation.y + e.box.scrollValue.y * -1;
321
- t(this, l).setScissor(h, n, e.box.width, e.box.height), t(this, l).setViewport(
322
- h,
323
- n,
324
- e.box.width,
325
- e.box.height
326
- );
327
- }
328
- (i = e.beforeRenderCallback) == null || i.call(e), t(this, l).render(e.scene, e.camera);
329
- }
330
- }
331
- U = new WeakMap(), y = new WeakMap(), l = new WeakMap(), j = new WeakMap(), f = new WeakMap(), T = new WeakMap(), V = new WeakMap(), M = new WeakMap(), $ = new WeakMap(), C = new WeakMap(), Z = new WeakMap(), g = new WeakMap(), B = new WeakMap(), G = new WeakMap();
332
- const u = new Ve();
333
- function Ae(s, e, i) {
334
- const h = e.x, n = e.y, z = i || s.image.width / s.image.height;
335
- let E = 0, w = 0, c = s.offset.x, m = s.offset.y, le = s.rotation, de = s.center.x, ue = s.center.y;
336
- h / n > z ? (E = 1, w = n / h * z) : (w = 1, E = h / n / z), s.matrix.setUvTransform(c, m, E, w, le, de, ue);
337
- }
338
- const K = new J(), Me = new J();
339
- function Fe(s, e = "default") {
340
- const i = u.getView(e), { width: h, height: n } = u, z = h / n;
341
- s instanceof J ? K.copy(s) : K.set(...s);
342
- const E = i.camera.getWorldPosition(Me).distanceTo(K);
343
- if (i.camera instanceof X)
344
- return {
345
- width: h / i.camera.zoom,
346
- height: n / i.camera.zoom,
347
- factor: 1,
348
- distance: E,
349
- aspect: z
350
- };
351
- {
352
- const w = i.camera.fov * Math.PI / 180, c = 2 * Math.tan(w / 2) * E, m = c * (h / n);
353
- return { width: m, height: c, factor: h / m, distance: E, aspect: z };
354
- }
355
- }
356
- function Ie(s, e) {
357
- s.traverse((i) => {
358
- i instanceof q && i.material && (Array.isArray(i.material) ? i.material : [i.material]).forEach(e);
359
- });
360
- }
361
- function Ne(s, e) {
362
- s.traverse((i) => {
363
- i instanceof q && e(i);
364
- });
365
- }
366
- export {
367
- ce as En3View,
368
- Ae as coverTexture,
369
- ze as dispose,
370
- u as en3,
371
- Fe as getCurrentViewport,
372
- Ie as traverseMaterials,
373
- Ne as traverseMeshes
374
- };
@@ -1,6 +0,0 @@
1
- import { Dot2D } from '../../utils';
2
- import { Texture } from 'three';
3
- /**
4
- * texture.matrixAutoUpdate must be false
5
- */
6
- export declare function coverTexture(texture: Texture, planeSize: Dot2D, aspect?: number): void;
@@ -1,2 +0,0 @@
1
- import { Object3D } from 'three';
2
- export declare function dispose(object3d: Object3D): void;
@@ -1,8 +0,0 @@
1
- import { Vector3 } from 'three';
2
- export declare function getCurrentViewport(target: Vector3 | [number, number, number], viewName?: string): {
3
- width: number;
4
- height: number;
5
- factor: number;
6
- distance: number;
7
- aspect: number;
8
- };
@@ -1,2 +0,0 @@
1
- import { Material, Object3D } from 'three';
2
- export declare function traverseMaterials(object: Object3D, callback: (material: Material) => void): void;
@@ -1,2 +0,0 @@
1
- import { Mesh, Object3D } from 'three';
2
- export declare function traverseMeshes(object: Object3D, callback: (mesh: Mesh) => void): void;