@vikejs/license-components 0.0.4 → 0.0.6
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/FreeTrialForm.js +7 -77
- package/dist/FreeTrialForm.js.map +1 -1
- package/dist/LicenseSnippet.d.ts +6 -0
- package/dist/LicenseSnippet.d.ts.map +1 -0
- package/dist/LicenseSnippet.js +67 -0
- package/dist/LicenseSnippet.js.map +1 -0
- package/dist/renderTokens.d.ts +4 -0
- package/dist/renderTokens.d.ts.map +1 -0
- package/dist/renderTokens.js +31 -0
- package/dist/renderTokens.js.map +1 -0
- package/package.json +11 -13
package/dist/FreeTrialForm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
export { FreeTrialForm };
|
|
3
3
|
import { useState } from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { LicenseSnippet } from './LicenseSnippet.js';
|
|
5
5
|
// Resolve the API origin at call time (client-only — `submit` is the sole caller). The docs dev
|
|
6
6
|
// server runs on :3001 by convention and pairs with the dashboard dev on :3000, so a page served
|
|
7
7
|
// from `localhost:3001` targets the local dashboard; every other context (prod vike.dev, `vike
|
|
@@ -54,53 +54,7 @@ function ResultView({ result }) {
|
|
|
54
54
|
}
|
|
55
55
|
const { license, unavailable } = result.data;
|
|
56
56
|
const licenseEntries = Object.entries(license);
|
|
57
|
-
return (_jsxs(_Fragment, { children: [licenseEntries.length > 0 && (_jsxs("section", { style: successBoxStyle, children: [_jsx("strong", { children: "
|
|
58
|
-
}
|
|
59
|
-
// Polished license snippet — ports the dashboard's LicenseKeysPanel look (packages/dashboard/
|
|
60
|
-
// pages/index/snippet.css): gray code block, green diff-highlight on the `license` lines, github-
|
|
61
|
-
// light token colors, and a Copy button. The CSS is injected as a scoped <style> (everything under
|
|
62
|
-
// `.license-snippet`) because this package is compiled by `tsc`, which can't bundle a CSS import.
|
|
63
|
-
function LicenseSnippet({ license }) {
|
|
64
|
-
const [copied, setCopied] = useState(false);
|
|
65
|
-
const lines = renderLicenseSnippetLines(license);
|
|
66
|
-
async function copy() {
|
|
67
|
-
try {
|
|
68
|
-
await navigator.clipboard.writeText(lines
|
|
69
|
-
.filter((l) => l.license)
|
|
70
|
-
.map((l) => l.text)
|
|
71
|
-
.join('\n'));
|
|
72
|
-
setCopied(true);
|
|
73
|
-
setTimeout(() => setCopied(false), 1500);
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
// clipboard can reject (denied permission / insecure context) — leave the button unchanged.
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return (_jsxs("div", { style: snippetWrapStyle, children: [_jsx("style", { children: SNIPPET_CSS }), _jsx("pre", { className: "license-snippet", children: _jsx("code", { children: lines.map((line, i) => (_jsx("span", { className: `line${line.license ? ' add' : ''}${line.text.startsWith('//') ? ' comment' : ''}`, children: line.text === '' ? ' ' : renderTokens(line.text) }, i))) }) }), _jsx("button", { type: "button", onClick: copy, style: copyButtonStyle, children: copied ? 'Copied' : 'Copy' })] }));
|
|
80
|
-
}
|
|
81
|
-
// Approximate Shiki's github-light (docpress's theme) without the dependency: single-quoted
|
|
82
|
-
// strings blue, `export`/`default` keywords red. The snippet is a fixed shape and its strings hold
|
|
83
|
-
// only domains + base64url keys (no nested quotes / keywords), so this split tokenizer is
|
|
84
|
-
// unambiguous. Mirrors LicenseKeysPanel.renderTokens.
|
|
85
|
-
function renderTokens(text) {
|
|
86
|
-
const nodes = [];
|
|
87
|
-
text.split(/('[^']*')/g).forEach((seg, i) => {
|
|
88
|
-
if (i % 2 === 1) {
|
|
89
|
-
nodes.push(_jsx("span", { className: "tok-str", children: seg }, i));
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
seg.split(/\b(export|default)\b/g).forEach((part, j) => {
|
|
93
|
-
if (!part)
|
|
94
|
-
return;
|
|
95
|
-
if (j % 2 === 1) {
|
|
96
|
-
nodes.push(_jsx("span", { className: "tok-kw", children: part }, `${i}-${j}`));
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
nodes.push(part);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
return nodes;
|
|
57
|
+
return (_jsxs(_Fragment, { children: [licenseEntries.length > 0 && (_jsxs("section", { style: successBoxStyle, children: [_jsx("strong", { children: "License key" }), _jsxs("p", { style: captionStyle, children: ["Set", ' ', _jsx("a", { href: "https://vike.dev/license", style: linkStyle, children: _jsx("code", { children: "+license" }) }), ' ', "in your ", _jsx("code", { children: "+config.js" }), " file:"] }), _jsx(LicenseSnippet, { license: license }), licenseEntries.map(([domain, value]) => (_jsx(Summary, { domain: domain, value: value }, domain)))] })), unavailable.length > 0 && _jsx(UnavailableList, { items: unavailable })] }));
|
|
104
58
|
}
|
|
105
59
|
function Summary({ domain, value }) {
|
|
106
60
|
// A `string` value is a forever entry (no-expiry grant); `{ expires }` is time-limited
|
|
@@ -149,40 +103,16 @@ const boxStyle = { padding: 16, borderRadius: 6, marginTop: 16 };
|
|
|
149
103
|
const successBoxStyle = { ...boxStyle, background: '#e7f7e0', color: '#256029' };
|
|
150
104
|
const warnBoxStyle = { ...boxStyle, background: '#fff3cd', color: '#7a5b00' };
|
|
151
105
|
const errorBoxStyle = { ...boxStyle, background: '#fde2e1', color: '#9d2222' };
|
|
106
|
+
// Caption introducing the snippet — matches the dashboard's LicenseKeysPanel caption.
|
|
107
|
+
const captionStyle = { fontSize: 13, margin: '0 0 4px' };
|
|
108
|
+
// vike.dev/license link color (docpress src/css/link.css), same as the dashboard.
|
|
109
|
+
const linkStyle = { color: '#4747ff', textDecoration: 'none' };
|
|
152
110
|
const dlStyle = {
|
|
153
111
|
margin: '8px 0 0',
|
|
154
112
|
display: 'grid',
|
|
155
113
|
gridTemplateColumns: 'auto 1fr',
|
|
156
114
|
columnGap: 12,
|
|
157
|
-
rowGap:
|
|
115
|
+
rowGap: 1,
|
|
158
116
|
fontSize: 13,
|
|
159
117
|
};
|
|
160
|
-
const snippetWrapStyle = { position: 'relative', margin: '4px 0 12px' };
|
|
161
|
-
const copyButtonStyle = {
|
|
162
|
-
position: 'absolute',
|
|
163
|
-
top: 6,
|
|
164
|
-
right: 6,
|
|
165
|
-
padding: '4px 8px',
|
|
166
|
-
fontSize: 12,
|
|
167
|
-
background: '#fff',
|
|
168
|
-
border: '1px solid #ddd',
|
|
169
|
-
borderRadius: 4,
|
|
170
|
-
cursor: 'pointer',
|
|
171
|
-
color: '#333',
|
|
172
|
-
};
|
|
173
|
-
// Scoped to `.license-snippet` (no global `code {}` — that would restyle the host page's inline
|
|
174
|
-
// code). Ported from the dashboard's pages/index/snippet.css; `background:#f4f4f4` is solid (rather
|
|
175
|
-
// than docpress's rgba-on-white) so the block stays a light code surface — dark text on light — on
|
|
176
|
-
// any host box tint or theme.
|
|
177
|
-
const SNIPPET_CSS = `
|
|
178
|
-
.license-snippet { margin: 0; border-radius: 6px; overflow-x: auto; background: #f4f4f4; font-size: 12px; line-height: 1.6; }
|
|
179
|
-
.license-snippet code { display: inline-block; min-width: 100%; padding: 16px 0; box-sizing: border-box; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace; color: #24292e; background: transparent; }
|
|
180
|
-
.license-snippet .line { display: block; position: relative; padding: 0 16px; white-space: pre; }
|
|
181
|
-
.license-snippet .line.add { background: #d7ecdf; }
|
|
182
|
-
.license-snippet .line.add::before { content: '+'; position: absolute; top: -1px; left: 4px; color: #89d189; font-size: 1.2em; font-weight: 500; }
|
|
183
|
-
.license-snippet .line.comment { color: #6a737d; }
|
|
184
|
-
.license-snippet .tok-kw { color: #d73a49; }
|
|
185
|
-
.license-snippet .tok-str { color: #032f62; }
|
|
186
|
-
`;
|
|
187
|
-
const installHintStyle = { marginTop: 8, fontSize: 13, color: '#444' };
|
|
188
118
|
//# sourceMappingURL=FreeTrialForm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FreeTrialForm.js","sourceRoot":"","sources":["../src/FreeTrialForm.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,CAAA;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAGhC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"FreeTrialForm.js","sourceRoot":"","sources":["../src/FreeTrialForm.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,CAAA;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAGhC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEpD,gGAAgG;AAChG,iGAAiG;AACjG,+FAA+F;AAC/F,kGAAkG;AAClG,iGAAiG;AACjG,+BAA+B;AAC/B,SAAS,WAAW;IAClB,MAAM,IAAI,GACR,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,KAAK,MAAM;QAC9D,CAAC,CAAC,uBAAuB;QACzB,CAAC,CAAC,uBAAuB,CAAA;IAC7B,OAAO,GAAG,IAAI,iCAAiC,CAAA;AACjD,CAAC;AAQD,SAAS,aAAa;IACpB,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAA;IACpD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAS,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAA;IAE9D,KAAK,UAAU,MAAM,CAAC,CAAY;QAChC,CAAC,CAAC,cAAc,EAAE,CAAA;QAClB,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC;YACzB,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,4BAA4B,EAAE,CAAC,CAAA;YACnE,OAAM;QACR,CAAC;QACD,SAAS,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA;QAC9B,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AA;AAChE,MAAM,eAAe,GAAG,EAAE,GAAG,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAA;AAChF,MAAM,YAAY,GAAG,EAAE,GAAG,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAA;AAC7E,MAAM,aAAa,GAAG,EAAE,GAAG,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAA;AAC9E,sFAAsF;AACtF,MAAM,YAAY,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,CAAA;AACxD,kFAAkF;AAClF,MAAM,SAAS,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,EAAE,CAAA;AAC9D,MAAM,OAAO,GAAG;IACd,MAAM,EAAE,SAAS;IACjB,OAAO,EAAE,MAAM;IACf,mBAAmB,EAAE,UAAU;IAC/B,SAAS,EAAE,EAAE;IACb,MAAM,EAAE,CAAC;IACT,QAAQ,EAAE,EAAE;CACb,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LicenseSnippet.d.ts","sourceRoot":"","sources":["../src/LicenseSnippet.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,CAAA;AAGzB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAY3C,iBAAS,cAAc,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,UAAU,CAAA;CAAE,2CA2C3D"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
export { LicenseSnippet };
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { renderLicenseSnippetLines } from './snippet.js';
|
|
5
|
+
import { renderTokens } from './renderTokens.js';
|
|
6
|
+
// The license-snippet code block — the SINGLE rendering shared by the dashboard's `LicenseKeysPanel`
|
|
7
|
+
// and license-components' `FreeTrialForm`, so the two surfaces are byte-identical (symlinked into
|
|
8
|
+
// `packages/license-components/src/` alongside snippet.ts / wire.ts / renderTokens.tsx).
|
|
9
|
+
//
|
|
10
|
+
// CSS is injected as a scoped `<style>` (everything under `.license-snippet`) rather than a CSS
|
|
11
|
+
// import, because license-components is compiled by `tsc` (no CSS-import support); Vite (the
|
|
12
|
+
// dashboard) is fine with it too. `// pages/+config.js` + a blank line lead the block (context lines:
|
|
13
|
+
// `license: false`, not diff-highlighted, excluded from Copy) — mirrors vike.dev/license.
|
|
14
|
+
function LicenseSnippet({ license }) {
|
|
15
|
+
const [copied, setCopied] = useState(false);
|
|
16
|
+
const lines = [
|
|
17
|
+
{ text: '// pages/+config.js', license: false },
|
|
18
|
+
{ text: '', license: false },
|
|
19
|
+
...renderLicenseSnippetLines(license),
|
|
20
|
+
];
|
|
21
|
+
// Copy only the `license: {…}` lines (not the filename comment or `export default {}` wrapper), so
|
|
22
|
+
// a customer with an existing +config pastes just the key — matches the diff-highlighted lines.
|
|
23
|
+
async function copy() {
|
|
24
|
+
try {
|
|
25
|
+
await navigator.clipboard.writeText(lines
|
|
26
|
+
.filter((l) => l.license)
|
|
27
|
+
.map((l) => l.text)
|
|
28
|
+
.join('\n'));
|
|
29
|
+
setCopied(true);
|
|
30
|
+
setTimeout(() => setCopied(false), 1500);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// clipboard can reject (denied permission / insecure context) — leave the button unchanged.
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return (_jsxs("div", { style: snippetWrapStyle, children: [_jsx("style", { children: SNIPPET_CSS }), _jsx("pre", { className: "license-snippet", children: _jsx("code", { children: lines.map((line, i) => (_jsx("span", { className: `line${line.license ? ' add' : ''}${line.text.startsWith('//') ? ' comment' : ''}`, children: line.text === '' ? ' ' : renderTokens(line.text) }, i))) }) }), _jsx("button", { type: "button", onClick: copy, style: copyButtonStyle, children: copied ? 'Copied' : 'Copy' })] }));
|
|
37
|
+
}
|
|
38
|
+
const snippetWrapStyle = { position: 'relative', margin: '8px 0' };
|
|
39
|
+
const copyButtonStyle = {
|
|
40
|
+
position: 'absolute',
|
|
41
|
+
top: 6,
|
|
42
|
+
right: 6,
|
|
43
|
+
padding: '4px 8px',
|
|
44
|
+
fontSize: 12,
|
|
45
|
+
background: '#fff',
|
|
46
|
+
border: '1px solid #ddd',
|
|
47
|
+
borderRadius: 4,
|
|
48
|
+
cursor: 'pointer',
|
|
49
|
+
color: '#333',
|
|
50
|
+
};
|
|
51
|
+
// github-light look (docpress's Shiki theme) without the dependency. `background:#f4f4f4` is solid
|
|
52
|
+
// (not docpress's rgba-on-white) so the block reads as a light code surface — dark text on light —
|
|
53
|
+
// on any host box tint or theme. `display:inline-block; min-width:100%` on the <code> is what lets a
|
|
54
|
+
// line's diff background span the full SCROLL width (not just the visible width); `!important` on it
|
|
55
|
+
// + `.line` because a host's typography CSS (e.g. the docs' `.prose pre code`) otherwise overrides
|
|
56
|
+
// the display and clips the highlight horizontally.
|
|
57
|
+
const SNIPPET_CSS = `
|
|
58
|
+
.license-snippet { margin: 0; border-radius: 6px; overflow-x: auto; background: #f4f4f4; font-size: 12px; line-height: 1.6; }
|
|
59
|
+
.license-snippet code { display: inline-block !important; min-width: 100% !important; padding: 16px 0; box-sizing: border-box; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace; color: #24292e; background: transparent; border-radius: 0; font-size: inherit; }
|
|
60
|
+
.license-snippet .line { display: block !important; position: relative; padding: 0 16px; white-space: pre; }
|
|
61
|
+
.license-snippet .line.add { background: #d7ecdf; }
|
|
62
|
+
.license-snippet .line.add::before { content: '+'; position: absolute; top: -1px; left: 4px; color: #89d189; font-size: 1.2em; font-weight: 500; }
|
|
63
|
+
.license-snippet .line.comment { color: #6a737d; }
|
|
64
|
+
.license-snippet .tok-kw { color: #d73a49; }
|
|
65
|
+
.license-snippet .tok-str { color: #032f62; }
|
|
66
|
+
`;
|
|
67
|
+
//# sourceMappingURL=LicenseSnippet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LicenseSnippet.js","sourceRoot":"","sources":["../src/LicenseSnippet.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,CAAA;AAEzB,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD,qGAAqG;AACrG,kGAAkG;AAClG,yFAAyF;AACzF,EAAE;AACF,gGAAgG;AAChG,6FAA6F;AAC7F,sGAAsG;AACtG,0FAA0F;AAC1F,SAAS,cAAc,CAAC,EAAE,OAAO,EAA2B;IAC1D,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC3C,MAAM,KAAK,GAAG;QACZ,EAAE,IAAI,EAAE,qBAAqB,EAAE,OAAO,EAAE,KAAK,EAAE;QAC/C,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE;QAC5B,GAAG,yBAAyB,CAAC,OAAO,CAAC;KACtC,CAAA;IACD,mGAAmG;IACnG,gGAAgG;IAChG,KAAK,UAAU,IAAI;QACjB,IAAI,CAAC;YACH,MAAM,SAAS,CAAC,SAAS,CAAC,SAAS,CACjC,KAAK;iBACF,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;iBACxB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;iBAClB,IAAI,CAAC,IAAI,CAAC,CACd,CAAA;YACD,SAAS,CAAC,IAAI,CAAC,CAAA;YACf,UAAU,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC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G;AACrG,mGAAmG;AACnG,oDAAoD;AACpD,MAAM,WAAW,GAAG;;;;;;;;;CASnB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderTokens.d.ts","sourceRoot":"","sources":["../src/renderTokens.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,CAAA;AAEvB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAUtC,iBAAS,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAyB7C"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
export { renderTokens };
|
|
3
|
+
// Syntax-highlight one line of the license snippet — the single source of truth for its token
|
|
4
|
+
// markup, shared by the dashboard's `LicenseKeysPanel` and license-components' `FreeTrialForm`.
|
|
5
|
+
//
|
|
6
|
+
// Approximates Shiki's `github-light` theme (docpress's, which powers vike.dev/docs) without the
|
|
7
|
+
// dependency: single-quoted string literals blue, `export`/`default` keywords red. The snippet is
|
|
8
|
+
// a fixed shape and its strings hold only domains + base64url keys (no nested quotes / keywords),
|
|
9
|
+
// so this split-based tokenizer is unambiguous. Emits `.tok-str` / `.tok-kw` spans; each consumer
|
|
10
|
+
// supplies the matching CSS (the dashboard's snippet.css, FreeTrialForm's inlined <style>).
|
|
11
|
+
function renderTokens(text) {
|
|
12
|
+
const nodes = [];
|
|
13
|
+
text.split(/('[^']*')/g).forEach((seg, i) => {
|
|
14
|
+
if (i % 2 === 1) {
|
|
15
|
+
nodes.push(_jsx("span", { className: "tok-str", children: seg }, i));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
seg.split(/\b(export|default)\b/g).forEach((part, j) => {
|
|
19
|
+
if (!part)
|
|
20
|
+
return;
|
|
21
|
+
if (j % 2 === 1) {
|
|
22
|
+
nodes.push(_jsx("span", { className: "tok-kw", children: part }, `${i}-${j}`));
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
nodes.push(part);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
return nodes;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=renderTokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderTokens.js","sourceRoot":"","sources":["../src/renderTokens.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,CAAA;AAIvB,8FAA8F;AAC9F,gGAAgG;AAChG,EAAE;AACF,iGAAiG;AACjG,kGAAkG;AAClG,kGAAkG;AAClG,kGAAkG;AAClG,4FAA4F;AAC5F,SAAS,YAAY,CAAC,IAAY;IAChC,MAAM,KAAK,GAAgB,EAAE,CAAA;IAC7B,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE;QAC1C,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAChB,KAAK,CAAC,IAAI,CACR,eAAc,SAAS,EAAC,SAAS,YAC9B,GAAG,IADK,CAAC,CAEL,CACR,CAAA;YACD,OAAM;QACR,CAAC;QACD,GAAG,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE;YACrD,IAAI,CAAC,IAAI;gBAAE,OAAM;YACjB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;gBAChB,KAAK,CAAC,IAAI,CACR,eAAwB,SAAS,EAAC,QAAQ,YACvC,IAAI,IADI,GAAG,CAAC,IAAI,CAAC,EAAE,CAEf,CACR,CAAA;YACH,CAAC;iBAAM,CAAC;gBACN,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAClB,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IACF,OAAO,KAAK,CAAA;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vikejs/license-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -16,20 +16,9 @@
|
|
|
16
16
|
"publishConfig": {
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
|
-
"scripts": {
|
|
20
|
-
"// === Dev": "",
|
|
21
|
-
"dev": "vite playground",
|
|
22
|
-
"typecheck": "tsc --noEmit",
|
|
23
|
-
"// === Build ===": "",
|
|
24
|
-
"build": "tsc",
|
|
25
|
-
"// === Release": "",
|
|
26
|
-
"prepublishOnly": "pnpm run build",
|
|
27
|
-
"release": "npm version patch && npm publish && git push && git push --tags"
|
|
28
|
-
},
|
|
29
19
|
"peerDependencies": {
|
|
30
20
|
"react": "^18.0.0 || ^19.0.0"
|
|
31
21
|
},
|
|
32
|
-
"dependencies": {},
|
|
33
22
|
"devDependencies": {
|
|
34
23
|
"@types/react": "^19.2.15",
|
|
35
24
|
"@types/react-dom": "^19.2.3",
|
|
@@ -43,5 +32,14 @@
|
|
|
43
32
|
"type": "git",
|
|
44
33
|
"url": "https://github.com/vikejs/vike-dashboard.git",
|
|
45
34
|
"directory": "packages/license-components"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"// === Dev": "",
|
|
38
|
+
"dev": "vite playground",
|
|
39
|
+
"typecheck": "tsc --noEmit",
|
|
40
|
+
"// === Build ===": "",
|
|
41
|
+
"build": "tsc",
|
|
42
|
+
"// === Release": "",
|
|
43
|
+
"release": "pnpm publish"
|
|
46
44
|
}
|
|
47
|
-
}
|
|
45
|
+
}
|