import { H as f } from "../annotorious-core.es-B2-qRuDb.js";
const v = (t) => ({
  parse: (e) => y(),
  serialize: (e) => F(e, t)
}), y = (t) => {
  throw "Not implemented";
}, b = (t) => {
  let e = t[0], a = t[0], o = t[1], n = t[1];
  for (let r = 0; r < t.length; r += 2) {
    const s = t[r], i = t[r + 1];
    e = Math.min(e, s), a = Math.max(a, s), o = Math.min(o, i), n = Math.max(n, i);
  }
  return [
    e,
    // x
    o,
    // y
    a - e,
    // w
    n - o
    // h
  ];
}, F = (t, e) => {
  const { bodies: a, target: o, ...n } = t, {
    selector: r,
    creator: s,
    created: i,
    updated: m,
    ...l
  } = o, w = r.map((g) => {
    const { id: p, quote: u, pageNumber: x, start: h, end: S, quadpoints: c } = g, d = [{
      type: "TextQuoteSelector",
      exact: u
    }, {
      type: "TextPositionSelector",
      start: h,
      end: S
    }];
    if (c) {
      const T = b(c);
      d.push({
        type: "FragmentSelector",
        conformsTo: "http://www.w3.org/TR/media-frags/",
        value: `page=${x}&viewrect=${T.join(",")}`
      });
    }
    return {
      ...l,
      id: p,
      source: e,
      selector: d
    };
  });
  return {
    ...n,
    "@context": "http://www.w3.org/ns/anno.jsonld",
    id: t.id,
    type: "Annotation",
    body: f(t.bodies),
    creator: s,
    created: i?.toISOString(),
    modified: m?.toISOString(),
    target: w
  };
};
export {
  v as W3CTextFormat,
  y as parseW3CPDFAnnotation,
  F as serializeW3CPDFAnnotation
};
//# sourceMappingURL=index.js.map
