diff --git a/doc/style-dedup.md b/doc/style-dedup.md new file mode 100644 index 00000000..1a5b9d60 --- /dev/null +++ b/doc/style-dedup.md @@ -0,0 +1,16 @@ +# Style Dedup Challenges + +## Why duplicates happen +- Figma’s REST styles endpoints (`/v1/files/:file_key/styles`, `/v1/teams/:team_id/styles`, etc.) return `key`, `file_key`, `node_id`, `style_type`, `name`, `description`, timestamps, and `sort_position`. There is **no** `collectionId` concept for styles; the “Headline/Headline 2” grouping you see in the UI is simply encoded in the `name` string via slash naming or folders. +- Designers can create multiple published styles that share the exact same `name` (path) inside the same file or library. When Figmage groups styles by `name` to generate strongly typed classes, every later style would overwrite the earlier one unless we intervene. +- The API doesn’t tell us which duplicate is “authoritative.” We can only distinguish them by IDs or timestamps (e.g., `key`, `node_id`, `created_at`), so deduping requires extra configuration or heuristics that Figmage doesn’t currently have. + +## Current Figmage strategy +- We keep **all** occurrences. While building `valuesByNameByMode`, duplicate style names receive deterministic suffixes (`Variant2`, `Variant3`, …) so map keys stay unique. +- The code generators also sanitize identifiers; if two already-suffixed names still collide after camel-casing, the generator appends another suffix. That’s how extreme cases produced names like `display1Variant2Variant2`—one suffix came from the token map, another from the generator’s collision guard. +- Users get a warning listing every duplicate style (with node IDs) so they can clean up the design file or expect suffixed members in the generated Dart code. + +## Key takeaways +- Styles don’t have collections in the REST API; only variables have `variableCollectionId`. Figmage infers “collections” from the slash-separated `name`. +- Duplicate warnings mean “Figmage kept every copy and suffixed the Dart members,” not that we can tell which one is canonical. +- To truly pick one style out of a set of duplicates, we would need extra rules (designer config, allowlists, or heuristics using `key`, `created_at`, etc.). Until then, suffixing keeps generated code consistent without silently dropping tokens.*** End Patch*** End Patch diff --git a/lib/src/data/generators/theme_extension_generators/mode_theme_extension_generator.dart b/lib/src/data/generators/theme_extension_generators/mode_theme_extension_generator.dart index 314e495a..af0e8e37 100644 --- a/lib/src/data/generators/theme_extension_generators/mode_theme_extension_generator.dart +++ b/lib/src/data/generators/theme_extension_generators/mode_theme_extension_generator.dart @@ -74,6 +74,9 @@ abstract class ModeThemeExtensionGenerator @override Class generateClass() { + final uniqueFieldNames = + _getUniqueVariableNames(valuesByNameByMode.values.first.keys); + final validValueMaps = valuesByNameByMode.map( (key, value) => MapEntry( switch (key) { @@ -81,7 +84,7 @@ abstract class ModeThemeExtensionGenerator _ => convertToValidVariableName(key), }, value.map( - (key, value) => MapEntry(convertToValidVariableName(key), value), + (key, value) => MapEntry(uniqueFieldNames[key]!, value), ), ), ); @@ -313,6 +316,28 @@ abstract class ModeThemeExtensionGenerator } } +Map _getUniqueVariableNames(Iterable names) { + final result = {}; + final usedNames = {}; + final counts = {}; + + for (final name in names) { + final baseName = convertToValidVariableName(name); + var count = (counts[baseName] ?? 0) + 1; + counts[baseName] = count; + var candidate = count == 1 ? baseName : '${baseName}Variant$count'; + while (usedNames.contains(candidate)) { + count += 1; + candidate = '${baseName}Variant$count'; + } + counts[baseName] = count; + usedNames.add(candidate); + result[name] = candidate; + } + + return result; +} + /// Extension on Reference extension ReferenceX on Reference { /// Returns the a nullable reference diff --git a/lib/src/data/repositories/figma_assets_repository.dart b/lib/src/data/repositories/figma_assets_repository.dart index fce55252..c226f679 100644 --- a/lib/src/data/repositories/figma_assets_repository.dart +++ b/lib/src/data/repositories/figma_assets_repository.dart @@ -1,6 +1,6 @@ import 'dart:io'; import 'package:collection/collection.dart'; -import 'package:figma_variables_api/figma_variables_api.dart'; +import 'package:figma/figma.dart'; import 'package:figmage/src/domain/models/config/config.dart'; import 'package:figmage/src/domain/repositories/assets_repository.dart'; import 'package:http/http.dart' as http; @@ -44,16 +44,15 @@ class FigmaAssetsRepository implements AssetsRepository { final result = await client.getImages( fileId, - batch, - scale: scale, + GetImages( + ids: batch.join(','), + scale: scale, + ), ); - if (result.err != null) { - throw UnknownAssetsException(result.err); - } - final images = await _downloadImages( - images: result.images, + images: result.images + .map((key, value) => MapEntry(key, value?.toString())), nodeSettings: nodeSettings, scale: scale.toDouble(), outputDir: outputDir, diff --git a/lib/src/data/repositories/figma_styles_repository.dart b/lib/src/data/repositories/figma_styles_repository.dart index 9640bdcf..224a5413 100644 --- a/lib/src/data/repositories/figma_styles_repository.dart +++ b/lib/src/data/repositories/figma_styles_repository.dart @@ -1,9 +1,17 @@ -import 'package:figma_variables_api/figma_variables_api.dart'; +import 'package:figma/figma.dart'; import 'package:figmage/src/data/util/converters/color_conversion_x.dart'; import 'package:figmage/src/data/util/converters/type_style_conversion_x.dart'; import 'package:figmage/src/domain/models/style/design_style.dart'; import 'package:figmage/src/domain/repositories/styles_repository.dart'; +typedef _StyleInfo = ({ + String? nodeId, + String key, + String name, + StyleType type, + String description, +}); + /// {@template figma_styles_repository} /// This repository fetches styles from the Figma API. /// {@endtemplate} @@ -13,100 +21,264 @@ class FigmaStylesRepository implements StylesRepository { required String fileId, required String token, required bool fromLibrary, + void Function(String message)? onProgress, + }) async { + final primaryClient = FigmaClient(token); + Object? http2Error; + try { + return await _loadStyles( + client: primaryClient, + fileId: fileId, + fromLibrary: fromLibrary, + onProgress: onProgress, + ); + } on StylesException { + rethrow; + } on FigmaException catch (error) { + if (!_isHttp2ConnectionIssue(error)) { + rethrow; + } + http2Error = error; + } catch (error) { + if (!_isHttp2ConnectionIssue(error)) { + rethrow; + } + http2Error = error; + } + + onProgress?.call( + 'Primary HTTP/2 request failed ' + '($http2Error). Retrying over HTTP/1.1...', + ); + final fallbackClient = FigmaClient(token, useHttp2: false); + return _loadStyles( + client: fallbackClient, + fileId: fileId, + fromLibrary: fromLibrary, + onProgress: onProgress, + ); + } + + Future>> _loadStyles({ + required FigmaClient client, + required String fileId, + required bool fromLibrary, + void Function(String message)? onProgress, }) async { - final client = FigmaClient(token); + onProgress?.call( + fromLibrary + ? 'Fetching published styles metadata...' + : 'Fetching local styles metadata...', + ); final styles = switch (fromLibrary) { - true => await _getPublishedStyles(client, fileId), - false => await _getUnpublishedStyles(client, fileId), + true => await _getPublishedStyles( + client, + fileId, + onProgress: onProgress, + ), + false => await _getUnpublishedStyles( + client, + fileId, + onProgress: onProgress, + ), }; + onProgress?.call('Retrieved metadata for ${styles.length} styles.'); if (styles.isEmpty) { return []; } - final NodesResponse nodesResponse; - try { - nodesResponse = await client.getFileNodes( - fileId, - FigmaQuery( - ids: styles.map((e) => e.nodeId).nonNulls.toList(), - ), + final nodeIds = styles + .map((style) => style.nodeId) + .whereType() + .toList(); + if (nodeIds.isEmpty) { + onProgress?.call( + 'No node IDs were associated with the retrieved styles. ' + 'Skipping node hydration.', ); - } on FigmaException catch (e) { - _throwError(e); + return []; } - final styleNodes = nodesResponse.nodes?.values.map((e) => e.document) ?? []; - return [ + + onProgress?.call( + 'Discovered ${styles.length} style metadata entries; ' + '${nodeIds.length} include node references.', + ); + onProgress?.call( + 'Fetching ${nodeIds.length} style nodes via /files/$fileId/nodes ' + '(HTTP${client.useHttp2 ? '2' : '1.1'})...', + ); + final nodesResponse = await _fetchNodes(client, fileId, nodeIds); + final styleNodes = nodesResponse.nodes.values + .map((nodeMeta) => nodeMeta.document) + .whereType() + .toList(); + final missingNodes = nodeIds.length - styleNodes.length; + onProgress?.call( + 'Hydrated ${styleNodes.length} node document(s); ' + '${missingNodes.clamp(0, nodeIds.length)} node id(s) missing.', + ); + final stylesFromNodes = [ for (final node in styleNodes) - if (node != null) - if (_transformNode(node) case final style?) style, + if (_transformNode(node) case final style?) style, ]; + final droppedNodes = styleNodes.length - stylesFromNodes.length; + onProgress?.call( + 'Converted ${styleNodes.length} node document(s) into ' + '${stylesFromNodes.length} supported style(s); ' + '$droppedNodes unsupported node(s) skipped.', + ); + return stylesFromNodes; } - Future> _getPublishedStyles( + Future> _getPublishedStyles( FigmaClient client, - String fileId, - ) async { + String fileId, { + void Function(String message)? onProgress, + }) async { + onProgress?.call( + 'Requesting published styles via /files/$fileId/styles...', + ); final StylesResponse stylesResponse; try { stylesResponse = await client.getFileStyles(fileId); } on FigmaException catch (e) { - _throwError(e); + if (e.code == 403) { + _throwError(e); + } + rethrow; } - return stylesResponse.meta?.styles ?? []; + final styles = stylesResponse.meta.styles; + onProgress?.call( + 'Retrieved metadata for ${styles.length} published styles.', + ); + + return [ + for (final style in styles) + ( + nodeId: style.nodeId, + key: style.key, + name: style.name, + type: style.styleType, + description: style.description, + ), + ]; } - Future> _getUnpublishedStyles( + Future> _getUnpublishedStyles( FigmaClient client, - String fileId, - ) async { - final FileStylesResponse response; + String fileId, { + void Function(String message)? onProgress, + }) async { + final uri = Uri.https( + 'api.figma.com', + '/${client.apiVersion}/files/$fileId', + ); try { - response = await client.getLocalFileStyles(fileId); - } on FigmaException catch (e) { - _throwError(e); - } - final styles = [ - if (response.styles case final styles?) - for (final MapEntry(:key, :value) in styles.entries) - Style( + onProgress?.call( + 'Requesting /files/$fileId for local styles metadata...', + ); + final json = await client.authenticatedGet(uri.toString()); + final stylesRaw = json['styles']; + if (stylesRaw is! Map) { + return const []; + } + onProgress?.call( + 'Extracted ${stylesRaw.length} styles from /files response.', + ); + + // TODO(figma-api): Swap this manual parsing once the official client + // exposes local styles directly to avoid depending on raw JSON. + final results = <_StyleInfo>[]; + for (final MapEntry(:key, :value) in stylesRaw.entries) { + if (value is! Map) { + continue; + } + + final styleKey = value['key'] as String?; + final name = value['name'] as String?; + final styleType = _parseStyleType(value['styleType']); + if (styleKey == null || name == null || styleType == null) { + continue; + } + + results.add( + ( nodeId: key, - key: value.key, - name: value.name, - type: value.type, - description: value.description, + key: styleKey, + name: name, + type: styleType, + description: value['description'] as String? ?? '', ), - ]; - - return styles; + ); + } + onProgress?.call( + 'Parsed ${results.length} local style metadata entries.', + ); + return results; + } on FigmaException catch (e) { + if (e.code == 403) { + _throwError(e); + } + rethrow; + } } DesignStyle? _transformNode(Node node) { return switch (node) { - Text( - :final id, - :final name?, - :final style?, - ) => - TextDesignStyle(id: id, fullName: name, value: style.toDomain()), - Rectangle( - :final id, - :final name?, - fills: [Paint(:final color?, :final opacity), ...], - ) => - ColorDesignStyle( - id: id, - fullName: name, - value: Color( - a: (color.a ?? 1) * (opacity ?? 1), - r: color.r, - g: color.g, - b: color.b, - ).toValue(), - ), - _ => null, - } as DesignStyle?; + TextNode( + :final id, + :final name, + :final style, + ) => + TextDesignStyle(id: id, fullName: name, value: style.toDomain()), + RectangleNode( + :final id, + :final name, + fills: [SolidPaint(:final color, :final opacity), ...], + ) => + ColorDesignStyle( + id: id, + fullName: name, + value: color.toValue(opacity: opacity), + ), + _ => null, + } + as DesignStyle?; + } + + Future _fetchNodes( + FigmaClient client, + String fileId, + List nodeIds, + ) async { + final uri = Uri.https( + 'api.figma.com', + '/${client.apiVersion}/files/$fileId/nodes', + {'ids': nodeIds.join(',')}, + ); + try { + final json = await client.authenticatedGet(uri.toString()); + return NodesResponse.fromJson(json); + } on FigmaException catch (e) { + if (e.code == 403) { + _throwError(e); + } + rethrow; + } + } + + StyleType? _parseStyleType(Object? value) { + if (value is! String) { + return null; + } + for (final styleType in StyleType.values) { + if (styleType.name == value.toLowerCase()) { + return styleType; + } + } + return null; } Never _throwError(FigmaException e) { @@ -115,4 +287,10 @@ class FigmaStylesRepository implements StylesRepository { _ => throw UnknownStylesException(e.message), }; } + + bool _isHttp2ConnectionIssue(Object error) { + final message = error.toString(); + return message.contains('HTTP/2 error') || + message.contains('Stream was terminated by peer'); + } } diff --git a/lib/src/data/repositories/figma_variables_repository.dart b/lib/src/data/repositories/figma_variables_repository.dart index 207101fa..a9c321c8 100644 --- a/lib/src/data/repositories/figma_variables_repository.dart +++ b/lib/src/data/repositories/figma_variables_repository.dart @@ -1,6 +1,7 @@ -import 'package:figma_variables_api/figma_variables_api.dart'; +import 'package:figma/figma.dart'; import 'package:figmage/src/domain/models/variable/alias_or/alias_or.dart'; import 'package:figmage/src/domain/models/variable/variable.dart'; +import 'package:figmage/src/domain/models/variable/variable_type.dart'; import 'package:figmage/src/domain/repositories/variables_repository.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -8,7 +9,7 @@ import 'package:freezed_annotation/freezed_annotation.dart'; @visibleForTesting typedef VariablesData = ({ Map> variables, - Map variableCollections + Map variableCollections }); /// The implementation of [VariablesRepository] for Figma. @@ -23,7 +24,7 @@ class FigmaVariablesRepository implements VariablesRepository { ); } - Future _getLocaleVariables({ + Future _getLocaleVariables({ required String fileId, required String token, }) async { @@ -35,7 +36,7 @@ class FigmaVariablesRepository implements VariablesRepository { if (e.code == 403) { throw const UnauthorizedVariablesException(); } else { - throw UnknownVariablesException(e.message); + throw UnknownVariablesException(e.message ?? e.toString()); } } catch (e) { throw UnknownVariablesException(e.toString()); @@ -44,11 +45,11 @@ class FigmaVariablesRepository implements VariablesRepository { /// Converts a list of DTO variables into model variables. /// - /// Given a [VariablesResponseDto], this method processes the variables within - /// it, maps them to model variables, and returns a list of variables. + /// Given a [LocalVariablesResponse], this method processes the variables + /// within it, maps them to model variables, and returns a list of variables. @visibleForTesting List> fromDtoToModel( - VariablesResponseDto variablesResponse, + LocalVariablesResponse variablesResponse, ) { final variableCollections = variablesResponse.meta.variableCollections; final dtoVariables = variablesResponse.meta.variables; @@ -62,7 +63,21 @@ class FigmaVariablesRepository implements VariablesRepository { }; final collectionName = variableCollection.name; - return switch (dtoVariable.resolvedType) { + final resolvedType = + VariableTypeX.fromResolvedDataType(dtoVariable.resolvedType); + + final codeSyntax = { + if (dtoVariable.codeSyntax.web != null) + 'WEB': dtoVariable.codeSyntax.web!, + if (dtoVariable.codeSyntax.android != null) + 'ANDROID': dtoVariable.codeSyntax.android!, + if (dtoVariable.codeSyntax.iOs != null) + 'iOS': dtoVariable.codeSyntax.iOs!, + }; + + final scopes = dtoVariable.scopes.map(_variableScopeToString).toList(); + + return switch (resolvedType) { VariableType.string => StringVariable( id: dtoVariable.id, name: dtoVariable.name, @@ -70,11 +85,11 @@ class FigmaVariablesRepository implements VariablesRepository { key: dtoVariable.key, variableCollectionId: dtoVariable.variableCollectionId, variableCollectionName: collectionName, - resolvedType: dtoVariable.resolvedType, + resolvedType: resolvedType, description: dtoVariable.description, hiddenFromPublishing: dtoVariable.hiddenFromPublishing, - scopes: dtoVariable.scopes, - codeSyntax: dtoVariable.codeSyntax, + scopes: scopes, + codeSyntax: codeSyntax, deletedButReferenced: dtoVariable.deletedButReferenced, valuesByModeId: dtoVariable.valuesByMode.map( (key, value) => MapEntry( @@ -91,11 +106,11 @@ class FigmaVariablesRepository implements VariablesRepository { key: dtoVariable.key, variableCollectionId: dtoVariable.variableCollectionId, variableCollectionName: collectionName, - resolvedType: dtoVariable.resolvedType, + resolvedType: resolvedType, description: dtoVariable.description, hiddenFromPublishing: dtoVariable.hiddenFromPublishing, - scopes: dtoVariable.scopes, - codeSyntax: dtoVariable.codeSyntax, + scopes: scopes, + codeSyntax: codeSyntax, deletedButReferenced: dtoVariable.deletedButReferenced, valuesByModeId: dtoVariable.valuesByMode.map( (key, value) => MapEntry( @@ -112,11 +127,11 @@ class FigmaVariablesRepository implements VariablesRepository { key: dtoVariable.key, variableCollectionId: dtoVariable.variableCollectionId, variableCollectionName: collectionName, - resolvedType: dtoVariable.resolvedType, + resolvedType: resolvedType, description: dtoVariable.description, hiddenFromPublishing: dtoVariable.hiddenFromPublishing, - scopes: dtoVariable.scopes, - codeSyntax: dtoVariable.codeSyntax, + scopes: scopes, + codeSyntax: codeSyntax, deletedButReferenced: dtoVariable.deletedButReferenced, valuesByModeId: dtoVariable.valuesByMode.map( (key, value) => MapEntry( @@ -133,11 +148,11 @@ class FigmaVariablesRepository implements VariablesRepository { key: dtoVariable.key, variableCollectionId: dtoVariable.variableCollectionId, variableCollectionName: collectionName, - resolvedType: dtoVariable.resolvedType, + resolvedType: resolvedType, description: dtoVariable.description, hiddenFromPublishing: dtoVariable.hiddenFromPublishing, - scopes: dtoVariable.scopes, - codeSyntax: dtoVariable.codeSyntax, + scopes: scopes, + codeSyntax: codeSyntax, deletedButReferenced: dtoVariable.deletedButReferenced, valuesByModeId: dtoVariable.valuesByMode.map( (key, value) => MapEntry( @@ -160,26 +175,75 @@ class FigmaVariablesRepository implements VariablesRepository { /// /// Returns an [AliasOr] object containing the resolved value. AliasOr _resolveAlias({ - required VariableModeValueDto value, - required Map dtoVariables, + required VariableValue value, + required Map dtoVariables, }) { - if (value case final VariableModeAliasDto aliasDto) { + if (value case final VariableAlias aliasDto) { if (dtoVariables.containsKey(aliasDto.id) == false) { return AliasUnresolved(id: aliasDto.id); } } return switch (value) { - VariableModeAliasDto() => Alias( + VariableAlias() => Alias( id: value.id, aliasOrValue: _resolveAlias( value: dtoVariables[value.id]!.valuesByMode.values.first, dtoVariables: dtoVariables, ), ), - VariableModeBooleanDto() => AliasData(data: value.value as T), - VariableModeDoubleDto() => AliasData(data: value.value as T), - VariableModeStringDto() => AliasData(data: value.value as T), - VariableModeColorDto() => AliasData(data: value.value as T), + bool() => AliasData(data: value as T), + num() => AliasData(data: _convertNumeric(value)), + String() => AliasData(data: value as T), + Rgba() => AliasData(data: _rgbaToInt(value) as T), + _ => throw UnimplementedError( + 'Unsupported value type: ${value.runtimeType}', + ), + }; + } + + T _convertNumeric(num value) { + if (T == double) { + return value.toDouble() as T; + } else if (T == int) { + return value.toInt() as T; + } else { + return value as T; + } + } + + String _variableScopeToString(VariableScope scope) { + return switch (scope) { + VariableScope.allScopes => 'ALL_SCOPES', + VariableScope.textContent => 'TEXT_CONTENT', + VariableScope.cornerRadius => 'CORNER_RADIUS', + VariableScope.widthHeight => 'WIDTH_HEIGHT', + VariableScope.gap => 'GAP', + VariableScope.allFills => 'ALL_FILLS', + VariableScope.frameFill => 'FRAME_FILL', + VariableScope.shapeFill => 'SHAPE_FILL', + VariableScope.textFill => 'TEXT_FILL', + VariableScope.strokeColor => 'STROKE_COLOR', + VariableScope.strokeFloat => 'STROKE_FLOAT', + VariableScope.effectFloat => 'EFFECT_FLOAT', + VariableScope.effectColor => 'EFFECT_COLOR', + VariableScope.opacity => 'OPACITY', + VariableScope.fontFamily => 'FONT_FAMILY', + VariableScope.fontStyle => 'FONT_STYLE', + VariableScope.fontWeight => 'FONT_WEIGHT', + VariableScope.fontSize => 'FONT_SIZE', + VariableScope.lineHeight => 'LINE_HEIGHT', + VariableScope.letterSpacing => 'LETTER_SPACING', + VariableScope.paragraphSpacing => 'PARAGRAPH_SPACING', + VariableScope.paragraphIndent => 'PARAGRAPH_INDENT', + VariableScope.fontVariations => 'FONT_VARIATIONS', }; } + + int _rgbaToInt(Rgba rgba) { + final r = (rgba.r * 255).round(); + final g = (rgba.g * 255).round(); + final b = (rgba.b * 255).round(); + final a = (rgba.a * 255).round(); + return (a << 24) | (r << 16) | (g << 8) | b; + } } diff --git a/lib/src/data/util/converters/color_conversion_x.dart b/lib/src/data/util/converters/color_conversion_x.dart index 09d4cb47..fbfcfe73 100644 --- a/lib/src/data/util/converters/color_conversion_x.dart +++ b/lib/src/data/util/converters/color_conversion_x.dart @@ -1,16 +1,13 @@ -import 'package:figma_variables_api/figma_variables_api.dart'; +import 'package:figma/figma.dart'; -/// Extension methods for converting [Color]s. -extension ColorConversionX on Color { - /// Converts a figma [Color] to a 32 bit integer. - int toValue() { - if ((r, g, b, a) case (final r?, final g?, final b?, final a?)) { - final red = (r * 255).round(); - final green = (g * 255).round(); - final blue = (b * 255).round(); - final alpha = (a * 255).round(); - return (alpha << 24) | (red << 16) | (green << 8) | blue; - } - throw Exception('Color is not valid'); +/// Extension methods for converting [Rgba]s. +extension ColorConversionX on Rgba { + /// Converts a figma [Rgba] to a 32 bit integer. + int toValue({num? opacity}) { + final red = (r * 255).round(); + final green = (g * 255).round(); + final blue = (b * 255).round(); + final alpha = (a * (opacity ?? 1) * 255).round(); + return (alpha << 24) | (red << 16) | (green << 8) | blue; } } diff --git a/lib/src/data/util/converters/type_style_conversion_x.dart b/lib/src/data/util/converters/type_style_conversion_x.dart index 6115d151..04839ed5 100644 --- a/lib/src/data/util/converters/type_style_conversion_x.dart +++ b/lib/src/data/util/converters/type_style_conversion_x.dart @@ -1,4 +1,4 @@ -import 'package:figma_variables_api/figma_variables_api.dart'; +import 'package:figma/figma.dart'; import 'package:figmage/src/domain/models/typography/typography.dart'; import 'package:meta/meta.dart'; @@ -11,7 +11,7 @@ extension TypeStyleConversionX on TypeStyle { fontFamilyPostScriptName: fontPostScriptName, fontSize: fontSize!.toDouble(), fontWeight: convertFontWeight(fontWeight ?? 400), - fontStyle: italic ?? false ? FontStyle.italic : FontStyle.normal, + fontStyle: italic ? FontStyle.italic : FontStyle.normal, letterSpacing: letterSpacing?.toDouble() ?? 0, height: convertLineHeight(lineHeightPx, fontSize), ); diff --git a/lib/src/domain/models/config/config.g.dart b/lib/src/domain/models/config/config.g.dart index 7ed76dd1..d2868c91 100644 --- a/lib/src/domain/models/config/config.g.dart +++ b/lib/src/domain/models/config/config.g.dart @@ -6,118 +6,131 @@ part of 'config.dart'; // JsonSerializableGenerator // ************************************************************************** -Config _$ConfigFromJson(Map json) => $checkedCreate( - 'Config', - json, - ($checkedConvert) { - final val = Config( - packageName: $checkedConvert('packageName', (v) => v as String?), - fileId: $checkedConvert('fileId', (v) => v as String?), - packageDescription: $checkedConvert( - 'packageDescription', - (v) => - v as String? ?? - 'A design tokens package, generated by figmage'), - dropUnresolved: - $checkedConvert('dropUnresolved', (v) => v as bool? ?? false), - includeDeletedButReferenced: $checkedConvert( - 'includeDeletedButReferenced', (v) => v as bool? ?? false), - stylesFromLibrary: - $checkedConvert('stylesFromLibrary', (v) => v as bool? ?? false), - asPackage: $checkedConvert('asPackage', (v) => v as bool? ?? true), - tokenPath: $checkedConvert('tokenPath', (v) => v as String? ?? 'src'), - colors: $checkedConvert( - 'colors', - (v) => v == null - ? const GenerationSettings() - : GenerationSettings.fromJson(v as Map)), - typography: $checkedConvert( - 'typography', - (v) => v == null - ? const TypographyGenerationSettings() - : TypographyGenerationSettings.fromJson(v as Map)), - strings: $checkedConvert( - 'strings', - (v) => v == null - ? const GenerationSettings() - : GenerationSettings.fromJson(v as Map)), - bools: $checkedConvert( - 'bools', - (v) => v == null - ? const GenerationSettings() - : GenerationSettings.fromJson(v as Map)), - numbers: $checkedConvert( - 'numbers', - (v) => v == null - ? const GenerationSettings() - : GenerationSettings.fromJson(v as Map)), - spacers: $checkedConvert( - 'spacers', - (v) => v == null - ? const GenerationSettings(generate: false) - : GenerationSettings.fromJson(v as Map)), - paddings: $checkedConvert( - 'paddings', - (v) => v == null - ? const GenerationSettings(generate: false) - : GenerationSettings.fromJson(v as Map)), - radii: $checkedConvert( - 'radii', - (v) => v == null - ? const GenerationSettings(generate: false) - : GenerationSettings.fromJson(v as Map)), - assets: $checkedConvert( - 'assets', - (v) => v == null - ? const AssetGenerationSettings() - : AssetGenerationSettings.fromJson( - Map.from(v as Map))), - ); - return val; - }, - ); +Config _$ConfigFromJson(Map json) => + $checkedCreate('Config', json, ($checkedConvert) { + final val = Config( + packageName: $checkedConvert('packageName', (v) => v as String?), + fileId: $checkedConvert('fileId', (v) => v as String?), + packageDescription: $checkedConvert( + 'packageDescription', + (v) => + v as String? ?? 'A design tokens package, generated by figmage', + ), + dropUnresolved: $checkedConvert( + 'dropUnresolved', + (v) => v as bool? ?? false, + ), + includeDeletedButReferenced: $checkedConvert( + 'includeDeletedButReferenced', + (v) => v as bool? ?? false, + ), + stylesFromLibrary: $checkedConvert( + 'stylesFromLibrary', + (v) => v as bool? ?? false, + ), + asPackage: $checkedConvert('asPackage', (v) => v as bool? ?? true), + tokenPath: $checkedConvert('tokenPath', (v) => v as String? ?? 'src'), + colors: $checkedConvert( + 'colors', + (v) => v == null + ? const GenerationSettings() + : GenerationSettings.fromJson(v as Map), + ), + typography: $checkedConvert( + 'typography', + (v) => v == null + ? const TypographyGenerationSettings() + : TypographyGenerationSettings.fromJson(v as Map), + ), + strings: $checkedConvert( + 'strings', + (v) => v == null + ? const GenerationSettings() + : GenerationSettings.fromJson(v as Map), + ), + bools: $checkedConvert( + 'bools', + (v) => v == null + ? const GenerationSettings() + : GenerationSettings.fromJson(v as Map), + ), + numbers: $checkedConvert( + 'numbers', + (v) => v == null + ? const GenerationSettings() + : GenerationSettings.fromJson(v as Map), + ), + spacers: $checkedConvert( + 'spacers', + (v) => v == null + ? const GenerationSettings(generate: false) + : GenerationSettings.fromJson(v as Map), + ), + paddings: $checkedConvert( + 'paddings', + (v) => v == null + ? const GenerationSettings(generate: false) + : GenerationSettings.fromJson(v as Map), + ), + radii: $checkedConvert( + 'radii', + (v) => v == null + ? const GenerationSettings(generate: false) + : GenerationSettings.fromJson(v as Map), + ), + assets: $checkedConvert( + 'assets', + (v) => v == null + ? const AssetGenerationSettings() + : AssetGenerationSettings.fromJson( + Map.from(v as Map), + ), + ), + ); + return val; + }); Map _$ConfigToJson(Config instance) => { - 'packageName': instance.packageName, - 'fileId': instance.fileId, - 'packageDescription': instance.packageDescription, - 'dropUnresolved': instance.dropUnresolved, - 'includeDeletedButReferenced': instance.includeDeletedButReferenced, - 'stylesFromLibrary': instance.stylesFromLibrary, - 'asPackage': instance.asPackage, - 'tokenPath': instance.tokenPath, - 'colors': instance.colors.toJson(), - 'typography': instance.typography.toJson(), - 'strings': instance.strings.toJson(), - 'bools': instance.bools.toJson(), - 'numbers': instance.numbers.toJson(), - 'spacers': instance.spacers.toJson(), - 'paddings': instance.paddings.toJson(), - 'radii': instance.radii.toJson(), - 'assets': instance.assets.toJson(), - }; + 'packageName': instance.packageName, + 'fileId': instance.fileId, + 'packageDescription': instance.packageDescription, + 'dropUnresolved': instance.dropUnresolved, + 'includeDeletedButReferenced': instance.includeDeletedButReferenced, + 'stylesFromLibrary': instance.stylesFromLibrary, + 'asPackage': instance.asPackage, + 'tokenPath': instance.tokenPath, + 'colors': instance.colors.toJson(), + 'typography': instance.typography.toJson(), + 'strings': instance.strings.toJson(), + 'bools': instance.bools.toJson(), + 'numbers': instance.numbers.toJson(), + 'spacers': instance.spacers.toJson(), + 'paddings': instance.paddings.toJson(), + 'radii': instance.radii.toJson(), + 'assets': instance.assets.toJson(), +}; -GenerationSettings _$GenerationSettingsFromJson(Map json) => $checkedCreate( - 'GenerationSettings', - json, - ($checkedConvert) { - final val = GenerationSettings( - generate: $checkedConvert('generate', (v) => v as bool? ?? true), - from: $checkedConvert( - 'from', - (v) => - (v as List?)?.map((e) => e as String) ?? const []), - inheritance: $checkedConvert( - 'inheritance', - (v) => - (v as List?)?.map((e) => - InheritanceSettings.fromJson( - Map.from(e as Map))) ?? - const []), - ); - return val; - }, - ); +GenerationSettings _$GenerationSettingsFromJson(Map json) => + $checkedCreate('GenerationSettings', json, ($checkedConvert) { + final val = GenerationSettings( + generate: $checkedConvert('generate', (v) => v as bool? ?? true), + from: $checkedConvert( + 'from', + (v) => (v as List?)?.map((e) => e as String) ?? const [], + ), + inheritance: $checkedConvert( + 'inheritance', + (v) => + (v as List?)?.map( + (e) => InheritanceSettings.fromJson( + Map.from(e as Map), + ), + ) ?? + const [], + ), + ); + return val; + }); Map _$GenerationSettingsToJson(GenerationSettings instance) => { @@ -127,102 +140,98 @@ Map _$GenerationSettingsToJson(GenerationSettings instance) => }; TypographyGenerationSettings _$TypographyGenerationSettingsFromJson(Map json) => - $checkedCreate( - 'TypographyGenerationSettings', - json, - ($checkedConvert) { - final val = TypographyGenerationSettings( - generate: $checkedConvert('generate', (v) => v as bool? ?? true), - from: $checkedConvert( - 'from', - (v) => - (v as List?)?.map((e) => e as String) ?? const []), - inheritance: $checkedConvert( - 'inheritance', - (v) => - (v as List?)?.map((e) => - InheritanceSettings.fromJson( - Map.from(e as Map))) ?? - const []), - useGoogleFonts: - $checkedConvert('useGoogleFonts', (v) => v as bool? ?? true), - ); - return val; - }, - ); + $checkedCreate('TypographyGenerationSettings', json, ($checkedConvert) { + final val = TypographyGenerationSettings( + generate: $checkedConvert('generate', (v) => v as bool? ?? true), + from: $checkedConvert( + 'from', + (v) => (v as List?)?.map((e) => e as String) ?? const [], + ), + inheritance: $checkedConvert( + 'inheritance', + (v) => + (v as List?)?.map( + (e) => InheritanceSettings.fromJson( + Map.from(e as Map), + ), + ) ?? + const [], + ), + useGoogleFonts: $checkedConvert( + 'useGoogleFonts', + (v) => v as bool? ?? true, + ), + ); + return val; + }); Map _$TypographyGenerationSettingsToJson( - TypographyGenerationSettings instance) => - { - 'generate': instance.generate, - 'from': instance.from.toList(), - 'inheritance': instance.inheritance.toList(), - 'useGoogleFonts': instance.useGoogleFonts, - }; + TypographyGenerationSettings instance, +) => { + 'generate': instance.generate, + 'from': instance.from.toList(), + 'inheritance': instance.inheritance.toList(), + 'useGoogleFonts': instance.useGoogleFonts, +}; InheritanceSettings _$InheritanceSettingsFromJson(Map json) => $checkedCreate( - 'InheritanceSettings', - json, - ($checkedConvert) { - final val = InheritanceSettings( - collections: $checkedConvert( - 'collections', - (v) => - (v as List?)?.map((e) => e as String).toList() ?? - const []), - interfaces: $checkedConvert( - 'interfaces', - (v) => - (v as List?) - ?.map((e) => InterfaceSettings.fromJson( - Map.from(e as Map))) - .toList() ?? - const []), - ); - return val; - }, + 'InheritanceSettings', + json, + ($checkedConvert) { + final val = InheritanceSettings( + collections: $checkedConvert( + 'collections', + (v) => + (v as List?)?.map((e) => e as String).toList() ?? const [], + ), + interfaces: $checkedConvert( + 'interfaces', + (v) => + (v as List?) + ?.map( + (e) => InterfaceSettings.fromJson( + Map.from(e as Map), + ), + ) + .toList() ?? + const [], + ), ); + return val; + }, +); Map _$InheritanceSettingsToJson( - InheritanceSettings instance) => - { - 'collections': instance.collections, - 'interfaces': instance.interfaces, - }; + InheritanceSettings instance, +) => { + 'collections': instance.collections, + 'interfaces': instance.interfaces, +}; -InterfaceSettings _$InterfaceSettingsFromJson(Map json) => $checkedCreate( - 'InterfaceSettings', - json, - ($checkedConvert) { - final val = InterfaceSettings( - name: $checkedConvert('name', (v) => v as String), - import: $checkedConvert('import', (v) => v as String), - ); - return val; - }, - ); +InterfaceSettings _$InterfaceSettingsFromJson(Map json) => + $checkedCreate('InterfaceSettings', json, ($checkedConvert) { + final val = InterfaceSettings( + name: $checkedConvert('name', (v) => v as String), + import: $checkedConvert('import', (v) => v as String), + ); + return val; + }); Map _$InterfaceSettingsToJson(InterfaceSettings instance) => - { - 'name': instance.name, - 'import': instance.import, - }; + {'name': instance.name, 'import': instance.import}; -AssetNodeSettings _$AssetNodeSettingsFromJson(Map json) => $checkedCreate( - 'AssetNodeSettings', - json, - ($checkedConvert) { - final val = AssetNodeSettings( - name: $checkedConvert('name', (v) => v as String), - scales: $checkedConvert( - 'scales', - (v) => - (v as List?)?.map((e) => e as num).toSet() ?? - const {1}), - ); - return val; - }, - ); +AssetNodeSettings _$AssetNodeSettingsFromJson(Map json) => + $checkedCreate('AssetNodeSettings', json, ($checkedConvert) { + final val = AssetNodeSettings( + name: $checkedConvert('name', (v) => v as String), + scales: $checkedConvert( + 'scales', + (v) => + (v as List?)?.map((e) => e as num).toSet() ?? const {1}, + ), + ); + return val; + }); Map _$AssetNodeSettingsToJson(AssetNodeSettings instance) => { @@ -231,30 +240,29 @@ Map _$AssetNodeSettingsToJson(AssetNodeSettings instance) => }; AssetGenerationSettings _$AssetGenerationSettingsFromJson(Map json) => - $checkedCreate( - 'AssetGenerationSettings', - json, - ($checkedConvert) { - final val = AssetGenerationSettings( - generate: $checkedConvert('generate', (v) => v as bool? ?? false), - nodes: $checkedConvert( - 'nodes', - (v) => - (v as Map?)?.map( - (k, e) => MapEntry( - k as String, - AssetNodeSettings.fromJson( - Map.from(e as Map))), - ) ?? - const {}), - ); - return val; - }, - ); + $checkedCreate('AssetGenerationSettings', json, ($checkedConvert) { + final val = AssetGenerationSettings( + generate: $checkedConvert('generate', (v) => v as bool? ?? false), + nodes: $checkedConvert( + 'nodes', + (v) => + (v as Map?)?.map( + (k, e) => MapEntry( + k as String, + AssetNodeSettings.fromJson( + Map.from(e as Map), + ), + ), + ) ?? + const {}, + ), + ); + return val; + }); Map _$AssetGenerationSettingsToJson( - AssetGenerationSettings instance) => - { - 'generate': instance.generate, - 'nodes': instance.nodes.map((k, e) => MapEntry(k, e.toJson())), - }; + AssetGenerationSettings instance, +) => { + 'generate': instance.generate, + 'nodes': instance.nodes.map((k, e) => MapEntry(k, e.toJson())), +}; diff --git a/lib/src/domain/models/tokens_by_file_type/tokens_by_type.freezed.dart b/lib/src/domain/models/tokens_by_file_type/tokens_by_type.freezed.dart index ac926659..b4cb70ea 100644 --- a/lib/src/domain/models/tokens_by_file_type/tokens_by_type.freezed.dart +++ b/lib/src/domain/models/tokens_by_file_type/tokens_by_type.freezed.dart @@ -11,369 +11,245 @@ part of 'tokens_by_type.dart'; // dart format off T _$identity(T value) => value; - /// @nodoc mixin _$TokensByType { - Iterable> get colorTokens; - Iterable> get typographyTokens; - Iterable> get numberTokens; - Iterable> get stringTokens; - Iterable> get boolTokens; - - /// Create a copy of TokensByType - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @pragma('vm:prefer-inline') - $TokensByTypeCopyWith get copyWith => - _$TokensByTypeCopyWithImpl( - this as TokensByType, _$identity); - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is TokensByType && - const DeepCollectionEquality() - .equals(other.colorTokens, colorTokens) && - const DeepCollectionEquality() - .equals(other.typographyTokens, typographyTokens) && - const DeepCollectionEquality() - .equals(other.numberTokens, numberTokens) && - const DeepCollectionEquality() - .equals(other.stringTokens, stringTokens) && - const DeepCollectionEquality() - .equals(other.boolTokens, boolTokens)); - } - - @override - int get hashCode => Object.hash( - runtimeType, - const DeepCollectionEquality().hash(colorTokens), - const DeepCollectionEquality().hash(typographyTokens), - const DeepCollectionEquality().hash(numberTokens), - const DeepCollectionEquality().hash(stringTokens), - const DeepCollectionEquality().hash(boolTokens)); - - @override - String toString() { - return 'TokensByType(colorTokens: $colorTokens, typographyTokens: $typographyTokens, numberTokens: $numberTokens, stringTokens: $stringTokens, boolTokens: $boolTokens)'; - } + + Iterable> get colorTokens; Iterable> get typographyTokens; Iterable> get numberTokens; Iterable> get stringTokens; Iterable> get boolTokens; +/// Create a copy of TokensByType +/// with the given fields replaced by the non-null parameter values. +@JsonKey(includeFromJson: false, includeToJson: false) +@pragma('vm:prefer-inline') +$TokensByTypeCopyWith get copyWith => _$TokensByTypeCopyWithImpl(this as TokensByType, _$identity); + + + +@override +bool operator ==(Object other) { + return identical(this, other) || (other.runtimeType == runtimeType&&other is TokensByType&&const DeepCollectionEquality().equals(other.colorTokens, colorTokens)&&const DeepCollectionEquality().equals(other.typographyTokens, typographyTokens)&&const DeepCollectionEquality().equals(other.numberTokens, numberTokens)&&const DeepCollectionEquality().equals(other.stringTokens, stringTokens)&&const DeepCollectionEquality().equals(other.boolTokens, boolTokens)); } -/// @nodoc -abstract mixin class $TokensByTypeCopyWith<$Res> { - factory $TokensByTypeCopyWith( - TokensByType value, $Res Function(TokensByType) _then) = - _$TokensByTypeCopyWithImpl; - @useResult - $Res call( - {Iterable> colorTokens, - Iterable> typographyTokens, - Iterable> numberTokens, - Iterable> stringTokens, - Iterable> boolTokens}); + +@override +int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(colorTokens),const DeepCollectionEquality().hash(typographyTokens),const DeepCollectionEquality().hash(numberTokens),const DeepCollectionEquality().hash(stringTokens),const DeepCollectionEquality().hash(boolTokens)); + +@override +String toString() { + return 'TokensByType(colorTokens: $colorTokens, typographyTokens: $typographyTokens, numberTokens: $numberTokens, stringTokens: $stringTokens, boolTokens: $boolTokens)'; +} + + } /// @nodoc -class _$TokensByTypeCopyWithImpl<$Res> implements $TokensByTypeCopyWith<$Res> { +abstract mixin class $TokensByTypeCopyWith<$Res> { + factory $TokensByTypeCopyWith(TokensByType value, $Res Function(TokensByType) _then) = _$TokensByTypeCopyWithImpl; +@useResult +$Res call({ + Iterable> colorTokens, Iterable> typographyTokens, Iterable> numberTokens, Iterable> stringTokens, Iterable> boolTokens +}); + + + + +} +/// @nodoc +class _$TokensByTypeCopyWithImpl<$Res> + implements $TokensByTypeCopyWith<$Res> { _$TokensByTypeCopyWithImpl(this._self, this._then); final TokensByType _self; final $Res Function(TokensByType) _then; - /// Create a copy of TokensByType - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? colorTokens = null, - Object? typographyTokens = null, - Object? numberTokens = null, - Object? stringTokens = null, - Object? boolTokens = null, - }) { - return _then(_self.copyWith( - colorTokens: null == colorTokens - ? _self.colorTokens - : colorTokens // ignore: cast_nullable_to_non_nullable - as Iterable>, - typographyTokens: null == typographyTokens - ? _self.typographyTokens - : typographyTokens // ignore: cast_nullable_to_non_nullable - as Iterable>, - numberTokens: null == numberTokens - ? _self.numberTokens - : numberTokens // ignore: cast_nullable_to_non_nullable - as Iterable>, - stringTokens: null == stringTokens - ? _self.stringTokens - : stringTokens // ignore: cast_nullable_to_non_nullable - as Iterable>, - boolTokens: null == boolTokens - ? _self.boolTokens - : boolTokens // ignore: cast_nullable_to_non_nullable - as Iterable>, - )); - } +/// Create a copy of TokensByType +/// with the given fields replaced by the non-null parameter values. +@pragma('vm:prefer-inline') @override $Res call({Object? colorTokens = null,Object? typographyTokens = null,Object? numberTokens = null,Object? stringTokens = null,Object? boolTokens = null,}) { + return _then(_self.copyWith( +colorTokens: null == colorTokens ? _self.colorTokens : colorTokens // ignore: cast_nullable_to_non_nullable +as Iterable>,typographyTokens: null == typographyTokens ? _self.typographyTokens : typographyTokens // ignore: cast_nullable_to_non_nullable +as Iterable>,numberTokens: null == numberTokens ? _self.numberTokens : numberTokens // ignore: cast_nullable_to_non_nullable +as Iterable>,stringTokens: null == stringTokens ? _self.stringTokens : stringTokens // ignore: cast_nullable_to_non_nullable +as Iterable>,boolTokens: null == boolTokens ? _self.boolTokens : boolTokens // ignore: cast_nullable_to_non_nullable +as Iterable>, + )); } +} + + /// Adds pattern-matching-related methods to [TokensByType]. extension TokensByTypePatterns on TokensByType { - /// A variant of `map` that fallback to returning `orElse`. - /// - /// It is equivalent to doing: - /// ```dart - /// switch (sealedClass) { - /// case final Subclass value: - /// return ...; - /// case _: - /// return orElse(); - /// } - /// ``` - - @optionalTypeArgs - TResult maybeMap( - TResult Function(_TokensByType value)? $default, { - required TResult orElse(), - }) { - final _that = this; - switch (_that) { - case _TokensByType() when $default != null: - return $default(_that); - case _: - return orElse(); - } - } - - /// A `switch`-like method, using callbacks. - /// - /// Callbacks receives the raw object, upcasted. - /// It is equivalent to doing: - /// ```dart - /// switch (sealedClass) { - /// case final Subclass value: - /// return ...; - /// case final Subclass2 value: - /// return ...; - /// } - /// ``` - - @optionalTypeArgs - TResult map( - TResult Function(_TokensByType value) $default, - ) { - final _that = this; - switch (_that) { - case _TokensByType(): - return $default(_that); - } - } - - /// A variant of `map` that fallback to returning `null`. - /// - /// It is equivalent to doing: - /// ```dart - /// switch (sealedClass) { - /// case final Subclass value: - /// return ...; - /// case _: - /// return null; - /// } - /// ``` - - @optionalTypeArgs - TResult? mapOrNull( - TResult? Function(_TokensByType value)? $default, - ) { - final _that = this; - switch (_that) { - case _TokensByType() when $default != null: - return $default(_that); - case _: - return null; - } - } - - /// A variant of `when` that fallback to an `orElse` callback. - /// - /// It is equivalent to doing: - /// ```dart - /// switch (sealedClass) { - /// case Subclass(:final field): - /// return ...; - /// case _: - /// return orElse(); - /// } - /// ``` - - @optionalTypeArgs - TResult maybeWhen( - TResult Function( - Iterable> colorTokens, - Iterable> typographyTokens, - Iterable> numberTokens, - Iterable> stringTokens, - Iterable> boolTokens)? - $default, { - required TResult orElse(), - }) { - final _that = this; - switch (_that) { - case _TokensByType() when $default != null: - return $default(_that.colorTokens, _that.typographyTokens, - _that.numberTokens, _that.stringTokens, _that.boolTokens); - case _: - return orElse(); - } - } - - /// A `switch`-like method, using callbacks. - /// - /// As opposed to `map`, this offers destructuring. - /// It is equivalent to doing: - /// ```dart - /// switch (sealedClass) { - /// case Subclass(:final field): - /// return ...; - /// case Subclass2(:final field2): - /// return ...; - /// } - /// ``` - - @optionalTypeArgs - TResult when( - TResult Function( - Iterable> colorTokens, - Iterable> typographyTokens, - Iterable> numberTokens, - Iterable> stringTokens, - Iterable> boolTokens) - $default, - ) { - final _that = this; - switch (_that) { - case _TokensByType(): - return $default(_that.colorTokens, _that.typographyTokens, - _that.numberTokens, _that.stringTokens, _that.boolTokens); - } - } - - /// A variant of `when` that fallback to returning `null` - /// - /// It is equivalent to doing: - /// ```dart - /// switch (sealedClass) { - /// case Subclass(:final field): - /// return ...; - /// case _: - /// return null; - /// } - /// ``` - - @optionalTypeArgs - TResult? whenOrNull( - TResult? Function( - Iterable> colorTokens, - Iterable> typographyTokens, - Iterable> numberTokens, - Iterable> stringTokens, - Iterable> boolTokens)? - $default, - ) { - final _that = this; - switch (_that) { - case _TokensByType() when $default != null: - return $default(_that.colorTokens, _that.typographyTokens, - _that.numberTokens, _that.stringTokens, _that.boolTokens); - case _: - return null; - } - } +/// A variant of `map` that fallback to returning `orElse`. +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case final Subclass value: +/// return ...; +/// case _: +/// return orElse(); +/// } +/// ``` + +@optionalTypeArgs TResult maybeMap(TResult Function( _TokensByType value)? $default,{required TResult orElse(),}){ +final _that = this; +switch (_that) { +case _TokensByType() when $default != null: +return $default(_that);case _: + return orElse(); + +} +} +/// A `switch`-like method, using callbacks. +/// +/// Callbacks receives the raw object, upcasted. +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case final Subclass value: +/// return ...; +/// case final Subclass2 value: +/// return ...; +/// } +/// ``` + +@optionalTypeArgs TResult map(TResult Function( _TokensByType value) $default,){ +final _that = this; +switch (_that) { +case _TokensByType(): +return $default(_that);} +} +/// A variant of `map` that fallback to returning `null`. +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case final Subclass value: +/// return ...; +/// case _: +/// return null; +/// } +/// ``` + +@optionalTypeArgs TResult? mapOrNull(TResult? Function( _TokensByType value)? $default,){ +final _that = this; +switch (_that) { +case _TokensByType() when $default != null: +return $default(_that);case _: + return null; + +} +} +/// A variant of `when` that fallback to an `orElse` callback. +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case Subclass(:final field): +/// return ...; +/// case _: +/// return orElse(); +/// } +/// ``` + +@optionalTypeArgs TResult maybeWhen(TResult Function( Iterable> colorTokens, Iterable> typographyTokens, Iterable> numberTokens, Iterable> stringTokens, Iterable> boolTokens)? $default,{required TResult orElse(),}) {final _that = this; +switch (_that) { +case _TokensByType() when $default != null: +return $default(_that.colorTokens,_that.typographyTokens,_that.numberTokens,_that.stringTokens,_that.boolTokens);case _: + return orElse(); + +} +} +/// A `switch`-like method, using callbacks. +/// +/// As opposed to `map`, this offers destructuring. +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case Subclass(:final field): +/// return ...; +/// case Subclass2(:final field2): +/// return ...; +/// } +/// ``` + +@optionalTypeArgs TResult when(TResult Function( Iterable> colorTokens, Iterable> typographyTokens, Iterable> numberTokens, Iterable> stringTokens, Iterable> boolTokens) $default,) {final _that = this; +switch (_that) { +case _TokensByType(): +return $default(_that.colorTokens,_that.typographyTokens,_that.numberTokens,_that.stringTokens,_that.boolTokens);} +} +/// A variant of `when` that fallback to returning `null` +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case Subclass(:final field): +/// return ...; +/// case _: +/// return null; +/// } +/// ``` + +@optionalTypeArgs TResult? whenOrNull(TResult? Function( Iterable> colorTokens, Iterable> typographyTokens, Iterable> numberTokens, Iterable> stringTokens, Iterable> boolTokens)? $default,) {final _that = this; +switch (_that) { +case _TokensByType() when $default != null: +return $default(_that.colorTokens,_that.typographyTokens,_that.numberTokens,_that.stringTokens,_that.boolTokens);case _: + return null; + +} +} + } /// @nodoc + class _TokensByType extends TokensByType { - const _TokensByType( - {this.colorTokens = const [], - this.typographyTokens = const [], - this.numberTokens = const [], - this.stringTokens = const [], - this.boolTokens = const []}) - : super._(); - - @override - @JsonKey() - final Iterable> colorTokens; - @override - @JsonKey() - final Iterable> typographyTokens; - @override - @JsonKey() - final Iterable> numberTokens; - @override - @JsonKey() - final Iterable> stringTokens; - @override - @JsonKey() - final Iterable> boolTokens; - - /// Create a copy of TokensByType - /// with the given fields replaced by the non-null parameter values. - @override - @JsonKey(includeFromJson: false, includeToJson: false) - @pragma('vm:prefer-inline') - _$TokensByTypeCopyWith<_TokensByType> get copyWith => - __$TokensByTypeCopyWithImpl<_TokensByType>(this, _$identity); - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _TokensByType && - const DeepCollectionEquality() - .equals(other.colorTokens, colorTokens) && - const DeepCollectionEquality() - .equals(other.typographyTokens, typographyTokens) && - const DeepCollectionEquality() - .equals(other.numberTokens, numberTokens) && - const DeepCollectionEquality() - .equals(other.stringTokens, stringTokens) && - const DeepCollectionEquality() - .equals(other.boolTokens, boolTokens)); - } - - @override - int get hashCode => Object.hash( - runtimeType, - const DeepCollectionEquality().hash(colorTokens), - const DeepCollectionEquality().hash(typographyTokens), - const DeepCollectionEquality().hash(numberTokens), - const DeepCollectionEquality().hash(stringTokens), - const DeepCollectionEquality().hash(boolTokens)); - - @override - String toString() { - return 'TokensByType(colorTokens: $colorTokens, typographyTokens: $typographyTokens, numberTokens: $numberTokens, stringTokens: $stringTokens, boolTokens: $boolTokens)'; - } + const _TokensByType({this.colorTokens = const [], this.typographyTokens = const [], this.numberTokens = const [], this.stringTokens = const [], this.boolTokens = const []}): super._(); + + +@override@JsonKey() final Iterable> colorTokens; +@override@JsonKey() final Iterable> typographyTokens; +@override@JsonKey() final Iterable> numberTokens; +@override@JsonKey() final Iterable> stringTokens; +@override@JsonKey() final Iterable> boolTokens; + +/// Create a copy of TokensByType +/// with the given fields replaced by the non-null parameter values. +@override @JsonKey(includeFromJson: false, includeToJson: false) +@pragma('vm:prefer-inline') +_$TokensByTypeCopyWith<_TokensByType> get copyWith => __$TokensByTypeCopyWithImpl<_TokensByType>(this, _$identity); + + + +@override +bool operator ==(Object other) { + return identical(this, other) || (other.runtimeType == runtimeType&&other is _TokensByType&&const DeepCollectionEquality().equals(other.colorTokens, colorTokens)&&const DeepCollectionEquality().equals(other.typographyTokens, typographyTokens)&&const DeepCollectionEquality().equals(other.numberTokens, numberTokens)&&const DeepCollectionEquality().equals(other.stringTokens, stringTokens)&&const DeepCollectionEquality().equals(other.boolTokens, boolTokens)); } -/// @nodoc -abstract mixin class _$TokensByTypeCopyWith<$Res> - implements $TokensByTypeCopyWith<$Res> { - factory _$TokensByTypeCopyWith( - _TokensByType value, $Res Function(_TokensByType) _then) = - __$TokensByTypeCopyWithImpl; - @override - @useResult - $Res call( - {Iterable> colorTokens, - Iterable> typographyTokens, - Iterable> numberTokens, - Iterable> stringTokens, - Iterable> boolTokens}); + +@override +int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(colorTokens),const DeepCollectionEquality().hash(typographyTokens),const DeepCollectionEquality().hash(numberTokens),const DeepCollectionEquality().hash(stringTokens),const DeepCollectionEquality().hash(boolTokens)); + +@override +String toString() { + return 'TokensByType(colorTokens: $colorTokens, typographyTokens: $typographyTokens, numberTokens: $numberTokens, stringTokens: $stringTokens, boolTokens: $boolTokens)'; } + +} + +/// @nodoc +abstract mixin class _$TokensByTypeCopyWith<$Res> implements $TokensByTypeCopyWith<$Res> { + factory _$TokensByTypeCopyWith(_TokensByType value, $Res Function(_TokensByType) _then) = __$TokensByTypeCopyWithImpl; +@override @useResult +$Res call({ + Iterable> colorTokens, Iterable> typographyTokens, Iterable> numberTokens, Iterable> stringTokens, Iterable> boolTokens +}); + + + + +} /// @nodoc class __$TokensByTypeCopyWithImpl<$Res> implements _$TokensByTypeCopyWith<$Res> { @@ -382,40 +258,20 @@ class __$TokensByTypeCopyWithImpl<$Res> final _TokensByType _self; final $Res Function(_TokensByType) _then; - /// Create a copy of TokensByType - /// with the given fields replaced by the non-null parameter values. - @override - @pragma('vm:prefer-inline') - $Res call({ - Object? colorTokens = null, - Object? typographyTokens = null, - Object? numberTokens = null, - Object? stringTokens = null, - Object? boolTokens = null, - }) { - return _then(_TokensByType( - colorTokens: null == colorTokens - ? _self.colorTokens - : colorTokens // ignore: cast_nullable_to_non_nullable - as Iterable>, - typographyTokens: null == typographyTokens - ? _self.typographyTokens - : typographyTokens // ignore: cast_nullable_to_non_nullable - as Iterable>, - numberTokens: null == numberTokens - ? _self.numberTokens - : numberTokens // ignore: cast_nullable_to_non_nullable - as Iterable>, - stringTokens: null == stringTokens - ? _self.stringTokens - : stringTokens // ignore: cast_nullable_to_non_nullable - as Iterable>, - boolTokens: null == boolTokens - ? _self.boolTokens - : boolTokens // ignore: cast_nullable_to_non_nullable - as Iterable>, - )); - } +/// Create a copy of TokensByType +/// with the given fields replaced by the non-null parameter values. +@override @pragma('vm:prefer-inline') $Res call({Object? colorTokens = null,Object? typographyTokens = null,Object? numberTokens = null,Object? stringTokens = null,Object? boolTokens = null,}) { + return _then(_TokensByType( +colorTokens: null == colorTokens ? _self.colorTokens : colorTokens // ignore: cast_nullable_to_non_nullable +as Iterable>,typographyTokens: null == typographyTokens ? _self.typographyTokens : typographyTokens // ignore: cast_nullable_to_non_nullable +as Iterable>,numberTokens: null == numberTokens ? _self.numberTokens : numberTokens // ignore: cast_nullable_to_non_nullable +as Iterable>,stringTokens: null == stringTokens ? _self.stringTokens : stringTokens // ignore: cast_nullable_to_non_nullable +as Iterable>,boolTokens: null == boolTokens ? _self.boolTokens : boolTokens // ignore: cast_nullable_to_non_nullable +as Iterable>, + )); +} + + } // dart format on diff --git a/lib/src/domain/models/typography/typography.freezed.dart b/lib/src/domain/models/typography/typography.freezed.dart index 25fc6077..a2b7f6e4 100644 --- a/lib/src/domain/models/typography/typography.freezed.dart +++ b/lib/src/domain/models/typography/typography.freezed.dart @@ -11,534 +11,279 @@ part of 'typography.dart'; // dart format off T _$identity(T value) => value; - /// @nodoc mixin _$Typography { - String get fontFamily; - String? get fontFamilyPostScriptName; - double get fontSize; - int get fontWeight; - TextDecoration get decoration; - FontStyle get fontStyle; - double get letterSpacing; - double get wordSpacing; - double get height; - - /// Create a copy of Typography - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @pragma('vm:prefer-inline') - $TypographyCopyWith get copyWith => - _$TypographyCopyWithImpl(this as Typography, _$identity); - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is Typography && - (identical(other.fontFamily, fontFamily) || - other.fontFamily == fontFamily) && - (identical( - other.fontFamilyPostScriptName, fontFamilyPostScriptName) || - other.fontFamilyPostScriptName == fontFamilyPostScriptName) && - (identical(other.fontSize, fontSize) || - other.fontSize == fontSize) && - (identical(other.fontWeight, fontWeight) || - other.fontWeight == fontWeight) && - (identical(other.decoration, decoration) || - other.decoration == decoration) && - (identical(other.fontStyle, fontStyle) || - other.fontStyle == fontStyle) && - (identical(other.letterSpacing, letterSpacing) || - other.letterSpacing == letterSpacing) && - (identical(other.wordSpacing, wordSpacing) || - other.wordSpacing == wordSpacing) && - (identical(other.height, height) || other.height == height)); - } - - @override - int get hashCode => Object.hash( - runtimeType, - fontFamily, - fontFamilyPostScriptName, - fontSize, - fontWeight, - decoration, - fontStyle, - letterSpacing, - wordSpacing, - height); - - @override - String toString() { - return 'Typography(fontFamily: $fontFamily, fontFamilyPostScriptName: $fontFamilyPostScriptName, fontSize: $fontSize, fontWeight: $fontWeight, decoration: $decoration, fontStyle: $fontStyle, letterSpacing: $letterSpacing, wordSpacing: $wordSpacing, height: $height)'; - } + + String get fontFamily; String? get fontFamilyPostScriptName; double get fontSize; int get fontWeight; TextDecoration get decoration; FontStyle get fontStyle; double get letterSpacing; double get wordSpacing; double get height; +/// Create a copy of Typography +/// with the given fields replaced by the non-null parameter values. +@JsonKey(includeFromJson: false, includeToJson: false) +@pragma('vm:prefer-inline') +$TypographyCopyWith get copyWith => _$TypographyCopyWithImpl(this as Typography, _$identity); + + + +@override +bool operator ==(Object other) { + return identical(this, other) || (other.runtimeType == runtimeType&&other is Typography&&(identical(other.fontFamily, fontFamily) || other.fontFamily == fontFamily)&&(identical(other.fontFamilyPostScriptName, fontFamilyPostScriptName) || other.fontFamilyPostScriptName == fontFamilyPostScriptName)&&(identical(other.fontSize, fontSize) || other.fontSize == fontSize)&&(identical(other.fontWeight, fontWeight) || other.fontWeight == fontWeight)&&(identical(other.decoration, decoration) || other.decoration == decoration)&&(identical(other.fontStyle, fontStyle) || other.fontStyle == fontStyle)&&(identical(other.letterSpacing, letterSpacing) || other.letterSpacing == letterSpacing)&&(identical(other.wordSpacing, wordSpacing) || other.wordSpacing == wordSpacing)&&(identical(other.height, height) || other.height == height)); } -/// @nodoc -abstract mixin class $TypographyCopyWith<$Res> { - factory $TypographyCopyWith( - Typography value, $Res Function(Typography) _then) = - _$TypographyCopyWithImpl; - @useResult - $Res call( - {String fontFamily, - String? fontFamilyPostScriptName, - double fontSize, - int fontWeight, - TextDecoration decoration, - FontStyle fontStyle, - double letterSpacing, - double wordSpacing, - double height}); + +@override +int get hashCode => Object.hash(runtimeType,fontFamily,fontFamilyPostScriptName,fontSize,fontWeight,decoration,fontStyle,letterSpacing,wordSpacing,height); + +@override +String toString() { + return 'Typography(fontFamily: $fontFamily, fontFamilyPostScriptName: $fontFamilyPostScriptName, fontSize: $fontSize, fontWeight: $fontWeight, decoration: $decoration, fontStyle: $fontStyle, letterSpacing: $letterSpacing, wordSpacing: $wordSpacing, height: $height)'; +} + + } /// @nodoc -class _$TypographyCopyWithImpl<$Res> implements $TypographyCopyWith<$Res> { +abstract mixin class $TypographyCopyWith<$Res> { + factory $TypographyCopyWith(Typography value, $Res Function(Typography) _then) = _$TypographyCopyWithImpl; +@useResult +$Res call({ + String fontFamily, String? fontFamilyPostScriptName, double fontSize, int fontWeight, TextDecoration decoration, FontStyle fontStyle, double letterSpacing, double wordSpacing, double height +}); + + + + +} +/// @nodoc +class _$TypographyCopyWithImpl<$Res> + implements $TypographyCopyWith<$Res> { _$TypographyCopyWithImpl(this._self, this._then); final Typography _self; final $Res Function(Typography) _then; - /// Create a copy of Typography - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? fontFamily = null, - Object? fontFamilyPostScriptName = freezed, - Object? fontSize = null, - Object? fontWeight = null, - Object? decoration = null, - Object? fontStyle = null, - Object? letterSpacing = null, - Object? wordSpacing = null, - Object? height = null, - }) { - return _then(_self.copyWith( - fontFamily: null == fontFamily - ? _self.fontFamily - : fontFamily // ignore: cast_nullable_to_non_nullable - as String, - fontFamilyPostScriptName: freezed == fontFamilyPostScriptName - ? _self.fontFamilyPostScriptName - : fontFamilyPostScriptName // ignore: cast_nullable_to_non_nullable - as String?, - fontSize: null == fontSize - ? _self.fontSize - : fontSize // ignore: cast_nullable_to_non_nullable - as double, - fontWeight: null == fontWeight - ? _self.fontWeight - : fontWeight // ignore: cast_nullable_to_non_nullable - as int, - decoration: null == decoration - ? _self.decoration - : decoration // ignore: cast_nullable_to_non_nullable - as TextDecoration, - fontStyle: null == fontStyle - ? _self.fontStyle - : fontStyle // ignore: cast_nullable_to_non_nullable - as FontStyle, - letterSpacing: null == letterSpacing - ? _self.letterSpacing - : letterSpacing // ignore: cast_nullable_to_non_nullable - as double, - wordSpacing: null == wordSpacing - ? _self.wordSpacing - : wordSpacing // ignore: cast_nullable_to_non_nullable - as double, - height: null == height - ? _self.height - : height // ignore: cast_nullable_to_non_nullable - as double, - )); - } +/// Create a copy of Typography +/// with the given fields replaced by the non-null parameter values. +@pragma('vm:prefer-inline') @override $Res call({Object? fontFamily = null,Object? fontFamilyPostScriptName = freezed,Object? fontSize = null,Object? fontWeight = null,Object? decoration = null,Object? fontStyle = null,Object? letterSpacing = null,Object? wordSpacing = null,Object? height = null,}) { + return _then(_self.copyWith( +fontFamily: null == fontFamily ? _self.fontFamily : fontFamily // ignore: cast_nullable_to_non_nullable +as String,fontFamilyPostScriptName: freezed == fontFamilyPostScriptName ? _self.fontFamilyPostScriptName : fontFamilyPostScriptName // ignore: cast_nullable_to_non_nullable +as String?,fontSize: null == fontSize ? _self.fontSize : fontSize // ignore: cast_nullable_to_non_nullable +as double,fontWeight: null == fontWeight ? _self.fontWeight : fontWeight // ignore: cast_nullable_to_non_nullable +as int,decoration: null == decoration ? _self.decoration : decoration // ignore: cast_nullable_to_non_nullable +as TextDecoration,fontStyle: null == fontStyle ? _self.fontStyle : fontStyle // ignore: cast_nullable_to_non_nullable +as FontStyle,letterSpacing: null == letterSpacing ? _self.letterSpacing : letterSpacing // ignore: cast_nullable_to_non_nullable +as double,wordSpacing: null == wordSpacing ? _self.wordSpacing : wordSpacing // ignore: cast_nullable_to_non_nullable +as double,height: null == height ? _self.height : height // ignore: cast_nullable_to_non_nullable +as double, + )); } +} + + /// Adds pattern-matching-related methods to [Typography]. extension TypographyPatterns on Typography { - /// A variant of `map` that fallback to returning `orElse`. - /// - /// It is equivalent to doing: - /// ```dart - /// switch (sealedClass) { - /// case final Subclass value: - /// return ...; - /// case _: - /// return orElse(); - /// } - /// ``` - - @optionalTypeArgs - TResult maybeMap( - TResult Function(_Typography value)? $default, { - required TResult orElse(), - }) { - final _that = this; - switch (_that) { - case _Typography() when $default != null: - return $default(_that); - case _: - return orElse(); - } - } - - /// A `switch`-like method, using callbacks. - /// - /// Callbacks receives the raw object, upcasted. - /// It is equivalent to doing: - /// ```dart - /// switch (sealedClass) { - /// case final Subclass value: - /// return ...; - /// case final Subclass2 value: - /// return ...; - /// } - /// ``` - - @optionalTypeArgs - TResult map( - TResult Function(_Typography value) $default, - ) { - final _that = this; - switch (_that) { - case _Typography(): - return $default(_that); - } - } - - /// A variant of `map` that fallback to returning `null`. - /// - /// It is equivalent to doing: - /// ```dart - /// switch (sealedClass) { - /// case final Subclass value: - /// return ...; - /// case _: - /// return null; - /// } - /// ``` - - @optionalTypeArgs - TResult? mapOrNull( - TResult? Function(_Typography value)? $default, - ) { - final _that = this; - switch (_that) { - case _Typography() when $default != null: - return $default(_that); - case _: - return null; - } - } - - /// A variant of `when` that fallback to an `orElse` callback. - /// - /// It is equivalent to doing: - /// ```dart - /// switch (sealedClass) { - /// case Subclass(:final field): - /// return ...; - /// case _: - /// return orElse(); - /// } - /// ``` - - @optionalTypeArgs - TResult maybeWhen( - TResult Function( - String fontFamily, - String? fontFamilyPostScriptName, - double fontSize, - int fontWeight, - TextDecoration decoration, - FontStyle fontStyle, - double letterSpacing, - double wordSpacing, - double height)? - $default, { - required TResult orElse(), - }) { - final _that = this; - switch (_that) { - case _Typography() when $default != null: - return $default( - _that.fontFamily, - _that.fontFamilyPostScriptName, - _that.fontSize, - _that.fontWeight, - _that.decoration, - _that.fontStyle, - _that.letterSpacing, - _that.wordSpacing, - _that.height); - case _: - return orElse(); - } - } - - /// A `switch`-like method, using callbacks. - /// - /// As opposed to `map`, this offers destructuring. - /// It is equivalent to doing: - /// ```dart - /// switch (sealedClass) { - /// case Subclass(:final field): - /// return ...; - /// case Subclass2(:final field2): - /// return ...; - /// } - /// ``` - - @optionalTypeArgs - TResult when( - TResult Function( - String fontFamily, - String? fontFamilyPostScriptName, - double fontSize, - int fontWeight, - TextDecoration decoration, - FontStyle fontStyle, - double letterSpacing, - double wordSpacing, - double height) - $default, - ) { - final _that = this; - switch (_that) { - case _Typography(): - return $default( - _that.fontFamily, - _that.fontFamilyPostScriptName, - _that.fontSize, - _that.fontWeight, - _that.decoration, - _that.fontStyle, - _that.letterSpacing, - _that.wordSpacing, - _that.height); - } - } - - /// A variant of `when` that fallback to returning `null` - /// - /// It is equivalent to doing: - /// ```dart - /// switch (sealedClass) { - /// case Subclass(:final field): - /// return ...; - /// case _: - /// return null; - /// } - /// ``` - - @optionalTypeArgs - TResult? whenOrNull( - TResult? Function( - String fontFamily, - String? fontFamilyPostScriptName, - double fontSize, - int fontWeight, - TextDecoration decoration, - FontStyle fontStyle, - double letterSpacing, - double wordSpacing, - double height)? - $default, - ) { - final _that = this; - switch (_that) { - case _Typography() when $default != null: - return $default( - _that.fontFamily, - _that.fontFamilyPostScriptName, - _that.fontSize, - _that.fontWeight, - _that.decoration, - _that.fontStyle, - _that.letterSpacing, - _that.wordSpacing, - _that.height); - case _: - return null; - } - } +/// A variant of `map` that fallback to returning `orElse`. +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case final Subclass value: +/// return ...; +/// case _: +/// return orElse(); +/// } +/// ``` + +@optionalTypeArgs TResult maybeMap(TResult Function( _Typography value)? $default,{required TResult orElse(),}){ +final _that = this; +switch (_that) { +case _Typography() when $default != null: +return $default(_that);case _: + return orElse(); + +} +} +/// A `switch`-like method, using callbacks. +/// +/// Callbacks receives the raw object, upcasted. +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case final Subclass value: +/// return ...; +/// case final Subclass2 value: +/// return ...; +/// } +/// ``` + +@optionalTypeArgs TResult map(TResult Function( _Typography value) $default,){ +final _that = this; +switch (_that) { +case _Typography(): +return $default(_that);} +} +/// A variant of `map` that fallback to returning `null`. +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case final Subclass value: +/// return ...; +/// case _: +/// return null; +/// } +/// ``` + +@optionalTypeArgs TResult? mapOrNull(TResult? Function( _Typography value)? $default,){ +final _that = this; +switch (_that) { +case _Typography() when $default != null: +return $default(_that);case _: + return null; + +} +} +/// A variant of `when` that fallback to an `orElse` callback. +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case Subclass(:final field): +/// return ...; +/// case _: +/// return orElse(); +/// } +/// ``` + +@optionalTypeArgs TResult maybeWhen(TResult Function( String fontFamily, String? fontFamilyPostScriptName, double fontSize, int fontWeight, TextDecoration decoration, FontStyle fontStyle, double letterSpacing, double wordSpacing, double height)? $default,{required TResult orElse(),}) {final _that = this; +switch (_that) { +case _Typography() when $default != null: +return $default(_that.fontFamily,_that.fontFamilyPostScriptName,_that.fontSize,_that.fontWeight,_that.decoration,_that.fontStyle,_that.letterSpacing,_that.wordSpacing,_that.height);case _: + return orElse(); + +} +} +/// A `switch`-like method, using callbacks. +/// +/// As opposed to `map`, this offers destructuring. +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case Subclass(:final field): +/// return ...; +/// case Subclass2(:final field2): +/// return ...; +/// } +/// ``` + +@optionalTypeArgs TResult when(TResult Function( String fontFamily, String? fontFamilyPostScriptName, double fontSize, int fontWeight, TextDecoration decoration, FontStyle fontStyle, double letterSpacing, double wordSpacing, double height) $default,) {final _that = this; +switch (_that) { +case _Typography(): +return $default(_that.fontFamily,_that.fontFamilyPostScriptName,_that.fontSize,_that.fontWeight,_that.decoration,_that.fontStyle,_that.letterSpacing,_that.wordSpacing,_that.height);} +} +/// A variant of `when` that fallback to returning `null` +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case Subclass(:final field): +/// return ...; +/// case _: +/// return null; +/// } +/// ``` + +@optionalTypeArgs TResult? whenOrNull(TResult? Function( String fontFamily, String? fontFamilyPostScriptName, double fontSize, int fontWeight, TextDecoration decoration, FontStyle fontStyle, double letterSpacing, double wordSpacing, double height)? $default,) {final _that = this; +switch (_that) { +case _Typography() when $default != null: +return $default(_that.fontFamily,_that.fontFamilyPostScriptName,_that.fontSize,_that.fontWeight,_that.decoration,_that.fontStyle,_that.letterSpacing,_that.wordSpacing,_that.height);case _: + return null; + +} +} + } /// @nodoc + class _Typography extends Typography { - const _Typography( - {required this.fontFamily, - required this.fontFamilyPostScriptName, - required this.fontSize, - this.fontWeight = 400, - this.decoration = TextDecoration.none, - this.fontStyle = FontStyle.normal, - this.letterSpacing = 1.0, - this.wordSpacing = 1.0, - this.height = 1.0}) - : super._(); - - @override - final String fontFamily; - @override - final String? fontFamilyPostScriptName; - @override - final double fontSize; - @override - @JsonKey() - final int fontWeight; - @override - @JsonKey() - final TextDecoration decoration; - @override - @JsonKey() - final FontStyle fontStyle; - @override - @JsonKey() - final double letterSpacing; - @override - @JsonKey() - final double wordSpacing; - @override - @JsonKey() - final double height; - - /// Create a copy of Typography - /// with the given fields replaced by the non-null parameter values. - @override - @JsonKey(includeFromJson: false, includeToJson: false) - @pragma('vm:prefer-inline') - _$TypographyCopyWith<_Typography> get copyWith => - __$TypographyCopyWithImpl<_Typography>(this, _$identity); - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _Typography && - (identical(other.fontFamily, fontFamily) || - other.fontFamily == fontFamily) && - (identical( - other.fontFamilyPostScriptName, fontFamilyPostScriptName) || - other.fontFamilyPostScriptName == fontFamilyPostScriptName) && - (identical(other.fontSize, fontSize) || - other.fontSize == fontSize) && - (identical(other.fontWeight, fontWeight) || - other.fontWeight == fontWeight) && - (identical(other.decoration, decoration) || - other.decoration == decoration) && - (identical(other.fontStyle, fontStyle) || - other.fontStyle == fontStyle) && - (identical(other.letterSpacing, letterSpacing) || - other.letterSpacing == letterSpacing) && - (identical(other.wordSpacing, wordSpacing) || - other.wordSpacing == wordSpacing) && - (identical(other.height, height) || other.height == height)); - } - - @override - int get hashCode => Object.hash( - runtimeType, - fontFamily, - fontFamilyPostScriptName, - fontSize, - fontWeight, - decoration, - fontStyle, - letterSpacing, - wordSpacing, - height); - - @override - String toString() { - return 'Typography(fontFamily: $fontFamily, fontFamilyPostScriptName: $fontFamilyPostScriptName, fontSize: $fontSize, fontWeight: $fontWeight, decoration: $decoration, fontStyle: $fontStyle, letterSpacing: $letterSpacing, wordSpacing: $wordSpacing, height: $height)'; - } + const _Typography({required this.fontFamily, required this.fontFamilyPostScriptName, required this.fontSize, this.fontWeight = 400, this.decoration = TextDecoration.none, this.fontStyle = FontStyle.normal, this.letterSpacing = 1.0, this.wordSpacing = 1.0, this.height = 1.0}): super._(); + + +@override final String fontFamily; +@override final String? fontFamilyPostScriptName; +@override final double fontSize; +@override@JsonKey() final int fontWeight; +@override@JsonKey() final TextDecoration decoration; +@override@JsonKey() final FontStyle fontStyle; +@override@JsonKey() final double letterSpacing; +@override@JsonKey() final double wordSpacing; +@override@JsonKey() final double height; + +/// Create a copy of Typography +/// with the given fields replaced by the non-null parameter values. +@override @JsonKey(includeFromJson: false, includeToJson: false) +@pragma('vm:prefer-inline') +_$TypographyCopyWith<_Typography> get copyWith => __$TypographyCopyWithImpl<_Typography>(this, _$identity); + + + +@override +bool operator ==(Object other) { + return identical(this, other) || (other.runtimeType == runtimeType&&other is _Typography&&(identical(other.fontFamily, fontFamily) || other.fontFamily == fontFamily)&&(identical(other.fontFamilyPostScriptName, fontFamilyPostScriptName) || other.fontFamilyPostScriptName == fontFamilyPostScriptName)&&(identical(other.fontSize, fontSize) || other.fontSize == fontSize)&&(identical(other.fontWeight, fontWeight) || other.fontWeight == fontWeight)&&(identical(other.decoration, decoration) || other.decoration == decoration)&&(identical(other.fontStyle, fontStyle) || other.fontStyle == fontStyle)&&(identical(other.letterSpacing, letterSpacing) || other.letterSpacing == letterSpacing)&&(identical(other.wordSpacing, wordSpacing) || other.wordSpacing == wordSpacing)&&(identical(other.height, height) || other.height == height)); } -/// @nodoc -abstract mixin class _$TypographyCopyWith<$Res> - implements $TypographyCopyWith<$Res> { - factory _$TypographyCopyWith( - _Typography value, $Res Function(_Typography) _then) = - __$TypographyCopyWithImpl; - @override - @useResult - $Res call( - {String fontFamily, - String? fontFamilyPostScriptName, - double fontSize, - int fontWeight, - TextDecoration decoration, - FontStyle fontStyle, - double letterSpacing, - double wordSpacing, - double height}); + +@override +int get hashCode => Object.hash(runtimeType,fontFamily,fontFamilyPostScriptName,fontSize,fontWeight,decoration,fontStyle,letterSpacing,wordSpacing,height); + +@override +String toString() { + return 'Typography(fontFamily: $fontFamily, fontFamilyPostScriptName: $fontFamilyPostScriptName, fontSize: $fontSize, fontWeight: $fontWeight, decoration: $decoration, fontStyle: $fontStyle, letterSpacing: $letterSpacing, wordSpacing: $wordSpacing, height: $height)'; +} + + } /// @nodoc -class __$TypographyCopyWithImpl<$Res> implements _$TypographyCopyWith<$Res> { +abstract mixin class _$TypographyCopyWith<$Res> implements $TypographyCopyWith<$Res> { + factory _$TypographyCopyWith(_Typography value, $Res Function(_Typography) _then) = __$TypographyCopyWithImpl; +@override @useResult +$Res call({ + String fontFamily, String? fontFamilyPostScriptName, double fontSize, int fontWeight, TextDecoration decoration, FontStyle fontStyle, double letterSpacing, double wordSpacing, double height +}); + + + + +} +/// @nodoc +class __$TypographyCopyWithImpl<$Res> + implements _$TypographyCopyWith<$Res> { __$TypographyCopyWithImpl(this._self, this._then); final _Typography _self; final $Res Function(_Typography) _then; - /// Create a copy of Typography - /// with the given fields replaced by the non-null parameter values. - @override - @pragma('vm:prefer-inline') - $Res call({ - Object? fontFamily = null, - Object? fontFamilyPostScriptName = freezed, - Object? fontSize = null, - Object? fontWeight = null, - Object? decoration = null, - Object? fontStyle = null, - Object? letterSpacing = null, - Object? wordSpacing = null, - Object? height = null, - }) { - return _then(_Typography( - fontFamily: null == fontFamily - ? _self.fontFamily - : fontFamily // ignore: cast_nullable_to_non_nullable - as String, - fontFamilyPostScriptName: freezed == fontFamilyPostScriptName - ? _self.fontFamilyPostScriptName - : fontFamilyPostScriptName // ignore: cast_nullable_to_non_nullable - as String?, - fontSize: null == fontSize - ? _self.fontSize - : fontSize // ignore: cast_nullable_to_non_nullable - as double, - fontWeight: null == fontWeight - ? _self.fontWeight - : fontWeight // ignore: cast_nullable_to_non_nullable - as int, - decoration: null == decoration - ? _self.decoration - : decoration // ignore: cast_nullable_to_non_nullable - as TextDecoration, - fontStyle: null == fontStyle - ? _self.fontStyle - : fontStyle // ignore: cast_nullable_to_non_nullable - as FontStyle, - letterSpacing: null == letterSpacing - ? _self.letterSpacing - : letterSpacing // ignore: cast_nullable_to_non_nullable - as double, - wordSpacing: null == wordSpacing - ? _self.wordSpacing - : wordSpacing // ignore: cast_nullable_to_non_nullable - as double, - height: null == height - ? _self.height - : height // ignore: cast_nullable_to_non_nullable - as double, - )); - } +/// Create a copy of Typography +/// with the given fields replaced by the non-null parameter values. +@override @pragma('vm:prefer-inline') $Res call({Object? fontFamily = null,Object? fontFamilyPostScriptName = freezed,Object? fontSize = null,Object? fontWeight = null,Object? decoration = null,Object? fontStyle = null,Object? letterSpacing = null,Object? wordSpacing = null,Object? height = null,}) { + return _then(_Typography( +fontFamily: null == fontFamily ? _self.fontFamily : fontFamily // ignore: cast_nullable_to_non_nullable +as String,fontFamilyPostScriptName: freezed == fontFamilyPostScriptName ? _self.fontFamilyPostScriptName : fontFamilyPostScriptName // ignore: cast_nullable_to_non_nullable +as String?,fontSize: null == fontSize ? _self.fontSize : fontSize // ignore: cast_nullable_to_non_nullable +as double,fontWeight: null == fontWeight ? _self.fontWeight : fontWeight // ignore: cast_nullable_to_non_nullable +as int,decoration: null == decoration ? _self.decoration : decoration // ignore: cast_nullable_to_non_nullable +as TextDecoration,fontStyle: null == fontStyle ? _self.fontStyle : fontStyle // ignore: cast_nullable_to_non_nullable +as FontStyle,letterSpacing: null == letterSpacing ? _self.letterSpacing : letterSpacing // ignore: cast_nullable_to_non_nullable +as double,wordSpacing: null == wordSpacing ? _self.wordSpacing : wordSpacing // ignore: cast_nullable_to_non_nullable +as double,height: null == height ? _self.height : height // ignore: cast_nullable_to_non_nullable +as double, + )); +} + + } // dart format on diff --git a/lib/src/domain/models/variable/alias_or/alias_or.freezed.dart b/lib/src/domain/models/variable/alias_or/alias_or.freezed.dart index 282a71d8..3a4a6162 100644 --- a/lib/src/domain/models/variable/alias_or/alias_or.freezed.dart +++ b/lib/src/domain/models/variable/alias_or/alias_or.freezed.dart @@ -11,426 +11,379 @@ part of 'alias_or.dart'; // dart format off T _$identity(T value) => value; - /// @nodoc mixin _$AliasOr { - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is AliasOr); - } - @override - int get hashCode => runtimeType.hashCode; - @override - String toString() { - return 'AliasOr<$T>()'; - } + + + +@override +bool operator ==(Object other) { + return identical(this, other) || (other.runtimeType == runtimeType&&other is AliasOr); +} + + +@override +int get hashCode => runtimeType.hashCode; + +@override +String toString() { + return 'AliasOr<$T>()'; +} + + } /// @nodoc -class $AliasOrCopyWith { - $AliasOrCopyWith(AliasOr _, $Res Function(AliasOr) __); +class $AliasOrCopyWith { +$AliasOrCopyWith(AliasOr _, $Res Function(AliasOr) __); } + /// Adds pattern-matching-related methods to [AliasOr]. extension AliasOrPatterns on AliasOr { - /// A variant of `map` that fallback to returning `orElse`. - /// - /// It is equivalent to doing: - /// ```dart - /// switch (sealedClass) { - /// case final Subclass value: - /// return ...; - /// case _: - /// return orElse(); - /// } - /// ``` - - @optionalTypeArgs - TResult maybeMap({ - TResult Function(AliasData value)? data, - TResult Function(Alias value)? alias, - TResult Function(AliasUnresolved value)? unresolved, - required TResult orElse(), - }) { - final _that = this; - switch (_that) { - case AliasData() when data != null: - return data(_that); - case Alias() when alias != null: - return alias(_that); - case AliasUnresolved() when unresolved != null: - return unresolved(_that); - case _: - return orElse(); - } - } - - /// A `switch`-like method, using callbacks. - /// - /// Callbacks receives the raw object, upcasted. - /// It is equivalent to doing: - /// ```dart - /// switch (sealedClass) { - /// case final Subclass value: - /// return ...; - /// case final Subclass2 value: - /// return ...; - /// } - /// ``` - - @optionalTypeArgs - TResult map({ - required TResult Function(AliasData value) data, - required TResult Function(Alias value) alias, - required TResult Function(AliasUnresolved value) unresolved, - }) { - final _that = this; - switch (_that) { - case AliasData(): - return data(_that); - case Alias(): - return alias(_that); - case AliasUnresolved(): - return unresolved(_that); - } - } - - /// A variant of `map` that fallback to returning `null`. - /// - /// It is equivalent to doing: - /// ```dart - /// switch (sealedClass) { - /// case final Subclass value: - /// return ...; - /// case _: - /// return null; - /// } - /// ``` - - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(AliasData value)? data, - TResult? Function(Alias value)? alias, - TResult? Function(AliasUnresolved value)? unresolved, - }) { - final _that = this; - switch (_that) { - case AliasData() when data != null: - return data(_that); - case Alias() when alias != null: - return alias(_that); - case AliasUnresolved() when unresolved != null: - return unresolved(_that); - case _: - return null; - } - } - - /// A variant of `when` that fallback to an `orElse` callback. - /// - /// It is equivalent to doing: - /// ```dart - /// switch (sealedClass) { - /// case Subclass(:final field): - /// return ...; - /// case _: - /// return orElse(); - /// } - /// ``` - - @optionalTypeArgs - TResult maybeWhen({ - TResult Function(T data)? data, - TResult Function(String id, AliasOr aliasOrValue)? alias, - TResult Function(String id)? unresolved, - required TResult orElse(), - }) { - final _that = this; - switch (_that) { - case AliasData() when data != null: - return data(_that.data); - case Alias() when alias != null: - return alias(_that.id, _that.aliasOrValue); - case AliasUnresolved() when unresolved != null: - return unresolved(_that.id); - case _: - return orElse(); - } - } - - /// A `switch`-like method, using callbacks. - /// - /// As opposed to `map`, this offers destructuring. - /// It is equivalent to doing: - /// ```dart - /// switch (sealedClass) { - /// case Subclass(:final field): - /// return ...; - /// case Subclass2(:final field2): - /// return ...; - /// } - /// ``` - - @optionalTypeArgs - TResult when({ - required TResult Function(T data) data, - required TResult Function(String id, AliasOr aliasOrValue) alias, - required TResult Function(String id) unresolved, - }) { - final _that = this; - switch (_that) { - case AliasData(): - return data(_that.data); - case Alias(): - return alias(_that.id, _that.aliasOrValue); - case AliasUnresolved(): - return unresolved(_that.id); - } - } - - /// A variant of `when` that fallback to returning `null` - /// - /// It is equivalent to doing: - /// ```dart - /// switch (sealedClass) { - /// case Subclass(:final field): - /// return ...; - /// case _: - /// return null; - /// } - /// ``` - - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function(T data)? data, - TResult? Function(String id, AliasOr aliasOrValue)? alias, - TResult? Function(String id)? unresolved, - }) { - final _that = this; - switch (_that) { - case AliasData() when data != null: - return data(_that.data); - case Alias() when alias != null: - return alias(_that.id, _that.aliasOrValue); - case AliasUnresolved() when unresolved != null: - return unresolved(_that.id); - case _: - return null; - } - } +/// A variant of `map` that fallback to returning `orElse`. +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case final Subclass value: +/// return ...; +/// case _: +/// return orElse(); +/// } +/// ``` + +@optionalTypeArgs TResult maybeMap({TResult Function( AliasData value)? data,TResult Function( Alias value)? alias,TResult Function( AliasUnresolved value)? unresolved,required TResult orElse(),}){ +final _that = this; +switch (_that) { +case AliasData() when data != null: +return data(_that);case Alias() when alias != null: +return alias(_that);case AliasUnresolved() when unresolved != null: +return unresolved(_that);case _: + return orElse(); + +} +} +/// A `switch`-like method, using callbacks. +/// +/// Callbacks receives the raw object, upcasted. +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case final Subclass value: +/// return ...; +/// case final Subclass2 value: +/// return ...; +/// } +/// ``` + +@optionalTypeArgs TResult map({required TResult Function( AliasData value) data,required TResult Function( Alias value) alias,required TResult Function( AliasUnresolved value) unresolved,}){ +final _that = this; +switch (_that) { +case AliasData(): +return data(_that);case Alias(): +return alias(_that);case AliasUnresolved(): +return unresolved(_that);} +} +/// A variant of `map` that fallback to returning `null`. +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case final Subclass value: +/// return ...; +/// case _: +/// return null; +/// } +/// ``` + +@optionalTypeArgs TResult? mapOrNull({TResult? Function( AliasData value)? data,TResult? Function( Alias value)? alias,TResult? Function( AliasUnresolved value)? unresolved,}){ +final _that = this; +switch (_that) { +case AliasData() when data != null: +return data(_that);case Alias() when alias != null: +return alias(_that);case AliasUnresolved() when unresolved != null: +return unresolved(_that);case _: + return null; + +} +} +/// A variant of `when` that fallback to an `orElse` callback. +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case Subclass(:final field): +/// return ...; +/// case _: +/// return orElse(); +/// } +/// ``` + +@optionalTypeArgs TResult maybeWhen({TResult Function( T data)? data,TResult Function( String id, AliasOr aliasOrValue)? alias,TResult Function( String id)? unresolved,required TResult orElse(),}) {final _that = this; +switch (_that) { +case AliasData() when data != null: +return data(_that.data);case Alias() when alias != null: +return alias(_that.id,_that.aliasOrValue);case AliasUnresolved() when unresolved != null: +return unresolved(_that.id);case _: + return orElse(); + +} +} +/// A `switch`-like method, using callbacks. +/// +/// As opposed to `map`, this offers destructuring. +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case Subclass(:final field): +/// return ...; +/// case Subclass2(:final field2): +/// return ...; +/// } +/// ``` + +@optionalTypeArgs TResult when({required TResult Function( T data) data,required TResult Function( String id, AliasOr aliasOrValue) alias,required TResult Function( String id) unresolved,}) {final _that = this; +switch (_that) { +case AliasData(): +return data(_that.data);case Alias(): +return alias(_that.id,_that.aliasOrValue);case AliasUnresolved(): +return unresolved(_that.id);} +} +/// A variant of `when` that fallback to returning `null` +/// +/// It is equivalent to doing: +/// ```dart +/// switch (sealedClass) { +/// case Subclass(:final field): +/// return ...; +/// case _: +/// return null; +/// } +/// ``` + +@optionalTypeArgs TResult? whenOrNull({TResult? Function( T data)? data,TResult? Function( String id, AliasOr aliasOrValue)? alias,TResult? Function( String id)? unresolved,}) {final _that = this; +switch (_that) { +case AliasData() when data != null: +return data(_that.data);case Alias() when alias != null: +return alias(_that.id,_that.aliasOrValue);case AliasUnresolved() when unresolved != null: +return unresolved(_that.id);case _: + return null; + +} +} + } /// @nodoc + class AliasData extends AliasOr { - const AliasData({required this.data}) : super._(); + const AliasData({required this.data}): super._(); + - final T data; + final T data; - /// Create a copy of AliasOr - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @pragma('vm:prefer-inline') - $AliasDataCopyWith> get copyWith => - _$AliasDataCopyWithImpl>(this, _$identity); +/// Create a copy of AliasOr +/// with the given fields replaced by the non-null parameter values. +@JsonKey(includeFromJson: false, includeToJson: false) +@pragma('vm:prefer-inline') +$AliasDataCopyWith> get copyWith => _$AliasDataCopyWithImpl>(this, _$identity); - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is AliasData && - const DeepCollectionEquality().equals(other.data, data)); - } - @override - int get hashCode => - Object.hash(runtimeType, const DeepCollectionEquality().hash(data)); - @override - String toString() { - return 'AliasOr<$T>.data(data: $data)'; - } +@override +bool operator ==(Object other) { + return identical(this, other) || (other.runtimeType == runtimeType&&other is AliasData&&const DeepCollectionEquality().equals(other.data, data)); } -/// @nodoc -abstract mixin class $AliasDataCopyWith - implements $AliasOrCopyWith { - factory $AliasDataCopyWith( - AliasData value, $Res Function(AliasData) _then) = - _$AliasDataCopyWithImpl; - @useResult - $Res call({T data}); + +@override +int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(data)); + +@override +String toString() { + return 'AliasOr<$T>.data(data: $data)'; +} + + } /// @nodoc -class _$AliasDataCopyWithImpl implements $AliasDataCopyWith { +abstract mixin class $AliasDataCopyWith implements $AliasOrCopyWith { + factory $AliasDataCopyWith(AliasData value, $Res Function(AliasData) _then) = _$AliasDataCopyWithImpl; +@useResult +$Res call({ + T data +}); + + + + +} +/// @nodoc +class _$AliasDataCopyWithImpl + implements $AliasDataCopyWith { _$AliasDataCopyWithImpl(this._self, this._then); final AliasData _self; final $Res Function(AliasData) _then; - /// Create a copy of AliasOr - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - $Res call({ - Object? data = freezed, - }) { - return _then(AliasData( - data: freezed == data - ? _self.data - : data // ignore: cast_nullable_to_non_nullable - as T, - )); - } +/// Create a copy of AliasOr +/// with the given fields replaced by the non-null parameter values. +@pragma('vm:prefer-inline') $Res call({Object? data = freezed,}) { + return _then(AliasData( +data: freezed == data ? _self.data : data // ignore: cast_nullable_to_non_nullable +as T, + )); +} + + } /// @nodoc + class Alias extends AliasOr { - const Alias({required this.id, required this.aliasOrValue}) : super._(); + const Alias({required this.id, required this.aliasOrValue}): super._(); + - final String id; - final AliasOr aliasOrValue; + final String id; + final AliasOr aliasOrValue; - /// Create a copy of AliasOr - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @pragma('vm:prefer-inline') - $AliasCopyWith> get copyWith => - _$AliasCopyWithImpl>(this, _$identity); +/// Create a copy of AliasOr +/// with the given fields replaced by the non-null parameter values. +@JsonKey(includeFromJson: false, includeToJson: false) +@pragma('vm:prefer-inline') +$AliasCopyWith> get copyWith => _$AliasCopyWithImpl>(this, _$identity); - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is Alias && - (identical(other.id, id) || other.id == id) && - (identical(other.aliasOrValue, aliasOrValue) || - other.aliasOrValue == aliasOrValue)); - } - @override - int get hashCode => Object.hash(runtimeType, id, aliasOrValue); - @override - String toString() { - return 'AliasOr<$T>.alias(id: $id, aliasOrValue: $aliasOrValue)'; - } +@override +bool operator ==(Object other) { + return identical(this, other) || (other.runtimeType == runtimeType&&other is Alias&&(identical(other.id, id) || other.id == id)&&(identical(other.aliasOrValue, aliasOrValue) || other.aliasOrValue == aliasOrValue)); +} + + +@override +int get hashCode => Object.hash(runtimeType,id,aliasOrValue); + +@override +String toString() { + return 'AliasOr<$T>.alias(id: $id, aliasOrValue: $aliasOrValue)'; } -/// @nodoc -abstract mixin class $AliasCopyWith - implements $AliasOrCopyWith { - factory $AliasCopyWith(Alias value, $Res Function(Alias) _then) = - _$AliasCopyWithImpl; - @useResult - $Res call({String id, AliasOr aliasOrValue}); - $AliasOrCopyWith get aliasOrValue; } /// @nodoc -class _$AliasCopyWithImpl implements $AliasCopyWith { +abstract mixin class $AliasCopyWith implements $AliasOrCopyWith { + factory $AliasCopyWith(Alias value, $Res Function(Alias) _then) = _$AliasCopyWithImpl; +@useResult +$Res call({ + String id, AliasOr aliasOrValue +}); + + +$AliasOrCopyWith get aliasOrValue; + +} +/// @nodoc +class _$AliasCopyWithImpl + implements $AliasCopyWith { _$AliasCopyWithImpl(this._self, this._then); final Alias _self; final $Res Function(Alias) _then; - /// Create a copy of AliasOr - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - $Res call({ - Object? id = null, - Object? aliasOrValue = null, - }) { - return _then(Alias( - id: null == id - ? _self.id - : id // ignore: cast_nullable_to_non_nullable - as String, - aliasOrValue: null == aliasOrValue - ? _self.aliasOrValue - : aliasOrValue // ignore: cast_nullable_to_non_nullable - as AliasOr, - )); - } - - /// Create a copy of AliasOr - /// with the given fields replaced by the non-null parameter values. - @override - @pragma('vm:prefer-inline') - $AliasOrCopyWith get aliasOrValue { - return $AliasOrCopyWith(_self.aliasOrValue, (value) { - return _then(_self.copyWith(aliasOrValue: value)); - }); - } +/// Create a copy of AliasOr +/// with the given fields replaced by the non-null parameter values. +@pragma('vm:prefer-inline') $Res call({Object? id = null,Object? aliasOrValue = null,}) { + return _then(Alias( +id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable +as String,aliasOrValue: null == aliasOrValue ? _self.aliasOrValue : aliasOrValue // ignore: cast_nullable_to_non_nullable +as AliasOr, + )); +} + +/// Create a copy of AliasOr +/// with the given fields replaced by the non-null parameter values. +@override +@pragma('vm:prefer-inline') +$AliasOrCopyWith get aliasOrValue { + + return $AliasOrCopyWith(_self.aliasOrValue, (value) { + return _then(_self.copyWith(aliasOrValue: value)); + }); +} } /// @nodoc + class AliasUnresolved extends AliasOr { - const AliasUnresolved({required this.id}) : super._(); + const AliasUnresolved({required this.id}): super._(); + - final String id; + final String id; - /// Create a copy of AliasOr - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @pragma('vm:prefer-inline') - $AliasUnresolvedCopyWith> get copyWith => - _$AliasUnresolvedCopyWithImpl>(this, _$identity); +/// Create a copy of AliasOr +/// with the given fields replaced by the non-null parameter values. +@JsonKey(includeFromJson: false, includeToJson: false) +@pragma('vm:prefer-inline') +$AliasUnresolvedCopyWith> get copyWith => _$AliasUnresolvedCopyWithImpl>(this, _$identity); - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is AliasUnresolved && - (identical(other.id, id) || other.id == id)); - } - @override - int get hashCode => Object.hash(runtimeType, id); - @override - String toString() { - return 'AliasOr<$T>.unresolved(id: $id)'; - } +@override +bool operator ==(Object other) { + return identical(this, other) || (other.runtimeType == runtimeType&&other is AliasUnresolved&&(identical(other.id, id) || other.id == id)); } -/// @nodoc -abstract mixin class $AliasUnresolvedCopyWith - implements $AliasOrCopyWith { - factory $AliasUnresolvedCopyWith( - AliasUnresolved value, $Res Function(AliasUnresolved) _then) = - _$AliasUnresolvedCopyWithImpl; - @useResult - $Res call({String id}); + +@override +int get hashCode => Object.hash(runtimeType,id); + +@override +String toString() { + return 'AliasOr<$T>.unresolved(id: $id)'; +} + + } /// @nodoc -class _$AliasUnresolvedCopyWithImpl +abstract mixin class $AliasUnresolvedCopyWith implements $AliasOrCopyWith { + factory $AliasUnresolvedCopyWith(AliasUnresolved value, $Res Function(AliasUnresolved) _then) = _$AliasUnresolvedCopyWithImpl; +@useResult +$Res call({ + String id +}); + + + + +} +/// @nodoc +class _$AliasUnresolvedCopyWithImpl implements $AliasUnresolvedCopyWith { _$AliasUnresolvedCopyWithImpl(this._self, this._then); final AliasUnresolved _self; final $Res Function(AliasUnresolved) _then; - /// Create a copy of AliasOr - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - $Res call({ - Object? id = null, - }) { - return _then(AliasUnresolved( - id: null == id - ? _self.id - : id // ignore: cast_nullable_to_non_nullable - as String, - )); - } +/// Create a copy of AliasOr +/// with the given fields replaced by the non-null parameter values. +@pragma('vm:prefer-inline') $Res call({Object? id = null,}) { + return _then(AliasUnresolved( +id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable +as String, + )); +} + + } // dart format on diff --git a/lib/src/domain/models/variable/variable.dart b/lib/src/domain/models/variable/variable.dart index f4ae0429..4c353c61 100644 --- a/lib/src/domain/models/variable/variable.dart +++ b/lib/src/domain/models/variable/variable.dart @@ -1,7 +1,7 @@ import 'package:equatable/equatable.dart'; -import 'package:figma_variables_api/figma_variables_api.dart'; import 'package:figmage/src/domain/models/design_token.dart'; import 'package:figmage/src/domain/models/variable/alias_or/alias_or.dart'; +import 'package:figmage/src/domain/models/variable/variable_type.dart'; /// {@template variable} /// Represents a Figma variable with different data types. diff --git a/lib/src/domain/models/variable/variable_type.dart b/lib/src/domain/models/variable/variable_type.dart new file mode 100644 index 00000000..a4c8ea65 --- /dev/null +++ b/lib/src/domain/models/variable/variable_type.dart @@ -0,0 +1,28 @@ +import 'package:figma/figma.dart'; + +/// Represents the type of a Figma variable. +enum VariableType { + /// String variable type. + string, + /// Float/number variable type. + float, + /// Color variable type. + color, + /// Boolean variable type. + boolean, +} + +/// Extension methods for [VariableType]. +extension VariableTypeX on VariableType { + /// Converts a Figma [VariableResolvedDataType] to a [VariableType]. + static VariableType fromResolvedDataType( + VariableResolvedDataType resolvedType, + ) { + return switch (resolvedType) { + VariableResolvedDataType.string => VariableType.string, + VariableResolvedDataType.float => VariableType.float, + VariableResolvedDataType.color => VariableType.color, + VariableResolvedDataType.boolean => VariableType.boolean, + }; + } +} diff --git a/lib/src/domain/providers/design_token_providers.dart b/lib/src/domain/providers/design_token_providers.dart index 6ca8e06e..4602a9ae 100644 --- a/lib/src/domain/providers/design_token_providers.dart +++ b/lib/src/domain/providers/design_token_providers.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:collection/collection.dart'; import 'package:figmage/src/data/util/converters/string_dart_conversion_x.dart'; import 'package:figmage/src/domain/models/design_token.dart'; import 'package:figmage/src/domain/models/figmage_settings.dart'; @@ -20,264 +21,313 @@ import 'package:riverpod/riverpod.dart'; /// If false, includes all tokens, with unresolved ones returning null. final filterUnresolvedTokensProvider = FutureProvider.family((ref, settings) async { - final logger = ref.watch(loggerProvider); + final logger = ref.watch(loggerProvider); - final tokensByType = await ref.watch(filteredTokensProvider(settings).future); - tokensByType.asMap().forEach((name, tokens) { - final allUnresolvedTokens = tokens.getUnresolvedTokens(); - // Filter out deleted variables from unresolved warnings when user chose to - // exclude them - final unresolvedTokens = settings.config.includeDeletedButReferenced - ? allUnresolvedTokens - : allUnresolvedTokens.where((token) => - !(token is Variable && (token.deletedButReferenced ?? false)), - ); + final tokensByType = await ref.watch( + filteredTokensProvider(settings).future, + ); + tokensByType.asMap().forEach((name, tokens) { + final allUnresolvedTokens = tokens.getUnresolvedTokens(); + // Filter out deleted variables when the user chose to exclude them. + final unresolvedTokens = settings.config.includeDeletedButReferenced + ? allUnresolvedTokens + : allUnresolvedTokens.where( + (token) => + !(token is Variable && + (token.deletedButReferenced ?? false)), + ); - if (unresolvedTokens.isNotEmpty) { - logger.warn( - 'Found ${unresolvedTokens.length} ${name.toTitleCase()} where the ' - 'value is, at least for one mode, unresolvable.'); - if (logger.level == Level.verbose) { - // In verbose mode, show ALL unresolved tokens for complete debugging - for (final token in allUnresolvedTokens) { - logger.info(' ${token.fullName}:'); - token.valuesByModeName.forEach((modeName, value) { - logger.info(' $modeName : $value'); - }); + if (unresolvedTokens.isNotEmpty) { + logger.warn( + 'Found ${unresolvedTokens.length} ${name.toTitleCase()} ' + 'where the value is, at least for one mode, unresolvable.', + ); + if (logger.level == Level.verbose) { + // In verbose mode, show all unresolved tokens for + // complete debugging. + for (final token in allUnresolvedTokens) { + logger.info(' ${token.fullName}:'); + token.valuesByModeName.forEach((modeName, value) { + logger.info(' $modeName : $value'); + }); + } + } } - } - } - }); - return settings.config.dropUnresolved - ? tokensByType.resolvable - : tokensByType; -}); + }); + return settings.config.dropUnresolved + ? tokensByType.resolvable + : tokensByType; + }); /// Filters all tokens by file type. final filteredTokensProvider = FutureProvider.family((ref, settings) async { - late final Iterable variables; - try { - variables = await ref.watch(variablesProvider(settings).future); - } catch (_) { - variables = []; - } + late final Iterable variables; + try { + variables = await ref.watch(variablesProvider(settings).future); + } catch (_) { + variables = []; + } - late final Iterable styles; - try { - styles = await ref.watch(stylesProvider(settings).future); - } catch (_) { - styles = []; - } + late final Iterable styles; + try { + styles = await ref.watch(stylesProvider(settings).future); + } catch (_) { + styles = []; + } - final allTokens = [...variables, ...styles]; - if (allTokens.isEmpty) { - throw ArgumentError.value( - allTokens, - "Tokens", - "Neither styles nor variables could be obtained from file " - "${settings.fileId} ", - ); - } - return TokensByType( - colorTokens: allTokens - .whereType>() - .filterByFrom(settings.config.colors), - typographyTokens: allTokens - .whereType>() - .filterByFrom(settings.config.typography), - numberTokens: allTokens - .whereType>() - .filterByFrom(settings.config.numbers), - stringTokens: allTokens - .whereType>() - .filterByFrom(settings.config.strings), - boolTokens: allTokens - .whereType>() - .filterByFrom(settings.config.bools), - ); -}); + final allTokens = [...variables, ...styles]; + if (allTokens.isEmpty) { + throw ArgumentError.value( + allTokens, + "Tokens", + "Neither styles nor variables could be obtained from file " + "${settings.fileId} ", + ); + } + return TokensByType( + colorTokens: allTokens.whereType>().filterByFrom( + settings.config.colors, + ), + typographyTokens: allTokens + .whereType>() + .filterByFrom(settings.config.typography), + numberTokens: allTokens.whereType>().filterByFrom( + settings.config.numbers, + ), + stringTokens: allTokens.whereType>().filterByFrom( + settings.config.strings, + ), + boolTokens: allTokens.whereType>().filterByFrom( + settings.config.bools, + ), + ); + }); /// Provides a Iterable of all variables obtained from the file in /// [FigmageSettings]. /// /// This provider doesn't filter for anything yet. final variablesProvider = - FutureProvider.family, FigmageSettings>( - (ref, settings) async { - final logger = ref.watch(loggerProvider); - final repo = ref.watch(variablesRepositoryProvider); - final varProgress = logger.progress("Fetching all variables..."); - try { - final variables = await repo.getVariables( - fileId: settings.fileId, - token: settings.token, - ); - switch (variables) { - case []: - varProgress.fail("No variables found"); - throw ArgumentError.value( - variables, - "variables", - "No variables found in file ${settings.fileId}", - ); - case [...]: - // Filter out deleted variables if not included in config - final deletedVariables = variables.where( - (v) => v.deletedButReferenced ?? false, + FutureProvider.family, FigmageSettings>(( + ref, + settings, + ) async { + final logger = ref.watch(loggerProvider); + final repo = ref.watch(variablesRepositoryProvider); + final varProgress = logger.progress("Fetching all variables..."); + try { + final variables = await repo.getVariables( + fileId: settings.fileId, + token: settings.token, ); - if (deletedVariables.isNotEmpty) { - logger.warn( - " Found ${deletedVariables.length} variables that have been" - " deleted but are still referenced.", - ); - if (logger.level == Level.verbose) { - for (final variable in deletedVariables) { - logger.info(" ${variable.fullName}"); - } - } - - if (!settings.config.includeDeletedButReferenced) { - final filteredVariables = variables.where( - (v) => !(v.deletedButReferenced ?? false), - ); - logger.warn( - " Excluding ${deletedVariables.length} deleted variables. " - "Set 'includeDeletedButReferenced: true' in figmage.yaml to " - "include them.", + switch (variables) { + case []: + varProgress.fail("No variables found"); + throw ArgumentError.value( + variables, + "variables", + "No variables found in file ${settings.fileId}", ); - varProgress.complete( - "Found ${filteredVariables.length} variables " - "(${deletedVariables.length} deleted variables excluded)", + case [...]: + // Filter out deleted variables if not included in config + final deletedVariables = variables.where( + (v) => v.deletedButReferenced ?? false, ); - return filteredVariables; - } else { - logger.info( - " Including ${deletedVariables.length} deleted variables" - " as per config.", - ); - } + if (deletedVariables.isNotEmpty) { + final warning = StringBuffer( + "Found ${deletedVariables.length} variables that have been " + "deleted but are still referenced.", + ); + if (!settings.config.includeDeletedButReferenced) { + warning + ..write( + " Excluding ${deletedVariables.length} deleted variables.", + ) + ..write( + " Set 'includeDeletedButReferenced: true' in figmage.yaml " + "to include them.", + ); + } + logger.warn(warning.toString()); + + if (logger.level == Level.verbose) { + for (final variable in deletedVariables) { + logger.info(" ${variable.fullName}"); + } + } + + if (!settings.config.includeDeletedButReferenced) { + final filteredVariables = variables.where( + (v) => !(v.deletedButReferenced ?? false), + ); + varProgress.complete( + "Found ${filteredVariables.length} variables " + "(${deletedVariables.length} deleted variables excluded)", + ); + return filteredVariables; + } + } + + varProgress.complete("Found ${variables.length} variables"); + return variables; } - - varProgress.complete("Found ${variables.length} variables"); - return variables; - } - } on VariablesException catch (e) { - varProgress.fail("Failed to fetch variables: ${e.message}"); - rethrow; - } catch (e) { - varProgress.fail("Failed to fetch variables for unknown reason ($e)"); - rethrow; - } -}); + } on VariablesException catch (e) { + varProgress.fail("Failed to fetch variables: ${e.message}"); + rethrow; + } catch (e) { + varProgress.fail("Failed to fetch variables for unknown reason ($e)"); + rethrow; + } + }); /// Provides a map of downloaded assets from the file in [FigmageSettings]. /// /// Returns a map of node IDs to their downloaded asset file paths (per scale). final assetsProvider = - FutureProvider.family>, FigmageSettings>( - (ref, settings) async { - final logger = ref.watch(loggerProvider); - final repo = ref.watch(assetsRepositoryProvider); - final assetsProgress = logger.progress("Downloading assets..."); + FutureProvider.family>, FigmageSettings>(( + ref, + settings, + ) async { + final logger = ref.watch(loggerProvider); + final repo = ref.watch(assetsRepositoryProvider); + final assetsProgress = logger.progress("Downloading assets..."); - try { - if (settings.config.assets.nodes.isEmpty) { - assetsProgress - .fail("No assets specified in figmage.yaml - nothing to download"); - return {}; - } - // Scale must be a number between 0.01 and 4 - if (settings.config.assets.nodes.entries - .any((e) => e.value.scales.any((s) => s < 0.01 || s > 4))) { - logger.warn( - """ + try { + if (settings.config.assets.nodes.isEmpty) { + assetsProgress.fail( + "No assets specified in figmage.yaml - nothing to download", + ); + return {}; + } + // Scale must be a number between 0.01 and 4 + if (settings.config.assets.nodes.entries.any( + (e) => e.value.scales.any((s) => s < 0.01 || s > 4), + )) { + logger.warn( + """ Figma only supports scale values between 0.01 and 4, values out of this range will be ignored""", - ); - } + ); + } - final assets = await repo.fetchAndSaveAssets( - fileId: settings.fileId, - token: settings.token, - nodeSettings: settings.config.assets.nodes, - outputDir: Directory('${settings.path}/assets'), - ); - assetsProgress.update('Download complete.'); - if (assets.values.any((l) => l.contains(null))) { - logger.warn( - ''' + final assets = await repo.fetchAndSaveAssets( + fileId: settings.fileId, + token: settings.token, + nodeSettings: settings.config.assets.nodes, + outputDir: Directory('${settings.path}/assets'), + ); + assetsProgress.update('Download complete.'); + if (assets.values.any((l) => l.contains(null))) { + logger.warn( + ''' Some assets failed to render. This may be due to: - Invalid node IDs - Nodes with no renderable components (e.g., invisible nodes or nodes with 0% opacity) ''', - ); - for (final asset in assets.entries.where((e) => e.value.contains(null))) { - logger.warn('${asset.key} could not be rendered'); - } - } + ); + for (final asset in assets.entries.where( + (e) => e.value.contains(null), + )) { + logger.warn('${asset.key} could not be rendered'); + } + } - // Remove all entries where rendering failed. - final successAssets = { - for (final entry in assets.entries) - // Create a filtered list without nulls - if (entry.value.whereType().isNotEmpty) - entry.key: entry.value.whereType().toList(), - }; + // Remove all entries where rendering failed. + final successAssets = { + for (final entry in assets.entries) + // Create a filtered list without nulls + if (entry.value.whereType().isNotEmpty) + entry.key: entry.value.whereType().toList(), + }; - if (successAssets.isEmpty) { - assetsProgress.fail("No assets downloaded"); - return {}; - } else { - assetsProgress.complete( - "Downloaded ${successAssets.length} assets", - ); - return successAssets; - } - } on AssetsException catch (e) { - assetsProgress.fail("Failed to download assets: ${e.message}"); - return {}; - } catch (e) { - assetsProgress.fail("Failed to download assets for unknown reason ($e)"); - return {}; - } -}); + if (successAssets.isEmpty) { + assetsProgress.fail("No assets downloaded"); + return {}; + } else { + assetsProgress.complete( + "Downloaded ${successAssets.length} assets", + ); + return successAssets; + } + } on AssetsException catch (e) { + assetsProgress.fail("Failed to download assets: ${e.message}"); + return {}; + } catch (e) { + assetsProgress.fail( + "Failed to download assets for unknown reason ($e)", + ); + return {}; + } + }); /// Provides a Iterable of all styles obtained from the file in /// [FigmageSettings]. /// /// This provider doesn't filter for anything yet. final stylesProvider = - FutureProvider.family, FigmageSettings>( - (ref, settings) async { - final logger = ref.watch(loggerProvider); - final repo = ref.watch(stylesRepositoryProvider); - final stylesProgress = logger.progress("Fetching all styles..."); + FutureProvider.family, FigmageSettings>(( + ref, + settings, + ) async { + final logger = ref.watch(loggerProvider); + final repo = ref.watch(stylesRepositoryProvider); + final stylesProgress = logger.progress("Fetching all styles..."); + + void onStylesProgress(String message) { + stylesProgress.update(message); + } - final List> styles; - try { - styles = await repo.getStyles( - fileId: settings.fileId, - token: settings.token, - fromLibrary: settings.config.stylesFromLibrary, - ); - } on StylesException catch (e) { - stylesProgress.fail("Failed to fetch styles: ${e.message}"); - rethrow; - } catch (e) { - stylesProgress.fail("Failed to fetch styles for unknown reason ($e)"); - rethrow; + final List> styles; + try { + styles = await repo.getStyles( + fileId: settings.fileId, + token: settings.token, + fromLibrary: settings.config.stylesFromLibrary, + onProgress: onStylesProgress, + ); + } on StylesException catch (e) { + stylesProgress.fail("Failed to fetch styles: ${e.message}"); + rethrow; + } catch (e) { + stylesProgress.fail("Failed to fetch styles for unknown reason ($e)"); + rethrow; + } + + switch (styles) { + case []: + stylesProgress.fail("No styles found"); + throw ArgumentError.value( + styles, + "styles", + "No styles found in file ${settings.fileId}", + ); + case [...]: + _warnAboutDuplicateStyleNames(logger, styles); + stylesProgress.complete("Found ${styles.length} styles"); + return styles; + } + }); + +void _warnAboutDuplicateStyleNames( + Logger logger, + Iterable> styles, +) { + final duplicates = groupBy(styles, (style) => style.fullName) + .entries + .where((entry) => entry.value.length > 1) + .toList(); + if (duplicates.isEmpty) { + return; } - switch (styles) { - case []: - stylesProgress.fail("No styles found"); - throw ArgumentError.value( - styles, - "styles", - "No styles found in file ${settings.fileId}", - ); - case [...]: - stylesProgress.complete("Found ${styles.length} styles"); - return styles; + final warning = StringBuffer( + 'Detected duplicate style names from Figma. ' + 'Figmage will append Variant suffixes (Variant2, Variant3, ...) ' + 'to keep the generated members unique:\n', + ); + for (final entry in duplicates) { + final nodeIds = entry.value.map((style) => style.id).join(', '); + warning.writeln(' - ${entry.key} (node IDs: $nodeIds)'); } -}); + logger.warn(warning.toString().trimRight()); +} diff --git a/lib/src/domain/repositories/styles_repository.dart b/lib/src/domain/repositories/styles_repository.dart index f5e558f3..7543c198 100644 --- a/lib/src/domain/repositories/styles_repository.dart +++ b/lib/src/domain/repositories/styles_repository.dart @@ -19,6 +19,7 @@ abstract interface class StylesRepository { required String fileId, required String token, required bool fromLibrary, + void Function(String message)? onProgress, }); } diff --git a/lib/src/domain/util/token_filter_x.dart b/lib/src/domain/util/token_filter_x.dart index 5884a963..9860e445 100644 --- a/lib/src/domain/util/token_filter_x.dart +++ b/lib/src/domain/util/token_filter_x.dart @@ -51,12 +51,13 @@ extension TokenFilterX on Iterable> { Map> get valuesByNameByMode { final sorted = sortTokensByName(); final allModes = getAllUniqueSortedModes(); + final uniqueNames = _getUniqueTokenNames(sorted); return { for (final mode in allModes) mode: { for (final token in sorted) if (token.valuesByModeName[mode] case final alias?) - token.name: alias.resolveValue, + uniqueNames[token]!: alias.resolveValue, }, }; } @@ -74,3 +75,17 @@ extension TokenFilterX on Iterable> { } } } + +Map, String> _getUniqueTokenNames( + Iterable> tokens, +) { + final occurrences = {}; + final names = , String>{}; + for (final token in tokens) { + final baseName = token.name; + final count = (occurrences[baseName] ?? 0) + 1; + occurrences[baseName] = count; + names[token] = count == 1 ? baseName : '${baseName}Variant$count'; + } + return names; +} diff --git a/packages/figma_variables_api/.gitignore b/packages/figma_variables_api/.gitignore deleted file mode 100644 index 83182914..00000000 --- a/packages/figma_variables_api/.gitignore +++ /dev/null @@ -1,27 +0,0 @@ -# Miscellaneous -*.class -*.log -*.pyc -*.swp -.DS_Store -.atom/ -.buildlog/ -.history -.svn/ -.mason/ -migrate_working_dir/ - -# IntelliJ related -*.iml -*.ipr -*.iws -.idea/ - -# See https://www.dartlang.org/guides/libraries/private-files - -# Files and directories created by pub -.dart_tool/ -.packages -build/ -pubspec.lock -pubspec_overrides.yaml \ No newline at end of file diff --git a/packages/figma_variables_api/CHANGELOG.md b/packages/figma_variables_api/CHANGELOG.md deleted file mode 100644 index a1aa9301..00000000 --- a/packages/figma_variables_api/CHANGELOG.md +++ /dev/null @@ -1,53 +0,0 @@ -## 0.1.0-dev.8 - - - **FEAT**: add support for deleted but referenced flag (#210). - - **FEAT**: pull assets from Figma (#162). - -## 0.1.0-dev.7 - - - **FEAT**: pull assets from Figma (#162). - -## 0.1.0-dev.6 - - - **FEAT**(figma_variables_api): enable fetching local styles from file. - - **FEAT**(figma_variables_api): support file endpoint. - -## 0.1.0-dev.5 - -> Note: This release has breaking changes. - - - **BREAKING** **FEAT**: other characters in Figma token names are converted into proper camel case paths. (#105). - -## 0.1.0-dev.4 - - - **FIX**: styles import is not handled by `package:figma` anymore (#96). - -## 0.1.0-dev.3 - -> Note: This release has breaking changes. - - - **FIX**: generator tries to fit all variable collections into one class (#42). - - **FIX**: no export for `typography.dart` (#41). - - **FEAT**: support for google fonts package (#28). - - **FEAT**: config yaml repository (#17). - - **FEAT**: universal extension generator (#13). - - **FEAT**: variables repo & model & convert aliases (#9). - - **BREAKING** **REFACTOR**: unify `SpacersGenerator` and `PaddingsGenerator` in `ReferenceThemeClassGenerator` (#59). - - **BREAKING** **FEAT**: connect everything together (#25). - -## 0.1.0-dev.2 - -> Note: This release has breaking changes. - - - **FIX**: generator tries to fit all variable collections into one class (#42). - - **FIX**: no export for `typography.dart` (#41). - - **FEAT**: support for google fonts package (#28). - - **FEAT**: config yaml repository (#17). - - **FEAT**: universal extension generator (#13). - - **FEAT**: variables repo & model & convert aliases (#9). - - **BREAKING** **REFACTOR**: unify `SpacersGenerator` and `PaddingsGenerator` in `ReferenceThemeClassGenerator` (#59). - - **BREAKING** **FEAT**: connect everything together (#25). - -## 0.1.0+1 - -- feat: initial commit 🎉 diff --git a/packages/figma_variables_api/LICENSE b/packages/figma_variables_api/LICENSE deleted file mode 100644 index 272093a5..00000000 --- a/packages/figma_variables_api/LICENSE +++ /dev/null @@ -1,7 +0,0 @@ -Copyright 2024 whynotmake.it (Jesper Bellenbaum, Tim Lehmann) - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/packages/figma_variables_api/README.md b/packages/figma_variables_api/README.md deleted file mode 100644 index 7fe29ec9..00000000 --- a/packages/figma_variables_api/README.md +++ /dev/null @@ -1,34 +0,0 @@ -# Figma Variables Api - -[![Powered by Mason](https://img.shields.io/endpoint?url=https%3A%2F%2Ftinyurl.com%2Fmason-badge)](https://github.com/felangel/mason) -[![melos](https://img.shields.io/badge/maintained%20with-melos-f700ff.svg?style=flat-square)](https://github.com/invertase/melos) - - -Figma REST API for variables. - -## Installation 💻 - -**❗ In order to start using Figma Variables Api you must have the [Dart SDK][dart_install_link] installed on your machine.** - -Install via `dart pub add`: - -```sh -dart pub add figma_variables_api -``` - ---- - -## Continuous Integration 🤖 - -Figma Variables Api comes with a built-in [GitHub Actions workflow][github_actions_link] but you can also add your preferred CI/CD solution. - - ---- - - -[dart_install_link]: https://dart.dev/get-dart -[github_actions_link]: https://docs.github.com/en/actions/learn-github-actions -[license_badge]: https://img.shields.io/badge/license-MIT-blue.svg -[license_link]: https://opensource.org/licenses/MIT -[mason_link]: https://github.com/felangel/mason -[very_good_ventures_link]: https://verygood.ventures diff --git a/packages/figma_variables_api/analysis_options.yaml b/packages/figma_variables_api/analysis_options.yaml deleted file mode 100644 index 818e6e33..00000000 --- a/packages/figma_variables_api/analysis_options.yaml +++ /dev/null @@ -1,14 +0,0 @@ -include: package:lints/recommended.yaml - -analyzer: - exclude: - - "**/*.freezed.dart" - - "**/*.g.dart" - -linter: - rules: - - require_trailing_commas - - prefer_final_locals - - prefer_final_in_for_each - - use_super_parameters - - sort_constructors_first diff --git a/packages/figma_variables_api/coverage.svg b/packages/figma_variables_api/coverage.svg deleted file mode 100644 index 849fac1a..00000000 --- a/packages/figma_variables_api/coverage.svg +++ /dev/null @@ -1 +0,0 @@ -figma_variables_api coverage: 40.43%figma_variables_api coverage40.43% \ No newline at end of file diff --git a/packages/figma_variables_api/coverage/lcov.info b/packages/figma_variables_api/coverage/lcov.info deleted file mode 100644 index fe6999be..00000000 --- a/packages/figma_variables_api/coverage/lcov.info +++ /dev/null @@ -1,788 +0,0 @@ -SF:/home/runner/work/figmage/figmage/packages/figma_variables_api/lib/src/client.dart -DA:30,0 -DA:56,0 -DA:57,0 -DA:58,0 -DA:59,0 -DA:60,0 -DA:62,0 -DA:69,0 -DA:70,0 -DA:71,0 -DA:75,0 -DA:76,0 -DA:77,0 -DA:80,0 -DA:81,0 -DA:82,0 -DA:86,0 -DA:92,0 -DA:95,0 -DA:97,0 -DA:99,0 -DA:100,0 -DA:105,0 -DA:109,0 -DA:110,0 -DA:114,0 -DA:118,0 -DA:120,0 -DA:121,0 -DA:122,0 -DA:124,0 -DA:129,0 -DA:137,0 -DA:138,0 -DA:140,0 -DA:141,0 -DA:142,0 -DA:143,0 -DA:144,0 -DA:146,0 -DA:150,0 -DA:151,0 -DA:152,0 -DA:153,0 -DA:154,0 -DA:158,0 -DA:159,0 -DA:160,0 -DA:161,0 -DA:162,0 -DA:163,0 -DA:164,0 -DA:165,0 -DA:171,0 -DA:174,0 -DA:175,0 -DA:176,0 -DA:177,0 -DA:178,0 -DA:179,0 -DA:180,0 -DA:181,0 -DA:184,0 -DA:185,0 -DA:188,0 -DA:190,0 -DA:193,0 -DA:194,0 -DA:197,0 -DA:198,0 -DA:200,0 -DA:207,0 -DA:215,0 -LF:73 -LH:0 -end_of_record -SF:/home/runner/work/figmage/figmage/packages/figma_variables_api/lib/src/query.dart -DA:6,0 -DA:71,0 -DA:72,0 -DA:73,0 -DA:74,0 -DA:75,0 -DA:76,0 -DA:77,0 -DA:78,0 -DA:79,0 -DA:80,0 -DA:81,0 -DA:82,0 -DA:83,0 -DA:84,0 -DA:87,0 -LF:16 -LH:0 -end_of_record -SF:/home/runner/work/figmage/figmage/packages/figma_variables_api/lib/src/dto/file_styles_response/file_styles_response.dart -DA:13,0 -DA:23,0 -DA:24,0 -DA:47,0 -DA:49,0 -DA:50,0 -DA:51,0 -DA:52,0 -DA:53,0 -DA:54,0 -DA:55,0 -DA:56,0 -DA:57,0 -LF:13 -LH:0 -end_of_record -SF:/home/runner/work/figmage/figmage/packages/figma_variables_api/lib/src/dto/file_styles_response/file_styles_response.g.dart -DA:43,0 -DA:47,0 -DA:48,0 -DA:50,0 -DA:51,0 -DA:53,0 -DA:55,0 -DA:57,0 -DA:59,0 -DA:61,0 -DA:62,0 -DA:64,0 -DA:66,0 -DA:68,0 -DA:69,0 -DA:71,0 -DA:88,0 -DA:89,0 -DA:90,0 -DA:93,0 -DA:94,0 -DA:97,0 -DA:98,0 -DA:101,0 -DA:102,0 -DA:105,0 -DA:106,0 -DA:109,0 -DA:110,0 -DA:113,0 -DA:114,0 -DA:124,0 -DA:125,0 -DA:132,0 -DA:133,0 -DA:134,0 -DA:135,0 -DA:136,0 -DA:138,0 -DA:139,0 -DA:140,0 -DA:141,0 -DA:142,0 -DA:143,0 -DA:147,0 -DA:148,0 -DA:149,0 -DA:150,0 -DA:151,0 -DA:152,0 -DA:153,0 -DA:154,0 -DA:155,0 -LF:53 -LH:0 -end_of_record -SF:/home/runner/work/figmage/figmage/packages/figma_variables_api/lib/src/dto/nodes/node_content.dart -DA:14,1 -DA:27,1 -DA:28,1 -DA:61,2 -DA:63,1 -DA:64,1 -DA:65,1 -DA:66,1 -DA:67,1 -DA:68,1 -DA:69,1 -DA:70,1 -DA:71,1 -DA:72,1 -DA:73,1 -DA:74,1 -LF:16 -LH:16 -end_of_record -SF:/home/runner/work/figmage/figmage/packages/figma_variables_api/lib/src/dto/nodes/node_content.g.dart -DA:52,0 -DA:56,0 -DA:57,0 -DA:59,0 -DA:60,0 -DA:62,0 -DA:64,0 -DA:66,0 -DA:68,0 -DA:70,0 -DA:71,0 -DA:73,0 -DA:74,0 -DA:76,0 -DA:78,0 -DA:80,0 -DA:82,0 -DA:84,0 -DA:86,0 -DA:88,0 -DA:89,0 -DA:91,0 -DA:111,0 -DA:112,0 -DA:113,0 -DA:116,0 -DA:117,0 -DA:120,0 -DA:121,0 -DA:124,0 -DA:125,0 -DA:128,0 -DA:129,0 -DA:132,0 -DA:133,0 -DA:136,0 -DA:137,0 -DA:140,0 -DA:141,0 -DA:144,0 -DA:145,0 -DA:148,0 -DA:149,0 -DA:159,0 -DA:166,2 -DA:167,1 -DA:168,1 -DA:169,1 -DA:171,2 -DA:172,1 -DA:173,1 -DA:174,2 -DA:175,2 -DA:176,0 -DA:178,2 -DA:179,0 -DA:181,2 -DA:182,2 -DA:183,0 -DA:187,1 -DA:188,1 -DA:189,1 -DA:190,1 -DA:191,2 -DA:192,1 -DA:193,1 -DA:194,2 -DA:195,1 -DA:196,1 -DA:197,1 -DA:198,1 -LF:71 -LH:24 -end_of_record -SF:/home/runner/work/figmage/figmage/packages/figma_variables_api/lib/src/dto/nodes/nodes_response.g.dart -DA:40,0 -DA:44,0 -DA:45,0 -DA:47,0 -DA:48,0 -DA:50,0 -DA:52,0 -DA:54,0 -DA:56,0 -DA:58,0 -DA:59,0 -DA:61,0 -DA:62,0 -DA:64,0 -DA:80,0 -DA:81,0 -DA:82,0 -DA:85,0 -DA:86,0 -DA:89,0 -DA:90,0 -DA:93,0 -DA:94,0 -DA:97,0 -DA:98,0 -DA:101,0 -DA:102,0 -DA:112,0 -DA:119,0 -DA:120,0 -DA:121,0 -DA:122,0 -DA:123,0 -DA:125,0 -DA:126,0 -DA:127,0 -DA:128,0 -DA:129,0 -DA:133,0 -DA:134,0 -DA:135,0 -DA:136,0 -DA:137,0 -DA:138,0 -DA:139,0 -DA:140,0 -LF:46 -LH:0 -end_of_record -SF:/home/runner/work/figmage/figmage/packages/figma_variables_api/lib/src/dto/nodes/nodes_response.dart -DA:14,0 -DA:23,0 -DA:24,0 -DA:44,0 -DA:46,0 -DA:47,0 -DA:48,0 -DA:49,0 -DA:50,0 -DA:51,0 -DA:52,0 -DA:53,0 -LF:12 -LH:0 -end_of_record -SF:/home/runner/work/figmage/figmage/packages/figma_variables_api/lib/src/dto/styles/styles_response.g.dart -DA:31,0 -DA:35,0 -DA:36,0 -DA:38,0 -DA:39,0 -DA:41,0 -DA:42,0 -DA:44,0 -DA:57,0 -DA:58,0 -DA:59,0 -DA:62,0 -DA:63,0 -DA:66,0 -DA:67,0 -DA:77,0 -DA:96,0 -DA:100,0 -DA:101,0 -DA:103,0 -DA:114,0 -DA:115,0 -DA:116,0 -DA:126,0 -DA:127,0 -DA:134,0 -DA:135,0 -DA:136,0 -DA:137,0 -DA:138,0 -DA:140,0 -DA:143,0 -DA:144,0 -DA:145,0 -DA:146,0 -DA:147,0 -DA:150,0 -DA:151,0 -DA:152,0 -DA:153,0 -DA:154,0 -DA:157,0 -DA:158,0 -DA:159,0 -LF:44 -LH:0 -end_of_record -SF:/home/runner/work/figmage/figmage/packages/figma_variables_api/lib/src/dto/styles/styles_response.dart -DA:12,0 -DA:14,0 -DA:15,0 -DA:26,0 -DA:27,0 -DA:29,0 -DA:35,0 -DA:37,0 -DA:38,0 -DA:42,0 -DA:43,0 -DA:45,0 -LF:12 -LH:0 -end_of_record -SF:/home/runner/work/figmage/figmage/packages/figma_variables_api/lib/src/dto/variable/variable_dto.dart -DA:14,3 -DA:28,3 -DA:29,3 -DA:43,1 -DA:44,1 -DA:45,1 -DA:46,1 -DA:47,1 -DA:48,1 -DA:49,1 -DA:50,1 -DA:51,1 -DA:52,1 -DA:53,1 -DA:54,1 -DA:55,1 -DA:58,4 -LF:17 -LH:17 -end_of_record -SF:/home/runner/work/figmage/figmage/packages/figma_variables_api/lib/src/dto/variable/variable_dto.g.dart -DA:55,2 -DA:59,0 -DA:60,0 -DA:62,0 -DA:63,0 -DA:65,0 -DA:66,0 -DA:68,0 -DA:69,0 -DA:71,0 -DA:73,0 -DA:75,0 -DA:77,0 -DA:79,0 -DA:80,0 -DA:82,0 -DA:84,0 -DA:86,0 -DA:88,0 -DA:90,0 -DA:91,0 -DA:93,0 -DA:95,0 -DA:97,2 -DA:118,2 -DA:119,2 -DA:120,4 -DA:123,2 -DA:124,0 -DA:127,2 -DA:128,4 -DA:131,2 -DA:132,4 -DA:136,2 -DA:138,4 -DA:142,2 -DA:143,4 -DA:147,2 -DA:148,4 -DA:152,2 -DA:154,4 -DA:158,2 -DA:159,4 -DA:162,2 -DA:163,4 -DA:167,2 -DA:168,4 -DA:178,4 -DA:185,6 -DA:186,3 -DA:187,3 -DA:188,3 -DA:189,3 -DA:190,3 -DA:191,6 -DA:192,3 -DA:193,3 -DA:194,6 -DA:195,9 -DA:198,12 -DA:199,6 -DA:202,2 -DA:203,2 -DA:204,2 -DA:205,2 -DA:206,2 -DA:207,2 -DA:208,2 -DA:209,4 -DA:210,2 -DA:211,2 -DA:213,10 -DA:214,2 -DA:215,2 -LF:74 -LH:51 -end_of_record -SF:/home/runner/work/figmage/figmage/packages/figma_variables_api/lib/src/dto/variable_mode_value/variable_mode_value_dto.dart -DA:7,4 -DA:9,4 -DA:10,4 -DA:11,1 -DA:12,4 -DA:13,4 -DA:14,4 -DA:15,1 -DA:16,4 -DA:17,4 -DA:18,3 -DA:19,3 -DA:20,3 -DA:21,3 -DA:22,12 -DA:23,4 -DA:26,1 -DA:34,1 -DA:38,1 -DA:39,1 -DA:41,1 -DA:42,2 -DA:47,2 -DA:51,2 -DA:52,2 -DA:54,1 -DA:55,2 -DA:60,1 -DA:64,1 -DA:65,1 -DA:67,1 -DA:68,2 -DA:73,3 -DA:80,3 -DA:81,3 -DA:91,1 -DA:92,3 -DA:93,3 -DA:94,3 -DA:95,3 -DA:96,6 -DA:99,2 -DA:100,2 -DA:102,1 -DA:103,2 -DA:108,4 -DA:110,4 -DA:111,4 -DA:117,3 -DA:118,3 -DA:120,1 -DA:121,3 -LF:52 -LH:52 -end_of_record -SF:/home/runner/work/figmage/figmage/packages/figma_variables_api/lib/src/dto/variable_mode_value/variable_mode_value_dto.g.dart -DA:9,0 -DA:11,0 -DA:12,0 -DA:15,0 -DA:17,0 -DA:18,0 -DA:21,0 -DA:23,0 -DA:24,0 -DA:27,0 -DA:29,0 -DA:30,0 -DA:33,0 -DA:35,0 -DA:36,0 -DA:39,0 -DA:41,0 -DA:42,0 -DA:45,3 -DA:47,3 -DA:48,6 -DA:49,6 -DA:50,6 -DA:51,6 -DA:54,2 -DA:56,2 -DA:57,2 -DA:58,2 -DA:59,2 -DA:60,2 -DA:63,4 -DA:65,4 -DA:66,4 -DA:67,4 -DA:70,3 -DA:72,3 -DA:73,3 -DA:74,3 -LF:38 -LH:20 -end_of_record -SF:/home/runner/work/figmage/figmage/packages/figma_variables_api/lib/src/dto/variable_collection/variable_collection_dto.g.dart -DA:47,1 -DA:51,0 -DA:53,0 -DA:55,0 -DA:56,0 -DA:58,0 -DA:59,0 -DA:61,0 -DA:62,0 -DA:64,0 -DA:66,0 -DA:68,0 -DA:69,0 -DA:71,0 -DA:73,0 -DA:75,0 -DA:77,0 -DA:79,1 -DA:97,1 -DA:99,1 -DA:100,2 -DA:103,1 -DA:104,2 -DA:107,1 -DA:108,0 -DA:111,1 -DA:112,2 -DA:115,1 -DA:116,2 -DA:119,1 -DA:120,2 -DA:124,1 -DA:126,2 -DA:130,1 -DA:131,2 -DA:141,1 -DA:142,1 -DA:149,3 -DA:151,3 -DA:152,3 -DA:153,3 -DA:154,3 -DA:155,3 -DA:156,3 -DA:157,9 -DA:158,3 -DA:159,3 -DA:160,3 -DA:161,3 -DA:162,6 -DA:163,3 -DA:166,2 -DA:168,2 -DA:169,2 -DA:170,2 -DA:171,2 -DA:172,2 -DA:173,10 -DA:174,2 -DA:175,2 -DA:176,2 -LF:61 -LH:44 -end_of_record -SF:/home/runner/work/figmage/figmage/packages/figma_variables_api/lib/src/dto/variable_collection/variable_collection_dto.dart -DA:11,3 -DA:22,3 -DA:23,3 -DA:33,1 -DA:34,1 -DA:35,1 -DA:36,1 -DA:37,1 -DA:38,1 -DA:39,1 -DA:40,1 -DA:41,1 -DA:42,1 -DA:45,4 -LF:14 -LH:14 -end_of_record -SF:/home/runner/work/figmage/figmage/packages/figma_variables_api/lib/src/dto/variable_mode/variable_mode_dto.dart -DA:10,3 -DA:15,3 -DA:16,3 -DA:21,1 -DA:22,3 -DA:24,4 -LF:6 -LH:6 -end_of_record -SF:/home/runner/work/figmage/figmage/packages/figma_variables_api/lib/src/dto/variable_mode/variable_mode_dto.g.dart -DA:28,0 -DA:32,0 -DA:33,0 -DA:35,0 -DA:36,0 -DA:38,0 -DA:50,0 -DA:51,0 -DA:52,0 -DA:55,0 -DA:56,0 -DA:66,0 -DA:73,3 -DA:74,3 -DA:75,3 -DA:76,3 -DA:79,2 -DA:80,2 -DA:81,2 -DA:82,2 -LF:20 -LH:8 -end_of_record -SF:/home/runner/work/figmage/figmage/packages/figma_variables_api/lib/src/dto/variable_response/variables_response_dto.g.dart -DA:32,0 -DA:36,0 -DA:37,0 -DA:39,0 -DA:40,0 -DA:42,0 -DA:43,0 -DA:45,0 -DA:58,0 -DA:59,0 -DA:60,0 -DA:63,0 -DA:64,0 -DA:67,0 -DA:68,0 -DA:78,0 -DA:79,0 -DA:86,2 -DA:88,2 -DA:89,4 -DA:90,2 -DA:91,4 -DA:94,1 -DA:96,1 -DA:97,1 -DA:98,1 -DA:99,2 -LF:27 -LH:10 -end_of_record -SF:/home/runner/work/figmage/figmage/packages/figma_variables_api/lib/src/dto/variable_response/variables_response_dto.dart -DA:12,2 -DA:18,2 -DA:19,2 -DA:30,1 -DA:31,4 -DA:33,2 -LF:6 -LH:6 -end_of_record -SF:/home/runner/work/figmage/figmage/packages/figma_variables_api/lib/src/dto/variables_meta/variables_meta_dto.dart -DA:12,2 -DA:17,2 -DA:18,2 -DA:22,0 -DA:23,0 -DA:25,2 -LF:6 -LH:4 -end_of_record -SF:/home/runner/work/figmage/figmage/packages/figma_variables_api/lib/src/dto/variables_meta/variables_meta_dto.g.dart -DA:29,0 -DA:33,0 -DA:35,0 -DA:37,0 -DA:40,0 -DA:42,0 -DA:54,0 -DA:55,0 -DA:56,0 -DA:60,0 -DA:62,0 -DA:72,0 -DA:79,2 -DA:80,2 -DA:81,4 -DA:82,6 -DA:85,4 -DA:86,4 -DA:87,2 -DA:91,1 -DA:92,1 -DA:93,5 -DA:95,5 -LF:23 -LH:11 -end_of_record diff --git a/packages/figma_variables_api/lib/figma_variables_api.dart b/packages/figma_variables_api/lib/figma_variables_api.dart deleted file mode 100644 index e4076fe6..00000000 --- a/packages/figma_variables_api/lib/figma_variables_api.dart +++ /dev/null @@ -1,6 +0,0 @@ -/// Figma REST API for variables. -library figma_variables_api; - -export 'src/client.dart'; -export 'src/query.dart'; -export 'src/models.dart'; diff --git a/packages/figma_variables_api/lib/src/client.dart b/packages/figma_variables_api/lib/src/client.dart deleted file mode 100644 index bedb96f8..00000000 --- a/packages/figma_variables_api/lib/src/client.dart +++ /dev/null @@ -1,222 +0,0 @@ -/// Figma Variables API Client -/// -/// Inspired by the original client developed by Arne Molland, this library -/// offers an easy-to-use interface for making requests to the Figma Variables API -/// and parsing responses into Dart objects. -/// -/// Original Source: -/// https://github.com/arnemolland/figma - -import 'dart:convert'; -import 'dart:io'; - -import 'package:figma_variables_api/figma_variables_api.dart'; -import 'package:http/http.dart'; -import 'package:http2/http2.dart'; - -/// Figma API base URL. -const base = 'api.figma.com'; - -/// A constant that is true if the application was compiled to run on the web. -/// -/// This implementation takes advantage of the fact that JavaScript does not support integers. -/// In this environment, Dart's doubles and ints are backed by the same kind of object. Thus a -/// double 0.0 is identical to an integer 0. This is not true for Dart code running in -/// AOT or on the VM. -const bool kIsWeb = identical(0, 0.0); - -/// A client for interacting with the Figma API. -class FigmaClient { - FigmaClient( - this.accessToken, { - this.apiVersion = 'v1', - this.useHttp2 = !kIsWeb, - this.useOAuth = false, - }); - - /// Use HTTP2 sockets for interacting with API. - /// - /// This is the recommended way, but it may not work on certain platforms like web. - /// - /// If `false`, then the `http` package is used. - final bool useHttp2; - - /// The personal access token for the Figma Account to be used - /// Or the OAuth token, if useOAuth is true. - final String accessToken; - - /// Specifies the Figma API version to be used. Should only be - /// specified if package is not updated with a new API release. - final String apiVersion; - - // If true, then use accessToken as OAuth token when calling figma API. - final bool useOAuth; - - /// Does an authenticated GET request towards the Figma API. - Future> authenticatedGet(String url) async { - final uri = Uri.parse(url); - return await _send('GET', uri, _authHeaders).then((res) { - if (res.statusCode >= 200 && res.statusCode < 300) { - return jsonDecode(res.body); - } else { - throw FigmaException(code: res.statusCode, message: res.body); - } - }); - } - - /// Retrieves the published local variables from the Figma file specified by - /// [fileId]. - Future getLocalVariables(String fileId) async { - final json = await _getFigma('/files/$fileId/variables/local'); - return VariablesResponseDto.fromJson(json); - } - - /// Retrieves all published styles from the Figma file specified by [key]. - Future getFileStyles(String key, [FigmaQuery? query]) async => - _getFigma('/files/$key/styles', query) - .then((data) => StylesResponse.fromJson(data)); - - /// Retrieves the file nodes specified. - Future getFileNodes(String key, FigmaQuery query) async { - final json = await _getFigma('/files/$key/nodes', query); - return NodesResponse.fromJson(json); - } - - /// Retrieves images for the specified nodes. - Future<({Map images, String? err})> getImages( - String key, - List ids, { - String format = 'png', - num? scale, - }) async { - final query = FigmaQuery( - ids: ids, - format: format, - scale: scale?.toDouble(), - ); - final json = await _getFigma('/images/$key', query); - return ( - images: Map.from(json['images'] as Map), - err: json['err'] as String?, - ); - } - - /// Retreives the local styles for a file with given [key]. - Future getLocalFileStyles( - String key, [ - FigmaQuery? query, - ]) async { - final json = await _getFigma('/files/$key', query); - return FileStylesResponse.fromJson(json); - } - - /// Does a GET request towards the Figma API. - Future> _getFigma( - String path, [ - FigmaQuery? query, - ]) async { - final uri = Uri.https(base, '$apiVersion$path', query?.params); - - return await _send('GET', uri, _authHeaders).then((res) { - if (res.statusCode >= 200 && res.statusCode < 300) { - return jsonDecode(res.body); - } else { - throw FigmaException(code: res.statusCode, message: res.body); - } - }); - } - - Future<_Response> _send( - String method, - Uri uri, - Map headers, [ - String? body, - ]) async { - // HTTP/2 is not supported on all platforms, so we need to fallback to - // HTTP/1.1 in that case. - if (!useHttp2) { - final client = Client(); - try { - final request = Request(method, uri); - request.headers.addAll(headers); - final response = await client.send(request); - final body = await response.stream.toBytes(); - return _Response(response.statusCode, utf8.decode(body)); - } finally { - client.close(); - } - } - - final transport = ClientTransportConnection.viaSocket( - await SecureSocket.connect( - uri.host, - uri.port, - supportedProtocols: ['h2'], - ), - ); - - final stream = transport.makeRequest( - [ - Header.ascii(':method', method), - Header.ascii(':path', uri.path + (uri.hasQuery ? '?${uri.query}' : '')), - Header.ascii(':scheme', uri.scheme), - Header.ascii(':authority', uri.host), - ...headers.entries.map( - (e) => Header.ascii(e.key.toLowerCase(), e.value), - ), - ], - endStream: body == null, - ); - if (body != null) { - stream.sendData(utf8.encode(body), endStream: true); - } - var status = 200; - final buffer = []; - await for (final message in stream.incomingMessages) { - if (message is HeadersStreamMessage) { - for (final header in message.headers) { - final name = utf8.decode(header.name); - final value = utf8.decode(header.value); - if (name == ':status') { - status = int.parse(value); - } - } - } else if (message is DataStreamMessage) { - buffer.addAll(message.bytes); - } - } - await transport.finish(); - - return _Response(status, utf8.decode(buffer)); - } - - Map get _authHeaders { - final headers = { - 'Content-Type': 'application/json', - }; - if (useOAuth) { - headers['Authorization'] = 'Bearer $accessToken'; - } else { - headers['X-Figma-Token'] = accessToken; - } - return headers; - } -} - -class _Response { - const _Response(this.statusCode, this.body); - - final int statusCode; - final String body; -} - -/// An error from the [Figma API docs](https://www.figma.com/developers/api#errors). -class FigmaException implements Exception { - const FigmaException({this.code, this.message}); - - /// HTTP status code. - final int? code; - - /// Error message. - final String? message; -} diff --git a/packages/figma_variables_api/lib/src/dto/file_styles_response/file_styles_response.dart b/packages/figma_variables_api/lib/src/dto/file_styles_response/file_styles_response.dart deleted file mode 100644 index 3f09eb76..00000000 --- a/packages/figma_variables_api/lib/src/dto/file_styles_response/file_styles_response.dart +++ /dev/null @@ -1,59 +0,0 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; -import 'package:figma_variables_api/figma_variables_api.dart'; -import 'package:json_annotation/json_annotation.dart'; - -part 'file_styles_response.g.dart'; - -/// A reduced version of the file endpoint response, that only contains styles -/// and metadata and leaves out the document. -@JsonSerializable() -@CopyWith() -class FileStylesResponse extends Equatable { - FileStylesResponse({ - this.name, - this.role, - this.lastModified, - this.thumbnailUrl, - this.version, - this.schemaVersion, - this.styles, - }); - - factory FileStylesResponse.fromJson(Map json) => - _$FileStylesResponseFromJson(json); - - /// Name of the file. - final String? name; - - /// Role. - final String? role; - - /// Last time file was modified. - final DateTime? lastModified; - - /// URL to file thumbnail. - final String? thumbnailUrl; - - /// File version. - final String? version; - - /// The schema version of the file. - final int? schemaVersion; - - /// Map of styles within the file, if any. - final Map? styles; - - Map toJson() => _$FileStylesResponseToJson(this); - - @override - List get props => [ - name, - role, - lastModified, - thumbnailUrl, - version, - schemaVersion, - styles, - ]; -} diff --git a/packages/figma_variables_api/lib/src/dto/file_styles_response/file_styles_response.g.dart b/packages/figma_variables_api/lib/src/dto/file_styles_response/file_styles_response.g.dart deleted file mode 100644 index f7e2dc95..00000000 --- a/packages/figma_variables_api/lib/src/dto/file_styles_response/file_styles_response.g.dart +++ /dev/null @@ -1,156 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'file_styles_response.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$FileStylesResponseCWProxy { - FileStylesResponse name(String? name); - - FileStylesResponse role(String? role); - - FileStylesResponse lastModified(DateTime? lastModified); - - FileStylesResponse thumbnailUrl(String? thumbnailUrl); - - FileStylesResponse version(String? version); - - FileStylesResponse schemaVersion(int? schemaVersion); - - FileStylesResponse styles(Map? styles); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `FileStylesResponse(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// FileStylesResponse(...).copyWith(id: 12, name: "My name") - /// ```` - FileStylesResponse call({ - String? name, - String? role, - DateTime? lastModified, - String? thumbnailUrl, - String? version, - int? schemaVersion, - Map? styles, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfFileStylesResponse.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfFileStylesResponse.copyWith.fieldName(...)` -class _$FileStylesResponseCWProxyImpl implements _$FileStylesResponseCWProxy { - const _$FileStylesResponseCWProxyImpl(this._value); - - final FileStylesResponse _value; - - @override - FileStylesResponse name(String? name) => this(name: name); - - @override - FileStylesResponse role(String? role) => this(role: role); - - @override - FileStylesResponse lastModified(DateTime? lastModified) => - this(lastModified: lastModified); - - @override - FileStylesResponse thumbnailUrl(String? thumbnailUrl) => - this(thumbnailUrl: thumbnailUrl); - - @override - FileStylesResponse version(String? version) => this(version: version); - - @override - FileStylesResponse schemaVersion(int? schemaVersion) => - this(schemaVersion: schemaVersion); - - @override - FileStylesResponse styles(Map? styles) => this(styles: styles); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `FileStylesResponse(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// FileStylesResponse(...).copyWith(id: 12, name: "My name") - /// ```` - FileStylesResponse call({ - Object? name = const $CopyWithPlaceholder(), - Object? role = const $CopyWithPlaceholder(), - Object? lastModified = const $CopyWithPlaceholder(), - Object? thumbnailUrl = const $CopyWithPlaceholder(), - Object? version = const $CopyWithPlaceholder(), - Object? schemaVersion = const $CopyWithPlaceholder(), - Object? styles = const $CopyWithPlaceholder(), - }) { - return FileStylesResponse( - name: name == const $CopyWithPlaceholder() - ? _value.name - // ignore: cast_nullable_to_non_nullable - : name as String?, - role: role == const $CopyWithPlaceholder() - ? _value.role - // ignore: cast_nullable_to_non_nullable - : role as String?, - lastModified: lastModified == const $CopyWithPlaceholder() - ? _value.lastModified - // ignore: cast_nullable_to_non_nullable - : lastModified as DateTime?, - thumbnailUrl: thumbnailUrl == const $CopyWithPlaceholder() - ? _value.thumbnailUrl - // ignore: cast_nullable_to_non_nullable - : thumbnailUrl as String?, - version: version == const $CopyWithPlaceholder() - ? _value.version - // ignore: cast_nullable_to_non_nullable - : version as String?, - schemaVersion: schemaVersion == const $CopyWithPlaceholder() - ? _value.schemaVersion - // ignore: cast_nullable_to_non_nullable - : schemaVersion as int?, - styles: styles == const $CopyWithPlaceholder() - ? _value.styles - // ignore: cast_nullable_to_non_nullable - : styles as Map?, - ); - } -} - -extension $FileStylesResponseCopyWith on FileStylesResponse { - /// Returns a callable class that can be used as follows: `instanceOfFileStylesResponse.copyWith(...)` or like so:`instanceOfFileStylesResponse.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$FileStylesResponseCWProxy get copyWith => - _$FileStylesResponseCWProxyImpl(this); -} - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -FileStylesResponse _$FileStylesResponseFromJson(Map json) => - FileStylesResponse( - name: json['name'] as String?, - role: json['role'] as String?, - lastModified: json['lastModified'] == null - ? null - : DateTime.parse(json['lastModified'] as String), - thumbnailUrl: json['thumbnailUrl'] as String?, - version: json['version'] as String?, - schemaVersion: (json['schemaVersion'] as num?)?.toInt(), - styles: (json['styles'] as Map?)?.map( - (k, e) => MapEntry(k, Style.fromJson(e as Map)), - ), - ); - -Map _$FileStylesResponseToJson(FileStylesResponse instance) => - { - 'name': instance.name, - 'role': instance.role, - 'lastModified': instance.lastModified?.toIso8601String(), - 'thumbnailUrl': instance.thumbnailUrl, - 'version': instance.version, - 'schemaVersion': instance.schemaVersion, - 'styles': instance.styles, - }; diff --git a/packages/figma_variables_api/lib/src/dto/nodes/node_content.dart b/packages/figma_variables_api/lib/src/dto/nodes/node_content.dart deleted file mode 100644 index 2553c558..00000000 --- a/packages/figma_variables_api/lib/src/dto/nodes/node_content.dart +++ /dev/null @@ -1,76 +0,0 @@ -import 'package:equatable/equatable.dart'; -import 'package:figma/figma.dart'; -import 'package:json_annotation/json_annotation.dart'; -import 'package:copy_with_extension/copy_with_extension.dart'; -// ignore: implementation_imports -import 'package:figma/src/converters/converters.dart'; - -part 'node_content.g.dart'; - -/// A response object containing a file. -@JsonSerializable() -@CopyWith() -class NodeContent extends Equatable { - NodeContent({ - this.name, - this.role, - this.lastModified, - this.thumbnailUrl, - this.version, - this.document, - this.components, - this.componentSets, - this.schemaVersion, - this.styles, - }); - - factory NodeContent.fromJson(Map json) => - _$NodeContentFromJson(json); - - /// Name of the file. - final String? name; - - /// Role. - final String? role; - - /// Last time file was modified. - final DateTime? lastModified; - - /// URL to file thumbnail. - final String? thumbnailUrl; - - /// File version. - final String? version; - - /// File document (top-level node). - @NodeJsonConverter() - final Node? document; - - /// File components, if any. - final Map? components; - - /// File component sets, if any. - final Map? componentSets; - - /// The schema version of the file. - final int? schemaVersion; - - /// Map of styles within the file, if any. - final Map? styles; - - Map toJson() => _$NodeContentToJson(this); - - @override - List get props => [ - name, - role, - lastModified, - thumbnailUrl, - version, - document, - components, - componentSets, - schemaVersion, - styles, - ]; -} diff --git a/packages/figma_variables_api/lib/src/dto/nodes/node_content.g.dart b/packages/figma_variables_api/lib/src/dto/nodes/node_content.g.dart deleted file mode 100644 index 13762b81..00000000 --- a/packages/figma_variables_api/lib/src/dto/nodes/node_content.g.dart +++ /dev/null @@ -1,199 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'node_content.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$NodeContentCWProxy { - NodeContent name(String? name); - - NodeContent role(String? role); - - NodeContent lastModified(DateTime? lastModified); - - NodeContent thumbnailUrl(String? thumbnailUrl); - - NodeContent version(String? version); - - NodeContent document(Node? document); - - NodeContent components(Map? components); - - NodeContent componentSets(Map? componentSets); - - NodeContent schemaVersion(int? schemaVersion); - - NodeContent styles(Map? styles); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `NodeContent(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// NodeContent(...).copyWith(id: 12, name: "My name") - /// ```` - NodeContent call({ - String? name, - String? role, - DateTime? lastModified, - String? thumbnailUrl, - String? version, - Node? document, - Map? components, - Map? componentSets, - int? schemaVersion, - Map? styles, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfNodeContent.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfNodeContent.copyWith.fieldName(...)` -class _$NodeContentCWProxyImpl implements _$NodeContentCWProxy { - const _$NodeContentCWProxyImpl(this._value); - - final NodeContent _value; - - @override - NodeContent name(String? name) => this(name: name); - - @override - NodeContent role(String? role) => this(role: role); - - @override - NodeContent lastModified(DateTime? lastModified) => - this(lastModified: lastModified); - - @override - NodeContent thumbnailUrl(String? thumbnailUrl) => - this(thumbnailUrl: thumbnailUrl); - - @override - NodeContent version(String? version) => this(version: version); - - @override - NodeContent document(Node? document) => this(document: document); - - @override - NodeContent components(Map? components) => - this(components: components); - - @override - NodeContent componentSets(Map? componentSets) => - this(componentSets: componentSets); - - @override - NodeContent schemaVersion(int? schemaVersion) => - this(schemaVersion: schemaVersion); - - @override - NodeContent styles(Map? styles) => this(styles: styles); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `NodeContent(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// NodeContent(...).copyWith(id: 12, name: "My name") - /// ```` - NodeContent call({ - Object? name = const $CopyWithPlaceholder(), - Object? role = const $CopyWithPlaceholder(), - Object? lastModified = const $CopyWithPlaceholder(), - Object? thumbnailUrl = const $CopyWithPlaceholder(), - Object? version = const $CopyWithPlaceholder(), - Object? document = const $CopyWithPlaceholder(), - Object? components = const $CopyWithPlaceholder(), - Object? componentSets = const $CopyWithPlaceholder(), - Object? schemaVersion = const $CopyWithPlaceholder(), - Object? styles = const $CopyWithPlaceholder(), - }) { - return NodeContent( - name: name == const $CopyWithPlaceholder() - ? _value.name - // ignore: cast_nullable_to_non_nullable - : name as String?, - role: role == const $CopyWithPlaceholder() - ? _value.role - // ignore: cast_nullable_to_non_nullable - : role as String?, - lastModified: lastModified == const $CopyWithPlaceholder() - ? _value.lastModified - // ignore: cast_nullable_to_non_nullable - : lastModified as DateTime?, - thumbnailUrl: thumbnailUrl == const $CopyWithPlaceholder() - ? _value.thumbnailUrl - // ignore: cast_nullable_to_non_nullable - : thumbnailUrl as String?, - version: version == const $CopyWithPlaceholder() - ? _value.version - // ignore: cast_nullable_to_non_nullable - : version as String?, - document: document == const $CopyWithPlaceholder() - ? _value.document - // ignore: cast_nullable_to_non_nullable - : document as Node?, - components: components == const $CopyWithPlaceholder() - ? _value.components - // ignore: cast_nullable_to_non_nullable - : components as Map?, - componentSets: componentSets == const $CopyWithPlaceholder() - ? _value.componentSets - // ignore: cast_nullable_to_non_nullable - : componentSets as Map?, - schemaVersion: schemaVersion == const $CopyWithPlaceholder() - ? _value.schemaVersion - // ignore: cast_nullable_to_non_nullable - : schemaVersion as int?, - styles: styles == const $CopyWithPlaceholder() - ? _value.styles - // ignore: cast_nullable_to_non_nullable - : styles as Map?, - ); - } -} - -extension $NodeContentCopyWith on NodeContent { - /// Returns a callable class that can be used as follows: `instanceOfNodeContent.copyWith(...)` or like so:`instanceOfNodeContent.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$NodeContentCWProxy get copyWith => _$NodeContentCWProxyImpl(this); -} - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -NodeContent _$NodeContentFromJson(Map json) => NodeContent( - name: json['name'] as String?, - role: json['role'] as String?, - lastModified: json['lastModified'] == null - ? null - : DateTime.parse(json['lastModified'] as String), - thumbnailUrl: json['thumbnailUrl'] as String?, - version: json['version'] as String?, - document: const NodeJsonConverter().fromJson(json['document']), - components: (json['components'] as Map?)?.map( - (k, e) => MapEntry(k, Component.fromJson(e as Map)), - ), - componentSets: (json['componentSets'] as Map?)?.map( - (k, e) => MapEntry(k, ComponentSet.fromJson(e as Map)), - ), - schemaVersion: (json['schemaVersion'] as num?)?.toInt(), - styles: (json['styles'] as Map?)?.map( - (k, e) => MapEntry(k, Style.fromJson(e as Map)), - ), - ); - -Map _$NodeContentToJson(NodeContent instance) => - { - 'name': instance.name, - 'role': instance.role, - 'lastModified': instance.lastModified?.toIso8601String(), - 'thumbnailUrl': instance.thumbnailUrl, - 'version': instance.version, - 'document': const NodeJsonConverter().toJson(instance.document), - 'components': instance.components, - 'componentSets': instance.componentSets, - 'schemaVersion': instance.schemaVersion, - 'styles': instance.styles, - }; diff --git a/packages/figma_variables_api/lib/src/dto/nodes/nodes_response.dart b/packages/figma_variables_api/lib/src/dto/nodes/nodes_response.dart deleted file mode 100644 index c8011576..00000000 --- a/packages/figma_variables_api/lib/src/dto/nodes/nodes_response.dart +++ /dev/null @@ -1,55 +0,0 @@ -import 'package:equatable/equatable.dart'; -import 'package:figma_variables_api/src/dto/nodes/node_content.dart'; -import 'package:json_annotation/json_annotation.dart'; -import 'package:copy_with_extension/copy_with_extension.dart'; - -export 'node_content.dart'; - -part 'nodes_response.g.dart'; - -/// A response object containing a list of a project's files. -@JsonSerializable() -@CopyWith() -class NodesResponse extends Equatable { - NodesResponse({ - this.name, - this.role, - this.lastModified, - this.thumbnailUrl, - this.err, - this.nodes, - }); - - factory NodesResponse.fromJson(Map json) => - _$NodesResponseFromJson(json); - - /// File name. - final String? name; - - /// Role. - final String? role; - - /// Date the file was last modified. - final DateTime? lastModified; - - /// URL to the thumbnail of the file. - final String? thumbnailUrl; - - /// Error message. - final String? err; - - /// Map from each [Node] id to the corresponding object. - final Map? nodes; - - Map toJson() => _$NodesResponseToJson(this); - - @override - List get props => [ - name, - role, - lastModified, - thumbnailUrl, - err, - nodes, - ]; -} diff --git a/packages/figma_variables_api/lib/src/dto/nodes/nodes_response.g.dart b/packages/figma_variables_api/lib/src/dto/nodes/nodes_response.g.dart deleted file mode 100644 index 7c9baa58..00000000 --- a/packages/figma_variables_api/lib/src/dto/nodes/nodes_response.g.dart +++ /dev/null @@ -1,141 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'nodes_response.dart'; - -// ************************************************************************** -// CopyWithGenerator -// ************************************************************************** - -abstract class _$NodesResponseCWProxy { - NodesResponse name(String? name); - - NodesResponse role(String? role); - - NodesResponse lastModified(DateTime? lastModified); - - NodesResponse thumbnailUrl(String? thumbnailUrl); - - NodesResponse err(String? err); - - NodesResponse nodes(Map? nodes); - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `NodesResponse(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// NodesResponse(...).copyWith(id: 12, name: "My name") - /// ```` - NodesResponse call({ - String? name, - String? role, - DateTime? lastModified, - String? thumbnailUrl, - String? err, - Map? nodes, - }); -} - -/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfNodesResponse.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfNodesResponse.copyWith.fieldName(...)` -class _$NodesResponseCWProxyImpl implements _$NodesResponseCWProxy { - const _$NodesResponseCWProxyImpl(this._value); - - final NodesResponse _value; - - @override - NodesResponse name(String? name) => this(name: name); - - @override - NodesResponse role(String? role) => this(role: role); - - @override - NodesResponse lastModified(DateTime? lastModified) => - this(lastModified: lastModified); - - @override - NodesResponse thumbnailUrl(String? thumbnailUrl) => - this(thumbnailUrl: thumbnailUrl); - - @override - NodesResponse err(String? err) => this(err: err); - - @override - NodesResponse nodes(Map? nodes) => this(nodes: nodes); - - @override - - /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `NodesResponse(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. - /// - /// Usage - /// ```dart - /// NodesResponse(...).copyWith(id: 12, name: "My name") - /// ```` - NodesResponse call({ - Object? name = const $CopyWithPlaceholder(), - Object? role = const $CopyWithPlaceholder(), - Object? lastModified = const $CopyWithPlaceholder(), - Object? thumbnailUrl = const $CopyWithPlaceholder(), - Object? err = const $CopyWithPlaceholder(), - Object? nodes = const $CopyWithPlaceholder(), - }) { - return NodesResponse( - name: name == const $CopyWithPlaceholder() - ? _value.name - // ignore: cast_nullable_to_non_nullable - : name as String?, - role: role == const $CopyWithPlaceholder() - ? _value.role - // ignore: cast_nullable_to_non_nullable - : role as String?, - lastModified: lastModified == const $CopyWithPlaceholder() - ? _value.lastModified - // ignore: cast_nullable_to_non_nullable - : lastModified as DateTime?, - thumbnailUrl: thumbnailUrl == const $CopyWithPlaceholder() - ? _value.thumbnailUrl - // ignore: cast_nullable_to_non_nullable - : thumbnailUrl as String?, - err: err == const $CopyWithPlaceholder() - ? _value.err - // ignore: cast_nullable_to_non_nullable - : err as String?, - nodes: nodes == const $CopyWithPlaceholder() - ? _value.nodes - // ignore: cast_nullable_to_non_nullable - : nodes as Map?, - ); - } -} - -extension $NodesResponseCopyWith on NodesResponse { - /// Returns a callable class that can be used as follows: `instanceOfNodesResponse.copyWith(...)` or like so:`instanceOfNodesResponse.copyWith.fieldName(...)`. - // ignore: library_private_types_in_public_api - _$NodesResponseCWProxy get copyWith => _$NodesResponseCWProxyImpl(this); -} - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -NodesResponse _$NodesResponseFromJson(Map json) => - NodesResponse( - name: json['name'] as String?, - role: json['role'] as String?, - lastModified: json['lastModified'] == null - ? null - : DateTime.parse(json['lastModified'] as String), - thumbnailUrl: json['thumbnailUrl'] as String?, - err: json['err'] as String?, - nodes: (json['nodes'] as Map?)?.map( - (k, e) => MapEntry(k, NodeContent.fromJson(e as Map)), - ), - ); - -Map _$NodesResponseToJson(NodesResponse instance) => - { - 'name': instance.name, - 'role': instance.role, - 'lastModified': instance.lastModified?.toIso8601String(), - 'thumbnailUrl': instance.thumbnailUrl, - 'err': instance.err, - 'nodes': instance.nodes, - }; diff --git a/packages/figma_variables_api/lib/src/dto/package_figma_models.dart b/packages/figma_variables_api/lib/src/dto/package_figma_models.dart deleted file mode 100644 index 98e6533e..00000000 --- a/packages/figma_variables_api/lib/src/dto/package_figma_models.dart +++ /dev/null @@ -1,6 +0,0 @@ -/// Models that are exported from the `figma` package. -/// -/// Until the `figma` package is fixed to work for Node queries, this is all we -/// have. -export 'package:figma/figma.dart' - show Node, Text, Rectangle, Paint, Color, Style, TypeStyle; diff --git a/packages/figma_variables_api/lib/src/dto/styles/style_type.dart b/packages/figma_variables_api/lib/src/dto/styles/style_type.dart deleted file mode 100644 index e37d5dd5..00000000 --- a/packages/figma_variables_api/lib/src/dto/styles/style_type.dart +++ /dev/null @@ -1,51 +0,0 @@ -import 'package:json_annotation/json_annotation.dart'; - -/// The type of style as string enum. -enum StyleType { - /// A fill style. - @JsonValue('FILL') - fill, - - /// A text style. - @JsonValue('TEXT') - text, - - /// An effect style. - @JsonValue('EFFECT') - effect, - - /// A grid style. - @JsonValue('GRID') - grid, -} - -/// The type of style as string enum for keys. -enum StyleTypeKey { - /// A fill style. - @JsonValue('fill') - fill, - - /// Multiple fill styles. - @JsonValue('fills') - fills, - - /// A stroke style. - @JsonValue('stroke') - stroke, - - /// Multiple stroke styles. - @JsonValue('strokes') - strokes, - - /// A text style. - @JsonValue('text') - text, - - /// An effect style. - @JsonValue('effect') - effect, - - /// A grid style. - @JsonValue('grid') - grid -} diff --git a/packages/figma_variables_api/lib/src/dto/styles/styles_response.dart b/packages/figma_variables_api/lib/src/dto/styles/styles_response.dart deleted file mode 100644 index ad9d7dfb..00000000 --- a/packages/figma_variables_api/lib/src/dto/styles/styles_response.dart +++ /dev/null @@ -1,46 +0,0 @@ -import 'package:copy_with_extension/copy_with_extension.dart'; -import 'package:equatable/equatable.dart'; -import 'package:figma/figma.dart'; -import 'package:json_annotation/json_annotation.dart'; - -part 'styles_response.g.dart'; - -/// A response object containing a list of styles. -@JsonSerializable() -@CopyWith() -class StylesResponse extends Equatable { - StylesResponse({this.status, this.error, this.meta}); - - factory StylesResponse.fromJson(Map json) => - _$StylesResponseFromJson(json); - - /// Status code. - final int? status; - - /// If the operation ended in error. - final bool? error; - - /// [Style] list + metadata. - final StylesResponseMeta? meta; - - @override - List get props => [status, error, meta]; - - Map toJson() => _$StylesResponseToJson(this); -} - -@JsonSerializable() -@CopyWith() -class StylesResponseMeta extends Equatable { - const StylesResponseMeta({required this.styles}); - - factory StylesResponseMeta.fromJson(Map json) => - _$StylesResponseMetaFromJson(json); - - final List