rw-elements-tools 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +1333 -0
- package/bin/cli.js +213 -0
- package/build-properties.js +654 -0
- package/build-shared-hooks.js +253 -0
- package/config.js +148 -0
- package/controls/Animations/AnimationEffects.js +111 -0
- package/controls/Animations/AnimationSettings.js +437 -0
- package/controls/Animations/Reveals.js +168 -0
- package/controls/Animations/ScrollAnimation_Opacity.js +15 -0
- package/controls/Animations/ScrollAnimation_Rotate.js +17 -0
- package/controls/Animations/ScrollAnimation_Scale.js +18 -0
- package/controls/Animations/ScrollAnimation_Translate.js +31 -0
- package/controls/Background/Background.js +66 -0
- package/controls/Background/BackgroundButton.js +69 -0
- package/controls/Background/BackgroundColor.js +28 -0
- package/controls/Background/BackgroundContainer.js +73 -0
- package/controls/Background/BackgroundGradient.js +149 -0
- package/controls/Background/BackgroundImage.js +108 -0
- package/controls/Background/BackgroundOnlyColor.js +53 -0
- package/controls/Background/BackgroundTransparent.js +66 -0
- package/controls/Background/BackgroundVideo.js +9 -0
- package/controls/Background/Color.js +52 -0
- package/controls/Background/Gradient.js +263 -0
- package/controls/Background/GradientContainer.js +263 -0
- package/controls/Background/Image.js +269 -0
- package/controls/Background/Image_CMS.js +305 -0
- package/controls/Background/SVG.js +235 -0
- package/controls/Background/Video.js +29 -0
- package/controls/Borders/Border.js +114 -0
- package/controls/Borders/BorderColor.js +25 -0
- package/controls/Borders/BorderRadius.js +19 -0
- package/controls/Borders/BorderStyle.js +26 -0
- package/controls/Borders/BorderWidth.js +20 -0
- package/controls/Borders/Borders.js +69 -0
- package/controls/Borders/BordersContainer.js +90 -0
- package/controls/Borders/BordersInput.js +107 -0
- package/controls/Borders/Outline.js +100 -0
- package/controls/Borders/OutlineColor.js +25 -0
- package/controls/Borders/OutlineOffset.js +13 -0
- package/controls/Borders/OutlineStyle.js +26 -0
- package/controls/Borders/OutlineWidth.js +13 -0
- package/controls/Effects/BackdropBlur.js +11 -0
- package/controls/Effects/Blur.js +11 -0
- package/controls/Effects/BoxShadow.js +15 -0
- package/controls/Effects/Brightness.js +11 -0
- package/controls/Effects/DropShadow.js +14 -0
- package/controls/Effects/Effects.js +71 -0
- package/controls/Effects/Filters.js +114 -0
- package/controls/Effects/Opacity.js +14 -0
- package/controls/Effects/Saturate.js +11 -0
- package/controls/Layout/AspectRatio.js +53 -0
- package/controls/Layout/Container.js +24 -0
- package/controls/Layout/Hidden.js +9 -0
- package/controls/Layout/Inset.js +15 -0
- package/controls/Layout/Isolation.js +25 -0
- package/controls/Layout/Layout.js +38 -0
- package/controls/Layout/Overflow.js +33 -0
- package/controls/Layout/Position.js +37 -0
- package/controls/Layout/TopRightBottomLeft.js +90 -0
- package/controls/Layout/Visibility.js +25 -0
- package/controls/Layout/ZIndex.js +36 -0
- package/controls/Overlay/Color.js +52 -0
- package/controls/Overlay/Gradient.js +298 -0
- package/controls/Overlay/Image.js +226 -0
- package/controls/Overlay/Overlay.js +66 -0
- package/controls/Sizing/Height.js +18 -0
- package/controls/Sizing/MaxHeight.js +17 -0
- package/controls/Sizing/MaxWidth.js +17 -0
- package/controls/Sizing/MinHeight.js +18 -0
- package/controls/Sizing/MinWidth.js +18 -0
- package/controls/Sizing/Sizing.js +66 -0
- package/controls/Sizing/SizingContainer.js +122 -0
- package/controls/Sizing/SizingImage.js +75 -0
- package/controls/Sizing/SizingInput.js +71 -0
- package/controls/Sizing/SizingSVG.js +74 -0
- package/controls/Sizing/Width.js +18 -0
- package/controls/Spacing/Margin.js +17 -0
- package/controls/Spacing/Padding.js +17 -0
- package/controls/Spacing/Spacing.js +23 -0
- package/controls/Spacing/SpacingButton.js +42 -0
- package/controls/Spacing/SpacingContainer.js +32 -0
- package/controls/Spacing/SpacingInput.js +42 -0
- package/controls/Transforms/Rotate.js +13 -0
- package/controls/Transforms/Scale.js +13 -0
- package/controls/Transforms/Skew.js +25 -0
- package/controls/Transforms/TransformOrigin.js +12 -0
- package/controls/Transforms/Transforms.js +98 -0
- package/controls/Transforms/Translate.js +26 -0
- package/controls/Transitions/Delay.js +13 -0
- package/controls/Transitions/Duration.js +13 -0
- package/controls/Transitions/Property.js +42 -0
- package/controls/Transitions/TimingFunction.js +44 -0
- package/controls/Transitions/Transitions.js +20 -0
- package/controls/alignment/AlignContent.js +48 -0
- package/controls/alignment/AlignItems.js +64 -0
- package/controls/alignment/AlignSelf.js +34 -0
- package/controls/alignment/JustifyContent.js +44 -0
- package/controls/alignment/JustifyItems.js +32 -0
- package/controls/alignment/JustifySelf.js +34 -0
- package/controls/core/CSSClasses.js +11 -0
- package/controls/core/ControlType.js +25 -0
- package/controls/core/HTMLTag.js +80 -0
- package/controls/core/HoverGroup.js +38 -0
- package/controls/core/ID.js +12 -0
- package/controls/core/Image.js +95 -0
- package/controls/core/MenuItem.js +187 -0
- package/controls/core/ObjectFit.js +32 -0
- package/controls/core/ObjectPosition.js +65 -0
- package/controls/grid-flex/ActAsGridOrFlexItem.js +54 -0
- package/controls/grid-flex/ColEnd.js +28 -0
- package/controls/grid-flex/ColStart.js +27 -0
- package/controls/grid-flex/Columns.js +38 -0
- package/controls/grid-flex/FlexDirection.js +27 -0
- package/controls/grid-flex/FlexItem.js +106 -0
- package/controls/grid-flex/GridItem.js +41 -0
- package/controls/grid-flex/Order.js +45 -0
- package/controls/grid-flex/RowEnd.js +28 -0
- package/controls/grid-flex/RowStart.js +27 -0
- package/controls/grid-flex/Rows.js +38 -0
- package/controls/index.js +187 -0
- package/controls/interactive/ButtonFontAndTextStyles.js +208 -0
- package/controls/interactive/Filter.js +54 -0
- package/controls/interactive/InputFontAndTextStyles.js +156 -0
- package/controls/interactive/Link.js +13 -0
- package/controls/typography/HeadingColor.js +112 -0
- package/controls/typography/TextColor.js +51 -0
- package/controls/typography/TextDecoration.js +99 -0
- package/controls/typography/TextFontsAndTextStyles.js +243 -0
- package/controls/typography/TextSimple.js +55 -0
- package/controls/typography/TextStyles.js +55 -0
- package/controls/typography/Typography.js +13 -0
- package/index.js +19 -0
- package/package.json +55 -0
- package/properties/BackgroundType.js +18 -0
- package/properties/ButtonSize.js +19 -0
- package/properties/ContainerHeights.js +23 -0
- package/properties/ContainerWidths.js +27 -0
- package/properties/FontWeight.js +16 -0
- package/properties/GradientDirection.js +39 -0
- package/properties/LetterSpacing.js +13 -0
- package/properties/LineHeight.js +13 -0
- package/properties/RevealAnimations.js +12 -0
- package/properties/Slider.js +10 -0
- package/properties/TextAlign.js +23 -0
- package/properties/TransformOrigins.js +43 -0
- package/properties/TransitionNames.js +20 -0
- package/properties/index.js +13 -0
- package/shared-hooks/animations/globalAnimations.js +141 -0
- package/shared-hooks/animations/globalReveal.js +48 -0
- package/shared-hooks/background/globalBackground.js +306 -0
- package/shared-hooks/background/globalBgImageFetchPriority.js +34 -0
- package/shared-hooks/borders/globalBorders.js +85 -0
- package/shared-hooks/borders/globalOutline.js +39 -0
- package/shared-hooks/core/addPrefixToTailwindClasses.js +24 -0
- package/shared-hooks/core/advancedClasses.js +5 -0
- package/shared-hooks/core/classnames.js +92 -0
- package/shared-hooks/core/getHoverPrefix.js +21 -0
- package/shared-hooks/core/globalHTMLTag.js +17 -0
- package/shared-hooks/core/injectPrefixOnDarkModeColors.js +6 -0
- package/shared-hooks/effects/globalEffects.js +45 -0
- package/shared-hooks/effects/globalFilters.js +80 -0
- package/shared-hooks/effects/globalOverlay.js +166 -0
- package/shared-hooks/interactive/globalFilter.js +24 -0
- package/shared-hooks/interactive/globalLink.js +23 -0
- package/shared-hooks/layout/globalActAsGridOrFlexItem.js +66 -0
- package/shared-hooks/layout/globalLayout.js +50 -0
- package/shared-hooks/navigation/globalMenuItem.js +35 -0
- package/shared-hooks/navigation/globalNavItems.js +60 -0
- package/shared-hooks/navigation/globalNavTitle.js +23 -0
- package/shared-hooks/sizing/aspectRatioClasses.js +20 -0
- package/shared-hooks/sizing/globalSizing.js +19 -0
- package/shared-hooks/sizing/globalSizingContainer.js +40 -0
- package/shared-hooks/sizing/objectClasses.js +9 -0
- package/shared-hooks/spacing/globalSpacing.js +13 -0
- package/shared-hooks/spacing/globalSpacingMargin.js +11 -0
- package/shared-hooks/spacing/globalSpacingPadding.js +11 -0
- package/shared-hooks/transforms/globalTransforms.js +78 -0
- package/shared-hooks/transitions/getAlpineTransitionAttributesDesktop.js +111 -0
- package/shared-hooks/transitions/getAlpineTransitionAttributesMobile.js +110 -0
- package/shared-hooks/transitions/globalTransitions.js +48 -0
- package/shared-hooks/typography/globalButtonFontAndTextStyles.js +65 -0
- package/shared-hooks/typography/globalHeadingColor.js +69 -0
- package/shared-hooks/typography/globalInputFontAndTextStyles.js +40 -0
- package/shared-hooks/typography/globalTextFontsAndTextStyles.js +47 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Shared Hooks Builder (with dead code elimination)
|
|
4
|
+
*
|
|
5
|
+
* - Reads shared hooks from shared-hooks/ and subfolders (alphabetical)
|
|
6
|
+
* - For each component hooks.source.js in packs/, concatenates shared + component
|
|
7
|
+
* - Uses esbuild DCE to remove unused code (anything not reachable from transformHook)
|
|
8
|
+
* - Output: plain static JS with const/let preserved
|
|
9
|
+
* - If a component has no hooks.source.js, it is skipped
|
|
10
|
+
* - Supports --watch to regenerate on changes
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import fs from 'fs';
|
|
14
|
+
import path from 'path';
|
|
15
|
+
import { fileURLToPath } from 'url';
|
|
16
|
+
import { transform } from 'esbuild';
|
|
17
|
+
|
|
18
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
19
|
+
const __dirname = path.dirname(__filename);
|
|
20
|
+
|
|
21
|
+
// Constants
|
|
22
|
+
const SOURCE_FILENAME = 'hooks.source.js';
|
|
23
|
+
const OUTPUT_FILENAME = 'hooks.js';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Gets the shared hooks directory (always in the package)
|
|
27
|
+
*/
|
|
28
|
+
function getSharedDir() {
|
|
29
|
+
return path.join(__dirname, 'shared-hooks');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Recursively lists all shared hook files in shared-hooks/ and subfolders
|
|
34
|
+
* @returns {Promise<string[]>} Array of absolute paths to shared hook files (sorted alphabetically)
|
|
35
|
+
*/
|
|
36
|
+
async function listSharedFiles() {
|
|
37
|
+
const sharedDir = getSharedDir();
|
|
38
|
+
const results = [];
|
|
39
|
+
|
|
40
|
+
async function walk(dir) {
|
|
41
|
+
let entries;
|
|
42
|
+
try {
|
|
43
|
+
entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
44
|
+
} catch (err) {
|
|
45
|
+
if (dir === sharedDir) {
|
|
46
|
+
console.error(`[hooks] Failed to read shared dir: ${err.message}`);
|
|
47
|
+
}
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
for (const entry of entries) {
|
|
52
|
+
const fullPath = path.join(dir, entry.name);
|
|
53
|
+
if (entry.isDirectory()) {
|
|
54
|
+
if (entry.name.startsWith('.')) continue;
|
|
55
|
+
await walk(fullPath);
|
|
56
|
+
} else if (entry.isFile() && entry.name.endsWith('.js')) {
|
|
57
|
+
results.push(fullPath);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
await walk(sharedDir);
|
|
63
|
+
return results.sort();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Recursively finds all hooks.source.js files in a directory
|
|
68
|
+
* @param {string} startDir - Directory to search
|
|
69
|
+
* @returns {Promise<string[]>} Array of absolute paths to source files
|
|
70
|
+
*/
|
|
71
|
+
async function findHookSources(startDir) {
|
|
72
|
+
const results = [];
|
|
73
|
+
|
|
74
|
+
async function walk(dir) {
|
|
75
|
+
let entries;
|
|
76
|
+
try {
|
|
77
|
+
entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
78
|
+
} catch {
|
|
79
|
+
return; // Directory doesn't exist or can't be read
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
for (const entry of entries) {
|
|
83
|
+
const fullPath = path.join(dir, entry.name);
|
|
84
|
+
if (entry.isDirectory()) {
|
|
85
|
+
if (entry.name === 'node_modules' || entry.name.startsWith('.')) continue;
|
|
86
|
+
await walk(fullPath);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (entry.isFile() && entry.name === SOURCE_FILENAME) {
|
|
90
|
+
results.push(fullPath);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
await walk(startDir);
|
|
96
|
+
return results;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Builds a single hooks.js file from shared hooks + component source
|
|
101
|
+
* @param {string[]} sharedFiles - Array of shared hook file paths
|
|
102
|
+
* @param {string} sourcePath - Path to the hooks.source.js file
|
|
103
|
+
* @param {string} projectRoot - Project root for relative path display
|
|
104
|
+
*/
|
|
105
|
+
async function buildOne(sharedFiles, sourcePath, projectRoot) {
|
|
106
|
+
const componentDir = path.dirname(sourcePath);
|
|
107
|
+
const outputPath = path.join(componentDir, OUTPUT_FILENAME);
|
|
108
|
+
|
|
109
|
+
// Read all shared hook files
|
|
110
|
+
const sharedPieces = [];
|
|
111
|
+
for (const file of sharedFiles) {
|
|
112
|
+
const content = await fs.promises.readFile(file, 'utf8');
|
|
113
|
+
sharedPieces.push(content.trim());
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Read the component source
|
|
117
|
+
let componentContent = await fs.promises.readFile(sourcePath, 'utf8');
|
|
118
|
+
|
|
119
|
+
// Remove any existing exports.transformHook line (we'll add our own export marker)
|
|
120
|
+
componentContent = componentContent.replace(/^\s*exports\.transformHook\s*=.*$/gm, '').trim();
|
|
121
|
+
|
|
122
|
+
// Concatenate everything and add an ESM export marker for DCE
|
|
123
|
+
// esbuild will keep transformHook and anything it references, drop the rest
|
|
124
|
+
const combinedSource = `
|
|
125
|
+
${sharedPieces.join('\n\n')}
|
|
126
|
+
|
|
127
|
+
${componentContent}
|
|
128
|
+
|
|
129
|
+
export { transformHook };
|
|
130
|
+
`;
|
|
131
|
+
|
|
132
|
+
// Use esbuild transform with DCE
|
|
133
|
+
// minifySyntax: true enables dead code elimination
|
|
134
|
+
// We keep identifiers and whitespace for readable output
|
|
135
|
+
const result = await transform(combinedSource, {
|
|
136
|
+
loader: 'js',
|
|
137
|
+
target: 'es2018',
|
|
138
|
+
minifySyntax: true, // Enables DCE
|
|
139
|
+
minifyWhitespace: false, // Keep formatting readable
|
|
140
|
+
minifyIdentifiers: false, // Keep variable names
|
|
141
|
+
format: 'esm',
|
|
142
|
+
legalComments: 'none',
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
let code = result.code;
|
|
146
|
+
|
|
147
|
+
// Replace ESM export with CommonJS-style assignment
|
|
148
|
+
code = code.replace(/export\s*\{\s*transformHook\s*(as\s+\w+)?\s*\}\s*;?\s*$/m, 'exports.transformHook = transformHook;');
|
|
149
|
+
|
|
150
|
+
const banner = `// AUTO-GENERATED: do not edit. Edit hooks.source.js instead.\n`;
|
|
151
|
+
|
|
152
|
+
await fs.promises.writeFile(outputPath, banner + code, 'utf8');
|
|
153
|
+
|
|
154
|
+
console.log(`[hooks] Wrote ${path.relative(projectRoot, outputPath)}`);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Builds all hooks.js files
|
|
159
|
+
* @param {Object} config - Configuration object
|
|
160
|
+
* @param {string} config.packsDir - Absolute path to the packs directory
|
|
161
|
+
* @param {string} [config.projectRoot] - Project root for display purposes
|
|
162
|
+
*/
|
|
163
|
+
export async function buildAll(config) {
|
|
164
|
+
const packsDir = config.packsDir;
|
|
165
|
+
const projectRoot = config.projectRoot || path.dirname(packsDir);
|
|
166
|
+
|
|
167
|
+
const sharedFiles = await listSharedFiles();
|
|
168
|
+
const sources = await findHookSources(packsDir);
|
|
169
|
+
|
|
170
|
+
console.log(`[hooks] Building ${sources.length} component hook(s); shared files: ${sharedFiles.length}`);
|
|
171
|
+
|
|
172
|
+
for (const sourcePath of sources) {
|
|
173
|
+
await buildOne(sharedFiles, sourcePath, projectRoot);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
console.log(`[hooks] Build complete`);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Starts watch mode for continuous building
|
|
181
|
+
* @param {Object} config - Configuration object
|
|
182
|
+
* @param {string} config.packsDir - Absolute path to the packs directory
|
|
183
|
+
* @param {string} [config.projectRoot] - Project root for display purposes
|
|
184
|
+
*/
|
|
185
|
+
export async function startWatch(config) {
|
|
186
|
+
const packsDir = config.packsDir;
|
|
187
|
+
const sharedDir = getSharedDir();
|
|
188
|
+
|
|
189
|
+
console.log('[hooks] Watch mode enabled. Listening for changes...');
|
|
190
|
+
|
|
191
|
+
let building = false;
|
|
192
|
+
const rebuild = async () => {
|
|
193
|
+
if (building) return;
|
|
194
|
+
building = true;
|
|
195
|
+
try {
|
|
196
|
+
await buildAll(config);
|
|
197
|
+
} catch (err) {
|
|
198
|
+
console.error('[hooks] Build error:', err.message || err);
|
|
199
|
+
} finally {
|
|
200
|
+
building = false;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
// Watch both the shared hooks directory and the packs directory
|
|
205
|
+
const watchDirs = [sharedDir, packsDir];
|
|
206
|
+
|
|
207
|
+
for (const watchDir of watchDirs) {
|
|
208
|
+
try {
|
|
209
|
+
const watcher = fs.watch(watchDir, { recursive: true }, (eventType, filename) => {
|
|
210
|
+
if (!filename) return;
|
|
211
|
+
const lower = filename.toLowerCase();
|
|
212
|
+
if (lower.endsWith('hooks.source.js') || lower.endsWith('.js')) {
|
|
213
|
+
// Only rebuild for hooks.source.js changes in packs or any .js in shared-hooks
|
|
214
|
+
if (watchDir === sharedDir || lower.endsWith('hooks.source.js')) {
|
|
215
|
+
console.log(`[hooks] Change detected: ${filename} (${eventType})`);
|
|
216
|
+
rebuild();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
watcher.on('error', (err) => {
|
|
222
|
+
console.error('[hooks] Watcher error:', err);
|
|
223
|
+
});
|
|
224
|
+
} catch (err) {
|
|
225
|
+
console.warn(`[hooks] Could not watch ${watchDir}: ${err.message}`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
await rebuild();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Allow direct execution for backwards compatibility
|
|
233
|
+
if (process.argv[1] === __filename) {
|
|
234
|
+
const WATCH = process.argv.includes('--watch') || process.argv.includes('-w');
|
|
235
|
+
const defaultPacksDir = path.resolve(__dirname, '..', 'packs');
|
|
236
|
+
const config = {
|
|
237
|
+
packsDir: defaultPacksDir,
|
|
238
|
+
projectRoot: path.resolve(__dirname, '..')
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
(async () => {
|
|
242
|
+
try {
|
|
243
|
+
if (WATCH) {
|
|
244
|
+
await startWatch(config);
|
|
245
|
+
} else {
|
|
246
|
+
await buildAll(config);
|
|
247
|
+
}
|
|
248
|
+
} catch (err) {
|
|
249
|
+
console.error('[hooks] Build failed:', err.message || err);
|
|
250
|
+
process.exit(1);
|
|
251
|
+
}
|
|
252
|
+
})();
|
|
253
|
+
}
|
package/config.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Resolver for rw-elements-tools
|
|
3
|
+
*
|
|
4
|
+
* Resolves configuration from multiple sources with the following priority:
|
|
5
|
+
* 1. CLI arguments (highest priority)
|
|
6
|
+
* 2. Environment variables
|
|
7
|
+
* 3. package.json "rw-elements-tools" field
|
|
8
|
+
* 4. rw-elements-tools.config.js file
|
|
9
|
+
* 5. Default values (lowest priority)
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import fs from 'fs';
|
|
13
|
+
import path from 'path';
|
|
14
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
15
|
+
|
|
16
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
17
|
+
const __dirname = path.dirname(__filename);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Default configuration values
|
|
21
|
+
*/
|
|
22
|
+
const DEFAULTS = {
|
|
23
|
+
packsDir: './packs',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Finds the project root by looking for package.json
|
|
28
|
+
* @returns {string} The project root directory
|
|
29
|
+
*/
|
|
30
|
+
function findProjectRoot() {
|
|
31
|
+
let currentDir = process.cwd();
|
|
32
|
+
|
|
33
|
+
while (currentDir !== path.dirname(currentDir)) {
|
|
34
|
+
if (fs.existsSync(path.join(currentDir, 'package.json'))) {
|
|
35
|
+
return currentDir;
|
|
36
|
+
}
|
|
37
|
+
currentDir = path.dirname(currentDir);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Fallback to cwd if no package.json found
|
|
41
|
+
return process.cwd();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Reads the package.json from the project root
|
|
46
|
+
* @param {string} projectRoot - The project root directory
|
|
47
|
+
* @returns {object|null} The package.json contents or null
|
|
48
|
+
*/
|
|
49
|
+
function readPackageJson(projectRoot) {
|
|
50
|
+
const packageJsonPath = path.join(projectRoot, 'package.json');
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
const content = fs.readFileSync(packageJsonPath, 'utf8');
|
|
54
|
+
return JSON.parse(content);
|
|
55
|
+
} catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Loads the rw-elements-tools.config.js file if it exists
|
|
62
|
+
* @param {string} projectRoot - The project root directory
|
|
63
|
+
* @returns {Promise<object|null>} The config file contents or null
|
|
64
|
+
*/
|
|
65
|
+
async function loadConfigFile(projectRoot) {
|
|
66
|
+
const configPaths = [
|
|
67
|
+
path.join(projectRoot, 'rw-elements-tools.config.js'),
|
|
68
|
+
path.join(projectRoot, 'rw-elements-tools.config.mjs'),
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
for (const configPath of configPaths) {
|
|
72
|
+
if (fs.existsSync(configPath)) {
|
|
73
|
+
try {
|
|
74
|
+
const configUrl = pathToFileURL(configPath).href;
|
|
75
|
+
const configModule = await import(configUrl);
|
|
76
|
+
return configModule.default || configModule;
|
|
77
|
+
} catch (err) {
|
|
78
|
+
console.warn(`[rw-elements-tools] Warning: Failed to load config file ${configPath}: ${err.message}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Resolves the full configuration from all sources
|
|
88
|
+
* @param {object} cliOptions - Options passed via CLI arguments
|
|
89
|
+
* @returns {Promise<object>} The resolved configuration
|
|
90
|
+
*/
|
|
91
|
+
export async function resolveConfig(cliOptions = {}) {
|
|
92
|
+
const projectRoot = findProjectRoot();
|
|
93
|
+
const packageJson = readPackageJson(projectRoot);
|
|
94
|
+
const configFile = await loadConfigFile(projectRoot);
|
|
95
|
+
|
|
96
|
+
// Build config with priority chain
|
|
97
|
+
const config = { ...DEFAULTS };
|
|
98
|
+
|
|
99
|
+
// 5. Default values (already set above)
|
|
100
|
+
|
|
101
|
+
// 4. Config file (rw-elements-tools.config.js)
|
|
102
|
+
if (configFile) {
|
|
103
|
+
if (configFile.packsDir) {
|
|
104
|
+
config.packsDir = configFile.packsDir;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 3. package.json "rw-elements-tools" field
|
|
109
|
+
if (packageJson && packageJson['rw-elements-tools']) {
|
|
110
|
+
const pkgConfig = packageJson['rw-elements-tools'];
|
|
111
|
+
if (pkgConfig.packsDir) {
|
|
112
|
+
config.packsDir = pkgConfig.packsDir;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// 2. Environment variables
|
|
117
|
+
if (process.env.RW_PACKS_DIR) {
|
|
118
|
+
config.packsDir = process.env.RW_PACKS_DIR;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// 1. CLI arguments (highest priority)
|
|
122
|
+
if (cliOptions.packsDir || cliOptions.packs) {
|
|
123
|
+
config.packsDir = cliOptions.packsDir || cliOptions.packs;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Resolve packsDir to absolute path from project root
|
|
127
|
+
if (!path.isAbsolute(config.packsDir)) {
|
|
128
|
+
config.packsDir = path.resolve(projectRoot, config.packsDir);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Add project root and package location to config
|
|
132
|
+
config.projectRoot = projectRoot;
|
|
133
|
+
config.packageRoot = __dirname;
|
|
134
|
+
|
|
135
|
+
return config;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Gets the path to a resource within the package
|
|
140
|
+
* @param {...string} segments - Path segments relative to package root
|
|
141
|
+
* @returns {string} Absolute path to the resource
|
|
142
|
+
*/
|
|
143
|
+
export function getPackagePath(...segments) {
|
|
144
|
+
return path.join(__dirname, ...segments);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export default { resolveConfig, getPackagePath };
|
|
148
|
+
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
const AnimationEffects = [
|
|
2
|
+
{
|
|
3
|
+
visible: "globalScrollAnimationTrigger != 'none' && globalScrollAnimationVisibleSettings == 'effects'",
|
|
4
|
+
title: "Preview",
|
|
5
|
+
id: "globalScrollAnimationPreviewInEditor",
|
|
6
|
+
responsive: false,
|
|
7
|
+
switch: {}
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
visible: "globalScrollAnimationTrigger != 'none' && globalScrollAnimationVisibleSettings == 'effects' && globalScrollAnimationPreviewInEditor == 'true'",
|
|
11
|
+
information: {},
|
|
12
|
+
title: "Previews the settings below. Spring effects are not supported in editor.",
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
visible: "globalScrollAnimationTrigger != 'none' && globalScrollAnimationVisibleSettings == 'effects'",
|
|
16
|
+
title: "State",
|
|
17
|
+
id: "globalScrollAnimationEnterState",
|
|
18
|
+
responsive: false,
|
|
19
|
+
segmented: {
|
|
20
|
+
default: "start",
|
|
21
|
+
items: [
|
|
22
|
+
{
|
|
23
|
+
title: "Start",
|
|
24
|
+
value: "start"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
title: "End",
|
|
28
|
+
value: "end"
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
visible: "globalScrollAnimationTrigger != 'none' && globalScrollAnimationVisibleSettings == 'effects' && globalScrollAnimationEnterState == 'start'",
|
|
35
|
+
globalControl: "ScrollAnimation_Opacity",
|
|
36
|
+
id: "{{value}}EnterStart",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
visible: "globalScrollAnimationTrigger != 'none' && globalScrollAnimationVisibleSettings == 'effects' && globalScrollAnimationEnterState == 'start'",
|
|
40
|
+
globalControl: "ScrollAnimation_Rotate",
|
|
41
|
+
id: "{{value}}EnterStart",
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
visible: "globalScrollAnimationTrigger != 'none' && globalScrollAnimationVisibleSettings == 'effects' && globalScrollAnimationEnterState == 'start'",
|
|
45
|
+
globalControl: "ScrollAnimation_Scale",
|
|
46
|
+
id: "{{value}}EnterStart",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
visible: "globalScrollAnimationTrigger != 'none' && globalScrollAnimationVisibleSettings == 'effects' && globalScrollAnimationEnterState == 'start'",
|
|
50
|
+
globalControl: "ScrollAnimation_Translate",
|
|
51
|
+
id: "{{value}}EnterStart",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
visible: "globalScrollAnimationTrigger != 'none' && globalScrollAnimationVisibleSettings == 'effects' && globalScrollAnimationEnterState == 'end'",
|
|
55
|
+
globalControl: "ScrollAnimation_Opacity",
|
|
56
|
+
id: "{{value}}EnterEnd",
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
visible: "globalScrollAnimationTrigger != 'none' && globalScrollAnimationVisibleSettings == 'effects' && globalScrollAnimationEnterState == 'end'",
|
|
60
|
+
globalControl: "ScrollAnimation_Rotate",
|
|
61
|
+
id: "{{value}}EnterEnd",
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
visible: "globalScrollAnimationTrigger != 'none' && globalScrollAnimationVisibleSettings == 'effects' && globalScrollAnimationEnterState == 'end'",
|
|
65
|
+
globalControl: "ScrollAnimation_Scale",
|
|
66
|
+
id: "{{value}}EnterEnd",
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
visible: "globalScrollAnimationTrigger != 'none' && globalScrollAnimationVisibleSettings == 'effects' && globalScrollAnimationEnterState == 'end'",
|
|
70
|
+
globalControl: "ScrollAnimation_Translate",
|
|
71
|
+
id: "{{value}}EnterEnd",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
visible: "globalScrollAnimationTrigger != 'none' && globalScrollAnimationVisibleSettings == 'effects'",
|
|
75
|
+
divider: {},
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
visible: "globalScrollAnimationTrigger != 'none' && globalScrollAnimationVisibleSettings == 'effects'",
|
|
79
|
+
title: "Exit",
|
|
80
|
+
heading: {}
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
visible: "globalScrollAnimationTrigger != 'none' && globalScrollAnimationVisibleSettings == 'effects'",
|
|
84
|
+
title: "Enable",
|
|
85
|
+
id: "globalScrollAnimationExitEnabled",
|
|
86
|
+
responsive: false,
|
|
87
|
+
switch: {}
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
visible: "globalScrollAnimationTrigger != 'none' && globalScrollAnimationVisibleSettings == 'effects' && globalScrollAnimationExitEnabled == 'true'",
|
|
91
|
+
globalControl: "ScrollAnimation_Opacity",
|
|
92
|
+
id: "{{value}}ExitEnd",
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
visible: "globalScrollAnimationTrigger != 'none' && globalScrollAnimationVisibleSettings == 'effects' && globalScrollAnimationExitEnabled == 'true'",
|
|
96
|
+
globalControl: "ScrollAnimation_Rotate",
|
|
97
|
+
id: "{{value}}ExitEnd",
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
visible: "globalScrollAnimationTrigger != 'none' && globalScrollAnimationVisibleSettings == 'effects' && globalScrollAnimationExitEnabled == 'true'",
|
|
101
|
+
globalControl: "ScrollAnimation_Scale",
|
|
102
|
+
id: "{{value}}ExitEnd",
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
visible: "globalScrollAnimationTrigger != 'none' && globalScrollAnimationVisibleSettings == 'effects' && globalScrollAnimationExitEnabled == 'true'",
|
|
106
|
+
globalControl: "ScrollAnimation_Translate",
|
|
107
|
+
id: "{{value}}ExitEnd",
|
|
108
|
+
},
|
|
109
|
+
]
|
|
110
|
+
|
|
111
|
+
export default AnimationEffects;
|