@prose-reader/shared 1.233.0 → 1.235.0

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/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export * from './Manifest';
1
+ export * from './array';
2
2
  export * from './contentType';
3
- export * from './url';
4
- export * from './resources';
3
+ export * from './Manifest';
5
4
  export * from './objects';
6
5
  export * from './report';
7
- export * from './array';
6
+ export * from './resources';
7
+ export * from './url';
package/dist/index.js CHANGED
@@ -1,7 +1,4 @@
1
- const s = (e) => {
2
- var n, t;
3
- return ((t = (n = e.split(/[#?]/)[0]) == null ? void 0 : n.split(".").pop()) == null ? void 0 : t.trim()) || "";
4
- };
1
+ const E = (e, n) => e === n ? !0 : e.length !== n.length ? !1 : e.every((t, o) => t === n[o]), s = (e) => e.split(/[#?]/)[0]?.split(".").pop()?.trim() || "";
5
2
  function p(e) {
6
3
  const n = [];
7
4
  if (e.length === 0)
@@ -20,7 +17,7 @@ function p(e) {
20
17
  const o = t.split("?");
21
18
  return t = o.shift() + (o.length > 0 ? "?" : "") + o.join("&"), t;
22
19
  }
23
- function E(...e) {
20
+ function y(...e) {
24
21
  const n = Array.from(Array.isArray(e[0]) ? e[0] : e);
25
22
  return p(n);
26
23
  }
@@ -43,13 +40,10 @@ const f = (e) => {
43
40
  case "xhtml":
44
41
  return "application/xhtml+xml";
45
42
  }
46
- }, y = ({
43
+ }, m = ({
47
44
  mimeType: e,
48
45
  uri: n
49
- }) => {
50
- const t = e ?? f(n ?? "");
51
- return t == null ? void 0 : t.startsWith("application/xhtml+xml");
52
- }, R = (e) => e.length ? e.indexOf(";") ? e.substring(0, e.indexOf(";")) : e : void 0, m = "prose-reader-resource-error", g = Object.prototype.hasOwnProperty, a = (e, n) => e === n ? e !== 0 || n !== 0 || 1 / e === 1 / n : !1, O = (e, n, t) => {
46
+ }) => (e ?? f(n ?? ""))?.startsWith("application/xhtml+xml"), R = (e) => e.length ? e.indexOf(";") ? e.substring(0, e.indexOf(";")) : e : void 0, g = Object.prototype.hasOwnProperty, a = (e, n) => e === n ? e !== 0 || n !== 0 || 1 / e === 1 / n : !1, O = (e, n, t) => {
53
47
  if (e === n)
54
48
  return !0;
55
49
  if (typeof e != "object" || e === null || typeof n != "object" || n === null)
@@ -58,23 +52,23 @@ const f = (e) => {
58
52
  if (o.length !== l.length)
59
53
  return !1;
60
54
  const r = t && typeof t.customEqual == "function" ? t.customEqual : a;
61
- for (let c = 0; c < o.length; c++) {
62
- const i = o[c] || "";
63
- if (!g.call(n, i) || !r(e[i], n[i]))
55
+ for (let i = 0; i < o.length; i++) {
56
+ const c = o[i] || "";
57
+ if (!g.call(n, c) || !r(e[c], n[c]))
64
58
  return !1;
65
59
  }
66
60
  return !0;
67
- }, $ = (e, n) => e.reduce(
61
+ }, _ = (e, n) => e.reduce(
68
62
  (t, o) => {
69
63
  const l = n(o);
70
64
  return t[l] || (t[l] = []), t[l].push(o), t;
71
65
  },
72
66
  {}
73
67
  );
74
- function x(e, n) {
68
+ function $(e, n) {
75
69
  const t = { ...e };
76
70
  for (const o in n)
77
- if (Object.prototype.hasOwnProperty.call(n, o)) {
71
+ if (Object.hasOwn(n, o)) {
78
72
  const l = n[o];
79
73
  (l !== void 0 || !(o in e)) && (t[o] = l);
80
74
  }
@@ -85,8 +79,7 @@ const d = () => {
85
79
  return window;
86
80
  };
87
81
  function h() {
88
- var n;
89
- const e = (n = d()) == null ? void 0 : n.__PROSE_READER_DEBUG;
82
+ const e = d()?.__PROSE_READER_DEBUG;
90
83
  return e === !0 || e === "true";
91
84
  }
92
85
  const u = (e, n = h(), t) => ({
@@ -97,7 +90,7 @@ const u = (e, n = h(), t) => ({
97
90
  console.info,
98
91
  console,
99
92
  `%c${e}`,
100
- t != null && t.color ? `color: ${t.color}` : void 0
93
+ t?.color ? `color: ${t.color}` : void 0
101
94
  ) : Function.prototype.bind.call(console.info, console) : () => {
102
95
  },
103
96
  log: n ? e ? Function.prototype.bind.call(console.log, console, e) : Function.prototype.bind.call(console.log, console) : () => {
@@ -106,23 +99,23 @@ const u = (e, n = h(), t) => ({
106
99
  },
107
100
  error: n ? e ? Function.prototype.bind.call(console.error, console, e) : Function.prototype.bind.call(console.error, console) : () => {
108
101
  }
109
- }), F = {
102
+ }), x = {
110
103
  ...u(),
111
104
  namespace: (e, n, t) => u(e, n, t)
112
- }, b = (e, n) => e === n ? !0 : e.length !== n.length ? !1 : e.every((t, o) => t === n[o]);
105
+ }, F = "prose-reader-resource-error";
113
106
  export {
114
- m as PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME,
115
- F as Report,
116
- b as arrayEqual,
107
+ F as PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME,
108
+ x as Report,
109
+ E as arrayEqual,
117
110
  f as detectMimeTypeFromName,
118
111
  w as getParentPath,
119
112
  s as getUrlExtension,
120
- $ as groupBy,
113
+ _ as groupBy,
121
114
  a as is,
122
115
  O as isShallowEqual,
123
- y as isXmlBasedMimeType,
116
+ m as isXmlBasedMimeType,
124
117
  R as parseContentType,
125
- x as shallowMergeIfDefined,
126
- E as urlJoin
118
+ $ as shallowMergeIfDefined,
119
+ y as urlJoin
127
120
  };
128
121
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/url.ts","../src/contentType.ts","../src/resources.ts","../src/objects.ts","../src/report.ts","../src/array.ts"],"sourcesContent":["export const getUrlExtension = (url: string) => {\n return url.split(/[#?]/)[0]?.split(`.`).pop()?.trim() || ``\n}\n\nfunction normalize(strArray: string[]) {\n const resultArray = []\n if (strArray.length === 0) {\n return \"\"\n }\n\n if (typeof strArray[0] !== \"string\") {\n throw new TypeError(`Url must be a string. Received ${strArray[0]}`)\n }\n\n // If the first part is a plain protocol, we combine it with the next part.\n if (strArray[0].match(/^[^/:]+:\\/*$/) && strArray.length > 1) {\n strArray[0] = strArray.shift() + strArray[0]\n }\n\n // There must be two or three slashes in the file protocol, two slashes in anything else.\n if (strArray[0].match(/^file:\\/\\/\\//)) {\n strArray[0] = strArray[0].replace(/^([^/:]+):\\/*/, \"$1:///\")\n } else {\n strArray[0] = strArray[0].replace(/^([^/:]+):\\/*/, \"$1://\")\n }\n\n for (let i = 0; i < strArray.length; i++) {\n let component = strArray[i]\n\n if (typeof component !== \"string\") {\n throw new TypeError(`Url must be a string. Received ${component}`)\n }\n\n if (component === \"\") {\n continue\n }\n\n if (i > 0) {\n // Removing the starting slashes for each component but the first.\n component = component.replace(/^[/]+/, \"\")\n }\n if (i < strArray.length - 1) {\n // Removing the ending slashes for each component but the last.\n component = component.replace(/[/]+$/, \"\")\n } else {\n // For the last component we will combine multiple slashes to a single one.\n component = component.replace(/[/]+$/, \"/\")\n }\n\n resultArray.push(component)\n }\n\n let str = resultArray.join(\"/\")\n // Each input component is now separated by a single slash except the possible first plain protocol part.\n\n // remove trailing slash before parameters or hash\n str = str.replace(/\\/(\\?|&|#[^!])/g, \"$1\")\n\n // replace ? in parameters with &\n const parts = str.split(\"?\")\n str = parts.shift() + (parts.length > 0 ? \"?\" : \"\") + parts.join(\"&\")\n\n return str\n}\n\nexport function urlJoin(...args: (string | string[])[]) {\n const parts = Array.from(Array.isArray(args[0]) ? args[0] : args) as string[]\n\n return normalize(parts)\n}\n\nexport function getParentPath(uri: string): string {\n const parts = uri.split(\"/\")\n\n parts.pop() // Remove the last segment\n\n return parts.join(\"/\")\n}\n","import { getUrlExtension } from \"./url\"\n\nexport const detectMimeTypeFromName = (name: string) => {\n const extension = getUrlExtension(name)\n\n switch (extension) {\n case `png`:\n return `image/png`\n case `jpg`:\n return `image/jpg`\n case `jpeg`:\n return `image/jpeg`\n case `txt`:\n return `text/plain`\n case `webp`:\n return `image/webp`\n case `xhtml`:\n return `application/xhtml+xml`\n }\n\n return undefined\n}\n\nexport const isXmlBasedMimeType = ({\n mimeType,\n uri,\n}: { uri?: string; mimeType?: string }) => {\n const _mimeType = mimeType ?? detectMimeTypeFromName(uri ?? \"\")\n\n return _mimeType?.startsWith(`application/xhtml+xml`)\n}\n\nexport const parseContentType = (str: string) => {\n if (!str.length) return undefined\n\n const cut = str.indexOf(`;`)\n\n return cut ? str.substring(0, str.indexOf(`;`)) : str\n}\n","export const PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME =\n \"prose-reader-resource-error\"\n","// MIT © 2017 azu\nconst hasOwn = Object.prototype.hasOwnProperty\n\n// Object.is polyfill\n// biome-ignore lint/suspicious/noExplicitAny: TODO\nexport const is = (x: any, y: any): boolean => {\n if (x === y) {\n return x !== 0 || y !== 0 || 1 / x === 1 / y\n }\n return false\n}\n\n/**\n * Return true, if `objectA` is shallow equal to `objectB`.\n * Pass Custom equality function to `customEqual`.\n * Default equality is `Object.is`\n * Support Array\n *\n * Options:\n *\n * - `customEqual`: function should return true if the `a` value is equal to `b` value.\n * - `debug`: enable debug info to console log. This log will be disable in production build\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: TODO\nexport const isShallowEqual = <T = any, R = any>(\n objectA: T,\n objectB: R,\n options?: {\n customEqual?: <T>(a: T, b: T) => boolean\n },\n): boolean => {\n // @ts-ignore\n if (objectA === objectB) {\n return true\n }\n if (typeof objectA !== \"object\" || objectA === null) {\n return false\n }\n if (typeof objectB !== \"object\" || objectB === null) {\n return false\n }\n\n const keysA = Object.keys(objectA)\n const keysB = Object.keys(objectB)\n\n if (keysA.length !== keysB.length) {\n return false\n }\n\n const isEqual =\n options && typeof options.customEqual === \"function\"\n ? options.customEqual\n : is\n\n for (let i = 0; i < keysA.length; i++) {\n const key = keysA[i] || ``\n // @ts-ignore\n if (!hasOwn.call(objectB, key) || !isEqual(objectA[key], objectB[key])) {\n return false\n }\n }\n\n return true\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: TODO\nexport const groupBy = <T, K extends keyof any>(\n list: T[],\n getKey: (item: T) => K,\n) =>\n list.reduce(\n (previous, currentItem) => {\n const group = getKey(currentItem)\n if (!previous[group]) previous[group] = []\n previous[group].push(currentItem)\n return previous\n },\n {} as Record<K, T[]>,\n )\n\nexport function shallowMergeIfDefined<T, U>(obj1: T, obj2: U): T & U {\n const result = { ...obj1 } as T & U\n\n for (const key in obj2) {\n if (Object.prototype.hasOwnProperty.call(obj2, key)) {\n // biome-ignore lint/suspicious/noExplicitAny: TODO\n const value = (obj2 as any)[key]\n // @ts-ignore\n if (value !== undefined || !(key in obj1)) {\n // biome-ignore lint/suspicious/noExplicitAny: TODO\n ;(result as any)[key] = value\n }\n }\n }\n\n return result\n}\n","declare global {\n interface Window {\n __PROSE_READER_DEBUG?: boolean | string\n }\n}\n\nconst getWindow = () => {\n if (typeof window === \"undefined\") {\n return undefined\n }\n\n return window\n}\n\nfunction isGlobalDebugEnabled() {\n const debug = getWindow()?.__PROSE_READER_DEBUG\n\n return debug === true || debug === \"true\"\n}\n\ntype Report = {\n namespace: (namespace: string, enabled?: boolean) => Report\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n debug: (...args: any[]) => void\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n info: (...args: any[]) => void\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n log: (...args: any[]) => void\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n warn: (...args: any[]) => void\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n error: (...args: any[]) => void\n}\n\nconst createReport = (\n namespace?: string,\n enabled = isGlobalDebugEnabled(),\n options?: {\n color?: string\n },\n): Report => {\n return {\n namespace: (_namespace: string, enabled?: boolean) =>\n createReport(`[${namespace}] [${_namespace}]`, enabled, options),\n debug: !enabled\n ? () => {}\n : namespace\n ? Function.prototype.bind.call(console.debug, console, namespace)\n : Function.prototype.bind.call(console.debug, console),\n info: !enabled\n ? () => {}\n : namespace\n ? Function.prototype.bind.call(\n console.info,\n console,\n `%c${namespace}`,\n options?.color ? `color: ${options.color}` : undefined,\n )\n : Function.prototype.bind.call(console.info, console),\n log: !enabled\n ? () => {}\n : namespace\n ? Function.prototype.bind.call(console.log, console, namespace)\n : Function.prototype.bind.call(console.log, console),\n warn: !enabled\n ? () => {}\n : namespace\n ? Function.prototype.bind.call(console.warn, console, namespace)\n : Function.prototype.bind.call(console.warn, console),\n error: !enabled\n ? () => {}\n : namespace\n ? Function.prototype.bind.call(console.error, console, namespace)\n : Function.prototype.bind.call(console.error, console),\n }\n}\n\nexport const Report = {\n ...createReport(),\n namespace: (\n namespace: string,\n enabled?: boolean,\n options?: {\n color?: string\n },\n ) => createReport(namespace, enabled, options),\n}\n","// biome-ignore lint/suspicious/noExplicitAny: TODO\nexport const arrayEqual = <A extends any[], B extends any[]>(a: A, b: B) => {\n // @ts-expect-error\n if (a === b) return true\n if (a.length !== b.length) return false\n\n return a.every((v, i) => v === b[i])\n}\n"],"names":["getUrlExtension","url","_a","_b","normalize","strArray","resultArray","i","component","str","parts","urlJoin","args","getParentPath","uri","detectMimeTypeFromName","name","isXmlBasedMimeType","mimeType","_mimeType","parseContentType","PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME","hasOwn","is","x","y","isShallowEqual","objectA","objectB","options","keysA","keysB","isEqual","key","groupBy","list","getKey","previous","currentItem","group","shallowMergeIfDefined","obj1","obj2","result","value","getWindow","isGlobalDebugEnabled","debug","createReport","namespace","enabled","_namespace","Report","arrayEqual","a","b","v"],"mappings":"AAAO,MAAMA,IAAkB,CAACC,MAAgB;AAAzC,MAAAC,GAAAC;AACL,WAAOA,KAAAD,IAAAD,EAAI,MAAM,MAAM,EAAE,CAAC,MAAnB,gBAAAC,EAAsB,MAAM,KAAK,UAAjC,gBAAAC,EAAwC,WAAU;AAC3D;AAEA,SAASC,EAAUC,GAAoB;AACrC,QAAMC,IAAc,CAAA;AACpB,MAAID,EAAS,WAAW;AACtB,WAAO;AAGT,MAAI,OAAOA,EAAS,CAAC,KAAM;AACzB,UAAM,IAAI,UAAU,kCAAkCA,EAAS,CAAC,CAAC,EAAE;AAIrE,EAAIA,EAAS,CAAC,EAAE,MAAM,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pD,MAAM;AAAA,EAAA;AAAA,EASV,KAAMqB,IAEFD,IACE,SAAS,UAAU,KAAK,KAAK,QAAQ,KAAK,SAASA,CAAS,IAC5D,SAAS,UAAU,KAAK,KAAK,QAAQ,KAAK,OAAO,IAHnD,MAAM;AAAA,EAAA;AAAA,EAIV,MAAOC,IAEHD,IACE,SAAS,UAAU,KAAK,KAAK,QAAQ,MAAM,SAASA,CAAS,IAC7D,SAAS,UAAU,KAAK,KAAK,QAAQ,MAAM,OAAO,IAHpD,MAAM;AAAA,EAAA;AAAA,EAIV,OAAQC,IAEJD,IACE,SAAS,UAAU,KAAK,KAAK,QAAQ,OAAO,SAASA,CAAS,IAC9D,SAAS,UAAU,KAAK,KAAK,QAAQ,OAAO,OAAO,IAHrD,MAAM;AAAA,EAAA;AAG+C,IAIhDG,IAAS;AAAA,EACpB,GAAGJ,EAAA;AAAA,EACH,WAAW,CACTC,GACAC,GACArB,MAGGmB,EAAaC,GAAWC,GAASrB,CAAO;AAC/C,GCrFawB,IAAa,CAAmCC,GAAMC,MAE7DD,MAAMC,IAAU,KAChBD,EAAE,WAAWC,EAAE,SAAe,KAE3BD,EAAE,MAAM,CAACE,GAAGjD,MAAMiD,MAAMD,EAAEhD,CAAC,CAAC;"}
1
+ {"version":3,"file":"index.js","sources":["../src/array.ts","../src/url.ts","../src/contentType.ts","../src/objects.ts","../src/report.ts","../src/resources.ts"],"sourcesContent":["// biome-ignore lint/suspicious/noExplicitAny: TODO\nexport const arrayEqual = <A extends any[], B extends any[]>(a: A, b: B) => {\n // @ts-expect-error\n if (a === b) return true\n if (a.length !== b.length) return false\n\n return a.every((v, i) => v === b[i])\n}\n","export const getUrlExtension = (url: string) => {\n return url.split(/[#?]/)[0]?.split(`.`).pop()?.trim() || ``\n}\n\nfunction normalize(strArray: string[]) {\n const resultArray = []\n if (strArray.length === 0) {\n return \"\"\n }\n\n if (typeof strArray[0] !== \"string\") {\n throw new TypeError(`Url must be a string. Received ${strArray[0]}`)\n }\n\n // If the first part is a plain protocol, we combine it with the next part.\n if (strArray[0].match(/^[^/:]+:\\/*$/) && strArray.length > 1) {\n strArray[0] = strArray.shift() + strArray[0]\n }\n\n // There must be two or three slashes in the file protocol, two slashes in anything else.\n if (strArray[0].match(/^file:\\/\\/\\//)) {\n strArray[0] = strArray[0].replace(/^([^/:]+):\\/*/, \"$1:///\")\n } else {\n strArray[0] = strArray[0].replace(/^([^/:]+):\\/*/, \"$1://\")\n }\n\n for (let i = 0; i < strArray.length; i++) {\n let component = strArray[i]\n\n if (typeof component !== \"string\") {\n throw new TypeError(`Url must be a string. Received ${component}`)\n }\n\n if (component === \"\") {\n continue\n }\n\n if (i > 0) {\n // Removing the starting slashes for each component but the first.\n component = component.replace(/^[/]+/, \"\")\n }\n if (i < strArray.length - 1) {\n // Removing the ending slashes for each component but the last.\n component = component.replace(/[/]+$/, \"\")\n } else {\n // For the last component we will combine multiple slashes to a single one.\n component = component.replace(/[/]+$/, \"/\")\n }\n\n resultArray.push(component)\n }\n\n let str = resultArray.join(\"/\")\n // Each input component is now separated by a single slash except the possible first plain protocol part.\n\n // remove trailing slash before parameters or hash\n str = str.replace(/\\/(\\?|&|#[^!])/g, \"$1\")\n\n // replace ? in parameters with &\n const parts = str.split(\"?\")\n str = parts.shift() + (parts.length > 0 ? \"?\" : \"\") + parts.join(\"&\")\n\n return str\n}\n\nexport function urlJoin(...args: (string | string[])[]) {\n const parts = Array.from(Array.isArray(args[0]) ? args[0] : args) as string[]\n\n return normalize(parts)\n}\n\nexport function getParentPath(uri: string): string {\n const parts = uri.split(\"/\")\n\n parts.pop() // Remove the last segment\n\n return parts.join(\"/\")\n}\n","import { getUrlExtension } from \"./url\"\n\nexport const detectMimeTypeFromName = (name: string) => {\n const extension = getUrlExtension(name)\n\n switch (extension) {\n case `png`:\n return `image/png`\n case `jpg`:\n return `image/jpg`\n case `jpeg`:\n return `image/jpeg`\n case `txt`:\n return `text/plain`\n case `webp`:\n return `image/webp`\n case `xhtml`:\n return `application/xhtml+xml`\n }\n\n return undefined\n}\n\nexport const isXmlBasedMimeType = ({\n mimeType,\n uri,\n}: {\n uri?: string\n mimeType?: string\n}) => {\n const _mimeType = mimeType ?? detectMimeTypeFromName(uri ?? \"\")\n\n return _mimeType?.startsWith(`application/xhtml+xml`)\n}\n\nexport const parseContentType = (str: string) => {\n if (!str.length) return undefined\n\n const cut = str.indexOf(`;`)\n\n return cut ? str.substring(0, str.indexOf(`;`)) : str\n}\n","// MIT © 2017 azu\nconst hasOwn = Object.prototype.hasOwnProperty\n\n// Object.is polyfill\n// biome-ignore lint/suspicious/noExplicitAny: TODO\nexport const is = (x: any, y: any): boolean => {\n if (x === y) {\n return x !== 0 || y !== 0 || 1 / x === 1 / y\n }\n return false\n}\n\n/**\n * Return true, if `objectA` is shallow equal to `objectB`.\n * Pass Custom equality function to `customEqual`.\n * Default equality is `Object.is`\n * Support Array\n *\n * Options:\n *\n * - `customEqual`: function should return true if the `a` value is equal to `b` value.\n * - `debug`: enable debug info to console log. This log will be disable in production build\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: TODO\nexport const isShallowEqual = <T = any, R = any>(\n objectA: T,\n objectB: R,\n options?: {\n customEqual?: <T>(a: T, b: T) => boolean\n },\n): boolean => {\n // @ts-ignore\n if (objectA === objectB) {\n return true\n }\n if (typeof objectA !== \"object\" || objectA === null) {\n return false\n }\n if (typeof objectB !== \"object\" || objectB === null) {\n return false\n }\n\n const keysA = Object.keys(objectA)\n const keysB = Object.keys(objectB)\n\n if (keysA.length !== keysB.length) {\n return false\n }\n\n const isEqual =\n options && typeof options.customEqual === \"function\"\n ? options.customEqual\n : is\n\n for (let i = 0; i < keysA.length; i++) {\n const key = keysA[i] || ``\n // @ts-ignore\n if (!hasOwn.call(objectB, key) || !isEqual(objectA[key], objectB[key])) {\n return false\n }\n }\n\n return true\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: TODO\nexport const groupBy = <T, K extends keyof any>(\n list: T[],\n getKey: (item: T) => K,\n) =>\n list.reduce(\n (previous, currentItem) => {\n const group = getKey(currentItem)\n if (!previous[group]) previous[group] = []\n previous[group].push(currentItem)\n return previous\n },\n {} as Record<K, T[]>,\n )\n\nexport function shallowMergeIfDefined<T extends object, U extends object>(\n obj1: T,\n obj2: U,\n): T & U {\n const result = { ...obj1 } as T & U\n\n for (const key in obj2) {\n if (Object.hasOwn(obj2, key)) {\n // biome-ignore lint/suspicious/noExplicitAny: TODO\n const value = (obj2 as any)[key]\n if (value !== undefined || !(key in obj1)) {\n // biome-ignore lint/suspicious/noExplicitAny: TODO\n ;(result as any)[key] = value\n }\n }\n }\n\n return result\n}\n","declare global {\n interface Window {\n __PROSE_READER_DEBUG?: boolean | string\n }\n}\n\nconst getWindow = () => {\n if (typeof window === \"undefined\") {\n return undefined\n }\n\n return window\n}\n\nfunction isGlobalDebugEnabled() {\n const debug = getWindow()?.__PROSE_READER_DEBUG\n\n return debug === true || debug === \"true\"\n}\n\nexport type Report = {\n namespace: (namespace: string, enabled?: boolean) => Report\n // biome-ignore lint/suspicious/noExplicitAny: TODO\n debug: (...args: any[]) => void\n // biome-ignore lint/suspicious/noExplicitAny: TODO\n info: (...args: any[]) => void\n // biome-ignore lint/suspicious/noExplicitAny: TODO\n log: (...args: any[]) => void\n // biome-ignore lint/suspicious/noExplicitAny: TODO\n warn: (...args: any[]) => void\n // biome-ignore lint/suspicious/noExplicitAny: TODO\n error: (...args: any[]) => void\n}\n\nconst createReport = (\n namespace?: string,\n enabled = isGlobalDebugEnabled(),\n options?: {\n color?: string\n },\n): Report => {\n return {\n namespace: (_namespace: string, enabled?: boolean) =>\n createReport(`[${namespace}] [${_namespace}]`, enabled, options),\n debug: !enabled\n ? () => {}\n : namespace\n ? Function.prototype.bind.call(console.debug, console, namespace)\n : Function.prototype.bind.call(console.debug, console),\n info: !enabled\n ? () => {}\n : namespace\n ? Function.prototype.bind.call(\n console.info,\n console,\n `%c${namespace}`,\n options?.color ? `color: ${options.color}` : undefined,\n )\n : Function.prototype.bind.call(console.info, console),\n log: !enabled\n ? () => {}\n : namespace\n ? Function.prototype.bind.call(console.log, console, namespace)\n : Function.prototype.bind.call(console.log, console),\n warn: !enabled\n ? () => {}\n : namespace\n ? Function.prototype.bind.call(console.warn, console, namespace)\n : Function.prototype.bind.call(console.warn, console),\n error: !enabled\n ? () => {}\n : namespace\n ? Function.prototype.bind.call(console.error, console, namespace)\n : Function.prototype.bind.call(console.error, console),\n }\n}\n\nexport const Report = {\n ...createReport(),\n namespace: (\n namespace: string,\n enabled?: boolean,\n options?: {\n color?: string\n },\n ) => createReport(namespace, enabled, options),\n}\n","export const PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME =\n \"prose-reader-resource-error\"\n"],"names":["arrayEqual","a","b","v","i","getUrlExtension","url","normalize","strArray","resultArray","component","str","parts","urlJoin","args","getParentPath","uri","detectMimeTypeFromName","name","isXmlBasedMimeType","mimeType","parseContentType","hasOwn","is","x","y","isShallowEqual","objectA","objectB","options","keysA","keysB","isEqual","key","groupBy","list","getKey","previous","currentItem","group","shallowMergeIfDefined","obj1","obj2","result","value","getWindow","isGlobalDebugEnabled","debug","createReport","namespace","enabled","_namespace","Report","PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME"],"mappings":"AACO,MAAMA,IAAa,CAAmCC,GAAMC,MAE7DD,MAAMC,IAAU,KAChBD,EAAE,WAAWC,EAAE,SAAe,KAE3BD,EAAE,MAAM,CAACE,GAAGC,MAAMD,MAAMD,EAAEE,CAAC,CAAC,GCNxBC,IAAkB,CAACC,MACvBA,EAAI,MAAM,MAAM,EAAE,CAAC,GAAG,MAAM,GAAG,EAAE,IAAA,GAAO,KAAA,KAAU;AAG3D,SAASC,EAAUC,GAAoB;AACrC,QAAMC,IAAc,CAAA;AACpB,MAAID,EAAS,WAAW;AACtB,WAAO;AAGT,MAAI,OAAOA,EAAS,CAAC,KAAM;AACzB,UAAM,IAAI,UAAU,kCAAkCA,EAAS,CAAC,CAAC,EAAE;AAIrE,EAAIA,E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U,KAAK,KAAK,QAAQ,KAAK,OAAO,IAHnD,MAAM;AAAA,EAAA;AAAA,EAIV,MAAOC,IAEHD,IACE,SAAS,UAAU,KAAK,KAAK,QAAQ,MAAM,SAASA,CAAS,IAC7D,SAAS,UAAU,KAAK,KAAK,QAAQ,MAAM,OAAO,IAHpD,MAAM;AAAA,EAAA;AAAA,EAIV,OAAQC,IAEJD,IACE,SAAS,UAAU,KAAK,KAAK,QAAQ,OAAO,SAASA,CAAS,IAC9D,SAAS,UAAU,KAAK,KAAK,QAAQ,OAAO,OAAO,IAHrD,MAAM;AAAA,EAAA;AAG+C,IAIhDG,IAAS;AAAA,EACpB,GAAGJ,EAAA;AAAA,EACH,WAAW,CACTC,GACAC,GACArB,MAGGmB,EAAaC,GAAWC,GAASrB,CAAO;AAC/C,GCtFawB,IACX;"}
@@ -1,2 +1,2 @@
1
- (function(l,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(l=typeof globalThis<"u"?globalThis:l||self,c(l["prose-shared"]={}))})(this,function(l){"use strict";const c=e=>{var n,t;return((t=(n=e.split(/[#?]/)[0])==null?void 0:n.split(".").pop())==null?void 0:t.trim())||""};function d(e){const n=[];if(e.length===0)return"";if(typeof e[0]!="string")throw new TypeError(`Url must be a string. Received ${e[0]}`);e[0].match(/^[^/:]+:\/*$/)&&e.length>1&&(e[0]=e.shift()+e[0]),e[0].match(/^file:\/\/\//)?e[0]=e[0].replace(/^([^/:]+):\/*/,"$1:///"):e[0]=e[0].replace(/^([^/:]+):\/*/,"$1://");for(let i=0;i<e.length;i++){let r=e[i];if(typeof r!="string")throw new TypeError(`Url must be a string. Received ${r}`);r!==""&&(i>0&&(r=r.replace(/^[/]+/,"")),i<e.length-1?r=r.replace(/[/]+$/,""):r=r.replace(/[/]+$/,"/"),n.push(r))}let t=n.join("/");t=t.replace(/\/(\?|&|#[^!])/g,"$1");const o=t.split("?");return t=o.shift()+(o.length>0?"?":"")+o.join("&"),t}function g(...e){const n=Array.from(Array.isArray(e[0])?e[0]:e);return d(n)}function h(e){const n=e.split("/");return n.pop(),n.join("/")}const p=e=>{switch(c(e)){case"png":return"image/png";case"jpg":return"image/jpg";case"jpeg":return"image/jpeg";case"txt":return"text/plain";case"webp":return"image/webp";case"xhtml":return"application/xhtml+xml"}},E=({mimeType:e,uri:n})=>{const t=e??p(n??"");return t==null?void 0:t.startsWith("application/xhtml+xml")},y=e=>e.length?e.indexOf(";")?e.substring(0,e.indexOf(";")):e:void 0,R="prose-reader-resource-error",w=Object.prototype.hasOwnProperty,a=(e,n)=>e===n?e!==0||n!==0||1/e===1/n:!1,m=(e,n,t)=>{if(e===n)return!0;if(typeof e!="object"||e===null||typeof n!="object"||n===null)return!1;const o=Object.keys(e),i=Object.keys(n);if(o.length!==i.length)return!1;const r=t&&typeof t.customEqual=="function"?t.customEqual:a;for(let s=0;s<o.length;s++){const f=o[s]||"";if(!w.call(n,f)||!r(e[f],n[f]))return!1}return!0},O=(e,n)=>e.reduce((t,o)=>{const i=n(o);return t[i]||(t[i]=[]),t[i].push(o),t},{});function _(e,n){const t={...e};for(const o in n)if(Object.prototype.hasOwnProperty.call(n,o)){const i=n[o];(i!==void 0||!(o in e))&&(t[o]=i)}return t}const T=()=>{if(!(typeof window>"u"))return window};function b(){var n;const e=(n=T())==null?void 0:n.__PROSE_READER_DEBUG;return e===!0||e==="true"}const u=(e,n=b(),t)=>({namespace:(o,i)=>u(`[${e}] [${o}]`,i,t),debug:n?e?Function.prototype.bind.call(console.debug,console,e):Function.prototype.bind.call(console.debug,console):()=>{},info:n?e?Function.prototype.bind.call(console.info,console,`%c${e}`,t!=null&&t.color?`color: ${t.color}`:void 0):Function.prototype.bind.call(console.info,console):()=>{},log:n?e?Function.prototype.bind.call(console.log,console,e):Function.prototype.bind.call(console.log,console):()=>{},warn:n?e?Function.prototype.bind.call(console.warn,console,e):Function.prototype.bind.call(console.warn,console):()=>{},error:n?e?Function.prototype.bind.call(console.error,console,e):Function.prototype.bind.call(console.error,console):()=>{}}),F={...u(),namespace:(e,n,t)=>u(e,n,t)},$=(e,n)=>e===n?!0:e.length!==n.length?!1:e.every((t,o)=>t===n[o]);l.PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME=R,l.Report=F,l.arrayEqual=$,l.detectMimeTypeFromName=p,l.getParentPath=h,l.getUrlExtension=c,l.groupBy=O,l.is=a,l.isShallowEqual=m,l.isXmlBasedMimeType=E,l.parseContentType=y,l.shallowMergeIfDefined=_,l.urlJoin=g,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
1
+ (function(i,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(i=typeof globalThis<"u"?globalThis:i||self,c(i["prose-shared"]={}))})(this,function(i){"use strict";const c=(e,n)=>e===n?!0:e.length!==n.length?!1:e.every((t,o)=>t===n[o]),p=e=>e.split(/[#?]/)[0]?.split(".").pop()?.trim()||"";function g(e){const n=[];if(e.length===0)return"";if(typeof e[0]!="string")throw new TypeError(`Url must be a string. Received ${e[0]}`);e[0].match(/^[^/:]+:\/*$/)&&e.length>1&&(e[0]=e.shift()+e[0]),e[0].match(/^file:\/\/\//)?e[0]=e[0].replace(/^([^/:]+):\/*/,"$1:///"):e[0]=e[0].replace(/^([^/:]+):\/*/,"$1://");for(let l=0;l<e.length;l++){let r=e[l];if(typeof r!="string")throw new TypeError(`Url must be a string. Received ${r}`);r!==""&&(l>0&&(r=r.replace(/^[/]+/,"")),l<e.length-1?r=r.replace(/[/]+$/,""):r=r.replace(/[/]+$/,"/"),n.push(r))}let t=n.join("/");t=t.replace(/\/(\?|&|#[^!])/g,"$1");const o=t.split("?");return t=o.shift()+(o.length>0?"?":"")+o.join("&"),t}function h(...e){const n=Array.from(Array.isArray(e[0])?e[0]:e);return g(n)}function E(e){const n=e.split("/");return n.pop(),n.join("/")}const a=e=>{switch(p(e)){case"png":return"image/png";case"jpg":return"image/jpg";case"jpeg":return"image/jpeg";case"txt":return"text/plain";case"webp":return"image/webp";case"xhtml":return"application/xhtml+xml"}},y=({mimeType:e,uri:n})=>(e??a(n??""))?.startsWith("application/xhtml+xml"),m=e=>e.length?e.indexOf(";")?e.substring(0,e.indexOf(";")):e:void 0,R=Object.prototype.hasOwnProperty,d=(e,n)=>e===n?e!==0||n!==0||1/e===1/n:!1,w=(e,n,t)=>{if(e===n)return!0;if(typeof e!="object"||e===null||typeof n!="object"||n===null)return!1;const o=Object.keys(e),l=Object.keys(n);if(o.length!==l.length)return!1;const r=t&&typeof t.customEqual=="function"?t.customEqual:d;for(let s=0;s<o.length;s++){const f=o[s]||"";if(!R.call(n,f)||!r(e[f],n[f]))return!1}return!0},_=(e,n)=>e.reduce((t,o)=>{const l=n(o);return t[l]||(t[l]=[]),t[l].push(o),t},{});function O(e,n){const t={...e};for(const o in n)if(Object.hasOwn(n,o)){const l=n[o];(l!==void 0||!(o in e))&&(t[o]=l)}return t}const T=()=>{if(!(typeof window>"u"))return window};function b(){const e=T()?.__PROSE_READER_DEBUG;return e===!0||e==="true"}const u=(e,n=b(),t)=>({namespace:(o,l)=>u(`[${e}] [${o}]`,l,t),debug:n?e?Function.prototype.bind.call(console.debug,console,e):Function.prototype.bind.call(console.debug,console):()=>{},info:n?e?Function.prototype.bind.call(console.info,console,`%c${e}`,t?.color?`color: ${t.color}`:void 0):Function.prototype.bind.call(console.info,console):()=>{},log:n?e?Function.prototype.bind.call(console.log,console,e):Function.prototype.bind.call(console.log,console):()=>{},warn:n?e?Function.prototype.bind.call(console.warn,console,e):Function.prototype.bind.call(console.warn,console):()=>{},error:n?e?Function.prototype.bind.call(console.error,console,e):Function.prototype.bind.call(console.error,console):()=>{}}),F={...u(),namespace:(e,n,t)=>u(e,n,t)},$="prose-reader-resource-error";i.PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME=$,i.Report=F,i.arrayEqual=c,i.detectMimeTypeFromName=a,i.getParentPath=E,i.getUrlExtension=p,i.groupBy=_,i.is=d,i.isShallowEqual=w,i.isXmlBasedMimeType=y,i.parseContentType=m,i.shallowMergeIfDefined=O,i.urlJoin=h,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
2
2
  //# sourceMappingURL=index.umd.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.cjs","sources":["../src/url.ts","../src/contentType.ts","../src/resources.ts","../src/objects.ts","../src/report.ts","../src/array.ts"],"sourcesContent":["export const getUrlExtension = (url: string) => {\n return url.split(/[#?]/)[0]?.split(`.`).pop()?.trim() || ``\n}\n\nfunction normalize(strArray: string[]) {\n const resultArray = []\n if (strArray.length === 0) {\n return \"\"\n }\n\n if (typeof strArray[0] !== \"string\") {\n throw new TypeError(`Url must be a string. Received ${strArray[0]}`)\n }\n\n // If the first part is a plain protocol, we combine it with the next part.\n if (strArray[0].match(/^[^/:]+:\\/*$/) && strArray.length > 1) {\n strArray[0] = strArray.shift() + strArray[0]\n }\n\n // There must be two or three slashes in the file protocol, two slashes in anything else.\n if (strArray[0].match(/^file:\\/\\/\\//)) {\n strArray[0] = strArray[0].replace(/^([^/:]+):\\/*/, \"$1:///\")\n } else {\n strArray[0] = strArray[0].replace(/^([^/:]+):\\/*/, \"$1://\")\n }\n\n for (let i = 0; i < strArray.length; i++) {\n let component = strArray[i]\n\n if (typeof component !== \"string\") {\n throw new TypeError(`Url must be a string. Received ${component}`)\n }\n\n if (component === \"\") {\n continue\n }\n\n if (i > 0) {\n // Removing the starting slashes for each component but the first.\n component = component.replace(/^[/]+/, \"\")\n }\n if (i < strArray.length - 1) {\n // Removing the ending slashes for each component but the last.\n component = component.replace(/[/]+$/, \"\")\n } else {\n // For the last component we will combine multiple slashes to a single one.\n component = component.replace(/[/]+$/, \"/\")\n }\n\n resultArray.push(component)\n }\n\n let str = resultArray.join(\"/\")\n // Each input component is now separated by a single slash except the possible first plain protocol part.\n\n // remove trailing slash before parameters or hash\n str = str.replace(/\\/(\\?|&|#[^!])/g, \"$1\")\n\n // replace ? in parameters with &\n const parts = str.split(\"?\")\n str = parts.shift() + (parts.length > 0 ? \"?\" : \"\") + parts.join(\"&\")\n\n return str\n}\n\nexport function urlJoin(...args: (string | string[])[]) {\n const parts = Array.from(Array.isArray(args[0]) ? args[0] : args) as string[]\n\n return normalize(parts)\n}\n\nexport function getParentPath(uri: string): string {\n const parts = uri.split(\"/\")\n\n parts.pop() // Remove the last segment\n\n return parts.join(\"/\")\n}\n","import { getUrlExtension } from \"./url\"\n\nexport const detectMimeTypeFromName = (name: string) => {\n const extension = getUrlExtension(name)\n\n switch (extension) {\n case `png`:\n return `image/png`\n case `jpg`:\n return `image/jpg`\n case `jpeg`:\n return `image/jpeg`\n case `txt`:\n return `text/plain`\n case `webp`:\n return `image/webp`\n case `xhtml`:\n return `application/xhtml+xml`\n }\n\n return undefined\n}\n\nexport const isXmlBasedMimeType = ({\n mimeType,\n uri,\n}: { uri?: string; mimeType?: string }) => {\n const _mimeType = mimeType ?? detectMimeTypeFromName(uri ?? \"\")\n\n return _mimeType?.startsWith(`application/xhtml+xml`)\n}\n\nexport const parseContentType = (str: string) => {\n if (!str.length) return undefined\n\n const cut = str.indexOf(`;`)\n\n return cut ? str.substring(0, str.indexOf(`;`)) : str\n}\n","export const PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME =\n \"prose-reader-resource-error\"\n","// MIT © 2017 azu\nconst hasOwn = Object.prototype.hasOwnProperty\n\n// Object.is polyfill\n// biome-ignore lint/suspicious/noExplicitAny: TODO\nexport const is = (x: any, y: any): boolean => {\n if (x === y) {\n return x !== 0 || y !== 0 || 1 / x === 1 / y\n }\n return false\n}\n\n/**\n * Return true, if `objectA` is shallow equal to `objectB`.\n * Pass Custom equality function to `customEqual`.\n * Default equality is `Object.is`\n * Support Array\n *\n * Options:\n *\n * - `customEqual`: function should return true if the `a` value is equal to `b` value.\n * - `debug`: enable debug info to console log. This log will be disable in production build\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: TODO\nexport const isShallowEqual = <T = any, R = any>(\n objectA: T,\n objectB: R,\n options?: {\n customEqual?: <T>(a: T, b: T) => boolean\n },\n): boolean => {\n // @ts-ignore\n if (objectA === objectB) {\n return true\n }\n if (typeof objectA !== \"object\" || objectA === null) {\n return false\n }\n if (typeof objectB !== \"object\" || objectB === null) {\n return false\n }\n\n const keysA = Object.keys(objectA)\n const keysB = Object.keys(objectB)\n\n if (keysA.length !== keysB.length) {\n return false\n }\n\n const isEqual =\n options && typeof options.customEqual === \"function\"\n ? options.customEqual\n : is\n\n for (let i = 0; i < keysA.length; i++) {\n const key = keysA[i] || ``\n // @ts-ignore\n if (!hasOwn.call(objectB, key) || !isEqual(objectA[key], objectB[key])) {\n return false\n }\n }\n\n return true\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: TODO\nexport const groupBy = <T, K extends keyof any>(\n list: T[],\n getKey: (item: T) => K,\n) =>\n list.reduce(\n (previous, currentItem) => {\n const group = getKey(currentItem)\n if (!previous[group]) previous[group] = []\n previous[group].push(currentItem)\n return previous\n },\n {} as Record<K, T[]>,\n )\n\nexport function shallowMergeIfDefined<T, U>(obj1: T, obj2: U): T & U {\n const result = { ...obj1 } as T & U\n\n for (const key in obj2) {\n if (Object.prototype.hasOwnProperty.call(obj2, key)) {\n // biome-ignore lint/suspicious/noExplicitAny: TODO\n const value = (obj2 as any)[key]\n // @ts-ignore\n if (value !== undefined || !(key in obj1)) {\n // biome-ignore lint/suspicious/noExplicitAny: TODO\n ;(result as any)[key] = value\n }\n }\n }\n\n return result\n}\n","declare global {\n interface Window {\n __PROSE_READER_DEBUG?: boolean | string\n }\n}\n\nconst getWindow = () => {\n if (typeof window === \"undefined\") {\n return undefined\n }\n\n return window\n}\n\nfunction isGlobalDebugEnabled() {\n const debug = getWindow()?.__PROSE_READER_DEBUG\n\n return debug === true || debug === \"true\"\n}\n\ntype Report = {\n namespace: (namespace: string, enabled?: boolean) => Report\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n debug: (...args: any[]) => void\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n info: (...args: any[]) => void\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n log: (...args: any[]) => void\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n warn: (...args: any[]) => void\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n error: (...args: any[]) => void\n}\n\nconst createReport = (\n namespace?: string,\n enabled = isGlobalDebugEnabled(),\n options?: {\n color?: string\n },\n): Report => {\n return {\n namespace: (_namespace: string, enabled?: boolean) =>\n createReport(`[${namespace}] [${_namespace}]`, enabled, options),\n debug: !enabled\n ? () => {}\n : namespace\n ? Function.prototype.bind.call(console.debug, console, namespace)\n : Function.prototype.bind.call(console.debug, console),\n info: !enabled\n ? () => {}\n : namespace\n ? Function.prototype.bind.call(\n console.info,\n console,\n `%c${namespace}`,\n options?.color ? `color: ${options.color}` : undefined,\n )\n : Function.prototype.bind.call(console.info, console),\n log: !enabled\n ? () => {}\n : namespace\n ? Function.prototype.bind.call(console.log, console, namespace)\n : Function.prototype.bind.call(console.log, console),\n warn: !enabled\n ? () => {}\n : namespace\n ? Function.prototype.bind.call(console.warn, console, namespace)\n : Function.prototype.bind.call(console.warn, console),\n error: !enabled\n ? () => {}\n : namespace\n ? Function.prototype.bind.call(console.error, console, namespace)\n : Function.prototype.bind.call(console.error, console),\n }\n}\n\nexport const Report = {\n ...createReport(),\n namespace: (\n namespace: string,\n enabled?: boolean,\n options?: {\n color?: string\n },\n ) => createReport(namespace, enabled, options),\n}\n","// biome-ignore lint/suspicious/noExplicitAny: TODO\nexport const arrayEqual = <A extends any[], B extends any[]>(a: A, b: B) => {\n // @ts-expect-error\n if (a === b) return true\n if (a.length !== b.length) return false\n\n return a.every((v, i) => v === b[i])\n}\n"],"names":["getUrlExtension","url","_b","_a","normalize","strArray","resultArray","component","str","parts","urlJoin","args","getParentPath","uri","detectMimeTypeFromName","name","isXmlBasedMimeType","mimeType","_mimeType","parseContentType","PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME","hasOwn","is","x","y","isShallowEqual","objectA","objectB","options","keysA","keysB","isEqual","i","key","groupBy","list","getKey","previous","currentItem","group","shallowMergeIfDefined","obj1","obj2","result","value","getWindow","isGlobalDebugEnabled","debug","createReport","namespace","enabled","_namespace","Report","arrayEqual","a","b","v"],"mappings":"uOAAO,MAAMA,EAAmBC,GAAgB,SAC9C,QAAOC,GAAAC,EAAAF,EAAI,MAAM,MAAM,EAAE,CAAC,IAAnB,YAAAE,EAAsB,MAAM,KAAK,QAAjC,YAAAD,EAAwC,SAAU,EAC3D,EAEA,SAASE,EAAUC,EAAoB,CACrC,MAAMC,EAAc,CAAA,EACpB,GAAID,EAAS,SAAW,EACtB,MAAO,GAGT,GAAI,OAAOA,EAAS,CAAC,GAAM,SACzB,MAAM,IAAI,UAAU,kCAAkCA,EAAS,CAAC,CAAC,EAAE,EAIjEA,EAAS,CAAC,EAAE,MAAM,cAAc,GAAKA,EAAS,OAAS,IACzDA,EAAS,CAAC,EAAIA,EAAS,MAAA,EAAUA,EAAS,CAAC,GAIzCA,EAAS,CAAC,EAAE,MAAM,cAAc,EAClCA,EAAS,CAAC,EAAIA,EAAS,CAAC,EAAE,QAAQ,gBAAiB,QAAQ,EAE3DA,EAAS,CAAC,EAAIA,EAAS,CAAC,EAAE,QAAQ,gBAAiB,OAAO,EAG5D,QAAS,EAAI,EAAG,EAAIA,EAAS,OAAQ,IAAK,CACxC,IAAIE,EAAYF,EAAS,CAAC,EAE1B,GAAI,OAAOE,GAAc,SACvB,MAAM,IAAI,UAAU,kCAAkCA,CAAS,EAAE,EAG/DA,IAAc,KAId,EAAI,IAENA,EAAYA,EAAU,QAAQ,QAAS,EAAE,GAEvC,EAAIF,EAAS,OAAS,EAExBE,EAAYA,EAAU,QAAQ,QAAS,EAAE,EAGzCA,EAAYA,EAAU,QAAQ,QAAS,GAAG,EAG5CD,EAAY,KAAKC,CAAS,EAAA,CAG5B,IAAIC,EAAMF,EAAY,KAAK,GAAG,EAI9BE,EAAMA,EAAI,Q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B,CAAO,EACjE,MAAQsB,EAEJD,EACE,SAAS,UAAU,KAAK,KAAK,QAAQ,MAAO,QAASA,CAAS,EAC9D,SAAS,UAAU,KAAK,KAAK,QAAQ,MAAO,OAAO,EAHrD,IAAM,CAAA,EAIV,KAAOC,EAEHD,EACE,SAAS,UAAU,KAAK,KACtB,QAAQ,KACR,QACA,KAAKA,CAAS,GACdrB,GAAA,MAAAA,EAAS,MAAQ,UAAUA,EAAQ,KAAK,GAAK,MAAA,EAE/C,SAAS,UAAU,KAAK,KAAK,QAAQ,KAAM,OAAO,EARpD,IAAM,CAAA,EASV,IAAMsB,EAEFD,EACE,SAAS,UAAU,KAAK,KAAK,QAAQ,IAAK,QAASA,CAAS,EAC5D,SAAS,UAAU,KAAK,KAAK,QAAQ,IAAK,OAAO,EAHnD,IAAM,CAAA,EAIV,KAAOC,EAEHD,EACE,SAAS,UAAU,KAAK,KAAK,QAAQ,KAAM,QAASA,CAAS,EAC7D,SAAS,UAAU,KAAK,KAAK,QAAQ,KAAM,OAAO,EAHpD,IAAM,CAAA,EAIV,MAAQC,EAEJD,EACE,SAAS,UAAU,KAAK,KAAK,QAAQ,MAAO,QAASA,CAAS,EAC9D,SAAS,UAAU,KAAK,KAAK,QAAQ,MAAO,OAAO,EAHrD,IAAM,CAAA,CAG+C,GAIhDG,EAAS,CACpB,GAAGJ,EAAA,EACH,UAAW,CACTC,EACAC,EACAtB,IAGGoB,EAAaC,EAAWC,EAAStB,CAAO,CAC/C,ECrFayB,EAAa,CAAmCC,EAAMC,IAE7DD,IAAMC,EAAU,GAChBD,EAAE,SAAWC,EAAE,OAAe,GAE3BD,EAAE,MAAM,CAACE,EAAGxB,IAAMwB,IAAMD,EAAEvB,CAAC,CAAC"}
1
+ {"version":3,"file":"index.umd.cjs","sources":["../src/array.ts","../src/url.ts","../src/contentType.ts","../src/objects.ts","../src/report.ts","../src/resources.ts"],"sourcesContent":["// biome-ignore lint/suspicious/noExplicitAny: TODO\nexport const arrayEqual = <A extends any[], B extends any[]>(a: A, b: B) => {\n // @ts-expect-error\n if (a === b) return true\n if (a.length !== b.length) return false\n\n return a.every((v, i) => v === b[i])\n}\n","export const getUrlExtension = (url: string) => {\n return url.split(/[#?]/)[0]?.split(`.`).pop()?.trim() || ``\n}\n\nfunction normalize(strArray: string[]) {\n const resultArray = []\n if (strArray.length === 0) {\n return \"\"\n }\n\n if (typeof strArray[0] !== \"string\") {\n throw new TypeError(`Url must be a string. Received ${strArray[0]}`)\n }\n\n // If the first part is a plain protocol, we combine it with the next part.\n if (strArray[0].match(/^[^/:]+:\\/*$/) && strArray.length > 1) {\n strArray[0] = strArray.shift() + strArray[0]\n }\n\n // There must be two or three slashes in the file protocol, two slashes in anything else.\n if (strArray[0].match(/^file:\\/\\/\\//)) {\n strArray[0] = strArray[0].replace(/^([^/:]+):\\/*/, \"$1:///\")\n } else {\n strArray[0] = strArray[0].replace(/^([^/:]+):\\/*/, \"$1://\")\n }\n\n for (let i = 0; i < strArray.length; i++) {\n let component = strArray[i]\n\n if (typeof component !== \"string\") {\n throw new TypeError(`Url must be a string. Received ${component}`)\n }\n\n if (component === \"\") {\n continue\n }\n\n if (i > 0) {\n // Removing the starting slashes for each component but the first.\n component = component.replace(/^[/]+/, \"\")\n }\n if (i < strArray.length - 1) {\n // Removing the ending slashes for each component but the last.\n component = component.replace(/[/]+$/, \"\")\n } else {\n // For the last component we will combine multiple slashes to a single one.\n component = component.replace(/[/]+$/, \"/\")\n }\n\n resultArray.push(component)\n }\n\n let str = resultArray.join(\"/\")\n // Each input component is now separated by a single slash except the possible first plain protocol part.\n\n // remove trailing slash before parameters or hash\n str = str.replace(/\\/(\\?|&|#[^!])/g, \"$1\")\n\n // replace ? in parameters with &\n const parts = str.split(\"?\")\n str = parts.shift() + (parts.length > 0 ? \"?\" : \"\") + parts.join(\"&\")\n\n return str\n}\n\nexport function urlJoin(...args: (string | string[])[]) {\n const parts = Array.from(Array.isArray(args[0]) ? args[0] : args) as string[]\n\n return normalize(parts)\n}\n\nexport function getParentPath(uri: string): string {\n const parts = uri.split(\"/\")\n\n parts.pop() // Remove the last segment\n\n return parts.join(\"/\")\n}\n","import { getUrlExtension } from \"./url\"\n\nexport const detectMimeTypeFromName = (name: string) => {\n const extension = getUrlExtension(name)\n\n switch (extension) {\n case `png`:\n return `image/png`\n case `jpg`:\n return `image/jpg`\n case `jpeg`:\n return `image/jpeg`\n case `txt`:\n return `text/plain`\n case `webp`:\n return `image/webp`\n case `xhtml`:\n return `application/xhtml+xml`\n }\n\n return undefined\n}\n\nexport const isXmlBasedMimeType = ({\n mimeType,\n uri,\n}: {\n uri?: string\n mimeType?: string\n}) => {\n const _mimeType = mimeType ?? detectMimeTypeFromName(uri ?? \"\")\n\n return _mimeType?.startsWith(`application/xhtml+xml`)\n}\n\nexport const parseContentType = (str: string) => {\n if (!str.length) return undefined\n\n const cut = str.indexOf(`;`)\n\n return cut ? str.substring(0, str.indexOf(`;`)) : str\n}\n","// MIT © 2017 azu\nconst hasOwn = Object.prototype.hasOwnProperty\n\n// Object.is polyfill\n// biome-ignore lint/suspicious/noExplicitAny: TODO\nexport const is = (x: any, y: any): boolean => {\n if (x === y) {\n return x !== 0 || y !== 0 || 1 / x === 1 / y\n }\n return false\n}\n\n/**\n * Return true, if `objectA` is shallow equal to `objectB`.\n * Pass Custom equality function to `customEqual`.\n * Default equality is `Object.is`\n * Support Array\n *\n * Options:\n *\n * - `customEqual`: function should return true if the `a` value is equal to `b` value.\n * - `debug`: enable debug info to console log. This log will be disable in production build\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: TODO\nexport const isShallowEqual = <T = any, R = any>(\n objectA: T,\n objectB: R,\n options?: {\n customEqual?: <T>(a: T, b: T) => boolean\n },\n): boolean => {\n // @ts-ignore\n if (objectA === objectB) {\n return true\n }\n if (typeof objectA !== \"object\" || objectA === null) {\n return false\n }\n if (typeof objectB !== \"object\" || objectB === null) {\n return false\n }\n\n const keysA = Object.keys(objectA)\n const keysB = Object.keys(objectB)\n\n if (keysA.length !== keysB.length) {\n return false\n }\n\n const isEqual =\n options && typeof options.customEqual === \"function\"\n ? options.customEqual\n : is\n\n for (let i = 0; i < keysA.length; i++) {\n const key = keysA[i] || ``\n // @ts-ignore\n if (!hasOwn.call(objectB, key) || !isEqual(objectA[key], objectB[key])) {\n return false\n }\n }\n\n return true\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: TODO\nexport const groupBy = <T, K extends keyof any>(\n list: T[],\n getKey: (item: T) => K,\n) =>\n list.reduce(\n (previous, currentItem) => {\n const group = getKey(currentItem)\n if (!previous[group]) previous[group] = []\n previous[group].push(currentItem)\n return previous\n },\n {} as Record<K, T[]>,\n )\n\nexport function shallowMergeIfDefined<T extends object, U extends object>(\n obj1: T,\n obj2: U,\n): T & U {\n const result = { ...obj1 } as T & U\n\n for (const key in obj2) {\n if (Object.hasOwn(obj2, key)) {\n // biome-ignore lint/suspicious/noExplicitAny: TODO\n const value = (obj2 as any)[key]\n if (value !== undefined || !(key in obj1)) {\n // biome-ignore lint/suspicious/noExplicitAny: TODO\n ;(result as any)[key] = value\n }\n }\n }\n\n return result\n}\n","declare global {\n interface Window {\n __PROSE_READER_DEBUG?: boolean | string\n }\n}\n\nconst getWindow = () => {\n if (typeof window === \"undefined\") {\n return undefined\n }\n\n return window\n}\n\nfunction isGlobalDebugEnabled() {\n const debug = getWindow()?.__PROSE_READER_DEBUG\n\n return debug === true || debug === \"true\"\n}\n\nexport type Report = {\n namespace: (namespace: string, enabled?: boolean) => Report\n // biome-ignore lint/suspicious/noExplicitAny: TODO\n debug: (...args: any[]) => void\n // biome-ignore lint/suspicious/noExplicitAny: TODO\n info: (...args: any[]) => void\n // biome-ignore lint/suspicious/noExplicitAny: TODO\n log: (...args: any[]) => void\n // biome-ignore lint/suspicious/noExplicitAny: TODO\n warn: (...args: any[]) => void\n // biome-ignore lint/suspicious/noExplicitAny: TODO\n error: (...args: any[]) => void\n}\n\nconst createReport = (\n namespace?: string,\n enabled = isGlobalDebugEnabled(),\n options?: {\n color?: string\n },\n): Report => {\n return {\n namespace: (_namespace: string, enabled?: boolean) =>\n createReport(`[${namespace}] [${_namespace}]`, enabled, options),\n debug: !enabled\n ? () => {}\n : namespace\n ? Function.prototype.bind.call(console.debug, console, namespace)\n : Function.prototype.bind.call(console.debug, console),\n info: !enabled\n ? () => {}\n : namespace\n ? Function.prototype.bind.call(\n console.info,\n console,\n `%c${namespace}`,\n options?.color ? `color: ${options.color}` : undefined,\n )\n : Function.prototype.bind.call(console.info, console),\n log: !enabled\n ? () => {}\n : namespace\n ? Function.prototype.bind.call(console.log, console, namespace)\n : Function.prototype.bind.call(console.log, console),\n warn: !enabled\n ? () => {}\n : namespace\n ? Function.prototype.bind.call(console.warn, console, namespace)\n : Function.prototype.bind.call(console.warn, console),\n error: !enabled\n ? () => {}\n : namespace\n ? Function.prototype.bind.call(console.error, console, namespace)\n : Function.prototype.bind.call(console.error, console),\n }\n}\n\nexport const Report = {\n ...createReport(),\n namespace: (\n namespace: string,\n enabled?: boolean,\n options?: {\n color?: string\n },\n ) => createReport(namespace, enabled, options),\n}\n","export const PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME =\n \"prose-reader-resource-error\"\n"],"names":["arrayEqual","a","b","v","i","getUrlExtension","url","normalize","strArray","resultArray","component","str","parts","urlJoin","args","getParentPath","uri","detectMimeTypeFromName","name","isXmlBasedMimeType","mimeType","parseContentType","hasOwn","is","x","y","isShallowEqual","objectA","objectB","options","keysA","keysB","isEqual","key","groupBy","list","getKey","previous","currentItem","group","shallowMergeIfDefined","obj1","obj2","result","value","getWindow","isGlobalDebugEnabled","debug","createReport","namespace","enabled","_namespace","Report","PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME"],"mappings":"uOACO,MAAMA,EAAa,CAAmCC,EAAMC,IAE7DD,IAAMC,EAAU,GAChBD,EAAE,SAAWC,EAAE,OAAe,GAE3BD,EAAE,MAAM,CAACE,EAAGC,IAAMD,IAAMD,EAAEE,CAAC,CAAC,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,KAAM,OAAO,EARpD,IAAM,CAAA,EASV,IAAMqB,EAEFD,EACE,SAAS,UAAU,KAAK,KAAK,QAAQ,IAAK,QAASA,CAAS,EAC5D,SAAS,UAAU,KAAK,KAAK,QAAQ,IAAK,OAAO,EAHnD,IAAM,CAAA,EAIV,KAAOC,EAEHD,EACE,SAAS,UAAU,KAAK,KAAK,QAAQ,KAAM,QAASA,CAAS,EAC7D,SAAS,UAAU,KAAK,KAAK,QAAQ,KAAM,OAAO,EAHpD,IAAM,CAAA,EAIV,MAAQC,EAEJD,EACE,SAAS,UAAU,KAAK,KAAK,QAAQ,MAAO,QAASA,CAAS,EAC9D,SAAS,UAAU,KAAK,KAAK,QAAQ,MAAO,OAAO,EAHrD,IAAM,CAAA,CAG+C,GAIhDG,EAAS,CACpB,GAAGJ,EAAA,EACH,UAAW,CACTC,EACAC,EACArB,IAGGmB,EAAaC,EAAWC,EAASrB,CAAO,CAC/C,ECtFawB,EACX"}
package/dist/objects.d.ts CHANGED
@@ -3,4 +3,4 @@ export declare const isShallowEqual: <T = any, R = any>(objectA: T, objectB: R,
3
3
  customEqual?: <T_1>(a: T_1, b: T_1) => boolean;
4
4
  }) => boolean;
5
5
  export declare const groupBy: <T, K extends keyof any>(list: T[], getKey: (item: T) => K) => Record<K, T[]>;
6
- export declare function shallowMergeIfDefined<T, U>(obj1: T, obj2: U): T & U;
6
+ export declare function shallowMergeIfDefined<T extends object, U extends object>(obj1: T, obj2: U): T & U;
package/dist/report.d.ts CHANGED
@@ -3,7 +3,7 @@ declare global {
3
3
  __PROSE_READER_DEBUG?: boolean | string;
4
4
  }
5
5
  }
6
- type Report = {
6
+ export type Report = {
7
7
  namespace: (namespace: string, enabled?: boolean) => Report;
8
8
  debug: (...args: any[]) => void;
9
9
  info: (...args: any[]) => void;
@@ -21,4 +21,3 @@ export declare const Report: {
21
21
  warn: (...args: any[]) => void;
22
22
  error: (...args: any[]) => void;
23
23
  };
24
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prose-reader/shared",
3
- "version": "1.233.0",
3
+ "version": "1.235.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.umd.cjs",
6
6
  "module": "./dist/index.js",
@@ -20,5 +20,5 @@
20
20
  "build": "tsc && vite build",
21
21
  "test": "vitest run --coverage"
22
22
  },
23
- "gitHead": "4ec533f8c570bd6168dfb27fc55acaffcce0a5d3"
23
+ "gitHead": "3dea646d56d3fc05d37fb0139622ada6df27c41c"
24
24
  }