@libsrcdev/gatsby-remark-images-anywhere 0.1.3 → 0.1.4
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/index.d.ts +84 -2
- package/dist/index.js +69 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Node, NodePluginArgs } from "gatsby";
|
|
2
2
|
import { FileSystemNode } from "gatsby-source-filesystem";
|
|
3
|
-
import { Literal } from "mdast";
|
|
3
|
+
import { Literal, Literal as RemarkLiteral, Node as RemarkNode } from "mdast";
|
|
4
4
|
|
|
5
5
|
//#region src/custom-http-headers/http-request-header-options.d.ts
|
|
6
6
|
type HttpRequestHeaderOptions = {
|
|
@@ -55,6 +55,87 @@ interface Options extends Partial<MarkupOptions>, HttpRequestHeaderOptions {
|
|
|
55
55
|
[key: string]: unknown;
|
|
56
56
|
}
|
|
57
57
|
//#endregion
|
|
58
|
+
//#region src/constants.d.ts
|
|
59
|
+
declare const CLASS_WRAPPER = "gria-image-wrapper";
|
|
60
|
+
declare const CLASS_PADDING = "gria-image-padding";
|
|
61
|
+
declare const CLASS_LINK = "gria-image-link";
|
|
62
|
+
declare const CLASS_IMAGE = "gria-image";
|
|
63
|
+
declare const CLASS_PLACEHOLDER = "gria-image-placeholder";
|
|
64
|
+
declare const SUPPORT_EXTS: string[];
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/custom-http-headers/is-trusted-url.d.ts
|
|
67
|
+
type UrlCheckOptions = {
|
|
68
|
+
allowedDomains: string[];
|
|
69
|
+
schemes?: string[];
|
|
70
|
+
allowSubdomains?: boolean;
|
|
71
|
+
maxSubdomainDepth?: number;
|
|
72
|
+
allowedPorts?: string[] | null;
|
|
73
|
+
disallowedQueryParams?: string[];
|
|
74
|
+
};
|
|
75
|
+
declare function isTrustedUrl(input: string, options: UrlCheckOptions): boolean;
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/custom-http-headers/http-header-trusted-provider.d.ts
|
|
78
|
+
declare function httpHeaderTrustedProvider(options: UrlCheckOptions, headerBuilder: (url: string) => Record<string, string> | undefined): (url: string) => Record<string, string> | undefined;
|
|
79
|
+
declare function forTrustedDomains(domains: string[], headerBuilder: (url: string) => Record<string, string> | undefined): (url: string) => Record<string, string> | undefined;
|
|
80
|
+
declare const buildRequestHttpHeadersWith: (httpHeaderProviders: HttpRequestHeaderProvider[]) => (url: string) => Record<string, string> | undefined;
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/default-markup.d.ts
|
|
83
|
+
declare const defaultMarkup: CreateMarkup;
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/relative-protocol-whitelist.d.ts
|
|
86
|
+
type MakeWhitelistTest = (whitelist: string[]) => (url: string) => boolean;
|
|
87
|
+
declare const makeWhitelistTest: MakeWhitelistTest;
|
|
88
|
+
declare const isWhitelisted: (url: string) => boolean;
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/util-download-image.d.ts
|
|
91
|
+
declare const downloadImage: ({
|
|
92
|
+
id,
|
|
93
|
+
url,
|
|
94
|
+
getCache,
|
|
95
|
+
getNode,
|
|
96
|
+
touchNode,
|
|
97
|
+
cache,
|
|
98
|
+
createNode,
|
|
99
|
+
createNodeId,
|
|
100
|
+
reporter,
|
|
101
|
+
dangerouslyBuildImageRequestHttpHeaders
|
|
102
|
+
}: any) => Promise<any>;
|
|
103
|
+
declare const processImage: ({
|
|
104
|
+
file,
|
|
105
|
+
reporter,
|
|
106
|
+
cache,
|
|
107
|
+
pathPrefix,
|
|
108
|
+
sharpMethod,
|
|
109
|
+
imageOptions
|
|
110
|
+
}: {
|
|
111
|
+
sharpMethod: SharpMethod;
|
|
112
|
+
} & {
|
|
113
|
+
[key: string]: any;
|
|
114
|
+
}) => Promise<SharpResult>;
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/util-html-to-md.d.ts
|
|
117
|
+
type RemarkImageNode = RemarkLiteral & {
|
|
118
|
+
url?: string;
|
|
119
|
+
title?: string;
|
|
120
|
+
alt?: string;
|
|
121
|
+
data: Record<string, any>;
|
|
122
|
+
};
|
|
123
|
+
declare const toMdNode: (node: RemarkLiteral) => RemarkImageNode | null;
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/utils.d.ts
|
|
126
|
+
/**
|
|
127
|
+
* Resolves a potentially incomplete URL to a full URL with protocol
|
|
128
|
+
* @param url - The URL to resolve (can be protocol-relative or full)
|
|
129
|
+
* @returns The full URL with protocol, or null if invalid or relative
|
|
130
|
+
*/
|
|
131
|
+
declare function resolveFullUrl(url: string): string | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* Resolves a relative URL by validating and returning it if it's relative
|
|
134
|
+
* @param url - The URL to check and resolve
|
|
135
|
+
* @returns The relative URL if valid, or undefined if not relative or invalid
|
|
136
|
+
*/
|
|
137
|
+
declare function resolveRelativeUrl(url: string): string | undefined;
|
|
138
|
+
//#endregion
|
|
58
139
|
//#region src/index.d.ts
|
|
59
140
|
declare function remarkImagesAnywhere({
|
|
60
141
|
markdownAST: mdast,
|
|
@@ -69,4 +150,5 @@ declare function remarkImagesAnywhere({
|
|
|
69
150
|
cache,
|
|
70
151
|
pathPrefix
|
|
71
152
|
}: Args, pluginOptions: Options): Promise<(null | undefined)[]>;
|
|
72
|
-
|
|
153
|
+
//#endregion
|
|
154
|
+
export { Args, CLASS_IMAGE, CLASS_LINK, CLASS_PADDING, CLASS_PLACEHOLDER, CLASS_WRAPPER, CreateMarkup, CreateMarkupArgs, HttpRequestHeaderOptions, HttpRequestHeaderProvider, MarkupOptions, Options, RemarkImageNode, type RemarkLiteral, type RemarkNode, SUPPORT_EXTS, SharpMethod, SharpResult, UrlCheckOptions, buildRequestHttpHeadersWith, remarkImagesAnywhere as default, defaultMarkup, downloadImage, forTrustedDomains, httpHeaderTrustedProvider, isTrustedUrl, isWhitelisted, makeWhitelistTest, processImage, resolveFullUrl, resolveRelativeUrl, toMdNode };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1
2
|
//#region rolldown:runtime
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
@@ -70917,8 +70918,57 @@ const makeWhitelistTest = (whitelist) => (url$3) => {
|
|
|
70917
70918
|
};
|
|
70918
70919
|
const isWhitelisted = makeWhitelistTest(rpWhitelist);
|
|
70919
70920
|
|
|
70921
|
+
//#endregion
|
|
70922
|
+
//#region src/custom-http-headers/is-trusted-url.ts
|
|
70923
|
+
function isTrustedUrl(input, options) {
|
|
70924
|
+
const { allowedDomains, schemes = ["http", "https"], allowSubdomains = false, maxSubdomainDepth = Infinity, allowedPorts = null, disallowedQueryParams = [] } = options;
|
|
70925
|
+
try {
|
|
70926
|
+
const url$3 = new URL(input);
|
|
70927
|
+
const protocol = url$3.protocol.replace(":", "");
|
|
70928
|
+
if (!schemes.includes(protocol)) return false;
|
|
70929
|
+
const hostname = url$3.hostname.toLowerCase();
|
|
70930
|
+
let domainMatch = false;
|
|
70931
|
+
for (const allowedDomain of allowedDomains) {
|
|
70932
|
+
const domain = allowedDomain.toLowerCase();
|
|
70933
|
+
if (hostname === domain) {
|
|
70934
|
+
domainMatch = true;
|
|
70935
|
+
break;
|
|
70936
|
+
}
|
|
70937
|
+
if (allowSubdomains && hostname.endsWith("." + domain)) {
|
|
70938
|
+
if (hostname.slice(0, -(domain.length + 1)).split(".").length <= maxSubdomainDepth) {
|
|
70939
|
+
domainMatch = true;
|
|
70940
|
+
break;
|
|
70941
|
+
}
|
|
70942
|
+
}
|
|
70943
|
+
}
|
|
70944
|
+
if (!domainMatch) return false;
|
|
70945
|
+
if (disallowedQueryParams.length > 0) {
|
|
70946
|
+
for (const param of disallowedQueryParams) if (url$3.searchParams.has(param)) return false;
|
|
70947
|
+
}
|
|
70948
|
+
if (allowedPorts) {
|
|
70949
|
+
const port = url$3.port || (protocol === "https" ? "443" : protocol === "http" ? "80" : "");
|
|
70950
|
+
if (!allowedPorts.includes(port)) return false;
|
|
70951
|
+
}
|
|
70952
|
+
return true;
|
|
70953
|
+
} catch {
|
|
70954
|
+
return false;
|
|
70955
|
+
}
|
|
70956
|
+
}
|
|
70957
|
+
|
|
70920
70958
|
//#endregion
|
|
70921
70959
|
//#region src/custom-http-headers/http-header-trusted-provider.ts
|
|
70960
|
+
function httpHeaderTrustedProvider(options, headerBuilder) {
|
|
70961
|
+
return (url$3) => {
|
|
70962
|
+
if (!isTrustedUrl(url$3, options)) return;
|
|
70963
|
+
return headerBuilder(url$3);
|
|
70964
|
+
};
|
|
70965
|
+
}
|
|
70966
|
+
function forTrustedDomains(domains, headerBuilder) {
|
|
70967
|
+
return httpHeaderTrustedProvider({
|
|
70968
|
+
allowedDomains: domains,
|
|
70969
|
+
allowSubdomains: false
|
|
70970
|
+
}, headerBuilder);
|
|
70971
|
+
}
|
|
70922
70972
|
const buildRequestHttpHeadersWith = (httpHeaderProviders) => (url$3) => {
|
|
70923
70973
|
for (const httpHeaderProvider of httpHeaderProviders ?? []) {
|
|
70924
70974
|
const httpHeaders = httpHeaderProvider(url$3);
|
|
@@ -71034,4 +71084,22 @@ async function remarkImagesAnywhere({ markdownAST: mdast, markdownNode, actions:
|
|
|
71034
71084
|
}
|
|
71035
71085
|
|
|
71036
71086
|
//#endregion
|
|
71037
|
-
|
|
71087
|
+
exports.CLASS_IMAGE = CLASS_IMAGE;
|
|
71088
|
+
exports.CLASS_LINK = CLASS_LINK;
|
|
71089
|
+
exports.CLASS_PADDING = CLASS_PADDING;
|
|
71090
|
+
exports.CLASS_PLACEHOLDER = CLASS_PLACEHOLDER;
|
|
71091
|
+
exports.CLASS_WRAPPER = CLASS_WRAPPER;
|
|
71092
|
+
exports.SUPPORT_EXTS = SUPPORT_EXTS;
|
|
71093
|
+
exports.buildRequestHttpHeadersWith = buildRequestHttpHeadersWith;
|
|
71094
|
+
exports.default = remarkImagesAnywhere;
|
|
71095
|
+
exports.defaultMarkup = defaultMarkup;
|
|
71096
|
+
exports.downloadImage = downloadImage;
|
|
71097
|
+
exports.forTrustedDomains = forTrustedDomains;
|
|
71098
|
+
exports.httpHeaderTrustedProvider = httpHeaderTrustedProvider;
|
|
71099
|
+
exports.isTrustedUrl = isTrustedUrl;
|
|
71100
|
+
exports.isWhitelisted = isWhitelisted;
|
|
71101
|
+
exports.makeWhitelistTest = makeWhitelistTest;
|
|
71102
|
+
exports.processImage = processImage;
|
|
71103
|
+
exports.resolveFullUrl = resolveFullUrl;
|
|
71104
|
+
exports.resolveRelativeUrl = resolveRelativeUrl;
|
|
71105
|
+
exports.toMdNode = toMdNode;
|