|
| 1 | +--- |
| 2 | +layout: doc |
| 3 | +--- |
| 4 | + |
| 5 | +<script setup lang="ts"> |
| 6 | +import { ref, computed } from 'vue'; |
| 7 | +import VPLink from 'vitepress/dist/client/theme-default/components/VPLink.vue'; |
| 8 | +import { open, openFile, addLibrary, runPlugin } from 'protocol-launcher/sketch'; |
| 9 | +import { SelectInstallationMethod } from '../../.vitepress/components'; |
| 10 | +import { openFileParams, openFileWithLayerParams, addLibraryParams, runPluginParams, runPluginWithQueryParams } from '../../.vitepress/constants/sketch'; |
| 11 | + |
| 12 | +const currentMethod = ref('On-Demand'); |
| 13 | +const importPath = computed(() => currentMethod.value === 'On-Demand' ? 'protocol-launcher/sketch' : 'protocol-launcher'); |
| 14 | +</script> |
| 15 | + |
| 16 | +# Sketch |
| 17 | + |
| 18 | +[Sketch](https://www.sketch.com/) is a vector graphics editor for macOS primarily used for user interface and icon design. **Protocol Launcher** allows you to generate deep links to open files, add libraries, and run plugins in Sketch. |
| 19 | + |
| 20 | +## Usage |
| 21 | + |
| 22 | +There are two ways to use this library: |
| 23 | + |
| 24 | +- On-Demand import from subpaths enables tree-shaking and keeps bundles small. |
| 25 | +- Full Import from the root package is convenient but includes all app modules. |
| 26 | + |
| 27 | +Pick On-Demand for production builds; Full Import is fine for quick scripts or demos. |
| 28 | + |
| 29 | +<SelectInstallationMethod v-model="currentMethod" /> |
| 30 | + |
| 31 | +### Open Sketch |
| 32 | + |
| 33 | +```ts-vue [{{currentMethod}}] |
| 34 | +import { {{ currentMethod === 'On-Demand' ? 'open' : 'sketch' }} } from '{{ importPath }}' |
| 35 | +
|
| 36 | +const url = {{currentMethod === 'On-Demand' ? '' : 'sketch.'}}open() |
| 37 | +``` |
| 38 | + |
| 39 | +<div class="flex justify-center"> |
| 40 | + <VPLink :href="open()" target="_self"> |
| 41 | + Open Sketch |
| 42 | + </VPLink> |
| 43 | +</div> |
| 44 | + |
| 45 | +### Open File |
| 46 | + |
| 47 | +```ts-vue [{{currentMethod}}] |
| 48 | +import { {{ currentMethod === 'On-Demand' ? 'openFile' : 'sketch' }} } from '{{ importPath }}' |
| 49 | +
|
| 50 | +const url = {{currentMethod === 'On-Demand' ? '' : 'sketch.'}}openFile({ |
| 51 | + path: '/Users/name/Documents/design.sketch', |
| 52 | +}) |
| 53 | +``` |
| 54 | + |
| 55 | +<div class="flex justify-center"> |
| 56 | + <VPLink :href="openFile(openFileParams)" target="_self"> |
| 57 | + Open File in Sketch |
| 58 | + </VPLink> |
| 59 | +</div> |
| 60 | + |
| 61 | +### Open File with Layer Focus and Zoom |
| 62 | + |
| 63 | +```ts-vue [{{currentMethod}}] |
| 64 | +import { {{ currentMethod === 'On-Demand' ? 'openFile' : 'sketch' }} } from '{{ importPath }}' |
| 65 | +
|
| 66 | +const url = {{currentMethod === 'On-Demand' ? '' : 'sketch.'}}openFile({ |
| 67 | + path: '/Users/name/Documents/design.sketch', |
| 68 | + centerOnLayer: 'layer-123', |
| 69 | + zoom: 2, |
| 70 | +}) |
| 71 | +``` |
| 72 | + |
| 73 | +<div class="flex justify-center"> |
| 74 | + <VPLink :href="openFile(openFileWithLayerParams)" target="_self"> |
| 75 | + Open File with Layer Focus in Sketch |
| 76 | + </VPLink> |
| 77 | +</div> |
| 78 | + |
| 79 | +### Add Library |
| 80 | + |
| 81 | +```ts-vue [{{currentMethod}}] |
| 82 | +import { {{ currentMethod === 'On-Demand' ? 'addLibrary' : 'sketch' }} } from '{{ importPath }}' |
| 83 | +
|
| 84 | +const url = {{currentMethod === 'On-Demand' ? '' : 'sketch.'}}addLibrary({ |
| 85 | + url: 'https://developer.apple.com/design/downloads/sketch.rss', |
| 86 | +}) |
| 87 | +``` |
| 88 | + |
| 89 | +<div class="flex justify-center"> |
| 90 | + <VPLink :href="addLibrary(addLibraryParams)" target="_self"> |
| 91 | + Add Library to Sketch |
| 92 | + </VPLink> |
| 93 | +</div> |
| 94 | + |
| 95 | +### Run Plugin |
| 96 | + |
| 97 | +```ts-vue [{{currentMethod}}] |
| 98 | +import { {{ currentMethod === 'On-Demand' ? 'runPlugin' : 'sketch' }} } from '{{ importPath }}' |
| 99 | +
|
| 100 | +const url = {{currentMethod === 'On-Demand' ? '' : 'sketch.'}}runPlugin({ |
| 101 | + pluginId: 'com.example.sketch.messenger', |
| 102 | + commandId: 'message.show', |
| 103 | +}) |
| 104 | +``` |
| 105 | + |
| 106 | +<div class="flex justify-center"> |
| 107 | + <VPLink :href="runPlugin(runPluginParams)" target="_self"> |
| 108 | + Run Plugin in Sketch |
| 109 | + </VPLink> |
| 110 | +</div> |
| 111 | + |
| 112 | +### Run Plugin with Query Parameters |
| 113 | + |
| 114 | +```ts-vue [{{currentMethod}}] |
| 115 | +import { {{ currentMethod === 'On-Demand' ? 'runPlugin' : 'sketch' }} } from '{{ importPath }}' |
| 116 | +
|
| 117 | +const url = {{currentMethod === 'On-Demand' ? '' : 'sketch.'}}runPlugin({ |
| 118 | + pluginId: 'com.example.sketch.messenger', |
| 119 | + commandId: 'message.show', |
| 120 | + query: { msg: 'Hello World' }, |
| 121 | +}) |
| 122 | +``` |
| 123 | + |
| 124 | +<div class="flex justify-center"> |
| 125 | + <VPLink :href="runPlugin(runPluginWithQueryParams)" target="_self"> |
| 126 | + Run Plugin with Query in Sketch |
| 127 | + </VPLink> |
| 128 | +</div> |
0 commit comments