@pixerate/editor 0.164.0 → 0.165.0
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/dist/agent/index.cjs +54 -39
- package/dist/agent/index.js +24 -9
- package/dist/animation/index.cjs +6 -5
- package/dist/animation/index.js +5 -4
- package/dist/animation-editor/index.cjs +65 -64
- package/dist/animation-editor/index.js +8 -7
- package/dist/bridge/cli.cjs +3 -3
- package/dist/bridge/cli.js +2 -2
- package/dist/bridge/index.cjs +3 -3
- package/dist/bridge/index.js +2 -2
- package/dist/canvas/index.cjs +89 -87
- package/dist/canvas/index.js +11 -9
- package/dist/chart/controller.d.cts +31 -2
- package/dist/chart/controller.d.ts +31 -2
- package/dist/chart/index.cjs +504 -132
- package/dist/chart/index.d.cts +2 -0
- package/dist/chart/index.d.ts +2 -0
- package/dist/chart/index.js +386 -14
- package/dist/chart/layout-families.d.cts +7 -0
- package/dist/chart/layout-families.d.ts +7 -0
- package/dist/chart/links.d.cts +34 -0
- package/dist/chart/links.d.ts +34 -0
- package/dist/chart/mermaid.d.cts +9 -6
- package/dist/chart/mermaid.d.ts +9 -6
- package/dist/chart/schemas.d.cts +3 -0
- package/dist/chart/schemas.d.ts +3 -0
- package/dist/chart/spec.d.cts +3 -2
- package/dist/chart/spec.d.ts +3 -2
- package/dist/chart/style.d.cts +33 -0
- package/dist/chart/style.d.ts +33 -0
- package/dist/chart/types.d.cts +24 -2
- package/dist/chart/types.d.ts +24 -2
- package/dist/{chunk-TALQONZ5.js → chunk-2J5VLJHC.js} +3 -3
- package/dist/{chunk-3NEZJCBY.js → chunk-2ZRN43IN.js} +340 -201
- package/dist/{chunk-ZVNAMTFO.cjs → chunk-3FSUJIXN.cjs} +18 -174
- package/dist/{chunk-RQCMSEM5.cjs → chunk-4QUUHTGJ.cjs} +2 -2
- package/dist/{chunk-CIPIESX4.cjs → chunk-4ZC5QJE2.cjs} +3 -3
- package/dist/{chunk-S6X2QRVU.cjs → chunk-5UEFBM2M.cjs} +1 -138
- package/dist/{chunk-YSAGBIRW.cjs → chunk-64VWWR5U.cjs} +16 -16
- package/dist/{chunk-QYZGBVNC.js → chunk-7272D3K2.js} +10 -8
- package/dist/{chunk-462WGGXX.cjs → chunk-AMX23CSN.cjs} +27 -16
- package/dist/{chunk-3VLOOO3G.js → chunk-BDIM6NVW.js} +1 -1
- package/dist/{chunk-POR54B55.js → chunk-CRFSQWKQ.js} +4 -1
- package/dist/{chunk-GZ2FM3ZB.js → chunk-DKNEQX7T.js} +6 -162
- package/dist/{chunk-JCXMJUQO.cjs → chunk-EGZM52EO.cjs} +3 -3
- package/dist/{chunk-ES3UEVUT.cjs → chunk-EUIDTZNQ.cjs} +112 -110
- package/dist/{chunk-H3OEM3Q2.js → chunk-F6R67I3A.js} +1 -1
- package/dist/{chunk-5FNGLV2D.js → chunk-FEU2XVQH.js} +15 -3
- package/dist/{chunk-SZA42R4N.js → chunk-FRBRLKNQ.js} +154 -16
- package/dist/chunk-HIDFL5LQ.js +484 -0
- package/dist/{chunk-MKTDELCD.js → chunk-I5MRJW7B.js} +1 -1
- package/dist/{chunk-SDHZG5TF.js → chunk-ILP77UD6.js} +160 -2
- package/dist/{chunk-GKNEJ6EN.cjs → chunk-IMRXC7OA.cjs} +241 -103
- package/dist/chunk-KGRZMHZB.js +204 -0
- package/dist/{chunk-SET6KJOP.js → chunk-LPIKXPBM.js} +1 -1
- package/dist/{chunk-BQWGN5WH.js → chunk-M2TPMYJE.js} +1 -1
- package/dist/{chunk-GTELFJRE.cjs → chunk-M5GLQQWG.cjs} +2 -2
- package/dist/{chunk-4VU4CP7R.js → chunk-MHLU6GRJ.js} +1 -138
- package/dist/{chunk-D54JHQK2.cjs → chunk-MKXK6E4O.cjs} +51 -51
- package/dist/{chunk-DAPQGA55.js → chunk-N7NBGT2Y.js} +2 -2
- package/dist/chunk-O6OGNDND.js +164 -0
- package/dist/{chunk-22KLZZGH.cjs → chunk-ODFCS7HF.cjs} +8 -8
- package/dist/{chunk-PA3IMPPS.cjs → chunk-OVYQAYGH.cjs} +81 -81
- package/dist/{chunk-YXOW456B.js → chunk-PPEDZ5WR.js} +1 -1
- package/dist/{chunk-YGG7WDWT.cjs → chunk-Q25WAFTD.cjs} +21 -18
- package/dist/{chunk-SBQVEBSU.cjs → chunk-QO2T6KA5.cjs} +165 -67
- package/dist/{chunk-24M7VD6M.cjs → chunk-S4EIAIEW.cjs} +7 -7
- package/dist/{chunk-M4MIZPQI.cjs → chunk-SJ2CPTQC.cjs} +189 -15
- package/dist/chunk-TFF2GTGN.cjs +153 -0
- package/dist/chunk-TTCJPX4U.cjs +204 -0
- package/dist/{chunk-NZD2MZJC.cjs → chunk-TVQW26AV.cjs} +35 -23
- package/dist/{chunk-R3P2M7HU.cjs → chunk-UVXTOZ2B.cjs} +346 -207
- package/dist/{chunk-WI7QJA7A.cjs → chunk-UXETV2NC.cjs} +161 -3
- package/dist/{chunk-Z4P2RBMJ.js → chunk-V5GSY3NC.js} +101 -3
- package/dist/{chunk-QY4KUDMY.js → chunk-VRXXAXUT.js} +2 -2
- package/dist/chunk-VU6WQSMB.cjs +164 -0
- package/dist/{chunk-OXERWBKE.js → chunk-X5W645RI.js} +3 -3
- package/dist/{chunk-NHLYK3AX.js → chunk-XBQX76CT.js} +182 -8
- package/dist/{chunk-5AARIS3R.cjs → chunk-XCDGM7TD.cjs} +37 -37
- package/dist/{chunk-EVXQNQND.js → chunk-XZB3TJ6K.js} +16 -5
- package/dist/chunk-YBAPT7NL.js +153 -0
- package/dist/chunk-Z2UQYMPS.cjs +484 -0
- package/dist/color/index.cjs +5 -3
- package/dist/color/index.js +12 -10
- package/dist/diagram/index.cjs +55 -243
- package/dist/diagram/index.js +12 -200
- package/dist/export/index.cjs +7 -6
- package/dist/export/index.js +6 -5
- package/dist/extensions/index.cjs +12 -9
- package/dist/extensions/index.js +11 -8
- package/dist/gradient/index.cjs +29 -27
- package/dist/gradient/index.js +6 -4
- package/dist/image-editor/index.cjs +644 -643
- package/dist/image-editor/index.js +7 -6
- package/dist/index.cjs +21 -18
- package/dist/index.js +14 -11
- package/dist/paint-editor/index.cjs +19 -18
- package/dist/paint-editor/index.js +7 -6
- package/dist/parameters/index.cjs +2 -2
- package/dist/parameters/index.js +1 -1
- package/dist/persistence/assetWrites.d.cts +22 -0
- package/dist/persistence/assetWrites.d.ts +22 -0
- package/dist/persistence/assets.d.cts +71 -0
- package/dist/persistence/assets.d.ts +71 -0
- package/dist/persistence/documentStore.d.cts +17 -1
- package/dist/persistence/documentStore.d.ts +17 -1
- package/dist/persistence/documentTools.d.cts +5 -1
- package/dist/persistence/documentTools.d.ts +5 -1
- package/dist/persistence/editorAutosave.d.cts +7 -0
- package/dist/persistence/editorAutosave.d.ts +7 -0
- package/dist/persistence/index.cjs +141 -21
- package/dist/persistence/index.js +130 -10
- package/dist/persistence/storage.d.cts +13 -1
- package/dist/persistence/storage.d.ts +13 -1
- package/dist/spreadsheet/index.cjs +3 -3
- package/dist/spreadsheet/index.js +2 -2
- package/dist/tokens/index.cjs +11 -3
- package/dist/tokens/index.d.cts +1 -0
- package/dist/tokens/index.d.ts +1 -0
- package/dist/tokens/index.js +10 -2
- package/dist/tokens/style.d.cts +36 -0
- package/dist/tokens/style.d.ts +36 -0
- package/dist/tools/index.cjs +15 -3
- package/dist/tools/index.d.cts +2 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +14 -2
- package/dist/tools/style-tools.d.cts +19 -0
- package/dist/tools/style-tools.d.ts +19 -0
- package/dist/tools/style.d.cts +212 -0
- package/dist/tools/style.d.ts +212 -0
- package/dist/tools/view.d.cts +6 -0
- package/dist/tools/view.d.ts +6 -0
- package/dist/typography/index.cjs +8 -6
- package/dist/typography/index.js +5 -3
- package/dist/vector/index.cjs +953 -952
- package/dist/vector/index.js +7 -6
- package/dist/video-editor/index.cjs +8 -7
- package/dist/video-editor/index.js +6 -5
- package/package.json +1 -1
- package/dist/chunk-ERAGQL2N.cjs +0 -68
- package/dist/chunk-KMU6QJB7.js +0 -68
|
@@ -3,6 +3,42 @@ import {
|
|
|
3
3
|
stripPrototypeKeys
|
|
4
4
|
} from "./chunk-HF5QZS7Z.js";
|
|
5
5
|
|
|
6
|
+
// src/persistence/assetWrites.ts
|
|
7
|
+
var leases = /* @__PURE__ */ new Map();
|
|
8
|
+
var watchers = /* @__PURE__ */ new Set();
|
|
9
|
+
function leaseAssetRefs(refs) {
|
|
10
|
+
const held = [...new Set(refs)];
|
|
11
|
+
for (const ref of held) {
|
|
12
|
+
leases.set(ref, (leases.get(ref) ?? 0) + 1);
|
|
13
|
+
for (const touched of watchers) touched.add(ref);
|
|
14
|
+
}
|
|
15
|
+
let released = false;
|
|
16
|
+
return () => {
|
|
17
|
+
if (released) return;
|
|
18
|
+
released = true;
|
|
19
|
+
for (const ref of held) {
|
|
20
|
+
const n = (leases.get(ref) ?? 1) - 1;
|
|
21
|
+
if (n > 0) leases.set(ref, n);
|
|
22
|
+
else leases.delete(ref);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function watchAssetLeases() {
|
|
27
|
+
const touched = new Set(leases.keys());
|
|
28
|
+
watchers.add(touched);
|
|
29
|
+
return { touched, stop: () => void watchers.delete(touched) };
|
|
30
|
+
}
|
|
31
|
+
function withAssetLock(prefix, mode, task) {
|
|
32
|
+
let locks;
|
|
33
|
+
try {
|
|
34
|
+
locks = globalThis.navigator?.locks;
|
|
35
|
+
} catch {
|
|
36
|
+
locks = void 0;
|
|
37
|
+
}
|
|
38
|
+
if (!locks || typeof locks.request !== "function") return task();
|
|
39
|
+
return locks.request(`pixerate-editor-assets:${prefix}`, { mode }, task);
|
|
40
|
+
}
|
|
41
|
+
|
|
6
42
|
// src/persistence/assets.ts
|
|
7
43
|
var EDITOR_ASSET_PREFIX = "pixerate-asset:";
|
|
8
44
|
var REF = /pixerate-asset:[0-9a-z]+-[0-9a-z]+(?:~[0-9]+)?/g;
|
|
@@ -45,7 +81,8 @@ function createEditorAssetRegistry() {
|
|
|
45
81
|
},
|
|
46
82
|
get size() {
|
|
47
83
|
return byRef.size;
|
|
48
|
-
}
|
|
84
|
+
},
|
|
85
|
+
refs: () => [...byRef.keys()]
|
|
49
86
|
};
|
|
50
87
|
}
|
|
51
88
|
function externalizeAssets(value, registry) {
|
|
@@ -85,11 +122,22 @@ function internalizeAssets(value, registry) {
|
|
|
85
122
|
return walk(value);
|
|
86
123
|
}
|
|
87
124
|
var persisted = /* @__PURE__ */ new WeakMap();
|
|
88
|
-
var
|
|
125
|
+
var assetPrefix = (options) => options.prefix ?? "pixerate.assets:";
|
|
126
|
+
var assetKey = (ref, options) => `${assetPrefix(options)}${ref.slice(EDITOR_ASSET_PREFIX.length)}`;
|
|
127
|
+
var markerKey = (options) => `${assetPrefix(options)}#collected`;
|
|
128
|
+
var ASSET_ID = /^[0-9a-z]+-[0-9a-z]+(?:~[0-9]+)?$/;
|
|
89
129
|
async function persistEditorAssets(storage, registry, document, options = {}) {
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
130
|
+
const refs = collectAssetRefs(document);
|
|
131
|
+
if (!refs.length) return;
|
|
132
|
+
const cache = persisted.get(storage) ?? { marker: void 0, keys: /* @__PURE__ */ new Set() };
|
|
133
|
+
persisted.set(storage, cache);
|
|
134
|
+
const marker = await storage.get(markerKey(options)).catch(() => void 0);
|
|
135
|
+
if (marker === void 0 || marker !== cache.marker) {
|
|
136
|
+
cache.keys.clear();
|
|
137
|
+
cache.marker = marker;
|
|
138
|
+
}
|
|
139
|
+
const written = cache.keys;
|
|
140
|
+
for (const ref of refs) {
|
|
93
141
|
const key = assetKey(ref, options);
|
|
94
142
|
if (written.has(key)) continue;
|
|
95
143
|
const data = registry.get(ref);
|
|
@@ -120,12 +168,135 @@ function withEditorAssets(storage, registry, options = {}) {
|
|
|
120
168
|
return value;
|
|
121
169
|
},
|
|
122
170
|
async set(key, value) {
|
|
123
|
-
if (value.includes(EDITOR_ASSET_PREFIX))
|
|
124
|
-
await storage.set(key, value);
|
|
171
|
+
if (!value.includes(EDITOR_ASSET_PREFIX)) return storage.set(key, value);
|
|
172
|
+
await writeWithAssets(storage, registry, value, options, () => storage.set(key, value));
|
|
125
173
|
},
|
|
126
|
-
remove: (key) => storage.remove(key)
|
|
174
|
+
remove: (key) => storage.remove(key),
|
|
175
|
+
...storage.keys ? { keys: (prefix) => storage.keys(prefix) } : {}
|
|
127
176
|
};
|
|
128
177
|
}
|
|
178
|
+
async function writeWithAssets(storage, registry, document, options, write) {
|
|
179
|
+
const release = leaseAssetRefs(collectAssetRefs(document));
|
|
180
|
+
try {
|
|
181
|
+
await withAssetLock(assetPrefix(options), "shared", async () => {
|
|
182
|
+
if (registry) await persistEditorAssets(storage, registry, document, options);
|
|
183
|
+
await write();
|
|
184
|
+
});
|
|
185
|
+
} finally {
|
|
186
|
+
release();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
var isRegistry = (value) => !!value && typeof value === "object" && ["put", "get", "has", "set"].every((k) => typeof value[k] === "function");
|
|
190
|
+
var refChars = (ref) => parseInt(ref.slice(EDITOR_ASSET_PREFIX.length).split("-")[0], 36) || 0;
|
|
191
|
+
function keptRefs(keep) {
|
|
192
|
+
const out = /* @__PURE__ */ new Set();
|
|
193
|
+
const addRegistry = (registry) => {
|
|
194
|
+
if (typeof registry.refs !== "function") {
|
|
195
|
+
throw new Error("A registry passed in keep cannot list its references (it has no refs()). Use createEditorAssetRegistry, or pass the documents to keep instead.");
|
|
196
|
+
}
|
|
197
|
+
for (const ref of registry.refs()) out.add(ref);
|
|
198
|
+
};
|
|
199
|
+
for (const item of keep) {
|
|
200
|
+
if (isRegistry(item)) addRegistry(item);
|
|
201
|
+
else if (item && typeof item === "object" && isRegistry(item.assets)) addRegistry(item.assets);
|
|
202
|
+
else for (const ref of collectAssetRefs(item)) out.add(ref);
|
|
203
|
+
}
|
|
204
|
+
return out;
|
|
205
|
+
}
|
|
206
|
+
async function collectEditorAssetGarbage(storage, options = {}) {
|
|
207
|
+
if (typeof storage.keys !== "function") {
|
|
208
|
+
throw new Error(
|
|
209
|
+
`This ${storage.kind} storage cannot list its keys, so unreferenced assets cannot be found. Give the adapter a keys(prefix) method (every built-in adapter has one).`
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
const listKeys = storage.keys.bind(storage);
|
|
213
|
+
const prefix = assetPrefix(options);
|
|
214
|
+
const keep = keptRefs(options.keep ?? []);
|
|
215
|
+
const dryRun = options.dryRun === true;
|
|
216
|
+
return withAssetLock(prefix, "exclusive", async () => {
|
|
217
|
+
const watch = watchAssetLeases();
|
|
218
|
+
try {
|
|
219
|
+
const assetKeys = (await listKeys(prefix)).filter((key) => ASSET_ID.test(key.slice(prefix.length)));
|
|
220
|
+
const others = (await listKeys("")).filter((key) => !key.startsWith(prefix));
|
|
221
|
+
const live = /* @__PURE__ */ new Set();
|
|
222
|
+
for (const key of others) {
|
|
223
|
+
const value = await storage.get(key);
|
|
224
|
+
if (value !== null && value.includes(EDITOR_ASSET_PREFIX)) for (const ref of collectAssetRefs(value)) live.add(ref);
|
|
225
|
+
}
|
|
226
|
+
const toRef = (key) => `${EDITOR_ASSET_PREFIX}${key.slice(prefix.length)}`;
|
|
227
|
+
let referenced = 0;
|
|
228
|
+
let kept = 0;
|
|
229
|
+
const candidates = [];
|
|
230
|
+
for (const key of assetKeys) {
|
|
231
|
+
const ref = toRef(key);
|
|
232
|
+
if (live.has(ref)) referenced++;
|
|
233
|
+
else if (keep.has(ref) || watch.touched.has(ref)) kept++;
|
|
234
|
+
else candidates.push(ref);
|
|
235
|
+
}
|
|
236
|
+
let unreferenced = candidates;
|
|
237
|
+
if (options.only) {
|
|
238
|
+
const wanted = new Set(options.only);
|
|
239
|
+
const stale = [...wanted].filter((ref) => !candidates.includes(ref));
|
|
240
|
+
if (stale.length) {
|
|
241
|
+
throw new Error(
|
|
242
|
+
`${stale.length} of the given asset${stale.length === 1 ? " is" : "s are"} not unreferenced in storage now (${stale.slice(0, 3).join(", ")}${stale.length > 3 ? ", \u2026" : ""}): unknown, already deleted, referenced or in use. Nothing was deleted; find the unreferenced assets again.`
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
unreferenced = candidates.filter((ref) => wanted.has(ref));
|
|
246
|
+
}
|
|
247
|
+
const report = {
|
|
248
|
+
assets: assetKeys.length,
|
|
249
|
+
scannedKeys: others.length,
|
|
250
|
+
referenced,
|
|
251
|
+
kept,
|
|
252
|
+
unreferenced,
|
|
253
|
+
unreferencedChars: unreferenced.reduce((n, ref) => n + refChars(ref), 0),
|
|
254
|
+
removed: [],
|
|
255
|
+
freedChars: 0,
|
|
256
|
+
dryRun
|
|
257
|
+
};
|
|
258
|
+
if (dryRun || !unreferenced.length) return report;
|
|
259
|
+
await storage.set(markerKey(options), `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`);
|
|
260
|
+
for (const ref of unreferenced) {
|
|
261
|
+
if (watch.touched.has(ref)) {
|
|
262
|
+
report.kept++;
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
try {
|
|
266
|
+
await storage.remove(assetKey(ref, options));
|
|
267
|
+
} catch (error) {
|
|
268
|
+
throw new Error(
|
|
269
|
+
`Deleted ${report.removed.length} of ${unreferenced.length} unreferenced assets, then storage failed: ${error instanceof Error ? error.message : String(error)}. The rest are still stored and nothing refers to the deleted ones; run the collection again.`
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
report.removed.push(ref);
|
|
273
|
+
report.freedChars += refChars(ref);
|
|
274
|
+
}
|
|
275
|
+
return report;
|
|
276
|
+
} finally {
|
|
277
|
+
watch.stop();
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
async function tryCollectEditorAssetGarbage(storage, options = {}) {
|
|
282
|
+
if (typeof storage.keys !== "function") return null;
|
|
283
|
+
try {
|
|
284
|
+
return await collectEditorAssetGarbage(storage, options);
|
|
285
|
+
} catch {
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
async function collectRetiredEditorAssets(storage, doc, setting = true) {
|
|
290
|
+
if (!doc.assets || setting === false) return null;
|
|
291
|
+
const extra = setting === true ? {} : setting;
|
|
292
|
+
let current;
|
|
293
|
+
try {
|
|
294
|
+
current = doc.getDocument();
|
|
295
|
+
} catch {
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
return tryCollectEditorAssetGarbage(storage, { ...extra, keep: [current, ...extra.keep ?? []] });
|
|
299
|
+
}
|
|
129
300
|
|
|
130
301
|
// src/persistence/migrate.ts
|
|
131
302
|
function hasLoadProblems(report) {
|
|
@@ -378,6 +549,9 @@ export {
|
|
|
378
549
|
persistEditorAssets,
|
|
379
550
|
preloadEditorAssets,
|
|
380
551
|
withEditorAssets,
|
|
552
|
+
collectEditorAssetGarbage,
|
|
553
|
+
tryCollectEditorAssetGarbage,
|
|
554
|
+
collectRetiredEditorAssets,
|
|
381
555
|
hasLoadProblems,
|
|
382
556
|
createLoadReport,
|
|
383
557
|
migrateDocument,
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
var
|
|
21
|
+
var _chunkEGZM52EOcjs = require('./chunk-EGZM52EO.cjs');
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
@@ -29,7 +29,7 @@ var _chunkGF2RBSDMcjs = require('./chunk-GF2RBSDM.cjs');
|
|
|
29
29
|
var _chunkDWJJI6RTcjs = require('./chunk-DWJJI6RT.cjs');
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
var
|
|
32
|
+
var _chunk4ZC5QJE2cjs = require('./chunk-4ZC5QJE2.cjs');
|
|
33
33
|
|
|
34
34
|
// src/vector/blend.ts
|
|
35
35
|
var lerpN = (a, b, t) => a + (b - a) * t;
|
|
@@ -37,7 +37,7 @@ var lerpP = (a, b, t) => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t];
|
|
|
37
37
|
var toP = (v) => [v.x, v.y];
|
|
38
38
|
var mapP = (m, p) => [m[0] * p[0] + m[2] * p[1] + m[4], m[1] * p[0] + m[3] * p[1] + m[5]];
|
|
39
39
|
var curvesOf = (c) => Math.max(0, (c.pts.length - 1) / 3) | 0;
|
|
40
|
-
function subpathToMorphContour(sp, m =
|
|
40
|
+
function subpathToMorphContour(sp, m = _chunkEGZM52EOcjs.IDENTITY_MATRIX) {
|
|
41
41
|
const n = sp.anchors.length;
|
|
42
42
|
if (!n) return null;
|
|
43
43
|
const first = mapP(m, toP(sp.anchors[0]));
|
|
@@ -67,8 +67,8 @@ function isStraight(p0, p1, p2, p3) {
|
|
|
67
67
|
const u2 = along(p2);
|
|
68
68
|
return off(p1) < tol && off(p2) < tol && u1 >= -1e-9 && u1 <= 1 + 1e-9 && u2 >= -1e-9 && u2 <= 1 + 1e-9;
|
|
69
69
|
}
|
|
70
|
-
function morphContourToSubpath(c, m =
|
|
71
|
-
const pts =
|
|
70
|
+
function morphContourToSubpath(c, m = _chunkEGZM52EOcjs.IDENTITY_MATRIX, closed = c.closed) {
|
|
71
|
+
const pts = _chunkEGZM52EOcjs.isIdentityMatrix.call(void 0, m) ? c.pts : c.pts.map((p) => mapP(m, p));
|
|
72
72
|
const curves = curvesOf(c);
|
|
73
73
|
const dropLast = closed && c.closed && curves > 0;
|
|
74
74
|
const count = dropLast ? curves : curves + 1;
|
|
@@ -84,7 +84,7 @@ function morphContourToSubpath(c, m = _chunkJCXMJUQOcjs.IDENTITY_MATRIX, closed
|
|
|
84
84
|
anchors[(k + 1) % count].in = { x: p2[0], y: p2[1] };
|
|
85
85
|
}
|
|
86
86
|
for (const a of anchors) {
|
|
87
|
-
const type =
|
|
87
|
+
const type = _chunkEGZM52EOcjs.inferAnchorType.call(void 0, a);
|
|
88
88
|
if (type !== "corner") a.type = type;
|
|
89
89
|
}
|
|
90
90
|
const isClosed = closed && curves > 0;
|
|
@@ -267,7 +267,7 @@ function bestStart(fixed, free, useShapeContext) {
|
|
|
267
267
|
return best;
|
|
268
268
|
}
|
|
269
269
|
function placeIn(c, from, to) {
|
|
270
|
-
const b =
|
|
270
|
+
const b = _chunkEGZM52EOcjs.unionBounds.call(void 0, [boundsOfPoints(c.pts)]);
|
|
271
271
|
const p = b ? [b.x + b.width / 2, b.y + b.height / 2] : c.pts[0];
|
|
272
272
|
if (!from || !to) return p;
|
|
273
273
|
const fx = from.width > 0 ? (p[0] - from.x) / from.width : 0.5;
|
|
@@ -452,11 +452,11 @@ function interpolateRigidMatrix(a, b, t) {
|
|
|
452
452
|
function interpolateVectorColor(a, b, t) {
|
|
453
453
|
if (t <= 0) return a;
|
|
454
454
|
if (t >= 1) return b;
|
|
455
|
-
return _nullishCoalesce(
|
|
455
|
+
return _nullishCoalesce(_chunk4ZC5QJE2cjs.mixColorsOklab.call(void 0, a, b, t), () => ( (t < 0.5 ? a : b)));
|
|
456
456
|
}
|
|
457
457
|
function resampleGradientStops(g, offsets) {
|
|
458
458
|
return offsets.map((offset) => {
|
|
459
|
-
const s =
|
|
459
|
+
const s = _chunkEGZM52EOcjs.sampleVectorGradient.call(void 0, g, offset);
|
|
460
460
|
return s.opacity < 1 ? { offset, color: s.color, opacity: Math.round(s.opacity * 1e4) / 1e4 } : { offset, color: s.color };
|
|
461
461
|
});
|
|
462
462
|
}
|
|
@@ -467,11 +467,11 @@ function lerpAngle(a, b, t) {
|
|
|
467
467
|
var lerpPoint = (a, b, t) => ({ x: lerpN(a.x, b.x, t), y: lerpN(a.y, b.y, t) });
|
|
468
468
|
var sameColourModel = (a, b) => (_nullishCoalesce(a.interpolation, () => ( "srgb"))) === (_nullishCoalesce(b.interpolation, () => ( "srgb"))) && (_nullishCoalesce(a.smoothness, () => ( 0))) === (_nullishCoalesce(b.smoothness, () => ( 0)));
|
|
469
469
|
function lerpStops(a, b, t) {
|
|
470
|
-
let stopsA =
|
|
471
|
-
let stopsB =
|
|
470
|
+
let stopsA = _chunkEGZM52EOcjs.sortedVectorGradientStops.call(void 0, a);
|
|
471
|
+
let stopsB = _chunkEGZM52EOcjs.sortedVectorGradientStops.call(void 0, b);
|
|
472
472
|
const resampled = stopsA.length !== stopsB.length || !sameColourModel(a, b);
|
|
473
473
|
if (resampled) {
|
|
474
|
-
const offs = [...
|
|
474
|
+
const offs = [..._chunkEGZM52EOcjs.expandVectorGradientStops.call(void 0, a), ..._chunkEGZM52EOcjs.expandVectorGradientStops.call(void 0, b), ...stopsA, ...stopsB].map((s) => s.offset).filter(Number.isFinite).sort((x, y) => x - y);
|
|
475
475
|
const common = offs.filter((o, i) => i === 0 || o - offs[i - 1] > 1e-4);
|
|
476
476
|
stopsA = resampleGradientStops(a, common);
|
|
477
477
|
stopsB = resampleGradientStops(b, common);
|
|
@@ -498,8 +498,8 @@ function lerpGradient(a, b, t) {
|
|
|
498
498
|
}
|
|
499
499
|
if (near.spread && near.spread !== "pad") out.spread = near.spread;
|
|
500
500
|
if (near.strokeMode && near.strokeMode !== "within") out.strokeMode = near.strokeMode;
|
|
501
|
-
const ea =
|
|
502
|
-
const eb =
|
|
501
|
+
const ea = _chunkEGZM52EOcjs.hasExplicitGradientGeometry.call(void 0, a);
|
|
502
|
+
const eb = _chunkEGZM52EOcjs.hasExplicitGradientGeometry.call(void 0, b);
|
|
503
503
|
if (!ea && !eb) {
|
|
504
504
|
if (a.angle !== void 0 || b.angle !== void 0 || a.type === "linear" || a.type === "reflected") {
|
|
505
505
|
const fallback = a.type === "linear" || a.type === "reflected" ? 180 : 90;
|
|
@@ -512,10 +512,10 @@ function lerpGradient(a, b, t) {
|
|
|
512
512
|
}
|
|
513
513
|
return out;
|
|
514
514
|
}
|
|
515
|
-
const pa =
|
|
516
|
-
const pb =
|
|
515
|
+
const pa = _chunkEGZM52EOcjs.vectorGradientPoints.call(void 0, a);
|
|
516
|
+
const pb = _chunkEGZM52EOcjs.vectorGradientPoints.call(void 0, b);
|
|
517
517
|
if (pa.units !== pb.units) {
|
|
518
|
-
const src =
|
|
518
|
+
const src = _chunkEGZM52EOcjs.explicitVectorGradient.call(void 0, near);
|
|
519
519
|
return { ...src, stops: out.stops, ...out.interpolation ? { interpolation: out.interpolation } : {}, ...out.smoothness ? { smoothness: out.smoothness } : {} };
|
|
520
520
|
}
|
|
521
521
|
out.start = lerpPoint(pa.start, pb.start, t);
|
|
@@ -535,14 +535,14 @@ function solidLike(color, like) {
|
|
|
535
535
|
function interpolateVectorPaint(a, b, t) {
|
|
536
536
|
if (t <= 0) return a;
|
|
537
537
|
if (t >= 1) return b;
|
|
538
|
-
const pa =
|
|
539
|
-
const pb =
|
|
538
|
+
const pa = _chunkEGZM52EOcjs.hasPaint.call(void 0, a);
|
|
539
|
+
const pb = _chunkEGZM52EOcjs.hasPaint.call(void 0, b);
|
|
540
540
|
if (!pa && !pb) return t < 0.5 ? a : b;
|
|
541
541
|
if (typeof a === "string" && pa && typeof b === "string" && pb) return interpolateVectorColor(a, b, t);
|
|
542
542
|
if (!pa && typeof b === "string") return interpolateVectorColor("transparent", b, t);
|
|
543
543
|
if (!pb && typeof a === "string") return interpolateVectorColor(a, "transparent", t);
|
|
544
|
-
const ga = pa &&
|
|
545
|
-
const gb = pb &&
|
|
544
|
+
const ga = pa && _chunkEGZM52EOcjs.isVectorGradient.call(void 0, a) ? a : null;
|
|
545
|
+
const gb = pb && _chunkEGZM52EOcjs.isVectorGradient.call(void 0, b) ? b : null;
|
|
546
546
|
if (ga && gb) return _nullishCoalesce(lerpGradient(ga, gb, t), () => ( (t < 0.5 ? a : b)));
|
|
547
547
|
if (gb) return _nullishCoalesce(lerpGradient(solidLike(pa ? a : null, gb), gb, t), () => ( b));
|
|
548
548
|
if (ga) return _nullishCoalesce(lerpGradient(ga, solidLike(pb ? b : null, ga), t), () => ( a));
|
|
@@ -553,8 +553,8 @@ function interpolateWidthProfiles(a, b, t) {
|
|
|
553
553
|
const at = [..._nullishCoalesce(a, () => ( [])), ..._nullishCoalesce(b, () => ( [])), { t: 0 }, { t: 1 }].map((p) => p.t).sort((x, y) => x - y);
|
|
554
554
|
const ts = at.filter((v, i) => i === 0 || v - at[i - 1] > 1e-6);
|
|
555
555
|
return ts.map((pos) => {
|
|
556
|
-
const x =
|
|
557
|
-
const y =
|
|
556
|
+
const x = _chunkEGZM52EOcjs.widthProfileAt.call(void 0, a, pos);
|
|
557
|
+
const y = _chunkEGZM52EOcjs.widthProfileAt.call(void 0, b, pos);
|
|
558
558
|
return { t: pos, left: lerpN(x.left, y.left, t), right: lerpN(x.right, y.right, t) };
|
|
559
559
|
});
|
|
560
560
|
}
|
|
@@ -597,7 +597,7 @@ function reversedStyle(s) {
|
|
|
597
597
|
out.endArrow = s.startArrow;
|
|
598
598
|
out.startArrowScale = s.endArrowScale;
|
|
599
599
|
out.endArrowScale = s.startArrowScale;
|
|
600
|
-
if (_optionalChain([s, 'access', _6 => _6.strokeWidthProfile, 'optionalAccess', _7 => _7.length])) out.strokeWidthProfile =
|
|
600
|
+
if (_optionalChain([s, 'access', _6 => _6.strokeWidthProfile, 'optionalAccess', _7 => _7.length])) out.strokeWidthProfile = _chunkEGZM52EOcjs.reverseWidthProfile.call(void 0, s.strokeWidthProfile);
|
|
601
601
|
for (const k of ["startArrow", "endArrow", "startArrowScale", "endArrowScale"]) if (out[k] === void 0) delete out[k];
|
|
602
602
|
return out;
|
|
603
603
|
}
|
|
@@ -623,19 +623,19 @@ function styleOf(n) {
|
|
|
623
623
|
return out;
|
|
624
624
|
}
|
|
625
625
|
function contoursOf(node, m) {
|
|
626
|
-
return
|
|
626
|
+
return _chunkEGZM52EOcjs.expandVectorCorners.call(void 0, node.subpaths).map((sp) => subpathToMorphContour(sp, m)).filter((c) => !!c);
|
|
627
627
|
}
|
|
628
|
-
function preparePathMorph(a, b, options, ma =
|
|
628
|
+
function preparePathMorph(a, b, options, ma = _chunkEGZM52EOcjs.nodeMatrix.call(void 0, a), mb = _chunkEGZM52EOcjs.nodeMatrix.call(void 0, b)) {
|
|
629
629
|
const corr = correspondMorphContours(contoursOf(a, ma), contoursOf(b, mb), options);
|
|
630
630
|
const sim = procrustes(corr.a, corr.b);
|
|
631
631
|
const styleA = styleOf(a);
|
|
632
632
|
const styleB = corr.reversed ? reversedStyle(styleOf(b)) : styleOf(b);
|
|
633
|
-
const rigid = !
|
|
633
|
+
const rigid = !_chunkEGZM52EOcjs.isIdentityMatrix.call(void 0, ma) || !_chunkEGZM52EOcjs.isIdentityMatrix.call(void 0, mb);
|
|
634
634
|
const id = _nullishCoalesce(options.id, () => ( a.id));
|
|
635
635
|
return (t) => {
|
|
636
636
|
const contours = interpolateMorphContours(corr.a, corr.b, t, { linear: options.linear, rigidity: options.rigidity, similarity: sim });
|
|
637
|
-
const m = rigid ? interpolateRigidMatrix(ma, mb, t) :
|
|
638
|
-
const back = rigid ?
|
|
637
|
+
const m = rigid ? interpolateRigidMatrix(ma, mb, t) : _chunkEGZM52EOcjs.IDENTITY_MATRIX;
|
|
638
|
+
const back = rigid ? _chunkEGZM52EOcjs.invertMatrix.call(void 0, m) : _chunkEGZM52EOcjs.IDENTITY_MATRIX;
|
|
639
639
|
const subpaths = contours.map((c, k) => {
|
|
640
640
|
const closed = t <= 0 ? corr.a[k].closed : t >= 1 ? corr.b[k].closed : corr.a[k].closed && corr.b[k].closed;
|
|
641
641
|
return morphContourToSubpath({ closed: corr.a[k].closed && corr.b[k].closed, pts: c.pts }, back, closed);
|
|
@@ -643,14 +643,14 @@ function preparePathMorph(a, b, options, ma = _chunkJCXMJUQOcjs.nodeMatrix.call(
|
|
|
643
643
|
const node = { id, type: "path", subpaths, ...interpolateVectorStyle(styleA, styleB, t) };
|
|
644
644
|
const opacity = lerpN(_nullishCoalesce(a.opacity, () => ( 1)), _nullishCoalesce(b.opacity, () => ( 1)), t);
|
|
645
645
|
if (opacity < 1) node.opacity = opacity;
|
|
646
|
-
if (rigid && !
|
|
646
|
+
if (rigid && !_chunkEGZM52EOcjs.isIdentityMatrix.call(void 0, m)) node.transform = m;
|
|
647
647
|
return node;
|
|
648
648
|
};
|
|
649
649
|
}
|
|
650
|
-
function flattenPaths(node, parent =
|
|
651
|
-
const m =
|
|
650
|
+
function flattenPaths(node, parent = _chunkEGZM52EOcjs.IDENTITY_MATRIX) {
|
|
651
|
+
const m = _chunkEGZM52EOcjs.multiplyMatrices.call(void 0, _chunkEGZM52EOcjs.nodeMatrix.call(void 0, node), parent);
|
|
652
652
|
if (node.type === "path") return [{ path: node, m, opacity: 1 }];
|
|
653
|
-
if (node.type === "text" || node.type === "instance") return flattenPaths(
|
|
653
|
+
if (node.type === "text" || node.type === "instance") return flattenPaths(_chunkEGZM52EOcjs.expandVectorAppearance.call(void 0, node), parent);
|
|
654
654
|
const o = _nullishCoalesce(node.opacity, () => ( 1));
|
|
655
655
|
return node.children.filter((c) => c.visible !== false).flatMap((c) => flattenPaths(c, m)).map((e) => ({ ...e, opacity: e.opacity * o }));
|
|
656
656
|
}
|
|
@@ -672,8 +672,8 @@ function createVectorMorph(a, b, options = {}) {
|
|
|
672
672
|
}
|
|
673
673
|
const pa = flattenPaths(a);
|
|
674
674
|
const pb = flattenPaths(b);
|
|
675
|
-
const ba =
|
|
676
|
-
const bb =
|
|
675
|
+
const ba = _chunkEGZM52EOcjs.unionBounds.call(void 0, pa.map((e) => placedBounds(e.path, e.m)));
|
|
676
|
+
const bb = _chunkEGZM52EOcjs.unionBounds.call(void 0, pb.map((e) => placedBounds(e.path, e.m)));
|
|
677
677
|
const id = _nullishCoalesce(options.id, () => ( a.id));
|
|
678
678
|
const parts = [];
|
|
679
679
|
const opacities = [];
|
|
@@ -685,10 +685,10 @@ function createVectorMorph(a, b, options = {}) {
|
|
|
685
685
|
parts.push(preparePathMorph(x.path, y.path, sub, x.m, y.m));
|
|
686
686
|
opacities.push([x.opacity, y.opacity]);
|
|
687
687
|
} else if (x) {
|
|
688
|
-
parts.push(preparePathMorph(x.path, collapsedPath(x.path, x.m, ba, bb), sub, x.m,
|
|
688
|
+
parts.push(preparePathMorph(x.path, collapsedPath(x.path, x.m, ba, bb), sub, x.m, _chunkEGZM52EOcjs.IDENTITY_MATRIX));
|
|
689
689
|
opacities.push([x.opacity, x.opacity]);
|
|
690
690
|
} else if (y) {
|
|
691
|
-
parts.push(preparePathMorph(collapsedPath(y.path, y.m, bb, ba), y.path, sub,
|
|
691
|
+
parts.push(preparePathMorph(collapsedPath(y.path, y.m, bb, ba), y.path, sub, _chunkEGZM52EOcjs.IDENTITY_MATRIX, y.m));
|
|
692
692
|
opacities.push([y.opacity, y.opacity]);
|
|
693
693
|
}
|
|
694
694
|
}
|
|
@@ -253,6 +253,12 @@ var ToolRegistryView = class {
|
|
|
253
253
|
return set.tools.some((t) => this.enabledTools.has(t)) ? "some" : "none";
|
|
254
254
|
};
|
|
255
255
|
const listedCount = () => this.listed(this.catalogue()).length;
|
|
256
|
+
const styleOf = async (set) => {
|
|
257
|
+
const domain = set.skill?.replace(/^pixerate-/, "");
|
|
258
|
+
if (!discovery.styles || !domain || !discovery.styles.domains.some((d) => d.id === domain)) return void 0;
|
|
259
|
+
const style = await discovery.styles.resolve(domain);
|
|
260
|
+
return style.skills.length ? { domain, skills: style.skills.length, layers: [...new Set(style.skills.map((s) => s.layer))] } : void 0;
|
|
261
|
+
};
|
|
256
262
|
const tools = [
|
|
257
263
|
{
|
|
258
264
|
name: "list_toolsets",
|
|
@@ -260,16 +266,18 @@ var ToolRegistryView = class {
|
|
|
260
266
|
description: "Lists the groups of editor tools available here (one per open editor or feature): name, title, what it covers, its agent skill, how many tools it has and whether they are in your tool list (`enabled`: all, some or none). Start here, then call search_tools or enable_tools.",
|
|
261
267
|
annotations: READ_ONLY,
|
|
262
268
|
inputSchema: { type: "object", properties: {}, additionalProperties: false },
|
|
263
|
-
handler: () => {
|
|
269
|
+
handler: async () => {
|
|
264
270
|
const cat = this.catalogue();
|
|
271
|
+
const styles = await Promise.all(cat.sets.map(styleOf));
|
|
265
272
|
return {
|
|
266
|
-
toolsets: cat.sets.map((set) => ({
|
|
273
|
+
toolsets: cat.sets.map((set, i) => ({
|
|
267
274
|
name: set.name,
|
|
268
275
|
...set.title ? { title: set.title } : {},
|
|
269
276
|
...set.description ? { description: set.description } : {},
|
|
270
277
|
...set.skill ? { skill: set.skill } : {},
|
|
271
278
|
tools: set.tools.length,
|
|
272
|
-
enabled: enabledState(set)
|
|
279
|
+
enabled: enabledState(set),
|
|
280
|
+
...styles[i] ? { style: styles[i] } : {}
|
|
273
281
|
})),
|
|
274
282
|
...skills.length > 0 ? { skills: skills.map((s) => s.name) } : {}
|
|
275
283
|
};
|
|
@@ -312,9 +320,12 @@ var ToolRegistryView = class {
|
|
|
312
320
|
description: "Adds tools to your tool list: single tools by name (from search_tools) and/or whole toolsets (from list_toolsets). Returns the names added and how many tools are listed now. Prefer single tools over large toolsets. Unknown names fail and change nothing.",
|
|
313
321
|
annotations: LISTING,
|
|
314
322
|
inputSchema: SELECTION_SCHEMA,
|
|
315
|
-
handler: (args) => {
|
|
323
|
+
handler: async (args) => {
|
|
316
324
|
const added = this.enableTools(args);
|
|
317
|
-
|
|
325
|
+
const sets = this.catalogue().sets.filter((set) => set.tools.some((t) => added.includes(t)));
|
|
326
|
+
const domains = (await Promise.all(sets.map(styleOf))).filter((s) => s !== void 0).map((s) => s.domain);
|
|
327
|
+
const style = [...new Set(domains)].map((d) => `House style applies: call get_style with domain "${d}" before making changes.`);
|
|
328
|
+
return { added, listed: listedCount(), ...style.length ? { style } : {} };
|
|
318
329
|
}
|
|
319
330
|
},
|
|
320
331
|
{
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import {
|
|
2
|
+
contrastLevel,
|
|
3
|
+
contrastRatio,
|
|
4
|
+
linearSrgbToDisplayP3,
|
|
5
|
+
linearToSrgb,
|
|
6
|
+
oklabToOklch,
|
|
7
|
+
oklabToRgb,
|
|
8
|
+
oklchToOklab,
|
|
9
|
+
parseColor,
|
|
10
|
+
rgbToHsl,
|
|
11
|
+
rgbToOklab,
|
|
12
|
+
srgbToLinear
|
|
13
|
+
} from "./chunk-MHLU6GRJ.js";
|
|
14
|
+
|
|
15
|
+
// src/color/gamut.ts
|
|
16
|
+
var clamp01 = (v) => Math.min(1, Math.max(0, v));
|
|
17
|
+
function inSrgbGamut(c, epsilon = 1e-5) {
|
|
18
|
+
return c.r >= -epsilon && c.r <= 1 + epsilon && c.g >= -epsilon && c.g <= 1 + epsilon && c.b >= -epsilon && c.b <= 1 + epsilon;
|
|
19
|
+
}
|
|
20
|
+
function deltaEOK(a, b) {
|
|
21
|
+
const la = rgbToOklab(a);
|
|
22
|
+
const lb = rgbToOklab(b);
|
|
23
|
+
return Math.hypot(la.l - lb.l, la.a - lb.a, la.b - lb.b);
|
|
24
|
+
}
|
|
25
|
+
function toSrgbGamut(c) {
|
|
26
|
+
const lch = oklabToOklch(rgbToOklab(c));
|
|
27
|
+
if (lch.l >= 1) return { r: 1, g: 1, b: 1, a: c.a };
|
|
28
|
+
if (lch.l <= 0) return { r: 0, g: 0, b: 0, a: c.a };
|
|
29
|
+
if (inSrgbGamut(c)) {
|
|
30
|
+
return { r: clamp01(c.r), g: clamp01(c.g), b: clamp01(c.b), a: c.a };
|
|
31
|
+
}
|
|
32
|
+
let low = 0;
|
|
33
|
+
let high = lch.c;
|
|
34
|
+
let clippedCandidate = { r: clamp01(c.r), g: clamp01(c.g), b: clamp01(c.b), a: c.a };
|
|
35
|
+
const JND = 0.02;
|
|
36
|
+
const EPS = 1e-4;
|
|
37
|
+
for (let i = 0; i < 30; i++) {
|
|
38
|
+
const mid = (low + high) / 2;
|
|
39
|
+
const candidate = oklabToRgb(oklchToOklab({ l: lch.l, c: mid, h: lch.h, alpha: c.a }));
|
|
40
|
+
const clipped = {
|
|
41
|
+
r: clamp01(candidate.r),
|
|
42
|
+
g: clamp01(candidate.g),
|
|
43
|
+
b: clamp01(candidate.b),
|
|
44
|
+
a: c.a
|
|
45
|
+
};
|
|
46
|
+
clippedCandidate = clipped;
|
|
47
|
+
const dE = deltaEOK(candidate, clipped);
|
|
48
|
+
if (dE < JND) {
|
|
49
|
+
if (JND - dE < EPS) {
|
|
50
|
+
return clipped;
|
|
51
|
+
}
|
|
52
|
+
low = mid;
|
|
53
|
+
} else {
|
|
54
|
+
high = mid;
|
|
55
|
+
}
|
|
56
|
+
if (high - low < 1e-4) {
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return clippedCandidate;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/color/format.ts
|
|
64
|
+
var clamp012 = (v) => Math.min(1, Math.max(0, v));
|
|
65
|
+
var byte = (v) => Math.round(clamp012(v) * 255);
|
|
66
|
+
var hex2 = (n) => n.toString(16).padStart(2, "0");
|
|
67
|
+
var round2 = (n) => (Math.round(n * 100) / 100).toString();
|
|
68
|
+
function formatHex(c) {
|
|
69
|
+
const mapped = toSrgbGamut(c);
|
|
70
|
+
const head = `#${hex2(byte(mapped.r))}${hex2(byte(mapped.g))}${hex2(byte(mapped.b))}`;
|
|
71
|
+
const alpha = byte(mapped.a);
|
|
72
|
+
return alpha === 255 ? head : head + hex2(alpha);
|
|
73
|
+
}
|
|
74
|
+
function formatColor(c, format) {
|
|
75
|
+
switch (format) {
|
|
76
|
+
case "hex":
|
|
77
|
+
return formatHex(c);
|
|
78
|
+
case "rgb": {
|
|
79
|
+
const inGamut = toSrgbGamut(c);
|
|
80
|
+
const r = byte(inGamut.r);
|
|
81
|
+
const g = byte(inGamut.g);
|
|
82
|
+
const b = byte(inGamut.b);
|
|
83
|
+
return c.a < 1 ? `rgb(${r} ${g} ${b} / ${round2(c.a)})` : `rgb(${r} ${g} ${b})`;
|
|
84
|
+
}
|
|
85
|
+
case "hsl": {
|
|
86
|
+
const hsl = rgbToHsl(toSrgbGamut(c));
|
|
87
|
+
const h = (Math.round(hsl.h * 100) / 100).toString();
|
|
88
|
+
const s = (Math.round(hsl.s * 1e4) / 100).toString();
|
|
89
|
+
const l = (Math.round(hsl.l * 1e4) / 100).toString();
|
|
90
|
+
return c.a < 1 ? `hsl(${h} ${s}% ${l}% / ${round2(c.a)})` : `hsl(${h} ${s}% ${l}%)`;
|
|
91
|
+
}
|
|
92
|
+
case "oklch": {
|
|
93
|
+
const lch = oklabToOklch(rgbToOklab(c));
|
|
94
|
+
const l = (lch.l * 100).toFixed(2);
|
|
95
|
+
const ch = lch.c.toFixed(4);
|
|
96
|
+
const h = lch.h.toFixed(2);
|
|
97
|
+
return c.a < 1 ? `oklch(${l}% ${ch} ${h} / ${round2(c.a)})` : `oklch(${l}% ${ch} ${h})`;
|
|
98
|
+
}
|
|
99
|
+
case "oklab": {
|
|
100
|
+
const lab = rgbToOklab(c);
|
|
101
|
+
const l = (lab.l * 100).toFixed(2);
|
|
102
|
+
const a = lab.a.toFixed(4);
|
|
103
|
+
const b = lab.b.toFixed(4);
|
|
104
|
+
return c.a < 1 ? `oklab(${l}% ${a} ${b} / ${round2(c.a)})` : `oklab(${l}% ${a} ${b})`;
|
|
105
|
+
}
|
|
106
|
+
case "p3": {
|
|
107
|
+
const linSrgb = {
|
|
108
|
+
r: srgbToLinear(c.r),
|
|
109
|
+
g: srgbToLinear(c.g),
|
|
110
|
+
b: srgbToLinear(c.b),
|
|
111
|
+
a: c.a
|
|
112
|
+
};
|
|
113
|
+
const linP3 = linearSrgbToDisplayP3(linSrgb);
|
|
114
|
+
const r = linearToSrgb(linP3.r).toFixed(4);
|
|
115
|
+
const g = linearToSrgb(linP3.g).toFixed(4);
|
|
116
|
+
const b = linearToSrgb(linP3.b).toFixed(4);
|
|
117
|
+
return c.a < 1 ? `color(display-p3 ${r} ${g} ${b} / ${round2(c.a)})` : `color(display-p3 ${r} ${g} ${b})`;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function normalizeColor(input) {
|
|
122
|
+
const parsed = parseColor(input);
|
|
123
|
+
return parsed ? formatHex(parsed) : null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// src/color/suggest.ts
|
|
127
|
+
function suggestAccessibleForeground(foreground, background, options = {}) {
|
|
128
|
+
const large = options.large ?? false;
|
|
129
|
+
const lch = oklabToOklch(rgbToOklab(foreground));
|
|
130
|
+
const asHex = (l) => parseColor(formatHex(toSrgbGamut(oklabToRgb(oklchToOklab({ ...lch, l })))));
|
|
131
|
+
for (let d = 0.01; d <= 1; d += 0.01) {
|
|
132
|
+
const downCand = asHex(Math.max(0, lch.l - d));
|
|
133
|
+
const upCand = asHex(Math.min(1, lch.l + d));
|
|
134
|
+
const downRatio = contrastRatio(downCand, background);
|
|
135
|
+
const upRatio = contrastRatio(upCand, background);
|
|
136
|
+
const downPass = contrastLevel(downRatio, { large }) !== "fail";
|
|
137
|
+
const upPass = contrastLevel(upRatio, { large }) !== "fail";
|
|
138
|
+
if (downPass && upPass) return formatHex(downRatio >= upRatio ? downCand : upCand);
|
|
139
|
+
if (downPass) return formatHex(downCand);
|
|
140
|
+
if (upPass) return formatHex(upCand);
|
|
141
|
+
}
|
|
142
|
+
return void 0;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export {
|
|
146
|
+
inSrgbGamut,
|
|
147
|
+
deltaEOK,
|
|
148
|
+
toSrgbGamut,
|
|
149
|
+
formatHex,
|
|
150
|
+
formatColor,
|
|
151
|
+
normalizeColor,
|
|
152
|
+
suggestAccessibleForeground
|
|
153
|
+
};
|