@blogmcp/mdx-schema 0.1.0
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/dist/checkPin.d.ts +48 -0
- package/dist/checkPin.js +139 -0
- package/dist/checkPin.js.map +1 -0
- package/dist/composables/useMdxParsing.d.ts +71 -0
- package/dist/composables/useMdxParsing.js +239 -0
- package/dist/composables/useMdxParsing.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/metadata/customComponents.d.ts +128 -0
- package/dist/metadata/customComponents.js +301 -0
- package/dist/metadata/customComponents.js.map +1 -0
- package/dist/metadata/index.d.ts +24 -0
- package/dist/metadata/index.js +427 -0
- package/dist/metadata/index.js.map +1 -0
- package/dist/metadata/validate.d.ts +46 -0
- package/dist/metadata/validate.js +95 -0
- package/dist/metadata/validate.js.map +1 -0
- package/dist/prepareProps.d.ts +42 -0
- package/dist/prepareProps.js +177 -0
- package/dist/prepareProps.js.map +1 -0
- package/dist/styles/index.d.ts +203 -0
- package/dist/styles/index.js +162 -0
- package/dist/styles/index.js.map +1 -0
- package/dist/types/index.d.ts +421 -0
- package/dist/types/index.js +25 -0
- package/dist/types/index.js.map +1 -0
- package/dist/version.d.ts +23 -0
- package/dist/version.js +23 -0
- package/dist/version.js.map +1 -0
- package/package.json +80 -0
- package/src/checkPin.ts +163 -0
- package/src/composables/useMdxParsing.ts +248 -0
- package/src/index.ts +22 -0
- package/src/metadata/customComponents.ts +360 -0
- package/src/metadata/index.ts +437 -0
- package/src/metadata/validate.ts +153 -0
- package/src/prepareProps.ts +219 -0
- package/src/styles/index.ts +196 -0
- package/src/types/index.ts +469 -0
- package/src/version.ts +24 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Render-time prop normalization shim.
|
|
3
|
+
*
|
|
4
|
+
* Centralized for ALL renderers (Vue, React, and the Headless SDK) — see
|
|
5
|
+
* the `prepareNotCalled` CI rule. Walks `metadata.deprecated[]` and
|
|
6
|
+
* applies each entry to a shallow-cloned copy of `rawProps`. Returns the
|
|
7
|
+
* normalized object; the input is never mutated.
|
|
8
|
+
*
|
|
9
|
+
* Per-kind behaviour:
|
|
10
|
+
* - propRename: if `rawProps[entry.prop]` is set AND
|
|
11
|
+
* `rawProps[entry.aliasFor]` is NOT set, copy the value across.
|
|
12
|
+
* When BOTH are present the new name wins (latest schema beats stored
|
|
13
|
+
* legacy). Old name is then dropped from the returned object so the
|
|
14
|
+
* downstream component never sees it.
|
|
15
|
+
* - enumValueRename: if `rawProps[entry.prop]` is a string AND is a key
|
|
16
|
+
* of `entry.valueAliases`, replace it with the mapped value.
|
|
17
|
+
* - propRemoved: KEEPS the prop in the returned object (review finding —
|
|
18
|
+
* deleting silently strips data that custom components, the headless
|
|
19
|
+
* SDK, or a future codemod-retry may still need). Logs once so an
|
|
20
|
+
* operator can investigate the tenant's `schema_version`.
|
|
21
|
+
* - propBecameRequired: if `rawProps[entry.prop]` is MISSING (legacy
|
|
22
|
+
* article authored before the prop became required, or stored
|
|
23
|
+
* content the backfill codemod hasn't touched), inject
|
|
24
|
+
* `entry.defaultValue` as the runtime fallback. Logs so an operator
|
|
25
|
+
* can investigate why the codemod hasn't caught up. If the prop is
|
|
26
|
+
* already present, no-op (the codemod did its job or the article
|
|
27
|
+
* was authored post-flip).
|
|
28
|
+
*
|
|
29
|
+
* Logging is process-deduped via the module-level `loggedKeys` Set
|
|
30
|
+
* keyed on `${componentName}.${kind}.${prop}` so each soft-break warns
|
|
31
|
+
* exactly once per process lifetime. Production silence is guaranteed
|
|
32
|
+
* by the `process.env.NODE_ENV === 'production'` short-circuit.
|
|
33
|
+
*/
|
|
34
|
+
import { isComponentStructureChangeEntry, isDefaultChangeAcceptedEntry, isEnumValueRenameEntry, isPropBecameRequiredEntry, isPropRemovedEntry, isPropRenameEntry, } from './types/index.js';
|
|
35
|
+
/**
|
|
36
|
+
* Process-lifetime dedupe set. Keys: `${componentName}.${kind}.${prop}`.
|
|
37
|
+
* Exported only for tests (so they can clear between specs).
|
|
38
|
+
*/
|
|
39
|
+
export const loggedKeys = new Set();
|
|
40
|
+
/** Test-only — never call from production code. */
|
|
41
|
+
export function _resetPrepareDedupeForTests() {
|
|
42
|
+
loggedKeys.clear();
|
|
43
|
+
}
|
|
44
|
+
function isProduction() {
|
|
45
|
+
// Node-safe: explicit guard so the shim works in browsers / Workers /
|
|
46
|
+
// any runtime without a `process` global. We treat "no process" as
|
|
47
|
+
// "not production" — surfacing dev-mode warnings is the safer default.
|
|
48
|
+
return typeof process !== 'undefined'
|
|
49
|
+
&& typeof process.env !== 'undefined'
|
|
50
|
+
&& process.env.NODE_ENV === 'production';
|
|
51
|
+
}
|
|
52
|
+
function logOnce(key, message) {
|
|
53
|
+
if (isProduction())
|
|
54
|
+
return;
|
|
55
|
+
if (loggedKeys.has(key))
|
|
56
|
+
return;
|
|
57
|
+
loggedKeys.add(key);
|
|
58
|
+
// eslint-disable-next-line no-console
|
|
59
|
+
console.warn(`[mdx-schema] ${message}`);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Matches event-handler-shaped prop keys: `onclick`, `onError`, `ONMOUSEOVER`,
|
|
63
|
+
* `onPointerDown`, etc.
|
|
64
|
+
*/
|
|
65
|
+
const EVENT_HANDLER_PROP_RE = /^on[A-Za-z]/i;
|
|
66
|
+
/**
|
|
67
|
+
* Defense-in-depth filter that drops STRING-valued event-handler-shaped
|
|
68
|
+
* props.
|
|
69
|
+
*
|
|
70
|
+
* The threat model: a stored MDX article writes
|
|
71
|
+
* `<Button onclick="alert(1)" label="x" />`. The MDX regex parser yields
|
|
72
|
+
* `{onclick: 'alert(1)', label: 'x'}` — a STRING value. Most of our
|
|
73
|
+
* components don't spread incoming props onto DOM elements, but the
|
|
74
|
+
* wrapping HOCs in `mdx-render-vue/registry.ts` and
|
|
75
|
+
* `mdx-render-react/server-render-map.ts` DO pass props through verbatim
|
|
76
|
+
* — a future component that spreads `{...rest}` onto a DOM element would
|
|
77
|
+
* render the `onclick` attribute and execute attacker code.
|
|
78
|
+
*
|
|
79
|
+
* String-only: we keep function-typed `onClick: () => {}` props since they
|
|
80
|
+
* come from programmatic mount (host code, not stored MDX content) and
|
|
81
|
+
* Vue/React treat them as event bindings — never as inline HTML attributes.
|
|
82
|
+
* MDX content can only ever produce STRING-valued attributes, so the
|
|
83
|
+
* string check is a precise fit to the threat.
|
|
84
|
+
*
|
|
85
|
+
* Layer A (HTML sanitizer in @blogmcp/sanitize) catches `on*=` in raw
|
|
86
|
+
* HTML within article bodies; this catches `on*=` in MDX component props
|
|
87
|
+
* (invisible to DOMPurify, which only sees the final HTML output).
|
|
88
|
+
*
|
|
89
|
+
* No real schema component currently has an `on*`-shaped prop, so this is
|
|
90
|
+
* safe across the 11-component library. Documented in the
|
|
91
|
+
* trust-contract docs.
|
|
92
|
+
*/
|
|
93
|
+
function isDangerousEventHandlerProp(key, value) {
|
|
94
|
+
return EVENT_HANDLER_PROP_RE.test(key) && typeof value === 'string';
|
|
95
|
+
}
|
|
96
|
+
export function prepareProps(rawProps, metadata) {
|
|
97
|
+
// Shallow clone — never mutate the caller's object.
|
|
98
|
+
const props = { ...rawProps };
|
|
99
|
+
// Defense in depth — strip string-valued event-handler-shaped keys
|
|
100
|
+
// before anything else runs. See `isDangerousEventHandlerProp` doc above.
|
|
101
|
+
for (const key of Object.keys(props)) {
|
|
102
|
+
if (isDangerousEventHandlerProp(key, props[key])) {
|
|
103
|
+
delete props[key];
|
|
104
|
+
logOnce(`${metadata.name}.eventHandlerProp.${key}`, `${metadata.name}: dropped string-valued event-handler-shaped prop "${key}" — MDX content cannot bind DOM event handlers (potential XSS vector).`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
for (const entry of metadata.deprecated) {
|
|
108
|
+
if (isPropRenameEntry(entry)) {
|
|
109
|
+
const oldPresent = Object.prototype.hasOwnProperty.call(props, entry.prop);
|
|
110
|
+
const newPresent = Object.prototype.hasOwnProperty.call(props, entry.aliasFor);
|
|
111
|
+
if (oldPresent) {
|
|
112
|
+
if (!newPresent) {
|
|
113
|
+
props[entry.aliasFor] = props[entry.prop];
|
|
114
|
+
}
|
|
115
|
+
// If both present, the explicit new name wins — drop the old
|
|
116
|
+
// name regardless so the rendered component sees only the
|
|
117
|
+
// canonical shape.
|
|
118
|
+
delete props[entry.prop];
|
|
119
|
+
logOnce(`${metadata.name}.propRename.${entry.prop}`, `${metadata.name}: prop "${entry.prop}" was renamed to "${entry.aliasFor}" in ${entry.since} (removed in ${entry.removeIn}). ${entry.message}`);
|
|
120
|
+
}
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (isEnumValueRenameEntry(entry)) {
|
|
124
|
+
const current = props[entry.prop];
|
|
125
|
+
if (typeof current === 'string' && Object.prototype.hasOwnProperty.call(entry.valueAliases, current)) {
|
|
126
|
+
const mapped = entry.valueAliases[current];
|
|
127
|
+
props[entry.prop] = mapped;
|
|
128
|
+
logOnce(`${metadata.name}.enumValueRename.${entry.prop}`, `${metadata.name}.${entry.prop}: value "${current}" was renamed to "${mapped}" in ${entry.since} (removed in ${entry.removeIn}). ${entry.message}`);
|
|
129
|
+
}
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (isPropRemovedEntry(entry)) {
|
|
133
|
+
if (Object.prototype.hasOwnProperty.call(props, entry.prop)) {
|
|
134
|
+
// Review fix: KEEP the prop in the output. Silently deleting
|
|
135
|
+
// it strips data that custom components (registerCustomComponent
|
|
136
|
+
// path) and the headless SDK may still need. The presence is a
|
|
137
|
+
// signal to investigate (stale schema_version, codemod skipped),
|
|
138
|
+
// not a license to drop data. (The historical concern about
|
|
139
|
+
// breaking the propRequiredFlipped flow is now moot — that
|
|
140
|
+
// case uses the dedicated `propBecameRequired` kind below.)
|
|
141
|
+
logOnce(`${metadata.name}.propRemoved.${entry.prop}`, `${metadata.name}: prop "${entry.prop}" was removed in ${entry.removeIn} but is still present on content (run codemod ${entry.codemod}). ${entry.message}`);
|
|
142
|
+
}
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (isPropBecameRequiredEntry(entry)) {
|
|
146
|
+
// Render-time safety net: when stored content omits a now-required
|
|
147
|
+
// prop (legacy article, codemod pending, tenant on stale
|
|
148
|
+
// schema_version), inject the codemod's backfill default so the
|
|
149
|
+
// receiving component never sees `undefined` for what its type
|
|
150
|
+
// contract says is mandatory. When the prop IS present we no-op —
|
|
151
|
+
// the codemod did its job or the article was authored post-flip.
|
|
152
|
+
if (!Object.prototype.hasOwnProperty.call(props, entry.prop)) {
|
|
153
|
+
props[entry.prop] = entry.defaultValue;
|
|
154
|
+
logOnce(`${metadata.name}.propBecameRequired.${entry.prop}`, `${metadata.name}: prop "${entry.prop}" became required in ${entry.since} but is missing from stored content (run codemod ${entry.codemod}; injected default for render). ${entry.message}`);
|
|
155
|
+
}
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (isDefaultChangeAcceptedEntry(entry)) {
|
|
159
|
+
// Pure release-notes acknowledgement — no render-time mutation.
|
|
160
|
+
// The shim does NOT rewrite stored props (authors opted in to drift).
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (isComponentStructureChangeEntry(entry)) {
|
|
164
|
+
// Render-time bookkeeping only — `hasChildren` / `selfClosing` are
|
|
165
|
+
// a parser-level concern, not a prop. The CI classifier enforces
|
|
166
|
+
// these entries; the shim has no prop to rewrite.
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
// Exhaustive-check escape hatch — TypeScript proves the union is
|
|
170
|
+
// fully matched; if a future tagged variant is added without an arm
|
|
171
|
+
// here this line forces a type error.
|
|
172
|
+
const _exhaustive = entry;
|
|
173
|
+
void _exhaustive;
|
|
174
|
+
}
|
|
175
|
+
return props;
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=prepareProps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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AC,OAAO,EAAE,CAC3J,CAAA;YACH,CAAC;YACD,SAAQ;QACV,CAAC;QAED,IAAI,yBAAyB,CAAC,KAAK,CAAC,EAAE,CAAC;YACrC,mEAAmE;YACnE,yDAAyD;YACzD,gEAAgE;YAChE,+DAA+D;YAC/D,kEAAkE;YAClE,iEAAiE;YACjE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC7D,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,YAAY,CAAA;gBACtC,OAAO,CACL,GAAG,QAAQ,CAAC,IAAI,uBAAuB,KAAK,CAAC,IAAI,EAAE,EACnD,GAAG,QAAQ,CAAC,IAAI,WAAW,KAAK,CAAC,IAAI,wBAAwB,KAAK,CAAC,KAAK,oDAAoD,KAAK,CAAC,OAAO,mCAAmC,KAAK,CAAC,OAAO,EAAE,CAC5L,CAAA;YACH,CAAC;YACD,SAAQ;QACV,CAAC;QAED,IAAI,4BAA4B,CAAC,KAAK,CAAC,EAAE,CAAC;YACxC,gEAAgE;YAChE,sEAAsE;YACtE,SAAQ;QACV,CAAC;QAED,IAAI,+BAA+B,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3C,mEAAmE;YACnE,iEAAiE;YACjE,kDAAkD;YAClD,SAAQ;QACV,CAAC;QAED,iEAAiE;QACjE,oEAAoE;QACpE,sCAAsC;QACtC,MAAM,WAAW,GAAU,KAAK,CAAA;QAChC,KAAK,WAAW,CAAA;IAClB,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Tailwind class tables for table-driven MDX components.
|
|
3
|
+
*
|
|
4
|
+
* Pure data — no framework dependencies. Lifted VERBATIM from the reference
|
|
5
|
+
* Vue SFCs (`@blogmcp/mdx-render-vue/src/render/...`) so that the Vue and
|
|
6
|
+
* React renderers compose byte-identical class strings. This is the single
|
|
7
|
+
* source of truth: when a variant/color/size class changes, change it here.
|
|
8
|
+
*
|
|
9
|
+
* Tailwind JIT note: consumer Tailwind configs MUST scan this file (e.g.
|
|
10
|
+
* `./node_modules/@blogmcp/mdx-schema/src/styles/**`) so every class string
|
|
11
|
+
* below is seen at build time. Interpolated class names would not be visible
|
|
12
|
+
* to the JIT — every class here is a literal.
|
|
13
|
+
*/
|
|
14
|
+
import type { GalleryProps } from '../types/index.js';
|
|
15
|
+
export declare const buttonStyles: {
|
|
16
|
+
readonly base: "inline-flex items-center justify-center font-medium border transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2";
|
|
17
|
+
readonly size: {
|
|
18
|
+
readonly sm: "px-2.5 py-1 text-sm rounded";
|
|
19
|
+
readonly md: "px-4 py-2 text-sm rounded-md";
|
|
20
|
+
readonly lg: "px-5 py-2.5 text-base rounded-md";
|
|
21
|
+
};
|
|
22
|
+
readonly variantColor: {
|
|
23
|
+
readonly solid: {
|
|
24
|
+
readonly primary: "bg-blue-600 text-white hover:bg-blue-700 border-transparent";
|
|
25
|
+
readonly neutral: "bg-gray-800 text-white hover:bg-gray-900 border-transparent";
|
|
26
|
+
readonly success: "bg-emerald-600 text-white hover:bg-emerald-700 border-transparent";
|
|
27
|
+
readonly warning: "bg-amber-500 text-white hover:bg-amber-600 border-transparent";
|
|
28
|
+
readonly error: "bg-red-600 text-white hover:bg-red-700 border-transparent";
|
|
29
|
+
};
|
|
30
|
+
readonly outline: {
|
|
31
|
+
readonly primary: "border-blue-600 text-blue-700 hover:bg-blue-50";
|
|
32
|
+
readonly neutral: "border-gray-400 text-gray-800 hover:bg-gray-50";
|
|
33
|
+
readonly success: "border-emerald-600 text-emerald-700 hover:bg-emerald-50";
|
|
34
|
+
readonly warning: "border-amber-500 text-amber-700 hover:bg-amber-50";
|
|
35
|
+
readonly error: "border-red-600 text-red-700 hover:bg-red-50";
|
|
36
|
+
};
|
|
37
|
+
readonly soft: {
|
|
38
|
+
readonly primary: "bg-blue-50 text-blue-700 hover:bg-blue-100 border-transparent";
|
|
39
|
+
readonly neutral: "bg-gray-100 text-gray-800 hover:bg-gray-200 border-transparent";
|
|
40
|
+
readonly success: "bg-emerald-50 text-emerald-700 hover:bg-emerald-100 border-transparent";
|
|
41
|
+
readonly warning: "bg-amber-50 text-amber-700 hover:bg-amber-100 border-transparent";
|
|
42
|
+
readonly error: "bg-red-50 text-red-700 hover:bg-red-100 border-transparent";
|
|
43
|
+
};
|
|
44
|
+
readonly ghost: {
|
|
45
|
+
readonly primary: "text-blue-700 hover:bg-blue-50 border-transparent";
|
|
46
|
+
readonly neutral: "text-gray-800 hover:bg-gray-100 border-transparent";
|
|
47
|
+
readonly success: "text-emerald-700 hover:bg-emerald-50 border-transparent";
|
|
48
|
+
readonly warning: "text-amber-700 hover:bg-amber-50 border-transparent";
|
|
49
|
+
readonly error: "text-red-700 hover:bg-red-50 border-transparent";
|
|
50
|
+
};
|
|
51
|
+
readonly link: {
|
|
52
|
+
readonly primary: "text-blue-700 hover:underline border-transparent bg-transparent";
|
|
53
|
+
readonly neutral: "text-gray-800 hover:underline border-transparent bg-transparent";
|
|
54
|
+
readonly success: "text-emerald-700 hover:underline border-transparent bg-transparent";
|
|
55
|
+
readonly warning: "text-amber-700 hover:underline border-transparent bg-transparent";
|
|
56
|
+
readonly error: "text-red-700 hover:underline border-transparent bg-transparent";
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
export declare const badgeStyles: {
|
|
61
|
+
readonly base: "inline-flex items-center px-2 py-0.5 text-xs font-medium border rounded-full";
|
|
62
|
+
readonly variantColor: {
|
|
63
|
+
readonly solid: {
|
|
64
|
+
readonly primary: "bg-blue-600 text-white border-transparent";
|
|
65
|
+
readonly neutral: "bg-gray-700 text-white border-transparent";
|
|
66
|
+
readonly success: "bg-emerald-600 text-white border-transparent";
|
|
67
|
+
readonly warning: "bg-amber-500 text-white border-transparent";
|
|
68
|
+
readonly error: "bg-red-600 text-white border-transparent";
|
|
69
|
+
};
|
|
70
|
+
readonly soft: {
|
|
71
|
+
readonly primary: "bg-blue-100 text-blue-800 border-transparent";
|
|
72
|
+
readonly neutral: "bg-gray-100 text-gray-700 border-transparent";
|
|
73
|
+
readonly success: "bg-emerald-100 text-emerald-800 border-transparent";
|
|
74
|
+
readonly warning: "bg-amber-100 text-amber-800 border-transparent";
|
|
75
|
+
readonly error: "bg-red-100 text-red-800 border-transparent";
|
|
76
|
+
};
|
|
77
|
+
readonly outline: {
|
|
78
|
+
readonly primary: "border-blue-500 text-blue-700";
|
|
79
|
+
readonly neutral: "border-gray-400 text-gray-700";
|
|
80
|
+
readonly success: "border-emerald-500 text-emerald-700";
|
|
81
|
+
readonly warning: "border-amber-500 text-amber-700";
|
|
82
|
+
readonly error: "border-red-500 text-red-700";
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
export declare const alertStyles: {
|
|
87
|
+
readonly base: "mdx-alert flex gap-3 rounded-md border px-4 py-3 text-sm";
|
|
88
|
+
readonly severity: {
|
|
89
|
+
readonly info: {
|
|
90
|
+
readonly wrap: "bg-blue-50 border-blue-200 text-blue-900";
|
|
91
|
+
readonly icon: "lucide:info";
|
|
92
|
+
readonly iconClass: "text-blue-600";
|
|
93
|
+
};
|
|
94
|
+
readonly success: {
|
|
95
|
+
readonly wrap: "bg-emerald-50 border-emerald-200 text-emerald-900";
|
|
96
|
+
readonly icon: "lucide:check-circle-2";
|
|
97
|
+
readonly iconClass: "text-emerald-600";
|
|
98
|
+
};
|
|
99
|
+
readonly warning: {
|
|
100
|
+
readonly wrap: "bg-amber-50 border-amber-200 text-amber-900";
|
|
101
|
+
readonly icon: "lucide:alert-triangle";
|
|
102
|
+
readonly iconClass: "text-amber-600";
|
|
103
|
+
};
|
|
104
|
+
readonly error: {
|
|
105
|
+
readonly wrap: "bg-red-50 border-red-200 text-red-900";
|
|
106
|
+
readonly icon: "lucide:alert-octagon";
|
|
107
|
+
readonly iconClass: "text-red-600";
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
export declare const calloutStyles: {
|
|
112
|
+
readonly default: {
|
|
113
|
+
readonly base: "callout my-6 p-4 rounded-lg border-l-4";
|
|
114
|
+
readonly type: {
|
|
115
|
+
readonly info: {
|
|
116
|
+
readonly bg: "bg-blue-50";
|
|
117
|
+
readonly border: "border-blue-500";
|
|
118
|
+
readonly text: "text-blue-900";
|
|
119
|
+
readonly iconColor: "text-blue-500";
|
|
120
|
+
};
|
|
121
|
+
readonly warning: {
|
|
122
|
+
readonly bg: "bg-yellow-50";
|
|
123
|
+
readonly border: "border-yellow-500";
|
|
124
|
+
readonly text: "text-yellow-900";
|
|
125
|
+
readonly iconColor: "text-yellow-500";
|
|
126
|
+
};
|
|
127
|
+
readonly tip: {
|
|
128
|
+
readonly bg: "bg-green-50";
|
|
129
|
+
readonly border: "border-green-500";
|
|
130
|
+
readonly text: "text-green-900";
|
|
131
|
+
readonly iconColor: "text-green-500";
|
|
132
|
+
};
|
|
133
|
+
readonly danger: {
|
|
134
|
+
readonly bg: "bg-red-50";
|
|
135
|
+
readonly border: "border-red-500";
|
|
136
|
+
readonly text: "text-red-900";
|
|
137
|
+
readonly iconColor: "text-red-500";
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
readonly minimal: {
|
|
142
|
+
readonly base: "callout my-6 p-4 rounded border";
|
|
143
|
+
readonly type: {
|
|
144
|
+
readonly info: {
|
|
145
|
+
readonly bg: "bg-blue-50";
|
|
146
|
+
readonly border: "border-blue-200";
|
|
147
|
+
readonly text: "text-blue-800";
|
|
148
|
+
};
|
|
149
|
+
readonly warning: {
|
|
150
|
+
readonly bg: "bg-yellow-50";
|
|
151
|
+
readonly border: "border-yellow-200";
|
|
152
|
+
readonly text: "text-yellow-800";
|
|
153
|
+
};
|
|
154
|
+
readonly tip: {
|
|
155
|
+
readonly bg: "bg-green-50";
|
|
156
|
+
readonly border: "border-green-200";
|
|
157
|
+
readonly text: "text-green-800";
|
|
158
|
+
};
|
|
159
|
+
readonly danger: {
|
|
160
|
+
readonly bg: "bg-red-50";
|
|
161
|
+
readonly border: "border-red-200";
|
|
162
|
+
readonly text: "text-red-800";
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
/** SVG path data for the `default` variant icon, keyed by callout type. */
|
|
167
|
+
readonly iconPaths: {
|
|
168
|
+
readonly info: "M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z";
|
|
169
|
+
readonly warning: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z";
|
|
170
|
+
readonly tip: "M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z";
|
|
171
|
+
readonly danger: "M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z";
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
export type ButtonVariant = keyof typeof buttonStyles.variantColor;
|
|
175
|
+
export type ButtonColor = keyof typeof buttonStyles.variantColor.solid;
|
|
176
|
+
export type ButtonSize = keyof typeof buttonStyles.size;
|
|
177
|
+
export type BadgeVariant = keyof typeof badgeStyles.variantColor;
|
|
178
|
+
export type BadgeColor = keyof typeof badgeStyles.variantColor.solid;
|
|
179
|
+
export type AlertSeverity = keyof typeof alertStyles.severity;
|
|
180
|
+
export type CalloutVariant = 'default' | 'minimal';
|
|
181
|
+
export interface GalleryTileLayout {
|
|
182
|
+
/** Inline style for the tile box (sets aspect-ratio, or empty for "auto"). */
|
|
183
|
+
tileStyle: Record<string, string>;
|
|
184
|
+
/** Inline style for the img/video (object-fit + object-position, or empty). */
|
|
185
|
+
mediaStyle: Record<string, string>;
|
|
186
|
+
/** Sizing class for the img/video: fills the fixed tile, or natural height. */
|
|
187
|
+
mediaSizeClass: string;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Derive tile/media inline styles from the Gallery `aspectRatio`/`fit`/`position`
|
|
191
|
+
* props.
|
|
192
|
+
*
|
|
193
|
+
* - `aspectRatio="auto"` → no fixed box; the image keeps its natural height
|
|
194
|
+
* (`w-full h-auto`); object-fit/position are irrelevant.
|
|
195
|
+
* - otherwise → a fixed-aspect box; the image fills it (`w-full h-full`) with
|
|
196
|
+
* `object-fit`/`object-position` controlling crop + region of interest.
|
|
197
|
+
*
|
|
198
|
+
* Uses `||` (not `??`) for the defaults so an empty-string prop (e.g.
|
|
199
|
+
* `aspectRatio=""` from a template emitting a blank attribute) falls back to the
|
|
200
|
+
* default instead of producing an invalid/empty CSS value (which would collapse
|
|
201
|
+
* the tile to zero height, or — for `fit=""` — stretch the image via `fill`).
|
|
202
|
+
*/
|
|
203
|
+
export declare function galleryTileLayout(props: Pick<GalleryProps, 'aspectRatio' | 'fit' | 'position'>): GalleryTileLayout;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Tailwind class tables for table-driven MDX components.
|
|
3
|
+
*
|
|
4
|
+
* Pure data — no framework dependencies. Lifted VERBATIM from the reference
|
|
5
|
+
* Vue SFCs (`@blogmcp/mdx-render-vue/src/render/...`) so that the Vue and
|
|
6
|
+
* React renderers compose byte-identical class strings. This is the single
|
|
7
|
+
* source of truth: when a variant/color/size class changes, change it here.
|
|
8
|
+
*
|
|
9
|
+
* Tailwind JIT note: consumer Tailwind configs MUST scan this file (e.g.
|
|
10
|
+
* `./node_modules/@blogmcp/mdx-schema/src/styles/**`) so every class string
|
|
11
|
+
* below is seen at build time. Interpolated class names would not be visible
|
|
12
|
+
* to the JIT — every class here is a literal.
|
|
13
|
+
*/
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// Button — from mdx-render-vue/src/render/button/Button.vue
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
export const buttonStyles = {
|
|
18
|
+
base: 'inline-flex items-center justify-center font-medium border transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2',
|
|
19
|
+
size: {
|
|
20
|
+
sm: 'px-2.5 py-1 text-sm rounded',
|
|
21
|
+
md: 'px-4 py-2 text-sm rounded-md',
|
|
22
|
+
lg: 'px-5 py-2.5 text-base rounded-md',
|
|
23
|
+
},
|
|
24
|
+
variantColor: {
|
|
25
|
+
solid: {
|
|
26
|
+
primary: 'bg-blue-600 text-white hover:bg-blue-700 border-transparent',
|
|
27
|
+
neutral: 'bg-gray-800 text-white hover:bg-gray-900 border-transparent',
|
|
28
|
+
success: 'bg-emerald-600 text-white hover:bg-emerald-700 border-transparent',
|
|
29
|
+
warning: 'bg-amber-500 text-white hover:bg-amber-600 border-transparent',
|
|
30
|
+
error: 'bg-red-600 text-white hover:bg-red-700 border-transparent',
|
|
31
|
+
},
|
|
32
|
+
outline: {
|
|
33
|
+
primary: 'border-blue-600 text-blue-700 hover:bg-blue-50',
|
|
34
|
+
neutral: 'border-gray-400 text-gray-800 hover:bg-gray-50',
|
|
35
|
+
success: 'border-emerald-600 text-emerald-700 hover:bg-emerald-50',
|
|
36
|
+
warning: 'border-amber-500 text-amber-700 hover:bg-amber-50',
|
|
37
|
+
error: 'border-red-600 text-red-700 hover:bg-red-50',
|
|
38
|
+
},
|
|
39
|
+
soft: {
|
|
40
|
+
primary: 'bg-blue-50 text-blue-700 hover:bg-blue-100 border-transparent',
|
|
41
|
+
neutral: 'bg-gray-100 text-gray-800 hover:bg-gray-200 border-transparent',
|
|
42
|
+
success: 'bg-emerald-50 text-emerald-700 hover:bg-emerald-100 border-transparent',
|
|
43
|
+
warning: 'bg-amber-50 text-amber-700 hover:bg-amber-100 border-transparent',
|
|
44
|
+
error: 'bg-red-50 text-red-700 hover:bg-red-100 border-transparent',
|
|
45
|
+
},
|
|
46
|
+
ghost: {
|
|
47
|
+
primary: 'text-blue-700 hover:bg-blue-50 border-transparent',
|
|
48
|
+
neutral: 'text-gray-800 hover:bg-gray-100 border-transparent',
|
|
49
|
+
success: 'text-emerald-700 hover:bg-emerald-50 border-transparent',
|
|
50
|
+
warning: 'text-amber-700 hover:bg-amber-50 border-transparent',
|
|
51
|
+
error: 'text-red-700 hover:bg-red-50 border-transparent',
|
|
52
|
+
},
|
|
53
|
+
link: {
|
|
54
|
+
primary: 'text-blue-700 hover:underline border-transparent bg-transparent',
|
|
55
|
+
neutral: 'text-gray-800 hover:underline border-transparent bg-transparent',
|
|
56
|
+
success: 'text-emerald-700 hover:underline border-transparent bg-transparent',
|
|
57
|
+
warning: 'text-amber-700 hover:underline border-transparent bg-transparent',
|
|
58
|
+
error: 'text-red-700 hover:underline border-transparent bg-transparent',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
// ---------------------------------------------------------------------------
|
|
63
|
+
// Badge — from mdx-render-vue/src/render/badge/Badge.vue
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
export const badgeStyles = {
|
|
66
|
+
base: 'inline-flex items-center px-2 py-0.5 text-xs font-medium border rounded-full',
|
|
67
|
+
variantColor: {
|
|
68
|
+
solid: {
|
|
69
|
+
primary: 'bg-blue-600 text-white border-transparent',
|
|
70
|
+
neutral: 'bg-gray-700 text-white border-transparent',
|
|
71
|
+
success: 'bg-emerald-600 text-white border-transparent',
|
|
72
|
+
warning: 'bg-amber-500 text-white border-transparent',
|
|
73
|
+
error: 'bg-red-600 text-white border-transparent',
|
|
74
|
+
},
|
|
75
|
+
soft: {
|
|
76
|
+
primary: 'bg-blue-100 text-blue-800 border-transparent',
|
|
77
|
+
neutral: 'bg-gray-100 text-gray-700 border-transparent',
|
|
78
|
+
success: 'bg-emerald-100 text-emerald-800 border-transparent',
|
|
79
|
+
warning: 'bg-amber-100 text-amber-800 border-transparent',
|
|
80
|
+
error: 'bg-red-100 text-red-800 border-transparent',
|
|
81
|
+
},
|
|
82
|
+
outline: {
|
|
83
|
+
primary: 'border-blue-500 text-blue-700',
|
|
84
|
+
neutral: 'border-gray-400 text-gray-700',
|
|
85
|
+
success: 'border-emerald-500 text-emerald-700',
|
|
86
|
+
warning: 'border-amber-500 text-amber-700',
|
|
87
|
+
error: 'border-red-500 text-red-700',
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
// ---------------------------------------------------------------------------
|
|
92
|
+
// Alert — from mdx-render-vue/src/render/alert/Alert.vue
|
|
93
|
+
// severity → wrap classes + iconify icon + icon color
|
|
94
|
+
// ---------------------------------------------------------------------------
|
|
95
|
+
export const alertStyles = {
|
|
96
|
+
base: 'mdx-alert flex gap-3 rounded-md border px-4 py-3 text-sm',
|
|
97
|
+
severity: {
|
|
98
|
+
info: { wrap: 'bg-blue-50 border-blue-200 text-blue-900', icon: 'lucide:info', iconClass: 'text-blue-600' },
|
|
99
|
+
success: { wrap: 'bg-emerald-50 border-emerald-200 text-emerald-900', icon: 'lucide:check-circle-2', iconClass: 'text-emerald-600' },
|
|
100
|
+
warning: { wrap: 'bg-amber-50 border-amber-200 text-amber-900', icon: 'lucide:alert-triangle', iconClass: 'text-amber-600' },
|
|
101
|
+
error: { wrap: 'bg-red-50 border-red-200 text-red-900', icon: 'lucide:alert-octagon', iconClass: 'text-red-600' },
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
// Callout — from mdx-render-vue/src/render/callout/{CalloutDefault,CalloutMinimal}.vue
|
|
106
|
+
//
|
|
107
|
+
// Two variants share a per-type color table. `default` adds an inline SVG icon
|
|
108
|
+
// (path data below); `minimal` is icon-less with flatter colors.
|
|
109
|
+
// ---------------------------------------------------------------------------
|
|
110
|
+
export const calloutStyles = {
|
|
111
|
+
default: {
|
|
112
|
+
base: 'callout my-6 p-4 rounded-lg border-l-4',
|
|
113
|
+
type: {
|
|
114
|
+
info: { bg: 'bg-blue-50', border: 'border-blue-500', text: 'text-blue-900', iconColor: 'text-blue-500' },
|
|
115
|
+
warning: { bg: 'bg-yellow-50', border: 'border-yellow-500', text: 'text-yellow-900', iconColor: 'text-yellow-500' },
|
|
116
|
+
tip: { bg: 'bg-green-50', border: 'border-green-500', text: 'text-green-900', iconColor: 'text-green-500' },
|
|
117
|
+
danger: { bg: 'bg-red-50', border: 'border-red-500', text: 'text-red-900', iconColor: 'text-red-500' },
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
minimal: {
|
|
121
|
+
base: 'callout my-6 p-4 rounded border',
|
|
122
|
+
type: {
|
|
123
|
+
info: { bg: 'bg-blue-50', border: 'border-blue-200', text: 'text-blue-800' },
|
|
124
|
+
warning: { bg: 'bg-yellow-50', border: 'border-yellow-200', text: 'text-yellow-800' },
|
|
125
|
+
tip: { bg: 'bg-green-50', border: 'border-green-200', text: 'text-green-800' },
|
|
126
|
+
danger: { bg: 'bg-red-50', border: 'border-red-200', text: 'text-red-800' },
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
/** SVG path data for the `default` variant icon, keyed by callout type. */
|
|
130
|
+
iconPaths: {
|
|
131
|
+
info: 'M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z',
|
|
132
|
+
warning: 'M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z',
|
|
133
|
+
tip: 'M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z',
|
|
134
|
+
danger: 'M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z',
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Derive tile/media inline styles from the Gallery `aspectRatio`/`fit`/`position`
|
|
139
|
+
* props.
|
|
140
|
+
*
|
|
141
|
+
* - `aspectRatio="auto"` → no fixed box; the image keeps its natural height
|
|
142
|
+
* (`w-full h-auto`); object-fit/position are irrelevant.
|
|
143
|
+
* - otherwise → a fixed-aspect box; the image fills it (`w-full h-full`) with
|
|
144
|
+
* `object-fit`/`object-position` controlling crop + region of interest.
|
|
145
|
+
*
|
|
146
|
+
* Uses `||` (not `??`) for the defaults so an empty-string prop (e.g.
|
|
147
|
+
* `aspectRatio=""` from a template emitting a blank attribute) falls back to the
|
|
148
|
+
* default instead of producing an invalid/empty CSS value (which would collapse
|
|
149
|
+
* the tile to zero height, or — for `fit=""` — stretch the image via `fill`).
|
|
150
|
+
*/
|
|
151
|
+
export function galleryTileLayout(props) {
|
|
152
|
+
const aspectRatio = props.aspectRatio || '1';
|
|
153
|
+
if (aspectRatio === 'auto') {
|
|
154
|
+
return { tileStyle: {}, mediaStyle: {}, mediaSizeClass: 'w-full h-auto' };
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
tileStyle: { aspectRatio },
|
|
158
|
+
mediaStyle: { objectFit: props.fit || 'cover', objectPosition: props.position || 'center' },
|
|
159
|
+
mediaSizeClass: 'w-full h-full',
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/styles/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,8EAA8E;AAC9E,4DAA4D;AAC5D,8EAA8E;AAC9E,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,kJAAkJ;IACxJ,IAAI,EAA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