Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-inlinesvg

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-inlinesvg - npm Package Compare versions

Comparing version 4.1.0-0 to 4.1.0

src/modules/cache.ts

106

dist/index.js

@@ -0,1 +1,2 @@

"use client";
"use strict";

@@ -43,3 +44,3 @@ var __create = Object.create;

var import_react2 = require("react");
var import_react_from_dom = __toESM(require("react-from-dom"));
var import_react_from_dom2 = __toESM(require("react-from-dom"));

@@ -58,3 +59,3 @@ // src/config.ts

// src/helpers.ts
// src/modules/helpers.ts
function canUseDOM() {

@@ -117,3 +118,3 @@ return !!(typeof window !== "undefined" && window.document && window.document.createElement);

// src/cache.ts
// src/modules/cache.ts
var CacheStore = class {

@@ -244,3 +245,3 @@ constructor() {

// src/hooks.tsx
// src/modules/hooks.tsx
var import_react = require("react");

@@ -255,37 +256,4 @@ function usePrevious(state) {

// src/index.tsx
var import_jsx_runtime = require("react/jsx-runtime");
var cacheStore;
function updateSVGAttributes(node, options) {
const { baseURL = "", hash, uniquifyIDs } = options;
const replaceableAttributes = ["id", "href", "xlink:href", "xlink:role", "xlink:arcrole"];
const linkAttributes = ["href", "xlink:href"];
const isDataValue = (name, value) => linkAttributes.includes(name) && (value ? !value.includes("#") : false);
if (!uniquifyIDs) {
return node;
}
[...node.children].forEach((d) => {
if (d.attributes?.length) {
const attributes = Object.values(d.attributes).map((a) => {
const attribute = a;
const match = /url\((.*?)\)/.exec(a.value);
if (match?.[1]) {
attribute.value = a.value.replace(match[0], `url(${baseURL}${match[1]}__${hash})`);
}
return attribute;
});
replaceableAttributes.forEach((r) => {
const attribute = attributes.find((a) => a.name === r);
if (attribute && !isDataValue(r, attribute.value)) {
attribute.value = `${attribute.value}__${hash}`;
}
});
}
if (d.children.length) {
return updateSVGAttributes(d, options);
}
return d;
});
return node;
}
// src/modules/utils.ts
var import_react_from_dom = __toESM(require("react-from-dom"));
function getNode(options) {

@@ -340,2 +308,38 @@ const {

}
function updateSVGAttributes(node, options) {
const { baseURL = "", hash, uniquifyIDs } = options;
const replaceableAttributes = ["id", "href", "xlink:href", "xlink:role", "xlink:arcrole"];
const linkAttributes = ["href", "xlink:href"];
const isDataValue = (name, value) => linkAttributes.includes(name) && (value ? !value.includes("#") : false);
if (!uniquifyIDs) {
return node;
}
[...node.children].forEach((d) => {
if (d.attributes?.length) {
const attributes = Object.values(d.attributes).map((a) => {
const attribute = a;
const match = /url\((.*?)\)/.exec(a.value);
if (match?.[1]) {
attribute.value = a.value.replace(match[0], `url(${baseURL}${match[1]}__${hash})`);
}
return attribute;
});
replaceableAttributes.forEach((r) => {
const attribute = attributes.find((a) => a.name === r);
if (attribute && !isDataValue(r, attribute.value)) {
attribute.value = `${attribute.value}__${hash}`;
}
});
}
if (d.children.length) {
return updateSVGAttributes(d, options);
}
return d;
});
return node;
}
// src/index.tsx
var import_jsx_runtime = require("react/jsx-runtime");
var cacheStore;
function ReactInlineSVG(props) {

@@ -393,6 +397,10 @@ const {

}, []);
const fetchContent = (0, import_react2.useCallback)(async () => {
const responseContent = await request(src, fetchOptions);
handleLoad(responseContent);
}, [fetchOptions, handleLoad, src]);
const getElement = (0, import_react2.useCallback)(() => {
try {
const node = getNode({ ...props, handleError, hash: hash.current, content });
const convertedElement = (0, import_react_from_dom.default)(node);
const convertedElement = (0, import_react_from_dom2.default)(node);
if (!convertedElement || !(0, import_react2.isValidElement)(convertedElement)) {

@@ -409,6 +417,2 @@ throw new Error("Could not convert the src to a React element");

}, [content, handleError, props]);
const fetchContent = (0, import_react2.useCallback)(async () => {
const responseContent = await request(src, fetchOptions);
handleLoad(responseContent);
}, [fetchOptions, handleLoad, src]);
const getContent = (0, import_react2.useCallback)(async () => {

@@ -490,15 +494,3 @@ const dataURI = /^data:image\/svg[^,]*?(;base64)?,(.*)/u.exec(src);

}
}, [
description,
getElement,
handleError,
isCached,
load,
onLoad,
previousProps,
previousState,
src,
status,
title
]);
}, [description, getElement, handleError, load, previousProps, src, title]);
(0, import_react2.useEffect)(() => {

@@ -505,0 +497,0 @@ if (!previousState) {

@@ -0,1 +1,2 @@

"use client";
"use strict";

@@ -27,3 +28,3 @@ var __defProp = Object.defineProperty;

// src/helpers.ts
// src/modules/helpers.ts
function canUseDOM() {

@@ -30,0 +31,0 @@ return !!(typeof window !== "undefined" && window.document && window.document.createElement);

{
"name": "react-inlinesvg",
"version": "4.1.0-0",
"version": "4.1.0",
"description": "An SVG loader for React",

@@ -103,2 +103,5 @@ "author": "Gil Barbara <gilbarbara@gmail.com>",

"tsup": {
"banner": {
"js": "\"use client\";"
},
"dts": true,

@@ -105,0 +108,0 @@ "entry": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc