@bamboocss/plugin-svelte
Advanced tools
| Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); | ||
| //#region \0rolldown/runtime.js | ||
| var __create = Object.create; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __getProtoOf = Object.getPrototypeOf; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) { | ||
| key = keys[i]; | ||
| if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { | ||
| get: ((k) => from[k]).bind(null, key), | ||
| enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable | ||
| }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { | ||
| value: mod, | ||
| enumerable: true | ||
| }) : target, mod)); | ||
| //#endregion | ||
| let magic_string = require("magic-string"); | ||
| magic_string = __toESM(magic_string); | ||
| //#region src/svelte-to-tsx.ts | ||
| /** @see https://github.com/sveltejs/svelte/blob/d3297e2a2595db08c85356d65fd5f953b04a681f/packages/svelte/src/compiler/preprocess/index.js#L255C1-L255C85 */ | ||
| const regex_style_tags = /<!--[^]*?-->|<style(\s[^]*?)?(?:>([^]*?)<\/style>|\/>)/gi; | ||
| /** @see https://github.com/sveltejs/svelte/blob/d3297e2a2595db08c85356d65fd5f953b04a681f/packages/svelte/src/compiler/preprocess/index.js#L256C1-L256C88 */ | ||
| const regex_script_tags = /<!--[^]*?-->|<script(\s[^]*?)?(?:>([^]*?)<\/script>|\/>)/gi; | ||
| const svelteToTsx = (code) => { | ||
| try { | ||
| const scripts = []; | ||
| const original = new magic_string.default(code); | ||
| let match; | ||
| while ((match = regex_script_tags.exec(code)) != null) { | ||
| const [fullMatch, _attributesStr, scriptContent] = match; | ||
| if (scriptContent) { | ||
| scripts.push(scriptContent); | ||
| original.remove(match.index, match.index + fullMatch.length); | ||
| } | ||
| } | ||
| const templateContent = original.toString().trimStart().replace(regex_style_tags, "").replace(regex_style_tags, ""); | ||
| return `${scripts.join("")}\nconst render = <div>${templateContent}</div>`.toString().trim(); | ||
| } catch { | ||
| return ""; | ||
| } | ||
| }; | ||
| //#endregion | ||
| //#region src/index.ts | ||
| function pluginSvelte() { | ||
| return { | ||
| name: "@bamboocss/plugin-svelte", | ||
| hooks: { "parser:before": ({ filePath, content }) => { | ||
| if (filePath.endsWith(".svelte")) return svelteToTsx(content); | ||
| } } | ||
| }; | ||
| } | ||
| //#endregion | ||
| exports.pluginSvelte = pluginSvelte; | ||
| exports.svelteToTsx = svelteToTsx; |
| import { BambooPlugin } from "@bamboocss/types"; | ||
| //#region src/svelte-to-tsx.d.ts | ||
| declare const svelteToTsx: (code: string) => string; | ||
| //#endregion | ||
| //#region src/index.d.ts | ||
| declare function pluginSvelte(): BambooPlugin; | ||
| //#endregion | ||
| export { pluginSvelte, svelteToTsx }; |
| import { BambooPlugin } from "@bamboocss/types"; | ||
| //#region src/svelte-to-tsx.d.ts | ||
| declare const svelteToTsx: (code: string) => string; | ||
| //#endregion | ||
| //#region src/index.d.ts | ||
| declare function pluginSvelte(): BambooPlugin; | ||
| //#endregion | ||
| export { pluginSvelte, svelteToTsx }; |
+32
-38
@@ -1,42 +0,36 @@ | ||
| // src/svelte-to-tsx.ts | ||
| import MagicString from "magic-string"; | ||
| var regex_style_tags = /<!--[^]*?-->|<style(\s[^]*?)?(?:>([^]*?)<\/style>|\/>)/gi; | ||
| var regex_script_tags = /<!--[^]*?-->|<script(\s[^]*?)?(?:>([^]*?)<\/script>|\/>)/gi; | ||
| var svelteToTsx = (code) => { | ||
| try { | ||
| const scripts = []; | ||
| const original = new MagicString(code); | ||
| let match; | ||
| while ((match = regex_script_tags.exec(code)) != null) { | ||
| const [fullMatch, _attributesStr, scriptContent] = match; | ||
| if (scriptContent) { | ||
| scripts.push(scriptContent); | ||
| original.remove(match.index, match.index + fullMatch.length); | ||
| } | ||
| } | ||
| const templateContent = original.toString().trimStart().replace(regex_style_tags, "").replace(regex_style_tags, ""); | ||
| const transformed = `${scripts.join("")} | ||
| const render = <div>${templateContent}</div>`; | ||
| return transformed.toString().trim(); | ||
| } catch { | ||
| return ""; | ||
| } | ||
| //#region src/svelte-to-tsx.ts | ||
| /** @see https://github.com/sveltejs/svelte/blob/d3297e2a2595db08c85356d65fd5f953b04a681f/packages/svelte/src/compiler/preprocess/index.js#L255C1-L255C85 */ | ||
| const regex_style_tags = /<!--[^]*?-->|<style(\s[^]*?)?(?:>([^]*?)<\/style>|\/>)/gi; | ||
| /** @see https://github.com/sveltejs/svelte/blob/d3297e2a2595db08c85356d65fd5f953b04a681f/packages/svelte/src/compiler/preprocess/index.js#L256C1-L256C88 */ | ||
| const regex_script_tags = /<!--[^]*?-->|<script(\s[^]*?)?(?:>([^]*?)<\/script>|\/>)/gi; | ||
| const svelteToTsx = (code) => { | ||
| try { | ||
| const scripts = []; | ||
| const original = new MagicString(code); | ||
| let match; | ||
| while ((match = regex_script_tags.exec(code)) != null) { | ||
| const [fullMatch, _attributesStr, scriptContent] = match; | ||
| if (scriptContent) { | ||
| scripts.push(scriptContent); | ||
| original.remove(match.index, match.index + fullMatch.length); | ||
| } | ||
| } | ||
| const templateContent = original.toString().trimStart().replace(regex_style_tags, "").replace(regex_style_tags, ""); | ||
| return `${scripts.join("")}\nconst render = <div>${templateContent}</div>`.toString().trim(); | ||
| } catch { | ||
| return ""; | ||
| } | ||
| }; | ||
| // src/index.ts | ||
| //#endregion | ||
| //#region src/index.ts | ||
| function pluginSvelte() { | ||
| return { | ||
| name: "@bamboocss/plugin-svelte", | ||
| hooks: { | ||
| "parser:before": ({ filePath, content }) => { | ||
| if (filePath.endsWith(".svelte")) { | ||
| return svelteToTsx(content); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| return { | ||
| name: "@bamboocss/plugin-svelte", | ||
| hooks: { "parser:before": ({ filePath, content }) => { | ||
| if (filePath.endsWith(".svelte")) return svelteToTsx(content); | ||
| } } | ||
| }; | ||
| } | ||
| export { | ||
| pluginSvelte, | ||
| svelteToTsx | ||
| }; | ||
| //#endregion | ||
| export { pluginSvelte, svelteToTsx }; |
+9
-9
| { | ||
| "name": "@bamboocss/plugin-svelte", | ||
| "version": "1.11.1", | ||
| "version": "1.11.2", | ||
| "description": "Bamboo CSS plugin for Svelte single file component support", | ||
@@ -10,3 +10,3 @@ "homepage": "https://bamboo-css.com", | ||
| "type": "git", | ||
| "url": "git+https://github.com/chakra-ui/bamboo.git", | ||
| "url": "git+https://github.com/bamboocss/bamboo.git", | ||
| "directory": "packages/plugin-svelte" | ||
@@ -18,10 +18,10 @@ }, | ||
| "sideEffects": false, | ||
| "main": "dist/index.js", | ||
| "main": "dist/index.cjs", | ||
| "module": "dist/index.mjs", | ||
| "types": "dist/index.d.ts", | ||
| "types": "dist/index.d.cts", | ||
| "exports": { | ||
| ".": { | ||
| "source": "./src/index.ts", | ||
| "types": "./dist/index.d.ts", | ||
| "require": "./dist/index.js", | ||
| "types": "./dist/index.d.cts", | ||
| "require": "./dist/index.cjs", | ||
| "import": { | ||
@@ -39,9 +39,9 @@ "types": "./dist/index.d.mts", | ||
| "magic-string": "0.30.21", | ||
| "@bamboocss/types": "1.11.1" | ||
| "@bamboocss/types": "1.11.2" | ||
| }, | ||
| "scripts": { | ||
| "build": "tsup src/index.ts --format=esm,cjs --dts", | ||
| "build-fast": "tsup src/index.ts --format=esm,cjs --no-dts", | ||
| "build": "tsdown src/index.ts --format=esm,cjs --dts", | ||
| "build-fast": "tsdown --dts=false src/index.ts --format=esm,cjs", | ||
| "dev": "pnpm build-fast --watch" | ||
| } | ||
| } |
| "use strict"; | ||
| var __create = Object.create; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __getProtoOf = Object.getPrototypeOf; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
| // If the importer is in node compatibility mode or this is not an ESM | ||
| // file that has been converted to a CommonJS file using a Babel- | ||
| // compatible transform (i.e. "__esModule" has not been set), then set | ||
| // "default" to the CommonJS "module.exports" for node compatibility. | ||
| isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
| mod | ||
| )); | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| // src/index.ts | ||
| var index_exports = {}; | ||
| __export(index_exports, { | ||
| pluginSvelte: () => pluginSvelte, | ||
| svelteToTsx: () => svelteToTsx | ||
| }); | ||
| module.exports = __toCommonJS(index_exports); | ||
| // src/svelte-to-tsx.ts | ||
| var import_magic_string = __toESM(require("magic-string")); | ||
| var regex_style_tags = /<!--[^]*?-->|<style(\s[^]*?)?(?:>([^]*?)<\/style>|\/>)/gi; | ||
| var regex_script_tags = /<!--[^]*?-->|<script(\s[^]*?)?(?:>([^]*?)<\/script>|\/>)/gi; | ||
| var svelteToTsx = (code) => { | ||
| try { | ||
| const scripts = []; | ||
| const original = new import_magic_string.default(code); | ||
| let match; | ||
| while ((match = regex_script_tags.exec(code)) != null) { | ||
| const [fullMatch, _attributesStr, scriptContent] = match; | ||
| if (scriptContent) { | ||
| scripts.push(scriptContent); | ||
| original.remove(match.index, match.index + fullMatch.length); | ||
| } | ||
| } | ||
| const templateContent = original.toString().trimStart().replace(regex_style_tags, "").replace(regex_style_tags, ""); | ||
| const transformed = `${scripts.join("")} | ||
| const render = <div>${templateContent}</div>`; | ||
| return transformed.toString().trim(); | ||
| } catch { | ||
| return ""; | ||
| } | ||
| }; | ||
| // src/index.ts | ||
| function pluginSvelte() { | ||
| return { | ||
| name: "@bamboocss/plugin-svelte", | ||
| hooks: { | ||
| "parser:before": ({ filePath, content }) => { | ||
| if (filePath.endsWith(".svelte")) { | ||
| return svelteToTsx(content); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| pluginSvelte, | ||
| svelteToTsx | ||
| }); |
6830
7.32%6
50%97
-17.8%+ Added
- Removed
Updated