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

@vkontakte/icons-sprite

Package Overview
Dependencies
Maintainers
18
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vkontakte/icons-sprite - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

141

dist/browser-sprite.js

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

import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
import { _ as _create_class } from "@swc/helpers/_/_create_class";
import { _ as _define_property } from "@swc/helpers/_/_define_property";
import { BrowserSymbol } from "./browser-symbol";

@@ -9,4 +11,4 @@ var namespaceURI = "http://www.w3.org/2000/svg";

_class_call_check(this, BrowserSprite);
this.symbols = new Map();
this.config = {
_define_property(this, "symbols", new Map());
_define_property(this, "config", {
attrs: {

@@ -18,62 +20,81 @@ "xmlns": namespaceURI,

}
};
this.node = null;
});
_define_property(this, "node", null);
Object.assign(this.config.attrs, config.attrs);
}
var _proto = BrowserSprite.prototype;
_proto.push = function push(symbol) {
var symbols = this.symbols;
var existing = symbols.has(symbol.id);
symbols.set(symbol.id, symbol);
return !existing;
};
_proto.add = function add(symbol) {
var isNewSymbol = this.push(symbol);
if (!!this.node && isNewSymbol) {
symbol.mount(this.node);
_create_class(BrowserSprite, [
{
key: "push",
value: function push(symbol) {
var symbols = this.symbols;
var existing = symbols.has(symbol.id);
symbols.set(symbol.id, symbol);
return !existing;
}
},
{
key: "add",
value: function add(symbol) {
var isNewSymbol = this.push(symbol);
if (!!this.node && isNewSymbol) {
symbol.mount(this.node);
}
return isNewSymbol;
}
},
{
key: "attach",
value: function attach(target) {
var _this = this;
if (!!this.node) {
return;
}
this.node = target;
// Already added symbols needs to be mounted
this.symbols.forEach(function(symbol) {
symbol.mount(target);
});
// Create symbols from existing DOM nodes, add and mount them
target.querySelectorAll("symbol").forEach(function(symbolNode) {
var symbol = BrowserSymbol.createFromExistingNode(symbolNode);
_this.add(symbol);
});
}
},
{
key: "mount",
value: function mount(target) {
var prepend = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
if (!!this.node) {
return this.node;
}
this.node = this.render();
if (prepend && target.childNodes[0]) {
target.insertBefore(this.node, target.firstChild);
} else {
target.appendChild(this.node);
}
return this.node;
}
},
{
key: "render",
value: function render() {
var el = document.createElementNS(namespaceURI, "svg");
Object.entries(this.config.attrs).forEach(function(entry) {
return el.setAttribute(entry[0], entry[1]);
});
this.symbols.forEach(function(symbol) {
return el.appendChild(symbol.node);
});
return el;
}
},
{
key: "unmount",
value: function unmount() {
this.node && this.node.parentNode && this.node.parentNode.removeChild(this.node);
}
}
return isNewSymbol;
};
_proto.attach = function attach(target) {
var _this = this;
if (!!this.node) {
return;
}
this.node = target;
// Already added symbols needs to be mounted
this.symbols.forEach(function(symbol) {
symbol.mount(target);
});
// Create symbols from existing DOM nodes, add and mount them
target.querySelectorAll("symbol").forEach(function(symbolNode) {
var symbol = BrowserSymbol.createFromExistingNode(symbolNode);
_this.add(symbol);
});
};
_proto.mount = function mount(target) {
var prepend = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
if (!!this.node) {
return this.node;
}
this.node = this.render();
if (prepend && target.childNodes[0]) {
target.insertBefore(this.node, target.firstChild);
} else {
target.appendChild(this.node);
}
return this.node;
};
_proto.render = function render() {
var el = document.createElementNS(namespaceURI, "svg");
Object.entries(this.config.attrs).forEach(function(entry) {
return el.setAttribute(entry[0], entry[1]);
});
this.symbols.forEach(function(symbol) {
return el.appendChild(symbol.node);
});
return el;
};
_proto.unmount = function unmount() {
this.node && this.node.parentNode && this.node.parentNode.removeChild(this.node);
};
]);
return BrowserSprite;

@@ -80,0 +101,0 @@ }();

@@ -1,3 +0,4 @@

import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
import _create_class from "@swc/helpers/src/_create_class.mjs";
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
import { _ as _create_class } from "@swc/helpers/_/_create_class";
import { _ as _define_property } from "@swc/helpers/_/_define_property";
import { parse } from "./utils/parse";

@@ -9,27 +10,6 @@ export var BrowserSymbol = /*#__PURE__*/ function() {

_class_call_check(this, BrowserSymbol);
this.isMounted = false;
_define_property(this, "isMounted", false);
_define_property(this, "node", void 0);
this.node = parse(content);
}
var _proto = BrowserSymbol.prototype;
_proto.mount = function mount(target) {
if (this.isMounted) {
return this.node;
}
this.isMounted = true;
target.appendChild(this.node);
return this.node;
};
_proto.unmount = function unmount() {
if (this.node && this.node.parentNode) {
this.node.parentNode.removeChild(this.node);
this.isMounted = false;
}
};
BrowserSymbol.createFromExistingNode = function createFromExistingNode(node) {
var symbol = new BrowserSymbol({
content: ""
});
symbol.node = node;
return symbol;
};
_create_class(BrowserSymbol, [

@@ -41,3 +21,34 @@ {

}
},
{
key: "mount",
value: function mount(target) {
if (this.isMounted) {
return this.node;
}
this.isMounted = true;
target.appendChild(this.node);
return this.node;
}
},
{
key: "unmount",
value: function unmount() {
if (this.node && this.node.parentNode) {
this.node.parentNode.removeChild(this.node);
this.isMounted = false;
}
}
}
], [
{
key: "createFromExistingNode",
value: function createFromExistingNode(node) {
var symbol = new BrowserSymbol({
content: ""
});
symbol.node = node;
return symbol;
}
}
]);

@@ -44,0 +55,0 @@ return BrowserSymbol;

@@ -11,4 +11,6 @@ "use strict";

});
var _classCallCheck = require("@swc/helpers/lib/_class_call_check.js").default;
var _browserSymbol = require("./browser-symbol");
var _class_call_check = require("@swc/helpers/_/_class_call_check");
var _create_class = require("@swc/helpers/_/_create_class");
var _define_property = require("@swc/helpers/_/_define_property");
var _browsersymbol = require("./browser-symbol");
var namespaceURI = "http://www.w3.org/2000/svg";

@@ -19,5 +21,5 @@ var BrowserSprite = /*#__PURE__*/ function() {

var config = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
_classCallCheck(this, BrowserSprite);
this.symbols = new Map();
this.config = {
_class_call_check._(this, BrowserSprite);
_define_property._(this, "symbols", new Map());
_define_property._(this, "config", {
attrs: {

@@ -29,62 +31,81 @@ "xmlns": namespaceURI,

}
};
this.node = null;
});
_define_property._(this, "node", null);
Object.assign(this.config.attrs, config.attrs);
}
var _proto = BrowserSprite.prototype;
_proto.push = function push(symbol) {
var symbols = this.symbols;
var existing = symbols.has(symbol.id);
symbols.set(symbol.id, symbol);
return !existing;
};
_proto.add = function add(symbol) {
var isNewSymbol = this.push(symbol);
if (!!this.node && isNewSymbol) {
symbol.mount(this.node);
_create_class._(BrowserSprite, [
{
key: "push",
value: function push(symbol) {
var symbols = this.symbols;
var existing = symbols.has(symbol.id);
symbols.set(symbol.id, symbol);
return !existing;
}
},
{
key: "add",
value: function add(symbol) {
var isNewSymbol = this.push(symbol);
if (!!this.node && isNewSymbol) {
symbol.mount(this.node);
}
return isNewSymbol;
}
},
{
key: "attach",
value: function attach(target) {
var _this = this;
if (!!this.node) {
return;
}
this.node = target;
// Already added symbols needs to be mounted
this.symbols.forEach(function(symbol) {
symbol.mount(target);
});
// Create symbols from existing DOM nodes, add and mount them
target.querySelectorAll("symbol").forEach(function(symbolNode) {
var symbol = _browsersymbol.BrowserSymbol.createFromExistingNode(symbolNode);
_this.add(symbol);
});
}
},
{
key: "mount",
value: function mount(target) {
var prepend = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
if (!!this.node) {
return this.node;
}
this.node = this.render();
if (prepend && target.childNodes[0]) {
target.insertBefore(this.node, target.firstChild);
} else {
target.appendChild(this.node);
}
return this.node;
}
},
{
key: "render",
value: function render() {
var el = document.createElementNS(namespaceURI, "svg");
Object.entries(this.config.attrs).forEach(function(entry) {
return el.setAttribute(entry[0], entry[1]);
});
this.symbols.forEach(function(symbol) {
return el.appendChild(symbol.node);
});
return el;
}
},
{
key: "unmount",
value: function unmount() {
this.node && this.node.parentNode && this.node.parentNode.removeChild(this.node);
}
}
return isNewSymbol;
};
_proto.attach = function attach(target) {
var _this = this;
if (!!this.node) {
return;
}
this.node = target;
// Already added symbols needs to be mounted
this.symbols.forEach(function(symbol) {
symbol.mount(target);
});
// Create symbols from existing DOM nodes, add and mount them
target.querySelectorAll("symbol").forEach(function(symbolNode) {
var symbol = _browserSymbol.BrowserSymbol.createFromExistingNode(symbolNode);
_this.add(symbol);
});
};
_proto.mount = function mount(target) {
var prepend = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
if (!!this.node) {
return this.node;
}
this.node = this.render();
if (prepend && target.childNodes[0]) {
target.insertBefore(this.node, target.firstChild);
} else {
target.appendChild(this.node);
}
return this.node;
};
_proto.render = function render() {
var el = document.createElementNS(namespaceURI, "svg");
Object.entries(this.config.attrs).forEach(function(entry) {
return el.setAttribute(entry[0], entry[1]);
});
this.symbols.forEach(function(symbol) {
return el.appendChild(symbol.node);
});
return el;
};
_proto.unmount = function unmount() {
this.node && this.node.parentNode && this.node.parentNode.removeChild(this.node);
};
]);
return BrowserSprite;

@@ -91,0 +112,0 @@ }();

@@ -11,4 +11,5 @@ "use strict";

});
var _classCallCheck = require("@swc/helpers/lib/_class_call_check.js").default;
var _createClass = require("@swc/helpers/lib/_create_class.js").default;
var _class_call_check = require("@swc/helpers/_/_class_call_check");
var _create_class = require("@swc/helpers/_/_create_class");
var _define_property = require("@swc/helpers/_/_define_property");
var _parse = require("./utils/parse");

@@ -19,29 +20,8 @@ var BrowserSymbol = /*#__PURE__*/ function() {

var content = param.content;
_classCallCheck(this, BrowserSymbol);
this.isMounted = false;
_class_call_check._(this, BrowserSymbol);
_define_property._(this, "isMounted", false);
_define_property._(this, "node", void 0);
this.node = (0, _parse.parse)(content);
}
var _proto = BrowserSymbol.prototype;
_proto.mount = function mount(target) {
if (this.isMounted) {
return this.node;
}
this.isMounted = true;
target.appendChild(this.node);
return this.node;
};
_proto.unmount = function unmount() {
if (this.node && this.node.parentNode) {
this.node.parentNode.removeChild(this.node);
this.isMounted = false;
}
};
BrowserSymbol.createFromExistingNode = function createFromExistingNode(node) {
var symbol = new BrowserSymbol({
content: ""
});
symbol.node = node;
return symbol;
};
_createClass(BrowserSymbol, [
_create_class._(BrowserSymbol, [
{

@@ -52,3 +32,34 @@ key: "id",

}
},
{
key: "mount",
value: function mount(target) {
if (this.isMounted) {
return this.node;
}
this.isMounted = true;
target.appendChild(this.node);
return this.node;
}
},
{
key: "unmount",
value: function unmount() {
if (this.node && this.node.parentNode) {
this.node.parentNode.removeChild(this.node);
this.isMounted = false;
}
}
}
], [
{
key: "createFromExistingNode",
value: function createFromExistingNode(node) {
var symbol = new BrowserSymbol({
content: ""
});
symbol.node = node;
return symbol;
}
}
]);

@@ -55,0 +66,0 @@ return BrowserSymbol;

@@ -19,8 +19,8 @@ "use strict";

});
var _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default;
var _objectWithoutProperties = require("@swc/helpers/lib/_object_without_properties.js").default;
var _react = _interopRequireDefault(require("react"));
var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
var _object_without_properties = require("@swc/helpers/_/_object_without_properties");
var _react = _interop_require_default._(require("react"));
var IconSettingsContext = /*#__PURE__*/ _react.default.createContext({});
var IconSettingsProvider = function(_param) {
var children = _param.children, settings = _objectWithoutProperties(_param, [
var children = _param.children, settings = _object_without_properties._(_param, [
"children"

@@ -27,0 +27,0 @@ ]);

@@ -13,19 +13,19 @@ "use strict";

BrowserSprite: function() {
return _browserSprite.BrowserSprite;
return _browsersprite.BrowserSprite;
},
BrowserSymbol: function() {
return _browserSymbol.BrowserSymbol;
return _browsersymbol.BrowserSymbol;
},
makeIcon: function() {
return _svgIcon.makeIcon;
return _SvgIcon.makeIcon;
},
IconSettingsProvider: function() {
return _iconSettings.IconSettingsProvider;
return _IconSettings.IconSettingsProvider;
}
});
var _browserSprite = require("./browser-sprite");
var _browserSymbol = require("./browser-symbol");
var _svgIcon = require("./SvgIcon");
var _iconSettings = require("./IconSettings");
var _browsersprite = require("./browser-sprite");
var _browsersymbol = require("./browser-symbol");
var _SvgIcon = require("./SvgIcon");
var _IconSettings = require("./IconSettings");
//# sourceMappingURL=index.js.map

@@ -19,3 +19,3 @@ "use strict";

});
var _browserSprite = require("./browser-sprite");
var _browsersprite = require("./browser-sprite");
var _react = require("react");

@@ -26,3 +26,3 @@ var canUseDOM = !!(typeof window !== "undefined" && window.document && window.document.createElement);

var spriteId = "__SVG_SPRITE_NODE__";
browserSprite = new _browserSprite.BrowserSprite({
browserSprite = new _browsersprite.BrowserSprite({
attrs: {

@@ -29,0 +29,0 @@ id: spriteId

@@ -11,9 +11,9 @@ "use strict";

});
var _extends = require("@swc/helpers/lib/_extends.js").default;
var _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default;
var _objectSpread = require("@swc/helpers/lib/_object_spread.js").default;
var _objectWithoutProperties = require("@swc/helpers/lib/_object_without_properties.js").default;
var _react = _interopRequireDefault(require("react"));
var _browserSymbol = require("./browser-symbol");
var _iconSettings = require("./IconSettings");
var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
var _object_spread = require("@swc/helpers/_/_object_spread");
var _object_spread_props = require("@swc/helpers/_/_object_spread_props");
var _object_without_properties = require("@swc/helpers/_/_object_without_properties");
var _react = _interop_require_default._(require("react"));
var _browsersymbol = require("./browser-symbol");
var _IconSettings = require("./IconSettings");
var _sprite = require("./sprite");

@@ -35,3 +35,3 @@ var _warnOnce = require("./warnOnce");

var SvgIcon = function(_param) {
var _param_width = _param.width, width = _param_width === void 0 ? 0 : _param_width, _param_height = _param.height, height = _param_height === void 0 ? 0 : _param_height, viewBox = _param.viewBox, id = _param.id, _param_className = _param.className, className = _param_className === void 0 ? "" : _param_className, fill = _param.fill, getRootRef = _param.getRootRef, tmp = _param.style, propsStyle = tmp === void 0 ? {} : tmp, title = _param.title, restProps = _objectWithoutProperties(_param, [
var _param_width = _param.width, width = _param_width === void 0 ? 0 : _param_width, _param_height = _param.height, height = _param_height === void 0 ? 0 : _param_height, viewBox = _param.viewBox, id = _param.id, _param_className = _param.className, className = _param_className === void 0 ? "" : _param_className, fill = _param.fill, getRootRef = _param.getRootRef, tmp = _param.style, propsStyle = tmp === void 0 ? {} : tmp, title = _param.title, restProps = _object_without_properties._(_param, [
"width",

@@ -48,3 +48,3 @@ "height",

var size = Math.max(width, height);
var iconSettings = _react.default.useContext(_iconSettings.IconSettingsContext);
var iconSettings = _react.default.useContext(_IconSettings.IconSettingsContext);
var ownClass = iconClass([

@@ -57,10 +57,10 @@ "Icon",

], iconSettings);
var style = _objectSpread({
var style = _object_spread._({
width: width,
height: height
}, propsStyle);
return /*#__PURE__*/ _react.default.createElement("svg", _extends({
return /*#__PURE__*/ _react.default.createElement("svg", _object_spread_props._(_object_spread._({
"aria-hidden": "true",
display: "block"
}, restProps, {
}, restProps), {
className: "".concat(ownClass, " ").concat(className),

@@ -83,3 +83,3 @@ viewBox: viewBox,

if (!isMounted) {
(0, _sprite.addSpriteSymbol)(new _browserSymbol.BrowserSymbol({
(0, _sprite.addSpriteSymbol)(new _browsersymbol.BrowserSymbol({
content: content

@@ -98,3 +98,3 @@ }));

}
return /*#__PURE__*/ _react.default.createElement(SvgIcon, _extends({}, props, {
return /*#__PURE__*/ _react.default.createElement(SvgIcon, _object_spread_props._(_object_spread._({}, props), {
viewBox: viewBox,

@@ -101,0 +101,0 @@ id: id,

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

import _object_without_properties from "@swc/helpers/src/_object_without_properties.mjs";
import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
import React from "react";

@@ -3,0 +3,0 @@ export var IconSettingsContext = /*#__PURE__*/ React.createContext({});

@@ -1,4 +0,4 @@

import _extends from "@swc/helpers/src/_extends.mjs";
import _object_spread from "@swc/helpers/src/_object_spread.mjs";
import _object_without_properties from "@swc/helpers/src/_object_without_properties.mjs";
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
import React from "react";

@@ -47,6 +47,6 @@ import { BrowserSymbol } from "./browser-symbol";

}, propsStyle);
return /*#__PURE__*/ React.createElement("svg", _extends({
return /*#__PURE__*/ React.createElement("svg", _object_spread_props(_object_spread({
"aria-hidden": "true",
display: "block"
}, restProps, {
}, restProps), {
className: "".concat(ownClass, " ").concat(className),

@@ -83,3 +83,3 @@ viewBox: viewBox,

}
return /*#__PURE__*/ React.createElement(SvgIcon, _extends({}, props, {
return /*#__PURE__*/ React.createElement(SvgIcon, _object_spread_props(_object_spread({}, props), {
viewBox: viewBox,

@@ -86,0 +86,0 @@ id: id,

{
"name": "@vkontakte/icons-sprite",
"version": "1.0.1",
"version": "1.1.0",
"homepage": "https://vkcom.github.io/icons/",

@@ -20,3 +20,3 @@ "repository": "https://github.com/VKCOM/icons",

"dependencies": {
"@swc/helpers": "^0.4.14"
"@swc/helpers": "^0.5.0"
},

@@ -27,13 +27,13 @@ "devDependencies": {

"@swc/cli": "^0.1.61",
"@swc/core": "^1.3.35",
"@swc/core": "^1.3.49",
"@swc/jest": "^0.2.24",
"@types/node": "^18.13.0",
"@types/node": "^18.15.11",
"@types/react": "16.14.34",
"concurrently": "^7.6.0",
"jest": "^29.4.2",
"jest-environment-jsdom": "^29.4.2",
"concurrently": "^8.0.1",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"react": "16.14.0",
"size-limit": "^8.1.2",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
"typescript": "^5.0.4"
},

@@ -40,0 +40,0 @@ "peerDependencies": {

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