heroshot 0.14.0 → 0.14.1

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,26 +1,34 @@
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) {
2
+ import y from "@heroshot/manifest";
3
+ import { jsx as h, jsxs as I } from "react/jsx-runtime";
4
+ import $, { createContext as j, useContext as C, useMemo as g, useState as L, useEffect as z } from "react";
5
+ let x = null;
6
+ function N(e) {
7
+ x = e;
8
+ }
9
+ function O() {
10
+ return x;
11
+ }
12
+ function R(e, t) {
5
13
  return e.screenshots[t];
6
14
  }
7
- function N(e, t = {}) {
15
+ function V(e, t = {}) {
8
16
  const { slug: a, format: s } = e, { viewport: r, colorScheme: c } = t, n = [a];
9
17
  r && n.push(r), c && n.push(c);
10
18
  const i = s === "jpeg" ? "jpg" : "png";
11
19
  return `${n.join("-")}.${i}`;
12
20
  }
13
- function O(e, t, a = {}) {
14
- const s = N(t, a);
21
+ function A(e, t, a = {}) {
22
+ const s = V(t, a);
15
23
  return `${e.outputDirectory}/${s}`;
16
24
  }
17
25
  function H(e, t, a) {
18
- const { colorSchemes: s } = t, r = s.length > 0, c = (i) => O(e, t, { viewport: a, colorScheme: i }), n = {
26
+ const { colorSchemes: s } = t, r = s.length > 0, c = (i) => A(e, t, { viewport: a, colorScheme: i }), n = {
19
27
  default: r ? c("light") : c()
20
28
  };
21
29
  return s.includes("light") && (n.light = c("light")), s.includes("dark") && (n.dark = c("dark")), n;
22
30
  }
23
- function R(e, t) {
31
+ function F(e, t) {
24
32
  const a = H(e, t), s = {};
25
33
  for (const r of t.viewports)
26
34
  s[r] = H(e, t, r);
@@ -29,15 +37,8 @@ function R(e, t) {
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
43
  children: t
43
44
  }) {
@@ -48,9 +49,9 @@ function S() {
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(() => {
52
+ function W() {
53
+ const e = $.useRef(!1), [t, a] = L(() => S().isDark);
54
+ return z(() => {
54
55
  const s = S();
55
56
  e.current = s.hasThemeHandling;
56
57
  const r = () => {
@@ -77,13 +78,13 @@ const k = {
77
78
  tablet: 768,
78
79
  desktop: 1280
79
80
  };
80
- function q({
81
+ function J({
81
82
  name: e,
82
83
  alt: t = "",
83
84
  manifest: a,
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 r = W(), c = C(D), n = a ?? c ?? O(), i = g(() => n ? R(n, e) : null, [n, e]), u = g(() => !i || !n ? null : F(n, i), [n, i]), v = g(() => {
87
88
  if (!u) return "";
88
89
  const { light: o, dark: f } = u;
89
90
  return r && f ? f : !r && o ? o : u.default;
@@ -115,7 +116,7 @@ function q({
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__ */ I("picture", { className: s, children: [
119
120
  T.map((o) => /* @__PURE__ */ h(
120
121
  "source",
121
122
  {
@@ -127,8 +128,11 @@ function q({
127
128
  /* @__PURE__ */ h("img", { src: v, alt: t, loading: "lazy" })
128
129
  ] }) : /* @__PURE__ */ h("img", { src: v, alt: t, 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,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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "heroshot",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
4
4
  "description": "Define your screenshots once, update them forever with one command",
5
5
  "type": "module",
6
6
  "author": "Ondrej Machala",