@vlian/framework 1.1.1 → 1.2.16

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 (444) hide show
  1. package/README.md +35 -1
  2. package/dist/analytics/index.cjs +24 -0
  3. package/dist/analytics/index.cjs.map +1 -0
  4. package/dist/analytics/index.d.ts +2 -0
  5. package/dist/analytics/index.js +3 -0
  6. package/dist/analytics/index.js.map +1 -0
  7. package/dist/analytics.umd.js +2406 -0
  8. package/dist/analytics.umd.js.map +1 -0
  9. package/dist/components/LocaleSwitch.cjs +118 -0
  10. package/dist/components/LocaleSwitch.cjs.map +1 -0
  11. package/dist/components/LocaleSwitch.d.ts +21 -0
  12. package/dist/components/LocaleSwitch.js +103 -0
  13. package/dist/components/LocaleSwitch.js.map +1 -0
  14. package/dist/components/ThemeSwitch.cjs +117 -0
  15. package/dist/components/ThemeSwitch.cjs.map +1 -0
  16. package/dist/components/ThemeSwitch.d.ts +20 -0
  17. package/dist/components/ThemeSwitch.js +102 -0
  18. package/dist/components/ThemeSwitch.js.map +1 -0
  19. package/dist/components/index.cjs +16 -0
  20. package/dist/components/index.cjs.map +1 -1
  21. package/dist/components/index.d.ts +5 -2
  22. package/dist/components/index.js +2 -1
  23. package/dist/components/index.js.map +1 -1
  24. package/dist/components/persistence.cjs +60 -0
  25. package/dist/components/persistence.cjs.map +1 -0
  26. package/dist/components/persistence.d.ts +12 -0
  27. package/dist/components/persistence.js +39 -0
  28. package/dist/components/persistence.js.map +1 -0
  29. package/dist/core/Test.d.ts +0 -1
  30. package/dist/core/app/AppContext.cjs +36 -30
  31. package/dist/core/app/AppContext.cjs.map +1 -1
  32. package/dist/core/app/AppContext.d.ts +9 -6
  33. package/dist/core/app/AppContext.js +36 -30
  34. package/dist/core/app/AppContext.js.map +1 -1
  35. package/dist/core/app/AppContext.types.d.ts +9 -10
  36. package/dist/core/app/AppContext.types.js.map +1 -1
  37. package/dist/core/app/BasicLayout.cjs +57 -22
  38. package/dist/core/app/BasicLayout.cjs.map +1 -1
  39. package/dist/core/app/BasicLayout.d.ts +7 -5
  40. package/dist/core/app/BasicLayout.js +57 -22
  41. package/dist/core/app/BasicLayout.js.map +1 -1
  42. package/dist/core/app/DefaultApp.cjs +104 -153
  43. package/dist/core/app/DefaultApp.cjs.map +1 -1
  44. package/dist/core/app/DefaultApp.d.ts +0 -21
  45. package/dist/core/app/DefaultApp.js +104 -153
  46. package/dist/core/app/DefaultApp.js.map +1 -1
  47. package/dist/core/app/index.d.ts +0 -1
  48. package/dist/core/config/AppConfig.cjs.map +1 -1
  49. package/dist/core/config/AppConfig.d.ts +3 -4
  50. package/dist/core/config/AppConfig.js.map +1 -1
  51. package/dist/core/config/ConfigLoader.cjs +90 -8
  52. package/dist/core/config/ConfigLoader.cjs.map +1 -1
  53. package/dist/core/config/ConfigLoader.d.ts +20 -5
  54. package/dist/core/config/ConfigLoader.js +90 -8
  55. package/dist/core/config/ConfigLoader.js.map +1 -1
  56. package/dist/core/config/ConfigValidator.d.ts +0 -1
  57. package/dist/core/config/index.d.ts +0 -1
  58. package/dist/core/dev/DevTools.cjs +141 -287
  59. package/dist/core/dev/DevTools.cjs.map +1 -1
  60. package/dist/core/dev/DevTools.d.ts +1 -32
  61. package/dist/core/dev/DevTools.js +143 -296
  62. package/dist/core/dev/DevTools.js.map +1 -1
  63. package/dist/core/error/ErrorBoundary.cjs +95 -23
  64. package/dist/core/error/ErrorBoundary.cjs.map +1 -1
  65. package/dist/core/error/ErrorBoundary.d.ts +7 -9
  66. package/dist/core/error/ErrorBoundary.js +96 -24
  67. package/dist/core/error/ErrorBoundary.js.map +1 -1
  68. package/dist/core/error/ErrorHandler.cjs +277 -0
  69. package/dist/core/error/ErrorHandler.cjs.map +1 -0
  70. package/dist/core/error/ErrorHandler.d.ts +171 -0
  71. package/dist/core/error/ErrorHandler.js +261 -0
  72. package/dist/core/error/ErrorHandler.js.map +1 -0
  73. package/dist/core/error/index.cjs +10 -0
  74. package/dist/core/error/index.cjs.map +1 -1
  75. package/dist/core/error/index.d.ts +2 -1
  76. package/dist/core/error/index.js +1 -0
  77. package/dist/core/error/index.js.map +1 -1
  78. package/dist/core/event/AppEventBus.d.ts +0 -1
  79. package/dist/core/event/frameworkEvents.d.ts +0 -1
  80. package/dist/core/event/hooks.d.ts +0 -1
  81. package/dist/core/event/index.d.ts +0 -1
  82. package/dist/core/event/types.d.ts +0 -1
  83. package/dist/core/event/useEventBus.d.ts +0 -1
  84. package/dist/core/index.cjs +2 -0
  85. package/dist/core/index.cjs.map +1 -1
  86. package/dist/core/index.d.ts +2 -1
  87. package/dist/core/index.js +2 -0
  88. package/dist/core/index.js.map +1 -1
  89. package/dist/core/initialization/InitializationErrorThrower.d.ts +0 -1
  90. package/dist/core/initialization/index.d.ts +0 -1
  91. package/dist/core/initialization/initialization.d.ts +0 -1
  92. package/dist/core/initialization/initializationErrorState.d.ts +0 -1
  93. package/dist/core/kernel/defaultAdapters.cjs +185 -0
  94. package/dist/core/kernel/defaultAdapters.cjs.map +1 -0
  95. package/dist/core/kernel/defaultAdapters.d.ts +2 -0
  96. package/dist/core/kernel/defaultAdapters.js +175 -0
  97. package/dist/core/kernel/defaultAdapters.js.map +1 -0
  98. package/dist/core/kernel/errors.cjs +71 -0
  99. package/dist/core/kernel/errors.cjs.map +1 -0
  100. package/dist/core/kernel/errors.d.ts +18 -0
  101. package/dist/core/kernel/errors.js +53 -0
  102. package/dist/core/kernel/errors.js.map +1 -0
  103. package/dist/core/kernel/index.cjs +22 -0
  104. package/dist/core/kernel/index.cjs.map +1 -0
  105. package/dist/core/kernel/index.d.ts +3 -0
  106. package/dist/core/kernel/index.js +4 -0
  107. package/dist/core/kernel/index.js.map +1 -0
  108. package/dist/core/kernel/startKernel.cjs +203 -0
  109. package/dist/core/kernel/startKernel.cjs.map +1 -0
  110. package/dist/core/kernel/startKernel.d.ts +2 -0
  111. package/dist/core/kernel/startKernel.js +193 -0
  112. package/dist/core/kernel/startKernel.js.map +1 -0
  113. package/dist/core/kernel/types.cjs +6 -0
  114. package/dist/core/kernel/types.cjs.map +1 -0
  115. package/dist/core/kernel/types.d.ts +114 -0
  116. package/dist/core/kernel/types.js +3 -0
  117. package/dist/core/kernel/types.js.map +1 -0
  118. package/dist/core/middleware.d.ts +0 -1
  119. package/dist/core/plugin/PluginEventBus.d.ts +0 -1
  120. package/dist/core/plugin/PluginSandbox.d.ts +0 -1
  121. package/dist/core/plugin.cjs +1 -1
  122. package/dist/core/plugin.cjs.map +1 -1
  123. package/dist/core/plugin.d.ts +0 -1
  124. package/dist/core/plugin.js +1 -1
  125. package/dist/core/plugin.js.map +1 -1
  126. package/dist/core/router/RouterManager.d.ts +0 -1
  127. package/dist/core/router/adapter/AdapterManager.d.ts +0 -1
  128. package/dist/core/router/adapter/index.d.ts +0 -1
  129. package/dist/core/router/adapter/react-router/ReactRouterAdapter.d.ts +0 -1
  130. package/dist/core/router/adapter/react-router/index.d.ts +0 -1
  131. package/dist/core/router/adapter/types.cjs.map +1 -1
  132. package/dist/core/router/adapter/types.d.ts +1 -2
  133. package/dist/core/router/adapter/types.js.map +1 -1
  134. package/dist/core/router/dev/RouterDevTools.cjs +148 -296
  135. package/dist/core/router/dev/RouterDevTools.cjs.map +1 -1
  136. package/dist/core/router/dev/RouterDevTools.d.ts +1 -6
  137. package/dist/core/router/dev/RouterDevTools.js +149 -301
  138. package/dist/core/router/dev/RouterDevTools.js.map +1 -1
  139. package/dist/core/router/dev/index.d.ts +0 -1
  140. package/dist/core/router/dynamic/DynamicRouteManager.d.ts +0 -1
  141. package/dist/core/router/dynamic/index.d.ts +0 -1
  142. package/dist/core/router/errors/RouterError.d.ts +0 -1
  143. package/dist/core/router/errors/index.d.ts +0 -1
  144. package/dist/core/router/index.d.ts +0 -1
  145. package/dist/core/router/lifecycle/RouterLifecycleManager.d.ts +0 -1
  146. package/dist/core/router/lifecycle/index.d.ts +0 -1
  147. package/dist/core/router/middleware/RouterMiddlewareManager.d.ts +0 -1
  148. package/dist/core/router/middleware/auth.d.ts +0 -1
  149. package/dist/core/router/middleware/index.d.ts +0 -1
  150. package/dist/core/router/middleware/types.d.ts +0 -1
  151. package/dist/core/router/monitoring/RouterMonitoring.d.ts +0 -1
  152. package/dist/core/router/monitoring/index.d.ts +0 -1
  153. package/dist/core/router/navigation/RouterNavigation.d.ts +0 -1
  154. package/dist/core/router/navigation/index.d.ts +0 -1
  155. package/dist/core/router/performance/RouteCache.d.ts +0 -1
  156. package/dist/core/router/performance/RoutePreloader.d.ts +0 -1
  157. package/dist/core/router/performance/index.d.ts +0 -1
  158. package/dist/core/router/plugin/RouterPluginManager.d.ts +0 -1
  159. package/dist/core/router/plugin/index.d.ts +0 -1
  160. package/dist/core/router/plugin/types.d.ts +0 -1
  161. package/dist/core/router/types.d.ts +1 -2
  162. package/dist/core/router/types.js.map +1 -1
  163. package/dist/core/router/utils/adapters/react-router/RouteErrorBoundary.cjs +90 -103
  164. package/dist/core/router/utils/adapters/react-router/RouteErrorBoundary.cjs.map +1 -1
  165. package/dist/core/router/utils/adapters/react-router/RouteErrorBoundary.d.ts +0 -1
  166. package/dist/core/router/utils/adapters/react-router/RouteErrorBoundary.js +91 -104
  167. package/dist/core/router/utils/adapters/react-router/RouteErrorBoundary.js.map +1 -1
  168. package/dist/core/router/utils/adapters/react-router/transform.cjs +13 -4
  169. package/dist/core/router/utils/adapters/react-router/transform.cjs.map +1 -1
  170. package/dist/core/router/utils/adapters/react-router/transform.d.ts +0 -1
  171. package/dist/core/router/utils/adapters/react-router/transform.js +13 -4
  172. package/dist/core/router/utils/adapters/react-router/transform.js.map +1 -1
  173. package/dist/core/router/utils/transform.cjs +1 -1
  174. package/dist/core/router/utils/transform.cjs.map +1 -1
  175. package/dist/core/router/utils/transform.d.ts +0 -1
  176. package/dist/core/router/utils/transform.js +1 -1
  177. package/dist/core/router/utils/transform.js.map +1 -1
  178. package/dist/core/router/validation/RouterConfigValidator.d.ts +0 -1
  179. package/dist/core/router/validation/index.d.ts +0 -1
  180. package/dist/core/router/validation/schema.d.ts +0 -1
  181. package/dist/core/router/version/RouteVersionManager.d.ts +0 -1
  182. package/dist/core/router/version/index.d.ts +0 -1
  183. package/dist/core/splash/SplashScreen.cjs +101 -15
  184. package/dist/core/splash/SplashScreen.cjs.map +1 -1
  185. package/dist/core/splash/SplashScreen.d.ts +0 -1
  186. package/dist/core/splash/SplashScreen.js +101 -15
  187. package/dist/core/splash/SplashScreen.js.map +1 -1
  188. package/dist/core/splash/index.d.ts +0 -1
  189. package/dist/core/splash/splashScreenUtils.d.ts +0 -1
  190. package/dist/core/startup/AppInstance.d.ts +0 -1
  191. package/dist/core/startup/environment.d.ts +0 -1
  192. package/dist/core/startup/index.d.ts +0 -1
  193. package/dist/core/startup/initializeServices.cjs +69 -24
  194. package/dist/core/startup/initializeServices.cjs.map +1 -1
  195. package/dist/core/startup/initializeServices.d.ts +9 -3
  196. package/dist/core/startup/initializeServices.js +73 -26
  197. package/dist/core/startup/initializeServices.js.map +1 -1
  198. package/dist/core/startup/performanceTracker.d.ts +0 -1
  199. package/dist/core/startup/renderApp.cjs +110 -69
  200. package/dist/core/startup/renderApp.cjs.map +1 -1
  201. package/dist/core/startup/renderApp.d.ts +2 -3
  202. package/dist/core/startup/renderApp.js +111 -70
  203. package/dist/core/startup/renderApp.js.map +1 -1
  204. package/dist/core/startup/startApp.cjs +123 -11
  205. package/dist/core/startup/startApp.cjs.map +1 -1
  206. package/dist/core/startup/startApp.d.ts +0 -1
  207. package/dist/core/startup/startApp.js +123 -11
  208. package/dist/core/startup/startApp.js.map +1 -1
  209. package/dist/core/types.d.ts +34 -21
  210. package/dist/core/types.js.map +1 -1
  211. package/dist/core/ui-adapter/adapters.cjs +45 -0
  212. package/dist/core/ui-adapter/adapters.cjs.map +1 -0
  213. package/dist/core/ui-adapter/adapters.d.ts +4 -0
  214. package/dist/core/ui-adapter/adapters.js +27 -0
  215. package/dist/core/ui-adapter/adapters.js.map +1 -0
  216. package/dist/core/ui-adapter/index.cjs +21 -0
  217. package/dist/core/ui-adapter/index.cjs.map +1 -0
  218. package/dist/core/ui-adapter/index.d.ts +2 -0
  219. package/dist/core/ui-adapter/index.js +3 -0
  220. package/dist/core/ui-adapter/index.js.map +1 -0
  221. package/dist/core/ui-adapter/types.cjs +6 -0
  222. package/dist/core/ui-adapter/types.cjs.map +1 -0
  223. package/dist/core/ui-adapter/types.d.ts +24 -0
  224. package/dist/core/ui-adapter/types.js +3 -0
  225. package/dist/core/ui-adapter/types.js.map +1 -0
  226. package/dist/index.cjs +1 -0
  227. package/dist/index.cjs.map +1 -1
  228. package/dist/index.d.ts +1 -1
  229. package/dist/index.js +1 -0
  230. package/dist/index.js.map +1 -1
  231. package/dist/index.umd.d.ts +0 -1
  232. package/dist/index.umd.js +33004 -38475
  233. package/dist/index.umd.js.map +1 -1
  234. package/dist/library/index.d.ts +0 -1
  235. package/dist/library/locale/index.d.ts +0 -1
  236. package/dist/library/locale/langs/en-us/index.d.ts +0 -1
  237. package/dist/library/locale/langs/zh-cn/index.d.ts +0 -1
  238. package/dist/library/locale/types.d.ts +0 -1
  239. package/dist/library/storage/cache.d.ts +0 -1
  240. package/dist/library/storage/encryption.d.ts +0 -1
  241. package/dist/library/storage/index.d.ts +0 -1
  242. package/dist/request/adapter/RequestAdapter.d.ts +0 -1
  243. package/dist/request/adapter/axiosAdapter.d.ts +0 -1
  244. package/dist/request/adapter/fetchAdapter.d.ts +0 -1
  245. package/dist/request/adapter/index.d.ts +0 -1
  246. package/dist/request/adapter/kyAdapter.d.ts +0 -1
  247. package/dist/request/adapter/undiciAdapter.d.ts +0 -1
  248. package/dist/request/core/RequestClient.d.ts +0 -1
  249. package/dist/request/core/index.d.ts +0 -1
  250. package/dist/request/index.d.ts +0 -1
  251. package/dist/request/plugin/RequestPlugin.d.ts +0 -1
  252. package/dist/request/plugin/cache.d.ts +0 -1
  253. package/dist/request/plugin/csrfPlugin.d.ts +0 -1
  254. package/dist/request/plugin/index.d.ts +0 -1
  255. package/dist/request/plugin/monitoring.d.ts +0 -1
  256. package/dist/request/plugin/queue.d.ts +0 -1
  257. package/dist/request/plugin/retry.d.ts +0 -1
  258. package/dist/request/plugin/validation.d.ts +0 -1
  259. package/dist/request/runtime/RequestContext.d.ts +0 -1
  260. package/dist/request/runtime/index.d.ts +0 -1
  261. package/dist/request/types.d.ts +0 -1
  262. package/dist/request/utils/RequestQueueManager.d.ts +0 -1
  263. package/dist/request/utils/dependencyCheck.d.ts +0 -1
  264. package/dist/request/utils/index.d.ts +0 -1
  265. package/dist/request.umd.js +5392 -0
  266. package/dist/request.umd.js.map +1 -0
  267. package/dist/state/StateManager.d.ts +0 -1
  268. package/dist/state/adapters/AdapterFactory.d.ts +0 -1
  269. package/dist/state/adapters/DefaultAdapter.d.ts +0 -1
  270. package/dist/state/adapters/ReduxAdapter.d.ts +0 -1
  271. package/dist/state/adapters/ZustandAdapter.d.ts +0 -1
  272. package/dist/state/adapters/index.d.ts +0 -1
  273. package/dist/state/adapters/types.d.ts +0 -1
  274. package/dist/state/core/DerivedStateInstance.d.ts +0 -1
  275. package/dist/state/core/StateInstance.d.ts +0 -1
  276. package/dist/state/core/StateRegistry.d.ts +0 -1
  277. package/dist/state/core/StateScope.d.ts +0 -1
  278. package/dist/state/core/index.d.ts +0 -1
  279. package/dist/state/index.d.ts +0 -1
  280. package/dist/state/types.d.ts +0 -1
  281. package/dist/state.umd.js +1414 -0
  282. package/dist/state.umd.js.map +1 -0
  283. package/dist/types.d.ts +0 -1
  284. package/dist/utils/analytics.d.ts +0 -1
  285. package/dist/utils/configSecurity.d.ts +0 -1
  286. package/dist/utils/csrf.d.ts +0 -1
  287. package/dist/utils/errors/ErrorCodes.d.ts +0 -1
  288. package/dist/utils/errors.cjs +44 -1
  289. package/dist/utils/errors.cjs.map +1 -1
  290. package/dist/utils/errors.d.ts +5 -1
  291. package/dist/utils/errors.js +44 -1
  292. package/dist/utils/errors.js.map +1 -1
  293. package/dist/utils/index.d.ts +0 -1
  294. package/dist/utils/logger.d.ts +0 -1
  295. package/dist/utils/logger.types.d.ts +0 -1
  296. package/dist/utils/monitoring.d.ts +0 -1
  297. package/dist/utils/performance.d.ts +0 -1
  298. package/dist/utils/resourceLoader.d.ts +0 -1
  299. package/dist/utils/runtimeSecurity.d.ts +0 -1
  300. package/dist/utils/security.d.ts +0 -1
  301. package/dist/utils/traceId.d.ts +0 -1
  302. package/dist/utils/validation.d.ts +0 -1
  303. package/package.json +57 -8
  304. package/dist/components/index.d.ts.map +0 -1
  305. package/dist/core/Test.d.ts.map +0 -1
  306. package/dist/core/app/AppContext.d.ts.map +0 -1
  307. package/dist/core/app/AppContext.types.d.ts.map +0 -1
  308. package/dist/core/app/BasicLayout.d.ts.map +0 -1
  309. package/dist/core/app/DefaultApp.d.ts.map +0 -1
  310. package/dist/core/app/index.d.ts.map +0 -1
  311. package/dist/core/config/AppConfig.d.ts.map +0 -1
  312. package/dist/core/config/ConfigLoader.d.ts.map +0 -1
  313. package/dist/core/config/ConfigValidator.d.ts.map +0 -1
  314. package/dist/core/config/index.d.ts.map +0 -1
  315. package/dist/core/dev/DevTools.d.ts.map +0 -1
  316. package/dist/core/error/ErrorBoundary.d.ts.map +0 -1
  317. package/dist/core/error/index.d.ts.map +0 -1
  318. package/dist/core/event/AppEventBus.d.ts.map +0 -1
  319. package/dist/core/event/frameworkEvents.d.ts.map +0 -1
  320. package/dist/core/event/hooks.d.ts.map +0 -1
  321. package/dist/core/event/index.d.ts.map +0 -1
  322. package/dist/core/event/types.d.ts.map +0 -1
  323. package/dist/core/event/useEventBus.d.ts.map +0 -1
  324. package/dist/core/index.d.ts.map +0 -1
  325. package/dist/core/initialization/InitializationErrorThrower.d.ts.map +0 -1
  326. package/dist/core/initialization/index.d.ts.map +0 -1
  327. package/dist/core/initialization/initialization.d.ts.map +0 -1
  328. package/dist/core/initialization/initializationErrorState.d.ts.map +0 -1
  329. package/dist/core/middleware.d.ts.map +0 -1
  330. package/dist/core/plugin/PluginEventBus.d.ts.map +0 -1
  331. package/dist/core/plugin/PluginSandbox.d.ts.map +0 -1
  332. package/dist/core/plugin.d.ts.map +0 -1
  333. package/dist/core/router/RouterManager.d.ts.map +0 -1
  334. package/dist/core/router/adapter/AdapterManager.d.ts.map +0 -1
  335. package/dist/core/router/adapter/index.d.ts.map +0 -1
  336. package/dist/core/router/adapter/react-router/ReactRouterAdapter.d.ts.map +0 -1
  337. package/dist/core/router/adapter/react-router/index.d.ts.map +0 -1
  338. package/dist/core/router/adapter/types.d.ts.map +0 -1
  339. package/dist/core/router/dev/RouterDevTools.d.ts.map +0 -1
  340. package/dist/core/router/dev/index.d.ts.map +0 -1
  341. package/dist/core/router/dynamic/DynamicRouteManager.d.ts.map +0 -1
  342. package/dist/core/router/dynamic/index.d.ts.map +0 -1
  343. package/dist/core/router/errors/RouterError.d.ts.map +0 -1
  344. package/dist/core/router/errors/index.d.ts.map +0 -1
  345. package/dist/core/router/index.d.ts.map +0 -1
  346. package/dist/core/router/lifecycle/RouterLifecycleManager.d.ts.map +0 -1
  347. package/dist/core/router/lifecycle/index.d.ts.map +0 -1
  348. package/dist/core/router/middleware/RouterMiddlewareManager.d.ts.map +0 -1
  349. package/dist/core/router/middleware/auth.d.ts.map +0 -1
  350. package/dist/core/router/middleware/index.d.ts.map +0 -1
  351. package/dist/core/router/middleware/types.d.ts.map +0 -1
  352. package/dist/core/router/monitoring/RouterMonitoring.d.ts.map +0 -1
  353. package/dist/core/router/monitoring/index.d.ts.map +0 -1
  354. package/dist/core/router/navigation/RouterNavigation.d.ts.map +0 -1
  355. package/dist/core/router/navigation/index.d.ts.map +0 -1
  356. package/dist/core/router/performance/RouteCache.d.ts.map +0 -1
  357. package/dist/core/router/performance/RoutePreloader.d.ts.map +0 -1
  358. package/dist/core/router/performance/index.d.ts.map +0 -1
  359. package/dist/core/router/plugin/RouterPluginManager.d.ts.map +0 -1
  360. package/dist/core/router/plugin/index.d.ts.map +0 -1
  361. package/dist/core/router/plugin/types.d.ts.map +0 -1
  362. package/dist/core/router/types.d.ts.map +0 -1
  363. package/dist/core/router/utils/adapters/react-router/RouteErrorBoundary.d.ts.map +0 -1
  364. package/dist/core/router/utils/adapters/react-router/transform.d.ts.map +0 -1
  365. package/dist/core/router/utils/transform.d.ts.map +0 -1
  366. package/dist/core/router/validation/RouterConfigValidator.d.ts.map +0 -1
  367. package/dist/core/router/validation/index.d.ts.map +0 -1
  368. package/dist/core/router/validation/schema.d.ts.map +0 -1
  369. package/dist/core/router/version/RouteVersionManager.d.ts.map +0 -1
  370. package/dist/core/router/version/index.d.ts.map +0 -1
  371. package/dist/core/splash/SplashScreen.d.ts.map +0 -1
  372. package/dist/core/splash/index.d.ts.map +0 -1
  373. package/dist/core/splash/splashScreenUtils.d.ts.map +0 -1
  374. package/dist/core/startup/AppInstance.d.ts.map +0 -1
  375. package/dist/core/startup/environment.d.ts.map +0 -1
  376. package/dist/core/startup/index.d.ts.map +0 -1
  377. package/dist/core/startup/initializeServices.d.ts.map +0 -1
  378. package/dist/core/startup/performanceTracker.d.ts.map +0 -1
  379. package/dist/core/startup/renderApp.d.ts.map +0 -1
  380. package/dist/core/startup/startApp.d.ts.map +0 -1
  381. package/dist/core/types.d.ts.map +0 -1
  382. package/dist/index.d.ts.map +0 -1
  383. package/dist/index.umd.d.ts.map +0 -1
  384. package/dist/library/index.d.ts.map +0 -1
  385. package/dist/library/locale/index.d.ts.map +0 -1
  386. package/dist/library/locale/langs/en-us/index.d.ts.map +0 -1
  387. package/dist/library/locale/langs/zh-cn/index.d.ts.map +0 -1
  388. package/dist/library/locale/types.d.ts.map +0 -1
  389. package/dist/library/storage/cache.d.ts.map +0 -1
  390. package/dist/library/storage/encryption.d.ts.map +0 -1
  391. package/dist/library/storage/index.d.ts.map +0 -1
  392. package/dist/request/adapter/RequestAdapter.d.ts.map +0 -1
  393. package/dist/request/adapter/axiosAdapter.d.ts.map +0 -1
  394. package/dist/request/adapter/fetchAdapter.d.ts.map +0 -1
  395. package/dist/request/adapter/index.d.ts.map +0 -1
  396. package/dist/request/adapter/kyAdapter.d.ts.map +0 -1
  397. package/dist/request/adapter/undiciAdapter.d.ts.map +0 -1
  398. package/dist/request/core/RequestClient.d.ts.map +0 -1
  399. package/dist/request/core/index.d.ts.map +0 -1
  400. package/dist/request/index.d.ts.map +0 -1
  401. package/dist/request/plugin/RequestPlugin.d.ts.map +0 -1
  402. package/dist/request/plugin/cache.d.ts.map +0 -1
  403. package/dist/request/plugin/csrfPlugin.d.ts.map +0 -1
  404. package/dist/request/plugin/index.d.ts.map +0 -1
  405. package/dist/request/plugin/monitoring.d.ts.map +0 -1
  406. package/dist/request/plugin/queue.d.ts.map +0 -1
  407. package/dist/request/plugin/retry.d.ts.map +0 -1
  408. package/dist/request/plugin/validation.d.ts.map +0 -1
  409. package/dist/request/runtime/RequestContext.d.ts.map +0 -1
  410. package/dist/request/runtime/index.d.ts.map +0 -1
  411. package/dist/request/types.d.ts.map +0 -1
  412. package/dist/request/utils/RequestQueueManager.d.ts.map +0 -1
  413. package/dist/request/utils/dependencyCheck.d.ts.map +0 -1
  414. package/dist/request/utils/index.d.ts.map +0 -1
  415. package/dist/state/StateManager.d.ts.map +0 -1
  416. package/dist/state/adapters/AdapterFactory.d.ts.map +0 -1
  417. package/dist/state/adapters/DefaultAdapter.d.ts.map +0 -1
  418. package/dist/state/adapters/ReduxAdapter.d.ts.map +0 -1
  419. package/dist/state/adapters/ZustandAdapter.d.ts.map +0 -1
  420. package/dist/state/adapters/index.d.ts.map +0 -1
  421. package/dist/state/adapters/types.d.ts.map +0 -1
  422. package/dist/state/core/DerivedStateInstance.d.ts.map +0 -1
  423. package/dist/state/core/StateInstance.d.ts.map +0 -1
  424. package/dist/state/core/StateRegistry.d.ts.map +0 -1
  425. package/dist/state/core/StateScope.d.ts.map +0 -1
  426. package/dist/state/core/index.d.ts.map +0 -1
  427. package/dist/state/index.d.ts.map +0 -1
  428. package/dist/state/types.d.ts.map +0 -1
  429. package/dist/types.d.ts.map +0 -1
  430. package/dist/utils/analytics.d.ts.map +0 -1
  431. package/dist/utils/configSecurity.d.ts.map +0 -1
  432. package/dist/utils/csrf.d.ts.map +0 -1
  433. package/dist/utils/errors/ErrorCodes.d.ts.map +0 -1
  434. package/dist/utils/errors.d.ts.map +0 -1
  435. package/dist/utils/index.d.ts.map +0 -1
  436. package/dist/utils/logger.d.ts.map +0 -1
  437. package/dist/utils/logger.types.d.ts.map +0 -1
  438. package/dist/utils/monitoring.d.ts.map +0 -1
  439. package/dist/utils/performance.d.ts.map +0 -1
  440. package/dist/utils/resourceLoader.d.ts.map +0 -1
  441. package/dist/utils/runtimeSecurity.d.ts.map +0 -1
  442. package/dist/utils/security.d.ts.map +0 -1
  443. package/dist/utils/traceId.d.ts.map +0 -1
  444. package/dist/utils/validation.d.ts.map +0 -1
@@ -0,0 +1,2406 @@
1
+ /*!
2
+ * @vlian/framework v1.2.16
3
+ * Secra Framework - 一个现代化的低代码框架
4
+ * (c) 2026 Secra Framework Contributors
5
+ * Licensed under Apache-2.0
6
+ */
7
+ (function (global, factory) {
8
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
9
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
10
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.vlianFrameworkAnalytics = {}));
11
+ })(this, (function (exports) { 'use strict';
12
+
13
+ /**
14
+ * 日志级别枚举
15
+ */ var LogLevel = /*#__PURE__*/ function(LogLevel) {
16
+ LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
17
+ LogLevel[LogLevel["INFO"] = 1] = "INFO";
18
+ LogLevel[LogLevel["WARN"] = 2] = "WARN";
19
+ LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
20
+ LogLevel[LogLevel["NONE"] = 4] = "NONE";
21
+ return LogLevel;
22
+ }({});
23
+
24
+ /*! @license DOMPurify 3.3.1 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.3.1/LICENSE */
25
+
26
+ const {
27
+ entries,
28
+ setPrototypeOf,
29
+ isFrozen,
30
+ getPrototypeOf,
31
+ getOwnPropertyDescriptor
32
+ } = Object;
33
+ let {
34
+ freeze,
35
+ seal,
36
+ create
37
+ } = Object; // eslint-disable-line import/no-mutable-exports
38
+ let {
39
+ apply,
40
+ construct
41
+ } = typeof Reflect !== 'undefined' && Reflect;
42
+ if (!freeze) {
43
+ freeze = function freeze(x) {
44
+ return x;
45
+ };
46
+ }
47
+ if (!seal) {
48
+ seal = function seal(x) {
49
+ return x;
50
+ };
51
+ }
52
+ if (!apply) {
53
+ apply = function apply(func, thisArg) {
54
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
55
+ args[_key - 2] = arguments[_key];
56
+ }
57
+ return func.apply(thisArg, args);
58
+ };
59
+ }
60
+ if (!construct) {
61
+ construct = function construct(Func) {
62
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
63
+ args[_key2 - 1] = arguments[_key2];
64
+ }
65
+ return new Func(...args);
66
+ };
67
+ }
68
+ const arrayForEach = unapply(Array.prototype.forEach);
69
+ const arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
70
+ const arrayPop = unapply(Array.prototype.pop);
71
+ const arrayPush = unapply(Array.prototype.push);
72
+ const arraySplice = unapply(Array.prototype.splice);
73
+ const stringToLowerCase = unapply(String.prototype.toLowerCase);
74
+ const stringToString = unapply(String.prototype.toString);
75
+ const stringMatch = unapply(String.prototype.match);
76
+ const stringReplace = unapply(String.prototype.replace);
77
+ const stringIndexOf = unapply(String.prototype.indexOf);
78
+ const stringTrim = unapply(String.prototype.trim);
79
+ const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
80
+ const regExpTest = unapply(RegExp.prototype.test);
81
+ const typeErrorCreate = unconstruct(TypeError);
82
+ /**
83
+ * Creates a new function that calls the given function with a specified thisArg and arguments.
84
+ *
85
+ * @param func - The function to be wrapped and called.
86
+ * @returns A new function that calls the given function with a specified thisArg and arguments.
87
+ */
88
+ function unapply(func) {
89
+ return function (thisArg) {
90
+ if (thisArg instanceof RegExp) {
91
+ thisArg.lastIndex = 0;
92
+ }
93
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
94
+ args[_key3 - 1] = arguments[_key3];
95
+ }
96
+ return apply(func, thisArg, args);
97
+ };
98
+ }
99
+ /**
100
+ * Creates a new function that constructs an instance of the given constructor function with the provided arguments.
101
+ *
102
+ * @param func - The constructor function to be wrapped and called.
103
+ * @returns A new function that constructs an instance of the given constructor function with the provided arguments.
104
+ */
105
+ function unconstruct(Func) {
106
+ return function () {
107
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
108
+ args[_key4] = arguments[_key4];
109
+ }
110
+ return construct(Func, args);
111
+ };
112
+ }
113
+ /**
114
+ * Add properties to a lookup table
115
+ *
116
+ * @param set - The set to which elements will be added.
117
+ * @param array - The array containing elements to be added to the set.
118
+ * @param transformCaseFunc - An optional function to transform the case of each element before adding to the set.
119
+ * @returns The modified set with added elements.
120
+ */
121
+ function addToSet(set, array) {
122
+ let transformCaseFunc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : stringToLowerCase;
123
+ if (setPrototypeOf) {
124
+ // Make 'in' and truthy checks like Boolean(set.constructor)
125
+ // independent of any properties defined on Object.prototype.
126
+ // Prevent prototype setters from intercepting set as a this value.
127
+ setPrototypeOf(set, null);
128
+ }
129
+ let l = array.length;
130
+ while (l--) {
131
+ let element = array[l];
132
+ if (typeof element === 'string') {
133
+ const lcElement = transformCaseFunc(element);
134
+ if (lcElement !== element) {
135
+ // Config presets (e.g. tags.js, attrs.js) are immutable.
136
+ if (!isFrozen(array)) {
137
+ array[l] = lcElement;
138
+ }
139
+ element = lcElement;
140
+ }
141
+ }
142
+ set[element] = true;
143
+ }
144
+ return set;
145
+ }
146
+ /**
147
+ * Clean up an array to harden against CSPP
148
+ *
149
+ * @param array - The array to be cleaned.
150
+ * @returns The cleaned version of the array
151
+ */
152
+ function cleanArray(array) {
153
+ for (let index = 0; index < array.length; index++) {
154
+ const isPropertyExist = objectHasOwnProperty(array, index);
155
+ if (!isPropertyExist) {
156
+ array[index] = null;
157
+ }
158
+ }
159
+ return array;
160
+ }
161
+ /**
162
+ * Shallow clone an object
163
+ *
164
+ * @param object - The object to be cloned.
165
+ * @returns A new object that copies the original.
166
+ */
167
+ function clone(object) {
168
+ const newObject = create(null);
169
+ for (const [property, value] of entries(object)) {
170
+ const isPropertyExist = objectHasOwnProperty(object, property);
171
+ if (isPropertyExist) {
172
+ if (Array.isArray(value)) {
173
+ newObject[property] = cleanArray(value);
174
+ } else if (value && typeof value === 'object' && value.constructor === Object) {
175
+ newObject[property] = clone(value);
176
+ } else {
177
+ newObject[property] = value;
178
+ }
179
+ }
180
+ }
181
+ return newObject;
182
+ }
183
+ /**
184
+ * This method automatically checks if the prop is function or getter and behaves accordingly.
185
+ *
186
+ * @param object - The object to look up the getter function in its prototype chain.
187
+ * @param prop - The property name for which to find the getter function.
188
+ * @returns The getter function found in the prototype chain or a fallback function.
189
+ */
190
+ function lookupGetter(object, prop) {
191
+ while (object !== null) {
192
+ const desc = getOwnPropertyDescriptor(object, prop);
193
+ if (desc) {
194
+ if (desc.get) {
195
+ return unapply(desc.get);
196
+ }
197
+ if (typeof desc.value === 'function') {
198
+ return unapply(desc.value);
199
+ }
200
+ }
201
+ object = getPrototypeOf(object);
202
+ }
203
+ function fallbackValue() {
204
+ return null;
205
+ }
206
+ return fallbackValue;
207
+ }
208
+
209
+ const html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'search', 'section', 'select', 'shadow', 'slot', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']);
210
+ const svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'enterkeyhint', 'exportparts', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'inputmode', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'part', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);
211
+ const svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']);
212
+ // List of SVG elements that are disallowed by default.
213
+ // We still need to know them so that we can do namespace
214
+ // checks properly in case one wants to add them to
215
+ // allow-list.
216
+ const svgDisallowed = freeze(['animate', 'color-profile', 'cursor', 'discard', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'foreignobject', 'hatch', 'hatchpath', 'mesh', 'meshgradient', 'meshpatch', 'meshrow', 'missing-glyph', 'script', 'set', 'solidcolor', 'unknown', 'use']);
217
+ const mathMl$1 = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'mprescripts']);
218
+ // Similarly to SVG, we want to know all MathML elements,
219
+ // even those that we disallow by default.
220
+ const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
221
+ const text = freeze(['#text']);
222
+
223
+ const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'exportparts', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inert', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'part', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'slot', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns', 'slot']);
224
+ const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'exponent', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'mask-type', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'slope', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);
225
+ const mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);
226
+ const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
227
+
228
+ // eslint-disable-next-line unicorn/better-regex
229
+ const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
230
+ const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
231
+ const TMPLIT_EXPR = seal(/\$\{[\w\W]*/gm); // eslint-disable-line unicorn/better-regex
232
+ const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/); // eslint-disable-line no-useless-escape
233
+ const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
234
+ const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
235
+ );
236
+ const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
237
+ const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
238
+ );
239
+ const DOCTYPE_NAME = seal(/^html$/i);
240
+ const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
241
+
242
+ var EXPRESSIONS = /*#__PURE__*/Object.freeze({
243
+ __proto__: null,
244
+ ARIA_ATTR: ARIA_ATTR,
245
+ ATTR_WHITESPACE: ATTR_WHITESPACE,
246
+ CUSTOM_ELEMENT: CUSTOM_ELEMENT,
247
+ DATA_ATTR: DATA_ATTR,
248
+ DOCTYPE_NAME: DOCTYPE_NAME,
249
+ ERB_EXPR: ERB_EXPR,
250
+ IS_ALLOWED_URI: IS_ALLOWED_URI,
251
+ IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
252
+ MUSTACHE_EXPR: MUSTACHE_EXPR,
253
+ TMPLIT_EXPR: TMPLIT_EXPR
254
+ });
255
+
256
+ /* eslint-disable @typescript-eslint/indent */
257
+ // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
258
+ const NODE_TYPE = {
259
+ element: 1,
260
+ text: 3,
261
+ // Deprecated
262
+ progressingInstruction: 7,
263
+ comment: 8,
264
+ document: 9};
265
+ const getGlobal = function getGlobal() {
266
+ return typeof window === 'undefined' ? null : window;
267
+ };
268
+ /**
269
+ * Creates a no-op policy for internal use only.
270
+ * Don't export this function outside this module!
271
+ * @param trustedTypes The policy factory.
272
+ * @param purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
273
+ * @return The policy created (or null, if Trusted Types
274
+ * are not supported or creating the policy failed).
275
+ */
276
+ const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
277
+ if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
278
+ return null;
279
+ }
280
+ // Allow the callers to control the unique policy name
281
+ // by adding a data-tt-policy-suffix to the script element with the DOMPurify.
282
+ // Policy creation with duplicate names throws in Trusted Types.
283
+ let suffix = null;
284
+ const ATTR_NAME = 'data-tt-policy-suffix';
285
+ if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
286
+ suffix = purifyHostElement.getAttribute(ATTR_NAME);
287
+ }
288
+ const policyName = 'dompurify' + (suffix ? '#' + suffix : '');
289
+ try {
290
+ return trustedTypes.createPolicy(policyName, {
291
+ createHTML(html) {
292
+ return html;
293
+ },
294
+ createScriptURL(scriptUrl) {
295
+ return scriptUrl;
296
+ }
297
+ });
298
+ } catch (_) {
299
+ // Policy creation failed (most likely another DOMPurify script has
300
+ // already run). Skip creating the policy, as this will only cause errors
301
+ // if TT are enforced.
302
+ console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
303
+ return null;
304
+ }
305
+ };
306
+ const _createHooksMap = function _createHooksMap() {
307
+ return {
308
+ afterSanitizeAttributes: [],
309
+ afterSanitizeElements: [],
310
+ afterSanitizeShadowDOM: [],
311
+ beforeSanitizeAttributes: [],
312
+ beforeSanitizeElements: [],
313
+ beforeSanitizeShadowDOM: [],
314
+ uponSanitizeAttribute: [],
315
+ uponSanitizeElement: [],
316
+ uponSanitizeShadowNode: []
317
+ };
318
+ };
319
+ function createDOMPurify() {
320
+ let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
321
+ const DOMPurify = root => createDOMPurify(root);
322
+ DOMPurify.version = '3.3.1';
323
+ DOMPurify.removed = [];
324
+ if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
325
+ // Not running in a browser, provide a factory function
326
+ // so that you can pass your own Window
327
+ DOMPurify.isSupported = false;
328
+ return DOMPurify;
329
+ }
330
+ let {
331
+ document
332
+ } = window;
333
+ const originalDocument = document;
334
+ const currentScript = originalDocument.currentScript;
335
+ const {
336
+ DocumentFragment,
337
+ HTMLTemplateElement,
338
+ Node,
339
+ Element,
340
+ NodeFilter,
341
+ NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,
342
+ HTMLFormElement,
343
+ DOMParser,
344
+ trustedTypes
345
+ } = window;
346
+ const ElementPrototype = Element.prototype;
347
+ const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
348
+ const remove = lookupGetter(ElementPrototype, 'remove');
349
+ const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
350
+ const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
351
+ const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
352
+ // As per issue #47, the web-components registry is inherited by a
353
+ // new document created via createHTMLDocument. As per the spec
354
+ // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
355
+ // a new empty registry is used when creating a template contents owner
356
+ // document, so we use that as our parent document to ensure nothing
357
+ // is inherited.
358
+ if (typeof HTMLTemplateElement === 'function') {
359
+ const template = document.createElement('template');
360
+ if (template.content && template.content.ownerDocument) {
361
+ document = template.content.ownerDocument;
362
+ }
363
+ }
364
+ let trustedTypesPolicy;
365
+ let emptyHTML = '';
366
+ const {
367
+ implementation,
368
+ createNodeIterator,
369
+ createDocumentFragment,
370
+ getElementsByTagName
371
+ } = document;
372
+ const {
373
+ importNode
374
+ } = originalDocument;
375
+ let hooks = _createHooksMap();
376
+ /**
377
+ * Expose whether this browser supports running the full DOMPurify.
378
+ */
379
+ DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
380
+ const {
381
+ MUSTACHE_EXPR,
382
+ ERB_EXPR,
383
+ TMPLIT_EXPR,
384
+ DATA_ATTR,
385
+ ARIA_ATTR,
386
+ IS_SCRIPT_OR_DATA,
387
+ ATTR_WHITESPACE,
388
+ CUSTOM_ELEMENT
389
+ } = EXPRESSIONS;
390
+ let {
391
+ IS_ALLOWED_URI: IS_ALLOWED_URI$1
392
+ } = EXPRESSIONS;
393
+ /**
394
+ * We consider the elements and attributes below to be safe. Ideally
395
+ * don't add any new ones but feel free to remove unwanted ones.
396
+ */
397
+ /* allowed element names */
398
+ let ALLOWED_TAGS = null;
399
+ const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
400
+ /* Allowed attribute names */
401
+ let ALLOWED_ATTR = null;
402
+ const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
403
+ /*
404
+ * Configure how DOMPurify should handle custom elements and their attributes as well as customized built-in elements.
405
+ * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
406
+ * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
407
+ * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
408
+ */
409
+ let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
410
+ tagNameCheck: {
411
+ writable: true,
412
+ configurable: false,
413
+ enumerable: true,
414
+ value: null
415
+ },
416
+ attributeNameCheck: {
417
+ writable: true,
418
+ configurable: false,
419
+ enumerable: true,
420
+ value: null
421
+ },
422
+ allowCustomizedBuiltInElements: {
423
+ writable: true,
424
+ configurable: false,
425
+ enumerable: true,
426
+ value: false
427
+ }
428
+ }));
429
+ /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
430
+ let FORBID_TAGS = null;
431
+ /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
432
+ let FORBID_ATTR = null;
433
+ /* Config object to store ADD_TAGS/ADD_ATTR functions (when used as functions) */
434
+ const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
435
+ tagCheck: {
436
+ writable: true,
437
+ configurable: false,
438
+ enumerable: true,
439
+ value: null
440
+ },
441
+ attributeCheck: {
442
+ writable: true,
443
+ configurable: false,
444
+ enumerable: true,
445
+ value: null
446
+ }
447
+ }));
448
+ /* Decide if ARIA attributes are okay */
449
+ let ALLOW_ARIA_ATTR = true;
450
+ /* Decide if custom data attributes are okay */
451
+ let ALLOW_DATA_ATTR = true;
452
+ /* Decide if unknown protocols are okay */
453
+ let ALLOW_UNKNOWN_PROTOCOLS = false;
454
+ /* Decide if self-closing tags in attributes are allowed.
455
+ * Usually removed due to a mXSS issue in jQuery 3.0 */
456
+ let ALLOW_SELF_CLOSE_IN_ATTR = true;
457
+ /* Output should be safe for common template engines.
458
+ * This means, DOMPurify removes data attributes, mustaches and ERB
459
+ */
460
+ let SAFE_FOR_TEMPLATES = false;
461
+ /* Output should be safe even for XML used within HTML and alike.
462
+ * This means, DOMPurify removes comments when containing risky content.
463
+ */
464
+ let SAFE_FOR_XML = true;
465
+ /* Decide if document with <html>... should be returned */
466
+ let WHOLE_DOCUMENT = false;
467
+ /* Track whether config is already set on this instance of DOMPurify. */
468
+ let SET_CONFIG = false;
469
+ /* Decide if all elements (e.g. style, script) must be children of
470
+ * document.body. By default, browsers might move them to document.head */
471
+ let FORCE_BODY = false;
472
+ /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
473
+ * string (or a TrustedHTML object if Trusted Types are supported).
474
+ * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
475
+ */
476
+ let RETURN_DOM = false;
477
+ /* Decide if a DOM `DocumentFragment` should be returned, instead of a html
478
+ * string (or a TrustedHTML object if Trusted Types are supported) */
479
+ let RETURN_DOM_FRAGMENT = false;
480
+ /* Try to return a Trusted Type object instead of a string, return a string in
481
+ * case Trusted Types are not supported */
482
+ let RETURN_TRUSTED_TYPE = false;
483
+ /* Output should be free from DOM clobbering attacks?
484
+ * This sanitizes markups named with colliding, clobberable built-in DOM APIs.
485
+ */
486
+ let SANITIZE_DOM = true;
487
+ /* Achieve full DOM Clobbering protection by isolating the namespace of named
488
+ * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
489
+ *
490
+ * HTML/DOM spec rules that enable DOM Clobbering:
491
+ * - Named Access on Window (§7.3.3)
492
+ * - DOM Tree Accessors (§3.1.5)
493
+ * - Form Element Parent-Child Relations (§4.10.3)
494
+ * - Iframe srcdoc / Nested WindowProxies (§4.8.5)
495
+ * - HTMLCollection (§4.2.10.2)
496
+ *
497
+ * Namespace isolation is implemented by prefixing `id` and `name` attributes
498
+ * with a constant string, i.e., `user-content-`
499
+ */
500
+ let SANITIZE_NAMED_PROPS = false;
501
+ const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';
502
+ /* Keep element content when removing element? */
503
+ let KEEP_CONTENT = true;
504
+ /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
505
+ * of importing it into a new Document and returning a sanitized copy */
506
+ let IN_PLACE = false;
507
+ /* Allow usage of profiles like html, svg and mathMl */
508
+ let USE_PROFILES = {};
509
+ /* Tags to ignore content of when KEEP_CONTENT is true */
510
+ let FORBID_CONTENTS = null;
511
+ const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
512
+ /* Tags that are safe for data: URIs */
513
+ let DATA_URI_TAGS = null;
514
+ const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
515
+ /* Attributes safe for values like "javascript:" */
516
+ let URI_SAFE_ATTRIBUTES = null;
517
+ const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
518
+ const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
519
+ const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
520
+ const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
521
+ /* Document namespace */
522
+ let NAMESPACE = HTML_NAMESPACE;
523
+ let IS_EMPTY_INPUT = false;
524
+ /* Allowed XHTML+XML namespaces */
525
+ let ALLOWED_NAMESPACES = null;
526
+ const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
527
+ let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
528
+ let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);
529
+ // Certain elements are allowed in both SVG and HTML
530
+ // namespace. We need to specify them explicitly
531
+ // so that they don't get erroneously deleted from
532
+ // HTML namespace.
533
+ const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
534
+ /* Parsing of strict XHTML documents */
535
+ let PARSER_MEDIA_TYPE = null;
536
+ const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
537
+ const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
538
+ let transformCaseFunc = null;
539
+ /* Keep a reference to config to pass to hooks */
540
+ let CONFIG = null;
541
+ /* Ideally, do not touch anything below this line */
542
+ /* ______________________________________________ */
543
+ const formElement = document.createElement('form');
544
+ const isRegexOrFunction = function isRegexOrFunction(testValue) {
545
+ return testValue instanceof RegExp || testValue instanceof Function;
546
+ };
547
+ /**
548
+ * _parseConfig
549
+ *
550
+ * @param cfg optional config literal
551
+ */
552
+ // eslint-disable-next-line complexity
553
+ const _parseConfig = function _parseConfig() {
554
+ let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
555
+ if (CONFIG && CONFIG === cfg) {
556
+ return;
557
+ }
558
+ /* Shield configuration object from tampering */
559
+ if (!cfg || typeof cfg !== 'object') {
560
+ cfg = {};
561
+ }
562
+ /* Shield configuration object from prototype pollution */
563
+ cfg = clone(cfg);
564
+ PARSER_MEDIA_TYPE =
565
+ // eslint-disable-next-line unicorn/prefer-includes
566
+ SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
567
+ // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
568
+ transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
569
+ /* Set configuration parameters */
570
+ ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
571
+ ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
572
+ ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
573
+ URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;
574
+ DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;
575
+ FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
576
+ FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone({});
577
+ FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone({});
578
+ USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;
579
+ ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
580
+ ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
581
+ ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
582
+ ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
583
+ SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
584
+ SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false; // Default true
585
+ WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
586
+ RETURN_DOM = cfg.RETURN_DOM || false; // Default false
587
+ RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
588
+ RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
589
+ FORCE_BODY = cfg.FORCE_BODY || false; // Default false
590
+ SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
591
+ SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
592
+ KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
593
+ IN_PLACE = cfg.IN_PLACE || false; // Default false
594
+ IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
595
+ NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
596
+ MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
597
+ HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
598
+ CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
599
+ if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
600
+ CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
601
+ }
602
+ if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
603
+ CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
604
+ }
605
+ if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
606
+ CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
607
+ }
608
+ if (SAFE_FOR_TEMPLATES) {
609
+ ALLOW_DATA_ATTR = false;
610
+ }
611
+ if (RETURN_DOM_FRAGMENT) {
612
+ RETURN_DOM = true;
613
+ }
614
+ /* Parse profile info */
615
+ if (USE_PROFILES) {
616
+ ALLOWED_TAGS = addToSet({}, text);
617
+ ALLOWED_ATTR = [];
618
+ if (USE_PROFILES.html === true) {
619
+ addToSet(ALLOWED_TAGS, html$1);
620
+ addToSet(ALLOWED_ATTR, html);
621
+ }
622
+ if (USE_PROFILES.svg === true) {
623
+ addToSet(ALLOWED_TAGS, svg$1);
624
+ addToSet(ALLOWED_ATTR, svg);
625
+ addToSet(ALLOWED_ATTR, xml);
626
+ }
627
+ if (USE_PROFILES.svgFilters === true) {
628
+ addToSet(ALLOWED_TAGS, svgFilters);
629
+ addToSet(ALLOWED_ATTR, svg);
630
+ addToSet(ALLOWED_ATTR, xml);
631
+ }
632
+ if (USE_PROFILES.mathMl === true) {
633
+ addToSet(ALLOWED_TAGS, mathMl$1);
634
+ addToSet(ALLOWED_ATTR, mathMl);
635
+ addToSet(ALLOWED_ATTR, xml);
636
+ }
637
+ }
638
+ /* Merge configuration parameters */
639
+ if (cfg.ADD_TAGS) {
640
+ if (typeof cfg.ADD_TAGS === 'function') {
641
+ EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
642
+ } else {
643
+ if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
644
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
645
+ }
646
+ addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
647
+ }
648
+ }
649
+ if (cfg.ADD_ATTR) {
650
+ if (typeof cfg.ADD_ATTR === 'function') {
651
+ EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
652
+ } else {
653
+ if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
654
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
655
+ }
656
+ addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
657
+ }
658
+ }
659
+ if (cfg.ADD_URI_SAFE_ATTR) {
660
+ addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
661
+ }
662
+ if (cfg.FORBID_CONTENTS) {
663
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
664
+ FORBID_CONTENTS = clone(FORBID_CONTENTS);
665
+ }
666
+ addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
667
+ }
668
+ if (cfg.ADD_FORBID_CONTENTS) {
669
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
670
+ FORBID_CONTENTS = clone(FORBID_CONTENTS);
671
+ }
672
+ addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
673
+ }
674
+ /* Add #text in case KEEP_CONTENT is set to true */
675
+ if (KEEP_CONTENT) {
676
+ ALLOWED_TAGS['#text'] = true;
677
+ }
678
+ /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
679
+ if (WHOLE_DOCUMENT) {
680
+ addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
681
+ }
682
+ /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
683
+ if (ALLOWED_TAGS.table) {
684
+ addToSet(ALLOWED_TAGS, ['tbody']);
685
+ delete FORBID_TAGS.tbody;
686
+ }
687
+ if (cfg.TRUSTED_TYPES_POLICY) {
688
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
689
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
690
+ }
691
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
692
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
693
+ }
694
+ // Overwrite existing TrustedTypes policy.
695
+ trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
696
+ // Sign local variables required by `sanitize`.
697
+ emptyHTML = trustedTypesPolicy.createHTML('');
698
+ } else {
699
+ // Uninitialized policy, attempt to initialize the internal dompurify policy.
700
+ if (trustedTypesPolicy === undefined) {
701
+ trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
702
+ }
703
+ // If creating the internal policy succeeded sign internal variables.
704
+ if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
705
+ emptyHTML = trustedTypesPolicy.createHTML('');
706
+ }
707
+ }
708
+ // Prevent further manipulation of configuration.
709
+ // Not available in IE8, Safari 5, etc.
710
+ if (freeze) {
711
+ freeze(cfg);
712
+ }
713
+ CONFIG = cfg;
714
+ };
715
+ /* Keep track of all possible SVG and MathML tags
716
+ * so that we can perform the namespace checks
717
+ * correctly. */
718
+ const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
719
+ const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
720
+ /**
721
+ * @param element a DOM element whose namespace is being checked
722
+ * @returns Return false if the element has a
723
+ * namespace that a spec-compliant parser would never
724
+ * return. Return true otherwise.
725
+ */
726
+ const _checkValidNamespace = function _checkValidNamespace(element) {
727
+ let parent = getParentNode(element);
728
+ // In JSDOM, if we're inside shadow DOM, then parentNode
729
+ // can be null. We just simulate parent in this case.
730
+ if (!parent || !parent.tagName) {
731
+ parent = {
732
+ namespaceURI: NAMESPACE,
733
+ tagName: 'template'
734
+ };
735
+ }
736
+ const tagName = stringToLowerCase(element.tagName);
737
+ const parentTagName = stringToLowerCase(parent.tagName);
738
+ if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
739
+ return false;
740
+ }
741
+ if (element.namespaceURI === SVG_NAMESPACE) {
742
+ // The only way to switch from HTML namespace to SVG
743
+ // is via <svg>. If it happens via any other tag, then
744
+ // it should be killed.
745
+ if (parent.namespaceURI === HTML_NAMESPACE) {
746
+ return tagName === 'svg';
747
+ }
748
+ // The only way to switch from MathML to SVG is via`
749
+ // svg if parent is either <annotation-xml> or MathML
750
+ // text integration points.
751
+ if (parent.namespaceURI === MATHML_NAMESPACE) {
752
+ return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
753
+ }
754
+ // We only allow elements that are defined in SVG
755
+ // spec. All others are disallowed in SVG namespace.
756
+ return Boolean(ALL_SVG_TAGS[tagName]);
757
+ }
758
+ if (element.namespaceURI === MATHML_NAMESPACE) {
759
+ // The only way to switch from HTML namespace to MathML
760
+ // is via <math>. If it happens via any other tag, then
761
+ // it should be killed.
762
+ if (parent.namespaceURI === HTML_NAMESPACE) {
763
+ return tagName === 'math';
764
+ }
765
+ // The only way to switch from SVG to MathML is via
766
+ // <math> and HTML integration points
767
+ if (parent.namespaceURI === SVG_NAMESPACE) {
768
+ return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
769
+ }
770
+ // We only allow elements that are defined in MathML
771
+ // spec. All others are disallowed in MathML namespace.
772
+ return Boolean(ALL_MATHML_TAGS[tagName]);
773
+ }
774
+ if (element.namespaceURI === HTML_NAMESPACE) {
775
+ // The only way to switch from SVG to HTML is via
776
+ // HTML integration points, and from MathML to HTML
777
+ // is via MathML text integration points
778
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
779
+ return false;
780
+ }
781
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
782
+ return false;
783
+ }
784
+ // We disallow tags that are specific for MathML
785
+ // or SVG and should never appear in HTML namespace
786
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
787
+ }
788
+ // For XHTML and XML documents that support custom namespaces
789
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
790
+ return true;
791
+ }
792
+ // The code should never reach this place (this means
793
+ // that the element somehow got namespace that is not
794
+ // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
795
+ // Return false just in case.
796
+ return false;
797
+ };
798
+ /**
799
+ * _forceRemove
800
+ *
801
+ * @param node a DOM node
802
+ */
803
+ const _forceRemove = function _forceRemove(node) {
804
+ arrayPush(DOMPurify.removed, {
805
+ element: node
806
+ });
807
+ try {
808
+ // eslint-disable-next-line unicorn/prefer-dom-node-remove
809
+ getParentNode(node).removeChild(node);
810
+ } catch (_) {
811
+ remove(node);
812
+ }
813
+ };
814
+ /**
815
+ * _removeAttribute
816
+ *
817
+ * @param name an Attribute name
818
+ * @param element a DOM node
819
+ */
820
+ const _removeAttribute = function _removeAttribute(name, element) {
821
+ try {
822
+ arrayPush(DOMPurify.removed, {
823
+ attribute: element.getAttributeNode(name),
824
+ from: element
825
+ });
826
+ } catch (_) {
827
+ arrayPush(DOMPurify.removed, {
828
+ attribute: null,
829
+ from: element
830
+ });
831
+ }
832
+ element.removeAttribute(name);
833
+ // We void attribute values for unremovable "is" attributes
834
+ if (name === 'is') {
835
+ if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
836
+ try {
837
+ _forceRemove(element);
838
+ } catch (_) {}
839
+ } else {
840
+ try {
841
+ element.setAttribute(name, '');
842
+ } catch (_) {}
843
+ }
844
+ }
845
+ };
846
+ /**
847
+ * _initDocument
848
+ *
849
+ * @param dirty - a string of dirty markup
850
+ * @return a DOM, filled with the dirty markup
851
+ */
852
+ const _initDocument = function _initDocument(dirty) {
853
+ /* Create a HTML document */
854
+ let doc = null;
855
+ let leadingWhitespace = null;
856
+ if (FORCE_BODY) {
857
+ dirty = '<remove></remove>' + dirty;
858
+ } else {
859
+ /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
860
+ const matches = stringMatch(dirty, /^[\r\n\t ]+/);
861
+ leadingWhitespace = matches && matches[0];
862
+ }
863
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {
864
+ // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
865
+ dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
866
+ }
867
+ const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
868
+ /*
869
+ * Use the DOMParser API by default, fallback later if needs be
870
+ * DOMParser not work for svg when has multiple root element.
871
+ */
872
+ if (NAMESPACE === HTML_NAMESPACE) {
873
+ try {
874
+ doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
875
+ } catch (_) {}
876
+ }
877
+ /* Use createHTMLDocument in case DOMParser is not available */
878
+ if (!doc || !doc.documentElement) {
879
+ doc = implementation.createDocument(NAMESPACE, 'template', null);
880
+ try {
881
+ doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
882
+ } catch (_) {
883
+ // Syntax error if dirtyPayload is invalid xml
884
+ }
885
+ }
886
+ const body = doc.body || doc.documentElement;
887
+ if (dirty && leadingWhitespace) {
888
+ body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
889
+ }
890
+ /* Work on whole document or just its body */
891
+ if (NAMESPACE === HTML_NAMESPACE) {
892
+ return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
893
+ }
894
+ return WHOLE_DOCUMENT ? doc.documentElement : body;
895
+ };
896
+ /**
897
+ * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
898
+ *
899
+ * @param root The root element or node to start traversing on.
900
+ * @return The created NodeIterator
901
+ */
902
+ const _createNodeIterator = function _createNodeIterator(root) {
903
+ return createNodeIterator.call(root.ownerDocument || root, root,
904
+ // eslint-disable-next-line no-bitwise
905
+ NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
906
+ };
907
+ /**
908
+ * _isClobbered
909
+ *
910
+ * @param element element to check for clobbering attacks
911
+ * @return true if clobbered, false if safe
912
+ */
913
+ const _isClobbered = function _isClobbered(element) {
914
+ return element instanceof HTMLFormElement && (typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' || !(element.attributes instanceof NamedNodeMap) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function');
915
+ };
916
+ /**
917
+ * Checks whether the given object is a DOM node.
918
+ *
919
+ * @param value object to check whether it's a DOM node
920
+ * @return true is object is a DOM node
921
+ */
922
+ const _isNode = function _isNode(value) {
923
+ return typeof Node === 'function' && value instanceof Node;
924
+ };
925
+ function _executeHooks(hooks, currentNode, data) {
926
+ arrayForEach(hooks, hook => {
927
+ hook.call(DOMPurify, currentNode, data, CONFIG);
928
+ });
929
+ }
930
+ /**
931
+ * _sanitizeElements
932
+ *
933
+ * @protect nodeName
934
+ * @protect textContent
935
+ * @protect removeChild
936
+ * @param currentNode to check for permission to exist
937
+ * @return true if node was killed, false if left alive
938
+ */
939
+ const _sanitizeElements = function _sanitizeElements(currentNode) {
940
+ let content = null;
941
+ /* Execute a hook if present */
942
+ _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
943
+ /* Check if element is clobbered or can clobber */
944
+ if (_isClobbered(currentNode)) {
945
+ _forceRemove(currentNode);
946
+ return true;
947
+ }
948
+ /* Now let's check the element's type and name */
949
+ const tagName = transformCaseFunc(currentNode.nodeName);
950
+ /* Execute a hook if present */
951
+ _executeHooks(hooks.uponSanitizeElement, currentNode, {
952
+ tagName,
953
+ allowedTags: ALLOWED_TAGS
954
+ });
955
+ /* Detect mXSS attempts abusing namespace confusion */
956
+ if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\w!]/g, currentNode.textContent)) {
957
+ _forceRemove(currentNode);
958
+ return true;
959
+ }
960
+ /* Remove any occurrence of processing instructions */
961
+ if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
962
+ _forceRemove(currentNode);
963
+ return true;
964
+ }
965
+ /* Remove any kind of possibly harmful comments */
966
+ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
967
+ _forceRemove(currentNode);
968
+ return true;
969
+ }
970
+ /* Remove element if anything forbids its presence */
971
+ if (!(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName])) {
972
+ /* Check if we have a custom element to handle */
973
+ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
974
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
975
+ return false;
976
+ }
977
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
978
+ return false;
979
+ }
980
+ }
981
+ /* Keep content except for bad-listed elements */
982
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
983
+ const parentNode = getParentNode(currentNode) || currentNode.parentNode;
984
+ const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
985
+ if (childNodes && parentNode) {
986
+ const childCount = childNodes.length;
987
+ for (let i = childCount - 1; i >= 0; --i) {
988
+ const childClone = cloneNode(childNodes[i], true);
989
+ childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
990
+ parentNode.insertBefore(childClone, getNextSibling(currentNode));
991
+ }
992
+ }
993
+ }
994
+ _forceRemove(currentNode);
995
+ return true;
996
+ }
997
+ /* Check whether element has a valid namespace */
998
+ if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
999
+ _forceRemove(currentNode);
1000
+ return true;
1001
+ }
1002
+ /* Make sure that older browsers don't get fallback-tag mXSS */
1003
+ if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
1004
+ _forceRemove(currentNode);
1005
+ return true;
1006
+ }
1007
+ /* Sanitize element content to be template-safe */
1008
+ if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
1009
+ /* Get the element's text content */
1010
+ content = currentNode.textContent;
1011
+ arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1012
+ content = stringReplace(content, expr, ' ');
1013
+ });
1014
+ if (currentNode.textContent !== content) {
1015
+ arrayPush(DOMPurify.removed, {
1016
+ element: currentNode.cloneNode()
1017
+ });
1018
+ currentNode.textContent = content;
1019
+ }
1020
+ }
1021
+ /* Execute a hook if present */
1022
+ _executeHooks(hooks.afterSanitizeElements, currentNode, null);
1023
+ return false;
1024
+ };
1025
+ /**
1026
+ * _isValidAttribute
1027
+ *
1028
+ * @param lcTag Lowercase tag name of containing element.
1029
+ * @param lcName Lowercase attribute name.
1030
+ * @param value Attribute value.
1031
+ * @return Returns true if `value` is valid, otherwise false.
1032
+ */
1033
+ // eslint-disable-next-line complexity
1034
+ const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
1035
+ /* Make sure attribute cannot clobber */
1036
+ if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
1037
+ return false;
1038
+ }
1039
+ /* Allow valid data-* attributes: At least one character after "-"
1040
+ (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
1041
+ XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
1042
+ We don't need to check the value; it's always URI safe. */
1043
+ if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
1044
+ if (
1045
+ // First condition does a very basic check if a) it's basically a valid custom element tagname AND
1046
+ // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1047
+ // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
1048
+ _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName, lcTag)) ||
1049
+ // Alternative, second condition checks if it's an `is`-attribute, AND
1050
+ // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1051
+ lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ; else {
1052
+ return false;
1053
+ }
1054
+ /* Check value is safe. First, is attr inert? If so, is safe */
1055
+ } else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if (value) {
1056
+ return false;
1057
+ } else ;
1058
+ return true;
1059
+ };
1060
+ /**
1061
+ * _isBasicCustomElement
1062
+ * checks if at least one dash is included in tagName, and it's not the first char
1063
+ * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
1064
+ *
1065
+ * @param tagName name of the tag of the node to sanitize
1066
+ * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
1067
+ */
1068
+ const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
1069
+ return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);
1070
+ };
1071
+ /**
1072
+ * _sanitizeAttributes
1073
+ *
1074
+ * @protect attributes
1075
+ * @protect nodeName
1076
+ * @protect removeAttribute
1077
+ * @protect setAttribute
1078
+ *
1079
+ * @param currentNode to sanitize
1080
+ */
1081
+ const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
1082
+ /* Execute a hook if present */
1083
+ _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
1084
+ const {
1085
+ attributes
1086
+ } = currentNode;
1087
+ /* Check if we have attributes; if not we might have a text node */
1088
+ if (!attributes || _isClobbered(currentNode)) {
1089
+ return;
1090
+ }
1091
+ const hookEvent = {
1092
+ attrName: '',
1093
+ attrValue: '',
1094
+ keepAttr: true,
1095
+ allowedAttributes: ALLOWED_ATTR,
1096
+ forceKeepAttr: undefined
1097
+ };
1098
+ let l = attributes.length;
1099
+ /* Go backwards over all attributes; safely remove bad ones */
1100
+ while (l--) {
1101
+ const attr = attributes[l];
1102
+ const {
1103
+ name,
1104
+ namespaceURI,
1105
+ value: attrValue
1106
+ } = attr;
1107
+ const lcName = transformCaseFunc(name);
1108
+ const initValue = attrValue;
1109
+ let value = name === 'value' ? initValue : stringTrim(initValue);
1110
+ /* Execute a hook if present */
1111
+ hookEvent.attrName = lcName;
1112
+ hookEvent.attrValue = value;
1113
+ hookEvent.keepAttr = true;
1114
+ hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
1115
+ _executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
1116
+ value = hookEvent.attrValue;
1117
+ /* Full DOM Clobbering protection via namespace isolation,
1118
+ * Prefix id and name attributes with `user-content-`
1119
+ */
1120
+ if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
1121
+ // Remove the attribute with this value
1122
+ _removeAttribute(name, currentNode);
1123
+ // Prefix the value and later re-create the attribute with the sanitized value
1124
+ value = SANITIZE_NAMED_PROPS_PREFIX + value;
1125
+ }
1126
+ /* Work around a security issue with comments inside attributes */
1127
+ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title|textarea)/i, value)) {
1128
+ _removeAttribute(name, currentNode);
1129
+ continue;
1130
+ }
1131
+ /* Make sure we cannot easily use animated hrefs, even if animations are allowed */
1132
+ if (lcName === 'attributename' && stringMatch(value, 'href')) {
1133
+ _removeAttribute(name, currentNode);
1134
+ continue;
1135
+ }
1136
+ /* Did the hooks approve of the attribute? */
1137
+ if (hookEvent.forceKeepAttr) {
1138
+ continue;
1139
+ }
1140
+ /* Did the hooks approve of the attribute? */
1141
+ if (!hookEvent.keepAttr) {
1142
+ _removeAttribute(name, currentNode);
1143
+ continue;
1144
+ }
1145
+ /* Work around a security issue in jQuery 3.0 */
1146
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
1147
+ _removeAttribute(name, currentNode);
1148
+ continue;
1149
+ }
1150
+ /* Sanitize attribute content to be template-safe */
1151
+ if (SAFE_FOR_TEMPLATES) {
1152
+ arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1153
+ value = stringReplace(value, expr, ' ');
1154
+ });
1155
+ }
1156
+ /* Is `value` valid for this attribute? */
1157
+ const lcTag = transformCaseFunc(currentNode.nodeName);
1158
+ if (!_isValidAttribute(lcTag, lcName, value)) {
1159
+ _removeAttribute(name, currentNode);
1160
+ continue;
1161
+ }
1162
+ /* Handle attributes that require Trusted Types */
1163
+ if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
1164
+ if (namespaceURI) ; else {
1165
+ switch (trustedTypes.getAttributeType(lcTag, lcName)) {
1166
+ case 'TrustedHTML':
1167
+ {
1168
+ value = trustedTypesPolicy.createHTML(value);
1169
+ break;
1170
+ }
1171
+ case 'TrustedScriptURL':
1172
+ {
1173
+ value = trustedTypesPolicy.createScriptURL(value);
1174
+ break;
1175
+ }
1176
+ }
1177
+ }
1178
+ }
1179
+ /* Handle invalid data-* attribute set by try-catching it */
1180
+ if (value !== initValue) {
1181
+ try {
1182
+ if (namespaceURI) {
1183
+ currentNode.setAttributeNS(namespaceURI, name, value);
1184
+ } else {
1185
+ /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1186
+ currentNode.setAttribute(name, value);
1187
+ }
1188
+ if (_isClobbered(currentNode)) {
1189
+ _forceRemove(currentNode);
1190
+ } else {
1191
+ arrayPop(DOMPurify.removed);
1192
+ }
1193
+ } catch (_) {
1194
+ _removeAttribute(name, currentNode);
1195
+ }
1196
+ }
1197
+ }
1198
+ /* Execute a hook if present */
1199
+ _executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
1200
+ };
1201
+ /**
1202
+ * _sanitizeShadowDOM
1203
+ *
1204
+ * @param fragment to iterate over recursively
1205
+ */
1206
+ const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
1207
+ let shadowNode = null;
1208
+ const shadowIterator = _createNodeIterator(fragment);
1209
+ /* Execute a hook if present */
1210
+ _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
1211
+ while (shadowNode = shadowIterator.nextNode()) {
1212
+ /* Execute a hook if present */
1213
+ _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
1214
+ /* Sanitize tags and elements */
1215
+ _sanitizeElements(shadowNode);
1216
+ /* Check attributes next */
1217
+ _sanitizeAttributes(shadowNode);
1218
+ /* Deep shadow DOM detected */
1219
+ if (shadowNode.content instanceof DocumentFragment) {
1220
+ _sanitizeShadowDOM(shadowNode.content);
1221
+ }
1222
+ }
1223
+ /* Execute a hook if present */
1224
+ _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
1225
+ };
1226
+ // eslint-disable-next-line complexity
1227
+ DOMPurify.sanitize = function (dirty) {
1228
+ let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1229
+ let body = null;
1230
+ let importedNode = null;
1231
+ let currentNode = null;
1232
+ let returnNode = null;
1233
+ /* Make sure we have a string to sanitize.
1234
+ DO NOT return early, as this will return the wrong type if
1235
+ the user has requested a DOM object rather than a string */
1236
+ IS_EMPTY_INPUT = !dirty;
1237
+ if (IS_EMPTY_INPUT) {
1238
+ dirty = '<!-->';
1239
+ }
1240
+ /* Stringify, in case dirty is an object */
1241
+ if (typeof dirty !== 'string' && !_isNode(dirty)) {
1242
+ if (typeof dirty.toString === 'function') {
1243
+ dirty = dirty.toString();
1244
+ if (typeof dirty !== 'string') {
1245
+ throw typeErrorCreate('dirty is not a string, aborting');
1246
+ }
1247
+ } else {
1248
+ throw typeErrorCreate('toString is not a function');
1249
+ }
1250
+ }
1251
+ /* Return dirty HTML if DOMPurify cannot run */
1252
+ if (!DOMPurify.isSupported) {
1253
+ return dirty;
1254
+ }
1255
+ /* Assign config vars */
1256
+ if (!SET_CONFIG) {
1257
+ _parseConfig(cfg);
1258
+ }
1259
+ /* Clean up removed elements */
1260
+ DOMPurify.removed = [];
1261
+ /* Check if dirty is correctly typed for IN_PLACE */
1262
+ if (typeof dirty === 'string') {
1263
+ IN_PLACE = false;
1264
+ }
1265
+ if (IN_PLACE) {
1266
+ /* Do some early pre-sanitization to avoid unsafe root nodes */
1267
+ if (dirty.nodeName) {
1268
+ const tagName = transformCaseFunc(dirty.nodeName);
1269
+ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1270
+ throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
1271
+ }
1272
+ }
1273
+ } else if (dirty instanceof Node) {
1274
+ /* If dirty is a DOM element, append to an empty document to avoid
1275
+ elements being stripped by the parser */
1276
+ body = _initDocument('<!---->');
1277
+ importedNode = body.ownerDocument.importNode(dirty, true);
1278
+ if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === 'BODY') {
1279
+ /* Node is already a body, use as is */
1280
+ body = importedNode;
1281
+ } else if (importedNode.nodeName === 'HTML') {
1282
+ body = importedNode;
1283
+ } else {
1284
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
1285
+ body.appendChild(importedNode);
1286
+ }
1287
+ } else {
1288
+ /* Exit directly if we have nothing to do */
1289
+ if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
1290
+ // eslint-disable-next-line unicorn/prefer-includes
1291
+ dirty.indexOf('<') === -1) {
1292
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
1293
+ }
1294
+ /* Initialize the document to work on */
1295
+ body = _initDocument(dirty);
1296
+ /* Check we have a DOM node from the data */
1297
+ if (!body) {
1298
+ return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
1299
+ }
1300
+ }
1301
+ /* Remove first element node (ours) if FORCE_BODY is set */
1302
+ if (body && FORCE_BODY) {
1303
+ _forceRemove(body.firstChild);
1304
+ }
1305
+ /* Get node iterator */
1306
+ const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
1307
+ /* Now start iterating over the created document */
1308
+ while (currentNode = nodeIterator.nextNode()) {
1309
+ /* Sanitize tags and elements */
1310
+ _sanitizeElements(currentNode);
1311
+ /* Check attributes next */
1312
+ _sanitizeAttributes(currentNode);
1313
+ /* Shadow DOM detected, sanitize it */
1314
+ if (currentNode.content instanceof DocumentFragment) {
1315
+ _sanitizeShadowDOM(currentNode.content);
1316
+ }
1317
+ }
1318
+ /* If we sanitized `dirty` in-place, return it. */
1319
+ if (IN_PLACE) {
1320
+ return dirty;
1321
+ }
1322
+ /* Return sanitized string or DOM */
1323
+ if (RETURN_DOM) {
1324
+ if (RETURN_DOM_FRAGMENT) {
1325
+ returnNode = createDocumentFragment.call(body.ownerDocument);
1326
+ while (body.firstChild) {
1327
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
1328
+ returnNode.appendChild(body.firstChild);
1329
+ }
1330
+ } else {
1331
+ returnNode = body;
1332
+ }
1333
+ if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
1334
+ /*
1335
+ AdoptNode() is not used because internal state is not reset
1336
+ (e.g. the past names map of a HTMLFormElement), this is safe
1337
+ in theory but we would rather not risk another attack vector.
1338
+ The state that is cloned by importNode() is explicitly defined
1339
+ by the specs.
1340
+ */
1341
+ returnNode = importNode.call(originalDocument, returnNode, true);
1342
+ }
1343
+ return returnNode;
1344
+ }
1345
+ let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
1346
+ /* Serialize doctype if allowed */
1347
+ if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
1348
+ serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
1349
+ }
1350
+ /* Sanitize final string template-safe */
1351
+ if (SAFE_FOR_TEMPLATES) {
1352
+ arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1353
+ serializedHTML = stringReplace(serializedHTML, expr, ' ');
1354
+ });
1355
+ }
1356
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
1357
+ };
1358
+ DOMPurify.setConfig = function () {
1359
+ let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1360
+ _parseConfig(cfg);
1361
+ SET_CONFIG = true;
1362
+ };
1363
+ DOMPurify.clearConfig = function () {
1364
+ CONFIG = null;
1365
+ SET_CONFIG = false;
1366
+ };
1367
+ DOMPurify.isValidAttribute = function (tag, attr, value) {
1368
+ /* Initialize shared config vars if necessary. */
1369
+ if (!CONFIG) {
1370
+ _parseConfig({});
1371
+ }
1372
+ const lcTag = transformCaseFunc(tag);
1373
+ const lcName = transformCaseFunc(attr);
1374
+ return _isValidAttribute(lcTag, lcName, value);
1375
+ };
1376
+ DOMPurify.addHook = function (entryPoint, hookFunction) {
1377
+ if (typeof hookFunction !== 'function') {
1378
+ return;
1379
+ }
1380
+ arrayPush(hooks[entryPoint], hookFunction);
1381
+ };
1382
+ DOMPurify.removeHook = function (entryPoint, hookFunction) {
1383
+ if (hookFunction !== undefined) {
1384
+ const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
1385
+ return index === -1 ? undefined : arraySplice(hooks[entryPoint], index, 1)[0];
1386
+ }
1387
+ return arrayPop(hooks[entryPoint]);
1388
+ };
1389
+ DOMPurify.removeHooks = function (entryPoint) {
1390
+ hooks[entryPoint] = [];
1391
+ };
1392
+ DOMPurify.removeAllHooks = function () {
1393
+ hooks = _createHooksMap();
1394
+ };
1395
+ return DOMPurify;
1396
+ }
1397
+ var purify = createDOMPurify();
1398
+
1399
+ function _define_property$3(obj, key, value) {
1400
+ if (key in obj) {
1401
+ Object.defineProperty(obj, key, {
1402
+ value: value,
1403
+ enumerable: true,
1404
+ configurable: true,
1405
+ writable: true
1406
+ });
1407
+ } else {
1408
+ obj[key] = value;
1409
+ }
1410
+ return obj;
1411
+ }
1412
+ /**
1413
+ * 框架错误基类
1414
+ */ class FrameworkError extends Error {
1415
+ /**
1416
+ * 转换为 JSON
1417
+ */ toJSON() {
1418
+ return {
1419
+ name: this.name,
1420
+ message: this.message,
1421
+ type: this.type,
1422
+ severity: this.severity,
1423
+ code: this.code,
1424
+ recoverable: this.recoverable,
1425
+ context: this.context,
1426
+ stack: this.stack,
1427
+ originalError: this.originalError ? {
1428
+ name: this.originalError.name,
1429
+ message: this.originalError.message,
1430
+ stack: this.originalError.stack
1431
+ } : undefined
1432
+ };
1433
+ }
1434
+ constructor(message, type = "UNKNOWN", severity = "MEDIUM", options){
1435
+ super(message), /**
1436
+ * 错误类型
1437
+ */ _define_property$3(this, "type", void 0), /**
1438
+ * 错误严重程度
1439
+ */ _define_property$3(this, "severity", void 0), /**
1440
+ * 错误代码
1441
+ */ _define_property$3(this, "code", void 0), /**
1442
+ * 原始错误
1443
+ */ _define_property$3(this, "originalError", void 0), /**
1444
+ * 错误上下文
1445
+ */ _define_property$3(this, "context", void 0), /**
1446
+ * 是否可恢复
1447
+ */ _define_property$3(this, "recoverable", void 0);
1448
+ this.name = 'FrameworkError';
1449
+ this.type = type;
1450
+ this.severity = severity;
1451
+ this.code = options?.code || `${type}_ERROR`;
1452
+ this.originalError = options?.originalError;
1453
+ this.context = options?.context;
1454
+ this.recoverable = options?.recoverable ?? false;
1455
+ // 保持正确的堆栈跟踪
1456
+ if (Error.captureStackTrace) {
1457
+ Error.captureStackTrace(this, FrameworkError);
1458
+ }
1459
+ }
1460
+ }
1461
+ /**
1462
+ * 安全错误
1463
+ */ class SecurityError extends FrameworkError {
1464
+ constructor(message, originalError, context){
1465
+ super(message, "SECURITY", "HIGH", {
1466
+ code: 'SECURITY_ERROR',
1467
+ originalError,
1468
+ context,
1469
+ recoverable: false
1470
+ });
1471
+ this.name = 'SecurityError';
1472
+ }
1473
+ }
1474
+
1475
+ /**
1476
+ * 敏感数据标识(扩展列表)
1477
+ */ const SENSITIVE_FIELDS = [
1478
+ 'password',
1479
+ 'pwd',
1480
+ 'passwd',
1481
+ 'token',
1482
+ 'secret',
1483
+ 'key',
1484
+ 'apiKey',
1485
+ 'apikey',
1486
+ 'api_key',
1487
+ 'accessToken',
1488
+ 'access_token',
1489
+ 'refreshToken',
1490
+ 'refresh_token',
1491
+ 'authorization',
1492
+ 'auth',
1493
+ 'cookie',
1494
+ 'session',
1495
+ 'sessionId',
1496
+ 'session_id',
1497
+ 'creditCard',
1498
+ 'credit_card',
1499
+ 'cardNumber',
1500
+ 'card_number',
1501
+ 'cvv',
1502
+ 'cvc',
1503
+ 'ssn',
1504
+ 'socialSecurityNumber',
1505
+ 'social_security_number',
1506
+ 'phone',
1507
+ 'phoneNumber',
1508
+ 'phone_number',
1509
+ 'mobile',
1510
+ 'email',
1511
+ 'emailAddress',
1512
+ 'email_address',
1513
+ 'privateKey',
1514
+ 'private_key',
1515
+ 'secretKey',
1516
+ 'secret_key',
1517
+ 'apiSecret',
1518
+ 'api_secret'
1519
+ ];
1520
+ /**
1521
+ * 敏感信息检测模式(正则表达式)
1522
+ */ const SENSITIVE_PATTERNS = [
1523
+ /\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/,
1524
+ /\b\d{3}-\d{2}-\d{4}\b/,
1525
+ /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/,
1526
+ /\b\d{10,}\b/
1527
+ ];
1528
+ /**
1529
+ * 安全工具类
1530
+ */ class SecurityUtils {
1531
+ /**
1532
+ * 清理 HTML,防止 XSS 攻击
1533
+ */ static sanitizeHTML(html, config) {
1534
+ if (typeof window === 'undefined') {
1535
+ // Node.js 环境,返回原始字符串(需要服务端处理)
1536
+ return html;
1537
+ }
1538
+ try {
1539
+ if (config?.allowHTML) {
1540
+ // 默认禁止所有标签,除非明确允许
1541
+ const allowedTags = config.allowedTags && config.allowedTags.length > 0 ? config.allowedTags : [];
1542
+ const allowedAttributes = config.allowedAttributes && config.allowedAttributes.length > 0 ? config.allowedAttributes : [];
1543
+ return purify.sanitize(html, {
1544
+ ALLOWED_TAGS: allowedTags,
1545
+ ALLOWED_ATTR: allowedAttributes,
1546
+ FORBID_TAGS: [
1547
+ 'script',
1548
+ 'iframe',
1549
+ 'object',
1550
+ 'embed',
1551
+ 'form',
1552
+ 'link',
1553
+ 'meta',
1554
+ 'style'
1555
+ ],
1556
+ FORBID_ATTR: [
1557
+ 'onerror',
1558
+ 'onload',
1559
+ 'onclick',
1560
+ 'onmouseover',
1561
+ 'onfocus',
1562
+ 'onblur',
1563
+ 'onchange'
1564
+ ],
1565
+ // 添加更多安全配置
1566
+ KEEP_CONTENT: false,
1567
+ RETURN_DOM: false,
1568
+ RETURN_DOM_FRAGMENT: false,
1569
+ RETURN_TRUSTED_TYPE: false
1570
+ });
1571
+ }
1572
+ // 默认模式:完全清理,不允许任何 HTML
1573
+ return purify.sanitize(html, {
1574
+ ALLOWED_TAGS: [],
1575
+ KEEP_CONTENT: false
1576
+ });
1577
+ } catch (error) {
1578
+ // 错误处理:不泄露敏感信息,记录错误但不抛出详细错误
1579
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
1580
+ // 只记录错误类型,不记录具体内容
1581
+ console.error('HTML 清理失败:', errorMessage.substring(0, 50));
1582
+ // 返回安全的空字符串或清理后的文本
1583
+ return this.sanitizeText(html);
1584
+ }
1585
+ }
1586
+ /**
1587
+ * 清理文本内容(移除所有 HTML 标签)
1588
+ */ static sanitizeText(text) {
1589
+ if (typeof window === 'undefined') {
1590
+ return text.replace(/<[^>]*>/g, '');
1591
+ }
1592
+ try {
1593
+ return purify.sanitize(text, {
1594
+ ALLOWED_TAGS: []
1595
+ });
1596
+ } catch (error) {
1597
+ throw new SecurityError('文本清理失败', error instanceof Error ? error : undefined);
1598
+ }
1599
+ }
1600
+ /**
1601
+ * 检查字符串是否包含潜在的危险内容
1602
+ */ static containsDangerousContent(text) {
1603
+ const dangerousPatterns = [
1604
+ /<script[\s\S]*?>[\s\S]*?<\/script>/gi,
1605
+ /javascript:/gi,
1606
+ /on\w+\s*=/gi,
1607
+ /<iframe[\s\S]*?>/gi,
1608
+ /<object[\s\S]*?>/gi,
1609
+ /<embed[\s\S]*?>/gi,
1610
+ /<link[\s\S]*?>/gi,
1611
+ /<meta[\s\S]*?>/gi,
1612
+ /data:text\/html/gi,
1613
+ /vbscript:/gi,
1614
+ /expression\s*\(/gi,
1615
+ /@import/gi,
1616
+ /<style[\s\S]*?>[\s\S]*?<\/style>/gi
1617
+ ];
1618
+ return dangerousPatterns.some((pattern)=>pattern.test(text));
1619
+ }
1620
+ /**
1621
+ * 验证 URL 是否安全
1622
+ */ static isSafeUrl(url) {
1623
+ try {
1624
+ const urlObj = new URL(url);
1625
+ // 检查协议
1626
+ if (![
1627
+ 'http:',
1628
+ 'https:'
1629
+ ].includes(urlObj.protocol)) {
1630
+ return false;
1631
+ }
1632
+ // 检查是否包含危险内容
1633
+ return !this.containsDangerousContent(url);
1634
+ } catch {
1635
+ return false;
1636
+ }
1637
+ }
1638
+ /**
1639
+ * 检查字段名是否为敏感字段
1640
+ */ static isSensitiveField(fieldName) {
1641
+ const lowerFieldName = fieldName.toLowerCase();
1642
+ return SENSITIVE_FIELDS.some((field)=>lowerFieldName.includes(field.toLowerCase()));
1643
+ }
1644
+ /**
1645
+ * 检查值是否包含敏感信息(基于模式匹配)
1646
+ */ static containsSensitiveData(value) {
1647
+ return SENSITIVE_PATTERNS.some((pattern)=>pattern.test(value));
1648
+ }
1649
+ /**
1650
+ * 生成 CSP(Content Security Policy)头
1651
+ */ static generateCSP(config) {
1652
+ const directives = [];
1653
+ const allowUnsafeInline = config?.allowUnsafeInline ?? false;
1654
+ const allowUnsafeEval = config?.allowUnsafeEval ?? false;
1655
+ if (config?.defaultSrc) {
1656
+ directives.push(`default-src ${config.defaultSrc.join(' ')}`);
1657
+ } else {
1658
+ directives.push("default-src 'self'");
1659
+ }
1660
+ if (config?.scriptSrc) {
1661
+ directives.push(`script-src ${config.scriptSrc.join(' ')}`);
1662
+ } else {
1663
+ // 默认不允许 unsafe-inline 和 unsafe-eval,提高安全性
1664
+ const scriptSrc = [
1665
+ "'self'"
1666
+ ];
1667
+ if (allowUnsafeInline) {
1668
+ scriptSrc.push("'unsafe-inline'");
1669
+ }
1670
+ if (allowUnsafeEval) {
1671
+ scriptSrc.push("'unsafe-eval'");
1672
+ }
1673
+ directives.push(`script-src ${scriptSrc.join(' ')}`);
1674
+ }
1675
+ if (config?.styleSrc) {
1676
+ directives.push(`style-src ${config.styleSrc.join(' ')}`);
1677
+ } else {
1678
+ // 对于样式,可以使用 nonce 或 hash 替代 unsafe-inline
1679
+ const styleSrc = [
1680
+ "'self'"
1681
+ ];
1682
+ if (allowUnsafeInline) {
1683
+ styleSrc.push("'unsafe-inline'");
1684
+ }
1685
+ directives.push(`style-src ${styleSrc.join(' ')}`);
1686
+ }
1687
+ if (config?.imgSrc) {
1688
+ directives.push(`img-src ${config.imgSrc.join(' ')}`);
1689
+ } else {
1690
+ directives.push("img-src 'self' data: https:");
1691
+ }
1692
+ if (config?.connectSrc) {
1693
+ directives.push(`connect-src ${config.connectSrc.join(' ')}`);
1694
+ } else {
1695
+ directives.push("connect-src 'self'");
1696
+ }
1697
+ if (config?.fontSrc) {
1698
+ directives.push(`font-src ${config.fontSrc.join(' ')}`);
1699
+ } else {
1700
+ directives.push("font-src 'self' data:");
1701
+ }
1702
+ if (config?.frameSrc) {
1703
+ directives.push(`frame-src ${config.frameSrc.join(' ')}`);
1704
+ } else {
1705
+ directives.push("frame-src 'none'");
1706
+ }
1707
+ return directives.join('; ');
1708
+ }
1709
+ /**
1710
+ * 转义 HTML 特殊字符
1711
+ */ static escapeHTML(text) {
1712
+ const map = {
1713
+ '&': '&amp;',
1714
+ '<': '&lt;',
1715
+ '>': '&gt;',
1716
+ '"': '&quot;',
1717
+ "'": '&#039;'
1718
+ };
1719
+ return text.replace(/[&<>"']/g, (char)=>map[char]);
1720
+ }
1721
+ /**
1722
+ * 验证输入是否安全
1723
+ */ static validateInput(input) {
1724
+ if (typeof input !== 'string') {
1725
+ return {
1726
+ safe: true
1727
+ };
1728
+ }
1729
+ if (this.containsDangerousContent(input)) {
1730
+ return {
1731
+ safe: false,
1732
+ sanitized: this.sanitizeText(input),
1733
+ reason: '包含潜在的危险内容'
1734
+ };
1735
+ }
1736
+ // 检查是否包含敏感数据模式
1737
+ if (this.containsSensitiveData(input)) {
1738
+ return {
1739
+ safe: false,
1740
+ sanitized: this.sanitizeText(input),
1741
+ reason: '可能包含敏感信息'
1742
+ };
1743
+ }
1744
+ return {
1745
+ safe: true,
1746
+ sanitized: input
1747
+ };
1748
+ }
1749
+ /**
1750
+ * 深度脱敏处理(递归处理嵌套对象)
1751
+ */ static deepSanitize(data, maxDepth = 10, currentDepth = 0) {
1752
+ if (currentDepth >= maxDepth) {
1753
+ return '***'; // 防止无限递归
1754
+ }
1755
+ if (data === null || data === undefined) {
1756
+ return data;
1757
+ }
1758
+ if (typeof data === 'string') {
1759
+ if (this.containsDangerousContent(data) || this.containsSensitiveData(data)) {
1760
+ return this.sanitizeText(data);
1761
+ }
1762
+ return data;
1763
+ }
1764
+ if (typeof data === 'number' || typeof data === 'boolean') {
1765
+ return data;
1766
+ }
1767
+ if (Array.isArray(data)) {
1768
+ return data.map((item)=>this.deepSanitize(item, maxDepth, currentDepth + 1));
1769
+ }
1770
+ if (typeof data === 'object') {
1771
+ const sanitized = {};
1772
+ for (const [key, value] of Object.entries(data)){
1773
+ if (this.isSensitiveField(key)) {
1774
+ sanitized[key] = '***';
1775
+ } else {
1776
+ sanitized[key] = this.deepSanitize(value, maxDepth, currentDepth + 1);
1777
+ }
1778
+ }
1779
+ return sanitized;
1780
+ }
1781
+ return data;
1782
+ }
1783
+ }
1784
+
1785
+ function _define_property$2(obj, key, value) {
1786
+ if (key in obj) {
1787
+ Object.defineProperty(obj, key, {
1788
+ value: value,
1789
+ enumerable: true,
1790
+ configurable: true,
1791
+ writable: true
1792
+ });
1793
+ } else {
1794
+ obj[key] = value;
1795
+ }
1796
+ return obj;
1797
+ }
1798
+ /**
1799
+ * 日志追踪 ID 生成器
1800
+ * 用于生成唯一的请求追踪 ID,便于日志关联和问题排查
1801
+ */ /**
1802
+ * 追踪 ID 生成器
1803
+ */ class TraceIdGenerator {
1804
+ /**
1805
+ * 获取单例实例
1806
+ */ static getInstance(prefix) {
1807
+ if (!TraceIdGenerator.instance) {
1808
+ TraceIdGenerator.instance = new TraceIdGenerator(prefix);
1809
+ }
1810
+ return TraceIdGenerator.instance;
1811
+ }
1812
+ /**
1813
+ * 生成追踪 ID
1814
+ */ generate() {
1815
+ const timestamp = Date.now();
1816
+ const random = Math.random().toString(36).substring(2, 9);
1817
+ const counter = (this.counter++).toString(36).padStart(4, '0');
1818
+ const parts = [
1819
+ timestamp.toString(36),
1820
+ random,
1821
+ counter
1822
+ ];
1823
+ if (this.prefix) {
1824
+ parts.unshift(this.prefix);
1825
+ }
1826
+ return parts.join('-');
1827
+ }
1828
+ /**
1829
+ * 从字符串解析追踪 ID(用于验证)
1830
+ */ static parse(traceId) {
1831
+ const parts = traceId.split('-');
1832
+ if (parts.length < 3) {
1833
+ return null;
1834
+ }
1835
+ try {
1836
+ const timestamp = parseInt(parts[parts.length - 3], 36);
1837
+ const random = parts[parts.length - 2];
1838
+ const counter = parseInt(parts[parts.length - 1], 36);
1839
+ return {
1840
+ prefix: parts.length > 3 ? parts.slice(0, -3).join('-') : undefined,
1841
+ timestamp,
1842
+ random,
1843
+ counter
1844
+ };
1845
+ } catch {
1846
+ return null;
1847
+ }
1848
+ }
1849
+ constructor(prefix = ''){
1850
+ _define_property$2(this, "counter", 0);
1851
+ _define_property$2(this, "prefix", void 0);
1852
+ this.prefix = prefix;
1853
+ }
1854
+ }
1855
+ _define_property$2(TraceIdGenerator, "instance", null);
1856
+
1857
+ function _define_property$1(obj, key, value) {
1858
+ if (key in obj) {
1859
+ Object.defineProperty(obj, key, {
1860
+ value: value,
1861
+ enumerable: true,
1862
+ configurable: true,
1863
+ writable: true
1864
+ });
1865
+ } else {
1866
+ obj[key] = value;
1867
+ }
1868
+ return obj;
1869
+ }
1870
+ /**
1871
+ * 检测运行环境是否为浏览器
1872
+ */ const isBrowser = ()=>{
1873
+ return typeof window !== 'undefined' && typeof window.document !== 'undefined';
1874
+ };
1875
+ /**
1876
+ * ANSI 颜色代码(用于 Node.js 环境)
1877
+ */ const ANSI_COLORS = {
1878
+ reset: '\x1b[0m',
1879
+ bright: '\x1b[1m',
1880
+ dim: '\x1b[2m',
1881
+ red: '\x1b[31m',
1882
+ yellow: '\x1b[33m',
1883
+ cyan: '\x1b[36m',
1884
+ white: '\x1b[37m'};
1885
+ /**
1886
+ * 浏览器控制台样式(用于浏览器环境)
1887
+ */ const BROWSER_STYLES = {
1888
+ debug: 'color: #888; font-weight: normal;',
1889
+ info: 'color: #2196F3; font-weight: normal;',
1890
+ warn: 'color: #FF9800; font-weight: bold;',
1891
+ error: 'color: #F44336; font-weight: bold;'
1892
+ };
1893
+ /**
1894
+ * 日志级别对应的颜色配置
1895
+ */ const LEVEL_COLORS = {
1896
+ [LogLevel.DEBUG]: {
1897
+ node: ANSI_COLORS.dim + ANSI_COLORS.white,
1898
+ browser: BROWSER_STYLES.debug
1899
+ },
1900
+ [LogLevel.INFO]: {
1901
+ node: ANSI_COLORS.cyan,
1902
+ browser: BROWSER_STYLES.info
1903
+ },
1904
+ [LogLevel.WARN]: {
1905
+ node: ANSI_COLORS.yellow,
1906
+ browser: BROWSER_STYLES.warn
1907
+ },
1908
+ [LogLevel.ERROR]: {
1909
+ node: ANSI_COLORS.red + ANSI_COLORS.bright,
1910
+ browser: BROWSER_STYLES.error
1911
+ },
1912
+ [LogLevel.NONE]: {
1913
+ node: '',
1914
+ browser: ''
1915
+ }
1916
+ };
1917
+ /**
1918
+ * 日志级别标签
1919
+ */ const LEVEL_LABELS = {
1920
+ [LogLevel.DEBUG]: 'DEBUG',
1921
+ [LogLevel.INFO]: 'INFO',
1922
+ [LogLevel.WARN]: 'WARN',
1923
+ [LogLevel.ERROR]: 'ERROR',
1924
+ [LogLevel.NONE]: ''
1925
+ };
1926
+ /**
1927
+ * Logger 类
1928
+ */ let Logger = class Logger {
1929
+ /**
1930
+ * 设置日志级别
1931
+ */ setLevel(level) {
1932
+ this.level = level;
1933
+ }
1934
+ /**
1935
+ * 获取当前日志级别
1936
+ */ getLevel() {
1937
+ return this.level;
1938
+ }
1939
+ /**
1940
+ * 格式化时间戳
1941
+ */ formatTimestamp() {
1942
+ const now = new Date();
1943
+ const year = now.getFullYear();
1944
+ const month = String(now.getMonth() + 1).padStart(2, '0');
1945
+ const day = String(now.getDate()).padStart(2, '0');
1946
+ const hours = String(now.getHours()).padStart(2, '0');
1947
+ const minutes = String(now.getMinutes()).padStart(2, '0');
1948
+ const seconds = String(now.getSeconds()).padStart(2, '0');
1949
+ const milliseconds = String(now.getMilliseconds()).padStart(3, '0');
1950
+ return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds}`;
1951
+ }
1952
+ /**
1953
+ * 构建日志前缀
1954
+ */ buildPrefix(logLevel) {
1955
+ const parts = [];
1956
+ if (this.showTimestamp) {
1957
+ parts.push(`[${this.formatTimestamp()}]`);
1958
+ }
1959
+ if (this.showLevel) {
1960
+ parts.push(`[${LEVEL_LABELS[logLevel]}]`);
1961
+ }
1962
+ if (this.prefix) {
1963
+ parts.push(`[${this.prefix}]`);
1964
+ }
1965
+ return parts.join(' ');
1966
+ }
1967
+ /**
1968
+ * 输出日志(Node.js 环境)
1969
+ */ logNode(level, ...args) {
1970
+ if (level < this.level) {
1971
+ return;
1972
+ }
1973
+ const prefix = this.buildPrefix(level);
1974
+ const colorConfig = LEVEL_COLORS[level];
1975
+ const reset = this.enableColors ? ANSI_COLORS.reset : '';
1976
+ if (this.enableColors && colorConfig.node) {
1977
+ console.log(`${colorConfig.node}${prefix}${reset}`, ...args);
1978
+ } else {
1979
+ console.log(prefix, ...args);
1980
+ }
1981
+ }
1982
+ /**
1983
+ * 输出日志(浏览器环境)
1984
+ */ logBrowser(level, ...args) {
1985
+ if (level < this.level) {
1986
+ return;
1987
+ }
1988
+ const prefix = this.buildPrefix(level);
1989
+ const colorConfig = LEVEL_COLORS[level];
1990
+ if (this.enableColors && colorConfig.browser) {
1991
+ console.log(`%c${prefix}`, colorConfig.browser, ...args);
1992
+ } else {
1993
+ console.log(prefix, ...args);
1994
+ }
1995
+ }
1996
+ /**
1997
+ * 脱敏处理
1998
+ */ sanitizeValue(value) {
1999
+ if (!this.enableSanitization) {
2000
+ return value;
2001
+ }
2002
+ if (typeof value === 'string') {
2003
+ // 检查是否包含敏感内容
2004
+ if (SecurityUtils.containsDangerousContent(value)) {
2005
+ return SecurityUtils.sanitizeText(value);
2006
+ }
2007
+ return value;
2008
+ }
2009
+ if (value && typeof value === 'object') {
2010
+ if (Array.isArray(value)) {
2011
+ return value.map((item)=>this.sanitizeValue(item));
2012
+ }
2013
+ const sanitized = {};
2014
+ for (const [key, val] of Object.entries(value)){
2015
+ // 检查是否为敏感字段
2016
+ if (SecurityUtils.isSensitiveField(key)) {
2017
+ sanitized[key] = '***';
2018
+ } else {
2019
+ sanitized[key] = this.sanitizeValue(val);
2020
+ }
2021
+ }
2022
+ return sanitized;
2023
+ }
2024
+ return value;
2025
+ }
2026
+ /**
2027
+ * 处理日志参数(脱敏、过滤等)
2028
+ */ processLogArgs(...args) {
2029
+ // 生产环境自动禁用 DEBUG 级别
2030
+ if (this.isProduction && this.level === LogLevel.DEBUG) {
2031
+ return [];
2032
+ }
2033
+ return args.map((arg)=>this.sanitizeValue(arg));
2034
+ }
2035
+ /**
2036
+ * 设置日志格式
2037
+ */ setFormat(format) {
2038
+ this.format = format;
2039
+ }
2040
+ /**
2041
+ * 设置日志上下文
2042
+ */ setContext(context) {
2043
+ this.context = {
2044
+ ...this.context,
2045
+ ...context
2046
+ };
2047
+ }
2048
+ /**
2049
+ * 更新日志上下文
2050
+ */ updateContext(context) {
2051
+ this.context = {
2052
+ ...this.context,
2053
+ ...context
2054
+ };
2055
+ }
2056
+ /**
2057
+ * 获取日志上下文
2058
+ */ getContext() {
2059
+ return {
2060
+ ...this.context
2061
+ };
2062
+ }
2063
+ /**
2064
+ * 清除日志上下文
2065
+ */ clearContext() {
2066
+ this.context = {};
2067
+ }
2068
+ /**
2069
+ * 注册日志处理器(用于日志聚合)
2070
+ */ addLogHandler(handler) {
2071
+ this.logHandlers.push(handler);
2072
+ return ()=>{
2073
+ const index = this.logHandlers.indexOf(handler);
2074
+ if (index > -1) {
2075
+ this.logHandlers.splice(index, 1);
2076
+ }
2077
+ };
2078
+ }
2079
+ /**
2080
+ * 创建结构化日志条目
2081
+ */ createStructuredEntry(level, message, data) {
2082
+ const entry = {
2083
+ timestamp: new Date().toISOString(),
2084
+ level,
2085
+ message,
2086
+ context: {
2087
+ ...this.context,
2088
+ traceId: this.context.traceId
2089
+ },
2090
+ source: this.prefix || 'framework'
2091
+ };
2092
+ if (data !== undefined) {
2093
+ entry.data = this.sanitizeValue(data);
2094
+ }
2095
+ // 如果是错误,提取堆栈信息
2096
+ if (data instanceof Error) {
2097
+ entry.stack = data.stack;
2098
+ entry.message = data.message || message;
2099
+ }
2100
+ return entry;
2101
+ }
2102
+ /**
2103
+ * 输出结构化日志
2104
+ */ outputStructured(entry) {
2105
+ // 调用日志处理器
2106
+ this.logHandlers.forEach((handler)=>{
2107
+ try {
2108
+ handler(entry);
2109
+ } catch (error) {
2110
+ // 忽略处理器错误,避免循环
2111
+ }
2112
+ });
2113
+ // 根据格式输出
2114
+ if (this.format === "json") {
2115
+ console.log(JSON.stringify(entry));
2116
+ } else if (this.format === "structured") {
2117
+ console.log(entry);
2118
+ } else {
2119
+ // TEXT 格式使用原有输出方式
2120
+ const args = entry.data !== undefined ? [
2121
+ entry.data
2122
+ ] : [];
2123
+ if (isBrowser()) {
2124
+ this.logBrowser(entry.level, entry.message, ...args);
2125
+ } else {
2126
+ this.logNode(entry.level, entry.message, ...args);
2127
+ }
2128
+ }
2129
+ }
2130
+ /**
2131
+ * 通用日志输出方法
2132
+ */ log(level, ...args) {
2133
+ if (level < this.level) {
2134
+ return;
2135
+ }
2136
+ const processedArgs = this.processLogArgs(...args);
2137
+ // 如果处理后没有参数(被过滤),则不输出
2138
+ if (processedArgs.length === 0) {
2139
+ return;
2140
+ }
2141
+ // 提取消息和数据
2142
+ const message = typeof processedArgs[0] === 'string' ? processedArgs[0] : 'Log message';
2143
+ const data = processedArgs.length > 1 ? processedArgs.slice(1) : typeof processedArgs[0] === 'string' ? undefined : processedArgs[0];
2144
+ // 创建结构化日志条目
2145
+ const entry = this.createStructuredEntry(level, message, data);
2146
+ // 输出日志
2147
+ this.outputStructured(entry);
2148
+ }
2149
+ /**
2150
+ * 输出 DEBUG 级别日志
2151
+ */ debug(...args) {
2152
+ this.log(LogLevel.DEBUG, ...args);
2153
+ }
2154
+ /**
2155
+ * 输出 INFO 级别日志
2156
+ */ info(...args) {
2157
+ this.log(LogLevel.INFO, ...args);
2158
+ }
2159
+ /**
2160
+ * 输出 WARN 级别日志
2161
+ */ warn(...args) {
2162
+ this.log(LogLevel.WARN, ...args);
2163
+ }
2164
+ /**
2165
+ * 输出 ERROR 级别日志
2166
+ */ error(...args) {
2167
+ this.log(LogLevel.ERROR, ...args);
2168
+ }
2169
+ constructor(options = {}){
2170
+ _define_property$1(this, "level", void 0);
2171
+ _define_property$1(this, "enableColors", void 0);
2172
+ _define_property$1(this, "showTimestamp", void 0);
2173
+ _define_property$1(this, "showLevel", void 0);
2174
+ _define_property$1(this, "prefix", void 0);
2175
+ _define_property$1(this, "enableSanitization", void 0);
2176
+ _define_property$1(this, "isProduction", void 0);
2177
+ _define_property$1(this, "format", void 0);
2178
+ _define_property$1(this, "context", {});
2179
+ _define_property$1(this, "logHandlers", []);
2180
+ this.level = options.level ?? LogLevel.INFO;
2181
+ this.enableColors = options.enableColors ?? true;
2182
+ this.showTimestamp = options.showTimestamp ?? true;
2183
+ this.showLevel = options.showLevel ?? true;
2184
+ this.prefix = options.prefix ?? '';
2185
+ this.enableSanitization = options.enableSanitization ?? true;
2186
+ this.isProduction = typeof process !== 'undefined' && process.env.NODE_ENV === 'production';
2187
+ this.format = options.format ?? "text";
2188
+ this.context = options.context ?? {};
2189
+ }
2190
+ };
2191
+ /**
2192
+ * 创建 Logger 实例
2193
+ */ const createLogger = (options)=>{
2194
+ return new Logger(options);
2195
+ };
2196
+ /**
2197
+ * 默认 Logger 实例
2198
+ */ const logger = createLogger();
2199
+
2200
+ function _define_property(obj, key, value) {
2201
+ if (key in obj) {
2202
+ Object.defineProperty(obj, key, {
2203
+ value: value,
2204
+ enumerable: true,
2205
+ configurable: true,
2206
+ writable: true
2207
+ });
2208
+ } else {
2209
+ obj[key] = value;
2210
+ }
2211
+ return obj;
2212
+ }
2213
+ /**
2214
+ * 分析服务类
2215
+ */ class AnalyticsService {
2216
+ /**
2217
+ * 启动批量上报定时器
2218
+ */ startBatchTimer() {
2219
+ if (this.batchTimer) {
2220
+ return;
2221
+ }
2222
+ this.batchTimer = setInterval(()=>{
2223
+ this.flush();
2224
+ }, this.config.batchInterval);
2225
+ }
2226
+ /**
2227
+ * 停止批量上报定时器
2228
+ */ stopBatchTimer() {
2229
+ if (this.batchTimer) {
2230
+ clearInterval(this.batchTimer);
2231
+ this.batchTimer = null;
2232
+ }
2233
+ }
2234
+ /**
2235
+ * 记录事件
2236
+ */ track(event) {
2237
+ if (!this.config.enabled) {
2238
+ return;
2239
+ }
2240
+ // 采样检查
2241
+ if (Math.random() > this.config.sampleRate) {
2242
+ return;
2243
+ }
2244
+ // 匿名化处理
2245
+ const anonymizedEvent = {
2246
+ ...event,
2247
+ timestamp: Date.now(),
2248
+ properties: this.anonymizeProperties(event.properties)
2249
+ };
2250
+ // 添加到队列
2251
+ this.eventQueue.push(anonymizedEvent);
2252
+ // 立即上报单个事件
2253
+ if (this.config.onEvent) {
2254
+ this.config.onEvent(anonymizedEvent);
2255
+ }
2256
+ // 检查是否需要批量上报
2257
+ if (this.eventQueue.length >= this.config.batchSize) {
2258
+ this.flush();
2259
+ }
2260
+ }
2261
+ /**
2262
+ * 记录页面浏览
2263
+ */ trackPageView(page, properties) {
2264
+ this.track({
2265
+ type: 'pageview',
2266
+ name: 'page_view',
2267
+ properties: {
2268
+ page,
2269
+ ...properties
2270
+ }
2271
+ });
2272
+ }
2273
+ /**
2274
+ * 记录点击事件
2275
+ */ trackClick(element, properties) {
2276
+ this.track({
2277
+ type: 'click',
2278
+ name: 'click',
2279
+ properties: {
2280
+ element,
2281
+ ...properties
2282
+ }
2283
+ });
2284
+ }
2285
+ /**
2286
+ * 记录自定义事件
2287
+ */ trackCustom(name, properties) {
2288
+ this.track({
2289
+ type: 'custom',
2290
+ name,
2291
+ properties
2292
+ });
2293
+ }
2294
+ /**
2295
+ * 记录错误事件
2296
+ */ trackError(error, properties) {
2297
+ this.track({
2298
+ type: 'error',
2299
+ name: 'error',
2300
+ properties: {
2301
+ errorName: error.name,
2302
+ errorMessage: error.message,
2303
+ errorStack: error.stack,
2304
+ ...properties
2305
+ }
2306
+ });
2307
+ }
2308
+ /**
2309
+ * 记录性能事件
2310
+ */ trackPerformance(metrics, properties) {
2311
+ this.track({
2312
+ type: 'performance',
2313
+ name: 'performance',
2314
+ properties: {
2315
+ ...metrics,
2316
+ ...properties
2317
+ }
2318
+ });
2319
+ }
2320
+ /**
2321
+ * 匿名化属性(使用深度脱敏)
2322
+ */ anonymizeProperties(properties) {
2323
+ if (!this.config.anonymize || !properties) {
2324
+ return properties;
2325
+ }
2326
+ // 使用深度脱敏处理
2327
+ return SecurityUtils.deepSanitize(properties);
2328
+ }
2329
+ /**
2330
+ * 刷新队列(批量上报)
2331
+ */ flush() {
2332
+ if (this.eventQueue.length === 0) {
2333
+ return;
2334
+ }
2335
+ const events = [
2336
+ ...this.eventQueue
2337
+ ];
2338
+ this.eventQueue = [];
2339
+ if (this.config.onBatch) {
2340
+ this.config.onBatch(events);
2341
+ }
2342
+ logger.debug(`分析服务批量上报 ${events.length} 个事件`);
2343
+ }
2344
+ /**
2345
+ * 启用分析
2346
+ */ enable() {
2347
+ this.config.enabled = true;
2348
+ this.startBatchTimer();
2349
+ }
2350
+ /**
2351
+ * 禁用分析
2352
+ */ disable() {
2353
+ this.config.enabled = false;
2354
+ this.stopBatchTimer();
2355
+ this.flush();
2356
+ }
2357
+ /**
2358
+ * 销毁服务
2359
+ */ destroy() {
2360
+ this.stopBatchTimer();
2361
+ this.flush();
2362
+ }
2363
+ constructor(config = {}){
2364
+ _define_property(this, "config", void 0);
2365
+ _define_property(this, "eventQueue", []);
2366
+ _define_property(this, "batchTimer", null);
2367
+ this.config = {
2368
+ enabled: config.enabled ?? true,
2369
+ sampleRate: config.sampleRate ?? 1.0,
2370
+ anonymize: config.anonymize ?? true,
2371
+ onEvent: config.onEvent ?? (()=>{}),
2372
+ onBatch: config.onBatch ?? (()=>{}),
2373
+ batchSize: config.batchSize ?? 10,
2374
+ batchInterval: config.batchInterval ?? 5000
2375
+ };
2376
+ if (this.config.enabled) {
2377
+ this.startBatchTimer();
2378
+ }
2379
+ }
2380
+ }
2381
+ /**
2382
+ * 默认分析服务实例
2383
+ */ let defaultAnalyticsService = null;
2384
+ /**
2385
+ * 初始化默认分析服务
2386
+ */ function initAnalytics(config) {
2387
+ if (!defaultAnalyticsService) {
2388
+ defaultAnalyticsService = new AnalyticsService(config);
2389
+ }
2390
+ return defaultAnalyticsService;
2391
+ }
2392
+ /**
2393
+ * 获取默认分析服务
2394
+ */ function getAnalytics() {
2395
+ if (!defaultAnalyticsService) {
2396
+ return initAnalytics();
2397
+ }
2398
+ return defaultAnalyticsService;
2399
+ }
2400
+
2401
+ exports.AnalyticsService = AnalyticsService;
2402
+ exports.getAnalytics = getAnalytics;
2403
+ exports.initAnalytics = initAnalytics;
2404
+
2405
+ }));
2406
+ //# sourceMappingURL=analytics.umd.js.map