npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@spidunno/desmos-loader

v1.13.2

Published

Load the Desmos API v1.13 without creating globals, with types

Readme

@spidunno/desmos-loader

Loads the Desmos API v1.13 without creating any globals, and gives you a fully typed Desmos to import.

Normally calculator.js is added with a <script> tag, which creates window.Desmos (plus window.jQuery, window.$ and a couple of others). This package fetches the script instead, runs it in its own scope, and hands you the API. The calculator still runs in your page, so its CSS, events and focus work as usual, and you can style it like any other element.

Install

npm install @spidunno/desmos-loader@~1.13.2

The version's major.minor is the Desmos API version it loads (1.13.x loads v1.13). The patch number is for fixes to this package. A tilde range keeps you on v1.13.

The types come from @spidunno/desmos-types, which is installed as a dependency, so you don't need to install it yourself. It's a tilde range, so updating your dependencies picks up new types (including internals regenerated for each Desmos build) without a new loader release.

Recommended usage

Call loadDesmos once, in a module of its own, and export Desmos from it:

// desmos.ts
import { loadDesmos, Desmos } from '@spidunno/desmos-loader';

await loadDesmos({ apiKey: 'YOUR_API_KEY' });

export { Desmos };

Then import Desmos from that module anywhere else in your code:

// graph.ts
import { Desmos } from './desmos';

const calculator: Desmos.GraphingCalculator = Desmos.GraphingCalculator(element, { keypad: false });
calculator.setExpression({ id: 'a', latex: 'y=x^2' });

Desmos works both as the API object (Desmos.GraphingCalculator(...)) and as a namespace of types (Desmos.GraphingCalculator, Desmos.GraphState, ...), the same as with the global script.

The await at the top level of desmos.ts is what makes this work: any module that imports desmos.ts waits until the API has loaded before it runs, so Desmos is always ready when you use it. Top-level await needs an ES2022 target, which every current bundler supports.

Desmos is undefined until loadDesmos resolves. You only see that if you use it from code that doesn't import the module that awaits loadDesmos.

Internals

For the internals types (calculator.controller, graph sketches, Desmos.Private, ...), import from @spidunno/desmos-loader/internals instead. It loads the same code; only the types differ.

// desmos.ts
import { loadDesmos, Desmos } from '@spidunno/desmos-loader/internals';

await loadDesmos({ apiKey: 'YOUR_API_KEY' });

export { Desmos };

See the @spidunno/desmos-types README for what is typed and how.

Options

loadDesmos({ apiKey: 'YOUR_API_KEY' });                     // from desmos.com
loadDesmos({ url: '/vendor/calculator.js' });               // from your own copy or a mirror
loadDesmos({ apiKey: 'YOUR_API_KEY', evaluate: 'module' }); // see below

evaluate chooses how the fetched code runs:

| Value | How | Content-Security-Policy needs | | --- | --- | --- | | 'function' (default) | With new Function | 'unsafe-eval' in script-src | | 'module' | As an ES module, imported from a blob: URL | blob: in script-src |

Desmos itself compiles expressions with new Function, so a page that runs Desmos at all already needs 'unsafe-eval': the default never needs more than Desmos does, and works the same in every browser and bundler. 'module' is there if you'd rather load the code as a module, for example to see it as a separate script in your browser's devtools.

loadDesmos returns the API too (const api = await loadDesmos(...)), and also sets the Desmos export. Each call fetches and runs a separate copy, so call it once.

How it avoids globals

calculator.js creates its globals in three ways, and the loader gives each one somewhere else to go:

  • Desmos: the bundle has a CommonJS branch that puts the API on module.exports when a module object exists. The loader provides one.
  • jQuery and $: the bundled jQuery doesn't set them when a noGlobal variable is defined. The loader defines one.
  • _touchtracking_id_counter and dcgTestOnlyFetchMonitor: the bundle writes these as window.<name> = …. The loader rewrites those two writes to a private object.

If a future calculator.js drops either hook, loadDesmos throws instead of silently creating globals. If it finds a new global after loading anyway, it logs a warning naming it.

One thing remains: once a calculator binds events to window, jQuery stores its event data in a non-enumerable, randomly named property on window (jQuery3600…). It doesn't appear in Object.keys(window) and can't clash with anything.

Things that aren't JavaScript globals are unchanged: the calculator adds its stylesheet to document.head (every rule is scoped under .dcg-calculator-api-container-v1_13), and listens for events on document and window, as it does when loaded with a script tag.