Comparing version 0.2.1 to 0.3.0
(() => { | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __spreadValues = (a, b) => { | ||
var __spreadValues = (a2, b) => { | ||
for (var prop in b || (b = {})) | ||
if (__hasOwnProp.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
__defNormalProp(a2, prop, b[prop]); | ||
if (__getOwnPropSymbols) | ||
for (var prop of __getOwnPropSymbols(b)) { | ||
if (__propIsEnum.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
__defNormalProp(a2, prop, b[prop]); | ||
} | ||
return a; | ||
return a2; | ||
}; | ||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); | ||
var __require = typeof require !== "undefined" ? require : (x) => { | ||
throw new Error('Dynamic require of "' + x + '" is not supported'); | ||
}; | ||
var __reExport = (target, module, desc) => { | ||
if (module && typeof module === "object" || typeof module === "function") { | ||
for (let key of __getOwnPropNames(module)) | ||
if (!__hasOwnProp.call(target, key) && key !== "default") | ||
__defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable }); | ||
} | ||
return target; | ||
}; | ||
var __toModule = (module) => { | ||
return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", module && module.__esModule && "default" in module ? { get: () => module.default, enumerable: true } : { value: module, enumerable: true })), module); | ||
}; | ||
@@ -52,16 +33,175 @@ // ../../node_modules/.pnpm/nanoevents@6.0.1/node_modules/nanoevents/index.js | ||
// src/models/stylus.ts | ||
var import_perfect_freehand = __toModule(__require("perfect-freehand")); | ||
// ../../node_modules/.pnpm/perfect-freehand@1.0.16/node_modules/perfect-freehand/dist/esm/index.js | ||
function W(e, t, s, h = (b) => b) { | ||
return e * h(0.5 - t * (0.5 - s)); | ||
} | ||
function re(e) { | ||
return [-e[0], -e[1]]; | ||
} | ||
function l(e, t) { | ||
return [e[0] + t[0], e[1] + t[1]]; | ||
} | ||
function a(e, t) { | ||
return [e[0] - t[0], e[1] - t[1]]; | ||
} | ||
function f(e, t) { | ||
return [e[0] * t, e[1] * t]; | ||
} | ||
function le(e, t) { | ||
return [e[0] / t, e[1] / t]; | ||
} | ||
function L(e) { | ||
return [e[1], -e[0]]; | ||
} | ||
function ne(e, t) { | ||
return e[0] * t[0] + e[1] * t[1]; | ||
} | ||
function oe(e, t) { | ||
return e[0] === t[0] && e[1] === t[1]; | ||
} | ||
function fe(e) { | ||
return Math.hypot(e[0], e[1]); | ||
} | ||
function be(e) { | ||
return e[0] * e[0] + e[1] * e[1]; | ||
} | ||
function Y(e, t) { | ||
return be(a(e, t)); | ||
} | ||
function G(e) { | ||
return le(e, fe(e)); | ||
} | ||
function ue(e, t) { | ||
return Math.hypot(e[1] - t[1], e[0] - t[0]); | ||
} | ||
function T(e, t, s) { | ||
let h = Math.sin(s), b = Math.cos(s), v = e[0] - t[0], n = e[1] - t[1], g = v * b - n * h, E = v * h + n * b; | ||
return [g + t[0], E + t[1]]; | ||
} | ||
function V(e, t, s) { | ||
return l(e, f(a(t, e), s)); | ||
} | ||
function Z(e, t, s) { | ||
return l(e, f(t, s)); | ||
} | ||
var { min: _, PI: ge } = Math; | ||
var se = 0.275; | ||
var j = ge + 1e-4; | ||
function ie(e, t = {}) { | ||
let { size: s = 16, smoothing: h = 0.5, thinning: b = 0.5, simulatePressure: v = true, easing: n = (r) => r, start: g = {}, end: E = {}, last: z = false } = t, { cap: d = true, taper: x = 0, easing: q = (r) => r * (2 - r) } = g, { cap: m = true, taper: c = 0, easing: M = (r) => --r * r * r + 1 } = E; | ||
if (e.length === 0 || s <= 0) | ||
return []; | ||
let H = e[e.length - 1].runningLength, $ = Math.pow(s * h, 2), D2 = [], R = [], N = e.slice(0, 10).reduce((r, i) => { | ||
let o = i.pressure; | ||
if (v) { | ||
let u = _(1, i.distance / s), J = _(1, 1 - u); | ||
o = _(1, r + (J - r) * (u * se)); | ||
} | ||
return (r + o) / 2; | ||
}, e[0].pressure), p = W(s, b, e[e.length - 1].pressure, n), U, B = e[0].vector, I = e[0].point, C = I, y = I, O = C; | ||
for (let r = 0; r < e.length; r++) { | ||
let { pressure: i } = e[r], { point: o, vector: u, distance: J, runningLength: K } = e[r]; | ||
if (r < e.length - 1 && H - K < 3) | ||
continue; | ||
if (b) { | ||
if (v) { | ||
let P = _(1, J / s), Q = _(1, 1 - P); | ||
i = _(1, N + (Q - N) * (P * se)); | ||
} | ||
p = W(s, b, i, n); | ||
} else | ||
p = s / 2; | ||
U === void 0 && (U = p); | ||
let pe = K < x ? q(K / x) : 1, ae = H - K < c ? M((H - K) / c) : 1; | ||
if (p = Math.max(0.01, p * Math.min(pe, ae)), r === e.length - 1) { | ||
let P = f(L(u), p); | ||
D2.push(a(o, P)), R.push(l(o, P)); | ||
continue; | ||
} | ||
let A = e[r + 1].vector, ee = ne(u, A); | ||
if (ee < 0) { | ||
let P = f(L(B), p); | ||
for (let Q = 1 / 13, w = 0; w <= 1; w += Q) | ||
y = T(a(o, P), o, j * w), D2.push(y), O = T(l(o, P), o, j * -w), R.push(O); | ||
I = y, C = O; | ||
continue; | ||
} | ||
let te = f(L(V(A, u, ee)), p); | ||
y = a(o, te), (r <= 1 || Y(I, y) > $) && (D2.push(y), I = y), O = l(o, te), (r <= 1 || Y(C, O) > $) && (R.push(O), C = O), N = i, B = u; | ||
} | ||
let S = e[0].point.slice(0, 2), k = e.length > 1 ? e[e.length - 1].point.slice(0, 2) : l(e[0].point, [1, 1]), X = [], F = []; | ||
if (e.length === 1) { | ||
if (!(x || c) || z) { | ||
let r = Z(S, G(L(a(S, k))), -(U || p)), i = []; | ||
for (let o = 1 / 13, u = o; u <= 1; u += o) | ||
i.push(T(r, S, j * 2 * u)); | ||
return i; | ||
} | ||
} else { | ||
if (!(x || c && e.length === 1)) | ||
if (d) | ||
for (let i = 1 / 13, o = i; o <= 1; o += i) { | ||
let u = T(R[0], S, j * o); | ||
X.push(u); | ||
} | ||
else { | ||
let i = a(D2[0], R[0]), o = f(i, 0.5), u = f(i, 0.51); | ||
X.push(a(S, o), a(S, u), l(S, u), l(S, o)); | ||
} | ||
let r = L(re(e[e.length - 1].vector)); | ||
if (c || x && e.length === 1) | ||
F.push(k); | ||
else if (m) { | ||
let i = Z(k, r, p); | ||
for (let o = 1 / 29, u = o; u < 1; u += o) | ||
F.push(T(i, k, j * 3 * u)); | ||
} else | ||
F.push(l(k, f(r, p)), l(k, f(r, p * 0.99)), a(k, f(r, p * 0.99)), a(k, f(r, p))); | ||
} | ||
return D2.concat(F, R.reverse(), X); | ||
} | ||
function ce(e, t = {}) { | ||
var q; | ||
let { streamline: s = 0.5, size: h = 16, last: b = false } = t; | ||
if (e.length === 0) | ||
return []; | ||
let v = 0.15 + (1 - s) * 0.85, n = Array.isArray(e[0]) ? e : e.map(({ x: m, y: c, pressure: M = 0.5 }) => [m, c, M]); | ||
if (n.length === 2) { | ||
let m = n[1]; | ||
n = n.slice(0, -1); | ||
for (let c = 1; c < 5; c++) | ||
n.push(V(n[0], m, c / 4)); | ||
} | ||
n.length === 1 && (n = [...n, [...l(n[0], [1, 1]), ...n[0].slice(2)]]); | ||
let g = [{ point: [n[0][0], n[0][1]], pressure: n[0][2] >= 0 ? n[0][2] : 0.25, vector: [1, 1], distance: 0, runningLength: 0 }], E = false, z = 0, d = g[0], x = n.length - 1; | ||
for (let m = 1; m < n.length; m++) { | ||
let c = b && m === x ? n[m].slice(0, 2) : V(d.point, n[m], v); | ||
if (oe(d.point, c)) | ||
continue; | ||
let M = ue(c, d.point); | ||
if (z += M, m < x && !E) { | ||
if (z < h) | ||
continue; | ||
E = true; | ||
} | ||
d = { point: c, pressure: n[m][2] >= 0 ? n[m][2] : 0.5, vector: G(a(d.point, c)), distance: M, runningLength: z }, g.push(d); | ||
} | ||
return g[0].vector = ((q = g[1]) == null ? void 0 : q.vector) || [0, 0], g; | ||
} | ||
function me(e, t = {}) { | ||
return ie(ce(e, t), t); | ||
} | ||
var Te = me; | ||
// src/utils/index.ts | ||
function numSort(a, b) { | ||
return a - b; | ||
function numSort(a2, b) { | ||
return a2 - b; | ||
} | ||
function getSymbol(a) { | ||
if (a < 0) | ||
function getSymbol(a2) { | ||
if (a2 < 0) | ||
return -1; | ||
return 1; | ||
} | ||
function splitNum(a) { | ||
return [Math.abs(a), getSymbol(a)]; | ||
function splitNum(a2) { | ||
return [Math.abs(a2), getSymbol(a2)]; | ||
} | ||
@@ -84,2 +224,6 @@ function guid() { | ||
} | ||
onSelected(el) { | ||
} | ||
onUnselected() { | ||
} | ||
onStart(point) { | ||
@@ -103,2 +247,5 @@ return void 0; | ||
} | ||
get svgElement() { | ||
return this.drauu.el; | ||
} | ||
getMousePosition(event) { | ||
@@ -190,3 +337,3 @@ var _a, _b; | ||
getSvgData(points) { | ||
const stroke = (0, import_perfect_freehand.default)(points, __spreadValues({ | ||
const stroke = Te(points, __spreadValues({ | ||
size: this.brush.size * 2, | ||
@@ -502,5 +649,5 @@ thinning: 0.9, | ||
}; | ||
function line(a, b) { | ||
const lengthX = b.x - a.x; | ||
const lengthY = b.y - a.y; | ||
function line(a2, b) { | ||
const lengthX = b.x - a2.x; | ||
const lengthY = b.y - a2.y; | ||
return { | ||
@@ -528,5 +675,113 @@ length: Math.sqrt(Math.pow(lengthX, 2) + Math.pow(lengthY, 2)), | ||
function toSvgData(points) { | ||
return points.reduce((acc, point, i, a) => i === 0 ? `M ${point.x.toFixed(D)},${point.y.toFixed(D)}` : `${acc} ${bezierCommand(point, i, a)}`, ""); | ||
return points.reduce((acc, point, i, a2) => i === 0 ? `M ${point.x.toFixed(D)},${point.y.toFixed(D)}` : `${acc} ${bezierCommand(point, i, a2)}`, ""); | ||
} | ||
// src/models/eraser.ts | ||
var EraserModel = class extends BaseModel { | ||
constructor() { | ||
super(...arguments); | ||
this.pathSubFactor = 20; | ||
this.pathFragments = []; | ||
} | ||
onSelected(el) { | ||
const calculatePathFragments = (children, element) => { | ||
if (children && children.length) { | ||
for (let i = 0; i < children.length; i++) { | ||
const ele = children[i]; | ||
if (ele.getTotalLength) { | ||
const pathLength = ele.getTotalLength(); | ||
for (let j2 = 0; j2 < this.pathSubFactor; j2++) { | ||
const pos1 = ele.getPointAtLength(pathLength * j2 / this.pathSubFactor); | ||
const pos2 = ele.getPointAtLength(pathLength * (j2 + 1) / this.pathSubFactor); | ||
this.pathFragments.push({ | ||
x1: pos1.x, | ||
x2: pos2.x, | ||
y1: pos1.y, | ||
y2: pos2.y, | ||
segment: j2, | ||
element: element || ele | ||
}); | ||
} | ||
} else { | ||
if (ele.children) | ||
calculatePathFragments(ele.children, ele); | ||
} | ||
} | ||
} | ||
}; | ||
if (el) | ||
calculatePathFragments(el.children); | ||
} | ||
onUnselected() { | ||
this.pathFragments = []; | ||
} | ||
onStart(point) { | ||
this.svgPointPrevious = this.svgElement.createSVGPoint(); | ||
this.svgPointPrevious.x = point.x; | ||
this.svgPointPrevious.y = point.y; | ||
return void 0; | ||
} | ||
onMove(point) { | ||
this.svgPointCurrent = this.svgElement.createSVGPoint(); | ||
this.svgPointCurrent.x = point.x; | ||
this.svgPointCurrent.y = point.y; | ||
const erased = this.checkAndEraseElement(); | ||
this.svgPointPrevious = this.svgPointCurrent; | ||
return erased; | ||
} | ||
onEnd() { | ||
this.svgPointPrevious = void 0; | ||
this.svgPointCurrent = void 0; | ||
return true; | ||
} | ||
checkAndEraseElement() { | ||
const erased = []; | ||
if (this.pathFragments.length) { | ||
for (let i = 0; i < this.pathFragments.length; i++) { | ||
const segment = this.pathFragments[i]; | ||
const line2 = { | ||
x1: this.svgPointPrevious.x, | ||
x2: this.svgPointCurrent.x, | ||
y1: this.svgPointPrevious.y, | ||
y2: this.svgPointCurrent.y | ||
}; | ||
if (this.lineLineIntersect(segment, line2)) { | ||
segment.element.remove(); | ||
erased.push(i); | ||
} | ||
} | ||
} | ||
if (erased.length) | ||
this.pathFragments = this.pathFragments.filter((v, i) => !erased.includes(i)); | ||
return erased.length > 0; | ||
} | ||
lineLineIntersect(line1, line2) { | ||
const x1 = line1.x1; | ||
const x2 = line1.x2; | ||
const x3 = line2.x1; | ||
const x4 = line2.x2; | ||
const y1 = line1.y1; | ||
const y2 = line1.y2; | ||
const y3 = line2.y1; | ||
const y4 = line2.y2; | ||
const pt_denom = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4); | ||
const pt_x_num = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4); | ||
const pt_y_num = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4); | ||
const btwn = (a2, b1, b2) => { | ||
if (a2 >= b1 && a2 <= b2) | ||
return true; | ||
return a2 >= b2 && a2 <= b1; | ||
}; | ||
if (pt_denom === 0) { | ||
return false; | ||
} else { | ||
const pt = { | ||
x: pt_x_num / pt_denom, | ||
y: pt_y_num / pt_denom | ||
}; | ||
return btwn(pt.x, x1, x2) && btwn(pt.y, y1, y2) && btwn(pt.x, x3, x4) && btwn(pt.y, y3, y4); | ||
} | ||
} | ||
}; | ||
// src/models/index.ts | ||
@@ -539,3 +794,4 @@ function createModels(drauu) { | ||
rectangle: new RectModel(drauu), | ||
ellipse: new EllipseModel(drauu) | ||
ellipse: new EllipseModel(drauu), | ||
eraseLine: new EraserModel(drauu) | ||
}; | ||
@@ -573,3 +829,6 @@ } | ||
set mode(v) { | ||
const unselected = this._models[this.mode]; | ||
unselected.onUnselected(); | ||
this.options.brush.mode = v; | ||
this.model.onSelected(this.el); | ||
} | ||
@@ -596,5 +855,4 @@ get brush() { | ||
throw new Error("[drauu] can only mount to a SVG element"); | ||
if (!this.el.createSVGPoint) { | ||
throw new Error("[drauu] SVG element must be create by document.createElementNS('http://www.w3.org/2000/sv', 'svg')"); | ||
} | ||
if (!this.el.createSVGPoint) | ||
throw new Error("[drauu] SVG element must be create by document.createElementNS('http://www.w3.org/2000/svg', 'svg')"); | ||
this.svgPoint = this.el.createSVGPoint(); | ||
@@ -673,3 +931,3 @@ const target = this.resolveSelector(eventEl) || this.el; | ||
this._currentNode = this.model._eventDown(event); | ||
if (this._currentNode) | ||
if (this._currentNode && this.mode !== "eraseLine") | ||
this.el.appendChild(this._currentNode); | ||
@@ -676,0 +934,0 @@ this._emitter.emit("changed"); |
@@ -1,15 +0,10 @@ | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); | ||
var __require = typeof require !== "undefined" ? require : (x) => { | ||
throw new Error('Dynamic require of "' + x + '" is not supported'); | ||
}; | ||
var __reExport = (target, module2, desc) => { | ||
var __reExport = (target, module2, copyDefault, desc) => { | ||
if (module2 && typeof module2 === "object" || typeof module2 === "function") { | ||
for (let key of __getOwnPropNames(module2)) | ||
if (!__hasOwnProp.call(target, key) && key !== "default") | ||
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default")) | ||
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable }); | ||
@@ -19,13 +14,11 @@ } | ||
}; | ||
var __toModule = (module2) => { | ||
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2); | ||
}; | ||
var __toCommonJS = /* @__PURE__ */ ((cache) => { | ||
return (module2, temp) => { | ||
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp); | ||
}; | ||
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0); | ||
// src/index.ts | ||
__markAsModule(exports); | ||
// ../../node_modules/.pnpm/tsup@5.1.0_typescript@4.4.3/node_modules/tsup/assets/cjs_shims.js | ||
var importMetaUrlShim = typeof document === "undefined" ? new (require("url")).URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href; | ||
// src/index.ts | ||
__reExport(exports, __toModule(require("@drauu/core"))); | ||
var src_exports = {}; | ||
__reExport(src_exports, require("@drauu/core")); | ||
module.exports = __toCommonJS(src_exports); |
{ | ||
"name": "drauu", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"main": "dist/index.js", | ||
@@ -25,3 +25,3 @@ "module": "dist/index.mjs", | ||
"dependencies": { | ||
"@drauu/core": "0.2.1" | ||
"@drauu/core": "0.3.0" | ||
}, | ||
@@ -28,0 +28,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
33868
995
0
+ Added@drauu/core@0.3.0(transitive)
- Removed@drauu/core@0.2.1(transitive)
Updated@drauu/core@0.3.0