调整涉及WASM内结构体的实例化位置。

This commit is contained in:
徐涛 2025-02-10 16:43:30 +08:00
parent 3eae8116e7
commit 2ddffe1b12
7 changed files with 20 additions and 30 deletions

View File

@ -23,8 +23,7 @@ export function useColorFunction(): ColorFunctionContextType {
} }
export function ColorFunctionProvider({ children }: WasmProviderProps) { export function ColorFunctionProvider({ children }: WasmProviderProps) {
//@ts-expect-error TS2503 const [wasmInstance, setWasmInstance] = useState<typeof funcs | null>(null);
const [wasmInstance, setWasmInstance] = useState<Wasm.InitOutput | null>(null);
const [isPending, startTransition] = useTransition(); const [isPending, startTransition] = useTransition();
const [error, setError] = useState<Error | null>(null); const [error, setError] = useState<Error | null>(null);
@ -43,6 +42,7 @@ export function ColorFunctionProvider({ children }: WasmProviderProps) {
try { try {
await init(); await init();
setWasmInstance(funcs); setWasmInstance(funcs);
console.debug('[Load WASM]', 'Loaded');
} catch (e) { } catch (e) {
console.error('[Load WASM]', e); console.error('[Load WASM]', e);
setError(e); setError(e);

View File

@ -4,18 +4,16 @@ import { useColorFunction } from '../../ColorFunctionContext';
import styles from './CompareLayout.module.css'; import styles from './CompareLayout.module.css';
import { CompareMethodProps } from './share-props'; import { CompareMethodProps } from './share-props';
const defaultCompareResult: HctDiffference = new HctDiffference(
new Differ(0, 0),
new Differ(0, 0),
new Differ(0, 0),
);
export function HCTCompare({ export function HCTCompare({
basic = '000000', basic = '000000',
compare = '000000', compare = '000000',
mode = 'absolute', mode = 'absolute',
}: CompareMethodProps) { }: CompareMethodProps) {
const { colorFn } = useColorFunction(); const { colorFn } = useColorFunction();
const defaultCompareResult: HctDiffference = useMemo(
() => new HctDiffference(new Differ(0, 0), new Differ(0, 0), new Differ(0, 0)),
[],
);
const differ = useMemo(() => { const differ = useMemo(() => {
if (!colorFn) { if (!colorFn) {
return defaultCompareResult; return defaultCompareResult;

View File

@ -4,18 +4,16 @@ import { useColorFunction } from '../../ColorFunctionContext';
import styles from './CompareLayout.module.css'; import styles from './CompareLayout.module.css';
import { CompareMethodProps } from './share-props'; import { CompareMethodProps } from './share-props';
const defaultCompareResult: HSLDifference = new HSLDifference(
new Differ(0, 0),
new Differ(0, 0),
new Differ(0, 0),
);
export function HSLCompare({ export function HSLCompare({
basic = '000000', basic = '000000',
compare = '000000', compare = '000000',
mode = 'absolute', mode = 'absolute',
}: CompareMethodProps) { }: CompareMethodProps) {
const { colorFn } = useColorFunction(); const { colorFn } = useColorFunction();
const defaultCompareResult: HSLDifference = useMemo(
() => new HSLDifference(new Differ(0, 0), new Differ(0, 0), new Differ(0, 0)),
[],
);
const differ = useMemo(() => { const differ = useMemo(() => {
if (!colorFn) { if (!colorFn) {
return defaultCompareResult; return defaultCompareResult;

View File

@ -4,18 +4,16 @@ import { useColorFunction } from '../../ColorFunctionContext';
import styles from './CompareLayout.module.css'; import styles from './CompareLayout.module.css';
import { CompareMethodProps } from './share-props'; import { CompareMethodProps } from './share-props';
const defaultCompareResult: OklchDifference = new OklchDifference(
new Differ(0, 0),
new Differ(0, 0),
new Differ(0, 0),
);
export function OklchCompare({ export function OklchCompare({
basic = '000000', basic = '000000',
compare = '000000', compare = '000000',
mode = 'absolute', mode = 'absolute',
}: CompareMethodProps) { }: CompareMethodProps) {
const { colorFn } = useColorFunction(); const { colorFn } = useColorFunction();
const defaultCompareResult: OklchDifference = useMemo(
() => new OklchDifference(new Differ(0, 0), new Differ(0, 0), new Differ(0, 0)),
[],
);
const differ = useMemo(() => { const differ = useMemo(() => {
if (!colorFn) { if (!colorFn) {
return defaultCompareResult; return defaultCompareResult;

View File

@ -4,18 +4,16 @@ import { useColorFunction } from '../../ColorFunctionContext';
import styles from './CompareLayout.module.css'; import styles from './CompareLayout.module.css';
import { CompareMethodProps } from './share-props'; import { CompareMethodProps } from './share-props';
const defaultCompareResult: RGBDifference = new RGBDifference(
new Differ(0, 0),
new Differ(0, 0),
new Differ(0, 0),
);
export function RGBCompare({ export function RGBCompare({
basic = '000000', basic = '000000',
compare = '000000', compare = '000000',
mode = 'absolute', mode = 'absolute',
}: CompareMethodProps) { }: CompareMethodProps) {
const { colorFn } = useColorFunction(); const { colorFn } = useColorFunction();
const defaultCompareResult: RGBDifference = useMemo(
() => new RGBDifference(new Differ(0, 0), new Differ(0, 0), new Differ(0, 0)),
[],
);
const differ = useMemo(() => { const differ = useMemo(() => {
if (!colorFn) { if (!colorFn) {
return defaultCompareResult; return defaultCompareResult;

View File

@ -5,10 +5,9 @@ import { useColorFunction } from '../../ColorFunctionContext';
import styles from './CompareLayout.module.css'; import styles from './CompareLayout.module.css';
import { CompareMethodProps } from './share-props'; import { CompareMethodProps } from './share-props';
const defaultMixResult: MixReversing = new MixReversing(0, 0, 0, 0);
export function ShadeScale({ basic = '000000', compare = '000000' }: CompareMethodProps) { export function ShadeScale({ basic = '000000', compare = '000000' }: CompareMethodProps) {
const { colorFn } = useColorFunction(); const { colorFn } = useColorFunction();
const defaultMixResult: MixReversing = useMemo(() => new MixReversing(0, 0, 0, 0), []);
const mixFactors = useMemo(() => { const mixFactors = useMemo(() => {
if (!colorFn) { if (!colorFn) {
return defaultMixResult; return defaultMixResult;

View File

@ -5,10 +5,9 @@ import { useColorFunction } from '../../ColorFunctionContext';
import styles from './CompareLayout.module.css'; import styles from './CompareLayout.module.css';
import { CompareMethodProps } from './share-props'; import { CompareMethodProps } from './share-props';
const defaultMixResult: MixReversing = new MixReversing(0, 0, 0, 0);
export function TintScale({ basic = '000000', compare = '000000' }: CompareMethodProps) { export function TintScale({ basic = '000000', compare = '000000' }: CompareMethodProps) {
const { colorFn } = useColorFunction(); const { colorFn } = useColorFunction();
const defaultMixResult: MixReversing = useMemo(() => new MixReversing(0, 0, 0, 0), []);
const mixFactors = useMemo(() => { const mixFactors = useMemo(() => {
if (!colorFn) { if (!colorFn) {
return defaultMixResult; return defaultMixResult;