@dropins/tools 1.3.1-alpha017 → 1.3.1-alpha018
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/components.js +1 -1
- package/components.js.map +1 -1
- package/lib/aem/assets.js +1 -1
- package/lib/aem/configs.js +1 -1
- package/lib/aem/configs.test.js +1 -1
- package/package.json +1 -1
package/lib/aem/assets.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{getConfigValue as b}from"./configs.js";import{p as l,I as u}from"../../chunks/Image.js";import"../../chunks/
|
|
3
|
+
import{getConfigValue as b}from"./configs.js";import{p as l,I as u}from"../../chunks/Image.js";import"../../chunks/get-path-value.js";import"../../chunks/cjs.js";import"../../preact-jsx-runtime.js";import"../../chunks/icons/Add.js";import"../../i18n.js";import"../../chunks/vcomponent.js";import"../../chunks/image-params-keymap.js";import"../../signals.js";function d(){const t=b("commerce-assets-enabled");return t&&(typeof t=="string"&&t.toLowerCase()==="true"||typeof t=="boolean"&&t===!0)}function $(){return{quality:80,format:"webp"}}function p(t){let e=t;if(e.startsWith("//")){const{protocol:s}=window.location;console.log("protocol",s),e=s+e}return e}function f(t){return!!(typeof t=="string"?new URL(p(t)):t).pathname.startsWith("/adobe/assets/urn:aaid:aem")}function g(t,e,s={}){const r={...$(),...s},{format:i,crop:a,size:n,...o}=r,m=new URLSearchParams(o);if(a){const[h,w]=[a.xOrigin||0,a.yOrigin||0],[A,U]=[a.width||100,a.height||100],P=`${h}p,${w}p,${A}p,${U}p`;m.set("crop",P)}return n&&n.width&&n.height&&m.set("size",`${n.width},${n.height}`),`${t}/as/${e}.${i}?${m.toString()}`}function x(t,e,s={}){if(!d())return t;const r=new URL(p(t));if(!f(r))return t;const i=r.origin+r.pathname;return g(i,e,s)}function y(t){return e=>{const{wrapper:s,alias:c,params:r,imageProps:i,src:a}=t,n=s??document.createElement("div"),o=g(a||i.src,c,r);l.render(u,{...i,src:o,params:{width:r.width,crop:null,fit:null,auto:null}})(n),e.replaceWith(n)}}function D(t,e){function s(){const o=e.wrapper??document.createElement("div"),{imageProps:m}=e;l.render(u,m)(o),t.replaceWith(o)}if(!d()){s();return}const{imageProps:r,src:i,...a}=e,n=new URL(p(i??r.src));if(!f(n)){s();return}y({src:n.toString(),params:{width:r.width,height:r.height,...a.params},imageProps:r,alias:a.alias,wrapper:a.wrapper})(t)}export{g as generateAemAssetsOptimizedUrl,$ as getDefaultAemAssetsOptimizationParams,d as isAemAssetsEnabled,f as isAemAssetsUrl,y as makeAemAssetsImageSlot,x as tryGenerateAemAssetsOptimizedUrl,D as tryRenderAemAssetsImage};
|
|
4
4
|
//# sourceMappingURL=assets.js.map
|
package/lib/aem/configs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{
|
|
3
|
+
import{g as u}from"../../chunks/get-path-value.js";import{d as f}from"../../chunks/cjs.js";let e=null,r=null,l=null;function C(){e=null,r=null,l=null}function s(t=e){return t?Object.keys(t==null?void 0:t.public).sort((i,o)=>{const a=i.split("/").filter(Boolean).length;return o.split("/").filter(Boolean).length-a}).find(i=>window.location.pathname===i||window.location.pathname.startsWith(i))??"/":(console.warn("No config found. Please call initializeConfig() first."),"/")}function c(){return e?Object.keys(e.public).filter(t=>t!=="default"):(console.warn("No config found. Please call initializeConfig() first."),[])}function m(){return c().length>=1}function w(t){if(!l)throw new Error("Configuration not initialized. Call initializeConfig() first.");const n=l.headers??{};return{...n.all??{},...n[t]??{}}}function g(t,n){var o;const i=(o=t.public)==null?void 0:o.default;return n==="/"||!t.public[n]?i:f(i,t.public[n])}function z(t){return e=t,r=s(e),l=g(e,r),l}function P(t){if(!l)throw new Error("Configuration not initialized. Call initializeConfig() first.");return u(l,t)}export{P as getConfigValue,w as getHeaders,c as getListOfRootPaths,s as getRootPath,z as initializeConfig,m as isMultistore,C as resetConfig};
|
|
4
4
|
//# sourceMappingURL=configs.js.map
|
package/lib/aem/configs.test.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{initializeConfig as o,getConfigValue as s,getRootPath as n,getListOfRootPaths as c,isMultistore as u,getHeaders as a,resetConfig as f}from"./configs.js";import"../../chunks/
|
|
3
|
+
import{initializeConfig as o,getConfigValue as s,getRootPath as n,getListOfRootPaths as c,isMultistore as u,getHeaders as a,resetConfig as f}from"./configs.js";import"../../chunks/get-path-value.js";import"../../chunks/cjs.js";describe("AEM Config",()=>{const t={public:{default:{headers:{all:{"x-test":"test"},commerce:{"x-commerce":"commerce"}}}}};beforeEach(()=>{i("/"),f()}),afterEach(()=>{jest.clearAllMocks(),jest.restoreAllMocks()}),test("should initialize config (default)",()=>{const e={public:{default:{foo:"bar"}}},l=o(e);expect(l).toEqual(e.public.default)}),test("should initialize config with default config if root path is not found",()=>{i("/not-found/");const e=o(t);expect(e).toEqual(t.public.default)}),test("should initialize config with default config if root path is empty",()=>{i("/sub-path/");const e=o({...t,public:{...t.public,"/sub-path/":{}}});expect(e).toEqual(t.public.default)}),test("should initialize config with overrides if root path is not empty",()=>{i("/sub-path/");const e=o({...t,public:{...t.public,"/sub-path/":{headers:{all:{"x-test":"test2"}}}}});expect(e).toEqual({headers:{all:{"x-test":"test2"},commerce:{"x-commerce":"commerce"}}})}),test("should throw error if no config is initialized",async()=>{expect(()=>s("foo")).toThrow("Configuration not initialized. Call initializeConfig() first.")}),test("should get config value",async()=>{o({public:{default:{foo:"bar"}}}),expect(s("foo")).toBe("bar")}),test("should get config value from root path",()=>{i("/sub-path/"),o({...t,public:{...t.public,"/sub-path/":{foo:"baz",nested:{foo:"nested"}}}}),expect(s("headers.all.x-test")).toBe("test"),expect(s("foo")).toBe("baz"),expect(s("nested.foo")).toBe("nested")}),test("should warn if value is not found",async()=>{const e=jest.spyOn(console,"warn").mockImplementation(()=>{});o(t),s("foo.bar"),expect(e).toHaveBeenCalledWith("Property foo.bar does not exist in the object")}),test("should warn if the root path has no config",async()=>{const e=jest.spyOn(console,"warn").mockImplementation(()=>{}),l=n(null);expect(l).toBe("/"),expect(e).toHaveBeenCalledWith("No config found. Please call initializeConfig() first.")}),test("should warn if the root path is not found",async()=>{i("/no-found/");const e=n({public:{default:{}}});expect(e).toBe("/")}),test("should get default root path",async()=>{i("/path/"),o(t),expect(n()).toBe("/")}),test("should get root path from public config",async()=>{i("/test/"),o({...t,public:{...t.public,"/test/":{}}}),expect(n()).toBe("/test/")}),test("should get list of root paths",async()=>{o({...t,public:{...t.public,"/test/":{},"/test2/":{}}}),expect(c()).toEqual(["/test/","/test2/"])}),test("should warn if list of root paths has no config",async()=>{const e=jest.spyOn(console,"warn").mockImplementation(()=>{}),l=c();expect(e).toHaveBeenCalledWith("No config found. Please call initializeConfig() first."),expect(l).toEqual([])}),test("should check if multistore",async()=>{o(t),expect(u()).toBe(!1),o({...t,public:{...t.public,"/test/":{}}}),expect(u()).toBe(!0)}),test("should throw error if headers are not initialized",async()=>{expect(()=>a("all")).toThrow("Configuration not initialized. Call initializeConfig() first.")}),test("should get headers",async()=>{o(t),expect(a("all")).toEqual(t.public.default.headers.all),expect(a("commerce")).toEqual({...t.public.default.headers.all,...t.public.default.headers.commerce})}),test('should get "all" headers if no config is found',async()=>{o(t),expect(a("not-found")).toEqual({...t.public.default.headers.all})}),test("should get empty headers if no config is found",async()=>{o({public:{default:{}}}),expect(a("not-found")).toEqual({})})});function i(t){Object.defineProperty(window,"location",{value:{pathname:t,origin:"http://localhost"}})}
|
|
4
4
|
//# sourceMappingURL=configs.test.js.map
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name": "@dropins/tools", "version": "1.3.1-
|
|
1
|
+
{"name": "@dropins/tools", "version": "1.3.1-alpha018", "license": "SEE LICENSE IN LICENSE.md"}
|