@lark-apaas/miaoda-inspector 0.1.0-alpha.1
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.
- package/LICENSE +13 -0
- package/README.md +1 -0
- package/dist/es/Inspector/Inspector.js +179 -0
- package/dist/es/Inspector/Overlay.js +400 -0
- package/dist/es/Inspector/hooks/index.js +3 -0
- package/dist/es/Inspector/hooks/use-effect-event.js +15 -0
- package/dist/es/Inspector/hooks/use-layout-effect.js +3 -0
- package/dist/es/Inspector/hooks/use-mouse.js +22 -0
- package/dist/es/Inspector/index.js +1 -0
- package/dist/es/Inspector/utils/fiber.js +61 -0
- package/dist/es/Inspector/utils/highlight.js +74 -0
- package/dist/es/Inspector/utils/index.js +3 -0
- package/dist/es/Inspector/utils/inspect.js +119 -0
- package/dist/es/Inspector/utils/overlay.js +20 -0
- package/dist/es/MiaodaInspector/MiaodaInspector.css +46 -0
- package/dist/es/MiaodaInspector/MiaodaInspector.js +397 -0
- package/dist/es/MiaodaInspector/index.js +1 -0
- package/dist/es/config/ui-config.js +787 -0
- package/dist/es/index.js +2 -0
- package/dist/es/types/iframe-events.js +1 -0
- package/dist/es/types/index.js +1 -0
- package/dist/es/utils/config-mapper.js +163 -0
- package/dist/es/utils/css.js +5 -0
- package/dist/es/utils/index.js +3 -0
- package/dist/es/utils/origin.js +19 -0
- package/dist/es/utils/style-calculator.js +158 -0
- package/dist/lib/Inspector/Inspector.js +203 -0
- package/dist/lib/Inspector/Overlay.js +419 -0
- package/dist/lib/Inspector/hooks/index.js +20 -0
- package/dist/lib/Inspector/hooks/use-effect-event.js +25 -0
- package/dist/lib/Inspector/hooks/use-layout-effect.js +13 -0
- package/dist/lib/Inspector/hooks/use-mouse.js +32 -0
- package/dist/lib/Inspector/index.js +11 -0
- package/dist/lib/Inspector/utils/fiber.js +95 -0
- package/dist/lib/Inspector/utils/highlight.js +84 -0
- package/dist/lib/Inspector/utils/index.js +20 -0
- package/dist/lib/Inspector/utils/inspect.js +153 -0
- package/dist/lib/Inspector/utils/overlay.js +39 -0
- package/dist/lib/MiaodaInspector/MiaodaInspector.css +46 -0
- package/dist/lib/MiaodaInspector/MiaodaInspector.js +447 -0
- package/dist/lib/MiaodaInspector/index.js +11 -0
- package/dist/lib/config/ui-config.js +797 -0
- package/dist/lib/index.js +21 -0
- package/dist/lib/types/iframe-events.js +4 -0
- package/dist/lib/types/index.js +47 -0
- package/dist/lib/utils/config-mapper.js +182 -0
- package/dist/lib/utils/css.js +20 -0
- package/dist/lib/utils/index.js +61 -0
- package/dist/lib/utils/origin.js +44 -0
- package/dist/lib/utils/style-calculator.js +207 -0
- package/dist/types/Inspector/Inspector.d.ts +102 -0
- package/dist/types/Inspector/Overlay.d.ts +71 -0
- package/dist/types/Inspector/hooks/index.d.ts +3 -0
- package/dist/types/Inspector/hooks/use-effect-event.d.ts +9 -0
- package/dist/types/Inspector/hooks/use-layout-effect.d.ts +2 -0
- package/dist/types/Inspector/hooks/use-mouse.d.ts +9 -0
- package/dist/types/Inspector/index.d.ts +1 -0
- package/dist/types/Inspector/utils/fiber.d.ts +34 -0
- package/dist/types/Inspector/utils/highlight.d.ts +8 -0
- package/dist/types/Inspector/utils/index.d.ts +3 -0
- package/dist/types/Inspector/utils/inspect.d.ts +110 -0
- package/dist/types/Inspector/utils/overlay.d.ts +30 -0
- package/dist/types/MiaodaInspector/MiaodaInspector.d.ts +47 -0
- package/dist/types/MiaodaInspector/index.d.ts +1 -0
- package/dist/types/config/ui-config.d.ts +49 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/types/iframe-events.d.ts +155 -0
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/utils/config-mapper.d.ts +12 -0
- package/dist/types/utils/css.d.ts +2 -0
- package/dist/types/utils/index.d.ts +3 -0
- package/dist/types/utils/origin.d.ts +9 -0
- package/dist/types/utils/style-calculator.d.ts +19 -0
- package/package.json +48 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
MiaodaInspector: function() {
|
|
14
|
+
return _MiaodaInspector.MiaodaInspector;
|
|
15
|
+
},
|
|
16
|
+
isOutgoingMessage: function() {
|
|
17
|
+
return _utils.isOutgoingMessage;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
const _MiaodaInspector = require("./MiaodaInspector");
|
|
21
|
+
const _utils = require("./utils");
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
InitConfigMessage: function() {
|
|
14
|
+
return _iframeevents.InitConfigMessage;
|
|
15
|
+
},
|
|
16
|
+
ClearSelectedMessage: function() {
|
|
17
|
+
return _iframeevents.ClearSelectedMessage;
|
|
18
|
+
},
|
|
19
|
+
EditTextMessage: function() {
|
|
20
|
+
return _iframeevents.EditTextMessage;
|
|
21
|
+
},
|
|
22
|
+
EditStyleMessage: function() {
|
|
23
|
+
return _iframeevents.EditStyleMessage;
|
|
24
|
+
},
|
|
25
|
+
EditClassNameMessage: function() {
|
|
26
|
+
return _iframeevents.EditClassNameMessage;
|
|
27
|
+
},
|
|
28
|
+
OutgoingMessage: function() {
|
|
29
|
+
return _iframeevents.OutgoingMessage;
|
|
30
|
+
},
|
|
31
|
+
PageMountedMessage: function() {
|
|
32
|
+
return _iframeevents.PageMountedMessage;
|
|
33
|
+
},
|
|
34
|
+
TextUpdateMessage: function() {
|
|
35
|
+
return _iframeevents.TextUpdateMessage;
|
|
36
|
+
},
|
|
37
|
+
SelectInspectorElementMessage: function() {
|
|
38
|
+
return _iframeevents.SelectInspectorElementMessage;
|
|
39
|
+
},
|
|
40
|
+
IncomingMessage: function() {
|
|
41
|
+
return _iframeevents.IncomingMessage;
|
|
42
|
+
},
|
|
43
|
+
InspectorInfo: function() {
|
|
44
|
+
return _iframeevents.InspectorInfo;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
const _iframeevents = require("./iframe-events");
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
getStyleCalculationConfig: function() {
|
|
14
|
+
return getStyleCalculationConfig;
|
|
15
|
+
},
|
|
16
|
+
getAllStyleConfigs: function() {
|
|
17
|
+
return getAllStyleConfigs;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
function _define_property(obj, key, value) {
|
|
21
|
+
if (key in obj) {
|
|
22
|
+
Object.defineProperty(obj, key, {
|
|
23
|
+
value,
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
obj[key] = value;
|
|
30
|
+
}
|
|
31
|
+
return obj;
|
|
32
|
+
}
|
|
33
|
+
function _object_spread(target) {
|
|
34
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
35
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
36
|
+
var ownKeys2 = Object.keys(source);
|
|
37
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
38
|
+
ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
39
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
ownKeys2.forEach(function(key) {
|
|
43
|
+
_define_property(target, key, source[key]);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return target;
|
|
47
|
+
}
|
|
48
|
+
function ownKeys(object, enumerableOnly) {
|
|
49
|
+
var keys = Object.keys(object);
|
|
50
|
+
if (Object.getOwnPropertySymbols) {
|
|
51
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
52
|
+
if (enumerableOnly) {
|
|
53
|
+
symbols = symbols.filter(function(sym) {
|
|
54
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
keys.push.apply(keys, symbols);
|
|
58
|
+
}
|
|
59
|
+
return keys;
|
|
60
|
+
}
|
|
61
|
+
function _object_spread_props(target, source) {
|
|
62
|
+
source = source != null ? source : {};
|
|
63
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
64
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
65
|
+
} else {
|
|
66
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
67
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return target;
|
|
71
|
+
}
|
|
72
|
+
function getColorStyleCalculationConfig(config, propertyName) {
|
|
73
|
+
const prefixMap = {
|
|
74
|
+
color: "text",
|
|
75
|
+
backgroundColor: "bg",
|
|
76
|
+
borderColor: "border"
|
|
77
|
+
};
|
|
78
|
+
const prefix = prefixMap[propertyName];
|
|
79
|
+
if (!prefix) {
|
|
80
|
+
throw new Error(`Unsupported color property: ${propertyName}`);
|
|
81
|
+
}
|
|
82
|
+
const map = {};
|
|
83
|
+
for (const [tokenName, colorValue] of Object.entries(config.tokens)) {
|
|
84
|
+
if (!tokenName.includes("-") || !colorValue.startsWith("#")) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const tailwindClass = `${prefix}-${tokenName}`;
|
|
88
|
+
map[colorValue.toLowerCase()] = tailwindClass;
|
|
89
|
+
}
|
|
90
|
+
const colorConfig = config.common[propertyName];
|
|
91
|
+
if (colorConfig.type === "color-picker") {
|
|
92
|
+
for (const colorGroup of colorConfig.recommendColors) {
|
|
93
|
+
for (const colorOption of colorGroup.options) {
|
|
94
|
+
if (colorOption.type === "tailwind" && colorOption.rawValue) {
|
|
95
|
+
map[colorOption.rawValue.toLowerCase()] = colorOption.value;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
let cssProperty;
|
|
101
|
+
if (propertyName === "color") {
|
|
102
|
+
cssProperty = "color";
|
|
103
|
+
} else if (propertyName === "backgroundColor") {
|
|
104
|
+
cssProperty = "backgroundColor";
|
|
105
|
+
} else {
|
|
106
|
+
cssProperty = "borderColor";
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
cssProperty,
|
|
110
|
+
tailwindPrefix: prefix,
|
|
111
|
+
map,
|
|
112
|
+
transformValue: (value) => value.toLowerCase()
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function getStyleCalculationConfig(config, propertyName) {
|
|
116
|
+
const uiComponent = config.common[propertyName];
|
|
117
|
+
if (uiComponent.type === "color-picker") {
|
|
118
|
+
return getColorStyleCalculationConfig(config, propertyName);
|
|
119
|
+
}
|
|
120
|
+
if (uiComponent.type !== "select" && uiComponent.type !== "spacing") {
|
|
121
|
+
throw new Error(`Unsupported UI component type: ${uiComponent.type} for property: ${propertyName}`);
|
|
122
|
+
}
|
|
123
|
+
const map = {};
|
|
124
|
+
for (const option of uiComponent.options) {
|
|
125
|
+
const numericValue = parseInt(option.rawValue, 10);
|
|
126
|
+
if (!Number.isNaN(numericValue)) {
|
|
127
|
+
map[numericValue] = option.value;
|
|
128
|
+
} else {
|
|
129
|
+
map[option.rawValue] = option.value;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const configMap = {
|
|
133
|
+
fontSize: {
|
|
134
|
+
cssProperty: "fontSize",
|
|
135
|
+
tailwindPrefix: "text",
|
|
136
|
+
tolerance: 2
|
|
137
|
+
},
|
|
138
|
+
fontWeight: {
|
|
139
|
+
cssProperty: "fontWeight",
|
|
140
|
+
tailwindPrefix: "font",
|
|
141
|
+
transformValue: (value) => parseInt(value, 10)
|
|
142
|
+
},
|
|
143
|
+
borderRadius: {
|
|
144
|
+
cssProperty: "borderRadius",
|
|
145
|
+
tailwindPrefix: "rounded"
|
|
146
|
+
},
|
|
147
|
+
borderWidth: {
|
|
148
|
+
cssProperty: "borderWidth",
|
|
149
|
+
tailwindPrefix: "border"
|
|
150
|
+
},
|
|
151
|
+
textAlign: {
|
|
152
|
+
cssProperty: "textAlign",
|
|
153
|
+
tailwindPrefix: "text",
|
|
154
|
+
transformValue: (value) => value
|
|
155
|
+
},
|
|
156
|
+
padding: {
|
|
157
|
+
cssProperty: "padding",
|
|
158
|
+
tailwindPrefix: "p",
|
|
159
|
+
skipTailwind: true
|
|
160
|
+
},
|
|
161
|
+
margin: {
|
|
162
|
+
cssProperty: "margin",
|
|
163
|
+
tailwindPrefix: "m",
|
|
164
|
+
skipTailwind: true
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const baseConfig = configMap[propertyName];
|
|
168
|
+
if (!baseConfig) {
|
|
169
|
+
throw new Error(`Unknown property: ${propertyName}`);
|
|
170
|
+
}
|
|
171
|
+
return _object_spread_props(_object_spread({}, baseConfig), {
|
|
172
|
+
map
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
function getAllStyleConfigs(config) {
|
|
176
|
+
const result = {};
|
|
177
|
+
const keys = Object.keys(config.common);
|
|
178
|
+
for (const key of keys) {
|
|
179
|
+
result[key] = getStyleCalculationConfig(config, key);
|
|
180
|
+
}
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "cx", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return cx;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _clsx = /* @__PURE__ */ _interop_require_default(require("clsx"));
|
|
12
|
+
const _tailwindmerge = require("tailwind-merge");
|
|
13
|
+
function _interop_require_default(obj) {
|
|
14
|
+
return obj && obj.__esModule ? obj : {
|
|
15
|
+
default: obj
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function cx(...args) {
|
|
19
|
+
return (0, _tailwindmerge.twMerge)((0, _clsx.default)(...args));
|
|
20
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
getPreviewParentOrigin: function() {
|
|
14
|
+
return _origin.getPreviewParentOrigin;
|
|
15
|
+
},
|
|
16
|
+
postMessage: function() {
|
|
17
|
+
return _origin.postMessage;
|
|
18
|
+
},
|
|
19
|
+
isIncomingMessage: function() {
|
|
20
|
+
return _origin.isIncomingMessage;
|
|
21
|
+
},
|
|
22
|
+
isOutgoingMessage: function() {
|
|
23
|
+
return _origin.isOutgoingMessage;
|
|
24
|
+
},
|
|
25
|
+
cx: function() {
|
|
26
|
+
return _css.cx;
|
|
27
|
+
},
|
|
28
|
+
calculateFontSizeInfo: function() {
|
|
29
|
+
return _stylecalculator.calculateFontSizeInfo;
|
|
30
|
+
},
|
|
31
|
+
calculateFontWeightInfo: function() {
|
|
32
|
+
return _stylecalculator.calculateFontWeightInfo;
|
|
33
|
+
},
|
|
34
|
+
calculateBorderRadiusInfo: function() {
|
|
35
|
+
return _stylecalculator.calculateBorderRadiusInfo;
|
|
36
|
+
},
|
|
37
|
+
calculateBorderWidthInfo: function() {
|
|
38
|
+
return _stylecalculator.calculateBorderWidthInfo;
|
|
39
|
+
},
|
|
40
|
+
calculateTextAlignInfo: function() {
|
|
41
|
+
return _stylecalculator.calculateTextAlignInfo;
|
|
42
|
+
},
|
|
43
|
+
calculatePaddingInfo: function() {
|
|
44
|
+
return _stylecalculator.calculatePaddingInfo;
|
|
45
|
+
},
|
|
46
|
+
calculateMarginInfo: function() {
|
|
47
|
+
return _stylecalculator.calculateMarginInfo;
|
|
48
|
+
},
|
|
49
|
+
calculateColorInfo: function() {
|
|
50
|
+
return _stylecalculator.calculateColorInfo;
|
|
51
|
+
},
|
|
52
|
+
calculateBackgroundColorInfo: function() {
|
|
53
|
+
return _stylecalculator.calculateBackgroundColorInfo;
|
|
54
|
+
},
|
|
55
|
+
calculateBorderColorInfo: function() {
|
|
56
|
+
return _stylecalculator.calculateBorderColorInfo;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
const _origin = require("./origin");
|
|
60
|
+
const _css = require("./css");
|
|
61
|
+
const _stylecalculator = require("./style-calculator");
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
getPreviewParentOrigin: function() {
|
|
14
|
+
return getPreviewParentOrigin;
|
|
15
|
+
},
|
|
16
|
+
postMessage: function() {
|
|
17
|
+
return postMessage;
|
|
18
|
+
},
|
|
19
|
+
isOutgoingMessage: function() {
|
|
20
|
+
return isOutgoingMessage;
|
|
21
|
+
},
|
|
22
|
+
isIncomingMessage: function() {
|
|
23
|
+
return isIncomingMessage;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
function getPreviewParentOrigin() {
|
|
27
|
+
const { origin } = window.location;
|
|
28
|
+
if (origin.includes("feishuapp.cn")) {
|
|
29
|
+
return "https://miaoda.feishu.cn";
|
|
30
|
+
}
|
|
31
|
+
if (origin.includes("fsapp.kundou.cn")) {
|
|
32
|
+
return "https://miaoda.feishu-pre.cn";
|
|
33
|
+
}
|
|
34
|
+
return "https://miaoda.feishu-boe.cn";
|
|
35
|
+
}
|
|
36
|
+
function postMessage(message, targetOrigin) {
|
|
37
|
+
window.parent.postMessage(message, targetOrigin !== null && targetOrigin !== void 0 ? targetOrigin : getPreviewParentOrigin());
|
|
38
|
+
}
|
|
39
|
+
function isOutgoingMessage(msg, type) {
|
|
40
|
+
return msg.type === type;
|
|
41
|
+
}
|
|
42
|
+
function isIncomingMessage(msg, type) {
|
|
43
|
+
return msg.type === type;
|
|
44
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
rgbaToHex: function() {
|
|
14
|
+
return rgbaToHex;
|
|
15
|
+
},
|
|
16
|
+
calculateStyle: function() {
|
|
17
|
+
return calculateStyle;
|
|
18
|
+
},
|
|
19
|
+
calculateFontSizeInfo: function() {
|
|
20
|
+
return calculateFontSizeInfo;
|
|
21
|
+
},
|
|
22
|
+
calculateFontWeightInfo: function() {
|
|
23
|
+
return calculateFontWeightInfo;
|
|
24
|
+
},
|
|
25
|
+
calculateBorderRadiusInfo: function() {
|
|
26
|
+
return calculateBorderRadiusInfo;
|
|
27
|
+
},
|
|
28
|
+
calculateBorderWidthInfo: function() {
|
|
29
|
+
return calculateBorderWidthInfo;
|
|
30
|
+
},
|
|
31
|
+
calculateTextAlignInfo: function() {
|
|
32
|
+
return calculateTextAlignInfo;
|
|
33
|
+
},
|
|
34
|
+
calculatePaddingInfo: function() {
|
|
35
|
+
return calculatePaddingInfo;
|
|
36
|
+
},
|
|
37
|
+
calculateMarginInfo: function() {
|
|
38
|
+
return calculateMarginInfo;
|
|
39
|
+
},
|
|
40
|
+
calculateColorInfo: function() {
|
|
41
|
+
return calculateColorInfo;
|
|
42
|
+
},
|
|
43
|
+
calculateBackgroundColorInfo: function() {
|
|
44
|
+
return calculateBackgroundColorInfo;
|
|
45
|
+
},
|
|
46
|
+
calculateBorderColorInfo: function() {
|
|
47
|
+
return calculateBorderColorInfo;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
function _define_property(obj, key, value) {
|
|
51
|
+
if (key in obj) {
|
|
52
|
+
Object.defineProperty(obj, key, {
|
|
53
|
+
value,
|
|
54
|
+
enumerable: true,
|
|
55
|
+
configurable: true,
|
|
56
|
+
writable: true
|
|
57
|
+
});
|
|
58
|
+
} else {
|
|
59
|
+
obj[key] = value;
|
|
60
|
+
}
|
|
61
|
+
return obj;
|
|
62
|
+
}
|
|
63
|
+
function _object_spread(target) {
|
|
64
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
65
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
66
|
+
var ownKeys2 = Object.keys(source);
|
|
67
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
68
|
+
ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
69
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
ownKeys2.forEach(function(key) {
|
|
73
|
+
_define_property(target, key, source[key]);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return target;
|
|
77
|
+
}
|
|
78
|
+
function ownKeys(object, enumerableOnly) {
|
|
79
|
+
var keys = Object.keys(object);
|
|
80
|
+
if (Object.getOwnPropertySymbols) {
|
|
81
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
82
|
+
if (enumerableOnly) {
|
|
83
|
+
symbols = symbols.filter(function(sym) {
|
|
84
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
keys.push.apply(keys, symbols);
|
|
88
|
+
}
|
|
89
|
+
return keys;
|
|
90
|
+
}
|
|
91
|
+
function _object_spread_props(target, source) {
|
|
92
|
+
source = source != null ? source : {};
|
|
93
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
94
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
95
|
+
} else {
|
|
96
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
97
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return target;
|
|
101
|
+
}
|
|
102
|
+
function rgbaToHex(rgba) {
|
|
103
|
+
const match = rgba.match(/rgba?\(([^)]+)\)/);
|
|
104
|
+
if (!match)
|
|
105
|
+
return rgba;
|
|
106
|
+
const values = match[1].split(",").map((v) => v.trim());
|
|
107
|
+
const r = parseInt(values[0], 10);
|
|
108
|
+
const g = parseInt(values[1], 10);
|
|
109
|
+
const b = parseInt(values[2], 10);
|
|
110
|
+
const toHex = (n) => {
|
|
111
|
+
const hex = n.toString(16);
|
|
112
|
+
return hex.length === 1 ? `0${hex}` : hex;
|
|
113
|
+
};
|
|
114
|
+
if (values.length === 4) {
|
|
115
|
+
const a = parseFloat(values[3]);
|
|
116
|
+
if (!Number.isNaN(a) && a < 1) {
|
|
117
|
+
const alphaHex = Math.round(a * 255).toString(16);
|
|
118
|
+
const alphaHexStr = alphaHex.length === 1 ? `0${alphaHex}` : alphaHex;
|
|
119
|
+
return `#${toHex(r)}${toHex(g)}${toHex(b)}${alphaHexStr}`;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
|
123
|
+
}
|
|
124
|
+
function isValidElement(element, componentName, canUseNewInspector) {
|
|
125
|
+
return !!(element && componentName && componentName[0] !== componentName[0].toUpperCase() && canUseNewInspector && !(element instanceof SVGElement));
|
|
126
|
+
}
|
|
127
|
+
function isValidElementWithComponent(element, componentName, canUseNewInspector) {
|
|
128
|
+
return !!(element && componentName && canUseNewInspector && !(element instanceof SVGElement));
|
|
129
|
+
}
|
|
130
|
+
function shouldBeInherited(element, cssProperty, tailwindPattern) {
|
|
131
|
+
const hasDirectStyle = element.style[cssProperty] !== "";
|
|
132
|
+
const hasTailwindClass = element.className.match(tailwindPattern);
|
|
133
|
+
return !hasDirectStyle && !hasTailwindClass;
|
|
134
|
+
}
|
|
135
|
+
function findClosestMatch(value, map, tolerance = 2) {
|
|
136
|
+
let closestClass = Object.values(map)[0];
|
|
137
|
+
let minDiff = Infinity;
|
|
138
|
+
for (const [px, className] of Object.entries(map)) {
|
|
139
|
+
const diff = Math.abs(value - Number(px));
|
|
140
|
+
if (diff < minDiff) {
|
|
141
|
+
minDiff = diff;
|
|
142
|
+
closestClass = className;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
className: minDiff <= tolerance ? closestClass : `raw:${value}`,
|
|
147
|
+
isExact: minDiff <= tolerance
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function calculateStyleProperty(element, config) {
|
|
151
|
+
const computedStyle = window.getComputedStyle(element);
|
|
152
|
+
const currentValue = computedStyle[config.cssProperty];
|
|
153
|
+
if (!currentValue) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
let tailwindClassName;
|
|
157
|
+
if (config.cssProperty === "textAlign" || config.skipTailwind) {
|
|
158
|
+
tailwindClassName = config.map[currentValue] || `raw:${currentValue}`;
|
|
159
|
+
} else if (config.cssProperty === "color" || config.cssProperty === "backgroundColor" || config.cssProperty === "borderColor") {
|
|
160
|
+
const normalizedColor = rgbaToHex(currentValue);
|
|
161
|
+
const colorValue = config.transformValue ? config.transformValue(normalizedColor) : normalizedColor;
|
|
162
|
+
tailwindClassName = config.map[colorValue] || `raw:${normalizedColor}`;
|
|
163
|
+
} else {
|
|
164
|
+
const numericValue = config.transformValue ? config.transformValue(currentValue) : parseFloat(currentValue);
|
|
165
|
+
const { className } = findClosestMatch(numericValue, config.map, config.tolerance);
|
|
166
|
+
tailwindClassName = className;
|
|
167
|
+
}
|
|
168
|
+
const inherited = config.tailwindPattern ? shouldBeInherited(element, config.cssProperty, config.tailwindPattern) : false;
|
|
169
|
+
return {
|
|
170
|
+
value: currentValue,
|
|
171
|
+
inherited,
|
|
172
|
+
tailwindClassName
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function calculateStyle(styleName, element, componentName, canUseNewInspector, styleConfigs) {
|
|
176
|
+
if ((styleName === "fontSize" || styleName === "fontWeight" || styleName === "color" || styleName === "textAlign") && !isValidElement(element, componentName, canUseNewInspector)) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
if (!isValidElementWithComponent(element, componentName, canUseNewInspector)) {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
const config = styleConfigs[styleName];
|
|
183
|
+
const tailwindPattern = new RegExp(`\\b${config.tailwindPrefix}-(${Object.keys(config.map).join("|")})\\b`);
|
|
184
|
+
return calculateStyleProperty(element, _object_spread_props(_object_spread({}, config), {
|
|
185
|
+
tailwindPattern
|
|
186
|
+
}));
|
|
187
|
+
}
|
|
188
|
+
const calculateFontSizeInfo = (element, componentName, canUseNewInspector, styleConfigs) => calculateStyle("fontSize", element, componentName, canUseNewInspector, styleConfigs);
|
|
189
|
+
const calculateFontWeightInfo = (element, componentName, canUseNewInspector, styleConfigs) => calculateStyle("fontWeight", element, componentName, canUseNewInspector, styleConfigs);
|
|
190
|
+
const calculateBorderRadiusInfo = (element, componentName, canUseNewInspector, styleConfigs) => calculateStyle("borderRadius", element, componentName, canUseNewInspector, styleConfigs);
|
|
191
|
+
const calculateBorderWidthInfo = (element, componentName, canUseNewInspector, styleConfigs) => calculateStyle("borderWidth", element, componentName, canUseNewInspector, styleConfigs);
|
|
192
|
+
const calculateTextAlignInfo = (element, componentName, canUseNewInspector, styleConfigs) => calculateStyle("textAlign", element, componentName, canUseNewInspector, styleConfigs);
|
|
193
|
+
const calculatePaddingInfo = (element, componentName, canUseNewInspector, styleConfigs) => {
|
|
194
|
+
if (!isValidElementWithComponent(element, componentName, canUseNewInspector)) {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
return calculateStyleProperty(element, styleConfigs.padding);
|
|
198
|
+
};
|
|
199
|
+
const calculateMarginInfo = (element, componentName, canUseNewInspector, styleConfigs) => {
|
|
200
|
+
if (!isValidElementWithComponent(element, componentName, canUseNewInspector)) {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
return calculateStyleProperty(element, styleConfigs.margin);
|
|
204
|
+
};
|
|
205
|
+
const calculateColorInfo = (element, componentName, canUseNewInspector, styleConfigs) => calculateStyle("color", element, componentName, canUseNewInspector, styleConfigs);
|
|
206
|
+
const calculateBackgroundColorInfo = (element, componentName, canUseNewInspector, styleConfigs) => calculateStyle("backgroundColor", element, componentName, canUseNewInspector, styleConfigs);
|
|
207
|
+
const calculateBorderColorInfo = (element, componentName, canUseNewInspector, styleConfigs) => calculateStyle("borderColor", element, componentName, canUseNewInspector, styleConfigs);
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { Fiber } from 'react-reconciler';
|
|
3
|
+
import { type CodeInfo } from './utils';
|
|
4
|
+
/**
|
|
5
|
+
* the inspect meta info that is sent to the callback when an element is hovered over or clicked.
|
|
6
|
+
*/
|
|
7
|
+
export interface InspectParams {
|
|
8
|
+
/** hover / click event target dom element */
|
|
9
|
+
element: HTMLElement;
|
|
10
|
+
/** nearest named react component fiber for dom element */
|
|
11
|
+
fiber?: Fiber;
|
|
12
|
+
/** source file line / column / path info for react component */
|
|
13
|
+
codeInfo?: CodeInfo;
|
|
14
|
+
/** react component name for dom element */
|
|
15
|
+
name?: string;
|
|
16
|
+
title?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* `v2.0.0` changes:
|
|
20
|
+
* - make 'Ctrl + Shift + Alt + C' as default shortcut on Windows/Linux
|
|
21
|
+
* - export `defaultHotkeys`
|
|
22
|
+
*/
|
|
23
|
+
export declare const defaultHotkeys: () => string[];
|
|
24
|
+
export interface InspectorProps {
|
|
25
|
+
/**
|
|
26
|
+
* Inspector Component toggle hotkeys,
|
|
27
|
+
*
|
|
28
|
+
* supported keys see: https://github.com/jaywcjlove/hotkeys#supported-keys
|
|
29
|
+
*
|
|
30
|
+
* @default - `['Ctrl', 'Shift', 'Command', 'C']` on macOS, `['Ctrl', 'Shift', 'Alt', 'C']` on other platforms.
|
|
31
|
+
*
|
|
32
|
+
* Setting `keys={null}` explicitly means that disable use hotkeys to trigger it.
|
|
33
|
+
*/
|
|
34
|
+
keys?: string[] | null;
|
|
35
|
+
/**
|
|
36
|
+
* If setting `active` prop, the Inspector will be a Controlled React Component,
|
|
37
|
+
* you need to control the `true`/`false` state to active the Inspector.
|
|
38
|
+
*
|
|
39
|
+
* If not setting `active` prop, this only a Uncontrolled component that
|
|
40
|
+
* will activate/deactivate by hotkeys.
|
|
41
|
+
*
|
|
42
|
+
* > add in version `v2.0.0`
|
|
43
|
+
*/
|
|
44
|
+
active?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Trigger by `active` state change, includes:
|
|
47
|
+
* - hotkeys toggle, before activate/deactivate Inspector
|
|
48
|
+
* - Escape / Click, before deactivate Inspector
|
|
49
|
+
*
|
|
50
|
+
* will NOT trigger by `active` prop change.
|
|
51
|
+
*
|
|
52
|
+
* > add in version `v2.0.0`
|
|
53
|
+
*/
|
|
54
|
+
onActiveChange?: (active: boolean) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Whether to disable all behavior include hotkeys listening or trigger,
|
|
57
|
+
* will automatically disable in production environment by default.
|
|
58
|
+
*
|
|
59
|
+
* @default `true` if `NODE_ENV` is 'production', otherwise is `false`.
|
|
60
|
+
* > add in version `v2.0.0`
|
|
61
|
+
*/
|
|
62
|
+
disable?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Callback when left-clicking on an element, with ensuring the source code info is found.
|
|
65
|
+
*
|
|
66
|
+
* By setting the `onInspectElement` prop, the default behavior ("open local IDE") will be disabled,
|
|
67
|
+
* that means you want to manually handle the source info, or handle how to goto editor by yourself.
|
|
68
|
+
*
|
|
69
|
+
* You can also use builtin `gotoServerEditor` utils in `onInspectElement` to get origin behavior ("open local IDE on server-side"),
|
|
70
|
+
* it looks like:
|
|
71
|
+
*
|
|
72
|
+
* ```tsx
|
|
73
|
+
* import { Inspector, gotoServerEditor } from 'react-dev-inspector'
|
|
74
|
+
*
|
|
75
|
+
* <Inspector
|
|
76
|
+
* onInspectElement={({ codeInfo }) => {
|
|
77
|
+
* ...; // your processing
|
|
78
|
+
* gotoServerEditor(codeInfo)
|
|
79
|
+
* }}
|
|
80
|
+
* </Inspector>
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* > add in version `v2.0.0`
|
|
84
|
+
*/
|
|
85
|
+
onInspectElement?: (params: Required<InspectParams>) => void;
|
|
86
|
+
/** Callback when hovering on an element */
|
|
87
|
+
onHoverElement?: (params: InspectParams) => void;
|
|
88
|
+
/**
|
|
89
|
+
* Callback when left-clicking on an element.
|
|
90
|
+
*/
|
|
91
|
+
onClickElement?: (params: InspectParams) => void;
|
|
92
|
+
/** any children of react nodes */
|
|
93
|
+
children?: ReactNode;
|
|
94
|
+
/**
|
|
95
|
+
* custom handler for component name and info display
|
|
96
|
+
* @param name component name
|
|
97
|
+
* @param info component info (file path)
|
|
98
|
+
* @returns [displayName, displayInfo] tuple for display
|
|
99
|
+
*/
|
|
100
|
+
handleCodeInfo?: (name: string, info?: string) => [string, string];
|
|
101
|
+
}
|
|
102
|
+
export declare const Inspector: (props: InspectorProps) => JSX.Element;
|