@autorender/sdk-core 0.1.23 → 0.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -355,7 +355,6 @@ interface ARInstance {
355
355
  transformString(transform: TransformOptions): string;
356
356
  responsiveImageAttributes(options: ResponsiveOptions): ResponsiveAttributes;
357
357
  getDPR(): number;
358
- getConnectionQuality(): '2g' | '3g' | '4g' | 'wifi' | 'unknown';
359
358
  }
360
359
 
361
360
  /**
package/dist/index.d.ts CHANGED
@@ -355,7 +355,6 @@ interface ARInstance {
355
355
  transformString(transform: TransformOptions): string;
356
356
  responsiveImageAttributes(options: ResponsiveOptions): ResponsiveAttributes;
357
357
  getDPR(): number;
358
- getConnectionQuality(): '2g' | '3g' | '4g' | 'wifi' | 'unknown';
359
358
  }
360
359
 
361
360
  /**
package/dist/index.js CHANGED
@@ -2948,124 +2948,6 @@ function getDPR() {
2948
2948
  const dpr = window.devicePixelRatio || 1;
2949
2949
  return dpr >= 2 ? 2 : 1;
2950
2950
  }
2951
- function getNavigatorConnection() {
2952
- if (typeof navigator === "undefined") return null;
2953
- const nav = navigator;
2954
- return nav.connection || nav.mozConnection || nav.webkitConnection || null;
2955
- }
2956
- function getConnectionQualityDetailed() {
2957
- if (typeof navigator === "undefined") {
2958
- return { quality: "unknown", reason: "ssr:no-navigator", saveData: false };
2959
- }
2960
- const connection = getNavigatorConnection();
2961
- if (!connection) {
2962
- return { quality: "unknown", reason: "no-network-info-api", saveData: false };
2963
- }
2964
- const saveData = connection.saveData === true;
2965
- const effectiveType = connection.effectiveType || connection.effectiveConnectionType;
2966
- const downlinkMbps = typeof connection.downlink === "number" ? connection.downlink : void 0;
2967
- const rttMs = typeof connection.rtt === "number" ? connection.rtt : void 0;
2968
- if (effectiveType) {
2969
- if (effectiveType === "slow-2g" || effectiveType === "2g") {
2970
- return { quality: "2g", reason: `effectiveType:${effectiveType}`, saveData, effectiveType, downlinkMbps, rttMs };
2971
- }
2972
- if (effectiveType === "3g") {
2973
- return { quality: "3g", reason: "effectiveType:3g", saveData, effectiveType, downlinkMbps, rttMs };
2974
- }
2975
- if (effectiveType === "4g") {
2976
- return { quality: "4g", reason: "effectiveType:4g", saveData, effectiveType, downlinkMbps, rttMs };
2977
- }
2978
- }
2979
- const type = connection.type;
2980
- if (type === "wifi" || type === "ethernet") {
2981
- return { quality: "wifi", reason: `type:${type}`, saveData, effectiveType, downlinkMbps, rttMs };
2982
- }
2983
- if (typeof downlinkMbps === "number") {
2984
- if (downlinkMbps < 0.7) {
2985
- return { quality: "2g", reason: `downlink<0.7Mbps:${downlinkMbps}`, saveData, effectiveType, downlinkMbps, rttMs };
2986
- }
2987
- if (downlinkMbps < 1.8) {
2988
- return { quality: "3g", reason: `downlink<1.8Mbps:${downlinkMbps}`, saveData, effectiveType, downlinkMbps, rttMs };
2989
- }
2990
- return { quality: "4g", reason: `downlink>=1.8Mbps:${downlinkMbps}`, saveData, effectiveType, downlinkMbps, rttMs };
2991
- }
2992
- return { quality: "unknown", reason: "insufficient-signals", saveData, effectiveType, downlinkMbps, rttMs };
2993
- }
2994
- function getConnectionQuality() {
2995
- return getConnectionQualityDetailed().quality;
2996
- }
2997
- function getQualityForConnection(input, opts) {
2998
- const highQuality = opts?.highQuality ?? "auto";
2999
- const saveDataQuality = opts?.saveDataQuality ?? 50;
3000
- if (input === "auto") {
3001
- const detected = getConnectionQualityDetailed();
3002
- if (detected.saveData) return saveDataQuality;
3003
- return getQualityForConnection(detected.quality, opts);
3004
- }
3005
- switch (input) {
3006
- case "2g":
3007
- return 50;
3008
- case "3g":
3009
- return 70;
3010
- case "4g":
3011
- case "wifi":
3012
- return highQuality;
3013
- default:
3014
- return highQuality;
3015
- }
3016
- }
3017
-
3018
- // src/viewtag/format-detection.ts
3019
- var cachedFormat = null;
3020
- function detectBestFormat() {
3021
- if (cachedFormat !== null) {
3022
- return cachedFormat;
3023
- }
3024
- if (typeof document === "undefined" || typeof Image === "undefined") {
3025
- cachedFormat = "webp";
3026
- return cachedFormat;
3027
- }
3028
- try {
3029
- const canvas = document.createElement("canvas");
3030
- canvas.width = 1;
3031
- canvas.height = 1;
3032
- const ctx = canvas.getContext("2d");
3033
- if (!ctx) {
3034
- cachedFormat = "webp";
3035
- return cachedFormat;
3036
- }
3037
- try {
3038
- const avifDataURL = canvas.toDataURL("image/avif");
3039
- if (avifDataURL && avifDataURL.indexOf("data:image/avif") === 0) {
3040
- cachedFormat = "avif";
3041
- return cachedFormat;
3042
- }
3043
- } catch (e) {
3044
- }
3045
- try {
3046
- const webpDataURL = canvas.toDataURL("image/webp");
3047
- if (webpDataURL && webpDataURL.indexOf("data:image/webp") === 0) {
3048
- cachedFormat = "webp";
3049
- return cachedFormat;
3050
- }
3051
- } catch (e) {
3052
- }
3053
- cachedFormat = "jpg";
3054
- return cachedFormat;
3055
- } catch (e) {
3056
- cachedFormat = "webp";
3057
- return cachedFormat;
3058
- }
3059
- }
3060
- function getBestFormatSync() {
3061
- if (cachedFormat !== null) {
3062
- return cachedFormat;
3063
- }
3064
- return detectBestFormat();
3065
- }
3066
- function resetFormatCache() {
3067
- cachedFormat = null;
3068
- }
3069
2951
 
3070
2952
  // src/viewtag/transform.ts
3071
2953
  function buildTransformString(transform, defaults, enableDPR = true, connectionQuality) {
@@ -3185,26 +3067,9 @@ function buildTransformString(transform, defaults, enableDPR = true, connectionQ
3185
3067
  if (transform.flip) addPart("flip_", transform.flip);
3186
3068
  if (transform.br !== void 0) addPart("br_", transform.br);
3187
3069
  let format = transform.f ?? defaults?.f;
3188
- if (format === "auto" || format === void 0) {
3189
- format = getBestFormatSync();
3190
- }
3191
- if (format) addPart("f_", format);
3192
- let quality = transform.q;
3193
- if (quality === "auto" || quality === void 0) {
3194
- const defaultQuality = defaults?.q;
3195
- if (quality === void 0) {
3196
- quality = defaultQuality;
3197
- }
3198
- if (quality === "auto" || quality === void 0) {
3199
- if (connectionQuality) {
3200
- const resolvedQuality = getQualityForConnection(connectionQuality);
3201
- quality = resolvedQuality;
3202
- } else {
3203
- quality = "auto";
3204
- }
3205
- }
3206
- }
3207
- if (quality !== void 0) addPart("q_", quality);
3070
+ if (format && format !== "auto") addPart("f_", format);
3071
+ const quality = transform.q ?? defaults?.q;
3072
+ if (quality !== void 0 && quality !== "auto") addPart("q_", quality);
3208
3073
  if (transform.bg) {
3209
3074
  if (transform.bg.startsWith("rgb:")) {
3210
3075
  addPart("bg_rgb:", transform.bg.replace("rgb:", ""));
@@ -3641,22 +3506,11 @@ function createAR(config) {
3641
3506
  defaults = {},
3642
3507
  deviceBreakpoints = DEFAULT_DEVICE_BREAKPOINTS2,
3643
3508
  imageBreakpoints = DEFAULT_IMAGE_BREAKPOINTS2,
3644
- enableDPR = true,
3645
- connectionQuality: configConnectionQuality = "auto"
3509
+ enableDPR = true
3646
3510
  } = config;
3647
3511
  if (!workspace) {
3648
3512
  throw new Error("workspace is required");
3649
3513
  }
3650
- const normalizedDefaults = {
3651
- f: defaults.f || "auto",
3652
- q: defaults.q !== void 0 ? defaults.q : "auto",
3653
- ...defaults
3654
- };
3655
- const effectiveConnectionQuality = configConnectionQuality === "auto" ? (() => {
3656
- const detected = getConnectionQuality();
3657
- console.log("detected", detected);
3658
- return detected === "unknown" ? "wifi" : detected;
3659
- })() : configConnectionQuality;
3660
3514
  const instance = {
3661
3515
  /**
3662
3516
  * Generate image URL with transformations
@@ -3667,9 +3521,8 @@ function createAR(config) {
3667
3521
  workspace,
3668
3522
  src,
3669
3523
  transform,
3670
- normalizedDefaults,
3671
- enableDPR,
3672
- effectiveConnectionQuality
3524
+ defaults,
3525
+ enableDPR
3673
3526
  );
3674
3527
  },
3675
3528
  /**
@@ -3678,9 +3531,8 @@ function createAR(config) {
3678
3531
  transformString(transform) {
3679
3532
  return buildTransformString(
3680
3533
  transform,
3681
- normalizedDefaults,
3682
- enableDPR,
3683
- effectiveConnectionQuality
3534
+ defaults,
3535
+ enableDPR
3684
3536
  );
3685
3537
  },
3686
3538
  /**
@@ -3692,11 +3544,10 @@ function createAR(config) {
3692
3544
  baseUrl,
3693
3545
  workspace,
3694
3546
  options,
3695
- normalizedDefaults,
3547
+ defaults,
3696
3548
  effectiveDeviceBreakpoints,
3697
3549
  imageBreakpoints,
3698
- enableDPR,
3699
- effectiveConnectionQuality
3550
+ enableDPR
3700
3551
  );
3701
3552
  },
3702
3553
  /**
@@ -3704,17 +3555,63 @@ function createAR(config) {
3704
3555
  */
3705
3556
  getDPR() {
3706
3557
  return getDPR();
3707
- },
3708
- /**
3709
- * Get current connection quality
3710
- */
3711
- getConnectionQuality() {
3712
- return getConnectionQuality();
3713
3558
  }
3714
3559
  };
3715
3560
  return instance;
3716
3561
  }
3717
3562
 
3563
+ // src/viewtag/format-detection.ts
3564
+ var cachedFormat = null;
3565
+ function detectBestFormat() {
3566
+ if (cachedFormat !== null) {
3567
+ return cachedFormat;
3568
+ }
3569
+ if (typeof document === "undefined" || typeof Image === "undefined") {
3570
+ cachedFormat = "webp";
3571
+ return cachedFormat;
3572
+ }
3573
+ try {
3574
+ const canvas = document.createElement("canvas");
3575
+ canvas.width = 1;
3576
+ canvas.height = 1;
3577
+ const ctx = canvas.getContext("2d");
3578
+ if (!ctx) {
3579
+ cachedFormat = "webp";
3580
+ return cachedFormat;
3581
+ }
3582
+ try {
3583
+ const avifDataURL = canvas.toDataURL("image/avif");
3584
+ if (avifDataURL && avifDataURL.indexOf("data:image/avif") === 0) {
3585
+ cachedFormat = "avif";
3586
+ return cachedFormat;
3587
+ }
3588
+ } catch (e) {
3589
+ }
3590
+ try {
3591
+ const webpDataURL = canvas.toDataURL("image/webp");
3592
+ if (webpDataURL && webpDataURL.indexOf("data:image/webp") === 0) {
3593
+ cachedFormat = "webp";
3594
+ return cachedFormat;
3595
+ }
3596
+ } catch (e) {
3597
+ }
3598
+ cachedFormat = "jpg";
3599
+ return cachedFormat;
3600
+ } catch (e) {
3601
+ cachedFormat = "webp";
3602
+ return cachedFormat;
3603
+ }
3604
+ }
3605
+ function getBestFormatSync() {
3606
+ if (cachedFormat !== null) {
3607
+ return cachedFormat;
3608
+ }
3609
+ return detectBestFormat();
3610
+ }
3611
+ function resetFormatCache() {
3612
+ cachedFormat = null;
3613
+ }
3614
+
3718
3615
  // src/index.ts
3719
3616
  var SOURCE_ALIAS_MAP = {
3720
3617
  local: "device",