@autorender/sdk-core 0.1.22 → 0.1.24

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
@@ -112,6 +112,7 @@ Creates a new AutoRender client instance for image transformations.
112
112
  ### `ARInstance`
113
113
 
114
114
  - `url(src: string, transform?: TransformOptions): string` - Generate transformed image URL
115
+ - `src` supports workspace paths (e.g., `products/shoe.jpg`) and absolute remote URLs (e.g., `https://example.com/image.jpg`).
115
116
  - `transformString(transform: TransformOptions): string` - Get transformation string only
116
117
  - `responsiveImageAttributes(options: ResponsiveOptions): ResponsiveAttributes` - Generate responsive image attributes
117
118
  - `getDPR(): number` - Get device pixel ratio (1 or 2)
package/dist/index.cjs CHANGED
@@ -23,6 +23,7 @@ __export(src_exports, {
23
23
  createAR: () => createAR,
24
24
  createUploader: () => createUploader,
25
25
  detectBestFormat: () => detectBestFormat,
26
+ encodeAssetPathForDelivery: () => encodeAssetPathForDelivery,
26
27
  getBestFormatSync: () => getBestFormatSync,
27
28
  registerAutorenderUploaderElement: () => registerAutorenderUploaderElement,
28
29
  resetFormatCache: () => resetFormatCache
@@ -3534,15 +3535,40 @@ function normalizePlacement(placement) {
3534
3535
  }
3535
3536
 
3536
3537
  // src/viewtag/url-builder.ts
3538
+ var ABSOLUTE_URL_RE = /^https?:\/\//i;
3539
+ function encodeAssetPathForDelivery(src) {
3540
+ const trimmed = src.trim();
3541
+ if (!trimmed) {
3542
+ return "";
3543
+ }
3544
+ if (ABSOLUTE_URL_RE.test(trimmed)) {
3545
+ const fetchPayload = `fetch_${trimmed}`;
3546
+ return encodeURIComponent(fetchPayload);
3547
+ }
3548
+ if (trimmed.startsWith("fetch_")) {
3549
+ return encodeURIComponent(trimmed);
3550
+ }
3551
+ return trimmed.split("/").filter(Boolean).map((segment) => encodeURIComponent(segment)).join("/");
3552
+ }
3537
3553
  function buildImageUrl(baseUrl, workspace, src, transform, defaults, enableDPR = true, connectionQuality) {
3538
3554
  const normalizedBase = baseUrl.replace(/\/+$/, "");
3539
3555
  const transformStr = buildTransformString(transform || {}, defaults, enableDPR, connectionQuality);
3540
- const encodedPath = src.split("/").filter(Boolean).map((segment) => encodeURIComponent(segment)).join("/");
3556
+ const trimmedSrc = src.trim();
3557
+ if (ABSOLUTE_URL_RE.test(trimmedSrc)) {
3558
+ const fetchPart = `fetch_${trimmedSrc}`;
3559
+ const transformWithFetch = transformStr ? `${transformStr},${fetchPart}` : fetchPart;
3560
+ return `${normalizedBase}/${workspace}/${transformWithFetch}`;
3561
+ }
3562
+ if (trimmedSrc.startsWith("fetch_")) {
3563
+ const fetchPart = trimmedSrc;
3564
+ const transformWithFetch = transformStr ? `${transformStr},${fetchPart}` : fetchPart;
3565
+ return `${normalizedBase}/${workspace}/${transformWithFetch}`;
3566
+ }
3567
+ const encodedPath = encodeAssetPathForDelivery(trimmedSrc);
3541
3568
  if (transformStr) {
3542
3569
  return `${normalizedBase}/${workspace}/${transformStr}/${encodedPath}`;
3543
- } else {
3544
- return `${normalizedBase}/${workspace}/${encodedPath}`;
3545
3570
  }
3571
+ return `${normalizedBase}/${workspace}/${encodedPath}`;
3546
3572
  }
3547
3573
 
3548
3574
  // src/viewtag/responsive.ts
@@ -3925,6 +3951,7 @@ function registerAutorenderUploaderElement() {
3925
3951
  createAR,
3926
3952
  createUploader,
3927
3953
  detectBestFormat,
3954
+ encodeAssetPathForDelivery,
3928
3955
  getBestFormatSync,
3929
3956
  registerAutorenderUploaderElement,
3930
3957
  resetFormatCache