unplugin-typegpu 0.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Software Mansion <swmansion.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+ <div align="center">
2
+
3
+ # unplugin-typegpu
4
+
5
+ 🚧 **Under Construction** 🚧 - [GitHub](https://github.com/software-mansion/TypeGPU/tree/main/packages/unplugin-typegpu)
6
+
7
+ </div>
8
+
9
+ Build plugins for [TypeGPU](https://typegpu.com) that enable:
10
+ - Seamless JavaScript -> WGSL transpilation
11
+ - [🚧 TODO] Improved debugging with automatic naming of resources
12
+
13
+ Currently supported:
14
+ * babel
15
+ ```js
16
+ // babel.config.js (React Native with Expo)
17
+
18
+ module.exports = function (api) {
19
+ api.cache(true);
20
+ return {
21
+ presets: ['babel-preset-expo'],
22
+ plugins: ['unplugin-typegpu/babel']
23
+ };
24
+ };
25
+
26
+ ```
27
+
28
+ * rollup
29
+
30
+ ```ts
31
+ // vite.config.js
32
+
33
+ import { defineConfig } from 'vite';
34
+ import typegpu from 'unplugin-typegpu/rollup';
35
+
36
+ export default defineConfig({
37
+ plugins: [typegpu()],
38
+ });
39
+
40
+ ```
41
+
42
+ ## Getting Started
43
+
44
+ ```sh
45
+ npm install unplugin-typegpu
46
+ ```
47
+
48
+ ## TypeGPU is created by Software Mansion
49
+
50
+ [![swm](https://logo.swmansion.com/logo?color=white&variant=desktop&width=150&tag=typegpu-github 'Software Mansion')](https://swmansion.com)
51
+
52
+ Since 2012 [Software Mansion](https://swmansion.com) is a software agency with experience in building web and mobile apps. We are Core React Native Contributors and experts in dealing with all kinds of React Native issues. We can help you build your next dream product – [Hire us](https://swmansion.com/contact/projects?utm_source=typegpu&utm_medium=readme).
package/babel.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkSPKQUOK3cjs = require('./chunk-SPKQUOK3.cjs');require('./chunk-5YUXNY4J.cjs');exports.default = _chunkSPKQUOK3cjs.a;
2
+ //# sourceMappingURL=babel.cjs.map
package/babel.cjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
package/babel.d.cts ADDED
@@ -0,0 +1,10 @@
1
+ import * as _babel_traverse from '@babel/traverse';
2
+ import * as t from '@babel/types';
3
+
4
+ declare function export_default(): {
5
+ visitor: {
6
+ Program(this: t.Node, path: _babel_traverse.NodePath<t.Program>, state: t.Node): void;
7
+ };
8
+ };
9
+
10
+ export { export_default as default };
package/babel.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import * as _babel_traverse from '@babel/traverse';
2
+ import * as t from '@babel/types';
3
+
4
+ declare function export_default(): {
5
+ visitor: {
6
+ Program(this: t.Node, path: _babel_traverse.NodePath<t.Program>, state: t.Node): void;
7
+ };
8
+ };
9
+
10
+ export { export_default as default };
package/babel.js ADDED
@@ -0,0 +1,2 @@
1
+ import{a}from"./chunk-5MLKKHGO.js";import"./chunk-XWE2EDOE.js";export{a as default};
2
+ //# sourceMappingURL=babel.js.map
package/babel.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,2 @@
1
+ import{a as c,b as m,c as u,d as f}from"./chunk-XWE2EDOE.js";import*as a from"@babel/standalone";import{transpileFn as d}from"tinyest-for-wgsl";var g=a.packages.template,n=a.packages.types;function y(i){return{ImportDeclaration(e){u(e.node,i)},CallExpression(e){let s=e.node;if(f(s,i)){let t=s.arguments[0];if(t&&(t.type==="FunctionExpression"||t.type==="ArrowFunctionExpression")){let{argNames:r,body:p,externalNames:o}=d(t);e.replaceWith(n.callExpression(s.callee,[n.callExpression(g.expression("tgpu.__assignAst")(),[t,g.expression`${c({argNames:r,body:p,externalNames:o})}`(),n.objectExpression(o.map(l=>n.objectProperty(n.identifier(l),n.identifier(l))))])])),e.skip()}}}}}function k(){return{visitor:{Program(i,e){var o;let s=(o=e.file)==null?void 0:o.code,t=e.opts,r=e.filename;if(m(t,r,s))return;let p={tgpuAliases:new Set(["tgpu"])};i.traverse(y(p))}}}}export{k as a};
2
+ //# sourceMappingURL=chunk-5MLKKHGO.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/babel.ts"],"sourcesContent":["import * as Babel from '@babel/standalone';\nimport type TemplateGenerator from '@babel/template';\nimport type { TraverseOptions } from '@babel/traverse';\nimport type * as t from '@babel/types';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport {\n type Context,\n type TypegpuPluginOptions,\n embedJSON,\n gatherTgpuAliases,\n isDoesCall,\n shouldSkipFile,\n} from './common';\n\n// NOTE: @babel/standalone does expose internal packages, as specified in the docs, but the\n// typing for @babel/standalone does not expose them.\nconst template = (\n Babel as unknown as { packages: { template: typeof TemplateGenerator } }\n).packages.template;\nconst types = (Babel as unknown as { packages: { types: typeof t } }).packages\n .types;\n\nfunction functionVisitor(ctx: Context): TraverseOptions {\n return {\n ImportDeclaration(path) {\n gatherTgpuAliases(path.node, ctx);\n },\n\n CallExpression(path) {\n const node = path.node;\n\n if (isDoesCall(node, ctx)) {\n const implementation = node.arguments[0];\n\n if (\n implementation &&\n (implementation.type === 'FunctionExpression' ||\n implementation.type === 'ArrowFunctionExpression')\n ) {\n const { argNames, body, externalNames } = transpileFn(implementation);\n\n path.replaceWith(\n types.callExpression(node.callee, [\n types.callExpression(template.expression('tgpu.__assignAst')(), [\n implementation,\n template.expression`${embedJSON({ argNames, body, externalNames })}`(),\n types.objectExpression(\n externalNames.map((name) =>\n types.objectProperty(\n types.identifier(name),\n types.identifier(name),\n ),\n ),\n ),\n ]),\n ]),\n );\n\n path.skip();\n }\n }\n },\n };\n}\n\nexport default function () {\n return {\n visitor: {\n Program(path, state) {\n // @ts-ignore\n const code: string | undefined = state.file?.code;\n // @ts-ignore\n const options: TypegpuPluginOptions | undefined = state.opts;\n // @ts-ignore\n const id: string | undefined = state.filename;\n\n if (shouldSkipFile(options, id, code)) {\n return;\n }\n\n const ctx: Context = {\n tgpuAliases: new Set(['tgpu']),\n };\n\n path.traverse(functionVisitor(ctx));\n },\n } satisfies TraverseOptions,\n };\n}\n"],"mappings":"6DAAA,UAAYA,MAAW,oBAIvB,OAAS,eAAAC,MAAmB,mBAY5B,IAAMC,EAEJ,WAAS,SACLC,EAAgE,WACnE,MAEH,SAASC,EAAgBC,EAA+B,CACtD,MAAO,CACL,kBAAkBC,EAAM,CACtBC,EAAkBD,EAAK,KAAMD,CAAG,CAClC,EAEA,eAAeC,EAAM,CACnB,IAAME,EAAOF,EAAK,KAElB,GAAIG,EAAWD,EAAMH,CAAG,EAAG,CACzB,IAAMK,EAAiBF,EAAK,UAAU,CAAC,EAEvC,GACEE,IACCA,EAAe,OAAS,sBACvBA,EAAe,OAAS,2BAC1B,CACA,GAAM,CAAE,SAAAC,EAAU,KAAAC,EAAM,cAAAC,CAAc,EAAIC,EAAYJ,CAAc,EAEpEJ,EAAK,YACHH,EAAM,eAAeK,EAAK,OAAQ,CAChCL,EAAM,eAAeD,EAAS,WAAW,kBAAkB,EAAE,EAAG,CAC9DQ,EACAR,EAAS,aAAaa,EAAU,CAAE,SAAAJ,EAAU,KAAAC,EAAM,cAAAC,CAAc,CAAC,CAAC,GAAG,EACrEV,EAAM,iBACJU,EAAc,IAAKG,GACjBb,EAAM,eACJA,EAAM,WAAWa,CAAI,EACrBb,EAAM,WAAWa,CAAI,CACvB,CACF,CACF,CACF,CAAC,CACH,CAAC,CACH,EAEAV,EAAK,KAAK,CACZ,CACF,CACF,CACF,CACF,CAEe,SAARW,GAAoB,CACzB,MAAO,CACL,QAAS,CACP,QAAQX,EAAMY,EAAO,CApE3B,IAAAC,EAsEQ,IAAMC,GAA2BD,EAAAD,EAAM,OAAN,YAAAC,EAAY,KAEvCE,EAA4CH,EAAM,KAElDI,EAAyBJ,EAAM,SAErC,GAAIK,EAAeF,EAASC,EAAIF,CAAI,EAClC,OAGF,IAAMf,EAAe,CACnB,YAAa,IAAI,IAAI,CAAC,MAAM,CAAC,CAC/B,EAEAC,EAAK,SAASF,EAAgBC,CAAG,CAAC,CACpC,CACF,CACF,CACF","names":["Babel","transpileFn","template","types","functionVisitor","ctx","path","gatherTgpuAliases","node","isDoesCall","implementation","argNames","body","externalNames","transpileFn","embedJSON","name","babel_default","state","_a","code","options","id","shouldSkipFile"]}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});function u(e){return JSON.stringify(e).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function a(e,p){let t="",r=p;for(;;)if(r.type==="MemberExpression"){if(r.property.type!=="Identifier")break;t=t?`${r.property.name}.${t}`:r.property.name,r=r.object}else if(r.type==="Identifier"){t=t?`${r.name}.${t}`:r.name;break}else break;return e.tgpuAliases.has(t)}var i=/import.*from\s*['"]typegpu.*['"]/g,l=/import\s*\(\s*['"]\s*typegpu.*['"]/g,n=/require\s*\(\s*['"]\s*typegpu.*['"]\s*\)/g;function s(e,p,t){if(t&&!(e!=null&&e.include)){if(!i.test(t)&&!n.test(t)&&!l.test(t))return!0}else if(e!=null&&e.include&&e.include!=="all"&&(!p||!e.include.some(r=>r.test(p))))return!0;return!1}function o(e,p){if(e.source.value==="typegpu")for(let t of e.specifiers)t.type==="ImportDefaultSpecifier"||t.type==="ImportSpecifier"&&t.imported.type==="Identifier"&&t.imported.name==="tgpu"?p.tgpuAliases.add(t.local.name):t.type==="ImportNamespaceSpecifier"&&p.tgpuAliases.add(`${t.local.name}.tgpu`)}function c(e,p){return e.callee.type==="MemberExpression"&&e.arguments.length===1&&e.callee.property.type==="Identifier"&&(e.callee.property.name==="procedure"&&a(p,e.callee.object)||e.callee.property.name==="does")}exports.a = u; exports.b = s; exports.c = o; exports.d = c;
2
+ //# sourceMappingURL=chunk-5YUXNY4J.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/common.ts"],"names":["embedJSON","jsValue","isTgpu","ctx","node","path","tail","typegpuImportRegex","typegpuDynamicImportRegex","typegpuRequireRegex","shouldSkipFile","options","id","code","pattern","gatherTgpuAliases","spec","isDoesCall"],"mappings":"AAeO,SAASA,EAAUC,EAAkB,CAC1C,OAAO,KAAK,UAAUA,CAAO,EAC1B,QAAQ,UAAW,SAAS,EAC5B,QAAQ,UAAW,SAAS,CACjC,CAMA,SAASC,EAAOC,EAAcC,EAA2C,CACvE,IAAIC,EAAO,GAEPC,EAAOF,EACX,OACE,GAAIE,EAAK,OAAS,mBAAoB,CACpC,GAAIA,EAAK,SAAS,OAAS,aAEzB,MAGFD,EAAOA,EAAO,GAAGC,EAAK,SAAS,IAAI,IAAID,CAAI,GAAKC,EAAK,SAAS,KAC9DA,EAAOA,EAAK,MACd,SAAWA,EAAK,OAAS,aAAc,CACrCD,EAAOA,EAAO,GAAGC,EAAK,IAAI,IAAID,CAAI,GAAKC,EAAK,KAC5C,KACF,KACE,OAIJ,OAAOH,EAAI,YAAY,IAAIE,CAAI,CACjC,CAEA,IAAME,EAAqB,oCACrBC,EAA4B,sCAC5BC,EAAsB,4CAErB,SAASC,EACdC,EACAC,EACAC,EACA,CACA,GAAIA,GAAQ,EAACF,GAAA,MAAAA,EAAS,UACpB,GACE,CAACJ,EAAmB,KAAKM,CAAI,GAC7B,CAACJ,EAAoB,KAAKI,CAAI,GAC9B,CAACL,EAA0B,KAAKK,CAAI,EAGpC,MAAO,WAGTF,GAAA,MAAAA,EAAS,SACTA,EAAQ,UAAY,QACnB,CAACC,GAAM,CAACD,EAAQ,QAAQ,KAAMG,GAAYA,EAAQ,KAAKF,CAAE,CAAC,GAE3D,MAAO,GAGT,MAAO,EACT,CAEO,SAASG,EACdX,EACAD,EACA,CACA,GAAIC,EAAK,OAAO,QAAU,UACxB,QAAWY,KAAQZ,EAAK,WAGpBY,EAAK,OAAS,0BAEbA,EAAK,OAAS,mBACbA,EAAK,SAAS,OAAS,cACvBA,EAAK,SAAS,OAAS,OAEzBb,EAAI,YAAY,IAAIa,EAAK,MAAM,IAAI,EAC1BA,EAAK,OAAS,4BAEvBb,EAAI,YAAY,IAAI,GAAGa,EAAK,MAAM,IAAI,OAAO,CAIrD,CAEO,SAASC,EACdb,EACAD,EACA,CACA,OACEC,EAAK,OAAO,OAAS,oBACrBA,EAAK,UAAU,SAAW,GAC1BA,EAAK,OAAO,SAAS,OAAS,eAC5BA,EAAK,OAAO,SAAS,OAAS,aAC9BF,EAAOC,EAAKC,EAAK,OAAO,MAAM,GAI9BA,EAAK,OAAO,SAAS,OAAS,OAEpC","sourcesContent":["import type * as babel from '@babel/types';\nimport type * as acorn from 'acorn';\n\nexport type Context = {\n /**\n * How the `tgpu` object is used in code. Since it can be aliased, we\n * need to catch that and act accordingly.\n */\n tgpuAliases: Set<string>;\n};\n\nexport interface TypegpuPluginOptions {\n include?: 'all' | RegExp[];\n}\n\nexport function embedJSON(jsValue: unknown) {\n return JSON.stringify(jsValue)\n .replace(/\\u2028/g, '\\\\u2028')\n .replace(/\\u2029/g, '\\\\u2029');\n}\n\n/**\n * Checks if `node` is an alias for the 'tgpu' object, traditionally\n * available via `import tgpu from 'typegpu'`.\n */\nfunction isTgpu(ctx: Context, node: babel.Node | acorn.AnyNode): boolean {\n let path = '';\n\n let tail = node;\n while (true) {\n if (tail.type === 'MemberExpression') {\n if (tail.property.type !== 'Identifier') {\n // Not handling computed expressions.\n break;\n }\n\n path = path ? `${tail.property.name}.${path}` : tail.property.name;\n tail = tail.object;\n } else if (tail.type === 'Identifier') {\n path = path ? `${tail.name}.${path}` : tail.name;\n break;\n } else {\n break;\n }\n }\n\n return ctx.tgpuAliases.has(path);\n}\n\nconst typegpuImportRegex = /import.*from\\s*['\"]typegpu.*['\"]/g;\nconst typegpuDynamicImportRegex = /import\\s*\\(\\s*['\"]\\s*typegpu.*['\"]/g;\nconst typegpuRequireRegex = /require\\s*\\(\\s*['\"]\\s*typegpu.*['\"]\\s*\\)/g;\n\nexport function shouldSkipFile(\n options: TypegpuPluginOptions | undefined,\n id: string | undefined,\n code: string | undefined,\n) {\n if (code && !options?.include) {\n if (\n !typegpuImportRegex.test(code) &&\n !typegpuRequireRegex.test(code) &&\n !typegpuDynamicImportRegex.test(code)\n ) {\n // No imports to `typegpu` or its sub modules, exiting early.\n return true;\n }\n } else if (\n options?.include &&\n options.include !== 'all' &&\n (!id || !options.include.some((pattern) => pattern.test(id)))\n ) {\n return true;\n }\n\n return false;\n}\n\nexport function gatherTgpuAliases(\n node: acorn.ImportDeclaration | babel.ImportDeclaration,\n ctx: Context,\n) {\n if (node.source.value === 'typegpu') {\n for (const spec of node.specifiers) {\n if (\n // The default export of 'typegpu' is the `tgpu` object.\n spec.type === 'ImportDefaultSpecifier' ||\n // Aliasing 'tgpu' while importing, e.g. import { tgpu as t } from 'typegpu';\n (spec.type === 'ImportSpecifier' &&\n spec.imported.type === 'Identifier' &&\n spec.imported.name === 'tgpu')\n ) {\n ctx.tgpuAliases.add(spec.local.name);\n } else if (spec.type === 'ImportNamespaceSpecifier') {\n // Importing everything, e.g. import * as t from 'typegpu';\n ctx.tgpuAliases.add(`${spec.local.name}.tgpu`);\n }\n }\n }\n}\n\nexport function isDoesCall(\n node: acorn.CallExpression | babel.CallExpression,\n ctx: Context,\n) {\n return (\n node.callee.type === 'MemberExpression' &&\n node.arguments.length === 1 &&\n node.callee.property.type === 'Identifier' &&\n ((node.callee.property.name === 'procedure' &&\n isTgpu(ctx, node.callee.object)) ||\n // Assuming that every call to `.does` is related to TypeGPU\n // because shells can be created separately from calls to `tgpu`,\n // making it hard to detect.\n node.callee.property.name === 'does')\n );\n}\n"]}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _chunk5YUXNY4Jcjs = require('./chunk-5YUXNY4J.cjs');var _estreewalker = require('estree-walker');var _magicstring = require('magic-string'); var _magicstring2 = _interopRequireDefault(_magicstring);var _tinyestforwgsl = require('tinyest-for-wgsl');function T(c){return{name:"rollup-plugin-typegpu",transform(o,d){if(_chunk5YUXNY4Jcjs.b.call(void 0, c,d,o))return;let r={tgpuAliases:new Set(["tgpu"])},y=this.parse(o,{allowReturnOutsideFunction:!0}),a=[];_estreewalker.walk.call(void 0, y,{enter(e,l,s,p){let n=e;if(n.type==="ImportDeclaration"&&_chunk5YUXNY4Jcjs.c.call(void 0, n,r),n.type==="CallExpression"&&_chunk5YUXNY4Jcjs.d.call(void 0, n,r)){let i=n.arguments[0];i&&i.type!=="TemplateLiteral"&&i.type!=="Literal"&&a.push({varDecl:n,implementation:i})}}});let t=new (0, _magicstring2.default)(o);for(let e of a){let{argNames:l,body:s,externalNames:p}=_tinyestforwgsl.transpileFn.call(void 0, e.implementation);t.appendLeft(e.implementation.start,"tgpu.__assignAst("),t.appendRight(e.implementation.end,`, ${_chunk5YUXNY4Jcjs.a.call(void 0, {argNames:l,body:s,externalNames:p})}`),p.length>0?t.appendRight(e.implementation.end,`, {${p.join(", ")}})`):t.appendRight(e.implementation.end,", undefined)")}return{code:t.toString(),map:t.generateMap()}}}}exports.a = T;
2
+ //# sourceMappingURL=chunk-GN3AXEAX.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/rollup.ts"],"names":["walk","MagicString","transpileFn","typegpu","options","code","id","shouldSkipFile","ctx","ast","tgslFunctionDefs","_node","_parent","prop","index","node","gatherTgpuAliases","isDoesCall","implementation","magicString","expr","argNames","body","externalNames","embedJSON"],"mappings":"8DACA,OAAS,QAAAA,MAAY,gBACrB,OAAOC,MAAiB,eAExB,OAAS,eAAAC,MAAmB,mBAuBb,SAARC,EACLC,EACqB,CACrB,MAAO,CACL,KAAM,wBACN,UAAUC,EAAMC,EAAI,CAClB,GAAIC,EAAeH,EAASE,EAAID,CAAI,EAClC,OAGF,IAAMG,EAAe,CACnB,YAAa,IAAI,IAAI,CAAC,MAAM,CAAC,CAC/B,EAEMC,EAAM,KAAK,MAAMJ,EAAM,CAC3B,2BAA4B,EAC9B,CAAC,EAEKK,EAAsC,CAAC,EAE7CV,EAAKS,EAAK,CACR,MAAME,EAAOC,EAASC,EAAMC,EAAO,CACjC,IAAMC,EAAOJ,EAMb,GAJII,EAAK,OAAS,qBAChBC,EAAkBD,EAAMP,CAAG,EAGzBO,EAAK,OAAS,kBACZE,EAAWF,EAAMP,CAAG,EAAG,CACzB,IAAMU,EAAiBH,EAAK,UAAU,CAAC,EAGrCG,GACEA,EAAe,OAAS,mBACxBA,EAAe,OAAS,WAE1BR,EAAiB,KAAK,CACpB,QAASK,EACT,eAAAG,CACF,CAAC,CAEL,CAEJ,CACF,CAAC,EAED,IAAMC,EAAc,IAAIlB,EAAYI,CAAI,EAExC,QAAWe,KAAQV,EAAkB,CACnC,GAAM,CAAE,SAAAW,EAAU,KAAAC,EAAM,cAAAC,CAAc,EAAIrB,EACxCkB,EAAK,cACP,EAGAD,EAAY,WAAWC,EAAK,eAAe,MAAO,mBAAmB,EACrED,EAAY,YACVC,EAAK,eAAe,IACpB,KAAKI,EAAU,CAAE,SAAAH,EAAU,KAAAC,EAAM,cAAAC,CAAc,CAAC,CAAC,EACnD,EAEIA,EAAc,OAAS,EACzBJ,EAAY,YACVC,EAAK,eAAe,IACpB,MAAMG,EAAc,KAAK,IAAI,CAAC,IAChC,EAEAJ,EAAY,YAAYC,EAAK,eAAe,IAAK,cAAc,CAEnE,CAEA,MAAO,CACL,KAAMD,EAAY,SAAS,EAC3B,IAAKA,EAAY,YAAY,CAC/B,CACF,CACF,CACF","sourcesContent":["import type { AnyNode, CallExpression } from 'acorn';\nimport { walk } from 'estree-walker';\nimport MagicString from 'magic-string';\nimport type { Plugin, SourceMap } from 'rollup';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport {\n type Context,\n type TypegpuPluginOptions,\n embedJSON,\n gatherTgpuAliases,\n isDoesCall,\n shouldSkipFile,\n} from './common';\n\ntype TgslFunctionDef = {\n varDecl: CallExpression;\n implementation: AnyNode;\n};\n\nexport interface TypegpuRollupPlugin {\n name: 'rollup-plugin-typegpu';\n transform(\n code: string,\n id: string,\n ): { code: string; map: SourceMap } | undefined;\n}\n\nexport default function typegpu(\n options?: TypegpuPluginOptions,\n): TypegpuRollupPlugin {\n return {\n name: 'rollup-plugin-typegpu' as const,\n transform(code, id) {\n if (shouldSkipFile(options, id, code)) {\n return;\n }\n\n const ctx: Context = {\n tgpuAliases: new Set(['tgpu']),\n };\n\n const ast = this.parse(code, {\n allowReturnOutsideFunction: true,\n });\n\n const tgslFunctionDefs: TgslFunctionDef[] = [];\n\n walk(ast, {\n enter(_node, _parent, prop, index) {\n const node = _node as AnyNode;\n\n if (node.type === 'ImportDeclaration') {\n gatherTgpuAliases(node, ctx);\n }\n\n if (node.type === 'CallExpression') {\n if (isDoesCall(node, ctx)) {\n const implementation = node.arguments[0];\n\n if (\n implementation &&\n !(implementation.type === 'TemplateLiteral') &&\n !(implementation.type === 'Literal')\n ) {\n tgslFunctionDefs.push({\n varDecl: node,\n implementation,\n });\n }\n }\n }\n },\n });\n\n const magicString = new MagicString(code);\n\n for (const expr of tgslFunctionDefs) {\n const { argNames, body, externalNames } = transpileFn(\n expr.implementation,\n );\n\n // Wrap the implementation in a call to `tgpu.__assignAst` to associate the AST with the implementation.\n magicString.appendLeft(expr.implementation.start, 'tgpu.__assignAst(');\n magicString.appendRight(\n expr.implementation.end,\n `, ${embedJSON({ argNames, body, externalNames })}`,\n );\n\n if (externalNames.length > 0) {\n magicString.appendRight(\n expr.implementation.end,\n `, {${externalNames.join(', ')}})`,\n );\n } else {\n magicString.appendRight(expr.implementation.end, ', undefined)');\n }\n }\n\n return {\n code: magicString.toString(),\n map: magicString.generateMap(),\n };\n },\n } satisfies Plugin;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }var _chunk5YUXNY4Jcjs = require('./chunk-5YUXNY4J.cjs');var _standalone = require('@babel/standalone'); var a = _interopRequireWildcard(_standalone);var _tinyestforwgsl = require('tinyest-for-wgsl');var g=a.packages.template,n=a.packages.types;function y(i){return{ImportDeclaration(e){_chunk5YUXNY4Jcjs.c.call(void 0, e.node,i)},CallExpression(e){let s=e.node;if(_chunk5YUXNY4Jcjs.d.call(void 0, s,i)){let t=s.arguments[0];if(t&&(t.type==="FunctionExpression"||t.type==="ArrowFunctionExpression")){let{argNames:r,body:p,externalNames:o}=_tinyestforwgsl.transpileFn.call(void 0, t);e.replaceWith(n.callExpression(s.callee,[n.callExpression(g.expression("tgpu.__assignAst")(),[t,g.expression`${_chunk5YUXNY4Jcjs.a.call(void 0, {argNames:r,body:p,externalNames:o})}`(),n.objectExpression(o.map(l=>n.objectProperty(n.identifier(l),n.identifier(l))))])])),e.skip()}}}}}function k(){return{visitor:{Program(i,e){var o;let s=(o=e.file)==null?void 0:o.code,t=e.opts,r=e.filename;if(_chunk5YUXNY4Jcjs.b.call(void 0, t,r,s))return;let p={tgpuAliases:new Set(["tgpu"])};i.traverse(y(p))}}}}exports.a = k;
2
+ //# sourceMappingURL=chunk-SPKQUOK3.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/babel.ts"],"names":["Babel","transpileFn","template","types","functionVisitor","ctx","path","gatherTgpuAliases","node","isDoesCall","implementation","argNames","body","externalNames","embedJSON","name","babel_default","state","_a","code","options","id","shouldSkipFile"],"mappings":"8DAAA,UAAYA,MAAW,oBAIvB,OAAS,eAAAC,MAAmB,mBAY5B,IAAMC,EAEJ,WAAS,SACLC,EAAgE,WACnE,MAEH,SAASC,EAAgBC,EAA+B,CACtD,MAAO,CACL,kBAAkBC,EAAM,CACtBC,EAAkBD,EAAK,KAAMD,CAAG,CAClC,EAEA,eAAeC,EAAM,CACnB,IAAME,EAAOF,EAAK,KAElB,GAAIG,EAAWD,EAAMH,CAAG,EAAG,CACzB,IAAMK,EAAiBF,EAAK,UAAU,CAAC,EAEvC,GACEE,IACCA,EAAe,OAAS,sBACvBA,EAAe,OAAS,2BAC1B,CACA,GAAM,CAAE,SAAAC,EAAU,KAAAC,EAAM,cAAAC,CAAc,EAAIZ,EAAYS,CAAc,EAEpEJ,EAAK,YACHH,EAAM,eAAeK,EAAK,OAAQ,CAChCL,EAAM,eAAeD,EAAS,WAAW,kBAAkB,EAAE,EAAG,CAC9DQ,EACAR,EAAS,aAAaY,EAAU,CAAE,SAAAH,EAAU,KAAAC,EAAM,cAAAC,CAAc,CAAC,CAAC,GAAG,EACrEV,EAAM,iBACJU,EAAc,IAAKE,GACjBZ,EAAM,eACJA,EAAM,WAAWY,CAAI,EACrBZ,EAAM,WAAWY,CAAI,CACvB,CACF,CACF,CACF,CAAC,CACH,CAAC,CACH,EAEAT,EAAK,KAAK,CACZ,CACF,CACF,CACF,CACF,CAEe,SAARU,GAAoB,CACzB,MAAO,CACL,QAAS,CACP,QAAQV,EAAMW,EAAO,CApE3B,IAAAC,EAsEQ,IAAMC,GAA2BD,EAAAD,EAAM,OAAN,YAAAC,EAAY,KAEvCE,EAA4CH,EAAM,KAElDI,EAAyBJ,EAAM,SAErC,GAAIK,EAAeF,EAASC,EAAIF,CAAI,EAClC,OAGF,IAAMd,EAAe,CACnB,YAAa,IAAI,IAAI,CAAC,MAAM,CAAC,CAC/B,EAEAC,EAAK,SAASF,EAAgBC,CAAG,CAAC,CACpC,CACF,CACF,CACF","sourcesContent":["import * as Babel from '@babel/standalone';\nimport type TemplateGenerator from '@babel/template';\nimport type { TraverseOptions } from '@babel/traverse';\nimport type * as t from '@babel/types';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport {\n type Context,\n type TypegpuPluginOptions,\n embedJSON,\n gatherTgpuAliases,\n isDoesCall,\n shouldSkipFile,\n} from './common';\n\n// NOTE: @babel/standalone does expose internal packages, as specified in the docs, but the\n// typing for @babel/standalone does not expose them.\nconst template = (\n Babel as unknown as { packages: { template: typeof TemplateGenerator } }\n).packages.template;\nconst types = (Babel as unknown as { packages: { types: typeof t } }).packages\n .types;\n\nfunction functionVisitor(ctx: Context): TraverseOptions {\n return {\n ImportDeclaration(path) {\n gatherTgpuAliases(path.node, ctx);\n },\n\n CallExpression(path) {\n const node = path.node;\n\n if (isDoesCall(node, ctx)) {\n const implementation = node.arguments[0];\n\n if (\n implementation &&\n (implementation.type === 'FunctionExpression' ||\n implementation.type === 'ArrowFunctionExpression')\n ) {\n const { argNames, body, externalNames } = transpileFn(implementation);\n\n path.replaceWith(\n types.callExpression(node.callee, [\n types.callExpression(template.expression('tgpu.__assignAst')(), [\n implementation,\n template.expression`${embedJSON({ argNames, body, externalNames })}`(),\n types.objectExpression(\n externalNames.map((name) =>\n types.objectProperty(\n types.identifier(name),\n types.identifier(name),\n ),\n ),\n ),\n ]),\n ]),\n );\n\n path.skip();\n }\n }\n },\n };\n}\n\nexport default function () {\n return {\n visitor: {\n Program(path, state) {\n // @ts-ignore\n const code: string | undefined = state.file?.code;\n // @ts-ignore\n const options: TypegpuPluginOptions | undefined = state.opts;\n // @ts-ignore\n const id: string | undefined = state.filename;\n\n if (shouldSkipFile(options, id, code)) {\n return;\n }\n\n const ctx: Context = {\n tgpuAliases: new Set(['tgpu']),\n };\n\n path.traverse(functionVisitor(ctx));\n },\n } satisfies TraverseOptions,\n };\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import{a as u,b as g,c as m,d as f}from"./chunk-XWE2EDOE.js";import{walk as x}from"estree-walker";import h from"magic-string";import{transpileFn as S}from"tinyest-for-wgsl";function T(c){return{name:"rollup-plugin-typegpu",transform(o,d){if(g(c,d,o))return;let r={tgpuAliases:new Set(["tgpu"])},y=this.parse(o,{allowReturnOutsideFunction:!0}),a=[];x(y,{enter(e,l,s,p){let n=e;if(n.type==="ImportDeclaration"&&m(n,r),n.type==="CallExpression"&&f(n,r)){let i=n.arguments[0];i&&i.type!=="TemplateLiteral"&&i.type!=="Literal"&&a.push({varDecl:n,implementation:i})}}});let t=new h(o);for(let e of a){let{argNames:l,body:s,externalNames:p}=S(e.implementation);t.appendLeft(e.implementation.start,"tgpu.__assignAst("),t.appendRight(e.implementation.end,`, ${u({argNames:l,body:s,externalNames:p})}`),p.length>0?t.appendRight(e.implementation.end,`, {${p.join(", ")}})`):t.appendRight(e.implementation.end,", undefined)")}return{code:t.toString(),map:t.generateMap()}}}}export{T as a};
2
+ //# sourceMappingURL=chunk-VSVKZFFD.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/rollup.ts"],"sourcesContent":["import type { AnyNode, CallExpression } from 'acorn';\nimport { walk } from 'estree-walker';\nimport MagicString from 'magic-string';\nimport type { Plugin, SourceMap } from 'rollup';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport {\n type Context,\n type TypegpuPluginOptions,\n embedJSON,\n gatherTgpuAliases,\n isDoesCall,\n shouldSkipFile,\n} from './common';\n\ntype TgslFunctionDef = {\n varDecl: CallExpression;\n implementation: AnyNode;\n};\n\nexport interface TypegpuRollupPlugin {\n name: 'rollup-plugin-typegpu';\n transform(\n code: string,\n id: string,\n ): { code: string; map: SourceMap } | undefined;\n}\n\nexport default function typegpu(\n options?: TypegpuPluginOptions,\n): TypegpuRollupPlugin {\n return {\n name: 'rollup-plugin-typegpu' as const,\n transform(code, id) {\n if (shouldSkipFile(options, id, code)) {\n return;\n }\n\n const ctx: Context = {\n tgpuAliases: new Set(['tgpu']),\n };\n\n const ast = this.parse(code, {\n allowReturnOutsideFunction: true,\n });\n\n const tgslFunctionDefs: TgslFunctionDef[] = [];\n\n walk(ast, {\n enter(_node, _parent, prop, index) {\n const node = _node as AnyNode;\n\n if (node.type === 'ImportDeclaration') {\n gatherTgpuAliases(node, ctx);\n }\n\n if (node.type === 'CallExpression') {\n if (isDoesCall(node, ctx)) {\n const implementation = node.arguments[0];\n\n if (\n implementation &&\n !(implementation.type === 'TemplateLiteral') &&\n !(implementation.type === 'Literal')\n ) {\n tgslFunctionDefs.push({\n varDecl: node,\n implementation,\n });\n }\n }\n }\n },\n });\n\n const magicString = new MagicString(code);\n\n for (const expr of tgslFunctionDefs) {\n const { argNames, body, externalNames } = transpileFn(\n expr.implementation,\n );\n\n // Wrap the implementation in a call to `tgpu.__assignAst` to associate the AST with the implementation.\n magicString.appendLeft(expr.implementation.start, 'tgpu.__assignAst(');\n magicString.appendRight(\n expr.implementation.end,\n `, ${embedJSON({ argNames, body, externalNames })}`,\n );\n\n if (externalNames.length > 0) {\n magicString.appendRight(\n expr.implementation.end,\n `, {${externalNames.join(', ')}})`,\n );\n } else {\n magicString.appendRight(expr.implementation.end, ', undefined)');\n }\n }\n\n return {\n code: magicString.toString(),\n map: magicString.generateMap(),\n };\n },\n } satisfies Plugin;\n}\n"],"mappings":"6DACA,OAAS,QAAAA,MAAY,gBACrB,OAAOC,MAAiB,eAExB,OAAS,eAAAC,MAAmB,mBAuBb,SAARC,EACLC,EACqB,CACrB,MAAO,CACL,KAAM,wBACN,UAAUC,EAAMC,EAAI,CAClB,GAAIC,EAAeH,EAASE,EAAID,CAAI,EAClC,OAGF,IAAMG,EAAe,CACnB,YAAa,IAAI,IAAI,CAAC,MAAM,CAAC,CAC/B,EAEMC,EAAM,KAAK,MAAMJ,EAAM,CAC3B,2BAA4B,EAC9B,CAAC,EAEKK,EAAsC,CAAC,EAE7CC,EAAKF,EAAK,CACR,MAAMG,EAAOC,EAASC,EAAMC,EAAO,CACjC,IAAMC,EAAOJ,EAMb,GAJII,EAAK,OAAS,qBAChBC,EAAkBD,EAAMR,CAAG,EAGzBQ,EAAK,OAAS,kBACZE,EAAWF,EAAMR,CAAG,EAAG,CACzB,IAAMW,EAAiBH,EAAK,UAAU,CAAC,EAGrCG,GACEA,EAAe,OAAS,mBACxBA,EAAe,OAAS,WAE1BT,EAAiB,KAAK,CACpB,QAASM,EACT,eAAAG,CACF,CAAC,CAEL,CAEJ,CACF,CAAC,EAED,IAAMC,EAAc,IAAIC,EAAYhB,CAAI,EAExC,QAAWiB,KAAQZ,EAAkB,CACnC,GAAM,CAAE,SAAAa,EAAU,KAAAC,EAAM,cAAAC,CAAc,EAAIC,EACxCJ,EAAK,cACP,EAGAF,EAAY,WAAWE,EAAK,eAAe,MAAO,mBAAmB,EACrEF,EAAY,YACVE,EAAK,eAAe,IACpB,KAAKK,EAAU,CAAE,SAAAJ,EAAU,KAAAC,EAAM,cAAAC,CAAc,CAAC,CAAC,EACnD,EAEIA,EAAc,OAAS,EACzBL,EAAY,YACVE,EAAK,eAAe,IACpB,MAAMG,EAAc,KAAK,IAAI,CAAC,IAChC,EAEAL,EAAY,YAAYE,EAAK,eAAe,IAAK,cAAc,CAEnE,CAEA,MAAO,CACL,KAAMF,EAAY,SAAS,EAC3B,IAAKA,EAAY,YAAY,CAC/B,CACF,CACF,CACF","names":["walk","MagicString","transpileFn","typegpu","options","code","id","shouldSkipFile","ctx","ast","tgslFunctionDefs","walk","_node","_parent","prop","index","node","gatherTgpuAliases","isDoesCall","implementation","magicString","MagicString","expr","argNames","body","externalNames","transpileFn","embedJSON"]}
@@ -0,0 +1,2 @@
1
+ function u(e){return JSON.stringify(e).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function a(e,p){let t="",r=p;for(;;)if(r.type==="MemberExpression"){if(r.property.type!=="Identifier")break;t=t?`${r.property.name}.${t}`:r.property.name,r=r.object}else if(r.type==="Identifier"){t=t?`${r.name}.${t}`:r.name;break}else break;return e.tgpuAliases.has(t)}var i=/import.*from\s*['"]typegpu.*['"]/g,l=/import\s*\(\s*['"]\s*typegpu.*['"]/g,n=/require\s*\(\s*['"]\s*typegpu.*['"]\s*\)/g;function s(e,p,t){if(t&&!(e!=null&&e.include)){if(!i.test(t)&&!n.test(t)&&!l.test(t))return!0}else if(e!=null&&e.include&&e.include!=="all"&&(!p||!e.include.some(r=>r.test(p))))return!0;return!1}function o(e,p){if(e.source.value==="typegpu")for(let t of e.specifiers)t.type==="ImportDefaultSpecifier"||t.type==="ImportSpecifier"&&t.imported.type==="Identifier"&&t.imported.name==="tgpu"?p.tgpuAliases.add(t.local.name):t.type==="ImportNamespaceSpecifier"&&p.tgpuAliases.add(`${t.local.name}.tgpu`)}function c(e,p){return e.callee.type==="MemberExpression"&&e.arguments.length===1&&e.callee.property.type==="Identifier"&&(e.callee.property.name==="procedure"&&a(p,e.callee.object)||e.callee.property.name==="does")}export{u as a,s as b,o as c,c as d};
2
+ //# sourceMappingURL=chunk-XWE2EDOE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/common.ts"],"sourcesContent":["import type * as babel from '@babel/types';\nimport type * as acorn from 'acorn';\n\nexport type Context = {\n /**\n * How the `tgpu` object is used in code. Since it can be aliased, we\n * need to catch that and act accordingly.\n */\n tgpuAliases: Set<string>;\n};\n\nexport interface TypegpuPluginOptions {\n include?: 'all' | RegExp[];\n}\n\nexport function embedJSON(jsValue: unknown) {\n return JSON.stringify(jsValue)\n .replace(/\\u2028/g, '\\\\u2028')\n .replace(/\\u2029/g, '\\\\u2029');\n}\n\n/**\n * Checks if `node` is an alias for the 'tgpu' object, traditionally\n * available via `import tgpu from 'typegpu'`.\n */\nfunction isTgpu(ctx: Context, node: babel.Node | acorn.AnyNode): boolean {\n let path = '';\n\n let tail = node;\n while (true) {\n if (tail.type === 'MemberExpression') {\n if (tail.property.type !== 'Identifier') {\n // Not handling computed expressions.\n break;\n }\n\n path = path ? `${tail.property.name}.${path}` : tail.property.name;\n tail = tail.object;\n } else if (tail.type === 'Identifier') {\n path = path ? `${tail.name}.${path}` : tail.name;\n break;\n } else {\n break;\n }\n }\n\n return ctx.tgpuAliases.has(path);\n}\n\nconst typegpuImportRegex = /import.*from\\s*['\"]typegpu.*['\"]/g;\nconst typegpuDynamicImportRegex = /import\\s*\\(\\s*['\"]\\s*typegpu.*['\"]/g;\nconst typegpuRequireRegex = /require\\s*\\(\\s*['\"]\\s*typegpu.*['\"]\\s*\\)/g;\n\nexport function shouldSkipFile(\n options: TypegpuPluginOptions | undefined,\n id: string | undefined,\n code: string | undefined,\n) {\n if (code && !options?.include) {\n if (\n !typegpuImportRegex.test(code) &&\n !typegpuRequireRegex.test(code) &&\n !typegpuDynamicImportRegex.test(code)\n ) {\n // No imports to `typegpu` or its sub modules, exiting early.\n return true;\n }\n } else if (\n options?.include &&\n options.include !== 'all' &&\n (!id || !options.include.some((pattern) => pattern.test(id)))\n ) {\n return true;\n }\n\n return false;\n}\n\nexport function gatherTgpuAliases(\n node: acorn.ImportDeclaration | babel.ImportDeclaration,\n ctx: Context,\n) {\n if (node.source.value === 'typegpu') {\n for (const spec of node.specifiers) {\n if (\n // The default export of 'typegpu' is the `tgpu` object.\n spec.type === 'ImportDefaultSpecifier' ||\n // Aliasing 'tgpu' while importing, e.g. import { tgpu as t } from 'typegpu';\n (spec.type === 'ImportSpecifier' &&\n spec.imported.type === 'Identifier' &&\n spec.imported.name === 'tgpu')\n ) {\n ctx.tgpuAliases.add(spec.local.name);\n } else if (spec.type === 'ImportNamespaceSpecifier') {\n // Importing everything, e.g. import * as t from 'typegpu';\n ctx.tgpuAliases.add(`${spec.local.name}.tgpu`);\n }\n }\n }\n}\n\nexport function isDoesCall(\n node: acorn.CallExpression | babel.CallExpression,\n ctx: Context,\n) {\n return (\n node.callee.type === 'MemberExpression' &&\n node.arguments.length === 1 &&\n node.callee.property.type === 'Identifier' &&\n ((node.callee.property.name === 'procedure' &&\n isTgpu(ctx, node.callee.object)) ||\n // Assuming that every call to `.does` is related to TypeGPU\n // because shells can be created separately from calls to `tgpu`,\n // making it hard to detect.\n node.callee.property.name === 'does')\n );\n}\n"],"mappings":"AAeO,SAASA,EAAUC,EAAkB,CAC1C,OAAO,KAAK,UAAUA,CAAO,EAC1B,QAAQ,UAAW,SAAS,EAC5B,QAAQ,UAAW,SAAS,CACjC,CAMA,SAASC,EAAOC,EAAcC,EAA2C,CACvE,IAAIC,EAAO,GAEPC,EAAOF,EACX,OACE,GAAIE,EAAK,OAAS,mBAAoB,CACpC,GAAIA,EAAK,SAAS,OAAS,aAEzB,MAGFD,EAAOA,EAAO,GAAGC,EAAK,SAAS,IAAI,IAAID,CAAI,GAAKC,EAAK,SAAS,KAC9DA,EAAOA,EAAK,MACd,SAAWA,EAAK,OAAS,aAAc,CACrCD,EAAOA,EAAO,GAAGC,EAAK,IAAI,IAAID,CAAI,GAAKC,EAAK,KAC5C,KACF,KACE,OAIJ,OAAOH,EAAI,YAAY,IAAIE,CAAI,CACjC,CAEA,IAAME,EAAqB,oCACrBC,EAA4B,sCAC5BC,EAAsB,4CAErB,SAASC,EACdC,EACAC,EACAC,EACA,CACA,GAAIA,GAAQ,EAACF,GAAA,MAAAA,EAAS,UACpB,GACE,CAACJ,EAAmB,KAAKM,CAAI,GAC7B,CAACJ,EAAoB,KAAKI,CAAI,GAC9B,CAACL,EAA0B,KAAKK,CAAI,EAGpC,MAAO,WAGTF,GAAA,MAAAA,EAAS,SACTA,EAAQ,UAAY,QACnB,CAACC,GAAM,CAACD,EAAQ,QAAQ,KAAMG,GAAYA,EAAQ,KAAKF,CAAE,CAAC,GAE3D,MAAO,GAGT,MAAO,EACT,CAEO,SAASG,EACdX,EACAD,EACA,CACA,GAAIC,EAAK,OAAO,QAAU,UACxB,QAAWY,KAAQZ,EAAK,WAGpBY,EAAK,OAAS,0BAEbA,EAAK,OAAS,mBACbA,EAAK,SAAS,OAAS,cACvBA,EAAK,SAAS,OAAS,OAEzBb,EAAI,YAAY,IAAIa,EAAK,MAAM,IAAI,EAC1BA,EAAK,OAAS,4BAEvBb,EAAI,YAAY,IAAI,GAAGa,EAAK,MAAM,IAAI,OAAO,CAIrD,CAEO,SAASC,EACdb,EACAD,EACA,CACA,OACEC,EAAK,OAAO,OAAS,oBACrBA,EAAK,UAAU,SAAW,GAC1BA,EAAK,OAAO,SAAS,OAAS,eAC5BA,EAAK,OAAO,SAAS,OAAS,aAC9BF,EAAOC,EAAKC,EAAK,OAAO,MAAM,GAI9BA,EAAK,OAAO,SAAS,OAAS,OAEpC","names":["embedJSON","jsValue","isTgpu","ctx","node","path","tail","typegpuImportRegex","typegpuDynamicImportRegex","typegpuRequireRegex","shouldSkipFile","options","id","code","pattern","gatherTgpuAliases","spec","isDoesCall"]}
package/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkGN3AXEAXcjs = require('./chunk-GN3AXEAX.cjs');var _chunkSPKQUOK3cjs = require('./chunk-SPKQUOK3.cjs');require('./chunk-5YUXNY4J.cjs');var t={babel:_chunkSPKQUOK3cjs.a,rollup:_chunkGN3AXEAXcjs.a};exports.default = t;
2
+ //# sourceMappingURL=index.cjs.map
package/index.cjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["src_default","babel_default","typegpu"],"mappings":"+GAKA,IAAOA,EAAQ,CACb,MAAAC,EACA,OAAAC,CACF","sourcesContent":["import babel from './babel';\nimport rollup from './rollup';\n\nexport type { TypegpuPluginOptions } from './common';\n\nexport default {\n babel,\n rollup,\n};\n"]}
package/index.d.cts ADDED
@@ -0,0 +1,13 @@
1
+ import export_default from './babel.cjs';
2
+ import { t as typegpu } from './rollup-C-ISXvlZ.cjs';
3
+ export { T as TypegpuPluginOptions } from './rollup-C-ISXvlZ.cjs';
4
+ import '@babel/traverse';
5
+ import '@babel/types';
6
+ import 'rollup';
7
+
8
+ declare const _default: {
9
+ babel: typeof export_default;
10
+ rollup: typeof typegpu;
11
+ };
12
+
13
+ export { _default as default };
package/index.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import export_default from './babel.js';
2
+ import { t as typegpu } from './rollup-C-ISXvlZ.js';
3
+ export { T as TypegpuPluginOptions } from './rollup-C-ISXvlZ.js';
4
+ import '@babel/traverse';
5
+ import '@babel/types';
6
+ import 'rollup';
7
+
8
+ declare const _default: {
9
+ babel: typeof export_default;
10
+ rollup: typeof typegpu;
11
+ };
12
+
13
+ export { _default as default };
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import{a as p}from"./chunk-VSVKZFFD.js";import{a as o}from"./chunk-5MLKKHGO.js";import"./chunk-XWE2EDOE.js";var t={babel:o,rollup:p};export{t as default};
2
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import babel from './babel';\nimport rollup from './rollup';\n\nexport type { TypegpuPluginOptions } from './common';\n\nexport default {\n babel,\n rollup,\n};\n"],"mappings":"4GAKA,IAAOA,EAAQ,CACb,MAAAC,EACA,OAAAC,CACF","names":["src_default","babel_default","typegpu"]}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "unplugin-typegpu",
3
+ "version": "0.1.0-alpha.1",
4
+ "description": "Build plugins for TypeGPU, enabling seamless JavaScript -> WGSL transpilation and improved debugging.",
5
+ "keywords": [
6
+ "rollup-plugin",
7
+ "babel-plugin",
8
+ "vite-plugin",
9
+ "typegpu",
10
+ "gpgpu",
11
+ "webgpu",
12
+ "wgpu",
13
+ "wgsl",
14
+ "typescript",
15
+ "shaders"
16
+ ],
17
+ "license": "MIT",
18
+ "type": "module",
19
+ "main": "./index.js",
20
+ "types": "./index.d.ts",
21
+ "exports": {
22
+ "./package.json": "./package.json",
23
+ ".": {
24
+ "types": "./index.d.ts",
25
+ "module": "./index.js",
26
+ "import": "./index.js",
27
+ "default": "./index.cjs"
28
+ },
29
+ "./rollup": {
30
+ "types": "./rollup.d.ts",
31
+ "module": "./rollup.js",
32
+ "import": "./rollup.js",
33
+ "default": "./rollup.cjs"
34
+ },
35
+ "./babel": {
36
+ "types": "./babel.d.ts",
37
+ "module": "./babel.js",
38
+ "import": "./babel.js",
39
+ "default": "./babel.cjs"
40
+ }
41
+ },
42
+ "sideEffects": false,
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/software-mansion/TypeGPU.git"
46
+ },
47
+ "bugs": {
48
+ "url": "https://github.com/software-mansion/TypeGPU/issues"
49
+ },
50
+ "homepage": "https://typegpu.com",
51
+ "dependencies": {
52
+ "tinyest-for-wgsl": "~0.1.0-alpha.0",
53
+ "estree-walker": "^3.0.3",
54
+ "magic-string": "^0.30.11",
55
+ "@babel/standalone": "^7.26.6"
56
+ },
57
+ "private": false,
58
+ "scripts": {}
59
+ }
@@ -0,0 +1,16 @@
1
+ import { SourceMap } from 'rollup';
2
+
3
+ interface TypegpuPluginOptions {
4
+ include?: 'all' | RegExp[];
5
+ }
6
+
7
+ interface TypegpuRollupPlugin {
8
+ name: 'rollup-plugin-typegpu';
9
+ transform(code: string, id: string): {
10
+ code: string;
11
+ map: SourceMap;
12
+ } | undefined;
13
+ }
14
+ declare function typegpu(options?: TypegpuPluginOptions): TypegpuRollupPlugin;
15
+
16
+ export { type TypegpuPluginOptions as T, type TypegpuRollupPlugin as a, typegpu as t };
@@ -0,0 +1,16 @@
1
+ import { SourceMap } from 'rollup';
2
+
3
+ interface TypegpuPluginOptions {
4
+ include?: 'all' | RegExp[];
5
+ }
6
+
7
+ interface TypegpuRollupPlugin {
8
+ name: 'rollup-plugin-typegpu';
9
+ transform(code: string, id: string): {
10
+ code: string;
11
+ map: SourceMap;
12
+ } | undefined;
13
+ }
14
+ declare function typegpu(options?: TypegpuPluginOptions): TypegpuRollupPlugin;
15
+
16
+ export { type TypegpuPluginOptions as T, type TypegpuRollupPlugin as a, typegpu as t };
package/rollup.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkGN3AXEAXcjs = require('./chunk-GN3AXEAX.cjs');require('./chunk-5YUXNY4J.cjs');exports.default = _chunkGN3AXEAXcjs.a;
2
+ //# sourceMappingURL=rollup.cjs.map
package/rollup.cjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
package/rollup.d.cts ADDED
@@ -0,0 +1,2 @@
1
+ import 'rollup';
2
+ export { a as TypegpuRollupPlugin, t as default } from './rollup-C-ISXvlZ.cjs';
package/rollup.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import 'rollup';
2
+ export { a as TypegpuRollupPlugin, t as default } from './rollup-C-ISXvlZ.js';
package/rollup.js ADDED
@@ -0,0 +1,2 @@
1
+ import{a}from"./chunk-VSVKZFFD.js";import"./chunk-XWE2EDOE.js";export{a as default};
2
+ //# sourceMappingURL=rollup.js.map
package/rollup.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}