highmark-cli 0.0.133 → 0.0.135

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "highmark-cli",
3
3
  "author": "James Smith",
4
- "version": "0.0.133",
4
+ "version": "0.0.135",
5
5
  "license": "MIT, Anti-996",
6
6
  "homepage": "https://github.com/djalbat/highmark-cli",
7
7
  "description": "Extensible, styleable Markdown.",
@@ -19,10 +19,10 @@
19
19
  "occam-entities": "^1.0.90"
20
20
  },
21
21
  "devDependencies": {
22
- "@swc/core": "^1.2.50",
22
+ "@swc/core": "1.2.52",
23
23
  "easy": "^16.0.19",
24
- "easy-layout": "^6.0.143",
25
- "easy-with-style": "^3.0.343",
24
+ "easy-layout": "^6.0.144",
25
+ "easy-with-style": "^3.0.348",
26
26
  "esbuild": "^0.9.2",
27
27
  "juxtapose": "^4.0.80",
28
28
  "watchful-cli": "^1.7.44"
package/src/client.js CHANGED
@@ -4,18 +4,27 @@ import "juxtapose";
4
4
 
5
5
  import withStyle from "easy-with-style"; ///
6
6
 
7
- import { Body } from "easy";
7
+ import { Body, Element } from "easy";
8
8
 
9
9
  import View from "./view";
10
10
 
11
+ import { elementFromDOMElement } from "./utilities/element";
12
+ import { LOADING_DIV_SELECTOR, VIEW_DIV_SELECTOR } from "./constants";
13
+
11
14
  const { renderStyles } = withStyle;
12
15
 
13
16
  renderStyles();
14
17
 
15
- const body = new Body();
18
+ const viewDOMElement = document.querySelector(VIEW_DIV_SELECTOR),
19
+ body = new Body(),
20
+ view = elementFromDOMElement(viewDOMElement, () =>
21
+
22
+ <View/>
23
+
24
+ ); ///
16
25
 
17
- body.mount(
26
+ body.mount(view);
18
27
 
19
- <View />
28
+ const loadingDiv = new Element(LOADING_DIV_SELECTOR);
20
29
 
21
- );
30
+ loadingDiv.hide();
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ export const { PI } = Math;
4
+
5
+ export const SINGLE_SPACE = " ";
6
+ export const MAXIMUM_TAP_TIME = 125;
7
+ export const VIEW_DIV_SELECTOR = "body > div:not(.loading)"; ///
8
+ export const ENABLE_SWIPES_DELAY = 500;
9
+ export const MINIMUM_SWIPE_SPEED = 1.25;
10
+ export const LOADING_DIV_SELECTOR = "body > div.loading";
11
+ export const ONE_HUNDRED_AND_EIGHTY = 180;
12
+ export const VIEW_CHILD_DIVS_SELECTOR = "body > div:not(.loading) div"; ///
13
+ export const MAXIMUM_CLICK_WIDTH_RATIO = 0.3;
14
+ export const MAXIMUM_SWIPE_ABSOLUTE_DIRECTION = 30;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ export const TAP_CUSTOM_EVENT_TYPE = "tap";
4
+ export const SWIPE_LEFT_CUSTOM_EVENT_TYPE = "swipe-left";
5
+ export const SWIPE_RIGHT_CUSTOM_EVENT_TYPE = "swipe-right";
6
+ export const ARROW_KEY_DOWN_CUSTOM_EVENT_TYPE = "arrow-key-down";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ export const TOUCHSTART_EVENT_TYPE = "touchstart";
4
+ export const TOUCHMOVE_EVENT_TYPE = "touchmove";
5
+ export const TOUCHEND_EVENT_TYPE = "touchend";
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ import { TOUCHSTART_EVENT_TYPE, TOUCHMOVE_EVENT_TYPE, TOUCHEND_EVENT_TYPE } from "../eventTypes";
4
+
5
+ function onTouchStart(touchStartHandler) {
6
+ const eventType = TOUCHSTART_EVENT_TYPE,
7
+ handler = touchStartHandler; ///
8
+
9
+ this.onEvent(eventType, handler);
10
+ }
11
+
12
+ function offTouchStart(touchStartHandler) {
13
+ const eventType = TOUCHSTART_EVENT_TYPE,
14
+ handler = touchStartHandler; ///
15
+
16
+ this.offEvent(eventType, handler);
17
+ }
18
+
19
+ function onTouchMove(touchStartHandler) {
20
+ const eventType = TOUCHMOVE_EVENT_TYPE,
21
+ handler = touchStartHandler; ///
22
+
23
+ this.onEvent(eventType, handler);
24
+ }
25
+
26
+ function offTouchMove(touchStartHandler) {
27
+ const eventType = TOUCHMOVE_EVENT_TYPE,
28
+ handler = touchStartHandler; ///
29
+
30
+ this.offEvent(eventType, handler);
31
+ }
32
+
33
+ function onTouchEnd(touchStartHandler) {
34
+ const eventType = TOUCHEND_EVENT_TYPE,
35
+ handler = touchStartHandler; ///
36
+
37
+ this.onEvent(eventType, handler);
38
+ }
39
+
40
+ function offTouchEnd(touchStartHandler) {
41
+ const eventType = TOUCHEND_EVENT_TYPE,
42
+ handler = touchStartHandler; ///
43
+
44
+ this.offEvent(eventType, handler);
45
+ }
46
+
47
+ const eventMixins = {
48
+ onTouchStart,
49
+ offTouchStart,
50
+ onTouchMove,
51
+ offTouchMove,
52
+ onTouchEnd,
53
+ offTouchEnd
54
+ };
55
+
56
+ export default eventMixins;
@@ -0,0 +1,240 @@
1
+ "use strict";
2
+
3
+ import { window } from "easy";
4
+
5
+ import Position from "../position";
6
+ import Velocity from "../velocity";
7
+
8
+ import { TAP_CUSTOM_EVENT_TYPE, SWIPE_LEFT_CUSTOM_EVENT_TYPE, SWIPE_RIGHT_CUSTOM_EVENT_TYPE } from "../customEventTypes";
9
+ import { MAXIMUM_TAP_TIME, MINIMUM_SWIPE_SPEED, ONE_HUNDRED_AND_EIGHTY, MAXIMUM_SWIPE_ABSOLUTE_DIRECTION } from "../constants";
10
+
11
+ function enableTouch() {
12
+ const startPosition = null;
13
+
14
+ this.updateState({
15
+ startPosition
16
+ });
17
+
18
+ this.onMouseDown(this.mouseDownHandler);
19
+ this.onMouseMove(this.mouseMoveHandler);
20
+
21
+ window.onMouseUp(this.mouseUpHandler, this);
22
+
23
+ this.onTouchStart(this.touchStartHandler);
24
+ this.onTouchMove(this.touchMoveHandler);
25
+ this.onTouchEnd(this.touchEndHandler);
26
+ }
27
+
28
+ function disableTouch() {
29
+ this.offMouseDown(this.mouseDownHandler);
30
+ this.offMouseMove(this.mouseMoveHandler);
31
+
32
+ window.offMouseUp(this.mouseUpHandler, this);
33
+
34
+ this.offTouchStart(this.touchStartHandler);
35
+ this.offTouchMove(this.touchMoveHandler);
36
+ this.offTouchEnd(this.touchEndHandler);
37
+ }
38
+
39
+ function onCustomTap(tapCustomHandler, element) {
40
+ const customEventType = TAP_CUSTOM_EVENT_TYPE,
41
+ customHandler = tapCustomHandler; ///
42
+
43
+ this.onCustomEvent(customEventType, customHandler, element);
44
+ }
45
+
46
+ function offCustomTap(tapCustomHandler, element) {
47
+ const customEventType = TAP_CUSTOM_EVENT_TYPE,
48
+ customHandler = tapCustomHandler; ///
49
+
50
+ this.offCustomEvent(customEventType, customHandler, element);
51
+ }
52
+
53
+ function onCustomSwipeLeft(swipeLeftCustomHandler, element) {
54
+ const customEventType = SWIPE_LEFT_CUSTOM_EVENT_TYPE,
55
+ customHandler = swipeLeftCustomHandler; ///
56
+
57
+ this.onCustomEvent(customEventType, customHandler, element);
58
+ }
59
+
60
+ function offCustomSwipeLeft(swipeLeftCustomHandler, element) {
61
+ const customEventType = SWIPE_LEFT_CUSTOM_EVENT_TYPE,
62
+ customHandler = swipeLeftCustomHandler; ///
63
+
64
+ this.offCustomEvent(customEventType, customHandler, element);
65
+ }
66
+
67
+ function onCustomSwipeRight(swipeRightCustomHandler, element) {
68
+ const customEventType = SWIPE_RIGHT_CUSTOM_EVENT_TYPE,
69
+ customHandler = swipeRightCustomHandler; ///
70
+
71
+ this.onCustomEvent(customEventType, customHandler, element);
72
+ }
73
+
74
+ function offCustomSwipeRight(swipeRightCustomHandler, element) {
75
+ const customEventType = SWIPE_RIGHT_CUSTOM_EVENT_TYPE,
76
+ customHandler = swipeRightCustomHandler; ///
77
+
78
+ this.offCustomEvent(customEventType, customHandler, element);
79
+ }
80
+
81
+ function getStartPosition() {
82
+ const { startPosition } = this.getState();
83
+
84
+ return startPosition;
85
+ }
86
+
87
+ function setStartPosition(startPosition) {
88
+ this.updateState({
89
+ startPosition
90
+ });
91
+ }
92
+
93
+ function touchStartHandler(event, element) {
94
+ this.startHandler(event, element, (event) => {
95
+ const touchEvent = event, ///
96
+ position = Position.fromTouchEvent(touchEvent);
97
+
98
+ return position;
99
+ });
100
+ }
101
+
102
+ function mouseDownHandler(event, element) {
103
+ this.startHandler(event, element, (event) => { ///
104
+ const mouseEvent = event, ///
105
+ position = Position.fromMouseEvent(mouseEvent);
106
+
107
+ return position;
108
+ });
109
+ }
110
+
111
+ function touchMoveHandler(event, element) {
112
+ this.moveHandler(event, element, (event) => {
113
+ const touchEvent = event, ///
114
+ position = Position.fromTouchEvent(touchEvent);
115
+
116
+ return position;
117
+ });
118
+ }
119
+
120
+ function mouseMoveHandler(event, element) {
121
+ this.moveHandler(event, element, (event) => {
122
+ const mouseEvent = event, ///
123
+ position = Position.fromMouseEvent(mouseEvent);
124
+
125
+ return position;
126
+ });
127
+ }
128
+
129
+ function touchEndHandler(event, element) {
130
+ this.endHandler(event, element, (event) => {
131
+ const touchEvent = event, ///
132
+ position = Position.fromTouchEvent(touchEvent);
133
+
134
+ return position;
135
+ });
136
+ }
137
+
138
+ function mouseUpHandler(event, element) {
139
+ this.endHandler(event, element, (event) => { ///
140
+ const mouseEvent = event, ///
141
+ position = Position.fromMouseEvent(mouseEvent);
142
+
143
+ return position;
144
+ });
145
+ }
146
+
147
+ function startHandler(event, element, positionFromEvent) {
148
+ const position = positionFromEvent(event),
149
+ startPosition = position; ///
150
+
151
+ this.setStartPosition(startPosition);
152
+ }
153
+
154
+ function moveHandler(event, element, positionFromEvent) {
155
+ let startPosition = this.getStartPosition();
156
+
157
+ if (startPosition !== null) {
158
+ const position = positionFromEvent(event);
159
+
160
+ if (position !== null) {
161
+ const positionMatchesStartPosition = position.match(startPosition);
162
+
163
+ if (positionMatchesStartPosition) {
164
+ const velocity = Velocity.fromPositionAndStartPosition(position, startPosition),
165
+ speed = velocity.getSpeed();
166
+
167
+ if (speed > MINIMUM_SWIPE_SPEED) {
168
+ const absoluteDirection = velocity.getAbsoluteDirection();
169
+
170
+ let customEventType = null;
171
+
172
+ if (absoluteDirection < MAXIMUM_SWIPE_ABSOLUTE_DIRECTION) {
173
+ customEventType = SWIPE_RIGHT_CUSTOM_EVENT_TYPE;
174
+ }
175
+
176
+ if ((ONE_HUNDRED_AND_EIGHTY - absoluteDirection) < MAXIMUM_SWIPE_ABSOLUTE_DIRECTION) {
177
+ customEventType = SWIPE_LEFT_CUSTOM_EVENT_TYPE;
178
+ }
179
+
180
+ if (customEventType !== null) {
181
+ this.callCustomHandlers(customEventType, event, element);
182
+ }
183
+ }
184
+ }
185
+ }
186
+ }
187
+ }
188
+
189
+ function endHandler(event, element, positionFromEvent) {
190
+ let startPosition;
191
+
192
+ startPosition = this.getStartPosition();
193
+
194
+ if (startPosition !== null) {
195
+ const position = positionFromEvent(event);
196
+
197
+ if (position !== null) {
198
+ const positionMatchesStartPosition = position.match(startPosition);
199
+
200
+ if (positionMatchesStartPosition) {
201
+ const velocity = Velocity.fromPositionAndStartPosition(position, startPosition),
202
+ speed = velocity.getSpeed();
203
+
204
+ if (speed === 0) {
205
+ const time = velocity.getTime();
206
+
207
+ if (time < MAXIMUM_TAP_TIME) {
208
+ const customEventType = TAP_CUSTOM_EVENT_TYPE;
209
+
210
+ this.callCustomHandlers(customEventType, event, element);
211
+ }
212
+ }
213
+ }
214
+ }
215
+ }
216
+ }
217
+
218
+ const customEventMixins = {
219
+ enableTouch,
220
+ disableTouch,
221
+ onCustomTap,
222
+ offCustomTap,
223
+ onCustomSwipeLeft,
224
+ offCustomSwipeLeft,
225
+ onCustomSwipeRight,
226
+ offCustomSwipeRight,
227
+ getStartPosition,
228
+ setStartPosition,
229
+ touchStartHandler,
230
+ mouseDownHandler,
231
+ touchMoveHandler,
232
+ mouseMoveHandler,
233
+ touchEndHandler,
234
+ mouseUpHandler,
235
+ startHandler,
236
+ moveHandler,
237
+ endHandler
238
+ };
239
+
240
+ export default customEventMixins;
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+
3
+ import { arrayUtilities } from "necessary";
4
+
5
+ import { PI, ONE_HUNDRED_AND_EIGHTY } from "./constants";
6
+
7
+ const { first } = arrayUtilities;
8
+
9
+ export default class Position {
10
+ constructor(top, left, time, identifier) {
11
+ this.top = top;
12
+ this.left = left;
13
+ this.time = time;
14
+ this.identifier = identifier;
15
+ }
16
+
17
+ getTop() {
18
+ return this.top;
19
+ }
20
+
21
+ getLeft() {
22
+ return this.left;
23
+ }
24
+
25
+ getTime() {
26
+ return this.time;
27
+ }
28
+
29
+ getIdentifier() {
30
+ return this.identifier;
31
+ }
32
+
33
+ getMagnitude() {
34
+ const magnitude = Math.sqrt(this.top * this.top + this.left * this.left);
35
+
36
+ return magnitude;
37
+ }
38
+
39
+ getDirection() {
40
+ let direction = 0;
41
+
42
+ if (this.left === 0) {
43
+ direction = (this.top < 0) ?
44
+ +PI / 2 :
45
+ -PI / 2;
46
+ } else {
47
+ direction = Math.atan2(-this.top, this.left);
48
+ }
49
+
50
+ direction = direction * ONE_HUNDRED_AND_EIGHTY / PI;
51
+
52
+ return direction;
53
+ }
54
+
55
+ minus(position) {
56
+ const positionTop = position.getTop(),
57
+ positionLeft = position.getLeft(),
58
+ positionTime = position.getTime(),
59
+ top = this.top - positionTop,
60
+ left = this.left - positionLeft,
61
+ time = this.time - positionTime,
62
+ identifier = null; ///
63
+
64
+ position = new Position(top, left, time, identifier); ///
65
+
66
+ return position;
67
+ }
68
+
69
+ match(position) {
70
+ const identifier = position.getIdentifier(),
71
+ matches = (this.identifier === identifier);
72
+
73
+ return matches;
74
+ }
75
+
76
+ static fromMouseEvent(mouseEvent) {
77
+ const { pageX, pageY } = mouseEvent,
78
+ top = pageY, ///
79
+ left = pageX, ///
80
+ time = getTime(),
81
+ identifier = null,
82
+ position = new Position(top, left, time, identifier);
83
+
84
+ return position;
85
+ }
86
+
87
+ static fromTouchEvent(touchEvent) {
88
+ let position = null;
89
+
90
+ const { touches } = touchEvent,
91
+ touchesLength = touches.length;
92
+
93
+ if (touchesLength === 1) {
94
+ const firstTouch = first(touches),
95
+ touch = firstTouch, ///
96
+ { pageX, pageY, identifier } = touch,
97
+ top = pageY,
98
+ left = pageX,
99
+ time = getTime();
100
+
101
+ position = new Position(top, left, time, identifier);
102
+ }
103
+
104
+ return position;
105
+ }
106
+ }
107
+
108
+ function getTime() {
109
+ const time = Date.now(); ///
110
+
111
+ return time;
112
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ import { SINGLE_SPACE } from "../constants";
4
+
5
+ export function elementsFromDOMElements(domElements, Element) {
6
+ const elements = domElements.map((domElement) => {
7
+ const element = elementFromDOMElement(domElement, Element);
8
+
9
+ return element;
10
+ });
11
+
12
+ return elements;
13
+ }
14
+
15
+ export function elementFromDOMElement(domElement, Element) {
16
+ const element = Element(); ///
17
+
18
+ const { domElement: temporaryDOMElement } = element,
19
+ { className: classNamesString } = temporaryDOMElement,
20
+ classNames = classNamesString.split(SINGLE_SPACE);
21
+
22
+ const { classList } = domElement;
23
+
24
+ classNames.forEach((className) => {
25
+ classList.add(className);
26
+ });
27
+
28
+ element.domElement = domElement; ///
29
+
30
+ domElement.__element__ = element; ///
31
+
32
+ return element;
33
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ import { arrayUtilities } from "necessary";
4
+
5
+ const { filter } = arrayUtilities;
6
+
7
+ export function leafNodesFromNodeList(nodeList) {
8
+ const nodes = [ ...nodeList ];
9
+
10
+ filter(nodes, (node) => {
11
+ const { childNodes: childNodeList } = node,
12
+ childNodes = [ ...childNodeList ],
13
+ childNodesIncludesNodes = nodes.some((node) => {
14
+ const childNodesIncludesNode = childNodes.includes(node);
15
+
16
+ if (childNodesIncludesNode) {
17
+ return true;
18
+ }
19
+ });
20
+
21
+ if (!childNodesIncludesNodes) {
22
+ return true;
23
+ }
24
+ });
25
+
26
+ const leafNodes = nodes; ///
27
+
28
+ return leafNodes;
29
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ export default class Velocity {
4
+ constructor(time, magnitude, direction) {
5
+ this.time = time;
6
+ this.magnitude = magnitude;
7
+ this.direction = direction;
8
+ }
9
+
10
+ getTime() {
11
+ return this.time;
12
+ }
13
+
14
+ getMagnitude() {
15
+ return this.magnitude;
16
+ }
17
+
18
+ getDirection() {
19
+ return this.direction;
20
+ }
21
+
22
+ getSpeed() {
23
+ const speed = (this.time === 0) ?
24
+ 0 : ///
25
+ this.magnitude / this.time;
26
+
27
+ return speed;
28
+ }
29
+
30
+ getAbsoluteDirection() {
31
+ const absoluteDirection = Math.abs(this.direction);
32
+
33
+ return absoluteDirection;
34
+ }
35
+
36
+ static fromPositionAndStartPosition(position, startPosition) {
37
+ const relativePosition = position.minus(startPosition),
38
+ time = relativePosition.getTime(),
39
+ magnitude = relativePosition.getMagnitude(),
40
+ direction = relativePosition.getDirection(),
41
+ velocity = new Velocity(time, magnitude, direction);
42
+
43
+ return velocity;
44
+ }
45
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ import { Element } from "easy";
4
+
5
+ import withStyle from "easy-with-style"; ///
6
+
7
+ import eventMixins from "../../mixins/event";
8
+ import touchMixins from "../../mixins/touch";
9
+
10
+ class LeafDiv extends Element {
11
+ wiggle() {
12
+ this.removeClass("wiggle");
13
+ this.addClass("wiggle");
14
+ }
15
+
16
+ didMount() {
17
+ this.enableTouch();
18
+ }
19
+
20
+ willUnmount() {
21
+ this.disableTouch();
22
+ }
23
+
24
+ static tagName = "div";
25
+
26
+ static defaultProperties = {
27
+ className: "leaf"
28
+ };
29
+ }
30
+
31
+ Object.assign(LeafDiv.prototype, eventMixins);
32
+ Object.assign(LeafDiv.prototype, touchMixins);
33
+
34
+ export default withStyle(LeafDiv)`
35
+
36
+ width: 100vw;
37
+ position: absolute;
38
+ min-height: 100vh;
39
+
40
+ @keyframes wiggle {
41
+ 0% { transform: translateX(-5px); }
42
+ 50% { transform: translateX(5px); }
43
+ 100% { transform: translateX(-5px); }
44
+ }
45
+
46
+ .wiggle {
47
+ animation: wiggle 0.5s ease-in-out 1;
48
+ }
49
+
50
+ `;