@melt-js/libs-core 2026.11.16-1 → 2026.11.16-2

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.
Files changed (90) hide show
  1. package/README.md +38 -22
  2. package/dist/browser.d.mts +3 -3
  3. package/dist/browser.mjs +1 -1
  4. package/dist/browser.mjs.gz +0 -0
  5. package/dist/cdn/browser.umd.cjs +1 -1
  6. package/dist/cdn/browser.umd.cjs.gz +0 -0
  7. package/dist/cdn/demo-browser.umd.cjs +1 -1
  8. package/dist/cdn/demo-browser.umd.cjs.gz +0 -0
  9. package/dist/cdn/demo.umd.cjs +1 -1
  10. package/dist/cdn/demo.umd.cjs.gz +0 -0
  11. package/dist/cdn/example-esm.html +1 -1
  12. package/dist/cdn/index.umd.cjs +1 -1
  13. package/dist/cdn/index.umd.cjs.gz +0 -0
  14. package/dist/cdn/manifest.json +17 -5
  15. package/dist/cdn/vendor.umd.cjs +0 -34
  16. package/dist/cdn/vendor.umd.cjs.gz +0 -0
  17. package/dist/cdn.d.mts +3 -3
  18. package/dist/cdn.mjs +1 -1
  19. package/dist/demo/browser.d.mts +1 -0
  20. package/dist/demo/browser.mjs +1 -1
  21. package/dist/demo/browser.mjs.gz +0 -0
  22. package/dist/demo/clipboard.d.mts +6 -6
  23. package/dist/demo/clipboard.mjs +1 -1
  24. package/dist/demo/docs.d.mts +28 -28
  25. package/dist/demo/docs.mjs +1 -1
  26. package/dist/demo/docs.mjs.gz +0 -0
  27. package/dist/demo/download.d.mts +3 -0
  28. package/dist/demo/download.mjs +1 -1
  29. package/dist/demo/download.mjs.gz +0 -0
  30. package/dist/demo/fullscreen.d.mts +8 -8
  31. package/dist/demo/fullscreen.mjs +1 -1
  32. package/dist/demo/highlight.d.mts +2 -0
  33. package/dist/demo/highlight.mjs +1 -0
  34. package/dist/demo/index.d.mts +1 -0
  35. package/dist/demo/index.mjs +1 -1
  36. package/dist/demo/model.d.mts +12 -12
  37. package/dist/demo/remote-debug.d.mts +9 -11
  38. package/dist/demo/remote-debug.mjs +1 -1
  39. package/dist/demo/split-pane.d.mts +8 -8
  40. package/dist/demo/split-pane.mjs +1 -1
  41. package/dist/demo/standalone.d.mts +3 -0
  42. package/dist/demo/standalone.mjs +1 -1
  43. package/dist/demo/standalone.mjs.gz +0 -0
  44. package/dist/demo/tabs.d.mts +15 -15
  45. package/dist/demo/tabs.mjs +1 -1
  46. package/dist/loading.mjs +1 -1
  47. package/dist/loading.mjs.gz +0 -0
  48. package/dist/remote.d.mts +114 -110
  49. package/dist/remote.mjs +1 -1
  50. package/dist/remote.mjs.gz +0 -0
  51. package/dist/vendor/hel-runtime.mjs +0 -34
  52. package/dist/vendor/hel-runtime.mjs.gz +0 -0
  53. package/package.json +1 -1
  54. package/scripts/browser-formats.mjs +8 -6
  55. package/scripts/build-browser.mjs +2 -2
  56. package/scripts/build-protected-esm.mjs +54 -51
  57. package/scripts/cdn-runtime.cjs +30 -30
  58. package/scripts/client-build-security.cjs +48 -48
  59. package/scripts/component-events.mjs +57 -57
  60. package/scripts/comps-bundle-obfuscation.cjs +4 -1
  61. package/scripts/comps-obfuscator-options.cjs +7 -1
  62. package/scripts/obfuscator-split-strings.cjs +22 -0
  63. package/scripts/package-artifacts.mjs +3 -3
  64. package/scripts/package-env.cjs +46 -90
  65. package/scripts/remote-address.cjs +30 -30
  66. package/scripts/vdoc-parser/NOTICE.md +13 -13
  67. package/scripts/vdoc-parser/constants.mjs +3 -3
  68. package/scripts/vdoc-parser/index.d.mts +34 -34
  69. package/scripts/vdoc-parser/index.mjs +2 -2
  70. package/scripts/vdoc-parser/parsers/index.mjs +14 -14
  71. package/scripts/vdoc-parser/parsers/parseCode.mjs +42 -42
  72. package/scripts/vdoc-parser/parsers/parseCommentBlock.mjs +9 -9
  73. package/scripts/vdoc-parser/parsers/parseComponentOptions.mjs +12 -12
  74. package/scripts/vdoc-parser/parsers/parseDefaultValue.mjs +57 -57
  75. package/scripts/vdoc-parser/parsers/parseDefineProps.mjs +33 -33
  76. package/scripts/vdoc-parser/parsers/parseExport.mjs +93 -93
  77. package/scripts/vdoc-parser/parsers/parseFile.mjs +22 -22
  78. package/scripts/vdoc-parser/parsers/parseFileSync.mjs +22 -22
  79. package/scripts/vdoc-parser/parsers/parsePropType.mjs +32 -32
  80. package/scripts/vdoc-parser/parsers/parseProps.mjs +90 -90
  81. package/scripts/vdoc-parser/parsers/parseSetupScript.mjs +14 -14
  82. package/scripts/vdoc-parser/parsers/parseSfc.mjs +21 -21
  83. package/scripts/vdoc-parser/parsers/parseTSTypeLiteral.mjs +48 -48
  84. package/scripts/vdoc-parser/parsers/parseTypes.mjs +53 -53
  85. package/scripts/vdoc-parser/parsers/parseTypesFile.mjs +22 -22
  86. package/scripts/vdoc-parser/parsers/parseTypesFileSync.mjs +22 -22
  87. package/scripts/vdoc-parser/resolvers/index.mjs +2 -2
  88. package/scripts/vdoc-parser/resolvers/resolveSpreadElements.mjs +51 -51
  89. package/scripts/vdoc-parser/utils.mjs +52 -52
  90. package/scripts/webpack-bundle-obfuscation.cjs +3 -1
@@ -14,37 +14,3 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
14
14
  please check your network if this behavior is not as you expected! you can also set enableDiskCacheForErr = false
15
15
  to skip reusing cached data.
16
16
  `)),u.label=5;case 5:return[2,{data:o,err:s}];case 6:return[2]}})})}function Io(r,e){return T(this,void 0,void 0,function(){var t,a,n,i,s,o,u;return P(this,function(c){switch(c.label){case 0:return t=wa(e.platform,e.apiMode),a=t.platform,n=t.apiMode,i=R(R({},e),{platform:a,apiMode:n}),[4,Jr(r,i)];case 1:if(s=c.sent(),o=s.app,u=s.version,ze("[[ getAppAndVersion ]] result:",{app:o,version:u}),!u)throw new Error("no version found or builded");return[2,{appInfo:o,appVersion:u}]}})})}function we(r,e){var t=e.appVersion,a=e.platform,n=e.toDisk,i=n===void 0?!0:n,s=e.loadOptions;if(!(!r||!t)){var o=r,u=o.name;if(i){var c=Yr(u,s.getCacheKey),f={app:r,version:t};Js(c,f,s.storageType)}if(s.semverApi){var p=(0,l.getAppMeta)(u,a);p?.__setByLatest!==!0&&(o=s.versionId?o:R(R({},o),{__setByLatest:!0}),(0,l.setAppMeta)(o,a))}else(0,l.setAppMeta)(r,a);(0,l.setVersion)(u,t,{platform:a});var v=ya(s),d=t.version_tag||t.sub_app_version;(0,l.setVerExtraCssList)(u,v,{platform:a,versionId:d})}}function Co(r,e){return T(this,void 0,void 0,function(){var t,a,n,i,s;return P(this,function(o){switch(o.label){case 0:return t=e.platform,a=e.loadOptions,[4,Io(r,e)];case 1:return n=o.sent(),i=n.appInfo,s=n.appVersion,we(i,{appVersion:s,platform:t,loadOptions:a}),[2,n]}})})}function Fa(r,e){return e===void 0&&(e={}),T(this,void 0,Promise,function(){var t,a,n,i,s,o,u,c,f,p,v,d,h,m,g,b,S,_,A,I,M=this;return P(this,function(y){switch(y.label){case 0:t=e.isFirstCall,a=t===void 0?!0:t,n=e.controlLoadAssets,i=n===void 0?!1:n,s=e.platform,o=e.versionId,u=o===void 0?"":o,y.label=1;case 1:return y.trys.push([1,6,,9]),[4,Eo(r,e)];case 2:return c=y.sent(),f=c.data,p=c.err,v=f||{},d=v.appInfo,h=v.appVersion,m=!d||!h,g=!1,m&&!a?(b=Ra(e),b?[4,Promise.resolve(b({platform:s,appName:r,versionId:u}))]:[3,4]):[3,4];case 3:S=y.sent(),S&&(d=S.app,h=S.version,g=!0,we(d,{appVersion:h,platform:ae(s),toDisk:!1,loadOptions:e})),y.label=4;case 4:if(!d)throw new Error(p||"app[".concat(r,"] not exist"));if(!h)throw new Error(p||"app[".concat(r,"]'s version[").concat(u,"] not exist"));return oa.tryTriggerOnFetchMetaSuccess(d,h,{loadOptions:e,fromFallback:g}),oa.recordAssetCtx(d,h,e),_=function(){return T(M,void 0,void 0,function(){return P(this,function(V){switch(V.label){case 0:return[4,bo(d,h,e)];case 1:return V.sent(),[2]}})})},i?[2,_]:[4,_()];case 5:return y.sent(),[2,null];case 6:return A=y.sent(),a?(console.error("loadApp err and try one more time: ",A),[4,Fa(r,R(R({},e),{isFirstCall:!1}))]):[3,8];case 7:return I=y.sent(),[2,I];case 8:throw new Error("loadApp [".concat(r,"] err (").concat(A.message,"), recommend config onFetchMetaFailed hook"));case 9:return[2]}})})}function To(r,e){return T(this,void 0,Promise,function(){var t;return P(this,function(a){switch(a.label){case 0:return[4,fo(r,e)];case 1:return t=a.sent(),[2,t]}})})}function Po(r,e){return T(this,void 0,Promise,function(){var t,a,n,i,s,o,u,c,f,p;return P(this,function(v){switch(v.label){case 0:return t=e||{},a=t.versionId,n=t.projectId,i=t.branchId,s=t.platform,o=t.reuseCache,u=o===void 0?!0:o,u&&!a&&!n&&!i&&(f=(0,l.getAppMeta)(r,s),p=(0,l.getVersion)(r,{platform:s}),f&&p&&(c={app:f,version:p})),c?[3,2]:[4,Jr(r,e||{})];case 1:c=v.sent(),v.label=2;case 2:return[2,c]}})})}function Mo(r,e){var t=e||{},a=t.versionId,n=t.platform,i=t.apiMode,s=i===void 0?Re:i,o=t.protocol,u=o===void 0?"http":o,c=t.projectId,f=t.branchId,p=t.semverApi,v=p===void 0?!0:p,d=qr(r,{platform:n,versionId:a,branchId:f,apiMode:s,projectId:c,semverApi:v}).url;return u==="http"&&(d=d.replace("https:","http:")),d}function Do(r,e,t){return T(this,void 0,void 0,function(){var a;return P(this,function(n){switch(n.label){case 0:return Array.isArray(r)?(a=[],r.forEach(function(i){return a.push(ua(i,e,t))}),[4,Promise.all(a)]):[3,2];case 1:return n.sent(),[3,4];case 2:return[4,ua(r,e,t)];case 3:n.sent(),n.label=4;case 4:return[2]}})})}var Oa=Object.freeze({__proto__:null,getSubAppVersion:To,getSubAppMeta:Po,getMetaDataUrl:Mo,clearDiskCachedApp:Do});function ja(r,e){var t=(0,l.getVersion)(r,e);return t?.src_map.webDirPath||""}function ye(r,e){var t=e||{},a=ae(t.platform),n=t.versionId||"";if(!n){var i=(0,l.getVersion)(r,{platform:a});if(i)n=i.version_tag||i.sub_app_version;else{var s=(0,l.getAppMeta)(r,a);n=s?.online_version||s?.build_version||""}}return{platform:a,versionId:n}}function Vo(r,e){var t={static:[],build:[]},a=(0,l.getVersion)(r,e);if(a){var n=a.src_map,i=n.webDirPath,s=n.chunkCssSrcList;s.forEach(function(o){o.startsWith(i)?t.build.push(o):t.static.push(o)})}return t}var xo=ja,ka=Object.freeze({__proto__:null,getPlatAndVer:ye,getGroupedStyleList:Vo,getWebDirPath:xo}),ca=l.helConsts.KEY_CSS_STR,et=l.helLoadStatus,Ua=et.LOADED,la=et.LOADING,Ro=et.NOT_LOAD,Xe=l.commonUtil.merge2List,Dr=(0,l.getHelEventBus)(),Vr=l.helEvents.STYLE_STR_FETCHED,ue={isStyleStatusMatch:function(r,e,t){var a=ye(r,t),n=a.platform,i=a.versionId,s=(0,l.getVerStyleStrStatus)(r,{platform:n,versionId:i});return s===e},getSelfCssList:function(r,e){var t=ye(r,e),a=(0,l.getVersion)(r,t),n=(0,l.getVerExtraCssList)(r,t),i=[],s=[];if(a){var o=a.src_map||{},u=o.chunkCssSrcList,c=u===void 0?[]:u,f=o.headAssetList,p=f===void 0?[]:f,v=o.bodyAssetList,d=v===void 0?[]:v;i=c;var h=function(g){var b=[];return g.forEach(function(S){var _=S.append,A=_===void 0?!0:_,I=S.attrs.href||"";I.endsWith(".css")&&A&&b.push(I)}),b},m=Xe(h(p),h(d));s=Xe(m,i)}return s=Xe(s,n),{buildCssList:i,initExtraCssList:n,appCssList:s}},fetchStyleStr:function(r){return T(this,void 0,void 0,function(){var e,t,a,n,i,s,o;return P(this,function(u){switch(u.label){case 0:e="",t=0,a=r.length,u.label=1;case 1:if(!(t<a))return[3,7];if(n=r[t],!n.endsWith(".css"))return[3,6];if(i=(0,l.getCommonData)(ca,n),i)return[3,5];u.label=2;case 2:return u.trys.push([2,4,,5]),[4,Ne(n,!1)];case 3:return s=u.sent(),i=s.reply,(0,l.setCommonData)(ca,n,i),[3,5];case 4:return o=u.sent(),console.error(o),[3,5];case 5:e+=i,u.label=6;case 6:return t++,[3,1];case 7:return[2,e]}})})},waitStyleReady:function(r,e){return T(this,void 0,void 0,function(){var t;return P(this,function(a){switch(a.label){case 0:return t=null,[4,new Promise(function(n){t=function(i){var s=i.appName,o=i.platform,u=i.versionId,c=e.branchId,f=e.versionId,p=e.platform,v=e.strictMatchVer;s!==r||o!==p||!Zr(r,{branchId:c,platform:p,emitVer:u,inputVer:f,strictMatchVer:v})||n(!0)},Dr.on(Vr,t)})];case 1:return a.sent(),t&&Dr.off(Vr,t),[2]}})})},computeStyleData:function(r,e){var t=ye(r,e),a=ue.getSelfCssList(r,e),n=a.appCssList,i=a.buildCssList,s=a.initExtraCssList,o=e.extraCssList,u=o===void 0?[]:o,c=e.getExcludeCssList,f=Xe(n,u),p=c?.(f,{version:(0,l.getVersion)(r,t)})||[],v=!p.length&&!u.length,d=f;return p.length&&(d=f.filter(function(h){return!p.includes(h)})),{validCssList:d,onlyUseAppCssList:v,buildCssList:i,initExtraCssList:s,appCssList:n}},fetchStyleData:function(r,e){return T(this,void 0,void 0,function(){var t,a,n,i,s,o,u,c,f,p,v,d,h,m,g,b,S,_;return P(this,function(A){switch(A.label){case 0:return t=ye(r,e),a=e.extraStyleStr,n=a===void 0?"":a,i=e.cssListToStr,s=e.extraCssList,o=s===void 0?[]:s,u=e.strictMatchVer,c=e.branchId,f=ue.computeStyleData(r,e),p=f.validCssList,v=f.onlyUseAppCssList,d=f.buildCssList,h=f.initExtraCssList,m=f.appCssList,g={validCssList:p,buildCssList:d,initExtraCssList:h,appCssList:m,extraCssList:o,extraStyleStr:n,renderStyleStr:""},i?v?(b=(0,l.getVerStyleStrStatus)(r,t),S="",b!==la?[3,2]:[4,ue.waitStyleReady(r,R(R({},t),{strictMatchVer:u,branchId:c}))]):[3,6]:[2,g];case 1:return A.sent(),S=(0,l.getAppStyleStr)(r,t)||"",[3,5];case 2:return b!==Ro?[3,4]:((0,l.setVerStyleStrStatus)(r,la,t),[4,ue.fetchStyleStr(m)]);case 3:return S=A.sent(),(0,l.setAppStyleStr)(r,S,t),(0,l.setVerStyleStrStatus)(r,Ua,t),Dr.emit(Vr,R({appName:r},t)),[3,5];case 4:S=(0,l.getAppStyleStr)(r,t)||"",A.label=5;case 5:return g.renderStyleStr="".concat(S).concat(n),[3,8];case 6:return[4,ue.fetchStyleStr(p)];case 7:_=A.sent(),g.renderStyleStr="".concat(_).concat(n),A.label=8;case 8:return[2,g]}})})}};function wo(r,e){return T(this,void 0,Promise,function(){var t;return P(this,function(a){switch(a.label){case 0:return[4,ue.fetchStyleData(r,e||{})];case 1:return t=a.sent(),[2,t]}})})}function No(r,e){var t=ye(r,e),a=(0,l.getAppStyleStr)(r,t);return a}function Fo(r,e){var t=ue.getSelfCssList(r,e||{});return t}function Oo(r){return T(this,void 0,void 0,function(){var e;return P(this,function(t){switch(t.label){case 0:return[4,ue.fetchStyleStr(r)];case 1:return e=t.sent(),[2,e]}})})}function jo(r,e){return ue.isStyleStatusMatch(r,Ua,e||{})}function ko(r){var e=(0,l.getGlobalThis)();if(e.document){var t=e.document.querySelectorAll('style[data-gname="'.concat(r,'"]'));t.forEach(l.commonUtil.disableNode)}}function Uo(r){var e=l.commonDataUtil.getStyleTagText(r);return e}function Bo(r,e){var t=rt(r,e),a=l.commonDataUtil.getIgnoreCssPrefixCssUrlList(t)||[];return a}function rt(r,e){var t=(e||{}).custom||{},a="",n=t.host,i=t.enable,s=i===void 0?!0:i;if(n&&s)if(n.endsWith(".json")||n.endsWith(".html")){var o=n.split("/"),u=o.length;o.splice(u-1,u),a=o.join("/")}else a=n;else a=ja(r,e);return a}var Ba=Object.freeze({__proto__:null,fetchAppStyleData:wo,getAppStyleStr:No,getAppCssList:Fo,fetchStyleByUrlList:Oo,isStyleFetched:jo,disableStyleTags:ko,getStyleTagText:Uo,getIgnoredCssUrlList:Bo,getSuitableCssPrefix:rt});function Ha(r,e,t){var a=t.platform,n=(0,l.getAppMeta)(e,a);if(!n){var i=(0,l.getAppMeta)(r,a),s=(0,l.getVersion)(r,t);if(i&&s){(0,l.setAppMeta)(R(R({},i),{name:e,__addedByTrust:!0}),a),(0,l.setVersion)(e,R(R({},s),{sub_app_name:e,__addedByTrust:!0}),{platform:a});var o=(0,l.getVerExtraCssList)(r,t);(0,l.setVerExtraCssList)(e,o,t)}}}function Ho(r,e,t){var a=t.platform,n=t.emitPlatform,i=t.versionId,s=t.emitVer,o=(0,l.getVerLib)(r,t);if(!o){Ha(r,e,t);var u=(0,l.getVerLib)(e,{platform:a,versionId:i});if(!u&&n&&(u=(0,l.getVerLib)(e,{platform:n,versionId:s,strictMatchVer:!1})),!u)throw new Error("seems plat ".concat(n," emit null lib for ").concat(e));return(0,l.libReady)(e,u,{platform:a,appName:r,versionId:i}),!1}return!0}function Go(r,e,t){var a=t.platform,n=t.emitPlatform,i=t.versionId,s=t.emitVer,o=(0,l.getVerApp)(r,t);if(!o){Ha(r,e,t);var u=(0,l.getVerApp)(e,{platform:a,versionId:i});if(!u&&n&&(u=(0,l.getVerApp)(e,{platform:n,versionId:s,strictMatchVer:!1})),!u)throw new Error("seems plat ".concat(n," emit null app for ").concat(e));return Gr(R(R({},u),{platform:a,appGroupName:e,appName:r,versionId:i})),!1}return!0}function tt(r,e){var t=e.versionId,a=t===void 0?"":t,n=e.isLib,i=ae(e.platform),s=ie(i,"strictMatchVer",[e.strictMatchVer]),o=R(R({},e),{strictMatchVer:s}),u=r,c=e.custom;Va(c)&&(u=c.appGroupName||r,o.strictMatchVer=!1);var f=(0,l.getAppMeta)(u,i);if(e.semverApi&&!a&&f&&f.__setByLatest!==!0)return null;if(n){var p=(0,l.getVerLib)(u,o),v={appName:u,appGroupName:f?.app_group_name||"",platform:i,appProperties:p,isLib:!0,versionId:a,Comp:null,lifecycle:void 0};return p?v:null}var d=(0,l.getVerApp)(u,o);return d||null}function Ga(r,e,t){var a="[[ judgeAppReady ]]",n=e.versionId,i=n===void 0?"":n,s=e.projectId,o=e.appName,u=e.platform,c=e.next,f=e.error,p=e.isLib,v=e.strictMatchVer;(0,l.log)("".concat(a," receive emit app and judge (emitAppInfo, judgeOptions):"),r,{inputVer:i,projectId:s,appName:o,platform:u,isLib:p,strictMatchVer:v});var d=ae(u),h=r.appName,m=r.appGroupName,g=r.platform,b=g===void 0?d:g,S=r.versionId,_="".concat(u,"/").concat(o,"/").concat(i),A=(0,l.getAppMeta)(o,u),I=t.branchId,M=t.custom,y=t.trust,V=function(Y){try{var Q=p?Ho(o,m,Y):Go(o,m,Y);return Q}catch(W){return f(W),!1}};if(M){var O=M.enable,j=O===void 0?!0:O,F=M.host,k=M.appGroupName,B=M.trust,w=B===void 0?!1:B,x=function(){return m&&(m===o||m===k)};if(j&&F){(0,l.log)("".concat(a," judge for custom:"),M);var D=function(Y){(0,l.log)("".concat(a," custom conf ").concat(Y?"":"mis","match current emit app!")),Y&&c()};if(!w)return D(x());var E=V({versionId:i,platform:d,emitPlatform:b,emitVer:S});return D(E)}}if(v===!1&&m&&A?.app_group_name===m&&d===b)return(0,l.log)("".concat(a," treat emitApp as wanted when strictMatchVer is false (appInfo):"),r),c();var C=function(){return(0,l.log)("".concat(a," still wait ").concat(_," to be emitted (emitAppInfo,toMatch):"),r,N)},N={branchId:I,platform:u,emitVer:S,inputVer:i,projectId:s,strictMatchVer:v};if(o!==h||!Zr(o,N))return C();var H=ie(d,"trustAppNames",[null,[]],{emptyArrIsNull:!1});if(d!==b&&(y||H.includes(o))){var E=V({versionId:i,platform:d,emitPlatform:b,emitVer:S});if(!E)return(0,l.log)("".concat(a," transfer ").concat(b," app [").concat(o,"] to ").concat(d," plat due to being in trustAppNames")),C()}c()}var Ka=Object.freeze({__proto__:null,getLibOrApp:tt,judgeAppReady:Ga});function $a(r){var e=r.platform,t=Ee(r,["platform"]);(0,l.initPlatformConfig)(t,e)}function Ya(){return(0,l.isSubApp)()}function Ur(r){if(r&&!r.default)try{r.default=r}catch{}return r}function rr(r){var e=(0,l.getGlobalThis)();Object.keys(r).forEach(function(t){var a=r[t];a&&(e[t]=a)})}function Wa(r){var e=Ur(r.React),t=Ur(r.ReactDOM),a=r.ReactIs||null,n=r.ReactReconciler||null,i={LEAH_React:e,LEAH_ReactDOM:t,LEAH_ReactIs:a,LEAH_ReactReconciler:n,React:e,ReactDOM:t,ReactIs:a,ReactReconciler:n};rr(i)}function Xa(r){var e=Ur(r.Vue),t={LEAH_Vue:e,Vue:e};rr(t)}function qa(r){return"".concat(ge.EXTRA_DATA_PREFIX,".").concat(r)}function Ja(r,e){var t,a,n=e??!1,i=(a=(t=(0,l.getGlobalThis)().localStorage)===null||t===void 0?void 0:t.getItem(qa(r)))!==null&&a!==void 0?a:null;return i?n?JSON.parse(i):i:null}function za(r,e,t){var a,n=t??!1,i=n?JSON.stringify(e):e;(a=(0,l.getGlobalThis)().localStorage)===null||a===void 0||a.setItem(qa(r),i)}function fa(r){var e;return typeof r=="string"?(e=(0,l.getGlobalThis)())===null||e===void 0?void 0:e.document.getElementById(r):r}function Qa(r,e){return{name:r,platform:e?.platform||(0,l.getAppPlatform)(r),versionId:e?.versionId||"",getShadowAppRoot:fa,getShadowBodyRoot:fa}}var xr=l.commonUtil.getObjsVal,Ko=l.commonUtil.purify,$o=ge.ENABLE_DISK_CACHE,Yo=ge.ENABLE_SYNC_META,Wo=ge.STORAGE_TYPE,Br="preFetchLib",Xo="preFetchApp",Le="preFetch";function Za(r,e){var t=typeof e=="string"?{versionId:e}:R({},e||{});t.platform=ae(t.platform),t.isLib=r;var a=t.platform;return t.strictMatchVer=ie(a,"strictMatchVer",[t.strictMatchVer]),t.storageType=t.storageType||"indexedDB",t.semverApi=ie(a,"semverApi",[t.semverApi]),t}function qo(r,e,t){if(t.shadow){if(!e)return;var a=rt(r,t);l.commonDataUtil.setIgnoreCssPrefix(a),l.commonDataUtil.setIgnoreStyleTagKey(r),l.commonDataUtil.setIgnoreStyleTagKey(e),l.commonDataUtil.setIgnoreCssPrefixKey(a,e)}}function pa(r,e,t){return T(this,void 0,void 0,function(){var a,n,i,s,o,u,c,f,p,v;return P(this,function(d){switch(d.label){case 0:return a=(0,l.getHelEventBus)(),n=e.platform,i=e.isLib,s=i===void 0?!1:i,o=e.versionId,u=e.projectId,c=e.strictMatchVer,f=s?l.helEvents.SUB_LIB_LOADED:l.helEvents.SUB_APP_LOADED,p=null,[4,new Promise(function(h,m){if(p=function(b){Ga(b,{appName:r,platform:n,versionId:o,projectId:u,isLib:s,next:h,error:m,strictMatchVer:c},e)},a.on(f,p),t){var g=(0,l.getAppMeta)(r,n);g&&qo(r,g.app_group_name,e),t().catch(m)}})];case 1:return d.sent(),p&&a.off(f,p),v=tt(r,e),[2,v]}})})}function en(r,e){return T(this,void 0,void 0,function(){var t,a,n,i,s,o,u;return P(this,function(c){switch(c.label){case 0:t=null,a=e.versionId,n=e.isLib,i=n?Br:Xo,c.label=1;case 1:return c.trys.push([1,7,,8]),t=tt(r,e),t&&(!a||a&&t.versionId===a)?((0,l.log)("[[ ".concat(i," ]] return cached app:"),r,e),[2,{emitApp:t,msg:""}]):(s=null,o=(0,l.getVerLoadStatus)(r,e),o!==l.helLoadStatus.LOADED?[3,3]:[4,pa(r,e)]);case 2:return t=c.sent(),(0,l.log)("[[ ".concat(i," ]] return emit app:"),r,e,t),[2,{emitApp:t,msg:""}];case 3:return o===l.helLoadStatus.LOADING?[3,5]:((0,l.setVerLoadStatus)(r,l.helLoadStatus.LOADING,e),[4,Fa(r,R(R({},e),{controlLoadAssets:!0}))]);case 4:s=c.sent(),(0,l.perfPeek)(Le,"loadApp"),c.label=5;case 5:return[4,pa(r,e,s)];case 6:return t=c.sent(),(0,l.perfPeek)(Le,"waitAppEmit"),(0,l.log)("[[ ".concat(i," ]] return fetch&emit app:"),r,e,t),[2,{emitApp:t,msg:""}];case 7:return u=c.sent(),console.error(u),(0,l.setVerLoadStatus)(r,l.helLoadStatus.NOT_LOAD,e),[2,{emitApp:t,msg:u.message}];case 8:return[2]}})})}function at(r,e){return T(this,void 0,Promise,function(){var t,a,n,i,s,o,u,c,f;return P(this,function(p){switch(p.label){case 0:return(0,l.perfMark)(Le),t="".concat(Br,"(").concat(r,")"),a=_a(t,!0),n=Za(!0,e),[4,en(r,n)];case 1:if(i=p.sent(),s=i.emitApp,o=i.msg,u=s?.appProperties,!u&&n.onLibNull&&(c=n.onLibNull(r,{versionId:n.versionId}),c&&(u=c)),Nr(t,a),(0,l.perfPeek)(Le,"end",!0),!u)throw f=o?" details : ".concat(o):"",new Error("".concat(Br," ").concat(r," fail from ").concat(n.platform,", it may be an invalid module!").concat(f));return[2,u]}})})}function rn(r,e){return T(this,void 0,void 0,function(){var t,a;return P(this,function(n){switch(n.label){case 0:return(0,l.perfMark)(Le),t=Za(!1,e),[4,en(r,t)];case 1:return a=n.sent(),(0,l.perfPeek)(Le,"end",!0),[2,a?.emitApp||null]}})})}function tn(r,e){return T(this,void 0,Promise,function(){var t,a,n,i,s,o,u,c,f,p,v,d,h,m,g,b,S,_,A,I,M,y,V,O,j;return P(this,function(F){switch(F.label){case 0:if(t=e?.preFetchConfigs||{},a=R({semverApi:!1},e?.common||{}),n=ae(a.platform),i=a.versionIdList,s=i===void 0?[]:i,o=a.projectIdList,u=o===void 0?[]:o,c=a.branchIdList,f=c===void 0?[]:c,p=[],v=[],d=[],r.length>8)throw new Error("only support 8 appName at most!");h=[],m=[],g={},b=[];for(S in r)b.push(S);_=0,F.label=1;case 1:return _<b.length?(A=b[_],I=r[A],M=t[I],y={platform:n,versionId:s[A]||"",projectId:u[A]||"",branchId:f[A]||""},typeof M=="string"&&M?y.versionId=M:typeof M=="object"&&M&&(y=R(R({},y),Ko(M)),y.platform=n),g[I]=y,y.enableDiskCache=xr([y,a],"enableDiskCache",$o),y.enableSyncMeta=xr([y,a],"enableSyncMeta",Yo),y.storageType=xr([y,a],"storageType",Wo),[4,Na(I,y,{callRemote:!1})]):[3,4];case 2:V=F.sent(),V||(m.push(I),p[A]=y.versionId||"",v[A]=y.projectId||"",d[A]=y.branchId||""),F.label=3;case 3:return _++,[3,1];case 4:return a.versionIdList=p,a.projectIdList=v,a.branchIdList=d,a.semverApi?[4,Promise.all(m.map(function(k){return Jr(k,g[k])}))]:[3,6];case 5:return h=F.sent(),[3,8];case 6:return[4,po(m,a)];case 7:h=F.sent(),F.label=8;case 8:return h.forEach(function(k){var B=k.app,w=k.version,x=g[B.name]||{};we(B,{appVersion:w,platform:n,toDisk:x.enableDiskCache,loadOptions:x})}),O=r.map(function(k){return at(k,g[k])}),[4,Promise.all(O)];case 9:return j=F.sent(),[2,j]}})})}var Jo=Object.freeze({__proto__:null,core:Hr,VER:da,emitApp:Gr,getAppCacheKey:er,getCachedAppMeta:$r,appMetaSrv:Oa,appParamSrv:ka,appStyleSrv:Ba,logicSrv:Ka,init:$a,isSubApp:Ya,bindExternals:rr,bindReactRuntime:Wa,bindVueRuntime:Xa,getExtraData:Ja,setExtraData:za,getFakeHelContext:Qa,batchPreFetchLib:tn,preFetchApp:rn,preFetchLib:at}),qe=l.commonUtil.purify,zo=(0,l.getUserEventBus)(),Qo=["eventBus","getExtraData","setExtraData","bindExternals","bindVueRuntime","bindReactRuntime","isSubApp"],Je={ignoreFns:["tryGetAppName","log","commonUtil","getCommonData","setCommonData","setGlobalThis"],arg1PlatFns:["getPlatformConfig","getSharedCache"],arg2PlatFns:["initPlatformConfig","getAppMeta","setAppMeta","tryGetVersion","setAppPlatform"],arg2PlatObjFns:[]},Zo=["preFetchLib","preFetchApp"],eu=["getSubAppMeta","getMetaDataUrl"],ru=["emitApp","init"],tu=["getAppCacheKey"];function au(r,e){var t=this,a=e.fnName,n=e.fn,i=e.isCore,s=e.preFetchOptions;return function(){for(var o=[],u=0;u<arguments.length;u++)o[u]=arguments[u];var c=function(S){return R({platform:r},qe(S||{}))},f=o[0],p=o[1],v=o[2];if(i){if(a==="getPlatform")return r;Je.arg1PlatFns.includes(a)?o[0]=f||r:Je.arg2PlatFns.includes(a)?o[1]=p||r:Je.arg2PlatObjFns.includes(a)?o[1]=c(p):Je.ignoreFns.includes(a)||(a.startsWith("set")?o[2]=c(v):o[1]=c(p))}else if(a==="batchPreFetchLib"){var d=p||{},h=c(d.common);o[1]=R(R({},d),{common:h})}else if(Zo.includes(a)){var m=qe(typeof p=="string"?{versionId:p}:p||{});s&&(m=qe(R(R({},s),m))),o[1]=R({platform:r},m)}else if(eu.includes(a)){var g=(s||{}).semverApi,b=g===void 0?!0:g;o[1]=c(R({semverApi:b},qe(p||{})))}else ru.includes(a)?o[0]=c(f):tu.includes(a)?o[1]=p||r:o[1]=c(p);return n.apply(t,o)}}function an(r,e,t){var a=t.preFetchOptions,n=t.isCore,i={};return Object.keys(e).forEach(function(s){var o=e[s];if(Qo.includes(s)){i[s]=o;return}var u=typeof o;if(u==="function"){var c={fnName:s,fn:o,isCore:n,preFetchOptions:a};i[s]=au(r,c);return}if(o&&u==="object"){var f=R(R({},t),{isCore:s==="core"});i[s]=an(r,o,f);return}i[s]=o}),i}function nt(r,e){var t=an(r,Jo,{preFetchOptions:e});return t.createInstance=nt,t.createOriginInstance=nn,t.resetGlobalThis=l.resetGlobalThis,t.eventBus=zo,t.default=t,t}function nn(r,e){var t=e||{},a=t.trustAppNames,n=Ee(t,["trustAppNames"]);return(0,l.originInit)(r,e),nt(r,n)}var sn=da,nu=at,iu=rn,su=tn,ou=Ba,uu=ka,cu=Oa,lu=Ka,fu=Gr,pu=$a,vu=Ya,du=er,hu=$r,mu=Qa,gu=Ja,bu=za,Au=rr,on=Xa,un=Wa,Su=Hr,_u=l.resetGlobalThis,yu=nt,Lu=nn,Eu=(0,l.getUserEventBus)();Su.log("hel-micro ver ".concat(sn));var cn={VER:sn,preFetchLib:nu,preFetchApp:iu,batchPreFetchLib:su,appStyleSrv:ou,appParamSrv:uu,appMetaSrv:cu,logicSrv:lu,emitApp:fu,eventBus:Eu,init:pu,isSubApp:vu,getAppCacheKey:du,getCachedAppMeta:hu,getFakeHelContext:mu,getExtraData:gu,setExtraData:bu,bindExternals:Au,bindVueRuntime:on,bindReactRuntime:un,resetGlobalThis:_u,core:Hr,createInstance:yu,createOriginInstance:Lu};Ao(cn);l.commonUtil.noop(va.default);var Iu=cn;var ln=Fe(Er());var export_exposeLib=ln.exposeLib;var export_getLib=ln.getLib;export{un as bindReactRuntime,on as bindVueRuntime,Iu as default,export_exposeLib as exposeLib,export_getLib as getLib};
17
- /*! Bundled license information:
18
-
19
- hel-lib-proxy/dist/hel-lib-proxy.min.js:
20
- (*! *****************************************************************************
21
- Copyright (c) Microsoft Corporation.
22
-
23
- Permission to use, copy, modify, and/or distribute this software for any
24
- purpose with or without fee is hereby granted.
25
-
26
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
27
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
28
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
29
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
30
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
31
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
32
- PERFORMANCE OF THIS SOFTWARE.
33
- ***************************************************************************** *)
34
-
35
- hel-micro/es/index.js:
36
- (*! *****************************************************************************
37
- Copyright (c) Microsoft Corporation.
38
-
39
- Permission to use, copy, modify, and/or distribute this software for any
40
- purpose with or without fee is hereby granted.
41
-
42
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
43
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
44
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
45
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
46
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
47
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
48
- PERFORMANCE OF THIS SOFTWARE.
49
- ***************************************************************************** *)
50
- */
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@melt-js/libs-core",
3
- "version": "2026.11.16-1",
3
+ "version": "2026.11.16-2",
4
4
  "type": "module",
5
5
  "main": "dist/remote.mjs",
6
6
  "module": "dist/remote.mjs",
@@ -9,6 +9,7 @@ import { rollup } from 'rollup'
9
9
  import { parse } from 'acorn'
10
10
  import JavaScriptObfuscator from 'javascript-obfuscator'
11
11
  import defaults from './comps-obfuscator-options.cjs'
12
+ import { splitStringsChunkLength } from './obfuscator-split-strings.cjs'
12
13
 
13
14
  const slash = value => value.replaceAll('\\', '/')
14
15
  const write = (file, content) => { fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, content) }
@@ -68,14 +69,14 @@ async function emitUmd(input, plugins, { name, globals, paths, intro, outputDire
68
69
 
69
70
  })
70
71
  const chunk = output.find(item => item.type === 'chunk')
71
- const { code } = await transform(chunk.code, { minify: true, target: 'es2020', legalComments: 'eof' })
72
+ const { code } = await transform(chunk.code, { minify: true, target: 'es2020', legalComments: 'none' })
72
73
  return { code, exports: chunk.exports }
73
74
  } finally { await bundle.close() }
74
75
  }
75
76
 
76
- function emitJs(file, code, protect) {
77
+ function emitJs(file, code, protect, chunkLength) {
77
78
  if (protect && process.env.HEL_OBFUSCATE !== '0') {
78
- code = JavaScriptObfuscator.obfuscate(code, { ...defaults, seed: 1 }).getObfuscatedCode()
79
+ code = JavaScriptObfuscator.obfuscate(code, { ...defaults, splitStringsChunkLength: chunkLength, seed: 1 }).getObfuscatedCode()
79
80
  // Several CDN scripts share a page. Keep generated decoder names out of its global scope.
80
81
  code = `(function(){${code}\n}).call(typeof globalThis!=='undefined'?globalThis:this);\n`
81
82
  }
@@ -153,6 +154,7 @@ function exampleFiles(root, pkg, output, manifest, imports, scripts, styles, rem
153
154
  export async function buildBrowserFormats(root = process.cwd()) {
154
155
  root = path.resolve(root)
155
156
  const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
157
+ const chunkLength = splitStringsChunkLength(root)
156
158
  const config = pkg.browserFormats
157
159
  if (!config) return
158
160
  const outputRoot = path.resolve(root, config.outDir)
@@ -271,12 +273,12 @@ export async function buildBrowserFormats(root = process.cwd()) {
271
273
  builder.onLoad({ filter: /.*/, namespace: 'hel-framework' }, args => ({ contents: 'import * as value from ' + quote('hel-framework:' + args.path) + ';module.exports=value.default||value;', loader: 'js' }))
272
274
  } }
273
275
  if (vendorImports.length) {
274
- const result = await build({ absWorkingDir: root, stdin: { contents: vendorImports.map(([id, key]) => `import * as ${key} from ${quote(id)};export {${key}};`).join('\n'), resolveDir: root }, bundle: true, format: 'esm', platform: 'browser', target: 'es2020', minify: true, sourcemap: false, write: false, plugins: [framePlugin] })
276
+ const result = await build({ absWorkingDir: root, stdin: { contents: vendorImports.map(([id, key]) => `import * as ${key} from ${quote(id)};export {${key}};`).join('\n'), resolveDir: root }, bundle: true, format: 'esm', platform: 'browser', target: 'es2020', minify: true, sourcemap: false, legalComments: 'none', write: false, plugins: [framePlugin] })
275
277
  const vendorEntry = path.join(output, '.vendor-input.mjs')
276
278
  const vendor = await emitUmd(vendorEntry, [{ name: 'vendor-esm-input', resolveId(id) { if (frames.has(id)) return { id, external: true }; if (id === vendorEntry) return id }, load(id) { if (id === vendorEntry) return result.outputFiles[0].text } }], {
277
279
  name: 'MeltCdnVendors.' + pkg.name, globals: id => frameGlobals[id],
278
280
  })
279
- emitJs(path.join(output, 'vendor.umd.cjs'), vendor.code, false)
281
+ emitJs(path.join(output, 'vendor.umd.cjs'), vendor.code, false, chunkLength)
280
282
  manifest.vendor = slash(path.relative(root, path.join(output, 'vendor.umd.cjs')))
281
283
  }
282
284
  const bridge = { name: 'cdn-business-boundary',
@@ -321,7 +323,7 @@ export async function buildBrowserFormats(root = process.cwd()) {
321
323
  })
322
324
  let code = result.code
323
325
  if (pkg.name === '@melt-js/libs-core' && key === '.') code += ';if(typeof window!=="undefined"){window.MeltCore=window.MeltPackages[' + quote(pkg.name) + '];window.HelLibProxy=window.MeltCore;}\n'
324
- emitJs(path.join(output, name + '.umd.cjs'), code, true)
326
+ emitJs(path.join(output, name + '.umd.cjs'), code, true, chunkLength)
325
327
  manifest.entries[specifier] = { specifier, esm: slash(path.relative(root, entryPath)), umd: slash(path.relative(root, path.join(output, name + '.umd.cjs'))), exports: result.exports }
326
328
  imports.set(specifier, cdn(pkg, slash(path.relative(root, path.resolve(root, target)))))
327
329
  }
@@ -28,7 +28,7 @@ await build({
28
28
  stdin: { contents: "export { default, bindReactRuntime, bindVueRuntime } from 'hel-micro'; export { exposeLib, getLib } from 'hel-lib-proxy'", resolveDir: root },
29
29
  outfile: path.join(dist, 'vendor/hel-runtime.mjs'),
30
30
  bundle: true, format: 'esm', platform: 'browser', target: 'es2020', minify: true, sourcemap: false,
31
- legalComments: 'eof',
31
+ legalComments: 'none',
32
32
  })
33
33
  const vendorFile = path.join(dist, 'vendor/hel-runtime.mjs')
34
34
  if (process.env.HEL_GZIP !== '0') fs.writeFileSync(vendorFile + '.gz', gzipSync(fs.readFileSync(vendorFile)))
@@ -40,7 +40,7 @@ reports.push(...await buildProtectedEsm({
40
40
  platform: 'browser',
41
41
  target: 'es2020',
42
42
  minify: true,
43
- legalComments: 'eof',
43
+ legalComments: 'none',
44
44
  plugins: [{ name: 'shared-hel-vendor', setup(builder) {
45
45
  builder.onResolve({ filter: /^(?:hel-micro|hel-lib-proxy)$/ }, () => ({ path: './vendor/hel-runtime.mjs', external: true }))
46
46
  } }],
@@ -1,51 +1,54 @@
1
- import fs from 'node:fs'
2
- import path from 'node:path'
3
- import { createHash } from 'node:crypto'
4
- import { gzipSync } from 'node:zlib'
5
- import { build } from 'esbuild'
6
- import JavaScriptObfuscator from 'javascript-obfuscator'
7
- import defaults from './comps-obfuscator-options.cjs'
8
- import contracts from './comps-source-obfuscation.cjs'
9
- import boundaries from './comps-bundle-obfuscation.cjs'
10
-
11
- // Final ESM output only. Dependencies must stay external or in a separate vendor build.
12
- export async function buildProtectedEsm(options, { root, enabled = process.env.HEL_OBFUSCATE !== '0' } = {}) {
13
- root = path.resolve(root || options.absWorkingDir || process.cwd())
14
- const classify = boundaries.createModuleClassifier(root)
15
- const result = await build({ ...options, absWorkingDir: root, sourcemap: false, metafile: true, write: false })
16
- const reports = []
17
- for (const output of result.outputFiles) {
18
- let content = output.contents
19
- if (/\.[cm]?js$/.test(output.path)) {
20
- const relative = path.relative(root, output.path).replaceAll('\\', '/')
21
- const metadata = result.metafile.outputs[relative]
22
- if (!metadata) throw new Error('Missing ESM output metadata: ' + relative)
23
- const inputs = Object.keys(metadata?.inputs || {})
24
- const vendors = inputs.filter(input => classify(path.resolve(root, input)) === 'thirdParty')
25
- if (vendors.length) throw new Error('Protected ESM must not contain third-party modules: ' + relative)
26
- const beforeHash = createHash('sha256').update(content).digest('hex')
27
- const code = output.text
28
- // Type-only entrypoints may compile to an empty module.
29
- if (enabled && code.trim() && !/^export\s*\{\s*\}\s*;?$/.test(code.trim())) {
30
- content = Buffer.from(JavaScriptObfuscator.obfuscate(code, {
31
- ...defaults, ...contracts.getSourceContractOptions(code),
32
- seed: 1, sourceMap: false, renameProperties: false,
33
- }).getObfuscatedCode())
34
- }
35
- reports.push({ file: relative, inputs, beforeHash,
36
- afterHash: createHash('sha256').update(content).digest('hex'),
37
- identifiers: (content.toString().match(/\b_0x[\da-f]+\b/g) || []).length })
38
- }
39
- fs.mkdirSync(path.dirname(output.path), { recursive: true })
40
- fs.writeFileSync(output.path, content)
41
- const sidecar = output.path + '.gz'
42
- if (process.env.HEL_GZIP !== '0' && /\.[cm]?js$/.test(output.path) && (content.length >= 10240 || fs.existsSync(sidecar))) {
43
- fs.writeFileSync(output.path + '.gz', gzipSync(content))
44
- } else if (fs.existsSync(sidecar)) {
45
- const archived = path.join(root, '.tmp/gzip-history', Date.now() + '-' + process.pid, path.relative(root, sidecar))
46
- fs.mkdirSync(path.dirname(archived), { recursive: true })
47
- fs.renameSync(sidecar, archived)
48
- }
49
- }
50
- return reports
51
- }
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+ import { createHash } from 'node:crypto'
4
+ import { gzipSync } from 'node:zlib'
5
+ import { build } from 'esbuild'
6
+ import JavaScriptObfuscator from 'javascript-obfuscator'
7
+ import defaults from './comps-obfuscator-options.cjs'
8
+ import { splitStringsChunkLength } from './obfuscator-split-strings.cjs'
9
+ import contracts from './comps-source-obfuscation.cjs'
10
+ import boundaries from './comps-bundle-obfuscation.cjs'
11
+
12
+ // Final ESM output only. Dependencies must stay external or in a separate vendor build.
13
+ export async function buildProtectedEsm(options, { root, enabled = process.env.HEL_OBFUSCATE !== '0' } = {}) {
14
+ root = path.resolve(root || options.absWorkingDir || process.cwd())
15
+ const classify = boundaries.createModuleClassifier(root)
16
+ // 受保护 ESM 产物一律不保留注释(含 /*! */ 版权 banner)。
17
+ const result = await build({ ...options, absWorkingDir: root, sourcemap: false, metafile: true, write: false, legalComments: 'none' })
18
+ const reports = []
19
+ for (const output of result.outputFiles) {
20
+ let content = output.contents
21
+ if (/\.[cm]?js$/.test(output.path)) {
22
+ const relative = path.relative(root, output.path).replaceAll('\\', '/')
23
+ const metadata = result.metafile.outputs[relative]
24
+ if (!metadata) throw new Error('Missing ESM output metadata: ' + relative)
25
+ const inputs = Object.keys(metadata?.inputs || {})
26
+ const vendors = inputs.filter(input => classify(path.resolve(root, input)) === 'thirdParty')
27
+ if (vendors.length) throw new Error('Protected ESM must not contain third-party modules: ' + relative)
28
+ const beforeHash = createHash('sha256').update(content).digest('hex')
29
+ const code = output.text
30
+ // Type-only entrypoints may compile to an empty module.
31
+ if (enabled && code.trim() && !/^export\s*\{\s*\}\s*;?$/.test(code.trim())) {
32
+ content = Buffer.from(JavaScriptObfuscator.obfuscate(code, {
33
+ ...defaults, ...contracts.getSourceContractOptions(code),
34
+ splitStringsChunkLength: splitStringsChunkLength(root),
35
+ seed: 1, sourceMap: false, renameProperties: false,
36
+ }).getObfuscatedCode())
37
+ }
38
+ reports.push({ file: relative, inputs, beforeHash,
39
+ afterHash: createHash('sha256').update(content).digest('hex'),
40
+ identifiers: (content.toString().match(/\b_0x[\da-f]+\b/g) || []).length })
41
+ }
42
+ fs.mkdirSync(path.dirname(output.path), { recursive: true })
43
+ fs.writeFileSync(output.path, content)
44
+ const sidecar = output.path + '.gz'
45
+ if (process.env.HEL_GZIP !== '0' && /\.[cm]?js$/.test(output.path) && (content.length >= 10240 || fs.existsSync(sidecar))) {
46
+ fs.writeFileSync(output.path + '.gz', gzipSync(content))
47
+ } else if (fs.existsSync(sidecar)) {
48
+ const archived = path.join(root, '.tmp/gzip-history', Date.now() + '-' + process.pid, path.relative(root, sidecar))
49
+ fs.mkdirSync(path.dirname(archived), { recursive: true })
50
+ fs.renameSync(sidecar, archived)
51
+ }
52
+ }
53
+ return reports
54
+ }
@@ -1,30 +1,30 @@
1
- const { createRequire } = require('node:module')
2
- const path = require('node:path')
3
-
4
- /** Preserve native package imports while sharing the host's CDN runtime in Vite dev/build. */
5
- module.exports = function cdnRuntime({ root, modules }) {
6
- const localRequire = createRequire(path.join(root, 'package.json'))
7
- const prefix = '\0hel:cdn-runtime:'
8
- const entries = new Map(Object.entries(modules).map(([name, global]) => {
9
- const names = Object.keys(localRequire(name)).filter(name => name !== 'default' && /^[$A-Z_a-z][$\w]*$/.test(name))
10
- const code = `const runtime = globalThis[${JSON.stringify(global)}];\n`
11
- + `if (!runtime) throw new Error('Load CDN runtime before importing ${name}');\n`
12
- + 'export default runtime;\n'
13
- + names.map(name => `export const ${name} = runtime[${JSON.stringify(name)}];`).join('\n')
14
- return [name, code]
15
- }))
16
- return {
17
- name: 'hel:cdn-runtime', enforce: 'pre',
18
- resolveId(id) { if (entries.has(id)) return prefix + id },
19
- load(id) { if (id.startsWith(prefix)) return entries.get(id.slice(prefix.length)) },
20
- config() {
21
- return { optimizeDeps: { esbuildOptions: { plugins: [{
22
- name: 'hel-cdn-runtime',
23
- setup(build) {
24
- build.onResolve({ filter: /.*/ }, args => entries.has(args.path) ? { path: args.path, namespace: 'hel-cdn' } : undefined)
25
- build.onLoad({ filter: /.*/, namespace: 'hel-cdn' }, args => ({ contents: entries.get(args.path), loader: 'js' }))
26
- },
27
- }] } } }
28
- },
29
- }
30
- }
1
+ const { createRequire } = require('node:module')
2
+ const path = require('node:path')
3
+
4
+ /** Preserve native package imports while sharing the host's CDN runtime in Vite dev/build. */
5
+ module.exports = function cdnRuntime({ root, modules }) {
6
+ const localRequire = createRequire(path.join(root, 'package.json'))
7
+ const prefix = '\0hel:cdn-runtime:'
8
+ const entries = new Map(Object.entries(modules).map(([name, global]) => {
9
+ const names = Object.keys(localRequire(name)).filter(name => name !== 'default' && /^[$A-Z_a-z][$\w]*$/.test(name))
10
+ const code = `const runtime = globalThis[${JSON.stringify(global)}];\n`
11
+ + `if (!runtime) throw new Error('Load CDN runtime before importing ${name}');\n`
12
+ + 'export default runtime;\n'
13
+ + names.map(name => `export const ${name} = runtime[${JSON.stringify(name)}];`).join('\n')
14
+ return [name, code]
15
+ }))
16
+ return {
17
+ name: 'hel:cdn-runtime', enforce: 'pre',
18
+ resolveId(id) { if (entries.has(id)) return prefix + id },
19
+ load(id) { if (id.startsWith(prefix)) return entries.get(id.slice(prefix.length)) },
20
+ config() {
21
+ return { optimizeDeps: { esbuildOptions: { plugins: [{
22
+ name: 'hel-cdn-runtime',
23
+ setup(build) {
24
+ build.onResolve({ filter: /.*/ }, args => entries.has(args.path) ? { path: args.path, namespace: 'hel-cdn' } : undefined)
25
+ build.onLoad({ filter: /.*/, namespace: 'hel-cdn' }, args => ({ contents: entries.get(args.path), loader: 'js' }))
26
+ },
27
+ }] } } }
28
+ },
29
+ }
30
+ }
@@ -1,48 +1,48 @@
1
- // Deployment configuration is a Node build input, never a browser environment API.
2
- const deploymentKey = /^(?:(?:VITE|VUE_APP|REACT_APP)_)?(?:(?:SFTP|GITHUB|UNPKG)_PUBLIC_URL|SFTP_[A-Z\d_]+|DEPLOY_[A-Z\d_]+)$/
3
-
4
- function stripDeploymentEnv(values) {
5
- for (const key of Object.keys(values || {})) {
6
- if (deploymentKey.test(key)) delete values[key]
7
- }
8
- }
9
-
10
- function applyWebpackClientSecurity(config) {
11
- if (process.env.NODE_ENV !== 'production' && config.mode !== 'production') return config
12
- config.devtool = false
13
- for (const plugin of config.plugins || []) {
14
- if (plugin?.constructor?.name !== 'DefinePlugin') continue
15
- const definitions = plugin.definitions || {}
16
- stripDeploymentEnv(definitions['process.env'])
17
- for (const key of Object.keys(definitions)) {
18
- if (deploymentKey.test(key.replace(/^process\.env\./, ''))) delete definitions[key]
19
- }
20
- }
21
- return config
22
- }
23
-
24
- function clientBuildSecurity({ loadEnv }) {
25
- return {
26
- // Vite 6 snapshots env while constructing its define plugin, before configResolved.
27
- // Select client keys before that snapshot rather than filtering only afterwards.
28
- name: 'hel:client-build-security', apply: 'build', enforce: 'pre',
29
- config(config, { mode }) {
30
- const path = require('node:path')
31
- const root = path.resolve(config.root || process.cwd())
32
- const envDir = path.resolve(root, config.envDir || '.')
33
- const prefixes = [config.envPrefix || 'VITE_'].flat()
34
- const values = loadEnv(mode, envDir, prefixes)
35
- stripDeploymentEnv(values)
36
- return { envPrefix: Object.keys(values), build: { sourcemap: false } }
37
- },
38
- configResolved(config) {
39
- config.build.sourcemap = false
40
- stripDeploymentEnv(config.env)
41
- for (const key of Object.keys(config.define || {})) {
42
- if (deploymentKey.test(key.replace(/^import\.meta\.env\./, ''))) delete config.define[key]
43
- }
44
- },
45
- }
46
- }
47
-
48
- module.exports = { stripDeploymentEnv, applyWebpackClientSecurity, clientBuildSecurity }
1
+ // Deployment configuration is a Node build input, never a browser environment API.
2
+ const deploymentKey = /^(?:(?:VITE|VUE_APP|REACT_APP)_)?(?:(?:SFTP|GITHUB|UNPKG)_PUBLIC_URL|SFTP_[A-Z\d_]+|DEPLOY_[A-Z\d_]+)$/
3
+
4
+ function stripDeploymentEnv(values) {
5
+ for (const key of Object.keys(values || {})) {
6
+ if (deploymentKey.test(key)) delete values[key]
7
+ }
8
+ }
9
+
10
+ function applyWebpackClientSecurity(config) {
11
+ if (process.env.NODE_ENV !== 'production' && config.mode !== 'production') return config
12
+ config.devtool = false
13
+ for (const plugin of config.plugins || []) {
14
+ if (plugin?.constructor?.name !== 'DefinePlugin') continue
15
+ const definitions = plugin.definitions || {}
16
+ stripDeploymentEnv(definitions['process.env'])
17
+ for (const key of Object.keys(definitions)) {
18
+ if (deploymentKey.test(key.replace(/^process\.env\./, ''))) delete definitions[key]
19
+ }
20
+ }
21
+ return config
22
+ }
23
+
24
+ function clientBuildSecurity({ loadEnv }) {
25
+ return {
26
+ // Vite 6 snapshots env while constructing its define plugin, before configResolved.
27
+ // Select client keys before that snapshot rather than filtering only afterwards.
28
+ name: 'hel:client-build-security', apply: 'build', enforce: 'pre',
29
+ config(config, { mode }) {
30
+ const path = require('node:path')
31
+ const root = path.resolve(config.root || process.cwd())
32
+ const envDir = path.resolve(root, config.envDir || '.')
33
+ const prefixes = [config.envPrefix || 'VITE_'].flat()
34
+ const values = loadEnv(mode, envDir, prefixes)
35
+ stripDeploymentEnv(values)
36
+ return { envPrefix: Object.keys(values), build: { sourcemap: false } }
37
+ },
38
+ configResolved(config) {
39
+ config.build.sourcemap = false
40
+ stripDeploymentEnv(config.env)
41
+ for (const key of Object.keys(config.define || {})) {
42
+ if (deploymentKey.test(key.replace(/^import\.meta\.env\./, ''))) delete config.define[key]
43
+ }
44
+ },
45
+ }
46
+ }
47
+
48
+ module.exports = { stripDeploymentEnv, applyWebpackClientSecurity, clientBuildSecurity }
@@ -1,57 +1,57 @@
1
- import fs from 'node:fs'
2
- import { parse } from '@babel/parser'
3
-
4
- /** Supplement props schemas with Vue event declarations; no component evaluation. */
5
- export function parseComponentEvents(file) {
6
- const source = fs.readFileSync(file, 'utf8')
7
- const events = new Map()
8
- const add = (name, type = '', description = '') => {
9
- if (!name || typeof name !== 'string') return
10
- const previous = events.get(name)
11
- events.set(name, { name, type: type || previous?.type || '', description: description || previous?.description || '', default: '', required: false, version: '', isEvent: true, bindable: false })
12
- }
13
- for (const match of source.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script>/gi)) {
14
- const code = match[1]
15
- const ast = parse(code, { sourceType: 'module', plugins: ['typescript', 'jsx', 'decorators-legacy'] })
16
- const text = node => node ? code.slice(node.start, node.end) : ''
17
- const nameOf = node => node?.name || node?.value
18
- const description = node => (node.leadingComments || []).map(comment => comment.value.replace(/\*/g, '').trim()).join(' ').replace(/^@description\s*/, '')
19
- function walk(node) {
20
- if (!node || typeof node !== 'object') return
21
- if (node.type === 'CallExpression') {
22
- const callee = node.callee
23
- if (callee.type === 'Identifier' && callee.name === 'defineEmits') {
24
- const declaration = node.typeParameters?.params?.[0] || node.typeArguments?.params?.[0]
25
- if (declaration?.type === 'TSTypeLiteral') {
26
- for (const member of declaration.members) {
27
- if (member.type === 'TSPropertySignature') add(nameOf(member.key), text(member.typeAnnotation?.typeAnnotation), description(member))
28
- if (member.type === 'TSCallSignatureDeclaration') {
29
- const parameters = member.parameters || []
30
- const eventType = parameters[0]?.typeAnnotation?.typeAnnotation
31
- const names = eventType?.type === 'TSUnionType' ? eventType.types : [eventType]
32
- for (const item of names) if (item?.type === 'TSLiteralType') add(item.literal.value, parameters.slice(1).map(text).join(', ') || '无参数', description(member))
33
- }
34
- }
35
- }
36
- const runtime = node.arguments[0]
37
- if (runtime?.type === 'ArrayExpression') for (const item of runtime.elements) add(item?.value)
38
- if (runtime?.type === 'ObjectExpression') for (const item of runtime.properties) add(nameOf(item.key), '', description(item))
39
- }
40
- if ((callee.type === 'Identifier' && callee.name === 'emit') || (callee.type === 'MemberExpression' && nameOf(callee.property) === '$emit')) {
41
- if (node.arguments[0]?.type === 'StringLiteral') add(node.arguments[0].value)
42
- }
43
- }
44
- if (node.type === 'ObjectProperty' && nameOf(node.key) === 'emits') {
45
- if (node.value.type === 'ArrayExpression') for (const item of node.value.elements) add(item?.value)
46
- if (node.value.type === 'ObjectExpression') for (const item of node.value.properties) add(nameOf(item.key), '', description(item))
47
- }
48
- for (const [key, child] of Object.entries(node)) {
49
- if (['loc', 'comments', 'tokens', 'leadingComments', 'trailingComments'].includes(key)) continue
50
- if (Array.isArray(child)) child.forEach(walk)
51
- else if (child && typeof child === 'object') walk(child)
52
- }
53
- }
54
- walk(ast.program)
55
- }
56
- return [...events.values()]
57
- }
1
+ import fs from 'node:fs'
2
+ import { parse } from '@babel/parser'
3
+
4
+ /** Supplement props schemas with Vue event declarations; no component evaluation. */
5
+ export function parseComponentEvents(file) {
6
+ const source = fs.readFileSync(file, 'utf8')
7
+ const events = new Map()
8
+ const add = (name, type = '', description = '') => {
9
+ if (!name || typeof name !== 'string') return
10
+ const previous = events.get(name)
11
+ events.set(name, { name, type: type || previous?.type || '', description: description || previous?.description || '', default: '', required: false, version: '', isEvent: true, bindable: false })
12
+ }
13
+ for (const match of source.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script>/gi)) {
14
+ const code = match[1]
15
+ const ast = parse(code, { sourceType: 'module', plugins: ['typescript', 'jsx', 'decorators-legacy'] })
16
+ const text = node => node ? code.slice(node.start, node.end) : ''
17
+ const nameOf = node => node?.name || node?.value
18
+ const description = node => (node.leadingComments || []).map(comment => comment.value.replace(/\*/g, '').trim()).join(' ').replace(/^@description\s*/, '')
19
+ function walk(node) {
20
+ if (!node || typeof node !== 'object') return
21
+ if (node.type === 'CallExpression') {
22
+ const callee = node.callee
23
+ if (callee.type === 'Identifier' && callee.name === 'defineEmits') {
24
+ const declaration = node.typeParameters?.params?.[0] || node.typeArguments?.params?.[0]
25
+ if (declaration?.type === 'TSTypeLiteral') {
26
+ for (const member of declaration.members) {
27
+ if (member.type === 'TSPropertySignature') add(nameOf(member.key), text(member.typeAnnotation?.typeAnnotation), description(member))
28
+ if (member.type === 'TSCallSignatureDeclaration') {
29
+ const parameters = member.parameters || []
30
+ const eventType = parameters[0]?.typeAnnotation?.typeAnnotation
31
+ const names = eventType?.type === 'TSUnionType' ? eventType.types : [eventType]
32
+ for (const item of names) if (item?.type === 'TSLiteralType') add(item.literal.value, parameters.slice(1).map(text).join(', ') || '无参数', description(member))
33
+ }
34
+ }
35
+ }
36
+ const runtime = node.arguments[0]
37
+ if (runtime?.type === 'ArrayExpression') for (const item of runtime.elements) add(item?.value)
38
+ if (runtime?.type === 'ObjectExpression') for (const item of runtime.properties) add(nameOf(item.key), '', description(item))
39
+ }
40
+ if ((callee.type === 'Identifier' && callee.name === 'emit') || (callee.type === 'MemberExpression' && nameOf(callee.property) === '$emit')) {
41
+ if (node.arguments[0]?.type === 'StringLiteral') add(node.arguments[0].value)
42
+ }
43
+ }
44
+ if (node.type === 'ObjectProperty' && nameOf(node.key) === 'emits') {
45
+ if (node.value.type === 'ArrayExpression') for (const item of node.value.elements) add(item?.value)
46
+ if (node.value.type === 'ObjectExpression') for (const item of node.value.properties) add(nameOf(item.key), '', description(item))
47
+ }
48
+ for (const [key, child] of Object.entries(node)) {
49
+ if (['loc', 'comments', 'tokens', 'leadingComments', 'trailingComments'].includes(key)) continue
50
+ if (Array.isArray(child)) child.forEach(walk)
51
+ else if (child && typeof child === 'object') walk(child)
52
+ }
53
+ }
54
+ walk(ast.program)
55
+ }
56
+ return [...events.values()]
57
+ }
@@ -2,6 +2,7 @@ const { createHash } = require('node:crypto')
2
2
  const fs = require('node:fs')
3
3
  const path = require('node:path')
4
4
  const defaults = require('./comps-obfuscator-options.cjs')
5
+ const { splitStringsChunkLength } = require('./obfuscator-split-strings.cjs')
5
6
 
6
7
  const normalize = value => value.replaceAll('\\', '/')
7
8
  const RUNTIME_ID = '\0hel:shared-vue-runtime'
@@ -161,7 +162,9 @@ function gzipPlugin() {
161
162
  */
162
163
  function bundleObfuscationPlugins({ root, obfuscatorPlugin, enabled = true, options = {}, library = false, rolldown = false }) {
163
164
  const classify = createModuleClassifier(root)
164
- const settings = { ...defaults, ...options, seed: options.seed ?? 1, renameProperties: false, sourceMap: false }
165
+ // Split granularity follows the package family; an explicit `options.splitStringsChunkLength` still wins.
166
+ const settings = { ...defaults, ...options, splitStringsChunkLength: options.splitStringsChunkLength ?? splitStringsChunkLength(root),
167
+ seed: options.seed ?? 1, renameProperties: false, sourceMap: false }
165
168
  const reports = []
166
169
  let currentReports = []
167
170
  let runId
@@ -32,7 +32,13 @@ module.exports = {
32
32
  stringArrayEncoding: ['base64'],
33
33
  // Keep base64 image data URLs intact, including those embedded in CSS url(...).
34
34
  reservedStrings: ['data:image/[^;,\\s]+(?:;[^;,]*)*;base64,'],
35
- splitStrings: false,
35
+ // Split medium/long literals into 5-char chunks before they land in the string array.
36
+ // Keeps string-array entries short, so the plaintext cannot be read back by grepping the bundle.
37
+ // import()/require() specifiers and asset URLs stay whole via ignoreImports + reservedStrings.
38
+ // This is the comps/demo/tpl granularity; libs packages resolve to 10 in obfuscator-split-strings.cjs
39
+ // because their public ESM/UMD is downloaded by hosts and a 5-char split grows it by 40%-85%.
40
+ splitStrings: true,
41
+ splitStringsChunkLength: 5,
36
42
  numbersToExpressions: false,
37
43
  unicodeEscapeSequence: false,
38
44
  sourceMap: false,