unplugin-gem 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/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # unplugin-gem
2
+
3
+ Universal plugin for [Gem](https://github.com/mantou132/gem) element transformations.
4
+
5
+ Supports **Vite**, **Webpack**, **Rollup**, **esbuild**, **Rspack**, **Farm**, and **Rolldown** through a single unified API.
6
+
7
+ ## Features
8
+
9
+ - 🔄 **Auto Import** - Automatically import Gem APIs
10
+ - 🎨 **CSS Minification** - Minify CSS in `css`` template literals
11
+ - 🔍 **Selector Compatible** - Transform `&:hover` for Shadow DOM compatibility
12
+ - 📦 **Resource Preload** - Preload resources with `?preload` query
13
+ - 🔥 **HMR Support** - Hot module replacement (experimental)
14
+ - 🛠️ **Universal** - Works with all major bundlers
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install unplugin-gem
20
+ # or
21
+ pnpm add unplugin-gem
22
+ # or
23
+ yarn add unplugin-gem
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ ### Vite
29
+
30
+ ```ts
31
+ // vite.config.ts
32
+ import gemPlugin from 'unplugin-gem/vite'
33
+
34
+ export default {
35
+ plugins: [
36
+ gemPlugin({
37
+ autoImport: true,
38
+ selectorCompatible: true,
39
+ styleMinify: true,
40
+ }),
41
+ ],
42
+ }
43
+ ```
44
+
45
+ ### Webpack
46
+
47
+ ```js
48
+ // webpack.config.js
49
+ const gemPlugin = require('unplugin-gem/webpack')
50
+
51
+ module.exports = {
52
+ plugins: [
53
+ gemPlugin({
54
+ autoImport: true,
55
+ selectorCompatible: true,
56
+ }),
57
+ ],
58
+ }
59
+ ```
60
+
61
+ ### Rollup
62
+
63
+ ```js
64
+ // rollup.config.js
65
+ import gemPlugin from 'unplugin-gem/rollup'
66
+
67
+ export default {
68
+ plugins: [
69
+ gemPlugin({
70
+ autoImport: true,
71
+ selectorCompatible: true,
72
+ }),
73
+ ],
74
+ }
75
+ ```
76
+
77
+ ### esbuild
78
+
79
+ ```js
80
+ // esbuild.config.js
81
+ import { build } from 'esbuild'
82
+ import gemPlugin from 'unplugin-gem/esbuild'
83
+
84
+ build({
85
+ plugins: [
86
+ gemPlugin({
87
+ autoImport: true,
88
+ selectorCompatible: true,
89
+ }),
90
+ ],
91
+ })
92
+ ```
93
+
94
+ ## How It Works
95
+
96
+ This plugin wraps [swc-plugin-gem](https://github.com/mantou132/gem/tree/main/crates/swc-plugin-gem) and uses [unplugin](https://github.com/unjs/unplugin) to provide universal bundler support.
97
+
98
+ ## License
99
+
100
+ MIT
@@ -0,0 +1,3 @@
1
+ declare const _default: (options?: import("./types").UnpluginGemOptions | undefined) => import("esbuild").Plugin;
2
+ export default _default;
3
+ //# sourceMappingURL=esbuild.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"esbuild.d.ts","sourceRoot":"","sources":["../src/esbuild.ts"],"names":[],"mappings":";AAEA,wBAAmC"}
@@ -0,0 +1,3 @@
1
+ import { unpluginGem } from './index';
2
+ export default unpluginGem.esbuild;
3
+ //# sourceMappingURL=esbuild.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"esbuild.js","sourceRoot":"","sources":["../src/esbuild.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,eAAe,WAAW,CAAC,OAAO,CAAC"}
package/dist/farm.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare const _default: (options?: import("./types").UnpluginGemOptions | undefined) => JsPlugin;
2
+ export default _default;
3
+ //# sourceMappingURL=farm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"farm.d.ts","sourceRoot":"","sources":["../src/farm.ts"],"names":[],"mappings":";AAEA,wBAAgC"}
package/dist/farm.js ADDED
@@ -0,0 +1,3 @@
1
+ import { unpluginGem } from './index';
2
+ export default unpluginGem.farm;
3
+ //# sourceMappingURL=farm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"farm.js","sourceRoot":"","sources":["../src/farm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,eAAe,WAAW,CAAC,IAAI,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { UnpluginGemOptions } from './types';
2
+ export type { UnpluginGemOptions } from './types';
3
+ export declare const unpluginGem: import("unplugin").UnpluginInstance<UnpluginGemOptions | undefined, boolean>;
4
+ export default unpluginGem;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAIlD,eAAO,MAAM,WAAW,8EAsDtB,CAAC;AAEH,eAAe,WAAW,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,58 @@
1
+ import { transform } from '@swc/core';
2
+ import { createUnplugin } from 'unplugin';
3
+ const TRANSFORM_EXTENSIONS = /\.(tsx?|jsx?)$/;
4
+ export const unpluginGem = createUnplugin((options = {}) => {
5
+ return {
6
+ name: 'unplugin-gem',
7
+ transformInclude(id) {
8
+ return TRANSFORM_EXTENSIONS.test(id);
9
+ },
10
+ async transform(code, id) {
11
+ try {
12
+ const result = await transform(code, {
13
+ filename: id,
14
+ sourceMaps: true,
15
+ jsc: {
16
+ parser: {
17
+ syntax: id.endsWith('.tsx') || id.endsWith('.ts') ? 'typescript' : 'ecmascript',
18
+ tsx: id.endsWith('.tsx'),
19
+ jsx: id.endsWith('.jsx'),
20
+ decorators: true,
21
+ },
22
+ transform: {
23
+ decoratorVersion: '2022-03',
24
+ },
25
+ externalHelpers: true,
26
+ target: 'es2022',
27
+ experimental: {
28
+ runPluginFirst: true,
29
+ plugins: [
30
+ [
31
+ 'swc-plugin-gem',
32
+ {
33
+ styleMinify: options.styleMinify ?? false,
34
+ autoImport: options.autoImport ?? false,
35
+ autoImportDts: options.autoImportDts ?? false,
36
+ resolvePath: options.resolvePath ?? false,
37
+ preload: options.preload ?? false,
38
+ hmr: options.hmr ?? false,
39
+ selectorCompatible: options.selectorCompatible ?? false,
40
+ },
41
+ ],
42
+ ],
43
+ },
44
+ },
45
+ });
46
+ return {
47
+ code: result.code,
48
+ map: result.map,
49
+ };
50
+ }
51
+ catch (error) {
52
+ this.error(`Failed to transform ${id}: ${error}`);
53
+ }
54
+ },
55
+ };
56
+ });
57
+ export default unpluginGem;
58
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAM1C,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AAE9C,MAAM,CAAC,MAAM,WAAW,GAAG,cAAc,CAAiC,CAAC,OAAO,GAAG,EAAE,EAAE,EAAE;IACzF,OAAO;QACL,IAAI,EAAE,cAAc;QAEpB,gBAAgB,CAAC,EAAE;YACjB,OAAO,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACvC,CAAC;QAED,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE;YACtB,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE;oBACnC,QAAQ,EAAE,EAAE;oBACZ,UAAU,EAAE,IAAI;oBAChB,GAAG,EAAE;wBACH,MAAM,EAAE;4BACN,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY;4BAC/E,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC;4BACxB,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC;4BACxB,UAAU,EAAE,IAAI;yBACjB;wBACD,SAAS,EAAE;4BACT,gBAAgB,EAAE,SAAS;yBAC5B;wBACD,eAAe,EAAE,IAAI;wBACrB,MAAM,EAAE,QAAQ;wBAChB,YAAY,EAAE;4BACZ,cAAc,EAAE,IAAI;4BACpB,OAAO,EAAE;gCACP;oCACE,gBAAgB;oCAChB;wCACE,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,KAAK;wCACzC,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,KAAK;wCACvC,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,KAAK;wCAC7C,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,KAAK;wCACzC,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,KAAK;wCACjC,GAAG,EAAE,OAAO,CAAC,GAAG,IAAI,KAAK;wCACzB,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,IAAI,KAAK;qCACxD;iCACF;6BACF;yBACF;qBACF;iBACF,CAAC,CAAC;gBAEH,OAAO;oBACL,IAAI,EAAE,MAAM,CAAC,IAAI;oBACjB,GAAG,EAAE,MAAM,CAAC,GAAG;iBAChB,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,KAAK,CAAC,uBAAuB,EAAE,KAAK,KAAK,EAAE,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const _default: (options?: import("./types").UnpluginGemOptions | undefined) => any;
2
+ export default _default;
3
+ //# sourceMappingURL=rolldown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rolldown.d.ts","sourceRoot":"","sources":["../src/rolldown.ts"],"names":[],"mappings":";AAEA,wBAAoC"}
@@ -0,0 +1,3 @@
1
+ import { unpluginGem } from './index';
2
+ export default unpluginGem.rolldown;
3
+ //# sourceMappingURL=rolldown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rolldown.js","sourceRoot":"","sources":["../src/rolldown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,eAAe,WAAW,CAAC,QAAQ,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const _default: (options?: import("./types").UnpluginGemOptions | undefined) => import("rollup").Plugin<any> | import("rollup").Plugin<any>[];
2
+ export default _default;
3
+ //# sourceMappingURL=rollup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollup.d.ts","sourceRoot":"","sources":["../src/rollup.ts"],"names":[],"mappings":";AAEA,wBAAkC"}
package/dist/rollup.js ADDED
@@ -0,0 +1,3 @@
1
+ import { unpluginGem } from './index';
2
+ export default unpluginGem.rollup;
3
+ //# sourceMappingURL=rollup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollup.js","sourceRoot":"","sources":["../src/rollup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,eAAe,WAAW,CAAC,MAAM,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const _default: (options?: import("./types").UnpluginGemOptions | undefined) => import("unplugin").RspackPluginInstance;
2
+ export default _default;
3
+ //# sourceMappingURL=rspack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rspack.d.ts","sourceRoot":"","sources":["../src/rspack.ts"],"names":[],"mappings":";AAEA,wBAAkC"}
package/dist/rspack.js ADDED
@@ -0,0 +1,3 @@
1
+ import { unpluginGem } from './index';
2
+ export default unpluginGem.rspack;
3
+ //# sourceMappingURL=rspack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rspack.js","sourceRoot":"","sources":["../src/rspack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,eAAe,WAAW,CAAC,MAAM,CAAC"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Auto import configuration
3
+ */
4
+ export type AutoImportConfig = boolean | {
5
+ extends?: 'gem';
6
+ members?: Record<string, string[]>;
7
+ };
8
+ /**
9
+ * Auto import .d.ts generation
10
+ */
11
+ export type AutoImportDts = boolean | string;
12
+ /**
13
+ * Plugin options matching swc-plugin-gem configuration
14
+ */
15
+ export interface UnpluginGemOptions {
16
+ /**
17
+ * Minify CSS in css`` template literals
18
+ * @default false
19
+ */
20
+ styleMinify?: boolean;
21
+ /**
22
+ * Auto import Gem APIs
23
+ * @default false
24
+ * @example
25
+ * ```ts
26
+ * {
27
+ * autoImport: {
28
+ * extends: 'gem',
29
+ * members: {
30
+ * 'my-package': ['myFunction']
31
+ * }
32
+ * }
33
+ * }
34
+ * ```
35
+ */
36
+ autoImport?: AutoImportConfig;
37
+ /**
38
+ * Generate .d.ts file for auto imports
39
+ * @default false
40
+ * @example
41
+ * ```ts
42
+ * // true -> src/auto-import.d.ts
43
+ * // string -> custom path
44
+ * autoImportDts: 'src/types/auto-import.d.ts'
45
+ * ```
46
+ */
47
+ autoImportDts?: AutoImportDts;
48
+ /**
49
+ * Resolve import paths to full ESM paths
50
+ * @default false
51
+ */
52
+ resolvePath?: boolean;
53
+ /**
54
+ * Enable resource preloading with ?preload query
55
+ * @default false
56
+ */
57
+ preload?: boolean;
58
+ /**
59
+ * Enable HMR support (experimental)
60
+ * @default false
61
+ */
62
+ hmr?: boolean;
63
+ /**
64
+ * Support `&:hover` in shadow DOM and light DOM
65
+ * Transform to `:is(&:hover,:host(:hover))`
66
+ * @default false
67
+ */
68
+ selectorCompatible?: boolean;
69
+ }
70
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACxB,OAAO,GACP;IACE,OAAO,CAAC,EAAE,KAAK,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CACpC,CAAC;AAEN;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,MAAM,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;;;;;;;;;;;;OAcG;IACH,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAE9B;;;;;;;;;OASG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;IAE9B;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;IAEd;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/dist/vite.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare const _default: (options?: import("./types").UnpluginGemOptions | undefined) => import("vite").Plugin<any> | import("vite").Plugin<any>[];
2
+ export default _default;
3
+ //# sourceMappingURL=vite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":";AAEA,wBAAgC"}
package/dist/vite.js ADDED
@@ -0,0 +1,3 @@
1
+ import { unpluginGem } from './index';
2
+ export default unpluginGem.vite;
3
+ //# sourceMappingURL=vite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.js","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,eAAe,WAAW,CAAC,IAAI,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const _default: (options?: import("./types").UnpluginGemOptions | undefined) => import("webpack").WebpackPluginInstance;
2
+ export default _default;
3
+ //# sourceMappingURL=webpack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack.d.ts","sourceRoot":"","sources":["../src/webpack.ts"],"names":[],"mappings":";AAEA,wBAAmC"}
@@ -0,0 +1,3 @@
1
+ import { unpluginGem } from './index';
2
+ export default unpluginGem.webpack;
3
+ //# sourceMappingURL=webpack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack.js","sourceRoot":"","sources":["../src/webpack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,eAAe,WAAW,CAAC,OAAO,CAAC"}
package/package.json ADDED
@@ -0,0 +1,114 @@
1
+ {
2
+ "name": "unplugin-gem",
3
+ "version": "0.1.0",
4
+ "description": "Universal plugin for Gem element transformations (Vite/Webpack/Rollup/esbuild)",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./vite": {
15
+ "types": "./dist/vite.d.ts",
16
+ "import": "./dist/vite.js"
17
+ },
18
+ "./webpack": {
19
+ "types": "./dist/webpack.d.ts",
20
+ "import": "./dist/webpack.js"
21
+ },
22
+ "./rollup": {
23
+ "types": "./dist/rollup.d.ts",
24
+ "import": "./dist/rollup.js"
25
+ },
26
+ "./esbuild": {
27
+ "types": "./dist/esbuild.d.ts",
28
+ "import": "./dist/esbuild.js"
29
+ },
30
+ "./rspack": {
31
+ "types": "./dist/rspack.d.ts",
32
+ "import": "./dist/rspack.js"
33
+ },
34
+ "./farm": {
35
+ "types": "./dist/farm.d.ts",
36
+ "import": "./dist/farm.js"
37
+ },
38
+ "./rolldown": {
39
+ "types": "./dist/rolldown.d.ts",
40
+ "import": "./dist/rolldown.js"
41
+ }
42
+ },
43
+ "files": [
44
+ "dist"
45
+ ],
46
+ "scripts": {
47
+ "build": "tsc",
48
+ "start": "pnpm build --watch",
49
+ "prepublishOnly": "pnpm build"
50
+ },
51
+ "keywords": [
52
+ "unplugin",
53
+ "vite",
54
+ "webpack",
55
+ "rollup",
56
+ "esbuild",
57
+ "gem",
58
+ "web-components",
59
+ "swc"
60
+ ],
61
+ "author": "mantou132",
62
+ "license": "MIT",
63
+ "repository": {
64
+ "type": "git",
65
+ "url": "git+https://github.com/mantou132/gem.git",
66
+ "directory": "packages/unplugin-gem"
67
+ },
68
+ "bugs": {
69
+ "url": "https://github.com/mantou132/gem/issues"
70
+ },
71
+ "homepage": "https://github.com/mantou132/gem#readme",
72
+ "dependencies": {
73
+ "@swc/core": "^1.9.3",
74
+ "@swc/helpers": "^0.5.21",
75
+ "unplugin": "^3.0.0"
76
+ },
77
+ "devDependencies": {
78
+ "@gemjs/config": "^2.1.2",
79
+ "@types/node": "^22.13.10",
80
+ "typescript": "^5.6.2"
81
+ },
82
+ "peerDependencies": {
83
+ "esbuild": ">=0.20.0",
84
+ "rollup": ">=3.0.0",
85
+ "vite": ">=4.0.0",
86
+ "webpack": ">=5.0.0",
87
+ "@rspack/core": ">=0.0.0",
88
+ "@farmfe/core": ">=0.0.0",
89
+ "rolldown": ">=0.0.0"
90
+ },
91
+ "peerDependenciesMeta": {
92
+ "esbuild": {
93
+ "optional": true
94
+ },
95
+ "rollup": {
96
+ "optional": true
97
+ },
98
+ "vite": {
99
+ "optional": true
100
+ },
101
+ "webpack": {
102
+ "optional": true
103
+ },
104
+ "@rspack/core": {
105
+ "optional": true
106
+ },
107
+ "@farmfe/core": {
108
+ "optional": true
109
+ },
110
+ "rolldown": {
111
+ "optional": true
112
+ }
113
+ }
114
+ }