@studiocms/ui 0.3.2 → 0.4.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/dist/components/Accordion/Accordion.astro +23 -0
- package/dist/components/Accordion/Item.astro +21 -0
- package/dist/components/Accordion/accordion.css +64 -0
- package/dist/components/Accordion/accordion.d.ts +1 -0
- package/dist/components/Accordion/accordion.js +70 -0
- package/dist/components/Badge/Badge.astro +49 -0
- package/dist/components/Badge/badge.css +111 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.astro +31 -0
- package/dist/components/Breadcrumbs/breadcrumbs.css +15 -0
- package/dist/components/Button/Button.astro +75 -0
- package/dist/components/Button/button.css +292 -0
- package/{src/components → dist/components/Card}/Card.astro +1 -48
- package/dist/components/Card/card.css +38 -0
- package/dist/components/Center/Center.astro +7 -0
- package/dist/components/Center/center.css +8 -0
- package/dist/components/Checkbox/Checkbox.astro +95 -0
- package/dist/components/Checkbox/checkbox.css +119 -0
- package/dist/components/Checkbox/checkbox.d.ts +2 -0
- package/dist/components/Checkbox/checkbox.js +20 -0
- package/{src/components → dist/components/Divider}/Divider.astro +2 -25
- package/dist/components/Divider/divider.css +21 -0
- package/dist/components/Dropdown/Dropdown.astro +116 -0
- package/dist/components/Dropdown/dropdown.css +180 -0
- package/dist/components/Dropdown/dropdown.d.ts +48 -0
- package/dist/components/Dropdown/dropdown.js +201 -0
- package/dist/components/Footer/Footer.astro +58 -0
- package/dist/components/Footer/footer.css +68 -0
- package/dist/components/Group/Group.astro +7 -0
- package/dist/components/Group/group.css +19 -0
- package/{src/utils → dist/components/Icon}/Icon.astro +1 -1
- package/{src/utils/iconType.ts → dist/components/Icon/iconType.d.ts} +0 -1
- package/dist/components/Icon/iconType.js +0 -0
- package/{src/components → dist/components/Input}/Input.astro +2 -48
- package/dist/components/Input/input.css +38 -0
- package/{src → dist}/components/Modal/Modal.astro +4 -122
- package/dist/components/Modal/modal.css +100 -0
- package/dist/components/Modal/modal.d.ts +48 -0
- package/dist/components/Modal/modal.js +129 -0
- package/dist/components/Progress/Progress.astro +21 -0
- package/dist/components/Progress/helper.d.ts +13 -0
- package/dist/components/Progress/helper.js +32 -0
- package/dist/components/Progress/progress.css +29 -0
- package/dist/components/Progress/progress.d.ts +1 -0
- package/dist/components/Progress/progress.js +10 -0
- package/dist/components/RadioGroup/RadioGroup.astro +124 -0
- package/dist/components/RadioGroup/radiogroup.css +96 -0
- package/dist/components/RadioGroup/radiogroup.d.ts +1 -0
- package/dist/components/RadioGroup/radiogroup.js +48 -0
- package/{src/components → dist/components/Row}/Row.astro +1 -24
- package/dist/components/Row/row.css +18 -0
- package/dist/components/SearchSelect/SearchSelect.astro +135 -0
- package/dist/components/SearchSelect/searchselect.css +95 -0
- package/dist/components/SearchSelect/searchselect.d.ts +6 -0
- package/dist/components/SearchSelect/searchselect.js +166 -0
- package/dist/components/Select/Select.astro +147 -0
- package/dist/components/Select/select.css +110 -0
- package/dist/components/Select/select.d.ts +1 -0
- package/dist/components/Select/select.js +143 -0
- package/dist/components/Sidebar/helpers.d.ts +76 -0
- package/dist/components/Sidebar/helpers.js +160 -0
- package/{src → dist}/components/Tabs/TabItem.astro +3 -3
- package/dist/components/Tabs/Tabs.astro +150 -0
- package/dist/components/Tabs/tabs.css +121 -0
- package/dist/components/Tabs/tabs.d.ts +1 -0
- package/dist/components/Tabs/tabs.js +82 -0
- package/{src/components → dist/components/Textarea}/Textarea.astro +2 -61
- package/dist/components/Textarea/textarea.css +49 -0
- package/dist/components/ThemeToggle/ThemeToggle.astro +21 -0
- package/dist/components/ThemeToggle/themetoggle.css +17 -0
- package/dist/components/ThemeToggle/themetoggle.d.ts +1 -0
- package/dist/components/ThemeToggle/themetoggle.js +4 -0
- package/dist/components/Toast/Toaster.astro +69 -0
- package/dist/components/Toast/toast.d.ts +8 -0
- package/dist/components/Toast/toast.js +9 -0
- package/dist/components/Toast/toaster.css +168 -0
- package/dist/components/Toast/toaster.d.ts +1 -0
- package/dist/components/Toast/toaster.js +160 -0
- package/dist/components/Toggle/Toggle.astro +84 -0
- package/dist/components/Toggle/toggle.css +93 -0
- package/dist/components/Toggle/toggle.d.ts +2 -0
- package/dist/components/Toggle/toggle.js +20 -0
- package/{src/components → dist/components/User}/User.astro +3 -43
- package/dist/components/User/user.css +35 -0
- package/dist/css/colors.css +95 -0
- package/dist/css/global.css +3 -0
- package/dist/css/radii.css +6 -0
- package/dist/css/resets.css +46 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +379 -0
- package/dist/toolbar/ColorPicker.d.ts +7 -0
- package/dist/toolbar/ColorPicker.js +85 -0
- package/dist/toolbar/icon.d.ts +1 -0
- package/dist/toolbar/icon.js +4 -0
- package/dist/toolbar/index.d.ts +2 -0
- package/dist/toolbar/index.js +292 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.js +0 -0
- package/dist/utils/ThemeHelper.d.ts +49 -0
- package/dist/utils/ThemeHelper.js +113 -0
- package/{src/utils/colors.ts → dist/utils/colors.d.ts} +1 -1
- package/dist/utils/colors.js +0 -0
- package/dist/utils/generateID.d.ts +2 -0
- package/dist/utils/generateID.js +6 -0
- package/dist/utils/headers.d.ts +43 -0
- package/dist/utils/headers.js +129 -0
- package/dist/utils/iconStrings.d.ts +4 -0
- package/dist/utils/iconStrings.js +13 -0
- package/dist/utils/integration-utils.d.ts +130 -0
- package/dist/utils/integration-utils.js +161 -0
- package/package.json +25 -9
- package/src/components/BaseHead.astro +0 -22
- package/src/components/Button.astro +0 -372
- package/src/components/Center.astro +0 -16
- package/src/components/Checkbox.astro +0 -250
- package/src/components/Dropdown/Dropdown.astro +0 -314
- package/src/components/Dropdown/dropdown.ts +0 -258
- package/src/components/Dropdown/index.ts +0 -2
- package/src/components/Footer.astro +0 -137
- package/src/components/Modal/index.ts +0 -2
- package/src/components/Modal/modal.ts +0 -163
- package/src/components/RadioGroup.astro +0 -299
- package/src/components/SearchSelect.astro +0 -486
- package/src/components/Select.astro +0 -467
- package/src/components/Sidebar/helpers.ts +0 -179
- package/src/components/Sidebar/index.ts +0 -3
- package/src/components/Tabs/Tabs.astro +0 -393
- package/src/components/Tabs/index.ts +0 -2
- package/src/components/ThemeToggle.astro +0 -46
- package/src/components/Toast/Toaster.astro +0 -470
- package/src/components/Toast/index.ts +0 -2
- package/src/components/Toast/toast.ts +0 -16
- package/src/components/Toggle.astro +0 -214
- package/src/components/index.ts +0 -27
- package/src/components.ts +0 -26
- package/src/css/colors.css +0 -106
- package/src/css/global.css +0 -2
- package/src/css/resets.css +0 -54
- package/src/env.d.ts +0 -15
- package/src/integration.ts +0 -31
- package/src/layouts/RootLayout.astro +0 -33
- package/src/layouts/index.ts +0 -2
- package/src/layouts.ts +0 -1
- package/src/types/index.ts +0 -11
- package/src/utils/ThemeHelper.ts +0 -145
- package/src/utils/create-resolver.ts +0 -30
- package/src/utils/generateID.ts +0 -5
- package/src/utils/headers.ts +0 -190
- package/src/utils/iconStrings.ts +0 -29
- package/src/utils/index.ts +0 -1
- package/src/utils/virtual-module-plugin-builder.ts +0 -37
- /package/{src → dist}/components/Sidebar/Double.astro +0 -0
- /package/{src → dist}/components/Sidebar/Single.astro +0 -0
- /package/{src → dist}/icons/Checkmark.astro +0 -0
- /package/{src → dist}/icons/ChevronUpDown.astro +0 -0
- /package/{src → dist}/icons/User.astro +0 -0
- /package/{src → dist}/icons/X-Mark.astro +0 -0
package/src/utils/headers.ts
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import type { AstroGlobalPartial } from 'astro';
|
|
2
|
-
import { z } from 'astro/zod';
|
|
3
|
-
|
|
4
|
-
export const HeadConfigSchema = () =>
|
|
5
|
-
z
|
|
6
|
-
.array(
|
|
7
|
-
z.object({
|
|
8
|
-
/** Name of the HTML tag to add to `<head>`, e.g. `'meta'`, `'link'`, or `'script'`. */
|
|
9
|
-
tag: z.enum(['title', 'base', 'link', 'style', 'meta', 'script', 'noscript', 'template']),
|
|
10
|
-
/** Attributes to set on the tag, e.g. `{ rel: 'stylesheet', href: '/custom.css' }`. */
|
|
11
|
-
attrs: z.record(z.union([z.string(), z.boolean(), z.undefined()])).default({}),
|
|
12
|
-
/** Content to place inside the tag (optional). */
|
|
13
|
-
content: z.string().default(''),
|
|
14
|
-
})
|
|
15
|
-
)
|
|
16
|
-
.default([]);
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Default Head Tags for use with createHead() helper
|
|
20
|
-
*
|
|
21
|
-
* @param title
|
|
22
|
-
* @param description
|
|
23
|
-
* @param lang
|
|
24
|
-
* @param Astro
|
|
25
|
-
* @param favicon
|
|
26
|
-
* @param ogImage
|
|
27
|
-
* @param canonical
|
|
28
|
-
* @returns
|
|
29
|
-
*/
|
|
30
|
-
export const headDefaults = (
|
|
31
|
-
title: string,
|
|
32
|
-
description: string,
|
|
33
|
-
Astro: AstroGlobalPartial,
|
|
34
|
-
ogImage: string | undefined,
|
|
35
|
-
canonical: URL | undefined
|
|
36
|
-
) => {
|
|
37
|
-
const headDefaults: z.input<ReturnType<typeof HeadConfigSchema>> = [
|
|
38
|
-
{ tag: 'meta', attrs: { charset: 'utf-8' } },
|
|
39
|
-
{
|
|
40
|
-
tag: 'meta',
|
|
41
|
-
attrs: { name: 'viewport', content: 'width=device-width, initial-scale=1' },
|
|
42
|
-
},
|
|
43
|
-
{ tag: 'title', content: `${title}` },
|
|
44
|
-
{ tag: 'meta', attrs: { name: 'title', content: title } },
|
|
45
|
-
{ tag: 'meta', attrs: { name: 'description', content: description } },
|
|
46
|
-
{ tag: 'link', attrs: { rel: 'canonical', href: canonical?.href } },
|
|
47
|
-
{ tag: 'meta', attrs: { name: 'generator', content: Astro.generator } },
|
|
48
|
-
// Favicon
|
|
49
|
-
{
|
|
50
|
-
tag: 'link',
|
|
51
|
-
attrs: { rel: 'apple-touch-icon', href: '/apple-touch-icon.png', sizes: '180x180' },
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
tag: 'link',
|
|
55
|
-
attrs: { rel: 'icon', href: '/favicon-32x32.png', type: 'image/png', sizes: '32x32' },
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
tag: 'link',
|
|
59
|
-
attrs: { rel: 'icon', href: '/favicon-16x16.png', type: 'image/png', sizes: '16x16' },
|
|
60
|
-
},
|
|
61
|
-
{ tag: 'link', attrs: { rel: 'icon', href: '/favicon.png', type: 'image/png' } },
|
|
62
|
-
{ tag: 'link', attrs: { rel: 'manifest', href: '/site.webmanifest' } },
|
|
63
|
-
{ tag: 'link', attrs: { rel: 'mask-icon', href: '/safari-pinned-tab.svg', color: '#5bbad5' } },
|
|
64
|
-
{ tag: 'link', attrs: { rel: 'shortcut icon', href: '/favicon.ico' } },
|
|
65
|
-
{ tag: 'meta', attrs: { name: 'msapplication-TileColor', content: '#da532c' } },
|
|
66
|
-
{ tag: 'meta', attrs: { name: 'msapplication-config', content: '/browserconfig.xml' } },
|
|
67
|
-
{ tag: 'meta', attrs: { name: 'theme-color', content: '#aa87f4' } },
|
|
68
|
-
// OpenGraph Tags
|
|
69
|
-
{ tag: 'meta', attrs: { property: 'og:title', content: title } },
|
|
70
|
-
{ tag: 'meta', attrs: { property: 'og:type', content: 'website' } },
|
|
71
|
-
{ tag: 'meta', attrs: { property: 'og:url', content: canonical?.href } },
|
|
72
|
-
{ tag: 'meta', attrs: { property: 'og:description', content: description } },
|
|
73
|
-
{ tag: 'meta', attrs: { property: 'og:site_name', content: title } },
|
|
74
|
-
// Twitter Tags
|
|
75
|
-
{
|
|
76
|
-
tag: 'meta',
|
|
77
|
-
attrs: { name: 'twitter:card', content: 'summary_large_image' },
|
|
78
|
-
},
|
|
79
|
-
{ tag: 'meta', attrs: { name: 'twitter:url', content: canonical?.href } },
|
|
80
|
-
{ tag: 'meta', attrs: { name: 'twitter:title', content: title } },
|
|
81
|
-
{ tag: 'meta', attrs: { name: 'twitter:description', content: description } },
|
|
82
|
-
];
|
|
83
|
-
|
|
84
|
-
if (ogImage) {
|
|
85
|
-
headDefaults.push(
|
|
86
|
-
{ tag: 'meta', attrs: { property: 'og:image', content: ogImage } },
|
|
87
|
-
{ tag: 'meta', attrs: { name: 'twitter:image', content: ogImage } }
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return headDefaults;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const HeadSchema = HeadConfigSchema();
|
|
95
|
-
|
|
96
|
-
export type HeadUserConfig = z.input<ReturnType<typeof HeadConfigSchema>>;
|
|
97
|
-
export type HeadConfig = z.output<ReturnType<typeof HeadConfigSchema>>;
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Test if a head config object contains a matching `<title>` or `<meta>` tag.
|
|
101
|
-
*
|
|
102
|
-
* For example, will return true if `head` already contains
|
|
103
|
-
* `<meta name="description" content="A">` and the passed `tag`
|
|
104
|
-
* is `<meta name="description" content="B">`. Tests against `name`,
|
|
105
|
-
* `property`, and `http-equiv` attributes for `<meta>` tags.
|
|
106
|
-
*/
|
|
107
|
-
function hasTag(head: HeadConfig, entry: HeadConfig[number]): boolean {
|
|
108
|
-
switch (entry.tag) {
|
|
109
|
-
case 'title':
|
|
110
|
-
return head.some(({ tag }) => tag === 'title');
|
|
111
|
-
case 'meta':
|
|
112
|
-
return hasOneOf(head, entry, ['name', 'property', 'http-equiv']);
|
|
113
|
-
default:
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Test if a head config object contains a tag of the same type
|
|
120
|
-
* as `entry` and a matching attribute for one of the passed `keys`.
|
|
121
|
-
*/
|
|
122
|
-
function hasOneOf(head: HeadConfig, entry: HeadConfig[number], keys: string[]): boolean {
|
|
123
|
-
const attr = getAttr(keys, entry);
|
|
124
|
-
if (!attr) return false;
|
|
125
|
-
const [key, val] = attr;
|
|
126
|
-
return head.some(({ tag, attrs }) => tag === entry.tag && attrs[key] === val);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/** Find the first matching key–value pair in a head entry’s attributes. */
|
|
130
|
-
function getAttr(
|
|
131
|
-
keys: string[],
|
|
132
|
-
entry: HeadConfig[number]
|
|
133
|
-
): [key: string, value: string | boolean] | undefined {
|
|
134
|
-
let attr: [string, string | boolean] | undefined;
|
|
135
|
-
for (const key of keys) {
|
|
136
|
-
const val = entry.attrs[key];
|
|
137
|
-
if (val) {
|
|
138
|
-
attr = [key, val];
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return attr;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/** Merge two heads, overwriting entries in the first head that exist in the second. */
|
|
146
|
-
function mergeHead(oldHead: HeadConfig, newHead: HeadConfig) {
|
|
147
|
-
return [...oldHead.filter((tag) => !hasTag(newHead, tag)), ...newHead];
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/** Sort head tags to place important tags first and relegate “SEO” meta tags. */
|
|
151
|
-
function sortHead(head: HeadConfig) {
|
|
152
|
-
return head.sort((a, b) => {
|
|
153
|
-
const aImportance = getImportance(a);
|
|
154
|
-
const bImportance = getImportance(b);
|
|
155
|
-
return aImportance > bImportance ? -1 : bImportance > aImportance ? 1 : 0;
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/** Get the relative importance of a specific head tag. */
|
|
160
|
-
function getImportance(entry: HeadConfig[number]) {
|
|
161
|
-
// 1. Important meta tags.
|
|
162
|
-
if (
|
|
163
|
-
entry.tag === 'meta' &&
|
|
164
|
-
('charset' in entry.attrs || 'http-equiv' in entry.attrs || entry.attrs.name === 'viewport')
|
|
165
|
-
) {
|
|
166
|
-
return 100;
|
|
167
|
-
}
|
|
168
|
-
// 2. Page title
|
|
169
|
-
if (entry.tag === 'title') return 90;
|
|
170
|
-
// 3. Anything that isn’t an SEO meta tag.
|
|
171
|
-
if (entry.tag !== 'meta') {
|
|
172
|
-
// The default favicon should be below any extra icons that the user may have set
|
|
173
|
-
// because if several icons are equally appropriate, the last one is used and we
|
|
174
|
-
// want to use the SVG icon when supported.
|
|
175
|
-
if (entry.tag === 'link' && 'rel' in entry.attrs && entry.attrs.rel === 'shortcut icon') {
|
|
176
|
-
return 70;
|
|
177
|
-
}
|
|
178
|
-
return 80;
|
|
179
|
-
}
|
|
180
|
-
// 4. SEO meta tags.
|
|
181
|
-
return 0;
|
|
182
|
-
}
|
|
183
|
-
/** Create a fully parsed, merged, and sorted head entry array from multiple sources. */
|
|
184
|
-
export function createHead(defaultHeaders: HeadUserConfig, ...heads: HeadConfig[]) {
|
|
185
|
-
let head = HeadSchema.parse(defaultHeaders);
|
|
186
|
-
for (const next of heads) {
|
|
187
|
-
head = mergeHead(head, next);
|
|
188
|
-
}
|
|
189
|
-
return sortHead(head);
|
|
190
|
-
}
|
package/src/utils/iconStrings.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
type ValidIconString =
|
|
2
|
-
| 'check-circle'
|
|
3
|
-
| 'exclamation-triangle'
|
|
4
|
-
| 'exclamation-circle'
|
|
5
|
-
| 'information-circle'
|
|
6
|
-
| 'x-mark';
|
|
7
|
-
|
|
8
|
-
const iconStrings: Record<ValidIconString, string> = {
|
|
9
|
-
'check-circle':
|
|
10
|
-
'<svg xmlns="http://www.w3.org/2000/svg" class="%class%" width="%width%" height="%height%" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75 11.25 15 15 9.75M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" /></svg>',
|
|
11
|
-
'exclamation-circle':
|
|
12
|
-
'<svg xmlns="http://www.w3.org/2000/svg" class="%class%" width="%width%" height="%height%" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m9-.75a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9 3.75h.008v.008H12v-.008Z" /></svg>',
|
|
13
|
-
'information-circle':
|
|
14
|
-
'<svg xmlns="http://www.w3.org/2000/svg" class="%class%" width="%width%" height="%height%" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="m11.25 11.25.041-.02a.75.75 0 0 1 1.063.852l-.708 2.836a.75.75 0 0 0 1.063.853l.041-.021M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9-3.75h.008v.008H12V8.25Z" /></svg>',
|
|
15
|
-
'x-mark':
|
|
16
|
-
'<svg xmlns="http://www.w3.org/2000/svg" class="%class%" width="%width%" height="%height%" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12" /></svg>',
|
|
17
|
-
'exclamation-triangle':
|
|
18
|
-
'<svg xmlns="http://www.w3.org/2000/svg" class="%class%" width="%width%" height="%height%" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z" /></svg>',
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
function getIconString(icon: ValidIconString, classes: string, width: number, height: number) {
|
|
22
|
-
return iconStrings[icon]
|
|
23
|
-
.replace('%class%', classes)
|
|
24
|
-
.replace('%width%', width.toString())
|
|
25
|
-
.replace('%height%', height.toString());
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export { getIconString };
|
|
29
|
-
export type { ValidIconString };
|
package/src/utils/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as Icon } from './Icon.astro';
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { AstroConfig } from 'astro';
|
|
2
|
-
|
|
3
|
-
type VitePlugin = Required<AstroConfig['vite']>['plugins'][number];
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Builds a Vite plugin that creates a virtual module.
|
|
7
|
-
*
|
|
8
|
-
* @param moduleId - The ID of the virtual module.
|
|
9
|
-
* @param name - The name of the plugin.
|
|
10
|
-
* @param moduleContent - The content of the virtual module.
|
|
11
|
-
* @returns A Vite plugin that resolves and loads the virtual module.
|
|
12
|
-
*/
|
|
13
|
-
export function viteVirtualModulePluginBuilder(
|
|
14
|
-
moduleId: string,
|
|
15
|
-
name: string,
|
|
16
|
-
moduleContent: string
|
|
17
|
-
) {
|
|
18
|
-
return function modulePlugin(): VitePlugin {
|
|
19
|
-
const resolvedVirtualModuleId = `\0${moduleId}`; // Prefix with \0 to avoid conflicts
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
name,
|
|
23
|
-
resolveId(id) {
|
|
24
|
-
if (id === moduleId) {
|
|
25
|
-
return resolvedVirtualModuleId;
|
|
26
|
-
}
|
|
27
|
-
return;
|
|
28
|
-
},
|
|
29
|
-
load(id) {
|
|
30
|
-
if (id === resolvedVirtualModuleId) {
|
|
31
|
-
return moduleContent;
|
|
32
|
-
}
|
|
33
|
-
return;
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|