{"id":18031763,"url":"https://github.com/dagronf/dsfcolorsampler","last_synced_at":"2025-07-15T18:37:00.930Z","repository":{"id":63907285,"uuid":"177482182","full_name":"dagronf/DSFColorSampler","owner":"dagronf","description":"A Swift 5 class that mimics the magnifying glass in color panel of macOSX","archived":false,"fork":false,"pushed_at":"2024-01-11T05:13:39.000Z","size":74,"stargazers_count":26,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-26T22:42:08.147Z","etag":null,"topics":["color","dropper","loupe","macos","macosx","nscolorsampler","pixel-color","screen-picker","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dagronf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-24T23:31:48.000Z","updated_at":"2024-03-22T06:07:54.000Z","dependencies_parsed_at":"2024-10-30T10:21:14.127Z","dependency_job_id":null,"html_url":"https://github.com/dagronf/DSFColorSampler","commit_stats":{"total_commits":12,"total_committers":1,"mean_commits":12.0,"dds":0.0,"last_synced_commit":"8aeb914503dbeab912a03aac363ff8e5e858e1aa"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2FDSFColorSampler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2FDSFColorSampler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2FDSFColorSampler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2FDSFColorSampler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dagronf","download_url":"https://codeload.github.com/dagronf/DSFColorSampler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245791341,"owners_count":20672665,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["color","dropper","loupe","macos","macosx","nscolorsampler","pixel-color","screen-picker","swift"],"created_at":"2024-10-30T10:10:42.594Z","updated_at":"2025-03-27T05:30:56.950Z","avatar_url":"https://github.com/dagronf.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DSFColorSampler\n\n![](https://img.shields.io/github/v/tag/dagronf/DSFColorSampler) ![](https://img.shields.io/badge/macOS-10.10+-red) ![](https://img.shields.io/badge/Swift-5.0-orange.svg)\n![](https://img.shields.io/badge/License-MIT-lightgrey) [![](https://img.shields.io/badge/pod-compatible-informational)](https://cocoapods.org) [![](https://img.shields.io/badge/spm-compatible-brightgreen.svg?style=flat)](https://swift.org/package-manager)\n\nA Swift 5, Objective-C compatible class that mimics the magnifying glass in color panel of macOS.\n\nAPI Compatible with NSColorSampler (macOS 10.15 Catalina and later)\n\n## Overview\n\nAdapted from [https://github.com/wentingliu/ScreenPicker](https://github.com/wentingliu/ScreenPicker) for Swift 5 with bug fixes and some minor improvements.\n\nAll credit to the original author (Wenting Liu), adapted licensing from [WTFPL](http://www.wtfpl.net)\n\n![](https://github.com/dagronf/dagronf.github.io/blob/master/art/projects/DSFColorPickerLoupe/colorpicker.jpg?raw=true)\n\n[Demonstration Video](https://github.com/dagronf/dagronf.github.io/raw/master/art/projects/DSFColorPickerLoupe/colorpicker.gif)\n\n## Why?\n\nApple released `NSColorSampler` for macOS 10.15+, which isn't much use to those who still need to support earlier systems.\n\n## Features\n\n* Compatible back to macOS 10.9\n* Simple shared controller with block callbacks\n* Hit Escape to cancel picking\n* Use the mouse scroll wheel to zoom in and zoom out\n\n## Usage\n\n### Swift Package Manager\n\nAdd `https://github.com/dagronf/DSFColorSampler` to your project.\n\n### Direct\n\nAdd `DSFColorSampler.swift` to your project.\n\n## API\n\n### Simple\n\nShow the color loupe, and call the provided completion block when the user selects a color.  \n\n#### Swift\n```swift\nDSFColorSampler.show { (selectedColor) in\n   if let selectedColor = selectedColor {\n      // Do something with selectedColor\n   }\n   else {\n      // User cancelled\n   }\n}\n```\n\n#### Objective-C\n\n```objc\n[DSFColorSampler showWithLocationChange:^(NSImage* snapshot, NSColor* color) {\n   //\n} selectionHandler:^(NSColor* color) {\n   //\n}];\n```\n\n### Dynamic image and mouse colors during selection\n\nShow the color loupe, and provide callback blocks for _both_ mouse movement and selection.  For mouse movement, an image snapshot of the mouse area is also provided.\n\n```swift\nDSFColorSampler.show(\n   locationChange: { (image, currentColor) in\n      // Do something with the image and currentColor at the new location\n   },\n   selectionHandler: { (selectedColor) in\n      // Do something with selectedColor\n   }\n)\n```\n\n### Async support\n\n**macOS 10.15+ only**\n\nThis library supports the new async/await model in Swift 5.5 using the `sample()` method\n\n```swift\nTask { [weak self] in\n   self?.selectedColor = await DSFColorSampler.sample()\n}\n```\n\nThe `sample()` method is marked as `@MainActor` so it's guaranteed to be run on the main thread.\n\nNote that if you're using this call, you might better be served using the NSColorSampler class in macOS 10.15+.\nThis feature was made available as a learning exercise as how to convert callback-based async calls to Task based.\n\n## Backwards compatibility for NSColorSampler (10.15+)\n\nThe `selectColor` function has been added to DSFColorSampler that calls `NSColorSampler().show()` on 10.15 or later, and `DSFColorSampler().show()` on systems prior to 10.15.\n\n### Swift\n\n```swift\nDSFColorSampler.selectColor { (selectedColor: NSColor?) in\n   // Do something with selectedColor\n}\n```\n\n### Objective-C\n\n```objc\n[DSFColorSampler selectColorWithSelectionHandler:^(NSColor* _Nullable selectedColor) {\n\t// Do something with\n} ];\n```\n\n# Releases\n\n### `3.0.0`\n\n* Removed SPM support for \u003c 10.13 (you can still use this library in earlier macOS by copying `DSFColorSampler.swift` into your project)\n\n### `2.1.0`\n\n* Added async task support for macOS 10.15+\n\n### `2.0.0`\n\n* Added `selectColor` static method to provide fallback capability for system before macOS 10.15.\n\n### `1.5.0`\n\n* Fixed color picking on multi-screen setups (including dragging the loupe from one screen to another). Previously could only pick colors from the main screen and additional screens would show a 'blank' color.\n\n### `1.4.0`\n\n* Added objc demo.\n\n### `1.3.0`\n\n* Removed unfinshed demo app.\n\n# License\n\n```\nMIT License\n\nCopyright (c) 2021 Darren Ford\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdagronf%2Fdsfcolorsampler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdagronf%2Fdsfcolorsampler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdagronf%2Fdsfcolorsampler/lists"}