市场夺宝奇兵
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

240 lines
8.5 KiB

  1. import { Fragment, computed, createBaseVNode, createBlock, createCommentVNode, createElementBlock, createVNode, defineComponent, h, normalizeClass, normalizeStyle, openBlock, renderList, renderSlot, resolveDynamicComponent, toDisplayString, unref, withCtx } from "./runtime-core.esm-bundler-Cyv4obHQ.js";
  2. import { isDark, toggleDark, usePayloadStore } from "./payload-BX9lTMvN.js";
  3. import { __plugin_vue_export_helper_default } from "./_plugin-vue_export-helper-DfavQbjy.js";
  4. const _sfc_main = {};
  5. const _hoisted_1$4 = { class: "h-[calc(100vh-55px)]" };
  6. function _sfc_render(_ctx, _cache) {
  7. return openBlock(), createElementBlock("div", _hoisted_1$4, [renderSlot(_ctx.$slots, "default")]);
  8. }
  9. var Container_default = /* @__PURE__ */ __plugin_vue_export_helper_default(_sfc_main, [["render", _sfc_render]]);
  10. /**
  11. * Predefined color map for matching the branding
  12. *
  13. * Accpet a 6-digit hex color string or a hue number
  14. * Hue numbers are preferred because they will adapt better contrast in light/dark mode
  15. *
  16. * Hue numbers reference:
  17. * - 0: red
  18. * - 30: orange
  19. * - 60: yellow
  20. * - 120: green
  21. * - 180: cyan
  22. * - 240: blue
  23. * - 270: purple
  24. */
  25. const predefinedColorMap = {
  26. error: 0,
  27. client: 60,
  28. bailout: -1,
  29. ssr: 270,
  30. vite: 250,
  31. vite1: 240,
  32. vite2: 120,
  33. virtual: 140
  34. };
  35. function getHashColorFromString(name, opacity = 1) {
  36. if (predefinedColorMap[name]) return getHsla(predefinedColorMap[name], opacity);
  37. let hash = 0;
  38. for (let i = 0; i < name.length; i++) hash = name.charCodeAt(i) + ((hash << 5) - hash);
  39. const hue = hash % 360;
  40. return getHsla(hue, opacity);
  41. }
  42. function getHsla(hue, opacity = 1) {
  43. const saturation = hue === -1 ? 0 : isDark.value ? 50 : 100;
  44. const lightness = isDark.value ? 60 : 20;
  45. return `hsla(${hue}, ${saturation}%, ${lightness}%, ${opacity})`;
  46. }
  47. function getPluginColor(name, opacity = 1) {
  48. if (predefinedColorMap[name]) {
  49. const color = predefinedColorMap[name];
  50. if (typeof color === "number") return getHsla(color, opacity);
  51. else {
  52. if (opacity === 1) return color;
  53. const opacityHex = Math.floor(opacity * 255).toString(16).padStart(2, "0");
  54. return color + opacityHex;
  55. }
  56. }
  57. return getHashColorFromString(name, opacity);
  58. }
  59. var PluginName_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
  60. __name: "PluginName",
  61. props: {
  62. name: {},
  63. compact: { type: Boolean },
  64. colored: { type: Boolean },
  65. hide: { type: Boolean }
  66. },
  67. setup(__props) {
  68. const props = __props;
  69. const startsGeneric = [
  70. "__load__",
  71. "vite-plugin-",
  72. "vite-",
  73. "rollup-plugin-",
  74. "rollup-",
  75. "unplugin-"
  76. ];
  77. const startCompact = [...startsGeneric, "vite:"];
  78. function render() {
  79. const starts = props.compact ? startCompact : startsGeneric;
  80. for (const s of starts) if (props.name.startsWith(s)) {
  81. if (props.compact) return h("span", props.name.slice(s.length));
  82. return h("span", [h("span", { class: "op50" }, s), h("span", props.name.slice(s.length))]);
  83. }
  84. const parts = props.name.split(":");
  85. if (parts.length > 1) return h("span", [h("span", { style: { color: getHashColorFromString(parts[0]) } }, `${parts[0]}:`), h("span", parts.slice(1).join(":"))]);
  86. return h("span", props.name);
  87. }
  88. return (_ctx, _cache) => {
  89. return openBlock(), createBlock(resolveDynamicComponent(render));
  90. };
  91. }
  92. });
  93. var PluginName_default = PluginName_vue_vue_type_script_setup_true_lang_default;
  94. const _hoisted_1$3 = ["textContent"];
  95. var Badge_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
  96. __name: "Badge",
  97. props: {
  98. text: {},
  99. color: {
  100. type: [Boolean, Number],
  101. default: true
  102. },
  103. as: {},
  104. size: {}
  105. },
  106. setup(__props) {
  107. const props = __props;
  108. const style = computed(() => {
  109. if (!props.text || props.color === false) return {};
  110. return {
  111. color: typeof props.color === "number" ? getHsla(props.color) : getHashColorFromString(props.text),
  112. background: typeof props.color === "number" ? getHsla(props.color, .1) : getHashColorFromString(props.text, .1)
  113. };
  114. });
  115. const sizeClasses = computed(() => {
  116. switch (props.size || "sm") {
  117. case "sm": return "px-1.5 text-11px leading-1.6em";
  118. }
  119. return "";
  120. });
  121. return (_ctx, _cache) => {
  122. return openBlock(), createBlock(resolveDynamicComponent(_ctx.as || "span"), {
  123. "ws-nowrap": "",
  124. rounded: "",
  125. class: normalizeClass(unref(sizeClasses)),
  126. style: normalizeStyle(unref(style))
  127. }, {
  128. default: withCtx(() => [renderSlot(_ctx.$slots, "default", {}, () => [createBaseVNode("span", { textContent: toDisplayString(props.text) }, null, 8, _hoisted_1$3)])]),
  129. _: 3
  130. }, 8, ["class", "style"]);
  131. };
  132. }
  133. });
  134. var Badge_default = Badge_vue_vue_type_script_setup_true_lang_default;
  135. const _hoisted_1$2 = {
  136. "h-54px": "",
  137. flex: "~ none gap-2",
  138. border: "b main",
  139. "pl-4": "",
  140. "pr-4": "",
  141. "font-light": "",
  142. "children:my-auto": ""
  143. };
  144. var NavBar_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
  145. __name: "NavBar",
  146. setup(__props) {
  147. const payload = usePayloadStore();
  148. return (_ctx, _cache) => {
  149. return openBlock(), createElementBlock("nav", _hoisted_1$2, [renderSlot(_ctx.$slots, "default"), renderSlot(_ctx.$slots, "actions", {}, () => [!unref(payload).metadata.embedded ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
  150. _cache[2] || (_cache[2] = createBaseVNode("div", {
  151. mx1: "",
  152. "h-full": "",
  153. "w-0": "",
  154. border: "r main"
  155. }, null, -1)),
  156. _cache[3] || (_cache[3] = createBaseVNode("a", {
  157. "icon-btn": "",
  158. "text-lg": "",
  159. href: "https://github.com/antfu/vite-plugin-inspect",
  160. target: "_blank"
  161. }, [createBaseVNode("div", { "i-carbon-logo-github": "" })], -1)),
  162. createBaseVNode("button", {
  163. class: "icon-btn text-lg",
  164. title: "Toggle Dark Mode",
  165. onClick: _cache[0] || (_cache[0] = ($event) => unref(toggleDark)())
  166. }, [..._cache[1] || (_cache[1] = [createBaseVNode("span", {
  167. "i-carbon-sun": "",
  168. "dark:i-carbon-moon": ""
  169. }, null, -1)])])
  170. ], 64)) : createCommentVNode("", true)])]);
  171. };
  172. }
  173. });
  174. var NavBar_default = NavBar_vue_vue_type_script_setup_true_lang_default;
  175. const _hoisted_1$1 = {
  176. flex: "~ gap-1 items-center",
  177. border: "~ subtle rounded",
  178. "bg-subtle": "",
  179. p1: ""
  180. };
  181. var SegmentControl_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
  182. __name: "SegmentControl",
  183. props: {
  184. options: {},
  185. modelValue: {}
  186. },
  187. emits: ["update:modelValue"],
  188. setup(__props) {
  189. return (_ctx, _cache) => {
  190. const _component_Badge = Badge_default;
  191. return openBlock(), createElementBlock("div", _hoisted_1$1, [(openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.options, (option) => {
  192. return openBlock(), createBlock(_component_Badge, {
  193. key: option.value,
  194. class: normalizeClass(["px-2 py-1 text-xs font-mono", option.value === _ctx.modelValue ? "" : "op50"]),
  195. color: option.value === _ctx.modelValue,
  196. "aria-pressed": option.value === _ctx.modelValue,
  197. size: "none",
  198. text: option.label,
  199. as: "button",
  200. onClick: ($event) => _ctx.$emit("update:modelValue", option.value)
  201. }, null, 8, [
  202. "class",
  203. "color",
  204. "aria-pressed",
  205. "text",
  206. "onClick"
  207. ]);
  208. }), 128))]);
  209. };
  210. }
  211. });
  212. var SegmentControl_default = SegmentControl_vue_vue_type_script_setup_true_lang_default;
  213. const _hoisted_1 = { flex: "~ gap-2" };
  214. var QuerySelector_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
  215. __name: "QuerySelector",
  216. setup(__props) {
  217. const payload = usePayloadStore();
  218. return (_ctx, _cache) => {
  219. const _component_SegmentControl = SegmentControl_default;
  220. return openBlock(), createElementBlock("div", _hoisted_1, [unref(payload).metadata.instances.length > 1 ? (openBlock(), createBlock(_component_SegmentControl, {
  221. key: 0,
  222. modelValue: unref(payload).query.vite,
  223. "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => unref(payload).query.vite = $event),
  224. options: unref(payload).metadata.instances.map((i) => ({
  225. label: i.vite,
  226. value: i.vite
  227. }))
  228. }, null, 8, ["modelValue", "options"])) : createCommentVNode("", true), createVNode(_component_SegmentControl, {
  229. modelValue: unref(payload).query.env,
  230. "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => unref(payload).query.env = $event),
  231. options: unref(payload).instance.environments.map((i) => ({
  232. label: i,
  233. value: i
  234. }))
  235. }, null, 8, ["modelValue", "options"])]);
  236. };
  237. }
  238. });
  239. var QuerySelector_default = QuerySelector_vue_vue_type_script_setup_true_lang_default;
  240. export { Badge_default, Container_default, NavBar_default, PluginName_default, QuerySelector_default, SegmentControl_default, getPluginColor };