@navita/extraction 3.0.0-next.0

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) 2023 Alexander Liljengård
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,157 @@
1
+ ![Navita Logo](https://navita.style/navita.svg)
2
+
3
+ Navita is a powerful CSS-in-JS library
4
+ that brings type-safe compile-time Atomic CSS-in-JS with zero runtime to your projects.
5
+
6
+ It allows you to easily style your components and apply themes without the need for any additional runtime dependencies.
7
+
8
+ With Navita, you can write clean and maintainable CSS in JavaScript, without sacrificing runtime performance.
9
+
10
+
11
+ 🔥   All styles generated at build time — just like Sass, Less, etc.
12
+
13
+ ✨   Minimal abstraction over standard CSS.
14
+
15
+ 🦄   Works with any JS-based front-end framework — or even without one.
16
+
17
+ 🎨   High-level theme system with support for simultaneous themes.
18
+
19
+ 💪   Type-safe styles via [CSSType](https://github.com/frenic/csstype).
20
+
21
+ 🌳   Co-locate your styles with your components — if you want to.
22
+
23
+ 🛠   Integrations with popular bundlers such as Webpack, Vite, and Next.js.
24
+
25
+ ---
26
+ 🌐 [Check out the documentation site for setup guides, examples and API docs.](https://navita.style)
27
+
28
+ ---
29
+
30
+ ## Installation
31
+
32
+ To start using Navita in your project, simply follow these steps:
33
+
34
+ ### Install Navita using npm:
35
+
36
+ ```bash
37
+ npm install @navita/css --save
38
+ ```
39
+
40
+ You'll also need to install the Navita integration for your preferred bundler.
41
+ Navita currently supports Webpack, Vite, and Next.js.
42
+
43
+ ### Choose the integration for your preferred bundler:
44
+ #### If you are using Webpack, install the Webpack integration:
45
+
46
+ ```bash
47
+ npm install @navita/webpack-plugin mini-css-extract-plugin --save-dev
48
+ ```
49
+
50
+ Update your `webpack.config.js` file to include both MiniCssExtractPlugin and NavitaPlugin:
51
+
52
+ ```javascript
53
+ const { NavitaPlugin } = require('@navita/webpack-plugin');
54
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
55
+
56
+ module.exports = {
57
+ // Other webpack options,
58
+ plugins: [
59
+ new MiniCssExtractPlugin(),
60
+ new NavitaPlugin(),
61
+ ],
62
+ };
63
+ ```
64
+
65
+ Read more about the Webpack integration in the [Webpack documentation](https://navita.style/integrations/webpack).
66
+
67
+ #### If you are using Vite, install the Vite integration:
68
+
69
+ ```bash
70
+ npm install @navita/vite-plugin --save-dev
71
+ ```
72
+
73
+ And add it to your `vite.config.js` file:
74
+
75
+ ```typescript
76
+ import { defineConfig } from 'vite';
77
+ import { navita } from '@navita/vite-plugin';
78
+
79
+ export default defineConfig({
80
+ plugins: [
81
+ // Other plugins
82
+ navita(/* Additional options */)
83
+ ],
84
+ });
85
+ ```
86
+
87
+ Read more about the Vite integration in the [Vite documentation](https://navita.style/integrations/vite).
88
+
89
+ ##### If you are using Next.js, install the Next.js integration:
90
+
91
+ 🚀   React Server Components support!
92
+
93
+ ```bash
94
+ npm install @navita/next-plugin --save-dev
95
+ ```
96
+
97
+ And add it to your `next.config.js` file:
98
+
99
+ ```javascript
100
+ const { createNavitaStylePlugin } = require("@navita/next-plugin");
101
+
102
+ /** @type {import('next').NextConfig} */
103
+ const nextConfig = {};
104
+
105
+ module.exports = createNavitaStylePlugin({
106
+ // Additional options
107
+ })(nextConfig);
108
+ ```
109
+
110
+ Read more about the Next.js integration in the [Next.js documentation](https://navita.style/integrations/next).
111
+
112
+ ## Usage
113
+
114
+ The main entry point for Navita is the `style` function.
115
+ Make sure you read the reset of the documentation on
116
+ <https://navita.style> to learn more about the APIs.
117
+
118
+ ```typescript
119
+ import { style } from '@navita/css';
120
+
121
+ const container = style({
122
+ padding: '2rem',
123
+ background: 'hotpink',
124
+ color: 'white',
125
+ });
126
+
127
+ document.write(`
128
+ <div class="${container}">
129
+ Hello World!
130
+ </div>
131
+ `);
132
+ ```
133
+
134
+ That's it!
135
+
136
+ 💡 Only references to the classNames will be included in the bundle.
137
+
138
+ > Note: Navita doesn't require special file extensions for your styles.
139
+ You can co-locate your CSS styles with your components.
140
+
141
+ ## Documentation
142
+
143
+ For detailed documentation, examples, and usage guidelines,
144
+ please visit the official Navita website: <https://navita.style>
145
+
146
+ ## Contributing
147
+
148
+ We welcome contributions from the community to make Navita even better!
149
+
150
+ ## Thanks
151
+ * [Vanilla-Extract](https://vanilla-extract.style) and [Linaria](https://linaria.dev) for the inspiration and the great work on the CSS-in-JS ecosystem.
152
+ * [Fela](https://fela.js.org) for the fantastic work on Atomic css-in-js.
153
+ * [Eagerpatch](https://eagerpatch.com) for giving us the space to do interesting work.
154
+ ***
155
+
156
+ MIT Licensed—A project by [Eagerpatch](https://eagerpatch.com).\
157
+ Made with ❤️ by [zn4rk](https://github.com/zn4rk) and contributors.
@@ -0,0 +1,23 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ exports.__toESM = __toESM;
@@ -0,0 +1,8 @@
1
+ import "node:path";
2
+ import "node:url";
3
+ import.meta.url;
4
+ import { createRequire } from "node:module";
5
+ //#region \0rolldown/runtime.js
6
+ var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
7
+ //#endregion
8
+ export { __require };
package/ast.cjs ADDED
@@ -0,0 +1,164 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/ast.ts
3
+ const SKIP_KEYS = /* @__PURE__ */ new Set([
4
+ "type",
5
+ "start",
6
+ "end",
7
+ "range",
8
+ "loc",
9
+ "parent"
10
+ ]);
11
+ /**
12
+ * Recursively visit every child node. The callback may return `false` to skip
13
+ * descending into that node's children.
14
+ */
15
+ function walk(node, visit) {
16
+ if (!node || typeof node !== "object") return;
17
+ if (Array.isArray(node)) {
18
+ for (const child of node) walk(child, visit);
19
+ return;
20
+ }
21
+ const n = node;
22
+ if (typeof n.type === "string") {
23
+ if (visit(n) === false) return;
24
+ }
25
+ for (const key in n) {
26
+ if (SKIP_KEYS.has(key)) continue;
27
+ const value = n[key];
28
+ if (value && typeof value === "object") walk(value, visit);
29
+ }
30
+ }
31
+ /** Unwrap `(expr)` parenthesized expressions. */
32
+ function unwrapParens(node) {
33
+ let current = node;
34
+ while (current && current.type === "ParenthesizedExpression") current = current.expression;
35
+ return current ?? null;
36
+ }
37
+ /**
38
+ * Return the callee identifier name of a call expression, if the callee is a
39
+ * plain identifier (mirrors the Rust `get_callee_ident`). Member expressions
40
+ * (`obj.style(...)`) return `null`.
41
+ */
42
+ function getCalleeName(callExpr) {
43
+ const callee = unwrapParens(callExpr.callee);
44
+ if (callee && callee.type === "Identifier") return callee.name;
45
+ return null;
46
+ }
47
+ /**
48
+ * If `expr` (after unwrapping parens) is a call expression whose callee is a
49
+ * plain identifier, return that identifier name (mirrors `get_callee_ident` on
50
+ * an init expression).
51
+ */
52
+ function getInitCalleeName(expr) {
53
+ const inner = unwrapParens(expr);
54
+ if (inner && inner.type === "CallExpression") return getCalleeName(inner);
55
+ return null;
56
+ }
57
+ /**
58
+ * Collect the binding identifier names introduced by a binding pattern.
59
+ * Mirrors `collect_ids_from_pat`.
60
+ */
61
+ function patternNames(pat, out = []) {
62
+ if (!pat) return out;
63
+ switch (pat.type) {
64
+ case "Identifier":
65
+ case "BindingIdentifier":
66
+ out.push(pat.name);
67
+ break;
68
+ case "AssignmentPattern":
69
+ patternNames(pat.left, out);
70
+ break;
71
+ case "ArrayPattern":
72
+ for (const element of pat.elements || []) if (element) patternNames(element, out);
73
+ break;
74
+ case "ObjectPattern":
75
+ for (const prop of pat.properties || []) if (prop.type === "RestElement") patternNames(prop.argument, out);
76
+ else patternNames(prop.value, out);
77
+ break;
78
+ case "RestElement":
79
+ patternNames(pat.argument, out);
80
+ break;
81
+ default: break;
82
+ }
83
+ return out;
84
+ }
85
+ /**
86
+ * Collect identifier names referenced inside a value expression, applying the
87
+ * same skipping rules as the Rust `IdentCollector`:
88
+ * - For member expressions, only descend into a computed property; never the
89
+ * static property name (`a.b` collects `a`, not `b`).
90
+ * - For object properties, only descend into a computed key; always the value
91
+ * (`{ key: value }` collects `value`, not `key`).
92
+ * - TypeScript type positions are skipped.
93
+ */
94
+ function collectArgumentIdents(node, out) {
95
+ if (!node || typeof node !== "object") return;
96
+ if (Array.isArray(node)) {
97
+ for (const child of node) collectArgumentIdents(child, out);
98
+ return;
99
+ }
100
+ const n = node;
101
+ switch (n.type) {
102
+ case "Identifier":
103
+ case "IdentifierReference":
104
+ out.add(n.name);
105
+ return;
106
+ case "MemberExpression":
107
+ case "StaticMemberExpression":
108
+ case "ComputedMemberExpression":
109
+ if (n.computed) collectArgumentIdents(n.property, out);
110
+ collectArgumentIdents(n.object, out);
111
+ return;
112
+ case "Property":
113
+ case "ObjectProperty":
114
+ if (n.computed) collectArgumentIdents(n.key, out);
115
+ collectArgumentIdents(n.value, out);
116
+ return;
117
+ case "TSAsExpression":
118
+ case "TSSatisfiesExpression":
119
+ case "TSNonNullExpression":
120
+ case "TSInstantiationExpression":
121
+ case "TSTypeAssertion":
122
+ collectArgumentIdents(n.expression, out);
123
+ return;
124
+ default: break;
125
+ }
126
+ for (const key in n) {
127
+ if (SKIP_KEYS.has(key)) continue;
128
+ const value = n[key];
129
+ if (value && typeof value === "object") collectArgumentIdents(value, out);
130
+ }
131
+ }
132
+ /** Build a (1-based line, 0-based column) lookup for byte/UTF-16 offsets. */
133
+ function createLineColumnLookup(code) {
134
+ const lineStarts = [0];
135
+ for (let i = 0; i < code.length; i++) if (code.charCodeAt(i) === 10) lineStarts.push(i + 1);
136
+ return (offset) => {
137
+ let lo = 0;
138
+ let hi = lineStarts.length - 1;
139
+ while (lo < hi) {
140
+ const mid = lo + hi + 1 >> 1;
141
+ if (lineStarts[mid] <= offset) lo = mid;
142
+ else hi = mid - 1;
143
+ }
144
+ return {
145
+ line: lo + 1,
146
+ column: offset - lineStarts[lo]
147
+ };
148
+ };
149
+ }
150
+ /** The imported name of a named import specifier (identifier or string key). */
151
+ function importedName(spec) {
152
+ const imported = spec.imported;
153
+ if (!imported) return spec.local.name;
154
+ return imported.type === "Identifier" || imported.type === "ImportSpecifier" ? imported.name : imported.value;
155
+ }
156
+ //#endregion
157
+ exports.collectArgumentIdents = collectArgumentIdents;
158
+ exports.createLineColumnLookup = createLineColumnLookup;
159
+ exports.getCalleeName = getCalleeName;
160
+ exports.getInitCalleeName = getInitCalleeName;
161
+ exports.importedName = importedName;
162
+ exports.patternNames = patternNames;
163
+ exports.unwrapParens = unwrapParens;
164
+ exports.walk = walk;
package/ast.mjs ADDED
@@ -0,0 +1,159 @@
1
+ import "node:path";
2
+ import "node:url";
3
+ import.meta.url;
4
+ //#region src/ast.ts
5
+ const SKIP_KEYS = /* @__PURE__ */ new Set([
6
+ "type",
7
+ "start",
8
+ "end",
9
+ "range",
10
+ "loc",
11
+ "parent"
12
+ ]);
13
+ /**
14
+ * Recursively visit every child node. The callback may return `false` to skip
15
+ * descending into that node's children.
16
+ */
17
+ function walk(node, visit) {
18
+ if (!node || typeof node !== "object") return;
19
+ if (Array.isArray(node)) {
20
+ for (const child of node) walk(child, visit);
21
+ return;
22
+ }
23
+ const n = node;
24
+ if (typeof n.type === "string") {
25
+ if (visit(n) === false) return;
26
+ }
27
+ for (const key in n) {
28
+ if (SKIP_KEYS.has(key)) continue;
29
+ const value = n[key];
30
+ if (value && typeof value === "object") walk(value, visit);
31
+ }
32
+ }
33
+ /** Unwrap `(expr)` parenthesized expressions. */
34
+ function unwrapParens(node) {
35
+ let current = node;
36
+ while (current && current.type === "ParenthesizedExpression") current = current.expression;
37
+ return current ?? null;
38
+ }
39
+ /**
40
+ * Return the callee identifier name of a call expression, if the callee is a
41
+ * plain identifier (mirrors the Rust `get_callee_ident`). Member expressions
42
+ * (`obj.style(...)`) return `null`.
43
+ */
44
+ function getCalleeName(callExpr) {
45
+ const callee = unwrapParens(callExpr.callee);
46
+ if (callee && callee.type === "Identifier") return callee.name;
47
+ return null;
48
+ }
49
+ /**
50
+ * If `expr` (after unwrapping parens) is a call expression whose callee is a
51
+ * plain identifier, return that identifier name (mirrors `get_callee_ident` on
52
+ * an init expression).
53
+ */
54
+ function getInitCalleeName(expr) {
55
+ const inner = unwrapParens(expr);
56
+ if (inner && inner.type === "CallExpression") return getCalleeName(inner);
57
+ return null;
58
+ }
59
+ /**
60
+ * Collect the binding identifier names introduced by a binding pattern.
61
+ * Mirrors `collect_ids_from_pat`.
62
+ */
63
+ function patternNames(pat, out = []) {
64
+ if (!pat) return out;
65
+ switch (pat.type) {
66
+ case "Identifier":
67
+ case "BindingIdentifier":
68
+ out.push(pat.name);
69
+ break;
70
+ case "AssignmentPattern":
71
+ patternNames(pat.left, out);
72
+ break;
73
+ case "ArrayPattern":
74
+ for (const element of pat.elements || []) if (element) patternNames(element, out);
75
+ break;
76
+ case "ObjectPattern":
77
+ for (const prop of pat.properties || []) if (prop.type === "RestElement") patternNames(prop.argument, out);
78
+ else patternNames(prop.value, out);
79
+ break;
80
+ case "RestElement":
81
+ patternNames(pat.argument, out);
82
+ break;
83
+ default: break;
84
+ }
85
+ return out;
86
+ }
87
+ /**
88
+ * Collect identifier names referenced inside a value expression, applying the
89
+ * same skipping rules as the Rust `IdentCollector`:
90
+ * - For member expressions, only descend into a computed property; never the
91
+ * static property name (`a.b` collects `a`, not `b`).
92
+ * - For object properties, only descend into a computed key; always the value
93
+ * (`{ key: value }` collects `value`, not `key`).
94
+ * - TypeScript type positions are skipped.
95
+ */
96
+ function collectArgumentIdents(node, out) {
97
+ if (!node || typeof node !== "object") return;
98
+ if (Array.isArray(node)) {
99
+ for (const child of node) collectArgumentIdents(child, out);
100
+ return;
101
+ }
102
+ const n = node;
103
+ switch (n.type) {
104
+ case "Identifier":
105
+ case "IdentifierReference":
106
+ out.add(n.name);
107
+ return;
108
+ case "MemberExpression":
109
+ case "StaticMemberExpression":
110
+ case "ComputedMemberExpression":
111
+ if (n.computed) collectArgumentIdents(n.property, out);
112
+ collectArgumentIdents(n.object, out);
113
+ return;
114
+ case "Property":
115
+ case "ObjectProperty":
116
+ if (n.computed) collectArgumentIdents(n.key, out);
117
+ collectArgumentIdents(n.value, out);
118
+ return;
119
+ case "TSAsExpression":
120
+ case "TSSatisfiesExpression":
121
+ case "TSNonNullExpression":
122
+ case "TSInstantiationExpression":
123
+ case "TSTypeAssertion":
124
+ collectArgumentIdents(n.expression, out);
125
+ return;
126
+ default: break;
127
+ }
128
+ for (const key in n) {
129
+ if (SKIP_KEYS.has(key)) continue;
130
+ const value = n[key];
131
+ if (value && typeof value === "object") collectArgumentIdents(value, out);
132
+ }
133
+ }
134
+ /** Build a (1-based line, 0-based column) lookup for byte/UTF-16 offsets. */
135
+ function createLineColumnLookup(code) {
136
+ const lineStarts = [0];
137
+ for (let i = 0; i < code.length; i++) if (code.charCodeAt(i) === 10) lineStarts.push(i + 1);
138
+ return (offset) => {
139
+ let lo = 0;
140
+ let hi = lineStarts.length - 1;
141
+ while (lo < hi) {
142
+ const mid = lo + hi + 1 >> 1;
143
+ if (lineStarts[mid] <= offset) lo = mid;
144
+ else hi = mid - 1;
145
+ }
146
+ return {
147
+ line: lo + 1,
148
+ column: offset - lineStarts[lo]
149
+ };
150
+ };
151
+ }
152
+ /** The imported name of a named import specifier (identifier or string key). */
153
+ function importedName(spec) {
154
+ const imported = spec.imported;
155
+ if (!imported) return spec.local.name;
156
+ return imported.type === "Identifier" || imported.type === "ImportSpecifier" ? imported.name : imported.value;
157
+ }
158
+ //#endregion
159
+ export { collectArgumentIdents, createLineColumnLookup, getCalleeName, getInitCalleeName, importedName, patternNames, unwrapParens, walk };
package/extraction.cjs ADDED
@@ -0,0 +1,23 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_rewrite = require("./rewrite.cjs");
3
+ const require_stripTypes = require("./stripTypes.cjs");
4
+ const require_toAmd = require("./toAmd.cjs");
5
+ //#region src/extraction.ts
6
+ /**
7
+ * Transform a TypeScript/TSX module into an evaluatable AMD module for
8
+ * `@navita/core`.
9
+ *
10
+ * For entry points, navita style calls are extracted into `collectResult(...)`
11
+ * wrappers and the module is pruned to only what's needed to evaluate them.
12
+ * For dependencies (`entryPoint: false`), the module is returned unchanged
13
+ * except for TypeScript stripping and AMD wrapping.
14
+ */
15
+ async function extraction(code, { filename, importMap = [], entryPoint = true }) {
16
+ if (entryPoint === false) return require_toAmd.esmToAmd(require_stripTypes.stripTypes(filename, code), { dropUnusedImports: false });
17
+ return require_toAmd.esmToAmd(require_stripTypes.stripTypes(filename, require_rewrite.rewrite(code, {
18
+ filename,
19
+ importMap
20
+ })), { dropUnusedImports: true });
21
+ }
22
+ //#endregion
23
+ exports.extraction = extraction;
package/extraction.mjs ADDED
@@ -0,0 +1,25 @@
1
+ import "node:path";
2
+ import "node:url";
3
+ import.meta.url;
4
+ import { rewrite } from "./rewrite.mjs";
5
+ import { stripTypes } from "./stripTypes.mjs";
6
+ import { esmToAmd } from "./toAmd.mjs";
7
+ //#region src/extraction.ts
8
+ /**
9
+ * Transform a TypeScript/TSX module into an evaluatable AMD module for
10
+ * `@navita/core`.
11
+ *
12
+ * For entry points, navita style calls are extracted into `collectResult(...)`
13
+ * wrappers and the module is pruned to only what's needed to evaluate them.
14
+ * For dependencies (`entryPoint: false`), the module is returned unchanged
15
+ * except for TypeScript stripping and AMD wrapping.
16
+ */
17
+ async function extraction(code, { filename, importMap = [], entryPoint = true }) {
18
+ if (entryPoint === false) return esmToAmd(stripTypes(filename, code), { dropUnusedImports: false });
19
+ return esmToAmd(stripTypes(filename, rewrite(code, {
20
+ filename,
21
+ importMap
22
+ })), { dropUnusedImports: true });
23
+ }
24
+ //#endregion
25
+ export { extraction };
package/index.cjs ADDED
@@ -0,0 +1,3 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_extraction = require("./extraction.cjs");
3
+ exports.extraction = require_extraction.extraction;
package/index.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { ImportMap } from "@navita/types";
2
+
3
+ //#region src/extraction.d.ts
4
+ type Options = {
5
+ filename: string;
6
+ importMap?: ImportMap;
7
+ entryPoint?: boolean;
8
+ };
9
+ /**
10
+ * Transform a TypeScript/TSX module into an evaluatable AMD module for
11
+ * `@navita/core`.
12
+ *
13
+ * For entry points, navita style calls are extracted into `collectResult(...)`
14
+ * wrappers and the module is pruned to only what's needed to evaluate them.
15
+ * For dependencies (`entryPoint: false`), the module is returned unchanged
16
+ * except for TypeScript stripping and AMD wrapping.
17
+ */
18
+ declare function extraction(code: string, {
19
+ filename,
20
+ importMap,
21
+ entryPoint
22
+ }: Options): Promise<string>;
23
+ //#endregion
24
+ export { extraction };
package/index.mjs ADDED
@@ -0,0 +1,5 @@
1
+ import "node:path";
2
+ import "node:url";
3
+ import.meta.url;
4
+ import { extraction } from "./extraction.mjs";
5
+ export { extraction };
package/loadOxc.cjs ADDED
@@ -0,0 +1,19 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/loadOxc.ts
3
+ function getNativeRequire() {
4
+ const proc = process;
5
+ return (typeof process !== "undefined" && typeof proc.getBuiltinModule === "function" ? proc.getBuiltinModule("module") : require("node:module")).createRequire(__filename);
6
+ }
7
+ let parser;
8
+ let transform;
9
+ function getParser() {
10
+ if (!parser) parser = getNativeRequire()("oxc-parser");
11
+ return parser;
12
+ }
13
+ function getTransform() {
14
+ if (!transform) transform = getNativeRequire()("oxc-transform");
15
+ return transform;
16
+ }
17
+ //#endregion
18
+ exports.getParser = getParser;
19
+ exports.getTransform = getTransform;
package/loadOxc.mjs ADDED
@@ -0,0 +1,21 @@
1
+ import "node:path";
2
+ import __tsdown_shims_url from "node:url";
3
+ const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url);
4
+ import { __require } from "./_virtual/_rolldown/runtime.mjs";
5
+ //#region src/loadOxc.ts
6
+ function getNativeRequire() {
7
+ const proc = process;
8
+ return (typeof process !== "undefined" && typeof proc.getBuiltinModule === "function" ? proc.getBuiltinModule("module") : __require("node:module")).createRequire(__TSDOWN_SHIM_FILENAME__);
9
+ }
10
+ let parser;
11
+ let transform;
12
+ function getParser() {
13
+ if (!parser) parser = getNativeRequire()("oxc-parser");
14
+ return parser;
15
+ }
16
+ function getTransform() {
17
+ if (!transform) transform = getNativeRequire()("oxc-transform");
18
+ return transform;
19
+ }
20
+ //#endregion
21
+ export { getParser, getTransform };