@lark-apaas/miaoda-inspector 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ const isReactSymbolFiber = (fiber) => {
6
6
  };
7
7
  const isForwardRef = (fiber) => {
8
8
  var _a;
9
- return ((_a = fiber == null ? void 0 : fiber.type) == null ? void 0 : _a.$$typeof) === Symbol.for("react.forward_ref");
9
+ return ((_a = fiber == null ? void 0 : fiber.type) == null ? void 0 : _a.$$typeof) === /* @__PURE__ */ Symbol.for("react.forward_ref");
10
10
  };
11
11
  const getElementFiber = (element) => {
12
12
  const fiberKey = Object.keys(element).find(
@@ -622,7 +622,7 @@ function MiaodaInspector(props) {
622
622
  postMessage({
623
623
  type: "PageMounted",
624
624
  data: {
625
- version: "1.0.7",
625
+ version: "1.0.8",
626
626
  feature: {
627
627
  selectParent: true,
628
628
  reverseSelect: true
@@ -0,0 +1,46 @@
1
+ import "../chunk-I4E63NIC.mjs";
2
+ import {
3
+ parse,
4
+ to,
5
+ serialize,
6
+ ColorSpace,
7
+ sRGB,
8
+ HSL,
9
+ HWB,
10
+ Lab,
11
+ LCH,
12
+ OKLab,
13
+ OKLCH,
14
+ P3,
15
+ REC_2020,
16
+ A98RGB,
17
+ ProPhoto
18
+ } from "colorjs.io/fn";
19
+ [
20
+ // sRGB 系 (rgb/hsl/hwb → rgb())
21
+ sRGB,
22
+ HSL,
23
+ HWB,
24
+ // Lab 系 (保留原格式)
25
+ Lab,
26
+ LCH,
27
+ OKLab,
28
+ OKLCH,
29
+ // 宽色域 (color() 函数)
30
+ P3,
31
+ REC_2020,
32
+ A98RGB,
33
+ ProPhoto
34
+ ].forEach((space) => ColorSpace.register(space));
35
+ function toHex(colorString) {
36
+ try {
37
+ const color = parse(colorString);
38
+ const srgbColor = to(color, "srgb");
39
+ return serialize(srgbColor, { format: "hex", collapse: false });
40
+ } catch (e) {
41
+ return colorString;
42
+ }
43
+ }
44
+ export {
45
+ toHex
46
+ };
@@ -2,28 +2,8 @@ import {
2
2
  __spreadProps,
3
3
  __spreadValues
4
4
  } from "../chunk-I4E63NIC.mjs";
5
+ import { toHex } from "./color";
5
6
  import { isAntdText, isNativeElementName } from "./element-guards";
6
- function rgbaToHex(rgba) {
7
- const match = rgba.match(/rgba?\(([^)]+)\)/);
8
- if (!match) return rgba;
9
- const values = match[1].split(",").map((v) => v.trim());
10
- const r = parseInt(values[0], 10);
11
- const g = parseInt(values[1], 10);
12
- const b = parseInt(values[2], 10);
13
- const toHex = (n) => {
14
- const hex = n.toString(16);
15
- return hex.length === 1 ? `0${hex}` : hex;
16
- };
17
- if (values.length === 4) {
18
- const a = parseFloat(values[3]);
19
- if (!Number.isNaN(a) && a < 1) {
20
- const alphaHex = Math.round(a * 255).toString(16);
21
- const alphaHexStr = alphaHex.length === 1 ? `0${alphaHex}` : alphaHex;
22
- return `#${toHex(r)}${toHex(g)}${toHex(b)}${alphaHexStr}`;
23
- }
24
- }
25
- return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
26
- }
27
7
  function isValidElement(element, componentName, canUseNewInspector) {
28
8
  if (!element || !componentName || !canUseNewInspector || element instanceof SVGElement) {
29
9
  return false;
@@ -66,7 +46,7 @@ function calculateStyleProperty(element, config) {
66
46
  if (config.cssProperty === "textAlign" || config.skipTailwind) {
67
47
  tailwindClassName = config.map[currentValue] || `raw:${currentValue}`;
68
48
  } else if (config.cssProperty === "color" || config.cssProperty === "backgroundColor" || config.cssProperty === "borderColor") {
69
- const normalizedColor = rgbaToHex(currentValue);
49
+ const normalizedColor = toHex(currentValue);
70
50
  const colorValue = config.transformValue ? config.transformValue(normalizedColor) : normalizedColor;
71
51
  tailwindClassName = config.map[colorValue] || `raw:${normalizedColor}`;
72
52
  } else {
@@ -129,6 +109,5 @@ export {
129
109
  calculateMarginInfo,
130
110
  calculatePaddingInfo,
131
111
  calculateStyle,
132
- calculateTextAlignInfo,
133
- rgbaToHex
112
+ calculateTextAlignInfo
134
113
  };
@@ -34,7 +34,7 @@ const isReactSymbolFiber = (fiber) => {
34
34
  };
35
35
  const isForwardRef = (fiber) => {
36
36
  var _a;
37
- return ((_a = fiber == null ? void 0 : fiber.type) == null ? void 0 : _a.$$typeof) === Symbol.for("react.forward_ref");
37
+ return ((_a = fiber == null ? void 0 : fiber.type) == null ? void 0 : _a.$$typeof) === /* @__PURE__ */ Symbol.for("react.forward_ref");
38
38
  };
39
39
  const getElementFiber = (element) => {
40
40
  const fiberKey = Object.keys(element).find(
@@ -640,7 +640,7 @@ function MiaodaInspector(props) {
640
640
  (0, import_utils2.postMessage)({
641
641
  type: "PageMounted",
642
642
  data: {
643
- version: "1.0.7",
643
+ version: "1.0.8",
644
644
  feature: {
645
645
  selectParent: true,
646
646
  reverseSelect: true
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to2, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to2, key) && key !== except)
14
+ __defProp(to2, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to2;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var color_exports = {};
20
+ __export(color_exports, {
21
+ toHex: () => toHex
22
+ });
23
+ module.exports = __toCommonJS(color_exports);
24
+ var import_fn = require("colorjs.io/fn");
25
+ [
26
+ // sRGB 系 (rgb/hsl/hwb → rgb())
27
+ import_fn.sRGB,
28
+ import_fn.HSL,
29
+ import_fn.HWB,
30
+ // Lab 系 (保留原格式)
31
+ import_fn.Lab,
32
+ import_fn.LCH,
33
+ import_fn.OKLab,
34
+ import_fn.OKLCH,
35
+ // 宽色域 (color() 函数)
36
+ import_fn.P3,
37
+ import_fn.REC_2020,
38
+ import_fn.A98RGB,
39
+ import_fn.ProPhoto
40
+ ].forEach((space) => import_fn.ColorSpace.register(space));
41
+ function toHex(colorString) {
42
+ try {
43
+ const color = (0, import_fn.parse)(colorString);
44
+ const srgbColor = (0, import_fn.to)(color, "srgb");
45
+ return (0, import_fn.serialize)(srgbColor, { format: "hex", collapse: false });
46
+ } catch (e) {
47
+ return colorString;
48
+ }
49
+ }
@@ -45,32 +45,11 @@ __export(style_calculator_exports, {
45
45
  calculateMarginInfo: () => calculateMarginInfo,
46
46
  calculatePaddingInfo: () => calculatePaddingInfo,
47
47
  calculateStyle: () => calculateStyle,
48
- calculateTextAlignInfo: () => calculateTextAlignInfo,
49
- rgbaToHex: () => rgbaToHex
48
+ calculateTextAlignInfo: () => calculateTextAlignInfo
50
49
  });
51
50
  module.exports = __toCommonJS(style_calculator_exports);
51
+ var import_color = require("./color");
52
52
  var import_element_guards = require("./element-guards");
53
- function rgbaToHex(rgba) {
54
- const match = rgba.match(/rgba?\(([^)]+)\)/);
55
- if (!match) return rgba;
56
- const values = match[1].split(",").map((v) => v.trim());
57
- const r = parseInt(values[0], 10);
58
- const g = parseInt(values[1], 10);
59
- const b = parseInt(values[2], 10);
60
- const toHex = (n) => {
61
- const hex = n.toString(16);
62
- return hex.length === 1 ? `0${hex}` : hex;
63
- };
64
- if (values.length === 4) {
65
- const a = parseFloat(values[3]);
66
- if (!Number.isNaN(a) && a < 1) {
67
- const alphaHex = Math.round(a * 255).toString(16);
68
- const alphaHexStr = alphaHex.length === 1 ? `0${alphaHex}` : alphaHex;
69
- return `#${toHex(r)}${toHex(g)}${toHex(b)}${alphaHexStr}`;
70
- }
71
- }
72
- return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
73
- }
74
53
  function isValidElement(element, componentName, canUseNewInspector) {
75
54
  if (!element || !componentName || !canUseNewInspector || element instanceof SVGElement) {
76
55
  return false;
@@ -113,7 +92,7 @@ function calculateStyleProperty(element, config) {
113
92
  if (config.cssProperty === "textAlign" || config.skipTailwind) {
114
93
  tailwindClassName = config.map[currentValue] || `raw:${currentValue}`;
115
94
  } else if (config.cssProperty === "color" || config.cssProperty === "backgroundColor" || config.cssProperty === "borderColor") {
116
- const normalizedColor = rgbaToHex(currentValue);
95
+ const normalizedColor = (0, import_color.toHex)(currentValue);
117
96
  const colorValue = config.transformValue ? config.transformValue(normalizedColor) : normalizedColor;
118
97
  tailwindClassName = config.map[colorValue] || `raw:${normalizedColor}`;
119
98
  } else {
@@ -0,0 +1,3 @@
1
+ declare function toHex(colorString: string): string;
2
+
3
+ export { toHex };
@@ -6,7 +6,6 @@ interface StyleCalculationResult {
6
6
  inherited: boolean;
7
7
  tailwindClassName: string;
8
8
  }
9
- declare function rgbaToHex(rgba: string): string;
10
9
  declare function calculateStyle(styleName: string, element: HTMLElement, componentName: string, canUseNewInspector: boolean, styleConfigs: Record<string, StyleCalculationConfig>): StyleCalculationResult | null;
11
10
  declare const calculateFontSizeInfo: (element: HTMLElement, componentName: string, canUseNewInspector: boolean, styleConfigs: Record<string, StyleCalculationConfig>) => StyleCalculationResult | null;
12
11
  declare const calculateFontWeightInfo: (element: HTMLElement, componentName: string, canUseNewInspector: boolean, styleConfigs: Record<string, StyleCalculationConfig>) => StyleCalculationResult | null;
@@ -19,4 +18,4 @@ declare const calculateColorInfo: (element: HTMLElement, componentName: string,
19
18
  declare const calculateBackgroundColorInfo: (element: HTMLElement, componentName: string, canUseNewInspector: boolean, styleConfigs: Record<string, StyleCalculationConfig>) => StyleCalculationResult | null;
20
19
  declare const calculateBorderColorInfo: (element: HTMLElement, componentName: string, canUseNewInspector: boolean, styleConfigs: Record<string, StyleCalculationConfig>) => StyleCalculationResult | null;
21
20
 
22
- export { calculateBackgroundColorInfo, calculateBorderColorInfo, calculateBorderRadiusInfo, calculateBorderWidthInfo, calculateColorInfo, calculateFontSizeInfo, calculateFontWeightInfo, calculateMarginInfo, calculatePaddingInfo, calculateStyle, calculateTextAlignInfo, rgbaToHex };
21
+ export { calculateBackgroundColorInfo, calculateBorderColorInfo, calculateBorderRadiusInfo, calculateBorderWidthInfo, calculateColorInfo, calculateFontSizeInfo, calculateFontWeightInfo, calculateMarginInfo, calculatePaddingInfo, calculateStyle, calculateTextAlignInfo };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/miaoda-inspector",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Inspector for Lark Apaas",
5
5
  "sideEffects": [
6
6
  "*.css"
@@ -27,6 +27,7 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "clsx": "~2.0.0",
30
+ "colorjs.io": "^0.5.2",
30
31
  "hotkeys-js": "^3.8.1",
31
32
  "picocolors": "1.0.0",
32
33
  "react-dev-utils": "12.0.1",