heroshot 0.14.0 → 0.14.2

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.
@@ -1,75 +1,76 @@
1
1
  "use client";
2
- import { jsx as h, jsxs as y } from "react/jsx-runtime";
3
- import I, { createContext as $, useContext as j, useMemo as g, useState as C, useEffect as L } from "react";
4
- function z(e, t) {
5
- return e.screenshots[t];
2
+ import y from "@heroshot/manifest";
3
+ import { jsx as h, jsxs as $ } from "react/jsx-runtime";
4
+ import I, { createContext as j, useContext as C, useMemo as g, useState as L, useEffect as z } from "react";
5
+ let S = null;
6
+ function N(e) {
7
+ S = e;
6
8
  }
7
- function N(e, t = {}) {
8
- const { slug: a, format: s } = e, { viewport: r, colorScheme: c } = t, n = [a];
9
- r && n.push(r), c && n.push(c);
10
- const i = s === "jpeg" ? "jpg" : "png";
11
- return `${n.join("-")}.${i}`;
9
+ function O() {
10
+ return S;
12
11
  }
13
- function O(e, t, a = {}) {
14
- const s = N(t, a);
15
- return `${e.outputDirectory}/${s}`;
12
+ function R(e, n) {
13
+ return e.screenshots[n];
16
14
  }
17
- function H(e, t, a) {
18
- const { colorSchemes: s } = t, r = s.length > 0, c = (i) => O(e, t, { viewport: a, colorScheme: i }), n = {
19
- default: r ? c("light") : c()
15
+ function V(e, n = {}) {
16
+ const { slug: c, format: s } = e, { viewport: t, colorScheme: i } = n, r = [c];
17
+ t && r.push(t), i && r.push(i);
18
+ const a = s === "jpeg" ? "jpg" : "png";
19
+ return `${r.join("-")}.${a}`;
20
+ }
21
+ function W(e, n, c = {}) {
22
+ const s = V(n, c), t = e.outputDirectory;
23
+ return `${t.startsWith("/") ? "" : "/"}${t}/${s}`;
24
+ }
25
+ function x(e, n, c) {
26
+ const { colorSchemes: s } = n, t = s.length > 0, i = (a) => W(e, n, { viewport: c, colorScheme: a }), r = {
27
+ default: t ? i("light") : i()
20
28
  };
21
- return s.includes("light") && (n.light = c("light")), s.includes("dark") && (n.dark = c("dark")), n;
29
+ return s.includes("light") && (r.light = i("light")), s.includes("dark") && (r.dark = i("dark")), r;
22
30
  }
23
- function R(e, t) {
24
- const a = H(e, t), s = {};
25
- for (const r of t.viewports)
26
- s[r] = H(e, t, r);
31
+ function A(e, n) {
32
+ const c = x(e, n), s = {};
33
+ for (const t of n.viewports)
34
+ s[t] = x(e, n, t);
27
35
  return {
28
- ...a,
36
+ ...c,
29
37
  viewports: s
30
38
  };
31
39
  }
32
- let x = null;
33
- function Q(e) {
34
- x = e;
35
- }
36
- function V() {
37
- return x;
38
- }
39
- const D = $(null);
40
- function _({
40
+ const D = j(null);
41
+ function G({
41
42
  manifest: e,
42
- children: t
43
+ children: n
43
44
  }) {
44
- return /* @__PURE__ */ h(D.Provider, { value: e, children: t });
45
+ return /* @__PURE__ */ h(D.Provider, { value: e, children: n });
45
46
  }
46
- function S() {
47
+ function H() {
47
48
  if (globalThis.window === void 0) return { isDark: !1, hasThemeHandling: !1 };
48
49
  const { theme: e } = document.documentElement.dataset;
49
50
  return e ? { isDark: e === "dark", hasThemeHandling: !0 } : document.documentElement.classList.contains("dark") ? { isDark: !0, hasThemeHandling: !0 } : document.documentElement.classList.length > 0 ? { isDark: !1, hasThemeHandling: !0 } : globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ? { isDark: !0, hasThemeHandling: !1 } : { isDark: !1, hasThemeHandling: !1 };
50
51
  }
51
- function A() {
52
- const e = I.useRef(!1), [t, a] = C(() => S().isDark);
53
- return L(() => {
54
- const s = S();
52
+ function F() {
53
+ const e = I.useRef(!1), [n, c] = L(() => H().isDark);
54
+ return z(() => {
55
+ const s = H();
55
56
  e.current = s.hasThemeHandling;
56
- const r = () => {
57
+ const t = () => {
57
58
  const { theme: u } = document.documentElement.dataset;
58
59
  return u ? (e.current = !0, u === "dark") : document.documentElement.classList.contains("dark") ? (e.current = !0, !0) : e.current ? !1 : globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ?? !1;
59
- }, c = new MutationObserver(() => {
60
- e.current = !0, a(r());
60
+ }, i = new MutationObserver(() => {
61
+ e.current = !0, c(t());
61
62
  });
62
- c.observe(document.documentElement, {
63
+ i.observe(document.documentElement, {
63
64
  attributes: !0,
64
65
  attributeFilter: ["data-theme", "class"]
65
66
  });
66
- const n = globalThis.matchMedia?.("(prefers-color-scheme: dark)"), i = () => {
67
- a(r());
67
+ const r = globalThis.matchMedia?.("(prefers-color-scheme: dark)"), a = () => {
68
+ c(t());
68
69
  };
69
- return n?.addEventListener("change", i), () => {
70
- c.disconnect(), n?.removeEventListener("change", i);
70
+ return r?.addEventListener("change", a), () => {
71
+ i.disconnect(), r?.removeEventListener("change", a);
71
72
  };
72
- }, []), t;
73
+ }, []), n;
73
74
  }
74
75
  const k = {
75
76
  mobile: 430,
@@ -77,18 +78,18 @@ const k = {
77
78
  tablet: 768,
78
79
  desktop: 1280
79
80
  };
80
- function q({
81
+ function J({
81
82
  name: e,
82
- alt: t = "",
83
- manifest: a,
83
+ alt: n = "",
84
+ manifest: c,
84
85
  className: s
85
86
  }) {
86
- const r = A(), c = j(D), n = a ?? c ?? V(), i = g(() => n ? z(n, e) : null, [n, e]), u = g(() => !i || !n ? null : R(n, i), [n, i]), v = g(() => {
87
+ const t = F(), i = C(D), r = c ?? i ?? O(), a = g(() => r ? R(r, e) : null, [r, e]), u = g(() => !a || !r ? null : A(r, a), [r, a]), v = g(() => {
87
88
  if (!u) return "";
88
89
  const { light: o, dark: f } = u;
89
- return r && f ? f : !r && o ? o : u.default;
90
- }, [u, r]), T = g(() => {
91
- if (!u || !i) return [];
90
+ return t && f ? f : !t && o ? o : u.default;
91
+ }, [u, t]), T = g(() => {
92
+ if (!u || !a) return [];
92
93
  const { viewports: o } = u, f = Object.keys(o);
93
94
  if (f.length === 0) return [];
94
95
  const b = [...f].sort((l, m) => {
@@ -101,34 +102,37 @@ function q({
101
102
  const p = d.light || d.default, E = d.dark || d.light || d.default, w = k[l] || Number.parseInt(l.split("x")[0] || "1280", 10), M = m === b.length - 1;
102
103
  return {
103
104
  viewport: l,
104
- srcset: r ? E : p,
105
+ srcset: t ? E : p,
105
106
  width: w,
106
107
  media: M ? void 0 : `(max-width: ${w}px)`
107
108
  };
108
109
  }).filter((l) => l !== null);
109
- }, [u, i, r]), P = T.length > 0;
110
- if (!n) {
110
+ }, [u, a, t]), P = T.length > 0;
111
+ if (!r) {
111
112
  const o = "Heroshot: No manifest found. Add heroshot() plugin to vite config, use HeroshotProvider, or pass manifest prop.";
112
113
  return typeof console < "u" && console.warn(o), /* @__PURE__ */ h("span", { style: { color: "red", fontSize: "12px" }, children: o });
113
114
  }
114
- if (!i) {
115
+ if (!a) {
115
116
  const o = `Heroshot: Screenshot "${e}" not found in config`;
116
117
  return typeof console < "u" && console.warn(o), /* @__PURE__ */ h("span", { style: { color: "red", fontSize: "12px" }, children: o });
117
118
  }
118
- return P ? /* @__PURE__ */ y("picture", { className: s, children: [
119
+ return P ? /* @__PURE__ */ $("picture", { className: s, children: [
119
120
  T.map((o) => /* @__PURE__ */ h(
120
121
  "source",
121
122
  {
122
123
  srcSet: o.srcset,
123
124
  media: o.media
124
125
  },
125
- `${o.viewport}-${r}`
126
+ `${o.viewport}-${t}`
126
127
  )),
127
- /* @__PURE__ */ h("img", { src: v, alt: t, loading: "lazy" })
128
- ] }) : /* @__PURE__ */ h("img", { src: v, alt: t, className: s, loading: "lazy" });
128
+ /* @__PURE__ */ h("img", { src: v, alt: n, loading: "lazy" })
129
+ ] }) : /* @__PURE__ */ h("img", { src: v, alt: n, className: s, loading: "lazy" });
129
130
  }
131
+ (function() {
132
+ N(y);
133
+ })();
130
134
  export {
131
- q as Heroshot,
132
- _ as HeroshotProvider,
133
- Q as setManifest
135
+ J as Heroshot,
136
+ G as HeroshotProvider,
137
+ N as setManifest
134
138
  };
@@ -1,74 +1,74 @@
1
1
  import { jsx as h, jsxs as y } from "react/jsx-runtime";
2
- import I, { createContext as $, useContext as j, useMemo as g, useState as C, useEffect as L } from "react";
3
- function z(e, t) {
4
- return e.screenshots[t];
2
+ import $, { createContext as I, useContext as j, useMemo as g, useState as C, useEffect as L } from "react";
3
+ function z(e, n) {
4
+ return e.screenshots[n];
5
5
  }
6
- function N(e, t = {}) {
7
- const { slug: a, format: s } = e, { viewport: r, colorScheme: c } = t, n = [a];
8
- r && n.push(r), c && n.push(c);
9
- const i = s === "jpeg" ? "jpg" : "png";
10
- return `${n.join("-")}.${i}`;
6
+ function N(e, n = {}) {
7
+ const { slug: c, format: s } = e, { viewport: t, colorScheme: i } = n, r = [c];
8
+ t && r.push(t), i && r.push(i);
9
+ const a = s === "jpeg" ? "jpg" : "png";
10
+ return `${r.join("-")}.${a}`;
11
11
  }
12
- function O(e, t, a = {}) {
13
- const s = N(t, a);
14
- return `${e.outputDirectory}/${s}`;
12
+ function O(e, n, c = {}) {
13
+ const s = N(n, c), t = e.outputDirectory;
14
+ return `${t.startsWith("/") ? "" : "/"}${t}/${s}`;
15
15
  }
16
- function H(e, t, a) {
17
- const { colorSchemes: s } = t, r = s.length > 0, c = (i) => O(e, t, { viewport: a, colorScheme: i }), n = {
18
- default: r ? c("light") : c()
16
+ function x(e, n, c) {
17
+ const { colorSchemes: s } = n, t = s.length > 0, i = (a) => O(e, n, { viewport: c, colorScheme: a }), r = {
18
+ default: t ? i("light") : i()
19
19
  };
20
- return s.includes("light") && (n.light = c("light")), s.includes("dark") && (n.dark = c("dark")), n;
20
+ return s.includes("light") && (r.light = i("light")), s.includes("dark") && (r.dark = i("dark")), r;
21
21
  }
22
- function R(e, t) {
23
- const a = H(e, t), s = {};
24
- for (const r of t.viewports)
25
- s[r] = H(e, t, r);
22
+ function R(e, n) {
23
+ const c = x(e, n), s = {};
24
+ for (const t of n.viewports)
25
+ s[t] = x(e, n, t);
26
26
  return {
27
- ...a,
27
+ ...c,
28
28
  viewports: s
29
29
  };
30
30
  }
31
- let x = null;
31
+ let S = null;
32
32
  function Q(e) {
33
- x = e;
33
+ S = e;
34
34
  }
35
35
  function V() {
36
- return x;
36
+ return S;
37
37
  }
38
- const D = $(null);
38
+ const D = I(null);
39
39
  function _({
40
40
  manifest: e,
41
- children: t
41
+ children: n
42
42
  }) {
43
- return /* @__PURE__ */ h(D.Provider, { value: e, children: t });
43
+ return /* @__PURE__ */ h(D.Provider, { value: e, children: n });
44
44
  }
45
- function S() {
45
+ function H() {
46
46
  if (globalThis.window === void 0) return { isDark: !1, hasThemeHandling: !1 };
47
47
  const { theme: e } = document.documentElement.dataset;
48
48
  return e ? { isDark: e === "dark", hasThemeHandling: !0 } : document.documentElement.classList.contains("dark") ? { isDark: !0, hasThemeHandling: !0 } : document.documentElement.classList.length > 0 ? { isDark: !1, hasThemeHandling: !0 } : globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ? { isDark: !0, hasThemeHandling: !1 } : { isDark: !1, hasThemeHandling: !1 };
49
49
  }
50
- function A() {
51
- const e = I.useRef(!1), [t, a] = C(() => S().isDark);
50
+ function W() {
51
+ const e = $.useRef(!1), [n, c] = C(() => H().isDark);
52
52
  return L(() => {
53
- const s = S();
53
+ const s = H();
54
54
  e.current = s.hasThemeHandling;
55
- const r = () => {
55
+ const t = () => {
56
56
  const { theme: u } = document.documentElement.dataset;
57
57
  return u ? (e.current = !0, u === "dark") : document.documentElement.classList.contains("dark") ? (e.current = !0, !0) : e.current ? !1 : globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ?? !1;
58
- }, c = new MutationObserver(() => {
59
- e.current = !0, a(r());
58
+ }, i = new MutationObserver(() => {
59
+ e.current = !0, c(t());
60
60
  });
61
- c.observe(document.documentElement, {
61
+ i.observe(document.documentElement, {
62
62
  attributes: !0,
63
63
  attributeFilter: ["data-theme", "class"]
64
64
  });
65
- const n = globalThis.matchMedia?.("(prefers-color-scheme: dark)"), i = () => {
66
- a(r());
65
+ const r = globalThis.matchMedia?.("(prefers-color-scheme: dark)"), a = () => {
66
+ c(t());
67
67
  };
68
- return n?.addEventListener("change", i), () => {
69
- c.disconnect(), n?.removeEventListener("change", i);
68
+ return r?.addEventListener("change", a), () => {
69
+ i.disconnect(), r?.removeEventListener("change", a);
70
70
  };
71
- }, []), t;
71
+ }, []), n;
72
72
  }
73
73
  const k = {
74
74
  mobile: 430,
@@ -78,16 +78,16 @@ const k = {
78
78
  };
79
79
  function q({
80
80
  name: e,
81
- alt: t = "",
82
- manifest: a,
81
+ alt: n = "",
82
+ manifest: c,
83
83
  className: s
84
84
  }) {
85
- const r = A(), c = j(D), n = a ?? c ?? V(), i = g(() => n ? z(n, e) : null, [n, e]), u = g(() => !i || !n ? null : R(n, i), [n, i]), v = g(() => {
85
+ const t = W(), i = j(D), r = c ?? i ?? V(), a = g(() => r ? z(r, e) : null, [r, e]), u = g(() => !a || !r ? null : R(r, a), [r, a]), v = g(() => {
86
86
  if (!u) return "";
87
87
  const { light: o, dark: f } = u;
88
- return r && f ? f : !r && o ? o : u.default;
89
- }, [u, r]), T = g(() => {
90
- if (!u || !i) return [];
88
+ return t && f ? f : !t && o ? o : u.default;
89
+ }, [u, t]), T = g(() => {
90
+ if (!u || !a) return [];
91
91
  const { viewports: o } = u, f = Object.keys(o);
92
92
  if (f.length === 0) return [];
93
93
  const b = [...f].sort((l, m) => {
@@ -100,17 +100,17 @@ function q({
100
100
  const p = d.light || d.default, E = d.dark || d.light || d.default, w = k[l] || Number.parseInt(l.split("x")[0] || "1280", 10), M = m === b.length - 1;
101
101
  return {
102
102
  viewport: l,
103
- srcset: r ? E : p,
103
+ srcset: t ? E : p,
104
104
  width: w,
105
105
  media: M ? void 0 : `(max-width: ${w}px)`
106
106
  };
107
107
  }).filter((l) => l !== null);
108
- }, [u, i, r]), P = T.length > 0;
109
- if (!n) {
108
+ }, [u, a, t]), P = T.length > 0;
109
+ if (!r) {
110
110
  const o = "Heroshot: No manifest found. Add heroshot() plugin to vite config, use HeroshotProvider, or pass manifest prop.";
111
111
  return typeof console < "u" && console.warn(o), /* @__PURE__ */ h("span", { style: { color: "red", fontSize: "12px" }, children: o });
112
112
  }
113
- if (!i) {
113
+ if (!a) {
114
114
  const o = `Heroshot: Screenshot "${e}" not found in config`;
115
115
  return typeof console < "u" && console.warn(o), /* @__PURE__ */ h("span", { style: { color: "red", fontSize: "12px" }, children: o });
116
116
  }
@@ -121,10 +121,10 @@ function q({
121
121
  srcSet: o.srcset,
122
122
  media: o.media
123
123
  },
124
- `${o.viewport}-${r}`
124
+ `${o.viewport}-${t}`
125
125
  )),
126
- /* @__PURE__ */ h("img", { src: v, alt: t, loading: "lazy" })
127
- ] }) : /* @__PURE__ */ h("img", { src: v, alt: t, className: s, loading: "lazy" });
126
+ /* @__PURE__ */ h("img", { src: v, alt: n, loading: "lazy" })
127
+ ] }) : /* @__PURE__ */ h("img", { src: v, alt: n, className: s, loading: "lazy" });
128
128
  }
129
129
  export {
130
130
  q as Heroshot,
@@ -1,5 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("node:fs"),i=require("node:path"),l=require("./getManifest-BMMzQAE9.cjs");function d(e){return e.startsWith("public/")?e.slice(7):e}function p(e={},c={}){return{...e,webpack(t,m){const n=process.cwd();let o=null;c.config?o=i.resolve(n,c.config):o=l.findConfig(n);let f=l.emptyManifest();if(o&&s.existsSync(o)){const a=l.loadManifest(o);a&&(f={...a,outputDirectory:d(a.outputDirectory)},console.log(`[heroshot] Loaded config from ${o}`))}else console.log("[heroshot] No config found, using empty manifest");const r=i.join(n,"node_modules",".heroshot");s.mkdirSync(r,{recursive:!0});const u=i.join(r,"manifest.json");s.writeFileSync(u,JSON.stringify(f,null,2));const h=i.join(r,"client.js");return s.writeFileSync(h,`import { setManifest } from 'heroshot/next';
2
- import manifest from './manifest.json';
3
- setManifest(manifest);
4
- export default manifest;
5
- `),t.resolve??={},t.resolve.alias??={},t.resolve.alias["@heroshot/manifest"]=u,t.resolve.alias["virtual:heroshot-manifest"]=h,typeof e.webpack=="function"?e.webpack(t,m):t}}}exports.withHeroshot=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("node:fs"),i=require("node:path"),c=require("./getManifest-BMMzQAE9.cjs");function d(e){return e.startsWith("public/")?e.slice(7):e}function m(e={},l={}){return{...e,webpack(o,h){const r=process.cwd();let t=null;l.config?t=i.resolve(r,l.config):t=c.findConfig(r);let u=c.emptyManifest();if(t&&n.existsSync(t)){const s=c.loadManifest(t);s&&(u={...s,outputDirectory:d(s.outputDirectory)},console.log(`[heroshot] Loaded config from ${t}`))}else console.log("[heroshot] No config found, using empty manifest");const a=i.join(r,"node_modules",".heroshot");n.mkdirSync(a,{recursive:!0});const f=i.join(a,"manifest.json");return n.writeFileSync(f,JSON.stringify(u,null,2)),o.resolve??={},o.resolve.alias??={},o.resolve.alias["@heroshot/manifest"]=f,typeof e.webpack=="function"?e.webpack(o,h):o}}}exports.withHeroshot=m;
@@ -1,41 +1,32 @@
1
- import { existsSync as h, mkdirSync as p, writeFileSync as m } from "node:fs";
2
- import { resolve as d, join as n } from "node:path";
3
- import { f as y, l as v, e as w } from "./getManifest-DfRVQbEx.js";
4
- function M(e) {
1
+ import { existsSync as u, mkdirSync as m, writeFileSync as p } from "node:fs";
2
+ import { resolve as h, join as c } from "node:path";
3
+ import { f as d, l as y, e as w } from "./getManifest-DfRVQbEx.js";
4
+ function g(e) {
5
5
  return e.startsWith("public/") ? e.slice(7) : e;
6
6
  }
7
- function k(e = {}, a = {}) {
7
+ function D(e = {}, i = {}) {
8
8
  return {
9
9
  ...e,
10
- webpack(t, u) {
11
- const s = process.cwd();
10
+ webpack(t, f) {
11
+ const r = process.cwd();
12
12
  let o = null;
13
- a.config ? o = d(s, a.config) : o = y(s);
14
- let f = w();
15
- if (o && h(o)) {
16
- const i = v(o);
17
- i && (f = {
18
- ...i,
19
- outputDirectory: M(i.outputDirectory)
13
+ i.config ? o = h(r, i.config) : o = d(r);
14
+ let n = w();
15
+ if (o && u(o)) {
16
+ const s = y(o);
17
+ s && (n = {
18
+ ...s,
19
+ outputDirectory: g(s.outputDirectory)
20
20
  }, console.log(`[heroshot] Loaded config from ${o}`));
21
21
  } else
22
22
  console.log("[heroshot] No config found, using empty manifest");
23
- const r = n(s, "node_modules", ".heroshot");
24
- p(r, { recursive: !0 });
25
- const l = n(r, "manifest.json");
26
- m(l, JSON.stringify(f, null, 2));
27
- const c = n(r, "client.js");
28
- return m(
29
- c,
30
- `import { setManifest } from 'heroshot/next';
31
- import manifest from './manifest.json';
32
- setManifest(manifest);
33
- export default manifest;
34
- `
35
- ), t.resolve ??= {}, t.resolve.alias ??= {}, t.resolve.alias["@heroshot/manifest"] = l, t.resolve.alias["virtual:heroshot-manifest"] = c, typeof e.webpack == "function" ? e.webpack(t, u) : t;
23
+ const l = c(r, "node_modules", ".heroshot");
24
+ m(l, { recursive: !0 });
25
+ const a = c(l, "manifest.json");
26
+ return p(a, JSON.stringify(n, null, 2)), t.resolve ??= {}, t.resolve.alias ??= {}, t.resolve.alias["@heroshot/manifest"] = a, typeof e.webpack == "function" ? e.webpack(t, f) : t;
36
27
  }
37
28
  };
38
29
  }
39
30
  export {
40
- k as withHeroshot
31
+ D as withHeroshot
41
32
  };
@@ -1,4 +1,5 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("node:fs"),d=require("node:path"),i=require("./getManifest-BMMzQAE9.cjs");function h(t){return t.startsWith("public/")||t.startsWith("static/")?t.slice(7):t}const u="virtual:heroshot-manifest",f="\0"+u;function m(t={}){let e=null,r=i.emptyManifest(),a="heroshot/vue";return{name:"heroshot",configResolved(o){const s=o.root;if(o.plugins.some(n=>n.name.includes("svelte"))&&(a="heroshot/svelte"),t.config?e=d.resolve(s,t.config):e=i.findConfig(s),e&&c.existsSync(e)){const n=i.loadManifest(e);n&&(r={...n,outputDirectory:h(n.outputDirectory)},console.log(`[heroshot] Loaded config from ${e}`))}else console.log("[heroshot] No config found, using empty manifest")},resolveId(o){if(o===u)return f},load(o){if(o===f)return`import { setManifest } from '${a}';
2
- const manifest = ${JSON.stringify(r,null,2)};
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("node:fs"),c=require("node:path"),i=require("./getManifest-BMMzQAE9.cjs");function h(n){return n.startsWith("public/")||n.startsWith("static/")?n.slice(7):n}const r="virtual:heroshot-manifest",f="\0"+r;function m(n={}){let t=null,l=i.emptyManifest(),a="heroshot/vue";return{name:"heroshot",configResolved(e){const o=e.root;if(e.plugins.some(s=>s.name.includes("svelte"))&&(a="heroshot/svelte"),n.config?t=c.resolve(o,n.config):t=i.findConfig(o),t&&d.existsSync(t)){const s=i.loadManifest(t);s&&(l={...s,outputDirectory:h(s.outputDirectory)},console.log(`[heroshot] Loaded config from ${t}`))}else console.log("[heroshot] No config found, using empty manifest")},transform(e,o){if(!(o.includes("\0")||o.includes("node_modules"))&&(e.includes("from 'heroshot/")||e.includes('from "heroshot/')))return e.includes(r)?void 0:`import '${r}';
2
+ ${e}`},resolveId(e){if(e===r)return f},load(e){if(e===f)return`import { setManifest } from '${a}';
3
+ const manifest = ${JSON.stringify(l,null,2)};
3
4
  setManifest(manifest);
4
- export default manifest;`},handleHotUpdate({file:o,server:s}){if(e&&o===e){const l=i.loadManifest(e);if(l){r=l,console.log("[heroshot] Config updated");const n=s.moduleGraph.getModuleById(f);n&&(s.moduleGraph.invalidateModule(n),s.ws.send({type:"full-reload"}))}}}}}exports.heroshot=m;
5
+ export default manifest;`},handleHotUpdate({file:e,server:o}){if(t&&e===t){const u=i.loadManifest(t);if(u){l=u,console.log("[heroshot] Config updated");const s=o.moduleGraph.getModuleById(f);s&&(o.moduleGraph.invalidateModule(s),o.ws.send({type:"full-reload"}))}}}}}exports.heroshot=m;
@@ -1,44 +1,50 @@
1
- import { existsSync as c } from "node:fs";
1
+ import { existsSync as d } from "node:fs";
2
2
  import { resolve as m } from "node:path";
3
- import { e as d, f as h, l as a } from "./getManifest-DfRVQbEx.js";
4
- function p(e) {
5
- return e.startsWith("public/") || e.startsWith("static/") ? e.slice(7) : e;
3
+ import { e as c, f as h, l as a } from "./getManifest-DfRVQbEx.js";
4
+ function p(n) {
5
+ return n.startsWith("public/") || n.startsWith("static/") ? n.slice(7) : n;
6
6
  }
7
- const u = "virtual:heroshot-manifest", l = "\0" + u;
8
- function D(e = {}) {
9
- let t = null, i = d(), f = "heroshot/vue";
7
+ const i = "virtual:heroshot-manifest", f = "\0" + i;
8
+ function D(n = {}) {
9
+ let o = null, r = c(), u = "heroshot/vue";
10
10
  return {
11
11
  name: "heroshot",
12
- configResolved(o) {
13
- const s = o.root;
14
- if (o.plugins.some((n) => n.name.includes("svelte")) && (f = "heroshot/svelte"), e.config ? t = m(s, e.config) : t = h(s), t && c(t)) {
15
- const n = a(t);
16
- n && (i = {
17
- ...n,
18
- outputDirectory: p(n.outputDirectory)
19
- }, console.log(`[heroshot] Loaded config from ${t}`));
12
+ configResolved(e) {
13
+ const t = e.root;
14
+ if (e.plugins.some((s) => s.name.includes("svelte")) && (u = "heroshot/svelte"), n.config ? o = m(t, n.config) : o = h(t), o && d(o)) {
15
+ const s = a(o);
16
+ s && (r = {
17
+ ...s,
18
+ outputDirectory: p(s.outputDirectory)
19
+ }, console.log(`[heroshot] Loaded config from ${o}`));
20
20
  } else
21
21
  console.log("[heroshot] No config found, using empty manifest");
22
22
  },
23
- resolveId(o) {
24
- if (o === u)
25
- return l;
23
+ // Auto-inject manifest import into entry modules so users don't need a separate plugin file
24
+ transform(e, t) {
25
+ if (!(t.includes("\0") || t.includes("node_modules")) && (e.includes("from 'heroshot/") || e.includes('from "heroshot/')))
26
+ return e.includes(i) ? void 0 : `import '${i}';
27
+ ${e}`;
26
28
  },
27
- load(o) {
28
- if (o === l)
29
- return `import { setManifest } from '${f}';
30
- const manifest = ${JSON.stringify(i, null, 2)};
29
+ resolveId(e) {
30
+ if (e === i)
31
+ return f;
32
+ },
33
+ load(e) {
34
+ if (e === f)
35
+ return `import { setManifest } from '${u}';
36
+ const manifest = ${JSON.stringify(r, null, 2)};
31
37
  setManifest(manifest);
32
38
  export default manifest;`;
33
39
  },
34
40
  // Hot reload on config changes
35
- handleHotUpdate({ file: o, server: s }) {
36
- if (t && o === t) {
37
- const r = a(t);
38
- if (r) {
39
- i = r, console.log("[heroshot] Config updated");
40
- const n = s.moduleGraph.getModuleById(l);
41
- n && (s.moduleGraph.invalidateModule(n), s.ws.send({ type: "full-reload" }));
41
+ handleHotUpdate({ file: e, server: t }) {
42
+ if (o && e === o) {
43
+ const l = a(o);
44
+ if (l) {
45
+ r = l, console.log("[heroshot] Config updated");
46
+ const s = t.moduleGraph.getModuleById(f);
47
+ s && (t.moduleGraph.invalidateModule(s), t.ws.send({ type: "full-reload" }));
42
48
  }
43
49
  }
44
50
  }
@@ -2,27 +2,27 @@ function h(t, n) {
2
2
  return t.screenshots[n];
3
3
  }
4
4
  function l(t, n = {}) {
5
- const { slug: o, format: e } = t, { viewport: r, colorScheme: i } = n, s = [o];
6
- r && s.push(r), i && s.push(i);
5
+ const { slug: i, format: e } = t, { viewport: o, colorScheme: r } = n, s = [i];
6
+ o && s.push(o), r && s.push(r);
7
7
  const c = e === "jpeg" ? "jpg" : "png";
8
8
  return `${s.join("-")}.${c}`;
9
9
  }
10
- function f(t, n, o = {}) {
11
- const e = l(n, o);
12
- return `${t.outputDirectory}/${e}`;
10
+ function f(t, n, i = {}) {
11
+ const e = l(n, i), o = t.outputDirectory;
12
+ return `${o.startsWith("/") ? "" : "/"}${o}/${e}`;
13
13
  }
14
- function a(t, n, o) {
15
- const { colorSchemes: e } = n, r = e.length > 0, i = (c) => f(t, n, { viewport: o, colorScheme: c }), s = {
16
- default: r ? i("light") : i()
14
+ function a(t, n, i) {
15
+ const { colorSchemes: e } = n, o = e.length > 0, r = (c) => f(t, n, { viewport: i, colorScheme: c }), s = {
16
+ default: o ? r("light") : r()
17
17
  };
18
- return e.includes("light") && (s.light = i("light")), e.includes("dark") && (s.dark = i("dark")), s;
18
+ return e.includes("light") && (s.light = r("light")), e.includes("dark") && (s.dark = r("dark")), s;
19
19
  }
20
20
  function g(t, n) {
21
- const o = a(t, n), e = {};
22
- for (const r of n.viewports)
23
- e[r] = a(t, n, r);
21
+ const i = a(t, n), e = {};
22
+ for (const o of n.viewports)
23
+ e[o] = a(t, n, o);
24
24
  return {
25
- ...o,
25
+ ...i,
26
26
  viewports: e
27
27
  };
28
28
  }
@@ -1,40 +1,40 @@
1
- import { defineComponent as L, computed as m, ref as N, onMounted as T, onUnmounted as C, createElementBlock as h, openBlock as v, normalizeClass as _, createElementVNode as D, Fragment as I, renderList as j, toDisplayString as z } from "vue";
2
- let M = null;
1
+ import { defineComponent as L, computed as h, ref as N, onMounted as T, onUnmounted as C, createElementBlock as m, openBlock as v, normalizeClass as x, createElementVNode as D, Fragment as I, renderList as j, toDisplayString as z } from "vue";
2
+ let E = null;
3
3
  function G(n) {
4
- M = n;
4
+ E = n;
5
5
  }
6
6
  function B() {
7
- return M;
7
+ return E;
8
8
  }
9
9
  function V(n, e) {
10
10
  return n.screenshots[e];
11
11
  }
12
12
  function F(n, e = {}) {
13
- const { slug: r, format: t } = n, { viewport: a, colorScheme: o } = e, s = [r];
14
- a && s.push(a), o && s.push(o);
13
+ const { slug: o, format: t } = n, { viewport: s, colorScheme: a } = e, r = [o];
14
+ s && r.push(s), a && r.push(a);
15
15
  const l = t === "jpeg" ? "jpg" : "png";
16
- return `${s.join("-")}.${l}`;
16
+ return `${r.join("-")}.${l}`;
17
17
  }
18
- function O(n, e, r = {}) {
19
- const t = F(e, r);
20
- return `${n.outputDirectory}/${t}`;
18
+ function O(n, e, o = {}) {
19
+ const t = F(e, o), s = n.outputDirectory;
20
+ return `${s.startsWith("/") ? "" : "/"}${s}/${t}`;
21
21
  }
22
- function E(n, e, r) {
23
- const { colorSchemes: t } = e, a = t.length > 0, o = (l) => O(n, e, { viewport: r, colorScheme: l }), s = {
24
- default: a ? o("light") : o()
22
+ function _(n, e, o) {
23
+ const { colorSchemes: t } = e, s = t.length > 0, a = (l) => O(n, e, { viewport: o, colorScheme: l }), r = {
24
+ default: s ? a("light") : a()
25
25
  };
26
- return t.includes("light") && (s.light = o("light")), t.includes("dark") && (s.dark = o("dark")), s;
26
+ return t.includes("light") && (r.light = a("light")), t.includes("dark") && (r.dark = a("dark")), r;
27
27
  }
28
- function A(n, e) {
29
- const r = E(n, e), t = {};
30
- for (const a of e.viewports)
31
- t[a] = E(n, e, a);
28
+ function W(n, e) {
29
+ const o = _(n, e), t = {};
30
+ for (const s of e.viewports)
31
+ t[s] = _(n, e, s);
32
32
  return {
33
- ...r,
33
+ ...o,
34
34
  viewports: t
35
35
  };
36
36
  }
37
- const W = ["srcset", "media"], Q = ["src", "alt"], R = ["src", "alt"], U = {
37
+ const A = ["srcset", "media"], Q = ["src", "alt"], R = ["src", "alt"], U = {
38
38
  key: 2,
39
39
  style: { color: "red", "font-size": "12px" }
40
40
  }, J = /* @__PURE__ */ L({
@@ -46,78 +46,78 @@ const W = ["srcset", "media"], Q = ["src", "alt"], R = ["src", "alt"], U = {
46
46
  class: {}
47
47
  },
48
48
  setup(n) {
49
- const e = n, r = m(() => e.manifest ?? B()), t = N(!1);
50
- let a = !1;
51
- function o() {
52
- return globalThis.window === void 0 ? !1 : document.documentElement.classList.contains("dark") ? !0 : a ? !1 : !!globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches;
49
+ const e = n, o = h(() => e.manifest ?? B()), t = N(!1);
50
+ let s = !1;
51
+ function a() {
52
+ return globalThis.window === void 0 ? !1 : document.documentElement.classList.contains("dark") ? !0 : s ? !1 : !!globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches;
53
53
  }
54
54
  T(() => {
55
- a = document.documentElement.classList.length > 0 || document.documentElement.dataset.theme !== void 0, t.value = o();
56
- const u = new MutationObserver(() => {
57
- a = !0, t.value = document.documentElement.classList.contains("dark");
55
+ s = document.documentElement.classList.length > 0 || document.documentElement.dataset.theme !== void 0, t.value = a();
56
+ const i = new MutationObserver(() => {
57
+ s = !0, t.value = document.documentElement.classList.contains("dark");
58
58
  });
59
- u.observe(document.documentElement, {
59
+ i.observe(document.documentElement, {
60
60
  attributes: !0,
61
61
  attributeFilter: ["class"]
62
62
  });
63
- const c = globalThis.matchMedia?.("(prefers-color-scheme: dark)"), i = () => {
64
- t.value = o();
63
+ const c = globalThis.matchMedia?.("(prefers-color-scheme: dark)"), u = () => {
64
+ t.value = a();
65
65
  };
66
- c?.addEventListener("change", i), C(() => {
67
- u.disconnect(), c?.removeEventListener("change", i);
66
+ c?.addEventListener("change", u), C(() => {
67
+ i.disconnect(), c?.removeEventListener("change", u);
68
68
  });
69
69
  });
70
- const s = m(() => r.value ? V(r.value, e.name) : null), l = m(() => !s.value || !r.value ? null : A(r.value, s.value)), w = m(() => {
70
+ const r = h(() => o.value ? V(o.value, e.name) : null), l = h(() => !r.value || !o.value ? null : W(o.value, r.value)), w = h(() => {
71
71
  if (!l.value) return "";
72
- const { light: u, dark: c } = l.value;
73
- return t.value && c ? c : !t.value && u ? u : l.value.default;
72
+ const { light: i, dark: c } = l.value;
73
+ return t.value && c ? c : !t.value && i ? i : l.value.default;
74
74
  }), g = {
75
75
  mobile: 430,
76
76
  // iPhone 15/16 Pro Max viewport
77
77
  tablet: 768,
78
78
  desktop: 1280
79
- }, y = m(() => {
80
- if (!l.value || !s.value) return [];
81
- const { viewports: u } = l.value, c = Object.keys(u);
79
+ }, y = h(() => {
80
+ if (!l.value || !r.value) return [];
81
+ const { viewports: i } = l.value, c = Object.keys(i);
82
82
  if (c.length === 0) return [];
83
- const i = [...c].sort((f, p) => {
83
+ const u = [...c].sort((f, p) => {
84
84
  const d = g[f] || Number.parseInt(f.split("x")[0] || "1280", 10), b = g[p] || Number.parseInt(p.split("x")[0] || "1280", 10);
85
85
  return d - b;
86
86
  });
87
- return i.map((f, p) => {
88
- const d = u[f];
87
+ return u.map((f, p) => {
88
+ const d = i[f];
89
89
  if (!d) return null;
90
- const b = d.light || d.default, P = d.dark || d.light || d.default, S = g[f] || Number.parseInt(f.split("x")[0] || "1280", 10), $ = p === i.length - 1, H = t.value ? P : b;
90
+ const b = d.light || d.default, $ = d.dark || d.light || d.default, S = g[f] || Number.parseInt(f.split("x")[0] || "1280", 10), P = p === u.length - 1, H = t.value ? $ : b;
91
91
  return {
92
92
  viewport: f,
93
93
  srcset: H,
94
94
  width: S,
95
95
  // Media query: max-width for this viewport (except for largest which is fallback)
96
- media: $ ? void 0 : `(max-width: ${S}px)`
96
+ media: P ? void 0 : `(max-width: ${S}px)`
97
97
  };
98
98
  }).filter(Boolean);
99
- }), x = m(() => y.value.length > 0), k = m(() => r.value ? s.value ? null : `Heroshot: Screenshot "${e.name}" not found in config` : "Heroshot: No manifest found. Add heroshot() plugin to vite config or pass manifest prop.");
100
- return k.value && typeof console < "u" && console.warn(k.value), (u, c) => s.value && x.value ? (v(), h("picture", {
99
+ }), M = h(() => y.value.length > 0), k = h(() => o.value ? r.value ? null : `Heroshot: Screenshot "${e.name}" not found in config` : "Heroshot: No manifest found. Add heroshot() plugin to vite config or pass manifest prop.");
100
+ return k.value && typeof console < "u" && console.warn(k.value), (i, c) => r.value && M.value ? (v(), m("picture", {
101
101
  key: 0,
102
- class: _(e.class)
102
+ class: x(e.class)
103
103
  }, [
104
- (v(!0), h(I, null, j(y.value, (i) => (v(), h("source", {
105
- key: `${i.viewport}-${t.value}`,
106
- srcset: i.srcset,
107
- media: i.media
108
- }, null, 8, W))), 128)),
104
+ (v(!0), m(I, null, j(y.value, (u) => (v(), m("source", {
105
+ key: `${u.viewport}-${t.value}`,
106
+ srcset: u.srcset,
107
+ media: u.media
108
+ }, null, 8, A))), 128)),
109
109
  D("img", {
110
110
  src: w.value,
111
111
  alt: n.alt,
112
112
  loading: "lazy"
113
113
  }, null, 8, Q)
114
- ], 2)) : s.value ? (v(), h("img", {
114
+ ], 2)) : r.value ? (v(), m("img", {
115
115
  key: 1,
116
116
  src: w.value,
117
117
  alt: n.alt,
118
- class: _(e.class),
118
+ class: x(e.class),
119
119
  loading: "lazy"
120
- }, null, 10, R)) : (v(), h("span", U, z(k.value), 1));
120
+ }, null, 10, R)) : (v(), m("span", U, z(k.value), 1));
121
121
  }
122
122
  });
123
123
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "heroshot",
3
- "version": "0.14.0",
3
+ "version": "0.14.2",
4
4
  "description": "Define your screenshots once, update them forever with one command",
5
5
  "type": "module",
6
6
  "author": "Ondrej Machala",