@ankhorage/zora 0.12.0 → 0.12.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.
- package/CHANGELOG.md +12 -0
- package/dist/internal/color/harmony.d.ts +12 -0
- package/dist/internal/color/harmony.d.ts.map +1 -0
- package/dist/internal/color/harmony.js +69 -0
- package/dist/internal/color/harmony.js.map +1 -0
- package/dist/internal/color/hue.d.ts +3 -0
- package/dist/internal/color/hue.d.ts.map +1 -0
- package/dist/internal/color/hue.js +7 -0
- package/dist/internal/color/hue.js.map +1 -0
- package/dist/internal/color/index.d.ts +4 -0
- package/dist/internal/color/index.d.ts.map +1 -1
- package/dist/internal/color/index.js +4 -0
- package/dist/internal/color/index.js.map +1 -1
- package/dist/internal/color/oklch.d.ts.map +1 -1
- package/dist/internal/color/oklch.js +1 -4
- package/dist/internal/color/oklch.js.map +1 -1
- package/dist/internal/color/roleHues.d.ts +15 -0
- package/dist/internal/color/roleHues.d.ts.map +1 -0
- package/dist/internal/color/roleHues.js +103 -0
- package/dist/internal/color/roleHues.js.map +1 -0
- package/dist/internal/color/scales.d.ts +10 -0
- package/dist/internal/color/scales.d.ts.map +1 -0
- package/dist/internal/color/scales.js +110 -0
- package/dist/internal/color/scales.js.map +1 -0
- package/dist/internal/color/types.d.ts +4 -0
- package/dist/internal/color/types.d.ts.map +1 -1
- package/dist/internal/color/types.js +3 -1
- package/dist/internal/color/types.js.map +1 -1
- package/package.json +1 -1
- package/src/internal/color/harmony.test.ts +145 -0
- package/src/internal/color/harmony.ts +96 -0
- package/src/internal/color/hue.test.ts +28 -0
- package/src/internal/color/hue.ts +7 -0
- package/src/internal/color/index.ts +20 -0
- package/src/internal/color/oklch.ts +1 -5
- package/src/internal/color/roleHues.test.ts +197 -0
- package/src/internal/color/roleHues.ts +142 -0
- package/src/internal/color/scales.test.ts +151 -0
- package/src/internal/color/scales.ts +145 -0
- package/src/internal/color/types.ts +10 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.12.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- da31347: Adds internal hue-role assignment for future ZORA theme generation work.
|
|
8
|
+
|
|
9
|
+
## 0.12.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 35c4046: Adds internal harmony hue-slot computation for future ZORA theme generation work.
|
|
14
|
+
|
|
3
15
|
## 0.12.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ZoraColorHarmony, ZoraHexColor } from '../../theme/types';
|
|
2
|
+
export type ZoraHarmonySlotId = 'base' | 'a' | 'b' | 'c';
|
|
3
|
+
export interface ZoraHarmonySlot {
|
|
4
|
+
id: ZoraHarmonySlotId;
|
|
5
|
+
hue: number;
|
|
6
|
+
}
|
|
7
|
+
export interface ZoraComputedHarmony {
|
|
8
|
+
kind: ZoraColorHarmony;
|
|
9
|
+
orderedSlots: readonly ZoraHarmonySlot[];
|
|
10
|
+
}
|
|
11
|
+
export declare function computeZoraHarmony(seed: ZoraHexColor, harmony: ZoraColorHarmony): ZoraComputedHarmony;
|
|
12
|
+
//# sourceMappingURL=harmony.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harmony.d.ts","sourceRoot":"","sources":["../../../src/internal/color/harmony.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAIxE,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAEzD,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,iBAAiB,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,gBAAgB,CAAC;IACvB,YAAY,EAAE,SAAS,eAAe,EAAE,CAAC;CAC1C;AAmBD,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE,gBAAgB,GACxB,mBAAmB,CA2DrB"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { normalizeHueDegrees, rotateHueDegrees } from './hue';
|
|
2
|
+
import { parseHexToOklch } from './oklch';
|
|
3
|
+
const DEFAULT_HARMONY_HUE_DEGREES = 260;
|
|
4
|
+
const MIN_SEED_CHROMA_FOR_HARMONY_HUE = 0.03;
|
|
5
|
+
function createSlot(id, hue) {
|
|
6
|
+
return { id, hue: normalizeHueDegrees(hue) };
|
|
7
|
+
}
|
|
8
|
+
function resolveSeedHueDegrees(seed) {
|
|
9
|
+
const parsed = parseHexToOklch(seed);
|
|
10
|
+
if (!Number.isFinite(parsed.h) || parsed.c < MIN_SEED_CHROMA_FOR_HARMONY_HUE) {
|
|
11
|
+
return DEFAULT_HARMONY_HUE_DEGREES;
|
|
12
|
+
}
|
|
13
|
+
return normalizeHueDegrees(parsed.h);
|
|
14
|
+
}
|
|
15
|
+
export function computeZoraHarmony(seed, harmony) {
|
|
16
|
+
const baseHue = resolveSeedHueDegrees(seed);
|
|
17
|
+
if (harmony === 'monochromatic') {
|
|
18
|
+
return {
|
|
19
|
+
kind: harmony,
|
|
20
|
+
orderedSlots: [createSlot('base', baseHue)],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (harmony === 'complementary') {
|
|
24
|
+
return {
|
|
25
|
+
kind: harmony,
|
|
26
|
+
orderedSlots: [createSlot('base', baseHue), createSlot('a', rotateHueDegrees(baseHue, 180))],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (harmony === 'analogous') {
|
|
30
|
+
return {
|
|
31
|
+
kind: harmony,
|
|
32
|
+
orderedSlots: [
|
|
33
|
+
createSlot('base', baseHue),
|
|
34
|
+
createSlot('a', rotateHueDegrees(baseHue, -30)),
|
|
35
|
+
createSlot('b', rotateHueDegrees(baseHue, 30)),
|
|
36
|
+
],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (harmony === 'splitComplementary') {
|
|
40
|
+
return {
|
|
41
|
+
kind: harmony,
|
|
42
|
+
orderedSlots: [
|
|
43
|
+
createSlot('base', baseHue),
|
|
44
|
+
createSlot('a', rotateHueDegrees(baseHue, 150)),
|
|
45
|
+
createSlot('b', rotateHueDegrees(baseHue, 210)),
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (harmony === 'triadic') {
|
|
50
|
+
return {
|
|
51
|
+
kind: harmony,
|
|
52
|
+
orderedSlots: [
|
|
53
|
+
createSlot('base', baseHue),
|
|
54
|
+
createSlot('a', rotateHueDegrees(baseHue, 120)),
|
|
55
|
+
createSlot('b', rotateHueDegrees(baseHue, 240)),
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
kind: harmony,
|
|
61
|
+
orderedSlots: [
|
|
62
|
+
createSlot('base', baseHue),
|
|
63
|
+
createSlot('a', rotateHueDegrees(baseHue, 90)),
|
|
64
|
+
createSlot('b', rotateHueDegrees(baseHue, 180)),
|
|
65
|
+
createSlot('c', rotateHueDegrees(baseHue, 270)),
|
|
66
|
+
],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=harmony.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harmony.js","sourceRoot":"","sources":["../../../src/internal/color/harmony.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAc1C,MAAM,2BAA2B,GAAG,GAAG,CAAC;AACxC,MAAM,+BAA+B,GAAG,IAAI,CAAC;AAE7C,SAAS,UAAU,CAAC,EAAqB,E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;aAC/C;SACF,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,KAAK,oBAAoB,EAAE,CAAC;QACrC,OAAO;YACL,IAAI,EAAE,OAAO;YACb,YAAY,EAAE;gBACZ,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC;gBAC3B,UAAU,CAAC,GAAG,EAAE,gBAAgB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;gBAC/C,UAAU,CAAC,GAAG,EAAE,gBAAgB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;aAChD;SACF,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO;YACL,IAAI,EAAE,OAAO;YACb,YAAY,EAAE;gBACZ,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC;gBAC3B,UAAU,CAAC,GAAG,EAAE,gBAAgB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;gBAC/C,UAAU,CAAC,GAAG,EAAE,gBAAgB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;aAChD;SACF,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI,EAAE,OAAO;QACb,YAAY,EAAE;YACZ,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC;YAC3B,UAAU,CAAC,GAAG,EAAE,gBAAgB,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YAC9C,UAAU,CAAC,GAAG,EAAE,gBAAgB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YAC/C,UAAU,CAAC,GAAG,EAAE,gBAAgB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;SAChD;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { ZoraColorHarmony, ZoraHexColor } from '../../theme/types';\nimport { normalizeHueDegrees, rotateHueDegrees } from './hue';\nimport { parseHexToOklch } from './oklch';\n\nexport type ZoraHarmonySlotId = 'base' | 'a' | 'b' | 'c';\n\nexport interface ZoraHarmonySlot {\n id: ZoraHarmonySlotId;\n hue: number;\n}\n\nexport interface ZoraComputedHarmony {\n kind: ZoraColorHarmony;\n orderedSlots: readonly ZoraHarmonySlot[];\n}\n\nconst DEFAULT_HARMONY_HUE_DEGREES = 260;\nconst MIN_SEED_CHROMA_FOR_HARMONY_HUE = 0.03;\n\nfunction createSlot(id: ZoraHarmonySlotId, hue: number): ZoraHarmonySlot {\n return { id, hue: normalizeHueDegrees(hue) };\n}\n\nfunction resolveSeedHueDegrees(seed: ZoraHexColor): number {\n const parsed = parseHexToOklch(seed);\n\n if (!Number.isFinite(parsed.h) || parsed.c < MIN_SEED_CHROMA_FOR_HARMONY_HUE) {\n return DEFAULT_HARMONY_HUE_DEGREES;\n }\n\n return normalizeHueDegrees(parsed.h);\n}\n\nexport function computeZoraHarmony(\n seed: ZoraHexColor,\n harmony: ZoraColorHarmony,\n): ZoraComputedHarmony {\n const baseHue = resolveSeedHueDegrees(seed);\n\n if (harmony === 'monochromatic') {\n return {\n kind: harmony,\n orderedSlots: [createSlot('base', baseHue)],\n };\n }\n\n if (harmony === 'complementary') {\n return {\n kind: harmony,\n orderedSlots: [createSlot('base', baseHue), createSlot('a', rotateHueDegrees(baseHue, 180))],\n };\n }\n\n if (harmony === 'analogous') {\n return {\n kind: harmony,\n orderedSlots: [\n createSlot('base', baseHue),\n createSlot('a', rotateHueDegrees(baseHue, -30)),\n createSlot('b', rotateHueDegrees(baseHue, 30)),\n ],\n };\n }\n\n if (harmony === 'splitComplementary') {\n return {\n kind: harmony,\n orderedSlots: [\n createSlot('base', baseHue),\n createSlot('a', rotateHueDegrees(baseHue, 150)),\n createSlot('b', rotateHueDegrees(baseHue, 210)),\n ],\n };\n }\n\n if (harmony === 'triadic') {\n return {\n kind: harmony,\n orderedSlots: [\n createSlot('base', baseHue),\n createSlot('a', rotateHueDegrees(baseHue, 120)),\n createSlot('b', rotateHueDegrees(baseHue, 240)),\n ],\n };\n }\n\n return {\n kind: harmony,\n orderedSlots: [\n createSlot('base', baseHue),\n createSlot('a', rotateHueDegrees(baseHue, 90)),\n createSlot('b', rotateHueDegrees(baseHue, 180)),\n createSlot('c', rotateHueDegrees(baseHue, 270)),\n ],\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hue.d.ts","sourceRoot":"","sources":["../../../src/internal/color/hue.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hue.js","sourceRoot":"","sources":["../../../src/internal/color/hue.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,mBAAmB,CAAC,GAAW;IAC7C,OAAO,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,GAAW,EAAE,KAAa;IACzD,OAAO,mBAAmB,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["export function normalizeHueDegrees(hue: number): number {\n return ((hue % 360) + 360) % 360;\n}\n\nexport function rotateHueDegrees(hue: number, delta: number): number {\n return normalizeHueDegrees(hue + delta);\n}\n"]}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export { computeZoraHarmony, type ZoraComputedHarmony, type ZoraHarmonySlot, type ZoraHarmonySlotId, } from './harmony';
|
|
1
2
|
export { parseHexToOklch } from './oklch';
|
|
2
3
|
export { resolveModePrimaryColor } from './primary';
|
|
4
|
+
export { assignZoraHarmonyRoleHues, getZoraHueRoleAssignment, type ZoraComputedHueRoles, type ZoraHueRoleAssignment, type ZoraHueRoleId, } from './roleHues';
|
|
5
|
+
export { createZoraColorScale, type CreateZoraColorScaleOptions, createZoraNeutralScale, createZoraPrimaryScale, } from './scales';
|
|
6
|
+
export { ZORA_COLOR_SCALE_STEPS, type ZoraColorScale, type ZoraColorScaleStep } from './types';
|
|
3
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/internal/color/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/internal/color/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,iBAAiB,GACvB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EACL,yBAAyB,EACzB,wBAAwB,EACxB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,aAAa,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,oBAAoB,EACpB,KAAK,2BAA2B,EAChC,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,sBAAsB,EAAE,KAAK,cAAc,EAAE,KAAK,kBAAkB,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export { computeZoraHarmony, } from './harmony';
|
|
1
2
|
export { parseHexToOklch } from './oklch';
|
|
2
3
|
export { resolveModePrimaryColor } from './primary';
|
|
4
|
+
export { assignZoraHarmonyRoleHues, getZoraHueRoleAssignment, } from './roleHues';
|
|
5
|
+
export { createZoraColorScale, createZoraNeutralScale, createZoraPrimaryScale, } from './scales';
|
|
6
|
+
export { ZORA_COLOR_SCALE_STEPS } from './types';
|
|
3
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/internal/color/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC","sourcesContent":["export { parseHexToOklch } from './oklch';\nexport { resolveModePrimaryColor } from './primary';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/internal/color/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GAInB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EACL,yBAAyB,EACzB,wBAAwB,GAIzB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,oBAAoB,EAEpB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,sBAAsB,EAAgD,MAAM,SAAS,CAAC","sourcesContent":["export {\n computeZoraHarmony,\n type ZoraComputedHarmony,\n type ZoraHarmonySlot,\n type ZoraHarmonySlotId,\n} from './harmony';\nexport { parseHexToOklch } from './oklch';\nexport { resolveModePrimaryColor } from './primary';\nexport {\n assignZoraHarmonyRoleHues,\n getZoraHueRoleAssignment,\n type ZoraComputedHueRoles,\n type ZoraHueRoleAssignment,\n type ZoraHueRoleId,\n} from './roleHues';\nexport {\n createZoraColorScale,\n type CreateZoraColorScaleOptions,\n createZoraNeutralScale,\n createZoraPrimaryScale,\n} from './scales';\nexport { ZORA_COLOR_SCALE_STEPS, type ZoraColorScale, type ZoraColorScaleStep } from './types';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oklch.d.ts","sourceRoot":"","sources":["../../../src/internal/color/oklch.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"oklch.d.ts","sourceRoot":"","sources":["../../../src/internal/color/oklch.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAS9C,wBAAgB,eAAe,CAAC,GAAG,EAAE,YAAY,GAAG,cAAc,CAoBjE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,cAAc,GAAG,YAAY,CAcpE;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,cAAc,GAAG,cAAc,CAavE"}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { converter, formatHex, parse, toGamut } from 'culori';
|
|
2
|
+
import { normalizeHueDegrees } from './hue';
|
|
2
3
|
const toOklch = converter('oklch');
|
|
3
4
|
const gamutMapToSrgb = toGamut('rgb', 'oklch');
|
|
4
|
-
function normalizeHueDegrees(hue) {
|
|
5
|
-
const normalized = ((hue % 360) + 360) % 360;
|
|
6
|
-
return normalized;
|
|
7
|
-
}
|
|
8
5
|
function isSixDigitHexColor(value) {
|
|
9
6
|
return /^#[0-9a-fA-F]{6}$/.test(value);
|
|
10
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oklch.js","sourceRoot":"","sources":["../../../src/internal/color/oklch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"oklch.js","sourceRoot":"","sources":["../../../src/internal/color/oklch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAG9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AAG5C,MAAM,OAAO,GAA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AC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;IACrF,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;IAE9B,IAAI,CAAC,GAAG,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC1E,CAAC;IAED,MAAM,UAAU,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;IACrC,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC1E,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAqB;IACrD,MAAM,MAAM,GAAG,cAAc,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;IACrF,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEhC,IAAI,OAAO,OAAO,CAAC,CAAC,KAAK,QAAQ,IAAI,OAAO,OAAO,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;QACnE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IAED,OAAO;QACL,CAAC,EAAE,OAAO,CAAC,CAAC;QACZ,CAAC,EAAE,OAAO,CAAC,CAAC;QACZ,CAAC,EAAE,mBAAmB,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KACtE,CAAC;AACJ,CAAC","sourcesContent":["import { converter, formatHex, parse, toGamut } from 'culori';\n\nimport type { ZoraHexColor } from '../../theme/types';\nimport { normalizeHueDegrees } from './hue';\nimport type { ZoraOklchColor } from './types';\n\nconst toOklch = converter('oklch');\nconst gamutMapToSrgb = toGamut('rgb', 'oklch');\n\nfunction isSixDigitHexColor(value: string): value is ZoraHexColor {\n return /^#[0-9a-fA-F]{6}$/.test(value);\n}\n\nexport function parseHexToOklch(hex: ZoraHexColor): ZoraOklchColor {\n if (!isSixDigitHexColor(hex)) {\n throw new Error(`Expected a 6-digit hex color like '#0f766e', got '${String(hex)}'.`);\n }\n\n const parsed = parse(hex);\n if (!parsed) {\n throw new Error(`Unable to parse hex color '${String(hex)}'.`);\n }\n\n const oklch = toOklch(parsed);\n if (typeof oklch.l !== 'number' || typeof oklch.c !== 'number') {\n throw new Error(`Unable to convert hex color '${String(hex)}' to OKLCH.`);\n }\n\n return {\n l: oklch.l,\n c: oklch.c,\n h: normalizeHueDegrees(typeof oklch.h === 'number' ? oklch.h : 0),\n };\n}\n\nexport function formatOklchAsHex(color: ZoraOklchColor): ZoraHexColor {\n const mapped = gamutMapToSrgb({ mode: 'oklch', l: color.l, c: color.c, h: color.h });\n const hex = formatHex(mapped);\n\n if (!hex || !isSixDigitHexColor(hex)) {\n throw new Error('Unable to format OKLCH color as a 6-digit hex value.');\n }\n\n const normalized = hex.toLowerCase();\n if (!isSixDigitHexColor(normalized)) {\n throw new Error('Unable to format OKLCH color as a 6-digit hex value.');\n }\n\n return normalized;\n}\n\nexport function clampOklchToGamut(color: ZoraOklchColor): ZoraOklchColor {\n const mapped = gamutMapToSrgb({ mode: 'oklch', l: color.l, c: color.c, h: color.h });\n const clamped = toOklch(mapped);\n\n if (typeof clamped.l !== 'number' || typeof clamped.c !== 'number') {\n throw new Error('Unable to clamp OKLCH color to sRGB gamut.');\n }\n\n return {\n l: clamped.l,\n c: clamped.c,\n h: normalizeHueDegrees(typeof clamped.h === 'number' ? clamped.h : 0),\n };\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ZoraColorHarmony } from '../../theme/types';
|
|
2
|
+
import type { ZoraComputedHarmony, ZoraHarmonySlotId } from './harmony';
|
|
3
|
+
export type ZoraHueRoleId = 'primary' | 'secondary' | 'accent' | 'highlight' | 'surfaceTint';
|
|
4
|
+
export interface ZoraHueRoleAssignment {
|
|
5
|
+
role: ZoraHueRoleId;
|
|
6
|
+
hue: number;
|
|
7
|
+
sourceSlotId: ZoraHarmonySlotId;
|
|
8
|
+
}
|
|
9
|
+
export interface ZoraComputedHueRoles {
|
|
10
|
+
harmony: ZoraColorHarmony;
|
|
11
|
+
assignments: readonly ZoraHueRoleAssignment[];
|
|
12
|
+
}
|
|
13
|
+
export declare function assignZoraHarmonyRoleHues(harmony: ZoraComputedHarmony): ZoraComputedHueRoles;
|
|
14
|
+
export declare function getZoraHueRoleAssignment(roles: ZoraComputedHueRoles, role: ZoraHueRoleId): ZoraHueRoleAssignment;
|
|
15
|
+
//# sourceMappingURL=roleHues.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roleHues.d.ts","sourceRoot":"","sources":["../../../src/internal/color/roleHues.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,mBAAmB,EAAmB,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAGzF,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,aAAa,CAAC;AAE7F,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,aAAa,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,iBAAiB,CAAC;CACjC;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,gBAAgB,CAAC;IAC1B,WAAW,EAAE,SAAS,qBAAqB,EAAE,CAAC;CAC/C;AAmCD,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,mBAAmB,GAAG,oBAAoB,CA8E5F;AAED,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,oBAAoB,EAC3B,IAAI,EAAE,aAAa,GAClB,qBAAqB,CAQvB"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { normalizeHueDegrees } from './hue';
|
|
2
|
+
function findSlot(harmony, id) {
|
|
3
|
+
return harmony.orderedSlots.find((slot) => slot.id === id);
|
|
4
|
+
}
|
|
5
|
+
function requireBaseSlot(harmony) {
|
|
6
|
+
const base = findSlot(harmony, 'base');
|
|
7
|
+
if (!base) {
|
|
8
|
+
throw new Error(`[zora] Expected harmony to include a base slot (kind: ${harmony.kind}).`);
|
|
9
|
+
}
|
|
10
|
+
return base;
|
|
11
|
+
}
|
|
12
|
+
function assignRole(role, harmony, preferred, fallback = 'base') {
|
|
13
|
+
const base = requireBaseSlot(harmony);
|
|
14
|
+
const preferredSlot = findSlot(harmony, preferred);
|
|
15
|
+
const fallbackSlot = findSlot(harmony, fallback);
|
|
16
|
+
const chosenSlot = preferredSlot ?? fallbackSlot ?? base;
|
|
17
|
+
return {
|
|
18
|
+
role,
|
|
19
|
+
hue: normalizeHueDegrees(chosenSlot.hue),
|
|
20
|
+
sourceSlotId: chosenSlot.id,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function assignZoraHarmonyRoleHues(harmony) {
|
|
24
|
+
const { kind } = harmony;
|
|
25
|
+
if (kind === 'monochromatic') {
|
|
26
|
+
return {
|
|
27
|
+
harmony: kind,
|
|
28
|
+
assignments: [
|
|
29
|
+
assignRole('primary', harmony, 'base'),
|
|
30
|
+
assignRole('secondary', harmony, 'base'),
|
|
31
|
+
assignRole('accent', harmony, 'base'),
|
|
32
|
+
assignRole('highlight', harmony, 'base'),
|
|
33
|
+
assignRole('surfaceTint', harmony, 'base'),
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (kind === 'complementary') {
|
|
38
|
+
return {
|
|
39
|
+
harmony: kind,
|
|
40
|
+
assignments: [
|
|
41
|
+
assignRole('primary', harmony, 'base'),
|
|
42
|
+
assignRole('secondary', harmony, 'base'),
|
|
43
|
+
assignRole('accent', harmony, 'a'),
|
|
44
|
+
assignRole('highlight', harmony, 'a'),
|
|
45
|
+
assignRole('surfaceTint', harmony, 'base'),
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (kind === 'analogous') {
|
|
50
|
+
return {
|
|
51
|
+
harmony: kind,
|
|
52
|
+
assignments: [
|
|
53
|
+
assignRole('primary', harmony, 'base'),
|
|
54
|
+
assignRole('secondary', harmony, 'a'),
|
|
55
|
+
assignRole('accent', harmony, 'b', 'a'),
|
|
56
|
+
assignRole('highlight', harmony, 'b', 'a'),
|
|
57
|
+
assignRole('surfaceTint', harmony, 'a'),
|
|
58
|
+
],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (kind === 'splitComplementary') {
|
|
62
|
+
return {
|
|
63
|
+
harmony: kind,
|
|
64
|
+
assignments: [
|
|
65
|
+
assignRole('primary', harmony, 'base'),
|
|
66
|
+
assignRole('secondary', harmony, 'a'),
|
|
67
|
+
assignRole('accent', harmony, 'b', 'a'),
|
|
68
|
+
assignRole('highlight', harmony, 'b', 'a'),
|
|
69
|
+
assignRole('surfaceTint', harmony, 'base'),
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (kind === 'triadic') {
|
|
74
|
+
return {
|
|
75
|
+
harmony: kind,
|
|
76
|
+
assignments: [
|
|
77
|
+
assignRole('primary', harmony, 'base'),
|
|
78
|
+
assignRole('secondary', harmony, 'a'),
|
|
79
|
+
assignRole('accent', harmony, 'b', 'a'),
|
|
80
|
+
assignRole('highlight', harmony, 'b', 'a'),
|
|
81
|
+
assignRole('surfaceTint', harmony, 'base'),
|
|
82
|
+
],
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
harmony: kind,
|
|
87
|
+
assignments: [
|
|
88
|
+
assignRole('primary', harmony, 'base'),
|
|
89
|
+
assignRole('secondary', harmony, 'a'),
|
|
90
|
+
assignRole('accent', harmony, 'b', 'a'),
|
|
91
|
+
assignRole('highlight', harmony, 'c', 'b'),
|
|
92
|
+
assignRole('surfaceTint', harmony, 'base'),
|
|
93
|
+
],
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
export function getZoraHueRoleAssignment(roles, role) {
|
|
97
|
+
const found = roles.assignments.find((assignment) => assignment.role === role);
|
|
98
|
+
if (!found) {
|
|
99
|
+
throw new Error(`[zora] Expected a hue-role assignment for "${role}" (harmony: ${roles.harmony}).`);
|
|
100
|
+
}
|
|
101
|
+
return found;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=roleHues.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roleHues.js","sourceRoot":"","sources":["../../../src/internal/color/roleHues.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AAe5C,SAAS,QAAQ,CACf,OAA4B,EAC5B,EAAqB;IAErB,OAAO,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,eAAe,CAAC,OAA4B;IACnD,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACvC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,yDAAyD,OAAO,CAAC,IAAI,IAAI,CAAC,CAAC;IAC7F,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,UAAU,CACjB,IAAmB,EACnB,OAA4B,EAC5B,SAA4B,EAC5B,WAA8B,MAAM;IAEpC,MAAM,IAAI,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,aAAa,GAAG,QAAQ,CAAC,OAAO,EAAE,SAAS,CAA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O,EAAE,IAAI;QACb,WAAW,EAAE;YACX,UAAU,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC;YACtC,UAAU,CAAC,WAAW,EAAE,OAAO,EAAE,GAAG,CAAC;YACrC,UAAU,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC;YACvC,UAAU,CAAC,WAAW,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC;YAC1C,UAAU,CAAC,aAAa,EAAE,OAAO,EAAE,MAAM,CAAC;SAC3C;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,KAA2B,EAC3B,IAAmB;IAEnB,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IAC/E,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CACb,8CAA8C,IAAI,eAAe,KAAK,CAAC,OAAO,IAAI,CACnF,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import type { ZoraColorHarmony } from '../../theme/types';\nimport type { ZoraComputedHarmony, ZoraHarmonySlot, ZoraHarmonySlotId } from './harmony';\nimport { normalizeHueDegrees } from './hue';\n\nexport type ZoraHueRoleId = 'primary' | 'secondary' | 'accent' | 'highlight' | 'surfaceTint';\n\nexport interface ZoraHueRoleAssignment {\n role: ZoraHueRoleId;\n hue: number;\n sourceSlotId: ZoraHarmonySlotId;\n}\n\nexport interface ZoraComputedHueRoles {\n harmony: ZoraColorHarmony;\n assignments: readonly ZoraHueRoleAssignment[];\n}\n\nfunction findSlot(\n harmony: ZoraComputedHarmony,\n id: ZoraHarmonySlotId,\n): ZoraHarmonySlot | undefined {\n return harmony.orderedSlots.find((slot) => slot.id === id);\n}\n\nfunction requireBaseSlot(harmony: ZoraComputedHarmony): ZoraHarmonySlot {\n const base = findSlot(harmony, 'base');\n if (!base) {\n throw new Error(`[zora] Expected harmony to include a base slot (kind: ${harmony.kind}).`);\n }\n return base;\n}\n\nfunction assignRole(\n role: ZoraHueRoleId,\n harmony: ZoraComputedHarmony,\n preferred: ZoraHarmonySlotId,\n fallback: ZoraHarmonySlotId = 'base',\n): ZoraHueRoleAssignment {\n const base = requireBaseSlot(harmony);\n const preferredSlot = findSlot(harmony, preferred);\n const fallbackSlot = findSlot(harmony, fallback);\n const chosenSlot = preferredSlot ?? fallbackSlot ?? base;\n\n return {\n role,\n hue: normalizeHueDegrees(chosenSlot.hue),\n sourceSlotId: chosenSlot.id,\n };\n}\n\nexport function assignZoraHarmonyRoleHues(harmony: ZoraComputedHarmony): ZoraComputedHueRoles {\n const { kind } = harmony;\n\n if (kind === 'monochromatic') {\n return {\n harmony: kind,\n assignments: [\n assignRole('primary', harmony, 'base'),\n assignRole('secondary', harmony, 'base'),\n assignRole('accent', harmony, 'base'),\n assignRole('highlight', harmony, 'base'),\n assignRole('surfaceTint', harmony, 'base'),\n ],\n };\n }\n\n if (kind === 'complementary') {\n return {\n harmony: kind,\n assignments: [\n assignRole('primary', harmony, 'base'),\n assignRole('secondary', harmony, 'base'),\n assignRole('accent', harmony, 'a'),\n assignRole('highlight', harmony, 'a'),\n assignRole('surfaceTint', harmony, 'base'),\n ],\n };\n }\n\n if (kind === 'analogous') {\n return {\n harmony: kind,\n assignments: [\n assignRole('primary', harmony, 'base'),\n assignRole('secondary', harmony, 'a'),\n assignRole('accent', harmony, 'b', 'a'),\n assignRole('highlight', harmony, 'b', 'a'),\n assignRole('surfaceTint', harmony, 'a'),\n ],\n };\n }\n\n if (kind === 'splitComplementary') {\n return {\n harmony: kind,\n assignments: [\n assignRole('primary', harmony, 'base'),\n assignRole('secondary', harmony, 'a'),\n assignRole('accent', harmony, 'b', 'a'),\n assignRole('highlight', harmony, 'b', 'a'),\n assignRole('surfaceTint', harmony, 'base'),\n ],\n };\n }\n\n if (kind === 'triadic') {\n return {\n harmony: kind,\n assignments: [\n assignRole('primary', harmony, 'base'),\n assignRole('secondary', harmony, 'a'),\n assignRole('accent', harmony, 'b', 'a'),\n assignRole('highlight', harmony, 'b', 'a'),\n assignRole('surfaceTint', harmony, 'base'),\n ],\n };\n }\n\n return {\n harmony: kind,\n assignments: [\n assignRole('primary', harmony, 'base'),\n assignRole('secondary', harmony, 'a'),\n assignRole('accent', harmony, 'b', 'a'),\n assignRole('highlight', harmony, 'c', 'b'),\n assignRole('surfaceTint', harmony, 'base'),\n ],\n };\n}\n\nexport function getZoraHueRoleAssignment(\n roles: ZoraComputedHueRoles,\n role: ZoraHueRoleId,\n): ZoraHueRoleAssignment {\n const found = roles.assignments.find((assignment) => assignment.role === role);\n if (!found) {\n throw new Error(\n `[zora] Expected a hue-role assignment for \"${role}\" (harmony: ${roles.harmony}).`,\n );\n }\n return found;\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ZoraHexColor } from '../../theme/types';
|
|
2
|
+
import { type ZoraColorScale } from './types';
|
|
3
|
+
export interface CreateZoraColorScaleOptions {
|
|
4
|
+
seed: ZoraHexColor;
|
|
5
|
+
role?: 'primary' | 'neutral';
|
|
6
|
+
}
|
|
7
|
+
export declare function createZoraColorScale(options: CreateZoraColorScaleOptions): ZoraColorScale;
|
|
8
|
+
export declare function createZoraPrimaryScale(seed: ZoraHexColor): ZoraColorScale;
|
|
9
|
+
export declare function createZoraNeutralScale(seed?: ZoraHexColor): ZoraColorScale;
|
|
10
|
+
//# sourceMappingURL=scales.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scales.d.ts","sourceRoot":"","sources":["../../../src/internal/color/scales.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,KAAK,cAAc,EAA2B,MAAM,SAAS,CAAC;AAEvE,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;CAC9B;AA4HD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,2BAA2B,GAAG,cAAc,CAKzF;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,YAAY,GAAG,cAAc,CAEzE;AAED,wBAAgB,sBAAsB,CAAC,IAAI,GAAE,YAAwB,GAAG,cAAc,CAErF"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { clampOklchToGamut, formatOklchAsHex, parseHexToOklch } from './oklch';
|
|
2
|
+
import {} from './types';
|
|
3
|
+
const PRIMARY_LIGHTNESS_BY_STEP = {
|
|
4
|
+
50: 0.97,
|
|
5
|
+
100: 0.93,
|
|
6
|
+
200: 0.86,
|
|
7
|
+
300: 0.78,
|
|
8
|
+
400: 0.68,
|
|
9
|
+
500: 0.58,
|
|
10
|
+
600: 0.5,
|
|
11
|
+
700: 0.42,
|
|
12
|
+
800: 0.34,
|
|
13
|
+
900: 0.27,
|
|
14
|
+
950: 0.2,
|
|
15
|
+
};
|
|
16
|
+
const NEUTRAL_LIGHTNESS_BY_STEP = {
|
|
17
|
+
50: 0.98,
|
|
18
|
+
100: 0.95,
|
|
19
|
+
200: 0.89,
|
|
20
|
+
300: 0.8,
|
|
21
|
+
400: 0.68,
|
|
22
|
+
500: 0.55,
|
|
23
|
+
600: 0.44,
|
|
24
|
+
700: 0.34,
|
|
25
|
+
800: 0.25,
|
|
26
|
+
900: 0.18,
|
|
27
|
+
950: 0.12,
|
|
28
|
+
};
|
|
29
|
+
const PRIMARY_CHROMA_MULTIPLIER_BY_STEP = {
|
|
30
|
+
50: 0.2,
|
|
31
|
+
100: 0.3,
|
|
32
|
+
200: 0.45,
|
|
33
|
+
300: 0.7,
|
|
34
|
+
400: 0.95,
|
|
35
|
+
500: 1,
|
|
36
|
+
600: 0.95,
|
|
37
|
+
700: 0.85,
|
|
38
|
+
800: 0.65,
|
|
39
|
+
900: 0.45,
|
|
40
|
+
950: 0.3,
|
|
41
|
+
};
|
|
42
|
+
const MAX_PRIMARY_SCALE_CHROMA = 0.2;
|
|
43
|
+
const MIN_PRIMARY_SCALE_CHROMA = 0.04;
|
|
44
|
+
const NEUTRAL_CHROMA = 0.012;
|
|
45
|
+
const DEFAULT_NEUTRAL_HUE_DEGREES = 260;
|
|
46
|
+
function clampNumber(value, min, max) {
|
|
47
|
+
return Math.max(min, Math.min(value, max));
|
|
48
|
+
}
|
|
49
|
+
function resolvePrimaryScaleChroma(seedChroma, step) {
|
|
50
|
+
const cappedSeedChroma = clampNumber(seedChroma, 0, MAX_PRIMARY_SCALE_CHROMA);
|
|
51
|
+
const multiplier = PRIMARY_CHROMA_MULTIPLIER_BY_STEP[step];
|
|
52
|
+
const scaled = cappedSeedChroma * multiplier;
|
|
53
|
+
const bounded = clampNumber(scaled, 0, MAX_PRIMARY_SCALE_CHROMA);
|
|
54
|
+
const shouldEnforceMin = step >= 300 && step <= 700 && seedChroma >= MIN_PRIMARY_SCALE_CHROMA;
|
|
55
|
+
return shouldEnforceMin ? Math.max(bounded, MIN_PRIMARY_SCALE_CHROMA) : bounded;
|
|
56
|
+
}
|
|
57
|
+
function createScaleEntries(options) {
|
|
58
|
+
const seed = parseHexToOklch(options.seed);
|
|
59
|
+
if (options.role === 'neutral') {
|
|
60
|
+
const hue = typeof seed.h === 'number' ? seed.h : DEFAULT_NEUTRAL_HUE_DEGREES;
|
|
61
|
+
return createScaleFromRamp({
|
|
62
|
+
hue,
|
|
63
|
+
chroma: NEUTRAL_CHROMA,
|
|
64
|
+
lightnessByStep: NEUTRAL_LIGHTNESS_BY_STEP,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return createScaleFromRamp({
|
|
68
|
+
hue: seed.h,
|
|
69
|
+
chromaByStep: (step) => resolvePrimaryScaleChroma(seed.c, step),
|
|
70
|
+
lightnessByStep: PRIMARY_LIGHTNESS_BY_STEP,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function createScaleColor(options, step) {
|
|
74
|
+
const lightness = options.lightnessByStep[step];
|
|
75
|
+
const chroma = typeof options.chromaByStep === 'function' ? options.chromaByStep(step) : (options.chroma ?? 0);
|
|
76
|
+
const clamped = clampOklchToGamut({
|
|
77
|
+
l: clampNumber(lightness, 0, 1),
|
|
78
|
+
c: clampNumber(chroma, 0, 1),
|
|
79
|
+
h: options.hue,
|
|
80
|
+
});
|
|
81
|
+
return formatOklchAsHex(clamped);
|
|
82
|
+
}
|
|
83
|
+
function createScaleFromRamp(options) {
|
|
84
|
+
return {
|
|
85
|
+
50: createScaleColor(options, 50),
|
|
86
|
+
100: createScaleColor(options, 100),
|
|
87
|
+
200: createScaleColor(options, 200),
|
|
88
|
+
300: createScaleColor(options, 300),
|
|
89
|
+
400: createScaleColor(options, 400),
|
|
90
|
+
500: createScaleColor(options, 500),
|
|
91
|
+
600: createScaleColor(options, 600),
|
|
92
|
+
700: createScaleColor(options, 700),
|
|
93
|
+
800: createScaleColor(options, 800),
|
|
94
|
+
900: createScaleColor(options, 900),
|
|
95
|
+
950: createScaleColor(options, 950),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export function createZoraColorScale(options) {
|
|
99
|
+
return createScaleEntries({
|
|
100
|
+
seed: options.seed,
|
|
101
|
+
role: options.role,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
export function createZoraPrimaryScale(seed) {
|
|
105
|
+
return createZoraColorScale({ seed, role: 'primary' });
|
|
106
|
+
}
|
|
107
|
+
export function createZoraNeutralScale(seed = '#94a3b8') {
|
|
108
|
+
return createZoraColorScale({ seed, role: 'neutral' });
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=scales.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scales.js","sourceRoot":"","sources":["../../../src/internal/color/scales.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,eAAe,EAAE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,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,OAAoC;IACvE,OAAO,kBAAkB,CAAC;QACxB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,IAAI,EAAE,OAAO,CAAC,IAAI;KACnB,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,IAAkB;IACvD,OAAO,oBAAoB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,OAAqB,SAAS;IACnE,OAAO,oBAAoB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;AACzD,CAAC","sourcesContent":["import type { ZoraHexColor } from '../../theme/types';\nimport { clampOklchToGamut, formatOklchAsHex, parseHexToOklch } from './oklch';\nimport { type ZoraColorScale, type ZoraColorScaleStep } from './types';\n\nexport interface CreateZoraColorScaleOptions {\n seed: ZoraHexColor;\n role?: 'primary' | 'neutral';\n}\n\nconst PRIMARY_LIGHTNESS_BY_STEP: Record<ZoraColorScaleStep, number> = {\n 50: 0.97,\n 100: 0.93,\n 200: 0.86,\n 300: 0.78,\n 400: 0.68,\n 500: 0.58,\n 600: 0.5,\n 700: 0.42,\n 800: 0.34,\n 900: 0.27,\n 950: 0.2,\n};\n\nconst NEUTRAL_LIGHTNESS_BY_STEP: Record<ZoraColorScaleStep, number> = {\n 50: 0.98,\n 100: 0.95,\n 200: 0.89,\n 300: 0.8,\n 400: 0.68,\n 500: 0.55,\n 600: 0.44,\n 700: 0.34,\n 800: 0.25,\n 900: 0.18,\n 950: 0.12,\n};\n\nconst PRIMARY_CHROMA_MULTIPLIER_BY_STEP: Record<ZoraColorScaleStep, number> = {\n 50: 0.2,\n 100: 0.3,\n 200: 0.45,\n 300: 0.7,\n 400: 0.95,\n 500: 1,\n 600: 0.95,\n 700: 0.85,\n 800: 0.65,\n 900: 0.45,\n 950: 0.3,\n};\n\nconst MAX_PRIMARY_SCALE_CHROMA = 0.2;\nconst MIN_PRIMARY_SCALE_CHROMA = 0.04;\nconst NEUTRAL_CHROMA = 0.012;\nconst DEFAULT_NEUTRAL_HUE_DEGREES = 260;\n\nfunction clampNumber(value: number, min: number, max: number): number {\n return Math.max(min, Math.min(value, max));\n}\n\nfunction resolvePrimaryScaleChroma(seedChroma: number, step: ZoraColorScaleStep): number {\n const cappedSeedChroma = clampNumber(seedChroma, 0, MAX_PRIMARY_SCALE_CHROMA);\n const multiplier = PRIMARY_CHROMA_MULTIPLIER_BY_STEP[step];\n const scaled = cappedSeedChroma * multiplier;\n\n const bounded = clampNumber(scaled, 0, MAX_PRIMARY_SCALE_CHROMA);\n const shouldEnforceMin = step >= 300 && step <= 700 && seedChroma >= MIN_PRIMARY_SCALE_CHROMA;\n\n return shouldEnforceMin ? Math.max(bounded, MIN_PRIMARY_SCALE_CHROMA) : bounded;\n}\n\nfunction createScaleEntries(options: CreateZoraColorScaleOptions): ZoraColorScale {\n const seed = parseHexToOklch(options.seed);\n\n if (options.role === 'neutral') {\n const hue = typeof seed.h === 'number' ? seed.h : DEFAULT_NEUTRAL_HUE_DEGREES;\n\n return createScaleFromRamp({\n hue,\n chroma: NEUTRAL_CHROMA,\n lightnessByStep: NEUTRAL_LIGHTNESS_BY_STEP,\n });\n }\n\n return createScaleFromRamp({\n hue: seed.h,\n chromaByStep: (step) => resolvePrimaryScaleChroma(seed.c, step),\n lightnessByStep: PRIMARY_LIGHTNESS_BY_STEP,\n });\n}\n\ninterface CreateScaleFromRampOptions {\n hue: number;\n chroma?: number;\n chromaByStep?: (step: ZoraColorScaleStep) => number;\n lightnessByStep: Record<ZoraColorScaleStep, number>;\n}\n\nfunction createScaleColor(\n options: CreateScaleFromRampOptions,\n step: ZoraColorScaleStep,\n): ZoraHexColor {\n const lightness = options.lightnessByStep[step];\n const chroma =\n typeof options.chromaByStep === 'function' ? options.chromaByStep(step) : (options.chroma ?? 0);\n\n const clamped = clampOklchToGamut({\n l: clampNumber(lightness, 0, 1),\n c: clampNumber(chroma, 0, 1),\n h: options.hue,\n });\n\n return formatOklchAsHex(clamped);\n}\n\nfunction createScaleFromRamp(options: CreateScaleFromRampOptions): ZoraColorScale {\n return {\n 50: createScaleColor(options, 50),\n 100: createScaleColor(options, 100),\n 200: createScaleColor(options, 200),\n 300: createScaleColor(options, 300),\n 400: createScaleColor(options, 400),\n 500: createScaleColor(options, 500),\n 600: createScaleColor(options, 600),\n 700: createScaleColor(options, 700),\n 800: createScaleColor(options, 800),\n 900: createScaleColor(options, 900),\n 950: createScaleColor(options, 950),\n };\n}\n\nexport function createZoraColorScale(options: CreateZoraColorScaleOptions): ZoraColorScale {\n return createScaleEntries({\n seed: options.seed,\n role: options.role,\n });\n}\n\nexport function createZoraPrimaryScale(seed: ZoraHexColor): ZoraColorScale {\n return createZoraColorScale({ seed, role: 'primary' });\n}\n\nexport function createZoraNeutralScale(seed: ZoraHexColor = '#94a3b8'): ZoraColorScale {\n return createZoraColorScale({ seed, role: 'neutral' });\n}\n"]}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import type { ZoraHexColor } from '../../theme/types';
|
|
1
2
|
export interface ZoraOklchColor {
|
|
2
3
|
l: number;
|
|
3
4
|
c: number;
|
|
4
5
|
h: number;
|
|
5
6
|
}
|
|
7
|
+
export declare const ZORA_COLOR_SCALE_STEPS: readonly [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
|
|
8
|
+
export type ZoraColorScaleStep = (typeof ZORA_COLOR_SCALE_STEPS)[number];
|
|
9
|
+
export type ZoraColorScale = Record<ZoraColorScaleStep, ZoraHexColor>;
|
|
6
10
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/internal/color/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/internal/color/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,MAAM,WAAW,cAAc;IAC7B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,eAAO,MAAM,sBAAsB,iEAEzB,CAAC;AAEX,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzE,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,kBAAkB,EAAE,YAAY,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/internal/color/types.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/internal/color/types.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;CAC5C,CAAC","sourcesContent":["import type { ZoraHexColor } from '../../theme/types';\n\nexport interface ZoraOklchColor {\n l: number;\n c: number;\n h: number;\n}\n\nexport const ZORA_COLOR_SCALE_STEPS = [\n 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950,\n] as const;\n\nexport type ZoraColorScaleStep = (typeof ZORA_COLOR_SCALE_STEPS)[number];\n\nexport type ZoraColorScale = Record<ZoraColorScaleStep, ZoraHexColor>;\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ankhorage/zora",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.12.
|
|
4
|
+
"version": "0.12.2",
|
|
5
5
|
"description": "Opinionated React Native and React Native Web UI kit built on @ankhorage/surface.",
|
|
6
6
|
"homepage": "https://github.com/ankhorage/zora#readme",
|
|
7
7
|
"bugs": {
|