74650c6c45bfc8710e90a45f75f345255a5a54bc6b0d12005a7c50e3540e731659419f454ff0a057203b01159dd59ed8a4c44f9851e40c25d7b6ef7791bc22 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /*!
  2. * shared v9.14.5
  3. * (c) 2025 kazuya kawaguchi
  4. * Released under the MIT License.
  5. */
  6. 'use strict';
  7. function warn(msg, err) {
  8. if (typeof console !== 'undefined') {
  9. console.warn(`[intlify] ` + msg);
  10. /* istanbul ignore if */
  11. if (err) {
  12. console.warn(err.stack);
  13. }
  14. }
  15. }
  16. const hasWarned = {};
  17. function warnOnce(msg) {
  18. if (!hasWarned[msg]) {
  19. hasWarned[msg] = true;
  20. warn(msg);
  21. }
  22. }
  23. /**
  24. * Original Utilities
  25. * written by kazuya kawaguchi
  26. */
  27. const inBrowser = typeof window !== 'undefined';
  28. let mark;
  29. let measure;
  30. const RE_ARGS = /\{([0-9a-zA-Z]+)\}/g;
  31. /* eslint-disable */
  32. function format(message, ...args) {
  33. if (args.length === 1 && isObject(args[0])) {
  34. args = args[0];
  35. }
  36. if (!args || !args.hasOwnProperty) {
  37. args = {};
  38. }
  39. return message.replace(RE_ARGS, (match, identifier) => {
  40. return args.hasOwnProperty(identifier) ? args[identifier] : '';
  41. });
  42. }
  43. const makeSymbol = (name, shareable = false) => !shareable ? Symbol(name) : Symbol.for(name);
  44. const generateFormatCacheKey = (locale, key, source) => friendlyJSONstringify({ l: locale, k: key, s: source });
  45. const friendlyJSONstringify = (json) => JSON.stringify(json)
  46. .replace(/\u2028/g, '\\u2028')
  47. .replace(/\u2029/g, '\\u2029')
  48. .replace(/\u0027/g, '\\u0027');
  49. const isNumber = (val) => typeof val === 'number' && isFinite(val);
  50. const isDate = (val) => toTypeString(val) === '[object Date]';
  51. const isRegExp = (val) => toTypeString(val) === '[object RegExp]';
  52. const isEmptyObject = (val) => isPlainObject(val) && Object.keys(val).length === 0;
  53. const assign = Object.assign;
  54. const _create = Object.create;
  55. const create = (obj = null) => _create(obj);
  56. let _globalThis;
  57. const getGlobalThis = () => {
  58. // prettier-ignore
  59. return (_globalThis ||
  60. (_globalThis =
  61. typeof globalThis !== 'undefined'
  62. ? globalThis
  63. : typeof self !== 'undefined'
  64. ? self
  65. : typeof window !== 'undefined'
  66. ? window
  67. : typeof global !== 'undefined'
  68. ? global
  69. : create()));
  70. };
  71. function escapeHtml(rawText) {
  72. return rawText
  73. .replace(/&/g, '&') // escape `&` first to avoid double escaping
  74. .replace(/</g, '&lt;')
  75. .replace(/>/g, '&gt;')
  76. .replace(/"/g, '&quot;')
  77. .replace(/'/g, '&apos;')
  78. .replace(/\//g, '&#x2F;') // escape `/` to prevent closing tags or JavaScript URLs
  79. .replace(/=/g, '&#x3D;'); // escape `=` to prevent attribute injection
  80. }
  81. function escapeAttributeValue(value) {
  82. return value
  83. .replace(/&(?![a-zA-Z0-9#]{2,6};)/g, '&amp;') // escape unescaped `&`
  84. .replace(/"/g, '&quot;')
  85. .replace(/'/g, '&apos;')
  86. .replace(/</g, '&lt;')
  87. .replace(/>/g, '&gt;');
  88. }
  89. function sanitizeTranslatedHtml(html) {
  90. // Escape dangerous characters in attribute values
  91. // Process attributes with double quotes
  92. html = html.replace(/(\w+)\s*=\s*"([^"]*)"/g, (_, attrName, attrValue) => `${attrName}="${escapeAttributeValue(attrValue)}"`);
  93. // Process attributes with single quotes
  94. html = html.replace(/(\w+)\s*=\s*'([^']*)'/g, (_, attrName, attrValue) => `${attrName}='${escapeAttributeValue(attrValue)}'`);
  95. // Detect and neutralize event handler attributes
  96. const eventHandlerPattern = /\s*on\w+\s*=\s*["']?[^"'>]+["']?/gi;
  97. if (eventHandlerPattern.test(html)) {
  98. // Neutralize event handler attributes by escaping 'on'
  99. html = html.replace(/(\s+)(on)(\w+\s*=)/gi, '$1&#111;n$3');
  100. }
  101. // Disable javascript: URLs in various contexts
  102. const javascriptUrlPattern = [
  103. // In href, src, action, formaction attributes
  104. /(\s+(?:href|src|action|formaction)\s*=\s*["']?)\s*javascript:/gi,
  105. // In style attributes within url()
  106. /(style\s*=\s*["'][^"']*url\s*\(\s*)javascript:/gi
  107. ];
  108. javascriptUrlPattern.forEach(pattern => {
  109. html = html.replace(pattern, '$1javascript&#58;');
  110. });
  111. return html;
  112. }
  113. const hasOwnProperty = Object.prototype.hasOwnProperty;
  114. function hasOwn(obj, key) {
  115. return hasOwnProperty.call(obj, key);
  116. }
  117. /* eslint-enable */
  118. /**
  119. * Useful Utilities By Evan you
  120. * Modified by kazuya kawaguchi
  121. * MIT License
  122. * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
  123. * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
  124. */
  125. const isArray = Array.isArray;
  126. const isFunction = (val) => typeof val === 'function';
  127. const isString = (val) => typeof val === 'string';
  128. const isBoolean = (val) => typeof val === 'boolean';
  129. const isSymbol = (val) => typeof val === 'symbol';
  130. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  131. const isObject = (val) => val !== null && typeof val === 'object';
  132. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  133. const isPromise = (val) => {
  134. return isObject(val) && isFunction(val.then) && isFunction(val.catch);
  135. };
  136. const objectToString = Object.prototype.toString;
  137. const toTypeString = (value) => objectToString.call(value);
  138. const isPlainObject = (val) => {
  139. if (!isObject(val))
  140. return false;
  141. const proto = Object.getPrototypeOf(val);
  142. return proto === null || proto.constructor === Object;
  143. };
  144. // for converting list and named values to displayed strings.
  145. const toDisplayString = (val) => {
  146. return val == null
  147. ? ''
  148. : isArray(val) || (isPlainObject(val) && val.toString === objectToString)
  149. ? JSON.stringify(val, null, 2)
  150. : String(val);
  151. };
  152. function join(items, separator = '') {
  153. return items.reduce((str, item, index) => (index === 0 ? str + item : str + separator + item), '');
  154. }
  155. const RANGE = 2;
  156. function generateCodeFrame(source, start = 0, end = source.length) {
  157. const lines = source.split(/\r?\n/);
  158. let count = 0;
  159. const res = [];
  160. for (let i = 0; i < lines.length; i++) {
  161. count += lines[i].length + 1;
  162. if (count >= start) {
  163. for (let j = i - RANGE; j <= i + RANGE || end > count; j++) {
  164. if (j < 0 || j >= lines.length)
  165. continue;
  166. const line = j + 1;
  167. res.push(`${line}${' '.repeat(3 - String(line).length)}| ${lines[j]}`);
  168. const lineLength = lines[j].length;
  169. if (j === i) {
  170. // push underline
  171. const pad = start - (count - lineLength) + 1;
  172. const length = Math.max(1, end > count ? lineLength - pad : end - start);
  173. res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
  174. }
  175. else if (j > i) {
  176. if (end > count) {
  177. const length = Math.max(Math.min(end - count, lineLength), 1);
  178. res.push(` | ` + '^'.repeat(length));
  179. }
  180. count += lineLength + 1;
  181. }
  182. }
  183. break;
  184. }
  185. }
  186. return res.join('\n');
  187. }
  188. function incrementer(code) {
  189. let current = code;
  190. return () => ++current;
  191. }
  192. /**
  193. * Event emitter, forked from the below:
  194. * - original repository url: https://github.com/developit/mitt
  195. * - code url: https://github.com/developit/mitt/blob/master/src/index.ts
  196. * - author: Jason Miller (https://github.com/developit)
  197. * - license: MIT
  198. */
  199. /**
  200. * Create a event emitter
  201. *
  202. * @returns An event emitter
  203. */
  204. function createEmitter() {
  205. const events = new Map();
  206. const emitter = {
  207. events,
  208. on(event, handler) {
  209. const handlers = events.get(event);
  210. const added = handlers && handlers.push(handler);
  211. if (!added) {
  212. events.set(event, [handler]);
  213. }
  214. },
  215. off(event, handler) {
  216. const handlers = events.get(event);
  217. if (handlers) {
  218. handlers.splice(handlers.indexOf(handler) >>> 0, 1);
  219. }
  220. },
  221. emit(event, payload) {
  222. (events.get(event) || [])
  223. .slice()
  224. .map(handler => handler(payload));
  225. (events.get('*') || [])
  226. .slice()
  227. .map(handler => handler(event, payload));
  228. }
  229. };
  230. return emitter;
  231. }
  232. const isNotObjectOrIsArray = (val) => !isObject(val) || isArray(val);
  233. // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
  234. function deepCopy(src, des) {
  235. // src and des should both be objects, and none of them can be a array
  236. if (isNotObjectOrIsArray(src) || isNotObjectOrIsArray(des)) {
  237. throw new Error('Invalid value');
  238. }
  239. const stack = [{ src, des }];
  240. while (stack.length) {
  241. const { src, des } = stack.pop();
  242. // using `Object.keys` which skips prototype properties
  243. Object.keys(src).forEach(key => {
  244. if (key === '__proto__') {
  245. return;
  246. }
  247. // if src[key] is an object/array, set des[key]
  248. // to empty object/array to prevent setting by reference
  249. if (isObject(src[key]) && !isObject(des[key])) {
  250. des[key] = Array.isArray(src[key]) ? [] : create();
  251. }
  252. if (isNotObjectOrIsArray(des[key]) || isNotObjectOrIsArray(src[key])) {
  253. // replace with src[key] when:
  254. // src[key] or des[key] is not an object, or
  255. // src[key] or des[key] is an array
  256. des[key] = src[key];
  257. }
  258. else {
  259. // src[key] and des[key] are both objects, merge them
  260. stack.push({ src: src[key], des: des[key] });
  261. }
  262. });
  263. }
  264. }
  265. exports.assign = assign;
  266. exports.create = create;
  267. exports.createEmitter = createEmitter;
  268. exports.deepCopy = deepCopy;
  269. exports.escapeHtml = escapeHtml;
  270. exports.format = format;
  271. exports.friendlyJSONstringify = friendlyJSONstringify;
  272. exports.generateCodeFrame = generateCodeFrame;
  273. exports.generateFormatCacheKey = generateFormatCacheKey;
  274. exports.getGlobalThis = getGlobalThis;
  275. exports.hasOwn = hasOwn;
  276. exports.inBrowser = inBrowser;
  277. exports.incrementer = incrementer;
  278. exports.isArray = isArray;
  279. exports.isBoolean = isBoolean;
  280. exports.isDate = isDate;
  281. exports.isEmptyObject = isEmptyObject;
  282. exports.isFunction = isFunction;
  283. exports.isNumber = isNumber;
  284. exports.isObject = isObject;
  285. exports.isPlainObject = isPlainObject;
  286. exports.isPromise = isPromise;
  287. exports.isRegExp = isRegExp;
  288. exports.isString = isString;
  289. exports.isSymbol = isSymbol;
  290. exports.join = join;
  291. exports.makeSymbol = makeSymbol;
  292. exports.mark = mark;
  293. exports.measure = measure;
  294. exports.objectToString = objectToString;
  295. exports.sanitizeTranslatedHtml = sanitizeTranslatedHtml;
  296. exports.toDisplayString = toDisplayString;
  297. exports.toTypeString = toTypeString;
  298. exports.warn = warn;
  299. exports.warnOnce = warnOnce;