UNPKG

storybook

Version:

Storybook: Develop, document, and test UI components in isolation

164 lines (154 loc) • 8.01 kB
import CJS_COMPAT_NODE_URL_x4zmn749tn from 'node:url'; import CJS_COMPAT_NODE_PATH_x4zmn749tn from 'node:path'; import CJS_COMPAT_NODE_MODULE_x4zmn749tn from "node:module"; var __filename = CJS_COMPAT_NODE_URL_x4zmn749tn.fileURLToPath(import.meta.url); var __dirname = CJS_COMPAT_NODE_PATH_x4zmn749tn.dirname(__filename); var require = CJS_COMPAT_NODE_MODULE_x4zmn749tn.createRequire(import.meta.url); // ------------------------------------------------------------ // end of CJS compatibility banner, injected by Storybook's esbuild configuration // ------------------------------------------------------------ // ../../node_modules/tiny-invariant/dist/esm/tiny-invariant.js var isProduction = process.env.NODE_ENV === "production", prefix = "Invariant failed"; function invariant(condition, message) { if (!condition) { if (isProduction) throw new Error(prefix); var provided = typeof message == "function" ? message() : message, value = provided ? "".concat(prefix, ": ").concat(provided) : prefix; throw new Error(value); } } // ../../node_modules/empathic/resolve.mjs import { createRequire } from "node:module"; import { isAbsolute, join, resolve } from "node:path"; import { fileURLToPath } from "node:url"; function absolute(input, root) { return isAbsolute(input) ? input : resolve(root || ".", input); } function from(root, ident, silent) { try { let r = root instanceof URL || root.startsWith("file://") ? join(fileURLToPath(root), "noop.js") : join(absolute(root), "noop.js"); return createRequire(r).resolve(ident); } catch (err) { if (!silent) throw err; } } // ../../node_modules/empathic/walk.mjs import { dirname } from "node:path"; function up(base, options) { let { last, cwd } = options || {}, tmp = absolute(base, cwd), root = absolute(last || "/", cwd), prev, arr = []; for (; prev !== root && (arr.push(tmp), tmp = dirname(prev = tmp), tmp !== prev); ) ; return arr; } // ../../node_modules/empathic/find.mjs import { join as join2 } from "node:path"; import { existsSync, statSync } from "node:fs"; function up2(name, options) { let dir, tmp, start = options && options.cwd || ""; for (dir of up(start, options)) if (tmp = join2(dir, name), existsSync(tmp)) return tmp; } function any(names, options) { let dir, start = options && options.cwd || "", j = 0, len = names.length, tmp; for (dir of up(start, options)) for (j = 0; j < len; j++) if (tmp = join2(dir, names[j]), existsSync(tmp)) return tmp; } // ../../node_modules/detect-indent/index.js var INDENT_REGEX = /^(?:( )+|\t+)/, INDENT_TYPE_SPACE = "space"; function makeIndentsMap(string, ignoreSingleSpaces) { let indents = /* @__PURE__ */ new Map(), previousSize = 0, previousIndentType, key; for (let line of string.split(/\n/g)) { if (!line) continue; let indent, indentType, use, weight, entry, matches = line.match(INDENT_REGEX); if (matches === null) previousSize = 0, previousIndentType = ""; else { if (indent = matches[0].length, indentType = matches[1] ? INDENT_TYPE_SPACE : "tab", ignoreSingleSpaces && indentType === INDENT_TYPE_SPACE && indent === 1) continue; indentType !== previousIndentType && (previousSize = 0), previousIndentType = indentType, use = 1, weight = 0; let indentDifference = indent - previousSize; if (previousSize = indent, indentDifference === 0) use = 0, weight = 1; else { let absoluteIndentDifference = indentDifference > 0 ? indentDifference : -indentDifference; key = encodeIndentsKey(indentType, absoluteIndentDifference); } entry = indents.get(key), entry = entry === void 0 ? [1, 0] : [entry[0] + use, entry[1] + weight], indents.set(key, entry); } } return indents; } function encodeIndentsKey(indentType, indentAmount) { return (indentType === INDENT_TYPE_SPACE ? "s" : "t") + String(indentAmount); } function decodeIndentsKey(indentsKey) { let type = indentsKey[0] === "s" ? INDENT_TYPE_SPACE : "tab", amount = Number(indentsKey.slice(1)); return { type, amount }; } function getMostUsedKey(indents) { let result, maxUsed = 0, maxWeight = 0; for (let [key, [usedCount, weight]] of indents) (usedCount > maxUsed || usedCount === maxUsed && weight > maxWeight) && (maxUsed = usedCount, maxWeight = weight, result = key); return result; } function makeIndentString(type, amount) { return (type === INDENT_TYPE_SPACE ? " " : " ").repeat(amount); } function detectIndent(string) { if (typeof string != "string") throw new TypeError("Expected a string"); let indents = makeIndentsMap(string, !0); indents.size === 0 && (indents = makeIndentsMap(string, !1)); let keyOfMostUsedIndent = getMostUsedKey(indents), type, amount = 0, indent = ""; return keyOfMostUsedIndent !== void 0 && ({ type, amount } = decodeIndentsKey(keyOfMostUsedIndent), indent = makeIndentString(type, amount)), { amount, type, indent }; } // ../../node_modules/strip-json-comments/index.js var singleComment = /* @__PURE__ */ Symbol("singleComment"), multiComment = /* @__PURE__ */ Symbol("multiComment"), stripWithoutWhitespace = () => "", stripWithWhitespace = (string, start, end) => string.slice(start, end).replace(/[^ \t\r\n]/g, " "), isEscaped = (jsonString, quotePosition) => { let index = quotePosition - 1, backslashCount = 0; for (; jsonString[index] === "\\"; ) index -= 1, backslashCount += 1; return !!(backslashCount % 2); }; function stripJsonComments(jsonString, { whitespace = !0, trailingCommas = !1 } = {}) { if (typeof jsonString != "string") throw new TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof jsonString}\``); let strip = whitespace ? stripWithWhitespace : stripWithoutWhitespace, isInsideString = !1, isInsideComment = !1, offset = 0, buffer = "", result = "", commaIndex = -1; for (let index = 0; index < jsonString.length; index++) { let currentCharacter = jsonString[index], nextCharacter = jsonString[index + 1]; if (!isInsideComment && currentCharacter === '"' && (isEscaped(jsonString, index) || (isInsideString = !isInsideString)), !isInsideString) if (!isInsideComment && currentCharacter + nextCharacter === "//") buffer += jsonString.slice(offset, index), offset = index, isInsideComment = singleComment, index++; else if (isInsideComment === singleComment && currentCharacter + nextCharacter === `\r `) { index++, isInsideComment = !1, buffer += strip(jsonString, offset, index), offset = index; continue; } else if (isInsideComment === singleComment && currentCharacter === ` `) isInsideComment = !1, buffer += strip(jsonString, offset, index), offset = index; else if (!isInsideComment && currentCharacter + nextCharacter === "/*") { buffer += jsonString.slice(offset, index), offset = index, isInsideComment = multiComment, index++; continue; } else if (isInsideComment === multiComment && currentCharacter + nextCharacter === "*/") { index++, isInsideComment = !1, buffer += strip(jsonString, offset, index + 1), offset = index + 1; continue; } else trailingCommas && !isInsideComment && (commaIndex !== -1 ? currentCharacter === "}" || currentCharacter === "]" ? (buffer += jsonString.slice(offset, index), result += strip(buffer, 0, 1) + buffer.slice(1), buffer = "", offset = index, commaIndex = -1) : currentCharacter !== " " && currentCharacter !== " " && currentCharacter !== "\r" && currentCharacter !== ` ` && (buffer += jsonString.slice(offset, index), offset = index, commaIndex = -1) : currentCharacter === "," && (result += buffer + jsonString.slice(offset, index), buffer = "", offset = index, commaIndex = index)); } let remaining = isInsideComment === singleComment ? strip(jsonString, offset) : jsonString.slice(offset); return result + buffer + remaining; } export { invariant, from, up, up2, any, detectIndent, stripJsonComments };