@themodcraft/addon-packs 1.1.0 → 1.1.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.
Files changed (46) hide show
  1. package/dist/addons/animations/animated-number/AnimatedNumber.js +1 -28
  2. package/dist/addons/animations/animated-number/index.js +1 -1
  3. package/dist/addons/animations/index.js +1 -1
  4. package/dist/addons/artstyles/colors/color-utils.js +1 -141
  5. package/dist/addons/artstyles/colors/index.js +1 -1
  6. package/dist/addons/artstyles/index.js +1 -1
  7. package/dist/addons/charts/index.js +1 -1
  8. package/dist/addons/charts/mini-bar-chart/MiniBarChart.js +1 -71
  9. package/dist/addons/charts/mini-bar-chart/index.js +1 -1
  10. package/dist/addons/configs/index.js +1 -1
  11. package/dist/addons/index.js +1 -8
  12. package/dist/addons/integrations/better-auth/better-auth.js +1 -11
  13. package/dist/addons/integrations/better-auth/index.js +1 -1
  14. package/dist/addons/integrations/index.js +1 -1
  15. package/dist/addons/paywall/Paywall.js +1 -144
  16. package/dist/addons/paywall/index.js +1 -1
  17. package/dist/addons/providers/auth/index.js +1 -1
  18. package/dist/addons/providers/index.js +1 -1
  19. package/dist/addons/providers/keyboard/index.js +1 -1
  20. package/dist/addons/providers/nexus/index.js +1 -1
  21. package/dist/addons/providers/runtime/auth-provider.js +1 -171
  22. package/dist/addons/providers/runtime/config-provider.js +1 -10
  23. package/dist/addons/providers/runtime/index.js +1 -6
  24. package/dist/addons/providers/runtime/keyboard-provider.js +1 -105
  25. package/dist/addons/providers/runtime/nexus-provider.js +1 -9
  26. package/dist/addons/providers/runtime/theme-provider.js +1 -130
  27. package/dist/addons/providers/runtime/ui-overlay-provider.js +1 -35
  28. package/dist/addons/providers/theme/index.js +1 -1
  29. package/dist/addons/themes/index.js +1 -1
  30. package/dist/artstyles.js +1 -1
  31. package/dist/configs/themodcraft-v3/index.js +1 -1
  32. package/dist/configs/themodcraft-v3/navigation.json +0 -0
  33. package/dist/configs/themodcraft-v3/sliderHome.json +0 -0
  34. package/dist/index.js +1 -9
  35. package/dist/paywall.js +1 -1
  36. package/dist/providers/auth.js +1 -1
  37. package/dist/providers/keyboard.js +1 -1
  38. package/dist/providers/nexus.js +1 -1
  39. package/dist/providers/theme.js +1 -1
  40. package/dist/providers.js +1 -1
  41. package/dist/theme-packs/themodcraft-v3/color-scheme.css +1 -106
  42. package/dist/theme-packs/themodcraft-v3/index.js +1 -1
  43. package/package.json +15 -13
  44. package/dist/addons/animations/animated-number/AnimatedNumber.types.js +0 -1
  45. package/dist/addons/charts/mini-bar-chart/MiniBarChart.types.js +0 -1
  46. package/dist/addons/paywall/Paywall.types.js +0 -1
@@ -1,29 +1,2 @@
1
1
  "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { useEffect, useRef, useState } from "react";
4
- export function AnimatedNumber({ className, durationMs = 800, format = (value) => String(Math.round(value)), value, }) {
5
- const [displayValue, setDisplayValue] = useState(value);
6
- const displayValueRef = useRef(value);
7
- useEffect(() => {
8
- displayValueRef.current = displayValue;
9
- }, [displayValue]);
10
- useEffect(() => {
11
- const start = performance.now();
12
- const from = displayValueRef.current;
13
- const delta = value - from;
14
- let frame = 0;
15
- function tick(now) {
16
- const progress = Math.min((now - start) / durationMs, 1);
17
- const eased = 1 - Math.pow(1 - progress, 3);
18
- const nextValue = from + delta * eased;
19
- displayValueRef.current = nextValue;
20
- setDisplayValue(nextValue);
21
- if (progress < 1) {
22
- frame = requestAnimationFrame(tick);
23
- }
24
- }
25
- frame = requestAnimationFrame(tick);
26
- return () => cancelAnimationFrame(frame);
27
- }, [durationMs, value]);
28
- return _jsx("span", { className: className, children: format(displayValue) });
29
- }
2
+ import{useState as r,useRef as n,useEffect as t}from"react";import{jsx as e}from"react/jsx-runtime";function a({className:a,durationMs:o=800,format:c=r=>String(Math.round(r)),value:m}){const[i,u]=r(m),s=n(m);return t(()=>{s.current=i},[i]),t(()=>{const r=performance.now(),n=s.current,t=m-n;let e=0;return e=requestAnimationFrame(function a(c){const m=Math.min((c-r)/o,1),i=1-Math.pow(1-m,3),f=n+t*i;s.current=f,u(f),m<1&&(e=requestAnimationFrame(a))}),()=>cancelAnimationFrame(e)},[o,m]),e("span",{className:a,children:c(i)})}export{a as AnimatedNumber};
@@ -1 +1 @@
1
- export { AnimatedNumber } from "./AnimatedNumber";
1
+ export{AnimatedNumber}from"./AnimatedNumber.js";
@@ -1 +1 @@
1
- export * from "@themodcraft/addon-animations";
1
+ export*from"@themodcraft/addon-animations";
@@ -1,141 +1 @@
1
- function clampChannel(value) {
2
- return Math.max(0, Math.min(255, Math.round(value)));
3
- }
4
- function clampAlpha(value) {
5
- return Math.max(0, Math.min(1, value));
6
- }
7
- function toHexChannel(value) {
8
- return clampChannel(value).toString(16).padStart(2, "0").toUpperCase();
9
- }
10
- function normalizeHex(hex) {
11
- const value = hex.trim();
12
- if (/^#([0-9A-Fa-f]{3})$/.test(value)) {
13
- const [, shortHex] = value.match(/^#([0-9A-Fa-f]{3})$/) ?? [];
14
- return `#${shortHex.split("").map((channel) => `${channel}${channel}`).join("")}`.toUpperCase();
15
- }
16
- if (/^#([0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/.test(value)) {
17
- return value.toUpperCase();
18
- }
19
- return null;
20
- }
21
- function hslToRgb({ h, l, s }) {
22
- const hue = ((h % 360) + 360) % 360;
23
- const saturation = Math.max(0, Math.min(100, s)) / 100;
24
- const lightness = Math.max(0, Math.min(100, l)) / 100;
25
- const chroma = (1 - Math.abs(2 * lightness - 1)) * saturation;
26
- const x = chroma * (1 - Math.abs(((hue / 60) % 2) - 1));
27
- const m = lightness - chroma / 2;
28
- let r = 0;
29
- let g = 0;
30
- let b = 0;
31
- if (hue < 60) {
32
- r = chroma;
33
- g = x;
34
- }
35
- else if (hue < 120) {
36
- r = x;
37
- g = chroma;
38
- }
39
- else if (hue < 180) {
40
- g = chroma;
41
- b = x;
42
- }
43
- else if (hue < 240) {
44
- g = x;
45
- b = chroma;
46
- }
47
- else if (hue < 300) {
48
- r = x;
49
- b = chroma;
50
- }
51
- else {
52
- r = chroma;
53
- b = x;
54
- }
55
- return {
56
- b: clampChannel((b + m) * 255),
57
- g: clampChannel((g + m) * 255),
58
- r: clampChannel((r + m) * 255),
59
- };
60
- }
61
- export function isValidHex(hex) {
62
- return Boolean(normalizeHex(hex));
63
- }
64
- export function rgbToHex(rgb) {
65
- const channels = rgb.match(/-?\d+(\.\d+)?/g)?.map(Number);
66
- if (!channels || channels.length < 3) {
67
- return null;
68
- }
69
- const [r, g, b] = channels;
70
- return `#${toHexChannel(r)}${toHexChannel(g)}${toHexChannel(b)}`;
71
- }
72
- export function rgbaToHex({ a, b, g, r }) {
73
- const alpha = typeof a === "number" ? toHexChannel(clampAlpha(a) * 255) : "";
74
- return `#${toHexChannel(r)}${toHexChannel(g)}${toHexChannel(b)}${alpha}`;
75
- }
76
- export function hexToRgb(hex) {
77
- const normalized = normalizeHex(hex);
78
- if (!normalized) {
79
- return null;
80
- }
81
- return {
82
- b: parseInt(normalized.slice(5, 7), 16),
83
- g: parseInt(normalized.slice(3, 5), 16),
84
- r: parseInt(normalized.slice(1, 3), 16),
85
- };
86
- }
87
- export function convertToHex(color) {
88
- if (typeof color === "string") {
89
- const normalizedHex = normalizeHex(color);
90
- if (normalizedHex) {
91
- return normalizedHex;
92
- }
93
- return rgbToHex(color);
94
- }
95
- if ("r" in color) {
96
- return rgbaToHex(color);
97
- }
98
- const rgb = hslToRgb(color);
99
- const alpha = typeof color.a === "number" ? toHexChannel(clampAlpha(color.a) * 255) : "";
100
- return `${rgbaToHex(rgb)}${alpha}`;
101
- }
102
- export function shiftColorLightness(hex, amount) {
103
- const rgb = hexToRgb(hex);
104
- if (!rgb) {
105
- return "#000000";
106
- }
107
- return rgbaToHex({
108
- b: rgb.b + amount,
109
- g: rgb.g + amount,
110
- r: rgb.r + amount,
111
- });
112
- }
113
- export function darken(hex, amount) {
114
- return shiftColorLightness(hex, -Math.abs(amount));
115
- }
116
- export function lighten(hex, amount) {
117
- return shiftColorLightness(hex, Math.abs(amount));
118
- }
119
- export function transformColor(hex, mode) {
120
- const rgb = hexToRgb(hex);
121
- if (!rgb) {
122
- return "#000000";
123
- }
124
- if (mode === "contrast") {
125
- const yiq = (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
126
- return yiq >= 128 ? "#000000" : "#FFFFFF";
127
- }
128
- if (mode === "invert") {
129
- return rgbaToHex({
130
- b: 255 - rgb.b,
131
- g: 255 - rgb.g,
132
- r: 255 - rgb.r,
133
- });
134
- }
135
- const luma = 0.2126 * rgb.r + 0.7152 * rgb.g + 0.0722 * rgb.b;
136
- return rgbaToHex({
137
- b: luma,
138
- g: luma,
139
- r: luma,
140
- });
141
- }
1
+ function t(t){return Math.max(0,Math.min(255,Math.round(t)))}function n(t){return Math.max(0,Math.min(1,t))}function r(n){return t(n).toString(16).padStart(2,"0").toUpperCase()}function e(t){const n=t.trim();if(/^#([0-9A-Fa-f]{3})$/.test(n)){const[,t]=n.match(/^#([0-9A-Fa-f]{3})$/)??[];return`#${t.split("").map(t=>`${t}${t}`).join("")}`.toUpperCase()}return/^#([0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/.test(n)?n.toUpperCase():null}function a(t){return Boolean(e(t))}function u(t){const n=t.match(/-?\d+(\.\d+)?/g)?.map(Number);if(!n||n.length<3)return null;const[e,a,u]=n;return`#${r(e)}${r(a)}${r(u)}`}function o({a:t,b:e,g:a,r:u}){const o="number"==typeof t?r(255*n(t)):"";return`#${r(u)}${r(a)}${r(e)}${o}`}function i(t){const n=e(t);return n?{b:parseInt(n.slice(5,7),16),g:parseInt(n.slice(3,5),16),r:parseInt(n.slice(1,3),16)}:null}function c(a){if("string"==typeof a){const t=e(a);return t||u(a)}if("r"in a)return o(a);const i=function({h:n,l:r,s:e}){const a=(n%360+360)%360,u=Math.max(0,Math.min(100,e))/100,o=Math.max(0,Math.min(100,r))/100,i=(1-Math.abs(2*o-1))*u,c=i*(1-Math.abs(a/60%2-1)),s=o-i/2;let f=0,b=0,h=0;return a<60?(f=i,b=c):a<120?(f=c,b=i):a<180?(b=i,h=c):a<240?(b=c,h=i):a<300?(f=c,h=i):(f=i,h=c),{b:t(255*(h+s)),g:t(255*(b+s)),r:t(255*(f+s))}}(a),c="number"==typeof a.a?r(255*n(a.a)):"";return`${o(i)}${c}`}function s(t,n){const r=i(t);return r?o({b:r.b+n,g:r.g+n,r:r.r+n}):"#000000"}function f(t,n){return s(t,-Math.abs(n))}function b(t,n){return s(t,Math.abs(n))}function h(t,n){const r=i(t);if(!r)return"#000000";if("contrast"===n){return(299*r.r+587*r.g+114*r.b)/1e3>=128?"#000000":"#FFFFFF"}if("invert"===n)return o({b:255-r.b,g:255-r.g,r:255-r.r});const e=.2126*r.r+.7152*r.g+.0722*r.b;return o({b:e,g:e,r:e})}export{c as convertToHex,f as darken,i as hexToRgb,a as isValidHex,b as lighten,u as rgbToHex,o as rgbaToHex,s as shiftColorLightness,h as transformColor};
@@ -1 +1 @@
1
- export { convertToHex, darken, hexToRgb, isValidHex, lighten, rgbaToHex, rgbToHex, shiftColorLightness, transformColor, } from "./color-utils";
1
+ export{convertToHex,darken,hexToRgb,isValidHex,lighten,rgbToHex,rgbaToHex,shiftColorLightness,transformColor}from"./color-utils.js";
@@ -1 +1 @@
1
- export * from "@themodcraft/addon-artstyles";
1
+ export*from"@themodcraft/addon-artstyles";
@@ -1 +1 @@
1
- export * from "@themodcraft/addon-charts";
1
+ export*from"@themodcraft/addon-charts";
@@ -1,72 +1,2 @@
1
1
  "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { BarElement, CategoryScale, Chart as ChartJS, LinearScale, Tooltip, } from "chart.js";
4
- import { useMemo } from "react";
5
- import { Bar } from "react-chartjs-2";
6
- ChartJS.register(CategoryScale, LinearScale, BarElement, Tooltip);
7
- function mergeChartOptions(baseOptions, chartOptions) {
8
- return {
9
- ...baseOptions,
10
- ...chartOptions,
11
- plugins: {
12
- ...baseOptions.plugins,
13
- ...chartOptions?.plugins,
14
- },
15
- scales: {
16
- ...baseOptions.scales,
17
- ...chartOptions?.scales,
18
- },
19
- };
20
- }
21
- export function MiniBarChart({ ariaLabel = "Mini bar chart", chartOptions, className, data, height, maxValue, showXAxis = false, showYAxis = true, }) {
22
- const chartMax = maxValue ?? Math.max(...data.map((item) => item.value), 1);
23
- const resolvedHeight = height ?? Math.max(data.length * 42, 120);
24
- const chartData = useMemo(() => ({
25
- labels: data.map((item) => item.label),
26
- datasets: [
27
- {
28
- backgroundColor: data.map((item) => item.color ?? "#0b63ce"),
29
- borderRadius: 6,
30
- borderSkipped: false,
31
- data: data.map((item) => item.value),
32
- label: ariaLabel,
33
- },
34
- ],
35
- }), [ariaLabel, data]);
36
- const options = useMemo(() => mergeChartOptions({
37
- animation: {
38
- duration: 220,
39
- },
40
- indexAxis: "y",
41
- maintainAspectRatio: false,
42
- plugins: {
43
- legend: {
44
- display: false,
45
- },
46
- tooltip: {
47
- enabled: true,
48
- },
49
- },
50
- responsive: true,
51
- scales: {
52
- x: {
53
- beginAtZero: true,
54
- display: showXAxis,
55
- grid: {
56
- display: showXAxis,
57
- },
58
- max: chartMax,
59
- ticks: {
60
- precision: 0,
61
- },
62
- },
63
- y: {
64
- display: showYAxis,
65
- grid: {
66
- display: false,
67
- },
68
- },
69
- },
70
- }, chartOptions), [chartMax, chartOptions, showXAxis, showYAxis]);
71
- return (_jsx("div", { "aria-label": ariaLabel, className: className, role: "img", style: { height: resolvedHeight }, children: _jsx(Bar, { data: chartData, options: options }) }));
72
- }
2
+ import{c as a}from"react/compiler-runtime";import{Chart as i,CategoryScale as t,LinearScale as e,BarElement as r,Tooltip as s}from"chart.js";import{Bar as n}from"react-chartjs-2";import{jsx as o}from"react/jsx-runtime";function l(i){const t=a(31),{ariaLabel:e,chartOptions:r,className:s,data:l,height:u,maxValue:g,showXAxis:h,showYAxis:b}=i,x=void 0===e?"Mini bar chart":e,f=void 0!==h&&h,y=void 0===b||b;let v;t[0]!==l||t[1]!==g?(v=g??Math.max(...l.map(m),1),t[0]=l,t[1]=g,t[2]=v):v=t[2];const A=v,j=u??Math.max(42*l.length,120);let k,M,w,N,R;t[3]!==l?(k=l.map(d),t[3]=l,t[4]=k):k=t[4],t[5]!==l?(M=l.map(p),t[5]=l,t[6]=M):M=t[6],t[7]!==l?(w=l.map(c),t[7]=l,t[8]=w):w=t[8],t[9]!==x||t[10]!==M||t[11]!==w?(N=[{backgroundColor:M,borderRadius:6,borderSkipped:!1,data:w,label:x}],t[9]=x,t[10]=M,t[11]=w,t[12]=N):N=t[12],t[13]!==k||t[14]!==N?(R={labels:k,datasets:N},t[13]=k,t[14]=N,t[15]=R):R=t[15];const C=R;let L;t[16]!==A||t[17]!==r||t[18]!==f||t[19]!==y?(L=function(a,i){return{...a,...i,plugins:{...a.plugins,...i?.plugins},scales:{...a.scales,...i?.scales}}}({animation:{duration:220},indexAxis:"y",maintainAspectRatio:!1,plugins:{legend:{display:!1},tooltip:{enabled:!0}},responsive:!0,scales:{x:{beginAtZero:!0,display:f,grid:{display:f},max:A,ticks:{precision:0}},y:{display:y,grid:{display:!1}}}},r),t[16]=A,t[17]=r,t[18]=f,t[19]=y,t[20]=L):L=t[20];const O=L;let S,V,X;return t[21]!==j?(S={height:j},t[21]=j,t[22]=S):S=t[22],t[23]!==C||t[24]!==O?(V=o(n,{data:C,options:O}),t[23]=C,t[24]=O,t[25]=V):V=t[25],t[26]!==x||t[27]!==s||t[28]!==S||t[29]!==V?(X=o("div",{"aria-label":x,className:s,role:"img",style:S,children:V}),t[26]=x,t[27]=s,t[28]=S,t[29]=V,t[30]=X):X=t[30],X}function c(a){return a.value}function p(a){return a.color??"#0b63ce"}function d(a){return a.label}function m(a){return a.value}i.register(t,e,r,s);export{l as MiniBarChart};
@@ -1 +1 @@
1
- export { MiniBarChart } from "./MiniBarChart";
1
+ export{MiniBarChart}from"./MiniBarChart.js";
@@ -1 +1 @@
1
- export * from "@themodcraft/addon-configs";
1
+ export*from"@themodcraft/addon-configs";
@@ -1,8 +1 @@
1
- export * from "./artstyles";
2
- export * from "./animations";
3
- export * from "./charts";
4
- export * from "./configs";
5
- export * from "./integrations";
6
- export * from "./paywall";
7
- export * from "./providers";
8
- export * from "./themes";
1
+ export*from"@themodcraft/addon-animations";export*from"@themodcraft/addon-artstyles";export*from"@themodcraft/addon-charts";export*from"@themodcraft/addon-configs";export*from"@themodcraft/addon-integrations";export*from"@themodcraft/addon-paywall";export*from"@themodcraft/addon-providers";export*from"@themodcraft/addon-themes";
@@ -1,11 +1 @@
1
- export function profileFromBetterAuthSession(session) {
2
- if (!session?.user) {
3
- return null;
4
- }
5
- return {
6
- email: session.user.email ?? null,
7
- image: session.user.image ?? null,
8
- name: session.user.name ?? null,
9
- username: session.user.username ?? null,
10
- };
11
- }
1
+ function e(e){return e?.user?{email:e.user.email??null,image:e.user.image??null,name:e.user.name??null,username:e.user.username??null}:null}export{e as profileFromBetterAuthSession};
@@ -1 +1 @@
1
- export * from "@themodcraft/addon-integrations/better-auth";
1
+ export*from"@themodcraft/addon-integrations/better-auth";
@@ -1 +1 @@
1
- export * from "@themodcraft/addon-integrations";
1
+ export*from"@themodcraft/addon-integrations";
@@ -1,145 +1,2 @@
1
1
  "use client";
2
- import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
3
- import { createContext, isValidElement, useCallback, useContext, useEffect, useMemo, useState, } from "react";
4
- const PaywallContext = createContext(null);
5
- function normalizeEntitlements(requiredEntitlements) {
6
- if (!requiredEntitlements) {
7
- return [];
8
- }
9
- return Array.isArray(requiredEntitlements)
10
- ? requiredEntitlements.filter(Boolean)
11
- : [requiredEntitlements].filter(Boolean);
12
- }
13
- function checkEntitlements(entitlements, requiredEntitlements, mode = "all") {
14
- const required = normalizeEntitlements(requiredEntitlements);
15
- if (!required.length) {
16
- return true;
17
- }
18
- if (mode === "any") {
19
- return required.some((entitlement) => entitlements.includes(entitlement));
20
- }
21
- return required.every((entitlement) => entitlements.includes(entitlement));
22
- }
23
- function missingEntitlements(entitlements, requiredEntitlements, mode = "all") {
24
- const required = normalizeEntitlements(requiredEntitlements);
25
- if (mode === "any" && required.some((entitlement) => entitlements.includes(entitlement))) {
26
- return [];
27
- }
28
- return required.filter((entitlement) => !entitlements.includes(entitlement));
29
- }
30
- function renderFallback(fallback, decision, actions) {
31
- if (typeof fallback === "function" && !isValidElement(fallback)) {
32
- return fallback(decision, actions);
33
- }
34
- return fallback;
35
- }
36
- function DefaultPaywallFallback({ decision, startCheckout, }) {
37
- const planLabel = decision.plan?.label ?? "Pro";
38
- return (_jsxs("div", { role: "group", style: { border: "1px solid var(--tmc-color-border, #d7dde5)", borderRadius: "8px", padding: "16px" }, children: [_jsxs("p", { style: { color: "var(--tmc-color-text, #111827)", fontWeight: 600, margin: 0 }, children: [planLabel, " access required"] }), _jsx("p", { style: { color: "var(--tmc-color-text-muted, #5f6b7a)", margin: "8px 0 0" }, children: "This package area is locked until the required entitlement is active." }), _jsx("button", { onClick: () => void startCheckout(), style: { background: "var(--tmc-color-accent, #0b63ce)", border: 0, borderRadius: "6px", color: "var(--tmc-color-accent-text, #ffffff)", cursor: "pointer", marginTop: "12px", padding: "8px 12px" }, type: "button", children: "Unlock" })] }));
39
- }
40
- export function PaywallProvider({ checkoutUrl, children, defaultFallback, entitlements = [], onCheckout, plans = [], resolveEntitlements, status = "ready", }) {
41
- const [resolvedEntitlements, setResolvedEntitlements] = useState(entitlements);
42
- const [resolvedStatus, setResolvedStatus] = useState(status);
43
- useEffect(() => {
44
- setResolvedEntitlements(entitlements);
45
- setResolvedStatus(status);
46
- }, [entitlements, status]);
47
- const refreshEntitlements = useCallback(async () => {
48
- if (!resolveEntitlements) {
49
- return resolvedEntitlements;
50
- }
51
- setResolvedStatus("loading");
52
- try {
53
- const nextEntitlements = await resolveEntitlements();
54
- setResolvedEntitlements(nextEntitlements);
55
- setResolvedStatus("ready");
56
- return nextEntitlements;
57
- }
58
- catch {
59
- setResolvedStatus("error");
60
- return [];
61
- }
62
- }, [resolveEntitlements, resolvedEntitlements]);
63
- useEffect(() => {
64
- if (!resolveEntitlements) {
65
- return;
66
- }
67
- void refreshEntitlements();
68
- }, [refreshEntitlements, resolveEntitlements]);
69
- const getDecision = useCallback((requiredEntitlements, mode = "all", planId) => {
70
- const required = normalizeEntitlements(requiredEntitlements);
71
- const plan = plans.find((currentPlan) => currentPlan.id === planId) ?? plans.find((currentPlan) => currentPlan.entitlements?.some((entitlement) => required.includes(entitlement)));
72
- const allowed = resolvedStatus === "ready" && checkEntitlements(resolvedEntitlements, required, mode);
73
- return {
74
- allowed,
75
- missingEntitlements: missingEntitlements(resolvedEntitlements, required, mode),
76
- plan,
77
- requiredEntitlements: required,
78
- status: resolvedStatus,
79
- };
80
- }, [plans, resolvedEntitlements, resolvedStatus]);
81
- const hasEntitlements = useCallback((requiredEntitlements, mode = "all") => (getDecision(requiredEntitlements, mode).allowed), [getDecision]);
82
- const startCheckout = useCallback(async (planId, decision) => {
83
- const plan = plans.find((currentPlan) => currentPlan.id === planId) ?? decision?.plan;
84
- const nextDecision = decision ?? getDecision(plan?.entitlements, "all", plan?.id);
85
- if (onCheckout) {
86
- await onCheckout(plan, nextDecision);
87
- return;
88
- }
89
- const url = plan?.checkoutUrl ?? checkoutUrl;
90
- if (url && typeof window !== "undefined") {
91
- window.location.href = url;
92
- }
93
- }, [checkoutUrl, getDecision, onCheckout, plans]);
94
- const value = useMemo(() => ({
95
- checkoutUrl,
96
- defaultFallback,
97
- entitlements: resolvedEntitlements,
98
- getDecision,
99
- hasEntitlements,
100
- plans,
101
- refreshEntitlements,
102
- startCheckout,
103
- status: resolvedStatus,
104
- }), [
105
- checkoutUrl,
106
- defaultFallback,
107
- getDecision,
108
- hasEntitlements,
109
- plans,
110
- refreshEntitlements,
111
- resolvedEntitlements,
112
- resolvedStatus,
113
- startCheckout,
114
- ]);
115
- return _jsx(PaywallContext.Provider, { value: value, children: children });
116
- }
117
- export function usePaywall() {
118
- const context = useContext(PaywallContext);
119
- if (!context) {
120
- throw new Error("usePaywall must be used inside PaywallProvider.");
121
- }
122
- return context;
123
- }
124
- export function useOptionalPaywall() {
125
- return useContext(PaywallContext);
126
- }
127
- export function PaywallGate({ children, fallback, loadingFallback = null, mode = "all", planId, required, }) {
128
- const paywall = usePaywall();
129
- const decision = paywall.getDecision(required, mode, planId);
130
- const actions = {
131
- refreshEntitlements: paywall.refreshEntitlements,
132
- startCheckout: () => paywall.startCheckout(planId, decision),
133
- };
134
- if (decision.status === "loading") {
135
- return loadingFallback;
136
- }
137
- if (decision.allowed) {
138
- return children;
139
- }
140
- const renderedFallback = renderFallback(fallback ?? paywall.defaultFallback, decision, actions);
141
- if (renderedFallback) {
142
- return renderedFallback;
143
- }
144
- return _jsx(DefaultPaywallFallback, { decision: decision, startCheckout: actions.startCheckout });
145
- }
2
+ import{c as e}from"react/compiler-runtime";import{useState as t,useEffect as n,useContext as r,isValidElement as o,createContext as l}from"react";import{jsx as i,jsxs as c}from"react/jsx-runtime";const a=l(null);function s(e){return e?Array.isArray(e)?e.filter(Boolean):[e].filter(Boolean):[]}function u(e,t,n="all"){const r=s(t);return"any"===n&&r.some(t=>e.includes(t))?[]:r.filter(t=>!e.includes(t))}function d(t){const n=e(13),{decision:r,startCheckout:o}=t,l=r.plan?.label??"Pro";let a,s,u,d,f,m,h,p;return n[0]===Symbol.for("react.memo_cache_sentinel")?(a={border:"1px solid var(--tmc-color-border, #d7dde5)",borderRadius:"8px",padding:"16px"},s={color:"var(--tmc-color-text, #111827)",fontWeight:600,margin:0},n[0]=a,n[1]=s):(a=n[0],s=n[1]),n[2]!==l?(u=c("p",{style:s,children:[l," access required"]}),n[2]=l,n[3]=u):u=n[3],n[4]===Symbol.for("react.memo_cache_sentinel")?(d=i("p",{style:{color:"var(--tmc-color-text-muted, #5f6b7a)",margin:"8px 0 0"},children:"This package area is locked until the required entitlement is active."}),n[4]=d):d=n[4],n[5]!==o?(f=()=>{o()},n[5]=o,n[6]=f):f=n[6],n[7]===Symbol.for("react.memo_cache_sentinel")?(m={background:"var(--tmc-color-accent, #0b63ce)",border:0,borderRadius:"6px",color:"var(--tmc-color-accent-text, #ffffff)",cursor:"pointer",marginTop:"12px",padding:"8px 12px"},n[7]=m):m=n[7],n[8]!==f?(h=i("button",{onClick:f,style:m,type:"button",children:"Unlock"}),n[8]=f,n[9]=h):h=n[9],n[10]!==u||n[11]!==h?(p=c("div",{role:"group",style:a,children:[u,d,h]}),n[10]=u,n[11]=h,n[12]=p):p=n[12],p}function f(r){const o=e(39),{checkoutUrl:l,children:c,defaultFallback:d,entitlements:f,onCheckout:m,plans:h,resolveEntitlements:p,status:y}=r;let b;o[0]!==f?(b=void 0===f?[]:f,o[0]=f,o[1]=b):b=o[1];const k=b;let v;o[2]!==h?(v=void 0===h?[]:h,o[2]=h,o[3]=v):v=o[3];const g=v,w=void 0===y?"ready":y,[x,C]=t(k),[_,E]=t(w);let P,S,q;o[4]!==k||o[5]!==w?(P=()=>{C(k),E(w)},S=[k,w],o[4]=k,o[5]=w,o[6]=P,o[7]=S):(P=o[6],S=o[7]),n(P,S),o[8]!==p||o[9]!==x?(q=async()=>{if(!p)return x;E("loading");try{const e=await p();return C(e),E("ready"),e}catch{return E("error"),[]}},o[8]=p,o[9]=x,o[10]=q):q=o[10];const F=q;let U,A,B;o[11]!==F||o[12]!==p?(A=()=>{p&&F()},U=[F,p],o[11]=F,o[12]=p,o[13]=U,o[14]=A):(U=o[13],A=o[14]),n(A,U),o[15]!==g||o[16]!==x||o[17]!==_?(B=(e,t,n)=>{const r=void 0===t?"all":t,o=s(e),l=g.find(e=>e.id===n)??g.find(e=>e.entitlements?.some(e=>o.includes(e))),i="ready"===_&&function(e,t,n="all"){const r=s(t);return!r.length||("any"===n?r.some(t=>e.includes(t)):r.every(t=>e.includes(t)))}(x,o,r);return{allowed:i,missingEntitlements:u(x,o,r),plan:l,requiredEntitlements:o,status:_}},o[15]=g,o[16]=x,o[17]=_,o[18]=B):B=o[18];const D=B;let R;o[19]!==D?(R=(e,t)=>D(e,void 0===t?"all":t).allowed,o[19]=D,o[20]=R):R=o[20];const T=R;let j;o[21]!==l||o[22]!==D||o[23]!==m||o[24]!==g?(j=async(e,t)=>{const n=g.find(t=>t.id===e)??t?.plan,r=t??D(n?.entitlements,"all",n?.id);if(m)return void await m(n,r);const o=n?.checkoutUrl??l;o&&"undefined"!=typeof window&&(window.location.href=o)},o[21]=l,o[22]=D,o[23]=m,o[24]=g,o[25]=j):j=o[25];const I=j;let W;o[26]!==l||o[27]!==d||o[28]!==D||o[29]!==T||o[30]!==g||o[31]!==F||o[32]!==x||o[33]!==_||o[34]!==I?(W={checkoutUrl:l,defaultFallback:d,entitlements:x,getDecision:D,hasEntitlements:T,plans:g,refreshEntitlements:F,startCheckout:I,status:_},o[26]=l,o[27]=d,o[28]=D,o[29]=T,o[30]=g,o[31]=F,o[32]=x,o[33]=_,o[34]=I,o[35]=W):W=o[35];const z=W;let G;return o[36]!==c||o[37]!==z?(G=i(a.Provider,{value:z,children:c}),o[36]=c,o[37]=z,o[38]=G):G=o[38],G}function m(){const e=r(a);if(!e)throw new Error("usePaywall must be used inside PaywallProvider.");return e}function h(){return r(a)}function p(t){const n=e(14),{children:r,fallback:l,loadingFallback:c,mode:a,planId:s,required:u}=t,f=void 0===c?null:c,h=void 0===a?"all":a,p=m();let y,b,k,v;if(n[0]!==r||n[1]!==l||n[2]!==f||n[3]!==h||n[4]!==p||n[5]!==s||n[6]!==u?(v=Symbol.for("react.early_return_sentinel"),b=p.getDecision(u,h,s),y={refreshEntitlements:p.refreshEntitlements,startCheckout:()=>p.startCheckout(s,b)},"loading"!==b.status?b.allowed?v=r:k=function(e,t,n){return"function"!=typeof e||o(e)?e:e(t,n)}(l??p.defaultFallback,b,y):v=f,n[0]=r,n[1]=l,n[2]=f,n[3]=h,n[4]=p,n[5]=s,n[6]=u,n[7]=y,n[8]=b,n[9]=k,n[10]=v):(y=n[7],b=n[8],k=n[9],v=n[10]),v!==Symbol.for("react.early_return_sentinel"))return v;if(k)return k;let g;return n[11]!==y.startCheckout||n[12]!==b?(g=i(d,{decision:b,startCheckout:y.startCheckout}),n[11]=y.startCheckout,n[12]=b,n[13]=g):g=n[13],g}export{p as PaywallGate,f as PaywallProvider,h as useOptionalPaywall,m as usePaywall};
@@ -1 +1 @@
1
- export * from "@themodcraft/addon-paywall";
1
+ export*from"@themodcraft/addon-paywall";
@@ -1 +1 @@
1
- export * from "@themodcraft/addon-providers/auth";
1
+ export*from"@themodcraft/addon-providers/auth";
@@ -1 +1 @@
1
- export * from "@themodcraft/addon-providers";
1
+ export*from"@themodcraft/addon-providers";
@@ -1 +1 @@
1
- export * from "@themodcraft/addon-providers/keyboard";
1
+ export*from"@themodcraft/addon-providers/keyboard";
@@ -1 +1 @@
1
- export * from "@themodcraft/addon-providers/nexus";
1
+ export*from"@themodcraft/addon-providers/nexus";