탐색

v2.1.0
본문

공동 작업자 커서

다른 사람의 포인터, 캐럿, 선택 영역을 그 사람을 나타내는 색으로 표시합니다.

이 페이지의 내용

공동 작업자 커서는 같은 대상에서 함께 작업하는 다른 사람들이 어디에 있는지 보여 줍니다. 캔버스나 보드에서는 포인터를, 텍스트에서는 캐럿과 선택 영역을 표시합니다. 각 사람은 하나의 식별 색으로 그려지고 그 옆에 이름이 표시되므로, 사용자는 누가 어디에 있는지 한눈에 알 수 있습니다. 포인터가 움직이는 위치 지정 요소 안에서, presence-name을 담은 요소에 presence와 그 사람의 식별 색을 지정하는 수정자(presence-1~presence-8 중 하나)를 추가하고, --presence-x와 --presence-y로 위치를 설정하세요.

공동 작업자 커서

<div class="sheet relative overflow-hidden w-full max-w(520) h(264)" id="board">  <div class="texture texture-grid absolute inset(0)"></div>  <div class="sheet sheet-raised absolute p-md text-sm w(168)" style="top: 32px; left: 28px">    <p class="m(0) fg-text-strong">Launch checklist</p>    <p class="m(0) mt-xs fg-text-muted">Docs, changelog and the post</p>  </div>  <div class="sheet sheet-raised absolute p-md text-sm w(168)" style="top: 128px; left: 260px">    <p class="m(0) fg-text-strong">Open questions</p>    <p class="m(0) mt-xs fg-text-muted">Who writes the release notes?</p>  </div>  <div class="presence presence-6" style="--presence-x: 150px; --presence-y: 78px" aria-hidden="true">    <span class="presence-name">Ada Lovelace</span>  </div>  <div class="presence presence-4" id="moving" style="--presence-x: 340px; --presence-y: 40px" aria-hidden="true">    <span class="presence-name">Alan Turing</span>  </div>  <div class="presence presence-8" style="--presence-x: 96px; --presence-y: 176px" aria-hidden="true">    <span class="presence-name">Grace Hopper</span>    <span class="presence-message">I can take the release notes</span>  </div></div><script>const pointer = document.getElementById('moving')const path = [[340, 40], [372, 64], [398, 108], [360, 150], [318, 132], [300, 84]]let at = 0setInterval(() => {  at = (at + 1) % path.length  pointer.style.setProperty('--presence-x', path[at][0] + 'px')  pointer.style.setProperty('--presence-y', path[at][1] + 'px')}, 700)</script>
보드 위의 세 사람입니다. Alan의 포인터는 애플리케이션이 알려 주는 대로 움직이며, 주어진 지점 사이를 부드럽게 이동합니다. 동작 줄이기 설정이 켜져 있으면 바로 건너뜁니다.

#포인터의 위치

좌표가 가리키는 지점은 포인터의 뾰족한 끝입니다. --presence-x와 --presence-y는 가장 가까운 위치 지정 요소(대개 캔버스나 보드)의 왼쪽 위 모서리로부터의 거리를 픽셀 단위로 나타냅니다. 이 요소에는 relative와 overflow-hidden을 적용해, 가장자리 근처의 포인터가 그 경계에서 잘리도록 합니다. 각 사람이 어디에 있는지, 언제 떠나는지는 애플리케이션이 알고 있습니다. 누군가 들어오면 presence를 추가하고, 포인터가 움직이면 두 속성을 설정하며, 떠나면 제거합니다. 그리기와 움직임은 스타일시트가 처리하며, 자체 스크립트는 없습니다.

app.js
function move(person, x, y) {  const pointer = board.querySelector(`[data-person="${person.id}"]`)  pointer.style.setProperty('--presence-x', `${x}px`)  pointer.style.setProperty('--presence-y', `${y}px`)}
  • 움직임. 포인터는 새 지점마다 160ms 동안 직선으로 부드럽게 이동하므로, 연결을 통해 초당 몇 번 전달되는 위치가 끊김 없는 움직임으로 바뀝니다. prefers-reduced-motion: reduce에서는 바로 건너뜁니다.
  • 방해하지 않기. 포인터는 포인터 이벤트를 받지 않으므로, 사용자 자신의 포인터와 그 아래 요소 사이를 가로막지 않습니다.
  • 좌표. 좌표는 캔버스 자체의 단위로 전송하고, 속성을 설정하기 전에 사용자의 화면 기준으로 변환하세요. 그래야 창 크기와 확대 배율이 다른 두 사람이 같은 대상을 가리킵니다.

#메시지

이름 아래의 presence-message에는 커서 채팅처럼 그 사람이 작성 중인 짧은 문구를 담습니다. 가리키고 있는 대상에 관한 질문 같은 것입니다. 메시지는 15rem에서 줄바꿈됩니다. 작성을 멈추고 몇 초가 지나면 제거하세요.

#식별 색

Master UI에서 색상(hue)은 상태를 나타내며, 여기서는 사람을 나타냅니다. 테마에는 --color-identity-1부터 --color-identity-8까지 모두 같은 명도인 여덟 가지 식별 색이 있습니다. 한 사람은 세션 동안 그중 하나를 유지하며, 그 옆에는 항상 이름이 표시되므로 색이 사람을 구별하는 유일한 수단이 되는 일은 없습니다. --color-identity-ink는 모든 식별 색 위에 놓이는 텍스트 색으로, 밝은 색 구성에서는 최소 4.8:1, 어두운 색 구성에서는 최소 9:1의 대비를 가집니다.

포인터, 캐럿, 선택 영역, 단독으로 쓰이는 이름에 presence-1~presence-8 수정자를 사용해 색을 고르세요. 사람을 나타내는 자체 색이 있는 제품이라면 그 대신 --presence-color를 설정하세요. 이때 --color-identity-ink가 읽히는 명도의 색을 지정하거나, 그 토큰도 함께 설정하세요.

식별 색

<span class="presence-name presence-1">Ada</span><span class="presence-name presence-2">Alan</span><span class="presence-name presence-3">Grace</span><span class="presence-name presence-4">Edsger</span><span class="presence-name presence-5">Barbara</span><span class="presence-name presence-6">Donald</span><span class="presence-name presence-7">Margaret</span><span class="presence-name presence-8">Ken</span>
<>  <span className="presence-name presence-1">Ada</span>  <span className="presence-name presence-2">Alan</span>  <span className="presence-name presence-3">Grace</span>  <span className="presence-name presence-4">Edsger</span>  <span className="presence-name presence-5">Barbara</span>  <span className="presence-name presence-6">Donald</span>  <span className="presence-name presence-7">Margaret</span>  <span className="presence-name presence-8">Ken</span></>
<span class="presence-name presence-1">Ada</span><span class="presence-name presence-2">Alan</span><span class="presence-name presence-3">Grace</span><span class="presence-name presence-4">Edsger</span><span class="presence-name presence-5">Barbara</span><span class="presence-name presence-6">Donald</span><span class="presence-name presence-7">Margaret</span><span class="presence-name presence-8">Ken</span>
<template>  <span class="presence-name presence-1">Ada</span>  <span class="presence-name presence-2">Alan</span>  <span class="presence-name presence-3">Grace</span>  <span class="presence-name presence-4">Edsger</span>  <span class="presence-name presence-5">Barbara</span>  <span class="presence-name presence-6">Donald</span>  <span class="presence-name presence-7">Margaret</span>  <span class="presence-name presence-8">Ken</span></template>
세션이 배정하는 순서대로 나열한 여덟 가지 식별 색입니다.

사람들이 들어오는 순서대로 이 순서에 따라 색을 배정하고, 떠난 사람의 색은 다음에 들어오는 사람에게 주세요. 모든 사용자가 같은 사람을 같은 색으로 보아야 한다면 사람의 id 해시처럼 변하지 않는 숫자로 색을 고르세요. 여덟 명을 넘으면 색이 반복되지만, 이름으로 여전히 구별할 수 있습니다.

#텍스트에서

함께 편집하는 문서에서 다른 사람의 캐럿은 두 글자 사이에 놓이는 presence-caret입니다. 그 사람의 색으로 된 2px 막대로 줄 높이만큼 길며, 그 위에 이름이 적힌 깃발이 섭니다. 공간을 차지하지 않으므로 캐럿이 움직여도 주변 단어는 움직이지 않습니다. 그 사람의 선택 영역은 선택한 단어를 감싸는 presence-selection으로, 단어 뒤에 그 사람의 색을 옅게 깔며 여러 줄에 걸쳐 이어집니다.

캐럿과 선택 영역

<div class="sheet p-lg max-w(440)">  <p class="m(0) text-sm fg-text-body leading-md">    The release ships <span class="presence-selection presence-4">on Thursday, after the docs build</span><span class="presence-caret presence-4" aria-hidden="true">      <span class="presence-name">Alan</span>    </span> passes, and the post goes out the same afternoon. Ada writes the changelog<span class="presence-caret presence-6" aria-hidden="true">      <span class="presence-name">Ada</span>    </span> while Grace checks the links.  </p></div>
<div className="sheet p-lg max-w(440)">  <p className="m(0) text-sm fg-text-body leading-md">    The release ships <span className="presence-selection presence-4">on Thursday, after the docs build</span><span className="presence-caret presence-4" aria-hidden="true">      <span className="presence-name">Alan</span>    </span> passes, and the post goes out the same afternoon. Ada writes the changelog<span className="presence-caret presence-6" aria-hidden="true">      <span className="presence-name">Ada</span>    </span> while Grace checks the links.  </p></div>
<div class="sheet p-lg max-w(440)">  <p class="m(0) text-sm fg-text-body leading-md">    The release ships <span class="presence-selection presence-4">on Thursday, after the docs build</span><span class="presence-caret presence-4" aria-hidden="true">      <span class="presence-name">Alan</span>    </span> passes, and the post goes out the same afternoon. Ada writes the changelog<span class="presence-caret presence-6" aria-hidden="true">      <span class="presence-name">Ada</span>    </span> while Grace checks the links.  </p></div>
<template>  <div class="sheet p-lg max-w(440)">    <p class="m(0) text-sm fg-text-body leading-md">      The release ships <span class="presence-selection presence-4">on Thursday, after the docs build</span><span class="presence-caret presence-4" aria-hidden="true">        <span class="presence-name">Alan</span>      </span> passes, and the post goes out the same afternoon. Ada writes the changelog<span class="presence-caret presence-6" aria-hidden="true">        <span class="presence-name">Ada</span>      </span> while Grace checks the links.    </p>  </div></template>
Alan이 선택한 구절의 끝에 Alan의 캐럿이 있고, Ada의 캐럿은 Ada가 입력 중인 위치에 있습니다.

편집기는 공동 작업 계층이 알려 주는 다른 사람들의 위치에 이 표시들을 둡니다. 이 표시들은 편집기가 렌더링하고 제거하는 장식이며, 문서의 일부가 아닙니다. 첫 줄 위에 이름 깃발이 들어갈 공간을 남기거나, 첫 줄에 있는 캐럿의 깃발이 텍스트를 담은 요소의 안쪽 여백까지 올라가도록 두세요.

#다른 컴포넌트를 써야 할 때

  • 어디에 있는지가 아니라 누가 있는지를 보여 주려면 헤더에 아바타를 겹쳐 표시하세요.
  • 애플리케이션이 아직 작성 중인 텍스트 끝의 표시는 캐럿입니다.
  • 검색 일치 항목처럼 사용자를 위해 강조한 단어는 강조 표시입니다.

#접근성

  • 포인터와 캐럿은 장식입니다. 캔버스나 문장 중간에 이름이 읽히지 않도록 각각에 aria-hidden="true"를 설정하세요. 누가 있는지는 헤더에 이름과 함께 표시한 아바타처럼 다른 곳에서 문구로 알리고, 들어오고 나가는 것이 작업에 중요하다면 polite 라이브 영역에서 안내하세요.
  • 선택 영역은 숨기지 않습니다. 그 안의 단어는 문서의 내용입니다. 옅게 깐 색은 단어의 색을 바꾸지 않으므로 단어의 대비가 유지됩니다.
  • 색이 유일한 단서가 되는 일은 없습니다. 모든 포인터와 캐럿 옆에 이름이 표시됩니다.
  • 강제 색상 모드에서는 화살표와 캐럿을 시스템 색으로 그리고, 깃발과 말풍선에 윤곽선을 추가합니다.

#클래스

클래스설명
presence포인터입니다. 화살표 끝이 이 요소를 담은 위치 지정 요소 안에서 --presence-x와 --presence-y 위치에 놓이며, 그 사람의 식별 색으로 그립니다. 새 위치로 부드럽게 이동하고 포인터 이벤트를 받지 않습니다.
presence-name그 사람의 이름으로, 해당 색의 깃발 모양에 식별 색용 글자색으로 표시합니다. 화살표 끝 옆이나 캐럿 위에 놓이거나, 참여자 목록에서 단독으로 쓰입니다.
presence-message그 사람이 작성 중인 짧은 메시지로, 이름 아래에 그 사람의 색으로 된 말풍선으로 표시합니다.
presence-caret텍스트 속 다른 사람의 캐럿입니다. 줄 높이만큼의 인라인 막대를 그 사람의 식별 색으로 그리며 공간을 차지하지 않습니다. 안에 presence-name을 넣으면 캐럿 위에 놓입니다.
presence-selection다른 사람의 선택 영역입니다. 선택한 단어 뒤에 그 사람의 식별 색을 옅게 깔며, 여러 줄에 걸쳐 이어집니다.
presence-1식별 색 1, --color-identity-1: 빨간색 계열입니다. 수정자나 --presence-color가 없으면 이 색을 사용합니다.적용할 클래스는 presence 또는 presence-caret 또는 presence-selection 또는 presence-name입니다
presence-2식별 색 2, --color-identity-2: 주황색 계열적용할 클래스는 presence 또는 presence-caret 또는 presence-selection 또는 presence-name입니다
presence-3식별 색 3, --color-identity-3: 호박색 계열적용할 클래스는 presence 또는 presence-caret 또는 presence-selection 또는 presence-name입니다
presence-4식별 색 4, --color-identity-4: 초록색 계열적용할 클래스는 presence 또는 presence-caret 또는 presence-selection 또는 presence-name입니다
presence-5식별 색 5, --color-identity-5: 청록색 계열적용할 클래스는 presence 또는 presence-caret 또는 presence-selection 또는 presence-name입니다
presence-6식별 색 6, --color-identity-6: 파란색 계열적용할 클래스는 presence 또는 presence-caret 또는 presence-selection 또는 presence-name입니다
presence-7식별 색 7, --color-identity-7: 보라색 계열적용할 클래스는 presence 또는 presence-caret 또는 presence-selection 또는 presence-name입니다
presence-8식별 색 8, --color-identity-8: 분홍색 계열적용할 클래스는 presence 또는 presence-caret 또는 presence-selection 또는 presence-name입니다

#사용자 지정 속성

속성기본값설명
--presence-colorvar(--color-identity-1)그 사람의 색입니다. presence-1부터 presence-8까지의 수정자가 식별 색으로 설정하며, 제품 고유의 색을 쓰려면 직접 설정하세요. presence, presence-caret, presence-selection, presence-name이 이 값을 읽습니다.
--presence-x0px이 요소를 담은 위치 지정 요소의 왼쪽 가장자리로부터 화살표 끝까지의 거리입니다. 애플리케이션이 설정합니다.
--presence-y0px해당 요소의 위쪽 가장자리로부터 화살표 끝까지의 거리입니다. 애플리케이션이 설정합니다.
--presence-arrow1.25rem화살표의 크기입니다. 이름은 화살표 끝 옆에 놓입니다.

#소스

@master/ui/components/presence.css
/* * Presence: where another person is, drawn in the color that names them. * A pointer is an arrow standing at the point the page gives it, with the person's name in a flag down and to * the side of its tip and, when they write one, a short message in a bubble under the name. In text, another * person's caret is a 2px bar in the line with their name above it, and their selection is a tint of their color * behind the words. * The color is the person's identity: one of --color-identity-1 to 8, chosen with presence-1 to presence-8, * or any color set as --presence-color. Every identity takes --color-identity-ink as its text. Hue means a * person here and nothing else. * Geometry: a 20px arrow whose tip is the point, cut out of the page by a ring of the identity ink so it reads * on any content; a 12px name in a flag with the chip's corner; a 13px message in a bubble with the control's * corner, at most 15rem wide. The flag and the bubble stand on the page with the raised shadow. * Coordinates and presence are the application's: it sets --presence-x and --presence-y, in pixels from the * top-left corner of the positioned element that holds the pointers, and adds and removes the elements. A * pointer glides to each new point and jumps under reduced motion. Nothing here takes a pointer event, so a * pointer never stands in the way of the reader's own. */@layer components.ui {  .presence {    --presence-color: var(--color-identity-1);    --presence-x: 0px;    --presence-y: 0px;    --presence-arrow: 1.25rem;    position: absolute;    top: 0;    left: 0;    z-index: 1;    display: flex;    flex-direction: column;    align-items: flex-start;    gap: .25rem;    width: max-content;    max-width: 15rem;    /* The flag starts under the arrow's tail, beside its point. */    padding: calc(var(--presence-arrow) * .85) 0 0 calc(var(--presence-arrow) * .6);    translate: var(--presence-x) var(--presence-y);    pointer-events: none;    transition-property: translate;    transition-duration: var(--duration-quick);    transition-timing-function: linear;    /* The point is placed from the left whatever the direction, so right to left the flag still starts beside it. */    &:dir(rtl) {      align-items: flex-end;    }    /*     * The arrow: a ring of the identity ink under a face of the identity color. Its tip, 2 of its 20 units in     * from the corner, is the point.     */    &::before, &::after {      content: '';      position: absolute;      top: calc(var(--presence-arrow) * -.1);      left: calc(var(--presence-arrow) * -.1);      width: var(--presence-arrow);      height: var(--presence-arrow);    }    &::before {      background: var(--color-identity-ink);      mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M2 2 18 8.6 10.6 10.6 8.6 18Z' fill='black' stroke='black' stroke-width='3.5' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;    }    &::after {      background: var(--presence-color, var(--color-identity-1));      mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M2 2 18 8.6 10.6 10.6 8.6 18Z' fill='black' stroke='black' stroke-width='1' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;    }    @media (prefers-reduced-motion: reduce) {      transition-duration: 0s;    }    @media (forced-colors: active) {      &::before, &::after {        forced-color-adjust: none;      }      &::before {        background: Canvas;      }      &::after {        background: CanvasText;      }    }  }  /* The person's name, in a flag of their color. */  .presence-name {    max-width: 100%;    margin: 0;    padding: .125rem .375rem;    overflow: hidden;    border-radius: calc(var(--radius-chip) * var(--corner-scale));    corner-shape: var(--corner-shape);    background: var(--presence-color, var(--color-identity-1));    color: var(--color-identity-ink);    box-shadow: 0 0 0 .5px var(--color-line-on-color), 0 1px 2px -1px var(--color-shade-1), 0 2px 4px -2px var(--color-shade-2), 0 4px 8px -4px var(--color-shade-3);    font: var(--font-weight-control) .75rem/1.35 var(--font-family-sans);    font-feature-settings: inherit;    letter-spacing: 0;    text-overflow: ellipsis;    white-space: nowrap;    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;    }  }  /* What the person is saying, in a bubble under the name: a few words, as cursor chat has them. */  .presence-message {    max-width: 100%;    margin: 0;    padding: .375rem .625rem;    border-radius: calc(var(--radius-control) * var(--corner-scale));    corner-shape: var(--corner-shape);    background: var(--presence-color, var(--color-identity-1));    color: var(--color-identity-ink);    box-shadow: 0 0 0 .5px var(--color-line-on-color), 0 1px 2px -1px var(--color-shade-1), 0 2px 4px -2px var(--color-shade-2), 0 4px 8px -4px var(--color-shade-3);    font: 400 .8125rem/1.4 var(--font-family-sans);    font-feature-settings: inherit;    text-wrap: pretty;    overflow-wrap: anywhere;    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;    }  }  /*   * Another person's caret in text: an inline mark between two letters, a bar as tall as the line of letters,   * with the name in a flag that stands on it. It takes no room in the line.   */  .presence-caret {    --presence-color: var(--color-identity-1);    position: relative;    display: inline-block;    width: 2px;    height: 1.2em;    margin-inline: -1px;    border-radius: 999px;    corner-shape: round;    background: var(--presence-color, var(--color-identity-1));    vertical-align: -.2em;    pointer-events: none;    .presence-name {      position: absolute;      bottom: 100%;      inset-inline-start: 0;      max-width: 12rem;      padding: 0 .3125rem;      border-end-start-radius: 0;      font-size: .6875rem;      line-height: 1.45;    }    /*     * The bar keeps the system's highlight. forced-color-adjust is inherited, so the name on it is handed back     * to forced colors and drawn as a name standing alone is.     */    @media (forced-colors: active) {      forced-color-adjust: none;      background: Highlight;      .presence-name {        forced-color-adjust: auto;      }    }  }  /*   * The eight identities, by class: presence-1 to presence-8 on a pointer, a caret, a selection or a name   * that stands alone. Naming each token here also keeps it in a stylesheet compiled for the classes a page   * uses. --presence-color takes any other color a product gives a person.   */  :is(.presence, .presence-caret, .presence-selection, .presence-name) {    &.presence-1 {      --presence-color: var(--color-identity-1);    }    &.presence-2 {      --presence-color: var(--color-identity-2);    }    &.presence-3 {      --presence-color: var(--color-identity-3);    }    &.presence-4 {      --presence-color: var(--color-identity-4);    }    &.presence-5 {      --presence-color: var(--color-identity-5);    }    &.presence-6 {      --presence-color: var(--color-identity-6);    }    &.presence-7 {      --presence-color: var(--color-identity-7);    }    &.presence-8 {      --presence-color: var(--color-identity-8);    }  }  /* Another person's selection: a tint of their color behind the words, carried across lines. */  .presence-selection {    --presence-color: var(--color-identity-1);    padding-block: .1em;    border-radius: calc(2px * var(--corner-scale));    corner-shape: var(--corner-shape);    background: color-mix(in oklab, var(--presence-color) 24%, transparent);    color: inherit;    box-decoration-break: clone;    -webkit-box-decoration-break: clone;    @media (forced-colors: active) {      outline: 1px dotted CanvasText;    }  }}