// @bun
var __create = Object.create;
var __getProtoOf = Object.getPrototypeOf;
var __defProp = Object.defineProperty;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __hasOwnProp = Object.prototype.hasOwnProperty;
function __accessProp(key) {
  return this[key];
}
var __toESMCache_node;
var __toESMCache_esm;
var __toESM = (mod, isNodeMode, target) => {
  var canCache = mod != null && typeof mod === "object";
  if (canCache) {
    var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
    var cached = cache.get(mod);
    if (cached)
      return cached;
  }
  target = mod != null ? __create(__getProtoOf(mod)) : {};
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
  for (let key of __getOwnPropNames(mod))
    if (!__hasOwnProp.call(to, key))
      __defProp(to, key, {
        get: __accessProp.bind(mod, key),
        enumerable: true
      });
  if (canCache)
    cache.set(mod, to);
  return to;
};
var __toCommonJS = (from) => {
  var entry = (__moduleCache ??= new WeakMap).get(from), desc;
  if (entry)
    return entry;
  entry = __defProp({}, "__esModule", { value: true });
  if (from && typeof from === "object" || typeof from === "function") {
    for (var key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(entry, key))
        __defProp(entry, key, {
          get: __accessProp.bind(from, key),
          enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
        });
  }
  __moduleCache.set(from, entry);
  return entry;
};
var __moduleCache;
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
var __returnValue = (v) => v;
function __exportSetter(name, newValue) {
  this[name] = __returnValue.bind(null, newValue);
}
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, {
      get: all[name],
      enumerable: true,
      configurable: true,
      set: __exportSetter.bind(all, name)
    });
};
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
    r = Reflect.decorate(decorators, target, key, desc);
  else
    for (var i = decorators.length - 1;i >= 0; i--)
      if (d = decorators[i])
        r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __legacyMetadataTS = (k, v) => {
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
    return Reflect.metadata(k, v);
};
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
var __require = import.meta.require;

// src/utils/imageProcessing.ts
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
import { join, resolve } from "path";
var DEFAULT_DEVICE_SIZES, DEFAULT_IMAGE_SIZES, DEFAULT_QUALITY = 75, OPTIMIZATION_ENDPOINT = "/_absolute/image", BLUR_DEVIATION = 20, sharpModule = undefined, sharpLoaded = false, sharpWarned = false, snapToSize = (target, sizes) => {
  for (const size of sizes) {
    if (size >= target)
      return size;
  }
  return sizes[sizes.length - 1] ?? target;
}, matchHostname = (actual, pattern) => {
  if (pattern === actual)
    return true;
  if (pattern.startsWith("*.")) {
    const suffix = pattern.slice(1);
    return actual.endsWith(suffix) && actual.length > suffix.length;
  }
  return false;
}, matchPathname = (actual, pattern) => {
  if (pattern.endsWith("/**")) {
    const prefix = pattern.slice(0, -2);
    return actual.startsWith(prefix);
  }
  return actual === pattern;
}, MIME_MAP, callSharp = (sharpRef, input) => {
  const factory = sharpRef;
  return factory(input);
}, toBuffer = (input) => {
  if (Buffer.isBuffer(input))
    return input;
  return Buffer.from(input);
}, buildOptimizedUrl = (src, width, quality, basePath = OPTIMIZATION_ENDPOINT) => `${basePath}?url=${encodeURIComponent(src)}&w=${width}&q=${quality}`, formatToMime = (format) => MIME_MAP[format], generateBlurSvg = (base64Thumbnail) => {
  const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 320"><filter id="b" color-interpolation-filters="sRGB"><feGaussianBlur stdDeviation="${BLUR_DEVIATION}"/><feColorMatrix values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 100 -1"/></filter><image filter="url(#b)" x="0" y="0" width="100%" height="100%" href="${base64Thumbnail}"/></svg>`;
  const encoded = encodeURIComponent(svg);
  return `url("data:image/svg+xml,${encoded}")`;
}, generateSrcSet = (src, width, sizes, config, loader) => {
  const quality = config?.quality ?? DEFAULT_QUALITY;
  const basePath = config?.path ?? OPTIMIZATION_ENDPOINT;
  const buildUrl = loader ?? ((params) => buildOptimizedUrl(params.src, params.width, params.quality, basePath));
  if (sizes) {
    const allSizes = getAllSizes(config);
    return allSizes.map((sizeWidth) => `${buildUrl({ quality, src, width: sizeWidth })} ${sizeWidth}w`).join(", ");
  }
  if (width) {
    const allSizes = getAllSizes(config);
    const w1x = snapToSize(width, allSizes);
    const w2x = snapToSize(width * 2, allSizes);
    return `${buildUrl({ quality, src, width: w1x })} 1x, ${buildUrl({ quality, src, width: w2x })} 2x`;
  }
  const deviceSizes = config?.deviceSizes ?? DEFAULT_DEVICE_SIZES;
  return deviceSizes.map((sizeWidth) => `${buildUrl({ quality, src, width: sizeWidth })} ${sizeWidth}w`).join(", ");
}, getAllSizes = (config) => {
  const device = config?.deviceSizes ?? DEFAULT_DEVICE_SIZES;
  const image = config?.imageSizes ?? DEFAULT_IMAGE_SIZES;
  return [...device, ...image].sort((left, right) => left - right);
}, getCacheDir = (buildDir) => {
  const dir = join(buildDir, ".cache", "images");
  if (!existsSync(dir))
    mkdirSync(dir, { recursive: true });
  return dir;
}, getCacheKey = (url, width, quality, format) => {
  const hasher = new Bun.CryptoHasher("sha256");
  hasher.update(`${url}|${width}|${quality}|${format}`);
  return hasher.digest("hex");
}, isCacheStale = (meta) => Date.now() > meta.expireAt, matchRemotePattern = (urlString, patterns) => {
  let parsed;
  try {
    parsed = new URL(urlString);
  } catch {
    return false;
  }
  return patterns.some((pattern) => {
    if (pattern.protocol && parsed.protocol !== `${pattern.protocol}:`)
      return false;
    if (!matchHostname(parsed.hostname, pattern.hostname))
      return false;
    if (pattern.port && parsed.port !== pattern.port)
      return false;
    if (pattern.pathname && !matchPathname(parsed.pathname, pattern.pathname))
      return false;
    return true;
  });
}, negotiateFormat = (acceptHeader, configuredFormats) => {
  for (const format of configuredFormats) {
    const mime = MIME_MAP[format];
    if (mime && acceptHeader.includes(mime))
      return format;
  }
  if (configuredFormats.includes("webp") && acceptHeader.includes("image/webp")) {
    return "webp";
  }
  return "jpeg";
}, AVIF_QUALITY_OFFSET = 20, AVIF_EFFORT = 3, optimizeImage = async (buffer, width, quality, format) => {
  const sharp = await tryLoadSharp();
  if (!sharp)
    return toBuffer(buffer);
  const pipeline = callSharp(sharp, toBuffer(buffer)).rotate().resize(width, undefined, { withoutEnlargement: true });
  switch (format) {
    case "avif":
      return pipeline.avif({
        effort: AVIF_EFFORT,
        quality: Math.max(1, quality - AVIF_QUALITY_OFFSET)
      }).toBuffer();
    case "jpeg":
      return pipeline.jpeg({ mozjpeg: true, quality }).toBuffer();
    case "png":
      return pipeline.png({ quality }).toBuffer();
    case "webp":
      return pipeline.webp({ quality }).toBuffer();
    default:
      return toBuffer(buffer);
  }
}, readFromCache = (cacheDir, cacheKey) => {
  const metaPath = join(cacheDir, `${cacheKey}.meta`);
  const dataPath = join(cacheDir, `${cacheKey}.data`);
  if (!existsSync(metaPath) || !existsSync(dataPath))
    return null;
  try {
    const meta = JSON.parse(readFileSync(metaPath, "utf-8"));
    const buffer = readFileSync(dataPath);
    return { buffer, meta };
  } catch {
    return null;
  }
}, tryLoadSharp = async () => {
  if (sharpLoaded)
    return sharpModule;
  sharpLoaded = true;
  try {
    const sharpPath = resolve(process.cwd(), "node_modules/sharp");
    const mod = await import(sharpPath);
    sharpModule = mod.default ?? mod;
    return sharpModule;
  } catch {
    if (sharpWarned)
      return null;
    sharpWarned = true;
    console.warn("[image] sharp not installed \u2014 serving unoptimized images. Install with: bun add sharp");
    return null;
  }
}, writeToCache = (cacheDir, cacheKey, buffer, meta) => {
  const metaPath = join(cacheDir, `${cacheKey}.meta`);
  const dataPath = join(cacheDir, `${cacheKey}.data`);
  writeFileSync(dataPath, buffer);
  writeFileSync(metaPath, JSON.stringify(meta));
};
var init_imageProcessing = __esm(() => {
  DEFAULT_DEVICE_SIZES = [
    640,
    750,
    828,
    1080,
    1200,
    1920,
    2048,
    3840
  ];
  DEFAULT_IMAGE_SIZES = [16, 32, 48, 64, 96, 128, 256, 384];
  MIME_MAP = {
    avif: "image/avif",
    jpeg: "image/jpeg",
    png: "image/png",
    webp: "image/webp"
  };
});

// src/react/components/Head.tsx
import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
var RobotsContent = ({ robots }) => {
  const directives = [];
  if (robots.index === false)
    directives.push("noindex");
  if (robots.index === true)
    directives.push("index");
  if (robots.follow === false)
    directives.push("nofollow");
  if (robots.follow === true)
    directives.push("follow");
  if (robots.noarchive)
    directives.push("noarchive");
  if (robots.nosnippet)
    directives.push("nosnippet");
  if (robots.noimageindex)
    directives.push("noimageindex");
  if (robots.maxSnippet !== undefined)
    directives.push(`max-snippet:${robots.maxSnippet}`);
  if (robots.maxImagePreview)
    directives.push(`max-image-preview:${robots.maxImagePreview}`);
  if (robots.maxVideoPreview !== undefined)
    directives.push(`max-video-preview:${robots.maxVideoPreview}`);
  const content = directives.join(", ");
  return content ? /* @__PURE__ */ jsxDEV("meta", {
    content,
    name: "robots"
  }, undefined, false, undefined, this) : null;
};
var OpenGraphTags = ({
  openGraph,
  title,
  description
}) => /* @__PURE__ */ jsxDEV(Fragment, {
  children: [
    /* @__PURE__ */ jsxDEV("meta", {
      content: openGraph.title ?? title,
      property: "og:title"
    }, undefined, false, undefined, this),
    /* @__PURE__ */ jsxDEV("meta", {
      content: openGraph.description ?? description,
      property: "og:description"
    }, undefined, false, undefined, this),
    openGraph.url && /* @__PURE__ */ jsxDEV("meta", {
      content: openGraph.url,
      property: "og:url"
    }, undefined, false, undefined, this),
    openGraph.image && /* @__PURE__ */ jsxDEV("meta", {
      content: openGraph.image,
      property: "og:image"
    }, undefined, false, undefined, this),
    openGraph.imageAlt && /* @__PURE__ */ jsxDEV("meta", {
      content: openGraph.imageAlt,
      property: "og:image:alt"
    }, undefined, false, undefined, this),
    openGraph.imageWidth && /* @__PURE__ */ jsxDEV("meta", {
      content: String(openGraph.imageWidth),
      property: "og:image:width"
    }, undefined, false, undefined, this),
    openGraph.imageHeight && /* @__PURE__ */ jsxDEV("meta", {
      content: String(openGraph.imageHeight),
      property: "og:image:height"
    }, undefined, false, undefined, this),
    openGraph.type && /* @__PURE__ */ jsxDEV("meta", {
      content: openGraph.type,
      property: "og:type"
    }, undefined, false, undefined, this),
    openGraph.siteName && /* @__PURE__ */ jsxDEV("meta", {
      content: openGraph.siteName,
      property: "og:site_name"
    }, undefined, false, undefined, this),
    openGraph.locale && /* @__PURE__ */ jsxDEV("meta", {
      content: openGraph.locale,
      property: "og:locale"
    }, undefined, false, undefined, this)
  ]
}, undefined, true, undefined, this);
var TwitterTags = ({
  twitter,
  title,
  description
}) => /* @__PURE__ */ jsxDEV(Fragment, {
  children: [
    twitter.card && /* @__PURE__ */ jsxDEV("meta", {
      content: twitter.card,
      name: "twitter:card"
    }, undefined, false, undefined, this),
    /* @__PURE__ */ jsxDEV("meta", {
      content: twitter.title ?? title,
      name: "twitter:title"
    }, undefined, false, undefined, this),
    /* @__PURE__ */ jsxDEV("meta", {
      content: twitter.description ?? description,
      name: "twitter:description"
    }, undefined, false, undefined, this),
    twitter.image && /* @__PURE__ */ jsxDEV("meta", {
      content: twitter.image,
      name: "twitter:image"
    }, undefined, false, undefined, this),
    twitter.imageAlt && /* @__PURE__ */ jsxDEV("meta", {
      content: twitter.imageAlt,
      name: "twitter:image:alt"
    }, undefined, false, undefined, this),
    twitter.site && /* @__PURE__ */ jsxDEV("meta", {
      content: twitter.site,
      name: "twitter:site"
    }, undefined, false, undefined, this),
    twitter.creator && /* @__PURE__ */ jsxDEV("meta", {
      content: twitter.creator,
      name: "twitter:creator"
    }, undefined, false, undefined, this)
  ]
}, undefined, true, undefined, this);
var CustomMetaTag = ({ tag }) => {
  if (tag.property)
    return /* @__PURE__ */ jsxDEV("meta", {
      content: tag.content,
      property: tag.property
    }, undefined, false, undefined, this);
  if (tag.httpEquiv)
    return /* @__PURE__ */ jsxDEV("meta", {
      content: tag.content,
      httpEquiv: tag.httpEquiv
    }, undefined, false, undefined, this);
  return /* @__PURE__ */ jsxDEV("meta", {
    content: tag.content,
    name: tag.name
  }, undefined, false, undefined, this);
};
var Head = ({
  title = "AbsoluteJS",
  description = "A page created using AbsoluteJS",
  icon = "/assets/ico/favicon.ico",
  font,
  cssPath,
  canonical,
  openGraph,
  twitter,
  robots,
  meta
} = {}) => /* @__PURE__ */ jsxDEV("head", {
  suppressHydrationWarning: true,
  children: [
    /* @__PURE__ */ jsxDEV("meta", {
      charSet: "utf-8"
    }, undefined, false, undefined, this),
    /* @__PURE__ */ jsxDEV("title", {
      children: title
    }, undefined, false, undefined, this),
    /* @__PURE__ */ jsxDEV("meta", {
      content: description,
      name: "description"
    }, undefined, false, undefined, this),
    /* @__PURE__ */ jsxDEV("meta", {
      content: "width=device-width, initial-scale=1",
      name: "viewport"
    }, undefined, false, undefined, this),
    /* @__PURE__ */ jsxDEV("link", {
      href: icon,
      rel: "icon"
    }, undefined, false, undefined, this),
    canonical && /* @__PURE__ */ jsxDEV("link", {
      href: canonical,
      rel: "canonical"
    }, undefined, false, undefined, this),
    openGraph && /* @__PURE__ */ jsxDEV(OpenGraphTags, {
      description,
      openGraph,
      title
    }, undefined, false, undefined, this),
    twitter && /* @__PURE__ */ jsxDEV(TwitterTags, {
      description,
      title,
      twitter
    }, undefined, false, undefined, this),
    robots && /* @__PURE__ */ jsxDEV(RobotsContent, {
      robots
    }, undefined, false, undefined, this),
    meta?.map((tag, i) => /* @__PURE__ */ jsxDEV(CustomMetaTag, {
      tag
    }, i, false, undefined, this)),
    font && /* @__PURE__ */ jsxDEV(Fragment, {
      children: [
        /* @__PURE__ */ jsxDEV("link", {
          href: "https://fonts.googleapis.com",
          rel: "preconnect"
        }, undefined, false, undefined, this),
        /* @__PURE__ */ jsxDEV("link", {
          crossOrigin: "anonymous",
          href: "https://fonts.gstatic.com",
          rel: "preconnect",
          suppressHydrationWarning: true
        }, undefined, false, undefined, this),
        /* @__PURE__ */ jsxDEV("link", {
          href: `https://fonts.googleapis.com/css2?family=${font}:wght@100..900&display=swap`,
          rel: "stylesheet",
          suppressHydrationWarning: true
        }, undefined, false, undefined, this)
      ]
    }, undefined, true, undefined, this),
    cssPath && [cssPath].flat().map((path) => /* @__PURE__ */ jsxDEV("link", {
      href: path,
      rel: "stylesheet",
      suppressHydrationWarning: true,
      type: "text/css"
    }, path, false, undefined, this))
  ]
}, undefined, true, undefined, this);
// src/react/components/Image.tsx
init_imageProcessing();
import { jsxDEV as jsxDEV2, Fragment as Fragment2 } from "react/jsx-dev-runtime";
var resolveSource = (src, overrideSrc, unoptimized, loader, width, quality) => {
  if (overrideSrc)
    return overrideSrc;
  if (unoptimized)
    return src;
  if (loader)
    return loader({ quality, src, width: width ?? 0 });
  if (!width)
    return buildOptimizedUrl(src, 0, quality);
  return buildOptimizedUrl(src, width, quality);
};
var resolveBlurBackground = (hasBlur, placeholder, blurDataURL) => {
  if (!hasBlur)
    return;
  if (typeof placeholder === "string" && placeholder !== "blur" && placeholder.startsWith("data:")) {
    return generateBlurSvg(placeholder);
  }
  if (blurDataURL)
    return generateBlurSvg(blurDataURL);
  return;
};
var Image = ({
  alt,
  blurDataURL,
  className,
  crossOrigin,
  fetchPriority,
  fill,
  height,
  loader,
  loading,
  onError,
  onLoad,
  overrideSrc,
  placeholder,
  priority,
  quality = DEFAULT_QUALITY,
  referrerPolicy,
  sizes,
  src,
  style,
  unoptimized,
  width
}) => {
  const resolvedSrc = resolveSource(src, overrideSrc, unoptimized, loader, width, quality);
  const srcSet = unoptimized ? undefined : generateSrcSet(src, width, sizes, undefined, loader ?? undefined);
  const resolvedSizes = sizes ?? (fill ? "100vw" : undefined);
  const resolvedLoading = priority ? "eager" : loading ?? "lazy";
  const resolvedFetchPriority = priority ? "high" : fetchPriority;
  const hasBlur = placeholder === "blur" || typeof placeholder === "string" && placeholder !== "empty" && placeholder.startsWith("data:");
  const blurBackground = resolveBlurBackground(hasBlur, placeholder, blurDataURL);
  const imgStyle = {
    ...style ?? {},
    ...blurBackground ? {
      backgroundImage: blurBackground,
      backgroundPosition: "center",
      backgroundRepeat: "no-repeat",
      backgroundSize: "cover"
    } : {},
    ...fill ? {
      color: "transparent",
      height: "100%",
      inset: 0,
      objectFit: "cover",
      position: "absolute",
      width: "100%"
    } : { color: "transparent" }
  };
  const preloadLink = priority ? /* @__PURE__ */ jsxDEV2("link", {
    as: "image",
    crossOrigin,
    href: resolvedSrc,
    imageSizes: resolvedSizes,
    imageSrcSet: srcSet,
    rel: "preload"
  }, undefined, false, undefined, this) : null;
  const imgElement = /* @__PURE__ */ jsxDEV2("img", {
    alt,
    className,
    crossOrigin,
    decoding: "async",
    fetchPriority: resolvedFetchPriority,
    height: fill ? undefined : height,
    loading: resolvedLoading,
    onError: onError ? (event) => onError(event.nativeEvent) : undefined,
    onLoad: (event) => {
      const { target } = event;
      if (blurBackground && target instanceof HTMLImageElement) {
        target.style.backgroundImage = "none";
      }
      if (onLoad)
        onLoad(event.nativeEvent);
    },
    referrerPolicy,
    sizes: resolvedSizes,
    src: resolvedSrc,
    srcSet,
    style: imgStyle,
    width: fill ? undefined : width
  }, undefined, false, undefined, this);
  if (fill) {
    return /* @__PURE__ */ jsxDEV2(Fragment2, {
      children: [
        preloadLink,
        /* @__PURE__ */ jsxDEV2("span", {
          style: {
            display: "block",
            height: "100%",
            overflow: "hidden",
            position: "relative",
            width: "100%"
          },
          children: imgElement
        }, undefined, false, undefined, this)
      ]
    }, undefined, true, undefined, this);
  }
  return /* @__PURE__ */ jsxDEV2(Fragment2, {
    children: [
      preloadLink,
      imgElement
    ]
  }, undefined, true, undefined, this);
};
// src/react/components/JsonLd.tsx
import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
var JsonLd = ({
  schema
}) => {
  const schemaOrgContext = "https://schema.org";
  const data = Array.isArray(schema) ? schema.map((s) => ({
    "@context": schemaOrgContext,
    ...s
  })) : { "@context": schemaOrgContext, ...schema };
  return /* @__PURE__ */ jsxDEV3("script", {
    dangerouslySetInnerHTML: { __html: JSON.stringify(data) },
    type: "application/ld+json"
  }, undefined, false, undefined, this);
};
// src/core/streamingSlotRegistrar.ts
var STREAMING_SLOT_REGISTRAR_KEY = Symbol.for("absolutejs.streamingSlotRegistrar");
var getRegistrarGlobal = () => globalThis;
var setStreamingSlotRegistrar = (nextRegistrar) => {
  getRegistrarGlobal()[STREAMING_SLOT_REGISTRAR_KEY] = nextRegistrar;
};
var registerStreamingSlot = (slot) => {
  getRegistrarGlobal()[STREAMING_SLOT_REGISTRAR_KEY]?.(slot);
};

// src/react/components/StreamSlot.tsx
import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
var StreamSlot = ({
  className,
  errorHtml,
  fallbackHtml = "",
  id,
  resolve: resolve2,
  timeoutMs
}) => {
  if (typeof window === "undefined") {
    registerStreamingSlot({
      errorHtml,
      fallbackHtml,
      id,
      resolve: resolve2,
      timeoutMs
    });
  }
  return /* @__PURE__ */ jsxDEV4("div", {
    className,
    dangerouslySetInnerHTML: { __html: fallbackHtml },
    "data-absolute-slot": "true",
    id: `slot-${id}`,
    suppressHydrationWarning: true
  }, undefined, false, undefined, this);
};

// src/react/components/SuspenseSlot.tsx
import { jsxDEV as jsxDEV5 } from "react/jsx-dev-runtime";
var SuspenseSlot = (props) => /* @__PURE__ */ jsxDEV5(StreamSlot, {
  ...props
}, undefined, false, undefined, this);
export {
  SuspenseSlot,
  StreamSlot,
  JsonLd,
  Image,
  Head
};

//# debugId=58DE35C17AA4A0D064756E2164756E21
//# sourceMappingURL=index.js.map
