-
+
+
+
+
@@ -18,4 +20,12 @@ function onSizeChange(event: Event) {
const n = Number((event.target as HTMLSelectElement).value) as CubeSize
store.setSize(n)
}
+
+function decrement(): void {
+ if (store.size > 2) store.setSize((store.size - 1) as CubeSize)
+}
+
+function increment(): void {
+ if (store.size < 7) store.setSize((store.size + 1) as CubeSize)
+}
diff --git a/src/components/SpecialViewControl.vue b/src/components/SpecialViewControl.vue
new file mode 100644
index 0000000..6b5c1bf
--- /dev/null
+++ b/src/components/SpecialViewControl.vue
@@ -0,0 +1,20 @@
+
+
+
+
+
diff --git a/src/components/StageMaskControl.vue b/src/components/StageMaskControl.vue
new file mode 100644
index 0000000..09091ea
--- /dev/null
+++ b/src/components/StageMaskControl.vue
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/components/ViewportRotationControl.vue b/src/components/ViewportRotationControl.vue
new file mode 100644
index 0000000..7c9d182
--- /dev/null
+++ b/src/components/ViewportRotationControl.vue
@@ -0,0 +1,61 @@
+
+
+
+
+
diff --git a/src/render/sr-visualizer/adapter.ts b/src/render/sr-visualizer/adapter.ts
index 884392e..e1fb977 100644
--- a/src/render/sr-visualizer/adapter.ts
+++ b/src/render/sr-visualizer/adapter.ts
@@ -1,6 +1,6 @@
// dom-factory MUST be imported first: sets globalThis.window/document for svg.js v2
import { createDOMContainer } from './dom-factory.js'
-import { cubeSVG, Axis } from 'sr-visualizer'
+import { cubeSVG, Axis, Masking } from 'sr-visualizer'
import { buildStickerColors } from './color-map.js'
import { ok, err } from '../../logic/result.js'
import type { CubeState } from '../../logic/index.js'
@@ -75,6 +75,16 @@ export class SrVisualizerAdapter implements Renderer {
height,
...(backgroundColor !== undefined && { backgroundColor }),
...(viewportRotations !== undefined && { viewportRotations }),
+ ...(options?.view && { view: options.view }),
+ // ストアが MASK_LIST 定数から値をセットするため実行時安全。Constitution II 準拠。
+ ...(options?.mask && { mask: options.mask as Masking }),
+ ...(options?.maskAlg && { maskAlg: options.maskAlg }),
+ ...(options?.cubeColor !== undefined && { cubeColor: options.cubeColor }),
+ ...(options?.maskColor !== undefined && { maskColor: options.maskColor }),
+ ...(options?.cubeOpacity !== undefined && { cubeOpacity: options.cubeOpacity }),
+ ...(options?.stickerOpacity !== undefined && { stickerOpacity: options.stickerOpacity }),
+ ...(options?.dist !== undefined && { dist: options.dist }),
+ ...(options?.arrows && { arrows: options.arrows }),
})
} catch (e) {
return err
({
diff --git a/src/render/sr-visualizer/dom-factory.ts b/src/render/sr-visualizer/dom-factory.ts
index 3e1378b..33f3dfa 100644
--- a/src/render/sr-visualizer/dom-factory.ts
+++ b/src/render/sr-visualizer/dom-factory.ts
@@ -1,26 +1,20 @@
-// In a browser environment, we use the global window/document.
-// In a Node environment, we use svgdom to provide a mock DOM.
-const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined'
+// In a browser/happy-dom environment the global window is already available.
+// In Node environment we initialize svgdom here, before sr-visualizer is imported,
+// so that SVG.js v2 picks up a working DOM when it first loads.
-export type DomContainer = HTMLElement | any
+export type DomContainer = Element
-let svgWindow: any = isBrowser ? window : null
-
-export async function ensureSVGWindow() {
- if (!svgWindow && !isBrowser) {
- const { createSVGWindow } = await import('svgdom')
- svgWindow = createSVGWindow()
- ;(globalThis as Record).window = svgWindow
- ;(globalThis as Record).document = svgWindow.document
- }
+if (typeof window === 'undefined') {
+ // svgdom lacks TypeScript types; cast through unknown is safe here
+ const { createSVGWindow } = await import('svgdom')
+ const svgWindow = createSVGWindow() as unknown as { document: Document }
+ ;(globalThis as Record).window = svgWindow
+ ;(globalThis as Record).document = svgWindow.document
}
+// Kept for call-site compatibility; initialization now happens at module load time.
+export async function ensureSVGWindow(): Promise {}
+
export function createDOMContainer(): DomContainer {
- if (isBrowser) {
- return document.createElement('div')
- }
- if (!svgWindow) {
- throw new Error('SVG window not initialized. Call ensureSVGWindow() first in Node environment.')
- }
- return svgWindow.document.createElement('div')
+ return document.createElement('div')
}
diff --git a/src/render/types.ts b/src/render/types.ts
index e872386..4bd92ec 100644
--- a/src/render/types.ts
+++ b/src/render/types.ts
@@ -16,6 +16,15 @@ export interface RenderOptions {
readonly width?: number
readonly height?: number
readonly viewportRotations?: ReadonlyArray
+ readonly view?: string
+ readonly mask?: string
+ readonly maskAlg?: string
+ readonly cubeColor?: string
+ readonly maskColor?: string
+ readonly cubeOpacity?: number
+ readonly stickerOpacity?: number
+ readonly dist?: number
+ readonly arrows?: string
}
export type RenderErrorKind =
diff --git a/src/stores/renderOptions.ts b/src/stores/renderOptions.ts
new file mode 100644
index 0000000..49f1305
--- /dev/null
+++ b/src/stores/renderOptions.ts
@@ -0,0 +1,151 @@
+import { defineStore } from 'pinia'
+import { ref, computed, watch, onMounted } from 'vue'
+import { DEFAULT_COLOR_SCHEME } from '../render/defaults.js'
+import type { RenderOptions, ViewAxis } from '../render/types.js'
+
+const STORAGE_KEY = 'vce3-render-options'
+
+export const useRenderOptionsStore = defineStore('renderOptions', () => {
+ const imageSize = ref(128)
+ const view = ref<'normal' | 'plan'>('normal')
+ const mask = ref('')
+ const maskAlg = ref('')
+ const colorScheme = ref>({ ...DEFAULT_COLOR_SCHEME })
+ const backgroundColor = ref('#ffffff')
+ const cubeColor = ref('#000000')
+ const maskColor = ref('#404040')
+ const cubeOpacity = ref(100)
+ const stickerOpacity = ref(100)
+ const dist = ref(5)
+ const viewportRotations = ref<[ViewAxis, number][]>([
+ ['y', 45],
+ ['x', -34],
+ ['z', 0],
+ ])
+ const arrows = ref('')
+
+ const renderOptions = computed((): RenderOptions => ({
+ width: imageSize.value,
+ height: imageSize.value,
+ colorScheme: colorScheme.value,
+ backgroundColor: backgroundColor.value,
+ cubeColor: cubeColor.value,
+ maskColor: maskColor.value,
+ cubeOpacity: cubeOpacity.value,
+ stickerOpacity: stickerOpacity.value,
+ dist: dist.value,
+ viewportRotations: viewportRotations.value,
+ ...(view.value === 'plan' && { view: 'plan' }),
+ ...(mask.value && { mask: mask.value }),
+ ...(mask.value && maskAlg.value && { maskAlg: maskAlg.value }),
+ ...(arrows.value && { arrows: arrows.value }),
+ }))
+
+ // a←b←c←d←(original a)
+ function cycleFaceColors(
+ a: 0 | 1 | 2 | 3 | 4 | 5,
+ b: 0 | 1 | 2 | 3 | 4 | 5,
+ c: 0 | 1 | 2 | 3 | 4 | 5,
+ d: 0 | 1 | 2 | 3 | 4 | 5,
+ ): void {
+ const s = { ...colorScheme.value }
+ const [ca, cb, cc, cd] = [s[a], s[b], s[c], s[d]]
+ s[a] = cb
+ s[b] = cc
+ s[c] = cd
+ s[d] = ca
+ colorScheme.value = s
+ }
+
+ // U←B, B←D, D←F, F←U
+ function rotateX(): void {
+ cycleFaceColors(0, 3, 1, 2)
+ }
+
+ // F←R, R←B, B←L, L←F
+ function rotateY(): void {
+ cycleFaceColors(2, 4, 3, 5)
+ }
+
+ // U←L, L←D, D←R, R←U
+ function rotateZ(): void {
+ cycleFaceColors(0, 5, 1, 4)
+ }
+
+ function resetColorScheme(): void {
+ colorScheme.value = { ...DEFAULT_COLOR_SCHEME }
+ }
+
+ // Constitution VI: localStorage 自動保存
+ watch(
+ () => ({
+ imageSize: imageSize.value,
+ view: view.value,
+ mask: mask.value,
+ maskAlg: maskAlg.value,
+ colorScheme: { ...colorScheme.value },
+ backgroundColor: backgroundColor.value,
+ cubeColor: cubeColor.value,
+ maskColor: maskColor.value,
+ cubeOpacity: cubeOpacity.value,
+ stickerOpacity: stickerOpacity.value,
+ dist: dist.value,
+ viewportRotations: viewportRotations.value,
+ arrows: arrows.value,
+ }),
+ (val) => {
+ localStorage.setItem(STORAGE_KEY, JSON.stringify({ v: 1, ...val }))
+ },
+ { deep: true },
+ )
+
+ // Constitution VI: マウント時に localStorage から復元
+ onMounted(() => {
+ const raw = localStorage.getItem(STORAGE_KEY)
+ if (!raw) return
+ try {
+ const data = JSON.parse(raw) as Record
+ if (data['v'] !== 1) return
+ if (typeof data['imageSize'] === 'number') imageSize.value = data['imageSize']
+ if (data['view'] === 'normal' || data['view'] === 'plan') view.value = data['view']
+ if (typeof data['mask'] === 'string') mask.value = data['mask']
+ if (typeof data['maskAlg'] === 'string') maskAlg.value = data['maskAlg']
+ if (typeof data['backgroundColor'] === 'string') backgroundColor.value = data['backgroundColor']
+ if (typeof data['cubeColor'] === 'string') cubeColor.value = data['cubeColor']
+ if (typeof data['maskColor'] === 'string') maskColor.value = data['maskColor']
+ if (typeof data['cubeOpacity'] === 'number') cubeOpacity.value = data['cubeOpacity']
+ if (typeof data['stickerOpacity'] === 'number') stickerOpacity.value = data['stickerOpacity']
+ if (typeof data['dist'] === 'number') dist.value = data['dist']
+ if (typeof data['arrows'] === 'string') arrows.value = data['arrows']
+ if (Array.isArray(data['viewportRotations'])) {
+ viewportRotations.value = data['viewportRotations'] as [ViewAxis, number][]
+ }
+ if (data['colorScheme'] !== null && typeof data['colorScheme'] === 'object') {
+ colorScheme.value = data['colorScheme'] as Record<0 | 1 | 2 | 3 | 4 | 5, string>
+ }
+ } catch {
+ // 不正データは無視してデフォルト値を維持
+ }
+ })
+
+ return {
+ imageSize,
+ view,
+ mask,
+ maskAlg,
+ colorScheme,
+ backgroundColor,
+ cubeColor,
+ maskColor,
+ cubeOpacity,
+ stickerOpacity,
+ dist,
+ viewportRotations,
+ arrows,
+ renderOptions,
+ resetColorScheme,
+ rotateX,
+ rotateY,
+ rotateZ,
+ }
+})
diff --git a/tests/components/AppearanceControl.test.ts b/tests/components/AppearanceControl.test.ts
new file mode 100644
index 0000000..04ee26e
--- /dev/null
+++ b/tests/components/AppearanceControl.test.ts
@@ -0,0 +1,50 @@
+// @vitest-environment happy-dom
+import { describe, it, expect, beforeEach } from 'vitest'
+import { mount } from '@vue/test-utils'
+import { createPinia, setActivePinia } from 'pinia'
+import AppearanceControl from '../../src/components/AppearanceControl.vue'
+import { useRenderOptionsStore } from '../../src/stores/renderOptions.js'
+
+describe('AppearanceControl', () => {
+ beforeEach(() => {
+ setActivePinia(createPinia())
+ })
+
+ it('背景色・キューブ色・マスク色の3つのカラーピッカーが存在する', () => {
+ const wrapper = mount(AppearanceControl, { global: { plugins: [createPinia()] } })
+ expect(wrapper.findAll('input[type="color"]')).toHaveLength(3)
+ })
+
+ it('背景色ピッカーの変更で store.backgroundColor が更新される', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(AppearanceControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ await wrapper.find('input[data-testid="background-color"]').setValue('#112233')
+
+ expect(store.backgroundColor).toBe('#112233')
+ })
+
+ it('cubeOpacity スライダーの変更で store.cubeOpacity が更新される', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(AppearanceControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ await wrapper.find('input[data-testid="cube-opacity"]').setValue('75')
+
+ expect(store.cubeOpacity).toBe(75)
+ })
+
+ it('dist スライダーの変更で store.dist が更新される', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(AppearanceControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ await wrapper.find('input[data-testid="dist"]').setValue('30')
+
+ expect(store.dist).toBe(30)
+ })
+})
diff --git a/tests/components/ColorSchemeControl.test.ts b/tests/components/ColorSchemeControl.test.ts
new file mode 100644
index 0000000..21152c5
--- /dev/null
+++ b/tests/components/ColorSchemeControl.test.ts
@@ -0,0 +1,81 @@
+// @vitest-environment happy-dom
+import { describe, it, expect, beforeEach } from 'vitest'
+import { mount } from '@vue/test-utils'
+import { createPinia, setActivePinia } from 'pinia'
+import ColorSchemeControl from '../../src/components/ColorSchemeControl.vue'
+import { useRenderOptionsStore } from '../../src/stores/renderOptions.js'
+import { DEFAULT_COLOR_SCHEME } from '../../src/render/defaults.js'
+
+describe('ColorSchemeControl', () => {
+ beforeEach(() => {
+ setActivePinia(createPinia())
+ })
+
+ it('6つのカラーピッカーが存在する', () => {
+ const wrapper = mount(ColorSchemeControl, { global: { plugins: [createPinia()] } })
+ expect(wrapper.findAll('input[type="color"]')).toHaveLength(6)
+ })
+
+ it('U面ピッカー(インデックス0)の値変更で store.colorScheme[0] が更新される', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(ColorSchemeControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ await wrapper.findAll('input[type="color"]')[0]!.setValue('#aabbcc')
+
+ expect(store.colorScheme[0]).toBe('#aabbcc')
+ })
+
+ it('"x" ボタンクリックで rotateX が実行される(U←B の色変化を確認)', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(ColorSchemeControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ const beforeB = store.colorScheme[3]
+ const xBtn = wrapper.findAll('button').find((b) => b.text() === 'x')
+ await xBtn!.trigger('click')
+
+ expect(store.colorScheme[0]).toBe(beforeB) // U ← B
+ })
+
+ it('"y" ボタンクリックで rotateY が実行される(F←R の色変化を確認)', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(ColorSchemeControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ const beforeR = store.colorScheme[4]
+ const yBtn = wrapper.findAll('button').find((b) => b.text() === 'y')
+ await yBtn!.trigger('click')
+
+ expect(store.colorScheme[2]).toBe(beforeR) // F ← R
+ })
+
+ it('"z" ボタンクリックで rotateZ が実行される(U←L の色変化を確認)', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(ColorSchemeControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ const beforeL = store.colorScheme[5]
+ const zBtn = wrapper.findAll('button').find((b) => b.text() === 'z')
+ await zBtn!.trigger('click')
+
+ expect(store.colorScheme[0]).toBe(beforeL) // U ← L
+ })
+
+ it('"Reset" ボタンクリックで resetColorScheme が実行される', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(ColorSchemeControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ store.colorScheme = { 0: '#111111', 1: '#222222', 2: '#333333', 3: '#444444', 4: '#555555', 5: '#666666' }
+ const resetBtn = wrapper.findAll('button').find((b) => b.text() === 'Reset')
+ await resetBtn!.trigger('click')
+
+ expect(store.colorScheme).toEqual(DEFAULT_COLOR_SCHEME)
+ })
+})
diff --git a/tests/components/ImageSizeControl.test.ts b/tests/components/ImageSizeControl.test.ts
new file mode 100644
index 0000000..f44e033
--- /dev/null
+++ b/tests/components/ImageSizeControl.test.ts
@@ -0,0 +1,68 @@
+// @vitest-environment happy-dom
+import { describe, it, expect, beforeEach } from 'vitest'
+import { mount } from '@vue/test-utils'
+import { createPinia, setActivePinia } from 'pinia'
+import ImageSizeControl from '../../src/components/ImageSizeControl.vue'
+import { useRenderOptionsStore } from '../../src/stores/renderOptions.js'
+
+describe('ImageSizeControl', () => {
+ beforeEach(() => {
+ setActivePinia(createPinia())
+ })
+
+ it('+1/−1/+10/−10/Reset の5ボタンが存在する', () => {
+ const wrapper = mount(ImageSizeControl, { global: { plugins: [createPinia()] } })
+ const buttons = wrapper.findAll('button')
+ expect(buttons).toHaveLength(5)
+ })
+
+ it('+10 ボタンクリックで store.imageSize が 10 増加する', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(ImageSizeControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ const before = store.imageSize
+ const btn = wrapper.findAll('button').find((b) => b.text() === '+10')
+ await btn!.trigger('click')
+
+ expect(store.imageSize).toBe(before + 10)
+ })
+
+ it('−10 ボタンで 1px 未満にならない(下限クランプ)', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(ImageSizeControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ store.imageSize = 5
+ const btn = wrapper.findAll('button').find((b) => b.text() === '−10')
+ await btn!.trigger('click')
+
+ expect(store.imageSize).toBe(1)
+ })
+
+ it('Reset ボタンで imageSize が 128 に戻る', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(ImageSizeControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ store.imageSize = 256
+ const btn = wrapper.findAll('button').find((b) => b.text() === 'Reset')
+ await btn!.trigger('click')
+
+ expect(store.imageSize).toBe(128)
+ })
+
+ it('スライダー変更で store.imageSize が更新される', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(ImageSizeControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ await wrapper.find('input[type="range"]').setValue('200')
+
+ expect(store.imageSize).toBe(200)
+ })
+})
diff --git a/tests/components/SizeSelector.test.ts b/tests/components/SizeSelector.test.ts
index 1e79566..35a118b 100644
--- a/tests/components/SizeSelector.test.ts
+++ b/tests/components/SizeSelector.test.ts
@@ -50,4 +50,54 @@ describe('SizeSelector', () => {
expect(store.cubeState.size).toBe(2)
})
+
+ it('+ ボタンクリックで store.size が 1 増加する', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(SizeSelector, { global: { plugins: [pinia] } })
+ const store = useCubeStore()
+
+ const btn = wrapper.findAll('button').find((b) => b.text() === '+')
+ await btn!.trigger('click')
+
+ expect(store.size).toBe(4)
+ })
+
+ it('− ボタンクリックで store.size が 1 減少する', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(SizeSelector, { global: { plugins: [pinia] } })
+ const store = useCubeStore()
+
+ const btn = wrapper.findAll('button').find((b) => b.text() === '−')
+ await btn!.trigger('click')
+
+ expect(store.size).toBe(2)
+ })
+
+ it('最小値(2)で − を押してもサイズが変わらない', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(SizeSelector, { global: { plugins: [pinia] } })
+ const store = useCubeStore()
+
+ store.setSize(2)
+ const btn = wrapper.findAll('button').find((b) => b.text() === '−')
+ await btn!.trigger('click')
+
+ expect(store.size).toBe(2)
+ })
+
+ it('最大値(7)で + を押してもサイズが変わらない', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(SizeSelector, { global: { plugins: [pinia] } })
+ const store = useCubeStore()
+
+ store.setSize(7)
+ const btn = wrapper.findAll('button').find((b) => b.text() === '+')
+ await btn!.trigger('click')
+
+ expect(store.size).toBe(7)
+ })
})
diff --git a/tests/components/SpecialViewControl.test.ts b/tests/components/SpecialViewControl.test.ts
new file mode 100644
index 0000000..8cfcc6f
--- /dev/null
+++ b/tests/components/SpecialViewControl.test.ts
@@ -0,0 +1,59 @@
+// @vitest-environment happy-dom
+import { describe, it, expect, beforeEach } from 'vitest'
+import { mount } from '@vue/test-utils'
+import { createPinia, setActivePinia } from 'pinia'
+import SpecialViewControl from '../../src/components/SpecialViewControl.vue'
+import { useRenderOptionsStore } from '../../src/stores/renderOptions.js'
+
+describe('SpecialViewControl', () => {
+ beforeEach(() => {
+ setActivePinia(createPinia())
+ })
+
+ it('ラジオボタンが "normal" と "plan" の2択存在する', () => {
+ const wrapper = mount(SpecialViewControl, { global: { plugins: [createPinia()] } })
+ const radios = wrapper.findAll('input[type="radio"]')
+ expect(radios).toHaveLength(2)
+ const values = radios.map((r) => (r.element as HTMLInputElement).value)
+ expect(values).toContain('normal')
+ expect(values).toContain('plan')
+ })
+
+ it('初期状態では "normal" が選択されている', () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(SpecialViewControl, { global: { plugins: [pinia] } })
+ const normalRadio = wrapper.find('input[value="normal"]')
+ expect((normalRadio.element as HTMLInputElement).checked).toBe(true)
+ })
+
+ it('"plan" ラジオを選択すると store.view が "plan" になる', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(SpecialViewControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ const radio = wrapper.find('input[value="plan"]')
+ ;(radio.element as HTMLInputElement).checked = true
+ await radio.trigger('change')
+
+ expect(store.view).toBe('plan')
+ })
+
+ it('"normal" に戻すと store.view が "normal" になる', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(SpecialViewControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ const planRadio = wrapper.find('input[value="plan"]')
+ ;(planRadio.element as HTMLInputElement).checked = true
+ await planRadio.trigger('change')
+
+ const normalRadio = wrapper.find('input[value="normal"]')
+ ;(normalRadio.element as HTMLInputElement).checked = true
+ await normalRadio.trigger('change')
+
+ expect(store.view).toBe('normal')
+ })
+})
diff --git a/tests/components/StageMaskControl.test.ts b/tests/components/StageMaskControl.test.ts
new file mode 100644
index 0000000..ff862fd
--- /dev/null
+++ b/tests/components/StageMaskControl.test.ts
@@ -0,0 +1,73 @@
+// @vitest-environment happy-dom
+import { describe, it, expect, beforeEach } from 'vitest'
+import { nextTick } from 'vue'
+import { mount } from '@vue/test-utils'
+import { createPinia, setActivePinia } from 'pinia'
+import StageMaskControl from '../../src/components/StageMaskControl.vue'
+import { useRenderOptionsStore } from '../../src/stores/renderOptions.js'
+
+describe('StageMaskControl', () => {
+ beforeEach(() => {
+ setActivePinia(createPinia())
+ })
+
+ it('マスク未選択時は maskAlg セレクトが disabled', () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(StageMaskControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+ expect(store.mask).toBe('')
+ const selects = wrapper.findAll('select')
+ const maskAlgSelect = selects[1]
+ expect((maskAlgSelect!.element as HTMLSelectElement).disabled).toBe(true)
+ })
+
+ it('"OLL" を選択すると store.mask が "oll" になる', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(StageMaskControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ await wrapper.findAll('select')[0]!.setValue('oll')
+
+ expect(store.mask).toBe('oll')
+ })
+
+ it('マスク選択後は maskAlg セレクトが有効になる', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(StageMaskControl, { global: { plugins: [pinia] } })
+
+ await wrapper.findAll('select')[0]!.setValue('oll')
+ await nextTick()
+
+ const maskAlgSelect = wrapper.findAll('select')[1]
+ expect((maskAlgSelect!.element as HTMLSelectElement).disabled).toBe(false)
+ })
+
+ it('Mask Alg で "y" を選ぶと store.maskAlg が "y" になる', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(StageMaskControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ store.mask = 'oll'
+ await nextTick()
+
+ await wrapper.findAll('select')[1]!.setValue('y')
+
+ expect(store.maskAlg).toBe('y')
+ })
+
+ it('マスクを空に戻すと store.mask が "" になる', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(StageMaskControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ await wrapper.findAll('select')[0]!.setValue('oll')
+ await wrapper.findAll('select')[0]!.setValue('')
+
+ expect(store.mask).toBe('')
+ })
+})
diff --git a/tests/components/ViewportRotationControl.test.ts b/tests/components/ViewportRotationControl.test.ts
new file mode 100644
index 0000000..a30aaa5
--- /dev/null
+++ b/tests/components/ViewportRotationControl.test.ts
@@ -0,0 +1,89 @@
+// @vitest-environment happy-dom
+import { describe, it, expect, beforeEach } from 'vitest'
+import { mount } from '@vue/test-utils'
+import { createPinia, setActivePinia } from 'pinia'
+import ViewportRotationControl from '../../src/components/ViewportRotationControl.vue'
+import { useRenderOptionsStore } from '../../src/stores/renderOptions.js'
+
+describe('ViewportRotationControl', () => {
+ beforeEach(() => {
+ setActivePinia(createPinia())
+ })
+
+ it('3スロット分の軸セレクトが存在する', () => {
+ const wrapper = mount(ViewportRotationControl, { global: { plugins: [createPinia()] } })
+ expect(wrapper.findAll('select')).toHaveLength(3)
+ })
+
+ it('3スロット分のスライダーが存在する', () => {
+ const wrapper = mount(ViewportRotationControl, { global: { plugins: [createPinia()] } })
+ expect(wrapper.findAll('input[type="range"]')).toHaveLength(3)
+ })
+
+ it('3スロット分の数値入力が存在する', () => {
+ const wrapper = mount(ViewportRotationControl, { global: { plugins: [createPinia()] } })
+ expect(wrapper.findAll('input[type="number"]')).toHaveLength(3)
+ })
+
+ it('初期状態でスロット0の軸が y、角度が 45 である', () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(ViewportRotationControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ expect(store.viewportRotations[0]).toEqual(['y', 45])
+ const rangeInput = wrapper.findAll('input[type="range"]')[0]!
+ expect((rangeInput.element as HTMLInputElement).value).toBe('45')
+ })
+
+ it('スロット0のスライダー変更で store.viewportRotations[0] の角度が更新される', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(ViewportRotationControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ await wrapper.findAll('input[type="range"]')[0]!.setValue('90')
+
+ expect(store.viewportRotations[0]![1]).toBe(90)
+ })
+
+ it('スロット0の数値入力変更で store.viewportRotations[0] の角度が更新される', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(ViewportRotationControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ await wrapper.findAll('input[type="number"]')[0]!.setValue('-90')
+
+ expect(store.viewportRotations[0]![1]).toBe(-90)
+ })
+
+ it('スロット0の Reset ボタンクリックでデフォルト値(y/45)に戻る', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(ViewportRotationControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ await wrapper.findAll('input[type="range"]')[0]!.setValue('90')
+ expect(store.viewportRotations[0]![1]).toBe(90)
+
+ const resetBtns = wrapper.findAll('button').filter((b) => b.text() === 'Reset')
+ await resetBtns[0]!.trigger('click')
+
+ expect(store.viewportRotations[0]).toEqual(['y', 45])
+ })
+
+ it('スロット1の Reset ボタンクリックでデフォルト値(x/-34)に戻る', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const wrapper = mount(ViewportRotationControl, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ await wrapper.findAll('input[type="range"]')[1]!.setValue('0')
+
+ const resetBtns = wrapper.findAll('button').filter((b) => b.text() === 'Reset')
+ await resetBtns[1]!.trigger('click')
+
+ expect(store.viewportRotations[1]).toEqual(['x', -34])
+ })
+})
diff --git a/tests/render/adapter.test.ts b/tests/render/adapter.test.ts
index 133da3c..f7a0488 100644
--- a/tests/render/adapter.test.ts
+++ b/tests/render/adapter.test.ts
@@ -1,10 +1,15 @@
-import { describe, it, expect } from 'vitest'
+import { describe, it, expect, beforeAll } from 'vitest'
import { SrVisualizerAdapter } from '../../src/render/sr-visualizer/adapter.js'
+import { ensureSVGWindow } from '../../src/render/sr-visualizer/dom-factory.js'
import { createCube } from '../../src/logic/index.js'
import { applyMove } from '../../src/logic/rotation.js'
import { Face, Direction, type CubeState } from '../../src/logic/types.js'
import { DEFAULT_COLOR_SCHEME } from '../../src/render/defaults.js'
+beforeAll(async () => {
+ await ensureSVGWindow()
+})
+
// ---------------------------------------------------------------------------
// ヘルパー
// ---------------------------------------------------------------------------
diff --git a/tests/render/index.test.ts b/tests/render/index.test.ts
index a10e12b..bcb129f 100644
--- a/tests/render/index.test.ts
+++ b/tests/render/index.test.ts
@@ -1,8 +1,13 @@
-import { describe, it, expect } from 'vitest'
+import { describe, it, expect, beforeAll } from 'vitest'
import { renderSVG, renderPNG, createRenderer, DEFAULT_COLOR_SCHEME } from '../../src/render/index.js'
+import { ensureSVGWindow } from '../../src/render/sr-visualizer/dom-factory.js'
import { createCube } from '../../src/logic/index.js'
import type { CubeState } from '../../src/logic/types.js'
+beforeAll(async () => {
+ await ensureSVGWindow()
+})
+
function solved(n: 2 | 3 | 4 | 5 | 6 | 7): CubeState {
const r = createCube(n)
if (!r.ok) throw new Error(r.error.message)
diff --git a/tests/render/render-options.test.ts b/tests/render/render-options.test.ts
index 1b103f1..ea62b76 100644
--- a/tests/render/render-options.test.ts
+++ b/tests/render/render-options.test.ts
@@ -1,10 +1,15 @@
-import { describe, it, expect } from 'vitest'
+import { describe, it, expect, beforeAll } from 'vitest'
import { SrVisualizerAdapter } from '../../src/render/sr-visualizer/adapter.js'
+import { ensureSVGWindow } from '../../src/render/sr-visualizer/dom-factory.js'
import { createCube } from '../../src/logic/index.js'
import type { CubeState } from '../../src/logic/types.js'
import { ViewAxis } from '../../src/render/types.js'
import { DEFAULT_COLOR_SCHEME } from '../../src/render/defaults.js'
+beforeAll(async () => {
+ await ensureSVGWindow()
+})
+
function solved(n: 2 | 3 | 4 | 5 | 6 | 7): CubeState {
const r = createCube(n)
if (!r.ok) throw new Error(r.error.message)
diff --git a/tests/stores/renderOptions.test.ts b/tests/stores/renderOptions.test.ts
new file mode 100644
index 0000000..bdb0f97
--- /dev/null
+++ b/tests/stores/renderOptions.test.ts
@@ -0,0 +1,346 @@
+// @vitest-environment happy-dom
+import { describe, it, expect, beforeEach } from 'vitest'
+import { defineComponent, nextTick } from 'vue'
+import { mount, flushPromises } from '@vue/test-utils'
+import { setActivePinia, createPinia } from 'pinia'
+import { useRenderOptionsStore } from '../../src/stores/renderOptions.js'
+import { DEFAULT_COLOR_SCHEME } from '../../src/render/defaults.js'
+
+const STORAGE_KEY = 'vce3-render-options'
+
+// onMounted を発火させるためのテスト用コンポーネント
+const TestComponent = defineComponent({
+ setup() {
+ useRenderOptionsStore()
+ return {}
+ },
+ template: '',
+})
+
+describe('useRenderOptionsStore', () => {
+ beforeEach(() => {
+ setActivePinia(createPinia())
+ localStorage.clear()
+ })
+
+ // ---------------------------------------------------------------------------
+ // デフォルト値
+ // ---------------------------------------------------------------------------
+
+ describe('デフォルト値', () => {
+ it('imageSize は 128', () => {
+ const store = useRenderOptionsStore()
+ expect(store.imageSize).toBe(128)
+ })
+
+ it('view は "normal"', () => {
+ const store = useRenderOptionsStore()
+ expect(store.view).toBe('normal')
+ })
+
+ it('mask は ""', () => {
+ const store = useRenderOptionsStore()
+ expect(store.mask).toBe('')
+ })
+
+ it('maskAlg は ""', () => {
+ const store = useRenderOptionsStore()
+ expect(store.maskAlg).toBe('')
+ })
+
+ it('backgroundColor は "#ffffff"', () => {
+ const store = useRenderOptionsStore()
+ expect(store.backgroundColor).toBe('#ffffff')
+ })
+
+ it('cubeColor は "#000000"', () => {
+ const store = useRenderOptionsStore()
+ expect(store.cubeColor).toBe('#000000')
+ })
+
+ it('maskColor は "#404040"', () => {
+ const store = useRenderOptionsStore()
+ expect(store.maskColor).toBe('#404040')
+ })
+
+ it('cubeOpacity は 100', () => {
+ const store = useRenderOptionsStore()
+ expect(store.cubeOpacity).toBe(100)
+ })
+
+ it('stickerOpacity は 100', () => {
+ const store = useRenderOptionsStore()
+ expect(store.stickerOpacity).toBe(100)
+ })
+
+ it('dist は 5', () => {
+ const store = useRenderOptionsStore()
+ expect(store.dist).toBe(5)
+ })
+
+ it('arrows は ""', () => {
+ const store = useRenderOptionsStore()
+ expect(store.arrows).toBe('')
+ })
+
+ it('viewportRotations は [y/45, x/-34, z/0]', () => {
+ const store = useRenderOptionsStore()
+ expect(store.viewportRotations).toEqual([
+ ['y', 45],
+ ['x', -34],
+ ['z', 0],
+ ])
+ })
+
+ it('colorScheme は WCA 標準色', () => {
+ const store = useRenderOptionsStore()
+ expect(store.colorScheme).toEqual(DEFAULT_COLOR_SCHEME)
+ })
+ })
+
+ // ---------------------------------------------------------------------------
+ // rotateX — U←B, B←D, D←F, F←U
+ // ---------------------------------------------------------------------------
+
+ describe('rotateX', () => {
+ it('U←B, B←D, D←F, F←U で色を循環する', () => {
+ const store = useRenderOptionsStore()
+ const before = { ...store.colorScheme }
+ store.rotateX()
+ const after = store.colorScheme
+ expect(after[0]).toBe(before[3]) // U ← B
+ expect(after[3]).toBe(before[1]) // B ← D
+ expect(after[1]).toBe(before[2]) // D ← F
+ expect(after[2]).toBe(before[0]) // F ← U
+ expect(after[4]).toBe(before[4]) // R は変化しない
+ expect(after[5]).toBe(before[5]) // L は変化しない
+ })
+
+ it('4回実行すると元の状態に戻る', () => {
+ const store = useRenderOptionsStore()
+ const before = { ...store.colorScheme }
+ for (let i = 0; i < 4; i++) store.rotateX()
+ expect(store.colorScheme).toEqual(before)
+ })
+ })
+
+ // ---------------------------------------------------------------------------
+ // rotateY — F←R, R←B, B←L, L←F
+ // ---------------------------------------------------------------------------
+
+ describe('rotateY', () => {
+ it('F←R, R←B, B←L, L←F で色を循環する', () => {
+ const store = useRenderOptionsStore()
+ const before = { ...store.colorScheme }
+ store.rotateY()
+ const after = store.colorScheme
+ expect(after[2]).toBe(before[4]) // F ← R
+ expect(after[4]).toBe(before[3]) // R ← B
+ expect(after[3]).toBe(before[5]) // B ← L
+ expect(after[5]).toBe(before[2]) // L ← F
+ expect(after[0]).toBe(before[0]) // U は変化しない
+ expect(after[1]).toBe(before[1]) // D は変化しない
+ })
+
+ it('4回実行すると元の状態に戻る', () => {
+ const store = useRenderOptionsStore()
+ const before = { ...store.colorScheme }
+ for (let i = 0; i < 4; i++) store.rotateY()
+ expect(store.colorScheme).toEqual(before)
+ })
+ })
+
+ // ---------------------------------------------------------------------------
+ // rotateZ — U←L, L←D, D←R, R←U
+ // ---------------------------------------------------------------------------
+
+ describe('rotateZ', () => {
+ it('U←L, L←D, D←R, R←U で色を循環する', () => {
+ const store = useRenderOptionsStore()
+ const before = { ...store.colorScheme }
+ store.rotateZ()
+ const after = store.colorScheme
+ expect(after[0]).toBe(before[5]) // U ← L
+ expect(after[5]).toBe(before[1]) // L ← D
+ expect(after[1]).toBe(before[4]) // D ← R
+ expect(after[4]).toBe(before[0]) // R ← U
+ expect(after[2]).toBe(before[2]) // F は変化しない
+ expect(after[3]).toBe(before[3]) // B は変化しない
+ })
+
+ it('4回実行すると元の状態に戻る', () => {
+ const store = useRenderOptionsStore()
+ const before = { ...store.colorScheme }
+ for (let i = 0; i < 4; i++) store.rotateZ()
+ expect(store.colorScheme).toEqual(before)
+ })
+ })
+
+ // ---------------------------------------------------------------------------
+ // resetColorScheme
+ // ---------------------------------------------------------------------------
+
+ describe('resetColorScheme', () => {
+ it('rotateX 後に WCA 標準色へ戻る', () => {
+ const store = useRenderOptionsStore()
+ store.rotateX()
+ expect(store.colorScheme).not.toEqual(DEFAULT_COLOR_SCHEME)
+ store.resetColorScheme()
+ expect(store.colorScheme).toEqual(DEFAULT_COLOR_SCHEME)
+ })
+
+ it('任意の色変更後に WCA 標準色へ戻る', () => {
+ const store = useRenderOptionsStore()
+ store.colorScheme = { 0: '#111111', 1: '#222222', 2: '#333333', 3: '#444444', 4: '#555555', 5: '#666666' }
+ store.resetColorScheme()
+ expect(store.colorScheme).toEqual(DEFAULT_COLOR_SCHEME)
+ })
+ })
+
+ // ---------------------------------------------------------------------------
+ // renderOptions computed
+ // ---------------------------------------------------------------------------
+
+ describe('renderOptions computed', () => {
+ it('width と height は imageSize と等しい', () => {
+ const store = useRenderOptionsStore()
+ expect(store.renderOptions.width).toBe(128)
+ expect(store.renderOptions.height).toBe(128)
+ })
+
+ it('imageSize 変更が width/height に反映される', () => {
+ const store = useRenderOptionsStore()
+ store.imageSize = 256
+ expect(store.renderOptions.width).toBe(256)
+ expect(store.renderOptions.height).toBe(256)
+ })
+
+ it('view="normal" のとき view フィールドが含まれない', () => {
+ const store = useRenderOptionsStore()
+ expect(store.view).toBe('normal')
+ expect(store.renderOptions).not.toHaveProperty('view')
+ })
+
+ it('view="plan" のとき { view: "plan" } が含まれる', () => {
+ const store = useRenderOptionsStore()
+ store.view = 'plan'
+ expect(store.renderOptions.view).toBe('plan')
+ })
+
+ it('mask="" のとき mask フィールドが含まれない', () => {
+ const store = useRenderOptionsStore()
+ expect(store.mask).toBe('')
+ expect(store.renderOptions).not.toHaveProperty('mask')
+ })
+
+ it('mask="oll" のとき { mask: "oll" } が含まれる', () => {
+ const store = useRenderOptionsStore()
+ store.mask = 'oll'
+ expect(store.renderOptions.mask).toBe('oll')
+ })
+
+ it('mask="" かつ maskAlg="y" のとき maskAlg フィールドが含まれない', () => {
+ const store = useRenderOptionsStore()
+ store.maskAlg = 'y'
+ expect(store.renderOptions).not.toHaveProperty('maskAlg')
+ })
+
+ it('mask="oll" かつ maskAlg="y" のとき { maskAlg: "y" } が含まれる', () => {
+ const store = useRenderOptionsStore()
+ store.mask = 'oll'
+ store.maskAlg = 'y'
+ expect(store.renderOptions.maskAlg).toBe('y')
+ })
+
+ it('arrows="" のとき arrows フィールドが含まれない', () => {
+ const store = useRenderOptionsStore()
+ expect(store.renderOptions).not.toHaveProperty('arrows')
+ })
+
+ it('arrows に値を設定すると含まれる', () => {
+ const store = useRenderOptionsStore()
+ store.arrows = 'UFR-UFR'
+ expect(store.renderOptions.arrows).toBe('UFR-UFR')
+ })
+ })
+
+ // ---------------------------------------------------------------------------
+ // localStorage 永続化(Constitution VI 準拠)
+ // ---------------------------------------------------------------------------
+
+ describe('localStorage 永続化', () => {
+ it('imageSize 変更時に localStorage へ保存される', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ mount(TestComponent, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ store.imageSize = 256
+ await nextTick()
+
+ expect(localStorage.getItem(STORAGE_KEY)).not.toBeNull()
+ })
+
+ it('保存データは有効な JSON', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ mount(TestComponent, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+
+ store.imageSize = 200
+ await nextTick()
+
+ const raw = localStorage.getItem(STORAGE_KEY)
+ expect(raw).not.toBeNull()
+ expect(() => JSON.parse(raw!)).not.toThrow()
+ })
+
+ it('マウント時に localStorage から imageSize が復元される', async () => {
+ localStorage.setItem(STORAGE_KEY, JSON.stringify({ v: 1, imageSize: 300 }))
+
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ mount(TestComponent, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+ await flushPromises()
+
+ expect(store.imageSize).toBe(300)
+ })
+
+ it('マウント時に localStorage から view が復元される', async () => {
+ localStorage.setItem(STORAGE_KEY, JSON.stringify({ v: 1, view: 'plan' }))
+
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ mount(TestComponent, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+ await flushPromises()
+
+ expect(store.view).toBe('plan')
+ })
+
+ it('不正 JSON の場合はデフォルト値のまま', async () => {
+ localStorage.setItem(STORAGE_KEY, 'INVALID{JSON}')
+
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ mount(TestComponent, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+ await flushPromises()
+
+ expect(store.imageSize).toBe(128)
+ expect(store.view).toBe('normal')
+ })
+
+ it('localStorage が空の場合はデフォルト値のまま', async () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ mount(TestComponent, { global: { plugins: [pinia] } })
+ const store = useRenderOptionsStore()
+ await flushPromises()
+
+ expect(store.imageSize).toBe(128)
+ expect(store.view).toBe('normal')
+ })
+ })
+})