summaryrefslogtreecommitdiff
path: root/website/.vitepress/theme/components/CompatibilityMatrix.vue
blob: 0e821d072bbbe8bc36c9f70f65dcaff534c7e56e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
<script setup lang="ts">
import { computed } from 'vue';
import { useData } from 'vitepress';
import {
  useCompatibilityData,
  checkCompatibility,
  formatProtocol,
  olderSide,
  type PlatformReleaseEntry,
} from './useCompatibilityData';

const { lang } = useData();
const isEn = computed(() => lang.value === 'en-US');
const { data, loading, error } = useCompatibilityData();

const t = computed(() =>
  isEn.value
    ? {
        loading: 'Loading compatibility data...',
        error: 'Failed to load compatibility data. Please check ',
        errorSuffix: ' directly.',
        emptyPaper: 'No Paper releases yet.',
        emptyVelocity: 'No Velocity releases yet.',
        empty: 'No releases yet. Compatibility matrix will appear once releases are published.',
        paperVersion: 'Paper version',
        velocityVersion: 'Velocity version',
        protocol: 'Protocol',
        unknown: 'unknown',
        compatible: 'Compatible',
        degraded: 'Connects with some features unavailable',
        incompatible: 'Incompatible',
        compatibleShort: 'OK',
        compatibilityHeader: 'Compatibility',
        reasonMajorMismatch: 'Major version mismatch',
        reasonPaperTooNew: 'Paper protocol newer than Velocity — update Velocity first',
        reasonPaperTooOld: 'Paper protocol older than Velocity accepts',
        reasonPaperBehind:
          'Connects, but Paper speaks an older protocol — features the newer Velocity adds are unavailable',
        reasonVelocityBehind:
          'Connects, but Velocity speaks an older protocol — features the newer Paper adds are unavailable',
        legend: 'Legend',
        legendCompatible: 'Fully compatible — every feature is available.',
        legendDegraded:
          'Connects — but features added on the newer side are unavailable.',
        legendIncompatible: 'Incompatible — handshake will be rejected.',
      }
    : {
        loading: '互換性情報を取得中...',
        error: '互換性情報の取得に失敗しました.',
        errorSuffix: ' を直接ご確認ください.',
        emptyPaper: 'Paper のリリースはまだありません.',
        emptyVelocity: 'Velocity のリリースはまだありません.',
        empty: 'リリースがまだありません.リリース後に互換性マトリクスが表示されます.',
        paperVersion: 'Paper バージョン',
        velocityVersion: 'Velocity バージョン',
        protocol: 'プロトコル',
        unknown: '不明',
        compatible: '完全互換',
        degraded: '接続可能だが一部機能が利用不可',
        incompatible: '非互換',
        compatibleShort: 'OK',
        compatibilityHeader: '互換性',
        reasonMajorMismatch: 'MAJOR バージョン不一致',
        reasonPaperTooNew: 'Paper のプロトコルが Velocity より新しい — Velocity を先に更新',
        reasonPaperTooOld: 'Paper のプロトコルが Velocity の許容範囲より古い',
        reasonPaperBehind:
          '接続可能.ただし Paper のプロトコルが古いため,新しい Velocity が追加した一部機能が利用できません',
        reasonVelocityBehind:
          '接続可能.ただし Velocity のプロトコルが古いため,新しい Paper が追加した一部機能が利用できません',
        legend: '凡例',
        legendCompatible: '完全互換 — 全機能が利用可能.',
        legendDegraded: '接続可能 — 新しい側が追加した一部機能が利用できません.',
        legendIncompatible: '非互換 — ハンドシェイクで拒否されます.',
      },
);

const sortedPaper = computed<PlatformReleaseEntry[]>(() =>
  [...data.value.paper].sort((a, b) => compareVersion(b.version, a.version)),
);
const sortedVelocity = computed<PlatformReleaseEntry[]>(() =>
  [...data.value.velocity].sort((a, b) => compareVersion(b.version, a.version)),
);

function compareVersion(a: string, b: string): number {
  const pa = a.split('.').map((n) => Number.parseInt(n, 10));
  const pb = b.split('.').map((n) => Number.parseInt(n, 10));
  for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
    const da = pa[i] ?? 0;
    const db = pb[i] ?? 0;
    if (da !== db) return da - db;
  }
  return 0;
}

type CellState = 'ok' | 'warn' | 'ng';

const MARK: Record<CellState, string> = { ok: '✓', warn: '⚠', ng: '✗' };

interface Cell {
  key: string;
  state: CellState;
  mark: string;
  label: string;
  reason: string;
}

function cell(paper: PlatformReleaseEntry, velocity: PlatformReleaseEntry): Cell {
  const base = { key: velocity.tag };

  if (!paper.protocol || !velocity.protocol) {
    return { ...base, state: 'ng', mark: MARK.ng, label: t.value.incompatible, reason: t.value.unknown };
  }

  const result = checkCompatibility(paper.protocol, velocity.protocol);
  switch (result) {
    case 'compatible':
      return { ...base, state: 'ok', mark: MARK.ok, label: t.value.compatible, reason: t.value.legendCompatible };
    case 'degraded':
      return {
        ...base,
        state: 'warn',
        mark: MARK.warn,
        label: t.value.degraded,
        reason:
          olderSide(paper.protocol, velocity.protocol) === 'paper'
            ? t.value.reasonPaperBehind
            : t.value.reasonVelocityBehind,
      };
    case 'major-mismatch':
      return { ...base, state: 'ng', mark: MARK.ng, label: t.value.incompatible, reason: t.value.reasonMajorMismatch };
    case 'paper-too-new':
      return { ...base, state: 'ng', mark: MARK.ng, label: t.value.incompatible, reason: t.value.reasonPaperTooNew };
    case 'paper-too-old':
      return { ...base, state: 'ng', mark: MARK.ng, label: t.value.incompatible, reason: t.value.reasonPaperTooOld };
  }
}

const rows = computed(() =>
  sortedPaper.value.map((paper) => ({
    paper,
    cells: sortedVelocity.value.map((velocity) => cell(paper, velocity)),
  })),
);
</script>

<template>
  <div class="compat-matrix">
    <div v-if="loading" class="compat-loading">
      <p>{{ t.loading }}</p>
    </div>

    <div v-else-if="error" class="compat-error">
      <p>
        {{ t.error
        }}<a href="https://github.com/m1sk9/LunaticChat/releases" target="_blank" rel="noopener">GitHub Releases</a>{{ t.errorSuffix }}
      </p>
    </div>

    <div v-else-if="sortedPaper.length === 0 && sortedVelocity.length === 0" class="compat-empty">
      <p>{{ t.empty }}</p>
    </div>

    <div v-else class="compat-content">
      <div class="compat-table-wrapper">
        <table class="compat-table">
          <thead>
            <tr>
              <th class="compat-corner">
                <span class="compat-axis-paper">{{ t.paperVersion }}</span>
                <span class="compat-axis-divider">/</span>
                <span class="compat-axis-velocity">{{ t.velocityVersion }}</span>
              </th>
              <th v-for="v in sortedVelocity" :key="v.tag" class="compat-col-header">
                <div class="compat-version">v{{ v.version }}</div>
                <div class="compat-protocol">
                  {{ t.protocol }}: {{ v.protocol ? formatProtocol(v.protocol) : t.unknown }}
                </div>
              </th>
            </tr>
          </thead>
          <tbody>
            <tr v-if="sortedPaper.length === 0">
              <td colspan="100" class="compat-empty-cell">{{ t.emptyPaper }}</td>
            </tr>
            <tr v-for="row in rows" :key="row.paper.tag">
              <th scope="row" class="compat-row-header">
                <div class="compat-version">v{{ row.paper.version }}</div>
                <div class="compat-protocol">
                  {{ t.protocol }}: {{ row.paper.protocol ? formatProtocol(row.paper.protocol) : t.unknown }}
                </div>
              </th>
              <td
                v-for="c in row.cells"
                :key="c.key"
                :class="['compat-cell', `compat-${c.state}`]"
                :title="c.reason"
              >
                <span :class="`compat-mark-${c.state}`" :aria-label="c.label">{{ c.mark }}</span>
              </td>
              <td v-if="sortedVelocity.length === 0" class="compat-empty-cell">{{ t.emptyVelocity }}</td>
            </tr>
          </tbody>
        </table>
      </div>

      <div class="compat-legend">
        <p class="compat-legend-title">{{ t.legend }}</p>
        <ul>
          <li><span class="compat-mark-ok">✓</span> {{ t.legendCompatible }}</li>
          <li><span class="compat-mark-warn">⚠</span> {{ t.legendDegraded }}</li>
          <li><span class="compat-mark-ng">✗</span> {{ t.legendIncompatible }}</li>
        </ul>
      </div>
    </div>
  </div>
</template>

<style scoped>
.compat-matrix {
  margin: 24px 0;
}

.compat-loading,
.compat-empty {
  text-align: center;
  padding: 32px 0;
  color: var(--vp-c-text-2);
}

.compat-error {
  border: 1px solid var(--vp-c-danger-soft);
  background: var(--vp-c-danger-soft);
  border-radius: 8px;
  padding: 16px 20px;
}

.compat-error a {
  color: var(--vp-c-brand-1);
  text-decoration: underline;
}

.compat-table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--vp-c-divider);
  border-radius: 8px;
}

.compat-table {
  border-collapse: collapse;
  width: auto;
  margin: 0;
  font-size: 0.875rem;
}

.compat-table th,
.compat-table td {
  border: 1px solid var(--vp-c-divider);
  padding: 8px 12px;
  text-align: center;
  vertical-align: middle;
}

.compat-corner {
  background: var(--vp-c-bg-soft);
  font-weight: 500;
  font-size: 0.75rem;
  white-space: nowrap;
  text-align: left !important;
}

.compat-axis-paper,
.compat-axis-velocity {
  display: inline-block;
}

.compat-axis-divider {
  margin: 0 4px;
  color: var(--vp-c-text-3);
}

.compat-col-header,
.compat-row-header {
  background: var(--vp-c-bg-soft);
  font-weight: 600;
  white-space: nowrap;
}

.compat-col-header {
  min-width: 110px;
}

.compat-version {
  font-size: 0.95rem;
}

.compat-protocol {
  font-size: 0.7rem;
  color: var(--vp-c-text-2);
  font-weight: 400;
  margin-top: 2px;
}

.compat-cell {
  min-width: 110px;
  font-size: 1.1rem;
  font-weight: 700;
}

.compat-ok {
  background: rgba(20, 200, 100, 0.08);
}

.compat-warn {
  background: rgba(230, 160, 30, 0.1);
}

.compat-ng {
  background: rgba(220, 60, 60, 0.06);
}

.compat-mark-ok {
  color: rgb(20, 160, 90);
}

.compat-mark-warn {
  color: rgb(176, 122, 10);
}

.compat-mark-ng {
  color: rgb(200, 60, 60);
}

/* Amber has to lift off a dark background to stay legible, where the green and
   red marks read well enough unchanged. */
:global(.dark) .compat-mark-warn {
  color: rgb(232, 179, 63);
}

.compat-empty-cell {
  color: var(--vp-c-text-3);
  font-style: italic;
}

.compat-legend {
  margin-top: 16px;
  font-size: 0.85rem;
  color: var(--vp-c-text-2);
}

.compat-legend-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.compat-legend ul {
  margin: 0;
  padding-left: 20px;
}

.compat-legend li {
  line-height: 1.7;
}
</style>