Skip to content

Commit

Permalink
fix: 修改因css注入让第一个元素并非跳过转化标识导致的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-lau committed Jul 24, 2024
1 parent 76f47d6 commit 6ee2ed1
Show file tree
Hide file tree
Showing 4 changed files with 4,301 additions and 2,151 deletions.
89 changes: 13 additions & 76 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,5 @@
'use strict';

function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}

function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}

function _iterableToArrayLimit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];

if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;

var _s, _e;

try {
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);

if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}

return _arr;
}

function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}

function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;

for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];

return arr2;
}

function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}

/**@typedef {{baseSize: {rem:number,vw:number},unitPrecision: number,selectorBlackList: string[],propList: string[],minPixelValue: number,exclude: string|RegExp|()=>boolean ,commentOfDisableAll:string,commentOfDisableRem:string,commentOfDisableVW:string}} Options */

/**
Expand Down Expand Up @@ -261,28 +202,24 @@ var converter = function converter() {

var remRootValue = baseSize.rem;
var vwRootValue = baseSize.vw;

var _css$nodes = _slicedToArray(css.nodes, 1),
firstNode = _css$nodes[0];

remReplace = createPxReplacer(remRootValue, minPixelValue, unitPrecision, 'rem');
vwReplace = createPxReplacer(vwRootValue, minPixelValue, unitPrecision, 'vw');
vwReplace = createPxReplacer(vwRootValue, minPixelValue, unitPrecision, 'vw'); // whole file

if (firstNode && firstNode.type === 'comment') {
// whole file
if (firstNode.text.trim() === commentOfDisableAll) {
isExcludeFile = true;
} // not convert rem
isExcludeFile = css.nodes.some(function (item) {
return item.type === 'comment' && item.text.trim() === commentOfDisableAll;
}); // not convert rem

if (isExcludeFile || css.nodes.some(function (item) {
return item.type === 'comment' && item.text.trim() === commentOfDisableRem;
})) {
remReplace = null;
} // not convert vw

if (isExcludeFile || firstNode.text.trim() === commentOfDisableRem) {
remReplace = null;
} // not convert vw


if (isExcludeFile || firstNode.text.trim() === commentOfDisableVW) {
vwReplace = null;
}
if (isExcludeFile || css.nodes.some(function (item) {
return item.type === 'comment' && item.text.trim() === commentOfDisableVW;
})) {
vwReplace = null;
}
},
Declaration: function Declaration(decl) {
Expand Down
Loading

0 comments on commit 6ee2ed1

Please sign in to comment.