index.es.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. /*!vue3-sketch-ruler v1.3.62022年11月Fri Nov 04 2022 18:18:02 GMT+0800 (中国标准时间)制作*/
  2. import { defineComponent, ref, onMounted, computed, reactive, watch } from "vue-demi";
  3. import { withDirectives, openBlock, createElementBlock, normalizeStyle, createElementVNode, toDisplayString, vShow, resolveComponent, normalizeClass, createVNode, Fragment, renderList, createBlock } from "vue";
  4. var rulerLine_vue_vue_type_style_index_0_scoped_true_lang = /* @__PURE__ */ (() => ".line[data-v-5dea28d6]{pointer-events:auto;position:absolute}.line .action[data-v-5dea28d6]{position:absolute;display:flex;justify-content:center;align-items:center}.line .value[data-v-5dea28d6]{pointer-events:none;transform:scale(.83)}.line .del[data-v-5dea28d6]{padding:3px 5px;cursor:pointer;visibility:hidden}.line:hover .del[data-v-5dea28d6]{visibility:visible}\n")();
  5. var _export_sfc = (sfc, props) => {
  6. const target = sfc.__vccOpts || sfc;
  7. for (const [key, val] of props) {
  8. target[key] = val;
  9. }
  10. return target;
  11. };
  12. const _sfc_main$3 = defineComponent({
  13. name: "LineRuler",
  14. props: {
  15. scale: Number,
  16. thick: Number,
  17. palette: Object,
  18. index: Number,
  19. start: Number,
  20. vertical: Boolean,
  21. value: Number,
  22. isShowReferLine: Boolean
  23. },
  24. emits: ["onMouseDown", "onRelease", "onRemove"],
  25. setup(props, { emit }) {
  26. const startValue = ref(0);
  27. const showLine = ref(true);
  28. onMounted(() => {
  29. startValue.value = props.value;
  30. });
  31. const setShowLine = (offset2) => {
  32. showLine.value = offset2 >= 0;
  33. };
  34. const offset = computed(() => {
  35. const offset2 = (startValue.value - props.start) * props.scale;
  36. setShowLine(offset2);
  37. const positionValue = offset2 + "px";
  38. const position = props.vertical ? { top: positionValue } : { left: positionValue };
  39. return position;
  40. });
  41. const borderCursor = computed(() => {
  42. var _a;
  43. const borderValue = `1px solid ${(_a = props.palette) == null ? void 0 : _a.lineColor}`;
  44. const border = props.vertical ? { borderTop: borderValue } : { borderLeft: borderValue };
  45. const cursorValue = props.isShowReferLine ? props.vertical ? "ns-resize" : "ew-resize" : "none";
  46. return {
  47. cursor: cursorValue,
  48. ...border
  49. };
  50. });
  51. const actionStyle = computed(() => {
  52. const actionStyle2 = props.vertical ? { left: props.thick + "px" } : { top: props.thick + "px" };
  53. return actionStyle2;
  54. });
  55. const handleDown = (e) => {
  56. const startD = props.vertical ? e.clientY : e.clientX;
  57. const initValue = startValue.value;
  58. emit("onMouseDown");
  59. const onMove = (e2) => {
  60. const currentD = props.vertical ? e2.clientY : e2.clientX;
  61. const newValue = Math.round(initValue + (currentD - startD) / props.scale);
  62. startValue.value = newValue;
  63. };
  64. const onEnd = () => {
  65. emit("onRelease", startValue.value, props.index);
  66. document.removeEventListener("mousemove", onMove);
  67. document.removeEventListener("mouseup", onEnd);
  68. };
  69. document.addEventListener("mousemove", onMove);
  70. document.addEventListener("mouseup", onEnd);
  71. };
  72. const handleRemove = () => {
  73. emit("onRemove", props.index);
  74. };
  75. return {
  76. startValue,
  77. showLine,
  78. offset,
  79. borderCursor,
  80. actionStyle,
  81. handleDown,
  82. handleRemove
  83. };
  84. }
  85. });
  86. const _hoisted_1$2 = { class: "value" };
  87. function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
  88. return withDirectives((openBlock(), createElementBlock("div", {
  89. class: "line",
  90. style: normalizeStyle([_ctx.offset, _ctx.borderCursor]),
  91. onMousedown: _cache[1] || (_cache[1] = (...args) => _ctx.handleDown && _ctx.handleDown(...args))
  92. }, [
  93. createElementVNode("div", {
  94. class: "action",
  95. style: normalizeStyle(_ctx.actionStyle)
  96. }, [
  97. createElementVNode("span", {
  98. class: "del",
  99. onClick: _cache[0] || (_cache[0] = (...args) => _ctx.handleRemove && _ctx.handleRemove(...args))
  100. }, "\xD7"),
  101. createElementVNode("span", _hoisted_1$2, toDisplayString(_ctx.startValue), 1)
  102. ], 4)
  103. ], 36)), [
  104. [vShow, _ctx.showLine]
  105. ]);
  106. }
  107. var RulerLine = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["render", _sfc_render$3], ["__scopeId", "data-v-5dea28d6"]]);
  108. const getGridSize = (scale) => {
  109. if (scale <= 0.25)
  110. return 40;
  111. if (scale <= 0.5)
  112. return 20;
  113. if (scale <= 1)
  114. return 10;
  115. if (scale <= 2)
  116. return 5;
  117. if (scale <= 4)
  118. return 2;
  119. return 1;
  120. };
  121. const FONT_SCALE = 0.83;
  122. const drawCavaseRuler = (ctx, start, selectStart, selectLength, options, h) => {
  123. const { scale, width, height, ratio, palette } = options;
  124. const { bgColor, fontColor, shadowColor, longfgColor, shortfgColor } = palette;
  125. ctx.scale(ratio, ratio);
  126. ctx.clearRect(0, 0, width, height);
  127. ctx.fillStyle = bgColor;
  128. ctx.fillRect(0, 0, width, height);
  129. if (selectLength) {
  130. const shadowX = (selectStart - start) * scale;
  131. const shadowWidth = selectLength * scale;
  132. ctx.fillStyle = shadowColor;
  133. h ? ctx.fillRect(shadowX, 0, shadowWidth, height * 3 / 8) : ctx.fillRect(0, shadowX, width * 3 / 8, shadowWidth);
  134. }
  135. const gridSize = getGridSize(scale);
  136. const gridPixel = gridSize * scale;
  137. const gridSize10 = gridSize * 10;
  138. const gridPixel10 = gridSize10 * scale;
  139. const startValue = Math.floor(start / gridSize) * gridSize;
  140. const startValue10 = Math.floor(start / gridSize10) * gridSize10;
  141. const offsetX = (startValue - start) / gridSize * gridPixel;
  142. const offsetX10 = (startValue10 - start) / gridSize10 * gridPixel10;
  143. const endValue = start + Math.ceil((h ? width : height) / scale);
  144. ctx.beginPath();
  145. ctx.fillStyle = fontColor;
  146. ctx.strokeStyle = longfgColor;
  147. for (let value = startValue10, count = 0; value < endValue; value += gridSize10, count++) {
  148. const x = offsetX10 + count * gridPixel10 + 0.5;
  149. h ? ctx.moveTo(x, 0) : ctx.moveTo(0, x);
  150. ctx.save();
  151. h ? ctx.translate(x, height * 0.4) : ctx.translate(width * 0.4, x);
  152. if (!h) {
  153. ctx.rotate(-Math.PI / 2);
  154. }
  155. ctx.scale(FONT_SCALE / ratio, FONT_SCALE / ratio);
  156. ctx.fillText(value.toString(), 4 * ratio, 7 * ratio);
  157. ctx.restore();
  158. h ? ctx.lineTo(x, height * 9 / 16) : ctx.lineTo(width * 9 / 16, x);
  159. }
  160. ctx.stroke();
  161. ctx.closePath();
  162. ctx.beginPath();
  163. ctx.strokeStyle = shortfgColor;
  164. for (let value = startValue, count = 0; value < endValue; value += gridSize, count++) {
  165. const x = offsetX + count * gridPixel + 0.5;
  166. h ? ctx.moveTo(x, 0) : ctx.moveTo(0, x);
  167. if (value % gridSize10 !== 0) {
  168. h ? ctx.lineTo(x, height * 1 / 4) : ctx.lineTo(width * 1 / 4, x);
  169. }
  170. }
  171. ctx.stroke();
  172. ctx.closePath();
  173. ctx.setTransform(1, 0, 0, 1, 0, 0);
  174. };
  175. const _sfc_main$2 = defineComponent({
  176. name: "CanvasRuler",
  177. props: {
  178. showIndicator: Boolean,
  179. valueNum: Number,
  180. scale: Number,
  181. ratio: Number,
  182. palette: Object,
  183. vertical: Boolean,
  184. start: Number,
  185. width: Number,
  186. height: Number,
  187. selectStart: Number,
  188. selectLength: Number
  189. },
  190. emits: ["onAddLine", "update:showIndicator", "update:valueNum"],
  191. setup(props, { emit }) {
  192. const state = reactive({
  193. canvasContext: null
  194. });
  195. let ratio = 1;
  196. const canvas = ref(null);
  197. onMounted(() => {
  198. ratio = props.ratio || window.devicePixelRatio || 1;
  199. initCanvasRef();
  200. updateCanvasContext(ratio);
  201. drawRuler(ratio);
  202. });
  203. const initCanvasRef = () => {
  204. state.canvasContext = canvas.value && canvas.value.getContext("2d");
  205. };
  206. const updateCanvasContext = (ratio2) => {
  207. if (canvas.value) {
  208. canvas.value.width = props.width * ratio2;
  209. canvas.value.height = props.height * ratio2;
  210. const ctx = state.canvasContext;
  211. if (ctx) {
  212. ctx.font = `${12 * ratio2}px -apple-system,
  213. "Helvetica Neue", ".SFNSText-Regular",
  214. "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB",
  215. "Microsoft YaHei", "WenQuanYi Zen Hei", sans-serif`;
  216. ctx.lineWidth = 1;
  217. ctx.textBaseline = "middle";
  218. }
  219. }
  220. };
  221. const drawRuler = (ratio2) => {
  222. const options = {
  223. scale: props.scale,
  224. width: props.width,
  225. height: props.height,
  226. palette: props.palette,
  227. ratio: ratio2
  228. };
  229. if (state.canvasContext) {
  230. drawCavaseRuler(state.canvasContext, props.start, props.selectStart, props.selectLength, options, !props.vertical);
  231. }
  232. };
  233. watch(() => props.start, () => drawRuler(ratio));
  234. watch([() => props.width, () => props.height], () => {
  235. updateCanvasContext(ratio);
  236. drawRuler(ratio);
  237. });
  238. const handle = (e, key) => {
  239. const getValueByOffset = (offset2, start, scale) => Math.round(start + offset2 / scale);
  240. const offset = props.vertical ? e.offsetY : e.offsetX;
  241. const value = getValueByOffset(offset, props.start, props.scale);
  242. switch (key) {
  243. case "click":
  244. emit("onAddLine", value);
  245. break;
  246. case "enter":
  247. emit("update:valueNum", value);
  248. emit("update:showIndicator", true);
  249. break;
  250. default:
  251. emit("update:valueNum", value);
  252. break;
  253. }
  254. };
  255. return {
  256. handle,
  257. canvas
  258. };
  259. }
  260. });
  261. function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
  262. return openBlock(), createElementBlock("canvas", {
  263. ref: "canvas",
  264. class: "ruler",
  265. onClick: _cache[0] || (_cache[0] = ($event) => _ctx.handle($event, "click")),
  266. onMouseenter: _cache[1] || (_cache[1] = ($event) => _ctx.handle($event, "enter")),
  267. onMousemove: _cache[2] || (_cache[2] = ($event) => _ctx.handle($event, "move")),
  268. onMouseleave: _cache[3] || (_cache[3] = ($event) => _ctx.$emit("update:showIndicator", false))
  269. }, null, 544);
  270. }
  271. var CanvasRuler = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["render", _sfc_render$2]]);
  272. const wrapperProps = {
  273. scale: Number,
  274. ratio: Number,
  275. thick: Number,
  276. palette: Object,
  277. vertical: {
  278. type: Boolean,
  279. default: true
  280. },
  281. width: {
  282. type: Number,
  283. default: 200
  284. },
  285. height: {
  286. type: Number,
  287. default: 200
  288. },
  289. start: {
  290. type: Number,
  291. default: 0
  292. },
  293. lines: {
  294. type: Array,
  295. default: () => []
  296. },
  297. selectStart: {
  298. type: Number
  299. },
  300. selectLength: {
  301. type: Number
  302. },
  303. isShowReferLine: {
  304. type: Boolean
  305. }
  306. };
  307. var rulerWrapper_vue_vue_type_style_index_0_scoped_true_lang = /* @__PURE__ */ (() => ".line[data-v-b6c23352],.h-container[data-v-b6c23352],.v-container[data-v-b6c23352]{position:absolute}.h-container .lines[data-v-b6c23352],.v-container .lines[data-v-b6c23352]{pointer-events:none}.h-container:hover .lines[data-v-b6c23352],.v-container:hover .lines[data-v-b6c23352]{pointer-events:auto}.h-container[data-v-b6c23352]{top:0}.h-container .line[data-v-b6c23352]{top:0;height:100vh;padding-left:5px}.h-container .line .action[data-v-b6c23352]{transform:translate(-24px)}.h-container .line .action .value[data-v-b6c23352]{margin-left:4px}.h-container .indicator[data-v-b6c23352]{top:0;height:100vw}.h-container .indicator .value[data-v-b6c23352]{width:auto;padding:0 2px;margin-top:4px;margin-left:4px}.v-container[data-v-b6c23352]{left:0}.v-container .line[data-v-b6c23352]{left:0;width:100vw;padding-top:5px}.v-container .line .action[data-v-b6c23352]{transform:translateY(-24px);flex-direction:column}.v-container .line .action .value[data-v-b6c23352]{margin-top:4px}.v-container .indicator[data-v-b6c23352]{width:100vw}.v-container .indicator .value[data-v-b6c23352]{left:0;width:auto;padding:0 2px;margin-top:-5px;margin-left:2px;transform:rotate(-90deg);transform-origin:0 0}\n")();
  308. const _sfc_main$1 = defineComponent({
  309. name: "RulerWrapper",
  310. components: {
  311. CanvasRuler,
  312. RulerLine
  313. },
  314. props: wrapperProps,
  315. setup(props) {
  316. const showIndicator = ref(false);
  317. const valueNum = ref(0);
  318. const rwClassName = computed(() => {
  319. const className = props.vertical ? "v-container" : "h-container";
  320. return className;
  321. });
  322. const rwStyle = computed(() => {
  323. const hContainer = {
  324. width: `calc(100% - ${props.thick}px)`,
  325. height: `${props.thick + 1}px`,
  326. left: `${props.thick}px`
  327. };
  328. const vContainer = {
  329. width: `${props.thick && props.thick + 1}px`,
  330. height: `calc(100% - ${props.thick}px)`,
  331. top: `${props.thick}px`
  332. };
  333. return props.vertical ? vContainer : hContainer;
  334. });
  335. const indicatorStyle = computed(() => {
  336. var _a;
  337. const indicatorOffset = (valueNum.value - props.start) * props.scale;
  338. let positionKey = "top";
  339. let boderKey = "borderLeft";
  340. positionKey = props.vertical ? "top" : "left";
  341. boderKey = props.vertical ? "borderBottom" : "borderLeft";
  342. return {
  343. [positionKey]: indicatorOffset + "px",
  344. [boderKey]: `1px solid ${(_a = props.palette) == null ? void 0 : _a.lineColor}`
  345. };
  346. });
  347. const handleNewLine = (value) => {
  348. props.lines.push(value);
  349. };
  350. const handleLineRelease = (value, index) => {
  351. const offset = value - props.start;
  352. const maxOffset = (props.vertical ? props.height : props.width) / props.scale;
  353. if (offset < 0 || offset > maxOffset) {
  354. handleLineRemove(index);
  355. } else {
  356. props.lines[index] = value;
  357. }
  358. };
  359. const handleLineRemove = (index) => {
  360. props.lines.splice(index, 1);
  361. };
  362. return {
  363. showIndicator,
  364. valueNum,
  365. rwClassName,
  366. rwStyle,
  367. indicatorStyle,
  368. handleNewLine,
  369. handleLineRelease,
  370. handleLineRemove
  371. };
  372. }
  373. });
  374. const _hoisted_1$1 = { class: "lines" };
  375. const _hoisted_2 = { class: "value" };
  376. function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
  377. const _component_CanvasRuler = resolveComponent("CanvasRuler");
  378. const _component_RulerLine = resolveComponent("RulerLine");
  379. return openBlock(), createElementBlock("div", {
  380. class: normalizeClass(_ctx.rwClassName),
  381. style: normalizeStyle(_ctx.rwStyle)
  382. }, [
  383. createVNode(_component_CanvasRuler, {
  384. vertical: _ctx.vertical,
  385. scale: _ctx.scale,
  386. width: _ctx.width,
  387. height: _ctx.height,
  388. start: _ctx.start,
  389. ratio: _ctx.ratio,
  390. "select-start": _ctx.selectStart,
  391. "select-length": _ctx.selectLength,
  392. palette: _ctx.palette,
  393. valueNum: _ctx.valueNum,
  394. "onUpdate:valueNum": _cache[0] || (_cache[0] = ($event) => _ctx.valueNum = $event),
  395. showIndicator: _ctx.showIndicator,
  396. "onUpdate:showIndicator": _cache[1] || (_cache[1] = ($event) => _ctx.showIndicator = $event),
  397. onOnAddLine: _ctx.handleNewLine
  398. }, null, 8, ["vertical", "scale", "width", "height", "start", "ratio", "select-start", "select-length", "palette", "valueNum", "showIndicator", "onOnAddLine"]),
  399. withDirectives(createElementVNode("div", _hoisted_1$1, [
  400. (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.lines, (v, i) => {
  401. return openBlock(), createBlock(_component_RulerLine, {
  402. key: v + i,
  403. index: i,
  404. value: v >> 0,
  405. scale: _ctx.scale,
  406. start: _ctx.start,
  407. thick: _ctx.thick,
  408. palette: _ctx.palette,
  409. vertical: _ctx.vertical,
  410. "is-show-refer-line": _ctx.isShowReferLine,
  411. onOnRemove: _ctx.handleLineRemove,
  412. onOnRelease: _ctx.handleLineRelease
  413. }, null, 8, ["index", "value", "scale", "start", "thick", "palette", "vertical", "is-show-refer-line", "onOnRemove", "onOnRelease"]);
  414. }), 128))
  415. ], 512), [
  416. [vShow, _ctx.isShowReferLine]
  417. ]),
  418. withDirectives(createElementVNode("div", {
  419. class: "indicator",
  420. style: normalizeStyle(_ctx.indicatorStyle)
  421. }, [
  422. createElementVNode("div", _hoisted_2, toDisplayString(_ctx.valueNum), 1)
  423. ], 4), [
  424. [vShow, _ctx.showIndicator]
  425. ])
  426. ], 6);
  427. }
  428. var RulerWrapper = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1], ["__scopeId", "data-v-b6c23352"]]);
  429. const eye64 = `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVCAYAAACpF6WWAAAAAXNSR0IArs4c6QAAAopJREFUOE/FlE9IVEEcx7+/N9ouds1Mu0QUSFZYdIgoUqQoKPBQHsKozpXE7jbTO/U8xLJvn6usBHWQ6hBFXupSkQeVbh0KJEPp0sH+eLGTsKs77xcj78m0ax0E8cHjzZv5zef3/c33xxA24KENYGJzoEEQbNNaN4Zh2OQ4znwYhr9c1/39vwrXVDo0NNS0tLR0GYB5D64BmAMwzMyvlFKz1es10Hw+f4mZ7wHYBeA9gNdENFepVOaEEM3M3OI4Thczn41gt6WUgQ3+C+r7/h0AWQD3mXnYqPA8L9nQ0HCemduIaFpKOWoAhUJhT6VSuQXgOjP3K6W8GLwKzeVyp4jonR0QBEErM48w8zFLyayUsjX+z+VyHhHdZebTSqkxM78CHRgYOKS1/ghgVErZY214RkQ7ADyRUj72ff8qgCtmXUrZGcf5vv8CwEUhxOF0Ov1pBRpla5dSdseBhUJhpznH6tIsZb1KqacW+BGArUaUXX63UuplHJTNZjuEEONSyhozfd/n6mQ1RkXZL2itz7mu+80EDA4ONi8vL/8AcM2UbikyR2BU9cSmmTU70YqKIAj2hWFo2uenlHK/BRg3Y2aeNO5GyU8S0ZbFxcUuz/NKEXAGQKPjOCcymcyX1dIi8DSAiWQyeaavr68cbSgCuBknYubnQoj+TCYzUywWE6VS6S2ADsdx2gxw1X3L7SNENMbMnwE8qK+vf5NKpRaMaeVyeW8ikfiaSqW+R7BuZr5BRMe11p2u607U9Gk8kc/ntzPzQwCmExYATDLzVBiGE0KIowAOADDf3QA+aK2VDaxRajto3K+rq+tl5nYAzQBamHmeiOYBTGmtR6ph/1Rqg9c73pz7dD1qN0TpHyNQRCUDJXrAAAAAAElFTkSuQmCC`;
  430. const closeEye64 = `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVCAYAAACpF6WWAAAAAXNSR0IArs4c6QAAAjtJREFUOE/NlD9oFEEUxn9v9ghC0hpRUogIAUmniGAT/5Q2FrETPSNRJILg7RwimI0ox85eQFCEBGIUO1PYpFM0jSConQoBEZGgGPsgl+w+2eM2bC57SopAFqYZ3v7m+977ZoQt+GQLmGxPaBiGgYiMWWvXBHZUGoZhH3BERPYC+4F+4Keq/urt7b1RLpf/ZEBVHa9Wq0HWyg3QKIoGVPU8cA7wgK/pUtXPQJ8xZk+pVBpuNBqXUoUiEvi+P56fzTpo6+SbwHNg1lo7WzTITGEKXFlZeeB53tVCpa3CK8AFa+1cBgvD8LKIXAQOJkkyICJDeYVBEJS6u7s/qeoLa+1o+l9TqXNuBLhmjDlbqVQ+5ICjInIfOBPH8W9jzGCR5YmJiRNxHM+papgqzqDvgSlr7VTernPuO3An3c9bBt74vv+yrdaKyLDv+/1Sq9UGPc97nY9EVuycU2AQOA7cAm4Dr4D5TvVxHB9rKo2iaEFVp621Ln96FEUngaOqGmSxabVqsh3a2h+x1h5qQjNrae/yE4+iaCwDJkky73neTuBZe129Xk+H+BS4l7ZqLVIZ2BhzuFKpvMsDVXXWGPMxFdAedOfcKeCRqj7MYrUhpz09PfXl5eXrectFWXXODQHpOq2qd/95o/JXr6ura3J1dXU6SZIfwKKIHAD2tVYMPBGRx77vN10UXtO85fTkmZmZHUtLSzUR2QXsBhaAL6r6DXhbrVYXi1yss59GqOgub/bN3Z7v6X/tb9Zmp/q/kN8s+lJb8oEAAAAASUVORK5CYII=`;
  431. const sketchRulerProps = {
  432. eyeIcon: {
  433. type: String
  434. },
  435. closeEyeIcon: {
  436. type: String
  437. },
  438. scale: {
  439. type: Number,
  440. default: 1
  441. },
  442. ratio: {
  443. type: Number
  444. },
  445. thick: {
  446. type: Number,
  447. default: 16
  448. },
  449. palette: Object,
  450. startX: {
  451. type: Number
  452. },
  453. startY: {
  454. type: Number,
  455. default: 0
  456. },
  457. width: {
  458. type: Number,
  459. default: 200
  460. },
  461. height: {
  462. type: Number,
  463. default: 200
  464. },
  465. shadow: {
  466. type: Object,
  467. default: () => {
  468. return {
  469. x: 0,
  470. y: 0,
  471. width: 0,
  472. height: 0
  473. };
  474. }
  475. },
  476. lines: {
  477. type: Object,
  478. default: () => {
  479. return {
  480. h: [],
  481. v: []
  482. };
  483. }
  484. },
  485. isShowReferLine: {
  486. type: Boolean,
  487. default: true
  488. }
  489. };
  490. var index_vue_vue_type_style_index_0_lang = /* @__PURE__ */ (() => '@charset "UTF-8";.style-ruler{position:absolute;z-index:3;width:100%;height:100%;overflow:hidden;font-size:12px;pointer-events:none}.style-ruler span{line-height:1}.corner{position:absolute;top:0;left:0;pointer-events:auto;cursor:pointer;box-sizing:content-box;transition:all .2s ease-in-out}.indicator{position:absolute;pointer-events:none}.indicator .value{position:absolute;background:white}.ruler{width:100%;height:100%;pointer-events:auto}\n')();
  491. const _sfc_main = defineComponent({
  492. name: "SketchRule",
  493. components: {
  494. RulerWrapper
  495. },
  496. props: sketchRulerProps,
  497. emits: ["onCornerClick"],
  498. setup(props, { emit }) {
  499. let showReferLine = ref(true);
  500. showReferLine.value = props.isShowReferLine;
  501. const paletteCpu = computed(() => {
  502. function merge(obj, o) {
  503. Object.keys(obj).forEach((key) => {
  504. if (key && obj.hasOwnProperty(key)) {
  505. if (typeof o["key"] === "object") {
  506. obj[key] = merge(obj[key], o[key]);
  507. } else if (o.hasOwnProperty(key)) {
  508. obj[key] = o[key];
  509. }
  510. }
  511. });
  512. return obj;
  513. }
  514. const finalObj = merge({
  515. bgColor: "rgba(225,225,225, 0)",
  516. longfgColor: "#BABBBC",
  517. shortfgColor: "#C8CDD0",
  518. fontColor: "#7D8694",
  519. shadowColor: "#E8E8E8",
  520. lineColor: "#EB5648",
  521. borderColor: "#DADADC",
  522. cornerActiveColor: "rgb(235, 86, 72, 0.6)",
  523. menu: {
  524. bgColor: "#fff",
  525. dividerColor: "#DBDBDB",
  526. listItem: {
  527. textColor: "#415058",
  528. hoverTextColor: "#298DF8",
  529. disabledTextColor: "rgba(65, 80, 88, 0.4)",
  530. bgColor: "#fff",
  531. hoverBgColor: "#F2F2F2"
  532. }
  533. }
  534. }, props.palette || {});
  535. return finalObj;
  536. });
  537. const cornerStyle = computed(() => {
  538. return {
  539. backgroundImage: showReferLine.value ? `url(${props.eyeIcon || eye64})` : `url(${props.closeEyeIcon || closeEye64})`,
  540. width: props.thick + "px",
  541. height: props.thick + "px",
  542. borderRight: `1px solid ${paletteCpu.value.borderColor}`,
  543. borderBottom: `1px solid ${paletteCpu.value.borderColor}`
  544. };
  545. });
  546. const onCornerClick = (e) => {
  547. showReferLine.value = !showReferLine.value;
  548. emit("onCornerClick", showReferLine.value);
  549. };
  550. watch([() => props.isShowReferLine], () => {
  551. showReferLine.value = props.isShowReferLine;
  552. });
  553. return {
  554. showReferLine,
  555. paletteCpu,
  556. cornerStyle,
  557. onCornerClick
  558. };
  559. }
  560. });
  561. const _hoisted_1 = {
  562. id: "mb-ruler",
  563. class: "style-ruler mb-ruler"
  564. };
  565. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  566. const _component_RulerWrapper = resolveComponent("RulerWrapper");
  567. return openBlock(), createElementBlock("div", _hoisted_1, [
  568. createVNode(_component_RulerWrapper, {
  569. vertical: false,
  570. width: _ctx.width,
  571. height: _ctx.thick,
  572. "is-show-refer-line": _ctx.showReferLine,
  573. thick: _ctx.thick,
  574. ratio: _ctx.ratio,
  575. start: _ctx.startX,
  576. lines: _ctx.lines.h,
  577. "select-start": _ctx.shadow.x,
  578. "select-length": _ctx.shadow.width,
  579. scale: _ctx.scale,
  580. palette: _ctx.paletteCpu
  581. }, null, 8, ["width", "height", "is-show-refer-line", "thick", "ratio", "start", "lines", "select-start", "select-length", "scale", "palette"]),
  582. createVNode(_component_RulerWrapper, {
  583. vertical: true,
  584. width: _ctx.thick,
  585. height: _ctx.height,
  586. "is-show-refer-line": _ctx.showReferLine,
  587. thick: _ctx.thick,
  588. ratio: _ctx.ratio,
  589. start: _ctx.startY,
  590. lines: _ctx.lines.v,
  591. "select-start": _ctx.shadow.y,
  592. "select-length": _ctx.shadow.height,
  593. scale: _ctx.scale,
  594. palette: _ctx.paletteCpu
  595. }, null, 8, ["width", "height", "is-show-refer-line", "thick", "ratio", "start", "lines", "select-start", "select-length", "scale", "palette"]),
  596. createElementVNode("a", {
  597. class: "corner",
  598. style: normalizeStyle(_ctx.cornerStyle),
  599. onClick: _cache[0] || (_cache[0] = (...args) => _ctx.onCornerClick && _ctx.onCornerClick(...args))
  600. }, null, 4)
  601. ]);
  602. }
  603. var SketchRule = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
  604. export { SketchRule, SketchRule as default };