sketchmark 2.1.7 → 2.1.9

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/tests/run.js CHANGED
@@ -110,6 +110,36 @@ test("renders path, text, image, and group to SVG and HTML", () => {
110
110
  assert(svg.includes('stroke-width="1"'), "path stroke should default to width 1 when stroke is set");
111
111
  assert((0, src_1.renderToHtml)(doc).includes("Sketchmark Kernel Visual"), "should render HTML shell");
112
112
  });
113
+ test("renders a self-contained interactive embed HTML shell", () => {
114
+ const doc = {
115
+ version: 1,
116
+ canvas: { width: 240, height: 140, background: "#f8fafc", duration: 1, fps: 12 },
117
+ elements: [
118
+ {
119
+ id: "label",
120
+ type: "text",
121
+ text: "Embed preview",
122
+ x: 40,
123
+ y: 70,
124
+ fill: "#0f172a",
125
+ timeline: {
126
+ tracks: {
127
+ position: { keyframes: [[0, [40, 70]], [1, [180, 70]]], ease: "linear" }
128
+ }
129
+ }
130
+ }
131
+ ]
132
+ };
133
+ const html = (0, src_1.renderToEmbedHtml)(doc, { title: "Embed Demo", maxFrames: 16 });
134
+ assert(html.includes("Sketchmark Embed"), "should include embed chrome");
135
+ assert(html.includes("background: transparent;"), "should default embed chrome to a transparent background");
136
+ assert(html.includes("prefers-color-scheme: dark"), "should adapt embed chrome for dark mode");
137
+ assert(html.includes('data-export-format="svg"'), "should include export controls");
138
+ assert(html.includes('data-export-format="mp4"'), "should include mp4 export");
139
+ assert(html.includes("__SKETCHMARK_EMBED__"), "should expose a runtime controller");
140
+ assert(html.includes("loadMp4Muxer"), "should inline mp4 export runtime");
141
+ assert(html.includes("sketchmark-rendered"), "should notify host frames when ready");
142
+ });
113
143
  test("resolves element-local timeline tracks", () => {
114
144
  const doc = {
115
145
  version: 1,
@@ -462,6 +492,58 @@ test("compiles per-property curves and timing offsets", () => {
462
492
  assert(keyframes[1].time === 1.5, `global and property offsets should shift the target keyframe, got ${keyframes[1].time}`);
463
493
  assert(near((0, src_1.resolveVisualFrame)(animated, 1).elements[0].x, 0), "hold curve should keep the point at the base value before the target");
464
494
  });
495
+ test("inserts element presets at root and inside groups", () => {
496
+ const doc = {
497
+ version: 1,
498
+ canvas: { width: 320, height: 180, duration: 2 },
499
+ elements: [{ id: "group", type: "group", x: 20, y: 30, width: 120, height: 80, children: [] }]
500
+ };
501
+ const rootInsert = (0, src_1.insertElementPreset)(doc, "rectangle");
502
+ assert(rootInsert.element.id === "rectangle", "root preset should use the preset name as id");
503
+ assert((0, src_1.validateVisualDocument)(rootInsert.document).ok, "root preset insert should validate");
504
+ assert((0, src_1.findElementById)(rootInsert.document, "rectangle").type === "path", "rectangle preset should be a path");
505
+ const nestedInsert = (0, src_1.insertElementPreset)(rootInsert.document, "text", { parentId: "group" });
506
+ assert(nestedInsert.parentId === "group", "nested insert should report parent id");
507
+ assert((0, src_1.findElementById)(nestedInsert.document, "group").children.some((item) => item.id === "text"), "nested preset should be added to group children");
508
+ const duplicate = (0, src_1.insertElementPreset)(nestedInsert.document, "text", { parentId: "group" });
509
+ assert(duplicate.element.id === "text_2", "duplicate preset ids should be made unique");
510
+ });
511
+ test("reorders and deletes elements inside their sibling layer", () => {
512
+ const doc = {
513
+ version: 1,
514
+ canvas: { width: 320, height: 180, duration: 2 },
515
+ elements: [
516
+ { id: "a", type: "point", x: 0, y: 0 },
517
+ { id: "b", type: "point", x: 10, y: 0 },
518
+ {
519
+ id: "group",
520
+ type: "group",
521
+ x: 20,
522
+ y: 30,
523
+ width: 120,
524
+ height: 80,
525
+ children: [
526
+ { id: "child1", type: "point", x: 0, y: 0 },
527
+ { id: "child2", type: "point", x: 10, y: 0 }
528
+ ]
529
+ }
530
+ ]
531
+ };
532
+ const front = (0, src_1.reorderElement)(doc, "a", { direction: "front" });
533
+ assert(front.previousIndex === 0 && front.index === 2, "root reorder should report old and new indexes");
534
+ assert((front.document.elements ?? []).map((item) => item.id).join(",") === "b,group,a", "front should move the element to the end of root order");
535
+ const backward = (0, src_1.reorderElement)(front.document, "a", { direction: "backward" });
536
+ assert((backward.document.elements ?? []).map((item) => item.id).join(",") === "b,a,group", "backward should move one layer down");
537
+ const nested = (0, src_1.reorderElement)(backward.document, "child1", { direction: "front" });
538
+ assert(nested.parentId === "group", "nested reorder should report parent id");
539
+ assert((0, src_1.findElementById)(nested.document, "group").children.map((item) => item.id).join(",") === "child2,child1", "nested reorder should only affect group children");
540
+ const deleted = (0, src_1.deleteElement)(nested.document, "child2");
541
+ assert(deleted.parentId === "group", "nested delete should report parent id");
542
+ assert(!(0, src_1.findElementById)(deleted.document, "child2"), "deleted child should be removed");
543
+ assert((0, src_1.findElementById)(deleted.document, "group").children.map((item) => item.id).join(",") === "child1", "delete should preserve remaining siblings");
544
+ const deletedGroup = (0, src_1.deleteElement)(deleted.document, "group");
545
+ assert(!(0, src_1.findElementById)(deletedGroup.document, "group") && !(0, src_1.findElementById)(deletedGroup.document, "child1"), "deleting a group should remove its children");
546
+ });
465
547
  test("edits nested element properties and timeline keyframes", () => {
466
548
  const doc = {
467
549
  version: 1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sketchmark",
3
- "version": "2.1.7",
3
+ "version": "2.1.9",
4
4
  "description": "Render kernel for Sketchmark visual documents.",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
@@ -25,6 +25,11 @@
25
25
  "require": "./dist/src/browser-export.js",
26
26
  "default": "./dist/src/browser-export.js"
27
27
  },
28
+ "./edit": {
29
+ "types": "./dist/src/edit.d.ts",
30
+ "require": "./dist/src/edit.js",
31
+ "default": "./dist/src/edit.js"
32
+ },
28
33
  "./editor": {
29
34
  "types": "./bin/editor-ui.d.ts",
30
35
  "require": "./bin/editor-ui.cjs",