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

vite-plugin-tsl-operator

v1.8.2

Published

A Vite plugin to let you use standard JS operators (+, -, *, /, %, >, <, ==, &&, ||, !) with TSL Nodes in your Three.js project.

Readme

vite-plugin-tsl-operator

Experimental

A Vite plugin to let you use +, -, *, /, %, +=, -=, *=, /=, %=, >, <, >=, <=, ==, ===, !=, !==, &&, ||, ! with TSL Node in your Threejs project making the code more consise and easy to write, modify & read.

Supported Operators

| Category | Operators | |----------|-----------| | Arithmetic | +, -, *, /, % | | Assignment | +=, -=, *=, /=, %= | | Comparison | >, <, >=, <=, ==, ===, !=, !== | | Logical | &&, \|\|, ! |

Example

Instead of:

Fn(()=>{
	let x = float(1).sub(alpha.mul(color.r))
	x = x.mul(4)
	return x
})

You can now write :

Fn(()=>{
	let x = 1 - ( alpha * color.r )
	x *= 4
	return x
})

Installation

pnpm i vite-plugin-tsl-operator

Usage

Add the plugin to your Vite config :

import { defineConfig } from 'vite'
import tslOperatorPlugin from 'vite-plugin-tsl-operator'

export default defineConfig({
	//...
  plugins: [
		tslOperatorPlugin({logs:false})
		//.. other plugins
	]
})

Options

| Option | Default | Description | |--------|---------|-------------| | logs | false | Log transformations to terminal | | autoImportMissingTSL | true | Automatically add missing TSL imports (float, int, Loop) | | importSource | 'three/tsl' | Import source for auto-imports |

Logging

tslOperatorPlugin({ logs: true })                     // log all files
tslOperatorPlugin({ logs: false })                    // no logging (default)
tslOperatorPlugin({ logs: "MyShader.js" })            // log only this file
tslOperatorPlugin({ logs: ["File1.js", "File2.js"] }) // log only these files
tslOperatorPlugin({ logs: /shader/i })                // log files matching regex

Auto Import

The plugin automatically adds missing imports when transformations require TSL types like float, int, or Loop.

// Before transformation (no float import)
import { Fn, uv } from 'three/tsl'
Fn(() => 1 - uv())

// After transformation (float automatically added)
import { Fn, uv, float } from 'three/tsl'
Fn(() => float(1).sub(uv()))

To disable auto-import or use a different import source:

tslOperatorPlugin({ autoImportMissingTSL: false })              // disable auto-import
tslOperatorPlugin({ importSource: 'three/webgpu' })   // use different source

Note : The transformation happened only when the file is call by the client or during build ( Vite optimization )

How it works

The plugin walks your source and selectively transforms code.

It only looks inside Fn(() => { ... }) blocks. Code outside is untouched.

const opacity = uniform(0) // Ignored (Plain JS)

Fn(()=>{
  return opacity * 3 // Transformed to opacity.mul(3)
})

Note: Files inside node_modules are excluded.

Smart Detection

The plugin automatically detects when to transform operators.

It uses context-aware logic to decide if an expression should be TSL or JavaScript.

Pure numeric expressions are preserved:

Fn(() => {
  const radius = 0.08
  const halfRadius = radius * 0.5      // Stays as-is (pure JS math)
  return smoothstep(radius, halfRadius, dist)  // dist is TSL, but radius/halfRadius are numbers
})

Variables initialized with numeric literals are recognized as plain JavaScript numbers and won't be transformed when used in arithmetic with other numbers.

Manual Overrides

If you have an edge case which is not cover by the smart-detection you can use //@tsl or //@js to force the behavior.

  • //@tsl : Force transformation (useful for custom functions or callbacks).
  • //@js : Disable transformation (keep as plain JS).

Directives apply to the next line or the entire Fn (if placed at the top).

//@tsl
Fn(() => {
  customNode( a > b ) // → customNode( a.greaterThan(b) )
})

Fn(() => {
  //@js
  const test = x + y  // will not transform

  const test = x + y  // will transform to x.add(y)
})

TSL Loop Transformation

Use //@tsl before for, while, or do...while loops to transform them into TSL Loop() constructs.

For Loop:

Fn(() => {
  //@tsl
  for (let i = 0; i < 10; i++) {
    sum += value
  }
})
// Transforms to:
// Loop({ start: int(0), end: int(10), type: "int", condition: "<", name: "i" }, ({ i }) => {
//   sum.addAssign(value)
// })

While Loop:

Fn(() => {
  //@tsl
  while (x < 10) {
    x += 1
  }
})
// Transforms to:
// Loop(x.lessThan(10), () => {
//   x.addAssign(1)
// })

Do-While Loop:

Fn(() => {
  //@tsl
  do {
    x += 1
  } while (x < 10)
})
// Transforms to an IIFE (executes body once) + Loop

Note: The plugin automatically infers int or float type based on the loop values.

About TSL

Official wiki : Three.js-Shading-Language

License

MIT