@panomc/plugin-kit 0.0.0-stage → 1.0.0-dev.61
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/assets/pano-bootstrap.css +17903 -0
- package/bin/__tests__/new/e2e.test.js +111 -0
- package/bin/__tests__/new/helpers.js +76 -0
- package/bin/__tests__/new/new.test.js +472 -0
- package/bin/new.js +530 -0
- package/bin/pano-plugin.js +162 -0
- package/bin/templates/plugin/README.md +30 -0
- package/bin/templates/plugin/_gitignore +15 -0
- package/bin/templates/plugin/build.gradle.kts +389 -0
- package/bin/templates/plugin/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/bin/templates/plugin/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/bin/templates/plugin/gradle.properties +55 -0
- package/bin/templates/plugin/gradlew +249 -0
- package/bin/templates/plugin/gradlew.bat +92 -0
- package/bin/templates/plugin/package.json.tpl +14 -0
- package/bin/templates/plugin/rollup.config.js +2 -0
- package/bin/templates/plugin/settings.gradle.kts +5 -0
- package/bin/templates/plugin/src/main/kotlin/__PKGPATH__/__CLASS__Plugin.kt +50 -0
- package/bin/templates/plugin/src/main/kotlin/__PKGPATH__/frontend/ExampleFallbackPage.kt +28 -0
- package/bin/templates/plugin/src/main/kotlin/__PKGPATH__/routes/GetHelloAPI.kt +19 -0
- package/bin/templates/plugin/src/main/kotlin/com/panomc/plugins/license/LicenseGuard.kt +30 -0
- package/bin/templates/plugin/src/main/kotlin/com/panomc/plugins/license/PluginLicenseClient.kt +144 -0
- package/bin/templates/plugin/src/main/resources/config.conf +1 -0
- package/bin/templates/plugin/src/main/resources/frontend-targets.json +1 -0
- package/bin/templates/plugin/src/main/resources/locales/en-US.json +3 -0
- package/bin/templates/plugin/src/main/resources/logo.png +0 -0
- package/bin/templates/plugin/src/theme/views/HelloPage.svelte +26 -0
- package/bin/ui.js +96 -0
- package/package.json +46 -4
- package/src/config.js +191 -0
- package/src/controller/__tests__/controller.test.js +647 -0
- package/src/controller/index.js +604 -0
- package/src/dev.js +208 -0
- package/src/index.js +22 -0
- package/src/rollup/__tests__/controllers/controllers.test.js +418 -0
- package/src/rollup/__tests__/controllers/fixture.js +143 -0
- package/src/rollup/__tests__/controllers/golden/controllers.json +34 -0
- package/src/rollup/__tests__/controllers/golden/controllers.types.js +69 -0
- package/src/rollup/__tests__/controllers/golden/pano-plugin.json +16 -0
- package/src/rollup/__tests__/controllers/golden/pano-plugin.lock.json +27 -0
- package/src/rollup/__tests__/controllers/golden/pano-plugin.with-views.json +54 -0
- package/src/rollup/__tests__/preset/preset.test.js +418 -0
- package/src/rollup/__tests__/rules/_build.js +39 -0
- package/src/rollup/__tests__/rules/_fixture.js +83 -0
- package/src/rollup/__tests__/rules/helpers.test.js +148 -0
- package/src/rollup/__tests__/rules/rules.test.js +259 -0
- package/src/rollup/__tests__/rules/stamp.test.js +113 -0
- package/src/rollup/__tests__/samples/samples.test.js +481 -0
- package/src/rollup/__tests__/seams/config.test.js +78 -0
- package/src/rollup/__tests__/seams/lock.test.js +124 -0
- package/src/rollup/__tests__/seams/sdk-seams.test.js +93 -0
- package/src/rollup/__tests__/seams/stubs.test.js +52 -0
- package/src/rollup/__tests__/views/helpers.js +82 -0
- package/src/rollup/__tests__/views/views.test.js +522 -0
- package/src/rollup/__tests__/widgets/helpers.js +117 -0
- package/src/rollup/__tests__/widgets/widgets.test.js +422 -0
- package/src/rollup/cli-build.js +90 -0
- package/src/rollup/cli-check.js +280 -0
- package/src/rollup/cli-classes.js +75 -0
- package/src/rollup/client-gen.js +72 -0
- package/src/rollup/controllers.js +434 -0
- package/src/rollup/entry.js +250 -0
- package/src/rollup/helpers.js +193 -0
- package/src/rollup/index.js +601 -0
- package/src/rollup/integrate.js +205 -0
- package/src/rollup/lock.js +230 -0
- package/src/rollup/meta.js +479 -0
- package/src/rollup/rules.js +950 -0
- package/src/rollup/samples.js +667 -0
- package/src/rollup/stamp.js +410 -0
- package/src/rollup/types.js +248 -0
- package/src/rollup/views.js +1205 -0
- package/src/rollup/widgets.js +1000 -0
- package/src/styles/__tests__/fallback/__snapshots__/build-fallback-css.test.js.snap +173 -0
- package/src/styles/__tests__/fallback/build-fallback-css.test.js +526 -0
- package/src/styles/__tests__/fallback/fixtures/base.css +247 -0
- package/src/styles/__tests__/fallback/plugins.test.js +301 -0
- package/src/styles/__tests__/lint/check-styles.test.js +423 -0
- package/src/styles/__tests__/lint/fixtures/ProductCard.golden.svelte +13 -0
- package/src/styles/__tests__/lint/fixtures/ProductCard.in.svelte +13 -0
- package/src/styles/__tests__/lint/semantic-classes.test.js +364 -0
- package/src/styles/bootstrap-classes.js +155 -0
- package/src/styles/check-styles.js +626 -0
- package/src/styles/fallback-css.js +1182 -0
- package/src/styles/plugin-css.js +237 -0
- package/src/styles/scan.js +206 -0
- package/src/styles/semantic-classes.js +436 -0
- package/src/styles/tokens.map.js +53 -0
- package/README.md +0 -3
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
@charset "UTF-8";
|
|
2
|
+
:root,
|
|
3
|
+
[data-bs-theme=light] {
|
|
4
|
+
--bs-white: #fff;
|
|
5
|
+
--bs-border-style: solid;
|
|
6
|
+
--bs-primary: #044389;
|
|
7
|
+
--bs-primary-rgb: 4, 67, 137;
|
|
8
|
+
--bs-success-rgb: 78, 205, 196;
|
|
9
|
+
--bs-light-rgb: 245, 247, 250;
|
|
10
|
+
--bs-body-bg: #fff;
|
|
11
|
+
--bs-body-color: #212529;
|
|
12
|
+
--bs-body-color-rgb: 33, 37, 41;
|
|
13
|
+
--bs-body-font-family: system-ui;
|
|
14
|
+
--bs-body-font-size: 1rem;
|
|
15
|
+
--bs-body-line-height: 1.5;
|
|
16
|
+
--bs-link-color: #044389;
|
|
17
|
+
--bs-link-color-rgb: 4, 67, 137;
|
|
18
|
+
--bs-link-hover-color-rgb: 3, 54, 110;
|
|
19
|
+
--bs-primary-bg-subtle: #cfe2ff;
|
|
20
|
+
--bs-heading-color: inherit;
|
|
21
|
+
--bs-btn-close-filter: ;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
[data-bs-theme=dark], [data-bs-theme=copper] {
|
|
25
|
+
color-scheme: dark;
|
|
26
|
+
--bs-body-bg: #212529;
|
|
27
|
+
--bs-body-color-rgb: 222, 226, 230;
|
|
28
|
+
--bs-code-color: #e685b5;
|
|
29
|
+
--bs-primary-bg-subtle: #031633;
|
|
30
|
+
--bs-heading-color: #fff;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
[data-bs-theme=copper] {
|
|
34
|
+
--bs-primary: #b87333;
|
|
35
|
+
--bs-primary-rgb: 184, 115, 51;
|
|
36
|
+
--bs-warning-extra: rgba($primary, 0.12);
|
|
37
|
+
--bs-copper-only: 1px;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
:root {
|
|
41
|
+
--bs-breakpoint-md: 768px;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
*,
|
|
45
|
+
*::before,
|
|
46
|
+
*::after {
|
|
47
|
+
box-sizing: border-box;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
body {
|
|
51
|
+
margin: 0;
|
|
52
|
+
color: var(--bs-body-color);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
56
|
+
:root {
|
|
57
|
+
scroll-behavior: smooth;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
a {
|
|
62
|
+
color: rgba(var(--bs-link-color-rgb), var(--bs-link-opacity, 1));
|
|
63
|
+
text-decoration: underline;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
a:hover {
|
|
67
|
+
--bs-link-color-rgb: var(--bs-link-hover-color-rgb);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
[type=button]:not(:disabled) {
|
|
71
|
+
cursor: pointer;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
optgroup {
|
|
75
|
+
font-weight: 700;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.btn {
|
|
79
|
+
--bs-btn-padding-x: 0.75rem;
|
|
80
|
+
--bs-btn-focus-box-shadow: 0 0 0 0.25rem rgba(var(--bs-btn-focus-shadow-rgb), .5);
|
|
81
|
+
display: inline-block;
|
|
82
|
+
padding: 0.375rem var(--bs-btn-padding-x);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.btn-primary {
|
|
86
|
+
--bs-btn-color: #fff;
|
|
87
|
+
--bs-btn-bg: #044389;
|
|
88
|
+
--bs-btn-focus-shadow-rgb: 42, 95, 155;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.btn-secondary {
|
|
92
|
+
--bs-btn-color: #000;
|
|
93
|
+
--bs-btn-bg: #ffc947;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.btn-check:checked + .btn {
|
|
97
|
+
color: red;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.btn:disabled,
|
|
101
|
+
.btn.disabled {
|
|
102
|
+
opacity: 0.65;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.card {
|
|
106
|
+
display: flex;
|
|
107
|
+
box-shadow: 0 0 0 1px rgba(var(--bs-body-color-rgb), 0.125), 0 1px 2px rgba(var(--bs-light-rgb), 0.2);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.card-body {
|
|
111
|
+
flex: 1 1 auto;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.fade {
|
|
115
|
+
transition: opacity 0.15s linear;
|
|
116
|
+
}
|
|
117
|
+
@media (prefers-reduced-motion: reduce) {
|
|
118
|
+
.fade {
|
|
119
|
+
transition: none;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
.fade:not(.show) {
|
|
123
|
+
opacity: 0;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.collapse:not(.show) {
|
|
127
|
+
display: none;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.spinner-border {
|
|
131
|
+
display: inline-block;
|
|
132
|
+
--bs-spinner-animation-name: spinner-border;
|
|
133
|
+
animation: 0.75s linear infinite var(--bs-spinner-animation-name);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@keyframes spinner-border {
|
|
137
|
+
to {
|
|
138
|
+
transform: rotate(360deg);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
@keyframes unused-frames {
|
|
142
|
+
to {
|
|
143
|
+
opacity: 0;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.form-select {
|
|
148
|
+
display: block;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
[data-bs-theme=dark] .form-select, [data-bs-theme=copper] .form-select {
|
|
152
|
+
--bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg'%3e%3c/svg%3e");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.navbar {
|
|
156
|
+
display: flex;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.navbar[data-bs-theme=dark] {
|
|
160
|
+
--bs-navbar-color: rgba(255, 255, 255, 0.55);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.modal {
|
|
164
|
+
position: fixed;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.modal-backdrop {
|
|
168
|
+
--bs-backdrop-bg: #000;
|
|
169
|
+
position: fixed;
|
|
170
|
+
background-color: var(--bs-backdrop-bg);
|
|
171
|
+
}
|
|
172
|
+
.modal-backdrop.fade {
|
|
173
|
+
opacity: 0;
|
|
174
|
+
}
|
|
175
|
+
.modal-backdrop.show {
|
|
176
|
+
opacity: 0.5;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.modal-open .modal {
|
|
180
|
+
overflow-y: auto;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.tooltip {
|
|
184
|
+
--bs-tooltip-color: var(--bs-body-bg);
|
|
185
|
+
z-index: 1080;
|
|
186
|
+
}
|
|
187
|
+
.tooltip.show {
|
|
188
|
+
opacity: 0.9;
|
|
189
|
+
}
|
|
190
|
+
.tooltip .tooltip-arrow {
|
|
191
|
+
display: block;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.popover {
|
|
195
|
+
position: absolute;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.nav-pills .nav-link.active {
|
|
199
|
+
color: #fff;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.alert {
|
|
203
|
+
padding: 1rem;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.alert-danger {
|
|
207
|
+
--bs-alert-color: #842029;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
.badge {
|
|
211
|
+
display: inline-block;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.mb-0 {
|
|
215
|
+
margin-bottom: 0 !important;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
.mb-1 {
|
|
219
|
+
margin-bottom: 0.25rem !important;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.text-bg-success {
|
|
223
|
+
color: #000 !important;
|
|
224
|
+
background-color: RGBA(var(--bs-success-rgb), var(--bs-bg-opacity, 1)) !important;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
.border {
|
|
228
|
+
border: 1px solid #dee2e6 !important;
|
|
229
|
+
--bs-border-opacity: 1;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
.blocks {
|
|
233
|
+
background-image: none;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
[data-bs-theme=dark] .blocks {
|
|
237
|
+
background-image: url("data:image/svg+xml,%3Csvg%3E%3C/svg%3E");
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
@font-face {
|
|
241
|
+
font-family: "Quicksand";
|
|
242
|
+
src: url("/assets/fonts/q.woff2") format("woff2");
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
.mb-0 {
|
|
246
|
+
margin-bottom: 0 !important;
|
|
247
|
+
}
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { afterAll, describe, expect, test } from 'bun:test';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { rollup } from 'rollup';
|
|
6
|
+
import svelte from 'rollup-plugin-svelte';
|
|
7
|
+
import { getBuildContext } from '../../../rollup/meta.js';
|
|
8
|
+
import { panoFallbackCss, scanViews, baseClassSet, nearMatches } from '../../fallback-css.js';
|
|
9
|
+
import { panoPluginCss, styleHash } from '../../plugin-css.js';
|
|
10
|
+
|
|
11
|
+
const dirs = [];
|
|
12
|
+
|
|
13
|
+
/** A plugin root with these files ({ 'src/theme/views/A.svelte': source }). */
|
|
14
|
+
function pluginRoot(files) {
|
|
15
|
+
const root = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'pano-fallback-')));
|
|
16
|
+
|
|
17
|
+
dirs.push(root);
|
|
18
|
+
|
|
19
|
+
for (const [name, source] of Object.entries(files)) {
|
|
20
|
+
const full = path.join(root, name);
|
|
21
|
+
|
|
22
|
+
fs.mkdirSync(path.dirname(full), { recursive: true });
|
|
23
|
+
fs.writeFileSync(full, source);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return root;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
afterAll(() => {
|
|
30
|
+
for (const d of dirs) fs.rmSync(d, { recursive: true, force: true });
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const CARD = `<script>
|
|
34
|
+
import { statusClass } from './lib/status.js';
|
|
35
|
+
/** @type {{ product: { name: string } }} */
|
|
36
|
+
let { product } = $props();
|
|
37
|
+
const BADGES = { ok: 'text-bg-success', bad: 'text-bg-danger' };
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<div class="card h-100">
|
|
41
|
+
<div class="card-body d-flex">
|
|
42
|
+
<h3 class="card-title h6">{product.name}</h3>
|
|
43
|
+
<button class="btn btn-primary btn-sm" onclick={() => {}}>buy</button>
|
|
44
|
+
<span class={statusClass('ok')}>ok</span>
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
|
|
48
|
+
<style>
|
|
49
|
+
.market-product-card { padding: 1rem; }
|
|
50
|
+
.card-title { margin: 0; }
|
|
51
|
+
</style>
|
|
52
|
+
`;
|
|
53
|
+
|
|
54
|
+
const FILES = {
|
|
55
|
+
'src/theme/views/ProductCard.svelte': CARD,
|
|
56
|
+
'src/theme/views/lib/status.js': "export const statusClass = (s) => (s === 'ok' ? 'badge bg-success' : `badge bg-${s}`);\nexport const unrelated = 'not a class';\n",
|
|
57
|
+
'src/entry.js': "import ProductCard from './theme/views/ProductCard.svelte';\nexport default ProductCard;\n",
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Builds `src/entry.js` of a plugin root with the two plugins and the svelte plugin; returns the
|
|
62
|
+
* written files of the client folder.
|
|
63
|
+
*/
|
|
64
|
+
async function build(root, { emitCss = false, fallback = {}, own = {} } = {}) {
|
|
65
|
+
const out = path.join(root, 'out/client');
|
|
66
|
+
const bundle = await rollup({
|
|
67
|
+
input: path.join(root, 'src/entry.js'),
|
|
68
|
+
external: (id) => id.startsWith('svelte'),
|
|
69
|
+
onwarn() {},
|
|
70
|
+
plugins: [
|
|
71
|
+
panoPluginCss({ ns: 'market', root, outDir: path.join(root, 'out'), side: 'client', ...own }),
|
|
72
|
+
panoFallbackCss({ ns: 'market', root, outDir: path.join(root, 'out'), side: 'client', ...fallback }),
|
|
73
|
+
svelte({ compilerOptions: { generate: 'client', css: 'external' }, emitCss, onwarn() {} }),
|
|
74
|
+
],
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
await bundle.write({ dir: out, format: 'es', entryFileNames: 'client.mjs' });
|
|
78
|
+
await bundle.close();
|
|
79
|
+
|
|
80
|
+
const files = {};
|
|
81
|
+
|
|
82
|
+
for (const name of fs.readdirSync(out)) files[name] = fs.readFileSync(path.join(out, name), 'utf8');
|
|
83
|
+
|
|
84
|
+
return files;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
describe('scanViews (STEP 1)', () => {
|
|
88
|
+
const root = pluginRoot(FILES);
|
|
89
|
+
const baseClasses = baseClassSet(fs.readFileSync(new URL('./fixtures/base.css', import.meta.url), 'utf8') +
|
|
90
|
+
'.badge, .bg-success, .bg-danger, .text-bg-success, .text-bg-danger, .card-title, .h-100, .d-flex, .btn-sm {}');
|
|
91
|
+
|
|
92
|
+
test('markup class tokens, script literals that are base classes, helper files', () => {
|
|
93
|
+
const scan = scanViews(path.join(root, 'src/theme/views'), baseClasses, 'market');
|
|
94
|
+
|
|
95
|
+
expect(scan.used.has('card')).toBe(true);
|
|
96
|
+
expect(scan.used.has('btn-sm')).toBe(true);
|
|
97
|
+
expect(scan.used.has('text-bg-success')).toBe(true); // BADGES map in <script>
|
|
98
|
+
expect(scan.used.has('text-bg-danger')).toBe(true);
|
|
99
|
+
expect(scan.used.has('unrelated')).toBe(false); // a helper literal that is not a class
|
|
100
|
+
expect(scan.used.has('not')).toBe(false);
|
|
101
|
+
expect(scan.fa).toBe(false);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('.js files under the views folder are read too', () => {
|
|
105
|
+
const lib = pluginRoot({
|
|
106
|
+
'views/A.svelte': '<div class="card"></div>',
|
|
107
|
+
'views/helpers/classes.js': "export const x = 'badge bg-danger'; export const y = `bg-${'success'}`;",
|
|
108
|
+
});
|
|
109
|
+
const scan = scanViews(path.join(lib, 'views'), baseClasses, 'market');
|
|
110
|
+
|
|
111
|
+
expect(scan.used.has('badge')).toBe(true);
|
|
112
|
+
expect(scan.used.has('bg-danger')).toBe(true);
|
|
113
|
+
expect(scan.used.has('bg-')).toBe(false);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('Font Awesome and tooltip hints', () => {
|
|
117
|
+
const r = pluginRoot({
|
|
118
|
+
'views/Icon.svelte': '<i class="fa-solid fa-user"></i><span data-bs-toggle="tooltip" title="x">y</span>',
|
|
119
|
+
});
|
|
120
|
+
const scan = scanViews(path.join(r, 'views'), baseClasses, 'market');
|
|
121
|
+
|
|
122
|
+
expect(scan.fa).toBe(true);
|
|
123
|
+
expect(scan.used.has('tooltip')).toBe(true);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('roots and classes per view: root class first, parts in source order, none without an element root', () => {
|
|
127
|
+
const r = pluginRoot({
|
|
128
|
+
'views/Parts.svelte':
|
|
129
|
+
'<div class="market-parts card"><h3 class="market-parts__title">a</h3><p class="market-parts__add-to-cart">b</p></div>',
|
|
130
|
+
'views/Wrapper.svelte': "<script>import Parts from './Parts.svelte';</script>\n<Parts />",
|
|
131
|
+
'views/helper.svelte': '<p>not a view name</p>',
|
|
132
|
+
});
|
|
133
|
+
const scan = scanViews(path.join(r, 'views'), baseClasses, 'market');
|
|
134
|
+
const byName = Object.fromEntries(scan.views.map((v) => [v.name, v]));
|
|
135
|
+
|
|
136
|
+
expect(byName.Parts.roots).toEqual(['div']);
|
|
137
|
+
expect(byName.Parts.classes).toEqual(['market-parts', 'market-parts__title', 'market-parts__add-to-cart']);
|
|
138
|
+
expect(byName.Wrapper.roots).toEqual([]);
|
|
139
|
+
expect(byName.Wrapper.classes).toEqual([]);
|
|
140
|
+
expect(byName.helper).toBeUndefined();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('a missing views folder is an empty scan', () => {
|
|
144
|
+
expect(scanViews('/nonexistent/views', baseClasses, 'market').used.size).toBe(0);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe('safelist helpers', () => {
|
|
149
|
+
test('nearMatches suggests close base classes', () => {
|
|
150
|
+
const known = new Set(['text-bg-success', 'text-bg-danger', 'btn', 'card']);
|
|
151
|
+
|
|
152
|
+
expect(nearMatches('text-bg-sucess', known)[0]).toBe('text-bg-success');
|
|
153
|
+
expect(nearMatches('zzzzzzzz', known)).toEqual([]);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe('panoFallbackCss + panoPluginCss in a rollup build', () => {
|
|
158
|
+
test('emits client/fallback.css with the classes of markup, scripts and helpers', async () => {
|
|
159
|
+
const root = pluginRoot(FILES);
|
|
160
|
+
const files = await build(root);
|
|
161
|
+
|
|
162
|
+
expect(Object.keys(files).sort()).toEqual(['client.mjs', 'fallback.css', 'plugin.css']);
|
|
163
|
+
|
|
164
|
+
const css = files['fallback.css'];
|
|
165
|
+
|
|
166
|
+
expect(css).toContain('@layer pano-fallback.components');
|
|
167
|
+
expect(css).toContain('.card-body');
|
|
168
|
+
expect(css).toContain('.btn-primary');
|
|
169
|
+
expect(css).toContain('.text-bg-success'); // built in a <script> map
|
|
170
|
+
expect(css).toContain('.text-bg-danger');
|
|
171
|
+
expect(css).toContain('.badge');
|
|
172
|
+
expect(css).toContain('.bg-success'); // a string literal of a helper file
|
|
173
|
+
expect(css).not.toContain('!important');
|
|
174
|
+
expect(css).not.toContain('.col-md-6');
|
|
175
|
+
expect(css).toContain('data-pano-fb="market"');
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test('records styles and per-view roots / classes for pano-plugin.json', async () => {
|
|
179
|
+
const root = pluginRoot(FILES);
|
|
180
|
+
const files = await build(root);
|
|
181
|
+
const context = getBuildContext(root);
|
|
182
|
+
|
|
183
|
+
expect(context.styles).toEqual({
|
|
184
|
+
fallback: 'client/fallback.css',
|
|
185
|
+
own: 'client/plugin.css',
|
|
186
|
+
hash: styleHash({ fallback: files['fallback.css'], own: files['plugin.css'] }),
|
|
187
|
+
icons: false,
|
|
188
|
+
});
|
|
189
|
+
expect(context.styles.hash).toMatch(/^[0-9a-f]{8}$/);
|
|
190
|
+
expect(context.views.ProductCard.roots).toEqual(['div']);
|
|
191
|
+
expect(context.views.ProductCard.classes).toEqual(['market-product-card']);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
test('the hash changes with either file', () => {
|
|
195
|
+
expect(styleHash({ fallback: 'a', own: 'b' })).not.toBe(styleHash({ fallback: 'a', own: 'c' }));
|
|
196
|
+
expect(styleHash({ fallback: 'a' })).not.toBe(styleHash({ fallback: 'b' }));
|
|
197
|
+
expect(styleHash({ fallback: 'a' })).toBe(styleHash({ fallback: 'a' }));
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test('icons: auto follows fa- classes, true / false are taken as given', async () => {
|
|
201
|
+
const withIcon = pluginRoot({ ...FILES, 'src/theme/views/Icon.svelte': '<i class="fa-solid fa-user"></i>' });
|
|
202
|
+
|
|
203
|
+
await build(withIcon);
|
|
204
|
+
expect(getBuildContext(withIcon).styles.icons).toBe(true);
|
|
205
|
+
|
|
206
|
+
const plain = pluginRoot(FILES);
|
|
207
|
+
|
|
208
|
+
await build(plain, { fallback: { icons: true } });
|
|
209
|
+
expect(getBuildContext(plain).styles.icons).toBe(true);
|
|
210
|
+
await build(withIcon, { fallback: { icons: false } });
|
|
211
|
+
expect(getBuildContext(withIcon).styles.icons).toBe(false);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test('the safelist adds classes the scan cannot see', async () => {
|
|
215
|
+
const root = pluginRoot(FILES);
|
|
216
|
+
const files = await build(root, { fallback: { safelist: ['table', 'progress-bar'] } });
|
|
217
|
+
|
|
218
|
+
expect(files['fallback.css']).toContain('.progress-bar');
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test('an unknown safelist entry fails the build and names near matches', async () => {
|
|
222
|
+
const root = pluginRoot(FILES);
|
|
223
|
+
|
|
224
|
+
await expect(build(root, { fallback: { safelist: ['text-bg-sucess'] } })).rejects.toThrow(
|
|
225
|
+
/text-bg-sucess[\s\S]*did you mean "text-bg-success"/,
|
|
226
|
+
);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test('a server build gets no-op plugins', () => {
|
|
230
|
+
expect(Object.keys(panoFallbackCss({ ns: 'market', side: 'server' }))).toEqual(['name']);
|
|
231
|
+
expect(Object.keys(panoPluginCss({ ns: 'market', side: 'server' }))).toEqual(['name']);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test('a bad namespace is refused', () => {
|
|
235
|
+
expect(() => panoFallbackCss({ ns: 'Bad' })).toThrow(/ns/);
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
describe('plugin.css (doc 03 section 3.1)', () => {
|
|
240
|
+
test('component CSS lands in @layer pano-plugin with the hashed selectors of the compiled markup', async () => {
|
|
241
|
+
const root = pluginRoot(FILES);
|
|
242
|
+
const files = await build(root);
|
|
243
|
+
const own = files['plugin.css'];
|
|
244
|
+
|
|
245
|
+
expect(own.startsWith('@layer pano-plugin {')).toBe(true);
|
|
246
|
+
expect(own.trimEnd().endsWith('}')).toBe(true);
|
|
247
|
+
expect(own).toContain('src/theme/views/ProductCard.svelte');
|
|
248
|
+
|
|
249
|
+
const hash = /svelte-[a-z0-9]+/.exec(own)[0];
|
|
250
|
+
|
|
251
|
+
expect(own).toContain(`.market-product-card.${hash}`);
|
|
252
|
+
expect(own).toContain(`.card-title.${hash}`);
|
|
253
|
+
// the same hash class sits on the markup of the compiled component
|
|
254
|
+
expect(files['client.mjs']).toContain(hash);
|
|
255
|
+
expect(own).not.toContain('<style');
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test('a plugin without <style> emits no file and no styles.own', async () => {
|
|
259
|
+
const root = pluginRoot({
|
|
260
|
+
'src/theme/views/Plain.svelte': '<div class="card">x</div>',
|
|
261
|
+
'src/entry.js': "import P from './theme/views/Plain.svelte'; export default P;",
|
|
262
|
+
});
|
|
263
|
+
const files = await build(root);
|
|
264
|
+
|
|
265
|
+
expect(files['plugin.css']).toBeUndefined();
|
|
266
|
+
expect(getBuildContext(root).styles.own).toBeUndefined();
|
|
267
|
+
expect(getBuildContext(root).styles.fallback).toBe('client/fallback.css');
|
|
268
|
+
expect(getBuildContext(root).styles.hash).toBe(styleHash({ fallback: files['fallback.css'] }));
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
test('with emitCss: true the same CSS is collected and no .css module reaches the bundle', async () => {
|
|
272
|
+
const root = pluginRoot(FILES);
|
|
273
|
+
const compiledHere = await build(root);
|
|
274
|
+
const emitted = await build(pluginRoot(FILES), { emitCss: true });
|
|
275
|
+
|
|
276
|
+
expect(emitted['plugin.css']).toBeDefined();
|
|
277
|
+
expect(emitted['client.mjs']).not.toContain('.css');
|
|
278
|
+
|
|
279
|
+
const hashOf = (css) => /svelte-[a-z0-9]+/.exec(css)[0];
|
|
280
|
+
|
|
281
|
+
// the file name of the hash differs between two temp roots, but both modes compile each root alike
|
|
282
|
+
const sameRoot = await build(root, { emitCss: true });
|
|
283
|
+
|
|
284
|
+
expect(hashOf(sameRoot['plugin.css'])).toBe(hashOf(compiledHere['plugin.css']));
|
|
285
|
+
expect(sameRoot['plugin.css']).toBe(compiledHere['plugin.css']);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
test('a rebuild forgets what the previous build recorded', async () => {
|
|
289
|
+
const root = pluginRoot(FILES);
|
|
290
|
+
|
|
291
|
+
await build(root);
|
|
292
|
+
expect(getBuildContext(root).styles.own).toBe('client/plugin.css');
|
|
293
|
+
|
|
294
|
+
fs.writeFileSync(
|
|
295
|
+
path.join(root, 'src/theme/views/ProductCard.svelte'),
|
|
296
|
+
CARD.replace(/<style>[\s\S]*<\/style>/, ''),
|
|
297
|
+
);
|
|
298
|
+
await build(root);
|
|
299
|
+
expect(getBuildContext(root).styles.own).toBeUndefined();
|
|
300
|
+
});
|
|
301
|
+
});
|