use-describe.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { computed, Ref, watch } from "vue";
  2. import { PropertyDescribes } from "../html-mount/propertys";
  3. import {
  4. getFixedStrokeWidthProperty,
  5. sysDescribes,
  6. } from "../html-mount/propertys/describes";
  7. import { useStore } from "../store";
  8. import { Proportion } from "../store/store";
  9. export const useInstallStrokeWidthDescribe = (
  10. describes: Ref<PropertyDescribes>,
  11. shape: Ref<{ strokeWidth?: number; fixed?: boolean }>,
  12. options: number[] = [],
  13. defProportion?: Proportion,
  14. fixed = false,
  15. label?: string
  16. ) => {
  17. const store = useStore();
  18. const proportion = computed(() => {
  19. return defProportion || { ...store.config.strokeProportion };
  20. });
  21. watch(
  22. () => [fixed || options.length > 0, proportion.value] as const,
  23. ([fixed, proportion]) => {
  24. if (!describes.value.strokeWidth) return;
  25. if (fixed) {
  26. const property = getFixedStrokeWidthProperty(shape);
  27. property.props.options = options.map((size) => ({
  28. label: `${size} ${proportion.unit}`,
  29. value: size / proportion.scale,
  30. }));
  31. if (label) {
  32. property.label = label
  33. }
  34. describes.value.strokeWidth = property as PropertyDescribes[string];
  35. } else {
  36. describes.value.strokeWidth = sysDescribes.strokeWidth as any;
  37. }
  38. },
  39. { immediate: true, flush: 'sync' }
  40. );
  41. };