diff --git a/frontend/src/app/main/ui/workspace/shapes/path/editor.cljs b/frontend/src/app/main/ui/workspace/shapes/path/editor.cljs index 56189d104..aa99ec566 100644 --- a/frontend/src/app/main/ui/workspace/shapes/path/editor.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/path/editor.cljs @@ -21,7 +21,6 @@ [app.main.ui.workspace.shapes.path.common :as pc] [app.util.dom :as dom] [app.util.keyboard :as kbd] - [app.util.path.format :as upf] [clojure.set :refer [map-invert]] [goog.events :as events] [rumext.v2 :as mf])) @@ -331,7 +330,7 @@ (reset! hover-point (when (< (gpt/distance position point) (/ 10 zoom)) point))))) [:g.path-editor {:ref editor-ref} - [:path {:d (upf/format-path content) + [:path {:d (.toString content) :style {:fill "none" :stroke pc/accent-color :strokeWidth (/ 1 zoom)}}] diff --git a/frontend/src/app/main/ui/workspace/viewport/outline.cljs b/frontend/src/app/main/ui/workspace/viewport/outline.cljs index 0043a3fe8..bbc7931d2 100644 --- a/frontend/src/app/main/ui/workspace/viewport/outline.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/outline.cljs @@ -8,7 +8,6 @@ (:require [app.common.data :as d] [app.common.data.macros :as dm] - [app.common.exceptions :as ex] [app.common.files.helpers :as cfh] [app.common.geom.shapes :as gsh] [app.common.types.component :as ctk] @@ -17,7 +16,6 @@ [app.main.ui.hooks :as hooks] [app.main.ui.shapes.attrs :as attrs] [app.util.object :as obj] - [app.util.path.format :as upf] [clojure.set :as set] [rumext.v2 :as mf])) @@ -51,7 +49,7 @@ path-data (mf/with-memo [path? content] (when (and ^boolean path? (some? content)) - (d/nilv (ex/ignoring (upf/format-path content)) ""))) + (.toString content))) border-attrs (attrs/get-border-props shape) diff --git a/frontend/src/app/plugins/shape.cljs b/frontend/src/app/plugins/shape.cljs index 23808214d..28f607119 100644 --- a/frontend/src/app/plugins/shape.cljs +++ b/frontend/src/app/plugins/shape.cljs @@ -51,7 +51,6 @@ [app.plugins.text :as text] [app.plugins.utils :as u] [app.util.object :as obj] - [app.util.path.format :as upf] [beicon.v2.core :as rx] [cuerdas.core :as str])) @@ -1019,7 +1018,7 @@ (u/display-not-valid :makeMask (:type shape)) :else - (upf/format-path (:content shape))))) + (str (:content shape))))) ;; Text shapes :getRange @@ -1310,7 +1309,7 @@ (cond-> (or (cfh/path-shape? data) (cfh/bool-shape? data)) (crc/add-properties! {:name "content" - :get #(-> % u/proxy->shape :content upf/format-path) + :get #(-> % u/proxy->shape :content str) :set (fn [_ value] (let [content (svg.path/parse value)] diff --git a/frontend/src/app/util/path/format.cljs b/frontend/src/app/util/path/format.cljs deleted file mode 100644 index cab80ceb2..000000000 --- a/frontend/src/app/util/path/format.cljs +++ /dev/null @@ -1,144 +0,0 @@ -;; This Source Code Form is subject to the terms of the Mozilla Public -;; License, v. 2.0. If a copy of the MPL was not distributed with this -;; file, You can obtain one at http://mozilla.org/MPL/2.0/. -;; -;; Copyright (c) KALEIDOS INC - -(ns app.util.path.format - "Legacy path data formater, replaced by - app.common.types.path.PathData type. - - WARNING: Pending to be removed from codebase once completly unused" - (:require - [app.common.geom.point :as gpt] - [app.common.types.path.helpers :refer [segment->point]] - [app.util.array :as arr])) - -(defn pt= - "Check if two points are close" - [p1 p2] - (< (gpt/distance p1 p2) 0.1)) - -(def path-precision 3) - -(defn- join-params - ([a] - (js* "\"\"+~{}" - (.toFixed a path-precision))) - ([a b] - (js* "\"\"+~{}+\",\"+~{}" - (.toFixed a path-precision) - (.toFixed b path-precision))) - ([a b c] - (js* "\"\"+~{}+\",\"+~{}+\",\"+~{}" - (.toFixed a path-precision) - (.toFixed b path-precision) - (.toFixed c path-precision))) - ([a b c d] - (js* "\"\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}" - (.toFixed a path-precision) - (.toFixed b path-precision) - (.toFixed c path-precision) - (.toFixed d path-precision))) - ([a b c d e] - (js* "\"\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}" - (.toFixed a path-precision) - (.toFixed b path-precision) - (.toFixed c path-precision) - (.toFixed d path-precision) - (.toFixed e path-precision))) - ([a b c d e f] - (js* "\"\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}" - (.toFixed a path-precision) - (.toFixed b path-precision) - (.toFixed c path-precision) - (.toFixed d path-precision) - (.toFixed e path-precision) - (.toFixed f path-precision))) - ([a b c d e f g] - (js* "\"\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}" - (.toFixed a path-precision) - (.toFixed b path-precision) - (.toFixed c path-precision) - (.toFixed d path-precision) - (.toFixed e path-precision) - (.toFixed f path-precision) - (.toFixed g path-precision)))) - -(defn- translate-params - [command {:keys [x y] :as params}] - (case command - (:move-to :line-to :smooth-quadratic-bezier-curve-to) - (join-params x y) - - :close-path - "" - - (:line-to-horizontal :line-to-vertical) - (:value params) - - :curve-to - (let [{:keys [c1x c1y c2x c2y]} params] - (join-params (or c1x x) (or c1y y) (or c2x x) (or c2y y) x y)) - - (:smooth-curve-to :quadratic-bezier-curve-to) - (let [{:keys [cx cy]} params] - (join-params cx cy x y)) - - :elliptical-arc - (let [{:keys [rx ry x-axis-rotation large-arc-flag sweep-flag]} params] - (join-params rx ry x-axis-rotation large-arc-flag sweep-flag x y)) - - "")) - -(defn- translate-command - [cname] - (case cname - :move-to "M" - :close-path "Z" - :line-to "L" - :line-to-horizontal "H" - :line-to-vertical "V" - :curve-to "C" - :smooth-curve-to "S" - :quadratic-bezier-curve-to "Q" - :smooth-quadratic-bezier-curve-to "T" - :elliptical-arc "A" - "")) - - -(defn- command->string - [{:keys [command relative params]}] - (let [cmd (cond-> (translate-command command) - relative (.toLowerCase)) - prm (translate-params command params)] - (js* "~{} + ~{}" cmd prm))) - -(defn- set-point - [command {:keys [x y]}] - (update command :params assoc :x x :y y)) - -(defn format-path [content] - (try - (let [result (make-array (count content))] - (reduce (fn [last-move current] - (let [point (segment->point current) - current-move? (= :move-to (:command current)) - last-move (if current-move? point last-move)] - - (if (and (not current-move?) (pt= last-move point)) - (arr/conj! result (command->string (set-point current last-move))) - (arr/conj! result (command->string current))) - - (when (and (not current-move?) (pt= last-move point)) - (arr/conj! result "Z")) - - last-move)) - nil - content) - (.join ^js result "")) - - (catch :default err - (.error js/console err) - nil))) -