@luna_ui/luna 0.3.3 → 0.3.5
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/cli.mjs +1264 -27
- package/dist/css/index.d.ts +194 -0
- package/dist/css/index.js +721 -0
- package/dist/css/runtime.d.ts +92 -0
- package/dist/css/runtime.js +179 -0
- package/dist/index.js +1 -1
- package/dist/jsx-dev-runtime.js +1 -1
- package/dist/jsx-runtime.d.ts +5 -0
- package/dist/jsx-runtime.js +1 -1
- package/dist/src-CHiGeWfy.js +1 -0
- package/dist/vite-plugin.d.ts +122 -0
- package/dist/vite-plugin.js +1518 -0
- package/package.json +16 -2
- package/src/css/extract.ts +798 -0
- package/src/css/index.ts +10 -0
- package/src/css/inject.ts +205 -0
- package/src/css/inline.ts +182 -0
- package/src/css/minify.ts +70 -0
- package/src/css/optimizer.ts +6 -0
- package/src/css/runtime.ts +344 -0
- package/src/css-optimizer/README.md +353 -0
- package/src/css-optimizer/cooccurrence.ts +100 -0
- package/src/css-optimizer/core.ts +263 -0
- package/src/css-optimizer/extractors.ts +243 -0
- package/src/css-optimizer/hash.ts +54 -0
- package/src/css-optimizer/index.ts +129 -0
- package/src/css-optimizer/merge.ts +109 -0
- package/src/css-optimizer/moonbit-analyzer.ts +210 -0
- package/src/css-optimizer/parser.ts +120 -0
- package/src/css-optimizer/pattern.ts +171 -0
- package/src/css-optimizer/transformers.ts +301 -0
- package/src/css-optimizer/types.ts +128 -0
- package/src/event-utils.ts +227 -0
- package/src/index.ts +890 -0
- package/src/jsx-dev-runtime.ts +2 -0
- package/src/jsx-runtime.ts +398 -0
- package/src/vite-plugin.ts +718 -0
- package/tests/__screenshots__/context.test.ts/Context-API-context-with-reactive-effects-context-value-accessible-in-effect-1.png +0 -0
- package/tests/__screenshots__/dom.test.ts/DOM-API-For-component--SolidJS-style--For-updates-when-signal-changes-1.png +0 -0
- package/tests/__screenshots__/dom.test.ts/DOM-API-Show-component--SolidJS-style--Show-accepts-children-as-function-1.png +0 -0
- package/tests/__screenshots__/dom.test.ts/DOM-API-Show-component--SolidJS-style--Show-toggles-visibility-1.png +0 -0
- package/tests/__screenshots__/dom.test.ts/DOM-API-createElement-createElement-with-dynamic-attribute-1.png +0 -0
- package/tests/__screenshots__/dom.test.ts/DOM-API-createElement-createElement-with-dynamic-style-1.png +0 -0
- package/tests/__screenshots__/dom.test.ts/DOM-API-createElementNs--SVG-support--createElementNs-with-dynamic-attribute-1.png +0 -0
- package/tests/__screenshots__/dom.test.ts/DOM-API-effect-with-DOM-effect-tracks-signal-changes-1.png +0 -0
- package/tests/__screenshots__/dom.test.ts/DOM-API-forEach--list-rendering--forEach-handles-clear-to-empty-1.png +0 -0
- package/tests/__screenshots__/dom.test.ts/DOM-API-forEach--list-rendering--forEach-handles-empty-array-1.png +0 -0
- package/tests/__screenshots__/dom.test.ts/DOM-API-forEach--list-rendering--forEach-removes-items-1.png +0 -0
- package/tests/__screenshots__/dom.test.ts/DOM-API-forEach--list-rendering--forEach-renders-initial-list-1.png +0 -0
- package/tests/__screenshots__/dom.test.ts/DOM-API-forEach--list-rendering--forEach-updates-when-items-change-1.png +0 -0
- package/tests/__screenshots__/dom.test.ts/DOM-API-forEach-with-SVG-elements-forEach-handles-empty-to-non-empty-transition-in-SVG-1.png +0 -0
- package/tests/__screenshots__/dom.test.ts/DOM-API-forEach-with-SVG-elements-forEach-handles-reordering-in-SVG-1.png +0 -0
- package/tests/__screenshots__/dom.test.ts/DOM-API-forEach-with-SVG-elements-forEach-updates-SVG-elements-when-signal-changes-1.png +0 -0
- package/tests/__screenshots__/dom.test.ts/DOM-API-forEach-with-SVG-elements-forEach-with-nested-SVG-groups-1.png +0 -0
- package/tests/__screenshots__/dom.test.ts/DOM-API-ref-callback--JSX-style--ref-callback-with-nested-elements-1.png +0 -0
- package/tests/__screenshots__/dom.test.ts/DOM-API-show--conditional-rendering--show-creates-a-node-1.png +0 -0
- package/tests/__screenshots__/dom.test.ts/DOM-API-show--conditional-rendering--show-with-false-condition-creates-placeholder-1.png +0 -0
- package/tests/__screenshots__/dom.test.ts/DOM-API-text-nodes-textDyn-creates-reactive-text-node-1.png +0 -0
- package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-Complex-nested-scenario-forEach-renders-correctly-without-show--initial-items--1.png +0 -0
- package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-Complex-nested-scenario-forEach-with-context-renders-correctly-without-show-1.png +0 -0
- package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-Complex-nested-scenario-nested-components-with-context--forEach--and-show-1.png +0 -0
- package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-Complex-nested-scenario-show-and-forEach-inherit-context-from-Owner--fixed--1.png +0 -0
- package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-Complex-nested-scenario-show-and-forEach-work-together--context-uses-default--1.png +0 -0
- package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-Context---ForEach-integration-forEach-items-can-access-context-1.png +0 -0
- package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-ForEach-with-reactive-updates-forEach-renders-initial-list-1.png +0 -0
- package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-ForEach-with-reactive-updates-forEach-updates-when-signal-changes-1.png +0 -0
- package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-ForEach-with-reactive-updates-forEach-with-object-items-1.png +0 -0
- package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-Show--conditional-rendering--show-hides-when-condition-is-false-1.png +0 -0
- package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-Show--conditional-rendering--show-renders-when-condition-is-true-1.png +0 -0
- package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-Show--conditional-rendering--show-toggles-from-false-to-true-1.png +0 -0
- package/tests/__screenshots__/integration.test.ts/Integration--Nested-Components-with-Context-Show--conditional-rendering--show-toggles-reactively-1.png +0 -0
- package/tests/__screenshots__/lifecycle.test.ts/onCleanup-in-Component-Body--Solid-js-style--event-listener-pattern--Solid-js-docs-example--1.png +0 -0
- package/tests/__screenshots__/lifecycle.test.ts/onCleanup-in-Component-Body--Solid-js-style--multiple-cleanups-in-component-body--LIFO-order--1.png +0 -0
- package/tests/__screenshots__/lifecycle.test.ts/onCleanup-in-Component-Body--Solid-js-style--onCleanup-in-component-body-runs-on-unmount-1.png +0 -0
- package/tests/__screenshots__/lifecycle.test.ts/onCleanup-in-Component-Body--Solid-js-style--onCleanup-works-with-For-loop-items--component-body-style--1.png +0 -0
- package/tests/__screenshots__/lifecycle.test.ts/onCleanup-in-Component-Body--Solid-js-style--timer-cleanup-pattern--Solid-js-style--1.png +0 -0
- package/tests/__screenshots__/lifecycle.test.ts/onCleanup-in-Effects-effect-cleanup-runs-before-re-run-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Bulk-Updates-large-list-update-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Bulk-Updates-nested-batch-operations-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Bulk-Updates-rapid-sequential-updates-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/DOM-Rendering-Comparison---Conditional-Show-component---visible-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/DOM-Rendering-Comparison---Conditional-show-hide-element---visible-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/DOM-Rendering-Comparison---Fragments-fragment-with-list-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/DOM-Rendering-Comparison---Fragments-nested-fragments-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/DOM-Rendering-Comparison---Fragments-simple-fragment-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/DOM-Rendering-Comparison---Reactive-Updates-conditional-toggle-updates-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/DOM-Rendering-Comparison---Reactive-Updates-list-addition-updates-match-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/DOM-Rendering-Comparison---Reactive-Updates-list-removal-updates-match-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/DOM-Rendering-Comparison---Reactive-Updates-text-updates-match-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Dynamic-Attributes-Comparison-dynamic-className-updates-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Dynamic-Attributes-Comparison-dynamic-style-updates-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Dynamic-Attributes-Comparison-multiple-dynamic-attributes-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Edge-Cases-deeply-nested-conditionals-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Edge-Cases-list-transitions-from-empty-to-populated-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Edge-Cases-list-transitions-from-populated-to-empty-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Effect-Cleanup-Comparison-nested-effects-cleanup-order-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Effect-Cleanup-Comparison-nested-effects-with-inner-signal-change-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Effect-Cleanup-Comparison-onCleanup-is-called-when-effect-re-runs-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Effect-Cleanup-Comparison-onCleanup-with-resource-simulation-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Fragment-Comparison-with-Preact-Fragment-with-multiple-children--no-wrapper--1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Fragment-Comparison-with-Preact-Fragment-with-no-children-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Fragment-Comparison-with-Preact-fragment-with-list-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Fragment-Comparison-with-Preact-nested-Fragments-work-correctly-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/List-Reordering-complex-reordering-with-additions-and-removals-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/List-Reordering-insert-in-middle-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/List-Reordering-remove-from-middle-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/List-Reordering-reverse-list-order-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/List-Reordering-shuffle-list-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Luna-Conditional-Rendering-Show-component-renders-when-condition-is-true-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Luna-Conditional-Rendering-show-renders-content-when-initially-true-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Luna-Conditional-Rendering-show-toggles-visibility-dynamically-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Memo-Dependency-Chain-conditional-memo-dependencies-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Signal-Behavior-Comparison-basic-signal-get-set-produces-same-values-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Signal-Behavior-Comparison-batch-updates-produce-same-final-values-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Untrack-and-Peek-Behavior-peek-reads-value-without-tracking-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Untrack-and-Peek-Behavior-selective-tracking-with-untrack-1.png +0 -0
- package/tests/__screenshots__/preact-signals-comparison.test.ts/Untrack-and-Peek-Behavior-untrack-prevents-dependency-tracking-1.png +0 -0
- package/tests/__screenshots__/resource.test.ts/Resource-API--SolidJS-style--reactivity-accessor-is-reactive-1.png +0 -0
- package/tests/__screenshots__/resource.test.ts/Resource-API-AsyncState-helpers-stateError-returns-empty-string-for-non-failure-1.png +0 -0
- package/tests/__screenshots__/resource.test.ts/Resource-API-AsyncState-helpers-stateError-returns-undefined-for-non-failure-1.png +0 -0
- package/tests/__screenshots__/resource.test.ts/Resource-API-AsyncState-helpers-stateIsFailure-and-stateError-1.png +0 -0
- package/tests/__screenshots__/resource.test.ts/Resource-API-AsyncState-helpers-stateIsPending-1.png +0 -0
- package/tests/__screenshots__/resource.test.ts/Resource-API-AsyncState-helpers-stateIsSuccess-and-stateValue-1.png +0 -0
- package/tests/__screenshots__/resource.test.ts/Resource-API-AsyncState-helpers-stateValue-returns-undefined-for-non-success-1.png +0 -0
- package/tests/__screenshots__/resource.test.ts/Resource-API-createDeferred-reject-transitions-to-failure-1.png +0 -0
- package/tests/__screenshots__/resource.test.ts/Resource-API-createDeferred-resolve-transitions-to-success-1.png +0 -0
- package/tests/__screenshots__/resource.test.ts/Resource-API-createDeferred-returns-resource--resolve--and-reject-functions-1.png +0 -0
- package/tests/__screenshots__/resource.test.ts/Resource-API-createDeferred-starts-in-pending-state-1.png +0 -0
- package/tests/__screenshots__/resource.test.ts/Resource-API-createResource-async-resolve-works-1.png +0 -0
- package/tests/__screenshots__/resource.test.ts/Resource-API-createResource-starts-in-pending-state-1.png +0 -0
- package/tests/__screenshots__/resource.test.ts/Resource-API-createResource-transitions-to-failure-on-reject-1.png +0 -0
- package/tests/__screenshots__/resource.test.ts/Resource-API-createResource-transitions-to-success-on-resolve-1.png +0 -0
- package/tests/__screenshots__/resource.test.ts/Resource-API-integration-with-Promise-can-wrap-fetch-like-async-operations-1.png +0 -0
- package/tests/__screenshots__/resource.test.ts/Resource-API-integration-with-Promise-works-with-setTimeout-simulation-1.png +0 -0
- package/tests/__screenshots__/resource.test.ts/Resource-API-resourceGet-vs-resourcePeek-resourceGet-tracks-dependencies-1.png +0 -0
- package/tests/__screenshots__/resource.test.ts/Resource-API-resourceGet-vs-resourcePeek-resourcePeek-does-not-track-dependencies-1.png +0 -0
- package/tests/__screenshots__/resource.test.ts/Resource-API-resourceRefetch-refetch-resets-to-pending-and-re-runs-fetcher-1.png +0 -0
- package/tests/__screenshots__/solidjs-api.test.ts/Portal-component-Portal-renders-children-to-body-by-default-1.png +0 -0
- package/tests/__screenshots__/solidjs-api.test.ts/Portal-component-Portal-renders-to-selector-mount-target-1.png +0 -0
- package/tests/__screenshots__/solidjs-api.test.ts/SolidJS-API-compatibility-createEffect-tracks-dependencies-automatically-1.png +0 -0
- package/tests/__screenshots__/solidjs-api.test.ts/Switch-Match-component-Switch-with-accessor-condition-in-Match-1.png +0 -0
- package/tests/__screenshots__/solidjs-api.test.ts/Switch-Match-component-Switch-with-multiple-Match-components-1.png +0 -0
- package/tests/__screenshots__/solidjs-api.test.ts/Switch-Match-component-Switch-with-single-Match-and-fallback-1.png +0 -0
- package/tests/__screenshots__/solidjs-api.test.ts/Switch-Match-components-Switch-updates-DOM-when-signal-changes-1.png +0 -0
- package/tests/__screenshots__/solidjs-api.test.ts/on---utility-on-tracks-multiple-dependencies-1.png +0 -0
- package/tests/__screenshots__/solidjs-api.test.ts/on---utility-on-tracks-single-dependency-1.png +0 -0
- package/tests/__screenshots__/solidjs-api.test.ts/on---utility-on-with-defer-option-skips-initial-run-1.png +0 -0
- package/tests/__screenshots__/store.test.ts/createStore-Arrays-array-updates-work-1.png +0 -0
- package/tests/__screenshots__/store.test.ts/createStore-Reactivity-only-triggers-when-accessed-property-changes-1.png +0 -0
- package/tests/__screenshots__/store.test.ts/createStore-Reactivity-parent-path-change-notifies-child-accessors-1.png +0 -0
- package/tests/__screenshots__/store.test.ts/createStore-Reactivity-tracks-nested-property-access-1.png +0 -0
- package/tests/__screenshots__/store.test.ts/createStore-Reactivity-tracks-property-access-in-effects-1.png +0 -0
- package/tests/context.test.ts +118 -0
- package/tests/css-optimizer-extractors.test.ts +264 -0
- package/tests/css-optimizer-integration.test.ts +566 -0
- package/tests/css-optimizer-transformers.test.ts +301 -0
- package/tests/css-optimizer.test.ts +646 -0
- package/tests/css-runtime.bench.ts +442 -0
- package/tests/css-runtime.test.ts +342 -0
- package/tests/dom.test.ts +872 -0
- package/tests/integration.test.ts +405 -0
- package/tests/issue-5-for-infinite-loop.test.ts +516 -0
- package/tests/jsx-runtime.test.tsx +393 -0
- package/tests/lifecycle.test.ts +833 -0
- package/tests/move-before.bench.ts +304 -0
- package/tests/preact-signals-comparison.test.ts +1608 -0
- package/tests/resource.test.ts +160 -0
- package/tests/router.test.ts +117 -0
- package/tests/show-initial-mount-leak.test.tsx +182 -0
- package/tests/solidjs-api.test.ts +659 -0
- package/tests/static-perf.bench.ts +64 -0
- package/tests/store.test.ts +263 -0
- package/tests/tsx-syntax.test.tsx +404 -0
- package/dist/src-DGWY0NYx.js +0 -1
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { describe, test, expect, beforeEach, afterEach, vi } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
initCssRuntime,
|
|
4
|
+
css,
|
|
5
|
+
styles,
|
|
6
|
+
hover,
|
|
7
|
+
focus,
|
|
8
|
+
active,
|
|
9
|
+
on,
|
|
10
|
+
hasClass,
|
|
11
|
+
getGeneratedCss,
|
|
12
|
+
getGeneratedCount,
|
|
13
|
+
resetRuntime,
|
|
14
|
+
combine,
|
|
15
|
+
} from "../src/css/runtime";
|
|
16
|
+
|
|
17
|
+
describe("CSS Runtime - Missing CSS Detection", () => {
|
|
18
|
+
let warnSpy: ReturnType<typeof vi.spyOn>;
|
|
19
|
+
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
// Reset runtime state
|
|
22
|
+
resetRuntime();
|
|
23
|
+
// Spy on console.warn
|
|
24
|
+
warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
25
|
+
// Initialize runtime
|
|
26
|
+
initCssRuntime({ warnOnGenerate: true });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
warnSpy.mockRestore();
|
|
31
|
+
// Clean up any injected style elements
|
|
32
|
+
const styleEl = document.getElementById("luna-dev-css");
|
|
33
|
+
if (styleEl) {
|
|
34
|
+
styleEl.remove();
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe("css()", () => {
|
|
39
|
+
test("generates class name from property:value", () => {
|
|
40
|
+
const className = css("display", "flex");
|
|
41
|
+
expect(className).toMatch(/^_[a-z0-9]+$/);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("same declaration produces same class name", () => {
|
|
45
|
+
const cls1 = css("display", "flex");
|
|
46
|
+
const cls2 = css("display", "flex");
|
|
47
|
+
expect(cls1).toBe(cls2);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("different declarations produce different class names", () => {
|
|
51
|
+
const cls1 = css("display", "flex");
|
|
52
|
+
const cls2 = css("display", "block");
|
|
53
|
+
expect(cls1).not.toBe(cls2);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("warns when generating CSS at runtime", () => {
|
|
57
|
+
css("color", "red");
|
|
58
|
+
expect(warnSpy).toHaveBeenCalledWith(
|
|
59
|
+
expect.stringContaining("[luna-css] Generated at runtime:"),
|
|
60
|
+
expect.stringContaining("luna css extract")
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("only warns once per declaration", () => {
|
|
65
|
+
css("margin", "10px");
|
|
66
|
+
css("margin", "10px");
|
|
67
|
+
css("margin", "10px");
|
|
68
|
+
// Should only warn once for the same declaration
|
|
69
|
+
const marginWarnings = warnSpy.mock.calls.filter(
|
|
70
|
+
(call) => call[0].includes("margin:10px")
|
|
71
|
+
);
|
|
72
|
+
expect(marginWarnings.length).toBe(1);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe("styles()", () => {
|
|
77
|
+
test("generates multiple class names", () => {
|
|
78
|
+
const classNames = styles([
|
|
79
|
+
["display", "flex"],
|
|
80
|
+
["padding", "10px"],
|
|
81
|
+
]);
|
|
82
|
+
expect(classNames.split(" ").length).toBe(2);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("warns for each new declaration", () => {
|
|
86
|
+
styles([
|
|
87
|
+
["width", "100%"],
|
|
88
|
+
["height", "50px"],
|
|
89
|
+
]);
|
|
90
|
+
expect(warnSpy).toHaveBeenCalledTimes(2);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe("pseudo-classes", () => {
|
|
95
|
+
test("hover() generates pseudo-class CSS", () => {
|
|
96
|
+
const className = hover("background", "blue");
|
|
97
|
+
expect(className).toMatch(/^_[a-z0-9]+$/);
|
|
98
|
+
expect(warnSpy).toHaveBeenCalledWith(
|
|
99
|
+
expect.stringContaining(":hover"),
|
|
100
|
+
expect.any(String)
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("focus() generates pseudo-class CSS", () => {
|
|
105
|
+
const className = focus("outline", "none");
|
|
106
|
+
expect(className).toMatch(/^_[a-z0-9]+$/);
|
|
107
|
+
expect(warnSpy).toHaveBeenCalledWith(
|
|
108
|
+
expect.stringContaining(":focus"),
|
|
109
|
+
expect.any(String)
|
|
110
|
+
);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("active() generates pseudo-class CSS", () => {
|
|
114
|
+
const className = active("transform", "scale(0.95)");
|
|
115
|
+
expect(className).toMatch(/^_[a-z0-9]+$/);
|
|
116
|
+
expect(warnSpy).toHaveBeenCalledWith(
|
|
117
|
+
expect.stringContaining(":active"),
|
|
118
|
+
expect.any(String)
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("on() generates custom pseudo-class", () => {
|
|
123
|
+
const className = on(":visited", "color", "purple");
|
|
124
|
+
expect(className).toMatch(/^_[a-z0-9]+$/);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe("hasClass()", () => {
|
|
129
|
+
test("returns false for non-existent class", () => {
|
|
130
|
+
expect(hasClass("_nonexistent123")).toBe(false);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test("returns true for generated class", () => {
|
|
134
|
+
const className = css("font-size", "16px");
|
|
135
|
+
expect(hasClass(className)).toBe(true);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe("getGeneratedCss()", () => {
|
|
140
|
+
test("returns empty string initially", () => {
|
|
141
|
+
resetRuntime();
|
|
142
|
+
initCssRuntime({ warnOnGenerate: false });
|
|
143
|
+
expect(getGeneratedCss()).toBe("");
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("returns generated CSS rules", () => {
|
|
147
|
+
const className = css("border", "1px solid black");
|
|
148
|
+
const generatedCss = getGeneratedCss();
|
|
149
|
+
expect(generatedCss).toContain(className);
|
|
150
|
+
expect(generatedCss).toContain("border:1px solid black");
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
describe("getGeneratedCount()", () => {
|
|
155
|
+
test("returns 0 initially", () => {
|
|
156
|
+
resetRuntime();
|
|
157
|
+
initCssRuntime({ warnOnGenerate: false });
|
|
158
|
+
expect(getGeneratedCount()).toBe(0);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test("increments with each new declaration", () => {
|
|
162
|
+
resetRuntime();
|
|
163
|
+
initCssRuntime({ warnOnGenerate: false });
|
|
164
|
+
|
|
165
|
+
css("opacity", "0.5");
|
|
166
|
+
expect(getGeneratedCount()).toBe(1);
|
|
167
|
+
|
|
168
|
+
css("visibility", "hidden");
|
|
169
|
+
expect(getGeneratedCount()).toBe(2);
|
|
170
|
+
|
|
171
|
+
// Same declaration doesn't increment
|
|
172
|
+
css("opacity", "0.5");
|
|
173
|
+
expect(getGeneratedCount()).toBe(2);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
describe("combine()", () => {
|
|
178
|
+
test("joins class names with space", () => {
|
|
179
|
+
const result = combine(["_abc", "_def", "_ghi"]);
|
|
180
|
+
expect(result).toBe("_abc _def _ghi");
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test("filters out falsy values", () => {
|
|
184
|
+
const result = combine(["_abc", "", "_def", undefined as any, "_ghi"]);
|
|
185
|
+
expect(result).toBe("_abc _def _ghi");
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
describe("DOM injection", () => {
|
|
190
|
+
test("injects style element into head", () => {
|
|
191
|
+
css("z-index", "100");
|
|
192
|
+
const styleEl = document.getElementById("luna-dev-css");
|
|
193
|
+
expect(styleEl).not.toBeNull();
|
|
194
|
+
expect(styleEl?.tagName).toBe("STYLE");
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test("style element contains generated CSS", () => {
|
|
198
|
+
const className = css("position", "absolute");
|
|
199
|
+
const styleEl = document.getElementById("luna-dev-css");
|
|
200
|
+
expect(styleEl?.textContent).toContain(className);
|
|
201
|
+
expect(styleEl?.textContent).toContain("position:absolute");
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test("multiple rules are appended to same style element", () => {
|
|
205
|
+
css("top", "0");
|
|
206
|
+
css("left", "0");
|
|
207
|
+
css("right", "0");
|
|
208
|
+
|
|
209
|
+
const styleEl = document.getElementById("luna-dev-css");
|
|
210
|
+
expect(styleEl?.textContent).toContain("top:0");
|
|
211
|
+
expect(styleEl?.textContent).toContain("left:0");
|
|
212
|
+
expect(styleEl?.textContent).toContain("right:0");
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
describe("warnOnGenerate option", () => {
|
|
217
|
+
test("no warnings when warnOnGenerate is false", () => {
|
|
218
|
+
resetRuntime();
|
|
219
|
+
const quietWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
220
|
+
|
|
221
|
+
initCssRuntime({ warnOnGenerate: false });
|
|
222
|
+
css("cursor", "pointer");
|
|
223
|
+
|
|
224
|
+
expect(quietWarnSpy).not.toHaveBeenCalled();
|
|
225
|
+
quietWarnSpy.mockRestore();
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
describe("CSS Runtime - Pre-extracted CSS Integration", () => {
|
|
231
|
+
let warnSpy: ReturnType<typeof vi.spyOn>;
|
|
232
|
+
let preExtractedStyle: HTMLStyleElement;
|
|
233
|
+
|
|
234
|
+
beforeEach(() => {
|
|
235
|
+
resetRuntime();
|
|
236
|
+
warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
237
|
+
|
|
238
|
+
// Simulate pre-extracted CSS (like virtual:luna.css)
|
|
239
|
+
preExtractedStyle = document.createElement("style");
|
|
240
|
+
preExtractedStyle.id = "pre-extracted-css";
|
|
241
|
+
preExtractedStyle.textContent = `
|
|
242
|
+
._swuc{display:flex}
|
|
243
|
+
._3m33u{align-items:center}
|
|
244
|
+
._5qn6e{justify-content:center}
|
|
245
|
+
`;
|
|
246
|
+
document.head.appendChild(preExtractedStyle);
|
|
247
|
+
|
|
248
|
+
initCssRuntime({ warnOnGenerate: true });
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
afterEach(() => {
|
|
252
|
+
warnSpy.mockRestore();
|
|
253
|
+
preExtractedStyle.remove();
|
|
254
|
+
const devStyle = document.getElementById("luna-dev-css");
|
|
255
|
+
if (devStyle) devStyle.remove();
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test("hasClass returns true for pre-extracted classes", () => {
|
|
259
|
+
expect(hasClass("_swuc")).toBe(true);
|
|
260
|
+
expect(hasClass("_3m33u")).toBe(true);
|
|
261
|
+
expect(hasClass("_5qn6e")).toBe(true);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test("hasClass returns false for missing classes", () => {
|
|
265
|
+
expect(hasClass("_missing123")).toBe(false);
|
|
266
|
+
expect(hasClass("_notextracted")).toBe(false);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
test("no warning when class already exists in stylesheet", () => {
|
|
270
|
+
// This simulates using a class that was pre-extracted
|
|
271
|
+
// The runtime should detect it exists and not regenerate/warn
|
|
272
|
+
// Note: css() will still generate the class name, but if it exists,
|
|
273
|
+
// it won't inject or warn
|
|
274
|
+
|
|
275
|
+
// First, verify the class exists
|
|
276
|
+
expect(hasClass("_swuc")).toBe(true);
|
|
277
|
+
|
|
278
|
+
// Calling css() with same declaration won't warn if already present
|
|
279
|
+
// But our implementation always checks after hash, so we need to test differently
|
|
280
|
+
|
|
281
|
+
// The key test: missing CSS triggers warning
|
|
282
|
+
css("background", "red"); // Not in pre-extracted
|
|
283
|
+
expect(warnSpy).toHaveBeenCalled();
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test("detects missing CSS and generates fallback", () => {
|
|
287
|
+
// Use a declaration that's definitely not pre-extracted
|
|
288
|
+
const className = css("border-radius", "999px");
|
|
289
|
+
|
|
290
|
+
// Should have warned
|
|
291
|
+
expect(warnSpy).toHaveBeenCalledWith(
|
|
292
|
+
expect.stringContaining("[luna-css]"),
|
|
293
|
+
expect.any(String)
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
// Should have injected the CSS
|
|
297
|
+
const devStyle = document.getElementById("luna-dev-css");
|
|
298
|
+
expect(devStyle?.textContent).toContain(className);
|
|
299
|
+
expect(devStyle?.textContent).toContain("border-radius:999px");
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
test("element styling works after runtime generation", () => {
|
|
303
|
+
const className = css("background-color", "#ff0000");
|
|
304
|
+
|
|
305
|
+
const div = document.createElement("div");
|
|
306
|
+
div.className = className;
|
|
307
|
+
document.body.appendChild(div);
|
|
308
|
+
|
|
309
|
+
// After runtime CSS injection, the element should have the style
|
|
310
|
+
const computed = getComputedStyle(div);
|
|
311
|
+
expect(computed.backgroundColor).toBe("rgb(255, 0, 0)");
|
|
312
|
+
|
|
313
|
+
div.remove();
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
describe("CSS Runtime - Class Name Determinism", () => {
|
|
318
|
+
beforeEach(() => {
|
|
319
|
+
resetRuntime();
|
|
320
|
+
initCssRuntime({ warnOnGenerate: false });
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
test("class names are deterministic (DJB2 hash)", () => {
|
|
324
|
+
// These should produce the same class name every time
|
|
325
|
+
const cls1 = css("display", "flex");
|
|
326
|
+
resetRuntime();
|
|
327
|
+
initCssRuntime({ warnOnGenerate: false });
|
|
328
|
+
const cls2 = css("display", "flex");
|
|
329
|
+
|
|
330
|
+
expect(cls1).toBe(cls2);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
test("known hash values for verification", () => {
|
|
334
|
+
// display:flex should produce a specific class name
|
|
335
|
+
// This verifies the hash function matches MoonBit implementation
|
|
336
|
+
const flexClass = css("display", "flex");
|
|
337
|
+
// The class should start with _ and be alphanumeric
|
|
338
|
+
expect(flexClass).toMatch(/^_[a-z0-9]+$/);
|
|
339
|
+
// Should be reasonably short (base36 encoded 24-bit hash)
|
|
340
|
+
expect(flexClass.length).toBeLessThanOrEqual(7);
|
|
341
|
+
});
|
|
342
|
+
});
|