@minto-ai/tools 1.0.668 → 1.0.669

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -805,6 +805,38 @@ await audioPermission.requestPlaybackPermission()
805
805
  await audioPermission.requestMicrophonePermission()
806
806
  ```
807
807
 
808
+ ### `getBrowserFingerprint`
809
+
810
+ > `function getBrowserFingerprint(): string`
811
+
812
+ 生成匿名浏览器指纹,用于区分浏览器匿名用户的唯一 ID。通过收集浏览器环境特征(如 UserAgent、语言、屏幕分辨率、色深、时区、硬件并发、平台,以及 Canvas 渲染指纹等),并使用 MurmurHash3(32 位)生成稳定的十六进制字符串。
813
+
814
+ #### 参数
815
+
816
+ - 无
817
+
818
+ #### 返回
819
+
820
+ `(string)`: 浏览器指纹 ID(十六进制字符串)。在非浏览器环境(如 Node/SSR)返回空字符串 `''`。
821
+
822
+ #### 例子
823
+
824
+ ```typescript
825
+ import { getBrowserFingerprint } from '@minto-ai/tools'
826
+
827
+ // 生成匿名用户唯一ID
828
+ const fingerprint = getBrowserFingerprint()
829
+ console.log(fingerprint) // 例如:'a1b2c3d4'
830
+
831
+ // 建议:结合本地存储缓存以保持一致性
832
+ localStorage.setItem('anonymous_id', fingerprint)
833
+ ```
834
+
835
+ #### 注意事项
836
+
837
+ - 指纹可能随浏览器升级、系统变更或渲染差异而变化,适合作为匿名用户的临时唯一标识,不建议用于强身份识别。
838
+ - 隐私增强模式或跨平台差异可能禁用部分特征(如 deviceMemory、Canvas),函数会自动兼容并尽可能生成可辨识的 ID。
839
+
808
840
  ## 工具
809
841
 
810
842
  ### `getUuid`
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 将任意格式的 URL 路径规范化为完整的绝对 URL 地址
3
+ * @param rawUrl - 待规范化的原始 URL 路径,支持空值、相对路径、绝对路径等格式
4
+ * @returns 规范化后的绝对 URL 字符串,空输入返回空字符串
5
+ */
6
+ declare function getAbsoluteUrl(rawUrl: string): string;
7
+ export default getAbsoluteUrl;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 获取浏览器唯一指纹 ID
3
+ * 通过收集浏览器特征(UserAgent, Screen, Language, Timezone, Canvas 等)生成哈希值
4
+ * 注意:此方法生成的 ID 在浏览器环境变化(如升级、窗口大小改变如果包含了窗口大小)时可能会变化,
5
+ * 但作为匿名用户的临时唯一标识通常足够。
6
+ *
7
+ * @returns 浏览器指纹 ID 字符串
8
+ */
9
+ export declare function getBrowserFingerprint(): string;
10
+ export default getBrowserFingerprint;
@@ -1,7 +1,9 @@
1
1
  import { default as copyText } from './copy-text';
2
2
  import { default as createAudioPermission } from './create-audio-permission';
3
+ import { default as getAbsoluteUrl } from './get-absolute-url';
4
+ import { default as getBrowserFingerprint } from './get-browser-fingerprint';
3
5
  import { default as isAndroid } from './is-android';
4
6
  import { default as isIos } from './is-ios';
5
7
  import { default as isMobile } from './is-mobile';
6
8
  import { default as isPc } from './is-pc';
7
- export { copyText, createAudioPermission, isAndroid, isIos, isMobile, isPc };
9
+ export { copyText, createAudioPermission, getAbsoluteUrl, getBrowserFingerprint, isAndroid, isIos, isMobile, isPc, };
package/dist/index.js CHANGED
@@ -13754,6 +13754,137 @@ function createAudioPermission() {
13754
13754
  }
13755
13755
  return audioPermissionInstance;
13756
13756
  }
13757
+ function getAbsoluteUrl(rawUrl) {
13758
+ if (!rawUrl) {
13759
+ return "";
13760
+ }
13761
+ try {
13762
+ var absoluteUrl = new URL(rawUrl).toString();
13763
+ return absoluteUrl;
13764
+ } catch (_unused) {
13765
+ try {
13766
+ var currentPageUrl = window.location.href;
13767
+ var _absoluteUrl = new URL(rawUrl, currentPageUrl).toString();
13768
+ return _absoluteUrl;
13769
+ } catch (_unused2) {
13770
+ var siteOrigin = window.location.origin;
13771
+ var normalizedPath = rawUrl.startsWith("/") ? rawUrl : "/".concat(rawUrl);
13772
+ var _absoluteUrl2 = "".concat(siteOrigin).concat(normalizedPath).replace(/\/+/g, "/");
13773
+ return _absoluteUrl2;
13774
+ }
13775
+ }
13776
+ }
13777
+ function murmurHash332Gc(key) {
13778
+ var seed = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
13779
+ var k1;
13780
+ var h1;
13781
+ var remainder = key.length & 3;
13782
+ var bytes = key.length - remainder;
13783
+ h1 = seed;
13784
+ var c1 = 3432918353;
13785
+ var c2 = 461845907;
13786
+ var i = 0;
13787
+ while (i < bytes) {
13788
+ k1 = key.charCodeAt(i) & 255 | (key.charCodeAt(++i) & 255) << 8 | (key.charCodeAt(++i) & 255) << 16 | (key.charCodeAt(++i) & 255) << 24;
13789
+ ++i;
13790
+ k1 = (k1 & 65535) * c1 + (((k1 >>> 16) * c1 & 65535) << 16) & 4294967295;
13791
+ k1 = k1 << 15 | k1 >>> 17;
13792
+ k1 = (k1 & 65535) * c2 + (((k1 >>> 16) * c2 & 65535) << 16) & 4294967295;
13793
+ h1 ^= k1;
13794
+ h1 = h1 << 13 | h1 >>> 19;
13795
+ var h1b = (h1 & 65535) * 5 + (((h1 >>> 16) * 5 & 65535) << 16) & 4294967295;
13796
+ h1 = (h1b & 65535) + 27492 + (((h1b >>> 16) + 58964 & 65535) << 16);
13797
+ }
13798
+ k1 = 0;
13799
+ if (remainder >= 3) {
13800
+ k1 ^= (key.charCodeAt(i + 2) & 255) << 16;
13801
+ }
13802
+ if (remainder >= 2) {
13803
+ k1 ^= (key.charCodeAt(i + 1) & 255) << 8;
13804
+ }
13805
+ if (remainder >= 1) {
13806
+ k1 ^= key.charCodeAt(i) & 255;
13807
+ k1 = (k1 & 65535) * c1 + (((k1 >>> 16) * c1 & 65535) << 16) & 4294967295;
13808
+ k1 = k1 << 15 | k1 >>> 17;
13809
+ k1 = (k1 & 65535) * c2 + (((k1 >>> 16) * c2 & 65535) << 16) & 4294967295;
13810
+ h1 ^= k1;
13811
+ }
13812
+ h1 ^= key.length;
13813
+ h1 ^= h1 >>> 16;
13814
+ h1 = (h1 & 65535) * 2246822507 + (((h1 >>> 16) * 2246822507 & 65535) << 16) & 4294967295;
13815
+ h1 ^= h1 >>> 13;
13816
+ h1 = (h1 & 65535) * 3266489909 + (((h1 >>> 16) * 3266489909 & 65535) << 16) & 4294967295;
13817
+ h1 ^= h1 >>> 16;
13818
+ return h1 >>> 0;
13819
+ }
13820
+ function getCanvasFingerprint() {
13821
+ try {
13822
+ var canvas = document.createElement("canvas");
13823
+ var ctx = canvas.getContext("2d");
13824
+ if (!ctx) {
13825
+ return "";
13826
+ }
13827
+ canvas.width = 200;
13828
+ canvas.height = 50;
13829
+ ctx.textBaseline = "top";
13830
+ ctx.font = "14px Arial";
13831
+ ctx.fillStyle = "#f60";
13832
+ ctx.fillRect(125, 1, 62, 20);
13833
+ ctx.fillStyle = "#069";
13834
+ ctx.fillText("Hello, world!", 2, 15);
13835
+ ctx.fillStyle = "rgba(102, 204, 0, 0.7)";
13836
+ ctx.fillText("Hello, world!", 4, 17);
13837
+ ctx.globalCompositeOperation = "multiply";
13838
+ ctx.fillStyle = "rgb(255,0,255)";
13839
+ ctx.beginPath();
13840
+ ctx.arc(50, 50, 50, 0, Math.PI * 2, true);
13841
+ ctx.closePath();
13842
+ ctx.fill();
13843
+ ctx.fillStyle = "rgb(0,255,255)";
13844
+ ctx.beginPath();
13845
+ ctx.arc(100, 50, 50, 0, Math.PI * 2, true);
13846
+ ctx.closePath();
13847
+ ctx.fill();
13848
+ ctx.fillStyle = "rgb(255,255,0)";
13849
+ ctx.beginPath();
13850
+ ctx.arc(75, 100, 50, 0, Math.PI * 2, true);
13851
+ ctx.closePath();
13852
+ ctx.fill();
13853
+ ctx.fillStyle = "rgb(255,0,255)";
13854
+ ctx.arc(75, 75, 75, 0, Math.PI * 2, true);
13855
+ ctx.arc(75, 75, 25, 0, Math.PI * 2, true);
13856
+ ctx.fill("evenodd");
13857
+ return canvas.toDataURL();
13858
+ } catch (_unused) {
13859
+ return "";
13860
+ }
13861
+ }
13862
+ function getBrowserFingerprint() {
13863
+ if (typeof window === "undefined") {
13864
+ return "";
13865
+ }
13866
+ var _window = window, navigator2 = _window.navigator, screen = _window.screen;
13867
+ var components = [];
13868
+ components.push(navigator2.userAgent);
13869
+ components.push(navigator2.language);
13870
+ components.push("".concat(screen.width, "x").concat(screen.height));
13871
+ components.push("".concat(screen.colorDepth));
13872
+ components.push("".concat((/* @__PURE__ */ new Date()).getTimezoneOffset()));
13873
+ if (navigator2.hardwareConcurrency) {
13874
+ components.push("".concat(navigator2.hardwareConcurrency));
13875
+ }
13876
+ if (navigator2.deviceMemory) {
13877
+ components.push("".concat(navigator2.deviceMemory));
13878
+ }
13879
+ if (navigator2.platform) {
13880
+ components.push(navigator2.platform);
13881
+ }
13882
+ var canvasFingerprint = getCanvasFingerprint();
13883
+ components.push(canvasFingerprint);
13884
+ var fingerprintString = components.join("###");
13885
+ var hash = murmurHash332Gc(fingerprintString);
13886
+ return hash.toString(16);
13887
+ }
13757
13888
  function isAndroid() {
13758
13889
  var userAgent2 = navigator.userAgent.toLowerCase();
13759
13890
  return /android/.test(userAgent2);
@@ -16797,6 +16928,8 @@ export {
16797
16928
  deepFreeze,
16798
16929
  index as default,
16799
16930
  divide2 as divide,
16931
+ getAbsoluteUrl,
16932
+ getBrowserFingerprint,
16800
16933
  getDecimalPlaces,
16801
16934
  getFileIcon,
16802
16935
  getFileName,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@minto-ai/tools",
3
3
  "type": "module",
4
- "version": "1.0.668",
4
+ "version": "1.0.669",
5
5
  "description": "明途公共工具库",
6
6
  "author": "hcc",
7
7
  "license": "ISC",