@particle-network/connectkit
Version:
214 lines (207 loc) • 7.68 kB
JavaScript
"use client";
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __esm = (fn, res) => function __init() {
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/utils/theme.ts
function getSystemMode() {
if (typeof window !== "undefined" && window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
return "dark";
} else {
return "light";
}
}
var init_theme = __esm({
"src/utils/theme.ts"() {
"use strict";
}
});
// src/utils/deepEqual.ts
function deepEqual(a, b) {
if (a === b)
return true;
if (a && b && typeof a === "object" && typeof b === "object") {
if (a.constructor !== b.constructor)
return false;
let length;
let i;
if (Array.isArray(a) && Array.isArray(b)) {
length = a.length;
if (length !== b.length)
return false;
for (i = length; i-- !== 0; )
if (!deepEqual(a[i], b[i]))
return false;
return true;
}
if (a.valueOf !== Object.prototype.valueOf)
return a.valueOf() === b.valueOf();
if (a.toString !== Object.prototype.toString)
return a.toString() === b.toString();
const keys = Object.keys(a);
length = keys.length;
if (length !== Object.keys(b).length)
return false;
for (i = length; i-- !== 0; )
if (!Object.prototype.hasOwnProperty.call(b, keys[i]))
return false;
for (i = length; i-- !== 0; ) {
const key = keys[i];
if (key && !deepEqual(a[key], b[key]))
return false;
}
return true;
}
return a !== a && b !== b;
}
var init_deepEqual = __esm({
"src/utils/deepEqual.ts"() {
"use strict";
}
});
// src/context/index.tsx
var import_react, import_jsx_runtime, Context, useContext;
var init_context = __esm({
"src/context/index.tsx"() {
"use strict";
import_react = __toESM(require("react"), 1);
import_jsx_runtime = require("react/jsx-runtime");
Context = (0, import_react.createContext)(null);
useContext = () => {
const context = import_react.default.useContext(Context);
if (!context)
throw Error("ConnectKit Hook must be inside a Provider.");
return context;
};
}
});
// src/hooks/useAppearance.ts
function getAppearance(config) {
const appearance = { ...config.appearanceStore.getState() };
if (deepEqual(previousAppearance, appearance))
return previousAppearance;
previousAppearance = appearance;
return appearance;
}
function useAppearance(config) {
if (!config) {
const { config: globalConfig } = useContext();
config = globalConfig;
}
const setAppearance = (0, import_react2.useCallback)(
(value) => {
config.appearanceStore.setState(value || {}, true);
},
[config.appearanceStore]
);
const appearance = (0, import_react2.useSyncExternalStore)(
config.appearanceStore.subscribe,
() => getAppearance(config),
() => getAppearance(config)
);
return {
appearance,
setAppearance
};
}
var import_react2, previousAppearance;
var init_useAppearance = __esm({
"src/hooks/useAppearance.ts"() {
"use strict";
import_react2 = require("react");
init_context();
init_deepEqual();
previousAppearance = {};
}
});
// src/hooks/useIconColor.ts
var import_react3, useIconColor, useIconColor_default;
var init_useIconColor = __esm({
"src/hooks/useIconColor.ts"() {
"use strict";
import_react3 = require("react");
init_theme();
init_useAppearance();
useIconColor = () => {
const [currentMode, setCurrentMode] = (0, import_react3.useState)();
const { appearance } = useAppearance();
(0, import_react3.useEffect)(() => {
if (appearance?.mode && appearance?.mode !== "auto") {
setCurrentMode(appearance?.mode);
} else {
setCurrentMode(getSystemMode());
}
}, [appearance?.mode]);
const foreground = (0, import_react3.useMemo)(() => {
if (currentMode === "dark") {
return "#000000";
} else {
return "#ffffff";
}
}, [currentMode]);
const background = (0, import_react3.useMemo)(() => {
if (currentMode === "dark") {
return "#ffffff";
} else {
return "#000000";
}
}, [currentMode]);
return { foreground, background, currentMode };
};
useIconColor_default = useIconColor;
}
});
// src/assets/social/github.tsx
var github_exports = {};
__export(github_exports, {
default: () => github_default
});
module.exports = __toCommonJS(github_exports);
var import_jsx_runtime2, Github, github_default;
var init_github = __esm({
"src/assets/social/github.tsx"() {
init_useIconColor();
import_jsx_runtime2 = require("react/jsx-runtime");
Github = () => {
const { foreground, background } = useIconColor_default();
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { width: "22", height: "22", viewBox: "0 0 22 22", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { width: "22", height: "22", rx: "11", fill: foreground }),
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
"path",
{
fillRule: "evenodd",
clipRule: "evenodd",
d: "M10.999 0C4.92483 0 0 4.92483 0 11.0003C0 15.8603 3.15154 19.9829 7.52264 21.4382C8.07299 21.5388 8.27355 21.1991 8.27355 20.9074C8.27355 20.6467 8.2641 19.9546 8.25869 19.0369C5.19899 19.7013 4.55342 17.562 4.55342 17.562C4.05304 16.2918 3.33184 15.9535 3.33184 15.9535C2.3331 15.2708 3.40747 15.2843 3.40747 15.2843C4.51156 15.3627 5.0923 16.4181 5.0923 16.4181C6.07348 18.0989 7.66715 17.6134 8.29381 17.3325C8.39375 16.6214 8.67737 16.1365 8.99205 15.8617C6.54956 15.5841 3.98146 14.6401 3.98146 10.425C3.98146 9.22435 4.41026 8.24249 5.11391 7.47334C5.00046 7.19512 4.62298 6.07686 5.22128 4.5622C5.22128 4.5622 6.14506 4.26643 8.24654 5.68992C9.12373 5.44614 10.0651 5.32392 11.0003 5.31987C11.9343 5.32392 12.8756 5.44614 13.7541 5.68992C15.8543 4.26643 16.776 4.5622 16.776 4.5622C17.3763 6.07686 16.9989 7.19512 16.8854 7.47334C17.5904 8.24249 18.0165 9.22435 18.0165 10.425C18.0165 14.6509 15.4444 15.5808 12.9938 15.8529C13.3888 16.1926 13.7406 16.8638 13.7406 17.8902C13.7406 19.3603 13.7271 20.5468 13.7271 20.9074C13.7271 21.2018 13.925 21.5442 14.4834 21.4368C18.8512 19.9789 22 15.859 22 11.0003C22 4.92483 17.0745 0 10.999 0Z",
fill: background
}
)
] });
};
github_default = Github;
}
});
init_github();
//# sourceMappingURL=github.cjs.map