{"version":3,"file":"pad-transformer.cjs","sources":["../../../src/iframe/transformers/pad-transformer.ts"],"sourcesContent":["import { IframeTransformer } from './interface';\n\n/**\n * This transformer is used to transform the pad URL to the embed URL inside the iframe\n * The embed URL is used to create a session for the pad before redirecting to the pad url\n */\nexport class PadIframeTransformer implements IframeTransformer {\n  // Define the pad path\n  private padPath = '/pad/';\n  // Define the embed path\n  private embedPath = '/collaborativeeditor/embed/';\n  onRenderHTML({ HTMLAttributes }) {\n    try {\n      // Get host URL from the current window\n      const currentUrl = window.location.href.split('?')[0];\n      const baseUrl = new URL(currentUrl).origin;\n      // Get Iframe src URL\n      const srcUrl = new URL(HTMLAttributes.src);\n      const pathMatch = srcUrl.pathname.match(\n        new RegExp(`^${this.padPath}(.+)$`),\n      );\n      // Check if the src URL is from the same origin and matches the pad path\n      if (srcUrl.origin === baseUrl && pathMatch && pathMatch[1]) {\n        // Extract pad ID from the URL\n        const padId = pathMatch[1].replace(/^p\\//i, '');\n        // Create a new URL with the embed path\n        const newUrl = new URL(`${baseUrl}${this.embedPath}${padId}`);\n        // Copy search params from the src URL to the new URL\n        srcUrl.searchParams.forEach((value, key) => {\n          newUrl.searchParams.set(key, value);\n        });\n        // Set the new URL\n        HTMLAttributes.src = newUrl.toString();\n      }\n    } catch (e) {\n      console.error('Error transforming pad URL:', e);\n    }\n  }\n}\n"],"names":[],"mappings":"gFAMO,MAAM,oBAAkD,CAAxD,aAAA,CAEL,KAAQ,QAAU,QAElB,KAAQ,UAAY,6BAAA,CACpB,aAAa,CAAE,gBAAkB,CAC/B,GAAI,CAEF,MAAM,WAAa,OAAO,SAAS,KAAK,MAAM,GAAG,EAAE,CAAC,EAC9C,QAAU,IAAI,IAAI,UAAU,EAAE,OAE9B,OAAS,IAAI,IAAI,eAAe,GAAG,EACnC,UAAY,OAAO,SAAS,MAChC,IAAI,OAAO,IAAI,KAAK,OAAO,OAAO,CAAA,EAGpC,GAAI,OAAO,SAAW,SAAW,WAAa,UAAU,CAAC,EAAG,CAE1D,MAAM,MAAQ,UAAU,CAAC,EAAE,QAAQ,QAAS,EAAE,EAExC,OAAS,IAAI,IAAI,GAAG,OAAO,GAAG,KAAK,SAAS,GAAG,KAAK,EAAE,EAE5D,OAAO,aAAa,QAAQ,CAAC,MAAO,MAAQ,CAC1C,OAAO,aAAa,IAAI,IAAK,KAAK,CACpC,CAAC,EAED,eAAe,IAAM,OAAO,SAAA,CAC9B,CACF,OAAS,EAAG,CACV,QAAQ,MAAM,8BAA+B,CAAC,CAChD,CACF,CACF"}