diff --git a/.eslintrc.cjs b/.eslintrc.cjs index ece4dbd..20fff36 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -1,10 +1,33 @@ +const { rules } = require("eslint-config-prettier") + module.exports = { root: true, parser: "@typescript-eslint/parser", extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"], plugins: ["svelte3", "@typescript-eslint"], - ignorePatterns: ["*.cjs"], - overrides: [{ files: ["*.svelte"], processor: "svelte3/svelte3" }], + + //(default) check *.svelte and *.ts files + // ignorePatterns: ["*.cjs"], + + // check only *.svelte files + ignorePatterns: ["*.cjs", "*.ts"], + + overrides: [ + { + files: ["*.svelte"], + processor: "svelte3/svelte3", + + // checking specific rules (set to "off" / "error") + // errors only + rules: { + "no-inferrable-types": "error", + "no-undef": "error", + "no-empty": "error", + "no-case-declarations": "error", + "no-prototype-builtins": "error" + } + } + ], settings: { "svelte3/typescript": () => require("typescript") }, diff --git a/.vscode/settings.json b/.vscode/settings.json index 3ce50ae..a6adc10 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { + "eslint.validate": ["javascript", "svelte"], "cSpell.enabled": false, "editor.wordSeparators": "`~!@#%^&*()-=+[{]}\\|;:'\",.<>/?", "todohighlight.keywords": [ diff --git a/package.json b/package.json index a791ae3..a80fbbb 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", "lint": "prettier --check . && eslint .", + "lint : quiet": "prettier --check . && eslint --quiet .", "format": "prettier --write ." }, "devDependencies": { diff --git a/src/lib/$app/env/index.ts b/src/lib/$app/env/index.ts index f93c977..7111125 100644 --- a/src/lib/$app/env/index.ts +++ b/src/lib/$app/env/index.ts @@ -1,3 +1,3 @@ // Mimic SvelteKit's `$app/env` foor non-SSR outputs in RollUp only and Vite only setups. -export const browser: boolean = true +export const browser = true diff --git a/src/lib/ani/SvelthreeAnimationManager.ts b/src/lib/ani/SvelthreeAnimationManager.ts index 7ecdda3..a9c5ca1 100644 --- a/src/lib/ani/SvelthreeAnimationManager.ts +++ b/src/lib/ani/SvelthreeAnimationManager.ts @@ -3,11 +3,13 @@ import SvelthreeAnimationProp from "./SvelthreeAnimationProp" import { verbose_mode } from "../utils/SvelthreeLogger" export default class SvelthreeAnimationManager { + // TODO (ESLint -> 'no-explicit-any') see https://github.com/vatro/svelthree/issues/165 animation: SvelthreeAnimationProp | any aniauto: boolean obj: Object3D scene: Scene + // TODO (ESLint -> 'no-explicit-any') see https://github.com/vatro/svelthree/issues/165 constructor(animation: SvelthreeAnimationProp | any, aniauto: boolean, obj: Object3D, scene: Scene | null) { this.animation = animation this.aniauto = aniauto @@ -165,6 +167,7 @@ export default class SvelthreeAnimationManager { return false } + // TODO (ESLint -> 'no-explicit-any') see https://github.com/vatro/svelthree/issues/165 getAnimation(): any { if (this.animationInitiated()) { return this.animation diff --git a/src/lib/ani/SvelthreeAnimationProp.ts b/src/lib/ani/SvelthreeAnimationProp.ts index bb3e35b..58029b9 100644 --- a/src/lib/ani/SvelthreeAnimationProp.ts +++ b/src/lib/ani/SvelthreeAnimationProp.ts @@ -14,14 +14,14 @@ export default class SvelthreeAnimationProp { try { initiatedFn = this.fn(obj, args) - if (!initiatedFn.hasOwnProperty("onStart")) { + if (!Object.prototype.hasOwnProperty.call(initiatedFn, "onStart")) { console.error("SVELTHREE > Provided animation is missing 'onStart' function!", { animation: initiatedFn }) //throw new Error("SVELTHREE Exception (see warning above)") } - if (!initiatedFn.hasOwnProperty("onDestroy")) { + if (!Object.prototype.hasOwnProperty.call(initiatedFn, "onDestroy")) { console.error("SVELTHREE > Provided animation has no 'onDestroy' function!", { animation: initiatedFn }) diff --git a/src/lib/components-internal/SvelthreeInteraction.svelte b/src/lib/components-internal/SvelthreeInteraction.svelte index b1913e4..c7e6e9a 100644 --- a/src/lib/components-internal/SvelthreeInteraction.svelte +++ b/src/lib/components-internal/SvelthreeInteraction.svelte @@ -13,6 +13,7 @@ This is a **svelthree** _SvelthreeInteraction_ Component. import { onMount, beforeUpdate, afterUpdate, onDestroy, getContext } from "svelte" import { get_current_component, SvelteComponentDev } from "svelte/internal" import { Object3D, Raycaster, Vector3 } from "three" + import type { Intersection, Camera, Ray } from "three" import { svelthreeStores } from "svelthree/stores" import { c_dev, c_lc_int, verbose_mode, get_comp_name_int } from "../utils/SvelthreeLogger" import type { LogLC, LogDEV } from "../utils/SvelthreeLogger" @@ -49,7 +50,7 @@ This is a **svelthree** _SvelthreeInteraction_ Component. const verbose: boolean = verbose_mode() export let log_dev: { [P in keyof LogDEV]: LogDEV[P] } = undefined - //export let log_rs: boolean = false + //export let log_rs = false export let log_lc: { [P in keyof LogLC]: LogLC[P] } = undefined export let interactionEnabled: boolean @@ -102,13 +103,13 @@ This is a **svelthree** _SvelthreeInteraction_ Component. interface RaycasterData { /** `intersections` are of the same form as those returned by [`.intersectObject`](https://threejs.org/docs/#api/en/core/Raycaster.intersectObject). */ - intersection: { [P in keyof THREE.Intersection]: THREE.Intersection[P] } + intersection: { [P in keyof Intersection]: Intersection[P] } /** Current `Raycaster` `.ray`, e.g. useful properties: `ray.origin: Vector3` | `ray.direction: Vector3`. */ - ray: THREE.Ray + ray: Ray /** The `Camera` used for raycasting. */ - camera: THREE.Camera + camera: Camera /** Current pointer position ( _'point' / Vector3 position_ ) in 3d world space. */ - unprojected_point: THREE.Vector3 + unprojected_point: Vector3 } let raycaster_data: RaycasterData @@ -145,7 +146,7 @@ This is a **svelthree** _SvelthreeInteraction_ Component. export let shadow_dom_el: SvelthreeShadowDOMElement = undefined - let listeners: boolean = false + let listeners = false // --- Reactively add listeners --- @@ -156,7 +157,7 @@ This is a **svelthree** _SvelthreeInteraction_ Component. // --- Pointer over / out of `` element state --- - let out_of_canvas_triggered: boolean = false + let out_of_canvas_triggered = false // pointer is out of / exited the `` element. $: if (obj.userData.interact && pointer.event && $pointer_over_canvas.status === false) { @@ -802,21 +803,24 @@ This is a **svelthree** _SvelthreeInteraction_ Component. if (cancel_or_stop_propagation_fn) cancel_or_stop_propagation_fn(e) switch (e.type) { - case "pointermove": + case "pointermove": { const queued_pointermove_event = () => dispatch_pointerevent_intersection_indep(e) queued_pointer_move_events[0] = queued_pointermove_event //queued_pointer_move_events[0] = () => dispatch_pointerevent_intersection_indep(e) break - case "pointermoveover": + } + case "pointermoveover": { const queued_pointermoveover_event = () => dispatch_pointerevent_intersection_indep(e) queued_pointer_moveover_events[0] = queued_pointermoveover_event //queued_pointer_moveover_events[0] = () => dispatch_pointerevent_intersection_indep(e) break - default: + } + default: { const queued_pointer_event = () => dispatch_pointerevent_intersection_dep(e) pointer_events_queue.push(queued_pointer_event) //pointer_events_queue.push(() => dispatch_pointerevent_intersection_dep(e)) break + } } break @@ -840,7 +844,7 @@ This is a **svelthree** _SvelthreeInteraction_ Component. /** intersection dependent -> has raycaster_data! */ function dispatch_pointerevent_intersection_dep(e: PointerEvent) { - const action_name: string = `on_${e.type}` + const action_name = `on_${e.type}` const detail = { e, @@ -855,7 +859,7 @@ This is a **svelthree** _SvelthreeInteraction_ Component. /** intersection independent -> no raycaster_data! */ function dispatch_pointerevent_intersection_indep(e: PointerEvent) { - const action_name: string = `on_${e.type}` + const action_name = `on_${e.type}` const detail = { e, @@ -956,11 +960,12 @@ This is a **svelthree** _SvelthreeInteraction_ Component. cancel_or_stop_propagation_fn(e) switch (render_mode) { - case "always": + case "always": { // QUEUED EVENT DISPATCHING: dispatch our custom event / execute handler on next render (raf aligned) const queued_focus_event = () => dispatch_focusevent_intersection_indep(e) focus_events_queue.push(queued_focus_event) break + } case "auto": // IMMEDIATE EVENT DISPATCHING (not raf aligned) / any changes will schedule a new render (raf aligned) dispatch_focusevent_intersection_indep(e) @@ -972,7 +977,7 @@ This is a **svelthree** _SvelthreeInteraction_ Component. } function dispatch_focusevent_intersection_indep(e: FocusEvent) { - const action_name: string = `on_${e.type}` + const action_name = `on_${e.type}` const detail = { e, @@ -1179,11 +1184,12 @@ This is a **svelthree** _SvelthreeInteraction_ Component. } switch (render_mode) { - case "always": + case "always": { // QUEUED EVENT DISPATCHING: dispatch our custom event / execute handler on next render (raf aligned) const queued_keyboard_event = () => dispatch_keyboardevent_intersection_indep(e) keyboard_events_queue.push(queued_keyboard_event) break + } case "auto": // IMMEDIATE EVENT DISPATCHING (not raf aligned) / any changes will schedule a new render (raf aligned) dispatch_keyboardevent_intersection_indep(e) @@ -1204,7 +1210,7 @@ This is a **svelthree** _SvelthreeInteraction_ Component. } function dispatch_keyboardevent_intersection_indep(e: KeyboardEvent) { - const action_name: string = `on_${e.type}` + const action_name = `on_${e.type}` const detail = { code: e.code, diff --git a/src/lib/components/AmbientLight.svelte b/src/lib/components/AmbientLight.svelte index 24d821f..701ff90 100644 --- a/src/lib/components/AmbientLight.svelte +++ b/src/lib/components/AmbientLight.svelte @@ -50,7 +50,7 @@ AmbientLight cannot be used to cast shadows as it doesn't have a direction. Posi const verbose: boolean = verbose_mode() - export let log_all: boolean = false + export let log_all = false export let log_dev: { [P in keyof LogDEV]: LogDEV[P] } = log_all ? { all: true } : undefined export let log_rs: boolean = log_all export let log_lc: { [P in keyof LogLC]: LogLC[P] } = log_all ? { all: true } : undefined @@ -86,8 +86,8 @@ AmbientLight cannot be used to cast shadows as it doesn't have a direction. Posi /** Sets the `name` property of the created / injected three.js instance. */ export let name: string = undefined - export const is_svelthree_component: boolean = true - export const is_svelthree_light: boolean = true + export const is_svelthree_component = true + export const is_svelthree_light = true // ONCE ON INITIALIZATION // @@ -103,6 +103,7 @@ AmbientLight cannot be used to cast shadows as it doesn't have a direction. Posi /** Executed when / if an instance was provided **on initializiation** -> only once if at all! */ function on_instance_provided(): void { if (light.type === "AmbientLight") { + //nothing } else { throw new Error( `SVELTHREE > ${c_name} provided 'light' instance has wrong type '${light.type}', should be '${c_name}'!` @@ -201,6 +202,7 @@ AmbientLight cannot be used to cast shadows as it doesn't have a direction. Posi } // accessability -> shadow dom wai-aria + // eslint-disable-next-line no-undef export let aria: Partial = undefined $: if (shadow_dom_el && aria !== undefined) { @@ -284,7 +286,7 @@ AmbientLight cannot be used to cast shadows as it doesn't have a direction. Posi /** Animation logic to be performed with the (three) object instance created by the component. */ export let animation: SvelthreeAnimationFunction = undefined - let animationEnabled: boolean = false + let animationEnabled = false $: if (animation) animationEnabled = true /** Immediately start provided animation, default: `false`. Alternative: `.start_animation()` or shorter `.start_ani()`. */ diff --git a/src/lib/components/Canvas.svelte b/src/lib/components/Canvas.svelte index 21be50a..dfa4652 100644 --- a/src/lib/components/Canvas.svelte +++ b/src/lib/components/Canvas.svelte @@ -43,15 +43,15 @@ This is a **svelthree** _Canvas_ Component. const dispatch: (type: string, detail?: any) => void = createEventDispatcher() - export let log_all: boolean = false + export let log_all = false export let log_dev: { [P in keyof LogDEV]: LogDEV[P] } = log_all ? { all: true } : undefined export let log_rs: boolean = log_all export let log_lc: { [P in keyof LogLC]: LogLC[P] } = log_all ? { all: true } : undefined // #endregion - export const is_svelthree_component: boolean = true - export const is_svelthree_canvas: boolean = true + export const is_svelthree_component = true + export const is_svelthree_canvas = true // #region --- Required Attributes @@ -70,7 +70,7 @@ This is a **svelthree** _Canvas_ Component. export { clazz as class } /** If `true` (_default_) the cursor will change automatically (_e.g. over/out canvas DOM element, **interactive** objects or when using the `OrbitControls` component_). */ - export let change_cursor: boolean = true + export let change_cursor = true export let interactive: boolean = undefined $: if (interactive !== undefined) { @@ -570,7 +570,7 @@ This is a **svelthree** _Canvas_ Component. * will also check all descendants of interactive objects. * - If set to `false` the interaction Raycaster will only check intersection with interactive objects. */ - export let recursive: boolean = true + export let recursive = true /** Updates the `all_intersections.result` array and changes the pointer appearance if the `change_cursor` prop is set to `true`.*/ function update_all_intersections_and_cursor(): void { @@ -732,6 +732,7 @@ This is a **svelthree** _Canvas_ Component. // --- Accessabilty --- export let tabindex: number = undefined + // eslint-disable-next-line no-undef export let aria: Partial = undefined $: if (c && browser) { diff --git a/src/lib/components/CubeCamera.svelte b/src/lib/components/CubeCamera.svelte index 140ec75..85d47ac 100644 --- a/src/lib/components/CubeCamera.svelte +++ b/src/lib/components/CubeCamera.svelte @@ -66,7 +66,7 @@ Renders a `CubeMap` which can be used with **non-PBR** materials having an `.env const verbose: boolean = verbose_mode() - export let log_all: boolean = false + export let log_all = false export let log_dev: { [P in keyof LogDEV]: LogDEV[P] } = log_all ? { all: true } : undefined export let log_rs: boolean = log_all export let log_lc: { [P in keyof LogLC]: LogLC[P] } = log_all ? { all: true } : undefined @@ -76,9 +76,9 @@ Renders a `CubeMap` which can be used with **non-PBR** materials having an `.env * - `false` (default) -> `update_cubecam()` will be called **once on initialization**, further updates have to be done **manually** by calling `[CubeCamera component reference].update_cubecam()`. * - `true` -> WebGLRenderer component will update the CubeCamera (_renderTarget.texture_) on **every frame**. */ - export let dynamic: boolean = false + export let dynamic = false - let camera_updated: boolean = false + let camera_updated = false /** `CubeCamera` instances are always added to the `root_scene` * no matter which component the `CubeCamera` component was added to. */ @@ -119,7 +119,7 @@ Renders a `CubeMap` which can be used with **non-PBR** materials having an `.env $: texture = browser ? camera.renderTarget.texture : undefined /** Set to `true` for correct **floor reflections** (_default: `false`_). */ - export let is_floor: boolean = false + export let is_floor = false let scene: THREE_Scene = getContext("scene") const sti: number = getContext("store_index") @@ -156,8 +156,8 @@ Renders a `CubeMap` which can be used with **non-PBR** materials having an `.env export let name: string = undefined let index_in_cubecameras: number = undefined - export const is_svelthree_component: boolean = true - export const is_svelthree_camera: boolean = true + export const is_svelthree_component = true + export const is_svelthree_camera = true // ONCE ON INITIALIZATION // @@ -306,6 +306,7 @@ Renders a `CubeMap` which can be used with **non-PBR** materials having an `.env } // accessability -> shadow dom wai-aria + // eslint-disable-next-line no-undef export let aria: Partial = undefined $: if (shadow_dom_el && aria !== undefined) { @@ -403,7 +404,7 @@ Renders a `CubeMap` which can be used with **non-PBR** materials having an `.env if (!bind_tex) { let op: Mesh = bound_pos as Mesh let op_mat: MaterialWithEnvMap = op.material as MaterialWithEnvMap - if (op_mat?.hasOwnProperty("envMap")) { + if (op_mat && Object.prototype.hasOwnProperty.call(op_mat, "envMap")) { op_mat.envMap = camera.renderTarget.texture } } @@ -602,7 +603,7 @@ Renders a `CubeMap` which can be used with **non-PBR** materials having an `.env /** Animation logic to be performed with the (three) object instance created by the component. */ export let animation: SvelthreeAnimationFunction = undefined - let animationEnabled: boolean = false + let animationEnabled = false $: if (animation) animationEnabled = true /** Immediately start provided animation, default: `false`. Alternative: `.start_animation()` or shorter `.start_ani()`. */ diff --git a/src/lib/components/DirectionalLight.svelte b/src/lib/components/DirectionalLight.svelte index d666c4a..8967af8 100644 --- a/src/lib/components/DirectionalLight.svelte +++ b/src/lib/components/DirectionalLight.svelte @@ -61,7 +61,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` const verbose: boolean = verbose_mode() - export let log_all: boolean = false + export let log_all = false export let log_dev: { [P in keyof LogDEV]: LogDEV[P] } = log_all ? { all: true } : undefined export let log_rs: boolean = log_all export let log_lc: { [P in keyof LogLC]: LogLC[P] } = log_all ? { all: true } : undefined @@ -97,8 +97,8 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Sets the `name` property of the created / injected three.js instance. */ export let name: string = undefined - export const is_svelthree_component: boolean = true - export const is_svelthree_light: boolean = true + export const is_svelthree_component = true + export const is_svelthree_light = true // ONCE ON INITIALIZATION // @@ -114,6 +114,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Executed when / if an instance was provided **on initializiation** -> only once if at all! */ function on_instance_provided(): void { if (light.type === "DirectionalLight") { + //nothing } else { throw new Error( `SVELTHREE > ${c_name} provided 'light' instance has wrong type '${light.type}', should be '${c_name}'!` @@ -212,6 +213,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` } // accessability -> shadow dom wai-aria + // eslint-disable-next-line no-undef export let aria: Partial = undefined $: if (shadow_dom_el && aria !== undefined) { @@ -425,7 +427,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Animation logic to be performed with the (three) object instance created by the component. */ export let animation: SvelthreeAnimationFunction = undefined - let animationEnabled: boolean = false + let animationEnabled = false $: if (animation) animationEnabled = true /** Immediately start provided animation, default: `false`. Alternative: `.start_animation()` or shorter `.start_ani()`. */ diff --git a/src/lib/components/Group.svelte b/src/lib/components/Group.svelte index 0f7f193..cf01127 100644 --- a/src/lib/components/Group.svelte +++ b/src/lib/components/Group.svelte @@ -55,13 +55,13 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` const verbose: boolean = verbose_mode() - export let log_all: boolean = false + export let log_all = false export let log_dev: { [P in keyof LogDEV]: LogDEV[P] } = log_all ? { all: true } : undefined export let log_rs: boolean = log_all export let log_lc: { [P in keyof LogLC]: LogLC[P] } = log_all ? { all: true } : undefined export let log_mau: boolean = log_all - export const isGroup: boolean = true + export const isGroup = true let scene: THREE_Scene = getContext("scene") const sti: number = getContext("store_index") @@ -98,8 +98,8 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Sets the `name` property of the created / injected three.js instance. */ export let name: string = undefined - export const is_svelthree_component: boolean = true - export const is_svelthree_group: boolean = true + export const is_svelthree_component = true + export const is_svelthree_group = true // ONCE ON INITIALIZATION // @@ -115,6 +115,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Executed when / if an instance was provided **on initializiation** -> only once if at all! */ function on_instance_provided(): void { if (group.type === "Group") { + //nothing } else { throw new Error( `SVELTHREE > ${c_name} provided 'group' instance has wrong type '${group.type}', should be '${c_name}'!` @@ -206,6 +207,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` } // accessability -> shadow dom wai-aria + // eslint-disable-next-line no-undef export let aria: Partial = undefined $: if (shadow_dom_el && aria !== undefined) { @@ -415,7 +417,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Animation logic to be performed with the (three) object instance created by the component. */ export let animation: SvelthreeAnimationFunction = undefined - let animationEnabled: boolean = false + let animationEnabled = false $: if (animation) animationEnabled = true /** Immediately start provided animation, default: `false`. Alternative: `.start_animation()` or shorter `.start_ani()`. */ diff --git a/src/lib/components/HemisphereLight.svelte b/src/lib/components/HemisphereLight.svelte index 1b4543f..e7ab716 100644 --- a/src/lib/components/HemisphereLight.svelte +++ b/src/lib/components/HemisphereLight.svelte @@ -51,7 +51,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` const verbose: boolean = verbose_mode() - export let log_all: boolean = false + export let log_all = false export let log_dev: { [P in keyof LogDEV]: LogDEV[P] } = log_all ? { all: true } : undefined export let log_rs: boolean = log_all export let log_lc: { [P in keyof LogLC]: LogLC[P] } = log_all ? { all: true } : undefined @@ -87,8 +87,8 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Sets the `name` property of the created / injected three.js instance. */ export let name: string = undefined - export const is_svelthree_component: boolean = true - export const is_svelthree_light: boolean = true + export const is_svelthree_component = true + export const is_svelthree_light = true // ONCE ON INITIALIZATION // @@ -104,6 +104,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Executed when / if an instance was provided **on initializiation** -> only once if at all! */ function on_instance_provided(): void { if (light.type === "HemisphereLight") { + //nothing } else { throw new Error( `SVELTHREE > ${c_name} provided 'light' instance has wrong type '${light.type}', should be '${c_name}'!` @@ -202,6 +203,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` } // accessability -> shadow dom wai-aria + // eslint-disable-next-line no-undef export let aria: Partial = undefined $: if (shadow_dom_el && aria !== undefined) { @@ -328,7 +330,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Animation logic to be performed with the (three) object instance created by the component. */ export let animation: SvelthreeAnimationFunction = undefined - let animationEnabled: boolean = false + let animationEnabled = false $: if (animation) animationEnabled = true /** Immediately start provided animation, default: `false`. Alternative: `.start_animation()` or shorter `.start_ani()`. */ diff --git a/src/lib/components/LoadedGLTF.svelte b/src/lib/components/LoadedGLTF.svelte index dd25654..2dfcec3 100644 --- a/src/lib/components/LoadedGLTF.svelte +++ b/src/lib/components/LoadedGLTF.svelte @@ -73,7 +73,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` const verbose: boolean = verbose_mode() - export let log_all: boolean = false + export let log_all = false export let log_dev: { [P in keyof LogDEV]: LogDEV[P] } = log_all ? { all: true } : undefined export let log_rs: boolean = log_all export let log_lc: { [P in keyof LogLC]: LogLC[P] } = log_all ? { all: true } : undefined @@ -115,8 +115,8 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Sets the `name` property of the created / injected three.js instance. */ export let name: string = undefined - export const is_svelthree_component: boolean = true - export const is_svelthree_container: boolean = true + export const is_svelthree_component = true + export const is_svelthree_container = true $: if (!container) { container = new THREE_Object3D() @@ -185,6 +185,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` } // accessability -> shadow dom wai-aria + // eslint-disable-next-line no-undef export let aria: Partial = undefined $: if (shadow_dom_el && aria !== undefined) { @@ -205,7 +206,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` * which will then be added to it's parent component / parent object (three) instance. * If the `add` attribute is set to `false`, the `container` instance will be `undefined` * and you'll have to manage adding loaded GLTF assets to your scene graph by yourself. */ - export let add: boolean = true + export let add = true /** GLTF file `url` (_or path_). */ export let url: string = undefined @@ -484,7 +485,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` * In case `interact` prop is set / set to `true`, but no e.g. `on:` directives or `on_` internal actions are set, * the object will automatically become an _interaction occluder / blocker_. */ - export let block: boolean = false + export let block = false const interaction_on_clear = { interact: undefined, @@ -691,7 +692,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Animation logic to be performed with the (three) object instance created by the component. */ export let animation: SvelthreeAnimationFunction = undefined - let animationEnabled: boolean = false + let animationEnabled = false $: if (animation) animationEnabled = true /** Immediately start provided animation, default: `false`. Alternative: `.start_animation()` or shorter `.start_ani()`. */ diff --git a/src/lib/components/Mesh.svelte b/src/lib/components/Mesh.svelte index 9a023af..af34e75 100644 --- a/src/lib/components/Mesh.svelte +++ b/src/lib/components/Mesh.svelte @@ -71,7 +71,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` const verbose: boolean = verbose_mode() - export let log_all: boolean = false + export let log_all = false export let log_dev: { [P in keyof LogDEV]: LogDEV[P] } = log_all ? { all: true } : undefined export let log_rs: boolean = log_all export let log_lc: { [P in keyof LogLC]: LogLC[P] } = log_all ? { all: true } : undefined @@ -129,8 +129,8 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` export let geometry: BufferGeometry = undefined let geometry_ref: BufferGeometry = undefined - export const is_svelthree_component: boolean = true - export const is_svelthree_mesh: boolean = true + export const is_svelthree_component = true + export const is_svelthree_mesh = true // ONCE ON INITIALIZATION // @@ -358,6 +358,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` } // accessability -> shadow dom wai-aria + // eslint-disable-next-line no-undef export let aria: Partial = undefined $: if (shadow_dom_el && aria !== undefined) { @@ -623,7 +624,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` * In case `interact` prop is set / set to `true`, but no e.g. `on:` directives or `on_` internal actions are set, * the object will automatically become an _interaction occluder / blocker_. */ - export let block: boolean = false + export let block = false const interaction_on_clear = { interact: undefined, @@ -830,7 +831,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Animation logic to be performed with the (three) object instance created by the component. */ export let animation: SvelthreeAnimationFunction = undefined - let animationEnabled: boolean = false + let animationEnabled = false $: if (animation) animationEnabled = true /** Immediately start provided animation, default: `false`. Alternative: `.start_animation()` or shorter `.start_ani()`. */ diff --git a/src/lib/components/Object3D.svelte b/src/lib/components/Object3D.svelte index 800b2eb..ead526d 100644 --- a/src/lib/components/Object3D.svelte +++ b/src/lib/components/Object3D.svelte @@ -54,13 +54,13 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` const verbose: boolean = verbose_mode() - export let log_all: boolean = false + export let log_all = false export let log_dev: { [P in keyof LogDEV]: LogDEV[P] } = log_all ? { all: true } : undefined export let log_rs: boolean = log_all export let log_lc: { [P in keyof LogLC]: LogLC[P] } = log_all ? { all: true } : undefined export let log_mau: boolean = log_all - export const isObject3D: boolean = true + export const isObject3D = true let scene: THREE_Scene = getContext("scene") const sti: number = getContext("store_index") @@ -97,8 +97,8 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Sets the `name` property of the created / injected three.js instance. */ export let name: string = undefined - export const is_svelthree_component: boolean = true - export const is_svelthree_object3d: boolean = true + export const is_svelthree_component = true + export const is_svelthree_object3d = true // ONCE ON INITIALIZATION // @@ -114,6 +114,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Executed when / if an instance was provided **on initializiation** -> only once if at all! */ function on_instance_provided(): void { if (object3d.type === "Object3D") { + //nothing } else { throw new Error( `SVELTHREE > ${c_name} provided 'object3d' instance has wrong type '${object3d.type}', should be '${c_name}'!` @@ -205,6 +206,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` } // accessability -> shadow dom wai-aria + // eslint-disable-next-line no-undef export let aria: Partial = undefined $: if (shadow_dom_el && aria !== undefined) { @@ -415,7 +417,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Animation logic to be performed with the (three) object instance created by the component. */ export let animation: SvelthreeAnimationFunction = undefined - let animationEnabled: boolean = false + let animationEnabled = false $: if (animation) animationEnabled = true /** Immediately start provided animation, default: `false`. Alternative: `.start_animation()` or shorter `.start_ani()`. */ diff --git a/src/lib/components/OrbitControls.svelte b/src/lib/components/OrbitControls.svelte index 49e6e8e..03deb71 100644 --- a/src/lib/components/OrbitControls.svelte +++ b/src/lib/components/OrbitControls.svelte @@ -38,7 +38,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` const verbose: boolean = verbose_mode() - export let log_all: boolean = false + export let log_all = false export let log_rs: boolean = log_all export let log_lc: { [P in keyof LogLC]: LogLC[P] } = log_all ? { all: true } : undefined @@ -48,11 +48,11 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Returns the `orbitcontrols` instance created by the component & allows providing (_injection_) of (_already created / premade_) `THREE.OrbitControls` instances. */ export let orbitcontrols: THREE_OrbitControls = undefined - export const is_svelthree_component: boolean = true - export const is_svelthree_orbitcontrols: boolean = true + export const is_svelthree_component = true + export const is_svelthree_orbitcontrols = true /** Display a console warning if the `OrbitControls` component's `cam` attribute was assigned a currently _inactive_ camera (also adss a `CameraHelper` to the assigned Camera). Default is `true`. Set `warn={false}` to hide the warning (_also: no `CameraHelper` be added_). */ - export let warn: boolean = true + export let warn = true // TODO clarify why / when we would need this. let index_in_orbitcontrols: number = undefined @@ -167,7 +167,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** When set to false, the controls will not respond to user input. Default is `true`. * [See threejs-docs.](https://threejs.org/docs/#examples/en/controls/OrbitControls.enabled) */ - export let enabled: boolean = true + export let enabled = true $: if (orbitcontrols && (enabled === true || !enabled)) set_enabled() function set_enabled(): void { @@ -187,7 +187,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Enable or disable horizontal and vertical rotation of the camera. Default `true`. * [See threejs-docs.](https://threejs.org/docs/#examples/en/controls/OrbitControls.enableRotate) */ - export let rotate: boolean = true + export let rotate = true $: if (orbitcontrols && (rotate === true || !rotate)) set_rotate() function set_rotate(): void { @@ -201,7 +201,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` * - `false`: will schedule a render on `OrbitControls`'s event `"change"`. * * [See threejs-docs.](https://threejs.org/docs/#examples/en/controls/OrbitControls.autoRotate) */ - export let auto: boolean = false + export let auto = false $: if (orbitcontrols && auto !== undefined) set_auto() function set_auto(): void { @@ -234,7 +234,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Set to true to enable damping (inertia), which can be used to give a sense of weight to the controls. Default is `false`. * [See threejs-docs.](https://threejs.org/docs/#examples/en/controls/OrbitControls.enableDamping) */ - export let damping: boolean = false + export let damping = false $: if (orbitcontrols && (damping === true || !damping)) set_damping() function set_damping(): void { @@ -244,7 +244,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Enable or disable camera panning. Default is `true`. * [See threejs-docs.](https://threejs.org/docs/#examples/en/controls/OrbitControls.enablePan) */ - export let pan: boolean = true + export let pan = true $: if (orbitcontrols && (pan === true || !pan)) set_pan() function set_pan(): void { @@ -254,7 +254,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Enable or disable zooming (dollying) of the camera. Default `false`. * [See threejs-docs.](https://threejs.org/docs/#examples/en/controls/OrbitControls.enableZoom) */ - export let zoom: boolean = false + export let zoom = false $: if (orbitcontrols && (zoom === true || !zoom)) set_zoom() function set_zoom(): void { diff --git a/src/lib/components/OrthographicCamera.svelte b/src/lib/components/OrthographicCamera.svelte index 0558612..1407edb 100644 --- a/src/lib/components/OrthographicCamera.svelte +++ b/src/lib/components/OrthographicCamera.svelte @@ -61,7 +61,7 @@ If you use this approach you'll see a warning in the console if you define left, const verbose: boolean = verbose_mode() - export let log_all: boolean = false + export let log_all = false export let log_dev: { [P in keyof LogDEV]: LogDEV[P] } = log_all ? { all: true } : undefined export let log_rs: boolean = log_all export let log_lc: { [P in keyof LogLC]: LogLC[P] } = log_all ? { all: true } : undefined @@ -111,8 +111,8 @@ If you use this approach you'll see a warning in the console if you define left, let camera_is_active: boolean = undefined let index_in_cameras: number = undefined - export const is_svelthree_component: boolean = true - export const is_svelthree_camera: boolean = true + export const is_svelthree_component = true + export const is_svelthree_camera = true // ONCE ON INITIALIZATION // @@ -279,6 +279,7 @@ If you use this approach you'll see a warning in the console if you define left, } // accessability -> shadow dom wai-aria + // eslint-disable-next-line no-undef export let aria: Partial = undefined $: if (shadow_dom_el && aria !== undefined) { @@ -428,7 +429,7 @@ If you use this approach you'll see a warning in the console if you define left, const canvas_dim: Writable<{ w: number; h: number }> = getContext("canvas_dim") - let camera_updated_on_init: boolean = false + let camera_updated_on_init = false // update frustum planes / aspect on initialization only (`frustumSize` not set -> svelthree default value in order prevent 'stretching') $: if (!frustumSize && !camera_updated_on_init && camera && $canvas_dom.element && $canvas_dim.w && $canvas_dim.h) { @@ -510,7 +511,7 @@ If you use this approach you'll see a warning in the console if you define left, /** Animation logic to be performed with the (three) object instance created by the component. */ export let animation: SvelthreeAnimationFunction = undefined - let animationEnabled: boolean = false + let animationEnabled = false $: if (animation) animationEnabled = true /** Immediately start provided animation, default: `false`. Alternative: `.start_animation()` or shorter `.start_ani()`. */ diff --git a/src/lib/components/PerspectiveCamera.svelte b/src/lib/components/PerspectiveCamera.svelte index 1e1b854..889e04d 100644 --- a/src/lib/components/PerspectiveCamera.svelte +++ b/src/lib/components/PerspectiveCamera.svelte @@ -54,7 +54,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` const verbose: boolean = verbose_mode() - export let log_all: boolean = false + export let log_all = false export let log_dev: { [P in keyof LogDEV]: LogDEV[P] } = log_all ? { all: true } : undefined export let log_rs: boolean = log_all export let log_lc: { [P in keyof LogLC]: LogLC[P] } = log_all ? { all: true } : undefined @@ -104,8 +104,8 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` let camera_is_active: boolean = undefined let index_in_cameras: number = undefined - export const is_svelthree_component: boolean = true - export const is_svelthree_camera: boolean = true + export const is_svelthree_component = true + export const is_svelthree_camera = true // ONCE ON INITIALIZATION // @@ -244,6 +244,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` } // accessability -> shadow dom wai-aria + // eslint-disable-next-line no-undef export let aria: Partial = undefined $: if (shadow_dom_el && aria !== undefined) { @@ -393,7 +394,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` const canvas_dim: Writable<{ w: number; h: number }> = getContext("canvas_dim") - let aspect_updated_on_init: boolean = false + let aspect_updated_on_init = false /** Camera frustum aspect ratio, usually the `canvas width / canvas height`. * **svelthree** always sets the aspect of the camera automatically _once_ on initialization to match canvas dimensions. @@ -544,7 +545,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Animation logic to be performed with the (three) object instance created by the component. */ export let animation: SvelthreeAnimationFunction = undefined - let animationEnabled: boolean = false + let animationEnabled = false $: if (animation) animationEnabled = true /** Immediately start provided animation, default: `false`. Alternative: `.start_animation()` or shorter `.start_ani()`. */ diff --git a/src/lib/components/PointLight.svelte b/src/lib/components/PointLight.svelte index c589b45..2c50b60 100644 --- a/src/lib/components/PointLight.svelte +++ b/src/lib/components/PointLight.svelte @@ -58,7 +58,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` const verbose: boolean = verbose_mode() - export let log_all: boolean = false + export let log_all = false export let log_dev: { [P in keyof LogDEV]: LogDEV[P] } = log_all ? { all: true } : undefined export let log_rs: boolean = log_all export let log_lc: { [P in keyof LogLC]: LogLC[P] } = log_all ? { all: true } : undefined @@ -94,8 +94,8 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Sets the `name` property of the created / injected three.js instance. */ export let name: string = undefined - export const is_svelthree_component: boolean = true - export const is_svelthree_light: boolean = true + export const is_svelthree_component = true + export const is_svelthree_light = true // ONCE ON INITIALIZATION // @@ -111,6 +111,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Executed when / if an instance was provided **on initializiation** -> only once if at all! */ function on_instance_provided(): void { if (light.type === "PointLight") { + //nothing } else { throw new Error( `SVELTHREE > ${c_name} provided 'light' instance has wrong type '${light.type}', should be '${c_name}'!` @@ -209,6 +210,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` } // accessability -> shadow dom wai-aria + // eslint-disable-next-line no-undef export let aria: Partial = undefined $: if (shadow_dom_el && aria !== undefined) { @@ -390,7 +392,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Animation logic to be performed with the (three) object instance created by the component. */ export let animation: SvelthreeAnimationFunction = undefined - let animationEnabled: boolean = false + let animationEnabled = false $: if (animation) animationEnabled = true /** Immediately start provided animation, default: `false`. Alternative: `.start_animation()` or shorter `.start_ani()`. */ diff --git a/src/lib/components/Points.svelte b/src/lib/components/Points.svelte index 6e5686f..9355348 100644 --- a/src/lib/components/Points.svelte +++ b/src/lib/components/Points.svelte @@ -71,7 +71,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` const verbose: boolean = verbose_mode() - export let log_all: boolean = false + export let log_all = false export let log_dev: { [P in keyof LogDEV]: LogDEV[P] } = log_all ? { all: true } : undefined export let log_rs: boolean = log_all export let log_lc: { [P in keyof LogLC]: LogLC[P] } = log_all ? { all: true } : undefined @@ -129,8 +129,8 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` export let geometry: BufferGeometry = undefined let geometry_ref: BufferGeometry = undefined - export const is_svelthree_component: boolean = true - export const is_svelthree_points: boolean = true + export const is_svelthree_component = true + export const is_svelthree_points = true // ONCE ON INITIALIZATION // @@ -146,6 +146,13 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Executed when / if an instance was provided **on initializiation** -> only once if at all! */ function on_instance_provided(): void { if (points.type === "Points") { + if (!points.geometry) { + throw new Error(`SVELTHREE > ${c_name} : provided 'points' instance has no geometry!`) + } + + if (!points.material) { + throw new Error(`SVELTHREE > ${c_name} : provided 'points' instance has no material!`) + } } else { throw new Error( `SVELTHREE > ${c_name} provided 'points' instance has wrong type '${points.type}', should be '${c_name}'!` @@ -351,6 +358,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` } // accessability -> shadow dom wai-aria + // eslint-disable-next-line no-undef export let aria: Partial = undefined $: if (shadow_dom_el && aria !== undefined) { @@ -616,7 +624,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` * In case `interact` prop is set / set to `true`, but no e.g. `on:` directives or `on_` internal actions are set, * the object will automatically become an _interaction occluder / blocker_. */ - export let block: boolean = false + export let block = false const interaction_on_clear = { interact: undefined, @@ -823,7 +831,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Animation logic to be performed with the (three) object instance created by the component. */ export let animation: SvelthreeAnimationFunction = undefined - let animationEnabled: boolean = false + let animationEnabled = false $: if (animation) animationEnabled = true /** Immediately start provided animation, default: `false`. Alternative: `.start_animation()` or shorter `.start_ani()`. */ diff --git a/src/lib/components/RectAreaLight.svelte b/src/lib/components/RectAreaLight.svelte index 0f90c5f..2d97e3a 100644 --- a/src/lib/components/RectAreaLight.svelte +++ b/src/lib/components/RectAreaLight.svelte @@ -55,7 +55,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` const verbose: boolean = verbose_mode() - export let log_all: boolean = false + export let log_all = false export let log_dev: { [P in keyof LogDEV]: LogDEV[P] } = log_all ? { all: true } : undefined export let log_rs: boolean = log_all export let log_lc: { [P in keyof LogLC]: LogLC[P] } = log_all ? { all: true } : undefined @@ -91,8 +91,8 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Sets the `name` property of the created / injected three.js instance. */ export let name: string = undefined - export const is_svelthree_component: boolean = true - export const is_svelthree_light: boolean = true + export const is_svelthree_component = true + export const is_svelthree_light = true // ONCE ON INITIALIZATION // @@ -108,6 +108,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Executed when / if an instance was provided **on initializiation** -> only once if at all! */ function on_instance_provided(): void { if (light.type === "RectAreaLight") { + //nothing } else { throw new Error( `SVELTHREE > ${c_name} provided 'light' instance has wrong type '${light.type}', should be '${c_name}'!` @@ -132,7 +133,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` if (browser) create_shadow_dom() } - let ral_ulib_initiated: boolean = false + let ral_ulib_initiated = false $: if (!ral_ulib_initiated) { ral_ulib_initiated = true RectAreaLightUniformsLib.init() @@ -212,6 +213,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` } // accessability -> shadow dom wai-aria + // eslint-disable-next-line no-undef export let aria: Partial = undefined $: if (shadow_dom_el && aria !== undefined) { @@ -405,7 +407,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Animation logic to be performed with the (three) object instance created by the component. */ export let animation: SvelthreeAnimationFunction = undefined - let animationEnabled: boolean = false + let animationEnabled = false $: if (animation) animationEnabled = true /** Immediately start provided animation, default: `false`. Alternative: `.start_animation()` or shorter `.start_ani()`. */ diff --git a/src/lib/components/Scene.svelte b/src/lib/components/Scene.svelte index d4da73c..9a9e325 100644 --- a/src/lib/components/Scene.svelte +++ b/src/lib/components/Scene.svelte @@ -72,7 +72,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` const verbose: boolean = verbose_mode() - export let log_all: boolean = false + export let log_all = false export let log_dev: { [P in keyof LogDEV]: LogDEV[P] } = log_all ? { all: true } : undefined export let log_rs: boolean = log_all export let log_lc: { [P in keyof LogLC]: LogLC[P] } = log_all ? { all: true } : undefined @@ -120,8 +120,8 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` export let name: string = undefined let scene_is_active: boolean = undefined - export const is_svelthree_component: boolean = true - export const is_svelthree_scene: boolean = true + export const is_svelthree_component = true + export const is_svelthree_scene = true // ONCE ON INITIALIZATION // @@ -137,6 +137,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Executed when / if an instance was provided **on initializiation** -> only once if at all! */ function on_instance_provided(): void { if (scene.type === "Scene") { + //nothing } else { throw new Error( `SVELTHREE > ${c_name} provided 'scene' instance has wrong type '${scene.type}', should be '${c_name}'!` @@ -261,6 +262,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` } // accessability -> shadow dom wai-aria + // eslint-disable-next-line no-undef export let aria: Partial = undefined $: if (shadow_dom_el && aria !== undefined) { @@ -612,7 +614,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` * In case `interact` prop is set / set to `true`, but no e.g. `on:` directives or `on_` internal actions are set, * the object will automatically become an _interaction occluder / blocker_. */ - export let block: boolean = false + export let block = false const interaction_on_clear = { interact: undefined, @@ -819,7 +821,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Animation logic to be performed with the (three) object instance created by the component. */ export let animation: SvelthreeAnimationFunction = undefined - let animationEnabled: boolean = false + let animationEnabled = false $: if (animation) animationEnabled = true /** Immediately start provided animation, default: `false`. Alternative: `.start_animation()` or shorter `.start_ani()`. */ diff --git a/src/lib/components/SpotLight.svelte b/src/lib/components/SpotLight.svelte index 12920d8..b9e2dff 100644 --- a/src/lib/components/SpotLight.svelte +++ b/src/lib/components/SpotLight.svelte @@ -61,7 +61,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` const verbose: boolean = verbose_mode() - export let log_all: boolean = false + export let log_all = false export let log_dev: { [P in keyof LogDEV]: LogDEV[P] } = log_all ? { all: true } : undefined export let log_rs: boolean = log_all export let log_lc: { [P in keyof LogLC]: LogLC[P] } = log_all ? { all: true } : undefined @@ -97,8 +97,8 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Sets the `name` property of the created / injected three.js instance. */ export let name: string = undefined - export const is_svelthree_component: boolean = true - export const is_svelthree_light: boolean = true + export const is_svelthree_component = true + export const is_svelthree_light = true // ONCE ON INITIALIZATION // @@ -114,6 +114,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Executed when / if an instance was provided **on initializiation** -> only once if at all! */ function on_instance_provided(): void { if (light.type === "SpotLight") { + //nothing } else { throw new Error( `SVELTHREE > ${c_name} provided 'light' instance has wrong type '${light.type}', should be '${c_name}'!` @@ -212,6 +213,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` } // accessability -> shadow dom wai-aria + // eslint-disable-next-line no-undef export let aria: Partial = undefined $: if (shadow_dom_el && aria !== undefined) { @@ -469,7 +471,7 @@ svelthree uses svelte-accmod, where accessors are always `true`, regardless of ` /** Animation logic to be performed with the (three) object instance created by the component. */ export let animation: SvelthreeAnimationFunction = undefined - let animationEnabled: boolean = false + let animationEnabled = false $: if (animation) animationEnabled = true /** Immediately start provided animation, default: `false`. Alternative: `.start_animation()` or shorter `.start_ani()`. */ diff --git a/src/lib/components/WebGLRenderer.svelte b/src/lib/components/WebGLRenderer.svelte index b44cdb4..7599739 100644 --- a/src/lib/components/WebGLRenderer.svelte +++ b/src/lib/components/WebGLRenderer.svelte @@ -33,7 +33,7 @@ This is a **svelthree** _WebGLRenderer_ Component. export const type: string = c_name const verbose: boolean = verbose_mode() - export let log_all: boolean = false + export let log_all = false export let log_dev: { [P in keyof LogDEV]: LogDEV[P] } = log_all ? { all: true } : undefined export let log_rs: boolean = log_all export let log_lc: { [P in keyof LogLC]: LogLC[P] } = log_all ? { all: true } : undefined @@ -76,7 +76,7 @@ This is a **svelthree** _WebGLRenderer_ Component. * An array of configuration objects specifying `Canvas` components incl. `Scene` and `Camera` components' `id`s that should be rendered. */ export let inputs: WebGLRendererInput[] = undefined - let inputs_processed: boolean = false + let inputs_processed = false const canvas_dom: Writable<{ element: HTMLCanvasElement }> = getContext("canvas_dom") // inside -> wait for canvas... @@ -146,7 +146,7 @@ This is a **svelthree** _WebGLRenderer_ Component. /** An array of `Canvas` components or `` DOM elements to rendered to. */ export let outputs: WebGLRendererOutput[] = undefined - let outputs_processed: boolean = false + let outputs_processed = false let first_outputs_canvas: HTMLCanvasElement | HTMLElement = undefined $: if (outputs?.length && outputs[0].canvas) first_outputs_canvas = outputs[0].canvas $: if (inside === false && first_outputs_canvas && inputs_processed) process_canvas_outputs() @@ -534,7 +534,7 @@ This is a **svelthree** _WebGLRenderer_ Component. const rAF = { id: undefined } const frames = { total: 0 } - export let enabled: boolean = true + export let enabled = true function start_renderer(): void { if (verbose && log_dev) console.debug(...c_dev(c_name, "start_renderer!")) diff --git a/src/lib/constants/LogCSS.ts b/src/lib/constants/LogCSS.ts index 48a89d3..5dc8c34 100644 --- a/src/lib/constants/LogCSS.ts +++ b/src/lib/constants/LogCSS.ts @@ -1,16 +1,16 @@ export default class LogCSS { - public static PREFIX_ON_MOUNT: string = "☰" - public static PREFIX_BEFORE_UPDATE: string = "~" - public static PREFIX_AFTER_UPDATE: string = "✓" + public static PREFIX_ON_MOUNT = "☰" + public static PREFIX_BEFORE_UPDATE = "~" + public static PREFIX_AFTER_UPDATE = "✓" - public static REACTIVE_STATEMENT: string = "color:red; font-weight:bold;" - public static BEFORE_UPDATE: string = + public static REACTIVE_STATEMENT = "color:red; font-weight:bold;" + public static BEFORE_UPDATE = "font-weight:bold; color: #A5F3FC; background: #4B5563; padding: 2px 4px; border: 1px solid #4B5563; border-radius: 6px;" - public static AFTER_UPDATE: string = + public static AFTER_UPDATE = "font-weight:bold; background: #4B5563; color: #BBF7D0; padding: 2px 4px; border: 1px solid #4B5563; border-radius: 6px;" - public static ON_MOUNT: string = + public static ON_MOUNT = "font-weight:bold; background: #4B5563; color: white; padding: 2px 4px; border: 1px solid #4B5563; border-radius: 6px;" - public static DEV_DEBUG: string = "font-weight:normal" - public static FEATURE_MAU: string = "font-weight:normal" + public static DEV_DEBUG = "font-weight:normal" + public static FEATURE_MAU = "font-weight:normal" } diff --git a/src/lib/types/types-extra.ts b/src/lib/types/types-extra.ts index a94b175..b3f417c 100644 --- a/src/lib/types/types-extra.ts +++ b/src/lib/types/types-extra.ts @@ -6,8 +6,6 @@ export type Constructor = { export type Array3 = [number, number, number] export type Array4 = [number, number, number, string] -export type Params = T extends new (...params: any) => any ? ConstructorParameters : T - // see https://stackoverflow.com/questions/49579094/typescript-conditional-types-filter-out-readonly-properties-pick-only-requir export type IfEquals = (() => T extends X ? 1 : 2) extends () => T extends Y ? 1 : 2 ? A @@ -83,6 +81,7 @@ export interface SvelthreeAnimationFunctionReturn { * _Usually used for continuing the animation in a multiple top-level Scenes scenario._ */ onSceneReactivated?: () => void + // TODO (ESLint -> 'no-explicit-any') see https://github.com/vatro/svelthree/issues/165 [anything: string]: any } @@ -114,6 +113,7 @@ export interface SvelthreeAnimationFunctionReturn { */ /*eslint @typescript-eslint/no-explicit-any: ["error", { "ignoreRestArgs": true }]*/ export interface SvelthreeAnimationFunction { + // TODO (ESLint -> 'no-explicit-any') see https://github.com/vatro/svelthree/issues/165 (obj: any, ...args: any[]): SvelthreeAnimationFunctionReturn } diff --git a/src/lib/utils/Calc.ts b/src/lib/utils/Calc.ts index cb5e332..56b2676 100644 --- a/src/lib/utils/Calc.ts +++ b/src/lib/utils/Calc.ts @@ -2,14 +2,12 @@ import { Vector3 } from "three" import type { PerspectiveCamera, OrthographicCamera } from "three" export default class Calc { - constructor() {} - public static get_unproject_pointer( c: HTMLCanvasElement, e: PointerEvent, cam: PerspectiveCamera | OrthographicCamera ): Vector3 { - let rect: DOMRect = c.getBoundingClientRect() + const rect: DOMRect = c.getBoundingClientRect() const px = ((e.clientX - rect.left) / (rect.right - rect.left)) * 2 - 1 const py = -((e.clientY - rect.top) / (rect.bottom - rect.top)) * 2 + 1 @@ -18,19 +16,19 @@ export default class Calc { // Perspective Camera // see: https://stackoverflow.com/questions/13055214/mouse-canvas-x-y-to-three-js-world-x-y-z - let v: Vector3 = new Vector3(px, py, 0.5) - let t: Vector3 = new Vector3() + const v: Vector3 = new Vector3(px, py, 0.5) + const t: Vector3 = new Vector3() v.unproject(cam) v.sub(cam.position).normalize() - let d = -cam.position.z / v.z + const d = -cam.position.z / v.z //let d = ( unproject_z - cam.position.z ) / v.z t.copy(cam.position).add(v.multiplyScalar(d)) return t } else if (cam.type === "OrthographicCamera") { - let vz: number = (cam.near + cam.far) / (cam.near - cam.far) - let v: Vector3 = new Vector3(px, py, vz) + const vz: number = (cam.near + cam.far) / (cam.near - cam.far) + const v: Vector3 = new Vector3(px, py, vz) v.unproject(cam).sub(cam.position) return v diff --git a/src/lib/utils/CameraUtils.ts b/src/lib/utils/CameraUtils.ts index d0d0de2..d2ee741 100644 --- a/src/lib/utils/CameraUtils.ts +++ b/src/lib/utils/CameraUtils.ts @@ -41,10 +41,10 @@ export default class CameraUtils { // abilty to have (blank) //const _frustumSize = frustumSize || CameraValues.CAM_ORTHO_FRUSTUM_SIZE - let left = (frustumSize * aspect) / -2 - let right = (frustumSize * aspect) / 2 - let top = frustumSize / 2 - let bottom = frustumSize / -2 + const left = (frustumSize * aspect) / -2 + const right = (frustumSize * aspect) / 2 + const top = frustumSize / 2 + const bottom = frustumSize / -2 cam.left = left cam.right = right diff --git a/src/lib/utils/CubeCameraHelper.ts b/src/lib/utils/CubeCameraHelper.ts index 2a3844f..3ce8ee6 100644 --- a/src/lib/utils/CubeCameraHelper.ts +++ b/src/lib/utils/CubeCameraHelper.ts @@ -9,10 +9,10 @@ export default class CubeCameraHelper { } private createHelpers(camera: CubeCamera): CameraHelper[] { - let all: CameraHelper[] = [] + const all: CameraHelper[] = [] for (let i = 0; i < camera.children.length; i++) { - let pc: PerspectiveCamera = (camera.children as PerspectiveCamera[])[i] - let helper = new CameraHelper(pc) + const pc: PerspectiveCamera = (camera.children as PerspectiveCamera[])[i] + const helper = new CameraHelper(pc) all.push(helper) } return all diff --git a/src/lib/utils/GLTF_afterLoaded.ts b/src/lib/utils/GLTF_afterLoaded.ts index cc327b9..1d37271 100644 --- a/src/lib/utils/GLTF_afterLoaded.ts +++ b/src/lib/utils/GLTF_afterLoaded.ts @@ -57,7 +57,7 @@ export default class GLTF_afterLoaded { if (obj[typ]) { // see https://github.com/mrdoob/three.js/blob/1a241ef10048770d56e06d6cd6a64c76cc720f95/src/core/Object3D.js#L342-L369 if (parent) { - let index_to_remove: number = parent.children.indexOf(obj) + const index_to_remove: number = parent.children.indexOf(obj) //console.log(`removing -> [${index_to_remove}] ${obj.type}`, obj.uuid) parent.children.splice(index_to_remove, 1) } @@ -70,7 +70,7 @@ export default class GLTF_afterLoaded { } } - function traverse(child: Object3D, parent?: Object3D) { + const traverse = (child: Object3D, parent?: Object3D) => { fns.push(check_obj(child, parent, typ)) const children = child.children for (let i = 0, l = children.length; i < l; i++) { @@ -106,7 +106,7 @@ export default class GLTF_afterLoaded { (obj: Object3D, props: { [P in keyof AnyMeshMaterialProps]: AnyMeshMaterialProps[P] }) => async () => { if (obj) { if (obj["isMesh"] && obj["material"]) { - for (let prop in props) { + for (const prop in props) { try { obj["material"][prop] = props[prop] } catch (e) { @@ -122,7 +122,10 @@ export default class GLTF_afterLoaded { } } - function traverse(child: Object3D, props: { [P in keyof AnyMeshMaterialProps]: AnyMeshMaterialProps[P] }) { + const traverse = ( + child: Object3D, + props: { [P in keyof AnyMeshMaterialProps]: AnyMeshMaterialProps[P] } + ) => { fns.push(check_obj(child, props)) const children = child.children for (let i = 0, l = children.length; i < l; i++) { @@ -159,7 +162,7 @@ export default class GLTF_afterLoaded { (obj: Object3D, props: { [P in keyof MeshProperties]: MeshProperties[P] }) => async () => { if (obj) { if (obj["isMesh"]) { - for (let prop in props) { + for (const prop in props) { try { obj[prop] = props[prop] } catch (e) { @@ -175,7 +178,7 @@ export default class GLTF_afterLoaded { } } - function traverse(child: Object3D, props: { [P in keyof MeshProperties]: MeshProperties[P] }) { + const traverse = (child: Object3D, props: { [P in keyof MeshProperties]: MeshProperties[P] }) => { fns.push(check_obj(child, props)) const children = child.children for (let i = 0, l = children.length; i < l; i++) { @@ -211,7 +214,7 @@ export default class GLTF_afterLoaded { const check_obj = (obj: Object3D, props: { [P in keyof AnyLightProps]: AnyLightProps[P] }) => async () => { if (obj) { if (obj["isLight"]) { - for (let prop in props) { + for (const prop in props) { try { obj[prop] = props[prop] } catch (e) { @@ -227,7 +230,7 @@ export default class GLTF_afterLoaded { } } - function traverse(child: Object3D, props: { [P in keyof AnyLightProps]: AnyLightProps[P] }) { + const traverse = (child: Object3D, props: { [P in keyof AnyLightProps]: AnyLightProps[P] }) => { fns.push(check_obj(child, props)) const children = child.children for (let i = 0, l = children.length; i < l; i++) { diff --git a/src/lib/utils/GLTF_utils.ts b/src/lib/utils/GLTF_utils.ts index 87090df..59aff9a 100644 --- a/src/lib/utils/GLTF_utils.ts +++ b/src/lib/utils/GLTF_utils.ts @@ -96,7 +96,7 @@ export default class GLTF_utils { } } - function traverse(child: Object3D) { + const traverse = (child: Object3D) => { fns.push(check_obj(child, check, found)) const children = child.children for (let i = 0, l = children.length; i < l; i++) { diff --git a/src/lib/utils/LightTarget.ts b/src/lib/utils/LightTarget.ts index 02fb34f..ec32a6a 100644 --- a/src/lib/utils/LightTarget.ts +++ b/src/lib/utils/LightTarget.ts @@ -18,7 +18,7 @@ export default class LightTarget { public on_light_target_change() { this.change = false - if (this.light.hasOwnProperty("target")) { + if (Object.prototype.hasOwnProperty.call(this.light, "target")) { // remove current target from parent if it's a built-in target if (this.light["target"]?.userData.is_builtin_target && this.light["target"].parent) { this.light["target"].parent.remove(this.light["target"]) diff --git a/src/lib/utils/PropUtils.ts b/src/lib/utils/PropUtils.ts index ce2904b..9d4a827 100644 --- a/src/lib/utils/PropUtils.ts +++ b/src/lib/utils/PropUtils.ts @@ -16,7 +16,7 @@ import { verbose_mode, log_prop_utils } from "../utils/SvelthreeLogger" */ export default class PropUtils { public static getShortHandAttrWarnings(prefix: string): { [key: string]: any } { - let warnings = { + const warnings = { rot: `${prefix} 'rot' attribute ignored! : overridden by either 'matrix' or 'quat' attribute!`, pos: `${prefix} 'pos' attribute ignored! : overridden by 'matrix' attribute!`, quat: `${prefix} 'quat' attribute ignored! : overridden by 'matrix' attribute!`, @@ -329,7 +329,7 @@ export default class PropUtils { // limit using manipulating `target` via `lookAt` to lights only if (obj["isLight"]) { // THREE IMPORTANT Only DirectionalLight and SpotLight have own `target` properties. Object3D does not. - if (obj.hasOwnProperty("target")) { + if (Object.prototype.hasOwnProperty.call(obj, "target")) { if (obj["target"].isObject3D) { if (obj.matrixAutoUpdate === false) { obj["target"].matrixAutoUpdate = false @@ -532,7 +532,7 @@ export default class PropUtils { if (val["isObject3D"]) { obj["target"] = val } else if (val["is_svelthree_component"]) { - let obj3d: Object3D = (val as TargetableSvelthreeComponent).get_instance() + const obj3d: Object3D = (val as TargetableSvelthreeComponent).get_instance() obj["target"] = obj3d } else { console.error(`[ PropUtils ] -> setLightTarget : invalid 'target' value!`, { val }) diff --git a/src/lib/utils/PropUtilsComplex.ts b/src/lib/utils/PropUtilsComplex.ts deleted file mode 100644 index 1f9437a..0000000 --- a/src/lib/utils/PropUtilsComplex.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { ComplexValueType } from "../types/types-extra" - -export default class PropUtilsComplex { - public static check(complex: ComplexValueType) { - switch (complex) { - case "Array3Nums": - break - default: - break - } - } - - public static checkArray3Nums() {} -} diff --git a/src/lib/utils/Propeller.ts b/src/lib/utils/Propeller.ts index 4e49f56..2c73574 100644 --- a/src/lib/utils/Propeller.ts +++ b/src/lib/utils/Propeller.ts @@ -63,7 +63,7 @@ export default class Propeller { default: // update `CubeCamera`'s `renderTargetProps` prop (`CubeTexture`) if (obj_type === "WebGLCubeRenderTarget") { - let cubeRenderTarget = obj as WebGLCubeRenderTarget + const cubeRenderTarget = obj as WebGLCubeRenderTarget PropUtils.applyValueToProp(cubeRenderTarget.texture, value, key) } else { // no wildcard updating of **inherited** properties via `Proppeller` -> show error in the console. diff --git a/src/lib/utils/RaycastArray.ts b/src/lib/utils/RaycastArray.ts index 1cc7c31..6a41432 100644 --- a/src/lib/utils/RaycastArray.ts +++ b/src/lib/utils/RaycastArray.ts @@ -4,7 +4,7 @@ import type { RaycastableSvelthreeComponents } from "../types/types-extra" class RaycastArray_Base extends Array { public head_path?: string[] | undefined = undefined public index_prop: string | undefined = undefined - public dirty: boolean = false + public dirty = false constructor(...args: any[]) { super(...args) diff --git a/src/lib/utils/RendererUtils.svelte b/src/lib/utils/RendererUtils.svelte index 3531cbd..ac05794 100644 --- a/src/lib/utils/RendererUtils.svelte +++ b/src/lib/utils/RendererUtils.svelte @@ -7,7 +7,7 @@ renderer_component: WebGLRenderer, event_name: string, callback: () => void, - skip_frames: number = 0 + skip_frames = 0 ) => { let skip = 0 let remove_on_render_event: () => void = undefined diff --git a/src/lib/utils/SvelthreeProps.ts b/src/lib/utils/SvelthreeProps.ts index c21ffb4..51aef4c 100644 --- a/src/lib/utils/SvelthreeProps.ts +++ b/src/lib/utils/SvelthreeProps.ts @@ -125,7 +125,7 @@ export default class SvelthreeProps { this.updatedKeys = [] // analyze and sort `props` object's properties - for (let k in props) { + for (const k in props) { const complexType: ComplexValueType | undefined = PropUtils.checkIfComplexValueType(props[k]) const is_own_prop: any = has_prop(this.obj, k) const is_inherited_prop: boolean = is_own_prop ? false : this.obj[k] ? true : false diff --git a/src/lib/utils/props/PropColorX.ts b/src/lib/utils/props/PropColorX.ts index ae49912..d24dc6c 100644 --- a/src/lib/utils/props/PropColorX.ts +++ b/src/lib/utils/props/PropColorX.ts @@ -20,7 +20,7 @@ export default class PropColorX { case value: // same object, perform deep check - for (let k in this.prevValues) { + for (const k in this.prevValues) { if (not_equal(this.prevValues[k], value[k])) { Propeller.update(obj, this.obj_type, this.key, value, this.origin, "Color") this.setPrevValues(value) diff --git a/src/lib/utils/props/PropEulerX.ts b/src/lib/utils/props/PropEulerX.ts index 6f006ec..aa353c9 100644 --- a/src/lib/utils/props/PropEulerX.ts +++ b/src/lib/utils/props/PropEulerX.ts @@ -20,7 +20,7 @@ export default class PropEulerX { case value: // same object, perform deep check - for (let k in this.prevValues) { + for (const k in this.prevValues) { if (not_equal(this.prevValues[k], value[k])) { Propeller.update(obj, this.obj_type, this.key, value, this.origin, "Euler") this.setPrevValues(value) diff --git a/src/lib/utils/props/PropQuaternionX.ts b/src/lib/utils/props/PropQuaternionX.ts index 53747e5..696ed25 100644 --- a/src/lib/utils/props/PropQuaternionX.ts +++ b/src/lib/utils/props/PropQuaternionX.ts @@ -20,7 +20,7 @@ export default class PropQuaternionX { case value: // same object, perform deep check - for (let k in value) { + for (const k in value) { if (not_equal(this.prevValues[k], value[k])) { Propeller.update(obj, this.obj_type, this.key, value, this.origin, "Quaternion") this.setPrevValues(value) diff --git a/src/lib/utils/props/PropVector3X.ts b/src/lib/utils/props/PropVector3X.ts index de296eb..0905742 100644 --- a/src/lib/utils/props/PropVector3X.ts +++ b/src/lib/utils/props/PropVector3X.ts @@ -20,7 +20,7 @@ export default class PropVector3X { case value: // same object, perform deep check - for (let k in value) { + for (const k in value) { if (not_equal(this.prevValues[k], value[k])) { Propeller.update(obj, this.obj_type, this.key, value, this.origin, "Vector3") this.setPrevValues(value)