carboncanvas 0.1.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/vite.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ // Types for the `carboncanvas/vite` subpath (the carbonPreset helper). Hand-
2
+ // authored (not generated by vite-plugin-dts): the preset is a build-time Node
3
+ // module that re-exports the data-anchor babel plugin, so it lives OUTSIDE the
4
+ // React library's dts-rollup surface (which only covers the runtime canvas API).
5
+
6
+ export interface CarbonPresetOptions {
7
+ /**
8
+ * Reserved. Durable source-anchored pins need `dataAnchorBabelPlugin` wired
9
+ * into your react() plugin's `babel.plugins` (a config fragment can't reach
10
+ * into it), so this flag is documentation/forward-compat only.
11
+ */
12
+ dataAnchor?: boolean;
13
+ }
14
+
15
+ /** The Vite config fragment carbonPreset returns. */
16
+ export interface CarbonViteFragment {
17
+ esbuild: { keepNames: true };
18
+ }
19
+
20
+ /**
21
+ * The Carbon Canvas Vite config fragment — spread into your `vite.config` to
22
+ * preserve component names in the production build (`esbuild.keepNames`).
23
+ */
24
+ export declare function carbonPreset(opts?: CarbonPresetOptions): CarbonViteFragment;
25
+
26
+ /**
27
+ * The data-anchor Babel plugin, re-exported so you can pass it to your own
28
+ * `react({ babel: { plugins: [dataAnchorBabelPlugin] } })` for durable pins.
29
+ */
30
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+ export declare const dataAnchorBabelPlugin: (babel: any) => any;
32
+
33
+ export default carbonPreset;
package/vite.js ADDED
@@ -0,0 +1,42 @@
1
+ // carbonPreset — a Vite config fragment for Carbon Canvas consumers
2
+ // (plan §6.2 / amendment B.5). Spread it into your `vite.config` so the
3
+ // production build preserves component names the Inspector reads off the live
4
+ // fibers:
5
+ //
6
+ // import { carbonPreset } from 'carboncanvas/vite';
7
+ // export default defineConfig({ ...carbonPreset(), plugins: [react()] });
8
+ //
9
+ // WHY A FRAGMENT + A SEPARATE PLUGIN RE-EXPORT (not one all-in-one preset):
10
+ // the fragment can safely set esbuild.keepNames, but the OPTIONAL data-anchor
11
+ // babel plugin has to live inside @vitejs/plugin-react's `babel.plugins` option
12
+ // — which a top-level config fragment cannot reach into without knowing your
13
+ // react() call. So the plugin is RE-EXPORTED here (`dataAnchorBabelPlugin`) and
14
+ // you pass it to your own react() plugin, matching the documented pattern:
15
+ //
16
+ // import { carbonPreset, dataAnchorBabelPlugin } from 'carboncanvas/vite';
17
+ // export default defineConfig({
18
+ // ...carbonPreset(),
19
+ // plugins: [react({ babel: { plugins: [dataAnchorBabelPlugin] } })],
20
+ // });
21
+
22
+ import dataAnchorBabelPlugin from './tools/babel-plugin-data-anchor.js';
23
+
24
+ /**
25
+ * Returns the Carbon Canvas Vite config fragment. Today that is
26
+ * `{ esbuild: { keepNames: true } }` — the one setting that keeps the Inspector
27
+ * showing REAL component names in a minified production build.
28
+ *
29
+ * @param {{ dataAnchor?: boolean }} [opts] Reserved. Durable source-anchored
30
+ * pins need the `dataAnchorBabelPlugin` re-export wired into YOUR react()
31
+ * plugin's babel option (a config fragment can't reach into it) — see the
32
+ * module header. The flag is accepted for forward-compat and documentation.
33
+ */
34
+ export function carbonPreset(opts = {}) {
35
+ void opts;
36
+ return {
37
+ esbuild: { keepNames: true },
38
+ };
39
+ }
40
+
41
+ export { dataAnchorBabelPlugin };
42
+ export default carbonPreset;