e2c35919880e6a25ed6278473fb04081d785e4b62877a35ddadeaea74d8f1262d0466f588da6a01da9c39f56714c585ac8e9433cefa63ba640f0553af1e2d5 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. # vue3-sketch-ruler
  2. >In using vue3/vue2, zoom operation for page display
  3. [![]( https://camo.githubusercontent.com/28479a7a834310a667f36760a27283f7389e864a/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f6c2f76322d646174657069636b65722e737667)]( https://camo.githubusercontent.com/28479a7a834310a667f36760a27283f7389e864a/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f6c2f76322d646174657069636b65722e737667) [![build status]( https://github.com/kakajun/vue3-sketch-ruler/actions/workflows/gh-pages.yml/badge.svg?branch=1x)]( https://github.com/kakajun/vue3-sketch-ruler/actions/workflows/gh-pages.yml)
  4. English | [中文](https://github.com/kakajun/vue3-sketch-ruler/blob/1x/README.CH.md)
  5. 时隔半年,重启mater的新版开发, 大家有兴趣的可以加我微信: ka132300 拉入群, 大家一起讨论
  6. 效果图如下
  7. ![image](https://github.com/kakajun/vue3-sketch-ruler/blob/1x/newruler.png)
  8. 🚀 Features
  9. --
  10. - 💪 Vue 3 Composition API
  11. - 🔥 Written in TypeScript
  12. - 🔋 SSR Friendly
  13. - 💡 works for both Vue. js 2/3.
  14. # Vue 3 + vite + TS package sketchrule
  15. ## Explain
  16. ---
  17. Application scope of plug-in: it is suitable for operating page scaling tools on low code platforms, such as drawing tools, large screen visualization, drawing tools, drawing monsters, etc., with scaling effects similar to PS
  18. Use Vue Demi, a set of code, package plug-ins in two environments, and support the use in vue2 and vue3 at the same time (when NPM installs plug-ins, it will automatically judge to load the code of the corresponding Vue version)
  19. Application case: [Avenue large screen visualization tool](https://data.avuejs.com/build/1)
  20. ![image](https://github.com/kakajun/vue3-sketch-ruler/blob/1x/example/v2/assets/dp.png)
  21. As the project was upgraded to vite, I found that the original plug-in Vue sketch ruler would report an error when used in vue3. Here, I repackaged a copy with vite. The packaged plug-in works the same as the original and supports the use in vue3 and vite
  22. The original code has been improved and optimized here. The function is the same as that of vue3 sketch ruler before. There is no time for optimization. The main improvements are as follows
  23. 1. The eslint repair of vue3 and the code formatting of stylelint and pretty support the use of sketchrule in vue3 and rewrite it to the writing method of vue3 composition API
  24. 2. Refactoring with typescript to define types and facilitate subsequent expansion
  25. 3. Perform object consolidation calculation for shadow and palette parameters. In the past, palette parameters were either passed or not passed. After improvement, I can only pass the attributes that need to be modified, and those that have not been modified can not be passed
  26. 4. Package and set the type (support TS type prompt)
  27. 5. Support the introduction of nuxt3 plug-in (the error messages not defined in window have been handled)
  28. The upgrade process is simple. I wrote a Nuggets article. Peers or interested parties can leave messages for communication
  29. [Nuggets: large screen page zoom plug-in - upgrade](https://juejin.cn/post/7025195450080690212)
  30. ## Attention
  31. 1. If the plug-in is used in vue2 / vue3, it needs to be installed with Vue Demi plug-in. This plug-in does not pack Vue Demi. In addition, Vue Demi is only 18.2 KB, which is very small, and only plays the role of Vue version switching,
  32. The 1x version here has the same function as Vue sketch ruler. If there are no bugs behind it, it will not be maintained. 1x basically does not change the original functions. If you need to download the source code or provide PR, please download the 1x branch. The new functions will be added in the next 2x. It is recommended to use the 1x version for the migration of old projects, and 2x for new projects, Achieve 0 configuration (I'm not satisfied with writing several versions during 2x dystocia, but this one will come out. The prototype has been transferred to the master branch)
  33. ## demo
  34. Case browsing:[ https://kakajun.github.io/vue3-sketch-ruler/1x ]( https://kakajun.github.io/vue3-sketch-ruler/1x)
  35. ![image]( https://github.com/kakajun/vue3-sketch-ruler/blob/1x/example/assets/demo.png)
  36. ## Installation
  37. >Supports global import and module import
  38. vue3
  39. ```
  40. npm install --save vue3-sketch-ruler vue-demi
  41. or
  42. yarn add vue3-sketch-ruler vue-demi -S
  43. ```
  44. vue2
  45. ```
  46. npm install --save vue3-sketch-ruler vue-demi @vue/composition-api
  47. or
  48. yarn add vue3-sketch-ruler vue-demi @vue/composition-api -S
  49. ```
  50. ## Introduction mode
  51. Copy the packaged dist package and import it with import. The following two reference methods are supported
  52. ```
  53. import { SketchRule } from 'vue3-sketch-ruler'
  54. import 'vue3-sketch-ruler/lib/style. css'
  55. components: { SketchRule }
  56. ```
  57. It can also be like this
  58. ```
  59. import SketchRule from 'vue3-sketch-ruler'
  60. import 'vue3-sketch-ruler/lib/style. css'
  61. components: SketchRule
  62. ```
  63. ## Supported functions
  64. -[x] ruler rendering
  65. -[x] zoom content, redraw ruler
  66. -[x] scroll content, redraw ruler
  67. -[x] toggles the ruler state to show or hide
  68. -[x] reference line management (add delete)
  69. -[x] supports dragging anywhere on the reference line
  70. -[x] the eye in the upper left corner, click to control the red line development
  71. -[x] General plug-in in vue2 / vue3
  72. ## Future supported functions
  73. -[] add canvas mouse drag function
  74. -[] there is a mouse in the lower right corner to enter the zoom function
  75. -[] add unit test function
  76. This is an open source amateur function. If you are interested in strengthening the plug-in, you are welcome to join, and you are also welcome to mention PR or issue
  77. ## Use
  78. ```
  79. <template>
  80. <SketchRule
  81. :thick="thick"
  82. :scale="scale"
  83. :width="582"
  84. :height="482"
  85. :startX="startX"
  86. :startY="startY"
  87. :shadow="shadow"
  88. :lines="lines"
  89. >
  90. </template>
  91. <script>
  92. import Vue from 'vue';
  93. import {SketchRule} from "vue-sketch-ruler";
  94. import 'vue3-sketch-ruler/lib/style.css'
  95. const rectWidth = 160;
  96. const rectHeight = 200;
  97. export default {
  98. data() {
  99. return {
  100. scale: 2, //658813476562495, //1,
  101. startX: 0,
  102. startY: 0,
  103. lines: {
  104. h: [100, 200],
  105. v: [100, 200]
  106. },
  107. thick: 20,
  108. isShowRuler: true,
  109. isShowReferLine: true
  110. }
  111. },
  112. components: {
  113. SketchRule
  114. }
  115. });
  116. </script>
  117. ```
  118. Refer to a complete example, [click here](https://github.com/kakajun/vue3-sketch-ruler/blob/1x/example/v3/components/user-ruler.vue)
  119. Vue3 API example, [click here](https://github.com/kakajun/vue3-sketch-ruler/blob/1x/example/v3/components/user-rulerts.vue)
  120. Examples used in nuxt3 [click here](https://github.com/kakajun/vue3-sketch-ruler/blob/1x/example/v3/components/Nuxt3.vue)
  121. ## api
  122. ### Attributes
  123. |Attribute name | description | type | default value|
  124. | --- | --- | --- | --- |
  125. |Scale | initialize the scale of the scale | number | 2|
  126. |Thickness | number | 16|
  127. |Width | the width of the window where the ruler is placed | number | -|
  128. |Height | height of the ruler window | number | -|
  129. |Startx | coordinate value | number | 0 at the beginning of x-axis ruler|
  130. |Starty | coordinate value | number | 0 at the beginning of y-axis ruler|
  131. |Shadow | parameter of shadow | shadow | 0|
  132. |Lines | initialize the reference line | object < array > | {H: [], V: []} on the horizontal ruler|
  133. |Palette | the style configuration parameters | palette | of the ruler are as follows:|
  134. palette:{bgColor: 'rgba(225,225,225, 0)',longfgColor: '#BABBBC',shortfgColor: '#C8CDD0',fontColor: '#7D8694', shadowColor: '#E8E8E8',lineColor: '#EB5648', borderColor: '#DADADC',cornerActiveColor: 'rgb(235, 86, 72, 0.6)',}
  135. ### Update description
  136. v1.1.11
  137. 1. Discard: horlinearr = "lines. H" and: verlinearr = "lines. V" are unified and integrated into the lines object. The callback handleline is also discarded. It's useless. If you don't want lines, just let lines = {}
  138. 2. Kill some useless styles (it's really useless, and the previous projects are useless. I just turn over and don't need to study the code carefully, so it won't affect the previously migrated projects)
  139. v1.2.3
  140. 1. Merge the methods, eliminate some unnecessary events, use V-model to pass parameters and optimize the code
  141. 2. Remove lodash and reduce the original packaging volume from 43K to 19.6k. It is a stable version. It is highly recommended to upgrade
  142. v1.2.5
  143. 1. Handle the window position to prevent errors in the rendering of nuxt on the server, and support the normal use of nuxt3
  144. v1.3.1
  145. 1. Use Vue Demi so that vue2 / vue3 can be used at the same time
  146. ### Event
  147. |Event name | description | callback parameters|
  148. | --- | --- | --- |
  149. |onCornerClick | click event in the upper left corner|
  150. ## Quote
  151. Vue ruler assembly [Vue sketch ruler](https://github.com/chuxiaoguo/vue-sketch-ruler.git)
  152. A react ruler component from the ink knife [MB sketch ruler](https://github.com/mockingbot/mb-sketch-ruler) .