Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include TypeScript type definitions on npm package #1502

Closed
10 tasks
aviggiano opened this issue Sep 3, 2020 · 39 comments
Closed
10 tasks

Include TypeScript type definitions on npm package #1502

aviggiano opened this issue Sep 3, 2020 · 39 comments
Labels

Comments

@aviggiano
Copy link

aviggiano commented Sep 3, 2020

Description

I'm using this module on a TypeScript React app through npm and I've noticed that it is missing its type definitions.
More specifically, I'm interested in using the Scene Graph API without having to debug or deep dive into the examples and glTF documentation.

I'm currently using the following:

declare global {
  namespace JSX {
    interface IntrinsicElements {
      'model-viewer': ModelViewerJSX & React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> ;
    }
  }
}

interface ModelViewerJSX {
  src: string
  poster?: string
  // ... others
}

interface ModelViewerElement extends Element {
  model: {
    materials: Array<{
      name: string,
      pbrMetallicRoughness: {
        setBaseColorFactor: ((x: [number, number, number, number]) => void),
        setMetallicFactor: ((x: number) => void),
        setRoughnessFactor: ((x: number) => void),

        baseColorTexture: null | {
          texture: {
            source: {
              setURI: ((x: string) => void),
            }
          }
        }
        metallicRoughnessTexture: null | {
          texture: {
            source: {
              setURI: ((x: string) => void),
            }
          }
        }
        // ... others
      }
    }>
  }
}

I believe these definitions are probably already inside the model-viewer repo, but are not getting exported to npm

Live Demo

N/A

Version

  • model-viewer: v1.2.1

Browser Affected

  • Chrome
  • Edge
  • Firefox
  • IE
  • Safari

OS

  • Android
  • iOS
  • Linux
  • MacOS
  • Windows
@elalish elalish added the type: feature New feature or request label Sep 3, 2020
@elalish
Copy link
Contributor

elalish commented Sep 3, 2020

Good call; we're TS internally, so I'll see if we can get our bundler to generate a proper .d.ts file.

@MariusVB
Copy link

Progress on this?

@elalish
Copy link
Contributor

elalish commented Dec 28, 2020

@MariusVB A contribution here would be much appreciated if anyone knows a tool that can create a top-level .d.ts file from a bundled library like ours. The alternative is maintaining the file manually, which seems awfully error-prone.

@MariusVB
Copy link

MariusVB commented Dec 28, 2020

@elalish
Copy link
Contributor

elalish commented Dec 28, 2020

@MariusVB Well, it looks like that probably won't generate complete typings, but you're welcome to give it a try. As I said, I would really like to have something that automatically produces the proper API typings (since all the type info in already contained in our TS source). If that's impossible, the second best would be some kind of test that checks that a manually-created .d.ts file is consistent with our source.

@Sheldonfrith
Copy link

What about the second answer in this thread (the one by magikMaker) https://stackoverflow.com/questions/12687779/how-do-you-produce-a-d-ts-typings-definition-file-from-an-existing-javascript ?

@elalish
Copy link
Contributor

elalish commented Jan 6, 2021

@Sheldonfrith The trouble is we want a .d.ts file for our public API, not for every internal class of the project. What we really want is this: microsoft/TypeScript#4433, but while that's not making much progress I did just notice an interesting comment about this solution: https://github.com/Swatinem/rollup-plugin-dts, which is the most promising thing I've seen yet. May have to give that a try.

@jeffscottward
Copy link

Bump - March 2021

@JanSob
Copy link

JanSob commented Apr 7, 2021

Also bump..I assume many webdevs use Angular/React with Typescript, so having type definitions would make model-viewer more accessible..

@elalish
Copy link
Contributor

elalish commented Jun 18, 2021

Would this help? Or is this orthogonal? https://dev.to/open-wc/introducing-custom-elements-manifest-gkk

@darwinshameran
Copy link

Bump - July 2021

@michaelkochhugobosscom
Copy link

would love to have the typings ..

@AhrenFullStop
Copy link

bump August 2021

@jeffscottward
Copy link

jeffscottward commented Aug 10, 2021 via email

@jeffscottward
Copy link

jeffscottward commented Aug 10, 2021 via email

@elalish
Copy link
Contributor

elalish commented Aug 10, 2021

Okay, so I need some feedback here because this is a surprisingly complicated topic. First thing: we do and have for quite some time published our .d.ts files: https://www.unpkg.com/browse/@google/model-viewer@1.8.0/lib/

What we don't have is a unified .d.ts file for our bundle, but if you're writing TS, do you really want to use our bundled version? Our thought was that those who wanted to incorporate our project at a deeper level (i.e. into a larger TS project) would probably rather import the lib, allowing you to do things like e.g. deduplicate three.js if you're also using it elsewhere. Of course if you want to stay in the land of public API, you'll need to only import model-viewer.d.ts (and avoid any symbols), as the rest of those types are private.

Has anyone tried this? I'm not very familiar with modern tools for building React/Angular apps, so I need some feedback from those who are. Also, is it possible we are missing some configuration in our package.json that would make this easier or more automatic?

@jeffscottward
Copy link

jeffscottward commented Aug 12, 2021 via email

@AhrenFullStop
Copy link

I found a solution if you are using Angular. Go to the @NgModule that imports the component that you are using model-viewer on. For me this was my component.module.ts but might be your app.module.ts
Then look inside the @NgModule, you will have imports, declarations and exports. simply add
schemas: [CUSTOM_ELEMENTS_SCHEMA]
-- make sure to
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';

This stops any errors.

@elalish
Copy link
Contributor

elalish commented Aug 12, 2021

@jeffscottward Yes, I agree and I want to make this as seamless as I can. What does your toolchain look like for installing deps for your React app (you'll have to start at the beginning, since I'm not a React user myself). I'm hoping there's a way to simply depend on our lib directly, which includes the types, rather than on the bundle. It's possible there's something I need to change in our package.json to facilitate this, but I'm not sure what parts your toolchain reads (different tools do it differently). How do you specify your model-viewer dep currently?

@jeffscottward
Copy link

jeffscottward commented Aug 12, 2021

@jeffscottward Yes, I agree and I want to make this as seamless as I can. What does your toolchain look like for installing deps for your React app (you'll have to start at the beginning, since I'm not a React user myself). I'm hoping there's a way to simply depend on our lib directly, which includes the types, rather than on the bundle. It's possible there's something I need to change in our package.json to facilitate this, but I'm not sure what parts your toolchain reads (different tools do it differently). How do you specify your model-viewer dep currently?

I use Next.js right out of the box with typescript
https://nextjs.org/docs/basic-features/typescript

I use yarn instead of npm to install deps but same difference.

For model-viewer I include <script> tags in <head> of _app.tsx file in pages folder

Here are the tags

<script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script>
<script src="https://unpkg.com/focus-visible@5.1.0/dist/focus-visible.js"></script>

I was having weird trouble with the npm module - some issues with a legacy version?
I have this in my code

// import "@google/model-viewer/dist/model-viewer-legacy" 
// https://github.com/google/model-viewer/issues/690

An attempt was made at some point to do typescript (honestly Im not very good at TS but I know the value of it)

// TODO: Clean this up once fixed
// https://github.com/google/model-viewer/issues/1502
declare global {
  namespace JSX {
    interface IntrinsicElements {
      'model-viewer': ModelViewerJSX &
        React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>
    }
  }
}

But yea ideally I want to just npm install, and import, and be done with it.
ie.

 import { ModelViewer } from "@google/model-viewer" 
 or
 import ModelViewer from "@google/model-viewer" 

I think I would be happiest with an index.d.ts file instead of seperate package for that like so
ex. https://github.com/axios/axios/blob/master/index.d.ts

@elalish
Copy link
Contributor

elalish commented Aug 12, 2021

First thing's first, we've removed IE support, so there is no "legacy" anymore. Seems it's also no longer necessary: #690 (comment)

I'm also curious what would happen if you import the library instead of the bundle: @google/model-viewer/lib/model-viewer.js.

Please let me know if any of this bears fruit. I think we're pretty close.

@jeffscottward
Copy link

jeffscottward commented Aug 12, 2021

Your docs do not explain how to actually import it via NPM
https://www.npmjs.com/package/@google/model-viewer

Also I get a compile error right away with this minimum react code

import ModelViewer from '@google/model-viewer/lib/model-viewer'

const Test = () => {
  console.log(ModelViewer)
  return (
    <div>

    </div>
  )
}

export default Test
wait  - compiling...
error - ./node_modules/@google/model-viewer/lib/features/animation.js:21:0
Module not found: Can't resolve 'lit-element'
null

@aviggiano
Copy link
Author

aviggiano commented Aug 12, 2021

@jeffscottward actually you should use it this way

import '@google/model-viewer/lib/model-viewer'

const Test = () => {
  return (
    <model-viewer src="..."/>
  )
}

export default Test

@elalish I created a MWE here that can help

Literally 3 lines of code to reproduce from scratch

npx create-react-app create-react-app-model-viewer --template typescript
cd create-react-app-model-viewer
yarn add @google/model-viewer

Then yarn start to test it. Try importing and adding a <model-viewer> element to the App.tsx file and it won't compile because of the type definitions. After manually adding the model-viewer declaration to the global namespace, it will work.

screenshot-2021-08-12-19-27-08

@jeffscottward
Copy link

@jeffscottward actually you should use it this way

import '@google/model-viewer/lib/model-viewer'

const Test = () => {
  return (
    <model-viewer src="..."/>
  )
}

export default Test

@elalish I created a MWE here that can help

Literally 3 lines of code to reproduce from scratch

npx create-react-app create-react-app-model-viewer --template typescript
cd create-react-app-model-viewer
yarn add @google/model-viewer

Then yarn start to test it. Try importing and adding a <model-viewer> element to the App.tsx file and it won't compile because of the type definitions. After manually adding the model-viewer declaration to the global namespace, it will work.

screenshot-2021-08-12-19-27-08

Couple of items here

  1. You did import '@google/model-viewer' not import '@google/model-viewer/lib/model-viewer'

  2. Thats a non-standard way of importing React components - for CSS ok as there is not top level object/function, but for tooling and idiomatic authoring, there should be an export, not an assumed namespace.

  3. After manually adding the model-viewer declaration to the global namespace, it will work. yea this basically what I had to do above, obv shouldn't be required to just plug and play

@aviggiano
Copy link
Author

@jeffscottward I agree, but this lib does not have a default export (I believe), so you can't do import ModelViewer from ...

@elalish
Copy link
Contributor

elalish commented Aug 12, 2021

Yeah, this is interesting; I have the feeling we may just need to patch up our package.json. I'm guessing when you import @google/model-viewer it may just follow the "module" path: "module": "dist/model-viewer.min.js"? In which case you're getting right back to the bundled version. Consider the error about lit-element, I'd guess we need to change our dependencies listing; it seems three.js and lit should probably be under "dependencies" instead of "devDependencies" so that React will know to go get them if you import the lib version. Now I just wish I had a way to test this before publishing to npm...

@elalish
Copy link
Contributor

elalish commented Aug 12, 2021

@jeffscottward I agree, but this lib does not have a default export (I believe), so you can't do import ModelViewer from ...

Would a default export be preferable? I don't have an opinion on this, just trying to figure out best practices. Here is our entry point: https://github.com/google/model-viewer/blob/master/packages/model-viewer/src/model-viewer.ts

@jeffscottward
Copy link

@elalish yes so you can name it whatever you feel like as opposed to having to look it up.
Or explicitly named *if you are exporting multiple objects.

Wherever it lands do please make sure to update the README of course :)
https://github.com/google/model-viewer/tree/master/packages/model-viewer#installing

BTW the npm page for the module sends you to the top of monorepo not to the viewer package - was confusing why I was seeing a different readme
https://www.npmjs.com/package/@google/model-viewer
vs
https://github.com/google/model-viewer

@Ducki
Copy link

Ducki commented Sep 17, 2021

Is there any progress or update on this?

@flashjpr
Copy link

Bump Nov

@adpops
Copy link

adpops commented Jan 15, 2022

Bump

@elalish
Copy link
Contributor

elalish commented Jan 15, 2022

We could really use a contribution here. The main reason I haven't done this is because I don't know a good way to test if what I'm doing works (since I have no experience with React/yarn/npx etc). Is anyone up for making a PR to tweak our package.json until the lib version of our library can be easily found and used? All the TS declarations are there, we just seem to be missing a little glue (and perhaps instructions).

@MathiasKandelborg
Copy link

Exciting stuff, I'll try and look into this. Not immediately, but I'm about to use the npm package in my typescript project, and I very much would love to just import model-viewer and have it over with, and I might be able to accomplish that.

Thanks for the great work so far!

@elalish
Copy link
Contributor

elalish commented Mar 14, 2022

I'm hoping we have a fix now that will go out with our next release, that will mean importing our lib rather than the bundle (which is the right way anyway for a project with its own build step). We had some errors in how our package.json was set up that was preventing this method. Not completely sure it's correct now, but hopeful.

@ranfysvalle02
Copy link

ranfysvalle02 commented Apr 6, 2022

While not a "fix" - I was able to get it working by just using "// @ts-nocheck" at the top of the file that was using model-viewer

@elalish
Copy link
Contributor

elalish commented Apr 6, 2022

I believe this has been fixed in our v1.11 release. I'm going to close this (a little hopefully) to notify people, but please comment a post a new issue if it's still not working for you.

@elalish elalish closed this as completed Apr 6, 2022
@subhankar-trisetra
Copy link
Contributor

For the ones, still facing problem, I've used this in my project:

import { Vector3 } from 'three';
import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader';
// Add model-viewer to the IntrinsicElements list
declare global {
    namespace JSX {
        interface IntrinsicElements {
            'model-viewer': ModelViewerElement;
        }
    }
}
export interface ModelViewerElement extends Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>, 'ref'> {
    /**
     * The URL to the 3D model. Only glTF/GLB models are supported.
     */
    src?: string;

    'ios-src'?: string;
    /**
     * Configures the model with custom text that will be used to describe the model to viewers who use a screen reader or otherwise
     * depend on additional semantic context to understand what they are viewing.
     */
    alt?: string;
    /**
     * Displays an image instead of the model, useful for showing the user something before a model is loaded and ready to render.
     * If you use a poster with transparency, you may also want to set --poster-color to transparent so that the background shows through.
     */
    poster?: string;
    /**
     * If you're using a seamless poster as generated by toBlob({idealAspect: true}) with --poster-color transparent (which is recommended),
     * then enable this attribute to turn off the poster's transition. This keeps the shadow from blinking, and the transition is no longer necessary anyway since the poster matches the rendering.
     */
    'seamless-poster'?: boolean;
    /**
     * An enumerable attribute describing under what conditions the model should be preloaded. The supported values are "auto", "lazy" and "eager". Auto is equivalent to lazy, which loads the model
     * when it is near the viewport for reveal="auto", and when interacted with for reveal="interaction". Eager loads the model immediately.
     */
    loading?: 'eager' | 'lazy' | 'auto';
    /**
     * This attribute controls when the model should be revealed. It currently supports three values: "auto", "interaction", and "manual".
     * If reveal is set to "interaction", <model-viewer> will wait until the user interacts with the poster before loading and revealing the model.
     * If reveal is set to "auto", the model will be revealed as soon as it is done loading and rendering. If reveal is set to "manual",
     * the model will remain hidden until dismissPoster() is called.
     *
     * @example: https://modelviewer.dev/examples/loading#preload
     */
    reveal?: 'auto' | 'interaction' | 'manual';
    /**
     * This attribute makes the browser include credentials (cookies, authorization headers or TLS client certificates) in the request to fetch the 3D model. It's useful if the 3D model file is stored on another server that require authentication. By default the file will be fetch without credentials. Note that this has no effect if you are loading files locally or from the same domain.
     */
    'with-credentials'?: boolean;
    /**
     * Controls the environmental reflection of the model. Normally if skybox-image is set, that image will also be used for the environment-image. Use environment-image to only set the reflection without affecting the background. If neither is specified, default lighting will be applied. If 'neutral' is specified without a skybox, then a more evenly-lit environment is applied instead.
     */
    'environment-image'?: string;
    'camera-controls'?: boolean;
    'disable-zoom'?: boolean;
    'auto-rotate'?: boolean;
    ar?: boolean;
    autoplay?: boolean;
    'shadow-intensity'?: number | string;
    'ar-scale'?: number | string;
    bounds?: string;
    style?: React.CSSProperties;
    ref?: React.MutableRefObject<ModelViewer | undefined>;
}

export interface ModelViewer extends ModelViewerElement {
    /**
     * This property is read-only. It returns true if the load event below has fired since the last src change.
     */
    readonly loaded: boolean;
    /**
     * This property, pronounced model-is-visible, is read-only. It returns true if the element is visible on the page (assuming there is an IntersectionObserver) and the poster has been dismissed. This property is related to the model-visibility event.
     */
    readonly modelIsVisible: boolean;
    /**
     * This object contains all the methods for the materials API. See examples for usage.
     */
    readonly model: Model;
    /**
     * This property reports an array of strings, corresponding to variants in the loaded model that can be selected with variant-name.
     */
    readonly availableVariants: string[];
    /**
     * Returns a readonly copy of the GLTF JSON object as loaded. Changing this object has no affect on the scene and changes made through
     * the materials API are not reflected here. This object is useful for reverting individual changes made through the materials API.
     */
    readonly originalGltfJson: GLTF;
    /**
     * This static, writable property sets <model-viewer>'s DRACO decoder location URL. By default, the DRACO decoder will be loaded from a Google CDN.
     * @example https://modelviewer.dev/examples/loading/#dracoSupport
     */
    dracoDecoderLocation: string;
    /**
     * This static, writable property sets <model-viewer>'s KTX2 transcoder location URL. By default, the KTX2 transcoder will be loaded from a Google CDN.
     * @example https://modelviewer.dev/examples/loading/#ktx2Support
     */
    ktx2TranscoderLocation: string;
    /**
     * Rotates the model to the orientation specified by roll, pitch, yaw Euler angles, where yaw is first applied about the Y-axis, then pitch about the new local X-axis (positive is front-down), then roll about the new local Z-axis. If specified before the model loads, automatic camera framing will take this change into account; otherwise the updateFraming() method must be called manually.
     * Default Value: 0deg 0deg 0deg
     * Options: $roll $pitch $yaw
     */
    orientation: string;
    /**
     * Scales the model as specified in the X, Y, and Z directions. Scale is applied before orientation. If specified before the model loads, automatic camera framing will take this change into account; otherwise the updateFraming() method must be called manually.
     * Default Value: 1 1 1
     * Options: $x $y $z
     */
    scale: string;
    /**
     *
     */
    cameraOrbit: string;
    /**
     * Dismisses the poster, causing the model to load and render if necessary. This is currently effectively the same as interacting with the poster via user input.
     */
    dismissPoster(): void;
    /**
     * Shows the poster, hiding the model. If this is called after the 3D model has been revealed, then it will behave as though reveal='interaction', being dismissed either by a user click or a call to dismissPoster().
     */
    showPoster(): void;
    /**
     * Returns the model's bounding box dimensions in meters, independent of turntable rotation. The returned object has x, y, and z properties along with a toString() method.
     */
    getDimensions(): {
        x: number;
        y: number;
        z: number;
        toString(): string;
    };
    /**
     * Create your own Texture object.
     */
    createTexture(uri: string, type?: 'image/png' | 'image/jpeg' | 'image/webp'): Promise<Texture>;
    /**
     *
     * @param clientX
     * @param clientY
     * @return Material
     * Returns a material whose mesh primitive intersects with a ray created from the input pixel coordinates relative to the screen.
     * Returns the material whose mesh is nearest the camera.
     */
    materialFromPoint(clientX: Vector3, clientY: Vector3): Material;
    /**
     * Exports the glTF scene as a Blob object
     */
    exportScene(): Promise<Blob>;
    /**
     * Returns a screenshot of the current model render in the format specified by type (defaults to image/png). The screenshot is encoded
     * as a data URL string. In formats that support a sliding scale of quality (such as image/jpeg and image/webp) you can also specify a
     * value for encoderOptions between 0 and 1 (encoderOptions defaults to 0.92 otherwise).
     */
    toDataURL(type?: 'image/png' | 'image/jpeg' | 'image/webp', encoderOptions?: number): string;
    /**
     * Returns a promise that resolves into a Blob object in the format specified by the mimeType (defaults to image/png). A Blob object
     * represents a file-like object of immutable, raw data. You can also specify a value between 0 and 1 for qualityArgument (Currently
     * only available on Chrome desktop and Firefox) which defaults to 0.92 and 0.8 for image/png and image/webp respectively. By setting
     * idealAspect to true, the blob will be captured at the ideal poster aspect ratio instead of the canvas aspect ratio. This allows for
     * easy poster creation, where a single poster will match the render seamlessly at any canvas aspect ratio.
     * It is recommended to use a seamless webp poster image and set --poster-color to transparent and enable seamless-poster.
     */
    toBlob(options?: {
        mimeType?: 'image/png' | 'image/jpeg' | 'image/webp';
        qualityArgument?: number;
        idealAspect?: boolean;
    }): Promise<Blob>;
    /**
     * Recalculates the camera defaults in case the model has been changed, for instance by the orientation or scale attributes.
     */
    updateFraming(): void;
    /**
     * Resets the turntable that rotates the model when auto-rotate is enabled. The new value of the turntable rotation will be theta radians after this method is invoked, but the model may not update until the next render frame. If no argument is supplied, theta defaults to zero.
     */
    resetTurntableRotation(theta?: number): void;
    /**
     * Get the current camera phi, theta & radius
     */
    getCameraOrbit(): {
        phi: number;
        radius: number;
        theta: number;
        toString(): string;
    };
}

interface Model {
    /**
     * An ordered set of unique Materials found in this model. The Materials
     * correspond to the listing of materials in the glTF, with the possible
     * addition of a default material at the end.
     */
    readonly materials: Material[];

    // Returns the first material to whose name matches 'name'.
    getMaterialByName(name: string): Material | null;
}

interface Material {
    name: string;

    // Returns the glTF index of this material.
    readonly index: number;
    readonly normalTexture: TextureInfo | null;
    readonly occlusionTexture: TextureInfo | null;
    readonly emissiveTexture: TextureInfo | null;
    readonly emissiveFactor: RGB;
    readonly pbrMetallicRoughness: PBRMetallicRoughness;

    setEmissiveFactor(rgb: RGB): void;
    setAlphaCutoff(cutoff: number): void;
    getAlphaCutoff(): number;
    setDoubleSided(doubleSided: boolean): void;
    getDoubleSided(): boolean;
    setAlphaMode(alphaMode: AlphaMode): void;
    getAlphaMode(): AlphaMode;
}

interface PBRMetallicRoughness {
    readonly baseColorFactor: RGBA;
    readonly metallicFactor: number;
    readonly roughnessFactor: number;
    readonly baseColorTexture: TextureInfo | null;
    readonly metallicRoughnessTexture: TextureInfo | null;

    setBaseColorFactor(rgba: RGBA): void;
    setMetallicFactor(value: number): void;
    setRoughnessFactor(value: number): void;
}

interface TextureInfo {
    readonly texture: Texture | null;

    /**
     * Sets the texture, or removes it if argument is null. Note you cannot build
     * your own Texture object, but must either use one from another TextureInfo,
     * or create one with the createTexture method.
     */
    setTexture(texture: Texture | null): void;
}

interface Texture {
    name: string;
    readonly sampler: Sampler;
    readonly source: Image;
}

interface Sampler {
    readonly name: string;
    readonly minFilter: MinFilter;
    readonly maxFilter: MaxFilter;
    readonly wrapS: WrapMode;
    readonly wrapT: WrapMode;

    setMinFilter(filter: MinFilter): void;
    setMaxFilter(filter: MaxFilter): void;
    setWrapS(mode: WrapMode): void;
    setWrapT(mode: WrapMode): void;
}

interface Image {
    readonly name: string;

    /**
     * The type is 'external' if the image has a configured URI. Otherwise, it is
     * considered to be 'embedded'. Note: this distinction is only implied by the
     * glTF spec, and is made explicit here for convenience.
     */
    readonly type: 'embedded' | 'external';

    // The URI of the image, if it is external.
    readonly uri?: string;

    // The bufferView of the image, if it is embedded.
    readonly bufferView?: number;

    /**
     * A method to create an object URL of this image at the desired
     * resolution. Especially useful for KTX2 textures which are GPU compressed,
     * and so are unreadable on the CPU without a method like this.
     */
    createThumbnail(width: number, height: number): Promise<string>;
}

export type RGBA = [number, number, number, number];
export type RGB = [number, number, number];
type AlphaMode = 'OPAQUE' | 'MASK' | 'BLEND';

enum WrapMode {
    ClampToEdge = 33071,
    MirroredRepeat = 33648,
    Repeat = 10497
}

enum MinFilter {
    Nearest = 9728,
    Linear = 9729,
    NearestMipmapNearest = 9984,
    LinearMipmapNearest = 9985,
    NearestMipmapLinear = 9986,
    LinearMipmapLinear = 9987
}

enum MaxFilter {
    Nearest = 9728,
    Linear = 9729
}

@EdixonAlberto
Copy link

I keep getting an error when using the <model-viewer> tag and I can't wait for this library to fix it or for DefinitelyTyped to do something. So I uploaded a types library on npm, I'm sharing it here in case anyone wants to use it or collaborate:
https://www.npmjs.com/package/model-viewer-types

I'm currently very active using model-viewer so I'll be giving it constant maintenance.

@elalish
Copy link
Contributor

elalish commented Aug 19, 2024

Thank you, though we do publish our own TS types - do you have any idea why they aren't being picked up in your workflow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.