@plumeria/utils 19.2.12 → 19.2.14

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.
@@ -5,6 +5,7 @@ export type TransformEnv = {
5
5
  filePath: string;
6
6
  root: string;
7
7
  styleProp: string;
8
+ classProp?: string;
8
9
  propertyPolicy: PropertyPolicy | undefined;
9
10
  isDev: boolean;
10
11
  collectOndemandSheets: boolean;
package/dist/transform.js CHANGED
@@ -146,6 +146,7 @@ const foldDynamicVars = (vars) => {
146
146
  };
147
147
  const transformSource = async (env) => {
148
148
  const { source, root, styleProp, propertyPolicy, isDev, collectOndemandSheets, addDependency, } = env;
149
+ const classProp = env.classProp ?? 'className';
149
150
  const id = env.moduleId;
150
151
  const resourcePath = env.moduleId;
151
152
  const baseId = env.filePath;
@@ -317,81 +318,82 @@ const transformSource = async (env) => {
317
318
  const createStaticImportMap = {};
318
319
  const plumeriaAliases = {};
319
320
  const localImports = {};
320
- (0, parser_1.traverse)(ast, {
321
- ImportDeclaration({ node }) {
322
- const sourcePath = node.source.value;
323
- if (sourcePath === '@plumeria/core') {
324
- node.specifiers.forEach((specifier) => {
325
- if (specifier.type === 'ImportNamespaceSpecifier') {
326
- plumeriaAliases[specifier.local.value] = 'NAMESPACE';
327
- }
328
- else if (specifier.type === 'ImportDefaultSpecifier') {
329
- plumeriaAliases[specifier.local.value] = 'NAMESPACE';
330
- }
331
- else if (specifier.type === 'ImportSpecifier') {
332
- const importedName = specifier.imported
321
+ for (const statement of ast.body) {
322
+ if (statement.type !== 'ImportDeclaration')
323
+ continue;
324
+ const node = statement;
325
+ const sourcePath = node.source.value;
326
+ if (sourcePath === '@plumeria/core') {
327
+ node.specifiers.forEach((specifier) => {
328
+ if (specifier.type === 'ImportNamespaceSpecifier') {
329
+ plumeriaAliases[specifier.local.value] = 'NAMESPACE';
330
+ }
331
+ else if (specifier.type === 'ImportDefaultSpecifier') {
332
+ plumeriaAliases[specifier.local.value] = 'NAMESPACE';
333
+ }
334
+ else if (specifier.type === 'ImportSpecifier') {
335
+ const importedName = specifier.imported
336
+ ? specifier.imported.value
337
+ : specifier.local.value;
338
+ plumeriaAliases[specifier.local.value] = importedName;
339
+ }
340
+ });
341
+ }
342
+ const actualPath = (0, resolver_1.resolveImportPath)(sourcePath, resourcePath);
343
+ if (actualPath) {
344
+ node.specifiers.forEach((specifier) => {
345
+ if (specifier.type === 'ImportNamespaceSpecifier') {
346
+ localImports[specifier.local.value] = {
347
+ actualPath,
348
+ importedName: '*',
349
+ };
350
+ return;
351
+ }
352
+ if (specifier.type === 'ImportSpecifier' ||
353
+ specifier.type === 'ImportDefaultSpecifier') {
354
+ const importedName = specifier.type === 'ImportDefaultSpecifier'
355
+ ? 'default'
356
+ : specifier.imported
333
357
  ? specifier.imported.value
334
358
  : specifier.local.value;
335
- plumeriaAliases[specifier.local.value] = importedName;
359
+ const localName = specifier.local.value;
360
+ let resolvedKey = `${actualPath}-${importedName}`;
361
+ const resolved = (0, parser_1.resolveExport)(actualPath, importedName);
362
+ if (resolved) {
363
+ resolvedKey = `${resolved.filePath}-${resolved.localName}`;
336
364
  }
337
- });
338
- }
339
- const actualPath = (0, resolver_1.resolveImportPath)(sourcePath, resourcePath);
340
- if (actualPath) {
341
- node.specifiers.forEach((specifier) => {
342
- if (specifier.type === 'ImportNamespaceSpecifier') {
343
- localImports[specifier.local.value] = {
344
- actualPath,
345
- importedName: '*',
346
- };
347
- return;
365
+ const uniqueKey = resolvedKey;
366
+ localImports[localName] = { actualPath, importedName };
367
+ if (scannedTables.staticTable[uniqueKey]) {
368
+ importMap[localName] = scannedTables.staticTable[uniqueKey];
348
369
  }
349
- if (specifier.type === 'ImportSpecifier' ||
350
- specifier.type === 'ImportDefaultSpecifier') {
351
- const importedName = specifier.type === 'ImportDefaultSpecifier'
352
- ? 'default'
353
- : specifier.imported
354
- ? specifier.imported.value
355
- : specifier.local.value;
356
- const localName = specifier.local.value;
357
- let resolvedKey = `${actualPath}-${importedName}`;
358
- const resolved = (0, parser_1.resolveExport)(actualPath, importedName);
359
- if (resolved) {
360
- resolvedKey = `${resolved.filePath}-${resolved.localName}`;
361
- }
362
- const uniqueKey = resolvedKey;
363
- localImports[localName] = { actualPath, importedName };
364
- if (scannedTables.staticTable[uniqueKey]) {
365
- importMap[localName] = scannedTables.staticTable[uniqueKey];
366
- }
367
- if (scannedTables.keyframesHashTable[uniqueKey]) {
368
- keyframesImportMap[localName] =
369
- scannedTables.keyframesHashTable[uniqueKey];
370
- }
371
- if (scannedTables.viewTransitionHashTable[uniqueKey]) {
372
- viewTransitionImportMap[localName] =
373
- scannedTables.viewTransitionHashTable[uniqueKey];
374
- }
375
- if (scannedTables.createHashTable[uniqueKey]) {
376
- createImportMap[localName] =
377
- scannedTables.createHashTable[uniqueKey];
378
- }
379
- if (scannedTables.createFunctionTable[uniqueKey]) {
380
- createFunctionImportMap[localName] = (0, dynamicKey_1.styleFunctionsOf)(scannedTables.createFunctionTable[uniqueKey]);
381
- }
382
- if (scannedTables.createThemeHashTable[uniqueKey]) {
383
- createThemeImportMap[localName] =
384
- scannedTables.createThemeHashTable[uniqueKey];
385
- }
386
- if (scannedTables.createStaticHashTable[uniqueKey]) {
387
- createStaticImportMap[localName] =
388
- scannedTables.createStaticHashTable[uniqueKey];
389
- }
370
+ if (scannedTables.keyframesHashTable[uniqueKey]) {
371
+ keyframesImportMap[localName] =
372
+ scannedTables.keyframesHashTable[uniqueKey];
390
373
  }
391
- });
392
- }
393
- },
394
- });
374
+ if (scannedTables.viewTransitionHashTable[uniqueKey]) {
375
+ viewTransitionImportMap[localName] =
376
+ scannedTables.viewTransitionHashTable[uniqueKey];
377
+ }
378
+ if (scannedTables.createHashTable[uniqueKey]) {
379
+ createImportMap[localName] =
380
+ scannedTables.createHashTable[uniqueKey];
381
+ }
382
+ if (scannedTables.createFunctionTable[uniqueKey]) {
383
+ createFunctionImportMap[localName] = (0, dynamicKey_1.styleFunctionsOf)(scannedTables.createFunctionTable[uniqueKey]);
384
+ }
385
+ if (scannedTables.createThemeHashTable[uniqueKey]) {
386
+ createThemeImportMap[localName] =
387
+ scannedTables.createThemeHashTable[uniqueKey];
388
+ }
389
+ if (scannedTables.createStaticHashTable[uniqueKey]) {
390
+ createStaticImportMap[localName] =
391
+ scannedTables.createStaticHashTable[uniqueKey];
392
+ }
393
+ }
394
+ });
395
+ }
396
+ }
395
397
  const mergedStaticTable = Object.create(scannedTables.staticTable);
396
398
  for (const key of Object.keys(localConsts)) {
397
399
  mergedStaticTable[key] = localConsts[key];
@@ -2126,7 +2128,7 @@ const transformSource = async (env) => {
2126
2128
  const attributes = jsxAttributeOwnerMap.get(node.span.start)?.attributes ?? [];
2127
2129
  const classNameAttr = attributes.find((attr) => attr.type === 'JSXAttribute' &&
2128
2130
  attr.name.type === 'Identifier' &&
2129
- attr.name.value === 'className');
2131
+ attr.name.value === classProp);
2130
2132
  let existingClassExpr = '';
2131
2133
  if (classNameAttr) {
2132
2134
  replacements.push({
@@ -2185,12 +2187,12 @@ const transformSource = async (env) => {
2185
2187
  replacements.push({
2186
2188
  start: node.span.start - baseByteOffset,
2187
2189
  end: node.span.end - baseByteOffset,
2188
- content: `className={${replacement}}${styleAttr}`,
2190
+ content: `${classProp}={${replacement}}${styleAttr}`,
2189
2191
  });
2190
2192
  }
2191
2193
  else {
2192
2194
  const keptClass = existingClassExpr
2193
- ? `className={${existingClassExpr}}`
2195
+ ? `${classProp}={${existingClassExpr}}`
2194
2196
  : '';
2195
2197
  replacements.push({
2196
2198
  start: node.span.start - baseByteOffset,
@@ -2321,17 +2323,16 @@ const transformSource = async (env) => {
2321
2323
  for (const replacement of replacements)
2322
2324
  replacement.content = replacement.content.replaceAll(deferred.token, content);
2323
2325
  }
2324
- const buffer = Buffer.from(source);
2325
2326
  let offset = 0;
2326
2327
  const parts = [];
2327
2328
  replacements.forEach((r) => {
2328
2329
  if (r.start < offset)
2329
2330
  return;
2330
- parts.push(buffer.subarray(offset, r.start));
2331
+ parts.push(sourceBuffer.subarray(offset, r.start));
2331
2332
  parts.push(Buffer.from(r.content));
2332
2333
  offset = r.end;
2333
2334
  });
2334
- parts.push(buffer.subarray(offset));
2335
+ parts.push(sourceBuffer.subarray(offset));
2335
2336
  const transformedSource = Buffer.concat(parts).toString();
2336
2337
  return { code: transformedSource, sheets: [...extractedSheets] };
2337
2338
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/utils",
3
- "version": "19.2.12",
3
+ "version": "19.2.14",
4
4
  "description": "Plumeria Utils",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",