@terrafirmagreg-team/mdx 1.2.1 → 1.2.2
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/package.json +3 -3
- package/src/components/docs-image.tsx +62 -62
- package/src/components/mdx-components.tsx +158 -158
- package/src/components/story-fields.tsx +318 -318
- package/src/components/story-panel.tsx +181 -181
- package/src/lib/md-plugins.ts +1 -0
- package/src/lib/mdx/directive-utils.ts +118 -118
- package/src/lib/pack-assets.ts +46 -46
- package/src/lib/story-remark.ts +468 -468
- package/src/lib/story.ts +11 -11
package/src/lib/pack-assets.ts
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import type { DocsImageProps } from '../types/mdx';
|
|
2
|
-
|
|
3
|
-
export function packPublicUrl(pack: string, ...segments: string[]): string {
|
|
4
|
-
const rel = segments
|
|
5
|
-
.map((s) => s.replace(/^\/+/, '').replaceAll('\\', '/'))
|
|
6
|
-
.filter(Boolean)
|
|
7
|
-
.join('/');
|
|
8
|
-
return rel ? `/${pack}/${rel}` : `/${pack}`;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function assetUrl(
|
|
12
|
-
pack: string,
|
|
13
|
-
modId: string,
|
|
14
|
-
...pathSegments: string[]
|
|
15
|
-
): string {
|
|
16
|
-
return packPublicUrl(pack, 'assets', modId, ...pathSegments);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function resolveSrc(
|
|
20
|
-
props: Pick<DocsImageProps, 'src' | 'pack' | 'mod' | 'path'>,
|
|
21
|
-
packFallback?: string,
|
|
22
|
-
): string | null {
|
|
23
|
-
if (props.src) {
|
|
24
|
-
const s = props.src.trim();
|
|
25
|
-
if (
|
|
26
|
-
s.startsWith('/') ||
|
|
27
|
-
s.startsWith('http://') ||
|
|
28
|
-
s.startsWith('https://')
|
|
29
|
-
) {
|
|
30
|
-
return s;
|
|
31
|
-
}
|
|
32
|
-
return `/${s.replace(/^\/+/, '')}`;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const pack = props.pack ?? packFallback;
|
|
36
|
-
if (!pack) return null;
|
|
37
|
-
|
|
38
|
-
if (props.mod && props.path) {
|
|
39
|
-
return assetUrl(pack, props.mod, props.path);
|
|
40
|
-
}
|
|
41
|
-
if (props.path) {
|
|
42
|
-
return packPublicUrl(pack, props.path);
|
|
43
|
-
}
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
|
|
1
|
+
import type { DocsImageProps } from '../types/mdx';
|
|
2
|
+
|
|
3
|
+
export function packPublicUrl(pack: string, ...segments: string[]): string {
|
|
4
|
+
const rel = segments
|
|
5
|
+
.map((s) => s.replace(/^\/+/, '').replaceAll('\\', '/'))
|
|
6
|
+
.filter(Boolean)
|
|
7
|
+
.join('/');
|
|
8
|
+
return rel ? `/${pack}/${rel}` : `/${pack}`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function assetUrl(
|
|
12
|
+
pack: string,
|
|
13
|
+
modId: string,
|
|
14
|
+
...pathSegments: string[]
|
|
15
|
+
): string {
|
|
16
|
+
return packPublicUrl(pack, 'assets', modId, ...pathSegments);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function resolveSrc(
|
|
20
|
+
props: Pick<DocsImageProps, 'src' | 'pack' | 'mod' | 'path'>,
|
|
21
|
+
packFallback?: string,
|
|
22
|
+
): string | null {
|
|
23
|
+
if (props.src) {
|
|
24
|
+
const s = props.src.trim();
|
|
25
|
+
if (
|
|
26
|
+
s.startsWith('/') ||
|
|
27
|
+
s.startsWith('http://') ||
|
|
28
|
+
s.startsWith('https://')
|
|
29
|
+
) {
|
|
30
|
+
return s;
|
|
31
|
+
}
|
|
32
|
+
return `/${s.replace(/^\/+/, '')}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const pack = props.pack ?? packFallback;
|
|
36
|
+
if (!pack) return null;
|
|
37
|
+
|
|
38
|
+
if (props.mod && props.path) {
|
|
39
|
+
return assetUrl(pack, props.mod, props.path);
|
|
40
|
+
}
|
|
41
|
+
if (props.path) {
|
|
42
|
+
return packPublicUrl(pack, props.path);
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|