@phun-ky/speccer 11.3.0 → 11.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -833
- package/dist/speccer.d.ts +8 -8
- package/dist/speccer.esm.js +1 -1
- package/dist/speccer.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# SPECCER
|
|
2
2
|
|
|
3
|
-

|
|
3
|
+

|
|
4
4
|
|
|
5
5
|
[](http://commitizen.github.io/cz-cli/)
|
|
6
6
|
[](http://makeapullrequest.com)
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
## About
|
|
18
18
|
|
|
19
|
-

|
|
19
|
+

|
|
20
20
|
|
|
21
21
|
**SPECCER** was originally created to simplify documenting components in a
|
|
22
22
|
design system, but it can be used to annotate or highlight any HTML element on a
|
|
@@ -24,52 +24,13 @@ webpage. If you need to draw attention to elements, **SPECCER** is your tool!
|
|
|
24
24
|
|
|
25
25
|
## Table of Contents<!-- omit from toc -->
|
|
26
26
|
|
|
27
|
-
- [
|
|
27
|
+
- [SPECCER](#speccer)
|
|
28
28
|
- [About](#about)
|
|
29
29
|
- [Installation](#installation)
|
|
30
|
-
- [
|
|
31
|
-
- [Typescript](#typescript)
|
|
32
|
-
- [ESM](#esm)
|
|
33
|
-
- [Lazy loading](#lazy-loading)
|
|
34
|
-
- [Script](#script)
|
|
35
|
-
- [Advanced usage](#advanced-usage)
|
|
36
|
-
- [React](#react)
|
|
37
|
-
- [1. Create a hook](#1-create-a-hook)
|
|
38
|
-
- [2. Use the hook](#2-use-the-hook)
|
|
39
|
-
- [Storybook](#storybook)
|
|
40
|
-
- [Features](#features)
|
|
41
|
-
- [Element spacing](#element-spacing)
|
|
42
|
-
- [Bound spacing](#bound-spacing)
|
|
43
|
-
- [Element dimensions](#element-dimensions)
|
|
44
|
-
- [Slim measure](#slim-measure)
|
|
45
|
-
- [Pin element to annotate or highlight the anatomy](#pin-element-to-annotate-or-highlight-the-anatomy)
|
|
46
|
-
- [Default](#default)
|
|
47
|
-
- [Bracket](#bracket)
|
|
48
|
-
- [Enclose](#enclose)
|
|
49
|
-
- [Align with parent container](#align-with-parent-container)
|
|
50
|
-
- [Pin with text](#pin-with-text)
|
|
51
|
-
- [Custom literals](#custom-literals)
|
|
52
|
-
- [Subtle anatomy](#subtle-anatomy)
|
|
53
|
-
- [Curly brackets](#curly-brackets)
|
|
54
|
-
- [Pin programmatically](#pin-programmatically)
|
|
55
|
-
- [Element typography](#element-typography)
|
|
56
|
-
- [Syntax highlighting for typography](#syntax-highlighting-for-typography)
|
|
57
|
-
- [Grid spacing](#grid-spacing)
|
|
58
|
-
- [Mark elements](#mark-elements)
|
|
59
|
-
- [A11y notation](#a11y-notation)
|
|
60
|
-
- [Tab stops](#tab-stops)
|
|
61
|
-
- [Landmarks and regions](#landmarks-and-regions)
|
|
62
|
-
- [Headings](#headings)
|
|
63
|
-
- [Autocomplete](#autocomplete)
|
|
64
|
-
- [Keys and shortcut](#keys-and-shortcut)
|
|
65
|
-
- [Customization](#customization)
|
|
66
|
-
- [API](#api)
|
|
67
|
-
- [Development](#development)
|
|
30
|
+
- [Documentation](#documentation)
|
|
68
31
|
- [Used by](#used-by)
|
|
69
|
-
- [Contributing](#contributing)
|
|
70
32
|
- [License](#license)
|
|
71
33
|
- [Changelog](#changelog)
|
|
72
|
-
- [FAQ](#faq)
|
|
73
34
|
- [Sponsor me](#sponsor-me)
|
|
74
35
|
|
|
75
36
|
## Installation
|
|
@@ -78,792 +39,14 @@ webpage. If you need to draw attention to elements, **SPECCER** is your tool!
|
|
|
78
39
|
npm i --save @phun-ky/speccer
|
|
79
40
|
```
|
|
80
41
|
|
|
81
|
-
|
|
42
|
+
## Documentation
|
|
82
43
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
### Typescript
|
|
86
|
-
|
|
87
|
-
Types can be found in `@phun-ky/speccer/dist/speccer.d.ts`.
|
|
88
|
-
|
|
89
|
-
### ESM
|
|
90
|
-
|
|
91
|
-
Either import and run the required functions:
|
|
92
|
-
|
|
93
|
-
```javascript
|
|
94
|
-
import '@phun-ky/speccer/dist/speccer.min.css';
|
|
95
|
-
import speccer from '@phun-ky/speccer';
|
|
96
|
-
|
|
97
|
-
// do stuff
|
|
98
|
-
speccer();
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
#### Lazy loading
|
|
102
|
-
|
|
103
|
-
If you're importing **SPECCER** instead of with a script tag,
|
|
104
|
-
[you can use the following approach](https://codepen.io/phun-ky/pen/VwRRLyY) to
|
|
105
|
-
apply lazy loading:
|
|
106
|
-
|
|
107
|
-
```javascript
|
|
108
|
-
import { pin } from 'https://esm.sh/@phun-ky/speccer';
|
|
109
|
-
|
|
110
|
-
const { pinElements } = pin;
|
|
111
|
-
/**
|
|
112
|
-
* Callback function for IntersectionObserver
|
|
113
|
-
* @param {IntersectionObserverEntry[]} entries - Array of entries being observed
|
|
114
|
-
* @param {IntersectionObserver} observer - The IntersectionObserver instance
|
|
115
|
-
* @returns {Promise<void>} Promise that resolves when element dissection is complete
|
|
116
|
-
*/
|
|
117
|
-
const intersectionCallback: IntersectionObserverCallback = async (entries, observer) => {
|
|
118
|
-
entries.forEach(async (entry) => {
|
|
119
|
-
if (entry.intersectionRatio > 0) {
|
|
120
|
-
await pinElements(entry.target);
|
|
121
|
-
observer.unobserve(entry.target);
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
// Creating IntersectionObserver instance with the callback
|
|
126
|
-
const pinElementObserver = new IntersectionObserver(intersectionCallback);
|
|
127
|
-
/**
|
|
128
|
-
* Function to observe elements using IntersectionObserver
|
|
129
|
-
* @param {Element} el - The element to be observed
|
|
130
|
-
*/
|
|
131
|
-
const observeElement = (el: Element): void => {
|
|
132
|
-
pinElementObserver.observe(el);
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
// Observing elements with the specified data attribute
|
|
136
|
-
document.querySelectorAll('[data-speccer="pin-area"]').forEach((el) => {
|
|
137
|
-
observeElement(el);
|
|
138
|
-
});
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
### Script
|
|
142
|
-
|
|
143
|
-
Or place these `script` and `link` tags in your web page:
|
|
144
|
-
|
|
145
|
-
```html
|
|
146
|
-
<link rel="stylesheet" href="../path/to/speccer.min.css" />
|
|
147
|
-
<script src="../path/to/speccer.js"></script>
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
Or with a CDN:
|
|
151
|
-
|
|
152
|
-
```html
|
|
153
|
-
<link
|
|
154
|
-
rel="stylesheet"
|
|
155
|
-
href="https://unpkg.com/@phun-ky/speccer/dist/speccer.min.css"
|
|
156
|
-
/>
|
|
157
|
-
<script src="https://unpkg.com/@phun-ky/speccer/dist/speccer.js"></script>
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
And then follow the steps below to display the specifications you want :)
|
|
161
|
-
|
|
162
|
-
#### Advanced usage
|
|
163
|
-
|
|
164
|
-
If you want to control **SPECCER** a bit more, you have some options. Apply one
|
|
165
|
-
of these attributes to the script element for different types of initialization:
|
|
166
|
-
|
|
167
|
-
```html
|
|
168
|
-
<script src="../speccer.js" data-<manual|instant|dom|lazy></script>
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
Or with a CDN:
|
|
172
|
-
|
|
173
|
-
```html
|
|
174
|
-
<script src="https://unpkg.com/@phun-ky/speccer/dist/speccer.js" data-<manual|instant|dom|lazy></script>
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
| Tag | Description |
|
|
178
|
-
| -------------- | ------------------------------------------------------------------- |
|
|
179
|
-
| `data-manual` | Makes `window.speccer()` available to be used when you feel like it |
|
|
180
|
-
| `data-instant` | fires off `speccer()` right away |
|
|
181
|
-
| `data-dom` | Waits for `DOMContentLoaded` |
|
|
182
|
-
| `data-lazy` | Lazy loads `speccer()` per specced element |
|
|
183
|
-
|
|
184
|
-
If no attribute is applied, it will default to `data-dom`, as in, it will
|
|
185
|
-
initialize when `DOMContentLoaded` is fired.
|
|
186
|
-
|
|
187
|
-
### React
|
|
188
|
-
|
|
189
|
-
If you use React, you can use an effect like this:
|
|
190
|
-
|
|
191
|
-
```javascript
|
|
192
|
-
import React, { useEffect } from 'react';
|
|
193
|
-
|
|
194
|
-
import debounce from './lib/debounce';
|
|
195
|
-
import '@phun-ky/speccer/dist/speccer.min.css';
|
|
196
|
-
|
|
197
|
-
const Component = () => {
|
|
198
|
-
let speccerEventFunc;
|
|
199
|
-
|
|
200
|
-
useEffect(async () => {
|
|
201
|
-
const { default: speccer } = await import('@phun-ky/speccer');
|
|
202
|
-
|
|
203
|
-
speccer();
|
|
204
|
-
|
|
205
|
-
speccerEventFunc = debounce(function () {
|
|
206
|
-
speccer();
|
|
207
|
-
}, 300);
|
|
208
|
-
|
|
209
|
-
window.addEventListener('resize', speccerEventFunc);
|
|
210
|
-
|
|
211
|
-
return () => {
|
|
212
|
-
window.removeEventListener('resize', speccerEventFunc);
|
|
213
|
-
};
|
|
214
|
-
}, []);
|
|
215
|
-
|
|
216
|
-
return <div />;
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
export default Component;
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
Or a hook like this:
|
|
223
|
-
|
|
224
|
-
#### 1. Create a hook
|
|
225
|
-
|
|
226
|
-
```typescript
|
|
227
|
-
// ./hooks/useSpeccer.ts
|
|
228
|
-
import { useEffect } from 'react';
|
|
229
|
-
|
|
230
|
-
import '@phun-ky/speccer/dist/speccer.min.css';
|
|
231
|
-
import debounce from './lib/debounce';
|
|
232
|
-
|
|
233
|
-
const useSpeccer = () => {
|
|
234
|
-
useEffect(() => {
|
|
235
|
-
let speccerEventFunc: () => void;
|
|
236
|
-
|
|
237
|
-
const loadSpeccer = async () => {
|
|
238
|
-
const { default: speccer } = await import('@phun-ky/speccer');
|
|
239
|
-
|
|
240
|
-
speccer();
|
|
241
|
-
|
|
242
|
-
speccerEventFunc = debounce(() => {
|
|
243
|
-
speccer();
|
|
244
|
-
}, 300);
|
|
245
|
-
|
|
246
|
-
window.addEventListener('resize', speccerEventFunc);
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
loadSpeccer();
|
|
250
|
-
|
|
251
|
-
return () => {
|
|
252
|
-
if (speccerEventFunc) {
|
|
253
|
-
window.removeEventListener('resize', speccerEventFunc);
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
}, []);
|
|
257
|
-
};
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
#### 2. Use the hook
|
|
261
|
-
|
|
262
|
-
```typescript
|
|
263
|
-
import { useSpeccer } from './hooks/useSpeccer';
|
|
264
|
-
|
|
265
|
-
export const MyComponent = () => {
|
|
266
|
-
…
|
|
267
|
-
useSpeccer();
|
|
268
|
-
…
|
|
269
|
-
return <div data-speccer="pin bracket top">…</div>;
|
|
270
|
-
};
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
### Storybook
|
|
274
|
-
|
|
275
|
-
You can add **SPECCER** to your stories!
|
|
276
|
-
|
|
277
|
-

|
|
278
|
-
|
|
279
|
-
In `preview.tsx`:
|
|
280
|
-
|
|
281
|
-
```typescript
|
|
282
|
-
import '@phun-ky/speccer/dist/speccer.min.css';
|
|
283
|
-
import { debounce } from '@mui/material'; // or any other debounce function
|
|
284
|
-
import { addons } from '@storybook/preview-api';
|
|
285
|
-
|
|
286
|
-
let speccerEventFunc: (() => void) | undefined;
|
|
287
|
-
|
|
288
|
-
addons.getChannel().on('docsRendered', async () => {
|
|
289
|
-
const { default: speccer } = await import('@phun-ky/speccer');
|
|
290
|
-
|
|
291
|
-
speccer();
|
|
292
|
-
speccerEventFunc = debounce(() => {
|
|
293
|
-
speccer();
|
|
294
|
-
}, 100);
|
|
295
|
-
|
|
296
|
-
window.addEventListener('resize', speccerEventFunc);
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
addons.getChannel().on('storyChanged', () => {
|
|
300
|
-
if (speccerEventFunc) {
|
|
301
|
-
window.removeEventListener('resize', speccerEventFunc);
|
|
302
|
-
speccerEventFunc = undefined;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// Remove all pinned elements
|
|
306
|
-
document.querySelectorAll('.ph-speccer')?.forEach((el) => {
|
|
307
|
-
if (el instanceof HTMLElement) {
|
|
308
|
-
el.remove();
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
});
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
And then in your `*.stories.tsx`:
|
|
315
|
-
|
|
316
|
-
```typescript
|
|
317
|
-
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
|
318
|
-
import { MyComponent } from '../path-to-component/MyComponent';
|
|
319
|
-
|
|
320
|
-
export default {
|
|
321
|
-
title: 'Components/MyComponent',
|
|
322
|
-
component: MyComponent,
|
|
323
|
-
tags: ['autodocs'],
|
|
324
|
-
…
|
|
325
|
-
|
|
326
|
-
} as ComponentMeta<typeof MyComponent>
|
|
327
|
-
|
|
328
|
-
const Template: ComponentStory<typeof MyComponent> = (args) => {
|
|
329
|
-
|
|
330
|
-
…
|
|
331
|
-
// you need `data-speccer="pin-area"` on the container of the elements you want to spec
|
|
332
|
-
return (
|
|
333
|
-
<div data-speccer="pin-area">
|
|
334
|
-
<MyComponent {...args} />
|
|
335
|
-
</div>
|
|
336
|
-
);
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
export const Basic = Template.bind({});
|
|
340
|
-
Basic.args = {
|
|
341
|
-
…,
|
|
342
|
-
"data-speccer": "pin bracket top",
|
|
343
|
-
};
|
|
344
|
-
```
|
|
345
|
-
|
|
346
|
-
> [!IMPORTANT] Just make sure `MyComponent` passed down the attributes to the
|
|
347
|
-
> DOM element
|
|
348
|
-
|
|
349
|
-
## Features
|
|
350
|
-
|
|
351
|
-
### Element spacing
|
|
352
|
-
|
|
353
|
-

|
|
354
|
-
|
|
355
|
-
Use the following attribute to display element padding and margin:
|
|
356
|
-
|
|
357
|
-
```html
|
|
358
|
-
<div data-speccer="spacing [padding|margin] [bound]" class="…"></div>
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
This will display the element _and all of it's children_ padding and margin,
|
|
362
|
-
unless you specify `padding` and `margin`
|
|
363
|
-
|
|
364
|
-

|
|
365
|
-
|
|
366
|
-
#### Bound spacing
|
|
367
|
-
|
|
368
|
-

|
|
369
|
-
|
|
370
|
-
This option binds the speccer elements to the bounds of the element container.
|
|
371
|
-
|
|
372
|
-
```html
|
|
373
|
-
<div data-speccer="spacing bound" class="…"></div>
|
|
374
|
-
```
|
|
375
|
-
|
|
376
|
-
### Element dimensions
|
|
377
|
-
|
|
378
|
-

|
|
379
|
-

|
|
380
|
-
|
|
381
|
-
Display dimensions with:
|
|
382
|
-
|
|
383
|
-
```html
|
|
384
|
-
<div
|
|
385
|
-
data-speccer="measure [height left|right] | [width top|bottom]"
|
|
386
|
-
class="…"
|
|
387
|
-
></div>
|
|
388
|
-
```
|
|
389
|
-
|
|
390
|
-
Where `height` and `width` comes with placement flags. Default for `height` is
|
|
391
|
-
`left`, default for `width` is `top`.
|
|
392
|
-
|
|
393
|
-

|
|
394
|
-
|
|
395
|
-
#### Slim measure
|
|
396
|
-
|
|
397
|
-

|
|
398
|
-
|
|
399
|
-
Use a slim style:
|
|
400
|
-
|
|
401
|
-
```html
|
|
402
|
-
<div data-speccer="measure slim height left" class="…"></div>
|
|
403
|
-
```
|
|
404
|
-
|
|
405
|
-
This will give a slimmer look and feel.
|
|
406
|
-
|
|
407
|
-
##### Subtle slim measure
|
|
408
|
-
|
|
409
|
-
Use a subtle style for the slim option, uses a dashed line instead of a solid
|
|
410
|
-
line:
|
|
411
|
-
|
|
412
|
-
```html
|
|
413
|
-
<div data-speccer="measure slim height left subtle" class="…"></div>
|
|
414
|
-
```
|
|
415
|
-
|
|
416
|
-
This will give a dashed border.
|
|
417
|
-
|
|
418
|
-
### Pin element to annotate or highlight the anatomy
|
|
419
|
-
|
|
420
|
-

|
|
421
|
-
|
|
422
|
-
In your component examples, use the following attribute. Remember to use the
|
|
423
|
-
`data-speccer="pin-area"`-attribute on a parent element to scope the marking.
|
|
424
|
-
|
|
425
|
-
```html
|
|
426
|
-
<div data-speccer="pin-area">
|
|
427
|
-
<div
|
|
428
|
-
data-speccer="pin [bracket [curly] |enclose] [left|right|top|bottom]"
|
|
429
|
-
class="…"
|
|
430
|
-
></div>
|
|
431
|
-
</div>
|
|
432
|
-
```
|
|
433
|
-
|
|
434
|
-
This will place a pin to the outline of the element. Default is `top`.
|
|
435
|
-
|
|
436
|
-
#### Default
|
|
437
|
-
|
|
438
|
-

|
|
439
|
-
|
|
440
|
-
```html
|
|
441
|
-
<div data-speccer="pin-area">
|
|
442
|
-
<div data-speccer="pin" class="…"></div>
|
|
443
|
-
</div>
|
|
444
|
-
```
|
|
445
|
-
|
|
446
|
-
#### Bracket
|
|
447
|
-
|
|
448
|
-
```html
|
|
449
|
-
<div data-speccer="pin-area">
|
|
450
|
-
<div data-speccer="pin bracket" class="…"></div>
|
|
451
|
-
</div>
|
|
452
|
-
```
|
|
453
|
-
|
|
454
|
-
#### Enclose
|
|
455
|
-
|
|
456
|
-

|
|
457
|
-
|
|
458
|
-
```html
|
|
459
|
-
<div data-speccer="pin-area">
|
|
460
|
-
<div data-speccer="pin enclose" class="…"></div>
|
|
461
|
-
</div>
|
|
462
|
-
```
|
|
463
|
-
|
|
464
|
-
##### Subtle enclose
|
|
465
|
-
|
|
466
|
-

|
|
467
|
-
|
|
468
|
-
```html
|
|
469
|
-
<div data-speccer="pin-area">
|
|
470
|
-
<div data-speccer="pin enclose" class="…"></div>
|
|
471
|
-
</div>
|
|
472
|
-
```
|
|
473
|
-
|
|
474
|
-
#### Align with parent container
|
|
475
|
-
|
|
476
|
-

|
|
477
|
-
|
|
478
|
-
You can also align the pins to the parent container.
|
|
479
|
-
|
|
480
|
-
```html
|
|
481
|
-
<div data-speccer="pin-area">
|
|
482
|
-
<div data-speccer="pin parent [left|right|top|bottom]" class="…"></div>
|
|
483
|
-
</div>
|
|
484
|
-
```
|
|
485
|
-
|
|
486
|
-
> [!NOTE] Only works with `pin [left|right|top|bottom]`, and not with `enclose`,
|
|
487
|
-
> `bracket` or `curly`!
|
|
488
|
-
|
|
489
|
-
The lines from the element to the pin is drawn with a svg path and circle, so
|
|
490
|
-
remember to add the following svg into your document:
|
|
491
|
-
|
|
492
|
-
```html
|
|
493
|
-
<svg
|
|
494
|
-
class="ph-speccer"
|
|
495
|
-
viewBox="0 0"
|
|
496
|
-
id="ph-speccer-svg"
|
|
497
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
498
|
-
>
|
|
499
|
-
<path
|
|
500
|
-
class="ph-speccer path original"
|
|
501
|
-
id="ph-speccer-path"
|
|
502
|
-
fill="none"
|
|
503
|
-
stroke-width="1"
|
|
504
|
-
stroke="currentColor"
|
|
505
|
-
/>
|
|
506
|
-
</svg>
|
|
507
|
-
```
|
|
508
|
-
|
|
509
|
-

|
|
510
|
-
|
|
511
|
-
#### Pin with text
|
|
512
|
-
|
|
513
|
-

|
|
514
|
-
|
|
515
|
-
If you want _text-in-place_ pinning feature, instead of referencing the pins,
|
|
516
|
-
you can use the `text` feature:
|
|
517
|
-
|
|
518
|
-
```html
|
|
519
|
-
<input
|
|
520
|
-
type="text"
|
|
521
|
-
…
|
|
522
|
-
data-speccer="pin left text"
|
|
523
|
-
data-speccer-title="Static text"
|
|
524
|
-
data-speccer-description="Document size [xx] by [yy][units]"
|
|
525
|
-
…
|
|
526
|
-
/>
|
|
527
|
-
```
|
|
528
|
-
|
|
529
|
-
#### Custom literals
|
|
530
|
-
|
|
531
|
-

|
|
532
|
-
|
|
533
|
-
You can use custom literals by assigned a global variable with the literals you
|
|
534
|
-
want:
|
|
535
|
-
|
|
536
|
-
```js
|
|
537
|
-
window.SPECCER_LITERALS = [
|
|
538
|
-
'あ',
|
|
539
|
-
'い',
|
|
540
|
-
'う',
|
|
541
|
-
'え',
|
|
542
|
-
'お',
|
|
543
|
-
'か',
|
|
544
|
-
'き',
|
|
545
|
-
'く',
|
|
546
|
-
…
|
|
547
|
-
];
|
|
548
|
-
```
|
|
549
|
-
|
|
550
|
-
Or with a data attribute on the `data-speccer="pin-area"`-element:
|
|
551
|
-
|
|
552
|
-
```html
|
|
553
|
-
<div data-speccer="pin-area" data-speccer-literals="ऄ|अआइईउऊऋऌऍऎएऐऑऒओऔकखगघङच">
|
|
554
|
-
…
|
|
555
|
-
</div>
|
|
556
|
-
```
|
|
557
|
-
|
|
558
|
-
> [!TIP] Try it out with emoticons!
|
|
559
|
-
>
|
|
560
|
-
> ```js
|
|
561
|
-
> window.SPECCER_LITERALS = [
|
|
562
|
-
> '🥰',
|
|
563
|
-
> …
|
|
564
|
-
> ];
|
|
565
|
-
> ```
|
|
566
|
-
|
|
567
|
-
#### Subtle anatomy
|
|
568
|
-
|
|
569
|
-

|
|
570
|
-
|
|
571
|
-
You can also give a more subtle touch to the anatomy elements.
|
|
572
|
-
|
|
573
|
-
```html
|
|
574
|
-
<div data-speccer="pin-area">
|
|
575
|
-
<div data-speccer="pin top subtle" class="…"></div>
|
|
576
|
-
</div>
|
|
577
|
-
```
|
|
578
|
-
|
|
579
|
-
This will give a dashed border, and a more subtle pin style.
|
|
580
|
-
|
|
581
|
-
#### Curly brackets
|
|
582
|
-
|
|
583
|
-
You can use curly brackets with the `curly` tag in `data-speccer` along side
|
|
584
|
-
`pin bracket` to provide a more sleek style.
|
|
585
|
-
|
|
586
|
-

|
|
587
|
-
|
|
588
|
-
> [!NOTE] Only works with `pin bracket`
|
|
589
|
-
|
|
590
|
-
The curly brackets are made with SVG paths, and it is required to have the
|
|
591
|
-
following snippet on your page for it to render:
|
|
592
|
-
|
|
593
|
-
```html
|
|
594
|
-
<svg
|
|
595
|
-
class="ph-speccer"
|
|
596
|
-
viewBox="0 0"
|
|
597
|
-
id="ph-speccer-svg"
|
|
598
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
599
|
-
>
|
|
600
|
-
<path
|
|
601
|
-
class="ph-speccer path original"
|
|
602
|
-
id="ph-speccer-path"
|
|
603
|
-
fill="none"
|
|
604
|
-
stroke-width="1"
|
|
605
|
-
stroke="currentColor"
|
|
606
|
-
/>
|
|
607
|
-
</svg>
|
|
608
|
-
```
|
|
609
|
-
|
|
610
|
-
#### Pin programmatically
|
|
611
|
-
|
|
612
|
-
from v9.5 you can utilize the `pin` feature to annotate or highlight the anatomy
|
|
613
|
-
of an element programmatically.
|
|
614
|
-
[Here is an example with a click event](https://codepen.io/phun-ky/pen/LYKOWyP).
|
|
615
|
-
|
|
616
|
-
[Kazam_screencast_00002.webm](https://github.com/user-attachments/assets/5c78cece-de46-4876-81f2-98c9108a2103)
|
|
617
|
-
|
|
618
|
-
### Element typography
|
|
619
|
-
|
|
620
|
-

|
|
621
|
-
|
|
622
|
-
Display typography details:
|
|
623
|
-
|
|
624
|
-
```html
|
|
625
|
-
<p data-speccer="typography [left|right|top|bottom]" class="…">Some text</p>
|
|
626
|
-
```
|
|
627
|
-
|
|
628
|
-
This will place a box to display typography information. Default is `left`.
|
|
629
|
-
|
|
630
|
-
> [!NOTE] > `getComputedStyles` are used to get the _computed_ values, so for
|
|
631
|
-
> example, a `line-height` set to `1.5` will be presented in pixels, like `96px`
|
|
632
|
-
> if the `font-size` is set to `64px`.
|
|
633
|
-
|
|
634
|
-
#### Syntax highlighting for typography
|
|
635
|
-
|
|
636
|
-
If you want to produce a box that uses `pre` and `code` tags with support for
|
|
637
|
-
syntax highlighting ([PrismJS](https://prismjs.com/) compatible), add `syntax`
|
|
638
|
-
to the `data-speccer="typography"` attribute.
|
|
639
|
-
|
|
640
|
-
```html
|
|
641
|
-
<p data-speccer="typography syntax right" class="…">Some text</p>
|
|
642
|
-
```
|
|
643
|
-
|
|
644
|
-
You can then override the colors, based on these variables:
|
|
645
|
-
|
|
646
|
-
```css
|
|
647
|
-
.ph-speccer.speccer.typography.syntax {
|
|
648
|
-
--ph-speccer-color-code-color-1: #737373;
|
|
649
|
-
--ph-speccer-color-code-color-2: #ff3aa8;
|
|
650
|
-
--ph-speccer-color-code-color-3: #38383d;
|
|
651
|
-
--ph-speccer-color-code-color-4: #ff3aa8;
|
|
652
|
-
--ph-speccer-color-code-color-5: #ff3aa8;
|
|
653
|
-
--ph-speccer-color-code-color-6: #0074e8;
|
|
654
|
-
--ph-speccer-color-code-color-7: #000000;
|
|
655
|
-
--ph-speccer-color-code-color-8: #cd0404;
|
|
656
|
-
}
|
|
657
|
-
```
|
|
658
|
-
|
|
659
|
-
Here is an example with these colors and overrides:
|
|
660
|
-
|
|
661
|
-
```css
|
|
662
|
-
.ph-speccer.speccer.typography.syntax {
|
|
663
|
-
color: #8c9b9b;
|
|
664
|
-
background-color: #262831;
|
|
665
|
-
border-radius: 0.375rem;
|
|
666
|
-
font-size: 12px;
|
|
667
|
-
line-height: 1.5;
|
|
668
|
-
border: none;
|
|
669
|
-
--ph-speccer-color-code-color-1: #859ba3;
|
|
670
|
-
--ph-speccer-color-code-color-2: #c79500;
|
|
671
|
-
--ph-speccer-color-code-color-3: #2caaa0;
|
|
672
|
-
--ph-speccer-color-code-color-4: #469edd;
|
|
673
|
-
--ph-speccer-color-code-color-5: #8c9b9b;
|
|
674
|
-
--ph-speccer-color-code-color-6: #e4e4e7;
|
|
675
|
-
--ph-speccer-color-code-color-7: #262831;
|
|
676
|
-
--ph-speccer-color-code-color-8: #ff6666;
|
|
677
|
-
}
|
|
678
|
-
```
|
|
679
|
-
|
|
680
|
-

|
|
681
|
-
|
|
682
|
-
## Grid spacing
|
|
683
|
-
|
|
684
|
-

|
|
685
|
-
|
|
686
|
-
This will highlight the grid spacing in a `display: grid;` element.
|
|
687
|
-
|
|
688
|
-
In your component examples, use the following attribute on your grid container.
|
|
689
|
-
|
|
690
|
-
```html
|
|
691
|
-
<div data-speccer="grid" …>…</div>
|
|
692
|
-
```
|
|
693
|
-
|
|
694
|
-
> [!TIP] If you only want to display `rows` or `columns`, use this syntax
|
|
695
|
-
> (default is both with `grid` only):
|
|
696
|
-
>
|
|
697
|
-
> ```html
|
|
698
|
-
> <div data-speccer="grid [rows|columns]" …>…</div>
|
|
699
|
-
> ```
|
|
700
|
-
|
|
701
|
-

|
|
702
|
-
|
|
703
|
-
## Mark elements
|
|
704
|
-
|
|
705
|
-

|
|
706
|
-
|
|
707
|
-
This will mark the given elements.
|
|
708
|
-
|
|
709
|
-
In your component examples, use the following attribute.
|
|
710
|
-
|
|
711
|
-
```html
|
|
712
|
-
<div data-speccer="mark" …>…</div>
|
|
713
|
-
```
|
|
714
|
-
|
|
715
|
-
### A11y notation
|
|
716
|
-
|
|
717
|
-
With **SPECCER**, you can also display accessibility notation, like
|
|
718
|
-
[Accessibility Bluelines](https://dribbble.com/shots/6269661-Accessibility-Bluelines?utm_source=Clipboard_Shot&utm_campaign=jeremyelder&utm_content=Accessibility%20Bluelines&utm_medium=Social_Share&utm_source=Clipboard_Shot&utm_campaign=jeremyelder&utm_content=Accessibility%20Bluelines&utm_medium=Social_Share)
|
|
719
|
-
or
|
|
720
|
-
[A11y Annotation Kit](https://www.figma.com/community/file/953682768192596304):
|
|
721
|
-
|
|
722
|
-
Prior art: [Jeremy Elder](https://twitter.com/JeremyElder) and
|
|
723
|
-
[Stephanie Hagadorn](https://shagadorn.work/)
|
|
724
|
-
|
|
725
|
-
#### Tab stops
|
|
726
|
-
|
|
727
|
-

|
|
728
|
-
|
|
729
|
-
If you want to display tab stops, append `data-speccer="a11y tabstops"` as an
|
|
730
|
-
attribute to the container you want to display the tab stops in.
|
|
731
|
-
|
|
732
|
-
#### Landmarks and regions
|
|
733
|
-
|
|
734
|
-

|
|
735
|
-
|
|
736
|
-
If you want to display landmarks and regions, append
|
|
737
|
-
`data-speccer="a11y landmark"` as an attribute to the container you want to
|
|
738
|
-
display the landmarks and regions in.
|
|
739
|
-
|
|
740
|
-
#### Headings
|
|
741
|
-
|
|
742
|
-

|
|
743
|
-
|
|
744
|
-
If you want to display headings, append `data-speccer="a11y headings"` as an
|
|
745
|
-
attribute to the container you want to display the headings in.
|
|
746
|
-
|
|
747
|
-
#### Autocomplete
|
|
748
|
-
|
|
749
|
-

|
|
750
|
-
|
|
751
|
-
If you want to display autocomplete, append `data-speccer="a11y autocomplete"`
|
|
752
|
-
as an attribute to the container you want to display the autocomplete in.
|
|
753
|
-
|
|
754
|
-
#### Keys and shortcut
|
|
755
|
-
|
|
756
|
-

|
|
757
|
-
|
|
758
|
-
If you want to display the shortcut with keys used for elements, use
|
|
759
|
-
`data-speccer="a11y shortcut"` and `data-speccer-a11y-shortcut="<shortcut>"` on
|
|
760
|
-
the element that uses this shortcut:
|
|
761
|
-
|
|
762
|
-
```html
|
|
763
|
-
<button
|
|
764
|
-
type="button"
|
|
765
|
-
data-speccer="a11y shortcut"
|
|
766
|
-
data-speccer-a11y-shortcut="ctrl + s"
|
|
767
|
-
>
|
|
768
|
-
Save
|
|
769
|
-
</button>
|
|
770
|
-
```
|
|
771
|
-
|
|
772
|
-
### Customization
|
|
773
|
-
|
|
774
|
-

|
|
775
|
-
|
|
776
|
-
Although the styling works nicely with dark mode, you can use the provided CSS
|
|
777
|
-
variables to customize the look and feel. If more control is needed, you can use
|
|
778
|
-
CSS overrides :)
|
|
779
|
-
|
|
780
|
-
```css
|
|
781
|
-
.ph-speccer.speccer {
|
|
782
|
-
--ph-speccer-color-artificialStrawberry: #ff3aa8;
|
|
783
|
-
--ph-speccer-color-venusSlipperOrchid: #db6fff;
|
|
784
|
-
--ph-speccer-color-superBanana: #fff76f;
|
|
785
|
-
--ph-speccer-color-white: #ffffff;
|
|
786
|
-
--ph-speccer-color-carbon: #333333;
|
|
787
|
-
--ph-speccer-color-red: #ff0000;
|
|
788
|
-
--ph-speccer-color-niuZaiSeDenim: #0074e8;
|
|
789
|
-
--ph-speccer-color-beautifulBlue: #1868b2;
|
|
790
|
-
--ph-speccer-color-fuchsiaBlue: #7e60c5;
|
|
791
|
-
--ph-speccer-base-color: var(--ph-speccer-color-artificialStrawberry);
|
|
792
|
-
--ph-speccer-spacing-color: var(--ph-speccer-base-color);
|
|
793
|
-
--ph-speccer-spacing-padding-color: var(--ph-speccer-color-carbon);
|
|
794
|
-
--ph-speccer-spacing-padding-color-background: rgb(
|
|
795
|
-
from var(--ph-speccer-color-venusSlipperOrchid) r g b /
|
|
796
|
-
var(--ph-speccer-opacity-40)
|
|
797
|
-
);
|
|
798
|
-
--ph-speccer-spacing-margin-color: var(--ph-speccer-color-red);
|
|
799
|
-
--ph-speccer-spacing-margin-color-background: rgb(
|
|
800
|
-
from var(--ph-speccer-color-superBanana) r g b /
|
|
801
|
-
var(--ph-speccer-opacity-40)
|
|
802
|
-
);
|
|
803
|
-
--ph-speccer-spacing-line-width: var(--ph-speccer-line-width);
|
|
804
|
-
--ph-speccer-typography-background-color: var(--ph-speccer-color-white);
|
|
805
|
-
--ph-speccer-typography-color-property: var(--ph-speccer-color-niuZaiSeDenim);
|
|
806
|
-
--ph-speccer-typography-color-text: var(--ph-speccer-base-color);
|
|
807
|
-
--ph-speccer-typography-color-value: var(--ph-speccer-base-color);
|
|
808
|
-
--ph-speccer-mark-background-color: rgb(
|
|
809
|
-
from var(--ph-speccer-base-color) r g b / var(--ph-speccer-opacity-20)
|
|
810
|
-
);
|
|
811
|
-
--ph-speccer-mark-border-color: var(--ph-speccer-base-color);
|
|
812
|
-
--ph-speccer-mark-border-width: 1.5px;
|
|
813
|
-
--ph-speccer-mark-border-style: solid;
|
|
814
|
-
--ph-speccer-measure-color: var(--ph-speccer-color-red);
|
|
815
|
-
--ph-speccer-measure-line-width: 1.5px;
|
|
816
|
-
--ph-speccer-measure-border-style: dotted;
|
|
817
|
-
--ph-speccer-measure-size: 8px;
|
|
818
|
-
--ph-speccer-a11y-color-background: var(--ph-speccer-color-beautifulBlue);
|
|
819
|
-
--ph-speccer-a11y-landmark-color-background: var(
|
|
820
|
-
--ph-speccer-color-fuchsiaBlue
|
|
821
|
-
);
|
|
822
|
-
--ph-speccer-color-text-light: var(--ph-speccer-color-white);
|
|
823
|
-
--ph-speccer-color-text-dark: var(--ph-speccer-color-carbon);
|
|
824
|
-
--ph-speccer-pin-color: var(--ph-speccer-base-color);
|
|
825
|
-
--ph-speccer-pin-size: 24px;
|
|
826
|
-
--ph-speccer-pin-space: 48px;
|
|
827
|
-
--ph-speccer-line-height: 12px;
|
|
828
|
-
--ph-speccer-line-width: 1.5px;
|
|
829
|
-
--ph-speccer-line-width-negative: -1.5px;
|
|
830
|
-
--ph-speccer-opacity-20: 0.2;
|
|
831
|
-
--ph-speccer-opacity-40: 0.4;
|
|
832
|
-
--ph-speccer-font-family:
|
|
833
|
-
'Menlo for Powerline', 'Menlo Regular for Powerline', 'DejaVu Sans Mono',
|
|
834
|
-
Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
|
|
835
|
-
--ph-speccer-font-size: 12px;
|
|
836
|
-
--ph-speccer-transition-default: all 2s cubic-bezier(0.4, 0, 0.2, 1);
|
|
837
|
-
}
|
|
838
|
-
```
|
|
839
|
-
|
|
840
|
-
## API
|
|
841
|
-
|
|
842
|
-
Full API documentation is available
|
|
843
|
-
[here](https://github.com/phun-ky/speccer/blob/main/docs/api/index.md).
|
|
844
|
-
|
|
845
|
-
## Development
|
|
846
|
-
|
|
847
|
-
```shell-session
|
|
848
|
-
// Build
|
|
849
|
-
$ npm run build
|
|
850
|
-
// Run dev
|
|
851
|
-
$ npm run dev
|
|
852
|
-
// Test
|
|
853
|
-
$ npm test
|
|
854
|
-
```
|
|
44
|
+
To see the documentation, go to [speccer.dev](https://speccer.dev).
|
|
855
45
|
|
|
856
46
|
## Used by
|
|
857
47
|
|
|
858
|
-
| [](https://www.if-insurance.com) | [](https://24sevenoffice.com) |
|
|
859
|
-
|
|
|
860
|
-
|
|
861
|
-
## Contributing
|
|
862
|
-
|
|
863
|
-
Want to contribute? Please read the
|
|
864
|
-
[CONTRIBUTING.md](https://github.com/phun-ky/speccer/blob/main/CONTRIBUTING.md)
|
|
865
|
-
and
|
|
866
|
-
[CODE_OF_CONDUCT.md](https://github.com/phun-ky/speccer/blob/main/CODE_OF_CONDUCT.md)
|
|
48
|
+
| [](https://www.if-insurance.com) | [](https://24sevenoffice.com) |
|
|
49
|
+
| ---------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
|
|
867
50
|
|
|
868
51
|
## License
|
|
869
52
|
|
|
@@ -877,12 +60,6 @@ See the
|
|
|
877
60
|
[CHANGELOG.md](https://github.com/phun-ky/speccer/blob/main/CHANGELOG.md) for
|
|
878
61
|
details on the latest updates.
|
|
879
62
|
|
|
880
|
-
## FAQ
|
|
881
|
-
|
|
882
|
-
See the
|
|
883
|
-
[discussions](https://github.com/phun-ky/speccer/discussions/categories/q-a) for
|
|
884
|
-
an FAQ or to ask questions if no answer is given.
|
|
885
|
-
|
|
886
63
|
## Sponsor me
|
|
887
64
|
|
|
888
65
|
I'm an Open Source evangelist, creating stuff that does not exist yet to help
|
|
@@ -895,7 +72,7 @@ we're all part of :)
|
|
|
895
72
|
|
|
896
73
|
[Support me on GitHub Sponsors](https://github.com/sponsors/phun-ky).
|
|
897
74
|
|
|
898
|
-

|
|
75
|
+

|
|
899
76
|
|
|
900
77
|
p.s. **Ukraine is still under brutal Russian invasion. A lot of Ukrainian people
|
|
901
78
|
are hurt, without shelter and need help**. You can help in various ways, for
|
package/dist/speccer.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ declare global {
|
|
|
21
21
|
speccer: any;
|
|
22
22
|
/**
|
|
23
23
|
* Represents the custom literals to be used.
|
|
24
|
-
* 
|
|
25
25
|
* @example
|
|
26
26
|
* ```js
|
|
27
27
|
* window.SPECCER_LITERALS = [あ,い,う,え,お,か,き,く,け,こ,さ,し,す,せ,そ,た,ち,つ,て,と,な,に,ぬ,ね,の,は,ひ,ふ,へ,ほ,ま,み,む,め,も,や,ゆ,よ,ら,り,る,れ,ろ,わ,を];
|
|
@@ -38,7 +38,7 @@ declare global {
|
|
|
38
38
|
*
|
|
39
39
|
* This feature will annotate or highlight accessibility areas like landmarks and region. It can also display tab stops/sequence and any keyboard shortcuts assigned
|
|
40
40
|
*
|
|
41
|
-
* 
|
|
42
42
|
*
|
|
43
43
|
* @example
|
|
44
44
|
*
|
|
@@ -318,7 +318,7 @@ declare const removeSpeccerElement: (el: HTMLElement) => void;
|
|
|
318
318
|
/**
|
|
319
319
|
* This feature will highlight the grid spacing in a `display: grid;` element.
|
|
320
320
|
*
|
|
321
|
-
* 
|
|
322
322
|
*
|
|
323
323
|
* @example
|
|
324
324
|
*
|
|
@@ -353,7 +353,7 @@ declare const grid: {
|
|
|
353
353
|
/**
|
|
354
354
|
* This feature highlights the spacing of an element.
|
|
355
355
|
*
|
|
356
|
-
* 
|
|
357
357
|
* *
|
|
358
358
|
* @example
|
|
359
359
|
*
|
|
@@ -379,7 +379,7 @@ declare const spacing: {
|
|
|
379
379
|
/**
|
|
380
380
|
* This feature annotate or highlight the anatomy of an element.
|
|
381
381
|
*
|
|
382
|
-
* 
|
|
383
383
|
*
|
|
384
384
|
* In your component examples, use the following attribute. Remember to use the `data-speccer="pin-area"`-attribute on a parent element to scope the marking.
|
|
385
385
|
*
|
|
@@ -402,7 +402,7 @@ declare const pin: {
|
|
|
402
402
|
/**
|
|
403
403
|
* This feature measures given element
|
|
404
404
|
*
|
|
405
|
-
* 
|
|
406
406
|
*
|
|
407
407
|
* @example
|
|
408
408
|
*
|
|
@@ -437,7 +437,7 @@ declare const measure: {
|
|
|
437
437
|
/**
|
|
438
438
|
* This feature marks given element
|
|
439
439
|
*
|
|
440
|
-
* 
|
|
441
441
|
*
|
|
442
442
|
* @example
|
|
443
443
|
*
|
|
@@ -469,7 +469,7 @@ declare const mark: {
|
|
|
469
469
|
/**
|
|
470
470
|
* This feature presents typography
|
|
471
471
|
*
|
|
472
|
-
* 
|
|
473
473
|
*
|
|
474
474
|
* @example
|
|
475
475
|
*
|
package/dist/speccer.esm.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @phun-ky/speccer
|
|
3
3
|
* A script to annotate, show spacing specs and to display typography information in documentation/website on HTML elements
|
|
4
4
|
* @author Alexander Vassbotn Røyne-Helgesen <alexander@phun-ky.net>
|
|
5
|
-
* @version 11.3.
|
|
5
|
+
* @version 11.3.1
|
|
6
6
|
* @license
|
|
7
7
|
* Copyright (c) 2018-2025 Alexander Vassbotn Røyne-Helgesen
|
|
8
8
|
*
|
package/dist/speccer.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @phun-ky/speccer
|
|
3
3
|
* A script to annotate, show spacing specs and to display typography information in documentation/website on HTML elements
|
|
4
4
|
* @author Alexander Vassbotn Røyne-Helgesen <alexander@phun-ky.net>
|
|
5
|
-
* @version 11.3.
|
|
5
|
+
* @version 11.3.1
|
|
6
6
|
* @license
|
|
7
7
|
* Copyright (c) 2018-2025 Alexander Vassbotn Røyne-Helgesen
|
|
8
8
|
*
|
package/package.json
CHANGED