@xom11/whiteboard 0.24.0 → 0.24.1
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/{ExcalidrawWithMenus-KBLDWPM2.mjs → ExcalidrawWithMenus-WENZRYYE.mjs} +2 -2
- package/dist/{ExcalidrawWithMenus-KBLDWPM2.mjs.map → ExcalidrawWithMenus-WENZRYYE.mjs.map} +1 -1
- package/dist/catalog.json +4 -4
- package/dist/{chunk-TOOHCAWP.mjs → chunk-4D5CSIJO.mjs} +4 -4
- package/dist/{chunk-TOOHCAWP.mjs.map → chunk-4D5CSIJO.mjs.map} +1 -1
- package/dist/chunk-6V4SH4JJ.mjs +1801 -0
- package/dist/chunk-6V4SH4JJ.mjs.map +1 -0
- package/dist/{chunk-VBJLUHCY.mjs → chunk-AZIARTGX.mjs} +3 -3
- package/dist/{chunk-VBJLUHCY.mjs.map → chunk-AZIARTGX.mjs.map} +1 -1
- package/dist/{chunk-6XUPIGVD.mjs → chunk-BKSXPNPQ.mjs} +4 -123
- package/dist/chunk-BKSXPNPQ.mjs.map +1 -0
- package/dist/{chunk-O6QTYAKE.mjs → chunk-CRAPWQKJ.mjs} +4 -4
- package/dist/{chunk-O6QTYAKE.mjs.map → chunk-CRAPWQKJ.mjs.map} +1 -1
- package/dist/{chunk-RBUILBX3.mjs → chunk-CSCF3YFZ.mjs} +5 -5
- package/dist/{chunk-RBUILBX3.mjs.map → chunk-CSCF3YFZ.mjs.map} +1 -1
- package/dist/{chunk-7WG2KDRF.mjs → chunk-IBTRMWD6.mjs} +3 -3
- package/dist/{chunk-7WG2KDRF.mjs.map → chunk-IBTRMWD6.mjs.map} +1 -1
- package/dist/{chunk-RD34F5PM.mjs → chunk-ICR4CVOE.mjs} +2 -2
- package/dist/chunk-ICR4CVOE.mjs.map +1 -0
- package/dist/{chunk-33PEN2WC.mjs → chunk-LVNCYP4J.mjs} +6 -6
- package/dist/{chunk-33PEN2WC.mjs.map → chunk-LVNCYP4J.mjs.map} +1 -1
- package/dist/{chunk-FZY33J6Z.mjs → chunk-MFOGFFIL.mjs} +6 -6
- package/dist/{chunk-FZY33J6Z.mjs.map → chunk-MFOGFFIL.mjs.map} +1 -1
- package/dist/{chunk-TQYQVXNW.mjs → chunk-QGNU34T7.mjs} +2 -2
- package/dist/chunk-QGNU34T7.mjs.map +1 -0
- package/dist/{chunk-RXOFO64U.mjs → chunk-SGFJLHHG.mjs} +3 -3
- package/dist/{chunk-RXOFO64U.mjs.map → chunk-SGFJLHHG.mjs.map} +1 -1
- package/dist/{chunk-2SKXRBGS.mjs → chunk-WWMQ2VHZ.mjs} +4 -4
- package/dist/{chunk-2SKXRBGS.mjs.map → chunk-WWMQ2VHZ.mjs.map} +1 -1
- package/dist/{chunk-XVSO7FBM.mjs → chunk-YIPI3WUL.mjs} +5 -5
- package/dist/{chunk-XVSO7FBM.mjs.map → chunk-YIPI3WUL.mjs.map} +1 -1
- package/dist/{chunk-VRWZILTG.mjs → chunk-ZBJBQKJ2.mjs} +128 -3
- package/dist/chunk-ZBJBQKJ2.mjs.map +1 -0
- package/dist/geometry-2d.js +2056 -100
- package/dist/geometry-2d.js.map +1 -1
- package/dist/geometry-2d.mjs +6 -6
- package/dist/geometry-3d.js +2051 -15
- package/dist/geometry-3d.js.map +1 -1
- package/dist/geometry-3d.mjs +5 -5
- package/dist/graph-2d.js +1938 -8
- package/dist/graph-2d.js.map +1 -1
- package/dist/graph-2d.mjs +8 -8
- package/dist/{host-EVJT3LIF.mjs → host-DOAYVL35.mjs} +29 -28
- package/dist/host-DOAYVL35.mjs.map +1 -0
- package/dist/{host-3N4E4KJH.mjs → host-GKNQBBUE.mjs} +11 -11
- package/dist/{host-3N4E4KJH.mjs.map → host-GKNQBBUE.mjs.map} +1 -1
- package/dist/{host-6SNSZ332.mjs → host-QS2EOTRJ.mjs} +3 -3
- package/dist/{host-6SNSZ332.mjs.map → host-QS2EOTRJ.mjs.map} +1 -1
- package/dist/{host-HN4X3TBC.mjs → host-TLIXN4CF.mjs} +8 -8
- package/dist/{host-HN4X3TBC.mjs.map → host-TLIXN4CF.mjs.map} +1 -1
- package/dist/index.js +2044 -120
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -30
- package/dist/index.mjs.map +1 -1
- package/dist/latex.js.map +1 -1
- package/dist/latex.mjs +1 -1
- package/dist/render-SA4JTOW3.mjs +8 -0
- package/dist/{render-OCVGDKK6.mjs.map → render-SA4JTOW3.mjs.map} +1 -1
- package/dist/serialize-3NZS6A6Q.mjs +6 -0
- package/dist/{serialize-GKN6OVPM.mjs.map → serialize-3NZS6A6Q.mjs.map} +1 -1
- package/package.json +11 -2
- package/dist/chunk-3KBL77M6.mjs +0 -127
- package/dist/chunk-3KBL77M6.mjs.map +0 -1
- package/dist/chunk-6XUPIGVD.mjs.map +0 -1
- package/dist/chunk-RD34F5PM.mjs.map +0 -1
- package/dist/chunk-TQYQVXNW.mjs.map +0 -1
- package/dist/chunk-VRWZILTG.mjs.map +0 -1
- package/dist/host-EVJT3LIF.mjs.map +0 -1
- package/dist/render-OCVGDKK6.mjs +0 -8
- package/dist/serialize-GKN6OVPM.mjs +0 -6
package/dist/graph-2d.js
CHANGED
|
@@ -37,10 +37,16 @@ var __export = (target, all) => {
|
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
// src/core/scene/registry.ts
|
|
40
|
+
function registerKind(def22) {
|
|
41
|
+
if (registry.has(def22.type)) {
|
|
42
|
+
console.warn(`[scene] kind "${def22.type}" \u0111\xE3 \u0111\u01B0\u1EE3c \u0111\u0103ng k\xFD \u2014 ghi \u0111\xE8 \u0111\u1ECBnh ngh\u0129a c\u0169`);
|
|
43
|
+
}
|
|
44
|
+
registry.set(def22.type, def22);
|
|
45
|
+
}
|
|
40
46
|
function getKind(type) {
|
|
41
|
-
const
|
|
42
|
-
if (!
|
|
43
|
-
return
|
|
47
|
+
const def22 = registry.get(type);
|
|
48
|
+
if (!def22) throw new Error(`[scene] unknown kind: ${type}`);
|
|
49
|
+
return def22;
|
|
44
50
|
}
|
|
45
51
|
var registry;
|
|
46
52
|
var init_registry = __esm({
|
|
@@ -456,8 +462,8 @@ var init_JxgRenderer = __esm({
|
|
|
456
462
|
}
|
|
457
463
|
create(obj) {
|
|
458
464
|
try {
|
|
459
|
-
const
|
|
460
|
-
const el =
|
|
465
|
+
const def22 = getKind(obj.kind);
|
|
466
|
+
const el = def22.render(obj, this.ctx());
|
|
461
467
|
this.elements.set(obj.id, el);
|
|
462
468
|
this.attachFreePointDragSync(obj, el);
|
|
463
469
|
} catch (err) {
|
|
@@ -535,11 +541,11 @@ var init_JxgRenderer = __esm({
|
|
|
535
541
|
continue;
|
|
536
542
|
}
|
|
537
543
|
if (Object.is(old, cur)) continue;
|
|
538
|
-
const
|
|
544
|
+
const def22 = getKind(cur.kind);
|
|
539
545
|
const existing = this.elements.get(id);
|
|
540
|
-
if (
|
|
546
|
+
if (def22.update && existing) {
|
|
541
547
|
try {
|
|
542
|
-
|
|
548
|
+
def22.update(cur, old, this.ctx(), existing);
|
|
543
549
|
continue;
|
|
544
550
|
} catch (err) {
|
|
545
551
|
console.warn(`[scene/render/2d] update fail, recreate:`, err);
|
|
@@ -996,6 +1002,1929 @@ var init_hooks = __esm({
|
|
|
996
1002
|
}
|
|
997
1003
|
});
|
|
998
1004
|
|
|
1005
|
+
// src/core/scene/kinds/3d-constraint.ts
|
|
1006
|
+
function constraintRefs(c) {
|
|
1007
|
+
switch (c.kind) {
|
|
1008
|
+
case "onPlane":
|
|
1009
|
+
return [c.planeId];
|
|
1010
|
+
case "onLine":
|
|
1011
|
+
return [c.lineId];
|
|
1012
|
+
case "onPolygon":
|
|
1013
|
+
return [c.polygonId];
|
|
1014
|
+
case "onSphere":
|
|
1015
|
+
return [c.sphereId];
|
|
1016
|
+
default:
|
|
1017
|
+
return [];
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
var init_d_constraint = __esm({
|
|
1021
|
+
"src/core/scene/kinds/3d-constraint.ts"() {
|
|
1022
|
+
}
|
|
1023
|
+
});
|
|
1024
|
+
|
|
1025
|
+
// src/core/scene/kinds/point3d.ts
|
|
1026
|
+
var def;
|
|
1027
|
+
var init_point3d = __esm({
|
|
1028
|
+
"src/core/scene/kinds/point3d.ts"() {
|
|
1029
|
+
init_registry();
|
|
1030
|
+
init_d_constraint();
|
|
1031
|
+
def = {
|
|
1032
|
+
type: "point3d",
|
|
1033
|
+
schemaVersion: 1,
|
|
1034
|
+
migrate: {},
|
|
1035
|
+
validate: (a) => {
|
|
1036
|
+
if (!a || !a.constraint || !a.constraint.kind) {
|
|
1037
|
+
throw new Error("point3d: constraint required");
|
|
1038
|
+
}
|
|
1039
|
+
},
|
|
1040
|
+
dependsOn: (a) => constraintRefs(a.constraint),
|
|
1041
|
+
measure: (obj) => {
|
|
1042
|
+
const c = obj.attrs.constraint;
|
|
1043
|
+
if (c.kind === "free") {
|
|
1044
|
+
return [
|
|
1045
|
+
{ label: "x", value: c.x },
|
|
1046
|
+
{ label: "y", value: c.y },
|
|
1047
|
+
{ label: "z", value: c.z }
|
|
1048
|
+
];
|
|
1049
|
+
}
|
|
1050
|
+
if (c.kind === "onGround") {
|
|
1051
|
+
return [
|
|
1052
|
+
{ label: "x", value: c.x },
|
|
1053
|
+
{ label: "y", value: c.y },
|
|
1054
|
+
{ label: "z", value: 0 }
|
|
1055
|
+
];
|
|
1056
|
+
}
|
|
1057
|
+
return null;
|
|
1058
|
+
},
|
|
1059
|
+
describe: (obj) => {
|
|
1060
|
+
const c = obj.attrs.constraint;
|
|
1061
|
+
if (c.kind === "free") return `${obj.label} = (${c.x.toFixed(2)}, ${c.y.toFixed(2)}, ${c.z.toFixed(2)})`;
|
|
1062
|
+
if (c.kind === "onGround") return `${obj.label} = (${c.x.toFixed(2)}, ${c.y.toFixed(2)}, 0)`;
|
|
1063
|
+
if (c.kind === "onAxis") return `${obj.label} tr\xEAn tr\u1EE5c ${c.axis} (t=${c.t.toFixed(2)})`;
|
|
1064
|
+
if (c.kind === "onPlane") return `${obj.label} tr\xEAn m\u1EB7t ${c.planeId}`;
|
|
1065
|
+
if (c.kind === "onLine") return `${obj.label} tr\xEAn \u0111\u01B0\u1EDDng ${c.lineId}`;
|
|
1066
|
+
if (c.kind === "onPolygon") return `${obj.label} tr\xEAn \u0111a gi\xE1c ${c.polygonId}`;
|
|
1067
|
+
if (c.kind === "onSphere") return `${obj.label} tr\xEAn m\u1EB7t c\u1EA7u ${c.sphereId}`;
|
|
1068
|
+
return obj.label;
|
|
1069
|
+
},
|
|
1070
|
+
render: (obj, ctx) => {
|
|
1071
|
+
const view = ctx.jxg;
|
|
1072
|
+
const c = obj.attrs.constraint;
|
|
1073
|
+
const opts = {
|
|
1074
|
+
name: obj.label,
|
|
1075
|
+
visible: obj.visible,
|
|
1076
|
+
fixed: obj.locked,
|
|
1077
|
+
strokeColor: obj.attrs.color ?? "#1e40af",
|
|
1078
|
+
fillColor: obj.attrs.color ?? "#1e40af",
|
|
1079
|
+
size: 4
|
|
1080
|
+
};
|
|
1081
|
+
if (c.kind === "free") {
|
|
1082
|
+
return view.create("point3d", [c.x, c.y, c.z], opts);
|
|
1083
|
+
} else if (c.kind === "onGround") {
|
|
1084
|
+
return view.create("point3d", [c.x, c.y, 0], opts);
|
|
1085
|
+
} else if (c.kind === "onAxis") {
|
|
1086
|
+
const coords = c.axis === "x" ? [c.t, 0, 0] : c.axis === "y" ? [0, c.t, 0] : [0, 0, c.t];
|
|
1087
|
+
return view.create("point3d", coords, opts);
|
|
1088
|
+
} else if (c.kind === "onPlane") {
|
|
1089
|
+
const plane = ctx.resolveRef(c.planeId);
|
|
1090
|
+
return view.create("point3d", [
|
|
1091
|
+
() => plane.F(c.u, c.v)[0],
|
|
1092
|
+
() => plane.F(c.u, c.v)[1],
|
|
1093
|
+
() => plane.F(c.u, c.v)[2]
|
|
1094
|
+
], opts);
|
|
1095
|
+
} else if (c.kind === "onLine") {
|
|
1096
|
+
const line = ctx.resolveRef(c.lineId);
|
|
1097
|
+
return view.create("point3d", [
|
|
1098
|
+
() => line.F(c.t)[0],
|
|
1099
|
+
() => line.F(c.t)[1],
|
|
1100
|
+
() => line.F(c.t)[2]
|
|
1101
|
+
], opts);
|
|
1102
|
+
} else if (c.kind === "onPolygon") {
|
|
1103
|
+
const poly = ctx.resolveRef(c.polygonId);
|
|
1104
|
+
return view.create("point3d", [
|
|
1105
|
+
() => poly.F(c.u, c.v)[0],
|
|
1106
|
+
() => poly.F(c.u, c.v)[1],
|
|
1107
|
+
() => poly.F(c.u, c.v)[2]
|
|
1108
|
+
], opts);
|
|
1109
|
+
} else if (c.kind === "onSphere") {
|
|
1110
|
+
const sph = ctx.resolveRef(c.sphereId);
|
|
1111
|
+
return view.create("point3d", [
|
|
1112
|
+
() => sph.F(c.theta, c.phi)[0],
|
|
1113
|
+
() => sph.F(c.theta, c.phi)[1],
|
|
1114
|
+
() => sph.F(c.theta, c.phi)[2]
|
|
1115
|
+
], opts);
|
|
1116
|
+
}
|
|
1117
|
+
return view.create("point3d", [0, 0, 0], opts);
|
|
1118
|
+
}
|
|
1119
|
+
};
|
|
1120
|
+
registerKind(def);
|
|
1121
|
+
}
|
|
1122
|
+
});
|
|
1123
|
+
|
|
1124
|
+
// src/core/scene/kinds/labelOf.ts
|
|
1125
|
+
function labelOf(id, state) {
|
|
1126
|
+
return state?.objects[id]?.label ?? id;
|
|
1127
|
+
}
|
|
1128
|
+
var init_labelOf = __esm({
|
|
1129
|
+
"src/core/scene/kinds/labelOf.ts"() {
|
|
1130
|
+
}
|
|
1131
|
+
});
|
|
1132
|
+
|
|
1133
|
+
// src/core/scene/kinds/segment3d.ts
|
|
1134
|
+
var def2;
|
|
1135
|
+
var init_segment3d = __esm({
|
|
1136
|
+
"src/core/scene/kinds/segment3d.ts"() {
|
|
1137
|
+
init_registry();
|
|
1138
|
+
init_labelOf();
|
|
1139
|
+
def2 = {
|
|
1140
|
+
type: "segment3d",
|
|
1141
|
+
schemaVersion: 1,
|
|
1142
|
+
migrate: {},
|
|
1143
|
+
validate: (a) => {
|
|
1144
|
+
if (!a?.p1 || !a?.p2) throw new Error("segment3d: p1 v\xE0 p2 b\u1EAFt bu\u1ED9c");
|
|
1145
|
+
},
|
|
1146
|
+
dependsOn: (a) => [a.p1, a.p2],
|
|
1147
|
+
measure: (obj, state) => {
|
|
1148
|
+
const p1 = state.objects[obj.attrs.p1];
|
|
1149
|
+
const p2 = state.objects[obj.attrs.p2];
|
|
1150
|
+
if (!p1 || !p2) return null;
|
|
1151
|
+
const c1 = p1.attrs.constraint;
|
|
1152
|
+
const c2 = p2.attrs.constraint;
|
|
1153
|
+
if (c1?.kind !== "free" || c2?.kind !== "free") return null;
|
|
1154
|
+
const dx = (c2.x ?? 0) - (c1.x ?? 0);
|
|
1155
|
+
const dy = (c2.y ?? 0) - (c1.y ?? 0);
|
|
1156
|
+
const dz = (c2.z ?? 0) - (c1.z ?? 0);
|
|
1157
|
+
return [{ label: "length", value: Math.hypot(dx, dy, dz) }];
|
|
1158
|
+
},
|
|
1159
|
+
describe: (obj, state) => `\u0110o\u1EA1n th\u1EB3ng ${labelOf(obj.attrs.p1, state)}${labelOf(obj.attrs.p2, state)}`,
|
|
1160
|
+
render: (obj, ctx) => {
|
|
1161
|
+
const view = ctx.jxg;
|
|
1162
|
+
const pA = ctx.resolveRef(obj.attrs.p1);
|
|
1163
|
+
const pB = ctx.resolveRef(obj.attrs.p2);
|
|
1164
|
+
return view.create("line3d", [pA, pB], {
|
|
1165
|
+
straightFirst: false,
|
|
1166
|
+
straightLast: false,
|
|
1167
|
+
strokeColor: obj.attrs.color ?? "#0f172a",
|
|
1168
|
+
strokeWidth: 2,
|
|
1169
|
+
visible: obj.visible
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
};
|
|
1173
|
+
registerKind(def2);
|
|
1174
|
+
}
|
|
1175
|
+
});
|
|
1176
|
+
|
|
1177
|
+
// src/core/scene/kinds/line3d.ts
|
|
1178
|
+
var init_line3d = __esm({
|
|
1179
|
+
"src/core/scene/kinds/line3d.ts"() {
|
|
1180
|
+
init_registry();
|
|
1181
|
+
init_labelOf();
|
|
1182
|
+
registerKind({
|
|
1183
|
+
type: "line3d",
|
|
1184
|
+
schemaVersion: 1,
|
|
1185
|
+
migrate: {},
|
|
1186
|
+
validate: (a) => {
|
|
1187
|
+
if (!a?.p1 || !a?.p2) throw new Error("line3d: p1/p2 required");
|
|
1188
|
+
},
|
|
1189
|
+
dependsOn: (a) => [a.p1, a.p2],
|
|
1190
|
+
describe: (obj, state) => `\u0110\u01B0\u1EDDng ${obj.label} qua ${labelOf(obj.attrs.p1, state)}, ${labelOf(obj.attrs.p2, state)}`,
|
|
1191
|
+
render: (obj, ctx) => {
|
|
1192
|
+
const view = ctx.jxg;
|
|
1193
|
+
const pA = ctx.resolveRef(obj.attrs.p1);
|
|
1194
|
+
const pB = ctx.resolveRef(obj.attrs.p2);
|
|
1195
|
+
return view.create("line3d", [pA, pB], {
|
|
1196
|
+
straightFirst: true,
|
|
1197
|
+
straightLast: true,
|
|
1198
|
+
strokeColor: obj.attrs.color ?? "#0f172a",
|
|
1199
|
+
strokeWidth: 2,
|
|
1200
|
+
visible: obj.visible
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
});
|
|
1206
|
+
|
|
1207
|
+
// src/core/scene/kinds/ray3d.ts
|
|
1208
|
+
var init_ray3d = __esm({
|
|
1209
|
+
"src/core/scene/kinds/ray3d.ts"() {
|
|
1210
|
+
init_registry();
|
|
1211
|
+
init_labelOf();
|
|
1212
|
+
registerKind({
|
|
1213
|
+
type: "ray3d",
|
|
1214
|
+
schemaVersion: 1,
|
|
1215
|
+
migrate: {},
|
|
1216
|
+
validate: (a) => {
|
|
1217
|
+
if (!a?.origin || !a?.through) throw new Error("ray3d: origin/through required");
|
|
1218
|
+
},
|
|
1219
|
+
dependsOn: (a) => [a.origin, a.through],
|
|
1220
|
+
describe: (obj, state) => `Tia ${obj.label} t\u1EEB ${labelOf(obj.attrs.origin, state)} qua ${labelOf(obj.attrs.through, state)}`,
|
|
1221
|
+
render: (obj, ctx) => {
|
|
1222
|
+
const view = ctx.jxg;
|
|
1223
|
+
const pOrigin = ctx.resolveRef(obj.attrs.origin);
|
|
1224
|
+
const pThrough = ctx.resolveRef(obj.attrs.through);
|
|
1225
|
+
return view.create("line3d", [pOrigin, pThrough], {
|
|
1226
|
+
straightFirst: false,
|
|
1227
|
+
straightLast: true,
|
|
1228
|
+
strokeColor: obj.attrs.color ?? "#0f172a",
|
|
1229
|
+
strokeWidth: 2,
|
|
1230
|
+
visible: obj.visible
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1235
|
+
});
|
|
1236
|
+
|
|
1237
|
+
// src/core/scene/kinds/vector3d.ts
|
|
1238
|
+
var init_vector3d = __esm({
|
|
1239
|
+
"src/core/scene/kinds/vector3d.ts"() {
|
|
1240
|
+
init_registry();
|
|
1241
|
+
init_labelOf();
|
|
1242
|
+
registerKind({
|
|
1243
|
+
type: "vector3d",
|
|
1244
|
+
schemaVersion: 1,
|
|
1245
|
+
migrate: {},
|
|
1246
|
+
validate: (a) => {
|
|
1247
|
+
if (!a?.from || !a?.to) throw new Error("vector3d: from/to required");
|
|
1248
|
+
},
|
|
1249
|
+
dependsOn: (a) => [a.from, a.to],
|
|
1250
|
+
describe: (obj, state) => `V\xE9c-t\u01A1 ${obj.label}: ${labelOf(obj.attrs.from, state)} \u2192 ${labelOf(obj.attrs.to, state)}`,
|
|
1251
|
+
render: (obj, ctx) => {
|
|
1252
|
+
const view = ctx.jxg;
|
|
1253
|
+
const pFrom = ctx.resolveRef(obj.attrs.from);
|
|
1254
|
+
const pTo = ctx.resolveRef(obj.attrs.to);
|
|
1255
|
+
return view.create("line3d", [pFrom, pTo], {
|
|
1256
|
+
straightFirst: false,
|
|
1257
|
+
straightLast: false,
|
|
1258
|
+
lastArrow: { type: 1 },
|
|
1259
|
+
strokeColor: obj.attrs.color ?? "#0f172a",
|
|
1260
|
+
strokeWidth: 2,
|
|
1261
|
+
visible: obj.visible
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1264
|
+
});
|
|
1265
|
+
}
|
|
1266
|
+
});
|
|
1267
|
+
|
|
1268
|
+
// src/core/scene/kinds/plane3d.ts
|
|
1269
|
+
var init_plane3d = __esm({
|
|
1270
|
+
"src/core/scene/kinds/plane3d.ts"() {
|
|
1271
|
+
init_registry();
|
|
1272
|
+
init_labelOf();
|
|
1273
|
+
registerKind({
|
|
1274
|
+
type: "plane3d",
|
|
1275
|
+
schemaVersion: 1,
|
|
1276
|
+
migrate: {},
|
|
1277
|
+
validate: (a) => {
|
|
1278
|
+
if (!a?.p1 || !a?.p2 || !a?.p3) throw new Error("plane3d: c\u1EA7n 3 \u0111i\u1EC3m");
|
|
1279
|
+
},
|
|
1280
|
+
dependsOn: (a) => [a.p1, a.p2, a.p3],
|
|
1281
|
+
describe: (obj, state) => `M\u1EB7t ${obj.label} qua ${labelOf(obj.attrs.p1, state)}, ${labelOf(obj.attrs.p2, state)}, ${labelOf(obj.attrs.p3, state)}`,
|
|
1282
|
+
render: (obj, ctx) => {
|
|
1283
|
+
const view = ctx.jxg;
|
|
1284
|
+
return view.create("plane3d", [
|
|
1285
|
+
ctx.resolveRef(obj.attrs.p1),
|
|
1286
|
+
ctx.resolveRef(obj.attrs.p2),
|
|
1287
|
+
ctx.resolveRef(obj.attrs.p3)
|
|
1288
|
+
], {
|
|
1289
|
+
fillOpacity: 0.15,
|
|
1290
|
+
fillColor: obj.attrs.color ?? "#60a5fa",
|
|
1291
|
+
strokeColor: obj.attrs.color ?? "#60a5fa",
|
|
1292
|
+
visible: obj.visible
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
});
|
|
1298
|
+
|
|
1299
|
+
// src/core/scene/kinds/polygon3d.ts
|
|
1300
|
+
var init_polygon3d = __esm({
|
|
1301
|
+
"src/core/scene/kinds/polygon3d.ts"() {
|
|
1302
|
+
init_registry();
|
|
1303
|
+
registerKind({
|
|
1304
|
+
type: "polygon3d",
|
|
1305
|
+
schemaVersion: 1,
|
|
1306
|
+
migrate: {},
|
|
1307
|
+
validate: (a) => {
|
|
1308
|
+
if (!a?.vertices || a.vertices.length < 3) throw new Error("polygon3d: c\u1EA7n \u22653 vertices");
|
|
1309
|
+
},
|
|
1310
|
+
dependsOn: (a) => [...a.vertices],
|
|
1311
|
+
describe: (obj) => `\u0110a gi\xE1c ${obj.label} (${obj.attrs.vertices.length} \u0111\u1EC9nh)`,
|
|
1312
|
+
render: (obj, ctx) => {
|
|
1313
|
+
const view = ctx.jxg;
|
|
1314
|
+
const refs = obj.attrs.vertices.map((id) => ctx.resolveRef(id));
|
|
1315
|
+
return view.create("polygon3d", [refs], {
|
|
1316
|
+
fillOpacity: 0.3,
|
|
1317
|
+
fillColor: obj.attrs.color ?? "#60a5fa",
|
|
1318
|
+
visible: obj.visible
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
});
|
|
1324
|
+
|
|
1325
|
+
// src/core/scene/kinds/sphere3d.ts
|
|
1326
|
+
var init_sphere3d = __esm({
|
|
1327
|
+
"src/core/scene/kinds/sphere3d.ts"() {
|
|
1328
|
+
init_registry();
|
|
1329
|
+
init_labelOf();
|
|
1330
|
+
registerKind({
|
|
1331
|
+
type: "sphere3d",
|
|
1332
|
+
schemaVersion: 1,
|
|
1333
|
+
migrate: {},
|
|
1334
|
+
validate: (a) => {
|
|
1335
|
+
if (!a?.center || !a?.surfacePoint) throw new Error("sphere3d: center/surfacePoint required");
|
|
1336
|
+
},
|
|
1337
|
+
dependsOn: (a) => [a.center, a.surfacePoint],
|
|
1338
|
+
describe: (obj, state) => `M\u1EB7t c\u1EA7u ${obj.label} t\xE2m ${labelOf(obj.attrs.center, state)}`,
|
|
1339
|
+
render: (obj, ctx) => {
|
|
1340
|
+
const view = ctx.jxg;
|
|
1341
|
+
return view.create("sphere3d", [
|
|
1342
|
+
ctx.resolveRef(obj.attrs.center),
|
|
1343
|
+
ctx.resolveRef(obj.attrs.surfacePoint)
|
|
1344
|
+
], {
|
|
1345
|
+
fillOpacity: 0.25,
|
|
1346
|
+
fillColor: obj.attrs.color ?? "#60a5fa",
|
|
1347
|
+
visible: obj.visible
|
|
1348
|
+
});
|
|
1349
|
+
}
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
});
|
|
1353
|
+
|
|
1354
|
+
// src/core/scene/kinds/polyhedron3d.ts
|
|
1355
|
+
var FLAVOR_LABEL;
|
|
1356
|
+
var init_polyhedron3d = __esm({
|
|
1357
|
+
"src/core/scene/kinds/polyhedron3d.ts"() {
|
|
1358
|
+
init_registry();
|
|
1359
|
+
FLAVOR_LABEL = {
|
|
1360
|
+
pyramid: "ch\xF3p",
|
|
1361
|
+
prism: "l\u0103ng tr\u1EE5",
|
|
1362
|
+
tetrahedron: "t\u1EE9 di\u1EC7n",
|
|
1363
|
+
cube: "l\u1EADp ph\u01B0\u01A1ng"
|
|
1364
|
+
};
|
|
1365
|
+
registerKind({
|
|
1366
|
+
type: "polyhedron3d",
|
|
1367
|
+
schemaVersion: 1,
|
|
1368
|
+
migrate: {},
|
|
1369
|
+
validate: (a) => {
|
|
1370
|
+
if (!a?.vertices || a.vertices.length < 4) throw new Error("polyhedron3d: c\u1EA7n \u22654 vertices");
|
|
1371
|
+
if (!a?.faces || a.faces.length < 4) throw new Error("polyhedron3d: c\u1EA7n \u22654 faces");
|
|
1372
|
+
},
|
|
1373
|
+
dependsOn: (a) => [...a.vertices],
|
|
1374
|
+
describe: (obj) => `Kh\u1ED1i ${FLAVOR_LABEL[obj.attrs.flavor]} ${obj.label}`,
|
|
1375
|
+
render: (obj, ctx) => {
|
|
1376
|
+
const view = ctx.jxg;
|
|
1377
|
+
const verts = obj.attrs.vertices.map((id) => ctx.resolveRef(id));
|
|
1378
|
+
const faces = obj.attrs.faces.map(
|
|
1379
|
+
(faceIndices, fi) => view.create("polygon3d", [faceIndices.map((i) => verts[i])], {
|
|
1380
|
+
id: `${obj.id}.face${faceIndices.join("-")}.${fi}`,
|
|
1381
|
+
fillOpacity: 0.25,
|
|
1382
|
+
fillColor: obj.attrs.color ?? "#fbbf24",
|
|
1383
|
+
strokeColor: "#0066cc",
|
|
1384
|
+
strokeWidth: 1.5,
|
|
1385
|
+
visible: obj.visible
|
|
1386
|
+
})
|
|
1387
|
+
);
|
|
1388
|
+
return { faces };
|
|
1389
|
+
}
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
});
|
|
1393
|
+
|
|
1394
|
+
// src/core/scene/kinds/cylinder3d.ts
|
|
1395
|
+
var CURVED_SEGMENTS;
|
|
1396
|
+
var init_cylinder3d = __esm({
|
|
1397
|
+
"src/core/scene/kinds/cylinder3d.ts"() {
|
|
1398
|
+
init_registry();
|
|
1399
|
+
CURVED_SEGMENTS = 16;
|
|
1400
|
+
registerKind({
|
|
1401
|
+
type: "cylinder3d",
|
|
1402
|
+
schemaVersion: 1,
|
|
1403
|
+
migrate: {},
|
|
1404
|
+
validate: (a) => {
|
|
1405
|
+
if (!a?.baseCenter || !a?.topCenter) throw new Error("cylinder3d: baseCenter/topCenter required");
|
|
1406
|
+
if (!(a.radius > 0)) throw new Error("cylinder3d: radius > 0");
|
|
1407
|
+
},
|
|
1408
|
+
dependsOn: (a) => [a.baseCenter, a.topCenter],
|
|
1409
|
+
describe: (obj) => `Tr\u1EE5 ${obj.label} R=${obj.attrs.radius.toFixed(2)}`,
|
|
1410
|
+
render: (obj, ctx) => {
|
|
1411
|
+
const view = ctx.jxg;
|
|
1412
|
+
const a = ctx.resolveRef(obj.attrs.baseCenter);
|
|
1413
|
+
const b = ctx.resolveRef(obj.attrs.topCenter);
|
|
1414
|
+
const r = obj.attrs.radius;
|
|
1415
|
+
const ax = a.X?.() ?? 0, ay = a.Y?.() ?? 0, az = a.Z?.() ?? 0;
|
|
1416
|
+
const bx = b.X?.() ?? 0, by = b.Y?.() ?? 0, bz = b.Z?.() ?? 0;
|
|
1417
|
+
const baseRing = [];
|
|
1418
|
+
const topRing = [];
|
|
1419
|
+
for (let i = 0; i < CURVED_SEGMENTS; i++) {
|
|
1420
|
+
const theta = i / CURVED_SEGMENTS * Math.PI * 2;
|
|
1421
|
+
const dx = r * Math.cos(theta);
|
|
1422
|
+
const dy = r * Math.sin(theta);
|
|
1423
|
+
baseRing.push([ax + dx, ay + dy, az]);
|
|
1424
|
+
topRing.push([bx + dx, by + dy, bz]);
|
|
1425
|
+
}
|
|
1426
|
+
const vertices = [...baseRing, ...topRing];
|
|
1427
|
+
const faces = [];
|
|
1428
|
+
faces.push(baseRing.map((_, i) => i));
|
|
1429
|
+
faces.push(topRing.map((_, i) => CURVED_SEGMENTS + i));
|
|
1430
|
+
for (let i = 0; i < CURVED_SEGMENTS; i++) {
|
|
1431
|
+
const next = (i + 1) % CURVED_SEGMENTS;
|
|
1432
|
+
faces.push([i, next, CURVED_SEGMENTS + next, CURVED_SEGMENTS + i]);
|
|
1433
|
+
}
|
|
1434
|
+
const vertJxgs = vertices.map(
|
|
1435
|
+
(v, i) => view.create("point3d", v, {
|
|
1436
|
+
id: `${obj.id}.v${i}`,
|
|
1437
|
+
visible: false,
|
|
1438
|
+
fixed: true,
|
|
1439
|
+
withLabel: false
|
|
1440
|
+
})
|
|
1441
|
+
);
|
|
1442
|
+
const faceJxgs = faces.map(
|
|
1443
|
+
(face, fi) => view.create("polygon3d", [face.map((idx) => vertJxgs[idx])], {
|
|
1444
|
+
id: `${obj.id}.face${fi}`,
|
|
1445
|
+
fillOpacity: 0.25,
|
|
1446
|
+
fillColor: obj.attrs.color ?? "#f97316",
|
|
1447
|
+
strokeColor: "#0066cc",
|
|
1448
|
+
strokeWidth: 1.5,
|
|
1449
|
+
visible: obj.visible
|
|
1450
|
+
})
|
|
1451
|
+
);
|
|
1452
|
+
return { _verts: vertJxgs, faces: faceJxgs };
|
|
1453
|
+
}
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
});
|
|
1457
|
+
|
|
1458
|
+
// src/core/scene/kinds/cone3d.ts
|
|
1459
|
+
var CURVED_SEGMENTS2;
|
|
1460
|
+
var init_cone3d = __esm({
|
|
1461
|
+
"src/core/scene/kinds/cone3d.ts"() {
|
|
1462
|
+
init_registry();
|
|
1463
|
+
CURVED_SEGMENTS2 = 16;
|
|
1464
|
+
registerKind({
|
|
1465
|
+
type: "cone3d",
|
|
1466
|
+
schemaVersion: 1,
|
|
1467
|
+
migrate: {},
|
|
1468
|
+
validate: (a) => {
|
|
1469
|
+
if (!a?.baseCenter || !a?.apex) throw new Error("cone3d: baseCenter/apex required");
|
|
1470
|
+
if (!(a.radius > 0)) throw new Error("cone3d: radius > 0");
|
|
1471
|
+
},
|
|
1472
|
+
dependsOn: (a) => [a.baseCenter, a.apex],
|
|
1473
|
+
describe: (obj) => `N\xF3n ${obj.label} R=${obj.attrs.radius.toFixed(2)}`,
|
|
1474
|
+
render: (obj, ctx) => {
|
|
1475
|
+
const view = ctx.jxg;
|
|
1476
|
+
const base = ctx.resolveRef(obj.attrs.baseCenter);
|
|
1477
|
+
const apexPt = ctx.resolveRef(obj.attrs.apex);
|
|
1478
|
+
const r = obj.attrs.radius;
|
|
1479
|
+
const bx = base.X?.() ?? 0, by = base.Y?.() ?? 0, bz = base.Z?.() ?? 0;
|
|
1480
|
+
const apexCoords = [
|
|
1481
|
+
apexPt.X?.() ?? 0,
|
|
1482
|
+
apexPt.Y?.() ?? 0,
|
|
1483
|
+
apexPt.Z?.() ?? 0
|
|
1484
|
+
];
|
|
1485
|
+
const baseRing = [];
|
|
1486
|
+
for (let i = 0; i < CURVED_SEGMENTS2; i++) {
|
|
1487
|
+
const theta = i / CURVED_SEGMENTS2 * Math.PI * 2;
|
|
1488
|
+
baseRing.push([bx + r * Math.cos(theta), by + r * Math.sin(theta), bz]);
|
|
1489
|
+
}
|
|
1490
|
+
const apexIdx = baseRing.length;
|
|
1491
|
+
const vertices = [...baseRing, apexCoords];
|
|
1492
|
+
const faces = [baseRing.map((_, i) => i)];
|
|
1493
|
+
for (let i = 0; i < CURVED_SEGMENTS2; i++) {
|
|
1494
|
+
faces.push([i, (i + 1) % CURVED_SEGMENTS2, apexIdx]);
|
|
1495
|
+
}
|
|
1496
|
+
const vertJxgs = vertices.map(
|
|
1497
|
+
(v, i) => view.create("point3d", v, {
|
|
1498
|
+
id: `${obj.id}.v${i}`,
|
|
1499
|
+
visible: false,
|
|
1500
|
+
fixed: true,
|
|
1501
|
+
withLabel: false
|
|
1502
|
+
})
|
|
1503
|
+
);
|
|
1504
|
+
const faceJxgs = faces.map(
|
|
1505
|
+
(face, fi) => view.create("polygon3d", [face.map((idx) => vertJxgs[idx])], {
|
|
1506
|
+
id: `${obj.id}.face${fi}`,
|
|
1507
|
+
fillOpacity: 0.25,
|
|
1508
|
+
fillColor: obj.attrs.color ?? "#f59e0b",
|
|
1509
|
+
strokeColor: "#0066cc",
|
|
1510
|
+
strokeWidth: 1.5,
|
|
1511
|
+
visible: obj.visible
|
|
1512
|
+
})
|
|
1513
|
+
);
|
|
1514
|
+
return { _verts: vertJxgs, faces: faceJxgs };
|
|
1515
|
+
}
|
|
1516
|
+
});
|
|
1517
|
+
}
|
|
1518
|
+
});
|
|
1519
|
+
|
|
1520
|
+
// src/core/scene/kinds/2d-constraint.ts
|
|
1521
|
+
function transformRefs(t) {
|
|
1522
|
+
switch (t.kind) {
|
|
1523
|
+
case "translate":
|
|
1524
|
+
return [];
|
|
1525
|
+
case "rotate":
|
|
1526
|
+
case "reflectPoint":
|
|
1527
|
+
case "dilate":
|
|
1528
|
+
return [t.center];
|
|
1529
|
+
case "reflectLine":
|
|
1530
|
+
return [t.line];
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
function constraintRefs2D(c) {
|
|
1534
|
+
switch (c.kind) {
|
|
1535
|
+
case "onLine":
|
|
1536
|
+
return [c.lineId];
|
|
1537
|
+
case "onSegment":
|
|
1538
|
+
return [c.segmentId];
|
|
1539
|
+
case "onCircle":
|
|
1540
|
+
return [c.circleId];
|
|
1541
|
+
case "onPolygon":
|
|
1542
|
+
return [c.polygonId];
|
|
1543
|
+
case "midpoint":
|
|
1544
|
+
return [c.p1, c.p2];
|
|
1545
|
+
case "transformed":
|
|
1546
|
+
return [c.source, ...transformRefs(c.transform)];
|
|
1547
|
+
case "perpFoot":
|
|
1548
|
+
return [c.from, c.onLine];
|
|
1549
|
+
case "circumcenter":
|
|
1550
|
+
return [c.vertices[0], c.vertices[1], c.vertices[2]];
|
|
1551
|
+
case "incenter":
|
|
1552
|
+
return [c.vertices[0], c.vertices[1], c.vertices[2]];
|
|
1553
|
+
case "centroid":
|
|
1554
|
+
return [c.vertices[0], c.vertices[1], c.vertices[2]];
|
|
1555
|
+
case "orthocenter":
|
|
1556
|
+
return [c.vertices[0], c.vertices[1], c.vertices[2]];
|
|
1557
|
+
default:
|
|
1558
|
+
return [];
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
var init_d_constraint2 = __esm({
|
|
1562
|
+
"src/core/scene/kinds/2d-constraint.ts"() {
|
|
1563
|
+
}
|
|
1564
|
+
});
|
|
1565
|
+
|
|
1566
|
+
// src/core/scene/kinds/point.ts
|
|
1567
|
+
function buildJxgTransforms(board, ctx, t) {
|
|
1568
|
+
switch (t.kind) {
|
|
1569
|
+
case "translate":
|
|
1570
|
+
return [board.create("transform", [t.dx, t.dy], { type: "translate" })];
|
|
1571
|
+
case "rotate": {
|
|
1572
|
+
const c = ctx.resolveRef(t.center);
|
|
1573
|
+
return [board.create("transform", [t.angleRad, c], { type: "rotate" })];
|
|
1574
|
+
}
|
|
1575
|
+
case "reflectPoint": {
|
|
1576
|
+
const c = ctx.resolveRef(t.center);
|
|
1577
|
+
return [board.create("transform", [Math.PI, c], { type: "rotate" })];
|
|
1578
|
+
}
|
|
1579
|
+
case "reflectLine": {
|
|
1580
|
+
const l = ctx.resolveRef(t.line);
|
|
1581
|
+
return [board.create("transform", [l], { type: "reflect" })];
|
|
1582
|
+
}
|
|
1583
|
+
case "dilate": {
|
|
1584
|
+
const c = ctx.resolveRef(t.center);
|
|
1585
|
+
return [
|
|
1586
|
+
board.create("transform", [() => -c.X(), () => -c.Y()], { type: "translate" }),
|
|
1587
|
+
board.create("transform", [t.k, t.k], { type: "scale" }),
|
|
1588
|
+
board.create("transform", [() => c.X(), () => c.Y()], { type: "translate" })
|
|
1589
|
+
];
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
var def3;
|
|
1594
|
+
var init_point = __esm({
|
|
1595
|
+
"src/core/scene/kinds/point.ts"() {
|
|
1596
|
+
init_registry();
|
|
1597
|
+
init_d_constraint2();
|
|
1598
|
+
def3 = {
|
|
1599
|
+
type: "point",
|
|
1600
|
+
schemaVersion: 1,
|
|
1601
|
+
migrate: {},
|
|
1602
|
+
validate: (a) => {
|
|
1603
|
+
if (!a || !a.constraint || !a.constraint.kind) {
|
|
1604
|
+
throw new Error("point: constraint required");
|
|
1605
|
+
}
|
|
1606
|
+
const c = a.constraint;
|
|
1607
|
+
if (c.kind === "perpFoot") {
|
|
1608
|
+
if (!c.from || !c.onLine) {
|
|
1609
|
+
throw new Error("point.perpFoot: from v\xE0 onLine b\u1EAFt bu\u1ED9c");
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
if (c.kind === "circumcenter") {
|
|
1613
|
+
if (!Array.isArray(c.vertices) || c.vertices.length !== 3) {
|
|
1614
|
+
throw new Error("point.circumcenter: vertices ph\u1EA3i l\xE0 tuple 3 id");
|
|
1615
|
+
}
|
|
1616
|
+
if (!c.vertices[0] || !c.vertices[1] || !c.vertices[2]) {
|
|
1617
|
+
throw new Error("point.circumcenter: 3 vertex id ph\u1EA3i non-empty");
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
if (c.kind === "incenter") {
|
|
1621
|
+
if (!Array.isArray(c.vertices) || c.vertices.length !== 3) {
|
|
1622
|
+
throw new Error("point.incenter: vertices ph\u1EA3i l\xE0 tuple 3 id");
|
|
1623
|
+
}
|
|
1624
|
+
if (!c.vertices[0] || !c.vertices[1] || !c.vertices[2]) {
|
|
1625
|
+
throw new Error("point.incenter: 3 vertex id ph\u1EA3i non-empty");
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
if (c.kind === "centroid") {
|
|
1629
|
+
if (!Array.isArray(c.vertices) || c.vertices.length !== 3) {
|
|
1630
|
+
throw new Error("point.centroid: vertices ph\u1EA3i l\xE0 tuple 3 id");
|
|
1631
|
+
}
|
|
1632
|
+
if (!c.vertices[0] || !c.vertices[1] || !c.vertices[2]) {
|
|
1633
|
+
throw new Error("point.centroid: 3 vertex id ph\u1EA3i non-empty");
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
if (c.kind === "orthocenter") {
|
|
1637
|
+
if (!Array.isArray(c.vertices) || c.vertices.length !== 3) {
|
|
1638
|
+
throw new Error("point.orthocenter: vertices ph\u1EA3i l\xE0 tuple 3 id");
|
|
1639
|
+
}
|
|
1640
|
+
if (!c.vertices[0] || !c.vertices[1] || !c.vertices[2]) {
|
|
1641
|
+
throw new Error("point.orthocenter: 3 vertex id ph\u1EA3i non-empty");
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
},
|
|
1645
|
+
dependsOn: (a) => constraintRefs2D(a.constraint),
|
|
1646
|
+
measure: (obj) => {
|
|
1647
|
+
const c = obj.attrs.constraint;
|
|
1648
|
+
if (c.kind === "free") {
|
|
1649
|
+
return [
|
|
1650
|
+
{ label: "x", value: c.x },
|
|
1651
|
+
{ label: "y", value: c.y }
|
|
1652
|
+
];
|
|
1653
|
+
}
|
|
1654
|
+
return null;
|
|
1655
|
+
},
|
|
1656
|
+
describe: (obj, state) => {
|
|
1657
|
+
const c = obj.attrs.constraint;
|
|
1658
|
+
if (c.kind === "free") return `\u0110i\u1EC3m ${obj.label}`;
|
|
1659
|
+
if (c.kind === "onAxis") return `${obj.label} tr\xEAn tr\u1EE5c ${c.axis}`;
|
|
1660
|
+
if (c.kind === "onLine") return `${obj.label} tr\xEAn \u0111\u01B0\u1EDDng ${state?.objects[c.lineId]?.label ?? c.lineId}`;
|
|
1661
|
+
if (c.kind === "onSegment") return `${obj.label} tr\xEAn \u0111o\u1EA1n ${state?.objects[c.segmentId]?.label ?? c.segmentId}`;
|
|
1662
|
+
if (c.kind === "onCircle") return `${obj.label} tr\xEAn \u0111\u01B0\u1EDDng tr\xF2n ${state?.objects[c.circleId]?.label ?? c.circleId}`;
|
|
1663
|
+
if (c.kind === "onPolygon") return `${obj.label} tr\xEAn \u0111a gi\xE1c ${state?.objects[c.polygonId]?.label ?? c.polygonId}`;
|
|
1664
|
+
if (c.kind === "midpoint") {
|
|
1665
|
+
const l1 = state?.objects[c.p1]?.label ?? c.p1;
|
|
1666
|
+
const l2 = state?.objects[c.p2]?.label ?? c.p2;
|
|
1667
|
+
return `${obj.label} = trung \u0111i\u1EC3m ${l1}${l2}`;
|
|
1668
|
+
}
|
|
1669
|
+
if (c.kind === "transformed") {
|
|
1670
|
+
const t = c.transform;
|
|
1671
|
+
const labelRef = (id) => state?.objects[id]?.label ?? id;
|
|
1672
|
+
const op = t.kind === "translate" ? `t\u1ECBnh ti\u1EBFn (${t.dx.toFixed(2)}, ${t.dy.toFixed(2)})` : t.kind === "rotate" ? `quay ${(t.angleRad * 180 / Math.PI).toFixed(0)}\xB0 quanh ${labelRef(t.center)}` : t.kind === "reflectLine" ? `\u0111\u1ED1i x\u1EE9ng qua ${labelRef(t.line)}` : t.kind === "reflectPoint" ? `\u0111\u1ED1i x\u1EE9ng qua \u0111i\u1EC3m ${labelRef(t.center)}` : t.kind === "dilate" ? `v\u1ECB t\u1EF1 k=${t.k} quanh ${labelRef(t.center)}` : "";
|
|
1673
|
+
return `${obj.label} = \u1EA3nh c\u1EE7a ${labelRef(c.source)} (${op})`;
|
|
1674
|
+
}
|
|
1675
|
+
if (c.kind === "perpFoot") {
|
|
1676
|
+
const fromLabel = state?.objects[c.from]?.label ?? c.from;
|
|
1677
|
+
const lineLabel = state?.objects[c.onLine]?.label ?? c.onLine;
|
|
1678
|
+
return `${obj.label} = ch\xE2n \u27C2 t\u1EEB ${fromLabel} xu\u1ED1ng ${lineLabel}`;
|
|
1679
|
+
}
|
|
1680
|
+
if (c.kind === "circumcenter") {
|
|
1681
|
+
const labels = c.vertices.map((id) => state?.objects[id]?.label ?? id).join("");
|
|
1682
|
+
return `${obj.label} = t\xE2m ngo\u1EA1i ti\u1EBFp \u0394${labels}`;
|
|
1683
|
+
}
|
|
1684
|
+
if (c.kind === "incenter") {
|
|
1685
|
+
const labels = c.vertices.map((id) => state?.objects[id]?.label ?? id).join("");
|
|
1686
|
+
return `${obj.label} = t\xE2m n\u1ED9i ti\u1EBFp \u0394${labels}`;
|
|
1687
|
+
}
|
|
1688
|
+
if (c.kind === "centroid") {
|
|
1689
|
+
const labels = c.vertices.map((id) => state?.objects[id]?.label ?? id).join("");
|
|
1690
|
+
return `${obj.label} = tr\u1ECDng t\xE2m \u0394${labels}`;
|
|
1691
|
+
}
|
|
1692
|
+
if (c.kind === "orthocenter") {
|
|
1693
|
+
const labels = c.vertices.map((id) => state?.objects[id]?.label ?? id).join("");
|
|
1694
|
+
return `${obj.label} = tr\u1EF1c t\xE2m \u0394${labels}`;
|
|
1695
|
+
}
|
|
1696
|
+
return `\u0110i\u1EC3m ${obj.label}`;
|
|
1697
|
+
},
|
|
1698
|
+
render: (obj, ctx) => {
|
|
1699
|
+
const board = ctx.jxg;
|
|
1700
|
+
const c = obj.attrs.constraint;
|
|
1701
|
+
const opts = {
|
|
1702
|
+
name: obj.label,
|
|
1703
|
+
withLabel: obj.attrs.showLabel ?? true,
|
|
1704
|
+
visible: obj.visible,
|
|
1705
|
+
fixed: obj.locked,
|
|
1706
|
+
strokeColor: obj.attrs.color ?? "#1e40af",
|
|
1707
|
+
fillColor: obj.attrs.color ?? "#1e40af",
|
|
1708
|
+
face: obj.attrs.face ?? "o",
|
|
1709
|
+
size: obj.attrs.size ?? 4
|
|
1710
|
+
};
|
|
1711
|
+
if (c.kind === "free") return board.create("point", [c.x, c.y], opts);
|
|
1712
|
+
if (c.kind === "onAxis") {
|
|
1713
|
+
const coords = c.axis === "x" ? [c.t, 0] : [0, c.t];
|
|
1714
|
+
return board.create("point", coords, opts);
|
|
1715
|
+
}
|
|
1716
|
+
if (c.kind === "onLine") {
|
|
1717
|
+
const line = ctx.resolveRef(c.lineId);
|
|
1718
|
+
return board.create("glider", [c.t, c.t, line], opts);
|
|
1719
|
+
}
|
|
1720
|
+
if (c.kind === "onSegment") {
|
|
1721
|
+
const seg = ctx.resolveRef(c.segmentId);
|
|
1722
|
+
return board.create("glider", [c.t, c.t, seg], opts);
|
|
1723
|
+
}
|
|
1724
|
+
if (c.kind === "onCircle") {
|
|
1725
|
+
const circle = ctx.resolveRef(c.circleId);
|
|
1726
|
+
return board.create("glider", [Math.cos(c.theta), Math.sin(c.theta), circle], opts);
|
|
1727
|
+
}
|
|
1728
|
+
if (c.kind === "onPolygon") {
|
|
1729
|
+
const poly = ctx.resolveRef(c.polygonId);
|
|
1730
|
+
return board.create("glider", [c.u, c.v, poly], opts);
|
|
1731
|
+
}
|
|
1732
|
+
if (c.kind === "midpoint") {
|
|
1733
|
+
const p1 = ctx.resolveRef(c.p1);
|
|
1734
|
+
const p2 = ctx.resolveRef(c.p2);
|
|
1735
|
+
return board.create("midpoint", [p1, p2], opts);
|
|
1736
|
+
}
|
|
1737
|
+
if (c.kind === "transformed") {
|
|
1738
|
+
const src = ctx.resolveRef(c.source);
|
|
1739
|
+
const transforms = buildJxgTransforms(board, ctx, c.transform);
|
|
1740
|
+
const parent = transforms.length === 1 ? transforms[0] : transforms;
|
|
1741
|
+
const pt = board.create("point", [src, parent], opts);
|
|
1742
|
+
pt._helpers = transforms;
|
|
1743
|
+
return pt;
|
|
1744
|
+
}
|
|
1745
|
+
if (c.kind === "perpFoot") {
|
|
1746
|
+
const from = ctx.resolveRef(c.from);
|
|
1747
|
+
const onLine = ctx.resolveRef(c.onLine);
|
|
1748
|
+
return board.create("perpendicularpoint", [onLine, from], opts);
|
|
1749
|
+
}
|
|
1750
|
+
if (c.kind === "circumcenter") {
|
|
1751
|
+
const a = ctx.resolveRef(c.vertices[0]);
|
|
1752
|
+
const b = ctx.resolveRef(c.vertices[1]);
|
|
1753
|
+
const c3 = ctx.resolveRef(c.vertices[2]);
|
|
1754
|
+
return board.create("circumcenter", [a, b, c3], opts);
|
|
1755
|
+
}
|
|
1756
|
+
if (c.kind === "incenter") {
|
|
1757
|
+
const a = ctx.resolveRef(c.vertices[0]);
|
|
1758
|
+
const b = ctx.resolveRef(c.vertices[1]);
|
|
1759
|
+
const c3 = ctx.resolveRef(c.vertices[2]);
|
|
1760
|
+
return board.create("incenter", [a, b, c3], opts);
|
|
1761
|
+
}
|
|
1762
|
+
if (c.kind === "centroid") {
|
|
1763
|
+
const a = ctx.resolveRef(c.vertices[0]);
|
|
1764
|
+
const b = ctx.resolveRef(c.vertices[1]);
|
|
1765
|
+
const c3 = ctx.resolveRef(c.vertices[2]);
|
|
1766
|
+
return board.create("point", [
|
|
1767
|
+
() => (a.X() + b.X() + c3.X()) / 3,
|
|
1768
|
+
() => (a.Y() + b.Y() + c3.Y()) / 3
|
|
1769
|
+
], opts);
|
|
1770
|
+
}
|
|
1771
|
+
if (c.kind === "orthocenter") {
|
|
1772
|
+
const a = ctx.resolveRef(c.vertices[0]);
|
|
1773
|
+
const b = ctx.resolveRef(c.vertices[1]);
|
|
1774
|
+
const c3 = ctx.resolveRef(c.vertices[2]);
|
|
1775
|
+
const hide = { visible: false, withLabel: false, fixed: true, name: "" };
|
|
1776
|
+
const lineBC = board.create("line", [b, c3], hide);
|
|
1777
|
+
const altA = board.create("perpendicular", [lineBC, a], hide);
|
|
1778
|
+
const lineAC = board.create("line", [a, c3], hide);
|
|
1779
|
+
const altB = board.create("perpendicular", [lineAC, b], hide);
|
|
1780
|
+
const ortho = board.create("intersection", [altA, altB, 0], opts);
|
|
1781
|
+
ortho._helpers = [lineBC, altA, lineAC, altB];
|
|
1782
|
+
return ortho;
|
|
1783
|
+
}
|
|
1784
|
+
return board.create("point", [0, 0], opts);
|
|
1785
|
+
},
|
|
1786
|
+
/**
|
|
1787
|
+
* Free → Free update giữ nguyên JxgObj identity (gọi setPositionDirectly +
|
|
1788
|
+
* setAttribute) để các object phụ thuộc (line/segment/...) không bị stale
|
|
1789
|
+
* parent ref. Đổi constraint kind → throw để renderer fallback recreate.
|
|
1790
|
+
*
|
|
1791
|
+
* Đây cũng là endpoint cho drag-sync dispatch trong JxgRenderer: khi user
|
|
1792
|
+
* kéo điểm, listener dispatch UPDATE_ATTRS → update hook chạy, vị trí đã
|
|
1793
|
+
* đúng sẵn nên setPositionDirectly là no-op nhưng vẫn cần để sync các attrs
|
|
1794
|
+
* khác (label/color/...).
|
|
1795
|
+
*/
|
|
1796
|
+
update: (obj, prev, ctx, existing) => {
|
|
1797
|
+
const c = obj.attrs.constraint;
|
|
1798
|
+
const oldC = prev.attrs.constraint;
|
|
1799
|
+
if (c.kind === "free" && oldC.kind === "free") {
|
|
1800
|
+
const el = existing;
|
|
1801
|
+
if (typeof el.setPositionDirectly === "function") {
|
|
1802
|
+
try {
|
|
1803
|
+
el.setPositionDirectly(1, [c.x, c.y]);
|
|
1804
|
+
} catch {
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
if (typeof el.setAttribute === "function") {
|
|
1808
|
+
try {
|
|
1809
|
+
el.setAttribute({
|
|
1810
|
+
name: obj.label,
|
|
1811
|
+
withLabel: obj.attrs.showLabel ?? true,
|
|
1812
|
+
visible: obj.visible,
|
|
1813
|
+
fixed: obj.locked,
|
|
1814
|
+
strokeColor: obj.attrs.color ?? "#1e40af",
|
|
1815
|
+
fillColor: obj.attrs.color ?? "#1e40af",
|
|
1816
|
+
face: obj.attrs.face ?? "o",
|
|
1817
|
+
size: obj.attrs.size ?? 4
|
|
1818
|
+
});
|
|
1819
|
+
} catch {
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
return;
|
|
1823
|
+
}
|
|
1824
|
+
throw new Error("point: constraint kind changed \u2014 recreate");
|
|
1825
|
+
}
|
|
1826
|
+
};
|
|
1827
|
+
registerKind(def3);
|
|
1828
|
+
}
|
|
1829
|
+
});
|
|
1830
|
+
|
|
1831
|
+
// src/core/scene/kinds/segment.ts
|
|
1832
|
+
var def4;
|
|
1833
|
+
var init_segment = __esm({
|
|
1834
|
+
"src/core/scene/kinds/segment.ts"() {
|
|
1835
|
+
init_registry();
|
|
1836
|
+
init_labelOf();
|
|
1837
|
+
def4 = {
|
|
1838
|
+
type: "segment",
|
|
1839
|
+
schemaVersion: 1,
|
|
1840
|
+
migrate: {},
|
|
1841
|
+
validate: (a) => {
|
|
1842
|
+
if (!a?.p1 || !a?.p2) throw new Error("segment: p1 v\xE0 p2 b\u1EAFt bu\u1ED9c");
|
|
1843
|
+
},
|
|
1844
|
+
dependsOn: (a) => [a.p1, a.p2],
|
|
1845
|
+
measure: (obj, state) => {
|
|
1846
|
+
const p1 = state.objects[obj.attrs.p1];
|
|
1847
|
+
const p2 = state.objects[obj.attrs.p2];
|
|
1848
|
+
if (!p1 || !p2) return null;
|
|
1849
|
+
const c1 = p1.attrs.constraint;
|
|
1850
|
+
const c2 = p2.attrs.constraint;
|
|
1851
|
+
if (c1?.kind !== "free" || c2?.kind !== "free") return null;
|
|
1852
|
+
const dx = (c2.x ?? 0) - (c1.x ?? 0);
|
|
1853
|
+
const dy = (c2.y ?? 0) - (c1.y ?? 0);
|
|
1854
|
+
return [{ label: "length", value: Math.hypot(dx, dy) }];
|
|
1855
|
+
},
|
|
1856
|
+
describe: (obj, state) => `\u0110o\u1EA1n th\u1EB3ng ${labelOf(obj.attrs.p1, state)}${labelOf(obj.attrs.p2, state)}`,
|
|
1857
|
+
render: (obj, ctx) => {
|
|
1858
|
+
const board = ctx.jxg;
|
|
1859
|
+
const p1 = ctx.resolveRef(obj.attrs.p1);
|
|
1860
|
+
const p2 = ctx.resolveRef(obj.attrs.p2);
|
|
1861
|
+
return board.create("segment", [p1, p2], {
|
|
1862
|
+
name: obj.label,
|
|
1863
|
+
withLabel: obj.attrs.showLabel ?? false,
|
|
1864
|
+
strokeColor: obj.attrs.color ?? "#0f172a",
|
|
1865
|
+
strokeWidth: obj.attrs.width ?? 2,
|
|
1866
|
+
dash: obj.attrs.dash ?? 0,
|
|
1867
|
+
visible: obj.visible,
|
|
1868
|
+
fixed: obj.locked
|
|
1869
|
+
});
|
|
1870
|
+
}
|
|
1871
|
+
};
|
|
1872
|
+
registerKind(def4);
|
|
1873
|
+
}
|
|
1874
|
+
});
|
|
1875
|
+
|
|
1876
|
+
// src/core/scene/kinds/line.ts
|
|
1877
|
+
function stripBorderSuffix(id) {
|
|
1878
|
+
const m = /^(.+):border:\d+$/.exec(id);
|
|
1879
|
+
return m ? m[1] : id;
|
|
1880
|
+
}
|
|
1881
|
+
function constructionRefs(c) {
|
|
1882
|
+
switch (c.kind) {
|
|
1883
|
+
case "perpendicular":
|
|
1884
|
+
case "parallel":
|
|
1885
|
+
return [c.throughPoint, stripBorderSuffix(c.toLine)];
|
|
1886
|
+
case "perpBisector":
|
|
1887
|
+
return [c.p1, c.p2];
|
|
1888
|
+
case "angleBisector":
|
|
1889
|
+
return [c.p1, c.vertex, c.p2];
|
|
1890
|
+
case "angleBisectorLines":
|
|
1891
|
+
return [stripBorderSuffix(c.line1), stripBorderSuffix(c.line2)];
|
|
1892
|
+
case "tangent":
|
|
1893
|
+
return [c.throughPoint, c.toCircle];
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
var def5;
|
|
1897
|
+
var init_line = __esm({
|
|
1898
|
+
"src/core/scene/kinds/line.ts"() {
|
|
1899
|
+
init_registry();
|
|
1900
|
+
init_labelOf();
|
|
1901
|
+
def5 = {
|
|
1902
|
+
type: "line",
|
|
1903
|
+
schemaVersion: 1,
|
|
1904
|
+
migrate: {},
|
|
1905
|
+
validate: (a) => {
|
|
1906
|
+
if (a?.construction) return;
|
|
1907
|
+
if (!a?.p1 || !a?.p2) throw new Error("line: p1 v\xE0 p2 b\u1EAFt bu\u1ED9c (ho\u1EB7c construction)");
|
|
1908
|
+
},
|
|
1909
|
+
dependsOn: (a) => a.construction ? constructionRefs(a.construction) : [a.p1, a.p2],
|
|
1910
|
+
describe: (obj, state) => {
|
|
1911
|
+
const L = (id) => labelOf(id, state);
|
|
1912
|
+
const c = obj.attrs.construction;
|
|
1913
|
+
if (!c) return `\u0110\u01B0\u1EDDng th\u1EB3ng ${L(obj.attrs.p1)}${L(obj.attrs.p2)}`;
|
|
1914
|
+
switch (c.kind) {
|
|
1915
|
+
case "perpendicular":
|
|
1916
|
+
return `${obj.label} \u27C2 ${L(c.toLine)} qua ${L(c.throughPoint)}`;
|
|
1917
|
+
case "parallel":
|
|
1918
|
+
return `${obj.label} \u2225 ${L(c.toLine)} qua ${L(c.throughPoint)}`;
|
|
1919
|
+
case "perpBisector":
|
|
1920
|
+
return `${obj.label}: trung tr\u1EF1c ${L(c.p1)}${L(c.p2)}`;
|
|
1921
|
+
case "angleBisector":
|
|
1922
|
+
return `${obj.label}: ph\xE2n gi\xE1c g\xF3c ${L(c.p1)}${L(c.vertex)}${L(c.p2)}`;
|
|
1923
|
+
case "angleBisectorLines":
|
|
1924
|
+
return `${obj.label}: ph\xE2n gi\xE1c ${L(c.line1)} & ${L(c.line2)} (${c.branch === 0 ? "1" : "2"})`;
|
|
1925
|
+
case "tangent":
|
|
1926
|
+
return `${obj.label}: ti\u1EBFp tuy\u1EBFn ${L(c.toCircle)} qua ${L(c.throughPoint)}`;
|
|
1927
|
+
}
|
|
1928
|
+
},
|
|
1929
|
+
render: (obj, ctx) => {
|
|
1930
|
+
const board = ctx.jxg;
|
|
1931
|
+
const baseOpts = {
|
|
1932
|
+
name: obj.label,
|
|
1933
|
+
withLabel: obj.attrs.showLabel ?? false,
|
|
1934
|
+
strokeColor: obj.attrs.color ?? "#0f172a",
|
|
1935
|
+
strokeWidth: obj.attrs.width ?? 2,
|
|
1936
|
+
dash: obj.attrs.dash ?? 0,
|
|
1937
|
+
visible: obj.visible,
|
|
1938
|
+
fixed: obj.locked
|
|
1939
|
+
};
|
|
1940
|
+
const c = obj.attrs.construction;
|
|
1941
|
+
if (!c) {
|
|
1942
|
+
const p1 = ctx.resolveRef(obj.attrs.p1);
|
|
1943
|
+
const p2 = ctx.resolveRef(obj.attrs.p2);
|
|
1944
|
+
return board.create("line", [p1, p2], {
|
|
1945
|
+
...baseOpts,
|
|
1946
|
+
straightFirst: true,
|
|
1947
|
+
straightLast: true
|
|
1948
|
+
});
|
|
1949
|
+
}
|
|
1950
|
+
switch (c.kind) {
|
|
1951
|
+
case "perpendicular": {
|
|
1952
|
+
const through = ctx.resolveRef(c.throughPoint);
|
|
1953
|
+
const toLine = ctx.resolveRef(c.toLine);
|
|
1954
|
+
return board.create("perpendicular", [toLine, through], baseOpts);
|
|
1955
|
+
}
|
|
1956
|
+
case "parallel": {
|
|
1957
|
+
const through = ctx.resolveRef(c.throughPoint);
|
|
1958
|
+
const toLine = ctx.resolveRef(c.toLine);
|
|
1959
|
+
return board.create("parallel", [toLine, through], baseOpts);
|
|
1960
|
+
}
|
|
1961
|
+
case "perpBisector": {
|
|
1962
|
+
const p1 = ctx.resolveRef(c.p1);
|
|
1963
|
+
const p2 = ctx.resolveRef(c.p2);
|
|
1964
|
+
const mid = board.create("midpoint", [p1, p2], {
|
|
1965
|
+
visible: false,
|
|
1966
|
+
withLabel: false,
|
|
1967
|
+
fixed: true,
|
|
1968
|
+
name: ""
|
|
1969
|
+
});
|
|
1970
|
+
const helperLine = board.create("line", [p1, p2], {
|
|
1971
|
+
visible: false,
|
|
1972
|
+
withLabel: false,
|
|
1973
|
+
fixed: true,
|
|
1974
|
+
name: "",
|
|
1975
|
+
straightFirst: true,
|
|
1976
|
+
straightLast: true
|
|
1977
|
+
});
|
|
1978
|
+
const bisector = board.create("perpendicular", [helperLine, mid], baseOpts);
|
|
1979
|
+
bisector._helpers = [mid, helperLine];
|
|
1980
|
+
return bisector;
|
|
1981
|
+
}
|
|
1982
|
+
case "angleBisector": {
|
|
1983
|
+
const p1 = ctx.resolveRef(c.p1);
|
|
1984
|
+
const vertex = ctx.resolveRef(c.vertex);
|
|
1985
|
+
const p2 = ctx.resolveRef(c.p2);
|
|
1986
|
+
return board.create("bisector", [p1, vertex, p2], baseOpts);
|
|
1987
|
+
}
|
|
1988
|
+
case "angleBisectorLines": {
|
|
1989
|
+
const line1Jxg = ctx.resolveRef(c.line1);
|
|
1990
|
+
const line2Jxg = ctx.resolveRef(c.line2);
|
|
1991
|
+
const comp = board.create("bisectorlines", [line1Jxg, line2Jxg], {
|
|
1992
|
+
line1: { visible: false, withLabel: false, fixed: true, name: "" },
|
|
1993
|
+
line2: { visible: false, withLabel: false, fixed: true, name: "" }
|
|
1994
|
+
});
|
|
1995
|
+
const selected = c.branch === 0 ? comp.line1 : comp.line2;
|
|
1996
|
+
const other = c.branch === 0 ? comp.line2 : comp.line1;
|
|
1997
|
+
selected.setAttribute({
|
|
1998
|
+
...baseOpts,
|
|
1999
|
+
visible: obj.visible,
|
|
2000
|
+
fixed: obj.locked
|
|
2001
|
+
});
|
|
2002
|
+
selected._helpers = [other];
|
|
2003
|
+
return selected;
|
|
2004
|
+
}
|
|
2005
|
+
case "tangent": {
|
|
2006
|
+
const through = ctx.resolveRef(c.throughPoint);
|
|
2007
|
+
const toCircle = ctx.resolveRef(c.toCircle);
|
|
2008
|
+
const branch = c.branch ?? "on";
|
|
2009
|
+
if (branch === "on") {
|
|
2010
|
+
const glider = board.create("glider", [through.X(), through.Y(), toCircle], {
|
|
2011
|
+
visible: false,
|
|
2012
|
+
withLabel: false,
|
|
2013
|
+
fixed: true,
|
|
2014
|
+
name: ""
|
|
2015
|
+
});
|
|
2016
|
+
const tangent2 = board.create("tangent", [glider], baseOpts);
|
|
2017
|
+
tangent2._helpers = [glider];
|
|
2018
|
+
return tangent2;
|
|
2019
|
+
}
|
|
2020
|
+
const center = toCircle.center;
|
|
2021
|
+
const mid = board.create("midpoint", [center, through], {
|
|
2022
|
+
visible: false,
|
|
2023
|
+
withLabel: false,
|
|
2024
|
+
fixed: true,
|
|
2025
|
+
name: ""
|
|
2026
|
+
});
|
|
2027
|
+
const thales = board.create("circle", [mid, through], {
|
|
2028
|
+
visible: false,
|
|
2029
|
+
withLabel: false,
|
|
2030
|
+
fixed: true,
|
|
2031
|
+
strokeOpacity: 0,
|
|
2032
|
+
fillOpacity: 0
|
|
2033
|
+
});
|
|
2034
|
+
const touch = board.create("intersection", [thales, toCircle, branch], {
|
|
2035
|
+
visible: false,
|
|
2036
|
+
withLabel: false,
|
|
2037
|
+
fixed: true,
|
|
2038
|
+
name: ""
|
|
2039
|
+
});
|
|
2040
|
+
const tangent = board.create("line", [through, touch], {
|
|
2041
|
+
...baseOpts,
|
|
2042
|
+
straightFirst: true,
|
|
2043
|
+
straightLast: true
|
|
2044
|
+
});
|
|
2045
|
+
tangent._helpers = [mid, thales, touch];
|
|
2046
|
+
return tangent;
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
}
|
|
2050
|
+
};
|
|
2051
|
+
registerKind(def5);
|
|
2052
|
+
}
|
|
2053
|
+
});
|
|
2054
|
+
|
|
2055
|
+
// src/core/scene/kinds/ray.ts
|
|
2056
|
+
var def6;
|
|
2057
|
+
var init_ray = __esm({
|
|
2058
|
+
"src/core/scene/kinds/ray.ts"() {
|
|
2059
|
+
init_registry();
|
|
2060
|
+
init_labelOf();
|
|
2061
|
+
def6 = {
|
|
2062
|
+
type: "ray",
|
|
2063
|
+
schemaVersion: 1,
|
|
2064
|
+
migrate: {},
|
|
2065
|
+
validate: (a) => {
|
|
2066
|
+
if (!a?.origin || !a?.through) throw new Error("ray: origin v\xE0 through b\u1EAFt bu\u1ED9c");
|
|
2067
|
+
},
|
|
2068
|
+
dependsOn: (a) => [a.origin, a.through],
|
|
2069
|
+
describe: (obj, state) => `Tia ${labelOf(obj.attrs.origin, state)}${labelOf(obj.attrs.through, state)}`,
|
|
2070
|
+
render: (obj, ctx) => {
|
|
2071
|
+
const board = ctx.jxg;
|
|
2072
|
+
const o = ctx.resolveRef(obj.attrs.origin);
|
|
2073
|
+
const t = ctx.resolveRef(obj.attrs.through);
|
|
2074
|
+
return board.create("line", [o, t], {
|
|
2075
|
+
name: obj.label,
|
|
2076
|
+
straightFirst: false,
|
|
2077
|
+
straightLast: true,
|
|
2078
|
+
strokeColor: obj.attrs.color ?? "#0f172a",
|
|
2079
|
+
strokeWidth: obj.attrs.width ?? 2,
|
|
2080
|
+
dash: obj.attrs.dash ?? 0,
|
|
2081
|
+
visible: obj.visible,
|
|
2082
|
+
fixed: obj.locked
|
|
2083
|
+
});
|
|
2084
|
+
}
|
|
2085
|
+
};
|
|
2086
|
+
registerKind(def6);
|
|
2087
|
+
}
|
|
2088
|
+
});
|
|
2089
|
+
|
|
2090
|
+
// src/core/scene/kinds/vector.ts
|
|
2091
|
+
var def7;
|
|
2092
|
+
var init_vector = __esm({
|
|
2093
|
+
"src/core/scene/kinds/vector.ts"() {
|
|
2094
|
+
init_registry();
|
|
2095
|
+
init_labelOf();
|
|
2096
|
+
def7 = {
|
|
2097
|
+
type: "vector",
|
|
2098
|
+
schemaVersion: 1,
|
|
2099
|
+
migrate: {},
|
|
2100
|
+
validate: (a) => {
|
|
2101
|
+
if (!a?.from || !a?.to) throw new Error("vector: from v\xE0 to b\u1EAFt bu\u1ED9c");
|
|
2102
|
+
},
|
|
2103
|
+
dependsOn: (a) => [a.from, a.to],
|
|
2104
|
+
describe: (obj, state) => `Vector ${labelOf(obj.attrs.from, state)}${labelOf(obj.attrs.to, state)}`,
|
|
2105
|
+
render: (obj, ctx) => {
|
|
2106
|
+
const board = ctx.jxg;
|
|
2107
|
+
const f = ctx.resolveRef(obj.attrs.from);
|
|
2108
|
+
const t = ctx.resolveRef(obj.attrs.to);
|
|
2109
|
+
return board.create("arrow", [f, t], {
|
|
2110
|
+
name: obj.label,
|
|
2111
|
+
strokeColor: obj.attrs.color ?? "#0f172a",
|
|
2112
|
+
strokeWidth: obj.attrs.width ?? 2,
|
|
2113
|
+
visible: obj.visible,
|
|
2114
|
+
fixed: obj.locked
|
|
2115
|
+
});
|
|
2116
|
+
}
|
|
2117
|
+
};
|
|
2118
|
+
registerKind(def7);
|
|
2119
|
+
}
|
|
2120
|
+
});
|
|
2121
|
+
|
|
2122
|
+
// src/core/scene/kinds/circle.ts
|
|
2123
|
+
function constructionRefs2(c) {
|
|
2124
|
+
switch (c.kind) {
|
|
2125
|
+
case "circumscribed":
|
|
2126
|
+
return [c.p1, c.p2, c.p3];
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
var def8;
|
|
2130
|
+
var init_circle = __esm({
|
|
2131
|
+
"src/core/scene/kinds/circle.ts"() {
|
|
2132
|
+
init_registry();
|
|
2133
|
+
init_labelOf();
|
|
2134
|
+
def8 = {
|
|
2135
|
+
type: "circle",
|
|
2136
|
+
schemaVersion: 1,
|
|
2137
|
+
migrate: {},
|
|
2138
|
+
validate: (a) => {
|
|
2139
|
+
if (a?.construction) return;
|
|
2140
|
+
if (!a?.center || !a?.surfacePoint) {
|
|
2141
|
+
throw new Error("circle: center v\xE0 surfacePoint b\u1EAFt bu\u1ED9c (ho\u1EB7c construction)");
|
|
2142
|
+
}
|
|
2143
|
+
},
|
|
2144
|
+
dependsOn: (a) => a.construction ? constructionRefs2(a.construction) : [a.center, a.surfacePoint],
|
|
2145
|
+
measure: (obj, state) => {
|
|
2146
|
+
if (obj.attrs.construction) return null;
|
|
2147
|
+
const center = obj.attrs.center ? state.objects[obj.attrs.center] : void 0;
|
|
2148
|
+
const surface = obj.attrs.surfacePoint ? state.objects[obj.attrs.surfacePoint] : void 0;
|
|
2149
|
+
if (!center || !surface) return null;
|
|
2150
|
+
const c1 = center.attrs.constraint;
|
|
2151
|
+
const c2 = surface.attrs.constraint;
|
|
2152
|
+
if (c1?.kind !== "free" || c2?.kind !== "free") return null;
|
|
2153
|
+
const dx = (c2.x ?? 0) - (c1.x ?? 0);
|
|
2154
|
+
const dy = (c2.y ?? 0) - (c1.y ?? 0);
|
|
2155
|
+
return [{ label: "r", value: Math.hypot(dx, dy) }];
|
|
2156
|
+
},
|
|
2157
|
+
describe: (obj, state) => {
|
|
2158
|
+
const L = (id) => labelOf(id, state);
|
|
2159
|
+
const c = obj.attrs.construction;
|
|
2160
|
+
if (c?.kind === "circumscribed") {
|
|
2161
|
+
return `\u0110\u01B0\u1EDDng tr\xF2n \u0111i qua ${L(c.p1)}${L(c.p2)}${L(c.p3)}`;
|
|
2162
|
+
}
|
|
2163
|
+
return `\u0110\u01B0\u1EDDng tr\xF2n t\xE2m ${L(obj.attrs.center)} b\xE1n k\xEDnh ${L(obj.attrs.center)}${L(obj.attrs.surfacePoint)}`;
|
|
2164
|
+
},
|
|
2165
|
+
render: (obj, ctx) => {
|
|
2166
|
+
const board = ctx.jxg;
|
|
2167
|
+
const baseOpts = {
|
|
2168
|
+
name: obj.label,
|
|
2169
|
+
withLabel: obj.attrs.showLabel ?? false,
|
|
2170
|
+
strokeColor: obj.attrs.color ?? "#0f172a",
|
|
2171
|
+
strokeWidth: obj.attrs.width ?? 2,
|
|
2172
|
+
dash: obj.attrs.dash ?? 0,
|
|
2173
|
+
fillColor: "none",
|
|
2174
|
+
visible: obj.visible,
|
|
2175
|
+
fixed: obj.locked
|
|
2176
|
+
};
|
|
2177
|
+
const c = obj.attrs.construction;
|
|
2178
|
+
if (c?.kind === "circumscribed") {
|
|
2179
|
+
const p1 = ctx.resolveRef(c.p1);
|
|
2180
|
+
const p2 = ctx.resolveRef(c.p2);
|
|
2181
|
+
const p3 = ctx.resolveRef(c.p3);
|
|
2182
|
+
return board.create("circumcircle", [p1, p2, p3], baseOpts);
|
|
2183
|
+
}
|
|
2184
|
+
const center = ctx.resolveRef(obj.attrs.center);
|
|
2185
|
+
const surface = ctx.resolveRef(obj.attrs.surfacePoint);
|
|
2186
|
+
return board.create("circle", [center, surface], baseOpts);
|
|
2187
|
+
}
|
|
2188
|
+
};
|
|
2189
|
+
registerKind(def8);
|
|
2190
|
+
}
|
|
2191
|
+
});
|
|
2192
|
+
|
|
2193
|
+
// src/core/scene/kinds/arc.ts
|
|
2194
|
+
function constructionRefs3(c) {
|
|
2195
|
+
switch (c.kind) {
|
|
2196
|
+
case "semicircle":
|
|
2197
|
+
return [c.p1, c.p2];
|
|
2198
|
+
case "byCenter":
|
|
2199
|
+
return [c.center, c.p1, c.p2];
|
|
2200
|
+
case "by3Points":
|
|
2201
|
+
return [c.p1, c.p2, c.p3];
|
|
2202
|
+
}
|
|
2203
|
+
}
|
|
2204
|
+
var def9;
|
|
2205
|
+
var init_arc = __esm({
|
|
2206
|
+
"src/core/scene/kinds/arc.ts"() {
|
|
2207
|
+
init_registry();
|
|
2208
|
+
init_labelOf();
|
|
2209
|
+
def9 = {
|
|
2210
|
+
type: "arc",
|
|
2211
|
+
schemaVersion: 1,
|
|
2212
|
+
migrate: {},
|
|
2213
|
+
validate: (a) => {
|
|
2214
|
+
const c = a?.construction;
|
|
2215
|
+
if (!c) throw new Error("arc: construction b\u1EAFt bu\u1ED9c");
|
|
2216
|
+
if (c.kind === "semicircle") {
|
|
2217
|
+
if (!c.p1 || !c.p2) throw new Error("arc.semicircle: p1, p2 b\u1EAFt bu\u1ED9c");
|
|
2218
|
+
} else if (c.kind === "byCenter") {
|
|
2219
|
+
if (!c.center || !c.p1 || !c.p2) throw new Error("arc.byCenter: center, p1, p2 b\u1EAFt bu\u1ED9c");
|
|
2220
|
+
} else if (c.kind === "by3Points") {
|
|
2221
|
+
if (!c.p1 || !c.p2 || !c.p3) throw new Error("arc.by3Points: p1, p2, p3 b\u1EAFt bu\u1ED9c");
|
|
2222
|
+
}
|
|
2223
|
+
},
|
|
2224
|
+
dependsOn: (a) => constructionRefs3(a.construction),
|
|
2225
|
+
describe: (obj, state) => {
|
|
2226
|
+
const L = (id) => labelOf(id, state);
|
|
2227
|
+
const c = obj.attrs.construction;
|
|
2228
|
+
switch (c.kind) {
|
|
2229
|
+
case "semicircle":
|
|
2230
|
+
return `N\u1EEDa \u0111\u01B0\u1EDDng tr\xF2n \u0111\u01B0\u1EDDng k\xEDnh ${L(c.p1)}${L(c.p2)}`;
|
|
2231
|
+
case "byCenter":
|
|
2232
|
+
return `Cung tr\xF2n t\xE2m ${L(c.center)} t\u1EEB ${L(c.p1)} \u0111\u1EBFn ${L(c.p2)}`;
|
|
2233
|
+
case "by3Points":
|
|
2234
|
+
return `Cung tr\xF2n qua ${L(c.p1)}${L(c.p2)}${L(c.p3)}`;
|
|
2235
|
+
}
|
|
2236
|
+
},
|
|
2237
|
+
render: (obj, ctx) => {
|
|
2238
|
+
const board = ctx.jxg;
|
|
2239
|
+
const baseOpts = {
|
|
2240
|
+
name: obj.label,
|
|
2241
|
+
withLabel: obj.attrs.showLabel ?? false,
|
|
2242
|
+
strokeColor: obj.attrs.color ?? "#0f172a",
|
|
2243
|
+
strokeWidth: obj.attrs.width ?? 2,
|
|
2244
|
+
dash: obj.attrs.dash ?? 0,
|
|
2245
|
+
fillColor: "none",
|
|
2246
|
+
visible: obj.visible,
|
|
2247
|
+
fixed: obj.locked
|
|
2248
|
+
};
|
|
2249
|
+
const c = obj.attrs.construction;
|
|
2250
|
+
if (c.kind === "semicircle") {
|
|
2251
|
+
const p1 = ctx.resolveRef(c.p1);
|
|
2252
|
+
const p2 = ctx.resolveRef(c.p2);
|
|
2253
|
+
return board.create("semicircle", [p1, p2], baseOpts);
|
|
2254
|
+
}
|
|
2255
|
+
if (c.kind === "byCenter") {
|
|
2256
|
+
const O = ctx.resolveRef(c.center);
|
|
2257
|
+
const A2 = ctx.resolveRef(c.p1);
|
|
2258
|
+
const B2 = ctx.resolveRef(c.p2);
|
|
2259
|
+
return board.create("arc", [O, A2, B2], baseOpts);
|
|
2260
|
+
}
|
|
2261
|
+
const A = ctx.resolveRef(c.p1);
|
|
2262
|
+
const B = ctx.resolveRef(c.p2);
|
|
2263
|
+
const C = ctx.resolveRef(c.p3);
|
|
2264
|
+
return board.create("circumcirclearc", [A, B, C], baseOpts);
|
|
2265
|
+
}
|
|
2266
|
+
};
|
|
2267
|
+
registerKind(def9);
|
|
2268
|
+
}
|
|
2269
|
+
});
|
|
2270
|
+
|
|
2271
|
+
// src/core/scene/kinds/sector.ts
|
|
2272
|
+
var def10;
|
|
2273
|
+
var init_sector = __esm({
|
|
2274
|
+
"src/core/scene/kinds/sector.ts"() {
|
|
2275
|
+
init_registry();
|
|
2276
|
+
init_labelOf();
|
|
2277
|
+
def10 = {
|
|
2278
|
+
type: "sector",
|
|
2279
|
+
schemaVersion: 1,
|
|
2280
|
+
migrate: {},
|
|
2281
|
+
validate: (a) => {
|
|
2282
|
+
const c = a?.construction;
|
|
2283
|
+
if (!c) throw new Error("sector: construction b\u1EAFt bu\u1ED9c");
|
|
2284
|
+
if (c.kind === "byCenter") {
|
|
2285
|
+
if (!c.center || !c.p1 || !c.p2) {
|
|
2286
|
+
throw new Error("sector.byCenter: center, p1, p2 b\u1EAFt bu\u1ED9c");
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
},
|
|
2290
|
+
dependsOn: (a) => {
|
|
2291
|
+
const c = a.construction;
|
|
2292
|
+
return [c.center, c.p1, c.p2];
|
|
2293
|
+
},
|
|
2294
|
+
describe: (obj, state) => {
|
|
2295
|
+
const L = (id) => labelOf(id, state);
|
|
2296
|
+
const c = obj.attrs.construction;
|
|
2297
|
+
return `H\xECnh qu\u1EA1t t\xE2m ${L(c.center)} t\u1EEB ${L(c.p1)} \u0111\u1EBFn ${L(c.p2)}`;
|
|
2298
|
+
},
|
|
2299
|
+
render: (obj, ctx) => {
|
|
2300
|
+
const board = ctx.jxg;
|
|
2301
|
+
const c = obj.attrs.construction;
|
|
2302
|
+
const O = ctx.resolveRef(c.center);
|
|
2303
|
+
const A = ctx.resolveRef(c.p1);
|
|
2304
|
+
const B = ctx.resolveRef(c.p2);
|
|
2305
|
+
return board.create("sector", [O, A, B], {
|
|
2306
|
+
name: obj.label,
|
|
2307
|
+
withLabel: obj.attrs.showLabel ?? false,
|
|
2308
|
+
strokeColor: obj.attrs.color ?? "#0f172a",
|
|
2309
|
+
strokeWidth: obj.attrs.width ?? 2,
|
|
2310
|
+
fillColor: obj.attrs.fillColor ?? "#f59e0b",
|
|
2311
|
+
fillOpacity: obj.attrs.fillOpacity ?? 0.18,
|
|
2312
|
+
visible: obj.visible,
|
|
2313
|
+
fixed: obj.locked
|
|
2314
|
+
});
|
|
2315
|
+
}
|
|
2316
|
+
};
|
|
2317
|
+
registerKind(def10);
|
|
2318
|
+
}
|
|
2319
|
+
});
|
|
2320
|
+
|
|
2321
|
+
// src/core/scene/kinds/polygon.ts
|
|
2322
|
+
function regularPolygonName(n) {
|
|
2323
|
+
if (n === 3) return "Tam gi\xE1c \u0111\u1EC1u";
|
|
2324
|
+
if (n === 4) return "H\xECnh vu\xF4ng";
|
|
2325
|
+
if (n === 5) return "Ng\u0169 gi\xE1c \u0111\u1EC1u";
|
|
2326
|
+
if (n === 6) return "L\u1EE5c gi\xE1c \u0111\u1EC1u";
|
|
2327
|
+
return `${n}-gi\xE1c \u0111\u1EC1u`;
|
|
2328
|
+
}
|
|
2329
|
+
function regularVertexLabels(p1Label, p2Label, n) {
|
|
2330
|
+
const A = "A".charCodeAt(0);
|
|
2331
|
+
const Z = "Z".charCodeAt(0);
|
|
2332
|
+
if (p1Label.length === 1 && p2Label.length === 1) {
|
|
2333
|
+
const c1 = p1Label.charCodeAt(0);
|
|
2334
|
+
const c2 = p2Label.charCodeAt(0);
|
|
2335
|
+
if (c1 >= A && c1 <= Z && c2 === c1 + 1 && c1 + n - 1 <= Z) {
|
|
2336
|
+
let out = "";
|
|
2337
|
+
for (let i = 0; i < n; i++) out += String.fromCharCode(c1 + i);
|
|
2338
|
+
return out;
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
return `${p1Label}${p2Label}\u2026`;
|
|
2342
|
+
}
|
|
2343
|
+
var def11;
|
|
2344
|
+
var init_polygon = __esm({
|
|
2345
|
+
"src/core/scene/kinds/polygon.ts"() {
|
|
2346
|
+
init_registry();
|
|
2347
|
+
init_labelOf();
|
|
2348
|
+
def11 = {
|
|
2349
|
+
type: "polygon",
|
|
2350
|
+
schemaVersion: 1,
|
|
2351
|
+
migrate: {},
|
|
2352
|
+
validate: (a) => {
|
|
2353
|
+
if (a?.construction) {
|
|
2354
|
+
if (a.construction.kind === "regular") {
|
|
2355
|
+
if (!a.construction.p1 || !a.construction.p2) {
|
|
2356
|
+
throw new Error("polygon (regular): p1 v\xE0 p2 b\u1EAFt bu\u1ED9c");
|
|
2357
|
+
}
|
|
2358
|
+
if (!Number.isFinite(a.construction.n) || a.construction.n < 3) {
|
|
2359
|
+
throw new Error("polygon (regular): n \u2265 3");
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
return;
|
|
2363
|
+
}
|
|
2364
|
+
if (!Array.isArray(a?.vertices) || a.vertices.length < 3) {
|
|
2365
|
+
throw new Error("polygon: c\u1EA7n \xEDt nh\u1EA5t 3 \u0111\u1EC9nh");
|
|
2366
|
+
}
|
|
2367
|
+
},
|
|
2368
|
+
dependsOn: (a) => {
|
|
2369
|
+
if (a.construction?.kind === "regular") return [a.construction.p1, a.construction.p2];
|
|
2370
|
+
return [...a.vertices ?? []];
|
|
2371
|
+
},
|
|
2372
|
+
describe: (obj, state) => {
|
|
2373
|
+
if (obj.attrs.construction?.kind === "regular") {
|
|
2374
|
+
const c = obj.attrs.construction;
|
|
2375
|
+
const labels = regularVertexLabels(labelOf(c.p1, state), labelOf(c.p2, state), c.n);
|
|
2376
|
+
return `${regularPolygonName(c.n)} ${labels}`;
|
|
2377
|
+
}
|
|
2378
|
+
return `\u0110a gi\xE1c ${(obj.attrs.vertices ?? []).map((id) => labelOf(id, state)).join("")}`;
|
|
2379
|
+
},
|
|
2380
|
+
render: (obj, ctx) => {
|
|
2381
|
+
const board = ctx.jxg;
|
|
2382
|
+
const label = obj.label;
|
|
2383
|
+
const showValue = obj.attrs.showValue ?? false;
|
|
2384
|
+
if (obj.attrs.construction?.kind === "regular") {
|
|
2385
|
+
const c = obj.attrs.construction;
|
|
2386
|
+
const p1 = ctx.resolveRef(c.p1);
|
|
2387
|
+
const p2 = ctx.resolveRef(c.p2);
|
|
2388
|
+
return board.create("regularpolygon", [p1, p2, c.n], {
|
|
2389
|
+
name: label,
|
|
2390
|
+
withLabel: obj.attrs.showLabel ?? false,
|
|
2391
|
+
borders: {
|
|
2392
|
+
strokeColor: obj.attrs.color ?? "#0f172a",
|
|
2393
|
+
strokeWidth: obj.attrs.width ?? 2
|
|
2394
|
+
},
|
|
2395
|
+
fillColor: obj.attrs.color ?? "#60a5fa",
|
|
2396
|
+
fillOpacity: obj.attrs.fillOpacity ?? 0.15,
|
|
2397
|
+
visible: obj.visible,
|
|
2398
|
+
fixed: obj.locked
|
|
2399
|
+
});
|
|
2400
|
+
}
|
|
2401
|
+
const verts = (obj.attrs.vertices ?? []).map((id) => ctx.resolveRef(id));
|
|
2402
|
+
const poly = board.create("polygon", verts, {
|
|
2403
|
+
name: showValue ? function() {
|
|
2404
|
+
const a = typeof this.Area === "function" ? this.Area() : 0;
|
|
2405
|
+
const prefix = obj.attrs.showLabel ?? true ? `${label}: ` : "";
|
|
2406
|
+
return `${prefix}S = ${Math.abs(a).toFixed(2)}`;
|
|
2407
|
+
} : label,
|
|
2408
|
+
withLabel: showValue ? true : obj.attrs.showLabel ?? false,
|
|
2409
|
+
borders: {
|
|
2410
|
+
strokeColor: obj.attrs.color ?? "#0f172a",
|
|
2411
|
+
strokeWidth: obj.attrs.width ?? 2
|
|
2412
|
+
},
|
|
2413
|
+
fillColor: obj.attrs.color ?? "#60a5fa",
|
|
2414
|
+
fillOpacity: obj.attrs.fillOpacity ?? 0.15,
|
|
2415
|
+
visible: obj.visible,
|
|
2416
|
+
fixed: obj.locked
|
|
2417
|
+
});
|
|
2418
|
+
return poly;
|
|
2419
|
+
}
|
|
2420
|
+
};
|
|
2421
|
+
registerKind(def11);
|
|
2422
|
+
}
|
|
2423
|
+
});
|
|
2424
|
+
|
|
2425
|
+
// src/core/scene/kinds/intersection.ts
|
|
2426
|
+
var def12;
|
|
2427
|
+
var init_intersection = __esm({
|
|
2428
|
+
"src/core/scene/kinds/intersection.ts"() {
|
|
2429
|
+
init_registry();
|
|
2430
|
+
def12 = {
|
|
2431
|
+
type: "intersection",
|
|
2432
|
+
schemaVersion: 1,
|
|
2433
|
+
migrate: {},
|
|
2434
|
+
validate: (a) => {
|
|
2435
|
+
if (!a || !("kind" in a)) throw new Error("intersection: kind b\u1EAFt bu\u1ED9c");
|
|
2436
|
+
if (!a.ref1 || !a.ref2) throw new Error("intersection: ref1 v\xE0 ref2 b\u1EAFt bu\u1ED9c");
|
|
2437
|
+
if (a.kind === "lineLine") return;
|
|
2438
|
+
if (a.kind === "lineCircle" || a.kind === "circleCircle") {
|
|
2439
|
+
if (a.branch !== 0 && a.branch !== 1) {
|
|
2440
|
+
throw new Error(`intersection.${a.kind}: branch ph\u1EA3i l\xE0 0 ho\u1EB7c 1`);
|
|
2441
|
+
}
|
|
2442
|
+
return;
|
|
2443
|
+
}
|
|
2444
|
+
throw new Error(`intersection: kind kh\xF4ng h\u1EE3p l\u1EC7 "${a.kind}"`);
|
|
2445
|
+
},
|
|
2446
|
+
dependsOn: (a) => [a.ref1, a.ref2],
|
|
2447
|
+
describe: (obj) => {
|
|
2448
|
+
const a = obj.attrs;
|
|
2449
|
+
return `${obj.label} = giao ${a.ref1} \u2229 ${a.ref2}`;
|
|
2450
|
+
},
|
|
2451
|
+
render: (obj, ctx) => {
|
|
2452
|
+
const board = ctx.jxg;
|
|
2453
|
+
const a = ctx.resolveRef(obj.attrs.ref1);
|
|
2454
|
+
const b = ctx.resolveRef(obj.attrs.ref2);
|
|
2455
|
+
const opts = {
|
|
2456
|
+
name: obj.label,
|
|
2457
|
+
withLabel: true,
|
|
2458
|
+
strokeColor: obj.attrs.color ?? "#dc2626",
|
|
2459
|
+
fillColor: obj.attrs.color ?? "#dc2626",
|
|
2460
|
+
visible: obj.visible,
|
|
2461
|
+
fixed: obj.locked
|
|
2462
|
+
};
|
|
2463
|
+
if (obj.attrs.kind === "lineLine") {
|
|
2464
|
+
return board.create("intersection", [a, b, 0], opts);
|
|
2465
|
+
}
|
|
2466
|
+
const branch = obj.attrs.branch ?? 0;
|
|
2467
|
+
return board.create("intersection", [a, b, branch], opts);
|
|
2468
|
+
}
|
|
2469
|
+
};
|
|
2470
|
+
registerKind(def12);
|
|
2471
|
+
}
|
|
2472
|
+
});
|
|
2473
|
+
|
|
2474
|
+
// src/core/scene/kinds/angle.ts
|
|
2475
|
+
var def13;
|
|
2476
|
+
var init_angle = __esm({
|
|
2477
|
+
"src/core/scene/kinds/angle.ts"() {
|
|
2478
|
+
init_registry();
|
|
2479
|
+
init_labelOf();
|
|
2480
|
+
def13 = {
|
|
2481
|
+
type: "angle",
|
|
2482
|
+
schemaVersion: 1,
|
|
2483
|
+
migrate: {},
|
|
2484
|
+
validate: (a) => {
|
|
2485
|
+
if (!a?.p1 || !a?.vertex || !a?.p2) {
|
|
2486
|
+
throw new Error("angle: p1, vertex, p2 b\u1EAFt bu\u1ED9c");
|
|
2487
|
+
}
|
|
2488
|
+
},
|
|
2489
|
+
dependsOn: (a) => [a.p1, a.vertex, a.p2],
|
|
2490
|
+
describe: (obj, state) => `G\xF3c ${labelOf(obj.attrs.p1, state)}${labelOf(obj.attrs.vertex, state)}${labelOf(obj.attrs.p2, state)}`,
|
|
2491
|
+
render: (obj, ctx) => {
|
|
2492
|
+
const board = ctx.jxg;
|
|
2493
|
+
const pa = ctx.resolveRef(obj.attrs.p1);
|
|
2494
|
+
const pv = ctx.resolveRef(obj.attrs.vertex);
|
|
2495
|
+
const pc = ctx.resolveRef(obj.attrs.p2);
|
|
2496
|
+
let parents = [pa, pv, pc];
|
|
2497
|
+
try {
|
|
2498
|
+
const ax = pa.X() - pv.X(), ay = pa.Y() - pv.Y();
|
|
2499
|
+
const cx = pc.X() - pv.X(), cy = pc.Y() - pv.Y();
|
|
2500
|
+
if (ax * cy - ay * cx < 0) parents = [pc, pv, pa];
|
|
2501
|
+
} catch {
|
|
2502
|
+
}
|
|
2503
|
+
return board.create("angle", parents, {
|
|
2504
|
+
name: obj.label,
|
|
2505
|
+
withLabel: obj.attrs.showLabel ?? true,
|
|
2506
|
+
radius: obj.attrs.radius ?? 1,
|
|
2507
|
+
fillColor: obj.attrs.color ?? "#22c55e",
|
|
2508
|
+
fillOpacity: obj.attrs.fillOpacity ?? 0.25,
|
|
2509
|
+
strokeColor: obj.attrs.color ?? "#16a34a",
|
|
2510
|
+
strokeWidth: 1.5,
|
|
2511
|
+
visible: obj.visible,
|
|
2512
|
+
fixed: obj.locked
|
|
2513
|
+
});
|
|
2514
|
+
}
|
|
2515
|
+
};
|
|
2516
|
+
registerKind(def13);
|
|
2517
|
+
}
|
|
2518
|
+
});
|
|
2519
|
+
|
|
2520
|
+
// src/core/scene/kinds/distance.ts
|
|
2521
|
+
var def14;
|
|
2522
|
+
var init_distance = __esm({
|
|
2523
|
+
"src/core/scene/kinds/distance.ts"() {
|
|
2524
|
+
init_registry();
|
|
2525
|
+
init_labelOf();
|
|
2526
|
+
def14 = {
|
|
2527
|
+
type: "distance",
|
|
2528
|
+
schemaVersion: 1,
|
|
2529
|
+
migrate: {},
|
|
2530
|
+
validate: (a) => {
|
|
2531
|
+
if (!a?.p1 || !a?.p2) throw new Error("distance: p1 v\xE0 p2 b\u1EAFt bu\u1ED9c");
|
|
2532
|
+
},
|
|
2533
|
+
dependsOn: (a) => [a.p1, a.p2],
|
|
2534
|
+
describe: (obj, state) => `Kho\u1EA3ng c\xE1ch ${labelOf(obj.attrs.p1, state)}${labelOf(obj.attrs.p2, state)}`,
|
|
2535
|
+
render: (obj, ctx) => {
|
|
2536
|
+
const board = ctx.jxg;
|
|
2537
|
+
const p1 = ctx.resolveRef(obj.attrs.p1);
|
|
2538
|
+
const p2 = ctx.resolveRef(obj.attrs.p2);
|
|
2539
|
+
const prefix = obj.attrs.prefix ?? "d = ";
|
|
2540
|
+
const precision = obj.attrs.precision ?? 2;
|
|
2541
|
+
return board.create("text", [
|
|
2542
|
+
() => (p1.X() + p2.X()) / 2,
|
|
2543
|
+
() => (p1.Y() + p2.Y()) / 2,
|
|
2544
|
+
() => `${prefix}${Math.hypot(p1.X() - p2.X(), p1.Y() - p2.Y()).toFixed(precision)}`
|
|
2545
|
+
], {
|
|
2546
|
+
fontSize: obj.attrs.fontSize ?? 14,
|
|
2547
|
+
strokeColor: obj.attrs.color ?? "#dc2626",
|
|
2548
|
+
anchorX: "middle",
|
|
2549
|
+
anchorY: "middle",
|
|
2550
|
+
visible: obj.visible,
|
|
2551
|
+
fixed: true
|
|
2552
|
+
});
|
|
2553
|
+
}
|
|
2554
|
+
};
|
|
2555
|
+
registerKind(def14);
|
|
2556
|
+
}
|
|
2557
|
+
});
|
|
2558
|
+
|
|
2559
|
+
// src/core/scene/kinds/function2d.ts
|
|
2560
|
+
var def15;
|
|
2561
|
+
var init_function2d = __esm({
|
|
2562
|
+
"src/core/scene/kinds/function2d.ts"() {
|
|
2563
|
+
init_registry();
|
|
2564
|
+
init_parser();
|
|
2565
|
+
def15 = {
|
|
2566
|
+
type: "function2d",
|
|
2567
|
+
schemaVersion: 1,
|
|
2568
|
+
migrate: {},
|
|
2569
|
+
validate: (a) => {
|
|
2570
|
+
if (!a) throw new Error("function2d: attrs b\u1EAFt bu\u1ED9c");
|
|
2571
|
+
if (typeof a.expression !== "string" || !a.expression.trim()) {
|
|
2572
|
+
throw new Error("function2d: expression r\u1ED7ng");
|
|
2573
|
+
}
|
|
2574
|
+
const v = validate(a.expression);
|
|
2575
|
+
if (!v.ok) throw new Error(`function2d: expression invalid \u2014 ${v.error}`);
|
|
2576
|
+
if (typeof a.color !== "string") throw new Error("function2d: color b\u1EAFt bu\u1ED9c");
|
|
2577
|
+
if (typeof a.visible !== "boolean") throw new Error("function2d: visible b\u1EAFt bu\u1ED9c");
|
|
2578
|
+
if (a.domain) {
|
|
2579
|
+
if (a.domain.min >= a.domain.max) {
|
|
2580
|
+
throw new Error("function2d: domain min ph\u1EA3i < max");
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
},
|
|
2584
|
+
dependsOn: () => [],
|
|
2585
|
+
describe: (obj) => `${obj.label}(x) = ${obj.attrs.expression}`,
|
|
2586
|
+
render: (obj, ctx) => {
|
|
2587
|
+
const board = ctx.jxg;
|
|
2588
|
+
if (!obj.visible || !obj.attrs.visible) return null;
|
|
2589
|
+
const fn = compile(obj.attrs.expression, ctx.paramMap ?? {});
|
|
2590
|
+
if (typeof fn !== "function") return null;
|
|
2591
|
+
const view = ctx.defaults.view;
|
|
2592
|
+
const xMin = obj.attrs.domain?.min ?? view?.xMin ?? -10;
|
|
2593
|
+
const xMax = obj.attrs.domain?.max ?? view?.xMax ?? 10;
|
|
2594
|
+
return board.create("functiongraph", [fn, xMin, xMax], {
|
|
2595
|
+
strokeColor: obj.attrs.color,
|
|
2596
|
+
strokeWidth: 2,
|
|
2597
|
+
name: obj.label,
|
|
2598
|
+
withLabel: false,
|
|
2599
|
+
highlight: false,
|
|
2600
|
+
fixed: true
|
|
2601
|
+
});
|
|
2602
|
+
}
|
|
2603
|
+
};
|
|
2604
|
+
registerKind(def15);
|
|
2605
|
+
}
|
|
2606
|
+
});
|
|
2607
|
+
|
|
2608
|
+
// src/core/scene/kinds/parameter.ts
|
|
2609
|
+
var def16;
|
|
2610
|
+
var init_parameter = __esm({
|
|
2611
|
+
"src/core/scene/kinds/parameter.ts"() {
|
|
2612
|
+
init_registry();
|
|
2613
|
+
def16 = {
|
|
2614
|
+
type: "parameter",
|
|
2615
|
+
schemaVersion: 1,
|
|
2616
|
+
migrate: {},
|
|
2617
|
+
validate: (a) => {
|
|
2618
|
+
if (!a) throw new Error("parameter: attrs b\u1EAFt bu\u1ED9c");
|
|
2619
|
+
if (typeof a.value !== "number" || typeof a.min !== "number" || typeof a.max !== "number") {
|
|
2620
|
+
throw new Error("parameter: value/min/max ph\u1EA3i l\xE0 number");
|
|
2621
|
+
}
|
|
2622
|
+
if (a.min >= a.max) throw new Error("parameter: min ph\u1EA3i < max");
|
|
2623
|
+
if (a.value < a.min || a.value > a.max) throw new Error("parameter: value ngo\xE0i [min, max]");
|
|
2624
|
+
if (typeof a.step !== "number" || a.step <= 0) throw new Error("parameter: step ph\u1EA3i > 0");
|
|
2625
|
+
},
|
|
2626
|
+
dependsOn: () => [],
|
|
2627
|
+
describe: (obj) => `${obj.label} = ${obj.attrs.value}`,
|
|
2628
|
+
render: () => null
|
|
2629
|
+
// Không render lên board
|
|
2630
|
+
};
|
|
2631
|
+
registerKind(def16);
|
|
2632
|
+
}
|
|
2633
|
+
});
|
|
2634
|
+
|
|
2635
|
+
// src/core/scene/kinds/pointOnCurve.ts
|
|
2636
|
+
var def17;
|
|
2637
|
+
var init_pointOnCurve = __esm({
|
|
2638
|
+
"src/core/scene/kinds/pointOnCurve.ts"() {
|
|
2639
|
+
init_registry();
|
|
2640
|
+
def17 = {
|
|
2641
|
+
type: "pointOnCurve",
|
|
2642
|
+
schemaVersion: 1,
|
|
2643
|
+
migrate: {},
|
|
2644
|
+
validate: (a) => {
|
|
2645
|
+
if (!a || typeof a.functionId !== "string" || !a.functionId) {
|
|
2646
|
+
throw new Error("pointOnCurve: functionId b\u1EAFt bu\u1ED9c");
|
|
2647
|
+
}
|
|
2648
|
+
if (typeof a.x !== "number" || !Number.isFinite(a.x)) {
|
|
2649
|
+
throw new Error("pointOnCurve: x ph\u1EA3i l\xE0 finite number");
|
|
2650
|
+
}
|
|
2651
|
+
},
|
|
2652
|
+
dependsOn: (a) => [a.functionId],
|
|
2653
|
+
describe: (obj) => `${obj.label} tr\xEAn ${obj.attrs.functionId} t\u1EA1i x=${obj.attrs.x.toFixed(3)}`,
|
|
2654
|
+
render: (obj, ctx) => {
|
|
2655
|
+
const board = ctx.jxg;
|
|
2656
|
+
const curve = ctx.resolveRef(obj.attrs.functionId);
|
|
2657
|
+
if (!curve) return null;
|
|
2658
|
+
return board.create("glider", [obj.attrs.x, 0, curve], {
|
|
2659
|
+
name: obj.label,
|
|
2660
|
+
size: 3,
|
|
2661
|
+
withLabel: obj.label !== "",
|
|
2662
|
+
fillColor: "#000",
|
|
2663
|
+
strokeColor: "#000"
|
|
2664
|
+
});
|
|
2665
|
+
}
|
|
2666
|
+
};
|
|
2667
|
+
registerKind(def17);
|
|
2668
|
+
}
|
|
2669
|
+
});
|
|
2670
|
+
|
|
2671
|
+
// src/core/scene/kinds/tangent2d.ts
|
|
2672
|
+
var def18;
|
|
2673
|
+
var init_tangent2d = __esm({
|
|
2674
|
+
"src/core/scene/kinds/tangent2d.ts"() {
|
|
2675
|
+
init_registry();
|
|
2676
|
+
def18 = {
|
|
2677
|
+
type: "tangent2d",
|
|
2678
|
+
schemaVersion: 1,
|
|
2679
|
+
migrate: {},
|
|
2680
|
+
validate: (a) => {
|
|
2681
|
+
if (!a || typeof a.pointId !== "string" || !a.pointId) {
|
|
2682
|
+
throw new Error("tangent2d: pointId b\u1EAFt bu\u1ED9c");
|
|
2683
|
+
}
|
|
2684
|
+
},
|
|
2685
|
+
dependsOn: (a) => [a.pointId],
|
|
2686
|
+
describe: (obj) => `Ti\u1EBFp tuy\u1EBFn t\u1EA1i ${obj.attrs.pointId}`,
|
|
2687
|
+
render: (obj, ctx) => {
|
|
2688
|
+
const board = ctx.jxg;
|
|
2689
|
+
const pt = ctx.resolveRef(obj.attrs.pointId);
|
|
2690
|
+
if (!pt) return null;
|
|
2691
|
+
return board.create("tangent", [pt], {
|
|
2692
|
+
strokeColor: "#65a30d",
|
|
2693
|
+
strokeWidth: 1.5,
|
|
2694
|
+
dash: 2,
|
|
2695
|
+
withLabel: false
|
|
2696
|
+
});
|
|
2697
|
+
}
|
|
2698
|
+
};
|
|
2699
|
+
registerKind(def18);
|
|
2700
|
+
}
|
|
2701
|
+
});
|
|
2702
|
+
|
|
2703
|
+
// src/core/scene/expressions/evaluator.ts
|
|
2704
|
+
function scanRoots(fn, xMin, xMax, samples = DEFAULT_SAMPLES) {
|
|
2705
|
+
if (!Number.isFinite(xMin) || !Number.isFinite(xMax) || xMin >= xMax) return [];
|
|
2706
|
+
const out = [];
|
|
2707
|
+
const step = (xMax - xMin) / samples;
|
|
2708
|
+
let prev = fn(xMin);
|
|
2709
|
+
for (let i = 1; i <= samples; i++) {
|
|
2710
|
+
const x = xMin + i * step;
|
|
2711
|
+
const curr = fn(x);
|
|
2712
|
+
if (!Number.isFinite(prev) || !Number.isFinite(curr)) {
|
|
2713
|
+
prev = curr;
|
|
2714
|
+
continue;
|
|
2715
|
+
}
|
|
2716
|
+
if (prev * curr < 0) {
|
|
2717
|
+
const root = bisect(fn, x - step, x);
|
|
2718
|
+
if (Number.isFinite(root)) out.push(root);
|
|
2719
|
+
} else if (prev !== 0 && curr === 0) {
|
|
2720
|
+
out.push(x);
|
|
2721
|
+
}
|
|
2722
|
+
prev = curr;
|
|
2723
|
+
}
|
|
2724
|
+
return out;
|
|
2725
|
+
}
|
|
2726
|
+
function bisect(fn, lo, hi) {
|
|
2727
|
+
for (let i = 0; i < 50; i++) {
|
|
2728
|
+
const mid = (lo + hi) / 2;
|
|
2729
|
+
const fmid = fn(mid);
|
|
2730
|
+
if (!Number.isFinite(fmid)) break;
|
|
2731
|
+
if (Math.abs(fmid) < 1e-10) return mid;
|
|
2732
|
+
const flo = fn(lo);
|
|
2733
|
+
if (!Number.isFinite(flo)) break;
|
|
2734
|
+
if (flo * fmid <= 0) hi = mid;
|
|
2735
|
+
else lo = mid;
|
|
2736
|
+
}
|
|
2737
|
+
return (lo + hi) / 2;
|
|
2738
|
+
}
|
|
2739
|
+
function scanExtrema(fn, xMin, xMax, samples = DEFAULT_SAMPLES) {
|
|
2740
|
+
if (!Number.isFinite(xMin) || !Number.isFinite(xMax) || xMin >= xMax) return [];
|
|
2741
|
+
const out = [];
|
|
2742
|
+
const step = (xMax - xMin) / samples;
|
|
2743
|
+
const xs = [];
|
|
2744
|
+
const ys = [];
|
|
2745
|
+
for (let i = 0; i <= samples + 1; i++) {
|
|
2746
|
+
const x = xMin + (i - 1) * step;
|
|
2747
|
+
xs.push(x);
|
|
2748
|
+
ys.push(fn(x));
|
|
2749
|
+
}
|
|
2750
|
+
let prevSign = 0;
|
|
2751
|
+
let prevSignIdx = 1;
|
|
2752
|
+
for (let i = 1; i <= samples; i++) {
|
|
2753
|
+
const d = ys[i + 1] - ys[i - 1];
|
|
2754
|
+
if (!Number.isFinite(d)) continue;
|
|
2755
|
+
const sign = d > 0 ? 1 : d < 0 ? -1 : 0;
|
|
2756
|
+
if (sign === 0) continue;
|
|
2757
|
+
if (prevSign !== 0 && sign !== prevSign) {
|
|
2758
|
+
const type = prevSign > 0 ? "max" : "min";
|
|
2759
|
+
const midI = Math.round((prevSignIdx + i) / 2);
|
|
2760
|
+
out.push({ x: xs[midI], y: ys[midI], type });
|
|
2761
|
+
}
|
|
2762
|
+
prevSign = sign;
|
|
2763
|
+
prevSignIdx = i;
|
|
2764
|
+
}
|
|
2765
|
+
return out;
|
|
2766
|
+
}
|
|
2767
|
+
var DEFAULT_SAMPLES;
|
|
2768
|
+
var init_evaluator = __esm({
|
|
2769
|
+
"src/core/scene/expressions/evaluator.ts"() {
|
|
2770
|
+
DEFAULT_SAMPLES = 1e3;
|
|
2771
|
+
}
|
|
2772
|
+
});
|
|
2773
|
+
|
|
2774
|
+
// src/core/scene/kinds/extremum2d.ts
|
|
2775
|
+
var def19;
|
|
2776
|
+
var init_extremum2d = __esm({
|
|
2777
|
+
"src/core/scene/kinds/extremum2d.ts"() {
|
|
2778
|
+
init_registry();
|
|
2779
|
+
init_evaluator();
|
|
2780
|
+
init_parser();
|
|
2781
|
+
def19 = {
|
|
2782
|
+
type: "extremum2d",
|
|
2783
|
+
schemaVersion: 1,
|
|
2784
|
+
migrate: {},
|
|
2785
|
+
validate: (a) => {
|
|
2786
|
+
if (!a || typeof a.functionId !== "string" || !a.functionId) {
|
|
2787
|
+
throw new Error("extremum2d: functionId b\u1EAFt bu\u1ED9c");
|
|
2788
|
+
}
|
|
2789
|
+
if (!a.interval || a.interval.min >= a.interval.max) {
|
|
2790
|
+
throw new Error("extremum2d: interval min ph\u1EA3i < max");
|
|
2791
|
+
}
|
|
2792
|
+
if (a.mode !== "max" && a.mode !== "min") {
|
|
2793
|
+
throw new Error('extremum2d: mode ph\u1EA3i l\xE0 "max" ho\u1EB7c "min"');
|
|
2794
|
+
}
|
|
2795
|
+
},
|
|
2796
|
+
dependsOn: (a) => [a.functionId],
|
|
2797
|
+
describe: (obj) => `${obj.attrs.mode === "max" ? "C\u1EF1c \u0111\u1EA1i" : "C\u1EF1c ti\u1EC3u"} c\u1EE7a ${obj.attrs.functionId} trong [${obj.attrs.interval.min}, ${obj.attrs.interval.max}]`,
|
|
2798
|
+
render: (obj, ctx) => {
|
|
2799
|
+
const board = ctx.jxg;
|
|
2800
|
+
const expr = ctx.defaults._functionExpr?.[obj.attrs.functionId];
|
|
2801
|
+
if (!expr) return null;
|
|
2802
|
+
const fn = compile(expr, ctx.paramMap ?? {});
|
|
2803
|
+
if (typeof fn !== "function") return null;
|
|
2804
|
+
const extrema = scanExtrema(fn, obj.attrs.interval.min, obj.attrs.interval.max).filter((e) => e.type === obj.attrs.mode);
|
|
2805
|
+
return extrema.map((e) => board.create("point", [e.x, e.y], {
|
|
2806
|
+
name: obj.label,
|
|
2807
|
+
size: 3,
|
|
2808
|
+
fillColor: "#dc2626",
|
|
2809
|
+
strokeColor: "#dc2626",
|
|
2810
|
+
withLabel: obj.label !== ""
|
|
2811
|
+
}));
|
|
2812
|
+
}
|
|
2813
|
+
};
|
|
2814
|
+
registerKind(def19);
|
|
2815
|
+
}
|
|
2816
|
+
});
|
|
2817
|
+
|
|
2818
|
+
// src/core/scene/kinds/root2d.ts
|
|
2819
|
+
var def20;
|
|
2820
|
+
var init_root2d = __esm({
|
|
2821
|
+
"src/core/scene/kinds/root2d.ts"() {
|
|
2822
|
+
init_registry();
|
|
2823
|
+
init_evaluator();
|
|
2824
|
+
init_parser();
|
|
2825
|
+
def20 = {
|
|
2826
|
+
type: "root2d",
|
|
2827
|
+
schemaVersion: 1,
|
|
2828
|
+
migrate: {},
|
|
2829
|
+
validate: (a) => {
|
|
2830
|
+
if (!a || typeof a.functionId !== "string" || !a.functionId) {
|
|
2831
|
+
throw new Error("root2d: functionId b\u1EAFt bu\u1ED9c");
|
|
2832
|
+
}
|
|
2833
|
+
if (!a.interval || a.interval.min >= a.interval.max) {
|
|
2834
|
+
throw new Error("root2d: interval min ph\u1EA3i < max");
|
|
2835
|
+
}
|
|
2836
|
+
},
|
|
2837
|
+
dependsOn: (a) => [a.functionId],
|
|
2838
|
+
describe: (obj) => `Nghi\u1EC7m c\u1EE7a ${obj.attrs.functionId} trong [${obj.attrs.interval.min}, ${obj.attrs.interval.max}]`,
|
|
2839
|
+
render: (obj, ctx) => {
|
|
2840
|
+
const board = ctx.jxg;
|
|
2841
|
+
const expr = ctx.defaults._functionExpr?.[obj.attrs.functionId];
|
|
2842
|
+
if (!expr) return null;
|
|
2843
|
+
const fn = compile(expr, ctx.paramMap ?? {});
|
|
2844
|
+
if (typeof fn !== "function") return null;
|
|
2845
|
+
const roots = scanRoots(fn, obj.attrs.interval.min, obj.attrs.interval.max);
|
|
2846
|
+
return roots.map((x) => board.create("point", [x, 0], {
|
|
2847
|
+
name: obj.label,
|
|
2848
|
+
size: 3,
|
|
2849
|
+
fillColor: "#dc2626",
|
|
2850
|
+
strokeColor: "#dc2626",
|
|
2851
|
+
withLabel: obj.label !== ""
|
|
2852
|
+
}));
|
|
2853
|
+
}
|
|
2854
|
+
};
|
|
2855
|
+
registerKind(def20);
|
|
2856
|
+
}
|
|
2857
|
+
});
|
|
2858
|
+
|
|
2859
|
+
// src/core/scene/kinds/slope2d.ts
|
|
2860
|
+
var def21;
|
|
2861
|
+
var init_slope2d = __esm({
|
|
2862
|
+
"src/core/scene/kinds/slope2d.ts"() {
|
|
2863
|
+
init_registry();
|
|
2864
|
+
def21 = {
|
|
2865
|
+
type: "slope2d",
|
|
2866
|
+
schemaVersion: 1,
|
|
2867
|
+
migrate: {},
|
|
2868
|
+
validate: (a) => {
|
|
2869
|
+
if (!a || typeof a.pointId !== "string" || !a.pointId) {
|
|
2870
|
+
throw new Error("slope2d: pointId b\u1EAFt bu\u1ED9c");
|
|
2871
|
+
}
|
|
2872
|
+
},
|
|
2873
|
+
dependsOn: (a) => [a.pointId],
|
|
2874
|
+
describe: (obj) => `Slope t\u1EA1i ${obj.attrs.pointId}`,
|
|
2875
|
+
render: (obj, ctx) => {
|
|
2876
|
+
const board = ctx.jxg;
|
|
2877
|
+
const pt = ctx.resolveRef(obj.attrs.pointId);
|
|
2878
|
+
if (!pt) return null;
|
|
2879
|
+
return board.create("slopetriangle", [pt], {
|
|
2880
|
+
name: obj.label,
|
|
2881
|
+
withLabel: true,
|
|
2882
|
+
fillColor: "#9333ea",
|
|
2883
|
+
strokeColor: "#9333ea",
|
|
2884
|
+
fillOpacity: 0.2
|
|
2885
|
+
});
|
|
2886
|
+
}
|
|
2887
|
+
};
|
|
2888
|
+
registerKind(def21);
|
|
2889
|
+
}
|
|
2890
|
+
});
|
|
2891
|
+
|
|
2892
|
+
// src/core/scene/kinds/index.ts
|
|
2893
|
+
var init_kinds = __esm({
|
|
2894
|
+
"src/core/scene/kinds/index.ts"() {
|
|
2895
|
+
init_point3d();
|
|
2896
|
+
init_segment3d();
|
|
2897
|
+
init_line3d();
|
|
2898
|
+
init_ray3d();
|
|
2899
|
+
init_vector3d();
|
|
2900
|
+
init_plane3d();
|
|
2901
|
+
init_polygon3d();
|
|
2902
|
+
init_sphere3d();
|
|
2903
|
+
init_polyhedron3d();
|
|
2904
|
+
init_cylinder3d();
|
|
2905
|
+
init_cone3d();
|
|
2906
|
+
init_point();
|
|
2907
|
+
init_segment();
|
|
2908
|
+
init_line();
|
|
2909
|
+
init_ray();
|
|
2910
|
+
init_vector();
|
|
2911
|
+
init_circle();
|
|
2912
|
+
init_arc();
|
|
2913
|
+
init_sector();
|
|
2914
|
+
init_polygon();
|
|
2915
|
+
init_intersection();
|
|
2916
|
+
init_angle();
|
|
2917
|
+
init_distance();
|
|
2918
|
+
init_function2d();
|
|
2919
|
+
init_parameter();
|
|
2920
|
+
init_pointOnCurve();
|
|
2921
|
+
init_tangent2d();
|
|
2922
|
+
init_extremum2d();
|
|
2923
|
+
init_root2d();
|
|
2924
|
+
init_slope2d();
|
|
2925
|
+
}
|
|
2926
|
+
});
|
|
2927
|
+
|
|
999
2928
|
// src/core/scene/index.ts
|
|
1000
2929
|
var init_scene = __esm({
|
|
1001
2930
|
"src/core/scene/index.ts"() {
|
|
@@ -1003,6 +2932,7 @@ var init_scene = __esm({
|
|
|
1003
2932
|
init_store();
|
|
1004
2933
|
init_selectors();
|
|
1005
2934
|
init_hooks();
|
|
2935
|
+
init_kinds();
|
|
1006
2936
|
}
|
|
1007
2937
|
});
|
|
1008
2938
|
|