@pixerate/editor 0.164.0 → 0.166.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 +60 -2
- package/dist/chart/controller.d.ts +60 -2
- package/dist/chart/index.cjs +657 -163
- package/dist/chart/index.d.cts +3 -0
- package/dist/chart/index.d.ts +3 -0
- package/dist/chart/index.js +512 -18
- package/dist/chart/layout-families.d.cts +14 -0
- package/dist/chart/layout-families.d.ts +14 -0
- package/dist/chart/layout-shared.d.cts +5 -0
- package/dist/chart/layout-shared.d.ts +5 -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/race.d.cts +26 -0
- package/dist/chart/race.d.ts +26 -0
- package/dist/chart/schemas.d.cts +5 -0
- package/dist/chart/schemas.d.ts +5 -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 +28 -2
- package/dist/chart/types.d.ts +28 -2
- 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-5FNGLV2D.js → chunk-5UNQDC3Q.js} +18 -3
- package/dist/{chunk-YSAGBIRW.cjs → chunk-6FYIFGBW.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-R3P2M7HU.cjs → chunk-BPX4Z3N3.cjs} +355 -207
- package/dist/{chunk-D54JHQK2.cjs → chunk-CHLV7UFP.cjs} +51 -51
- package/dist/{chunk-OXERWBKE.js → chunk-DFCAR7AW.js} +3 -3
- 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-3NEZJCBY.js → chunk-FR432ROA.js} +349 -201
- package/dist/chunk-HIDFL5LQ.js +484 -0
- package/dist/{chunk-22KLZZGH.cjs → chunk-HXOBOHH2.cjs} +8 -8
- package/dist/{chunk-MKTDELCD.js → chunk-I5MRJW7B.js} +1 -1
- package/dist/{chunk-SDHZG5TF.js → chunk-ILP77UD6.js} +160 -2
- package/dist/{chunk-Z4P2RBMJ.js → chunk-ITANXMZD.js} +177 -3
- 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-NZD2MZJC.cjs → chunk-MZFZSVUJ.cjs} +38 -23
- package/dist/{chunk-DAPQGA55.js → chunk-NQQDGGXY.js} +2 -2
- package/dist/chunk-O6OGNDND.js +164 -0
- package/dist/{chunk-PA3IMPPS.cjs → chunk-OVYQAYGH.cjs} +81 -81
- package/dist/{chunk-YXOW456B.js → chunk-PPEDZ5WR.js} +1 -1
- package/dist/{chunk-24M7VD6M.cjs → chunk-S4EIAIEW.cjs} +7 -7
- package/dist/{chunk-M4MIZPQI.cjs → chunk-SJ2CPTQC.cjs} +189 -15
- package/dist/{chunk-YGG7WDWT.cjs → chunk-SZWVMB3B.cjs} +24 -18
- package/dist/chunk-TFF2GTGN.cjs +153 -0
- package/dist/chunk-TTCJPX4U.cjs +204 -0
- package/dist/{chunk-SBQVEBSU.cjs → chunk-UUUTEVX6.cjs} +242 -68
- package/dist/{chunk-WI7QJA7A.cjs → chunk-UXETV2NC.cjs} +161 -3
- package/dist/{chunk-GKNEJ6EN.cjs → chunk-V5L2G22R.cjs} +321 -107
- package/dist/{chunk-TALQONZ5.js → chunk-VB2CY6EG.js} +3 -3
- package/dist/{chunk-QY4KUDMY.js → chunk-VRXXAXUT.js} +2 -2
- package/dist/chunk-VU6WQSMB.cjs +164 -0
- package/dist/{chunk-NHLYK3AX.js → chunk-XBQX76CT.js} +182 -8
- package/dist/{chunk-5AARIS3R.cjs → chunk-XCDGM7TD.cjs} +37 -37
- package/dist/{chunk-POR54B55.js → chunk-XNU45TYA.js} +7 -1
- package/dist/{chunk-EVXQNQND.js → chunk-XZB3TJ6K.js} +16 -5
- package/dist/chunk-YBAPT7NL.js +153 -0
- package/dist/{chunk-SZA42R4N.js → chunk-YUFTVNLX.js} +230 -16
- 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/skills/pixerate-chart/SKILL.md +20 -2
- package/dist/chunk-ERAGQL2N.cjs +0 -68
- package/dist/chunk-KMU6QJB7.js +0 -68
|
@@ -3,6 +3,42 @@
|
|
|
3
3
|
|
|
4
4
|
var _chunk2BSBFBOAcjs = require('./chunk-2BSBFBOA.cjs');
|
|
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, (_nullishCoalesce(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 = (_nullishCoalesce(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 = _optionalChain([globalThis, 'access', _ => _.navigator, 'optionalAccess', _2 => _2.locks]);
|
|
35
|
+
} catch (e) {
|
|
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) => _nullishCoalesce(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 = _nullishCoalesce(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,11 +168,134 @@ 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) } : {}
|
|
176
|
+
};
|
|
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);
|
|
127
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(_nullishCoalesce(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 (e2) {
|
|
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 (e3) {
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
return tryCollectEditorAssetGarbage(storage, { ...extra, keep: [current, ..._nullishCoalesce(extra.keep, () => ( []))] });
|
|
128
299
|
}
|
|
129
300
|
|
|
130
301
|
// src/persistence/migrate.ts
|
|
@@ -148,7 +319,7 @@ function toObject(json) {
|
|
|
148
319
|
if (typeof json === "string") {
|
|
149
320
|
try {
|
|
150
321
|
value = JSON.parse(json);
|
|
151
|
-
} catch (
|
|
322
|
+
} catch (e4) {
|
|
152
323
|
return void 0;
|
|
153
324
|
}
|
|
154
325
|
}
|
|
@@ -185,7 +356,7 @@ function migrateDocument(json, options) {
|
|
|
185
356
|
}
|
|
186
357
|
let doc = deepClone(original);
|
|
187
358
|
for (let step = from; step < target; step++) {
|
|
188
|
-
const fn = _optionalChain([options, 'access',
|
|
359
|
+
const fn = _optionalChain([options, 'access', _3 => _3.steps, 'optionalAccess', _4 => _4[step]]);
|
|
189
360
|
if (!fn) {
|
|
190
361
|
report.readOnly = {
|
|
191
362
|
kind: "migrationFailed",
|
|
@@ -242,7 +413,7 @@ function loadSections(doc, sections, options = {}) {
|
|
|
242
413
|
function loadDocument(json, sections, options) {
|
|
243
414
|
const { doc, report } = migrateDocument(json, options);
|
|
244
415
|
const ignore = _nullishCoalesce(options.ignore, () => ( [_nullishCoalesce(options.versionKey, () => ( "version"))]));
|
|
245
|
-
const result = loadSections(_optionalChain([report, 'access',
|
|
416
|
+
const result = loadSections(_optionalChain([report, 'access', _5 => _5.readOnly, 'optionalAccess', _6 => _6.kind]) === "invalid" ? {} : doc, sections, {
|
|
246
417
|
ignore
|
|
247
418
|
});
|
|
248
419
|
report.problems = result.problems;
|
|
@@ -340,7 +511,7 @@ function defineEditorDocument(spec) {
|
|
|
340
511
|
if (document === void 0 || document === null) throw new EditorDocumentLoadError(`No ${spec.kind} document was given.`);
|
|
341
512
|
try {
|
|
342
513
|
const result = spec.load(spec.assets ? internalizeAssets(document, spec.assets) : document, { history: _nullishCoalesce(options.history, () => ( "reset")) });
|
|
343
|
-
if (_optionalChain([result, 'optionalAccess',
|
|
514
|
+
if (_optionalChain([result, 'optionalAccess', _7 => _7.problems, 'optionalAccess', _8 => _8.length])) report.problems.push(...result.problems);
|
|
344
515
|
} catch (error) {
|
|
345
516
|
if (error instanceof EditorDocumentLoadError) throw error;
|
|
346
517
|
throw new EditorDocumentLoadError(error instanceof Error ? error.message : String(error));
|
|
@@ -360,9 +531,9 @@ function defineEditorDocument(spec) {
|
|
|
360
531
|
},
|
|
361
532
|
history: spec.history,
|
|
362
533
|
...spec.assets ? { assets: spec.assets } : {},
|
|
363
|
-
readOnly: () => _nullishCoalesce(_optionalChain([spec, 'access',
|
|
534
|
+
readOnly: () => _nullishCoalesce(_optionalChain([spec, 'access', _9 => _9.readOnly, 'optionalCall', _10 => _10()]), () => ( false)),
|
|
364
535
|
destroy() {
|
|
365
|
-
_optionalChain([unsubscribe, 'optionalCall',
|
|
536
|
+
_optionalChain([unsubscribe, 'optionalCall', _11 => _11()]);
|
|
366
537
|
unsubscribe = null;
|
|
367
538
|
}
|
|
368
539
|
};
|
|
@@ -390,4 +561,7 @@ function defineEditorDocument(spec) {
|
|
|
390
561
|
|
|
391
562
|
|
|
392
563
|
|
|
393
|
-
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
exports.EDITOR_ASSET_PREFIX = EDITOR_ASSET_PREFIX; exports.isInlineAsset = isInlineAsset; exports.createEditorAssetRegistry = createEditorAssetRegistry; exports.externalizeAssets = externalizeAssets; exports.collectAssetRefs = collectAssetRefs; exports.internalizeAssets = internalizeAssets; exports.persistEditorAssets = persistEditorAssets; exports.preloadEditorAssets = preloadEditorAssets; exports.withEditorAssets = withEditorAssets; exports.collectEditorAssetGarbage = collectEditorAssetGarbage; exports.tryCollectEditorAssetGarbage = tryCollectEditorAssetGarbage; exports.collectRetiredEditorAssets = collectRetiredEditorAssets; exports.hasLoadProblems = hasLoadProblems; exports.createLoadReport = createLoadReport; exports.migrateDocument = migrateDocument; exports.loadSections = loadSections; exports.loadDocument = loadDocument; exports.EditorDocumentLoadError = EditorDocumentLoadError; exports.EDITOR_DOCUMENT_FORMAT = EDITOR_DOCUMENT_FORMAT; exports.isEditorDocumentFile = isEditorDocumentFile; exports.toEditorDocumentFile = toEditorDocumentFile; exports.serializeEditorDocument = serializeEditorDocument; exports.parseEditorDocument = parseEditorDocument; exports.defineEditorDocument = defineEditorDocument;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkBPX4Z3N3cjs = require('./chunk-BPX4Z3N3.cjs');
|
|
12
12
|
|
|
13
13
|
// src/chart/ooxml.ts
|
|
14
14
|
var CHART_OOXML_NS = "http://schemas.openxmlformats.org/drawingml/2006/chart";
|
|
@@ -111,11 +111,11 @@ function chartFromOoxml(xml, options = {}) {
|
|
|
111
111
|
try {
|
|
112
112
|
doc = new (parser(options))().parseFromString(xml, "application/xml");
|
|
113
113
|
} catch (error) {
|
|
114
|
-
return { spec:
|
|
114
|
+
return { spec: _chunkBPX4Z3N3cjs.normalizeChartSpec.call(void 0, {}).spec, issues: [{ path: "", message: `The chart XML could not be read: ${error.message}` }], unsupported, lossless: false };
|
|
115
115
|
}
|
|
116
116
|
const root = doc.documentElement;
|
|
117
117
|
if (!root || root.localName !== "chartSpace" || doc.getElementsByTagName("parsererror").length) {
|
|
118
|
-
return { spec:
|
|
118
|
+
return { spec: _chunkBPX4Z3N3cjs.normalizeChartSpec.call(void 0, {}).spec, issues: [{ path: "", message: "This is not a chart part: expected a c:chartSpace (or cx:chartSpace) root element." }], unsupported, lossless: false };
|
|
119
119
|
}
|
|
120
120
|
if (_optionalChain([root, 'access', _14 => _14.namespaceURI, 'optionalAccess', _15 => _15.includes, 'call', _16 => _16("chartex")]) || kid(root, "chartData")) return readChartex(root, issues, unsupported);
|
|
121
121
|
const chart = kid(root, "chart");
|
|
@@ -280,7 +280,7 @@ function chartFromOoxml(xml, options = {}) {
|
|
|
280
280
|
}
|
|
281
281
|
if (!types.length) {
|
|
282
282
|
issues.push({ path: "plotArea", message: unsupported.length ? `The chart type is not supported: ${unsupported.join(", ")}.` : "The chart has no plot groups." });
|
|
283
|
-
return { spec:
|
|
283
|
+
return { spec: _chunkBPX4Z3N3cjs.normalizeChartSpec.call(void 0, input).spec, issues, unsupported, lossless: false };
|
|
284
284
|
}
|
|
285
285
|
const first = types[0];
|
|
286
286
|
const combo = types.some((t) => t !== first);
|
|
@@ -290,14 +290,14 @@ function chartFromOoxml(xml, options = {}) {
|
|
|
290
290
|
if (!combo) {
|
|
291
291
|
for (const s of series) if (s.axis) issues.push({ path: "series", message: `"${s.name}" is on a second value axis.` });
|
|
292
292
|
}
|
|
293
|
-
if (types.some((t) => !
|
|
293
|
+
if (types.some((t) => !_chunkBPX4Z3N3cjs.isCartesianChart.call(void 0, t)) && combo) unsupported.push("a pie or radar mixed with other chart types");
|
|
294
294
|
input.series = series;
|
|
295
295
|
input.categories = categories.length ? categories : Array.from({ length: Math.max(0, ...series.map((s) => s.values.length)) }, (_, i) => `${i + 1}`);
|
|
296
296
|
input.stacking = stacking;
|
|
297
297
|
input.orientation = orientation;
|
|
298
298
|
input.dataLabels = dataLabels;
|
|
299
299
|
input.points = points || first !== "line";
|
|
300
|
-
if (bool(val(groups[0], "varyColors")) && !combo &&
|
|
300
|
+
if (bool(val(groups[0], "varyColors")) && !combo && _chunkBPX4Z3N3cjs.isCartesianChart.call(void 0, first) && series.length === 1) input.varyColors = true;
|
|
301
301
|
const readAxis = (a, fallback) => {
|
|
302
302
|
const axis = { ...fallback, format: {} };
|
|
303
303
|
if (!a) return axis;
|
|
@@ -324,12 +324,12 @@ function chartFromOoxml(xml, options = {}) {
|
|
|
324
324
|
};
|
|
325
325
|
const xy = first === "scatter" || first === "bubble";
|
|
326
326
|
const catAxis = _nullishCoalesce(_nullishCoalesce(kid(plot, "catAx"), () => ( kid(plot, "dateAx"))), () => ( (xy ? valAxes.find((a) => !vertical(a)) : void 0)));
|
|
327
|
-
input.xAxis = readAxis(catAxis,
|
|
327
|
+
input.xAxis = readAxis(catAxis, _chunkBPX4Z3N3cjs.defaultChartAxis.call(void 0, false));
|
|
328
328
|
if (kid(plot, "dateAx")) input.xAxis.kind = "date";
|
|
329
|
-
input.yAxis = readAxis(_nullishCoalesce(_nullishCoalesce(primaryAxis, () => ( valAxes.find(vertical))), () => ( valAxes[0])),
|
|
329
|
+
input.yAxis = readAxis(_nullishCoalesce(_nullishCoalesce(primaryAxis, () => ( valAxes.find(vertical))), () => ( valAxes[0])), _chunkBPX4Z3N3cjs.defaultChartAxis.call(void 0, true));
|
|
330
330
|
const secondaryAxis = valAxes.find((a) => a !== primaryAxis && (xy ? vertical(a) && a !== primaryAxis : true) && a !== catAxis);
|
|
331
|
-
if (series.some((s) => s.axis === "secondary") && secondaryAxis) input.yAxis2 = readAxis(secondaryAxis,
|
|
332
|
-
const { spec, issues: specIssues } =
|
|
331
|
+
if (series.some((s) => s.axis === "secondary") && secondaryAxis) input.yAxis2 = readAxis(secondaryAxis, _chunkBPX4Z3N3cjs.defaultChartAxis.call(void 0, false));
|
|
332
|
+
const { spec, issues: specIssues } = _chunkBPX4Z3N3cjs.normalizeChartSpec.call(void 0, input);
|
|
333
333
|
issues.push(...specIssues);
|
|
334
334
|
const uniq = [...new Set(unsupported)];
|
|
335
335
|
return { spec, issues, unsupported: uniq, lossless: uniq.length === 0 && specIssues.length === 0 };
|
|
@@ -382,7 +382,7 @@ function readChartex(root, issues, unsupported) {
|
|
|
382
382
|
const type = layouts[layout];
|
|
383
383
|
if (!type) {
|
|
384
384
|
issues.push({ path: "plotArea", message: `The chart layout "${layout || "unknown"}" is not supported.` });
|
|
385
|
-
return { spec:
|
|
385
|
+
return { spec: _chunkBPX4Z3N3cjs.normalizeChartSpec.call(void 0, {}).spec, issues, unsupported: [layout || "unknown chartex layout"], lossless: false };
|
|
386
386
|
}
|
|
387
387
|
if (layout === "paretoLine") unsupported.push("pareto line");
|
|
388
388
|
const series = [];
|
|
@@ -409,18 +409,18 @@ function readChartex(root, issues, unsupported) {
|
|
|
409
409
|
const first = data.get(_nullishCoalesce(_optionalChain([kid, 'call', _35 => _35(seriesEls[0], "dataId"), 'optionalAccess', _36 => _36.getAttribute, 'call', _37 => _37("val")]), () => ( "0")));
|
|
410
410
|
if ((type === "treemap" || type === "sunburst") && _optionalChain([first, 'optionalAccess', _38 => _38.paths])) {
|
|
411
411
|
const treeIssues = [];
|
|
412
|
-
input.tree =
|
|
412
|
+
input.tree = _chunkBPX4Z3N3cjs.chartTreeFromRows.call(void 0, first.paths.map((path2, i) => ({ path: path2, value: _nullishCoalesce(first.values[i], () => ( 0)) })), treeIssues);
|
|
413
413
|
for (const t of treeIssues) issues.push({ path: "chartData", message: t.message });
|
|
414
414
|
}
|
|
415
|
-
const { spec, issues: specIssues } =
|
|
415
|
+
const { spec, issues: specIssues } = _chunkBPX4Z3N3cjs.normalizeChartSpec.call(void 0, input);
|
|
416
416
|
issues.push(...specIssues);
|
|
417
417
|
return { spec, issues, unsupported, lossless: unsupported.length === 0 && specIssues.length === 0 };
|
|
418
418
|
}
|
|
419
419
|
var esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
420
420
|
var hex = (color) => {
|
|
421
421
|
if (!color) return null;
|
|
422
|
-
const rgb =
|
|
423
|
-
return rgb ?
|
|
422
|
+
const rgb = _chunkBPX4Z3N3cjs.parseChartColor.call(void 0, color);
|
|
423
|
+
return rgb ? _chunkBPX4Z3N3cjs.chartRgbToHex.call(void 0, rgb).slice(1).toUpperCase() : null;
|
|
424
424
|
};
|
|
425
425
|
var fillXml = (color, line = false) => {
|
|
426
426
|
const h = hex(color);
|
|
@@ -464,7 +464,7 @@ function errBarsXml(bars, dir) {
|
|
|
464
464
|
var MARKER_OUT = { circle: "circle", square: "square", diamond: "diamond", triangle: "triangle", cross: "x", none: "none" };
|
|
465
465
|
function chartToOoxml(spec) {
|
|
466
466
|
const issues = [];
|
|
467
|
-
const family =
|
|
467
|
+
const family = _chunkBPX4Z3N3cjs.chartFamily.call(void 0, spec);
|
|
468
468
|
let type = spec.type;
|
|
469
469
|
if (family === "waterfall" || family === "histogram" || family === "box" || family === "funnel") {
|
|
470
470
|
issues.push(`${spec.type} charts are written as bar charts: DrawingML has no ${spec.type} type (Office 2016 stores it as chartex).`);
|
|
@@ -475,6 +475,12 @@ function chartToOoxml(spec) {
|
|
|
475
475
|
} else if (family === "sunburst") {
|
|
476
476
|
issues.push(`Sunburst charts are written as doughnut charts of the ${spec.tree.length ? "top-level group totals" : "values"}: DrawingML has no sunburst type (Office 2016 stores it as chartex).`);
|
|
477
477
|
type = "donut";
|
|
478
|
+
} else if (family === "barrace") {
|
|
479
|
+
issues.push("Bar chart races are written as clustered bar charts of every name at every time point: DrawingML has no animation.");
|
|
480
|
+
type = "bar";
|
|
481
|
+
} else if (family === "sankey") {
|
|
482
|
+
issues.push("Sankey diagrams are written as bar charts of how much passes through each node: DrawingML has no flows.");
|
|
483
|
+
type = "bar";
|
|
478
484
|
} else if (family === "parliament") {
|
|
479
485
|
issues.push("Parliament charts are written as doughnut charts of the seats: DrawingML has no parliament type.");
|
|
480
486
|
type = "donut";
|
|
@@ -499,7 +505,7 @@ function chartToOoxml(spec) {
|
|
|
499
505
|
const ids = { cat: 500000001, val: 500000002, cat2: 500000003, val2: 500000004 };
|
|
500
506
|
const xy = family === "xy" || type === "scatter" || type === "bubble";
|
|
501
507
|
const pieLike = type === "pie" || type === "donut";
|
|
502
|
-
const typed = (s) => pieLike || type === "radar" ? type : type === "bubble" ? "bubble" : xy ? "scatter" :
|
|
508
|
+
const typed = (s) => pieLike || type === "radar" ? type : type === "bubble" ? "bubble" : xy ? "scatter" : _chunkBPX4Z3N3cjs.chartSeriesType.call(void 0, { type }, s);
|
|
503
509
|
const groups = [];
|
|
504
510
|
visible.forEach((s) => {
|
|
505
511
|
const kind = typed(s);
|
|
@@ -562,7 +568,7 @@ function chartToOoxml(spec) {
|
|
|
562
568
|
return `<c:ser>${parts.join("")}</c:ser>`;
|
|
563
569
|
};
|
|
564
570
|
const dLbls = `<c:dLbls><c:showLegendKey val="0"/><c:showVal val="${spec.dataLabels ? 1 : 0}"/><c:showCatName val="0"/><c:showSerName val="0"/><c:showPercent val="0"/><c:showBubbleSize val="0"/></c:dLbls>`;
|
|
565
|
-
const vary =
|
|
571
|
+
const vary = _chunkBPX4Z3N3cjs.chartVariesColors.call(void 0, spec) ? 1 : 0;
|
|
566
572
|
const groupXml = groups.map((g) => {
|
|
567
573
|
const axes2 = g.secondary ? `<c:axId val="${ids.cat2}"/><c:axId val="${ids.val2}"/>` : `<c:axId val="${ids.cat}"/><c:axId val="${ids.val}"/>`;
|
|
568
574
|
const sers = g.series.map(({ s, index }) => serXml(g.kind, s, index)).join("");
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _chunk5UEFBM2Mcjs = require('./chunk-5UEFBM2M.cjs');
|
|
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 = _chunk5UEFBM2Mcjs.rgbToOklab.call(void 0, a);
|
|
22
|
+
const lb = _chunk5UEFBM2Mcjs.rgbToOklab.call(void 0, 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 = _chunk5UEFBM2Mcjs.oklabToOklch.call(void 0, _chunk5UEFBM2Mcjs.rgbToOklab.call(void 0, 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 = _chunk5UEFBM2Mcjs.oklabToRgb.call(void 0, _chunk5UEFBM2Mcjs.oklchToOklab.call(void 0, { 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 = _chunk5UEFBM2Mcjs.rgbToHsl.call(void 0, 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 = _chunk5UEFBM2Mcjs.oklabToOklch.call(void 0, _chunk5UEFBM2Mcjs.rgbToOklab.call(void 0, 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 = _chunk5UEFBM2Mcjs.rgbToOklab.call(void 0, 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: _chunk5UEFBM2Mcjs.srgbToLinear.call(void 0, c.r),
|
|
109
|
+
g: _chunk5UEFBM2Mcjs.srgbToLinear.call(void 0, c.g),
|
|
110
|
+
b: _chunk5UEFBM2Mcjs.srgbToLinear.call(void 0, c.b),
|
|
111
|
+
a: c.a
|
|
112
|
+
};
|
|
113
|
+
const linP3 = _chunk5UEFBM2Mcjs.linearSrgbToDisplayP3.call(void 0, linSrgb);
|
|
114
|
+
const r = _chunk5UEFBM2Mcjs.linearToSrgb.call(void 0, linP3.r).toFixed(4);
|
|
115
|
+
const g = _chunk5UEFBM2Mcjs.linearToSrgb.call(void 0, linP3.g).toFixed(4);
|
|
116
|
+
const b = _chunk5UEFBM2Mcjs.linearToSrgb.call(void 0, 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 = _chunk5UEFBM2Mcjs.parseColor.call(void 0, input);
|
|
123
|
+
return parsed ? formatHex(parsed) : null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// src/color/suggest.ts
|
|
127
|
+
function suggestAccessibleForeground(foreground, background, options = {}) {
|
|
128
|
+
const large = _nullishCoalesce(options.large, () => ( false));
|
|
129
|
+
const lch = _chunk5UEFBM2Mcjs.oklabToOklch.call(void 0, _chunk5UEFBM2Mcjs.rgbToOklab.call(void 0, foreground));
|
|
130
|
+
const asHex = (l) => _chunk5UEFBM2Mcjs.parseColor.call(void 0, formatHex(toSrgbGamut(_chunk5UEFBM2Mcjs.oklabToRgb.call(void 0, _chunk5UEFBM2Mcjs.oklchToOklab.call(void 0, { ...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 = _chunk5UEFBM2Mcjs.contrastRatio.call(void 0, downCand, background);
|
|
135
|
+
const upRatio = _chunk5UEFBM2Mcjs.contrastRatio.call(void 0, upCand, background);
|
|
136
|
+
const downPass = _chunk5UEFBM2Mcjs.contrastLevel.call(void 0, downRatio, { large }) !== "fail";
|
|
137
|
+
const upPass = _chunk5UEFBM2Mcjs.contrastLevel.call(void 0, 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
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
exports.inSrgbGamut = inSrgbGamut; exports.deltaEOK = deltaEOK; exports.toSrgbGamut = toSrgbGamut; exports.formatHex = formatHex; exports.formatColor = formatColor; exports.normalizeColor = normalizeColor; exports.suggestAccessibleForeground = suggestAccessibleForeground;
|