Skip to content

Commit

Permalink
Expose context in BaseValue (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrezero authored Jan 24, 2025
1 parent f599006 commit 2cf6d7e
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { BaseValueAbstract, DecisionValueContext } from '../../types';

export const createBaseValue = (context: DecisionValueContext): BaseValueAbstract => ({
context: () => context,
});
2 changes: 2 additions & 0 deletions packages/libs/designer-decisions/src/primitives/base/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @index(['./*.{ts,tsx}', './!(private|parts|functions)*/index.{ts,tsx}'], f => `export * from '${f.path.replace(/\/index$/, '')}';`)
export * from './createBaseValue';
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { DecisionValueContext, OklabChromaScale, OklabChromaValue } from '../../../types';
import { createBaseValue } from '../../base';
import { createItemSet } from '../../set';

export const createOklabChromaScale = (
Expand All @@ -10,6 +11,7 @@ export const createOklabChromaScale = (
const items = createItemSet(input);

return {
...createBaseValue(context),
get: () => items,
};
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ColorOklabChroma, DecisionValueContext, OklabChromaValue } from '../../../types';
import { createBaseValue } from '../../base';
import { createColorValue } from '../value';

import { resolveOklabChromaValue } from './resolveOklabChromaValue';
Expand All @@ -12,6 +13,7 @@ export const createOklabChromaValue = (
const value = resolveOklabChromaValue(context, input);

return {
...createBaseValue(context),
get: () => value,
toColor: components => {
const { h, l } = components;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { DecisionValueContext, OklabHueSet, OklabHueValue } from '../../../types';
import { createBaseValue } from '../../base';
import { createItemSet } from '../../set';

export const createOklabHueSet = (
Expand All @@ -10,6 +11,7 @@ export const createOklabHueSet = (
const items = createItemSet(input);

return {
...createBaseValue(context),
get: () => items,
};
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ColorOklabHue, DecisionValueContext, OklabHueValue } from '../../../types';
import { createBaseValue } from '../../base';
import { createColorValue } from '../value';

import { resolveOklabHueValue } from './resolveOklabHueValue';
Expand All @@ -12,6 +13,7 @@ export const createOklabHueValue = (
const value = resolveOklabHueValue(context, input);

return {
...createBaseValue(context),
get: () => value,
toColor: components => {
const { l, c } = components;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
OklabLightnessScale,
OklabLightnessValue,
} from '../../../types';
import { createBaseValue } from '../../base';
import { createItemSet } from '../../set';

export const createOklabLightnessScale = (
Expand All @@ -14,6 +15,7 @@ export const createOklabLightnessScale = (
const items = createItemSet(input);

return {
...createBaseValue(context),
get: () => items,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
DecisionValueContext,
OklabLightnessValue,
} from '../../../types';
import { createBaseValue } from '../../base';
import { createColorValue } from '../value';

import { resolveOklabLightnessValue } from './resolveOklabLightnessValue';
Expand All @@ -16,6 +17,7 @@ export const createOklabLightnessValue = (
const value = resolveOklabLightnessValue(context, input);

return {
...createBaseValue(context),
get: () => value,
toColor: components => {
const { c, h } = components;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ColorSet, ColorValue, DecisionValueContext } from '../../../types';
import { createBaseValue } from '../../base';
import { createItemSet } from '../../set';

export const createColorSet = (context: DecisionValueContext, input: ColorValue[]): ColorSet => {
Expand All @@ -7,6 +8,7 @@ export const createColorSet = (context: DecisionValueContext, input: ColorValue[
const items = createItemSet(input);

return {
...createBaseValue(context),
get: () => items,
};
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { DecisionValueContext, SRGBHueSet, SRGBHueValue } from '../../../types';
import { createBaseValue } from '../../base';
import { createItemSet } from '../../set';

export const createSRGBHueSet = (
Expand All @@ -10,6 +11,7 @@ export const createSRGBHueSet = (
const items = createItemSet(input);

return {
...createBaseValue(context),
get: () => items,
};
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ColorSRGBHue, DecisionValueContext, SRGBHueValue } from '../../../types';
import { createBaseValue } from '../../base';
import { createColorValue } from '../value';

import { resolveSRGBHueValue } from './resolveSRGBHueValue';
Expand All @@ -12,6 +13,7 @@ export const createSRGBHueValue = (
const value = resolveSRGBHueValue(context, input);

return {
...createBaseValue(context),
get: () => value,
toColor: components => {
const { s, l } = components;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { DecisionValueContext, SRGBLightnessScale, SRGBLightnessValue } from '../../../types';
import { createBaseValue } from '../../base';
import { createItemSet } from '../../set';

export const createSRGBLightnessScale = (
Expand All @@ -10,6 +11,7 @@ export const createSRGBLightnessScale = (
const items = createItemSet(input);

return {
...createBaseValue(context),
get: () => items,
};
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ColorSRGBLightness, DecisionValueContext, SRGBLightnessValue } from '../../../types';
import { createBaseValue } from '../../base';
import { createColorValue } from '../value';

import { resolveSRGBLightnessValue } from './resolveSRGBLightnessValue';
Expand All @@ -12,6 +13,7 @@ export const createSRGBLightnessValue = (
const value = resolveSRGBLightnessValue(context, input);

return {
...createBaseValue(context),
get: () => value,
toColor: components => {
const { h, s } = components;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
SRGBSaturationScale,
SRGBSaturationValue,
} from '../../../types';
import { createBaseValue } from '../../base';
import { createItemSet } from '../../set';

export const createSRGBSaturationScale = (
Expand All @@ -14,6 +15,7 @@ export const createSRGBSaturationScale = (
const items = createItemSet(input);

return {
...createBaseValue(context),
get: () => items,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
DecisionValueContext,
SRGBSaturationValue,
} from '../../../types';
import { createBaseValue } from '../../base';
import { createColorValue } from '../value';

import { resolveSRGBSaturationValue } from './resolveSRGBSaturationValue';
Expand All @@ -16,6 +17,7 @@ export const createSRGBSaturationValue = (
const value = resolveSRGBSaturationValue(context, input);

return {
...createBaseValue(context),
get: () => value,
toColor: components => {
const { h, l } = components;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
ColorValue,
DecisionValueContext,
} from '../../../types';
import { createBaseValue } from '../../base';

import { resolveColorValue } from './resolveColorValue';

Expand Down Expand Up @@ -53,6 +54,7 @@ export const createColorValue = (
};

return {
...createBaseValue(context),
get: () => value,
toObject,
toString,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { DecisionValueContext, SpaceScale, SpaceValue } from '../../../types';
import { createBaseValue } from '../../base';
import { createItemSet } from '../../set';

export const createSpaceScale = (
Expand All @@ -10,6 +11,7 @@ export const createSpaceScale = (
const items = createItemSet(input);

return {
...createBaseValue(context),
get: () => items,
};
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { DecisionValueContext, SpaceInputValue, SpaceValue } from '../../../types';
import { createBaseValue } from '../../base';

import { resolveSpaceValue } from './resolveSpaceValue';

Expand All @@ -11,6 +12,7 @@ export const createSpaceValue = (
const value = resolveSpaceValue(context, input);

return {
...createBaseValue(context),
get: () => String(value.value) + value.units,
getValueWithUnits: () => value,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export type BaseValue<T> = {
import type { DecisionValueContext } from '../decision-values';

export type BaseValueAbstract = {
context(): DecisionValueContext;
};

export type BaseValue<T> = BaseValueAbstract & {
get(): T;
};

Expand Down

0 comments on commit 2cf6d7e

Please sign in to comment.