New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vite-plugin-style-to-vw

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-style-to-vw - npm Package Compare versions

Comparing version 1.1.6 to 1.1.7

2

dist/index.js

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

"use strict";var y=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var P=(t,e)=>{for(var a in e)y(t,a,{get:e[a],enumerable:!0})},b=(t,e,a,l)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of v(e))!V.call(t,i)&&i!==a&&y(t,i,{get:()=>e[i],enumerable:!(l=m(e,i))||l.enumerable});return t};var S=t=>b(y({},"__esModule",{value:!0}),t);var _={};P(_,{default:()=>U});module.exports=S(_);var g={unitToConvert:"px",viewportWidth:750,unitPrecision:5,viewportUnit:"vw",fontViewportUnit:"vw",minPixelValue:1};function M(t,e){let a=Math.pow(10,e+1),l=Math.floor(t*a);return Math.round(l/10)*10/a}function w(t,e,a,l){return function(i,r){if(r=Number(r),!r)return i;let s=parseFloat(r);return s<=e?i:M(s/t*100,a)+l}}var h=/<template>([\s\S]+)<\/template>/gi,o=/(\d+)px/g,p=/style\s*(:|=)\s*(?:"([^"]*?)"|'([^']*?)'|{([^}]*)})/g;function R(t=g){return{name:"vite-plugin-style-to-vw",transform(e,a){if(t=Object.assign(g,t),/.vue$/.test(a)){let l="",i="";if(h.test(e)?(l=e.match(h)[0],i=e.match(h)[0]):e.includes("setup")&&(l=e,i=e),p.test(l)){let r=l.match(p);if(r?.length){let s=[];for(let n=0;n<r.length;n++){let f=r[n].replace(o,c=>c.replace(o,w(t.viewportWidth,t.minPixelValue,t.unitPrecision,t.viewportUnit)));s.push(f)}let u=l;for(let n=0;n<r.length;n++)u=u.replace(r[n],`${s[n]}`);e=e.replace(i,u)}}}else if(/\.tsx|\.jsx$/.test(a)){let l=e,i=e;if(p.test(l)){let r=l.match(p);if(r?.length){let s=[];for(let n=0;n<r.length;n++){let f=r[n].replace(o,c=>c.replace(o,w(t.viewportWidth,t.minPixelValue,t.unitPrecision,t.viewportUnit)));s.push(f)}let u=l;for(let n=0;n<r.length;n++)u=u.replace(r[n],`${s[n]}`);e=e.replace(i,u)}}}return{code:e}}}}var U=R;0&&(module.exports={});
"use strict";var y=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var P=(t,e)=>{for(var a in e)y(t,a,{get:e[a],enumerable:!0})},b=(t,e,a,l)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of v(e))!V.call(t,i)&&i!==a&&y(t,i,{get:()=>e[i],enumerable:!(l=x(e,i))||l.enumerable});return t};var S=t=>b(y({},"__esModule",{value:!0}),t);var _={};P(_,{default:()=>U});module.exports=S(_);var g={unitToConvert:"px",viewportWidth:750,unitPrecision:5,viewportUnit:"vw",fontViewportUnit:"vw",minPixelValue:1};function M(t,e){let a=Math.pow(10,e+1),l=Math.floor(t*a);return Math.round(l/10)*10/a}function w(t,e,a,l){return function(i,r){if(r=Number(r),!r)return i;let s=parseFloat(r);return s<=e?i:M(s/t*100,a)+l}}var h=/<template>([\s\S]+)<\/template>/gi,o=/(\d+)px/g,p=/style\s*(:|=)\s*(?:"([^"]*?)"|'([^']*?)'|{([^}]*)})/g;function R(t=g){return{name:"vite-plugin-style-to-vw",transform(e,a){if(t=Object.assign(g,t),/.vue$/.test(a)){let l="",i="";if(h.test(e)?(l=e.match(h)[0],i=e.match(h)[0]):e.includes("setup")&&(l=e,i=e),p.test(l)){let r=l.match(p);if(r?.length){let s=[];for(let n=0;n<r.length;n++){let f=r[n].replace(o,c=>c.replace(o,w(t.viewportWidth,t.minPixelValue,t.unitPrecision,t.viewportUnit)));s.push(f)}let u=l;for(let n=0;n<r.length;n++)u=u.replace(r[n],`${s[n]}`);e=e.replace(i,u)}}}else if(/\.tsx|\.jsx$/.test(a)){let l=e,i=e;if(p.test(l)){let r=l.match(p);if(r?.length){let s=[];for(let n=0;n<r.length;n++){let f=r[n].replace(o,c=>c.replace(o,w(t.viewportWidth,t.minPixelValue,t.unitPrecision,t.viewportUnit)));s.push(f)}let u=l;for(let n=0;n<r.length;n++)u=u.replace(r[n],`${s[n]}`);e=e.replace(i,u)}}}return{code:e,map:null}}}}var U=R;0&&(module.exports={});
{
"name": "vite-plugin-style-to-vw",
"version": "1.1.6",
"version": "1.1.7",
"description": "一个可以将签内样式px转换vw的plugin",

@@ -5,0 +5,0 @@ "exports": {

@@ -27,3 +27,3 @@ import type { IdefaultsProp } from './index.d'

) {
return function ($0:any, $1:any) {
return function ($0: any, $1: any) {
$1 = Number($1)

@@ -46,3 +46,3 @@ if (!$1) return $0;

// 构建阶段的通用钩子:在每个传入模块请求时被调用:在每个传入模块请求时被调用,主要是用来转换单个模块
transform(code:any, id:any) {
transform(code: any, id: any) {
customOptions = Object.assign(defaultsProp, customOptions)

@@ -56,3 +56,3 @@ if (/.vue$/.test(id)) {

_sourceCopy = code.match(templateReg)[0]
} else if(code.includes('setup')) {
} else if (code.includes('setup')) {
_source = code

@@ -64,6 +64,6 @@ _sourceCopy = code

const styleMatches = _source.match(styleRegex) as string[]
if(styleMatches?.length) {
if (styleMatches?.length) {
// 遍历每个 style 属性值,替换 px 为 vw
const newStyleValues:string[] = []
const newStyleValues: string[] = []
for (let i = 0; i < styleMatches.length; i++) {

@@ -94,8 +94,8 @@ const styleValue = styleMatches[i]

code = code.replace(_sourceCopy, newStr)
}
}
}else if(/\.tsx|\.jsx$/.test(id)) {
} else if (/\.tsx|\.jsx$/.test(id)) {
const _source = code

@@ -105,5 +105,5 @@ const _sourceCopy = code

const styleMatches = _source.match(styleRegex) as string[]
if(styleMatches?.length) {
if (styleMatches?.length) {
// 遍历每个 style 属性值,替换 px 为 vw
const newStyleValues:string[] = []
const newStyleValues: string[] = []
for (let i = 0; i < styleMatches.length; i++) {

@@ -132,7 +132,10 @@ const styleValue = styleMatches[i]

}
}
}
return { code }
return {
code,
map: null, // Prevent missing sourcemap warning
}
},

@@ -139,0 +142,0 @@

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