diff options
Diffstat (limited to 'Map/Presentation')
22 files changed, 145 insertions, 120 deletions
diff --git a/Map/Presentation/Base Components/EvolutionPicker/EvolutionPicker.swift b/Map/Presentation/Base Components/EvolutionPicker/EvolutionPicker.swift index da67054..83d5009 100644 --- a/Map/Presentation/Base Components/EvolutionPicker/EvolutionPicker.swift +++ b/Map/Presentation/Base Components/EvolutionPicker/EvolutionPicker.swift @@ -18,7 +18,6 @@ struct EvolutionPicker: View { @State var isShowingMenu = false @State var isHovered = false - @FocusState var isFocused: Bool @Binding var selectedEvolution: StageType diff --git a/Map/Presentation/Base Components/EvolutionPicker/EvolutionPickerMenuHeader.swift b/Map/Presentation/Base Components/EvolutionPicker/EvolutionPickerMenuHeader.swift index b3eeb97..095c74c 100644 --- a/Map/Presentation/Base Components/EvolutionPicker/EvolutionPickerMenuHeader.swift +++ b/Map/Presentation/Base Components/EvolutionPicker/EvolutionPickerMenuHeader.swift @@ -8,6 +8,7 @@ struct EvolutionPickerMenuHeader: View { HStack(alignment: .center, spacing: Dimensions.Spacing.regular) { Text(key) .font(.Theme.Caption.emphasized) + .lineSpacing(Dimensions.LineHeight.caption - Dimensions.FontSize.caption) .padding(.vertical, Dimensions.Spacing.cozy) .textCase(.uppercase) .padding(.leading, Dimensions.Spacing.regular) diff --git a/Map/Presentation/Base Components/EvolutionPicker/GlassEvolutionPicker.swift b/Map/Presentation/Base Components/EvolutionPicker/GlassEvolutionPicker.swift index 3b6f199..72a572a 100644 --- a/Map/Presentation/Base Components/EvolutionPicker/GlassEvolutionPicker.swift +++ b/Map/Presentation/Base Components/EvolutionPicker/GlassEvolutionPicker.swift @@ -18,7 +18,6 @@ import SwiftUI struct GlassEvolutionPicker: View { @State var isShowingMenu = false - @FocusState var isFocused: Bool @Binding var selectedEvolution: StageType diff --git a/Map/Presentation/Base Components/MapRender/MapAxes.swift b/Map/Presentation/Base Components/MapRender/MapAxes.swift index 9d0f43f..7c2b74b 100644 --- a/Map/Presentation/Base Components/MapRender/MapAxes.swift +++ b/Map/Presentation/Base Components/MapRender/MapAxes.swift @@ -19,7 +19,7 @@ struct MapAxes: View { let mapSize: CGSize let lineWidth: CGFloat let evolution: Stage - let stages: [CGFloat] + let stages: [Double] let stageHeight = CGFloat(100.0) let padding = CGFloat(5.0) diff --git a/Map/Presentation/Base Components/MapRender/MapBackground.swift b/Map/Presentation/Base Components/MapRender/MapBackground.swift index b33e791..710d549 100644 --- a/Map/Presentation/Base Components/MapRender/MapBackground.swift +++ b/Map/Presentation/Base Components/MapRender/MapBackground.swift @@ -14,14 +14,13 @@ // along with this program. If not, see https://map.tranquil.systems. import Patterns import SwiftUI +import WmapParser struct MapBackground: View { let mapSize: CGSize - let lineWidth: CGFloat - let stages: [CGFloat] - let opacity = 0.1 - + let stages: [Double] + var body: some View { ZStack(alignment: .topLeading) { PatternView( @@ -57,6 +56,6 @@ struct MapBackground: View { #Preview { MapBackground( - mapSize: CGSize(width: 200.0, height: 200.0), lineWidth: CGFloat(0.5), - stages: [25.0, 50.0, 75.0]) + mapSize: CGSize(width: 200.0, height: 200.0), + stages: []) } diff --git a/Map/Presentation/Base Components/MapRender/MapEdges.swift b/Map/Presentation/Base Components/MapRender/MapEdges.swift index 3c6ef82..5819069 100644 --- a/Map/Presentation/Base Components/MapRender/MapEdges.swift +++ b/Map/Presentation/Base Components/MapRender/MapEdges.swift @@ -13,6 +13,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see https://map.tranquil.systems. import SwiftUI +import WmapParser struct MapEdges: View { diff --git a/Map/Presentation/Base Components/MapRender/MapGroup.swift b/Map/Presentation/Base Components/MapRender/MapGroup.swift index a5877a8..ca5e954 100644 --- a/Map/Presentation/Base Components/MapRender/MapGroup.swift +++ b/Map/Presentation/Base Components/MapRender/MapGroup.swift @@ -22,7 +22,6 @@ struct MapGroup: View { let group: [Vertex] let color: Color - let cornerSize = CGSize(width: 2.0, height: 2.0) var strokeSize: CGFloat { 1.75 * vertexSize.width } var hull: [CGPoint] { @@ -92,6 +91,6 @@ struct MapGroup: View { Vertex(id: 0, label: "A Circle", position: CGPoint(x: 50.0, y: 50.0)), Vertex(id: 1, label: "A Square", position: CGPoint(x: 10.0, y: 20.0), shape: .square), Vertex(id: 2, label: "A triangle", position: CGPoint(x: 25, y: 32.0), shape: .triangle), - Vertex(id: 3, label: "An X", position: CGPoint(x: 70.0, y: 70.0), shape: .x), + Vertex(id: 3, label: "An X", position: CGPoint(x: 70.0, y: 70.0), shape: .xMark), ], color: .red) } diff --git a/Map/Presentation/Base Components/MapRender/MapGroups.swift b/Map/Presentation/Base Components/MapRender/MapGroups.swift index 1983dcd..149ea65 100644 --- a/Map/Presentation/Base Components/MapRender/MapGroups.swift +++ b/Map/Presentation/Base Components/MapRender/MapGroups.swift @@ -40,7 +40,7 @@ struct MapGroups: View { Vertex(id: 0, label: "A Circle", position: CGPoint(x: 50.0, y: 50.0)), Vertex(id: 1, label: "A Square", position: CGPoint(x: 10.0, y: 20.0), shape: .square), Vertex(id: 2, label: "A triangle", position: CGPoint(x: 25, y: 32.0), shape: .triangle), - Vertex(id: 3, label: "An X", position: CGPoint(x: 70.0, y: 70.0), shape: .x), + Vertex(id: 3, label: "An X", position: CGPoint(x: 70.0, y: 70.0), shape: .xMark), ] ]) } diff --git a/Map/Presentation/Base Components/MapRender/MapMask.swift b/Map/Presentation/Base Components/MapRender/MapMask.swift index b477c0a..c4ba055 100644 --- a/Map/Presentation/Base Components/MapRender/MapMask.swift +++ b/Map/Presentation/Base Components/MapRender/MapMask.swift @@ -65,7 +65,7 @@ struct MapMask: View { Vertex(id: 0, label: "A Circle", position: CGPoint(x: 50.0, y: 50.0)), Vertex(id: 1, label: "A Square", position: CGPoint(x: 10.0, y: 20.0), shape: .square), Vertex(id: 2, label: "A triangle", position: CGPoint(x: 25, y: 32.0), shape: .triangle), - Vertex(id: 3, label: "An X", position: CGPoint(x: 70.0, y: 70.0), shape: .x), + Vertex(id: 3, label: "An X", position: CGPoint(x: 70.0, y: 70.0), shape: .xMark), ], labelPositions: [:]) } diff --git a/Map/Presentation/Base Components/MapRender/MapStages.swift b/Map/Presentation/Base Components/MapRender/MapStages.swift index 7d7e51e..bcd95a2 100644 --- a/Map/Presentation/Base Components/MapRender/MapStages.swift +++ b/Map/Presentation/Base Components/MapRender/MapStages.swift @@ -19,8 +19,7 @@ struct MapStages: View { let mapSize: CGSize let lineWidth: CGFloat - let stages: [CGFloat] - let opacity = 0.1 + let stages: [Double] var body: some View { ZStack(alignment: .topLeading) { diff --git a/Map/Presentation/Base Components/MapRender/MapVertices.swift b/Map/Presentation/Base Components/MapRender/MapVertices.swift index 621c2f9..a3558fa 100644 --- a/Map/Presentation/Base Components/MapRender/MapVertices.swift +++ b/Map/Presentation/Base Components/MapRender/MapVertices.swift @@ -132,7 +132,7 @@ struct MapVertices: View { to: CGPoint(x: w(vertex.position.x), y: h(vertex.position.y) + vertexSize.height)) path.closeSubpath() } - case .x: + case .xMark: return Path { path in path.move(to: CGPoint(x: w(vertex.position.x), y: h(vertex.position.y))) path.addLine( @@ -156,7 +156,7 @@ struct MapVertices: View { Vertex(id: 0, label: "A Circle", position: CGPoint(x: 50.0, y: 50.0)), Vertex(id: 1, label: "A Square", position: CGPoint(x: 10.0, y: 20.0), shape: .square), Vertex(id: 2, label: "A triangle", position: CGPoint(x: 25, y: 32.0), shape: .triangle), - Vertex(id: 3, label: "An X", position: CGPoint(x: 70.0, y: 70.0), shape: .x), + Vertex(id: 3, label: "An X", position: CGPoint(x: 70.0, y: 70.0), shape: .xMark), ], labelPositions: [:]) } diff --git a/Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift b/Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift index a1b357d..99fa684 100644 --- a/Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift +++ b/Map/Presentation/Base Components/MapTextEditor/MapTextEditor.swift @@ -14,17 +14,17 @@ // along with this program. If not, see https://map.tranquil.systems. import Cocoa import SwiftUI +import WmapParser +import SwiftTreeSitter +import SwiftTreeSitterLayer +import TreeSitterWmap + class MapTextEditorController: NSViewController { @Binding var text: String - var parsedMap: Wmap.ParsedMap { - didSet { - syntaxHighlighter.updateSyntaxElements(from: parsedMap) - // Don't re-highlight entire document here - let the text change handler do it - } - } + var parsedMap: WmapParser.Map? var highlightRanges: [Range<String.Index>] { didSet { @@ -41,17 +41,18 @@ class MapTextEditorController: NSViewController { let onChange: () -> Void - private let syntaxHighlighter = Wmap.SyntaxHighlighter() private let changeDebouncer: Debouncer = Debouncer(seconds: 1) private var trackingArea: NSTrackingArea? private var hoverView: NSView? + private var rootLayer: LanguageLayer? + var hoverTimer: Timer? var isHoveringValidationText = false var isHoveringHoverView = false init( text: Binding<String>, - parsedMap: Wmap.ParsedMap = Wmap.ParsedMap(entities: [], vertexLabels: Set()), + parsedMap: WmapParser.Map? = nil, highlightRanges: [Range<String.Index>], selectedRange: Int, onChange: @escaping () -> Void @@ -62,9 +63,16 @@ class MapTextEditorController: NSViewController { self.highlightRanges = highlightRanges self.selectedRange = selectedRange super.init(nibName: nil, bundle: nil) + + if let wmapConfiguration = try? LanguageConfiguration(tree_sitter_wmap(), name: "wmap") { + let languageConfiguration = LanguageLayer.Configuration(languageProvider: { name in + switch name { + case "wmap": return wmapConfiguration + default: return nil + } + }) + self.rootLayer = try? LanguageLayer(languageConfig: wmapConfiguration, configuration: languageConfiguration) - Task { - syntaxHighlighter.updateSyntaxElements(from: parsedMap) } } @@ -75,7 +83,7 @@ class MapTextEditorController: NSViewController { override func loadView() { let scrollView = NSTextView.scrollableTextView() let textView = scrollView.documentView as! NSTextView - + scrollView.translatesAutoresizingMaskIntoConstraints = false textView.backgroundColor = .Theme.UI.background @@ -87,7 +95,7 @@ class MapTextEditorController: NSViewController { textView.font = NSFont.Theme.Editor.regular textView.textColor = NSColor.Theme.Syntax.text textView.textContainerInset = NSSize( - width: Dimensions.Spacing.coziest, height: Dimensions.Spacing.coziest) + width: Dimensions.Spacing.regular, height: Dimensions.Spacing.regular) // Configure text wrapping based on user preference let softWrapLines = UserDefaults.standard.bool(forKey: "softWrapLines") @@ -114,6 +122,7 @@ class MapTextEditorController: NSViewController { textView.isVerticallyResizable = true setupTrackingArea(for: textView) + rootLayer?.replaceContent(with: text) self.view = scrollView } @@ -241,10 +250,10 @@ class MapTextEditorController: NSViewController { var effectiveRange = NSRange() let attributes = textStorage.attributes(at: characterIndex, effectiveRange: &effectiveRange) - if let missinVertex = attributes[.init(rawValue: "MissingComponent")] as? String { + if let missingVertex = attributes[.init(rawValue: "MissingComponent")] as? String { isHoveringValidationText = true hoverTimer?.invalidate() - showHoverView(for: effectiveRange, with: missinVertex, characterIndex: characterIndex) + showHoverView(for: effectiveRange, with: missingVertex, characterIndex: characterIndex) } else { isHoveringValidationText = false scheduleHideHoverView() @@ -346,17 +355,39 @@ class MapTextEditorController: NSViewController { } } - private func getSyntaxElementAt(characterIndex: Int) -> Wmap.SyntaxElement? { - let textStorage = currentTextView?.textStorage - guard let textStorage = textStorage else { return nil } + private func applyTreeSitterHighlighting(textStorage: NSTextStorage, range: NSRange) { + guard let highlights = try? rootLayer?.highlights(in: range, provider: text.predicateTextProvider) + else { return } + + for highlight in highlights { + let color = NSColor.Theme.Syntax.colorForSyntax(highlight.name) + var attributes: [NSAttributedString.Key: Any] = [ + .foregroundColor: color + ] - for element in syntaxHighlighter.cachedSyntaxElements { - let nsRange = NSRange(element.range.stringRange, in: textStorage.string) - if nsRange.contains(characterIndex) { - return element + // Check for missing components + if UserDefaults.standard.bool(forKey: "useSmartEditor"), + let parsedMap, + highlight.name == "variable.component_label" { + + // Extract the component label text from the range + let componentText = (textStorage.string as NSString).substring(with: highlight.range).trimmingCharacters(in: .whitespacesAndNewlines) + + // Check if this component exists in the parsed map + let componentExists = parsedMap.components.contains(where: { + $0.label.lowercased() == componentText.lowercased() + }) + + if !componentExists && UserDefaults.standard.bool(forKey: "highlightMissingComponents") { + attributes[.underlineStyle] = + NSUnderlineStyle.thick.rawValue | NSUnderlineStyle.patternDot.rawValue + attributes[.underlineColor] = NSColor.Theme.Syntax.error + attributes[.init("MissingComponent")] = componentText + } } + + textStorage.addAttributes(attributes, range: highlight.range) } - return nil } } @@ -400,6 +431,13 @@ extension MapTextEditorController: NSTextStorageDelegate { } let editedRange = textStorage.editedRange + let content = textStorage.string + + // Update tree-sitter layer with new content + Task { @MainActor in + rootLayer?.replaceContent(with: content) + } + if editedRange.location != NSNotFound { DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { [weak self] in guard let self = self, @@ -432,21 +470,22 @@ extension MapTextEditorController: NSTextStorageDelegate { // Set default text color for the range textStorage.addAttribute(.foregroundColor, value: NSColor.Theme.Syntax.text, range: range) - syntaxHighlighter.applySyntaxHighlighting(textStorage: textStorage, range: range) + // Apply tree-sitter syntax highlighting + applyTreeSitterHighlighting(textStorage: textStorage, range: range) } } struct MapTextEditor: NSViewControllerRepresentable { @Binding var text: String - var parsedMap: Wmap.ParsedMap + var parsedMap: WmapParser.Map? var highlightRanges: [Range<String.Index>] var selectedRange: Int var onChange: () -> Void = {} init( text: Binding<String>, - parsedMap: Wmap.ParsedMap = Wmap.ParsedMap(entities: [], vertexLabels: Set()), + parsedMap: WmapParser.Map? = nil, highlightRanges: [Range<String.Index>] = [], selectedRange: Int = 0, onChange: @escaping () -> Void = {} ) { diff --git a/Map/Presentation/Base Components/SearchBar.swift b/Map/Presentation/Base Components/SearchBar.swift index cf19ddd..706b66f 100644 --- a/Map/Presentation/Base Components/SearchBar.swift +++ b/Map/Presentation/Base Components/SearchBar.swift @@ -20,7 +20,6 @@ struct SearchBar: View { @FocusState var isSearchFocused: Bool var onNext: () -> Void = {} var onPrevious: () -> Void = {} - var onSubmit: () -> Void = {} var onDismiss: () -> Void = {} var body: some View { diff --git a/Map/Presentation/Commands/MapCommands.swift b/Map/Presentation/Commands/MapCommands.swift index fe21f57..b992a42 100644 --- a/Map/Presentation/Commands/MapCommands.swift +++ b/Map/Presentation/Commands/MapCommands.swift @@ -34,10 +34,6 @@ struct MapCommands: Commands { return [] } - private var defaultTemplate: Template? { - templates.first { $0.isDefault } - } - var body: some Commands { // File diff --git a/Map/Presentation/Complex Components/MapRender/MapRenderView.swift b/Map/Presentation/Complex Components/MapRender/MapRenderView.swift index ce95813..ba525ad 100644 --- a/Map/Presentation/Complex Components/MapRender/MapRenderView.swift +++ b/Map/Presentation/Complex Components/MapRender/MapRenderView.swift @@ -16,13 +16,13 @@ import Combine import CoreData import CoreGraphics import SwiftUI +import WmapParser struct MapRenderView: View { - var entities: [Wmap.Entity] + var parsedMap: WmapParser.Map @Binding var evolution: StageType - @State private var lastEntityHash: Int = 0 @AppStorage("showMapBackground") var showMapBackground: Bool = UserPreferences.Defaults .showMapBackground @AppStorage("useCustomFont") var useCustomFont: Bool = UserPreferences.Defaults.useCustomFont @@ -34,7 +34,7 @@ struct MapRenderView: View { Stage.stages(evolution) } - @State private var parsedMap: RenderableMap = RenderableMap.empty + @State private var renderableMap: RenderableMap = .empty @State private var smartLabelPositions: [Int: CGPoint] = [:] @State private var parseTask: Task<Void, Never>? @@ -49,11 +49,10 @@ struct MapRenderView: View { private func convertEntitiesInBackground() { parseTask?.cancel() - let currentEntities = entities parseTask = Task { let parsed = await Task.detached(priority: .userInitiated) { - RenderableMap.from(currentEntities) + RenderableMap.from(parsedMap) }.value let positions = await Task.detached(priority: .userInitiated) { @@ -87,7 +86,7 @@ struct MapRenderView: View { if !Task.isCancelled { await MainActor.run { - parsedMap = parsed + renderableMap = parsed smartLabelPositions = positions } } @@ -107,37 +106,37 @@ struct MapRenderView: View { // The order Matters. Think of this as layers. if showMapBackground { - MapBackground(mapSize: mapSize, lineWidth: lineWidth, stages: parsedMap.stages) + MapBackground(mapSize: mapSize, stages: renderableMap.stages) } MapAxes( - mapSize: mapSize, lineWidth: lineWidth, evolution: stage, stages: parsedMap.stages) + mapSize: mapSize, lineWidth: lineWidth, evolution: stage, stages: renderableMap.stages) Group { - MapStages(mapSize: mapSize, lineWidth: lineWidth, stages: parsedMap.stages) + MapStages(mapSize: mapSize, lineWidth: lineWidth, stages: renderableMap.stages) MapEdges( - mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, edges: parsedMap.edges) + mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, edges: renderableMap.edges) MapOpportunities( mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, - opportunities: parsedMap.opportunities) - MapIntertias(mapSize: mapSize, vertexSize: vertexSize, inertias: parsedMap.inertias) + opportunities: renderableMap.opportunities) + MapIntertias(mapSize: mapSize, vertexSize: vertexSize, inertias: renderableMap.inertias) }.mask { MapMask( - mapSize: mapSize, vertexSize: vertexSize, vertices: parsedMap.vertices, + mapSize: mapSize, vertexSize: vertexSize, vertices: renderableMap.vertices, labelPositions: smartLabelPositions) } MapVertices( - mapSize: mapSize, vertexSize: vertexSize, vertices: parsedMap.vertices, + mapSize: mapSize, vertexSize: vertexSize, vertices: renderableMap.vertices, labelPositions: smartLabelPositions, onDragVertex: onDragVertex) if #available(macOS 26.0, *) { - MapGroups(mapSize: mapSize, vertexSize: vertexSize, groups: parsedMap.groups) + MapGroups(mapSize: mapSize, vertexSize: vertexSize, groups: renderableMap.groups) .drawingGroup() .opacity(0.1) } else { - MapGroups(mapSize: mapSize, vertexSize: vertexSize, groups: parsedMap.groups).drawingGroup( + MapGroups(mapSize: mapSize, vertexSize: vertexSize, groups: renderableMap.groups).drawingGroup( opaque: true ).opacity(0.1) } MapNotes( - mapSize: mapSize, lineWidth: lineWidth, notes: parsedMap.notes) + mapSize: mapSize, lineWidth: lineWidth, notes: renderableMap.notes) } .id("\(useCustomFont)-\(customFontName)") .offset(x: padding, y: padding).frame( @@ -147,7 +146,7 @@ struct MapRenderView: View { .onAppear { convertEntitiesInBackground() } - .onChange(of: entities) { _, _ in + .onChange(of: parsedMap) { _, _ in convertEntitiesInBackground() } .onChange(of: useSmartLabelPositioning) { @@ -157,19 +156,11 @@ struct MapRenderView: View { parseTask?.cancel() } } - - func h(_ dimension: CGFloat) -> CGFloat { - max(0.0, min(mapSize.height, dimension * mapSize.height / 100.0)) - } - - func w(_ dimension: CGFloat) -> CGFloat { - max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0)) - } } #Preview { MapRenderView( - entities: [], + parsedMap: WmapParser.parse(""), evolution: Binding.constant(StageType.general) ) } diff --git a/Map/Presentation/MapEditor.swift b/Map/Presentation/MapEditor.swift index f5589e5..892c803 100644 --- a/Map/Presentation/MapEditor.swift +++ b/Map/Presentation/MapEditor.swift @@ -13,13 +13,13 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see https://map.tranquil.systems. import SwiftUI +import WmapParser struct MapEditor: View { @Binding var document: MapDocument - var url: URL? @State var selectedEvolution: StageType = .behavior @State var isSearching: Bool = false - var parsedMap: Wmap.ParsedMap { + var parsedMap: WmapParser.Map { document.parsed } @@ -89,9 +89,6 @@ struct MapEditor: View { } } }, - onSubmit: { - - }, onDismiss: { isSearching = false } @@ -129,7 +126,7 @@ struct MapEditor: View { GeometryReader { geometry in ScrollView([.horizontal, .vertical], showsIndicators: false) { MapRenderView( - entities: parsedMap.entities, evolution: $selectedEvolution, + parsedMap: parsedMap, evolution: $selectedEvolution, onDragVertex: onDragVertex ) .scaleEffect(zoom, anchor: .center).frame( @@ -285,5 +282,5 @@ struct MapEditor: View { } #Preview { - MapEditor(document: .constant(MapDocument(text: nil)), url: URL(filePath: "test.wmap")!) + MapEditor(document: .constant(MapDocument(text: nil))) } diff --git a/Map/Presentation/PreferencesWindow.swift b/Map/Presentation/PreferencesWindow.swift index fa5bd4c..3a50119 100644 --- a/Map/Presentation/PreferencesWindow.swift +++ b/Map/Presentation/PreferencesWindow.swift @@ -93,7 +93,8 @@ struct PreferencesWindow: View { selectedTab == tab ? Color.Theme.UI.accent : Color.background.opacity(0.01) ) .foregroundColor(selectedTab == tab ? Color.white : Color.Theme.UI.foreground) - .cornerRadius(Dimensions.Preferences.Toolbar.radius) + .clipShape(clipShape()) + .padding(.horizontal, 2.0) } .buttonStyle(.plain) } @@ -101,8 +102,17 @@ struct PreferencesWindow: View { } } } + + private func clipShape() -> AnyShape { + if #available(macOS 26.0, *) { + AnyShape(RoundedRectangle(cornerRadius: Dimensions.Preferences.Toolbar.glassRadius)) + } else { + AnyShape(RoundedRectangle(cornerRadius: Dimensions.Preferences.Toolbar.radius)) + } + } } + #Preview { PreferencesWindow() } diff --git a/Map/Presentation/Theme/Color+theme.swift b/Map/Presentation/Theme/Color+theme.swift index e0addca..dcc84cb 100644 --- a/Map/Presentation/Theme/Color+theme.swift +++ b/Map/Presentation/Theme/Color+theme.swift @@ -25,10 +25,7 @@ extension Color { static let lightPorcelainGreen = Color("Light Porcelain Green") static let naplesYellow = Color("Naples Yellow") static let hermosaPink = Color("Hermosa Pink") - static let neutralGray = Color("Neutral Gray") static let lightNeutralGray = Color("Light Neutral Gray") - static let darkNeutralGray = Color("Dark Neutral Gray") - static let darkerNeutralGray = Color("Darker Neutral Gray") // MARK: - General diff --git a/Map/Presentation/Theme/Dimensions.swift b/Map/Presentation/Theme/Dimensions.swift index 57bd8b8..b7c1faf 100644 --- a/Map/Presentation/Theme/Dimensions.swift +++ b/Map/Presentation/Theme/Dimensions.swift @@ -20,7 +20,6 @@ struct Dimensions { struct FontSize { static let body: CGFloat = 13 - static let title: CGFloat = 32 static let caption: CGFloat = 11 static let smallControl: CGFloat = 11 @@ -38,19 +37,10 @@ struct Dimensions { struct LineHeight { static let body: CGFloat = 18 - static let title: CGFloat = 38 static let caption: CGFloat = 18 - static let smallControl: CGFloat = 18 - - static var editor: CGFloat { - let fontSize = UserDefaults.standard.double(forKey: "editorFontSize") - let actualSize = fontSize > 0 ? fontSize : 14 - return actualSize >= 16 ? 38 : 18 - } struct Map { static let note: CGFloat = 18 - static let axisLabel: CGFloat = 18 static let vertexLabel: CGFloat = 18 } } @@ -109,6 +99,7 @@ struct Dimensions { struct Toolbar { static let radius: CGFloat = 8.0 + static let glassRadius: CGFloat = 24.0 static let size: CGFloat = 16.0 static let width: CGFloat = 60.0 static let height: CGFloat = 40.0 diff --git a/Map/Presentation/Theme/Font+theme.swift b/Map/Presentation/Theme/Font+theme.swift index 4660e48..bb1d8f6 100644 --- a/Map/Presentation/Theme/Font+theme.swift +++ b/Map/Presentation/Theme/Font+theme.swift @@ -31,18 +31,12 @@ extension Font { static let emphasized = Font.ronzino(size: Dimensions.FontSize.body).weight(.medium) } - struct Title { - static let emphasized = Font.libertinus(size: Dimensions.FontSize.title).weight(.medium) - } - struct Caption { - static let regular = Font.ronzino(size: Dimensions.FontSize.caption).weight(.regular) static let emphasized = Font.ronzino(size: Dimensions.FontSize.caption).weight(.medium) } struct SmallControl { static let regular = Font.ronzino(size: Dimensions.FontSize.smallControl).weight(.regular) - static let emphasized = Font.ronzino(size: Dimensions.FontSize.smallControl).weight(.medium) } struct Map { diff --git a/Map/Presentation/Theme/NSColor+theme.swift b/Map/Presentation/Theme/NSColor+theme.swift index 7e53717..21db412 100644 --- a/Map/Presentation/Theme/NSColor+theme.swift +++ b/Map/Presentation/Theme/NSColor+theme.swift @@ -29,11 +29,43 @@ extension NSColor { .withAlphaComponent( 0.3) static let error = (NSColor(named: "Jasper Red") ?? .textColor) + + static func colorForSyntax(_ captureName: String) -> NSColor { + switch captureName { + case ("variable.component_label"): + return .Theme.Syntax.vertex + case ("number.real_number"): + return .Theme.Syntax.number + case ("punctuation.position"): + return .Theme.Syntax.punctuation + case ("punctuation.shape"): + return .Theme.Syntax.punctuation + case ("punctuation.dependency_type"): + return .Theme.Syntax.punctuation + case ("parameter.optional"): + return .Theme.Syntax.option + case ("operator.sign"): + return .Theme.Syntax.option + case ("keyword.evolution"): + return .Theme.Syntax.symbol + case ("keyword.inertia"): + return .Theme.Syntax.symbol + case ("keyword.stage"): + return .Theme.Syntax.symbol + case ("keyword.stage_number"): + return .Theme.Syntax.symbol + case ("keyword.note"): + return .Theme.Syntax.symbol + case ("keyword.group"): + return .Theme.Syntax.symbol + default: + return .Theme.Syntax.text + } + } } struct UI { static let background = NSColor(named: "Background") ?? .windowBackgroundColor - static let border = NSColor(named: "Border") ?? .separatorColor } } } diff --git a/Map/Presentation/Theme/NSFont+theme.swift b/Map/Presentation/Theme/NSFont+theme.swift index cd119f2..712cc1d 100644 --- a/Map/Presentation/Theme/NSFont+theme.swift +++ b/Map/Presentation/Theme/NSFont+theme.swift @@ -16,30 +16,12 @@ import AppKit extension NSFont { - static func libertinus(size: CGFloat) -> NSFont { - return NSFont(name: "Libertinus Serif", size: size) ?? .systemFont(ofSize: size) - } - static func ronzino(size: CGFloat) -> NSFont { return NSFont(name: "Ronzino", size: size) ?? .systemFont(ofSize: size) } public struct Theme { - struct Body { - @MainActor static let regular = NSFont.ronzino(size: Dimensions.FontSize.body) - @MainActor static let emphasized = NSFont.ronzino(size: Dimensions.FontSize.body) - } - - struct Title { - @MainActor static let emphasized = NSFont.libertinus(size: Dimensions.FontSize.title) - } - - struct Caption { - @MainActor static let regular = NSFont.ronzino(size: Dimensions.FontSize.caption) - @MainActor static let emphasized = NSFont.ronzino(size: Dimensions.FontSize.caption) - } - struct SmallControl { @MainActor static let regular = NSFont.ronzino(size: Dimensions.FontSize.smallControl) @MainActor static let emphasized = NSFont.ronzino(size: Dimensions.FontSize.smallControl) |