@firebuzz/design-mode 0.1.4 → 0.2.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 +77 -0
- package/dist/index.d.mts +10 -17
- package/dist/index.d.ts +10 -17
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/dist/overlay.js.map +1 -1
- package/dist/overlay.mjs.map +1 -1
- package/package.json +58 -62
package/LICENSE
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, Apache 2.0 Future License
|
|
2
|
+
**Abbreviation**: FSL-1.1-Apache-2.0
|
|
3
|
+
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Notice
|
|
7
|
+
Copyright 2023-2024 Firebuzz Inc., the creators of **Firebuzz**.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
The party offering **Firebuzz** under these Terms and Conditions.
|
|
15
|
+
|
|
16
|
+
### The Software
|
|
17
|
+
The "Software" is each version of **Firebuzz** that we make available under these Terms and Conditions, as indicated by our inclusion of these Terms and Conditions with the Software.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## License Grant
|
|
22
|
+
Subject to your compliance with this License Grant and the Patents, Redistribution, and Trademark clauses below, we hereby grant you the right to use, copy, modify, create derivative works, publicly perform, publicly display, and redistribute **Firebuzz** for any Permitted Purpose identified below.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Permitted Purpose
|
|
27
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use means making **Firebuzz** available to others in a commercial product or service that:
|
|
28
|
+
|
|
29
|
+
1. Substitutes for **Firebuzz**;
|
|
30
|
+
2. Substitutes for any other product or service we offer using **Firebuzz** that exists as of the date we make **Firebuzz** available; or
|
|
31
|
+
3. Offers the same or substantially similar functionality as **Firebuzz**.
|
|
32
|
+
|
|
33
|
+
Permitted Purposes specifically include using **Firebuzz**:
|
|
34
|
+
|
|
35
|
+
1. For your internal use and access;
|
|
36
|
+
2. For non-commercial education;
|
|
37
|
+
3. For non-commercial research; and
|
|
38
|
+
4. In connection with professional services that you provide to a licensee using **Firebuzz** in accordance with these Terms and Conditions.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Patents
|
|
43
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our patents, the license grant above includes a license under our patents. If you make a claim against any party that **Firebuzz** infringes or contributes to the infringement of any patent, then your patent license to **Firebuzz** ends immediately.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Redistribution
|
|
48
|
+
The Terms and Conditions apply to all copies, modifications, and derivatives of **Firebuzz**.
|
|
49
|
+
|
|
50
|
+
If you redistribute any copies, modifications, or derivatives of **Firebuzz**, you must:
|
|
51
|
+
|
|
52
|
+
1. Include a copy of or a link to these Terms and Conditions; and
|
|
53
|
+
2. Not remove any copyright notices provided in or with **Firebuzz**.
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Disclaimer
|
|
58
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, TITLE, OR NON-INFRINGEMENT.
|
|
59
|
+
|
|
60
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO **Firebuzz**, INCLUDING INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Trademarks
|
|
65
|
+
Except for displaying the License Details and identifying us as the origin of **Firebuzz**, you have no right under these Terms and Conditions to use our trademarks, trade names, service marks, or product names.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Grant of Future License
|
|
70
|
+
We hereby irrevocably grant you an additional license to use **Firebuzz** under the Apache License, Version 2.0, effective on the third anniversary of the date we make **Firebuzz** available. On or after that date, you may use **Firebuzz** under the Apache License, Version 2.0, in which case the following will apply:
|
|
71
|
+
|
|
72
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
|
|
73
|
+
|
|
74
|
+
You may obtain a copy of the License at:
|
|
75
|
+
[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
|
|
76
|
+
|
|
77
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,22 +1,5 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Vite plugin that enables design mode features for Firebuzz templates
|
|
5
|
-
* - Generates Tailwind config JSON for client-side use
|
|
6
|
-
* - Injects overlay script for element selection
|
|
7
|
-
*
|
|
8
|
-
* NOTE: This plugin does NOT modify JSX/TSX files.
|
|
9
|
-
* Element tracking is done at runtime using React Fiber's _debugSource.
|
|
10
|
-
*
|
|
11
|
-
* @param options - Plugin configuration options
|
|
12
|
-
* @param options.tailwindConfigPath - Path to tailwind.config.js (default: "./tailwind.config.js")
|
|
13
|
-
* @param options.outputPath - Path to output tailwind.config.json (default: "./src/design-mode/tailwind.config.json")
|
|
14
|
-
*/
|
|
15
|
-
declare function firebuzzDesignMode(options?: {
|
|
16
|
-
tailwindConfigPath?: string;
|
|
17
|
-
outputPath?: string;
|
|
18
|
-
}): Plugin;
|
|
19
|
-
|
|
20
3
|
/**
|
|
21
4
|
* TypeScript type definitions for Firebuzz Design Mode
|
|
22
5
|
*/
|
|
@@ -82,4 +65,14 @@ interface AllElementsStateMessage {
|
|
|
82
65
|
}
|
|
83
66
|
type DesignModeMessageType = DesignModeMessage | ElementSelectedMessage | AllElementsStateMessage;
|
|
84
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Vite plugin that enables design mode features for Firebuzz templates
|
|
70
|
+
* - Injects Tailwind Play CDN for runtime CSS generation
|
|
71
|
+
* - Injects overlay script for element selection
|
|
72
|
+
*
|
|
73
|
+
* NOTE: This plugin does NOT modify JSX/TSX files.
|
|
74
|
+
* Element tracking is done at runtime using React Fiber's _debugSource.
|
|
75
|
+
*/
|
|
76
|
+
declare function firebuzzDesignMode(): Plugin;
|
|
77
|
+
|
|
85
78
|
export { type AllElementsStateMessage, type DesignModeMessage, type DesignModeMessageType, type ElementData, type ElementSelectedMessage, type ElementUpdates, type SourceLocation, type ThemeVariables, firebuzzDesignMode };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,22 +1,5 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Vite plugin that enables design mode features for Firebuzz templates
|
|
5
|
-
* - Generates Tailwind config JSON for client-side use
|
|
6
|
-
* - Injects overlay script for element selection
|
|
7
|
-
*
|
|
8
|
-
* NOTE: This plugin does NOT modify JSX/TSX files.
|
|
9
|
-
* Element tracking is done at runtime using React Fiber's _debugSource.
|
|
10
|
-
*
|
|
11
|
-
* @param options - Plugin configuration options
|
|
12
|
-
* @param options.tailwindConfigPath - Path to tailwind.config.js (default: "./tailwind.config.js")
|
|
13
|
-
* @param options.outputPath - Path to output tailwind.config.json (default: "./src/design-mode/tailwind.config.json")
|
|
14
|
-
*/
|
|
15
|
-
declare function firebuzzDesignMode(options?: {
|
|
16
|
-
tailwindConfigPath?: string;
|
|
17
|
-
outputPath?: string;
|
|
18
|
-
}): Plugin;
|
|
19
|
-
|
|
20
3
|
/**
|
|
21
4
|
* TypeScript type definitions for Firebuzz Design Mode
|
|
22
5
|
*/
|
|
@@ -82,4 +65,14 @@ interface AllElementsStateMessage {
|
|
|
82
65
|
}
|
|
83
66
|
type DesignModeMessageType = DesignModeMessage | ElementSelectedMessage | AllElementsStateMessage;
|
|
84
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Vite plugin that enables design mode features for Firebuzz templates
|
|
70
|
+
* - Injects Tailwind Play CDN for runtime CSS generation
|
|
71
|
+
* - Injects overlay script for element selection
|
|
72
|
+
*
|
|
73
|
+
* NOTE: This plugin does NOT modify JSX/TSX files.
|
|
74
|
+
* Element tracking is done at runtime using React Fiber's _debugSource.
|
|
75
|
+
*/
|
|
76
|
+
declare function firebuzzDesignMode(): Plugin;
|
|
77
|
+
|
|
85
78
|
export { type AllElementsStateMessage, type DesignModeMessage, type DesignModeMessageType, type ElementData, type ElementSelectedMessage, type ElementUpdates, type SourceLocation, type ThemeVariables, firebuzzDesignMode };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var l=require('fs/promises'),r=require('path'),url=require('url');var _documentCurrentScript=typeof document!=='undefined'?document.currentScript:null;function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var l__default=/*#__PURE__*/_interopDefault(l);var r__default=/*#__PURE__*/_interopDefault(r);function d(){let n=process.env.NODE_ENV==="development"&&process.env.VITE_DESIGN_MODE!=="false",a=process.cwd(),t=r__default.default.resolve(a,"./node_modules/.vite-plugin-firebuzz-design-mode/overlay.js");return {name:"vite-plugin-firebuzz-design-mode",enforce:"pre",async buildStart(){if(n)try{let e=(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)),o=url.fileURLToPath(e),c=r__default.default.resolve(r__default.default.dirname(o),".."),s=r__default.default.join(c,"dist","overlay.mjs");await l__default.default.mkdir(r__default.default.dirname(t),{recursive:!0}),await l__default.default.copyFile(s,t);}catch(e){console.warn("[Firebuzz Design Mode] Could not copy overlay file:",e);}},transformIndexHtml(e){if(!n)return e;let o='<script src="https://cdn.tailwindcss.com"></script>',s=`<script type="module" src="${t.replace(a,"")}"></script>`,i=e.replace("</head>",`${o}</head>`);return i=i.replace("</body>",`${s}</body>`),i}}}
|
|
2
|
+
exports.firebuzzDesignMode=d;//# sourceMappingURL=index.js.map
|
|
2
3
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/vite-plugin.ts"],"names":["firebuzzDesignMode","
|
|
1
|
+
{"version":3,"sources":["../src/vite-plugin.ts"],"names":["firebuzzDesignMode","isDesignModeEnabled","projectRoot","overlayOutputPath","path","currentFileUrl","currentFilePath","fileURLToPath","packageRoot","overlaySource","fs","error","html","tailwindCDN","overlayScript","modifiedHtml"],"mappings":"mUAaO,SAASA,CAAAA,EAA6B,CAE5C,IAAMC,CAAAA,CACL,OAAA,CAAQ,GAAA,CAAI,QAAA,GAAa,aAAA,EACzB,OAAA,CAAQ,GAAA,CAAI,gBAAA,GAAqB,OAAA,CAE5BC,CAAAA,CAAc,OAAA,CAAQ,GAAA,EAAI,CAE1BC,CAAAA,CAAoBC,kBAAAA,CAAK,OAAA,CAC9BF,EACA,6DACD,CAAA,CAEA,OAAO,CACN,IAAA,CAAM,kCAAA,CACN,OAAA,CAAS,KAAA,CAET,MAAM,UAAA,EAAa,CAClB,GAAKD,CAAAA,CAGL,GAAI,CAEH,IAAMI,EAAiB,0PAAY,CAC7BC,CAAAA,CAAkBC,iBAAAA,CAAcF,CAAc,CAAA,CAC9CG,CAAAA,CAAcJ,kBAAAA,CAAK,QAAQA,kBAAAA,CAAK,OAAA,CAAQE,CAAe,CAAA,CAAG,IAAI,CAAA,CAC9DG,CAAAA,CAAgBL,kBAAAA,CAAK,KAAKI,CAAAA,CAAa,MAAA,CAAQ,aAAa,CAAA,CAGlE,MAAME,kBAAAA,CAAG,KAAA,CAAMN,kBAAAA,CAAK,OAAA,CAAQD,CAAiB,CAAA,CAAG,CAAE,SAAA,CAAW,CAAA,CAAK,CAAC,CAAA,CAGnE,MAAMO,kBAAAA,CAAG,QAAA,CAASD,CAAAA,CAAeN,CAAiB,EACnD,CAAA,MAASQ,CAAAA,CAAO,CACf,QAAQ,IAAA,CACP,qDAAA,CACAA,CACD,EACD,CACD,CAAA,CAEA,kBAAA,CAAmBC,CAAAA,CAAM,CACxB,GAAI,CAACX,CAAAA,CAAqB,OAAOW,CAAAA,CAGjC,IAAMC,CAAAA,CACL,qDAAA,CAIKC,CAAAA,CAAgB,CAAA,2BAAA,EADFX,CAAAA,CAAkB,OAAA,CAAQD,CAAAA,CAAa,EAAE,CACE,CAAA,WAAA,CAAA,CAG3Da,EAAeH,CAAAA,CAAK,OAAA,CAAQ,SAAA,CAAW,CAAA,EAAGC,CAAW,CAAA,OAAA,CAAS,CAAA,CAClE,OAAAE,EAAeA,CAAAA,CAAa,OAAA,CAAQ,SAAA,CAAW,CAAA,EAAGD,CAAa,CAAA,OAAA,CAAS,CAAA,CAEjEC,CACR,CACD,CACD","file":"index.js","sourcesContent":["import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport type { Plugin } from \"vite\";\n\n/**\n * Vite plugin that enables design mode features for Firebuzz templates\n * - Injects Tailwind Play CDN for runtime CSS generation\n * - Injects overlay script for element selection\n *\n * NOTE: This plugin does NOT modify JSX/TSX files.\n * Element tracking is done at runtime using React Fiber's _debugSource.\n */\nexport function firebuzzDesignMode(): Plugin {\n\t// Only enable in development, never in production builds\n\tconst isDesignModeEnabled =\n\t\tprocess.env.NODE_ENV === \"development\" &&\n\t\tprocess.env.VITE_DESIGN_MODE !== \"false\";\n\n\tconst projectRoot = process.cwd();\n\n\tconst overlayOutputPath = path.resolve(\n\t\tprojectRoot,\n\t\t\"./node_modules/.vite-plugin-firebuzz-design-mode/overlay.js\",\n\t);\n\n\treturn {\n\t\tname: \"vite-plugin-firebuzz-design-mode\",\n\t\tenforce: \"pre\",\n\n\t\tasync buildStart() {\n\t\t\tif (!isDesignModeEnabled) return;\n\n\t\t\t// Copy overlay file to a location Vite can serve\n\t\t\ttry {\n\t\t\t\t// Find the overlay source file from the package using import.meta.url\n\t\t\t\tconst currentFileUrl = import.meta.url;\n\t\t\t\tconst currentFilePath = fileURLToPath(currentFileUrl);\n\t\t\t\tconst packageRoot = path.resolve(path.dirname(currentFilePath), \"..\");\n\t\t\t\tconst overlaySource = path.join(packageRoot, \"dist\", \"overlay.mjs\");\n\n\t\t\t\t// Ensure output directory exists\n\t\t\t\tawait fs.mkdir(path.dirname(overlayOutputPath), { recursive: true });\n\n\t\t\t\t// Copy the overlay file\n\t\t\t\tawait fs.copyFile(overlaySource, overlayOutputPath);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t\"[Firebuzz Design Mode] Could not copy overlay file:\",\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\n\t\ttransformIndexHtml(html) {\n\t\t\tif (!isDesignModeEnabled) return html;\n\n\t\t\t// Inject Tailwind Play CDN for runtime CSS generation\n\t\t\tconst tailwindCDN =\n\t\t\t\t'<script src=\"https://cdn.tailwindcss.com\"></script>';\n\n\t\t\t// Inject the overlay script\n\t\t\tconst overlayPath = overlayOutputPath.replace(projectRoot, \"\");\n\t\t\tconst overlayScript = `<script type=\"module\" src=\"${overlayPath}\"></script>`;\n\n\t\t\t// Inject both in the head (Tailwind CDN) and before </body> (overlay)\n\t\t\tlet modifiedHtml = html.replace(\"</head>\", `${tailwindCDN}</head>`);\n\t\t\tmodifiedHtml = modifiedHtml.replace(\"</body>\", `${overlayScript}</body>`);\n\n\t\t\treturn modifiedHtml;\n\t\t},\n\t};\n}\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import l from'fs/promises';import r from'path';import {fileURLToPath}from'url';function d(){let n=process.env.NODE_ENV==="development"&&process.env.VITE_DESIGN_MODE!=="false",a=process.cwd(),t=r.resolve(a,"./node_modules/.vite-plugin-firebuzz-design-mode/overlay.js");return {name:"vite-plugin-firebuzz-design-mode",enforce:"pre",async buildStart(){if(n)try{let e=import.meta.url,o=fileURLToPath(e),c=r.resolve(r.dirname(o),".."),s=r.join(c,"dist","overlay.mjs");await l.mkdir(r.dirname(t),{recursive:!0}),await l.copyFile(s,t);}catch(e){console.warn("[Firebuzz Design Mode] Could not copy overlay file:",e);}},transformIndexHtml(e){if(!n)return e;let o='<script src="https://cdn.tailwindcss.com"></script>',s=`<script type="module" src="${t.replace(a,"")}"></script>`,i=e.replace("</head>",`${o}</head>`);return i=i.replace("</body>",`${s}</body>`),i}}}
|
|
2
|
+
export{d as firebuzzDesignMode};//# sourceMappingURL=index.mjs.map
|
|
2
3
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/vite-plugin.ts"],"names":["firebuzzDesignMode","
|
|
1
|
+
{"version":3,"sources":["../src/vite-plugin.ts"],"names":["firebuzzDesignMode","isDesignModeEnabled","projectRoot","overlayOutputPath","path","currentFileUrl","currentFilePath","fileURLToPath","packageRoot","overlaySource","fs","error","html","tailwindCDN","overlayScript","modifiedHtml"],"mappings":"+EAaO,SAASA,CAAAA,EAA6B,CAE5C,IAAMC,CAAAA,CACL,OAAA,CAAQ,GAAA,CAAI,QAAA,GAAa,aAAA,EACzB,OAAA,CAAQ,GAAA,CAAI,gBAAA,GAAqB,OAAA,CAE5BC,CAAAA,CAAc,OAAA,CAAQ,GAAA,EAAI,CAE1BC,CAAAA,CAAoBC,CAAAA,CAAK,OAAA,CAC9BF,EACA,6DACD,CAAA,CAEA,OAAO,CACN,IAAA,CAAM,kCAAA,CACN,OAAA,CAAS,KAAA,CAET,MAAM,UAAA,EAAa,CAClB,GAAKD,CAAAA,CAGL,GAAI,CAEH,IAAMI,EAAiB,MAAA,CAAA,IAAA,CAAY,GAAA,CAC7BC,CAAAA,CAAkBC,aAAAA,CAAcF,CAAc,CAAA,CAC9CG,CAAAA,CAAcJ,CAAAA,CAAK,QAAQA,CAAAA,CAAK,OAAA,CAAQE,CAAe,CAAA,CAAG,IAAI,CAAA,CAC9DG,CAAAA,CAAgBL,CAAAA,CAAK,KAAKI,CAAAA,CAAa,MAAA,CAAQ,aAAa,CAAA,CAGlE,MAAME,CAAAA,CAAG,KAAA,CAAMN,CAAAA,CAAK,OAAA,CAAQD,CAAiB,CAAA,CAAG,CAAE,SAAA,CAAW,CAAA,CAAK,CAAC,CAAA,CAGnE,MAAMO,CAAAA,CAAG,QAAA,CAASD,CAAAA,CAAeN,CAAiB,EACnD,CAAA,MAASQ,CAAAA,CAAO,CACf,QAAQ,IAAA,CACP,qDAAA,CACAA,CACD,EACD,CACD,CAAA,CAEA,kBAAA,CAAmBC,CAAAA,CAAM,CACxB,GAAI,CAACX,CAAAA,CAAqB,OAAOW,CAAAA,CAGjC,IAAMC,CAAAA,CACL,qDAAA,CAIKC,CAAAA,CAAgB,CAAA,2BAAA,EADFX,CAAAA,CAAkB,OAAA,CAAQD,CAAAA,CAAa,EAAE,CACE,CAAA,WAAA,CAAA,CAG3Da,EAAeH,CAAAA,CAAK,OAAA,CAAQ,SAAA,CAAW,CAAA,EAAGC,CAAW,CAAA,OAAA,CAAS,CAAA,CAClE,OAAAE,EAAeA,CAAAA,CAAa,OAAA,CAAQ,SAAA,CAAW,CAAA,EAAGD,CAAa,CAAA,OAAA,CAAS,CAAA,CAEjEC,CACR,CACD,CACD","file":"index.mjs","sourcesContent":["import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport type { Plugin } from \"vite\";\n\n/**\n * Vite plugin that enables design mode features for Firebuzz templates\n * - Injects Tailwind Play CDN for runtime CSS generation\n * - Injects overlay script for element selection\n *\n * NOTE: This plugin does NOT modify JSX/TSX files.\n * Element tracking is done at runtime using React Fiber's _debugSource.\n */\nexport function firebuzzDesignMode(): Plugin {\n\t// Only enable in development, never in production builds\n\tconst isDesignModeEnabled =\n\t\tprocess.env.NODE_ENV === \"development\" &&\n\t\tprocess.env.VITE_DESIGN_MODE !== \"false\";\n\n\tconst projectRoot = process.cwd();\n\n\tconst overlayOutputPath = path.resolve(\n\t\tprojectRoot,\n\t\t\"./node_modules/.vite-plugin-firebuzz-design-mode/overlay.js\",\n\t);\n\n\treturn {\n\t\tname: \"vite-plugin-firebuzz-design-mode\",\n\t\tenforce: \"pre\",\n\n\t\tasync buildStart() {\n\t\t\tif (!isDesignModeEnabled) return;\n\n\t\t\t// Copy overlay file to a location Vite can serve\n\t\t\ttry {\n\t\t\t\t// Find the overlay source file from the package using import.meta.url\n\t\t\t\tconst currentFileUrl = import.meta.url;\n\t\t\t\tconst currentFilePath = fileURLToPath(currentFileUrl);\n\t\t\t\tconst packageRoot = path.resolve(path.dirname(currentFilePath), \"..\");\n\t\t\t\tconst overlaySource = path.join(packageRoot, \"dist\", \"overlay.mjs\");\n\n\t\t\t\t// Ensure output directory exists\n\t\t\t\tawait fs.mkdir(path.dirname(overlayOutputPath), { recursive: true });\n\n\t\t\t\t// Copy the overlay file\n\t\t\t\tawait fs.copyFile(overlaySource, overlayOutputPath);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t\"[Firebuzz Design Mode] Could not copy overlay file:\",\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\n\t\ttransformIndexHtml(html) {\n\t\t\tif (!isDesignModeEnabled) return html;\n\n\t\t\t// Inject Tailwind Play CDN for runtime CSS generation\n\t\t\tconst tailwindCDN =\n\t\t\t\t'<script src=\"https://cdn.tailwindcss.com\"></script>';\n\n\t\t\t// Inject the overlay script\n\t\t\tconst overlayPath = overlayOutputPath.replace(projectRoot, \"\");\n\t\t\tconst overlayScript = `<script type=\"module\" src=\"${overlayPath}\"></script>`;\n\n\t\t\t// Inject both in the head (Tailwind CDN) and before </body> (overlay)\n\t\t\tlet modifiedHtml = html.replace(\"</head>\", `${tailwindCDN}</head>`);\n\t\t\tmodifiedHtml = modifiedHtml.replace(\"</body>\", `${overlayScript}</body>`);\n\n\t\t\treturn modifiedHtml;\n\t\t},\n\t};\n}\n"]}
|