• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

caleb531 / flip-book / 10499286139

21 Aug 2024 11:59PM UTC coverage: 25.53% (-2.0%) from 27.541%
10499286139

push

github

caleb531
Convert components to JSX

72 of 100 branches covered (72.0%)

Branch coverage included in aggregate %.

0 of 743 new or added lines in 22 files covered. (0.0%)

54 existing lines in 21 files now uncovered.

386 of 1694 relevant lines covered (22.79%)

6.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/scripts/components/drawing-area.jsx
NEW
1
import FrameComponent from "./frame.jsx";
×
2

3
class DrawingAreaComponent extends FrameComponent {
×
NEW
4
  oninit({ attrs: { story, frame, drawingEnabled = true } }) {
×
5
    this.story = story;
×
NEW
6
    super.oninit({ attrs: { frame } });
×
7
    this.drawingEnabled = drawingEnabled;
×
8
  }
×
9

NEW
10
  oncreate({ dom }) {
×
NEW
11
    super.oncreate({ dom });
×
UNCOV
12
  }
×
13

NEW
14
  onupdate({ attrs: { story, frame, drawingEnabled = true } }) {
×
15
    this.story = story;
×
16
    this.drawingEnabled = drawingEnabled;
×
NEW
17
    super.onupdate({ attrs: { frame } });
×
18
  }
×
19

20
  handleDrawStart(event, pageX, pageY) {
×
21
    event.preventDefault();
×
22
    if (this.drawingEnabled) {
×
23
      this.mousedown = true;
×
24
      // Cache canvas size/position computations for the duration of the drag
25
      this.canvasScaleFactor = this.canvas.width / this.canvas.offsetWidth;
×
26
      this.canvasOffsetLeft = event.target.parentElement.offsetLeft;
×
27
      this.canvasOffsetTop = event.target.parentElement.offsetTop;
×
28
      let startX = (pageX - this.canvasOffsetLeft) * this.canvasScaleFactor;
×
29
      let startY = (pageY - this.canvasOffsetTop) * this.canvasScaleFactor;
×
30
      this.frame.startNewGroup({
×
NEW
31
        styles: Object.assign({}, this.story.frameStyles),
×
32
      });
×
33
      this.frame.addPoint(startX, startY);
×
34
      this.lastX = startX;
×
35
      this.lastY = startY;
×
36
      this.frame.resetUndoHistory();
×
37
    }
×
38
  }
×
39

40
  handleDrawMove(event, pageX, pageY) {
×
41
    event.preventDefault();
×
42
    if (this.mousedown && this.drawingEnabled) {
×
43
      let endX = (pageX - this.canvasOffsetLeft) * this.canvasScaleFactor;
×
44
      let endY = (pageY - this.canvasOffsetTop) * this.canvasScaleFactor;
×
45
      let diffX = endX - this.lastX;
×
46
      let diffY = endY - this.lastY;
×
47
      if (diffX !== 0 || diffY !== 0) {
×
48
        this.frame.addPoint(diffX, diffY);
×
49
        this.lastX = endX;
×
50
        this.lastY = endY;
×
51
        this.render();
×
52
      }
×
53
    }
×
54
    event.redraw = false;
×
55
  }
×
56

57
  async handleDrawEnd(event) {
×
58
    event.preventDefault();
×
59
    if (this.drawingEnabled && this.mousedown) {
×
60
      this.mousedown = false;
×
61
      await this.story.save();
×
62
    } else {
×
63
      event.redraw = false;
×
64
    }
×
65
  }
×
66

67
  handleTouchStart(event) {
×
68
    if (event.changedTouches?.length > 0) {
×
NEW
69
      this.handleDrawStart(
×
NEW
70
        event,
×
NEW
71
        event.changedTouches[0].pageX,
×
NEW
72
        event.changedTouches[0].pageY,
×
NEW
73
      );
×
74
    }
×
75
  }
×
76

77
  handleTouchMove(event) {
×
78
    if (event.changedTouches?.length > 0) {
×
NEW
79
      this.handleDrawMove(
×
NEW
80
        event,
×
NEW
81
        event.changedTouches[0].pageX,
×
NEW
82
        event.changedTouches[0].pageY,
×
NEW
83
      );
×
84
    }
×
85
  }
×
86

87
  handleTouchEnd(event) {
×
88
    if (event.changedTouches?.length > 0) {
×
89
      this.handleDrawEnd(event);
×
90
    }
×
91
  }
×
92

93
  handleMouseDown(event) {
×
94
    this.handleDrawStart(event, event.pageX, event.pageY);
×
95
  }
×
96

97
  handleMouseMove(event) {
×
98
    this.handleDrawMove(event, event.pageX, event.pageY);
×
99
  }
×
100

101
  handleMouseUp(event) {
×
102
    this.handleDrawEnd(event);
×
103
  }
×
104

105
  async undo() {
×
106
    this.frame.undo();
×
107
    this.render();
×
108
    await this.story.save();
×
109
  }
×
110

111
  async redo() {
×
112
    this.frame.redo();
×
113
    this.render();
×
114
    await this.story.save();
×
115
  }
×
116

117
  view() {
×
NEW
118
    return (
×
NEW
119
      <canvas
×
NEW
120
        className="selected-frame"
×
NEW
121
        width={FrameComponent.width}
×
NEW
122
        height={FrameComponent.height}
×
123
        // Touch events
NEW
124
        ontouchstart={(event) => this.handleTouchStart(event)}
×
NEW
125
        ontouchmove={(event) => this.handleTouchMove(event)}
×
NEW
126
        ontouchend={(event) => this.handleTouchEnd(event)}
×
127
        // Mouse events
NEW
128
        onmousedown={(event) => this.handleMouseDown(event)}
×
NEW
129
        onmousemove={(event) => this.handleMouseMove(event)}
×
NEW
130
        onmouseup={(event) => this.handleMouseUp(event)}
×
NEW
131
        onmouseout={(event) => this.handleMouseUp(event)}
×
NEW
132
      />
×
133
    );
UNCOV
134
  }
×
UNCOV
135
}
×
136
export default DrawingAreaComponent;
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc