ducjs 4.0.4 → 4.1.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/ducjs_wasi.wasm +0 -0
- package/dist/ducjs_wasm.d.ts +2 -2
- package/dist/ducjs_wasm.js +7 -7
- package/dist/ducjs_wasm_bg.wasm +0 -0
- package/dist/ducjs_wasm_bg.wasm.d.ts +2 -2
- package/dist/restore/index.d.ts +1 -0
- package/dist/restore/index.js +1 -0
- package/dist/restore/restoreDataState.js +2 -2
- package/dist/restore/restoreElements.js +13 -1
- package/dist/restore/updateModelCode.d.ts +11 -0
- package/dist/restore/updateModelCode.js +63 -0
- package/dist/utils/math/random.js +7 -2
- package/package.json +1 -1
package/dist/ducjs_wasi.wasm
CHANGED
|
Binary file
|
package/dist/ducjs_wasm.d.ts
CHANGED
|
@@ -228,8 +228,8 @@ export interface InitOutput {
|
|
|
228
228
|
readonly rust_sqlite_wasm_realloc: (a: number, b: number) => number;
|
|
229
229
|
readonly sqlite3_os_end: () => number;
|
|
230
230
|
readonly sqlite3_os_init: () => number;
|
|
231
|
-
readonly
|
|
232
|
-
readonly
|
|
231
|
+
readonly wasm_bindgen_adb4849040331bf2___convert__closures_____invoke___wasm_bindgen_adb4849040331bf2___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_adb4849040331bf2___JsError___true_: (a: number, b: number, c: any) => [number, number];
|
|
232
|
+
readonly wasm_bindgen_adb4849040331bf2___convert__closures_____invoke___js_sys_495b1fea2679fcbe___Function_fn_wasm_bindgen_adb4849040331bf2___JsValue_____wasm_bindgen_adb4849040331bf2___sys__Undefined___js_sys_495b1fea2679fcbe___Function_fn_wasm_bindgen_adb4849040331bf2___JsValue_____wasm_bindgen_adb4849040331bf2___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
|
|
233
233
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
234
234
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
235
235
|
readonly __wbindgen_exn_store: (a: number) => void;
|
package/dist/ducjs_wasm.js
CHANGED
|
@@ -955,7 +955,7 @@ function __wbg_get_imports() {
|
|
|
955
955
|
const a = state0.a;
|
|
956
956
|
state0.a = 0;
|
|
957
957
|
try {
|
|
958
|
-
return
|
|
958
|
+
return wasm_bindgen_adb4849040331bf2___convert__closures_____invoke___js_sys_495b1fea2679fcbe___Function_fn_wasm_bindgen_adb4849040331bf2___JsValue_____wasm_bindgen_adb4849040331bf2___sys__Undefined___js_sys_495b1fea2679fcbe___Function_fn_wasm_bindgen_adb4849040331bf2___JsValue_____wasm_bindgen_adb4849040331bf2___sys__Undefined_______true_(a, state0.b, arg0, arg1);
|
|
959
959
|
} finally {
|
|
960
960
|
state0.a = a;
|
|
961
961
|
}
|
|
@@ -1096,8 +1096,8 @@ function __wbg_get_imports() {
|
|
|
1096
1096
|
return ret;
|
|
1097
1097
|
}, arguments); },
|
|
1098
1098
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
1099
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx:
|
|
1100
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
1099
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 99, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
1100
|
+
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_adb4849040331bf2___convert__closures_____invoke___wasm_bindgen_adb4849040331bf2___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_adb4849040331bf2___JsError___true_);
|
|
1101
1101
|
return ret;
|
|
1102
1102
|
},
|
|
1103
1103
|
__wbindgen_cast_0000000000000002: function(arg0) {
|
|
@@ -1148,15 +1148,15 @@ function __wbg_get_imports() {
|
|
|
1148
1148
|
};
|
|
1149
1149
|
}
|
|
1150
1150
|
|
|
1151
|
-
function
|
|
1152
|
-
const ret = wasm.
|
|
1151
|
+
function wasm_bindgen_adb4849040331bf2___convert__closures_____invoke___wasm_bindgen_adb4849040331bf2___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_adb4849040331bf2___JsError___true_(arg0, arg1, arg2) {
|
|
1152
|
+
const ret = wasm.wasm_bindgen_adb4849040331bf2___convert__closures_____invoke___wasm_bindgen_adb4849040331bf2___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_adb4849040331bf2___JsError___true_(arg0, arg1, arg2);
|
|
1153
1153
|
if (ret[1]) {
|
|
1154
1154
|
throw takeFromExternrefTable0(ret[0]);
|
|
1155
1155
|
}
|
|
1156
1156
|
}
|
|
1157
1157
|
|
|
1158
|
-
function
|
|
1159
|
-
wasm.
|
|
1158
|
+
function wasm_bindgen_adb4849040331bf2___convert__closures_____invoke___js_sys_495b1fea2679fcbe___Function_fn_wasm_bindgen_adb4849040331bf2___JsValue_____wasm_bindgen_adb4849040331bf2___sys__Undefined___js_sys_495b1fea2679fcbe___Function_fn_wasm_bindgen_adb4849040331bf2___JsValue_____wasm_bindgen_adb4849040331bf2___sys__Undefined_______true_(arg0, arg1, arg2, arg3) {
|
|
1159
|
+
wasm.wasm_bindgen_adb4849040331bf2___convert__closures_____invoke___js_sys_495b1fea2679fcbe___Function_fn_wasm_bindgen_adb4849040331bf2___JsValue_____wasm_bindgen_adb4849040331bf2___sys__Undefined___js_sys_495b1fea2679fcbe___Function_fn_wasm_bindgen_adb4849040331bf2___JsValue_____wasm_bindgen_adb4849040331bf2___sys__Undefined_______true_(arg0, arg1, arg2, arg3);
|
|
1160
1160
|
}
|
|
1161
1161
|
|
|
1162
1162
|
const DucOpfsDocumentFinalization = (typeof FinalizationRegistry === 'undefined')
|
package/dist/ducjs_wasm_bg.wasm
CHANGED
|
Binary file
|
|
@@ -56,8 +56,8 @@ export const rust_sqlite_wasm_localtime: (a: number) => number;
|
|
|
56
56
|
export const rust_sqlite_wasm_realloc: (a: number, b: number) => number;
|
|
57
57
|
export const sqlite3_os_end: () => number;
|
|
58
58
|
export const sqlite3_os_init: () => number;
|
|
59
|
-
export const
|
|
60
|
-
export const
|
|
59
|
+
export const wasm_bindgen_adb4849040331bf2___convert__closures_____invoke___wasm_bindgen_adb4849040331bf2___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_adb4849040331bf2___JsError___true_: (a: number, b: number, c: any) => [number, number];
|
|
60
|
+
export const wasm_bindgen_adb4849040331bf2___convert__closures_____invoke___js_sys_495b1fea2679fcbe___Function_fn_wasm_bindgen_adb4849040331bf2___JsValue_____wasm_bindgen_adb4849040331bf2___sys__Undefined___js_sys_495b1fea2679fcbe___Function_fn_wasm_bindgen_adb4849040331bf2___JsValue_____wasm_bindgen_adb4849040331bf2___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
|
|
61
61
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
62
62
|
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
63
63
|
export const __wbindgen_exn_store: (a: number) => void;
|
package/dist/restore/index.d.ts
CHANGED
package/dist/restore/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { randomId } from "../utils/math/random";
|
|
2
2
|
import tinycolor from "tinycolor2";
|
|
3
3
|
import { BEZIER_MIRRORING, BLENDING, BOOLEAN_OPERATION, ELEMENT_CONTENT_PREFERENCE, IMAGE_STATUS, LINE_HEAD, STROKE_CAP, STROKE_JOIN, STROKE_PLACEMENT, STROKE_PREFERENCE, STROKE_SIDE_PREFERENCE, TEXT_ALIGN, VERTICAL_ALIGN, } from "../enums";
|
|
4
4
|
import { getPrecisionScope } from "../technical/measurements";
|
|
@@ -26,7 +26,7 @@ export const restore = (data, elementsConfig, restoreConfig = {}) => {
|
|
|
26
26
|
const restoredIssues = restoreIssues(data === null || data === void 0 ? void 0 : data.issues);
|
|
27
27
|
// Generate a new ID if none exists or if it's empty
|
|
28
28
|
const parsedId = data === null || data === void 0 ? void 0 : data.id;
|
|
29
|
-
const restoredId = (parsedId && parsedId.trim().length > 0) ? parsedId :
|
|
29
|
+
const restoredId = (parsedId && parsedId.trim().length > 0) ? parsedId : randomId();
|
|
30
30
|
return {
|
|
31
31
|
dictionary: restoredDictionary,
|
|
32
32
|
thumbnail: isValidUint8Array(data === null || data === void 0 ? void 0 : data.thumbnail),
|
|
@@ -3,6 +3,7 @@ import { isElbowArrow, isLinearElement, isTextElement, } from "../types";
|
|
|
3
3
|
import { arrayToMap, bumpVersion, DEFAULT_ELEMENT_PROPS, DEFAULT_ELLIPSE_ELEMENT, DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE, DEFAULT_FREEDRAW_ELEMENT, detectLineHeight, FONT_FAMILY, getContainerElement, getDefaultTableData, getNormalizedDimensions, getNormalizedPoints, getSizeFromPoints, getUpdatedTimestamp, isInvisiblySmallElement, LINE_CONFIRM_THRESHOLD, mergeOverlappingPoints, migratePoints, normalizeFixedPoint, normalizeLink, randomId, refreshTextDimensions, validateClosedPath } from "../utils";
|
|
4
4
|
import { isValidBezierMirroringValue, isValidBlendingValue, isValidBoolean, isValidBoolean as isValidBooleanValue, // Renaming to avoid conflict
|
|
5
5
|
isValidColor, isValidDucHead, isValidFunction, isValidImageScaleValue, isValidImageStatusValue, isValidPercentageValue, isValidPolygonSides, isValidRadianValue, isValidString, isValidTextAlignValue, isValidVerticalAlignValue, restoreDucStackProperties, restorePrecisionValue, validateBackground, validateStroke } from "./restoreDataState";
|
|
6
|
+
import { updateModelCodeElementIds } from "./updateModelCode";
|
|
6
7
|
import { LINE_SPACING_TYPE, } from "../enums";
|
|
7
8
|
const PARAMETRIC_SOURCE_TYPE = { CODE: 10, FILE: 11 };
|
|
8
9
|
import tinycolor from "tinycolor2";
|
|
@@ -588,6 +589,7 @@ export const migrateArrayOrderToZIndex = (elements) => {
|
|
|
588
589
|
};
|
|
589
590
|
export const restoreElements = (elements, currentScope, restoredBlocks, opts) => {
|
|
590
591
|
const existingIds = new Set();
|
|
592
|
+
const idMap = new Map();
|
|
591
593
|
// First restore all elements with their original properties
|
|
592
594
|
const restored = (elements || []).reduce((elements, element) => {
|
|
593
595
|
if (element.type !== "selection") {
|
|
@@ -606,7 +608,10 @@ export const restoreElements = (elements, currentScope, restoredBlocks, opts) =>
|
|
|
606
608
|
if (migratedElement &&
|
|
607
609
|
(isPassThrough || !isInvisiblySmallElement(migratedElement))) {
|
|
608
610
|
if (existingIds.has(migratedElement.id)) {
|
|
609
|
-
|
|
611
|
+
const oldId = migratedElement.id;
|
|
612
|
+
const newId = randomId();
|
|
613
|
+
migratedElement = Object.assign(Object.assign({}, migratedElement), { id: newId });
|
|
614
|
+
idMap.set(oldId, newId);
|
|
610
615
|
}
|
|
611
616
|
existingIds.add(migratedElement.id);
|
|
612
617
|
elements.push(migratedElement);
|
|
@@ -614,6 +619,13 @@ export const restoreElements = (elements, currentScope, restoredBlocks, opts) =>
|
|
|
614
619
|
}
|
|
615
620
|
return elements;
|
|
616
621
|
}, []);
|
|
622
|
+
if (idMap.size > 0) {
|
|
623
|
+
for (const el of restored) {
|
|
624
|
+
if (el.type === "model" && typeof el.code === "string" && el.code) {
|
|
625
|
+
el.code = updateModelCodeElementIds(el.code, idMap);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
617
629
|
let restoredElements = (opts === null || opts === void 0 ? void 0 : opts.syncInvalidIndices)
|
|
618
630
|
? opts.syncInvalidIndices(restored, currentScope)
|
|
619
631
|
: restored;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const getEncodedPythonModelModuleName: (elementId: string) => string;
|
|
2
|
+
export declare const getPythonModelModuleName: (elementId: string) => string;
|
|
3
|
+
/**
|
|
4
|
+
* Updates Python code referencing model element IDs when IDs are restored or duplicated.
|
|
5
|
+
* Replaces references in:
|
|
6
|
+
* - `from duc_model.<id_or_module> import ...`
|
|
7
|
+
* - `import duc_model.<id_or_module>`
|
|
8
|
+
* - `duc_model.<id_or_module>`
|
|
9
|
+
* - `from duc_model import <id_or_module>`
|
|
10
|
+
*/
|
|
11
|
+
export declare const updateModelCodeElementIds: (code: string, idMap: Map<string, string> | Record<string, string>) => string;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const PYTHON_IDENTIFIER_PATTERN = /^[A-Za-z_]\w*$/u;
|
|
2
|
+
export const getEncodedPythonModelModuleName = (elementId) => {
|
|
3
|
+
const encodedId = Array.from(new TextEncoder().encode(elementId))
|
|
4
|
+
.map((byte) => byte.toString(16).padStart(2, "0"))
|
|
5
|
+
.join("");
|
|
6
|
+
return `element_${encodedId || "00"}`;
|
|
7
|
+
};
|
|
8
|
+
export const getPythonModelModuleName = (elementId) => (PYTHON_IDENTIFIER_PATTERN.test(elementId)
|
|
9
|
+
? elementId
|
|
10
|
+
: getEncodedPythonModelModuleName(elementId));
|
|
11
|
+
const escapeRegex = (value) => (value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
12
|
+
/**
|
|
13
|
+
* Updates Python code referencing model element IDs when IDs are restored or duplicated.
|
|
14
|
+
* Replaces references in:
|
|
15
|
+
* - `from duc_model.<id_or_module> import ...`
|
|
16
|
+
* - `import duc_model.<id_or_module>`
|
|
17
|
+
* - `duc_model.<id_or_module>`
|
|
18
|
+
* - `from duc_model import <id_or_module>`
|
|
19
|
+
*/
|
|
20
|
+
export const updateModelCodeElementIds = (code, idMap) => {
|
|
21
|
+
if (!code || typeof code !== "string") {
|
|
22
|
+
return code;
|
|
23
|
+
}
|
|
24
|
+
const entries = [];
|
|
25
|
+
const entriesIterable = idMap instanceof Map ? idMap.entries() : Object.entries(idMap);
|
|
26
|
+
for (const [oldId, newId] of entriesIterable) {
|
|
27
|
+
if (!oldId || !newId || oldId === newId) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const oldModuleName = getPythonModelModuleName(oldId);
|
|
31
|
+
const newModuleName = getPythonModelModuleName(newId);
|
|
32
|
+
const oldEncoded = getEncodedPythonModelModuleName(oldId);
|
|
33
|
+
const targets = new Set();
|
|
34
|
+
targets.add(oldId);
|
|
35
|
+
targets.add(oldModuleName);
|
|
36
|
+
targets.add(oldEncoded);
|
|
37
|
+
entries.push({
|
|
38
|
+
targets: Array.from(targets).sort((a, b) => b.length - a.length),
|
|
39
|
+
replacement: newModuleName,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (entries.length === 0) {
|
|
43
|
+
return code;
|
|
44
|
+
}
|
|
45
|
+
let updatedCode = code;
|
|
46
|
+
for (const { targets, replacement } of entries) {
|
|
47
|
+
for (const target of targets) {
|
|
48
|
+
const escaped = escapeRegex(target);
|
|
49
|
+
const boundary = /^\w+$/.test(target) ? "\\b" : "(?=[^A-Za-z0-9_-]|$)";
|
|
50
|
+
// 1. Replace `duc_model.<target>`
|
|
51
|
+
const ducModelRegex = new RegExp(`(duc_model\\.)(?:${escaped})${boundary}`, "g");
|
|
52
|
+
updatedCode = updatedCode.replace(ducModelRegex, `$1${replacement}`);
|
|
53
|
+
// 2. Replace `from duc_model import ...` items
|
|
54
|
+
const fromImportRegex = /(from\s+duc_model\s+import\s+)([^#\n\r]+)/g;
|
|
55
|
+
updatedCode = updatedCode.replace(fromImportRegex, (_full, prefix, importedList) => {
|
|
56
|
+
const itemRegex = new RegExp(`(^|[,\\s])${escaped}(\\b|(?=[\\s,]|$))`, "g");
|
|
57
|
+
const replacedList = importedList.replace(itemRegex, `$1${replacement}$2`);
|
|
58
|
+
return `${prefix}${replacedList}`;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return updatedCode;
|
|
63
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { customAlphabet } from "nanoid";
|
|
2
2
|
export function randomSeed() {
|
|
3
3
|
return Math.floor(Math.random() * Math.pow(2, 31));
|
|
4
4
|
}
|
|
@@ -22,4 +22,9 @@ export const reseed = (seed) => {
|
|
|
22
22
|
random = new Random(seed);
|
|
23
23
|
testIdBase = 0;
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
// Python-identifier-safe alphabet: letters, digits, underscore (no hyphens)
|
|
26
|
+
const ID_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
|
|
27
|
+
const ID_INITIAL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
28
|
+
const generateBody = customAlphabet(ID_ALPHABET, 20);
|
|
29
|
+
const generateInitial = customAlphabet(ID_INITIAL_ALPHABET, 1);
|
|
30
|
+
export const randomId = () => `${generateInitial()}${generateBody()}`;
|