{"id":23536614,"url":"https://github.com/mockingbot/electron-color-picker","last_synced_at":"2025-04-23T11:56:27.494Z","repository":{"id":57221595,"uuid":"116123620","full_name":"mockingbot/electron-color-picker","owner":"mockingbot","description":"Pick color from Desktop, suitable for use with Electron.","archived":false,"fork":false,"pushed_at":"2020-07-17T17:36:05.000Z","size":885,"stargazers_count":24,"open_issues_count":9,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-23T11:56:21.961Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/mockingbot.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}},"created_at":"2018-01-03T10:22:31.000Z","updated_at":"2024-11-20T09:51:10.000Z","dependencies_parsed_at":"2022-08-29T02:12:51.292Z","dependency_job_id":null,"html_url":"https://github.com/mockingbot/electron-color-picker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mockingbot%2Felectron-color-picker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mockingbot%2Felectron-color-picker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mockingbot%2Felectron-color-picker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mockingbot%2Felectron-color-picker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mockingbot","download_url":"https://codeload.github.com/mockingbot/electron-color-picker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250430590,"owners_count":21429323,"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":[],"created_at":"2024-12-26T02:29:43.787Z","updated_at":"2025-04-23T11:56:27.436Z","avatar_url":"https://github.com/mockingbot.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# electron-color-picker\n\n[![i:npm]][l:npm]\n[![i:size]][l:size]\n[![i:npm-dev]][l:npm]\n\nPick color from Desktop, in Electron.\n\n[i:npm]: https://img.shields.io/npm/v/electron-color-picker?colorB=blue\n[i:npm-dev]: https://img.shields.io/npm/v/electron-color-picker/dev\n[l:npm]: https://npm.im/electron-color-picker\n[i:size]: https://packagephobia.now.sh/badge?p=electron-color-picker\n[l:size]: https://packagephobia.now.sh/result?p=electron-color-picker\n\n[//]: # (NON_PACKAGE_CONTENT)\n\n\n* [Example](#example)\n* [Usage](#usage)\n* [Advanced Usage](#advanced-usage)\n\n\n\u003e #### Note\n\u003e \n\u003e On Windows \u0026 MacOS will use our native [color-picker](https://github.com/mockingbot/mb_colorpicker_desktop_native).\n\u003e \n\u003e On Linux will use [SCROT][l:scrot] to get screenshot and pick color from it.\n\u003e The idea is directly borrowed from package [desktop-screenshot][l:desktop-screenshot].\n\u003e \n\u003e Error will be thrown:\n\u003e - when try to start multiple color-picker.\n\u003e - on unsupported platform.\n\n[l:scrot]: https://en.wikipedia.org/wiki/Scrot\n[l:desktop-screenshot]: https://npm.im/desktop-screenshot\n\n\n## Example\n\n📁 [example/](example/)\n\nBasic implementation of using DOM Button to trigger color picking,\nand pass result back through `ipc`.\n\nTry example with:\n```bash\ncd example/\n\nnpm install\n\nnpm run-dev # for debug with electron\n# or\nnpm run-prod # for electron-packager output\n```\n\nFor a more detailed explanation of the example setup,\ncheck: [example/concept.md](example/concept.md)\n\n\n## Usage\n\nFirst add this package to your project: \n```bash\nnpm install electron-color-picker\n```\n\nSample function `saveColorToClipboard()`:\n```js\nconst { clipboard } = require('electron')\nconst {\n  getColorHexRGB,\n\n  // for more control and customized checks\n  DARWIN_IS_PLATFORM_PRE_CATALINA, // darwin only, undefined on other platform\n  darwinGetColorHexRGB, // darwin only, throw error on other platform\n  darwinGetScreenPermissionGranted, // darwin only, throw error on other platform\n  darwinRequestScreenPermissionPopup // darwin only, throw error on other platform\n} = require('electron-color-picker')\n\nconst saveColorToClipboard = async () =\u003e {\n  // color may be '#0099ff' or '' (pick cancelled with ESC)\n  const color = await getColorHexRGB().catch((error) =\u003e {\n    console.warn('[ERROR] getColor', error)\n    return ''\n  })\n  console.log(`getColor: ${color}`)\n  color \u0026\u0026 clipboard.writeText(color)\n}\n\nif (process.platform === 'darwin' \u0026\u0026 !DARWIN_IS_PLATFORM_PRE_CATALINA) {\n  const darwinScreenPermissionSample = async () =\u003e {\n    const isGranted = await darwinGetScreenPermissionGranted() // initial check\n    console.log('darwinGetScreenPermissionGranted:', isGranted)\n    if (!isGranted) { // request user for permission, no result, and will not wait for user click\n      await darwinRequestScreenPermissionPopup()\n      console.warn('no permission granted yet, try again')\n      return ''\n    }\n    const color = await darwinGetColorHexRGB().catch((error) =\u003e {\n      console.warn('[ERROR] getColor', error)\n      return ''\n    })\n    console.log(`getColor: ${color}`)\n    color \u0026\u0026 clipboard.writeText(color)\n  }\n}\n```\n\n\n## Advanced Usage\n\nTo pull deeper code for specific platform,\nconsider direct require/import the platform `index` file.\nDo read the source code and check the functionality though.\n\n```js\nconst { // code with simple mutex wrapper\n  getColorHexRGB,\n  DARWIN_IS_PLATFORM_PRE_CATALINA,\n  darwinGetColorHexRGB,\n  darwinGetScreenPermissionGranted,\n  darwinRequestScreenPermissionPopup\n} = require('electron-color-picker')\n\nconst { // platform specific function, with less check\n  runColorPicker,\n  DARWIN_IS_PLATFORM_PRE_CATALINA,\n  darwinRunColorPicker,\n  darwinGetScreenPermissionGranted,\n  darwinRequestScreenPermissionPopup\n} = require('electron-color-picker/library/darwin/index.js')\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmockingbot%2Felectron-color-picker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmockingbot%2Felectron-color-picker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmockingbot%2Felectron-color-picker/lists"}