GithubHelp home page GithubHelp logo

phun-ky / speccer Goto Github PK

View Code? Open in Web Editor NEW
13.0 3.0 1.0 6.79 MB

SPECCER was originally created to simplify documenting components in a design system, but it can be used to highlight any HTML element on a webpage. If you need to draw attention to elements, SPECCER is your tool!

Home Page: https://phun-ky.net/projects/speccer/

License: MIT License

JavaScript 1.22% Stylus 8.41% HTML 32.44% TypeScript 57.94%
annotate annotation speccer specification specs specifications information documentation html-elements spacing

speccer's Introduction

@phun-ky/speccer

Speccer hero, with logo and slogan: A zero dependency package to highlight elements

Commitizen friendly PRs Welcome SemVer 2.0 npm version issues license size npm GitHub Repo stars codecov build

About

Image of speccer

SPECCER was originally created to simplify documenting components in a design system, but it can be used to highlight any HTML element on a webpage. If you need to draw attention to elements, SPECCER is your tool!

Table of Contents

Installation

npm i --save @phun-ky/speccer

See a live demo.

Usage

Typescript

Types can be found in @phun-ky/speccer/dist/speccer.d.ts.

ESM

Either import and run the required functions:

import '@phun-ky/speccer/dist/speccer.min.css';
import speccer from '@phun-ky/speccer';

// do stuff
speccer();

Lazy loading

If you're importing SPECCER instead of with a script tag, you can use the following approach to apply lazy loading:

import { pin } from "https://esm.sh/@phun-ky/speccer";

const { pinElements } = pin;

/**
 * Callback function for IntersectionObserver
 * @param {IntersectionObserverEntry[]} entries - Array of entries being observed
 * @param {IntersectionObserver} observer - The IntersectionObserver instance
 * @returns {Promise<void>} Promise that resolves when element dissection is complete
 */
const intersectionCallback: IntersectionObserverCallback = async (entries, observer) => {
  entries.forEach(async (entry) => {
    if (entry.intersectionRatio > 0) {
      await pinElements(entry.target);
      observer.unobserve(entry.target);
    }
  });
};

// Creating IntersectionObserver instance with the callback
const pinElementObserver = new IntersectionObserver(intersectionCallback);

/**
 * Function to observe elements using IntersectionObserver
 * @param {Element} el - The element to be observed
 */
const observeElement = (el: Element): void => {
  pinElementObserver.observe(el);
};

// Observing elements with the specified data attribute
document.querySelectorAll('[data-speccer="pin-area"]').forEach((el) => {
  observeElement(el);
});

Script

Or place these script and link tags in your web page:

<link rel="stylesheet" href="../path/to/speccer.min.css" />
<script src="../path/to/speccer.js"></script>

Or with a CDN:

<link
  rel="stylesheet"
  href="https://unpkg.com/@phun-ky/speccer/dist/speccer.min.css"
/>
<script src="https://unpkg.com/@phun-ky/speccer/dist/speccer.js"></script>

And then follow the steps below to display the specifications you want :)

Advanced usage

If you want to control SPECCER a bit more, you have some options. Apply one of these attributes to the script element for different types of initialization:

<script src="../speccer.js" data-<manual|instant|dom|lazy></script>

Or with a CDN:

<script src="https://unpkg.com/@phun-ky/speccer/dist/speccer.js" data-<manual|instant|dom|lazy></script>
Tag Description
data-manual Makes window.speccer() available to be used when you feel like it
data-instant fires off speccer() right away
data-dom Waits for DOMContentLoaded
data-lazy Lazy loads speccer() per specced element

If no attribute is applied, it will default to data-dom, as in, it will initialize when DOMContentLoaded is fired.

React

If you use React, you can use an effect like this:

import React, { useEffect } from 'react';
import PropTypes from 'prop-types';

import debounce from './lib/debounce';
import '@phun-ky/speccer/dist/speccer.min.css';

const Component = () => {
  let speccerEventFunc;

  useEffect(async () => {
    const { default: speccer } = await import('@phun-ky/speccer');

    speccer();

    speccerEventFunc = debounce(function () {
      speccer();
    }, 300);

    window.addEventListener('resize', speccerEventFunc);
    return () => {
      window.removeEventListener('resize', speccerEventFunc);
    };
  }, []);

  return <div />;
};

export default Component;

Features

Element spacing

Image of speccer

Use the following attribute to display element padding and margin:

<div data-speccer="spacing" class="..."></div>

This will display the element and all of it's children padding and margin.

Element dimensions

Image of speccer

Display dimensions with:

<div
  data-speccer="measure [height right|left] | [width top|bottom]"
  class="..."
></div>

Where height and width comes with placement flags. Default for height is left, default for width is top.

Subtle measure

Image of subtle option for measure

Use a subtle style:

<div data-speccer="measure height left subtle" class="..."></div>

This will give a dashed border.

Pin element to highlight the anatomy

Image of speccer

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.

<div data-speccer="pin-area">
  <div
    data-speccer="pin [bracket [curly] |enclose] [left|right|top|bottom]"
    class="..."
  ></div>
</div>

This will place a pin to the outline of the element. Default is top.

Align with parent container

Screenshot of the dissection/anatomy feature where the pins are aligned with the parent container

You can also align the pins to the parent container.

<div data-speccer="pin-area">
  <div data-speccer="pin parent [left|right|top|bottom]" class="..."></div>
</div>

Note

Only works with pin [left|right|top|bottom], and not with enclose, bracket or curly!

The lines from the element to the pin is drawn with a svg path and circle, so remember to add the following svg into your document:

<svg
  class="ph-speccer"
  viewBox="0 0"
  id="ph-speccer-svg"
  xmlns="http://www.w3.org/2000/svg"
>
  <path
    class="ph-speccer path original"
    id="ph-speccer-path"
    fill="none"
    stroke-width="1"
    stroke="currentColor"
  />
</svg>

Custom literals

Image of japanese literals instead of latin characters

You can use custom literals by assigned a global variable with the literals you want:

window.SPECCER_LITERALS = [
  'あ',
  'い',
  'う',
  'え',
  'お',
  'か',
  'き',
  'く',
  
];

Subtle anatomy

Image of subtle option for anatomy

You can also give a more subtle touch to the anatomy elements.

<div data-speccer="pin-area">
  <div data-speccer="pin top subtle" class="..."></div>
</div>

This will give a dashed border, and a more subtle pin style.

Curly brackets

You can use curly brackets with the curly tag in data-speccer along side pin bracket to provide a more sleek style.

Note

Only works with pin bracket

The curly brackets are made with SVG paths, and it is required to have the following snippet on your page for it to render:

<svg
  class="ph-speccer"
  viewBox="0 0"
  id="ph-speccer-svg"
  xmlns="http://www.w3.org/2000/svg"
>
  <path
    class="ph-speccer path original"
    id="ph-speccer-path"
    fill="none"
    stroke-width="1"
    stroke="currentColor"
  />
</svg>

Pin programatically

from v9.5 you can utilize the pin feature to highlight the anatomy of an element programaticaly. Here is an example with a click event.

Kazam_screencast_00002.webm

Element typography

Image of typography speccer

Display typography details:

<p data-speccer="typography [left|right|top|bottom]" class="...">Some text</p>

This will place a box to display typography information. Default is left.

Note

getComputedStyles are used to get the computed values, so for example, a line-height set to 1.5 will be presented in pixels, like 96px if the font-size is set to 64px.

Syntax highlighting for typography

If you want to produce a box that uses pre and code tags with support for syntax highlighting (PrismJS compatible), add syntax to the data-speccer="typography" attribute.

<p data-speccer="typography syntax right" class="...">Some text</p>

You can then override the colors, based on these variables:

.ph-speccer.speccer.typography.syntax {
  --ph-speccer-color-code-color-1: #737373;
  --ph-speccer-color-code-color-2: #ff3aa8;
  --ph-speccer-color-code-color-3: #38383d;
  --ph-speccer-color-code-color-4: #ff3aa8;
  --ph-speccer-color-code-color-5: #ff3aa8;
  --ph-speccer-color-code-color-6: #0074e8;
  --ph-speccer-color-code-color-7: #000000;
  --ph-speccer-color-code-color-8: #cd0404;
}

Here is an example with these colors and overrides:

.ph-speccer.speccer.typography.syntax {
  color: #8c9b9b;
  background-color: #262831;
  border-radius: 0.375rem;
  font-size: 12px;
  line-height: 1.5;
  border: none;
  --ph-speccer-color-code-color-1: #859ba3;
  --ph-speccer-color-code-color-2: #c79500;
  --ph-speccer-color-code-color-3: #2caaa0;
  --ph-speccer-color-code-color-4: #469edd;
  --ph-speccer-color-code-color-5: #8c9b9b;
  --ph-speccer-color-code-color-6: #e4e4e7;
  --ph-speccer-color-code-color-7: #262831;
  --ph-speccer-color-code-color-8: #ff6666;
}

Screenshot of typgraphy with different syntax theme

Grid spacing

Screenshot of grid feature

This will highlight the grid spacing in a display: grid; element.

In your component examples, use the following attribute on your grid container.

<div data-speccer="grid" ></div>

If you only want to display rows or columns, use this syntax (default is both with grid only):

<div data-speccer="grid [rows|columns]" ></div>

Mark elements

Screenshot of marked elements

This will mark the given elements.

In your component examples, use the following attribute.

<div data-speccer="mark" ></div>

A11y notation

With SPECCER, you can also display accessibility notation, like Accessibility Bluelines:

Prior art: Jeremy Elder

Tab stops

Screenshot of speccer a11y tab stops in use

If you want to display tab stops, append data-speccer="a11y tabstops" as an attribute to the container you want to display the tab stops in.

Landmarks and regions

Screenshot of speccer a11y landmarks in use

If you want to display landmarks and regions, append data-speccer="a11y landmark" as an attribute to the container you want to display the landmarks and regions in.

Keys and shortcut

Screenshot of speccer a11y shortcuts in use

If you want to display the shortcut with keys used for elements, use data-speccer="a11y shortcut" and data-speccer-a11y-shortcut="<shortcut>" on the element that uses this shortcut:

<button
  type="button"
  data-speccer="a11y shortcut"
  data-speccer-a11y-shortcut="ctrl + s"
>
  Save
</button>

Customization

Screenshot of speccer in a dark mode example

Allthough the styling works nicely with dark mode, you can use the provided CSS variables to customize the look and feel. If more control is needed, you can use CSS overrides :)

.ph-speccer.speccer {
  --ph-speccer-color-artificialStrawberry: #ff3aa8;
  --ph-speccer-color-venusSlipperOrchid: #db6fff;
  --ph-speccer-color-superBanana: #fff76f;
  --ph-speccer-color-white: #ffffff;
  --ph-speccer-color-carbon: #333333;
  --ph-speccer-color-red: #ff0000;
  --ph-speccer-color-niuZaiSeDenim: #0074e8;
  --ph-speccer-color-beautifulBlue: #1868b2;
  --ph-speccer-color-fuchsiaBlue: #7e60c5;
  --ph-speccer-base-color: var(--ph-speccer-color-artificialStrawberry);
  --ph-speccer-spacing-color: var(--ph-speccer-base-color);
  --ph-speccer-spacing-color-padding: rgb(
    from var(--ph-speccer-color-venusSlipperOrchid) r g b /
      var(--ph-speccer-opacity-40)
  );
  --ph-speccer-spacing-color-padding-hover: var(
    --ph-speccer-color-venusSlipperOrchid
  );
  --ph-speccer-spacing-color-margin: rgb(
    from var(--ph-speccer-color-superBanana) r g b /
      var(--ph-speccer-opacity-40)
  );
  --ph-speccer-spacing-color-margin-hover: var(--ph-speccer-color-superBanana);
  --ph-speccer-typography-background-color: var(--ph-speccer-color-white);
  --ph-speccer-typography-color-property: var(--ph-speccer-color-niuZaiSeDenim);
  --ph-speccer-typography-color-text: var(--ph-speccer-base-color);
  --ph-speccer-typography-color-value: var(--ph-speccer-base-color);
  --ph-speccer-mark-background-color: rgb(
    from var(--ph-speccer-base-color) r g b / var(--ph-speccer-opacity-20)
  );
  --ph-speccer-mark-border-color: var(--ph-speccer-base-color);
  --ph-speccer-mark-border-width: 1px;
  --ph-speccer-mark-border-style: solid;
  --ph-speccer-measure-color: var(--ph-speccer-color-red);
  --ph-speccer-measure-size: 8px;
  --ph-speccer-a11y-color-background: var(--ph-speccer-color-beautifulBlue);
  --ph-speccer-a11y-landmark-color-background: var(
    --ph-speccer-color-fuchsiaBlue
  );
  --ph-speccer-color-text-light: var(--ph-speccer-color-white);
  --ph-speccer-color-text-dark: var(--ph-speccer-color-carbon);
  --ph-speccer-pin-color: var(--ph-speccer-base-color);
  --ph-speccer-pin-size: 24px;
  --ph-speccer-pin-space: 48px;
  --ph-speccer-line-height: 12px;
  --ph-speccer-line-width: 1px;
  --ph-speccer-line-width-negative: -1px;
  --ph-speccer-opacity-20: 0.2;
  --ph-speccer-opacity-40: 0.4;
  --ph-speccer-font-family: 'Menlo for Powerline', 'Menlo Regular for Powerline',
    'DejaVu Sans Mono', Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono',
    monospace;
  --ph-speccer-font-size: 12px;
  --ph-speccer-transition-default: all 2s cubic-bezier(0.4, 0, 0.2, 1);
}

API

Full API documentation is available here.

Development

// Build
$ npm run build
// Run dev
$ npm run dev
// Test
$ npm test

Contributing

Want to contribute? Please read the CONTRIBUTING.md and CODE_OF_CONDUCT.md

License

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog

See the CHANGELOG.md for details on the latest updates.

FAQ

See the discussions for an FAQ or to ask questions if no answer is given.

Sponsor me

I'm an Open Source evangelist, creating stuff that does not exist yet to help get rid of secondary activities and to enhance systems already in place, be it documentation or web sites.

The sponsorship is an unique opportunity to alleviate more hours for me to maintain my projects, create new ones and contribute to the large community we're all part of :)

Support me on GitHub Sponsors.

Speccer banner, with logo and slogan: A zero dependency package to highlight elements

p.s. Ukraine is still under brutal Russian invasion. A lot of Ukrainian people are hurt, without shelter and need help. You can help in various ways, for instance, directly helping refugees, spreading awareness, putting pressure on your local government or companies. You can also support Ukraine by donating e.g. to Red Cross, Ukraine humanitarian organisation or donate Ambulances for Ukraine.

speccer's People

Contributors

dependabot[bot] avatar phun-ky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

bogdancerovac

speccer's Issues

O[e] is not a function

image

Uncaught (in promise) TypeError: O[e] is not a function
    T intrinsic-coords.ts:65
    N get-coords-pair-from-objects.ts:30
    s bezier.ts:166
    draw DrawSVGLine.ts:101
    connect DrawSVGLine.ts:64
    #o DrawSVGLine.ts:57
    q DrawSVGLine.ts:23
    W index.ts:119
    W index.ts:78
    st main.ts:74
    speccerEventFunc pen.js:848
    later pen.js:839
    setTimeout handler*debounce/< pen.js:843
    EventListener.handleEvent* pen.js:852
intrinsic-coords.ts:65:17

Add option to use numbers or given literals for dissection

For example, if I wanted to use numbers:

speccer({numbers: true});

This should be behind an option tbh.

Or given literals, like japanese:

window.SPECCER_LITERALS = [,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,];
speccer();

Set release note template based on old project

v14 Release Notes
=================

[Changelog](/changelog)

v14 released 10th of November, and here are the release notes, and any notable changes are described.

The release includes, but not limited to features, documentation, refactoring and bug fixes. For any questions, please contact us!

*   release
*   v14
*   documentation
*   navigation
*   refactoring

The If Design System v14 release includes new navigational structure for the documentation site, quality of life updates for designers and developers, and with low impact design changes, no redesigns are required.

### [](#overview)Overview

If Design System v14 focuses on new navigational structure for the documentation site, documentation separation, package separation and quality of life updates for designers and developers. We’ve also updated the spacing guidelines, to keep spacing more predictable.

#### [](#whats-new)What’s new

*   **Design**:
    *   We added new spacing guidelines and removed old spacing tokens
*   **Develop**:
    *   We removed the usage of `babel`. It is no longer required with [the removal of IE11 support](/blog/v13-release-notes). YMMV, you can bundle source files your self if you want support for outdated browsers
    *   Markup change in the [Info Card](/components/cards/info-card) Component, to be able to let the arrow animation on hover to be part of the content flow
    *   We eased up on the external link rules, to make it easier to manage
    *   Added CDN for [CSS (core)](/develop/frameworks/html-css#cdn), [JS (JavaScript libraries)](/develop/frameworks/javascript#cdn) and [WC (Web Components)](http://web.archive.orghttp://localhost:8000/develop/frameworks/webcomponents#cdn) packages
*   **Documentation site**:
    *   We did some layout adjustments for the documentation site, for a more clean look
    *   Improved the search for the documentation
    *   Separated out the CSS/JS/WC documentation in a separate page per component. The first page of a component is the design guidelines page
    *   New navigational structure for the documentation site. [](http://web.archive.org/). This makes it easier to navigate to exactly what you want
    *   Improved the [Component Status](/resources/status) page on documentation site
*   **Components**:
    *   [Navigational Cards](/components/cards/navigational-card) of type `text` now has a visual icon instead of arrow for download links and external links
    *   Adjusted the [Consent Banner](/components/feedback/consent-banner) component, we made it less obtrusive
    *   We renamed the `util`\-package to `utils` for all frameworks. See [Utils CSS documentation](/components/utils/css) and [Utils JavaScript documentation](/components/utils/js)
*   **Internal**
    
    *   Renamed the `if-design-system`\-repository to `ids-core`, to better reflect what it is
    *   Changed the `@if-design-system`\-scope to `@ids-core`
    *   Renamed `if-design-components-javascript`\-repository to `ids-js`
    *   Changed the `@if-design-components-javascript`\-scope to `@ids-js`
        *   Moved the JavaScript libraries under the `@if-design-system`\-scope to the `@ids-js`\-scope
        *   Extracted the JavaScript implementation examples to separated, _supported_ packages under the `@ids-js`\-scope
    *   Added `ids-wc`\-repository for our Web Components
        *   Moved the Web Components under the `@if-design-system`\-scope to the `@ids-wc`\-scope
    
    *   Removed old icon category `Social` from the Nucleo JSON file, it has been replaced by `SoMe`
    *   Converted and renamed remaining design tokens that used Theo to build them. We are now using Style Dictionary everywhere
    *   Upgraded to GatsbyJS v4.0.1

#### [](#whats-not-changing)What’s not changing

*   All components are as is, except from [Info Card](/components/cards/info-card) and [Navigational Card](/components/cards/navigational-card)

### [](#release-faqs)Release FAQs

#### [](#what-are-the-benefits-of-if-design-system-v14-for-me-as-a-designer)What are the benefits of If Design System v14 for me as a designer?

*   Better control over spacing, with the new spacing guidelines

#### [](#what-are-the-benefits-of-if-design-system-v14-for-me-as-a-developer)What are the benefits of If Design System v14 for me as a developer?

*   Quality of life updates such as:
    *   JavaScript library packages in separate scope, and is now fully supported
    *   Web Component packages in separate scope, and is now fully supported

#### [](#what-are-the-benefits-to-my-external-facing-users)What are the benefits to my external facing users?

*   The [Consent Banner](/components/feedback/consent-banner) is less obtrusive

#### [](#do-i-need-to-update-right-away-if-not-when-will-we-need-to-update)Do I need to update right away? If not, when will we need to update?

*   If Design System v14 includes functionality that may be a motivator for migration, but teams can migrate to v14 when they have the bandwidth
*   Teams that are using v13 today can continue to stay on v13 and everything that is implemented will continue to work

#### [](#what-will-the-if-design-system-team-be-supporting-for-v13)What will the If Design System team be supporting for v13?

*   No new functionality will be introduced in v13 after the v14 release
*   We will continue to address high impact bugs that come up for the v13 release after the v14 release
*   We will continue to accept any contributions that look to address issues in the v13 release if we are unable to get to them in time for your sprint

#### [](#what-is-the-rule-for-supporting-deprecated-assets)What is the rule for supporting deprecated assets?

*   Assets that were deprecated from v12 to v13 will be removed in v14
*   Assets that are deprecated in v13 will remain in v14 and will be removed in v15. While the timeline of v15 has not been set, the team’s intent is for major versions to be at minimum 3 months apart

#### [](#will-i-need-to-redesign-something)Will I need to redesign something?

*   No, we added new spacing guidelines, and they can be adapted into your designs for your upcoming work

#### [](#how-big-is-the-expected-effort-to-migrate-code-to-v14)How big is the expected effort to migrate code to v14?

*   The If Design System team is providing an guide to help with the migration process
*   A lot of the changes made will be name-based
*   The separation of JavaScript and Web Components requires the install of new packages
``

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.