@libsrcdev/gatsby-remark-images-anywhere 0.1.0 → 0.1.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/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Node, NodePluginArgs } from "gatsby";
2
2
  import { FileSystemNode } from "gatsby-source-filesystem";
3
+ import { Literal } from "mdast";
3
4
 
4
5
  //#region src/custom-http-headers/http-request-header-options.d.ts
5
6
  type HttpRequestHeaderOptions = {
@@ -9,12 +10,8 @@ type HttpRequestHeaderOptions = {
9
10
  //#endregion
10
11
  //#region src/type.d.ts
11
12
  type SharpMethod = 'fluid' | 'fixed' | 'resize';
12
- interface RemarkNode {
13
- type: string;
14
- [key: string]: any;
15
- }
16
13
  interface Args extends NodePluginArgs {
17
- markdownAST: RemarkNode;
14
+ markdownAST: Literal;
18
15
  markdownNode: Node;
19
16
  files: FileSystemNode[];
20
17
  }
@@ -58,7 +55,7 @@ interface Options extends Partial<MarkupOptions>, HttpRequestHeaderOptions {
58
55
  }
59
56
  //#endregion
60
57
  //#region src/index.d.ts
61
- declare const addImage: ({
58
+ declare function remarkImagesAnywhere({
62
59
  markdownAST: mdast,
63
60
  markdownNode,
64
61
  actions,
@@ -70,5 +67,5 @@ declare const addImage: ({
70
67
  reporter,
71
68
  cache,
72
69
  pathPrefix
73
- }: Args, pluginOptions: Options) => Promise<(null | undefined)[]>;
74
- export = addImage;
70
+ }: Args, pluginOptions: Options): Promise<(null | undefined)[]>;
71
+ export = remarkImagesAnywhere;
package/dist/index.js CHANGED
@@ -29,11 +29,9 @@ var __toESM = (mod, isNodeMode, target$1) => (target$1 = mod != null ? __create(
29
29
  let path = require("path");
30
30
  path = __toESM(path);
31
31
  let unist_util_select = require("unist-util-select");
32
- unist_util_select = __toESM(unist_util_select);
33
32
  let slash = require("slash");
34
33
  slash = __toESM(slash);
35
34
  let parse5 = require("parse5");
36
- parse5 = __toESM(parse5);
37
35
 
38
36
  //#region node_modules/universalify/index.js
39
37
  var require_universalify = /* @__PURE__ */ __commonJSMin(((exports) => {
@@ -70756,23 +70754,27 @@ const processImage = async ({ file: file$1, reporter, cache: cache$3, pathPrefix
70756
70754
  //#region src/util-html-to-md.ts
70757
70755
  const toMdNode = (node) => {
70758
70756
  const value = node.value;
70759
- const imgNode = parse5.default.parseFragment(value).childNodes.find((node$1) => node$1.tagName === "img");
70757
+ const imgNode = (0, parse5.parseFragment)(value).childNodes.find((node$1) => {
70758
+ if ("tagName" in node$1) return node$1.tagName === "img";
70759
+ return false;
70760
+ });
70760
70761
  if (!imgNode) return null;
70761
- const attrs = imgNode.attrs.reduce((acc, cur) => {
70762
+ const attrs = "attrs" in imgNode ? imgNode.attrs.reduce((acc, cur) => {
70762
70763
  const { name: name$1, value: value$1 } = cur;
70763
70764
  acc[name$1] = value$1;
70764
70765
  return acc;
70765
- }, {});
70766
- if (!attrs.src) return null;
70766
+ }, {}) : {};
70767
+ if ("src" in attrs) return null;
70767
70768
  const original = { ...node };
70768
- node.type = "image";
70769
- node.value = "";
70770
- node.url = attrs.src;
70771
- node.title = attrs.title;
70772
- node.alt = attrs.alt;
70773
- node.data = {};
70774
- node.data.original = original;
70775
- return node;
70769
+ const remarkImageNode = node;
70770
+ remarkImageNode.type = "image";
70771
+ remarkImageNode.value = "";
70772
+ remarkImageNode.url = attrs.src;
70773
+ remarkImageNode.title = attrs.title;
70774
+ remarkImageNode.alt = attrs.alt;
70775
+ remarkImageNode.data = {};
70776
+ remarkImageNode.data.original = original;
70777
+ return remarkImageNode;
70776
70778
  };
70777
70779
 
70778
70780
  //#endregion
@@ -70923,12 +70925,12 @@ function createRequestHttpHeaderBuilder({ dangerouslyBuildRequestHttpHeaders, ht
70923
70925
  if (httpHeaders) return httpHeaders;
70924
70926
  }
70925
70927
  };
70926
- return (url$3) => void 0;
70928
+ return (_$2) => void 0;
70927
70929
  }
70928
70930
 
70929
70931
  //#endregion
70930
70932
  //#region src/index.ts
70931
- const addImage = async ({ markdownAST: mdast, markdownNode, actions: actions$1, store, files, getNode, getCache, createNodeId, reporter, cache: cache$3, pathPrefix }, pluginOptions$1) => {
70933
+ async function remarkImagesAnywhere({ markdownAST: mdast, markdownNode, actions: actions$1, store, files, getNode, getCache, createNodeId, reporter, cache: cache$3, pathPrefix }, pluginOptions$1) {
70932
70934
  const { plugins, staticDir = "static", createMarkup = defaultMarkup, sharpMethod = "fluid", loading = "lazy", linkImagesToOriginal = false, showCaptions = false, wrapperStyle = "", backgroundColor = "#fff", tracedSVG = false, blurUp = true, dangerouslyBuildRequestHttpHeaders, httpHeaderProviders, ...imageOptions } = pluginOptions$1;
70933
70935
  if ([
70934
70936
  "fluid",
@@ -70938,12 +70940,12 @@ const addImage = async ({ markdownAST: mdast, markdownNode, actions: actions$1,
70938
70940
  const { touchNode, createNode } = actions$1;
70939
70941
  const dirPath = markdownNode.parent && getNode(markdownNode.parent)?.dir;
70940
70942
  const { directory } = store.getState().program;
70941
- const imgNodes = unist_util_select.default.selectAll("image[url]", mdast);
70942
- const htmlImgNodes = unist_util_select.default.selectAll("html, jsx", mdast).map((node) => toMdNode(node)).filter((node) => !!node);
70943
+ const imgNodes = (0, unist_util_select.selectAll)("image[url]", mdast).filter((node) => "src" in node);
70944
+ const htmlImgNodes = (0, unist_util_select.selectAll)("html, jsx", mdast).filter((node) => "value" in node).map((node, _$2, __) => toMdNode(node)).filter((node, _$2, __) => !!node);
70943
70945
  imgNodes.push(...htmlImgNodes);
70944
70946
  const processPromises = imgNodes.map(async (node) => {
70947
+ if (!node.url) return;
70945
70948
  let url$3 = node.url;
70946
- if (!url$3) return;
70947
70949
  let gImgFileNode;
70948
70950
  if (isWhitelisted(url$3)) url$3 = `https:${url$3}`;
70949
70951
  if (url$3.startsWith("http")) gImgFileNode = await downloadImage({
@@ -70998,7 +71000,7 @@ const addImage = async ({ markdownAST: mdast, markdownNode, actions: actions$1,
70998
71000
  return null;
70999
71001
  });
71000
71002
  return Promise.all(processPromises);
71001
- };
71002
- module.exports = addImage;
71003
+ }
71003
71004
 
71004
- //#endregion
71005
+ //#endregion
71006
+ module.exports = remarkImagesAnywhere;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libsrcdev/gatsby-remark-images-anywhere",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Handle images with relative, absolute, remote path for gatsby-transformer-remark.",
5
5
  "keywords": [
6
6
  "gatsby",