xhs-mp-compiler-utils 2.0.21 → 2.0.22

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.js CHANGED
@@ -1,2 +1 @@
1
1
  "use strict";var e=require("path");var t,s;exports.CompileCallRuntimeMethodsNames=void 0,(t=exports.CompileCallRuntimeMethodsNames||(exports.CompileCallRuntimeMethodsNames={})).ExecExpWithContext="x0",t.CalcClass="x1",t.Rpx2vw="x2",t.RunModuleUpdater="x3",exports.CompileAddedAttrs=void 0,(s=exports.CompileAddedAttrs||(exports.CompileAddedAttrs={})).OwnerId="xhs__i",s.EventMap="xhs__p",s.ComponentIndex="xhs__c",s.ComponentId="xhs__id",s.ComponentOwnerId="xhs__oid",s.MLPath="xhs__mlpath";const o=(e,t)=>{const s=10**(t+1),o=Math.floor(e*s);return 10*Math.round(o/10)/s};const r=/([\d.]+)rpx/g;function n(){var e;return null===(e=process.env.__platform||"xhs")||void 0===e?void 0:e.trim()}function p(){return`${n()}ml`.trim()}const x=(t="")=>t.split(e.sep).join(e.posix.sep);exports.COMPILE_CALL_RUNTIME="$__t",exports.RPX_REGEX=r,exports.calcRpx2Vw=(e,t=750,s=5,r="vw")=>o(parseFloat(`${e}`)/t*100,s)+r,exports.getCssSuffixName=function(){return"xhs"===n()?"css":"wxss"},exports.getIDEMessage=e=>{const{message:t="",file:s,line:o,column:r,type:n,prefix:p,errorLines:x=[]}=e;return["\n<xhsml!",`[${n}:${p}]:[file:${s}]`,`第${o}行, 第${r}列 ${null==t?void 0:t.trim()}`,...x,"!xhsml>\n"].join("\n")},exports.getMlSuffixName=p,exports.getPlatform=n,exports.getShortPath=(e,t)=>{const s=p();e=(e=x(e)).endsWith("/")?e:`${e}/`;const o=new RegExp(`.${s}$`,"g");return x(t).replace(o,"").replace(e,"")},exports.isRpxValue=e=>!(!e||!(null==e?void 0:e.match(r))||(null==e?void 0:e.startsWith("'"))||(null==e?void 0:e.startsWith('"'))||(null==e?void 0:e.startsWith("url"))),exports.rpx2vwll=function(e){return e.replace(/([\d.]+)rpx/g,((e,t)=>`${o(t/750*100,5)}vw`))},exports.toFixed=o,exports.toUnixPath=x,exports.unixJoin=(...t)=>x(e.join(...t)),exports.unixResolve=(...t)=>x(e.resolve(...t));
2
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xhs-mp-compiler-utils",
3
- "version": "2.0.21",
3
+ "version": "2.0.22",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../src/constants/constants.ts","../src/utils/utils.ts","../src/utils/platform.ts","../src/utils/path.ts","../src/utils/ideError.ts"],"sourcesContent":["/**\n * FBI Warning!\n * `COMPILE_CALL_RUNTIME` `CompileCallRuntimeMethodsNames` `CompileAddedAttrs`\n * 这三个变量是构建与运行时产生耦合的位置:\n * 变量值的变更将产生 break change\n * 新增变量需要向前兼容\n */\n\nconst COMPILE_CALL_RUNTIME = '$__t'\n\nenum CompileCallRuntimeMethodsNames {\n ExecExpWithContext = 'x0',\n CalcClass = 'x1',\n Rpx2vw = 'x2',\n RunModuleUpdater = 'x3',\n}\n\nenum CompileAddedAttrs {\n OwnerId = 'xhs__i',\n EventMap = 'xhs__p',\n ComponentIndex = 'xhs__c',\n // 2.0新增用于描述节点之间关系\n ComponentId = 'xhs__id',\n ComponentOwnerId = 'xhs__oid',\n // 用于标记模板位置\n MLPath = 'xhs__mlpath',\n}\n\nexport { COMPILE_CALL_RUNTIME, CompileCallRuntimeMethodsNames, CompileAddedAttrs }\n","export const toFixed = (number: number, precision: number) => {\n const multiplier = 10 ** (precision + 1)\n const wholeNumber = Math.floor(number * multiplier)\n return (Math.round(wholeNumber / 10) * 10) / multiplier\n}\n\nexport function rpx2vwll(styleStr: string) {\n return styleStr.replace(/([\\d.]+)rpx/g, (m, $1) => `${toFixed(($1 / 750) * 100, 5)}vw`)\n}\n\nexport const RPX_REGEX = /([\\d.]+)rpx/g\n\nexport const calcRpx2Vw = (pixels: any, baseWidth = 750, unitPrecision = 5, outputUnit = 'vw') =>\n toFixed((parseFloat(`${pixels}`) / baseWidth) * 100, unitPrecision) + outputUnit\n\nexport const isRpxValue = (cssValue: string) => {\n if (\n !cssValue ||\n !cssValue?.match(RPX_REGEX) ||\n cssValue?.startsWith('\\'') ||\n cssValue?.startsWith('\"') ||\n cssValue?.startsWith('url')\n ) return false\n\n return true\n}","export function getPlatform() : 'xhs' | 'wx' {\n return (process.env.__platform || 'xhs')?.trim() as any\n}\n\nexport function getCssSuffixName() {\n return getPlatform() === 'xhs' ? 'css' : 'wxss'\n}\n\nexport function getMlSuffixName() {\n return `${getPlatform()}ml`.trim()\n}","import path from 'path'\nimport { getMlSuffixName } from \"./platform\"\n\nexport const toUnixPath = (pathStr: string = '') => pathStr.split(path.sep).join(path.posix.sep)\n\nexport const unixJoin = (...paths: string[]) => toUnixPath(path.join(...paths))\n\nexport const unixResolve = (...paths: string[]) => toUnixPath(path.resolve(...paths))\n\nexport const getShortPath = (miniprogramDir: string, rootContext: string): string => {\n const suffix = getMlSuffixName()\n miniprogramDir = toUnixPath(miniprogramDir)\n miniprogramDir = miniprogramDir.endsWith('/') ? miniprogramDir : `${miniprogramDir}/`\n const reg = new RegExp(`.${suffix}$`, 'g')\n return toUnixPath(rootContext).replace(reg, '').replace(miniprogramDir, '')\n}\n","\n\n/**\n * 生成IDE友好的错误信息\n * @param options\n * @param options.type 类型 // warning | error\n * @param options.prefix 错误前缀 // 文件编译错误 、xhsml编译错误、警告 等等\n * @param options.message 错误信息 // TS7006: Parameter 'e' implicitly has an 'any' type.\n * @param options.errorLines 错误行 // 错误前后几行\n * @param options.file 文件路径 \n * @param options.line 行 // 行列用于IDE聚焦错误位置\n * @param options.column 列\n * @returns\n */\nexport const getIDEMessage = (options: {\n type: 'warning' | 'error',\n prefix: string,\n message: string, // 错误信息\n errorLines: string[],\n file: string,\n line: number,\n column: number,\n}) => {\n const {message = '', file, line, column, type, prefix, errorLines=[]} = options\n return [\n '\\n<xhsml!',\n `[${type}:${prefix}]:[file:${file}]`,\n `第${line}行, 第${column}列 ${message?.trim()}`,\n ...errorLines,\n '!xhsml>\\n'\n ].join('\\n')\n}"],"names":["CompileCallRuntimeMethodsNames","CompileAddedAttrs","toFixed","number","precision","multiplier","wholeNumber","Math","floor","round","RPX_REGEX","getPlatform","_a","process","env","__platform","trim","getMlSuffixName","toUnixPath","pathStr","split","path","sep","join","posix","pixels","baseWidth","unitPrecision","outputUnit","parseFloat","options","message","file","line","column","type","prefix","errorLines","miniprogramDir","rootContext","suffix","endsWith","reg","RegExp","replace","cssValue","match","startsWith","styleStr","m","$1","paths","resolve"],"mappings":"mCAUA,IAAKA,EAOAC,EAPAD,QAKJA,oCAAA,GALIA,EAAAA,yCAAAA,QAAAA,+BAKJ,CAAA,IAJC,mBAAA,KACAA,EAAA,UAAA,KACAA,EAAA,OAAA,KACAA,EAAA,iBAAA,KAGGC,QASJA,uBAAA,GATIA,EAAAA,QAAiBA,oBAAjBA,0BASJ,CAAA,IARC,QAAA,SACAA,EAAA,SAAA,SACAA,EAAA,eAAA,SAEAA,EAAA,YAAA,UACAA,EAAA,iBAAA,WAEAA,EAAA,OAAA,oBCzBWC,EAAU,CAACC,EAAgBC,KACtC,MAAMC,EAAa,KAAOD,EAAY,GAChCE,EAAcC,KAAKC,MAAML,EAASE,GACxC,OAAuC,GAA/BE,KAAKE,MAAMH,EAAc,IAAYD,CAAU,EAOlD,MAAMK,EAAY,wBCVTC,UACZ,OAA0C,QAAnCC,EAACC,QAAQC,IAAIC,YAAc,aAAQ,IAAAH,OAAA,EAAAA,EAAAI,MAC9C,UAMgBC,IACZ,MAAO,GAAGN,QAAkBK,MAChC,CCPa,MAAAE,EAAa,CAACC,EAAkB,KAAOA,EAAQC,MAAMC,EAAKC,KAAKC,KAAKF,EAAKG,MAAMF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