@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.
Files changed (89) hide show
  1. package/assets/pano-bootstrap.css +17903 -0
  2. package/bin/__tests__/new/e2e.test.js +111 -0
  3. package/bin/__tests__/new/helpers.js +76 -0
  4. package/bin/__tests__/new/new.test.js +472 -0
  5. package/bin/new.js +530 -0
  6. package/bin/pano-plugin.js +162 -0
  7. package/bin/templates/plugin/README.md +30 -0
  8. package/bin/templates/plugin/_gitignore +15 -0
  9. package/bin/templates/plugin/build.gradle.kts +389 -0
  10. package/bin/templates/plugin/gradle/wrapper/gradle-wrapper.jar +0 -0
  11. package/bin/templates/plugin/gradle/wrapper/gradle-wrapper.properties +7 -0
  12. package/bin/templates/plugin/gradle.properties +55 -0
  13. package/bin/templates/plugin/gradlew +249 -0
  14. package/bin/templates/plugin/gradlew.bat +92 -0
  15. package/bin/templates/plugin/package.json.tpl +14 -0
  16. package/bin/templates/plugin/rollup.config.js +2 -0
  17. package/bin/templates/plugin/settings.gradle.kts +5 -0
  18. package/bin/templates/plugin/src/main/kotlin/__PKGPATH__/__CLASS__Plugin.kt +50 -0
  19. package/bin/templates/plugin/src/main/kotlin/__PKGPATH__/frontend/ExampleFallbackPage.kt +28 -0
  20. package/bin/templates/plugin/src/main/kotlin/__PKGPATH__/routes/GetHelloAPI.kt +19 -0
  21. package/bin/templates/plugin/src/main/kotlin/com/panomc/plugins/license/LicenseGuard.kt +30 -0
  22. package/bin/templates/plugin/src/main/kotlin/com/panomc/plugins/license/PluginLicenseClient.kt +144 -0
  23. package/bin/templates/plugin/src/main/resources/config.conf +1 -0
  24. package/bin/templates/plugin/src/main/resources/frontend-targets.json +1 -0
  25. package/bin/templates/plugin/src/main/resources/locales/en-US.json +3 -0
  26. package/bin/templates/plugin/src/main/resources/logo.png +0 -0
  27. package/bin/templates/plugin/src/theme/views/HelloPage.svelte +26 -0
  28. package/bin/ui.js +96 -0
  29. package/package.json +46 -4
  30. package/src/config.js +191 -0
  31. package/src/controller/__tests__/controller.test.js +647 -0
  32. package/src/controller/index.js +604 -0
  33. package/src/dev.js +208 -0
  34. package/src/index.js +22 -0
  35. package/src/rollup/__tests__/controllers/controllers.test.js +418 -0
  36. package/src/rollup/__tests__/controllers/fixture.js +143 -0
  37. package/src/rollup/__tests__/controllers/golden/controllers.json +34 -0
  38. package/src/rollup/__tests__/controllers/golden/controllers.types.js +69 -0
  39. package/src/rollup/__tests__/controllers/golden/pano-plugin.json +16 -0
  40. package/src/rollup/__tests__/controllers/golden/pano-plugin.lock.json +27 -0
  41. package/src/rollup/__tests__/controllers/golden/pano-plugin.with-views.json +54 -0
  42. package/src/rollup/__tests__/preset/preset.test.js +418 -0
  43. package/src/rollup/__tests__/rules/_build.js +39 -0
  44. package/src/rollup/__tests__/rules/_fixture.js +83 -0
  45. package/src/rollup/__tests__/rules/helpers.test.js +148 -0
  46. package/src/rollup/__tests__/rules/rules.test.js +259 -0
  47. package/src/rollup/__tests__/rules/stamp.test.js +113 -0
  48. package/src/rollup/__tests__/samples/samples.test.js +481 -0
  49. package/src/rollup/__tests__/seams/config.test.js +78 -0
  50. package/src/rollup/__tests__/seams/lock.test.js +124 -0
  51. package/src/rollup/__tests__/seams/sdk-seams.test.js +93 -0
  52. package/src/rollup/__tests__/seams/stubs.test.js +52 -0
  53. package/src/rollup/__tests__/views/helpers.js +82 -0
  54. package/src/rollup/__tests__/views/views.test.js +522 -0
  55. package/src/rollup/__tests__/widgets/helpers.js +117 -0
  56. package/src/rollup/__tests__/widgets/widgets.test.js +422 -0
  57. package/src/rollup/cli-build.js +90 -0
  58. package/src/rollup/cli-check.js +280 -0
  59. package/src/rollup/cli-classes.js +75 -0
  60. package/src/rollup/client-gen.js +72 -0
  61. package/src/rollup/controllers.js +434 -0
  62. package/src/rollup/entry.js +250 -0
  63. package/src/rollup/helpers.js +193 -0
  64. package/src/rollup/index.js +601 -0
  65. package/src/rollup/integrate.js +205 -0
  66. package/src/rollup/lock.js +230 -0
  67. package/src/rollup/meta.js +479 -0
  68. package/src/rollup/rules.js +950 -0
  69. package/src/rollup/samples.js +667 -0
  70. package/src/rollup/stamp.js +410 -0
  71. package/src/rollup/types.js +248 -0
  72. package/src/rollup/views.js +1205 -0
  73. package/src/rollup/widgets.js +1000 -0
  74. package/src/styles/__tests__/fallback/__snapshots__/build-fallback-css.test.js.snap +173 -0
  75. package/src/styles/__tests__/fallback/build-fallback-css.test.js +526 -0
  76. package/src/styles/__tests__/fallback/fixtures/base.css +247 -0
  77. package/src/styles/__tests__/fallback/plugins.test.js +301 -0
  78. package/src/styles/__tests__/lint/check-styles.test.js +423 -0
  79. package/src/styles/__tests__/lint/fixtures/ProductCard.golden.svelte +13 -0
  80. package/src/styles/__tests__/lint/fixtures/ProductCard.in.svelte +13 -0
  81. package/src/styles/__tests__/lint/semantic-classes.test.js +364 -0
  82. package/src/styles/bootstrap-classes.js +155 -0
  83. package/src/styles/check-styles.js +626 -0
  84. package/src/styles/fallback-css.js +1182 -0
  85. package/src/styles/plugin-css.js +237 -0
  86. package/src/styles/scan.js +206 -0
  87. package/src/styles/semantic-classes.js +436 -0
  88. package/src/styles/tokens.map.js +53 -0
  89. package/README.md +0 -3
@@ -0,0 +1,364 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import {
5
+ SemanticClassCollisionError,
6
+ addPartClasses,
7
+ addRootClass,
8
+ kebab,
9
+ panoSemanticClasses,
10
+ } from '../../semantic-classes.js';
11
+
12
+ const fixtures = path.join(import.meta.dir, 'fixtures');
13
+ const read = (name) => fs.readFileSync(path.join(fixtures, name), 'utf8');
14
+ const ctx = { ns: 'market', view: 'ProductCard' };
15
+ const ROOT = 'market-product-card';
16
+
17
+ describe('kebab', () => {
18
+ test('view names', () => {
19
+ expect(kebab('ProductCard')).toBe('product-card');
20
+ expect(kebab('HTMLView')).toBe('html-view');
21
+ expect(kebab('Navbar')).toBe('navbar');
22
+ expect(kebab('addToCart')).toBe('add-to-cart');
23
+ expect(kebab('add_to_cart')).toBe('add-to-cart');
24
+ });
25
+ });
26
+
27
+ describe('addRootClass', () => {
28
+ test('plain root without a class attribute', () => {
29
+ const r = addRootClass('<div><p>x</p></div>', ctx);
30
+ expect(r.code).toBe(`<div class="${ROOT}"><p>x</p></div>`);
31
+ expect(r.added).toEqual([ROOT]);
32
+ expect(r.roots).toEqual(['div']);
33
+ expect(r.warnings).toEqual([]);
34
+ });
35
+
36
+ test('plain root keeps script and style blocks untouched', () => {
37
+ const src = '<script>let a = 1;</script>\n<section id="s">{a}</section>\n<style>p { color: red }</style>';
38
+ const r = addRootClass(src, ctx);
39
+ expect(r.code).toBe(
40
+ `<script>let a = 1;</script>\n<section class="${ROOT}" id="s">{a}</section>\n<style>p { color: red }</style>`,
41
+ );
42
+ });
43
+
44
+ test('self closing and void roots', () => {
45
+ expect(addRootClass('<img src="a.png" />', ctx).code).toBe(`<img class="${ROOT}" src="a.png" />`);
46
+ });
47
+
48
+ test('{#if} roots: every branch gets the class, else-if included', () => {
49
+ const src = '{#if a}<div>a</div>{:else if b}<section>b</section>{:else}<p>c</p>{/if}';
50
+ const r = addRootClass(src, ctx);
51
+ expect(r.code).toBe(
52
+ `{#if a}<div class="${ROOT}">a</div>{:else if b}<section class="${ROOT}">b</section>{:else}<p class="${ROOT}">c</p>{/if}`,
53
+ );
54
+ expect(r.roots).toEqual(['div', 'section', 'p']);
55
+ expect(r.added).toEqual([ROOT]);
56
+ });
57
+
58
+ test('{#each} body and fallback, {#key} and {#await} roots', () => {
59
+ const src =
60
+ '{#each items as i}<li>{i}</li>{:else}<p>none</p>{/each}' +
61
+ '{#key k}<div>k</div>{/key}' +
62
+ '{#await p}<span>wait</span>{:then v}<b>{v}</b>{:catch e}<i>{e}</i>{/await}';
63
+ const r = addRootClass(src, ctx);
64
+ for (const tag of ['li', 'p', 'div', 'span', 'b', 'i'])
65
+ expect(r.code).toContain(`<${tag} class="${ROOT}">`);
66
+ expect(r.roots).toEqual(['li', 'p', 'div', 'span', 'b', 'i']);
67
+ });
68
+
69
+ test('elements nested in a root element are not roots', () => {
70
+ const r = addRootClass('<div><span>x</span></div>', ctx);
71
+ expect(r.code).not.toContain('<span class');
72
+ });
73
+
74
+ test('a component root gets no class and the build message', () => {
75
+ const src = '<script>import Card from "./Card.svelte";</script>\n<Card title="x" />';
76
+ const r = addRootClass(src, ctx);
77
+ expect(r.code).toBe(src);
78
+ expect(r.added).toEqual([]);
79
+ expect(r.roots).toEqual([]);
80
+ expect(r.warnings).toEqual([
81
+ 'ProductCard has no root element; wrap it in an element so themes can target it',
82
+ ]);
83
+ });
84
+
85
+ test('{@render} and text-only tops have no root either', () => {
86
+ expect(addRootClass('{@render children?.()}', ctx).roots).toEqual([]);
87
+ expect(addRootClass('just text', ctx).warnings.length).toBe(1);
88
+ });
89
+
90
+ test('class form 1: text value is prepended', () => {
91
+ expect(addRootClass('<div class="card h-100">x</div>', ctx).code).toBe(
92
+ `<div class="${ROOT} card h-100">x</div>`,
93
+ );
94
+ expect(addRootClass("<div class='card'>x</div>", ctx).code).toBe(
95
+ `<div class='${ROOT} card'>x</div>`,
96
+ );
97
+ });
98
+
99
+ test('class form 1: quoted value with expression parts is prepended', () => {
100
+ expect(addRootClass('<div class="card {size}">x</div>', ctx).code).toBe(
101
+ `<div class="${ROOT} card {size}">x</div>`,
102
+ );
103
+ expect(addRootClass('<div class="{size}">x</div>', ctx).code).toBe(
104
+ `<div class="${ROOT} {size}">x</div>`,
105
+ );
106
+ });
107
+
108
+ test('class form 1: unquoted and empty values', () => {
109
+ expect(addRootClass('<div class=card>x</div>', ctx).code).toBe(`<div class="${ROOT} card">x</div>`);
110
+ expect(addRootClass('<div class>x</div>', ctx).code).toBe(`<div class="${ROOT}">x</div>`);
111
+ });
112
+
113
+ test('class form 2: expression becomes an array', () => {
114
+ expect(addRootClass('<div class={cls}>x</div>', ctx).code).toBe(
115
+ `<div class={['${ROOT}', cls]}>x</div>`,
116
+ );
117
+ expect(addRootClass("<div class={a ? 'x' : 'y'}>x</div>", ctx).code).toBe(
118
+ `<div class={['${ROOT}', a ? 'x' : 'y']}>x</div>`,
119
+ );
120
+ });
121
+
122
+ test('class form 3: an array literal gets the entry inserted', () => {
123
+ expect(addRootClass("<div class={['card', { on: x }]}>x</div>", ctx).code).toBe(
124
+ `<div class={['${ROOT}', 'card', { on: x }]}>x</div>`,
125
+ );
126
+ expect(addRootClass('<div class={[]}>x</div>', ctx).code).toBe(`<div class={['${ROOT}']}>x</div>`);
127
+ });
128
+
129
+ test('idempotent for every class form', () => {
130
+ const sources = [
131
+ '<div>x</div>',
132
+ '<div class="card">x</div>',
133
+ '<div class={cls}>x</div>',
134
+ "<div class={['card', { on: x }]}>x</div>",
135
+ '<div class="card {size}">x</div>',
136
+ '{#if a}<div>a</div>{:else}<p>b</p>{/if}',
137
+ '<div class>x</div>',
138
+ ];
139
+ for (const src of sources) {
140
+ const once = addRootClass(src, ctx);
141
+ const twice = addRootClass(once.code, ctx);
142
+ expect(twice.code).toBe(once.code);
143
+ expect(twice.added).toEqual([]);
144
+ expect(twice.roots).toEqual(once.roots);
145
+ }
146
+ });
147
+
148
+ test('a root class written by hand is left alone', () => {
149
+ const src = `<div class="${ROOT} card">x</div>`;
150
+ const r = addRootClass(src, ctx);
151
+ expect(r.code).toBe(src);
152
+ expect(r.added).toEqual([]);
153
+ expect(r.roots).toEqual(['div']);
154
+ });
155
+
156
+ test('a Bootstrap / FontAwesome collision throws and names namespace', () => {
157
+ expect(() => addRootClass('<div>x</div>', { ns: 'card', view: 'Body' })).toThrow(
158
+ SemanticClassCollisionError,
159
+ );
160
+ try {
161
+ addRootClass('<div>x</div>', { ns: 'card', view: 'Body' });
162
+ } catch (error) {
163
+ expect(error.message).toContain('"card-body"');
164
+ expect(error.message).toContain('"namespace"');
165
+ expect(error.message).toContain('pano.plugin.js');
166
+ }
167
+ expect(() => addRootClass('<div>x</div>', { ns: 'fa', view: 'Solid' })).toThrow(/namespace/);
168
+ expect(() => addRootClass('<div>x</div>', { ns: 'pano', view: 'Post' })).not.toThrow();
169
+ });
170
+ });
171
+
172
+ describe('addPartClasses', () => {
173
+ const part = (src) => addPartClasses(src, ctx);
174
+
175
+ test('Bootstrap table: every entry', () => {
176
+ const table = {
177
+ 'card-body': 'body',
178
+ 'card-title': 'title',
179
+ 'card-header': 'header',
180
+ 'card-footer': 'footer',
181
+ 'card-img-top': 'image',
182
+ badge: 'badge',
183
+ alert: 'alert',
184
+ 'list-group': 'list',
185
+ 'list-group-item': 'item',
186
+ table: 'table',
187
+ 'form-control': 'input',
188
+ 'form-select': 'select',
189
+ 'form-label': 'label',
190
+ 'form-check-input': 'check',
191
+ 'nav-link': 'link',
192
+ 'modal-header': 'header',
193
+ 'modal-body': 'body',
194
+ 'modal-footer': 'footer',
195
+ 'offcanvas-header': 'header',
196
+ 'offcanvas-body': 'body',
197
+ 'dropdown-menu': 'menu',
198
+ 'dropdown-item': 'menu-item',
199
+ pagination: 'pager',
200
+ btn: 'action',
201
+ };
202
+ for (const [bootstrapClass, name] of Object.entries(table)) {
203
+ const r = part(`<div><span class="${bootstrapClass} mb-2">x</span></div>`);
204
+ expect(r.added.map((a) => a.class)).toEqual([`${ROOT}__${name}`]);
205
+ expect(r.code).toContain(`class="${ROOT}__${name} ${bootstrapClass} mb-2"`);
206
+ }
207
+ });
208
+
209
+ test('tag table: img and headings that carry a Bootstrap class', () => {
210
+ const r = part('<div><img class="img-fluid" src="a"><h4 class="mb-0">t</h4><h2>plain</h2></div>');
211
+ expect(r.added.map((a) => a.class)).toEqual([`${ROOT}__image`, `${ROOT}__title`]);
212
+ expect(r.code).toContain('<h2>plain</h2>');
213
+ });
214
+
215
+ test('the Bootstrap table wins over the tag table', () => {
216
+ const r = part('<div><h5 class="card-header">t</h5></div>');
217
+ expect(r.added.map((a) => a.class)).toEqual([`${ROOT}__header`]);
218
+ });
219
+
220
+ test('elements without a Bootstrap component class are left alone', () => {
221
+ const src = '<div class="d-flex gap-2"><span class="text-muted">x</span></div>';
222
+ expect(part(src).code).toBe(src);
223
+ });
224
+
225
+ test('an element that already has an <ns>- class is skipped', () => {
226
+ const src = '<div><p class="market-other__x card-body">x</p></div>';
227
+ expect(part(src)).toEqual({ code: src, added: [] });
228
+ });
229
+
230
+ test('clash: the last segment of the first $_ key, then -2, -3', () => {
231
+ const src =
232
+ '<div>' +
233
+ '<button class="btn">{$_("theme.a")}</button>' +
234
+ '<button class="btn">{$_(\'theme.store.addToCart\')}</button>' +
235
+ '<button class="btn">{$_(\'theme.store.addToCart\')}</button>' +
236
+ '<button class="btn">no key</button>' +
237
+ '</div>';
238
+ const names = part(src).added.map((a) => a.class.replace(`${ROOT}__`, ''));
239
+ expect(names).toEqual(['action', 'add-to-cart', 'action-2', 'action-3']);
240
+ });
241
+
242
+ test('names already present in the file count as used', () => {
243
+ const src = `<div class="card"><p class="${ROOT}__title">x</p><h3 class="card-title">y</h3></div>`;
244
+ expect(part(src).added.map((a) => a.class)).toEqual([`${ROOT}__title-2`]);
245
+ });
246
+
247
+ test('reports the 1-based line of each element', () => {
248
+ const r = part('<div>\n <p class="alert">x</p>\n\n <b class="badge">y</b>\n</div>');
249
+ expect(r.added.map((a) => a.line)).toEqual([2, 4]);
250
+ });
251
+
252
+ test('works inside blocks and component children', () => {
253
+ const src =
254
+ '{#if a}<div>{#each l as i}<span class="badge">{i}</span>{/each}</div>{/if}' +
255
+ '<Modal><div class="modal-body">x</div></Modal>';
256
+ const r = part(src);
257
+ expect(r.added.map((a) => a.class)).toEqual([`${ROOT}__badge`, `${ROOT}__body`]);
258
+ });
259
+
260
+ test('the three class forms', () => {
261
+ expect(part('<p class="alert">x</p>').code).toBe(`<p class="${ROOT}__alert alert">x</p>`);
262
+ expect(part('<p class={alertClass} data-x="1">x</p>').code).toBe(
263
+ '<p class={alertClass} data-x="1">x</p>',
264
+ ); // no literal Bootstrap class: nothing to name
265
+ expect(part("<p class={['alert', kind]}>x</p>").code).toBe(
266
+ `<p class={['${ROOT}__alert', 'alert', kind]}>x</p>`,
267
+ );
268
+ expect(part('<p class="btn {extra}">x</p>').code).toBe(
269
+ `<p class="${ROOT}__action btn {extra}">x</p>`,
270
+ );
271
+ });
272
+
273
+ test('idempotent', () => {
274
+ const once = part(read('ProductCard.in.svelte'));
275
+ const twice = part(once.code);
276
+ expect(twice.code).toBe(once.code);
277
+ expect(twice.added).toEqual([]);
278
+ });
279
+ });
280
+
281
+ describe('ProductCard golden file (doc 03 section 1.1)', () => {
282
+ const run = (input) => {
283
+ const root = addRootClass(input, ctx);
284
+ return addPartClasses(root.code, ctx).code;
285
+ };
286
+
287
+ test('root step then codemod equals the golden file', () => {
288
+ expect(run(read('ProductCard.in.svelte'))).toBe(read('ProductCard.golden.svelte'));
289
+ });
290
+
291
+ test('the golden file contains the lines of the worked example', () => {
292
+ const golden = read('ProductCard.golden.svelte');
293
+ for (const line of [
294
+ "<div class={['market-product-card', 'card', 'h-100', { 'is-sold-out': !product.inStock }]}>",
295
+ '<div class="market-product-card__body card-body d-flex flex-column gap-1">',
296
+ '<h3 class="market-product-card__title h6 card-title mb-0 text-truncate">',
297
+ '<button class="market-product-card__add-to-cart btn btn-primary btn-sm w-100" onclick={add}>',
298
+ ])
299
+ expect(golden).toContain(line);
300
+ });
301
+
302
+ test('running both steps on the golden file changes nothing', () => {
303
+ const golden = read('ProductCard.golden.svelte');
304
+ expect(run(golden)).toBe(golden);
305
+ });
306
+ });
307
+
308
+ describe('panoSemanticClasses', () => {
309
+ test('is a svelte markup preprocessor', () => {
310
+ const pre = panoSemanticClasses({ ns: 'market' });
311
+ expect(pre.name).toBe('pano-semantic-classes');
312
+ expect(typeof pre.markup).toBe('function');
313
+ });
314
+
315
+ test('adds the root class from the file name', () => {
316
+ const pre = panoSemanticClasses({ ns: 'market' });
317
+ const out = pre.markup({ content: '<div>x</div>', filename: '/p/src/theme/views/ProductCard.svelte' });
318
+ expect(out.code).toBe(`<div class="${ROOT}">x</div>`);
319
+ });
320
+
321
+ test('leaves other files, node_modules and unchanged sources alone', () => {
322
+ const pre = panoSemanticClasses({ ns: 'market' });
323
+ expect(pre.markup({ content: '<div>x</div>', filename: '/p/a.js' })).toBeUndefined();
324
+ expect(pre.markup({ content: '<div>x</div>', filename: '/p/node_modules/x/A.svelte' })).toBeUndefined();
325
+ expect(pre.markup({ content: '<div>x</div>' })).toBeUndefined();
326
+ expect(
327
+ pre.markup({ content: `<div class="${ROOT}">x</div>`, filename: '/p/ProductCard.svelte' }),
328
+ ).toBeUndefined();
329
+ });
330
+
331
+ test('views option: a directory list and a resolver', () => {
332
+ const dirs = panoSemanticClasses({ ns: 'market', views: ['/p/src/theme/views'] });
333
+ expect(dirs.markup({ content: '<b>x</b>', filename: '/p/src/theme/views/A.svelte' }).code).toContain(
334
+ 'market-a',
335
+ );
336
+ expect(dirs.markup({ content: '<b>x</b>', filename: '/p/src/theme/lib/B.svelte' })).toBeUndefined();
337
+ const fn = panoSemanticClasses({ ns: 'market', views: (f) => (f.endsWith('Z.svelte') ? 'Zed' : null) });
338
+ expect(fn.markup({ content: '<b>x</b>', filename: '/q/Z.svelte' }).code).toContain('market-zed');
339
+ });
340
+
341
+ test('no element root prints the build message', () => {
342
+ const messages = [];
343
+ const pre = panoSemanticClasses({ ns: 'market', warn: (m) => messages.push(m) });
344
+ expect(pre.markup({ content: '<Card />', filename: '/p/Wrapper.svelte' })).toBeUndefined();
345
+ expect(messages).toEqual([
346
+ '/p/Wrapper.svelte: Wrapper has no root element; wrap it in an element so themes can target it',
347
+ ]);
348
+ });
349
+
350
+ test('a collision fails the build, a syntax error is left to the compiler', () => {
351
+ const pre = panoSemanticClasses({ ns: 'card' });
352
+ expect(() => pre.markup({ content: '<div>x</div>', filename: '/p/Body.svelte' })).toThrow(/namespace/);
353
+ const ok = panoSemanticClasses({ ns: 'market' });
354
+ expect(ok.markup({ content: '<div>', filename: '/p/Broken.svelte' })).toBeUndefined();
355
+ });
356
+
357
+ test('works as a rollup-plugin-svelte preprocess group through svelte/compiler', async () => {
358
+ const { preprocess } = await import('svelte/compiler');
359
+ const out = await preprocess('<div>x</div>', panoSemanticClasses({ ns: 'market' }), {
360
+ filename: '/p/ProductCard.svelte',
361
+ });
362
+ expect(out.code).toBe(`<div class="${ROOT}">x</div>`);
363
+ });
364
+ });
@@ -0,0 +1,155 @@
1
+ // Class names the theme side may use: Bootstrap 5.3 + FontAwesome (14 §2 rule 4). Prefix based.
2
+ const prefixes = [
3
+ 'container',
4
+ 'row',
5
+ 'col',
6
+ 'offset',
7
+ 'order',
8
+ 'btn',
9
+ 'card',
10
+ 'badge',
11
+ 'alert',
12
+ 'modal',
13
+ 'offcanvas',
14
+ 'dropdown',
15
+ 'nav',
16
+ 'navbar',
17
+ 'tab',
18
+ 'tabs',
19
+ 'list-group',
20
+ 'form',
21
+ 'input-group',
22
+ 'invalid-feedback',
23
+ 'valid-feedback',
24
+ 'is-invalid',
25
+ 'is-valid',
26
+ 'table',
27
+ 'pagination',
28
+ 'page',
29
+ 'breadcrumb',
30
+ 'accordion',
31
+ 'collapse',
32
+ 'collapsing',
33
+ 'progress',
34
+ 'spinner',
35
+ 'placeholder',
36
+ 'toast',
37
+ 'tooltip',
38
+ 'popover',
39
+ 'carousel',
40
+ 'ratio',
41
+ 'stretched-link',
42
+ 'd',
43
+ 'align',
44
+ 'flex',
45
+ 'justify-content',
46
+ 'align-items',
47
+ 'align-self',
48
+ 'align-content',
49
+ 'float',
50
+ 'w',
51
+ 'h',
52
+ 'mw',
53
+ 'mh',
54
+ 'vw',
55
+ 'vh',
56
+ 'min-vw',
57
+ 'min-vh',
58
+ 'text',
59
+ 'fw',
60
+ 'fst',
61
+ 'fs',
62
+ 'lh',
63
+ 'font-monospace',
64
+ 'link',
65
+ 'link-opacity',
66
+ 'link-underline',
67
+ 'link-offset',
68
+ 'bg',
69
+ 'border',
70
+ 'rounded',
71
+ 'shadow',
72
+ 'opacity',
73
+ 'object-fit',
74
+ 'overflow',
75
+ 'position',
76
+ 'top',
77
+ 'bottom',
78
+ 'start',
79
+ 'end',
80
+ 'translate-middle',
81
+ 'z',
82
+ 'sticky',
83
+ 'sticky-top',
84
+ 'sticky-bottom',
85
+ 'fixed-top',
86
+ 'fixed-bottom',
87
+ 'visible',
88
+ 'invisible',
89
+ 'visually-hidden',
90
+ 'visually-hidden-focusable',
91
+ 'user-select',
92
+ 'pe-none',
93
+ 'pe-auto',
94
+ 'vstack',
95
+ 'hstack',
96
+ 'vr',
97
+ 'clearfix',
98
+ 'focus-ring',
99
+ 'icon-link',
100
+ 'sr-only',
101
+ 'show',
102
+ 'fade',
103
+ 'active',
104
+ 'disabled',
105
+ 'open',
106
+ 'close',
107
+ 'btn-close',
108
+ 'dropdown-toggle',
109
+ 'dropdown-menu',
110
+ 'dropdown-item',
111
+ 'small',
112
+ 'lead',
113
+ 'display',
114
+ 'h1',
115
+ 'h2',
116
+ 'h3',
117
+ 'h4',
118
+ 'h5',
119
+ 'h6',
120
+ 'blockquote',
121
+ 'initialism',
122
+ 'list-unstyled',
123
+ 'list-inline',
124
+ 'list-inline-item',
125
+ 'figure',
126
+ 'img-fluid',
127
+ 'img-thumbnail',
128
+ 'text-bg',
129
+ 'sticky-lg-top',
130
+ 'sticky-md-top',
131
+ 'sticky-sm-top',
132
+ 'sticky-xl-top',
133
+ 'sticky-xxl-top',
134
+ 'ratio-1x1',
135
+ 'selected',
136
+ 'checked',
137
+ 'fa',
138
+ 'fas',
139
+ 'far',
140
+ 'fab',
141
+ 'fal',
142
+ 'fad',
143
+ 'fa-solid',
144
+ 'fa-regular',
145
+ 'fa-brands',
146
+ ];
147
+ const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
148
+ export const bootstrapClassPattern = new RegExp(
149
+ `^(?:${prefixes.map(escape).join('|')})(?:-[\\w.:%/-]+)?$|^fa-[\\w-]+$`,
150
+ );
151
+ // Spacing / gutter utilities have a closed value set: m-3, px-md-2, mt-n1, g-0, gap-2, gy-lg-4.
152
+ const spacingPattern =
153
+ /^(?:[mp][xytbse]?|g[xy]?|gap(?:-[xy])?)(?:-(?:sm|md|lg|xl|xxl))?-(?:auto|n?[0-5])$/;
154
+ export const isAllowedThemeClass = (token) =>
155
+ spacingPattern.test(token) || bootstrapClassPattern.test(token);