// packages/block-library/src/embed/transforms.js
import { createBlock } from "@wordpress/blocks";
import metadata from "./block.json";
import { removeAspectRatioClasses } from "./util";
var { name: EMBED_BLOCK } = metadata;
var transforms = {
  from: [
    {
      type: "raw",
      isMatch: (node) => node.nodeName === "P" && /^\s*(https?:\/\/\S+)\s*$/i.test(node.textContent) && node.textContent?.match(/https/gi)?.length === 1,
      transform: (node) => {
        return createBlock(EMBED_BLOCK, {
          url: node.textContent.trim()
        });
      }
    }
  ],
  to: [
    {
      type: "block",
      blocks: ["core/paragraph"],
      isMatch: ({ url }) => !!url,
      transform: ({ url, caption, className }) => {
        let value = `<a href="${url}">${url}</a>`;
        if (caption?.trim()) {
          value += `<br />${caption}`;
        }
        return createBlock("core/paragraph", {
          content: value,
          className: removeAspectRatioClasses(className)
        });
      }
    }
  ]
};
var transforms_default = transforms;
export {
  transforms_default as default
};
//# sourceMappingURL=transforms.js.map
